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

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 8 12:18:57 PDT 2024


Author: Rahul Joshi
Date: 2024-09-08T12:18:53-07:00
New Revision: ce3c58e10481dd1d0393d342b4102c633cfd0def

URL: https://github.com/llvm/llvm-project/commit/ce3c58e10481dd1d0393d342b4102c633cfd0def
DIFF: https://github.com/llvm/llvm-project/commit/ce3c58e10481dd1d0393d342b4102c633cfd0def.diff

LOG: [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`.

Added: 
    

Modified: 
    llvm/include/llvm/TableGen/Record.h
    llvm/lib/TableGen/Record.cpp
    llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
    llvm/utils/TableGen/Common/CodeGenRegisters.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 3b36173f6f1d19..98c8fd0ca051f9 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -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; }

diff  --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 692667f9753283..85516b7b9f20aa 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -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 '" +
@@ -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());
@@ -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) {
@@ -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))
@@ -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 {

diff  --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
index 9a31d4f6487cb5..d580059a3d66f6 100644
--- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp
@@ -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");

diff  --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index ee58cad358a4f1..1d6f8c6b4fd883 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -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.


        


More information about the llvm-commits mailing list