Parse information about type constraints on SDNodes
authorChris Lattner <sabre@nondot.org>
Thu, 8 Sep 2005 21:27:15 +0000 (21:27 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 8 Sep 2005 21:27:15 +0000 (21:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23281 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelEmitter.cpp
utils/TableGen/DAGISelEmitter.h

index 6bace1158d3fd5e369490b132d39de81fb3e10e1..dfb17f3ae42c1b4896cd557a2af20e006b8c58a3 100644 (file)
 #include <set>
 using namespace llvm;
 
+//===----------------------------------------------------------------------===//
+// SDTypeConstraint implementation
+//
+
+SDTypeConstraint::SDTypeConstraint(Record *R) {
+  OperandNo = R->getValueAsInt("OperandNum");
+  
+  if (R->isSubClassOf("SDTCisVT")) {
+    ConstraintType = SDTCisVT;
+    x.SDTCisVT_Info.VT = getValueType(R->getValueAsDef("VT"));
+  } else if (R->isSubClassOf("SDTCisInt")) {
+    ConstraintType = SDTCisInt;
+  } else if (R->isSubClassOf("SDTCisFP")) {
+    ConstraintType = SDTCisFP;
+  } else if (R->isSubClassOf("SDTCisSameAs")) {
+    ConstraintType = SDTCisSameAs;
+    x.SDTCisSameAs_Info.OtherOperandNum = R->getValueAsInt("OtherOperandNum");
+  } else if (R->isSubClassOf("SDTCisVTSmallerThanOp")) {
+    ConstraintType = SDTCisVTSmallerThanOp;
+    x.SDTCisVTSmallerThanOp_Info.OtherOperandNum = 
+      R->getValueAsInt("OtherOperandNum");
+  } else {
+    std::cerr << "Unrecognized SDTypeConstraint '" << R->getName() << "'!\n";
+    exit(1);
+  }
+}
+
 //===----------------------------------------------------------------------===//
 // SDNodeInfo implementation
 //
 SDNodeInfo::SDNodeInfo(Record *R) : Def(R) {
   EnumName    = R->getValueAsString("Opcode");
   SDClassName = R->getValueAsString("SDClass");
+  Record *TypeProfile = R->getValueAsDef("TypeProfile");
+  NumResults = TypeProfile->getValueAsInt("NumResults");
+  NumOperands = TypeProfile->getValueAsInt("NumOperands");
+  
+  // Parse the type constraints.
+  ListInit *Constraints = TypeProfile->getValueAsListInit("Constraints");
+  for (unsigned i = 0, e = Constraints->getSize(); i != e; ++i) {
+    assert(dynamic_cast<DefInit*>(Constraints->getElement(i)) &&
+           "Constraints list should contain constraint definitions!");
+    Record *Constraint = 
+      static_cast<DefInit*>(Constraints->getElement(i))->getDef();
+    TypeConstraints.push_back(Constraint);
+  }
 }
 
 //===----------------------------------------------------------------------===//
index 20ead35a79d432b1f811f063b2e4fc6ca3030d8a..e2fade9917130d8aaf9213f077a91140c6cd1f76 100644 (file)
@@ -24,6 +24,29 @@ namespace llvm {
   class TreePattern;
   class DAGISelEmitter;
   
+  /// SDTypeConstraint - This is a discriminated union of constraints,
+  /// corresponding to the SDTypeConstraint tablegen class in Target.td.
+  struct SDTypeConstraint {
+    SDTypeConstraint(Record *R);
+    
+    unsigned OperandNo;   // The operand # this constraint applies to.
+    enum { 
+      SDTCisVT, SDTCisInt, SDTCisFP, SDTCisSameAs, SDTCisVTSmallerThanOp
+    } ConstraintType;
+    
+    union {   // The discriminated union.
+      struct {
+        MVT::ValueType VT;
+      } SDTCisVT_Info;
+      struct {
+        unsigned OtherOperandNum;
+      } SDTCisSameAs_Info;
+      struct {
+        unsigned OtherOperandNum;
+      } SDTCisVTSmallerThanOp_Info;
+    } x;
+  };
+  
   /// SDNodeInfo - One of these records is created for each SDNode instance in
   /// the target .td file.  This represents the various dag nodes we will be
   /// processing.
@@ -31,12 +54,20 @@ namespace llvm {
     Record *Def;
     std::string EnumName;
     std::string SDClassName;
+    int NumResults, NumOperands;
+    std::vector<SDTypeConstraint> TypeConstraints;
   public:
     SDNodeInfo(Record *R);  // Parse the specified record.
     
+    int getNumResults() const { return NumResults; }
+    int getNumOperands() const { return NumOperands; }
     Record *getRecord() const { return Def; }
     const std::string &getEnumName() const { return EnumName; }
     const std::string &getSDClassName() const { return SDClassName; }
+    
+    const std::vector<SDTypeConstraint> &getTypeConstraints() {
+      return TypeConstraints;
+    }
   };
 
   /// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped