aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ProfileData/InstrProf.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ProfileData/InstrProf.cpp')
-rw-r--r--llvm/lib/ProfileData/InstrProf.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp
index 3e0e2b2..c7749f3 100644
--- a/llvm/lib/ProfileData/InstrProf.cpp
+++ b/llvm/lib/ProfileData/InstrProf.cpp
@@ -1382,6 +1382,45 @@ getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind,
return ValueDataArray;
}
+SmallVector<InstrProfValueData, 4>
+getValueProfDataFromInst(const Instruction &Inst, InstrProfValueKind ValueKind,
+ uint32_t MaxNumValueData, uint64_t &TotalC,
+ bool GetNoICPValue) {
+ // Four inline elements seem to work well in practice. With MaxNumValueData,
+ // this array won't grow very big anyway.
+ SmallVector<InstrProfValueData, 4> ValueData;
+ MDNode *MD = mayHaveValueProfileOfKind(Inst, ValueKind);
+ if (!MD)
+ return ValueData;
+ const unsigned NOps = MD->getNumOperands();
+ // Get total count
+ ConstantInt *TotalCInt = mdconst::dyn_extract<ConstantInt>(MD->getOperand(2));
+ if (!TotalCInt)
+ return ValueData;
+ TotalC = TotalCInt->getZExtValue();
+
+ ValueData.reserve((NOps - 3) / 2);
+ for (unsigned I = 3; I < NOps; I += 2) {
+ if (ValueData.size() >= MaxNumValueData)
+ break;
+ ConstantInt *Value = mdconst::dyn_extract<ConstantInt>(MD->getOperand(I));
+ ConstantInt *Count =
+ mdconst::dyn_extract<ConstantInt>(MD->getOperand(I + 1));
+ if (!Value || !Count) {
+ ValueData.clear();
+ return ValueData;
+ }
+ uint64_t CntValue = Count->getZExtValue();
+ if (!GetNoICPValue && (CntValue == NOMORE_ICP_MAGICNUM))
+ continue;
+ InstrProfValueData V;
+ V.Value = Value->getZExtValue();
+ V.Count = CntValue;
+ ValueData.push_back(V);
+ }
+ return ValueData;
+}
+
MDNode *getPGOFuncNameMetadata(const Function &F) {
return F.getMetadata(getPGOFuncNameMetadataName());
}