diff options
-rw-r--r-- | include/llvm/CodeGen/MachineConstantPool.h | 30 | ||||
-rw-r--r-- | include/llvm/CodeGen/SelectionDAGNodes.h | 4 | ||||
-rw-r--r-- | lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 84 | ||||
-rw-r--r-- | lib/CodeGen/MachineFunction.cpp | 27 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 8 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp | 3 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 6 | ||||
-rw-r--r-- | lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp | 2 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 58 | ||||
-rw-r--r-- | lib/Target/ARM/ARMConstantPoolValue.cpp | 4 | ||||
-rw-r--r-- | lib/Target/ARM/ARMISelLowering.cpp | 20 | ||||
-rw-r--r-- | lib/Target/ARM/ARMRegisterInfo.cpp | 2 | ||||
-rw-r--r-- | lib/Target/CellSPU/SPUISelDAGToDAG.cpp | 2 | ||||
-rw-r--r-- | lib/Target/X86/X86FastISel.cpp | 3 | ||||
-rw-r--r-- | lib/Target/X86/X86ISelLowering.cpp | 17 | ||||
-rw-r--r-- | lib/Target/X86/X86InstrInfo.cpp | 2 | ||||
-rw-r--r-- | test/CodeGen/X86/2009-03-12-CPAlignBug.ll | 37 |
19 files changed, 181 insertions, 134 deletions
diff --git a/include/llvm/CodeGen/MachineConstantPool.h b/include/llvm/CodeGen/MachineConstantPool.h index d042258f5e..d5bd25c47b 100644 --- a/include/llvm/CodeGen/MachineConstantPool.h +++ b/include/llvm/CodeGen/MachineConstantPool.h @@ -70,28 +70,26 @@ public: MachineConstantPoolValue *MachineCPVal; } Val; - /// The offset of the constant from the start of the pool. The top bit is set - /// when Val is a MachineConstantPoolValue. - unsigned Offset; + /// The required alignment for this entry. The top bit is set when Val is + /// a MachineConstantPoolValue. + unsigned Alignment; - MachineConstantPoolEntry(Constant *V, unsigned O) - : Offset(O) { - assert((int)Offset >= 0 && "Offset is too large"); + MachineConstantPoolEntry(Constant *V, unsigned A) + : Alignment(A) { Val.ConstVal = V; } - MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned O) - : Offset(O){ - assert((int)Offset >= 0 && "Offset is too large"); + MachineConstantPoolEntry(MachineConstantPoolValue *V, unsigned A) + : Alignment(A) { Val.MachineCPVal = V; - Offset |= 1 << (sizeof(unsigned)*8-1); + Alignment |= 1 << (sizeof(unsigned)*8-1); } bool isMachineConstantPoolEntry() const { - return (int)Offset < 0; + return (int)Alignment < 0; } - int getOffset() const { - return Offset & ~(1 << (sizeof(unsigned)*8-1)); + int getAlignment() const { + return Alignment & ~(1 << (sizeof(unsigned)*8-1)); } const Type *getType() const; @@ -117,13 +115,13 @@ public: : TD(td), PoolAlignment(1) {} ~MachineConstantPool(); - /// getConstantPoolAlignment - Return the log2 of the alignment required by + /// getConstantPoolAlignment - Return the the alignment required by /// the whole constant pool, of which the first element must be aligned. unsigned getConstantPoolAlignment() const { return PoolAlignment; } /// getConstantPoolIndex - Create a new entry in the constant pool or return - /// an existing one. User must specify the log2 of the minimum required - /// alignment for the object. + /// an existing one. User must specify the minimum required alignment for + /// the object. unsigned getConstantPoolIndex(Constant *C, unsigned Alignment); unsigned getConstantPoolIndex(MachineConstantPoolValue *V,unsigned Alignment); diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index 93d03f14b8..aaca06526b 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -1840,7 +1840,7 @@ class ConstantPoolSDNode : public SDNode { MachineConstantPoolValue *MachineCPVal; } Val; int Offset; // It's a MachineConstantPoolValue if top bit is set. - unsigned Alignment; + unsigned Alignment; // Minimum alignment requirement of CP (not log2 value). protected: friend class SelectionDAG; ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0) @@ -1896,7 +1896,7 @@ public: } // Return the alignment of this constant pool object, which is either 0 (for - // default alignment) or log2 of the desired value. + // default alignment) or the desired value. unsigned getAlignment() const { return Alignment; } const Type *getType() const; diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 2a3a8bb32d..b25776abb9 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -240,6 +240,16 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { IncrementFunctionNumber(); } +namespace { + // SectionCPs - Keep track the alignment, constpool entries per Section. + struct SectionCPs { + const Section *S; + unsigned Alignment; + SmallVector<unsigned, 4> CPEs; + SectionCPs(const Section *s, unsigned a) : S(s), Alignment(a) {}; + }; +} + /// EmitConstantPool - Print to the current output stream assembly /// representations of the constants in the constant pool MCP. This is /// used to print out constants which have been "spilled to memory" by @@ -251,48 +261,60 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { // Calculate sections for constant pool entries. We collect entries to go into // the same section together to reduce amount of section switch statements. - typedef - std::multimap<const Section*, - std::pair<MachineConstantPoolEntry, unsigned> > CPMap; - CPMap CPs; - SmallPtrSet<const Section*, 5> Sections; - + SmallVector<SectionCPs, 4> CPSections; for (unsigned i = 0, e = CP.size(); i != e; ++i) { MachineConstantPoolEntry CPE = CP[i]; + unsigned Align = CPE.getAlignment(); const Section* S = TAI->SelectSectionForMachineConst(CPE.getType()); - CPs.insert(std::make_pair(S, std::make_pair(CPE, i))); - Sections.insert(S); + // The number of sections are small, just do a linear search from the + // last section to the first. + bool Found = false; + unsigned SecIdx = CPSections.size(); + while (SecIdx != 0) { + if (CPSections[--SecIdx].S == S) { + Found = true; + break; + } + } + if (!Found) { + SecIdx = CPSections.size(); + CPSections.push_back(SectionCPs(S, Align)); + } + + if (Align > CPSections[SecIdx].Alignment) + CPSections[SecIdx].Alignment = Align; + CPSections[SecIdx].CPEs.push_back(i); } // Now print stuff into the calculated sections. - for (SmallPtrSet<const Section*, 5>::iterator IS = Sections.begin(), - ES = Sections.end(); IS != ES; ++IS) { - SwitchToSection(*IS); - EmitAlignment(MCP->getConstantPoolAlignment()); + for (unsigned i = 0, e = CPSections.size(); i != e; ++i) { + SwitchToSection(CPSections[i].S); + EmitAlignment(Log2_32(CPSections[i].Alignment)); - std::pair<CPMap::iterator, CPMap::iterator> II = CPs.equal_range(*IS); - for (CPMap::iterator I = II.first, E = II.second; I != E; ++I) { - CPMap::iterator J = next(I); - MachineConstantPoolEntry Entry = I->second.first; - unsigned index = I->second.second; + unsigned Offset = 0; + for (unsigned j = 0, ee = CPSections[i].CPEs.size(); j != ee; ++j) { + unsigned CPI = CPSections[i].CPEs[j]; + MachineConstantPoolEntry CPE = CP[CPI]; + + // Emit inter-object padding for alignment. + unsigned AlignMask = CPE.getAlignment() - 1; + unsigned NewOffset = (Offset + AlignMask) & ~AlignMask; + EmitZeros(NewOffset - Offset); + + const Type *Ty = CPE.getType(); + Offset = NewOffset + TM.getTargetData()->getTypePaddedSize(Ty); O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_' - << index << ":\t\t\t\t\t"; - // O << TAI->getCommentString() << ' ' << - // WriteTypeSymbolic(O, CP[i].first.getType(), 0); + << CPI << ":\t\t\t\t\t"; + if (VerboseAsm) { + O << TAI->getCommentString() << ' '; + WriteTypeSymbolic(O, CPE.getType(), 0); + } O << '\n'; - if (Entry.isMachineConstantPoolEntry()) - EmitMachineConstantPoolValue(Entry.Val.MachineCPVal); + if (CPE.isMachineConstantPoolEntry()) + EmitMachineConstantPoolValue(CPE.Val.MachineCPVal); else - EmitGlobalConstant(Entry.Val.ConstVal); - - // Emit inter-object padding for alignment. - if (J != E) { - const Type *Ty = Entry.getType(); - unsigned EntSize = TM.getTargetData()->getTypePaddedSize(Ty); - unsigned ValEnd = Entry.getOffset() + EntSize; - EmitZeros(J->second.first.getOffset()-ValEnd); - } + EmitGlobalConstant(CPE.Val.ConstVal); } } } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index cf7f39140b..e19cf7a6ed 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -521,19 +521,12 @@ unsigned MachineConstantPool::getConstantPoolIndex(Constant *C, // Check to see if we already have this constant. // // FIXME, this could be made much more efficient for large constant pools. - unsigned AlignMask = (1 << Alignment)-1; for (unsigned i = 0, e = Constants.size(); i != e; ++i) - if (Constants[i].Val.ConstVal == C && (Constants[i].Offset & AlignMask)== 0) + if (Constants[i].Val.ConstVal == C && + (Constants[i].getAlignment() & (Alignment - 1)) == 0) return i; - unsigned Offset = 0; - if (!Constants.empty()) { - Offset = Constants.back().getOffset(); - Offset += TD->getTypePaddedSize(Constants.back().getType()); - Offset = (Offset+AlignMask)&~AlignMask; - } - - Constants.push_back(MachineConstantPoolEntry(C, Offset)); + Constants.push_back(MachineConstantPoolEntry(C, Alignment)); return Constants.size()-1; } @@ -545,19 +538,11 @@ unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V, // Check to see if we already have this constant. // // FIXME, this could be made much more efficient for large constant pools. - unsigned AlignMask = (1 << Alignment)-1; int Idx = V->getExistingMachineCPValue(this, Alignment); if (Idx != -1) return (unsigned)Idx; - - unsigned Offset = 0; - if (!Constants.empty()) { - Offset = Constants.back().getOffset(); - Offset += TD->getTypePaddedSize(Constants.back().getType()); - Offset = (Offset+AlignMask)&~AlignMask; - } - - Constants.push_back(MachineConstantPoolEntry(V, Offset)); + + Constants.push_back(MachineConstantPoolEntry(V, Alignment)); return Constants.size()-1; } @@ -568,7 +553,7 @@ void MachineConstantPool::print(raw_ostream &OS) const { Constants[i].Val.MachineCPVal->print(OS); else OS << *(Value*)Constants[i].Val.ConstVal; - OS << " , offset=" << Constants[i].getOffset(); + OS << " , alignment=" << Constants[i].getAlignment(); OS << "\n"; } } diff --git a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index 671c85e6d7..7cacbd3021 100644 --- a/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -5672,8 +5672,7 @@ SDValue DAGCombiner::SimplifySelectCC(DebugLoc DL, SDValue N0, SDValue N1, Constant *CA = ConstantArray::get(ArrayType::get(FPTy, 2), Elts, 2); SDValue CPIdx = DAG.getConstantPool(CA, TLI.getPointerTy(), TD.getPrefTypeAlignment(FPTy)); - unsigned Alignment = - 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); // Get the offsets to the 0 and 1 element of the array so that we can // select between them. diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 8c074e75eb..fd08ee688d 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -592,7 +592,7 @@ static SDValue ExpandConstantFP(ConstantFPSDNode *CFP, bool UseCP, } SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy()); - unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); if (Extend) return DAG.getExtLoad(ISD::EXTLOAD, dl, OrigVT, DAG.getEntryNode(), @@ -5547,7 +5547,7 @@ SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) { } Constant *CP = ConstantVector::get(CV); SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy()); - unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); return DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, PseudoSourceValue::getConstantPool(), 0, false, Alignment); @@ -6019,7 +6019,7 @@ ExpandIntToFP(bool isSigned, MVT DestTy, SDValue Source, DebugLoc dl) { Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); - unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); CPIdx = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), CPIdx, CstOffset); Alignment = std::min(Alignment, 4u); SDValue FudgeInReg; @@ -6173,7 +6173,7 @@ SDValue SelectionDAGLegalize::ExpandLegalINT_TO_FP(bool isSigned, Constant *FudgeFactor = ConstantInt::get(Type::Int64Ty, FF); SDValue CPIdx = DAG.getConstantPool(FudgeFactor, TLI.getPointerTy()); - unsigned Alignment = 1 << cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); CPIdx = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), CPIdx, CstOffset); Alignment = std::min(Alignment, 4u); SDValue FudgeInReg; diff --git a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 3cc8f966aa..6c70cced15 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -2289,8 +2289,7 @@ SDValue DAGTypeLegalizer::ExpandIntOp_UINT_TO_FP(SDNode *N) { if (TLI.isBigEndian()) std::swap(Zero, Four); SDValue Offset = DAG.getNode(ISD::SELECT, dl, Zero.getValueType(), SignSet, Zero, Four); - unsigned Alignment = - 1 << cast<ConstantPoolSDNode>(FudgePtr)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(FudgePtr)->getAlignment(); FudgePtr = DAG.getNode(ISD::ADD, dl, TLI.getPointerTy(), FudgePtr, Offset); Alignment = std::min(Alignment, 4u); diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp index 852c43089d..5dfd5c3fb2 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAGSDNodesEmit.cpp @@ -298,11 +298,10 @@ void ScheduleDAGSDNodes::AddOperand(MachineInstr *MI, SDValue Op, const Type *Type = CP->getType(); // MachineConstantPool wants an explicit alignment. if (Align == 0) { - Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type); + Align = TM.getTargetData()->getPrefTypeAlignment(Type); if (Align == 0) { // Alignment of vector types. FIXME! Align = TM.getTargetData()->getTypePaddedSize(Type); - Align = Log2_64(Align); } } diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index 71560fe2ae..b85a04d858 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -1023,8 +1023,7 @@ SDValue SelectionDAG::getConstantPool(Constant *C, MVT VT, unsigned Alignment, int Offset, bool isTarget) { if (Alignment == 0) - Alignment = - TLI.getTargetData()->getPreferredTypeAlignmentShift(C->getType()); + Alignment = TLI.getTargetData()->getPrefTypeAlignment(C->getType()); unsigned Opc = isTarget ? ISD::TargetConstantPool : ISD::ConstantPool; FoldingSetNodeID ID; AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); @@ -1046,8 +1045,7 @@ SDValue SelectionDAG::getConstantPool(MachineConstantPoolValue *C, MVT VT, unsigned Alignment, int Offset, bool isTarget) { if (Alignment == 0) - Alignment = - TLI.getTargetData()->getPreferredTypeAlignmentShift(C->getType()); + Alignment = TLI.getTargetData()->getPrefTypeAlignment(C->getType()); unsigned Opc = isTarget ? ISD::TargetConstantPool : ISD::ConstantPool; FoldingSetNodeID ID; AddNodeIDNode(ID, Opc, getVTList(VT), 0, 0); diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp index 0392338762..3eec684c6f 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAGPrinter.cpp @@ -162,7 +162,7 @@ std::string DOTGraphTraits<SelectionDAG*>::getNodeLabel(const SDNode *Node, Op += '>'; } } - Op += " A=" + itostr(1 << CP->getAlignment()); + Op += " A=" + itostr(CP->getAlignment()); } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(Node)) { Op = "BB: "; const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index 0273bc1820..54c54518b8 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -98,7 +98,7 @@ namespace { /// external functions. std::map<void*, void*> ExternalFnToStubMap; - //map addresses to indexes in the GOT + /// revGOTMap - map addresses to indexes in the GOT std::map<void*, unsigned> revGOTMap; unsigned nextGOTIndex; @@ -562,6 +562,10 @@ namespace { /// void *ConstantPoolBase; + /// ConstPoolAddresses - Addresses of individual constant pool entries. + /// + SmallVector<uintptr_t, 8> ConstPoolAddresses; + /// JumpTable - The jump tables for the current function. /// MachineJumpTableInfo *JumpTable; @@ -787,15 +791,19 @@ void JITEmitter::AddStubToCurrentFunction(void *StubAddr) { FnRefs.insert(CurFn); } -static unsigned GetConstantPoolSizeInBytes(MachineConstantPool *MCP) { +static unsigned GetConstantPoolSizeInBytes(MachineConstantPool *MCP, + const TargetData *TD) { const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants(); if (Constants.empty()) return 0; - MachineConstantPoolEntry CPE = Constants.back(); - unsigned Size = CPE.Offset; - const Type *Ty = CPE.isMachineConstantPoolEntry() - ? CPE.Val.MachineCPVal->getType() : CPE.Val.ConstVal->getType(); - Size += TheJIT->getTargetData()->getTypePaddedSize(Ty); + unsigned Size = 0; + for (unsigned i = 0, e = Constants.size(); i != e; ++i) { + MachineConstantPoolEntry CPE = Constants[i]; + unsigned AlignMask = CPE.getAlignment() - 1; + Size = (Size + AlignMask) & ~AlignMask; + const Type *Ty = CPE.getType(); + Size += TD->getTypePaddedSize(Ty); + } return Size; } @@ -979,11 +987,10 @@ void JITEmitter::startFunction(MachineFunction &F) { ActualSize = RoundUpToAlign(ActualSize, 16); // Add the alignment of the constant pool - ActualSize = RoundUpToAlign(ActualSize, - 1 << MCP->getConstantPoolAlignment()); + ActualSize = RoundUpToAlign(ActualSize, MCP->getConstantPoolAlignment()); // Add the constant pool size - ActualSize += GetConstantPoolSizeInBytes(MCP); + ActualSize += GetConstantPoolSizeInBytes(MCP, TheJIT->getTargetData()); // Add the aligment of the jump table info ActualSize = RoundUpToAlign(ActualSize, MJTI->getAlignment()); @@ -1139,6 +1146,7 @@ bool JITEmitter::finishFunction(MachineFunction &F) { << ": " << (FnEnd-FnStart) << " bytes of text, " << Relocations.size() << " relocations\n"; Relocations.clear(); + ConstPoolAddresses.clear(); // Mark code region readable and executable if it's not so already. MemMgr->setMemoryExecutable(); @@ -1274,13 +1282,8 @@ void JITEmitter::emitConstantPool(MachineConstantPool *MCP) { const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants(); if (Constants.empty()) return; - MachineConstantPoolEntry CPE = Constants.back(); - unsigned Size = CPE.Offset; - const Type *Ty = CPE.isMachineConstantPoolEntry() - ? CPE.Val.MachineCPVal->getType() : CPE.Val.ConstVal->getType(); - Size += TheJIT->getTargetData()->getTypePaddedSize(Ty); - - unsigned Align = 1 << MCP->getConstantPoolAlignment(); + unsigned Size = GetConstantPoolSizeInBytes(MCP, TheJIT->getTargetData()); + unsigned Align = MCP->getConstantPoolAlignment(); ConstantPoolBase = allocateSpace(Size, Align); ConstantPool = MCP; @@ -1290,16 +1293,26 @@ void JITEmitter::emitConstantPool(MachineConstantPool *MCP) { << "] (size: " << Size << ", alignment: " << Align << ")\n"; // Initialize the memory for all of the constant pool entries. + unsigned Offset = 0; for (unsigned i = 0, e = Constants.size(); i != e; ++i) { - void *CAddr = (char*)ConstantPoolBase+Constants[i].Offset; - if (Constants[i].isMachineConstantPoolEntry()) { + MachineConstantPoolEntry CPE = Constants[i]; + unsigned AlignMask = CPE.getAlignment() - 1; + Offset = (Offset + AlignMask) & ~AlignMask; + + uintptr_t CAddr = (uintptr_t)ConstantPoolBase + Offset; + ConstPoolAddresses.push_back(CAddr); + if (CPE.isMachineConstantPoolEntry()) { // FIXME: add support to lower machine constant pool values into bytes! cerr << "Initialize memory with machine specific constant pool entry" << " has not been implemented!\n"; abort(); } - TheJIT->InitializeMemory(Constants[i].Val.ConstVal, CAddr); - DOUT << "JIT: CP" << i << " at [" << CAddr << "]\n"; + TheJIT->InitializeMemory(CPE.Val.ConstVal, (void*)CAddr); + DOUT << "JIT: CP" << i << " at [0x" + << std::hex << CAddr << std::dec << "]\n"; + + const Type *Ty = CPE.Val.ConstVal->getType(); + Offset += TheJIT->getTargetData()->getTypePaddedSize(Ty); } } @@ -1398,8 +1411,7 @@ void *JITEmitter::finishGVStub(const GlobalValue* GV) { uintptr_t JITEmitter::getConstantPoolEntryAddress(unsigned ConstantNum) const { assert(ConstantNum < ConstantPool->getConstants().size() && "Invalid ConstantPoolIndex!"); - return (uintptr_t)ConstantPoolBase + - ConstantPool->getConstants()[ConstantNum].Offset; + return ConstPoolAddresses[ConstantNum]; } // getJumpTableEntryAddress - Return the address of the JumpTable with index diff --git a/lib/Target/ARM/ARMConstantPoolValue.cpp b/lib/Target/ARM/ARMConstantPoolValue.cpp index c95a6e6b47..3a038c9a8c 100644 --- a/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -47,11 +47,11 @@ ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP, unsigned Alignment) { - unsigned AlignMask = (1 << Alignment)-1; + unsigned AlignMask = Alignment - 1; const std::vector<MachineConstantPoolEntry> Constants = CP->getConstants(); for (unsigned i = 0, e = Constants.size(); i != e; ++i) { if (Constants[i].isMachineConstantPoolEntry() && - (Constants[i].Offset & AlignMask) == 0) { + (Constants[i].getAlignment() & AlignMask) == 0) { ARMConstantPoolValue *CPV = (ARMConstantPoolValue *)Constants[i].Val.MachineCPVal; if (CPV->GV == GV && diff --git a/lib/Target/ARM/ARMISelLowering.cpp b/lib/Target/ARM/ARMISelLowering.cpp index 25dda0c4d6..f3f214a43b 100644 --- a/lib/Target/ARM/ARMISelLowering.cpp +++ b/lib/Target/ARM/ARMISelLowering.cpp @@ -540,7 +540,7 @@ SDValue ARMTargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) { if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps()) { ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPStub, 4); - SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 2); + SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); Callee = DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), CPAddr, NULL, 0); @@ -559,7 +559,7 @@ SDValue ARMTargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) { if (isARMFunc && Subtarget->isThumb() && !Subtarget->hasV5TOps()) { ARMConstantPoolValue *CPV = new ARMConstantPoolValue(Sym, ARMPCLabelIndex, ARMCP::CPStub, 4); - SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 2); + SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); Callee = DAG.getLoad(getPointerTy(), dl, DAG.getEntryNode(), CPAddr, NULL, 0); @@ -744,7 +744,7 @@ ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue, PCAdj, "tlsgd", true); - SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 2); + SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, NULL, 0); SDValue Chain = Argument.getValue(1); @@ -785,7 +785,7 @@ ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue, PCAdj, "gottpoff", true); - Offset = DAG.getTargetConstantPool(CPV, PtrVT, 2); + Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0); Chain = Offset.getValue(1); @@ -798,7 +798,7 @@ ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, // local exec model ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMCP::CPValue, "tpoff"); - Offset = DAG.getTargetConstantPool(CPV, PtrVT, 2); + Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0); } @@ -832,7 +832,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT"); - SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2); + SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0); @@ -843,7 +843,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, Result = DAG.getLoad(PtrVT, dl, Chain, Result, NULL, 0); return Result; } else { - SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 2); + SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0); } @@ -869,7 +869,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, bool IsIndirect = GVIsIndirectSymbol(GV, RelocM); SDValue CPAddr; if (RelocM == Reloc::Static) - CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 2); + CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); else { unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb() ? 4 : 8); @@ -877,7 +877,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, : ARMCP::CPValue; ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex, Kind, PCAdj); - CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2); + CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); } CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); @@ -904,7 +904,7 @@ SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, ARMConstantPoolValue *CPV = new ARMConstantPoolValue("_GLOBAL_OFFSET_TABLE_", ARMPCLabelIndex, ARMCP::CPValue, PCAdj); - SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 2); + SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0); SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32); diff --git a/lib/Target/ARM/ARMRegisterInfo.cpp b/lib/Target/ARM/ARMRegisterInfo.cpp index 8785c39a96..b220b3bb2b 100644 --- a/lib/Target/ARM/ARMRegisterInfo.cpp +++ b/lib/Target/ARM/ARMRegisterInfo.cpp @@ -184,7 +184,7 @@ void ARMRegisterInfo::emitLoadConstPool(MachineBasicBlock &MBB, MachineFunction &MF = *MBB.getParent(); MachineConstantPool *ConstantPool = MF.getConstantPool(); Constant *C = ConstantInt::get(Type::Int32Ty, Val); - unsigned Idx = ConstantPool->getConstantPoolIndex(C, 2); + unsigned Idx = ConstantPool->getConstantPoolIndex(C, 4); if (isThumb) BuildMI(MBB, MBBI, dl, TII->get(ARM::tLDRcp),DestReg).addConstantPoolIndex(Idx); diff --git a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp index 23bb08c0c0..73607bf251 100644 --- a/lib/Target/CellSPU/SPUISelDAGToDAG.cpp +++ b/lib/Target/CellSPU/SPUISelDAGToDAG.cpp @@ -276,7 +276,7 @@ public: Constant *CP = ConstantVector::get(CV); SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy()); - unsigned Alignment = 1 << cast<ConstantPoolSDNode > (CPIdx)->getAlignment(); + unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment(); SDValue CGPoolOffset = SPU::LowerConstantPool(CPIdx, *CurDAG, SPUtli.getSPUTargetMachine()); diff --git a/lib/Target/X86/X86FastISel.cpp b/lib/Target/X86/X86FastISel.cpp index 10359a74af..61ca24e2b2 100644 --- a/lib/Target/X86/X86FastISel.cpp +++ b/lib/Target/X86/X86FastISel.cpp @@ -1480,11 +1480,10 @@ unsigned X86FastISel::TargetMaterializeConstant(Constant *C) { } // MachineConstantPool wants an explicit alignment. - unsigned Align = TD.getPreferredTypeAlignmentShift(C->getType()); + unsigned Align = TD.getPrefTypeAlignment(C->getType()); if (Align == 0) { // Alignment of vector types. FIXME! Align = TD.getTypePaddedSize(C->getType()); - Align = Log2_64(Align); } // x86-32 PIC requires a PIC base register for constant pools. diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index e8e7736021..d10e4bb345 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -4672,9 +4672,8 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) { ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); // FIXME there isn't really any debug info here, should come from the parent DebugLoc dl = CP->getDebugLoc(); - SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), - getPointerTy(), - CP->getAlignment()); + SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(), + CP->getAlignment()); Result = DAG.getNode(X86ISD::Wrapper, dl, getPointerTy(), Result); // With PIC, the address is actually $g + Offset. if (getTargetMachine().getRelocationModel() == Reloc::PIC_ && @@ -5063,13 +5062,13 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) { CV0.push_back(ConstantInt::get(APInt(32, 0))); CV0.push_back(ConstantInt::get(APInt(32, 0))); Constant *C0 = ConstantVector::get(CV0); - SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 4); |