Skip to content

Commit 8e9ffa1

Browse files
committed
[NFC] Cleanup callers of AttributeList::hasAttributes()
AttributeList::hasAttributes() is confusing, use clearer methods like hasFnAttrs().
1 parent d7593eb commit 8e9ffa1

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3613,7 +3613,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
36133613
assert(F->getName() == MangledName && "name was uniqued!");
36143614
if (D)
36153615
SetFunctionAttributes(GD, F, IsIncompleteFunction, IsThunk);
3616-
if (ExtraAttrs.hasAttributes(llvm::AttributeList::FunctionIndex)) {
3616+
if (ExtraAttrs.hasFnAttrs()) {
36173617
llvm::AttrBuilder B(ExtraAttrs, llvm::AttributeList::FunctionIndex);
36183618
F->addAttributes(llvm::AttributeList::FunctionIndex, B);
36193619
}

llvm/include/llvm/IR/Attributes.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -657,17 +657,18 @@ class AttributeList {
657657
return hasAttribute(ReturnIndex, Kind);
658658
}
659659

660-
/// Return true if attributes exists for the return value.
660+
/// Return true if attributes exist for the return value.
661661
bool hasRetAttrs() const { return hasAttributes(ReturnIndex); }
662662

663-
/// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
664-
/// may be faster.
663+
/// Return true if the attribute exists for the function.
665664
bool hasFnAttr(Attribute::AttrKind Kind) const;
666665

667-
/// Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
668-
/// may be faster.
666+
/// Return true if the attribute exists for the function.
669667
bool hasFnAttr(StringRef Kind) const;
670668

669+
/// Return true the attributes exist for the function.
670+
bool hasFnAttrs() const { return hasAttributes(FunctionIndex); }
671+
671672
/// Return true if the specified attribute is set for at least one
672673
/// parameter or for the return value. If Index is not nullptr, the index
673674
/// of a parameter with the specified attribute is provided.

llvm/lib/IR/AsmWriter.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,7 @@ void AssemblyWriter::printFunction(const Function *F) {
36823682
Out << "; Materializable\n";
36833683

36843684
const AttributeList &Attrs = F->getAttributes();
3685-
if (Attrs.hasAttributes(AttributeList::FunctionIndex)) {
3685+
if (Attrs.hasFnAttrs()) {
36863686
AttributeSet AS = Attrs.getFnAttrs();
36873687
std::string AttrStr;
36883688

@@ -3720,7 +3720,7 @@ void AssemblyWriter::printFunction(const Function *F) {
37203720
}
37213721

37223722
FunctionType *FT = F->getFunctionType();
3723-
if (Attrs.hasAttributes(AttributeList::ReturnIndex))
3723+
if (Attrs.hasRetAttrs())
37243724
Out << Attrs.getAsString(AttributeList::ReturnIndex) << ' ';
37253725
TypePrinter.print(F->getReturnType(), Out);
37263726
Out << ' ';
@@ -3769,7 +3769,7 @@ void AssemblyWriter::printFunction(const Function *F) {
37693769
if (F->getAddressSpace() != 0 || !Mod ||
37703770
Mod->getDataLayout().getProgramAddressSpace() != 0)
37713771
Out << " addrspace(" << F->getAddressSpace() << ")";
3772-
if (Attrs.hasAttributes(AttributeList::FunctionIndex))
3772+
if (Attrs.hasFnAttrs())
37733773
Out << " #" << Machine.getAttributeGroupSlot(Attrs.getFnAttrs());
37743774
if (F->hasSection()) {
37753775
Out << " section \"";
@@ -4126,7 +4126,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
41264126
Type *RetTy = FTy->getReturnType();
41274127
const AttributeList &PAL = CI->getAttributes();
41284128

4129-
if (PAL.hasAttributes(AttributeList::ReturnIndex))
4129+
if (PAL.hasRetAttrs())
41304130
Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
41314131

41324132
// Only print addrspace(N) if necessary:
@@ -4155,7 +4155,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
41554155
Out << ", ...";
41564156

41574157
Out << ')';
4158-
if (PAL.hasAttributes(AttributeList::FunctionIndex))
4158+
if (PAL.hasFnAttrs())
41594159
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs());
41604160

41614161
writeOperandBundles(CI);
@@ -4171,7 +4171,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
41714171
PrintCallingConv(II->getCallingConv(), Out);
41724172
}
41734173

4174-
if (PAL.hasAttributes(AttributeList::ReturnIndex))
4174+
if (PAL.hasRetAttrs())
41754175
Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
41764176

41774177
// Only print addrspace(N) if necessary:
@@ -4193,7 +4193,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
41934193
}
41944194

41954195
Out << ')';
4196-
if (PAL.hasAttributes(AttributeList::FunctionIndex))
4196+
if (PAL.hasFnAttrs())
41974197
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs());
41984198

41994199
writeOperandBundles(II);
@@ -4214,7 +4214,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
42144214
PrintCallingConv(CBI->getCallingConv(), Out);
42154215
}
42164216

4217-
if (PAL.hasAttributes(AttributeList::ReturnIndex))
4217+
if (PAL.hasRetAttrs())
42184218
Out << ' ' << PAL.getAsString(AttributeList::ReturnIndex);
42194219

42204220
// If possible, print out the short form of the callbr instruction. We can
@@ -4233,7 +4233,7 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
42334233
}
42344234

42354235
Out << ')';
4236-
if (PAL.hasAttributes(AttributeList::FunctionIndex))
4236+
if (PAL.hasFnAttrs())
42374237
Out << " #" << Machine.getAttributeGroupSlot(PAL.getFnAttrs());
42384238

42394239
writeOperandBundles(CBI);

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
19281928
}
19291929
}
19301930

1931-
if (!Attrs.hasAttributes(AttributeList::FunctionIndex))
1931+
if (!Attrs.hasFnAttrs())
19321932
return;
19331933

19341934
verifyAttributeTypes(Attrs.getFnAttrs(), V);

0 commit comments

Comments
 (0)