[llvm] r348034 - [TableGen] Fix negation of simple predicates

Evandro Menezes via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 30 13:03:25 PST 2018


Author: evandro
Date: Fri Nov 30 13:03:24 2018
New Revision: 348034

URL: http://llvm.org/viewvc/llvm-project?rev=348034&view=rev
Log:
[TableGen] Fix negation of simple predicates

Simple predicates, such as those defined by `CheckRegOperandSimple` or
`CheckImmOperandSimple`, were not being negated when used with `CheckNot`.

This change fixes this issue by defining the previously declared methods to
handle simple predicates.

Differential revision: https://reviews.llvm.org/D55089

Modified:
    llvm/trunk/utils/TableGen/PredicateExpander.cpp

Modified: llvm/trunk/utils/TableGen/PredicateExpander.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/PredicateExpander.cpp?rev=348034&r1=348033&r2=348034&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/PredicateExpander.cpp (original)
+++ llvm/trunk/utils/TableGen/PredicateExpander.cpp Fri Nov 30 13:03:24 2018
@@ -26,24 +26,39 @@ void PredicateExpander::expandCheckImmOp
     OS << FunctionMapper << "(";
   OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
      << ").getImm()";
-  OS << (FunctionMapper.empty() ? " " : ") ");
-  OS << (shouldNegate() ? "!= " : "== ") << ImmVal;
+  if (!FunctionMapper.empty())
+    OS << ")";
+  OS << (shouldNegate() ? " != " : " == ") << ImmVal;
 }
 
 void PredicateExpander::expandCheckImmOperand(raw_ostream &OS, int OpIndex,
                                               StringRef ImmVal,
                                               StringRef FunctionMapper) {
+  if (ImmVal.empty())
+    expandCheckImmOperandSimple(OS, OpIndex, FunctionMapper);
+
   if (!FunctionMapper.empty())
     OS << FunctionMapper << "(";
   OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
      << ").getImm()";
-
-  OS << (FunctionMapper.empty() ? "" : ")");
-  if (ImmVal.empty())
-    return;
+  if (!FunctionMapper.empty())
+    OS << ")";
   OS << (shouldNegate() ? " != " : " == ") << ImmVal;
 }
 
+void PredicateExpander::expandCheckImmOperandSimple(raw_ostream &OS,
+                                                    int OpIndex,
+                                                    StringRef FunctionMapper) {
+  if (shouldNegate())
+    OS << "!";
+  if (!FunctionMapper.empty())
+    OS << FunctionMapper << "(";
+  OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
+     << ").getImm()";
+  if (!FunctionMapper.empty())
+    OS << ")";
+}
+
 void PredicateExpander::expandCheckRegOperand(raw_ostream &OS, int OpIndex,
                                               const Record *Reg,
                                               StringRef FunctionMapper) {
@@ -53,9 +68,8 @@ void PredicateExpander::expandCheckRegOp
     OS << FunctionMapper << "(";
   OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
      << ").getReg()";
-  OS << (FunctionMapper.empty() ? "" : ")");
-  if (!Reg)
-    return;
+  if (!FunctionMapper.empty())
+    OS << ")";
   OS << (shouldNegate() ? " != " : " == ");
   const StringRef Str = Reg->getValueAsString("Namespace");
   if (!Str.empty())
@@ -63,6 +77,20 @@ void PredicateExpander::expandCheckRegOp
   OS << Reg->getName();
 }
 
+
+void PredicateExpander::expandCheckRegOperandSimple(raw_ostream &OS,
+                                                    int OpIndex,
+                                                    StringRef FunctionMapper) {
+  if (shouldNegate())
+    OS << "!";
+  if (!FunctionMapper.empty())
+    OS << FunctionMapper << "(";
+  OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
+     << ").getReg()";
+  if (!FunctionMapper.empty())
+    OS << ")";
+}
+
 void PredicateExpander::expandCheckInvalidRegOperand(raw_ostream &OS,
                                                      int OpIndex) {
   OS << "MI" << (isByRef() ? "." : "->") << "getOperand(" << OpIndex
@@ -290,9 +318,8 @@ void PredicateExpander::expandPredicate(
                                  Rec->getValueAsString("FunctionMapper"));
 
   if (Rec->isSubClassOf("CheckRegOperandSimple"))
-    return expandCheckRegOperand(OS, Rec->getValueAsInt("OpIndex"),
-                                 nullptr,
-                                 Rec->getValueAsString("FunctionMapper"));
+    return expandCheckRegOperandSimple(OS, Rec->getValueAsInt("OpIndex"),
+                                       Rec->getValueAsString("FunctionMapper"));
 
   if (Rec->isSubClassOf("CheckInvalidRegOperand"))
     return expandCheckInvalidRegOperand(OS, Rec->getValueAsInt("OpIndex"));
@@ -308,8 +335,8 @@ void PredicateExpander::expandPredicate(
                                  Rec->getValueAsString("FunctionMapper"));
 
   if (Rec->isSubClassOf("CheckImmOperandSimple"))
-    return expandCheckImmOperand(OS, Rec->getValueAsInt("OpIndex"), "", 
-                                 Rec->getValueAsString("FunctionMapper"));
+    return expandCheckImmOperandSimple(OS, Rec->getValueAsInt("OpIndex"),
+                                       Rec->getValueAsString("FunctionMapper"));
 
   if (Rec->isSubClassOf("CheckSameRegOperand"))
     return expandCheckSameRegOperand(OS, Rec->getValueAsInt("FirstIndex"),




More information about the llvm-commits mailing list