Skip to content

Commit ce3c58e

Browse files
authored
[NFC][TableGen] Replace DefInit::get() with Record::getDefInit() (#107762)
Eliminate DefInit::get() as its a duplicate of Record::getDefInit(). Use early return in `VarDefInit::instantiate`.
1 parent 6f67c38 commit ce3c58e

File tree

4 files changed

+52
-62
lines changed

4 files changed

+52
-62
lines changed

llvm/include/llvm/TableGen/Record.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,14 +1323,10 @@ class DefInit : public TypedInit {
13231323
return I->getKind() == IK_DefInit;
13241324
}
13251325

1326-
static DefInit *get(Record*);
1327-
13281326
Init *convertInitializerTo(RecTy *Ty) const override;
13291327

13301328
Record *getDef() const { return Def; }
13311329

1332-
//virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);
1333-
13341330
RecTy *getFieldType(StringInit *FieldName) const override;
13351331

13361332
bool isConcrete() const override { return true; }

llvm/lib/TableGen/Record.cpp

Lines changed: 50 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
894894
break;
895895
}
896896

897-
DefInit *DI = DefInit::get(D);
897+
DefInit *DI = D->getDefInit();
898898
if (!DI->getType()->typeIsA(getType())) {
899899
PrintFatalErrorHelper(Twine("Expected type '") +
900900
getType()->getAsString() + "', got '" +
@@ -1682,7 +1682,7 @@ Init *TernOpInit::Fold(Record *CurRec) const {
16821682
Record *Val = RHSd->getDef();
16831683
if (LHSd->getAsString() == RHSd->getAsString())
16841684
Val = MHSd->getDef();
1685-
return DefInit::get(Val);
1685+
return Val->getDefInit();
16861686
}
16871687
if (LHSv && MHSv && RHSv) {
16881688
std::string Val = std::string(RHSv->getName());
@@ -2083,7 +2083,7 @@ Init *ExistsOpInit::Fold(Record *CurRec, bool IsFinal) const {
20832083
if (D) {
20842084
// Check if types are compatible.
20852085
return IntInit::get(getRecordKeeper(),
2086-
DefInit::get(D)->getType()->typeIsA(CheckType));
2086+
D->getDefInit()->getType()->typeIsA(CheckType));
20872087
}
20882088

20892089
if (CurRec) {
@@ -2235,10 +2235,6 @@ Init *VarBitInit::resolveReferences(Resolver &R) const {
22352235
DefInit::DefInit(Record *D)
22362236
: TypedInit(IK_DefInit, D->getType()), Def(D) {}
22372237

2238-
DefInit *DefInit::get(Record *R) {
2239-
return R->getDefInit();
2240-
}
2241-
22422238
Init *DefInit::convertInitializerTo(RecTy *Ty) const {
22432239
if (auto *RRT = dyn_cast<RecordRecTy>(Ty))
22442240
if (getType()->typeIsConvertibleTo(RRT))
@@ -2290,64 +2286,62 @@ void VarDefInit::Profile(FoldingSetNodeID &ID) const {
22902286
}
22912287

22922288
DefInit *VarDefInit::instantiate() {
2293-
if (!Def) {
2294-
RecordKeeper &Records = Class->getRecords();
2295-
auto NewRecOwner =
2296-
std::make_unique<Record>(Records.getNewAnonymousName(), Class->getLoc(),
2297-
Records, Record::RK_AnonymousDef);
2298-
Record *NewRec = NewRecOwner.get();
2299-
2300-
// Copy values from class to instance
2301-
for (const RecordVal &Val : Class->getValues())
2302-
NewRec->addValue(Val);
2303-
2304-
// Copy assertions from class to instance.
2305-
NewRec->appendAssertions(Class);
2306-
2307-
// Copy dumps from class to instance.
2308-
NewRec->appendDumps(Class);
2309-
2310-
// Substitute and resolve template arguments
2311-
ArrayRef<Init *> TArgs = Class->getTemplateArgs();
2312-
MapResolver R(NewRec);
2313-
2314-
for (Init *Arg : TArgs) {
2315-
R.set(Arg, NewRec->getValue(Arg)->getValue());
2316-
NewRec->removeValue(Arg);
2317-
}
2318-
2319-
for (auto *Arg : args()) {
2320-
if (Arg->isPositional())
2321-
R.set(TArgs[Arg->getIndex()], Arg->getValue());
2322-
if (Arg->isNamed())
2323-
R.set(Arg->getName(), Arg->getValue());
2324-
}
2289+
if (Def)
2290+
return Def;
23252291

2326-
NewRec->resolveReferences(R);
2292+
RecordKeeper &Records = Class->getRecords();
2293+
auto NewRecOwner =
2294+
std::make_unique<Record>(Records.getNewAnonymousName(), Class->getLoc(),
2295+
Records, Record::RK_AnonymousDef);
2296+
Record *NewRec = NewRecOwner.get();
23272297

2328-
// Add superclasses.
2329-
ArrayRef<std::pair<Record *, SMRange>> SCs = Class->getSuperClasses();
2330-
for (const auto &SCPair : SCs)
2331-
NewRec->addSuperClass(SCPair.first, SCPair.second);
2298+
// Copy values from class to instance
2299+
for (const RecordVal &Val : Class->getValues())
2300+
NewRec->addValue(Val);
23322301

2333-
NewRec->addSuperClass(Class,
2334-
SMRange(Class->getLoc().back(),
2335-
Class->getLoc().back()));
2302+
// Copy assertions from class to instance.
2303+
NewRec->appendAssertions(Class);
23362304

2337-
// Resolve internal references and store in record keeper
2338-
NewRec->resolveReferences();
2339-
Records.addDef(std::move(NewRecOwner));
2305+
// Copy dumps from class to instance.
2306+
NewRec->appendDumps(Class);
23402307

2341-
// Check the assertions.
2342-
NewRec->checkRecordAssertions();
2308+
// Substitute and resolve template arguments
2309+
ArrayRef<Init *> TArgs = Class->getTemplateArgs();
2310+
MapResolver R(NewRec);
23432311

2344-
// Check the assertions.
2345-
NewRec->emitRecordDumps();
2312+
for (Init *Arg : TArgs) {
2313+
R.set(Arg, NewRec->getValue(Arg)->getValue());
2314+
NewRec->removeValue(Arg);
2315+
}
23462316

2347-
Def = DefInit::get(NewRec);
2317+
for (auto *Arg : args()) {
2318+
if (Arg->isPositional())
2319+
R.set(TArgs[Arg->getIndex()], Arg->getValue());
2320+
if (Arg->isNamed())
2321+
R.set(Arg->getName(), Arg->getValue());
23482322
}
23492323

2350-
return Def;
2324+
NewRec->resolveReferences(R);
2325+
2326+
// Add superclasses.
2327+
ArrayRef<std::pair<Record *, SMRange>> SCs = Class->getSuperClasses();
2328+
for (const auto &SCPair : SCs)
2329+
NewRec->addSuperClass(SCPair.first, SCPair.second);
2330+
2331+
NewRec->addSuperClass(
2332+
Class, SMRange(Class->getLoc().back(), Class->getLoc().back()));
2333+
2334+
// Resolve internal references and store in record keeper
2335+
NewRec->resolveReferences();
2336+
Records.addDef(std::move(NewRecOwner));
2337+
2338+
// Check the assertions.
2339+
NewRec->checkRecordAssertions();
2340+
2341+
// Check the assertions.
2342+
NewRec->emitRecordDumps();
2343+
2344+
return Def = NewRec->getDefInit();
23512345
}
23522346

23532347
Init *VarDefInit::resolveReferences(Resolver &R) const {

llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3334,7 +3334,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() {
33343334

33353335
// Find some SDNode.
33363336
assert(!SDNodes.empty() && "No SDNodes parsed?");
3337-
Init *SomeSDNode = DefInit::get(SDNodes.begin()->first);
3337+
Init *SomeSDNode = SDNodes.begin()->first->getDefInit();
33383338

33393339
for (unsigned i = 0, e = DefaultOps.size(); i != e; ++i) {
33403340
DagInit *DefaultInfo = DefaultOps[i]->getValueAsDag("DefaultOps");

llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ struct TupleExpander : SetTheory::Expander {
664664
if (i)
665665
Name += '_';
666666
Name += Reg->getName();
667-
Tuple.push_back(DefInit::get(Reg));
667+
Tuple.push_back(Reg->getDefInit());
668668
}
669669

670670
// Take the cost list of the first register in the tuple.

0 commit comments

Comments
 (0)