From: Evan Cheng Date: Tue, 31 Jan 2006 22:23:14 +0000 (+0000) Subject: Allow the specification of explicit alignments for constant pool entries. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;ds=sidebyside;h=b8973bd8f50d7321635e1e07b81a880a0828d185;p=oota-llvm.git Allow the specification of explicit alignments for constant pool entries. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@25855 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/CodeGen/MachineConstantPool.h b/include/llvm/CodeGen/MachineConstantPool.h index c2c3399adb7..1bbf88d843b 100644 --- a/include/llvm/CodeGen/MachineConstantPool.h +++ b/include/llvm/CodeGen/MachineConstantPool.h @@ -30,20 +30,23 @@ namespace llvm { class Constant; class MachineConstantPool { - std::vector Constants; + std::vector > Constants; public: /// getConstantPoolIndex - Create a new entry in the constant pool or return - /// an existing one. + /// an existing one. User may specify an alignment that is greater than the + /// default alignment. If one is not specified, it will be 0. /// - unsigned getConstantPoolIndex(Constant *C) { + unsigned getConstantPoolIndex(Constant *C, unsigned Alignment = 0) { // Check to see if we already have this constant. // // FIXME, this could be made much more efficient for large constant pools. for (unsigned i = 0, e = Constants.size(); i != e; ++i) - if (Constants[i] == C) + if (Constants[i].first == C) { + Constants[i].second = std::max(Constants[i].second, Alignment); return i; - Constants.push_back(C); + } + Constants.push_back(std::make_pair(C, Alignment)); return Constants.size()-1; } @@ -51,7 +54,9 @@ public: /// bool isEmpty() const { return Constants.empty(); } - const std::vector &getConstants() const { return Constants; } + const std::vector > &getConstants() const { + return Constants; + } /// print - Used by the MachineFunction printer to print information about /// stack objects. Implemented in MachineFunction.cpp diff --git a/include/llvm/CodeGen/SelectionDAG.h b/include/llvm/CodeGen/SelectionDAG.h index 195e8e435b0..6d75e47acfb 100644 --- a/include/llvm/CodeGen/SelectionDAG.h +++ b/include/llvm/CodeGen/SelectionDAG.h @@ -120,8 +120,10 @@ public: int offset = 0); SDOperand getFrameIndex(int FI, MVT::ValueType VT); SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT); - SDOperand getConstantPool(Constant *C, MVT::ValueType VT); - SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT); + SDOperand getConstantPool(Constant *C, MVT::ValueType VT, + unsigned Alignment=0); + SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT, + unsigned Alignment=0); SDOperand getBasicBlock(MachineBasicBlock *MBB); SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT); SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT); @@ -606,8 +608,8 @@ private: std::map, SDNode*> ConstantFPs; std::map, SDNode*> TargetConstantFPs; std::map FrameIndices, TargetFrameIndices; - std::map ConstantPoolIndices; - std::map TargetConstantPoolIndices; + std::map, SDNode*> ConstantPoolIndices; + std::map, SDNode*> TargetConstantPoolIndices; std::map BBNodes; std::vector ValueTypeNodes; std::map ExternalSymbols; diff --git a/include/llvm/CodeGen/SelectionDAGNodes.h b/include/llvm/CodeGen/SelectionDAGNodes.h index ae2519a8363..0b850e617b1 100644 --- a/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/include/llvm/CodeGen/SelectionDAGNodes.h @@ -1058,14 +1058,20 @@ public: class ConstantPoolSDNode : public SDNode { Constant *C; + unsigned Alignment; protected: friend class SelectionDAG; ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget) : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), - C(c) {} + C(c), Alignment(0) {} + ConstantPoolSDNode(Constant *c, MVT::ValueType VT, unsigned Align, + bool isTarget) + : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), + C(c), Alignment(Align) {} public: Constant *get() const { return C; } + unsigned getAlignment() const { return Alignment; } static bool classof(const ConstantPoolSDNode *) { return true; } static bool classof(const SDNode *N) { diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index ab0465df1c3..df00f47f293 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -103,7 +103,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { /// the code generator. /// void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { - const std::vector &CP = MCP->getConstants(); + const std::vector > &CP = MCP->getConstants(); if (CP.empty()) return; const TargetData &TD = TM.getTargetData(); @@ -111,13 +111,17 @@ void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { for (unsigned i = 0, e = CP.size(); i != e; ++i) { // FIXME: force doubles to be naturally aligned. We should handle this // more correctly in the future. - unsigned Alignment = TD.getTypeAlignmentShift(CP[i]->getType()); - if (CP[i]->getType() == Type::DoubleTy && Alignment < 3) Alignment = 3; + unsigned Alignment = CP[i].second; + if (Alignment == 0) { + Alignment = TD.getTypeAlignmentShift(CP[i].first->getType()); + if (CP[i].first->getType() == Type::DoubleTy && Alignment < 3) + Alignment = 3; + } EmitAlignment(Alignment); O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i - << ":\t\t\t\t\t" << CommentString << *CP[i] << '\n'; - EmitGlobalConstant(CP[i]); + << ":\t\t\t\t\t" << CommentString << *CP[i].first << '\n'; + EmitGlobalConstant(CP[i].first); } } diff --git a/lib/CodeGen/MachineFunction.cpp b/lib/CodeGen/MachineFunction.cpp index f0ece6b3dbb..3c41dbe4bb5 100644 --- a/lib/CodeGen/MachineFunction.cpp +++ b/lib/CodeGen/MachineFunction.cpp @@ -346,8 +346,11 @@ void MachineFrameInfo::dump(const MachineFunction &MF) const { //===----------------------------------------------------------------------===// void MachineConstantPool::print(std::ostream &OS) const { - for (unsigned i = 0, e = Constants.size(); i != e; ++i) - OS << " is" << *(Value*)Constants[i] << "\n"; + for (unsigned i = 0, e = Constants.size(); i != e; ++i) { + OS << " is" << *(Value*)Constants[i].first; + if (Constants[i].second != 0) OS << " , align=" << Constants[i].second; + OS << "\n"; + } } void MachineConstantPool::dump() const { print(std::cerr); } diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp index 9f285d5c9c9..c0fd3975649 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp @@ -194,7 +194,8 @@ void ScheduleDAG::EmitNode(NodeInfo *NI) { MI->addFrameIndexOperand(FI->getIndex()); } else if (ConstantPoolSDNode *CP = dyn_cast(Node->getOperand(i))) { - unsigned Idx = ConstPool->getConstantPoolIndex(CP->get()); + unsigned Idx = ConstPool->getConstantPoolIndex(CP->get(), + CP->getAlignment()); MI->addConstantPoolIndexOperand(Idx); } else if (ExternalSymbolSDNode *ES = dyn_cast(Node->getOperand(i))) { diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp index aa9ea638f8e..6f1a263048d 100644 --- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -310,10 +310,14 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { Erased = TargetFrameIndices.erase(cast(N)->getIndex()); break; case ISD::ConstantPool: - Erased = ConstantPoolIndices.erase(cast(N)->get()); + Erased = ConstantPoolIndices. + erase(std::make_pair(cast(N)->get(), + cast(N)->getAlignment())); break; case ISD::TargetConstantPool: - Erased =TargetConstantPoolIndices.erase(cast(N)->get()); + Erased = TargetConstantPoolIndices. + erase(std::make_pair(cast(N)->get(), + cast(N)->getAlignment())); break; case ISD::BasicBlock: Erased = BBNodes.erase(cast(N)->getBasicBlock()); @@ -655,18 +659,20 @@ SDOperand SelectionDAG::getTargetFrameIndex(int FI, MVT::ValueType VT) { return SDOperand(N, 0); } -SDOperand SelectionDAG::getConstantPool(Constant *C, MVT::ValueType VT) { - SDNode *&N = ConstantPoolIndices[C]; +SDOperand SelectionDAG::getConstantPool(Constant *C, MVT::ValueType VT, + unsigned Alignment) { + SDNode *&N = ConstantPoolIndices[std::make_pair(C, Alignment)]; if (N) return SDOperand(N, 0); - N = new ConstantPoolSDNode(C, VT, false); + N = new ConstantPoolSDNode(C, VT, Alignment, false); AllNodes.push_back(N); return SDOperand(N, 0); } -SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT) { - SDNode *&N = TargetConstantPoolIndices[C]; +SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT, + unsigned Alignment) { + SDNode *&N = TargetConstantPoolIndices[std::make_pair(C, Alignment)]; if (N) return SDOperand(N, 0); - N = new ConstantPoolSDNode(C, VT, true); + N = new ConstantPoolSDNode(C, VT, Alignment, true); AllNodes.push_back(N); return SDOperand(N, 0); } diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index fb204715efa..d2f943f4016 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -566,16 +566,18 @@ void JITEmitter::finishFunction(MachineFunction &F) { } void JITEmitter::emitConstantPool(MachineConstantPool *MCP) { - const std::vector &Constants = MCP->getConstants(); + const std::vector > &Constants = MCP->getConstants(); if (Constants.empty()) return; for (unsigned i = 0, e = Constants.size(); i != e; ++i) { - const Type *Ty = Constants[i]->getType(); + const Type *Ty = Constants[i].first->getType(); unsigned Size = (unsigned)TheJIT->getTargetData().getTypeSize(Ty); - unsigned Alignment = TheJIT->getTargetData().getTypeAlignment(Ty); + unsigned Alignment = (Constants[i].second == 0) + ? TheJIT->getTargetData().getTypeAlignment(Ty) + : Constants[i].second; void *Addr = MemMgr.allocateConstant(Size, Alignment); - TheJIT->InitializeMemory(Constants[i], Addr); + TheJIT->InitializeMemory(Constants[i].first, Addr); ConstantPoolAddresses.push_back(Addr); } } diff --git a/lib/Target/Alpha/AlphaISelLowering.cpp b/lib/Target/Alpha/AlphaISelLowering.cpp index 517ffaeab6a..2990146899b 100644 --- a/lib/Target/Alpha/AlphaISelLowering.cpp +++ b/lib/Target/Alpha/AlphaISelLowering.cpp @@ -482,8 +482,9 @@ SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { } } case ISD::ConstantPool: { - Constant *C = cast(Op)->get(); - SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64); + ConstantPoolSDNode *CP = cast(Op); + Constant *C = CP->get(); + SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64, CP->getAlignment()); SDOperand Hi = DAG.getNode(AlphaISD::GPRelHi, MVT::i64, CPI, DAG.getNode(AlphaISD::GlobalBaseReg, MVT::i64)); diff --git a/lib/Target/IA64/IA64ISelDAGToDAG.cpp b/lib/Target/IA64/IA64ISelDAGToDAG.cpp index 072b55b2124..2b817bb6fd8 100644 --- a/lib/Target/IA64/IA64ISelDAGToDAG.cpp +++ b/lib/Target/IA64/IA64ISelDAGToDAG.cpp @@ -442,8 +442,10 @@ SDOperand IA64DAGToDAGISel::Select(SDOperand Op) { case ISD::ConstantPool: { // TODO: nuke the constant pool // (ia64 doesn't need one) - Constant *C = cast(N)->get(); - SDOperand CPI = CurDAG->getTargetConstantPool(C, MVT::i64); + ConstantPoolSDNode *CP = cast(N); + Constant *C = CP->get(); + SDOperand CPI = CurDAG->getTargetConstantPool(C, MVT::i64, + CP->getAlignment()); return CurDAG->getTargetNode(IA64::ADDL_GA, MVT::i64, // ? CurDAG->getRegister(IA64::r1, MVT::i64), CPI); } diff --git a/lib/Target/PowerPC/PPCISelLowering.cpp b/lib/Target/PowerPC/PPCISelLowering.cpp index 8b5546d62cd..28beeafce16 100644 --- a/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/lib/Target/PowerPC/PPCISelLowering.cpp @@ -389,8 +389,9 @@ SDOperand PPCTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { return DAG.getNode(ISD::BUILD_PAIR, MVT::i64, OutLo, OutHi); } case ISD::ConstantPool: { - Constant *C = cast(Op)->get(); - SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32); + ConstantPoolSDNode *CP = cast(Op); + Constant *C = CP->get(); + SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32, CP->getAlignment()); SDOperand Zero = DAG.getConstant(0, MVT::i32); if (PPCGenerateStaticCode) { diff --git a/lib/Target/Sparc/SparcISelDAGToDAG.cpp b/lib/Target/Sparc/SparcISelDAGToDAG.cpp index 38f3c15a8a6..c2741059b03 100644 --- a/lib/Target/Sparc/SparcISelDAGToDAG.cpp +++ b/lib/Target/Sparc/SparcISelDAGToDAG.cpp @@ -693,7 +693,8 @@ LowerOperation(SDOperand Op, SelectionDAG &DAG) { } case ISD::ConstantPool: { Constant *C = cast(Op)->get(); - SDOperand CP = DAG.getTargetConstantPool(C, MVT::i32); + SDOperand CP = DAG.getTargetConstantPool(C, MVT::i32, + cast(Op)->getAlignment()); SDOperand Hi = DAG.getNode(V8ISD::Hi, MVT::i32, CP); SDOperand Lo = DAG.getNode(V8ISD::Lo, MVT::i32, CP); return DAG.getNode(ISD::ADD, MVT::i32, Lo, Hi); diff --git a/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp b/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp index 38f3c15a8a6..c2741059b03 100644 --- a/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp +++ b/lib/Target/SparcV8/SparcV8ISelDAGToDAG.cpp @@ -693,7 +693,8 @@ LowerOperation(SDOperand Op, SelectionDAG &DAG) { } case ISD::ConstantPool: { Constant *C = cast(Op)->get(); - SDOperand CP = DAG.getTargetConstantPool(C, MVT::i32); + SDOperand CP = DAG.getTargetConstantPool(C, MVT::i32, + cast(Op)->getAlignment()); SDOperand Hi = DAG.getNode(V8ISD::Hi, MVT::i32, CP); SDOperand Lo = DAG.getNode(V8ISD::Lo, MVT::i32, CP); return DAG.getNode(ISD::ADD, MVT::i32, Lo, Hi); diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp index 564c7edf1f0..638a6995228 100644 --- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp +++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp @@ -209,11 +209,14 @@ namespace { // Print a constant (which may be an aggregate) prefixed by all the // appropriate directives. Uses printConstantValueOnly() to print the // value or values. - void printConstant(const Constant* CV, std::string valID = "") { + void printConstant(const Constant* CV, unsigned Alignment, + std::string valID = "") { if (valID.length() == 0) valID = getID(CV); - O << "\t.align\t" << ConstantToAlignment(CV, TM) << "\n"; + if (Alignment == 0) + Alignment = ConstantToAlignment(CV, TM); + O << "\t.align\t" << Alignment << "\n"; // Print .size and .type only if it is not a string. if (const ConstantArray *CVA = dyn_cast(CV)) @@ -721,12 +724,12 @@ void SparcV9AsmPrinter::emitFunction(const Function &F) { // Emit constant pool for this function const MachineConstantPool *MCP = MF.getConstantPool(); - const std::vector &CP = MCP->getConstants(); + const std::vector > &CP = MCP->getConstants(); enterSection(ReadOnlyData); for (unsigned i = 0, e = CP.size(); i != e; ++i) { std::string cpiName = ".CPI_" + CurrentFnName + "_" + utostr(i); - printConstant(CP[i], cpiName); + printConstant(CP[i].first, CP[i].second, cpiName); } enterSection(Text); @@ -755,7 +758,7 @@ void SparcV9AsmPrinter::printGlobalVariable(const GlobalVariable* GV) { if (GV->hasInitializer() && !(GV->getInitializer()->isNullValue() || isa(GV->getInitializer()))) { - printConstant(GV->getInitializer(), getID(GV)); + printConstant(GV->getInitializer(), 0, getID(GV)); } else { O << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(), TM) << "\n";