[NFC] Cleanup callers of AttributeList::hasAttributes()

AttributeList::hasAttributes() is confusing, use clearer methods like
hasFnAttrs().
This commit is contained in:
Arthur Eubanks 2021-08-13 12:07:05 -07:00
parent d7593ebaee
commit 8e9ffa1dc6
4 changed files with 17 additions and 16 deletions

View File

@ -3613,7 +3613,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
assert(F->getName() == MangledName && "name was uniqued!");
if (D)
SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
if (ExtraAttrs.hasAttributes(llvm::AttributeList::FunctionIndex)) {
if (ExtraAttrs.hasFnAttrs()) {
llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex);
F->addAttributes(llvm::AttributeList::FunctionIndex, B);
}

View File

@ -657,17 +657,18 @@ public:
return hasAttribute(ReturnIndex, Kind);
}
/// Return true if attributes exists for the return value.
/// Return true if attributes exist for the return value.
bool hasRetAttrs() const { return hasAttributes(ReturnIndex); }
/// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
/// may be faster.
/// Return true if the attribute exists for the function.
bool hasFnAttr(Attribute::AttrKind Kind) const;
/// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
/// may be faster.
/// Return true if the attribute exists for the function.
bool hasFnAttr(StringRef Kind) const;
/// Return true the attributes exist for the function.
bool hasFnAttrs() const { return hasAttributes(FunctionIndex); }
/// 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.

View File

@ -3682,7 +3682,7 @@ void AssemblyWriter::printFunction(const Function *F) {
Out << "; Materializable\n";
const AttributeList &Attrs = F->getAttributes();
if (Attrs.hasAttributes(AttributeList::FunctionIndex)) {
if (Attrs.hasFnAttrs()) {
AttributeSet AS = Attrs.getFnAttrs();
std::string AttrStr;
@ -3720,7 +3720,7 @@ void AssemblyWriter::printFunction(const Function *F) {
}
FunctionType *FT = F->getFunctionType();
if (Attrs.hasAttributes(AttributeList::ReturnIndex))
if (Attrs.hasRetAttrs())
Out << Attrs.getAsString(AttributeList::ReturnIndex) << ' ';
TypePrinter.print(F->getReturnType(), Out);
Out << ' ';
@ -3769,7 +3769,7 @@ void AssemblyWriter::printFunction(const Function *F) {
if (F->getAddressSpace() != 0 || !Mod ||
Mod->getDataLayout().getProgramAddressSpace() != 0)
Out << " addrspace(" << F->getAddressSpace() << ")";
if (Attrs.hasAttributes(AttributeList::FunctionIndex))
if (Attrs.hasFnAttrs())
Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttrs());
if (F->hasSection()) {
Out << " section \"";
@ -4126,7 +4126,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Type *RetTy = FTy->getReturnType();
const AttributeList &PAL = CI->getAttributes();
if (PAL.hasAttributes(AttributeList::ReturnIndex))
if (PAL.hasRetAttrs())
Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
// Only print addrspace(N) if necessary:
@ -4155,7 +4155,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
Out << ", ...";
Out << ')';
if (PAL.hasAttributes(AttributeList::FunctionIndex))
if (PAL.hasFnAttrs())
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs());
writeOperandBundles(CI);
@ -4171,7 +4171,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
PrintCallingConv(II->getCallingConv(), Out);
}
if (PAL.hasAttributes(AttributeList::ReturnIndex))
if (PAL.hasRetAttrs())
Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
// Only print addrspace(N) if necessary:
@ -4193,7 +4193,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
}
Out << ')';
if (PAL.hasAttributes(AttributeList::FunctionIndex))
if (PAL.hasFnAttrs())
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs());
writeOperandBundles(II);
@ -4214,7 +4214,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
PrintCallingConv(CBI->getCallingConv(), Out);
}
if (PAL.hasAttributes(AttributeList::ReturnIndex))
if (PAL.hasRetAttrs())
Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
// If possible, print out the short form of the callbr instruction. We can
@ -4233,7 +4233,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
}
Out << ')';
if (PAL.hasAttributes(AttributeList::FunctionIndex))
if (PAL.hasFnAttrs())
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs());
writeOperandBundles(CBI);

View File

@ -1928,7 +1928,7 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
}
}
if (!Attrs.hasAttributes(AttributeList::FunctionIndex))
if (!Attrs.hasFnAttrs())
return;
verifyAttributeTypes(Attrs.getFnAttrs(), V);