[llvm-commits] [llvm] r45648 - in /llvm/trunk/utils/TableGen: InstrInfoEmitter.cpp InstrInfoEmitter.h

Chris Lattner sabre at nondot.org
Sat Jan 5 18:16:26 PST 2008


Author: lattner
Date: Sat Jan  5 20:16:26 2008
New Revision: 45648

URL: http://llvm.org/viewvc/llvm-project?rev=45648&view=rev
Log:
remove some old hacky code that tried to infer whether a store 
occured in a pattern, but failed miserably.  The new code works for
any instruction that has a store in its pattern, including all the 
x86 mem op mem instructions.

The only target-independent code that uses this is branch folding,
so this won't change anything in practice.

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

Modified: llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp?rev=45648&r1=45647&r2=45648&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/InstrInfoEmitter.cpp Sat Jan  5 20:16:26 2008
@@ -141,6 +141,51 @@
 // Instruction Analysis
 //===----------------------------------------------------------------------===//
 
+class InstAnalyzer {
+  const CodeGenDAGPatterns &CDP;
+  bool &isStore;
+  bool &isLoad;
+  bool &NeverHasSideEffects;
+public:
+  InstAnalyzer(const CodeGenDAGPatterns &cdp,
+               bool &isstore, bool &isload, bool &nhse)
+    : CDP(cdp), isStore(isstore), isLoad(isload), NeverHasSideEffects(nhse) {
+  }
+  
+  void Analyze(Record *InstRecord) {
+    const TreePattern *Pattern = CDP.getInstruction(InstRecord).getPattern();
+    if (Pattern == 0) return;  // No pattern.
+    
+    // Assume there is no side-effect unless we see one.
+    // FIXME: Enable this.
+    //NeverHasSideEffects = true;
+
+    
+    // FIXME: Assume only the first tree is the pattern. The others are clobber
+    // nodes.
+    AnalyzeNode(Pattern->getTree(0));
+  }
+  
+private:
+  void AnalyzeNode(const TreePatternNode *N) {
+    if (N->isLeaf()) {
+      return;
+    }
+
+    if (N->getOperator()->getName() != "set") {
+      // Get information about the SDNode for the operator.
+      const SDNodeInfo &OpInfo = CDP.getSDNodeInfo(N->getOperator());
+      
+      if (OpInfo.getEnumName() == "ISD::STORE")
+        isStore = true;
+    }
+
+    for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
+      AnalyzeNode(N->getChild(i));
+  }
+  
+};
+
 void InstrInfoEmitter::InferFromPattern(const CodeGenInstruction &Inst, 
                                         bool &isStore, bool &isLoad, 
                                         bool &NeverHasSideEffects) {
@@ -148,26 +193,11 @@
   isLoad              = Inst.isLoad;
   NeverHasSideEffects = Inst.neverHasSideEffects;
   
-  const TreePattern *Pattern = CDP.getInstruction(Inst.TheDef).getPattern();
-  if (Pattern == 0) return;  // No pattern.
-
-  // FIXME: Change this to use pattern info.
-  if (dynamic_cast<ListInit*>(Inst.TheDef->getValueInit("Pattern"))) {
-    ListInit *LI = Inst.TheDef->getValueAsListInit("Pattern");
-    if (LI && LI->getSize() > 0) {
-      DagInit *Dag = (DagInit *)LI->getElement(0);
-      DefInit *OpDef = dynamic_cast<DefInit*>(Dag->getOperator());
-      if (OpDef) {
-        Record *Operator = OpDef->getDef();
-        if (Operator->isSubClassOf("SDNode")) {
-          const std::string Opcode = Operator->getValueAsString("Opcode");
-          if (Opcode == "ISD::STORE" || Opcode == "ISD::TRUNCSTORE")
-            isStore = true;
-        }
-      }
-    }
-  }
+  InstAnalyzer(CDP, isStore, isLoad, NeverHasSideEffects).Analyze(Inst.TheDef);
   
+  // If the .td file explicitly says there is no side effect, believe it.
+  if (Inst.neverHasSideEffects)
+    NeverHasSideEffects = true;
 }
 
 

Modified: llvm/trunk/utils/TableGen/InstrInfoEmitter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/InstrInfoEmitter.h?rev=45648&r1=45647&r2=45648&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/InstrInfoEmitter.h (original)
+++ llvm/trunk/utils/TableGen/InstrInfoEmitter.h Sat Jan  5 20:16:26 2008
@@ -29,7 +29,7 @@
 
 class InstrInfoEmitter : public TableGenBackend {
   RecordKeeper &Records;
-  CodeGenDAGPatterns CDP;
+  const CodeGenDAGPatterns CDP;
   std::map<std::string, unsigned> ItinClassMap;
   
 public:





More information about the llvm-commits mailing list