diff options
Diffstat (limited to 'llvm/lib/IR/Instructions.cpp')
-rw-r--r-- | llvm/lib/IR/Instructions.cpp | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp index 53e7477..603ea9d 100644 --- a/llvm/lib/IR/Instructions.cpp +++ b/llvm/lib/IR/Instructions.cpp @@ -31,6 +31,7 @@ #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" +#include "llvm/IR/ProfDataUtils.h" #include "llvm/IR/Type.h" #include "llvm/IR/Value.h" #include "llvm/Support/AtomicOrdering.h" @@ -4572,15 +4573,6 @@ void SwitchInst::growOperands() { growHungoffUses(ReservedSpace); } -MDNode * -SwitchInstProfUpdateWrapper::getProfBranchWeightsMD(const SwitchInst &SI) { - if (MDNode *ProfileData = SI.getMetadata(LLVMContext::MD_prof)) - if (auto *MDName = dyn_cast<MDString>(ProfileData->getOperand(0))) - if (MDName->getString() == "branch_weights") - return ProfileData; - return nullptr; -} - MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() { assert(Changed && "called only if metadata has changed"); @@ -4599,7 +4591,7 @@ MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() { } void SwitchInstProfUpdateWrapper::init() { - MDNode *ProfileData = getProfBranchWeightsMD(SI); + MDNode *ProfileData = getBranchWeightMDNode(SI); if (!ProfileData) return; @@ -4609,11 +4601,8 @@ void SwitchInstProfUpdateWrapper::init() { } SmallVector<uint32_t, 8> Weights; - for (unsigned CI = 1, CE = SI.getNumSuccessors(); CI <= CE; ++CI) { - ConstantInt *C = mdconst::extract<ConstantInt>(ProfileData->getOperand(CI)); - uint32_t CW = C->getValue().getZExtValue(); - Weights.push_back(CW); - } + if (!extractBranchWeights(ProfileData, Weights)) + return; this->Weights = std::move(Weights); } @@ -4686,7 +4675,7 @@ void SwitchInstProfUpdateWrapper::setSuccessorWeight( SwitchInstProfUpdateWrapper::CaseWeightOpt SwitchInstProfUpdateWrapper::getSuccessorWeight(const SwitchInst &SI, unsigned idx) { - if (MDNode *ProfileData = getProfBranchWeightsMD(SI)) + if (MDNode *ProfileData = getBranchWeightMDNode(SI)) if (ProfileData->getNumOperands() == SI.getNumSuccessors() + 1) return mdconst::extract<ConstantInt>(ProfileData->getOperand(idx + 1)) ->getValue() |