Change ConstantPoolSDNode to actually hold the Constant itself instead of
authorChris Lattner <sabre@nondot.org>
Fri, 26 Aug 2005 17:15:30 +0000 (17:15 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 26 Aug 2005 17:15:30 +0000 (17:15 +0000)
putting it into the constant pool.  This allows the isel machinery to
create constants that it will end up deciding are not needed, without them
ending up in the resultant function constant pool.

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

include/llvm/CodeGen/SelectionDAG.h
include/llvm/CodeGen/SelectionDAGNodes.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp
lib/Target/Alpha/AlphaISelPattern.cpp
lib/Target/IA64/IA64ISelPattern.cpp
lib/Target/PowerPC/PPCISelDAGToDAG.cpp
lib/Target/PowerPC/PPCISelPattern.cpp
lib/Target/X86/X86ISelPattern.cpp

index df17366dd8e864d1f77b60087160ea9ed9414a2d..97934a536fed678fd425e53f0c58ac64087ddb13 100644 (file)
@@ -100,8 +100,8 @@ public:
   SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT);
   SDOperand getFrameIndex(int FI, MVT::ValueType VT);
   SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT);
-  SDOperand getConstantPool(unsigned CPIdx, MVT::ValueType VT);
-  SDOperand getTargetConstantPool(unsigned CPIdx, MVT::ValueType VT);
+  SDOperand getConstantPool(Constant *C, MVT::ValueType VT);
+  SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT);
   SDOperand getBasicBlock(MachineBasicBlock *MBB);
   SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
   SDOperand getValueType(MVT::ValueType);
@@ -320,7 +320,8 @@ private:
   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstants;
   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> ConstantFPs;
   std::map<int, SDNode*> FrameIndices, TargetFrameIndices;
-  std::map<unsigned, SDNode*> ConstantPoolIndices, TargetConstantPoolIndices;
+  std::map<Constant *, SDNode*> ConstantPoolIndices;
+  std::map<Constant *, SDNode*> TargetConstantPoolIndices;
   std::map<MachineBasicBlock *, SDNode*> BBNodes;
   std::vector<SDNode*> ValueTypeNodes;
   std::map<std::string, SDNode*> ExternalSymbols;
index 9f1769e0d69352bf1dff9d760452177a7c825545..40b73eec5a29717bf04219703309dc293226d1a9 100644 (file)
@@ -828,15 +828,15 @@ public:
 };
 
 class ConstantPoolSDNode : public SDNode {
-  unsigned CPI;
+  Constant *C;
 protected:
   friend class SelectionDAG;
-  ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT, bool isTarget)
+  ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget)
     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
-      CPI(cpi) {}
+    C(c) {}
 public:
 
