mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-26 07:34:06 +00:00
[PM] Pull the two helpers for this pass into static functions. There are
no members for them to use. Also, make them accept references as there is no possibility of a null pointer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226994 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0a9ef5f8c2
commit
d491dadacd
@ -47,11 +47,6 @@ namespace {
|
|||||||
/// terminators. It then removes the expect intrinsics from the IR so the rest
|
/// terminators. It then removes the expect intrinsics from the IR so the rest
|
||||||
/// of the optimizer can ignore them.
|
/// of the optimizer can ignore them.
|
||||||
class LowerExpectIntrinsic : public FunctionPass {
|
class LowerExpectIntrinsic : public FunctionPass {
|
||||||
|
|
||||||
bool HandleSwitchExpect(SwitchInst *SI);
|
|
||||||
|
|
||||||
bool HandleIfExpect(BranchInst *BI);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static char ID;
|
static char ID;
|
||||||
LowerExpectIntrinsic() : FunctionPass(ID) {
|
LowerExpectIntrinsic() : FunctionPass(ID) {
|
||||||
@ -62,8 +57,8 @@ public:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LowerExpectIntrinsic::HandleSwitchExpect(SwitchInst *SI) {
|
static bool handleSwitchExpect(SwitchInst &SI) {
|
||||||
CallInst *CI = dyn_cast<CallInst>(SI->getCondition());
|
CallInst *CI = dyn_cast<CallInst>(SI.getCondition());
|
||||||
if (!CI)
|
if (!CI)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -76,25 +71,25 @@ bool LowerExpectIntrinsic::HandleSwitchExpect(SwitchInst *SI) {
|
|||||||
if (!ExpectedValue)
|
if (!ExpectedValue)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
SwitchInst::CaseIt Case = SI->findCaseValue(ExpectedValue);
|
SwitchInst::CaseIt Case = SI.findCaseValue(ExpectedValue);
|
||||||
unsigned n = SI->getNumCases(); // +1 for default case.
|
unsigned n = SI.getNumCases(); // +1 for default case.
|
||||||
std::vector<uint32_t> Weights(n + 1);
|
std::vector<uint32_t> Weights(n + 1);
|
||||||
|
|
||||||
Weights[0] =
|
Weights[0] =
|
||||||
Case == SI->case_default() ? LikelyBranchWeight : UnlikelyBranchWeight;
|
Case == SI.case_default() ? LikelyBranchWeight : UnlikelyBranchWeight;
|
||||||
for (unsigned i = 0; i != n; ++i)
|
for (unsigned i = 0; i != n; ++i)
|
||||||
Weights[i + 1] =
|
Weights[i + 1] =
|
||||||
i == Case.getCaseIndex() ? LikelyBranchWeight : UnlikelyBranchWeight;
|
i == Case.getCaseIndex() ? LikelyBranchWeight : UnlikelyBranchWeight;
|
||||||
|
|
||||||
SI->setMetadata(LLVMContext::MD_prof,
|
SI.setMetadata(LLVMContext::MD_prof,
|
||||||
MDBuilder(CI->getContext()).createBranchWeights(Weights));
|
MDBuilder(CI->getContext()).createBranchWeights(Weights));
|
||||||
|
|
||||||
SI->setCondition(ArgValue);
|
SI.setCondition(ArgValue);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LowerExpectIntrinsic::HandleIfExpect(BranchInst *BI) {
|
static bool handleBranchExpect(BranchInst &BI) {
|
||||||
if (BI->isUnconditional())
|
if (BI.isUnconditional())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Handle non-optimized IR code like:
|
// Handle non-optimized IR code like:
|
||||||
@ -108,9 +103,9 @@ bool LowerExpectIntrinsic::HandleIfExpect(BranchInst *BI) {
|
|||||||
|
|
||||||
CallInst *CI;
|
CallInst *CI;
|
||||||
|
|
||||||
ICmpInst *CmpI = dyn_cast<ICmpInst>(BI->getCondition());
|
ICmpInst *CmpI = dyn_cast<ICmpInst>(BI.getCondition());
|
||||||
if (!CmpI) {
|
if (!CmpI) {
|
||||||
CI = dyn_cast<CallInst>(BI->getCondition());
|
CI = dyn_cast<CallInst>(BI.getCondition());
|
||||||
} else {
|
} else {
|
||||||
if (CmpI->getPredicate() != CmpInst::ICMP_NE)
|
if (CmpI->getPredicate() != CmpInst::ICMP_NE)
|
||||||
return false;
|
return false;
|
||||||
@ -139,12 +134,12 @@ bool LowerExpectIntrinsic::HandleIfExpect(BranchInst *BI) {
|
|||||||
else
|
else
|
||||||
Node = MDB.createBranchWeights(UnlikelyBranchWeight, LikelyBranchWeight);
|
Node = MDB.createBranchWeights(UnlikelyBranchWeight, LikelyBranchWeight);
|
||||||
|
|
||||||
BI->setMetadata(LLVMContext::MD_prof, Node);
|
BI.setMetadata(LLVMContext::MD_prof, Node);
|
||||||
|
|
||||||
if (CmpI)
|
if (CmpI)
|
||||||
CmpI->setOperand(0, ArgValue);
|
CmpI->setOperand(0, ArgValue);
|
||||||
else
|
else
|
||||||
BI->setCondition(ArgValue);
|
BI.setCondition(ArgValue);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,10 +149,10 @@ bool LowerExpectIntrinsic::runOnFunction(Function &F) {
|
|||||||
|
|
||||||
// Create "block_weights" metadata.
|
// Create "block_weights" metadata.
|
||||||
if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
|
if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
|
||||||
if (HandleIfExpect(BI))
|
if (handleBranchExpect(*BI))
|
||||||
IfHandled++;
|
IfHandled++;
|
||||||
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB->getTerminator())) {
|
} else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB->getTerminator())) {
|
||||||
if (HandleSwitchExpect(SI))
|
if (handleSwitchExpect(*SI))
|
||||||
IfHandled++;
|
IfHandled++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user