OSDN Git Service

Make sure to use the result of the pattern to infer the result type of the
authorChris Lattner <sabre@nondot.org>
Tue, 20 Jun 2006 00:18:02 +0000 (00:18 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 20 Jun 2006 00:18:02 +0000 (00:18 +0000)
instruction, and the result type of the instruction to refine the pattern.
This allows us to write things like this:

def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (v2i64 VR128:$src)>;

as:
def : Pat<(v2i64 (bitconvert (v16i8 VR128:$src))), (VR128:$src)>

and fixes a ppc64 issue.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28863 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/DAGISelEmitter.cpp

index c46b088..5febdda 100644 (file)
@@ -1554,22 +1554,6 @@ void DAGISelEmitter::ParsePatterns() {
     // Inline pattern fragments into it.
     Pattern->InlinePatternFragments();
     
-    // Infer as many types as possible.  If we cannot infer all of them, we can
-    // never do anything with this pattern: report it to the user.
-    if (!Pattern->InferAllTypes())
-      Pattern->error("Could not infer all types in pattern!");
-
-    // Validate that the input pattern is correct.
-    {
-      std::map<std::string, TreePatternNode*> InstInputs;
-      std::map<std::string, TreePatternNode*> InstResults;
-      std::vector<Record*> InstImpInputs;
-      std::vector<Record*> InstImpResults;
-      FindPatternInputsAndOutputs(Pattern, Pattern->getOnlyTree(),
-                                  InstInputs, InstResults,
-                                  InstImpInputs, InstImpResults);
-    }
-    
     ListInit *LI = Patterns[i]->getValueAsListInit("ResultInstrs");
     if (LI->getSize() == 0) continue;  // no pattern.
     
@@ -1578,15 +1562,43 @@ void DAGISelEmitter::ParsePatterns() {
     
     // Inline pattern fragments into it.
     Result->InlinePatternFragments();
-    
-    // Infer as many types as possible.  If we cannot infer all of them, we can
-    // never do anything with this pattern: report it to the user.
-    if (!Result->InferAllTypes())
-      Result->error("Could not infer all types in pattern result!");
-   
+
     if (Result->getNumTrees() != 1)
       Result->error("Cannot handle instructions producing instructions "
                     "with temporaries yet!");
+    
+    bool IterateInference;
+    do {
+      // Infer as many types as possible.  If we cannot infer all of them, we
+      // can never do anything with this pattern: report it to the user.
+      if (!Pattern->InferAllTypes())
+        Pattern->error("Could not infer all types in pattern!");
+      
+      // Infer as many types as possible.  If we cannot infer all of them, we can
+      // never do anything with this pattern: report it to the user.
+      if (!Result->InferAllTypes())
+        Result->error("Could not infer all types in pattern result!");
+     
+      // Apply the type of the result to the source pattern.  This helps us
+      // resolve cases where the input type is known to be a pointer type (which
+      // is considered resolved), but the result knows it needs to be 32- or
+      // 64-bits.  Infer the other way for good measure.
+      IterateInference = Pattern->getOnlyTree()->
+        UpdateNodeType(Result->getOnlyTree()->getExtTypes(), *Result);
+      IterateInference |= Result->getOnlyTree()->
+        UpdateNodeType(Pattern->getOnlyTree()->getExtTypes(), *Result);
+    } while (IterateInference);
+    
+    // Validate that the input pattern is correct.
+    {
+      std::map<std::string, TreePatternNode*> InstInputs;
+      std::map<std::string, TreePatternNode*> InstResults;
+      std::vector<Record*> InstImpInputs;
+      std::vector<Record*> InstImpResults;
+      FindPatternInputsAndOutputs(Pattern, Pattern->getOnlyTree(),
+                                  InstInputs, InstResults,
+                                  InstImpInputs, InstImpResults);
+    }
 
     // Promote the xform function to be an explicit node if set.
     std::vector<TreePatternNode*> ResultNodeOperands;