Skip to content

Commit 9ccd7c3

Browse files
aeubanksmemfrob
authored andcommitted
[NFC] Remove some unclear attribute methods
To any downstream users broken by this change, please examine your uses of these methods and see if you can use a better method. For example, getAttribute(AttributeList::FunctionIndex) => getFnAttr(), or addAttribute(AttributeList::FirstArgIndex + ArgNo) => addParamAttribute(ArgNo). 0 corresponds to ReturnIndex, ~0 corresponds to FunctionIndex. This may make future cleanups less painful. I've made the mistake of assuming that these indexes are for parameters multiple times, but actually they're based off of a weird indexing scheme AttributeList::AttrIndex where 0 is the return value and ~0 is the function. Hopefully renaming these methods will make this clearer. Ideally users should use more specific methods like AttributeList::getFnAttr(). This touches all relevant methods in AttributeList, CallBase, and Function. This hopefully will make easier a future change to cleanup AttrIndex. A previous worry about cleaning up AttrIndex was that too many downstream users would have to look through all uses of AttrIndex and relevant attribute method calls to see if anything was unintentionally hardcoded (e.g. using 0 instead of ReturnIndex). With this change hopefully downstream users will look at existing usages of these methods and clean them up. Reviewed By: rnk, MaskRay Differential Revision: https://reviews.llvm.org/D108614
1 parent c04b4ed commit 9ccd7c3

File tree

3 files changed

+0
-83
lines changed

3 files changed

+0
-83
lines changed

