Skip to content

Commit

Permalink
IR: make getParamByValType Just Work. NFC.
Browse files Browse the repository at this point in the history
Most parts of LLVM don't care whether the byval type is derived from an
explicit Attribute or from the parameter's pointee type, so it makes
sense for the main access function to just return the right value.

The very few users who do care (only BitcodeReader so far) can find out
how it's specified by accessing the Attribute directly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362642 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
TNorthover committed Jun 5, 2019
1 parent bd31482 commit ee9bd50
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
2 changes: 2 additions & 0 deletions include/llvm/IR/Argument.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class Argument final : public Value {
/// Check if an argument has a given attribute.
bool hasAttribute(Attribute::AttrKind Kind) const;

Attribute getAttribute(Attribute::AttrKind Kind) const;

/// Method for support type inquiry through isa, cast, and dyn_cast.
static bool classof(const Value *V) {
return V->getValueID() == ArgumentVal;
Expand Down
10 changes: 8 additions & 2 deletions include/llvm/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ class Function : public GlobalObject, public ilist_node<Function> {
return getAttributes().hasParamAttribute(ArgNo, Kind);
}

/// gets the specified attribute from the list of attributes.
Attribute getParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
return getAttributes().getParamAttr(ArgNo, Kind);
}

/// gets the attribute from the list of attributes.
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
return AttributeSets.getAttribute(i, Kind);
Expand Down Expand Up @@ -431,9 +436,10 @@ class Function : public GlobalObject, public ilist_node<Function> {
return AttributeSets.getParamAlignment(ArgNo);
}

/// Extract the byval type for a parameter (nullptr=unknown).
/// Extract the byval type for a parameter.
Type *getParamByValType(unsigned ArgNo) const {
return AttributeSets.getParamByValType(ArgNo);
Type *Ty = AttributeSets.getParamByValType(ArgNo);
return Ty ? Ty : (arg_begin() + ArgNo)->getType()->getPointerElementType();
}

/// Extract the number of dereferenceable bytes for a call or
Expand Down
5 changes: 3 additions & 2 deletions include/llvm/IR/InstrTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1560,9 +1560,10 @@ class CallBase : public Instruction {
return Attrs.getParamAlignment(ArgNo);
}

/// Extract the byval type for a call or parameter (nullptr=unknown).
/// Extract the byval type for a call or parameter.
Type *getParamByValType(unsigned ArgNo) const {
return Attrs.getParamByValType(ArgNo);
Type *Ty = Attrs.getParamByValType(ArgNo);
return Ty ? Ty : getArgOperand(ArgNo)->getType()->getPointerElementType();
}

/// Extract the number of dereferenceable bytes for a call or
Expand Down
3 changes: 2 additions & 1 deletion lib/Bitcode/Reader/BitcodeReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3049,7 +3049,8 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) {
// pointee type. There should be no opaque pointers where the byval type is
// implicit.
for (auto &Arg : Func->args()) {
if (Arg.hasByValAttr() && !Arg.getParamByValType()) {
if (Arg.hasByValAttr() &&
!Arg.getAttribute(Attribute::ByVal).getValueAsType()) {
Arg.removeAttr(Attribute::ByVal);
Arg.addAttr(Attribute::getWithByValType(
Context, Arg.getType()->getPointerElementType()));
Expand Down
2 changes: 1 addition & 1 deletion lib/Bitcode/Writer/ValueEnumerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -951,7 +951,7 @@ void ValueEnumerator::incorporateFunction(const Function &F) {
// Adding function arguments to the value table.
for (const auto &I : F.args()) {
EnumerateValue(&I);
if (I.hasAttribute(Attribute::ByVal) && I.getParamByValType())
if (I.hasAttribute(Attribute::ByVal))
EnumerateType(I.getParamByValType());
}
FirstFuncConstantID = Values.size();
Expand Down
3 changes: 1 addition & 2 deletions lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9584,8 +9584,7 @@ void SelectionDAGISel::LowerArguments(const Function &F) {
// For ByVal, size and alignment should be passed from FE. BE will
// guess if this info is not there but there are cases it cannot get
// right.
unsigned FrameSize = DL.getTypeAllocSize(
Arg.getParamByValType() ? Arg.getParamByValType() : ElementTy);
unsigned FrameSize = DL.getTypeAllocSize(Arg.getParamByValType());
Flags.setByValSize(FrameSize);

unsigned FrameAlign;
Expand Down
4 changes: 3 additions & 1 deletion lib/CodeGen/SelectionDAG/TargetLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ void TargetLoweringBase::ArgListEntry::setAttributes(const CallBase *Call,
IsSwiftSelf = Call->paramHasAttr(ArgIdx, Attribute::SwiftSelf);
IsSwiftError = Call->paramHasAttr(ArgIdx, Attribute::SwiftError);
Alignment = Call->getParamAlignment(ArgIdx);
ByValType = Call->getParamByValType(ArgIdx);
ByValType = nullptr;
if (Call->paramHasAttr(ArgIdx, Attribute::ByVal))
ByValType = Call->getParamByValType(ArgIdx);
}

/// Generate a libcall taking the given operands as arguments and returning a
Expand Down
4 changes: 4 additions & 0 deletions lib/IR/Function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ bool Argument::hasAttribute(Attribute::AttrKind Kind) const {
return getParent()->hasParamAttribute(getArgNo(), Kind);
}

Attribute Argument::getAttribute(Attribute::AttrKind Kind) const {
return getParent()->getParamAttribute(getArgNo(), Kind);
}

//===----------------------------------------------------------------------===//
// Helper Methods in Function
//===----------------------------------------------------------------------===//
Expand Down

0 comments on commit ee9bd50

Please sign in to comment.