aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/IRBuilder.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2022-07-03 14:10:23 +0000
committerDimitry Andric <dim@FreeBSD.org>2022-07-03 14:10:23 +0000
commit145449b1e420787bb99721a429341fa6be3adfb6 (patch)
tree1d56ae694a6de602e348dd80165cf881a36600ed /llvm/lib/IR/IRBuilder.cpp
parentecbca9f5fb7d7613d2b94982c4825eb0d33d6842 (diff)
downloadsrc-145449b1e420787bb99721a429341fa6be3adfb6.tar.gz
src-145449b1e420787bb99721a429341fa6be3adfb6.zip
Vendor import of llvm-project main llvmorg-15-init-15358-g53dc0f107877.vendor/llvm-project/llvmorg-15-init-15358-g53dc0f107877
Diffstat (limited to 'llvm/lib/IR/IRBuilder.cpp')
-rw-r--r--llvm/lib/IR/IRBuilder.cpp178
1 files changed, 107 insertions, 71 deletions
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<DILocation>(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<Value *> 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<MemSetInst>(CI)->setDestAlignment(Align->value());
+ cast<MemSetInst>(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<MemSetInlineInst>(CI)->setDestAlignment(*DstAlign);
// Set the TBAA info if present.
if (TBAATag)
@@ -672,34 +717,29 @@ getStatepointBundles(Optional<ArrayRef<T1>> TransitionArgs,
template <typename T0, typename T1, typename T2, typename T3>
static CallInst *CreateGCStatepointCallCommon(
IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
- Value *ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
- Optional<ArrayRef<T1>> TransitionArgs,
- Optional<ArrayRef<T2>> DeoptArgs, ArrayRef<T3> GCArgs,
- const Twine &Name) {
- // Extract out the type of the callee.
- auto *FuncPtrType = cast<PointerType>(ActualCallee->getType());
- assert(isa<FunctionType>(FuncPtrType->getPointerElementType()) &&
- "actual callee must be a callable value");
-
+ FunctionCallee ActualCallee, uint32_t Flags, ArrayRef<T0> CallArgs,
+ Optional<ArrayRef<T1>> TransitionArgs, Optional<ArrayRef<T2>> DeoptArgs,
+ ArrayRef<T3> 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<Value *> 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<Value *> 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<Value *> CallArgs, Optional<ArrayRef<Value *>> DeoptArgs,
ArrayRef<Value *> GCArgs, const Twine &Name) {
return CreateGCStatepointCallCommon<Value *, Value *, Value *, Value *>(
@@ -708,17 +748,17 @@ CallInst *IRBuilderBase::CreateGCStatepointCall(
}
CallInst *IRBuilderBase::CreateGCStatepointCall(
- uint64_t ID, uint32_t NumPatchBytes, Value *ActualCallee, uint32_t Flags,
- ArrayRef<Value *> CallArgs, Optional<ArrayRef<Use>> TransitionArgs,
- Optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
- const Twine &Name) {
+ uint64_t ID, uint32_t NumPatchBytes, FunctionCallee ActualCallee,
+ uint32_t Flags, ArrayRef<Value *> CallArgs,
+ Optional<ArrayRef<Use>> TransitionArgs, Optional<ArrayRef<Use>> DeoptArgs,
+ ArrayRef<Value *> GCArgs, const Twine &Name) {
return CreateGCStatepointCallCommon<Value *, Use, Use, Value *>(
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<Use> CallArgs, Optional<ArrayRef<Value *>> DeoptArgs,
ArrayRef<Value *> GCArgs, const Twine &Name) {
return CreateGCStatepointCallCommon<Use, Value *, Value *, Value *>(
@@ -729,32 +769,31 @@ CallInst *IRBuilderBase::CreateGCStatepointCall(
template <typename T0, typename T1, typename T2, typename T3>
static InvokeInst *CreateGCStatepointInvokeCommon(
IRBuilderBase *Builder, uint64_t ID, uint32_t NumPatchBytes,
- Value *ActualInvokee, BasicBlock *NormalDest, BasicBlock *UnwindDest,
- uint32_t Flags, ArrayRef<T0> InvokeArgs,
+ FunctionCallee ActualInvokee, BasicBlock *NormalDest,
+ BasicBlock *UnwindDest, uint32_t Flags, ArrayRef<T0> InvokeArgs,
Optional<ArrayRef<T1>> TransitionArgs, Optional<ArrayRef<T2>> DeoptArgs,
ArrayRef<T3> GCArgs, const Twine &Name) {
- // Extract out the type of the callee.
- auto *FuncPtrType = cast<PointerType>(ActualInvokee->getType());
- assert(isa<FunctionType>(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<Value *> 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<Value *> InvokeArgs, Optional<ArrayRef<Value *>> DeoptArgs,
ArrayRef<Value *> 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<Value *> InvokeArgs, Optional<ArrayRef<Use>> TransitionArgs,
- Optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
+ Optional<ArrayRef<Use>> DeoptArgs, ArrayRef<Value *> GCArgs,
+ const Twine &Name) {
return CreateGCStatepointInvokeCommon<Value *, Use, Use, Value *>(
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<Use> InvokeArgs,
- Optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs, const Twine &Name) {
+ Optional<ArrayRef<Value *>> DeoptArgs, ArrayRef<Value *> GCArgs,
+ const Twine &Name) {
return CreateGCStatepointInvokeCommon<Use, Value *, Value *, Value *>(
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() {}