Skip to content

Commit

Permalink
[NFC] Remove AttributeList::hasParamAttribute()
Browse files Browse the repository at this point in the history
It's the same as AttributeList::hasParamAttr().
  • Loading branch information
aeubanks committed Aug 13, 2021
1 parent 5eeaac2 commit a0c42ca
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 59 deletions.
3 changes: 0 additions & 3 deletions llvm/include/llvm/IR/Attributes.h
Expand Up @@ -660,9 +660,6 @@ class AttributeList {
/// may be faster.
bool hasFnAttribute(StringRef Kind) const;

/// Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;

/// Return true if the specified attribute is set for at least one
/// parameter or for the return value. If Index is not nullptr, the index
/// of a parameter with the specified attribute is provided.
Expand Down
6 changes: 3 additions & 3 deletions llvm/include/llvm/IR/Function.h
Expand Up @@ -447,7 +447,7 @@ class Function : public GlobalObject, public ilist_node<Function> {

/// check if an attributes is in the list of attributes.
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const {
return getAttributes().hasParamAttribute(ArgNo, Kind);
return getAttributes().hasParamAttr(ArgNo, Kind);
}

/// gets the specified attribute from the list of attributes.
Expand Down Expand Up @@ -692,8 +692,8 @@ class Function : public GlobalObject, public ilist_node<Function> {
/// Determine if the function returns a structure through first
/// or second pointer argument.
bool hasStructRetAttr() const {
return AttributeSets.hasParamAttribute(0, Attribute::StructRet) ||
AttributeSets.hasParamAttribute(1, Attribute::StructRet);
return AttributeSets.hasParamAttr(0, Attribute::StructRet) ||
AttributeSets.hasParamAttr(1, Attribute::StructRet);
}

/// Determine if the parameter or return value is marked with NoAlias
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/Lint.cpp
Expand Up @@ -235,7 +235,7 @@ void Lint::visitCallBase(CallBase &I) {
for (auto BI = I.arg_begin(); BI != AE; ++BI, ++ArgNo) {
// Skip ByVal arguments since they will be memcpy'd to the callee's
// stack so we're not really passing the pointer anyway.
if (PAL.hasParamAttribute(ArgNo, Attribute::ByVal))
if (PAL.hasParamAttr(ArgNo, Attribute::ByVal))
continue;
// If both arguments are readonly, they have no dependence.
if (Formal->onlyReadsMemory() && I.onlyReadsMemory(ArgNo))
Expand Down Expand Up @@ -268,7 +268,7 @@ void Lint::visitCallBase(CallBase &I) {
for (Value *Arg : I.args()) {
// Skip ByVal arguments since they will be memcpy'd to the callee's
// stack anyway.
if (PAL.hasParamAttribute(ArgNo++, Attribute::ByVal))
if (PAL.hasParamAttr(ArgNo++, Attribute::ByVal))
continue;
Value *Obj = findValue(Arg, /*OffsetOk=*/true);
Assert(!isa<AllocaInst>(Obj),
Expand Down
5 changes: 0 additions & 5 deletions llvm/lib/IR/Attributes.cpp
Expand Up @@ -1405,11 +1405,6 @@ bool AttributeList::hasFnAttribute(StringRef Kind) const {
return hasAttribute(AttributeList::FunctionIndex, Kind);
}

bool AttributeList::hasParamAttribute(unsigned ArgNo,
Attribute::AttrKind Kind) const {
return hasAttribute(ArgNo + FirstArgIndex, Kind);
}

bool AttributeList::hasAttrSomewhere(Attribute::AttrKind Attr,
unsigned *Index) const {
return pImpl && pImpl->hasAttrSomewhere(Attr, Index);
Expand Down
20 changes: 10 additions & 10 deletions llvm/lib/IR/Function.cpp
Expand Up @@ -140,20 +140,20 @@ bool Argument::hasPreallocatedAttr() const {
bool Argument::hasPassPointeeByValueCopyAttr() const {
if (!getType()->isPointerTy()) return false;
AttributeList Attrs = getParent()->getAttributes();
return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated);
return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) ||
Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) ||
Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated);
}

bool Argument::hasPointeeInMemoryValueAttr() const {
if (!getType()->isPointerTy())
return false;
AttributeList Attrs = getParent()->getAttributes();
return Attrs.hasParamAttribute(getArgNo(), Attribute::ByVal) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::StructRet) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::InAlloca) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::Preallocated) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::ByRef);
return Attrs.hasParamAttr(getArgNo(), Attribute::ByVal) ||
Attrs.hasParamAttr(getArgNo(), Attribute::StructRet) ||
Attrs.hasParamAttr(getArgNo(), Attribute::InAlloca) ||
Attrs.hasParamAttr(getArgNo(), Attribute::Preallocated) ||
Attrs.hasParamAttr(getArgNo(), Attribute::ByRef);
}

/// For a byval, sret, inalloca, or preallocated parameter, get the in-memory
Expand Down Expand Up @@ -278,8 +278,8 @@ bool Argument::hasSExtAttr() const {

bool Argument::onlyReadsMemory() const {
AttributeList Attrs = getParent()->getAttributes();
return Attrs.hasParamAttribute(getArgNo(), Attribute::ReadOnly) ||
Attrs.hasParamAttribute(getArgNo(), Attribute::ReadNone);
return Attrs.hasParamAttr(getArgNo(), Attribute::ReadOnly) ||
Attrs.hasParamAttr(getArgNo(), Attribute::ReadNone);
}

void Argument::addAttrs(AttrBuilder &B) {
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/Instructions.cpp
Expand Up @@ -343,10 +343,10 @@ Value *CallBase::getReturnedArgOperand() const {
bool CallBase::paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
assert(ArgNo < getNumArgOperands() && "Param index out of bounds!");

if (Attrs.hasParamAttribute(ArgNo, Kind))
if (Attrs.hasParamAttr(ArgNo, Kind))
return true;
if (const Function *F = getCalledFunction())
return F->getAttributes().hasParamAttribute(ArgNo, Kind);
return F->getAttributes().hasParamAttr(ArgNo, Kind);
return false;
}

Expand Down
24 changes: 12 additions & 12 deletions llvm/lib/IR/Verifier.cpp
Expand Up @@ -2348,7 +2348,7 @@ void Verifier::visitFunction(const Function &F) {
case CallingConv::C:
break;
case CallingConv::X86_INTR: {
Assert(F.arg_empty() || Attrs.hasParamAttribute(0, Attribute::ByVal),
Assert(F.arg_empty() || Attrs.hasParamAttr(0, Attribute::ByVal),
"Calling convention parameter requires byval", &F);
break;
}
Expand All @@ -2368,14 +2368,14 @@ void Verifier::visitFunction(const Function &F) {
const unsigned StackAS = DL.getAllocaAddrSpace();
unsigned i = 0;
for (const Argument &Arg : F.args()) {
Assert(!Attrs.hasParamAttribute(i, Attribute::ByVal),
Assert(!Attrs.hasParamAttr(i, Attribute::ByVal),
"Calling convention disallows byval", &F);
Assert(!Attrs.hasParamAttribute(i, Attribute::Preallocated),
Assert(!Attrs.hasParamAttr(i, Attribute::Preallocated),
"Calling convention disallows preallocated", &F);
Assert(!Attrs.hasParamAttribute(i, Attribute::InAlloca),
Assert(!Attrs.hasParamAttr(i, Attribute::InAlloca),
"Calling convention disallows inalloca", &F);

if (Attrs.hasParamAttribute(i, Attribute::ByRef)) {
if (Attrs.hasParamAttr(i, Attribute::ByRef)) {
// FIXME: Should also disallow LDS and GDS, but we don't have the enum
// value here.
Assert(Arg.getType()->getPointerAddressSpace() != StackAS,
Expand Down Expand Up @@ -2416,7 +2416,7 @@ void Verifier::visitFunction(const Function &F) {
}

// Check that swifterror argument is only used by loads and stores.
if (Attrs.hasParamAttribute(i, Attribute::SwiftError)) {
if (Attrs.hasParamAttr(i, Attribute::SwiftError)) {
verifySwiftErrorValue(&Arg);
}
++i;
Expand Down Expand Up @@ -3118,7 +3118,7 @@ void Verifier::visitCallBase(CallBase &Call) {
Call);
}

if (Attrs.hasParamAttribute(i, Attribute::ImmArg)) {
if (Attrs.hasParamAttr(i, Attribute::ImmArg)) {
// Don't allow immarg on call sites, unless the underlying declaration
// also has the matching immarg.
Assert(Callee && Callee->hasParamAttribute(i, Attribute::ImmArg),
Expand Down Expand Up @@ -3150,9 +3150,9 @@ void Verifier::visitCallBase(CallBase &Call) {
bool SawReturned = false;

for (unsigned Idx = 0; Idx < FTy->getNumParams(); ++Idx) {
if (Attrs.hasParamAttribute(Idx, Attribute::Nest))
if (Attrs.hasParamAttr(Idx, Attribute::Nest))
SawNest = true;
if (Attrs.hasParamAttribute(Idx, Attribute::Returned))
if (Attrs.hasParamAttr(Idx, Attribute::Returned))
SawReturned = true;
}

Expand Down Expand Up @@ -3329,9 +3329,9 @@ static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) {
}

// `align` is ABI-affecting only in combination with `byval` or `byref`.
if (Attrs.hasParamAttribute(I, Attribute::Alignment) &&
(Attrs.hasParamAttribute(I, Attribute::ByVal) ||
Attrs.hasParamAttribute(I, Attribute::ByRef)))
if (Attrs.hasParamAttr(I, Attribute::Alignment) &&
(Attrs.hasParamAttr(I, Attribute::ByVal) ||
Attrs.hasParamAttr(I, Attribute::ByRef)))
Copy.addAlignmentAttr(Attrs.getParamAlignment(I));
return Copy;
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
Expand Up @@ -1825,8 +1825,8 @@ bool isArgPassedInSGPR(const Argument *A) {
case CallingConv::AMDGPU_Gfx:
// For non-compute shaders, SGPR inputs are marked with either inreg or byval.
// Everything else is in VGPRs.
return F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::InReg) ||
F->getAttributes().hasParamAttribute(A->getArgNo(), Attribute::ByVal);
return F->getAttributes().hasParamAttr(A->getArgNo(), Attribute::InReg) ||
F->getAttributes().hasParamAttr(A->getArgNo(), Attribute::ByVal);
default:
// TODO: Should calls support inreg for SGPR inputs?
return false;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
Expand Up @@ -1457,7 +1457,7 @@ void NVPTXAsmPrinter::emitFunctionParamList(const Function *F, raw_ostream &O) {
}
}

if (!PAL.hasParamAttribute(paramIndex, Attribute::ByVal)) {
if (!PAL.hasParamAttr(paramIndex, Attribute::ByVal)) {
if (Ty->isAggregateType() || Ty->isVectorTy() || Ty->isIntegerTy(128)) {
// Just print .param .align <a> .b8 .param[size];
// <a> = PAL.getparamalignment
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
Expand Up @@ -2530,7 +2530,7 @@ SDValue NVPTXTargetLowering::LowerFormalArguments(
// to newly created nodes. The SDNodes for params have to
// appear in the same order as their order of appearance
// in the original function. "idx+1" holds that order.
if (!PAL.hasParamAttribute(i, Attribute::ByVal)) {
if (!PAL.hasParamAttr(i, Attribute::ByVal)) {
bool aggregateIsPacked = false;
if (StructType *STy = dyn_cast<StructType>(Ty))
aggregateIsPacked = STy->isPacked();
Expand Down
24 changes: 12 additions & 12 deletions llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
Expand Up @@ -648,11 +648,11 @@ bool WebAssemblyFastISel::fastLowerArguments() {
unsigned I = 0;
for (auto const &Arg : F->args()) {
const AttributeList &Attrs = F->getAttributes();
if (Attrs.hasParamAttribute(I, Attribute::ByVal) ||
Attrs.hasParamAttribute(I, Attribute::SwiftSelf) ||
Attrs.hasParamAttribute(I, Attribute::SwiftError) ||
Attrs.hasParamAttribute(I, Attribute::InAlloca) ||
Attrs.hasParamAttribute(I, Attribute::Nest))
if (Attrs.hasParamAttr(I, Attribute::ByVal) ||
Attrs.hasParamAttr(I, Attribute::SwiftSelf) ||
Attrs.hasParamAttr(I, Attribute::SwiftError) ||
Attrs.hasParamAttr(I, Attribute::InAlloca) ||
Attrs.hasParamAttr(I, Attribute::Nest))
return false;

Type *ArgTy = Arg.getType();
Expand Down Expand Up @@ -832,18 +832,18 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) {
return false;

const AttributeList &Attrs = Call->getAttributes();
if (Attrs.hasParamAttribute(I, Attribute::ByVal) ||
Attrs.hasParamAttribute(I, Attribute::SwiftSelf) ||
Attrs.hasParamAttribute(I, Attribute::SwiftError) ||
Attrs.hasParamAttribute(I, Attribute::InAlloca) ||
Attrs.hasParamAttribute(I, Attribute::Nest))
if (Attrs.hasParamAttr(I, Attribute::ByVal) ||
Attrs.hasParamAttr(I, Attribute::SwiftSelf) ||
Attrs.hasParamAttr(I, Attribute::SwiftError) ||
Attrs.hasParamAttr(I, Attribute::InAlloca) ||
Attrs.hasParamAttr(I, Attribute::Nest))
return false;

unsigned Reg;

if (Attrs.hasParamAttribute(I, Attribute::SExt))
if (Attrs.hasParamAttr(I, Attribute::SExt))
Reg = getRegForSignedValue(V);
else if (Attrs.hasParamAttribute(I, Attribute::ZExt))
else if (Attrs.hasParamAttr(I, Attribute::ZExt))
Reg = getRegForUnsignedValue(V);
else
Reg = getRegForValue(V);
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/Coroutines/CoroSplit.cpp
Expand Up @@ -1262,7 +1262,7 @@ static bool shouldBeMustTail(const CallInst &CI, const Function &F) {
Attribute::SwiftSelf, Attribute::SwiftError};
AttributeList Attrs = CI.getAttributes();
for (auto AK : ABIAttrs)
if (Attrs.hasParamAttribute(0, AK))
if (Attrs.hasParamAttr(0, AK))
return false;

return true;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
Expand Up @@ -763,7 +763,7 @@ bool DeadArgumentEliminationPass::RemoveDeadStuffFromFunction(Function *F) {
Params.push_back(I->getType());
ArgAlive[ArgI] = true;
ArgAttrVec.push_back(PAL.getParamAttributes(ArgI));
HasLiveReturnedArg |= PAL.hasParamAttribute(ArgI, Attribute::Returned);
HasLiveReturnedArg |= PAL.hasParamAttr(ArgI, Attribute::Returned);
} else {
++NumArgumentsEliminated;
LLVM_DEBUG(dbgs() << "DeadArgumentEliminationPass - Removing argument "
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
Expand Up @@ -2836,12 +2836,12 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
if (Call.isInAllocaArgument(i))
return false; // Cannot transform to and from inalloca.

if (CallerPAL.hasParamAttribute(i, Attribute::SwiftError))
if (CallerPAL.hasParamAttr(i, Attribute::SwiftError))
return false;

// If the parameter is passed as a byval argument, then we have to have a
// sized type and the sized type has to have the same size as the old type.
if (ParamTy != ActTy && CallerPAL.hasParamAttribute(i, Attribute::ByVal)) {
if (ParamTy != ActTy && CallerPAL.hasParamAttr(i, Attribute::ByVal)) {
PointerType *ParamPTy = dyn_cast<PointerType>(ParamTy);
if (!ParamPTy || !ParamPTy->getElementType()->isSized())
return false;
Expand Down Expand Up @@ -2911,7 +2911,7 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) {
Args.push_back(NewArg);

// Add any parameter attributes.
if (CallerPAL.hasParamAttribute(i, Attribute::ByVal)) {
if (CallerPAL.hasParamAttr(i, Attribute::ByVal)) {
AttrBuilder AB(CallerPAL.getParamAttributes(i));
AB.addByValAttr(NewArg->getType()->getPointerElementType());
ArgAttrs.push_back(AttributeSet::get(Ctx, AB));
Expand Down
2 changes: 1 addition & 1 deletion llvm/unittests/IR/AttributesTest.cpp
Expand Up @@ -158,7 +158,7 @@ TEST(Attributes, AddMatchingAlignAttr) {
AL = AL.addAttributes(C, AttributeList::FirstArgIndex, B);
EXPECT_EQ(Align(8), AL.getParamAlignment(0));
EXPECT_EQ(Align(32), AL.getParamAlignment(1));
EXPECT_TRUE(AL.hasParamAttribute(0, Attribute::NonNull));
EXPECT_TRUE(AL.hasParamAttr(0, Attribute::NonNull));
}

TEST(Attributes, EmptyGet) {
Expand Down

0 comments on commit a0c42ca

Please sign in to comment.