[TableGen] Minor tweak to AssemblerCondDag evaluation to be more consistent with...
authorCraig Topper <craig.topper@sifive.com>
Tue, 28 Feb 2023 08:09:27 +0000 (00:09 -0800)
committerCraig Topper <craig.topper@sifive.com>
Wed, 1 Mar 2023 05:26:57 +0000 (21:26 -0800)
Instead of using getAsString on the dag operator, check if the operator
is a DefInit and then get the name of the Def.

llvm/utils/TableGen/AsmWriterEmitter.cpp
llvm/utils/TableGen/SubtargetFeatureInfo.cpp

index 6c1a2df..f905993 100644 (file)
@@ -996,7 +996,10 @@ void AsmWriterEmitter::EmitPrintAliasInstruction(raw_ostream &O) {
 
       for (Record *const R : ReqFeatures) {
         const DagInit *D = R->getValueAsDag("AssemblerCondDag");
-        std::string CombineType = D->getOperator()->getAsString();
+        auto *Op = dyn_cast<DefInit>(D->getOperator());
+        if (!Op)
+          PrintFatalError(R->getLoc(), "Invalid AssemblerCondDag!");
+        StringRef CombineType = Op->getDef()->getName();
         if (CombineType != "any_of" && CombineType != "all_of")
           PrintFatalError(R->getLoc(), "Invalid AssemblerCondDag!");
         if (D->getNumArgs() == 0)
index 1abcf48..7579fab 100644 (file)
@@ -117,16 +117,19 @@ static bool emitFeaturesAux(StringRef TargetName, const Init &Val,
     return false;
   }
   if (auto *D = dyn_cast<DagInit>(&Val)) {
-    std::string Op = D->getOperator()->getAsString();
-    if (Op == "not" && D->getNumArgs() == 1) {
+    auto *Op = dyn_cast<DefInit>(D->getOperator());
+    if (!Op)
+      return true;
+    StringRef OpName = Op->getDef()->getName();
+    if (OpName == "not" && D->getNumArgs() == 1) {
       OS << '!';
       return emitFeaturesAux(TargetName, *D->getArg(0), true, OS);
     }
-    if ((Op == "any_of" || Op == "all_of") && D->getNumArgs() > 0) {
+    if ((OpName == "any_of" || OpName == "all_of") && D->getNumArgs() > 0) {
       bool Paren = D->getNumArgs() > 1 && std::exchange(ParenIfBinOp, true);
       if (Paren)
         OS << '(';
-      ListSeparator LS(Op == "any_of" ? " || " : " && ");
+      ListSeparator LS(OpName == "any_of" ? " || " : " && ");
       for (auto *Arg : D->getArgs()) {
         OS << LS;
         if (emitFeaturesAux(TargetName, *Arg, ParenIfBinOp, OS))