From: Tobias Grosser Date: Mon, 8 Aug 2016 15:25:46 +0000 (+0000) Subject: [IslNodeBuilder] Directly use the insert location of our Builder X-Git-Tag: llvmorg-4.0.0-rc1~13056 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=000db70754841d2e86b7a72029f21e3e2fbdc981;p=platform%2Fupstream%2Fllvm.git [IslNodeBuilder] Directly use the insert location of our Builder ... instead of adding instructions at the end of the basic block the builder is currently at. This makes it easier to reason about where IR is generated, as with the IRBuilder there is just a single location that specificies where IR is generated. llvm-svn: 278013 --- diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp index e46304f..b8a83ab 100644 --- a/polly/lib/CodeGen/IslNodeBuilder.cpp +++ b/polly/lib/CodeGen/IslNodeBuilder.cpp @@ -1222,7 +1222,20 @@ void IslNodeBuilder::addParameters(__isl_take isl_set *Context) { } Value *IslNodeBuilder::generateSCEV(const SCEV *Expr) { - Instruction *InsertLocation = &*--(Builder.GetInsertBlock()->end()); + /// We pass the insert location of our Builder, as Polly ensures during IR + /// generation that there is always a valid CFG into which instructions are + /// inserted. As a result, the insertpoint is known to be always followed by a + /// terminator instruction. This means the insert point may be specified by a + /// terminator instruction, but it can never point to an ->end() iterator + /// which does not have a corresponding instruction. Hence, dereferencing + /// the insertpoint to obtain an instruction is known to be save. + /// + /// We also do not need to update the Builder here, as new instructions are + /// always inserted _before_ the given InsertLocation. As a result, the + /// insert location remains valid. + assert(Builder.GetInsertBlock()->end() != Builder.getInsertPoint() && + "Insert location points after last valid instruction"); + Instruction *InsertLocation = &*Builder.GetInsertPoint(); return expandCodeFor(S, SE, DL, "polly", Expr, Expr->getType(), InsertLocation, &ValueMap); }