From 145449b1e420787bb99721a429341fa6be3adfb6 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 3 Jul 2022 16:10:23 +0200 Subject: Vendor import of llvm-project main llvmorg-15-init-15358-g53dc0f107877. --- llvm/lib/IR/IRBuilder.cpp | 178 ++++++++++++++++++++++++++++------------------ 1 file changed, 107 insertions(+), 71 deletions(-) (limited to 'llvm/lib/IR/IRBuilder.cpp') diff --git a/llvm/lib/IR/IRBuilder.cpp b/llvm/lib/IR/IRBuilder.cpp index 4e8f1b506811..d0c622fe2389 100644 --- a/llvm/lib/IR/IRBuilder.cpp +++ b/llvm/lib/IR/IRBuilder.cpp @@ -16,6 +16,7 @@ #include "llvm/ADT/None.h" #include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" @@ -68,6 +69,21 @@ Value *IRBuilderBase::getCastedInt8PtrValue(Value *Ptr) { return CreateBitCast(Ptr, getInt8PtrTy(PT->getAddressSpace())); } +DebugLoc IRBuilderBase::getCurrentDebugLocation() const { + for (auto &KV : MetadataToCopy) + if (KV.first == LLVMContext::MD_dbg) + return {cast(KV.second)}; + + return {}; +} +void IRBuilderBase::SetInstDebugLocation(Instruction *I) const { + for (const auto &KV : MetadataToCopy) + if (KV.first == LLVMContext::MD_dbg) { + I->setDebugLoc(DebugLoc(KV.second)); + return; + } +} + static CallInst *createCallHelper(Function *Callee, ArrayRef Ops, IRBuilderBase *Builder, const Twine &Name = "", @@ -133,7 +149,36 @@ CallInst *IRBuilderBase::CreateMemSet(Value *Ptr, Value *Val, Value *Size, CallInst *CI = createCallHelper(TheFn, Ops, this); if (Align) - cast(CI)->setDestAlignment(Align->value()); + cast(CI)->setDestAlignment(*Align); + + // Set the TBAA info if present. + if (TBAATag) + CI->setMetadata(LLVMContext::MD_tbaa, TBAATag); + + if (ScopeTag) + CI->setMetadata(LLVMContext::MD_alias_scope, ScopeTag); + + if (NoAliasTag) + CI->setMetadata(LLVMContext::MD_noalias, NoAliasTag); + + return CI; +} + +CallInst *IRBuilderBase::CreateMemSetInline(Value *Dst, MaybeAlign DstAlign, + Value *Val, Value *Size, + bool IsVolatile, MDNode *TBAATag, + MDNode *ScopeTag, + MDNode *NoAliasTag) { + Dst = getCastedInt8PtrValue(Dst); + Value *Ops[] = {Dst, Val, Size, getInt1(IsVolatile)}; + Type *Tys[] = {Dst->getType(), Size->getType()}; + Module *M = BB->getParent()->getParent(); + Function *TheFn = Intrinsic::getDeclaration(M, Intrinsic::memset_inline, Tys); + + CallInst *CI = createCallHelper(TheFn, Ops, this); + + if (DstAlign) + cast(CI)->setDestAlignment(*DstAlign); // Set the TBAA info if present. if (TBAATag) @@ -672,34 +717,29 @@ getStatepointBundles(Optional> TransitionArgs, template static CallInst *CreateGCStatepointCallCommon( IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, - Value *ActualCallee, uint32_t Flags, ArrayRef CallArgs, - Optional> TransitionArgs, - Optional> DeoptArgs, ArrayRef GCArgs, - const Twine &Name) { - // Extract out the type of the callee. - auto *FuncPtrType = cast(ActualCallee->getType()); - assert(isa(FuncPtrType->getPointerElementType()) && - "actual callee must be a callable value"); - + FunctionCallee ActualCallee, uint32_t Flags, ArrayRef CallArgs, + Optional> TransitionArgs, Optional> DeoptArgs, + ArrayRef GCArgs, const Twine &Name) { Module *M = Builder->GetInsertBlock()->getParent()->getParent(); // Fill in the one generic type'd argument (the function is also vararg) - Type *ArgTypes[] = { FuncPtrType }; Function *FnStatepoint = - Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, - ArgTypes); - - std::vector Args = - getStatepointArgs(*Builder, ID, NumPatchBytes, ActualCallee, Flags, - CallArgs); - - return Builder->CreateCall(FnStatepoint, Args, - getStatepointBundles(TransitionArgs, DeoptArgs, - GCArgs), - Name); + Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, + {ActualCallee.getCallee()->getType()}); + + std::vector Args = getStatepointArgs( + *Builder, ID, NumPatchBytes, ActualCallee.getCallee(), Flags, CallArgs); + + CallInst *CI = Builder->CreateCall( + FnStatepoint, Args, + getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name); + CI->addParamAttr(2, + Attribute::get(Builder->getContext(), Attribute::ElementType, + ActualCallee.getFunctionType())); + return CI; } CallInst *IRBuilderBase::CreateGCStatepointCall( - uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, + uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef CallArgs, Optional> DeoptArgs, ArrayRef GCArgs, const Twine &Name) { return CreateGCStatepointCallCommon( @@ -708,17 +748,17 @@ CallInst *IRBuilderBase::CreateGCStatepointCall( } CallInst *IRBuilderBase::CreateGCStatepointCall( - uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags, - ArrayRef CallArgs, Optional> TransitionArgs, - Optional> DeoptArgs, ArrayRef GCArgs, - const Twine &Name) { + uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, + uint32_t Flags, ArrayRef CallArgs, + Optional> TransitionArgs, Optional> DeoptArgs, + ArrayRef GCArgs, const Twine &Name) { return CreateGCStatepointCallCommon( this, ID, NumPatchBytes, ActualCallee, Flags, CallArgs, TransitionArgs, DeoptArgs, GCArgs, Name); } CallInst *IRBuilderBase::CreateGCStatepointCall( - uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, + uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee, ArrayRef CallArgs, Optional> DeoptArgs, ArrayRef GCArgs, const Twine &Name) { return CreateGCStatepointCallCommon( @@ -729,32 +769,31 @@ CallInst *IRBuilderBase::CreateGCStatepointCall( template static InvokeInst *CreateGCStatepointInvokeCommon( IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes, - Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, - uint32_t Flags, ArrayRef InvokeArgs, + FunctionCallee ActualInvokee, BasicBlock *NormalDest, + BasicBlock *UnwindDest, uint32_t Flags, ArrayRef InvokeArgs, Optional> TransitionArgs, Optional> DeoptArgs, ArrayRef GCArgs, const Twine &Name) { - // Extract out the type of the callee. - auto *FuncPtrType = cast(ActualInvokee->getType()); - assert(isa(FuncPtrType->getPointerElementType()) && - "actual callee must be a callable value"); - Module *M = Builder->GetInsertBlock()->getParent()->getParent(); // Fill in the one generic type'd argument (the function is also vararg) - Function *FnStatepoint = Intrinsic::getDeclaration( - M, Intrinsic::experimental_gc_statepoint, {FuncPtrType}); + Function *FnStatepoint = + Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_statepoint, + {ActualInvokee.getCallee()->getType()}); std::vector Args = - getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee, Flags, - InvokeArgs); + getStatepointArgs(*Builder, ID, NumPatchBytes, ActualInvokee.getCallee(), + Flags, InvokeArgs); - return Builder->CreateInvoke(FnStatepoint, NormalDest, UnwindDest, Args, - getStatepointBundles(TransitionArgs, DeoptArgs, - GCArgs), - Name); + InvokeInst *II = Builder->CreateInvoke( + FnStatepoint, NormalDest, UnwindDest, Args, + getStatepointBundles(TransitionArgs, DeoptArgs, GCArgs), Name); + II->addParamAttr(2, + Attribute::get(Builder->getContext(), Attribute::ElementType, + ActualInvokee.getFunctionType())); + return II; } InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( - uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, + uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef InvokeArgs, Optional> DeoptArgs, ArrayRef GCArgs, const Twine &Name) { @@ -765,19 +804,21 @@ InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( } InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( - uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, + uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags, ArrayRef InvokeArgs, Optional> TransitionArgs, - Optional> DeoptArgs, ArrayRef GCArgs, const Twine &Name) { + Optional> DeoptArgs, ArrayRef GCArgs, + const Twine &Name) { return CreateGCStatepointInvokeCommon( this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, Flags, InvokeArgs, TransitionArgs, DeoptArgs, GCArgs, Name); } InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( - uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee, + uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest, ArrayRef InvokeArgs, - Optional> DeoptArgs, ArrayRef GCArgs, const Twine &Name) { + Optional> DeoptArgs, ArrayRef GCArgs, + const Twine &Name) { return CreateGCStatepointInvokeCommon( this, ID, NumPatchBytes, ActualInvokee, NormalDest, UnwindDest, uint32_t(StatepointFlags::None), InvokeArgs, None, DeoptArgs, GCArgs, @@ -785,31 +826,26 @@ InvokeInst *IRBuilderBase::CreateGCStatepointInvoke( } CallInst *IRBuilderBase::CreateGCResult(Instruction *Statepoint, - Type *ResultType, - const Twine &Name) { - Intrinsic::ID ID = Intrinsic::experimental_gc_result; - Module *M = BB->getParent()->getParent(); - Type *Types[] = {ResultType}; - Function *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); + Type *ResultType, const Twine &Name) { + Intrinsic::ID ID = Intrinsic::experimental_gc_result; + Module *M = BB->getParent()->getParent(); + Type *Types[] = {ResultType}; + Function *FnGCResult = Intrinsic::getDeclaration(M, ID, Types); - Value *Args[] = {Statepoint}; - return createCallHelper(FnGCResult, Args, this, Name); + Value *Args[] = {Statepoint}; + return createCallHelper(FnGCResult, Args, this, Name); } CallInst *IRBuilderBase::CreateGCRelocate(Instruction *Statepoint, - int BaseOffset, - int DerivedOffset, - Type *ResultType, - const Twine &Name) { - Module *M = BB->getParent()->getParent(); - Type *Types[] = {ResultType}; - Function *FnGCRelocate = - Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); + int BaseOffset, int DerivedOffset, + Type *ResultType, const Twine &Name) { + Module *M = BB->getParent()->getParent(); + Type *Types[] = {ResultType}; + Function *FnGCRelocate = + Intrinsic::getDeclaration(M, Intrinsic::experimental_gc_relocate, Types); - Value *Args[] = {Statepoint, - getInt32(BaseOffset), - getInt32(DerivedOffset)}; - return createCallHelper(FnGCRelocate, Args, this, Name); + Value *Args[] = {Statepoint, getInt32(BaseOffset), getInt32(DerivedOffset)}; + return createCallHelper(FnGCRelocate, Args, this, Name); } CallInst *IRBuilderBase::CreateGCGetPointerBase(Value *DerivedPtr, @@ -1262,8 +1298,8 @@ CallInst *IRBuilderBase::CreateAlignmentAssumption(const DataLayout &DL, return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue); } -IRBuilderDefaultInserter::~IRBuilderDefaultInserter() {} -IRBuilderCallbackInserter::~IRBuilderCallbackInserter() {} -IRBuilderFolder::~IRBuilderFolder() {} +IRBuilderDefaultInserter::~IRBuilderDefaultInserter() = default; +IRBuilderCallbackInserter::~IRBuilderCallbackInserter() = default; +IRBuilderFolder::~IRBuilderFolder() = default; void ConstantFolder::anchor() {} void NoFolder::anchor() {} -- cgit v1.2.3