mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-26 06:04:47 +00:00
Allow the specification of explicit alignments for constant pool entries.
llvm-svn: 25855
This commit is contained in:
parent
5587b270e4
commit
f115c17f23
@ -30,20 +30,23 @@ namespace llvm {
|
||||
class Constant;
|
||||
|
||||
class MachineConstantPool {
|
||||
std::vector<Constant*> Constants;
|
||||
std::vector<std::pair<Constant*,unsigned> > 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<Constant*> &getConstants() const { return Constants; }
|
||||
const std::vector<std::pair<Constant*,unsigned> > &getConstants() const {
|
||||
return Constants;
|
||||
}
|
||||
|
||||
/// print - Used by the MachineFunction printer to print information about
|
||||
/// stack objects. Implemented in MachineFunction.cpp
|
||||
|
@ -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<std::pair<uint64_t, MVT::ValueType>, SDNode*> ConstantFPs;
|
||||
std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstantFPs;
|
||||
std::map<int, SDNode*> FrameIndices, TargetFrameIndices;
|
||||
std::map<Constant *, SDNode*> ConstantPoolIndices;
|
||||
std::map<Constant *, SDNode*> TargetConstantPoolIndices;
|
||||
std::map<std::pair<Constant *, unsigned>, SDNode*> ConstantPoolIndices;
|
||||
std::map<std::pair<Constant *, unsigned>, SDNode*> TargetConstantPoolIndices;
|
||||
std::map<MachineBasicBlock *, SDNode*> BBNodes;
|
||||
std::vector<SDNode*> ValueTypeNodes;
|
||||
std::map<std::string, SDNode*> ExternalSymbols;
|
||||
|
@ -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) {
|
||||
|
@ -103,7 +103,7 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
|
||||
/// the code generator.
|
||||
///
|
||||
void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
|
||||
const std::vector<Constant*> &CP = MCP->getConstants();
|
||||
const std::vector<std::pair<Constant*, unsigned> > &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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 << " <cp #" << i << "> is" << *(Value*)Constants[i] << "\n";
|
||||
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
|
||||
OS << " <cp #" << i << "> is" << *(Value*)Constants[i].first;
|
||||
if (Constants[i].second != 0) OS << " , align=" << Constants[i].second;
|
||||
OS << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void MachineConstantPool::dump() const { print(std::cerr); }
|
||||
|
@ -194,7 +194,8 @@ void ScheduleDAG::EmitNode(NodeInfo *NI) {
|
||||
MI->addFrameIndexOperand(FI->getIndex());
|
||||
} else if (ConstantPoolSDNode *CP =
|
||||
dyn_cast<ConstantPoolSDNode>(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<ExternalSymbolSDNode>(Node->getOperand(i))) {
|
||||
|
@ -310,10 +310,14 @@ void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) {
|
||||
Erased = TargetFrameIndices.erase(cast<FrameIndexSDNode>(N)->getIndex());
|
||||
break;
|
||||
case ISD::ConstantPool:
|
||||
Erased = ConstantPoolIndices.erase(cast<ConstantPoolSDNode>(N)->get());
|
||||
Erased = ConstantPoolIndices.
|
||||
erase(std::make_pair(cast<ConstantPoolSDNode>(N)->get(),
|
||||
cast<ConstantPoolSDNode>(N)->getAlignment()));
|
||||
break;
|
||||
case ISD::TargetConstantPool:
|
||||
Erased =TargetConstantPoolIndices.erase(cast<ConstantPoolSDNode>(N)->get());
|
||||
Erased = TargetConstantPoolIndices.
|
||||
erase(std::make_pair(cast<ConstantPoolSDNode>(N)->get(),
|
||||
cast<ConstantPoolSDNode>(N)->getAlignment()));
|
||||
break;
|
||||
case ISD::BasicBlock:
|
||||
Erased = BBNodes.erase(cast<BasicBlockSDNode>(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);
|
||||
}
|
||||
|
@ -566,16 +566,18 @@ void JITEmitter::finishFunction(MachineFunction &F) {
|
||||
}
|
||||
|
||||
void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
|
||||
const std::vector<Constant*> &Constants = MCP->getConstants();
|
||||
const std::vector<std::pair<Constant*,unsigned> > &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);
|
||||
}
|
||||
}
|
||||
|
@ -482,8 +482,9 @@ SDOperand AlphaTargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
|
||||
}
|
||||
}
|
||||
case ISD::ConstantPool: {
|
||||
Constant *C = cast<ConstantPoolSDNode>(Op)->get();
|
||||
SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i64);
|
||||
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(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));
|
||||
|
@ -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<ConstantPoolSDNode>(N)->get();
|
||||
SDOperand CPI = CurDAG->getTargetConstantPool(C, MVT::i64);
|
||||
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(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);
|
||||
}
|
||||
|
@ -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<ConstantPoolSDNode>(Op)->get();
|
||||
SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32);
|
||||
ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
|
||||
Constant *C = CP->get();
|
||||
SDOperand CPI = DAG.getTargetConstantPool(C, MVT::i32, CP->getAlignment());
|
||||
SDOperand Zero = DAG.getConstant(0, MVT::i32);
|
||||
|
||||
if (PPCGenerateStaticCode) {
|
||||
|
@ -693,7 +693,8 @@ LowerOperation(SDOperand Op, SelectionDAG &DAG) {
|
||||
}
|
||||
case ISD::ConstantPool: {
|
||||
Constant *C = cast<ConstantPoolSDNode>(Op)->get();
|
||||
SDOperand CP = DAG.getTargetConstantPool(C, MVT::i32);
|
||||
SDOperand CP = DAG.getTargetConstantPool(C, MVT::i32,
|
||||
cast<ConstantPoolSDNode>(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);
|
||||
|
@ -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<ConstantArray>(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<Constant*> &CP = MCP->getConstants();
|
||||
const std::vector<std::pair<Constant*, unsigned> > &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<UndefValue>(GV->getInitializer()))) {
|
||||
printConstant(GV->getInitializer(), getID(GV));
|
||||
printConstant(GV->getInitializer(), 0, getID(GV));
|
||||
} else {
|
||||
O << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
|
||||
TM) << "\n";
|
||||
|
Loading…
x
Reference in New Issue
Block a user