diff options
author | Christian Ulmann <christian.ulmann@nextsilicon.com> | 2023-01-19 12:04:53 +0100 |
---|---|---|
committer | Christian Ulmann <christian.ulmann@nextsilicon.com> | 2023-01-19 14:26:26 +0100 |
commit | e741b8c2e5200269f846bdd88ca98e44681fe8df (patch) | |
tree | 633474d1ab03298472179373e5b21ea8c9ec1e05 /llvm/lib/IR/Instructions.cpp | |
parent | 7e5681cf295a267de0b8c2216f049d0285a73c4c (diff) | |
download | llvm-e741b8c2e5200269f846bdd88ca98e44681fe8df.zip llvm-e741b8c2e5200269f846bdd88ca98e44681fe8df.tar.gz llvm-e741b8c2e5200269f846bdd88ca98e44681fe8df.tar.bz2 |
[llvm][ir] Purge MD_prof custom accessors
This commit purges direct accesses to MD_prof metadata and replaces them
with the accessors provided from the utility file wherever possible.
This commit can be seen as the first step towards switching the branch weights to 64 bits.
See post here: https://discourse.llvm.org/t/extend-md-prof-branch-weights-metadata-from-32-to-64-bits/67492
Reviewed By: davidxl, paulkirth
Differential Revision: https://reviews.llvm.org/D141393
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() |