From ed169db8a55114fce67e98df0164a77a5e671d0e Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Sat, 25 Feb 2006 09:54:52 +0000 Subject: [PATCH] Added an offset field to ConstantPoolSDNode. llvm-svn: 26371 --- llvm/include/llvm/CodeGen/MachineInstr.h | 16 +++++++----- .../llvm/CodeGen/MachineInstrBuilder.h | 8 +++--- llvm/include/llvm/CodeGen/SelectionDAG.h | 10 ++++--- llvm/include/llvm/CodeGen/SelectionDAGNodes.h | 21 ++++++++------- llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp | 3 ++- .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 20 ++++++++------ llvm/lib/Target/X86/X86ATTAsmPrinter.cpp | 23 ++++++---------- llvm/lib/Target/X86/X86IntelAsmPrinter.cpp | 26 +++++++------------ 8 files changed, 64 insertions(+), 63 deletions(-) diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h index 4f09046b0e55..b84388597af4 100644 --- a/llvm/include/llvm/CodeGen/MachineInstr.h +++ b/llvm/include/llvm/CodeGen/MachineInstr.h @@ -131,7 +131,8 @@ private: // will be set for a value after reg allocation int offset; // Offset to address of global or external, only - // valid for MO_GlobalAddress and MO_ExternalSym + // valid for MO_GlobalAddress, MO_ExternalSym + // and MO_ConstantPoolIndex } extra; void zeroContents () { @@ -140,11 +141,14 @@ private: } MachineOperand(int64_t ImmVal = 0, - MachineOperandType OpTy = MO_VirtualRegister) + MachineOperandType OpTy = MO_VirtualRegister, int Offset = 0) : flags(0), opType(OpTy) { zeroContents (); contents.immedVal = ImmVal; - extra.regNum = -1; + if (OpTy == MachineOperand::MO_ConstantPoolIndex) + extra.offset = Offset; + else + extra.regNum = -1; } MachineOperand(int Reg, MachineOperandType OpTy, UseType UseTy) @@ -286,7 +290,7 @@ public: return (GlobalValue*)contents.value; } int getOffset() const { - assert((isGlobalAddress() || isExternalSymbol()) && + assert((isGlobalAddress() || isExternalSymbol() || isConstantPoolIndex()) && "Wrong MachineOperand accessor"); return extra.offset; } @@ -344,7 +348,7 @@ public: } void setOffset(int Offset) { - assert((isGlobalAddress() || isExternalSymbol()) && + assert((isGlobalAddress() || isExternalSymbol() || isConstantPoolIndex()) && "Wrong MachineOperand accessor"); extra.offset = Offset; } @@ -644,7 +648,7 @@ public: /// addConstantPoolndexOperand - Add a constant pool object index to the /// instruction. /// - void addConstantPoolIndexOperand(unsigned I) { + void addConstantPoolIndexOperand(unsigned I, int Offset=0) { assert(!OperandsComplete() && "Trying to add an operand to a machine instr that is already done!"); operands.push_back(MachineOperand(I, MachineOperand::MO_ConstantPoolIndex)); diff --git a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h index 2aee02ee6cb2..1f877c0809fe 100644 --- a/llvm/include/llvm/CodeGen/MachineInstrBuilder.h +++ b/llvm/include/llvm/CodeGen/MachineInstrBuilder.h @@ -125,13 +125,15 @@ public: return *this; } - const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx) const { - MI->addConstantPoolIndexOperand(Idx); + const MachineInstrBuilder &addConstantPoolIndex(unsigned Idx, + int Offset = 0) const { + MI->addConstantPoolIndexOperand(Idx, Offset); return *this; } const MachineInstrBuilder &addGlobalAddress(GlobalValue *GV, - bool isPCRelative = false, int Offset = 0) const { + bool isPCRelative = false, + int Offset = 0) const { MI->addGlobalAddressOperand(GV, isPCRelative, Offset); return *this; } diff --git a/llvm/include/llvm/CodeGen/SelectionDAG.h b/llvm/include/llvm/CodeGen/SelectionDAG.h index 1986b4531c89..01f56a9e8665 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAG.h +++ b/llvm/include/llvm/CodeGen/SelectionDAG.h @@ -121,9 +121,9 @@ public: SDOperand getFrameIndex(int FI, MVT::ValueType VT); SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT); SDOperand getConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment=0); + unsigned Alignment=0, int offset = 0); SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment=0); + unsigned Alignment=0, int offset = 0); SDOperand getBasicBlock(MachineBasicBlock *MBB); SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT); SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT); @@ -469,8 +469,10 @@ private: std::map, SDNode*> ConstantFPs; std::map, SDNode*> TargetConstantFPs; std::map FrameIndices, TargetFrameIndices; - std::map, SDNode*> ConstantPoolIndices; - std::map, SDNode*> TargetConstantPoolIndices; + std::map >, SDNode*> ConstantPoolIndices; + std::map >, SDNode*> TargetConstantPoolIndices; std::map BBNodes; std::vector ValueTypeNodes; std::map ExternalSymbols; diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h index b72bf20fd197..a4e8854d2508 100644 --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -1028,19 +1028,19 @@ public: class GlobalAddressSDNode : public SDNode { GlobalValue *TheGlobal; - int offset; + int Offset; protected: friend class SelectionDAG; GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT, int o=0) - : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) { + : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT), + Offset(o) { TheGlobal = const_cast(GA); - offset = o; } public: GlobalValue *getGlobal() const { return TheGlobal; } - int getOffset() const { return offset; } + int getOffset() const { return Offset; } static bool classof(const GlobalAddressSDNode *) { return true; } static bool classof(const SDNode *N) { @@ -1069,19 +1069,22 @@ public: class ConstantPoolSDNode : public SDNode { Constant *C; + int Offset; unsigned Alignment; protected: friend class SelectionDAG; - ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget) + ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, + int o=0) : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), - C(c), Alignment(0) {} - ConstantPoolSDNode(Constant *c, MVT::ValueType VT, unsigned Align, - bool isTarget) + C(c), Offset(o), Alignment(0) {} + ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o, + unsigned Align) : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), - C(c), Alignment(Align) {} + C(c), Offset(o), Alignment(Align) {} public: Constant *get() const { return C; } + int getOffset() const { return Offset; } // Return the alignment of this constant pool object, which is either 0 (for // default alignment) or log2 of the desired value. diff --git a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index 9bc168f7a6d7..611abc3a1163 100644 --- a/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -154,6 +154,7 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op, MI->addFrameIndexOperand(FI->getIndex()); } else if (ConstantPoolSDNode *CP = dyn_cast(Op)) { + int Offset = CP->getOffset(); unsigned Align = CP->getAlignment(); // MachineConstantPool wants an explicit alignment. if (Align == 0) { @@ -165,7 +166,7 @@ void ScheduleDAG::AddOperand(MachineInstr *MI, SDOperand Op, } unsigned Idx = ConstPool->getConstantPoolIndex(CP->get(), Align); - MI->addConstantPoolIndexOperand(Idx); + MI->addConstantPoolIndexOperand(Idx, Offset); } else if (ExternalSymbolSDNode *ES = dyn_cast(Op)) { MI->addExternalSymbolOperand(ES->getSymbol(), false); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 59449625e666..8b930948d2aa 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -302,12 +302,14 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { case ISD::ConstantPool: Erased = ConstantPoolIndices. erase(std::make_pair(cast(N)->get(), - cast(N)->getAlignment())); + std::make_pair(cast(N)->getOffset(), + cast(N)->getAlignment()))); break; case ISD::TargetConstantPool: Erased = TargetConstantPoolIndices. erase(std::make_pair(cast(N)->get(), - cast(N)->getAlignment())); + std::make_pair(cast(N)->getOffset(), + cast(N)->getAlignment()))); break; case ISD::BasicBlock: Erased = BBNodes.erase(cast(N)->getBasicBlock()); @@ -650,19 +652,21 @@ SDOperand SelectionDAG::getTargetFrameIndex(int FI, MVT::ValueType VT) { } SDOperand SelectionDAG::getConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment) { - SDNode *&N = ConstantPoolIndices[std::make_pair(C, Alignment)]; + unsigned Alignment, int Offset) { + SDNode *&N = ConstantPoolIndices[std::make_pair(C, + std::make_pair(Offset, Alignment))]; if (N) return SDOperand(N, 0); - N = new ConstantPoolSDNode(C, VT, Alignment, false); + N = new ConstantPoolSDNode(false, C, VT, Offset, Alignment); AllNodes.push_back(N); return SDOperand(N, 0); } SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT, - unsigned Alignment) { - SDNode *&N = TargetConstantPoolIndices[std::make_pair(C, Alignment)]; + unsigned Alignment, int Offset) { + SDNode *&N = TargetConstantPoolIndices[std::make_pair(C, + std::make_pair(Offset, Alignment))]; if (N) return SDOperand(N, 0); - N = new ConstantPoolSDNode(C, VT, Alignment, true); + N = new ConstantPoolSDNode(true, C, VT, Offset, Alignment); AllNodes.push_back(N); return SDOperand(N, 0); } diff --git a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp index 38418b3593c6..f8f54d434a14 100755 --- a/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86ATTAsmPrinter.cpp @@ -196,25 +196,18 @@ void X86ATTAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){ O << " + " << DispSpec.getImmedValue(); O << "]"; return; - } else if (BaseReg.isConstantPoolIndex()) { - O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" - << BaseReg.getConstantPoolIndex(); - if (forDarwin && TM.getRelocationModel() == Reloc::PIC) - O << "-\"L" << getFunctionNumber() << "$pb\""; - if (DispSpec.getImmedValue()) - O << "+" << DispSpec.getImmedValue(); - if (IndexReg.getReg()) { - O << "(,"; - printOperand(MI, Op+2); - if (ScaleVal != 1) - O << "," << ScaleVal; - O << ")"; - } - return; } if (DispSpec.isGlobalAddress()) { printOperand(MI, Op+3, "mem"); + } else if (DispSpec.isConstantPoolIndex()) { + O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" + << DispSpec.getConstantPoolIndex(); + if (forDarwin && TM.getRelocationModel() == Reloc::PIC) + O << "-\"L" << getFunctionNumber() << "$pb\""; + if (DispSpec.getOffset()) + O << "+" << DispSpec.getOffset(); + return; } else { int DispVal = DispSpec.getImmedValue(); if (DispVal || (!IndexReg.getReg() && !BaseReg.getReg())) diff --git a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp index de503b924e41..7f4592bb5b57 100755 --- a/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp +++ b/llvm/lib/Target/X86/X86IntelAsmPrinter.cpp @@ -171,23 +171,6 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){ if (BaseReg.isFrameIndex()) { O << "[frame slot #" << BaseReg.getFrameIndex(); - if (DispSpec.getImmedValue()) - O << " + " << DispSpec.getImmedValue(); - O << "]"; - return; - } else if (BaseReg.isConstantPoolIndex()) { - O << "[" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" - << BaseReg.getConstantPoolIndex(); - if (forDarwin && TM.getRelocationModel() == Reloc::PIC) - O << "-\"L" << getFunctionNumber() << "$pb\""; - - if (IndexReg.getReg()) { - O << " + "; - if (ScaleVal != 1) - O << ScaleVal << "*"; - printOp(IndexReg); - } - if (DispSpec.getImmedValue()) O << " + " << DispSpec.getImmedValue(); O << "]"; @@ -213,6 +196,15 @@ void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op){ if (NeedPlus) O << " + "; printOp(DispSpec, "mem"); + } else if (DispSpec.isConstantPoolIndex()) { + O << "[" << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_" + << DispSpec.getConstantPoolIndex(); + if (forDarwin && TM.getRelocationModel() == Reloc::PIC) + O << "-\"L" << getFunctionNumber() << "$pb\""; + if (DispSpec.getOffset()) + O << " + " << DispSpec.getOffset(); + O << "]"; + return; } else { int DispVal = DispSpec.getImmedValue(); if (DispVal || (!BaseReg.getReg() && !IndexReg.getReg())) {