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
This commit is contained in:
Benjamin Kramer
2012-05-26 13:59:43 +00:00
parent 9632f77f8d
commit 937338cf64
3 changed files with 45 additions and 31 deletions
+5 -6
View File
@@ -37,6 +37,7 @@
#include "llvm/Support/ConstantRange.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/IRBuilder.h"
#include "llvm/Support/MDBuilder.h"
#include "llvm/Support/NoFolder.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
@@ -1740,12 +1741,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
ProbTrue = ProbTrue.udiv(GCD);
ProbFalse = ProbFalse.udiv(GCD);
LLVMContext &Context = BI->getContext();
Value *Ops[3];
Ops[0] = BI->getMetadata(LLVMContext::MD_prof)->getOperand(0);
Ops[1] = ConstantInt::get(Context, ProbTrue);
Ops[2] = ConstantInt::get(Context, ProbFalse);
PBI->setMetadata(LLVMContext::MD_prof, MDNode::get(Context, Ops));
MDBuilder MDB(BI->getContext());
MDNode *N = MDB.createBranchWeights(ProbTrue.getZExtValue(),
ProbFalse.getZExtValue());
PBI->setMetadata(LLVMContext::MD_prof, N);
} else {
PBI->setMetadata(LLVMContext::MD_prof, NULL);
}