diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-06-26 11:36:22 -0400 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2020-07-09 09:37:41 -0400 |
commit | 6f5d9136b27eefc981333d8c23ea9c0a38033d7b (patch) | |
tree | ad0938f22174bbd6c86feb0f61eab9d4a375b3a8 /llvm/lib/IR/Function.cpp | |
parent | d12d0b73f1c9c3a711c5cc15266a2b493cd712e9 (diff) | |
download | llvm-6f5d9136b27eefc981333d8c23ea9c0a38033d7b.zip llvm-6f5d9136b27eefc981333d8c23ea9c0a38033d7b.tar.gz llvm-6f5d9136b27eefc981333d8c23ea9c0a38033d7b.tar.bz2 |
OpaquePtr: Don't check pointee type for byval/preallocated
Since none of these users really care about the actual type, hide the
type under a new size-getting attribute to go along with
hasPassPointeeByValueAttr. This will work better for the future byref
attribute, which may end up only tracking the byte size and not the IR
type.
We currently have 3 parameter attributes that should carry the type
(technically inalloca does not yet). The APIs are somewhat awkward
since preallocated/inalloca piggyback on byval in some places, but in
others are treated as distinct attributes. Since these are all
mutually exclusive, we should probably just merge all the attribute
infrastructure treating these as totally distinct attributes.
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index 78092cd..0ec0cce 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -128,6 +128,27 @@ bool Argument::hasPassPointeeByValueAttr() const { Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated); } +uint64_t Argument::getPassPointeeByValueCopySize(const DataLayout &DL) const { + AttributeSet ParamAttrs + = getParent()->getAttributes().getParamAttributes(getArgNo()); + + // FIXME: All the type carrying attributes are mutually exclusive, so there + // should be a single query to get the stored type that handles any of them. + if (Type *ByValTy = ParamAttrs.getByValType()) + return DL.getTypeAllocSize(ByValTy); + if (Type *PreAllocTy = ParamAttrs.getPreallocatedType()) + return DL.getTypeAllocSize(PreAllocTy); + + // FIXME: inalloca always depends on pointee element type. It's also possible + // for byval to miss it. + if (ParamAttrs.hasAttribute(Attribute::InAlloca) || + ParamAttrs.hasAttribute(Attribute::ByVal) || + ParamAttrs.hasAttribute(Attribute::Preallocated)) + return DL.getTypeAllocSize(cast<PointerType>(getType())->getElementType()); + + return 0; +} + unsigned Argument::getParamAlignment() const { assert(getType()->isPointerTy() && "Only pointers have alignments"); return getParent()->getParamAlignment(getArgNo()); |