diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -408,6 +408,7 @@ /// /// \returns The insertion position *after* the sections. InsertPointTy CreateSections(const LocationDescription &Loc, + InsertPointTy AllocaIP, ArrayRef SectionCBs, PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB, bool IsCancellable, diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h --- a/llvm/include/llvm/IR/IRBuilder.h +++ b/llvm/include/llvm/IR/IRBuilder.h @@ -62,10 +62,10 @@ public: virtual ~IRBuilderDefaultInserter(); - virtual void InsertHelper(Instruction *I, const Twine &Name, - BasicBlock *BB, + virtual void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const { - if (BB) BB->getInstList().insert(InsertPt, I); + if (BB) + BB->getInstList().insert(InsertPt, I); I->setName(Name); } }; @@ -81,8 +81,7 @@ IRBuilderCallbackInserter(std::function Callback) : Callback(std::move(Callback)) {} - void InsertHelper(Instruction *I, const Twine &Name, - BasicBlock *BB, + void InsertHelper(Instruction *I, const Twine &Name, BasicBlock *BB, BasicBlock::iterator InsertPt) const override { IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt); Callback(I); @@ -111,8 +110,8 @@ public: IRBuilderBase(LLVMContext &context, const IRBuilderFolder &Folder, - const IRBuilderDefaultInserter &Inserter, - MDNode *FPMathTag, ArrayRef OpBundles) + const IRBuilderDefaultInserter &Inserter, MDNode *FPMathTag, + ArrayRef OpBundles) : Context(context), Folder(Folder), Inserter(Inserter), DefaultFPMathTag(FPMathTag), IsFPConstrained(false), DefaultConstrainedExcept(fp::ebStrict), @@ -122,7 +121,7 @@ } /// Insert and return the specified instruction. - template + template InstTy *Insert(InstTy *I, const Twine &Name = "") const { Inserter.InsertHelper(I, Name, BB, InsertPt); SetInstDebugLocation(I); @@ -130,9 +129,7 @@ } /// No-op overload to handle constants. - Constant *Insert(Constant *C, const Twine& = "") const { - return C; - } + Constant *Insert(Constant *C, const Twine & = "") const { return C; } Value *Insert(Value *V, const Twine &Name = "") const { if (Instruction *I = dyn_cast(V)) @@ -374,7 +371,6 @@ } }; - //===--------------------------------------------------------------------===// // Miscellaneous creation methods. //===--------------------------------------------------------------------===// @@ -393,24 +389,16 @@ Module *M = nullptr); /// Get a constant value representing either true or false. - ConstantInt *getInt1(bool V) { - return ConstantInt::get(getInt1Ty(), V); - } + ConstantInt *getInt1(bool V) { return ConstantInt::get(getInt1Ty(), V); } /// Get the constant value for i1 true. - ConstantInt *getTrue() { - return ConstantInt::getTrue(Context); - } + ConstantInt *getTrue() { return ConstantInt::getTrue(Context); } /// Get the constant value for i1 false. - ConstantInt *getFalse() { - return ConstantInt::getFalse(Context); - } + ConstantInt *getFalse() { return ConstantInt::getFalse(Context); } /// Get a constant 8-bit value. - ConstantInt *getInt8(uint8_t C) { - return ConstantInt::get(getInt8Ty(), C); - } + ConstantInt *getInt8(uint8_t C) { return ConstantInt::get(getInt8Ty(), C); } /// Get a constant 16-bit value. ConstantInt *getInt16(uint16_t C) { @@ -434,71 +422,47 @@ } /// Get a constant integer value. - ConstantInt *getInt(const APInt &AI) { - return ConstantInt::get(Context, AI); - } + ConstantInt *getInt(const APInt &AI) { return ConstantInt::get(Context, AI); } //===--------------------------------------------------------------------===// // Type creation methods //===--------------------------------------------------------------------===// /// Fetch the type representing a single bit - IntegerType *getInt1Ty() { - return Type::getInt1Ty(Context); - } + IntegerType *getInt1Ty() { return Type::getInt1Ty(Context); } /// Fetch the type representing an 8-bit integer. - IntegerType *getInt8Ty() { - return Type::getInt8Ty(Context); - } + IntegerType *getInt8Ty() { return Type::getInt8Ty(Context); } /// Fetch the type representing a 16-bit integer. - IntegerType *getInt16Ty() { - return Type::getInt16Ty(Context); - } + IntegerType *getInt16Ty() { return Type::getInt16Ty(Context); } /// Fetch the type representing a 32-bit integer. - IntegerType *getInt32Ty() { - return Type::getInt32Ty(Context); - } + IntegerType *getInt32Ty() { return Type::getInt32Ty(Context); } /// Fetch the type representing a 64-bit integer. - IntegerType *getInt64Ty() { - return Type::getInt64Ty(Context); - } + IntegerType *getInt64Ty() { return Type::getInt64Ty(Context); } /// Fetch the type representing a 128-bit integer. IntegerType *getInt128Ty() { return Type::getInt128Ty(Context); } /// Fetch the type representing an N-bit integer. - IntegerType *getIntNTy(unsigned N) { - return Type::getIntNTy(Context, N); - } + IntegerType *getIntNTy(unsigned N) { return Type::getIntNTy(Context, N); } /// Fetch the type representing a 16-bit floating point value. - Type *getHalfTy() { - return Type::getHalfTy(Context); - } + Type *getHalfTy() { return Type::getHalfTy(Context); } /// Fetch the type representing a 16-bit brain floating point value. - Type *getBFloatTy() { - return Type::getBFloatTy(Context); - } + Type *getBFloatTy() { return Type::getBFloatTy(Context); } /// Fetch the type representing a 32-bit floating point value. - Type *getFloatTy() { - return Type::getFloatTy(Context); - } + Type *getFloatTy() { return Type::getFloatTy(Context); } /// Fetch the type representing a 64-bit floating point value. - Type *getDoubleTy() { - return Type::getDoubleTy(Context); - } + Type *getDoubleTy() { return Type::getDoubleTy(Context); } /// Fetch the type representing void. - Type *getVoidTy() { - return Type::getVoidTy(Context); - } + Type *getVoidTy() { return Type::getVoidTy(Context); } /// Fetch the type representing a pointer to an 8-bit integer value. PointerType *getInt8PtrTy(unsigned AddrSpace = 0) { @@ -524,8 +488,8 @@ MaybeAlign Align, bool isVolatile = false, MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr, MDNode *NoAliasTag = nullptr) { - return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, - TBAATag, ScopeTag, NoAliasTag); + return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile, TBAATag, + ScopeTag, NoAliasTag); } CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, MaybeAlign Align, @@ -596,7 +560,8 @@ /// Create and insert an element unordered-atomic memcpy between the /// specified pointers. /// - /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively. + /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, + /// respectively. /// /// If the pointers aren't i8*, they will be converted. If a TBAA tag is /// specified, it will be added to the instruction. Likewise with alias.scope @@ -859,16 +824,13 @@ /// Create a call to the experimental.gc.result intrinsic to extract /// the result from a call wrapped in a statepoint. - CallInst *CreateGCResult(Instruction *Statepoint, - Type *ResultType, + CallInst *CreateGCResult(Instruction *Statepoint, Type *ResultType, const Twine &Name = ""); /// Create a call to the experimental.gc.relocate intrinsics to /// project the relocated value of one pointer from the statepoint. - CallInst *CreateGCRelocate(Instruction *Statepoint, - int BaseOffset, - int DerivedOffset, - Type *ResultType, + CallInst *CreateGCRelocate(Instruction *Statepoint, int BaseOffset, + int DerivedOffset, Type *ResultType, const Twine &Name = ""); /// Create a call to intrinsic \p ID with 1 operand which is mangled on its @@ -938,9 +900,7 @@ public: /// Create a 'ret void' instruction. - ReturnInst *CreateRetVoid() { - return Insert(ReturnInst::Create(Context)); - } + ReturnInst *CreateRetVoid() { return Insert(ReturnInst::Create(Context)); } /// Create a 'ret ' instruction. ReturnInst *CreateRet(Value *V) { @@ -1045,18 +1005,16 @@ ArrayRef IndirectDests, ArrayRef Args = None, const Twine &Name = "") { - return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, - Args), Name); - } - CallBrInst *CreateCallBr(FunctionType *Ty, Value *Callee, - BasicBlock *DefaultDest, - ArrayRef IndirectDests, - ArrayRef Args, - ArrayRef OpBundles, - const Twine &Name = "") { return Insert( - CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args, - OpBundles), Name); + CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, Args), Name); + } + CallBrInst * + CreateCallBr(FunctionType *Ty, Value *Callee, BasicBlock *DefaultDest, + ArrayRef IndirectDests, ArrayRef Args, + ArrayRef OpBundles, const Twine &Name = "") { + return Insert(CallBrInst::Create(Ty, Callee, DefaultDest, IndirectDests, + Args, OpBundles), + Name); } CallBrInst *CreateCallBr(FunctionCallee Callee, BasicBlock *DefaultDest, @@ -1116,11 +1074,13 @@ private: BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc, Value *LHS, Value *RHS, - const Twine &Name, - bool HasNUW, bool HasNSW) { + const Twine &Name, bool HasNUW, + bool HasNSW) { BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name); - if (HasNUW) BO->setHasNoUnsignedWrap(); - if (HasNSW) BO->setHasNoSignedWrap(); + if (HasNUW) + BO->setHasNoUnsignedWrap(); + if (HasNSW) + BO->setHasNoSignedWrap(); return BO; } @@ -1134,8 +1094,8 @@ return I; } - Value *foldConstant(Instruction::BinaryOps Opc, Value *L, - Value *R, const Twine &Name) const { + Value *foldConstant(Instruction::BinaryOps Opc, Value *L, Value *R, + const Twine &Name) const { auto *LC = dyn_cast(L); auto *RC = dyn_cast(R); return (LC && RC) ? Insert(Folder.CreateBinOp(Opc, LC, RC), Name) : nullptr; @@ -1185,8 +1145,8 @@ if (auto *LC = dyn_cast(LHS)) if (auto *RC = dyn_cast(RHS)) return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name); - return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, - HasNUW, HasNSW); + return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name, HasNUW, + HasNSW); } Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") { @@ -1202,8 +1162,8 @@ if (auto *LC = dyn_cast(LHS)) if (auto *RC = dyn_cast(RHS)) return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name); - return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, - HasNUW, HasNSW); + return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name, HasNUW, + HasNSW); } Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") { @@ -1219,8 +1179,8 @@ if (auto *LC = dyn_cast(LHS)) if (auto *RC = dyn_cast(RHS)) return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name); - return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, - HasNUW, HasNSW); + return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name, HasNUW, + HasNSW); } Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") { @@ -1260,12 +1220,14 @@ } Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Value *V = foldConstant(Instruction::URem, LHS, RHS, Name)) return V; + if (Value *V = foldConstant(Instruction::URem, LHS, RHS, Name)) + return V; return Insert(BinaryOperator::CreateURem(LHS, RHS), Name); } Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Value *V = foldConstant(Instruction::SRem, LHS, RHS, Name)) return V; + if (Value *V = foldConstant(Instruction::SRem, LHS, RHS, Name)) + return V; return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name); } @@ -1274,20 +1236,20 @@ if (auto *LC = dyn_cast(LHS)) if (auto *RC = dyn_cast(RHS)) return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name); - return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name, - HasNUW, HasNSW); + return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name, HasNUW, + HasNSW); } Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name, - HasNUW, HasNSW); + return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name, HasNUW, + HasNSW); } Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "", bool HasNUW = false, bool HasNSW = false) { - return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name, - HasNUW, HasNSW); + return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name, HasNUW, + HasNSW); } Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "", @@ -1302,12 +1264,14 @@ Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "", bool isExact = false) { - return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); + return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name, + isExact); } Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "", bool isExact = false) { - return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); + return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name, + isExact); } Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "", @@ -1322,18 +1286,20 @@ Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "", bool isExact = false) { - return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); + return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name, + isExact); } Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "", bool isExact = false) { - return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact); + return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name, + isExact); } Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") { if (auto *RC = dyn_cast(RHS)) { if (isa(RC) && cast(RC)->isMinusOne()) - return LHS; // LHS & -1 -> LHS + return LHS; // LHS & -1 -> LHS if (auto *LC = dyn_cast(LHS)) return Insert(Folder.CreateAnd(LC, RC), Name); } @@ -1348,7 +1314,7 @@ return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } - Value *CreateAnd(ArrayRef Ops) { + Value *CreateAnd(ArrayRef Ops) { assert(!Ops.empty()); Value *Accum = Ops[0]; for (unsigned i = 1; i < Ops.size(); i++) @@ -1359,7 +1325,7 @@ Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") { if (auto *RC = dyn_cast(RHS)) { if (RC->isNullValue()) - return LHS; // LHS | 0 -> LHS + return LHS; // LHS | 0 -> LHS if (auto *LC = dyn_cast(LHS)) return Insert(Folder.CreateOr(LC, RC), Name); } @@ -1374,7 +1340,7 @@ return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name); } - Value *CreateOr(ArrayRef Ops) { + Value *CreateOr(ArrayRef Ops) { assert(!Ops.empty()); Value *Accum = Ops[0]; for (unsigned i = 1; i < Ops.size(); i++) @@ -1383,7 +1349,8 @@ } Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") { - if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V; + if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) + return V; return Insert(BinaryOperator::CreateXor(LHS, RHS), Name); } @@ -1401,7 +1368,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd, L, R, nullptr, Name, FPMD); - if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF); return Insert(I, Name); } @@ -1414,7 +1382,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fadd, L, R, FMFSource, Name); - if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), nullptr, FMFSource->getFastMathFlags()); return Insert(I, Name); @@ -1426,7 +1395,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub, L, R, nullptr, Name, FPMD); - if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF); return Insert(I, Name); } @@ -1439,7 +1409,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fsub, L, R, FMFSource, Name); - if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), nullptr, FMFSource->getFastMathFlags()); return Insert(I, Name); @@ -1451,7 +1422,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul, L, R, nullptr, Name, FPMD); - if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF); return Insert(I, Name); } @@ -1464,7 +1436,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fmul, L, R, FMFSource, Name); - if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), nullptr, FMFSource->getFastMathFlags()); return Insert(I, Name); @@ -1476,7 +1449,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv, L, R, nullptr, Name, FPMD); - if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF); return Insert(I, Name); } @@ -1489,7 +1463,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_fdiv, L, R, FMFSource, Name); - if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr, FMFSource->getFastMathFlags()); return Insert(I, Name); @@ -1501,7 +1476,8 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem, L, R, nullptr, Name, FPMD); - if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMF); return Insert(I, Name); } @@ -1514,35 +1490,39 @@ return CreateConstrainedFPBinOp(Intrinsic::experimental_constrained_frem, L, R, FMFSource, Name); - if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V; + if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) + return V; Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), nullptr, FMFSource->getFastMathFlags()); return Insert(I, Name); } - Value *CreateBinOp(Instruction::BinaryOps Opc, - Value *LHS, Value *RHS, const Twine &Name = "", - MDNode *FPMathTag = nullptr) { - if (Value *V = foldConstant(Opc, LHS, RHS, Name)) return V; + Value *CreateBinOp(Instruction::BinaryOps Opc, Value *LHS, Value *RHS, + const Twine &Name = "", MDNode *FPMathTag = nullptr) { + if (Value *V = foldConstant(Opc, LHS, RHS, Name)) + return V; Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS); if (isa(BinOp)) setFPAttrs(BinOp, FPMathTag, FMF); return Insert(BinOp, Name); } - CallInst *CreateConstrainedFPBinOp( - Intrinsic::ID ID, Value *L, Value *R, Instruction *FMFSource = nullptr, - const Twine &Name = "", MDNode *FPMathTag = nullptr, - Optional Rounding = None, - Optional Except = None); + CallInst * + CreateConstrainedFPBinOp(Intrinsic::ID ID, Value *L, Value *R, + Instruction *FMFSource = nullptr, + const Twine &Name = "", MDNode *FPMathTag = nullptr, + Optional Rounding = None, + Optional Except = None); - Value *CreateNeg(Value *V, const Twine &Name = "", - bool HasNUW = false, bool HasNSW = false) { + Value *CreateNeg(Value *V, const Twine &Name = "", bool HasNUW = false, + bool HasNSW = false) { if (auto *VC = dyn_cast(V)) return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name); BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name); - if (HasNUW) BO->setHasNoUnsignedWrap(); - if (HasNSW) BO->setHasNoSignedWrap(); + if (HasNUW) + BO->setHasNoUnsignedWrap(); + if (HasNSW) + BO->setHasNoSignedWrap(); return BO; } @@ -1566,11 +1546,11 @@ /// default FMF. Value *CreateFNegFMF(Value *V, Instruction *FMFSource, const Twine &Name = "") { - if (auto *VC = dyn_cast(V)) - return Insert(Folder.CreateFNeg(VC), Name); - return Insert(setFPAttrs(UnaryOperator::CreateFNeg(V), nullptr, - FMFSource->getFastMathFlags()), - Name); + if (auto *VC = dyn_cast(V)) + return Insert(Folder.CreateFNeg(VC), Name); + return Insert(setFPAttrs(UnaryOperator::CreateFNeg(V), nullptr, + FMFSource->getFastMathFlags()), + Name); } Value *CreateNot(Value *V, const Twine &Name = "") { @@ -1579,8 +1559,7 @@ return Insert(BinaryOperator::CreateNot(V), Name); } - Value *CreateUnOp(Instruction::UnaryOps Opc, - Value *V, const Twine &Name = "", + Value *CreateUnOp(Instruction::UnaryOps Opc, Value *V, const Twine &Name = "", MDNode *FPMathTag = nullptr) { if (auto *VC = dyn_cast(V)) return Insert(Folder.CreateUnOp(Opc, VC), Name); @@ -1649,14 +1628,6 @@ return CreateAlignedStore(Val, Ptr, MaybeAlign(), isVolatile); } - Value *CreateLVal(Type *Ty, const Twine &Name = "", Value *Init = nullptr) { - Value *LVal = CreateAlloca(Ty, nullptr, Name); - if (Init) { - CreateStore(Init, LVal); - } - return LVal; - } - LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, unsigned Align, const char *Name), @@ -1665,7 +1636,7 @@ } LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name) { - return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name); + return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/ false, Name); } LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, @@ -1676,7 +1647,7 @@ } LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const Twine &Name = "") { - return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/false, Name); + return CreateAlignedLoad(Ty, Ptr, Align, /*isVolatile*/ false, Name); } LLVM_ATTRIBUTE_DEPRECATED(LoadInst *CreateAlignedLoad(Type *Ty, Value *Ptr, @@ -1767,8 +1738,8 @@ Ptr, Cmp, New, Alignment, SuccessOrdering, FailureOrdering, SSID)); } - AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, - AtomicOrdering Ordering, + AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, + Value *Val, AtomicOrdering Ordering, SyncScope::ID SSID = SyncScope::System) { const DataLayout &DL = BB->getModule()->getDataLayout(); Align Alignment(DL.getTypeStoreSize(Val->getType())); @@ -1859,10 +1830,8 @@ Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name = "") { - Value *Idxs[] = { - ConstantInt::get(Type::getInt32Ty(Context), Idx0), - ConstantInt::get(Type::getInt32Ty(Context), Idx1) - }; + Value *Idxs[] = {ConstantInt::get(Type::getInt32Ty(Context), Idx0), + ConstantInt::get(Type::getInt32Ty(Context), Idx1)}; if (auto *PC = dyn_cast(Ptr)) return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name); @@ -1872,10 +1841,8 @@ Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name = "") { - Value *Idxs[] = { - ConstantInt::get(Type::getInt32Ty(Context), Idx0), - ConstantInt::get(Type::getInt32Ty(Context), Idx1) - }; + Value *Idxs[] = {ConstantInt::get(Type::getInt32Ty(Context), Idx0), + ConstantInt::get(Type::getInt32Ty(Context), Idx1)}; if (auto *PC = dyn_cast(Ptr)) return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name); @@ -1914,10 +1881,8 @@ Value *CreateConstGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "") { - Value *Idxs[] = { - ConstantInt::get(Type::getInt64Ty(Context), Idx0), - ConstantInt::get(Type::getInt64Ty(Context), Idx1) - }; + Value *Idxs[] = {ConstantInt::get(Type::getInt64Ty(Context), Idx0), + ConstantInt::get(Type::getInt64Ty(Context), Idx1)}; if (auto *PC = dyn_cast(Ptr)) return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name); @@ -1932,10 +1897,8 @@ Value *CreateConstInBoundsGEP2_64(Type *Ty, Value *Ptr, uint64_t Idx0, uint64_t Idx1, const Twine &Name = "") { - Value *Idxs[] = { - ConstantInt::get(Type::getInt64Ty(Context), Idx0), - ConstantInt::get(Type::getInt64Ty(Context), Idx1) - }; + Value *Idxs[] = {ConstantInt::get(Type::getInt64Ty(Context), Idx0), + ConstantInt::get(Type::getInt64Ty(Context), Idx1)}; if (auto *PC = dyn_cast(Ptr)) return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name); @@ -1990,10 +1953,8 @@ /// Create a ZExt or Trunc from the integer value V to DestTy. Return /// the value untouched if the type of V is already DestTy. - Value *CreateZExtOrTrunc(Value *V, Type *DestTy, - const Twine &Name = "") { - assert(V->getType()->isIntOrIntVectorTy() && - DestTy->isIntOrIntVectorTy() && + Value *CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name = "") { + assert(V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"); Type *VTy = V->getType(); if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits()) @@ -2005,10 +1966,8 @@ /// Create a SExt or Trunc from the integer value V to DestTy. Return /// the value untouched if the type of V is already DestTy. - Value *CreateSExtOrTrunc(Value *V, Type *DestTy, - const Twine &Name = "") { - assert(V->getType()->isIntOrIntVectorTy() && - DestTy->isIntOrIntVectorTy() && + Value *CreateSExtOrTrunc(Value *V, Type *DestTy, const Twine &Name = "") { + assert(V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"); Type *VTy = V->getType(); if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits()) @@ -2032,22 +1991,21 @@ return CreateCast(Instruction::FPToSI, V, DestTy, Name); } - Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){ + Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = "") { if (IsFPConstrained) return CreateConstrainedFPCast(Intrinsic::experimental_constrained_uitofp, V, DestTy, nullptr, Name); return CreateCast(Instruction::UIToFP, V, DestTy, Name); } - Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){ + Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = "") { if (IsFPConstrained) return CreateConstrainedFPCast(Intrinsic::experimental_constrained_sitofp, V, DestTy, nullptr, Name); return CreateCast(Instruction::SIToFP, V, DestTy, Name); } - Value *CreateFPTrunc(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name = "") { if (IsFPConstrained) return CreateConstrainedFPCast( Intrinsic::experimental_constrained_fptrunc, V, DestTy, nullptr, @@ -2062,28 +2020,23 @@ return CreateCast(Instruction::FPExt, V, DestTy, Name); } - Value *CreatePtrToInt(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::PtrToInt, V, DestTy, Name); } - Value *CreateIntToPtr(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateIntToPtr(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::IntToPtr, V, DestTy, Name); } - Value *CreateBitCast(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateBitCast(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::BitCast, V, DestTy, Name); } - Value *CreateAddrSpaceCast(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name = "") { return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name); } - Value *CreateZExtOrBitCast(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateZExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; if (auto *VC = dyn_cast(V)) @@ -2091,8 +2044,7 @@ return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name); } - Value *CreateSExtOrBitCast(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateSExtOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; if (auto *VC = dyn_cast(V)) @@ -2100,8 +2052,7 @@ return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name); } - Value *CreateTruncOrBitCast(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreateTruncOrBitCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; if (auto *VC = dyn_cast(V)) @@ -2118,8 +2069,7 @@ return Insert(CastInst::Create(Op, V, DestTy), Name); } - Value *CreatePointerCast(Value *V, Type *DestTy, - const Twine &Name = "") { + Value *CreatePointerCast(Value *V, Type *DestTy, const Twine &Name = "") { if (V->getType() == DestTy) return V; if (auto *VC = dyn_cast(V)) @@ -2170,12 +2120,12 @@ return Insert(CastInst::CreateFPCast(V, DestTy), Name); } - CallInst *CreateConstrainedFPCast( - Intrinsic::ID ID, Value *V, Type *DestTy, - Instruction *FMFSource = nullptr, const Twine &Name = "", - MDNode *FPMathTag = nullptr, - Optional Rounding = None, - Optional Except = None); + CallInst * + CreateConstrainedFPCast(Intrinsic::ID ID, Value *V, Type *DestTy, + Instruction *FMFSource = nullptr, + const Twine &Name = "", MDNode *FPMathTag = nullptr, + Optional Rounding = None, + Optional Except = None); // Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a // compile time error, instead of converting the string to bool for the @@ -2334,9 +2284,10 @@ bool IsSignaling); public: - CallInst *CreateConstrainedFPCmp( - Intrinsic::ID ID, CmpInst::Predicate P, Value *L, Value *R, - const Twine &Name = "", Optional Except = None); + CallInst * + CreateConstrainedFPCmp(Intrinsic::ID ID, CmpInst::Predicate P, Value *L, + Value *R, const Twine &Name = "", + Optional Except = None); //===--------------------------------------------------------------------===// // Instruction creation methods: Other Instructions @@ -2385,10 +2336,11 @@ OpBundles, Name, FPMathTag); } - CallInst *CreateConstrainedFPCall( - Function *Callee, ArrayRef Args, const Twine &Name = "", - Optional Rounding = None, - Optional Except = None); + CallInst * + CreateConstrainedFPCall(Function *Callee, ArrayRef Args, + const Twine &Name = "", + Optional Rounding = None, + Optional Except = None); Value *CreateSelect(Value *C, Value *True, Value *False, const Twine &Name = "", Instruction *MDFrom = nullptr); @@ -2397,8 +2349,7 @@ return Insert(new VAArgInst(List, Ty), Name); } - Value *CreateExtractElement(Value *Vec, Value *Idx, - const Twine &Name = "") { + Value *CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name = "") { if (auto *VC = dyn_cast(Vec)) if (auto *IC = dyn_cast(Idx)) return Insert(Folder.CreateExtractElement(VC, IC), Name); @@ -2456,16 +2407,14 @@ return CreateShuffleVector(V, UndefValue::get(V->getType()), Mask, Name); } - Value *CreateExtractValue(Value *Agg, - ArrayRef Idxs, + Value *CreateExtractValue(Value *Agg, ArrayRef Idxs, const Twine &Name = "") { if (auto *AggC = dyn_cast(Agg)) return Insert(Folder.CreateExtractValue(AggC, Idxs), Name); return Insert(ExtractValueInst::Create(Agg, Idxs), Name); } - Value *CreateInsertValue(Value *Agg, Value *Val, - ArrayRef Idxs, + Value *CreateInsertValue(Value *Agg, Value *Val, ArrayRef Idxs, const Twine &Name = "") { if (auto *AggC = dyn_cast(Agg)) if (auto *ValC = dyn_cast(Val)) @@ -2488,14 +2437,12 @@ /// Return an i1 value testing if \p Arg is null. Value *CreateIsNull(Value *Arg, const Twine &Name = "") { - return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), - Name); + return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()), Name); } /// Return an i1 value testing if \p Arg is not null. Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") { - return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), - Name); + return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()), Name); } /// Return the i64 difference between two pointer values, dividing out @@ -2609,7 +2556,8 @@ MDNode *FPMathTag = nullptr, ArrayRef OpBundles = None) : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter, - FPMathTag, OpBundles), Folder(Folder) { + FPMathTag, OpBundles), + Folder(Folder) { SetInsertPoint(TheBB); } @@ -2622,8 +2570,8 @@ explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr, ArrayRef OpBundles = None) - : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, - FPMathTag, OpBundles) { + : IRBuilderBase(IP->getContext(), this->Folder, this->Inserter, FPMathTag, + OpBundles) { SetInsertPoint(IP); } @@ -2631,7 +2579,8 @@ MDNode *FPMathTag = nullptr, ArrayRef OpBundles = None) : IRBuilderBase(TheBB->getContext(), this->Folder, this->Inserter, - FPMathTag, OpBundles), Folder(Folder) { + FPMathTag, OpBundles), + Folder(Folder) { SetInsertPoint(TheBB, IP); } diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp --- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp +++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp @@ -782,9 +782,9 @@ // TODO: Handle privatisation callbacks OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::CreateSections( - const LocationDescription &Loc, ArrayRef SectionCBs, - PrivatizeCallbackTy PrivCB, FinalizeCallbackTy FiniCB, bool IsCancellable, - bool IsNoWait) { + const LocationDescription &Loc, InsertPointTy AllocaIP, + ArrayRef SectionCBs, PrivatizeCallbackTy PrivCB, + FinalizeCallbackTy FiniCB, bool IsCancellable, bool IsNoWait) { if (!updateToLocation(Loc)) return Loc.IP; Constant *SrcLocStr = getOrCreateSrcLocStr(Loc); @@ -794,31 +794,39 @@ BasicBlock *InsertBB = Builder.GetInsertBlock(); Function *CurFn = InsertBB->getParent(); - // allocate and initialize helper vars for for loop - Value *LB = Builder.CreateLVal(Int32, "omp.sections.lb", Builder.getInt32(0)); + InsertPointTy CurrIP = Builder.saveIP(); + Builder.restoreIP(AllocaIP); + // allocate helper vars for for loop + Value *LB = Builder.CreateAlloca(Int32, nullptr, "omp.sections.lb"); + Value *UB = Builder.CreateAlloca(Int32, nullptr, "omp.sections.ub"); + Value *ST = Builder.CreateAlloca(Int32, nullptr, "omp.sections.st"); + Value *IL = Builder.CreateAlloca(Int32, nullptr, "omp.sections.il"); + Value *IV = Builder.CreateAlloca(Int32, nullptr, "omp.sections.iv"); + + Builder.restoreIP(CurrIP); + // initialize helper vars for for loop ConstantInt *GlobalUBVal = Builder.getInt32(SectionCBs.size() - 1); - Value *UB = Builder.CreateLVal(Int32, ".omp.sections.ub", GlobalUBVal); - Value *ST = - Builder.CreateLVal(Int32, ".omp.sections.st.", Builder.getInt32(1)); - Value *IL = - Builder.CreateLVal(Int32, ".omp.sections.il.", Builder.getInt32(0)); - Value *IV = Builder.CreateLVal(Int32, ".omp.sections.iv."); + Builder.CreateStore(Builder.getInt32(0), LB); + Builder.CreateStore(GlobalUBVal, UB); + Builder.CreateStore(Builder.getInt32(1), ST); + Builder.CreateStore(Builder.getInt32(0), IL); auto CreateForLoopCB = [&]() { Instruction *LBRef = Builder.CreateLoad(LB); Builder.CreateStore(LBRef, IV); // create new basic blocks for emitting the for loop - auto *ForBodyBB = BasicBlock::Create(M.getContext(), "omp.inner.for.body"); - auto *ForExitBB = BasicBlock::Create(M.getContext(), "omp.inner.for.exit"); - auto *ForIncBB = BasicBlock::Create(M.getContext(), "omp.inner.for.inc"); - CurFn->getBasicBlockList().insertAfter(InsertBB->getIterator(), ForIncBB); - CurFn->getBasicBlockList().insertAfter(InsertBB->getIterator(), ForBodyBB); - CurFn->getBasicBlockList().insertAfter(InsertBB->getIterator(), ForExitBB); + auto *ForBodyBB = BasicBlock::Create(M.getContext(), + "omp.sections.inner.for.body", CurFn); + auto *ForExitBB = BasicBlock::Create(M.getContext(), + "omp.sections.inner.for.exit", CurFn); + auto *ForIncBB = + BasicBlock::Create(M.getContext(), "omp.sections.inner.for.inc", CurFn); // split InsertBB to create the basic block for emitting for-loop-condition auto *UI = new UnreachableInst(Builder.getContext(), InsertBB); - BasicBlock *ForCondBB = InsertBB->splitBasicBlock(UI, "omp.inner.for.cond"); + BasicBlock *ForCondBB = + InsertBB->splitBasicBlock(UI, "omp.sections.inner.for.cond"); UI->eraseFromParent(); Builder.SetInsertPoint(ForCondBB); Instruction *IVRef = Builder.CreateLoad(IV); @@ -826,43 +834,38 @@ Value *cmpRef = Builder.CreateICmpSLE(IVRef, UBRef, "cmp"); Builder.CreateCondBr(cmpRef, ForBodyBB, ForExitBB); - // callback for creating switch statement inside for body. - auto CreateSwitchCB = [&]() { - auto *SwitchExitBB = - BasicBlock::Create(M.getContext(), "omp.switch.exit"); - CurFn->getBasicBlockList().insertAfter(InsertBB->getIterator(), - SwitchExitBB); - - SwitchInst *SwitchStmt = - Builder.CreateSwitch(Builder.CreateLoad(IV), SwitchExitBB); - // each section in emitted as a switch case - // Iterate through all sections and emit a switch construct: - // switch (IV) { - // case 0: - // ; - // break; - // ... - // case - 1: - // - 1]>; - // break; - // } - // .omp.sections.exit: - unsigned CaseNumber = 0; - for (auto SectionCB : SectionCBs) { - auto *CaseBB = BasicBlock::Create(M.getContext(), ".omp.sections.case"); - CurFn->getBasicBlockList().insertAfter(InsertBB->getIterator(), CaseBB); - SwitchStmt->addCase(Builder.getInt32(CaseNumber), CaseBB); - Builder.SetInsertPoint(CaseBB); - SectionCB(InsertPointTy(), Builder.saveIP(), *SwitchExitBB); - CaseNumber++; - } - Builder.SetInsertPoint(SwitchExitBB); - }; - // for Body Builder.SetInsertPoint(ForBodyBB); - CreateSwitchCB(); + // creating switch statement inside for body. + auto *SwitchExitBB = + BasicBlock::Create(M.getContext(), "omp.switch.exit", CurFn); + SwitchInst *SwitchStmt = + Builder.CreateSwitch(Builder.CreateLoad(IV), SwitchExitBB); + // each section in emitted as a switch case + // Iterate through all sections and emit a switch construct: + // switch (IV) { + // case 0: + // ; + // break; + // ... + // case - 1: + // - 1]>; + // break; + // } + // .omp.sections.exit: + unsigned CaseNumber = 0; + for (auto SectionCB : SectionCBs) { + auto *CaseBB = + BasicBlock::Create(M.getContext(), "omp.sections.case", CurFn); + SwitchStmt->addCase(Builder.getInt32(CaseNumber), CaseBB); + Builder.SetInsertPoint(CaseBB); + SectionCB(InsertPointTy(), Builder.saveIP(), *SwitchExitBB); + CaseNumber++; + } + Builder.SetInsertPoint(SwitchExitBB); + // end switch statement inside for body Builder.CreateBr(ForIncBB); + // end for body // for inc Builder.SetInsertPoint(ForIncBB); @@ -1245,7 +1248,7 @@ llvm::Value *Args[] = {Ident, ThreadId, Pointer, Size, ThreadPrivateCache}; Function *Fn = - getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_threadprivate_cached); + getOrCreateRuntimeFunctionPtr(OMPRTL___kmpc_threadprivate_cached); return Builder.CreateCall(Fn, Args); } diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -143,8 +143,7 @@ EXPECT_EQ(CancelBBTI->getSuccessor(1)->size(), 1U); EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(), 1U); - EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getSuccessor(0), - CBB); + EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getSuccessor(0), CBB); EXPECT_EQ(cast(Cancel)->getArgOperand(1), GTID); @@ -182,7 +181,6 @@ BB = BB->getTerminator()->getSuccessor(0); EXPECT_EQ(BB->size(), 4U); - CallInst *GTID = dyn_cast(&BB->front()); EXPECT_NE(GTID, nullptr); EXPECT_EQ(GTID->getNumArgOperands(), 1U); @@ -200,12 +198,12 @@ Instruction *CancelBBTI = Cancel->getParent()->getTerminator(); EXPECT_EQ(CancelBBTI->getNumSuccessors(), 2U); EXPECT_EQ(CancelBBTI->getSuccessor(0)->size(), 1U); - EXPECT_EQ(CancelBBTI->getSuccessor(0)->getUniqueSuccessor(), NewIP.getBlock()); + EXPECT_EQ(CancelBBTI->getSuccessor(0)->getUniqueSuccessor(), + NewIP.getBlock()); EXPECT_EQ(CancelBBTI->getSuccessor(1)->size(), 1U); EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getNumSuccessors(), 1U); - EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getSuccessor(0), - CBB); + EXPECT_EQ(CancelBBTI->getSuccessor(1)->getTerminator()->getSuccessor(0), CBB); EXPECT_EQ(cast(Cancel)->getArgOperand(1), GTID); @@ -994,31 +992,33 @@ OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL}); - IntegerType* Int32 = Type::getInt32Ty(M->getContext()); - AllocaInst* MasterAddress = Builder.CreateAlloca(Int32->getPointerTo()); - AllocaInst* PrivAddress = Builder.CreateAlloca(Int32->getPointerTo()); + IntegerType *Int32 = Type::getInt32Ty(M->getContext()); + AllocaInst *MasterAddress = Builder.CreateAlloca(Int32->getPointerTo()); + AllocaInst *PrivAddress = Builder.CreateAlloca(Int32->getPointerTo()); BasicBlock *EntryBB = BB; - OMPBuilder.CreateCopyinClauseBlocks(Builder.saveIP(), MasterAddress, PrivAddress, Int32, /*BranchtoEnd*/true); + OMPBuilder.CreateCopyinClauseBlocks(Builder.saveIP(), MasterAddress, + PrivAddress, Int32, /*BranchtoEnd*/ true); - BranchInst* EntryBr = dyn_cast_or_null(EntryBB->getTerminator()); + BranchInst *EntryBr = dyn_cast_or_null(EntryBB->getTerminator()); EXPECT_NE(EntryBr, nullptr); EXPECT_TRUE(EntryBr->isConditional()); - BasicBlock* NotMasterBB = EntryBr->getSuccessor(0); - BasicBlock* CopyinEnd = EntryBr->getSuccessor(1); - CmpInst* CMP = dyn_cast_or_null(EntryBr->getCondition()); + BasicBlock *NotMasterBB = EntryBr->getSuccessor(0); + BasicBlock *CopyinEnd = EntryBr->getSuccessor(1); + CmpInst *CMP = dyn_cast_or_null(EntryBr->getCondition()); EXPECT_NE(CMP, nullptr); EXPECT_NE(NotMasterBB, nullptr); EXPECT_NE(CopyinEnd, nullptr); - BranchInst* NotMasterBr = dyn_cast_or_null(NotMasterBB->getTerminator()); + BranchInst *NotMasterBr = + dyn_cast_or_null(NotMasterBB->getTerminator()); EXPECT_NE(NotMasterBr, nullptr); EXPECT_FALSE(NotMasterBr->isConditional()); - EXPECT_EQ(CopyinEnd,NotMasterBr->getSuccessor(0)); + EXPECT_EQ(CopyinEnd, NotMasterBr->getSuccessor(0)); } TEST_F(OpenMPIRBuilderTest, SingleDirective) { @@ -1105,7 +1105,7 @@ using InsertPointTy = OpenMPIRBuilder::InsertPointTy; using BodyGenCallbackTy = llvm::function_ref; + llvm::BasicBlock & ContinuationBB)>; OpenMPIRBuilder OMPBuilder(*M); OMPBuilder.initialize(); F->setName("func"); @@ -1140,8 +1140,11 @@ SectionCBVector.push_back(SectionCB); ArrayRef SectionCBs = makeArrayRef(SectionCBVector); - Builder.restoreIP( - OMPBuilder.CreateSections(Loc, SectionCBs, PrivCB, FiniCB, false, false)); + IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(), + F->getEntryBlock().getFirstInsertionPt()); + + Builder.restoreIP(OMPBuilder.CreateSections(Loc, AllocaIP, SectionCBs, PrivCB, + FiniCB, false, false)); Builder.CreateRetVoid(); // Required at the end of the function EXPECT_NE(PrivAI, nullptr); @@ -1152,7 +1155,7 @@ EXPECT_EQ(OutlinedFn->getBasicBlockList().size(), 8U); ASSERT_EQ(NumBodiesGenerated, 2U); - ASSERT_EQ(NumFiniCBCalls, 0U); + ASSERT_EQ(NumFiniCBCalls, 1U); } } // namespace