diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-26 13:59:43 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-05-26 13:59:43 +0000 |
commit | 937338cf64350a7d05d0c956dc8e8564e959cb7b (patch) | |
tree | 986770448d7197905604cb67a67e36ca61b6cbda /include/llvm/Support/MDBuilder.h | |
parent | 9632f77f8dde9d2c9c9cb9d022b846a82c918cbd (diff) |
Add support for branch weight metadata to MDBuilder and use it in various places.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@157515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/Support/MDBuilder.h')
-rw-r--r-- | include/llvm/Support/MDBuilder.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/include/llvm/Support/MDBuilder.h b/include/llvm/Support/MDBuilder.h index 40f028a432..855e58d699 100644 --- a/include/llvm/Support/MDBuilder.h +++ b/include/llvm/Support/MDBuilder.h @@ -49,6 +49,29 @@ namespace llvm { return MDNode::get(Context, Op); } + //===------------------------------------------------------------------===// + // Prof metadata. + //===------------------------------------------------------------------===// + + /// \brief Return metadata containing two branch weights. + MDNode *createBranchWeights(uint32_t TrueWeight, uint32_t FalseWeight) { + uint32_t Weights[] = { TrueWeight, FalseWeight }; + return createBranchWeights(Weights); + } + + /// \brief Return metadata containing a number of branch weights. + MDNode *createBranchWeights(ArrayRef<uint32_t> Weights) { + assert(Weights.size() >= 2 && "Need at least two branch weights!"); + + SmallVector<Value *, 4> Vals(Weights.size()+1); + Vals[0] = createString("branch_weights"); + + Type *Int32Ty = Type::getInt32Ty(Context); + for (unsigned i = 0, e = Weights.size(); i != e; ++i) + Vals[i+1] = ConstantInt::get(Int32Ty, Weights[i]); + + return MDNode::get(Context, Vals); + } //===------------------------------------------------------------------===// // Range metadata. |