[llvm-commits] CVS: llvm/utils/TableGen/DAGISelEmitter.cpp DAGISelEmitter.h

Chris Lattner lattner at cs.uiuc.edu
Thu Sep 8 14:27:26 PDT 2005



Changes in directory llvm/utils/TableGen:

DAGISelEmitter.cpp updated: 1.4 -> 1.5
DAGISelEmitter.h updated: 1.3 -> 1.4
---
Log message:

Parse information about type constraints on SDNodes


---
Diffs of the changes:  (+71 -0)

 DAGISelEmitter.cpp |   40 ++++++++++++++++++++++++++++++++++++++++
 DAGISelEmitter.h   |   31 +++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+)


Index: llvm/utils/TableGen/DAGISelEmitter.cpp
diff -u llvm/utils/TableGen/DAGISelEmitter.cpp:1.4 llvm/utils/TableGen/DAGISelEmitter.cpp:1.5
--- llvm/utils/TableGen/DAGISelEmitter.cpp:1.4	Thu Sep  8 16:04:46 2005
+++ llvm/utils/TableGen/DAGISelEmitter.cpp	Thu Sep  8 16:27:15 2005
@@ -19,11 +19,51 @@
 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: llvm/utils/TableGen/DAGISelEmitter.h
diff -u llvm/utils/TableGen/DAGISelEmitter.h:1.3 llvm/utils/TableGen/DAGISelEmitter.h:1.4
--- llvm/utils/TableGen/DAGISelEmitter.h:1.3	Thu Sep  8 16:03:01 2005
+++ llvm/utils/TableGen/DAGISelEmitter.h	Thu Sep  8 16:27:15 2005
@@ -24,6 +24,29 @@
   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 @@
     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






More information about the llvm-commits mailing list