diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-09-30 15:39:48 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-09-30 15:39:48 +0000 |
commit | adb412daa41aef94a9f724dfd1ade9f579bb3a84 (patch) | |
tree | e70185344707fc03fefd43f8b39fefb4b8005d8c /unittests/IR | |
parent | 5a17a462cdba1b894cdd618798596076ed79c9ac (diff) | |
download | external_llvm-adb412daa41aef94a9f724dfd1ade9f579bb3a84.zip external_llvm-adb412daa41aef94a9f724dfd1ade9f579bb3a84.tar.gz external_llvm-adb412daa41aef94a9f724dfd1ade9f579bb3a84.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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191673 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/IR')
-rw-r--r-- | unittests/IR/IRBuilderTest.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/unittests/IR/IRBuilderTest.cpp b/unittests/IR/IRBuilderTest.cpp index fecc4a4..d79ff62 100644 --- a/unittests/IR/IRBuilderTest.cpp +++ b/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()); +} + + } |