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/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index ab0465d..df00f47 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -103,7 +103,7 @@
/// 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 @@
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 f0ece6b..3c41dbe 100644
--- a/lib/CodeGen/MachineFunction.cpp
+++ b/lib/CodeGen/MachineFunction.cpp
@@ -346,8 +346,11 @@
//===----------------------------------------------------------------------===//
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); }
diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
index 9f285d5..c0fd397 100644
--- a/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/ScheduleDAG.cpp
@@ -194,7 +194,8 @@
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))) {
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index aa9ea63..6f1a263 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -310,10 +310,14 @@
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 @@
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);
}