[llvm-commits] [llvm] r37933 - in /llvm/trunk/utils/TableGen: DAGISelEmitter.cpp DAGISelEmitter.h

Evan Cheng evan.cheng at apple.com
Thu Jul 5 18:05:26 PDT 2007


Author: evancheng
Date: Thu Jul  5 20:05:26 2007
New Revision: 37933

URL: http://llvm.org/viewvc/llvm-project?rev=37933&view=rev
Log:
Refactor code to add initial support for OptionalDefOperand.

Modified:
    llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
    llvm/trunk/utils/TableGen/DAGISelEmitter.h

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.cpp?rev=37933&r1=37932&r2=37933&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.cpp Thu Jul  5 20:05:26 2007
@@ -775,11 +775,12 @@
     for (unsigned i = 0, e = Inst.getNumOperands(); i != e; ++i) {
       Record *OperandNode = Inst.getOperand(i);
       
-      // If the instruction expects a predicate operand, we codegen this by
-      // setting the predicate to it's "execute always" value if it has a
-      // non-empty ExecuteAlways field.
-      if (OperandNode->isSubClassOf("PredicateOperand") &&
-          !ISE.getPredicateOperand(OperandNode).AlwaysOps.empty())
+      // If the instruction expects a predicate or optional def operand, we
+      // codegen this by setting the operand to it's default value if it has a
+      // non-empty DefaultOps field.
+      if ((OperandNode->isSubClassOf("PredicateOperand") ||
+           OperandNode->isSubClassOf("OptionalDefOperand")) &&
+          !ISE.getDefaultOperand(OperandNode).DefaultOps.empty())
         continue;
        
       // Verify that we didn't run out of provided operands.
@@ -1246,47 +1247,54 @@
   }
 }
 
