Added an index field to GlobalAddressSDNode so it can represent X+12, etc.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 30 Nov 2005 02:04:11 +0000 (02:04 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 30 Nov 2005 02:04:11 +0000 (02:04 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24523 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAG.h
include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp

index 2523b5ef912384a5176db1a7aae7552d831b94ac..2f9ffda633686121ad8d3388b3fa4e8b139ee838 100644 (file)
@@ -110,7 +110,8 @@ public:
   SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT);
   SDOperand getConstantFP(double Val, MVT::ValueType VT);
   SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT);
-  SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT);
+  SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
+                                   int offset=0);
   SDOperand getFrameIndex(int FI, MVT::ValueType VT);
   SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT);
   SDOperand getConstantPool(Constant *C, MVT::ValueType VT);
@@ -283,6 +284,9 @@ public:
   void SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
                     SDOperand Op1, SDOperand Op2, SDOperand Op3, SDOperand Op4,
                     SDOperand Op5);
+  void SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
+                    SDOperand Op1, SDOperand Op2, SDOperand Op3, SDOperand Op4,
+                    SDOperand Op5, SDOperand Op6);
   void SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1, 
                     MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
   void SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
index f6a6201678512a2a18a726f828681e44bcb3425b..b9cfa1930ce77b641eead28373a21dd88aaaef3f 100644 (file)
@@ -795,6 +795,21 @@ protected:
     Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
     Op4.Val->Uses.push_back(this);
   }
+  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
+                   SDOperand Op4, SDOperand Op5) {
+    assert(NumOperands == 0 && "Should not have operands yet!");
+    OperandList = new SDOperand[6];
+    OperandList[0] = Op0;
+    OperandList[1] = Op1;
+    OperandList[2] = Op2;
+    OperandList[3] = Op3;
+    OperandList[4] = Op4;
+    OperandList[5] = Op5;
+    NumOperands = 6;
+    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
+    Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
+    Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
+  }
   void addUser(SDNode *User) {
     Uses.push_back(User);
   }
@@ -923,15 +938,19 @@ public:
 
 class GlobalAddressSDNode : public SDNode {
   GlobalValue *TheGlobal;
+  int offset;
 protected:
   friend class SelectionDAG;
-  GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT)
+  GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
+                      int o=0)
     : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) {
     TheGlobal = const_cast<GlobalValue*>(GA);
+    offset = o;
   }
 public:
 
   GlobalValue *getGlobal() const { return TheGlobal; }
+  int getOffset() const { return offset; }
 
   static bool classof(const GlobalAddressSDNode *) { return true; }
   static bool classof(const SDNode *N) {
index e6f33761e17018ff11a83438b373c373b585f51b..f250a7bc050f5a006774c56d1496e549bf0b2df8 100644 (file)
@@ -1123,7 +1123,7 @@ void SimpleSched::EmitNode(NodeInfo *NI) {
         MI->addRegOperand(R->getReg(), MachineOperand::Use);
       } else if (GlobalAddressSDNode *TGA =
                        dyn_cast<GlobalAddressSDNode>(Node->getOperand(i))) {
-        MI->addGlobalAddressOperand(TGA->getGlobal(), false, 0);
+        MI->addGlobalAddressOperand(TGA->getGlobal(), false, TGA->getOffset());
       } else if (BasicBlockSDNode *BB =
                        dyn_cast<BasicBlockSDNode>(Node->getOperand(i))) {
         MI->addMachineBasicBlockOperand(BB->getBasicBlock());
index 1eb95864c079a2f772636461e7e5319a2a027138..606ed5234b47d271c96d8aec454b8efcf7591754 100644 (file)
@@ -500,10 +500,10 @@ SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV,
 }
 
 SDOperand SelectionDAG::getTargetGlobalAddress(const GlobalValue *GV,
-                                               MVT::ValueType VT) {
+                                               MVT::ValueType VT, int offset) {
   SDNode *&N = TargetGlobalValues[GV];
   if (N) return SDOperand(N, 0);
-  N = new GlobalAddressSDNode(true, GV, VT);
+  N = new GlobalAddressSDNode(true, GV, VT, offset);
   AllNodes.push_back(N);
   return SDOperand(N, 0);
 }
@@ -1457,6 +1457,16 @@ void SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
   N->setOperands(Op1, Op2, Op3, Op4, Op5);
 }
 
+void SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc,
+                                MVT::ValueType VT, SDOperand Op1,
+                                SDOperand Op2, SDOperand Op3, SDOperand Op4,
+                                SDOperand Op5, SDOperand Op6) {
+  RemoveNodeFromCSEMaps(N);
+  N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc);
+  N->setValueTypes(VT);
+  N->setOperands(Op1, Op2, Op3, Op4, Op5, Op6);
+}
+
 void SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, 
                                 MVT::ValueType VT1, MVT::ValueType VT2,
                                 SDOperand Op1, SDOperand Op2) {
@@ -1859,8 +1869,13 @@ void SDNode::dump(const SelectionDAG *G) const {
     std::cerr << "<" << CSDN->getValue() << ">";
   } else if (const GlobalAddressSDNode *GADN =
              dyn_cast<GlobalAddressSDNode>(this)) {
+    int offset = GADN->getOffset();
     std::cerr << "<";
     WriteAsOperand(std::cerr, GADN->getGlobal()) << ">";
+    if (offset > 0)
+      std::cerr << " + " << offset;
+    else
+      std::cerr << " " << offset;
   } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
     std::cerr << "<" << FIDN->getIndex() << ">";
   } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
index d554a7d392e4b9fd8195b2cea3f9efdfbaee83a8..61e4e0212420c1bebafa176cda64335ef0a0c2ac 100644 (file)
@@ -70,7 +70,12 @@ std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
     Op += ": " + ftostr(CSDN->getValue());
   } else if (const GlobalAddressSDNode *GADN =
              dyn_cast<GlobalAddressSDNode>(Node)) {
+    int offset = GADN->getOffset();
     Op += ": " + GADN->getGlobal()->getName();
+    if (offset > 0)
+      Op += "+" + itostr(offset);
+    else
+      Op += itostr(offset);
   } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(Node)) {
     Op += " " + itostr(FIDN->getIndex());
   } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){