R600/SI: add folding helper
authorChristian Konig <christian.koenig@amd.com>
Tue, 26 Feb 2013 17:52:16 +0000 (17:52 +0000)
committerChristian Konig <christian.koenig@amd.com>
Tue, 26 Feb 2013 17:52:16 +0000 (17:52 +0000)
Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Tom Stellard <thomas.stellard@amd.com>
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176100 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/R600/AMDGPUISelLowering.h
lib/Target/R600/AMDILISelDAGToDAG.cpp
lib/Target/R600/SIISelLowering.cpp
lib/Target/R600/SIISelLowering.h

index 404f6201a55d0b5e032011c502671b54f1b0bbaf..9e7d997d4a0d8c81405e891024b7abcd79b5cd8e 100644 (file)
@@ -65,6 +65,10 @@ public:
   SDValue LowerMinMax(SDValue Op, SelectionDAG &DAG) const;
   virtual const char* getTargetNodeName(unsigned Opcode) const;
 
+  virtual SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const {
+    return N;
+  }
+
 // Functions defined in AMDILISelLowering.cpp
 public:
 
index 2e726e949db86a8c1d97a339137f1f9150894920..2f70fa9e31d7b29dedfa42ba3adecaa7c362cc4b 100644 (file)
@@ -43,6 +43,7 @@ public:
 
   SDNode *Select(SDNode *N);
   virtual const char *getPassName() const;
+  virtual void PostprocessISelDAG();
 
 private:
   inline SDValue getSmallIPtrImm(unsigned Imm);
@@ -575,3 +576,21 @@ bool AMDGPUDAGToDAGISel::SelectADDRIndirect(SDValue Addr, SDValue &Base,
 
   return true;
 }
+
+void AMDGPUDAGToDAGISel::PostprocessISelDAG() {
+
+  // Go over all selected nodes and try to fold them a bit more
+  const AMDGPUTargetLowering& Lowering = ((const AMDGPUTargetLowering&)TLI);
+  for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
+       E = CurDAG->allnodes_end(); I != E; ++I) {
+
+    MachineSDNode *Node = dyn_cast<MachineSDNode>(I);
+    if (!Node)
+      continue;
+
+    SDNode *ResNode = Lowering.PostISelFolding(Node, *CurDAG);
+    if (ResNode != Node)
+      ReplaceUses(Node, ResNode);
+  }
+}
+
index 212e3f23a8496b7663abd082ebd8145e9c761d43..13173e89d5358201b8aca07002154085771b5976 100644 (file)
@@ -357,3 +357,9 @@ SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
   }
   return SDValue();
 }
+
+SDNode *SITargetLowering::PostISelFolding(MachineSDNode *Node,
+                                          SelectionDAG &DAG) const {
+  // TODO: Implement immediate folding
+  return Node;
+}
index 5d048f85007a937c5e6ad5e25804cb5b5f5671a4..71f99acd0cc52f540d0444d1cd1c68d085d036dd 100644 (file)
@@ -41,6 +41,7 @@ public:
   virtual EVT getSetCCResultType(EVT VT) const;
   virtual SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const;
   virtual SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const;
+  virtual SDNode *PostISelFolding(MachineSDNode *N, SelectionDAG &DAG) const;
 };
 
 } // End namespace llvm