-void DAGISelEmitter::ParsePredicateOperands() {
-  std::vector<Record*> PredOps =
-    Records.getAllDerivedDefinitions("PredicateOperand");
+void DAGISelEmitter::ParseDefaultOperands() {
+  std::vector<Record*> DefaultOps[2];
+  DefaultOps[0] = Records.getAllDerivedDefinitions("PredicateOperand");
+  DefaultOps[1] = Records.getAllDerivedDefinitions("OptionalDefOperand");
 
   // Find some SDNode.
   assert(!SDNodes.empty() && "No SDNodes parsed?");
   Init *SomeSDNode = new DefInit(SDNodes.begin()->first);
   
-  for (unsigned i = 0, e = PredOps.size(); i != e; ++i) {
-    DagInit *AlwaysInfo = PredOps[i]->getValueAsDag("ExecuteAlways");
-    
-    // Clone the AlwaysInfo dag node, changing the operator from 'ops' to
-    // SomeSDnode so that we can parse this.
-    std::vector<std::pair<Init*, std::string> > Ops;
-    for (unsigned op = 0, e = AlwaysInfo->getNumArgs(); op != e; ++op)
-      Ops.push_back(std::make_pair(AlwaysInfo->getArg(op),
-                                   AlwaysInfo->getArgName(op)));
-    DagInit *DI = new DagInit(SomeSDNode, Ops);
-    
-    // Create a TreePattern to parse this.
-    TreePattern P(PredOps[i], DI, false, *this);
-    assert(P.getNumTrees() == 1 && "This ctor can only produce one tree!");
-
-    // Copy the operands over into a DAGPredicateOperand.
-    DAGPredicateOperand PredOpInfo;
-    
-    TreePatternNode *T = P.getTree(0);
-    for (unsigned op = 0, e = T->getNumChildren(); op != e; ++op) {
-      TreePatternNode *TPN = T->getChild(op);
-      while (TPN->ApplyTypeConstraints(P, false))
-        /* Resolve all types */;
-      
-      if (TPN->ContainsUnresolvedType())
-        throw "Value #" + utostr(i) + " of PredicateOperand '" +
-              PredOps[i]->getName() + "' doesn't have a concrete type!";
+  for (unsigned iter = 0; iter != 2; ++iter) {
+    for (unsigned i = 0, e = DefaultOps[iter].size(); i != e; ++i) {
+      DagInit *DefaultInfo = DefaultOps[iter][i]->getValueAsDag("DefaultOps");
+    
+      // Clone the DefaultInfo dag node, changing the operator from 'ops' to
+      // SomeSDnode so that we can parse this.
+      std::vector<std::pair<Init*, std::string> > Ops;
+      for (unsigned op = 0, e = DefaultInfo->getNumArgs(); op != e; ++op)
+        Ops.push_back(std::make_pair(DefaultInfo->getArg(op),
+                                     DefaultInfo->getArgName(op)));
+      DagInit *DI = new DagInit(SomeSDNode, Ops);
+    
+      // Create a TreePattern to parse this.
+      TreePattern P(DefaultOps[iter][i], DI, false, *this);
+      assert(P.getNumTrees() == 1 && "This ctor can only produce one tree!");
+
+      // Copy the operands over into a DAGDefaultOperand.
+      DAGDefaultOperand DefaultOpInfo;
+    
+      TreePatternNode *T = P.getTree(0);
+      for (unsigned op = 0, e = T->getNumChildren(); op != e; ++op) {
+        TreePatternNode *TPN = T->getChild(op);
+        while (TPN->ApplyTypeConstraints(P, false))
+          /* Resolve all types */;
+      
+        if (TPN->ContainsUnresolvedType())
+          if (iter == 0)
+            throw "Value #" + utostr(i) + " of PredicateOperand '" +
+              DefaultOps[iter][i]->getName() + "' doesn't have a concrete type!";
+          else
+            throw "Value #" + utostr(i) + " of OptionalDefOperand '" +
+              DefaultOps[iter][i]->getName() + "' doesn't have a concrete type!";
       
-      PredOpInfo.AlwaysOps.push_back(TPN);
-    }
+        DefaultOpInfo.DefaultOps.push_back(TPN);
+      }
 
-    // Insert it into the PredicateOperands map so we can find it later.
-    PredicateOperands[PredOps[i]] = PredOpInfo;
+      // Insert it into the DefaultOperands map so we can find it later.
+      DefaultOperands[DefaultOps[iter][i]] = DefaultOpInfo;
+    }
   }
 }
 
@@ -1550,13 +1558,14 @@
         I->error("Operand #" + utostr(i) + " in operands list has no name!");
 
       if (!InstInputsCheck.count(OpName)) {
-        // If this is an predicate operand with an ExecuteAlways set filled in,
-        // we can ignore this.  When we codegen it, we will do so as always
-        // executed.
-        if (Op.Rec->isSubClassOf("PredicateOperand")) {
-          // Does it have a non-empty ExecuteAlways field?  If so, ignore this
+        // If this is an predicate operand or optional def operand with an
+        // DefaultOps set filled in, we can ignore this.  When we codegen it,
+        // we will do so as always executed.
+        if (Op.Rec->isSubClassOf("PredicateOperand") ||
+            Op.Rec->isSubClassOf("OptionalDefOperand")) {
+          // Does it have a non-empty DefaultOps field?  If so, ignore this
           // operand.
-          if (!getPredicateOperand(Op.Rec).AlwaysOps.empty())
+          if (!getDefaultOperand(Op.Rec).DefaultOps.empty())
             continue;
         }
         I->error("Operand $" + OpName +
@@ -2813,19 +2822,20 @@
         // If this is a normal operand or a predicate operand without
         // 'execute always', emit it.
         Record *OperandNode = II.OperandList[InstOpNo].Rec;
-        if (!OperandNode->isSubClassOf("PredicateOperand") ||
-            ISE.getPredicateOperand(OperandNode).AlwaysOps.empty()) {
+        if ((!OperandNode->isSubClassOf("PredicateOperand") &&
+             !OperandNode->isSubClassOf("OptionalDefOperand")) ||
+            ISE.getDefaultOperand(OperandNode).DefaultOps.empty()) {
           Ops = EmitResultCode(N->getChild(ChildNo), RetSelected, 
                                InFlagDecled, ResNodeDecled);
           AllOps.insert(AllOps.end(), Ops.begin(), Ops.end());
           ++ChildNo;
         } else {
-          // Otherwise, this is a predicate operand, emit the 'execute always'
-          // operands.
-          const DAGPredicateOperand &Pred =
-            ISE.getPredicateOperand(II.OperandList[InstOpNo].Rec);
-          for (unsigned i = 0, e = Pred.AlwaysOps.size(); i != e; ++i) {
-            Ops = EmitResultCode(Pred.AlwaysOps[i], RetSelected, 
+          // Otherwise, this is a predicate or optional def operand, emit the
+          // 'default ops' operands.
+          const DAGDefaultOperand &DefaultOp =
+            ISE.getDefaultOperand(II.OperandList[InstOpNo].Rec);
+          for (unsigned i = 0, e = DefaultOp.DefaultOps.size(); i != e; ++i) {
+            Ops = EmitResultCode(DefaultOp.DefaultOps[i], RetSelected, 
                                  InFlagDecled, ResNodeDecled);
             AllOps.insert(AllOps.end(), Ops.begin(), Ops.end());
             NumEAInputs += Ops.size();
@@ -3962,7 +3972,7 @@
   ParseNodeTransforms(OS);
   ParseComplexPatterns();
   ParsePatternFragments(OS);
-  ParsePredicateOperands();
+  ParseDefaultOperands();
   ParseInstructions();
   ParsePatterns();
   

Modified: llvm/trunk/utils/TableGen/DAGISelEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/DAGISelEmitter.h?rev=37933&r1=37932&r2=37933&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/DAGISelEmitter.h (original)
+++ llvm/trunk/utils/TableGen/DAGISelEmitter.h Thu Jul  5 20:05:26 2007
@@ -343,10 +343,10 @@
     TreePatternNode *ParseTreePattern(DagInit *DI);
   };
 
-  /// DAGPredicateOperand - One of these is created for each PredicateOperand
-  /// that has a set ExecuteAlways field.
-  struct DAGPredicateOperand {
-    std::vector<TreePatternNode*> AlwaysOps;
+  /// DAGDefaultOperand - One of these is created for each PredicateOperand
+  /// or OptionalDefOperand that has a set ExecuteAlways / DefaultOps field.
+  struct DAGDefaultOperand {
+    std::vector<TreePatternNode*> DefaultOps;
   };
 
   class DAGInstruction {
@@ -430,7 +430,7 @@
   std::map<Record*, std::pair<Record*, std::string> > SDNodeXForms;
   std::map<Record*, ComplexPattern> ComplexPatterns;
   std::map<Record*, TreePattern*> PatternFragments;
-  std::map<Record*, DAGPredicateOperand> PredicateOperands;
+  std::map<Record*, DAGDefaultOperand> DefaultOperands;
   std::map<Record*, DAGInstruction> Instructions;
   
   // Specific SDNode definitions:
@@ -485,9 +485,9 @@
     abort();
   }
   
-  const DAGPredicateOperand &getPredicateOperand(Record *R) {
-    assert(PredicateOperands.count(R) &&"Isn't an analyzed predicate operand!");
-    return PredicateOperands.find(R)->second;
+  const DAGDefaultOperand &getDefaultOperand(Record *R) {
+    assert(DefaultOperands.count(R) &&"Isn't an analyzed default operand!");
+    return DefaultOperands.find(R)->second;
   }
   
   TreePattern *getPatternFragment(Record *R) const {
@@ -516,7 +516,7 @@
   void ParseNodeTransforms(std::ostream &OS);
   void ParseComplexPatterns();
   void ParsePatternFragments(std::ostream &OS);
-  void ParsePredicateOperands();
+  void ParseDefaultOperands();
   void ParseInstructions();
   void ParsePatterns();
   void GenerateVariants();





More information about the llvm-commits mailing list