Skip to content

Commit 3932360

Browse files
authored
[LLVM][TableGen] Rename ListInit::getValues() to getElements() (llvm#140289)
Rename `ListInit::getValues()` to `getElements()` to better match with other `ListInit` members like `getElement`. Keep `getValues()` for existing downstream code but mark it deprecated.
1 parent 0f38543 commit 3932360

17 files changed

+60
-56
lines changed

clang/utils/TableGen/ClangOptionDocEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo,
367367
R->getValueAsListOfDefs("HelpTextsForVariants")) {
368368
// This is a list of visibilities.
369369
ArrayRef<const Init *> Visibilities =
370-
VisibilityHelp->getValueAsListInit("Visibilities")->getValues();
370+
VisibilityHelp->getValueAsListInit("Visibilities")->getElements();
371371

372372
// See if any of the program's visibilities are in the list.
373373
for (StringRef DocInfoMask :

clang/utils/TableGen/NeonEmitter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class Intrinsic {
486486
return Idx;
487487
}
488488

489-
bool hasBody() const { return Body && !Body->getValues().empty(); }
489+
bool hasBody() const { return Body && !Body->empty(); }
490490

491491
void setNeededEarly() { NeededEarly = true; }
492492

@@ -1436,14 +1436,14 @@ void Intrinsic::emitBodyAsBuiltinCall() {
14361436
void Intrinsic::emitBody(StringRef CallPrefix) {
14371437
std::vector<std::string> Lines;
14381438

1439-
if (!Body || Body->getValues().empty()) {
1439+
if (!Body || Body->empty()) {
14401440
// Nothing specific to output - must output a builtin.
14411441
emitBodyAsBuiltinCall();
14421442
return;
14431443
}
14441444

14451445
// We have a list of "things to output". The last should be returned.
1446-
for (auto *I : Body->getValues()) {
1446+
for (auto *I : Body->getElements()) {
14471447
if (const auto *SI = dyn_cast<StringInit>(I)) {
14481448
Lines.push_back(replaceParamsIn(SI->getAsString()));
14491449
} else if (const auto *DI = dyn_cast<DagInit>(I)) {

llvm/include/llvm/TableGen/Record.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ class ListInit final : public TypedInit,
747747
public FoldingSetNode,
748748
private TrailingObjects<ListInit, const Init *> {
749749
friend TrailingObjects;
750-
unsigned NumValues;
750+
unsigned NumElements;
751751

752752
public:
753753
using const_iterator = const Init *const *;
@@ -769,11 +769,14 @@ class ListInit final : public TypedInit,
769769

770770
void Profile(FoldingSetNodeID &ID) const;
771771

772-
ArrayRef<const Init *> getValues() const {
773-
return ArrayRef(getTrailingObjects(), NumValues);
772+
ArrayRef<const Init *> getElements() const {
773+
return ArrayRef(getTrailingObjects(), NumElements);
774774
}
775775

776-
const Init *getElement(unsigned Idx) const { return getValues()[Idx]; }
776+
LLVM_DEPRECATED("Use getElements instead", "getElements")
777+
ArrayRef<const Init *> getValues() const { return getElements(); }
778+
779+
const Init *getElement(unsigned Idx) const { return getElements()[Idx]; }
777780

778781
const RecTy *getElementType() const {
779782
return cast<ListRecTy>(getType())->getElementType();
@@ -794,11 +797,11 @@ class ListInit final : public TypedInit,
794797
bool isConcrete() const override;
795798
std::string getAsString() const override;
796799

797-
const_iterator begin() const { return getValues().begin(); }
798-
const_iterator end() const { return getValues().end(); }
800+
const_iterator begin() const { return getElements().begin(); }
801+
const_iterator end() const { return getElements().end(); }
799802

800-
size_t size () const { return NumValues; }
801-
bool empty() const { return NumValues == 0; }
803+
size_t size() const { return NumElements; }
804+
bool empty() const { return NumElements == 0; }
802805

803806
const Init *getBit(unsigned Bit) const override {
804807
llvm_unreachable("Illegal bit reference off list");

llvm/lib/TableGen/Record.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -691,18 +691,19 @@ const Init *StringInit::convertInitializerTo(const RecTy *Ty) const {
691691
return nullptr;
692692
}
693693

694-
static void ProfileListInit(FoldingSetNodeID &ID, ArrayRef<const Init *> Range,
694+
static void ProfileListInit(FoldingSetNodeID &ID,
695+
ArrayRef<const Init *> Elements,
695696
const RecTy *EltTy) {
696-
ID.AddInteger(Range.size());
697+
ID.AddInteger(Elements.size());
697698
ID.AddPointer(EltTy);
698699

699-
for (const Init *I : Range)
700-
ID.AddPointer(I);
700+
for (const Init *E : Elements)
701+
ID.AddPointer(E);
701702
}
702703

703704
ListInit::ListInit(ArrayRef<const Init *> Elements, const RecTy *EltTy)
704705
: TypedInit(IK_ListInit, ListRecTy::get(EltTy)),
705-
NumValues(Elements.size()) {
706+
NumElements(Elements.size()) {
706707
llvm::uninitialized_copy(Elements, getTrailingObjects());
707708
}
708709

@@ -728,7 +729,7 @@ const ListInit *ListInit::get(ArrayRef<const Init *> Elements,
728729

729730
void ListInit::Profile(FoldingSetNodeID &ID) const {
730731
const RecTy *EltTy = cast<ListRecTy>(getType())->getElementType();
731-
ProfileListInit(ID, getValues(), EltTy);
732+
ProfileListInit(ID, getElements(), EltTy);
732733
}
733734

734735
const Init *ListInit::convertInitializerTo(const RecTy *Ty) const {
@@ -737,13 +738,13 @@ const Init *ListInit::convertInitializerTo(const RecTy *Ty) const {
737738

738739
if (const auto *LRT = dyn_cast<ListRecTy>(Ty)) {
739740
SmallVector<const Init *, 8> Elements;
740-
Elements.reserve(getValues().size());
741+
Elements.reserve(size());
741742

742743
// Verify that all of the elements of the list are subclasses of the
743744
// appropriate class!
744745
bool Changed = false;
745746
const RecTy *ElementType = LRT->getElementType();
746-
for (const Init *I : getValues())
747+
for (const Init *I : getElements())
747748
if (const Init *CI = I->convertInitializerTo(ElementType)) {
748749
Elements.push_back(CI);
749750
if (CI != I)
@@ -772,7 +773,7 @@ const Init *ListInit::resolveReferences(Resolver &R) const {
772773
Resolved.reserve(size());
773774
bool Changed = false;
774775

775-
for (const Init *CurElt : getValues()) {
776+
for (const Init *CurElt : getElements()) {
776777
const Init *E = CurElt->resolveReferences(R);
777778
Changed |= E != CurElt;
778779
Resolved.push_back(E);
@@ -943,9 +944,10 @@ const Init *UnOpInit::Fold(const Record *CurRec, bool IsFinal) const {
943944
case TAIL:
944945
if (const auto *LHSl = dyn_cast<ListInit>(LHS)) {
945946
assert(!LHSl->empty() && "Empty list in tail");
946-
// Note the +1. We can't just pass the result of getValues()
947+
// Note the slice(1). We can't just pass the result of getElements()
947948
// directly.
948-
return ListInit::get(LHSl->getValues().slice(1), LHSl->getElementType());
949+
return ListInit::get(LHSl->getElements().slice(1),
950+
LHSl->getElementType());
949951
}
950952
break;
951953

@@ -1011,11 +1013,11 @@ const Init *UnOpInit::Fold(const Record *CurRec, bool IsFinal) const {
10111013
[](const ListInit *List) -> std::optional<std::vector<const Init *>> {
10121014
std::vector<const Init *> Flattened;
10131015
// Concatenate elements of all the inner lists.
1014-
for (const Init *InnerInit : List->getValues()) {
1016+
for (const Init *InnerInit : List->getElements()) {
10151017
const auto *InnerList = dyn_cast<ListInit>(InnerInit);
10161018
if (!InnerList)
10171019
return std::nullopt;
1018-
llvm::append_range(Flattened, InnerList->getValues());
1020+
llvm::append_range(Flattened, InnerList->getElements());
10191021
};
10201022
return Flattened;
10211023
};
@@ -1115,7 +1117,7 @@ static const StringInit *interleaveStringList(const ListInit *List,
11151117
SmallString<80> Result(Element->getValue());
11161118
StringInit::StringFormat Fmt = StringInit::SF_String;
11171119

1118-
for (const Init *Elem : List->getValues().drop_front()) {
1120+
for (const Init *Elem : List->getElements().drop_front()) {
11191121
Result.append(Delim->getValue());
11201122
const auto *Element = dyn_cast<StringInit>(Elem);
11211123
if (!Element)
@@ -1137,7 +1139,7 @@ static const StringInit *interleaveIntList(const ListInit *List,
11371139
return nullptr;
11381140
SmallString<80> Result(Element->getAsString());
11391141

1140-
for (const Init *Elem : List->getValues().drop_front()) {
1142+
for (const Init *Elem : List->getElements().drop_front()) {
11411143
Result.append(Delim->getValue());
11421144
const auto *Element = dyn_cast_or_null<IntInit>(
11431145
Elem->convertInitializerTo(IntRecTy::get(RK)));
@@ -1719,7 +1721,7 @@ static const Init *FilterHelper(const Init *LHS, const Init *MHS,
17191721
if (const auto *MHSl = dyn_cast<ListInit>(MHS)) {
17201722
SmallVector<const Init *, 8> NewList;
17211723

1722-
for (const Init *Item : MHSl->getValues()) {
1724+
for (const Init *Item : MHSl->getElements()) {
17231725
const Init *Include = ItemApply(LHS, Item, RHS, CurRec);
17241726
if (!Include)
17251727
return nullptr;
@@ -3088,7 +3090,7 @@ std::vector<const Record *>
30883090
Record::getValueAsListOfDefs(StringRef FieldName) const {
30893091
const ListInit *List = getValueAsListInit(FieldName);
30903092
std::vector<const Record *> Defs;
3091-
for (const Init *I : List->getValues()) {
3093+
for (const Init *I : List->getElements()) {
30923094
if (const auto *DI = dyn_cast<DefInit>(I))
30933095
Defs.push_back(DI->getDef());
30943096
else
@@ -3117,7 +3119,7 @@ std::vector<int64_t>
31173119
Record::getValueAsListOfInts(StringRef FieldName) const {
31183120
const ListInit *List = getValueAsListInit(FieldName);
31193121
std::vector<int64_t> Ints;
3120-
for (const Init *I : List->getValues()) {
3122+
for (const Init *I : List->getElements()) {
31213123
if (const auto *II = dyn_cast<IntInit>(I))
31223124
Ints.push_back(II->getValue());
31233125
else
@@ -3133,7 +3135,7 @@ std::vector<StringRef>
31333135
Record::getValueAsListOfStrings(StringRef FieldName) const {
31343136
const ListInit *List = getValueAsListInit(FieldName);
31353137
std::vector<StringRef> Strings;
3136-
for (const Init *I : List->getValues()) {
3138+
for (const Init *I : List->getElements()) {
31373139
if (const auto *SI = dyn_cast<StringInit>(I))
31383140
Strings.push_back(SI->getValue());
31393141
else

llvm/utils/TableGen/AsmMatcherEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ void AsmMatcherInfo::buildOperandClasses() {
14021402
CI->Kind = ClassInfo::UserClass0 + Index;
14031403

14041404
const ListInit *Supers = Rec->getValueAsListInit("SuperClasses");
1405-
for (const Init *I : Supers->getValues()) {
1405+
for (const Init *I : Supers->getElements()) {
14061406
const DefInit *DI = dyn_cast<DefInit>(I);
14071407
if (!DI) {
14081408
PrintError(Rec->getLoc(), "Invalid super class reference!");

llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static TypeSigTy ComputeTypeSignature(const CodeGenIntrinsic &Int) {
301301
const Record *TypeInfo = Int.TheDef->getValueAsDef("TypeInfo");
302302
const ListInit *TypeList = TypeInfo->getValueAsListInit("TypeSig");
303303

304-
for (const auto *TypeListEntry : TypeList->getValues())
304+
for (const auto *TypeListEntry : TypeList->getElements())
305305
TypeSig.emplace_back(cast<IntInit>(TypeListEntry)->getValue());
306306
return TypeSig;
307307
}

llvm/utils/TableGen/CallingConvEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void CallingConvEmitter::emitAction(const Record *Action, indent Indent,
154154
O << Indent << "static const MCPhysReg " << RLName << "[] = {\n";
155155
O << Indent << " ";
156156
ListSeparator LS;
157-
for (const Init *V : RL->getValues())
157+
for (const Init *V : RL->getElements())
158158
O << LS << getQualifiedRegisterName(V);
159159
O << "\n" << Indent << "};\n";
160160
};

llvm/utils/TableGen/CodeGenMapTable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class InstrMap {
137137
"' has empty " +
138138
"`ValueCols' field!");
139139

140-
for (const Init *I : ColValList->getValues()) {
140+
for (const Init *I : ColValList->getElements()) {
141141
const auto *ColI = cast<ListInit>(I);
142142

143143
// Make sure that all the sub-lists in 'ValueCols' have same number of
@@ -228,7 +228,7 @@ void MapTableEmitter::buildRowInstrMap() {
228228
for (const Record *CurInstr : InstrDefs) {
229229
std::vector<const Init *> KeyValue;
230230
const ListInit *RowFields = InstrMapDesc.getRowFields();
231-
for (const Init *RowField : RowFields->getValues()) {
231+
for (const Init *RowField : RowFields->getElements()) {
232232
const RecordVal *RecVal = CurInstr->getValue(RowField);
233233
if (RecVal == nullptr)
234234
PrintFatalError(CurInstr->getLoc(),
@@ -303,7 +303,7 @@ const Record *MapTableEmitter::getInstrForColumn(const Record *KeyInstr,
303303
std::vector<const Init *> KeyValue;
304304

305305
// Construct KeyValue using KeyInstr's values for RowFields.
306-
for (const Init *RowField : RowFields->getValues()) {
306+
for (const Init *RowField : RowFields->getElements()) {
307307
const Init *KeyInstrVal = KeyInstr->getValue(RowField)->getValue();
308308
KeyValue.push_back(KeyInstrVal);
309309
}
@@ -475,7 +475,7 @@ void MapTableEmitter::emitTablesWithFunc(raw_ostream &OS) {
475475
OS << "// " << InstrMapDesc.getName() << "\nLLVM_READONLY\n";
476476
OS << "int " << InstrMapDesc.getName() << "(uint16_t Opcode";
477477
if (ValueCols.size() > 1) {
478-
for (const Init *CF : ColFields->getValues()) {
478+
for (const Init *CF : ColFields->getElements()) {
479479
std::string ColName = CF->getAsUnquotedString();
480480
OS << ", enum " << ColName << " in" << ColName;
481481
}

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ std::string TreePredicateFn::getPredCode() const {
10121012
" if (";
10131013

10141014
ListSeparator LS(" && ");
1015-
for (const Init *Val : AddressSpaces->getValues()) {
1015+
for (const Init *Val : AddressSpaces->getElements()) {
10161016
Code += LS;
10171017

10181018
const IntInit *IntVal = dyn_cast<IntInit>(Val);
@@ -1489,7 +1489,7 @@ int PatternToMatch::getPatternComplexity(const CodeGenDAGPatterns &CGP) const {
14891489

14901490
void PatternToMatch::getPredicateRecords(
14911491
SmallVectorImpl<const Record *> &PredicateRecs) const {
1492-
for (const Init *I : Predicates->getValues()) {
1492+
for (const Init *I : Predicates->getElements()) {
14931493
if (const DefInit *Pred = dyn_cast<DefInit>(I)) {
14941494
const Record *Def = Pred->getDef();
14951495
if (!Def->isSubClassOf("Predicate")) {
@@ -1934,7 +1934,7 @@ static unsigned GetNumNodeResults(const Record *Operator,
19341934
const ListInit *LI = Operator->getValueAsListInit("Fragments");
19351935
assert(LI && "Invalid Fragment");
19361936
unsigned NumResults = 0;
1937-
for (const Init *I : LI->getValues()) {
1937+
for (const Init *I : LI->getElements()) {
19381938
const Record *Op = nullptr;
19391939
if (const DagInit *Dag = dyn_cast<DagInit>(I))
19401940
if (const DefInit *DI = dyn_cast<DefInit>(Dag->getOperator()))
@@ -2855,7 +2855,7 @@ TreePattern::TreePattern(const Record *TheRec, const ListInit *RawPat,
28552855
bool isInput, CodeGenDAGPatterns &cdp)
28562856
: TheRecord(TheRec), CDP(cdp), isInputPattern(isInput), HasError(false),
28572857
Infer(*this) {
2858-
for (const Init *I : RawPat->getValues())
2858+
for (const Init *I : RawPat->getElements())
28592859
Trees.push_back(ParseTreePattern(I, ""));
28602860
}
28612861

@@ -3766,7 +3766,7 @@ static bool hasNullFragReference(const DagInit *DI) {
37663766
/// hasNullFragReference - Return true if any DAG in the list references
37673767
/// the null_frag operator.
37683768
static bool hasNullFragReference(const ListInit *LI) {
3769-
for (const Init *I : LI->getValues()) {
3769+
for (const Init *I : LI->getElements()) {
37703770
const DagInit *DI = dyn_cast<DagInit>(I);
37713771
assert(DI && "non-dag in an instruction Pattern list?!");
37723772
if (hasNullFragReference(DI))

llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ CodeGenRegisterClass::CodeGenRegisterClass(CodeGenRegBank &RegBank,
770770

771771
// Alternative allocation orders may be subsets.
772772
SetTheory::RecSet Order;
773-
for (auto [Idx, AltOrderElem] : enumerate(AltOrders->getValues())) {
773+
for (auto [Idx, AltOrderElem] : enumerate(AltOrders->getElements())) {
774774
RegBank.getSets().evaluate(AltOrderElem, Order, R->getLoc());
775775
Orders[1 + Idx].append(Order.begin(), Order.end());
776776
// Verify that all altorder members are regclass members.

llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ bool CombineRuleBuilder::addFeaturePredicates(RuleMatcher &M) {
14041404
return true;
14051405

14061406
const ListInit *Preds = RuleDef.getValueAsListInit("Predicates");
1407-
for (const Init *PI : Preds->getValues()) {
1407+
for (const Init *PI : Preds->getElements()) {
14081408
const DefInit *Pred = dyn_cast<DefInit>(PI);
14091409
if (!Pred)
14101410
continue;

llvm/utils/TableGen/GlobalISelEmitter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static std::string explainPredicates(const TreePatternNode &N) {
129129
OS << " AddressSpaces=[";
130130

131131
StringRef AddrSpaceSeparator;
132-
for (const Init *Val : AddrSpaces->getValues()) {
132+
for (const Init *Val : AddrSpaces->getElements()) {
133133
const IntInit *IntVal = dyn_cast<IntInit>(Val);
134134
if (!IntVal)
135135
continue;
@@ -600,7 +600,7 @@ Expected<InstructionMatcher &> GlobalISelEmitter::addBuiltinPredicates(
600600
if (const ListInit *AddrSpaces = Predicate.getAddressSpaces()) {
601601
SmallVector<unsigned, 4> ParsedAddrSpaces;
602602

603-
for (const Init *Val : AddrSpaces->getValues()) {
603+
for (const Init *Val : AddrSpaces->getElements()) {
604604
const IntInit *IntVal = dyn_cast<IntInit>(Val);
605605
if (!IntVal)
606606
return failedImport("Address space is not an integer");

llvm/utils/TableGen/OptionParserEmitter.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
501501
for (const Record *VisibilityHelp :
502502
R.getValueAsListOfDefs("HelpTextsForVariants")) {
503503
ArrayRef<const Init *> Visibilities =
504-
VisibilityHelp->getValueAsListInit("Visibilities")->getValues();
504+
VisibilityHelp->getValueAsListInit("Visibilities")->getElements();
505505

506506
std::vector<std::string> VisibilityNames;
507507
for (const Init *Visibility : Visibilities)
@@ -523,11 +523,10 @@ static void emitOptionParser(const RecordKeeper &Records, raw_ostream &OS) {
523523
OS << ", ";
524524
if (!isa<UnsetInit>(R.getValueInit("Values")))
525525
writeCstring(OS, R.getValueAsString("Values"));
526-
else if (!isa<UnsetInit>(R.getValueInit("ValuesCode"))) {
526+
else if (!isa<UnsetInit>(R.getValueInit("ValuesCode")))
527527
OS << getOptionName(R) << "_Values";
528-
} else {
528+
else
529529
OS << "nullptr";
530-
}
531530
};
532531

533532
auto IsMarshallingOption = [](const Record &R) {

mlir/lib/TableGen/AttrOrTypeDef.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ AttrOrTypeDef::AttrOrTypeDef(const Record *def) : def(def) {
4646
const auto *builderList =
4747
dyn_cast_or_null<ListInit>(def->getValueInit("builders"));
4848
if (builderList && !builderList->empty()) {
49-
for (const Init *init : builderList->getValues()) {
49+
for (const Init *init : builderList->getElements()) {
5050
AttrOrTypeBuilder builder(cast<DefInit>(init)->getDef(), def->getLoc());
5151

5252
// Ensure that all parameters have names.

0 commit comments

Comments
 (0)