aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/IR/IRBuilderTest.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2013-09-30 15:39:48 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2013-09-30 15:39:48 +0000
commitd36f1abefddd6568513a302fb7c9ec27165bad13 (patch)
tree49f8d7ec63a7f3832c1fcf8f19fcbf1c6ca7fcea /llvm/unittests/IR/IRBuilderTest.cpp
parent1dc83cb6f7b0b3228795e8df2eef7f4539d5bbcd (diff)
downloadllvm-d36f1abefddd6568513a302fb7c9ec27165bad13.zip
llvm-d36f1abefddd6568513a302fb7c9ec27165bad13.tar.gz
llvm-d36f1abefddd6568513a302fb7c9ec27165bad13.tar.bz2
IRBuilder: Add RAII objects to reset insertion points or fast math flags.
Inspired by the object from the SLPVectorizer. This found a minor bug in the debug loc restoration in the vectorizer where the location of a following instruction was attached instead of the location from the original instruction. llvm-svn: 191673
Diffstat (limited to 'llvm/unittests/IR/IRBuilderTest.cpp')
-rw-r--r--llvm/unittests/IR/IRBuilderTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp
index fecc4a4..d79ff62 100644
--- a/llvm/unittests/IR/IRBuilderTest.cpp
+++ b/llvm/unittests/IR/IRBuilderTest.cpp
@@ -182,4 +182,40 @@ TEST_F(IRBuilderTest, FastMathFlags) {
}
+TEST_F(IRBuilderTest, RAIIHelpersTest) {
+ IRBuilder<> Builder(BB);
+ EXPECT_FALSE(Builder.getFastMathFlags().allowReciprocal());
+ MDBuilder MDB(M->getContext());
+
+ MDNode *FPMathA = MDB.createFPMath(0.01);
+ MDNode *FPMathB = MDB.createFPMath(0.1);
+
+ Builder.SetDefaultFPMathTag(FPMathA);
+
+ {
+ IRBuilder<>::FastMathFlagGuard Guard(Builder);
+ FastMathFlags FMF;
+ FMF.setAllowReciprocal();
+ Builder.SetFastMathFlags(FMF);
+ Builder.SetDefaultFPMathTag(FPMathB);
+ EXPECT_TRUE(Builder.getFastMathFlags().allowReciprocal());
+ EXPECT_EQ(FPMathB, Builder.getDefaultFPMathTag());
+ }
+
+ EXPECT_FALSE(Builder.getFastMathFlags().allowReciprocal());
+ EXPECT_EQ(FPMathA, Builder.getDefaultFPMathTag());
+
+ Value *F = Builder.CreateLoad(GV);
+
+ {
+ IRBuilder<>::InsertPointGuard Guard(Builder);
+ Builder.SetInsertPoint(cast<Instruction>(F));
+ EXPECT_EQ(F, Builder.GetInsertPoint());
+ }
+
+ EXPECT_EQ(BB->end(), Builder.GetInsertPoint());
+ EXPECT_EQ(BB, Builder.GetInsertBlock());
+}
+
+
}