From 299493720382ab26e0842eca233fd240dce3b3d6 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 16 Jul 2012 07:45:06 +0000 Subject: Add support for attaching branch weight metadata directly from the IRBuilder. Added a basic unit test for this with CreateCondBr. I didn't go all the way and test the switch side as the boilerplate for setting up the switch IRBuilder unit tests is a lot more. Fortunately, the two share all the interesting code paths. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160251 91177308-0d34-0410-b5e6-96231b3b80d8 --- unittests/VMCore/IRBuilderTest.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'unittests') diff --git a/unittests/VMCore/IRBuilderTest.cpp b/unittests/VMCore/IRBuilderTest.cpp index 3eb5926d54..b6a3795fd0 100644 --- a/unittests/VMCore/IRBuilderTest.cpp +++ b/unittests/VMCore/IRBuilderTest.cpp @@ -12,6 +12,7 @@ #include "llvm/IRBuilder.h" #include "llvm/IntrinsicInst.h" #include "llvm/LLVMContext.h" +#include "llvm/MDBuilder.h" #include "llvm/Module.h" #include "llvm/ADT/OwningPtr.h" @@ -83,6 +84,16 @@ TEST_F(IRBuilderTest, CreateCondBr) { EXPECT_EQ(2u, TI->getNumSuccessors()); EXPECT_EQ(TBB, TI->getSuccessor(0)); EXPECT_EQ(FBB, TI->getSuccessor(1)); + + BI->eraseFromParent(); + MDNode *Weights = MDBuilder(getGlobalContext()).createBranchWeights(42, 13); + BI = Builder.CreateCondBr(Builder.getTrue(), TBB, FBB, Weights); + TI = BB->getTerminator(); + EXPECT_EQ(BI, TI); + EXPECT_EQ(2u, TI->getNumSuccessors()); + EXPECT_EQ(TBB, TI->getSuccessor(0)); + EXPECT_EQ(FBB, TI->getSuccessor(1)); + EXPECT_EQ(Weights, TI->getMetadata(LLVMContext::MD_prof)); } } -- cgit v1.2.3-18-g5258