diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2018-06-27 23:58:08 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2018-06-27 23:58:08 +0000 |
commit | 5bf1ead3771667bc51d7b6b2ddc29cb860b4fe21 (patch) | |
tree | aae2c2b9bd92abfe0bf8942cfbdcd8f567aa554e /llvm/lib/IR | |
parent | 0cad9cb9a4b9c3fcda1086dbdab734ef82f780c3 (diff) | |
download | bcm5719-llvm-5bf1ead3771667bc51d7b6b2ddc29cb860b4fe21.tar.gz bcm5719-llvm-5bf1ead3771667bc51d7b6b2ddc29cb860b4fe21.zip |
Add support for generating a call graph profile from Branch Frequency Info.
=== Generating the CG Profile ===
The CGProfile module pass simply gets the block profile count for each BB and scans for call instructions. For each call instruction it adds an edge from the current function to the called function with the current BB block profile count as the weight.
After scanning all the functions, it generates an appending module flag containing the data. The format looks like:
```
!llvm.module.flags = !{!0}
!0 = !{i32 5, !"CG Profile", !1}
!1 = !{!2, !3, !4} ; List of edges
!2 = !{void ()* @a, void ()* @b, i64 32} ; Edge from a to b with a weight of 32
!3 = !{void (i1)* @freq, void ()* @a, i64 11}
!4 = !{void (i1)* @freq, void ()* @b, i64 20}
```
Differential Revision: https://reviews.llvm.org/D48105
llvm-svn: 335794
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r-- | llvm/lib/IR/Verifier.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index dca9d9b64ff..11af71142ef 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -409,6 +409,7 @@ private: void visitModuleFlag(const MDNode *Op, DenseMap<const MDString *, const MDNode *> &SeenIDs, SmallVectorImpl<const MDNode *> &Requirements); + void visitModuleFlagCGProfileEntry(const MDOperand &MDO); void visitFunction(const Function &F); void visitBasicBlock(BasicBlock &BB); void visitRangeMetadata(Instruction &I, MDNode *Range, Type *Ty); @@ -1411,6 +1412,25 @@ Verifier::visitModuleFlag(const MDNode *Op, Assert(M.getNamedMetadata("llvm.linker.options"), "'Linker Options' named metadata no longer supported"); } + + if (ID->getString() == "CG Profile") { + for (const MDOperand &MDO : cast<MDNode>(Op->getOperand(2))->operands()) + visitModuleFlagCGProfileEntry(MDO); + } +} + +void Verifier::visitModuleFlagCGProfileEntry(const MDOperand &MDO) { + auto Node = dyn_cast_or_null<MDNode>(MDO); + Assert(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO); + auto From = dyn_cast_or_null<ValueAsMetadata>(Node->getOperand(0)); + Assert(From && isa<Function>(From->getValue()), "expected a Function", + Node->getOperand(0)); + auto To = dyn_cast_or_null<ValueAsMetadata>(Node->getOperand(1)); + Assert(To && isa<Function>(To->getValue()), "expected a Function", + Node->getOperand(1)); + auto Count = dyn_cast_or_null<ConstantAsMetadata>(Node->getOperand(2)); + Assert(Count && Count->getType()->isIntegerTy(), + "expected an integer constant", Node->getOperand(2)); } /// Return true if this attribute kind only applies to functions. |