Skip to content

[NFC][TableGen] Replace DefInit::get() with Record::getDefInit() #107762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions llvm/include/llvm/TableGen/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -1323,14 +1323,10 @@ class DefInit : public TypedInit {
return I->getKind() == IK_DefInit;
}

static DefInit *get(Record*);

Init *convertInitializerTo(RecTy *Ty) const override;

Record *getDef() const { return Def; }

//virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits);

RecTy *getFieldType(StringInit *FieldName) const override;

bool isConcrete() const override { return true; }
Expand Down
106 changes: 50 additions & 56 deletions llvm/lib/TableGen/Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
break;
}

DefInit *DI = DefInit::get(D);
DefInit *DI = D->getDefInit();
if (!DI->getType()->typeIsA(getType())) {
PrintFatalErrorHelper(Twine("Expected type '") +
getType()->getAsString() + "', got '" +
Expand Down Expand Up @@ -1682,7 +1682,7 @@ Init *TernOpInit::Fold(Record *CurRec) const {
Record *Val = RHSd->getDef();
if (LHSd->getAsString() == RHSd->getAsString())
Val = MHSd->getDef();
return DefInit::get(Val);
return Val->getDefInit();
}
if (LHSv && MHSv && RHSv) {
std::string Val = std::string(RHSv->getName());
Expand Down Expand Up @@ -2083,7 +2083,7 @@ Init *ExistsOpInit::Fold(Record *CurRec, bool IsFinal) const {
if (D) {
// Check if types are compatible.
return IntInit::get(getRecordKeeper(),
DefInit::get(D)->getType()->typeIsA(CheckType));
D->getDefInit()->getType()->typeIsA(CheckType));
}

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

DefInit *DefInit::get(Record *R) {
return R->getDefInit();
}

Init *DefInit::convertInitializerTo(RecTy *Ty) const {
if (auto *RRT = dyn_cast<RecordRecTy>(Ty))
if (getType()->typeIsConvertibleTo(RRT))
Expand Down Expand Up @@ -2290,64 +2286,62 @@ void VarDefInit::Profile(FoldingSetNodeID &ID) const {
}

DefInit *VarDefInit::instantiate() {
if (!Def) {
RecordKeeper &Records = Class->getRecords();
auto NewRecOwner =
std::make_unique<Record>(Records.getNewAnonymousName(), Class->getLoc(),
Records, Record::RK_AnonymousDef);
Record *NewRec = NewRecOwner.get();

// Copy values from class to instance
for (const RecordVal &Val : Class->getValues())
NewRec->addValue(Val);

// Copy assertions from class to instance.
NewRec->appendAssertions(Class);

// Copy dumps from class to instance.
NewRec->appendDumps(Class);

// Substitute and resolve template arguments
ArrayRef<Init *> TArgs = Class->getTemplateArgs();
MapResolver R(NewRec);

for (Init *Arg : TArgs) {
R.set(Arg, NewRec->getValue(Arg)->getValue());
NewRec->removeValue(Arg);
}

for (auto *Arg : args()) {
if (Arg->isPositional())
R.set(TArgs[Arg->getIndex()], Arg->getValue());
if (Arg->isNamed())
R.set(Arg->getName(), Arg->getValue());
}
if (Def)
return Def;

NewRec->resolveReferences(R);
RecordKeeper &Records = Class->getRecords();
auto NewRecOwner =
std::make_unique<Record>(Records.getNewAnonymousName(), Class->getLoc(),
Records, Record::RK_AnonymousDef);
Record *NewRec = NewRecOwner.get();

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

NewRec->addSuperClass(Class,
SMRange(Class->getLoc().back(),
Class->getLoc().back()));
// Copy assertions from class to instance.
NewRec->appendAssertions(Class);

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

// Check the assertions.
NewRec->checkRecordAssertions();
// Substitute and resolve template arguments
ArrayRef<Init *> TArgs = Class->getTemplateArgs();
MapResolver R(NewRec);

// Check the assertions.
NewRec->emitRecordDumps();
for (Init *Arg : TArgs) {
R.set(Arg, NewRec->getValue(Arg)->getValue());
NewRec->removeValue(Arg);
}

Def = DefInit::get(NewRec);
for (auto *Arg : args()) {
if (Arg->isPositional())
R.set(TArgs[Arg->getIndex()], Arg->getValue());
if (Arg->isNamed())
R.set(Arg->getName(), Arg->getValue());
}

return Def;
NewRec->resolveReferences(R);

// Add superclasses.
ArrayRef<std::pair<Record *, SMRange>> SCs = Class->getSuperClasses();
for (const auto &SCPair : SCs)
NewRec->addSuperClass(SCPair.first, SCPair.second);

NewRec->addSuperClass(
Class, SMRange(Class->getLoc().back(), Class->getLoc().back()));

// Resolve internal references and store in record keeper
NewRec->resolveReferences();
Records.addDef(std::move(NewRecOwner));

// Check the assertions.
NewRec->checkRecordAssertions();

// Check the assertions.
NewRec->emitRecordDumps();

return Def = NewRec->getDefInit();
}

Init *VarDefInit::resolveReferences(Resolver &R) const {
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3334,7 +3334,7 @@ void CodeGenDAGPatterns::ParseDefaultOperands() {

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

for (unsigned i = 0, e = DefaultOps.size(); i != e; ++i) {
DagInit *DefaultInfo = DefaultOps[i]->getValueAsDag("DefaultOps");
Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/CodeGenRegisters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ struct TupleExpander : SetTheory::Expander {
if (i)
Name += '_';
Name += Reg->getName();
Tuple.push_back(DefInit::get(Reg));
Tuple.push_back(Reg->getDefInit());
}

// Take the cost list of the first register in the tuple.
Expand Down
Loading