-  unsigned getIndex() const { return CPI; }
+  Constant *get() const { return C; }
 
   static bool classof(const ConstantPoolSDNode *) { return true; }
   static bool classof(const SDNode *N) {
index d94e8026dd2cce90c2e33c5610b6114a1e8adf77..dc706c1eeacdfa12a94044f3544f058aebba08bf 100644 (file)
@@ -12,7 +12,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/CodeGen/SelectionDAG.h"
-#include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/Support/MathExtras.h"
@@ -248,9 +247,7 @@ SDOperand SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned,
   if (TLI.isLittleEndian()) FF <<= 32;
   static Constant *FudgeFactor = ConstantUInt::get(Type::ULongTy, FF);
 
-  MachineConstantPool *CP = DAG.getMachineFunction().getConstantPool();
-  SDOperand CPIdx = DAG.getConstantPool(CP->getConstantPoolIndex(FudgeFactor),
-                                        TLI.getPointerTy());
+  SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
   CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
   SDOperand FudgeInReg;
   if (DestVT == MVT::f32)
@@ -529,8 +526,6 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
 
     if (!isLegal) {
       // Otherwise we need to spill the constant to memory.
-      MachineConstantPool *CP = DAG.getMachineFunction().getConstantPool();
-
       bool Extend = false;
 
       // If a FP immediate is precise when represented as a float, we put it
@@ -549,8 +544,7 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) {
         Extend = true;
       }
 
-      SDOperand CPIdx = DAG.getConstantPool(CP->getConstantPoolIndex(LLVMC),
-                                            TLI.getPointerTy());
+      SDOperand CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy());
       if (Extend) {
         Result = DAG.getExtLoad(ISD::EXTLOAD, MVT::f64, DAG.getEntryNode(),
                                 CPIdx, DAG.getSrcValue(NULL), MVT::f32);
@@ -2751,9 +2745,7 @@ ExpandIntToFP(bool isSigned, MVT::ValueType DestTy, SDOperand Source) {
     if (TLI.isLittleEndian()) FF <<= 32;
     static Constant *FudgeFactor = ConstantUInt::get(Type::ULongTy, FF);
 
-    MachineConstantPool *CP = DAG.getMachineFunction().getConstantPool();
-    SDOperand CPIdx = DAG.getConstantPool(CP->getConstantPoolIndex(FudgeFactor),
-                                          TLI.getPointerTy());
+    SDOperand CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy());
     CPIdx = DAG.getNode(ISD::ADD, TLI.getPointerTy(), CPIdx, CstOffset);
     SDOperand FudgeInReg;
     if (DestTy == MVT::f32)
index 20236f8adff4345290f372196cc9f30c0c0e9701..33c9167f69ba950ddffba861a1458eebd9ce16be 100644 (file)
@@ -13,6 +13,7 @@
 //===----------------------------------------------------------------------===//
 
 #define DEBUG_TYPE "sched"
+#include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/SelectionDAGISel.h"
 #include "llvm/CodeGen/SelectionDAG.h"
@@ -38,12 +39,14 @@ namespace {
     const TargetInstrInfo &TII;
     const MRegisterInfo &MRI;
     SSARegMap *RegMap;
+    MachineConstantPool *ConstPool;
     
     std::map<SDNode *, unsigned> EmittedOps;
   public:
     SimpleSched(SelectionDAG &D, MachineBasicBlock *bb)
       : DAG(D), BB(bb), TM(D.getTarget()), TII(*TM.getInstrInfo()),
-        MRI(*TM.getRegisterInfo()), RegMap(BB->getParent()->getSSARegMap()) {
+        MRI(*TM.getRegisterInfo()), RegMap(BB->getParent()->getSSARegMap()),
+        ConstPool(BB->getParent()->getConstantPool()) {
       assert(&TII && "Target doesn't provide instr info?");
       assert(&MRI && "Target doesn't provide register info?");
     }
@@ -148,7 +151,8 @@ unsigned SimpleSched::Emit(SDOperand Op) {
         MI->addFrameIndexOperand(FI->getIndex());
       } else if (ConstantPoolSDNode *CP = 
                     dyn_cast<ConstantPoolSDNode>(Op.getOperand(i))) {
-        MI->addConstantPoolIndexOperand(CP->getIndex());
+        unsigned Idx = ConstPool->getConstantPoolIndex(CP->get());
+        MI->addConstantPoolIndexOperand(Idx);
       } else if (ExternalSymbolSDNode *ES = 
                  dyn_cast<ExternalSymbolSDNode>(Op.getOperand(i))) {
         MI->addExternalSymbolOperand(ES->getSymbol(), false);
index 2bcbd9857d0f42bda10cf678d252b9b338aa136d..25fba29845e40b3908aa57dbe2d952ca15029eb9 100644 (file)
@@ -265,10 +265,10 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
     TargetFrameIndices.erase(cast<FrameIndexSDNode>(N)->getIndex());
     break;
   case ISD::ConstantPool:
-    ConstantPoolIndices.erase(cast<ConstantPoolSDNode>(N)->getIndex());
+    ConstantPoolIndices.erase(cast<ConstantPoolSDNode>(N)->get());
     break;
   case ISD::TargetConstantPool:
-    TargetConstantPoolIndices.erase(cast<ConstantPoolSDNode>(N)->getIndex());
+    TargetConstantPoolIndices.erase(cast<ConstantPoolSDNode>(N)->get());
     break;
   case ISD::BasicBlock:
     BBNodes.erase(cast<BasicBlockSDNode>(N)->getBasicBlock());
@@ -452,19 +452,18 @@ SDOperand SelectionDAG::getTargetFrameIndex(int FI, MVT::ValueType VT) {
   return SDOperand(N, 0);
 }
 
-SDOperand SelectionDAG::getConstantPool(unsigned CPIdx, MVT::ValueType VT) {
-  SDNode *N = ConstantPoolIndices[CPIdx];
+SDOperand SelectionDAG::getConstantPool(Constant *C, MVT::ValueType VT) {
+  SDNode *&N = ConstantPoolIndices[C];
   if (N) return SDOperand(N, 0);
-  N = new ConstantPoolSDNode(CPIdx, VT, false);
+  N = new ConstantPoolSDNode(C, VT, false);
   AllNodes.push_back(N);
   return SDOperand(N, 0);
 }
 
-SDOperand SelectionDAG::getTargetConstantPool(unsigned CPIdx,
-                                              MVT::ValueType VT) {
-  SDNode *N = TargetConstantPoolIndices[CPIdx];
+SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT) {
+  SDNode *&N = TargetConstantPoolIndices[C];
   if (N) return SDOperand(N, 0);
-  N = new ConstantPoolSDNode(CPIdx, VT, true);
+  N = new ConstantPoolSDNode(C, VT, true);
   AllNodes.push_back(N);
   return SDOperand(N, 0);
 }
@@ -2134,8 +2133,8 @@ const char *SDNode::getOperationName(const SelectionDAG *G) const {
   case ISD::BasicBlock:    return "BasicBlock";
   case ISD::Register:      return "Register";
   case ISD::ExternalSymbol: return "ExternalSymbol";
-  case ISD::ConstantPool:  return "ConstantPoolIndex";
-  case ISD::TargetConstantPool:  return "TargetConstantPoolIndex";
+  case ISD::ConstantPool:  return "ConstantPool";
+  case ISD::TargetConstantPool:  return "TargetConstantPool";
   case ISD::CopyToReg:     return "CopyToReg";
   case ISD::CopyFromReg:   return "CopyFromReg";
   case ISD::ImplicitDef:   return "ImplicitDef";
@@ -2287,7 +2286,7 @@ void SDNode::dump(const SelectionDAG *G) const {
   } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) {
     std::cerr << "<" << FIDN->getIndex() << ">";
   } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){
-    std::cerr << "<" << CP->getIndex() << ">";
+    std::cerr << "<" << *CP->get() << ">";
   } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) {
     std::cerr << "<";
     const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
index bb0524db69d36402c9d43d8747b359fea7f36b85..d69004a557fa62cbad4992ecef8db9ba714ee2e3 100644 (file)
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Constants.h"
+#include "llvm/Function.h"
 #include "llvm/CodeGen/SelectionDAG.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/Target/MRegisterInfo.h"
 #include "llvm/Target/TargetMachine.h"
-#include "llvm/Function.h"
 #include "llvm/Support/GraphWriter.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/Config/config.h"
@@ -67,7 +68,8 @@ std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node,
   } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(Node)) {
     Op += " " + itostr(FIDN->getIndex());
   } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Node)){
-    Op += "<" + utostr(CP->getIndex()) + ">";
+    if (ConstantFP *CFP = dyn_cast<ConstantFP>(CP->get()))
+      Op += "<" + ftostr(CFP->getValue()) + ">";
   } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(Node)) {
     Op = "BB: ";
     const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock();
index e559852d2b9c71a8179e07d1d4a6f361507e23f1..cf5245d19c3914e1a42952e4c1c28c4f169a1400 100644 (file)
@@ -1216,7 +1216,8 @@ unsigned AlphaISel::SelectExpr(SDOperand N) {
     return Result;
 
   case ISD::ConstantPool:
-    Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
+    Tmp1 = BB->getParent()->getConstantPool()->
+       getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
     AlphaLowering.restoreGP(BB);
     Tmp2 = MakeReg(MVT::i64);
     BuildMI(BB, Alpha::LDAHr, 2, Tmp2).addConstantPoolIndex(Tmp1)
@@ -1285,16 +1286,18 @@ unsigned AlphaISel::SelectExpr(SDOperand N) {
           .addGlobalAddress(GASD->getGlobal()).addReg(Tmp1);
       } else if (ConstantPoolSDNode *CP =
                      dyn_cast<ConstantPoolSDNode>(Address)) {
+        unsigned CPIdx = BB->getParent()->getConstantPool()->
+             getConstantPoolIndex(CP->get());
         AlphaLowering.restoreGP(BB);
         has_sym = true;
         Tmp1 = MakeReg(MVT::i64);
-        BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CP->getIndex())
+        BuildMI(BB, Alpha::LDAHr, 2, Tmp1).addConstantPoolIndex(CPIdx)
           .addReg(Alpha::R29);
         if (EnableAlphaLSMark)
           BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
             .addImm(getUID());
         BuildMI(BB, GetRelVersion(Opc), 2, Result)
-          .addConstantPoolIndex(CP->getIndex()).addReg(Tmp1);
+          .addConstantPoolIndex(CPIdx).addReg(Tmp1);
       } else if(Address.getOpcode() == ISD::FrameIndex) {
         if (EnableAlphaLSMark)
           BuildMI(BB, Alpha::MEMLABEL, 4).addImm(i).addImm(j).addImm(k)
index c0af3427164bfae81a001df705973f3698a4fc87..32aa94ac58b3d2a68b568fa2e3faf16e92f51830 100644 (file)
@@ -956,7 +956,8 @@ unsigned ISel::SelectExpr(SDOperand N) {
   }
 
   case ISD::ConstantPool: {
-    Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
+    Tmp1 = BB->getParent()->getConstantPool()->
+          getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
     IA64Lowering.restoreGP(BB); // FIXME: do i really need this?
     BuildMI(BB, IA64::ADD, 2, Result).addConstantPoolIndex(Tmp1)
       .addReg(IA64::r1);
@@ -1974,10 +1975,12 @@ pC = pA OR pB
         BuildMI(BB, IA64::CMPNE, 2, Result).addReg(dummy3).addReg(IA64::r0);
       }
     } else if(ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
+      unsigned CPIdx = BB->getParent()->getConstantPool()->
+         getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
       Select(Chain);
       IA64Lowering.restoreGP(BB);
       unsigned dummy = MakeReg(MVT::i64);
-      BuildMI(BB, IA64::ADD, 2, dummy).addConstantPoolIndex(CP->getIndex())
+      BuildMI(BB, IA64::ADD, 2, dummy).addConstantPoolIndex(CPIdx)
         .addReg(IA64::r1); // CPI+GP
       if(!isBool)
         BuildMI(BB, Opc, 1, Result).addReg(dummy);
index 8c1e6cbf8bf35c11bb0fcc5cbdb28304edfd1870..2ae44ce461c3e2eef841a815aeb7a82e058d4af5 100644 (file)
@@ -15,7 +15,6 @@
 #include "PowerPC.h"
 #include "PPC32TargetMachine.h"
 #include "PPC32ISelLowering.h"
-#include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/SSARegMap.h"
@@ -696,11 +695,9 @@ SDOperand PPC32DAGToDAGISel::Select(SDOperand Op) {
     break;
   }
   case ISD::ConstantFP: {  // FIXME: this should get sucked into the legalizer
-    MachineConstantPool *CP = CurDAG->getMachineFunction().getConstantPool();
     Constant *CFP = ConstantFP::get(Type::FloatTy,
                                     cast<ConstantFPSDNode>(N)->getValue());
-    SDOperand CPN = CurDAG->getConstantPool(CP->getConstantPoolIndex(CFP),
-                                            MVT::i32);
+    SDOperand CPN = CurDAG->getConstantPool(CFP, MVT::i32);
     SDOperand Tmp;
     if (PICEnabled)
       Tmp = CurDAG->getTargetNode(PPC::ADDIS, MVT::i32, getGlobalBaseReg(),CPN);
@@ -723,8 +720,8 @@ SDOperand PPC32DAGToDAGISel::Select(SDOperand Op) {
     break;
   }
   case ISD::ConstantPool: {
-    unsigned CPIIdx = cast<ConstantPoolSDNode>(N)->getIndex();
-    SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(CPIIdx, MVT::i32);
+    Constant *C = cast<ConstantPoolSDNode>(N)->get();
+    SDOperand Tmp, CPI = CurDAG->getTargetConstantPool(C, MVT::i32);
     if (PICEnabled)
       Tmp = CurDAG->getTargetNode(PPC::ADDIS, MVT::i32, getGlobalBaseReg(),CPI);
     else
index 3187e4a349cc9db5fd087bad463ee92cdb437193..7ff5eb9c13ccd265ad48360fed55d92b47465918 100644 (file)
@@ -866,7 +866,8 @@ unsigned ISel::SelectExpr(SDOperand N, bool Recording) {
     return Result;
 
   case ISD::ConstantPool:
-    Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
+    Tmp1 = BB->getParent()->getConstantPool()->
+               getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
     Tmp2 = MakeIntReg();
     if (PICEnabled)
       BuildMI(BB, PPC::ADDIS, 2, Tmp2).addReg(getGlobalBaseReg())
@@ -927,7 +928,8 @@ unsigned ISel::SelectExpr(SDOperand N, bool Recording) {
 
     if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(Address)) {
       Tmp1 = MakeIntReg();
-      int CPI = CP->getIndex();
+      unsigned CPI = BB->getParent()->getConstantPool()->
+        getConstantPoolIndex(CP->get());
       if (PICEnabled)
         BuildMI(BB, PPC::ADDIS, 2, Tmp1).addReg(getGlobalBaseReg())
           .addConstantPoolIndex(CPI);
index ff0ee633ff9d6ca7cca893bf9c3b8c179da4e818..9f602418aba3916c913b99d074fd9be6fe7eafa5 100644 (file)
@@ -2329,7 +2329,8 @@ unsigned ISel::SelectExpr(SDOperand N) {
     addFrameReference(BuildMI(BB, X86::LEA32r, 4, Result), (int)Tmp1);
     return Result;
   case ISD::ConstantPool:
-    Tmp1 = cast<ConstantPoolSDNode>(N)->getIndex();
+    Tmp1 = BB->getParent()->getConstantPool()->
+         getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
     addConstantPoolReference(BuildMI(BB, X86::LEA32r, 4, Result), Tmp1);
     return Result;
   case ISD::ConstantFP:
@@ -3317,8 +3318,10 @@ unsigned ISel::SelectExpr(SDOperand N) {
     }
 
     if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(N.getOperand(1))){
+      unsigned CPIdx = BB->getParent()->getConstantPool()->
+         getConstantPoolIndex(CP->get());
       Select(N.getOperand(0));
-      addConstantPoolReference(BuildMI(BB, Opc, 4, Result), CP->getIndex());
+      addConstantPoolReference(BuildMI(BB, Opc, 4, Result), CPIdx);
     } else {
       X86AddressMode AM;
 
@@ -3370,8 +3373,10 @@ unsigned ISel::SelectExpr(SDOperand N) {
       if (Node->getValueType(0) == MVT::f64) {
         assert(cast<VTSDNode>(Node->getOperand(3))->getVT() == MVT::f32 &&
                "Bad EXTLOAD!");
-        addConstantPoolReference(BuildMI(BB, X86::FLD32m, 4, Result),
-                                 CP->getIndex());
+        unsigned CPIdx = BB->getParent()->getConstantPool()->
+          getConstantPoolIndex(cast<ConstantPoolSDNode>(N)->get());
+
+        addConstantPoolReference(BuildMI(BB, X86::FLD32m, 4, Result), CPIdx);
         return Result;
       }