llvm/include/llvm/IR/Attributes.h

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -459,41 +459,24 @@ class AttributeList {
459459
/// Returns a new list because attribute lists are immutable.
460460
LLVM_NODISCARD AttributeList addAttributeAtIndex(
461461
LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const;
462-
LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index,
463-
Attribute::AttrKind Kind) const {
464-
return addAttributeAtIndex(C, Index, Kind);
465-
}
466462

467463
/// Add an attribute to the attribute set at the given index.
468464
/// Returns a new list because attribute lists are immutable.
469465
LLVM_NODISCARD AttributeList
470466
addAttributeAtIndex(LLVMContext &C, unsigned Index, StringRef Kind,
471467
StringRef Value = StringRef()) const;
472-
LLVM_NODISCARD AttributeList
473-
addAttribute(LLVMContext &C, unsigned Index, StringRef Kind,
474-
StringRef Value = StringRef()) const {
475-
return addAttributeAtIndex(C, Index, Kind, Value);
476-
}
477468

478469
/// Add an attribute to the attribute set at the given index.
479470
/// Returns a new list because attribute lists are immutable.
480471
LLVM_NODISCARD AttributeList addAttributeAtIndex(LLVMContext &C,
481472
unsigned Index,
482473
Attribute A) const;
483-
LLVM_NODISCARD AttributeList addAttribute(LLVMContext &C, unsigned Index,
484-
Attribute A) const {
485-
return addAttributeAtIndex(C, Index, A);
486-
}
487474

488475
/// Add attributes to the attribute set at the given index.
489476
/// Returns a new list because attribute lists are immutable.
490477
LLVM_NODISCARD AttributeList addAttributesAtIndex(LLVMContext &C,
491478
unsigned Index,
492479
const AttrBuilder &B) const;
493-
LLVM_NODISCARD AttributeList addAttributes(LLVMContext &C, unsigned Index,
494-
const AttrBuilder &B) const {
495-
return addAttributesAtIndex(C, Index, B);
496-
}
497480

498481
/// Add a function attribute to the list. Returns a new list because
499482
/// attribute lists are immutable.
@@ -577,10 +560,6 @@ class AttributeList {
577560
/// attribute list. Returns a new list because attribute lists are immutable.
578561
LLVM_NODISCARD AttributeList removeAttributeAtIndex(
579562
LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const;
580-
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index,
581-
Attribute::AttrKind Kind) const {
582-
return removeAttributeAtIndex(C, Index, Kind);
583-
}
584563

585564
/// Remove the specified attribute at the specified index from this
586565
/// attribute list. Returns a new list because attribute lists are immutable.
@@ -596,19 +575,11 @@ class AttributeList {
596575
/// attribute list. Returns a new list because attribute lists are immutable.
597576
LLVM_NODISCARD AttributeList removeAttributesAtIndex(
598577
LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const;
599-
LLVM_NODISCARD AttributeList removeAttributes(
600-
LLVMContext &C, unsigned Index, const AttrBuilder &AttrsToRemove) const {
601-
return removeAttributesAtIndex(C, Index, AttrsToRemove);
602-
}
603578

604579
/// Remove all attributes at the specified index from this
605580
/// attribute list. Returns a new list because attribute lists are immutable.
606581
LLVM_NODISCARD AttributeList removeAttributesAtIndex(LLVMContext &C,
607582
unsigned Index) const;
608-
LLVM_NODISCARD AttributeList removeAttributes(LLVMContext &C,
609-
unsigned Index) const {
610-
return removeAttributesAtIndex(C, Index);
611-
}
612583

613584
/// Remove the specified attribute at the function index from this
614585
/// attribute list. Returns a new list because attribute lists are immutable.
@@ -697,12 +668,6 @@ class AttributeList {
697668
return Attrs.addAttributeAtIndex(C, ArgNo,
698669
Attr.getWithNewType(C, ReplacementTy));
699670
}
700-
LLVM_NODISCARD AttributeList replaceAttributeType(LLVMContext &C,
701-
unsigned ArgNo,
702-
Attribute::AttrKind Kind,
703-
Type *ReplacementTy) const {
704-
return replaceAttributeTypeAtIndex(C, ArgNo, Kind, ReplacementTy);
705-
}
706671

707672
/// \brief Add the dereferenceable attribute to the attribute set at the given
708673
/// index. Returns a new list because attribute lists are immutable.
@@ -745,21 +710,12 @@ class AttributeList {
745710

746711
/// Return true if the attribute exists at the given index.
747712
bool hasAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const;
748-
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const {
749-
return hasAttributeAtIndex(Index, Kind);
750-
}
751713

752714
/// Return true if the attribute exists at the given index.
753715
bool hasAttributeAtIndex(unsigned Index, StringRef Kind) const;
754-
bool hasAttribute(unsigned Index, StringRef Kind) const {
755-
return hasAttributeAtIndex(Index, Kind);
756-
}
757716

758717
/// Return true if attribute exists at the given index.
759718
bool hasAttributesAtIndex(unsigned Index) const;
760-
bool hasAttributes(unsigned Index) const {
761-
return hasAttributesAtIndex(Index);
762-
}
763719

764720
/// Return true if the attribute exists for the given argument
765721
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
@@ -806,15 +762,9 @@ class AttributeList {
806762

807763
/// Return the attribute object that exists at the given index.
808764
Attribute getAttributeAtIndex(unsigned Index, Attribute::AttrKind Kind) const;
809-
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const {
810-
return getAttributeAtIndex(Index, Kind);
811-
}
812765

813766
/// Return the attribute object that exists at the given index.
814767
Attribute getAttributeAtIndex(unsigned Index, StringRef Kind) const;
815-
Attribute getAttribute(unsigned Index, StringRef Kind) const {
816-
return getAttributeAtIndex(Index, Kind);
817-
}
818768

819769
/// Return the attribute object that exists at the arg index.
820770
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {

llvm/include/llvm/IR/Function.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
331331
// TODO: remove non-AtIndex versions of these methods.
332332
/// adds the attribute to the list of attributes.
333333
void addAttributeAtIndex(unsigned i, Attribute Attr);
334-
void addAttribute(unsigned i, Attribute Attr) {
335-
addAttributeAtIndex(i, Attr);
336-
}
337334

338335
/// Add function attributes to this function.
339336
void addFnAttr(Attribute::AttrKind Kind);
@@ -361,15 +358,9 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
361358

362359
/// removes the attribute from the list of attributes.
363360
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind);
364-
void removeAttribute(unsigned i, Attribute::AttrKind Kind) {
365-
removeAttributeAtIndex(i, Kind);
366-
}
367361

368362
/// removes the attribute from the list of attributes.
369363
void removeAttributeAtIndex(unsigned i, StringRef Kind);
370-
void removeAttribute(unsigned i, StringRef Kind) {
371-
removeAttributeAtIndex(i, Kind);
372-
}
373364

374365
/// Remove function attributes from this function.
375366
void removeFnAttr(Attribute::AttrKind Kind);
@@ -411,15 +402,9 @@ class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
411402

412403
/// gets the attribute from the list of attributes.
413404
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const;
414-
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
415-
return getAttributeAtIndex(i, Kind);
416-
}
417405

418406
/// gets the attribute from the list of attributes.
419407
Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const;
420-
Attribute getAttribute(unsigned i, StringRef Kind) const {
421-
return getAttributeAtIndex(i, Kind);
422-
}
423408

424409
/// Return the attribute for the given attribute kind.
425410
Attribute getFnAttribute(Attribute::AttrKind Kind) const;

llvm/include/llvm/IR/InstrTypes.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,17 +1490,11 @@ class CallBase : public Instruction {
14901490
void addAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
14911491
Attrs = Attrs.addAttributeAtIndex(getContext(), i, Kind);
14921492
}
1493-
void addAttribute(unsigned i, Attribute::AttrKind Kind) {
1494-
addAttributeAtIndex(i, Kind);
1495-
}
14961493

14971494
/// adds the attribute to the list of attributes.
14981495
void addAttributeAtIndex(unsigned i, Attribute Attr) {
14991496
Attrs = Attrs.addAttributeAtIndex(getContext(), i, Attr);
15001497
}
1501-
void addAttribute(unsigned i, Attribute Attr) {
1502-
addAttributeAtIndex(i, Attr);
1503-
}
15041498

15051499
/// Adds the attribute to the function.
15061500
void addFnAttr(Attribute::AttrKind Kind) {
@@ -1538,17 +1532,11 @@ class CallBase : public Instruction {
15381532
void removeAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) {
15391533
Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind);
15401534
}
1541-
void removeAttribute(unsigned i, Attribute::AttrKind Kind) {
1542-
removeAttributeAtIndex(i, Kind);
1543-
}
15441535

15451536
/// removes the attribute from the list of attributes.
15461537
void removeAttributeAtIndex(unsigned i, StringRef Kind) {
15471538
Attrs = Attrs.removeAttributeAtIndex(getContext(), i, Kind);
15481539
}
1549-
void removeAttribute(unsigned i, StringRef Kind) {
1550-
removeAttributeAtIndex(i, Kind);
1551-
}
15521540

15531541
/// Removes the attributes from the function
15541542
void removeFnAttrs(const AttrBuilder &AttrsToRemove) {
@@ -1611,17 +1599,11 @@ class CallBase : public Instruction {
16111599
Attribute getAttributeAtIndex(unsigned i, Attribute::AttrKind Kind) const {
16121600
return getAttributes().getAttributeAtIndex(i, Kind);
16131601
}
1614-
Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
1615-
return getAttributeAtIndex(i, Kind);
1616-
}
16171602

16181603
/// Get the attribute of a given kind at a position.
16191604
Attribute getAttributeAtIndex(unsigned i, StringRef Kind) const {
16201605
return getAttributes().getAttributeAtIndex(i, Kind);
16211606
}
1622-
Attribute getAttribute(unsigned i, StringRef Kind) const {
1623-
return getAttributeAtIndex(i, Kind);
1624-
}
16251607

16261608
/// Get the attribute of a given kind for the function.
16271609
Attribute getFnAttr(StringRef Kind) const {

0 commit comments

Comments
 (0)