From adb412daa41aef94a9f724dfd1ade9f579bb3a84 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 30 Sep 2013 15:39:48 +0000 Subject: 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 --- unittests/IR/IRBuilderTest.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'unittests') 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(F)); + EXPECT_EQ(F, Builder.GetInsertPoint()); + } + + EXPECT_EQ(BB->end(), Builder.GetInsertPoint()); + EXPECT_EQ(BB, Builder.GetInsertBlock()); +} + + } -- cgit v1.1