[llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp MachineFunction.cpp
Evan Cheng
evan.cheng at apple.com
Tue Sep 12 14:00:52 PDT 2006
Changes in directory llvm/lib/CodeGen:
AsmPrinter.cpp updated: 1.93 -> 1.94
MachineFunction.cpp updated: 1.97 -> 1.98
---
Log message:
Added support for machine specific constantpool values. These are useful for
representing expressions that can only be resolved at link time, etc.
---
Diffs of the changes: (+95 -38)
AsmPrinter.cpp | 93 ++++++++++++++++++++++++++++++++--------------------
MachineFunction.cpp | 40 ++++++++++++++++++++--
2 files changed, 95 insertions(+), 38 deletions(-)
Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.93 llvm/lib/CodeGen/AsmPrinter.cpp:1.94
--- llvm/lib/CodeGen/AsmPrinter.cpp:1.93 Thu Sep 7 17:06:40 2006
+++ llvm/lib/CodeGen/AsmPrinter.cpp Tue Sep 12 16:00:35 2006
@@ -126,10 +126,11 @@
std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > TargetCPs;
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
MachineConstantPoolEntry CPE = CP[i];
- const Constant *CV = CPE.Val;
- const Type *Ty = CV->getType();
+ const Type *Ty = CPE.isMachineConstantPoolEntry()
+ ? CPE.Val.MachineCPVal->getType() : CPE.Val.ConstVal->getType();
if (TAI->getFourByteConstantSection() &&
TM.getTargetData()->getTypeSize(Ty) == 4)
FourByteCPs.push_back(std::make_pair(CPE, i));
@@ -160,11 +161,20 @@
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
<< CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
- WriteTypeSymbolic(O, CP[i].first.Val->getType(), 0) << '\n';
- EmitGlobalConstant(CP[i].first.Val);
+ if (CP[i].first.isMachineConstantPoolEntry()) {
+ WriteTypeSymbolic(O, CP[i].first.Val.MachineCPVal->getType(), 0) << '\n';
+ printDataDirective(CP[i].first.Val.MachineCPVal->getType());
+ EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
+ } else {
+ WriteTypeSymbolic(O, CP[i].first.Val.ConstVal->getType(), 0) << '\n';
+ EmitGlobalConstant(CP[i].first.Val.ConstVal);
+ }
if (i != e-1) {
+ const Type *Ty = CP[i].first.isMachineConstantPoolEntry()
+ ? CP[i].first.Val.MachineCPVal->getType()
+ : CP[i].first.Val.ConstVal->getType();
unsigned EntSize =
- TM.getTargetData()->getTypeSize(CP[i].first.Val->getType());
+ TM.getTargetData()->getTypeSize(Ty);
unsigned ValEnd = CP[i].first.Offset + EntSize;
// Emit inter-object padding for alignment.
EmitZeros(CP[i+1].first.Offset-ValEnd);
@@ -580,40 +590,17 @@
}
const Type *type = CV->getType();
- switch (type->getTypeID()) {
- case Type::BoolTyID:
- case Type::UByteTyID: case Type::SByteTyID:
- O << TAI->getData8bitsDirective();
- break;
- case Type::UShortTyID: case Type::ShortTyID:
- O << TAI->getData16bitsDirective();
- break;
- case Type::PointerTyID:
- if (TD->getPointerSize() == 8) {
- assert(TAI->getData64bitsDirective() &&
- "Target cannot handle 64-bit pointer exprs!");
- O << TAI->getData64bitsDirective();
- break;
- }
- //Fall through for pointer size == int size
- case Type::UIntTyID: case Type::IntTyID:
- O << TAI->getData32bitsDirective();
- break;
- case Type::ULongTyID: case Type::LongTyID:
- assert(TAI->getData64bitsDirective() &&
- "Target cannot handle 64-bit constant exprs!");
- O << TAI->getData64bitsDirective();
- break;
- case Type::FloatTyID: case Type::DoubleTyID:
- assert (0 && "Should have already output floating point constant.");
- default:
- assert (0 && "Can't handle printing this type of thing");
- break;
- }
+ printDataDirective(type);
EmitConstantValueOnly(CV);
O << "\n";
}
+void
+AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
+ // Target doesn't support this yet!
+ abort();
+}
+
/// printInlineAsm - This method formats and prints the specified machine
/// instruction that is an inline asm.
void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
@@ -829,3 +816,39 @@
O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
<< '_' << uid << '\n';
}
+
+/// printDataDirective - This method prints the asm directive for the
+/// specified type.
+void AsmPrinter::printDataDirective(const Type *type) {
+ const TargetData *TD = TM.getTargetData();
+ switch (type->getTypeID()) {
+ case Type::BoolTyID:
+ case Type::UByteTyID: case Type::SByteTyID:
+ O << TAI->getData8bitsDirective();
+ break;
+ case Type::UShortTyID: case Type::ShortTyID:
+ O << TAI->getData16bitsDirective();
+ break;
+ case Type::PointerTyID:
+ if (TD->getPointerSize() == 8) {
+ assert(TAI->getData64bitsDirective() &&
+ "Target cannot handle 64-bit pointer exprs!");
+ O << TAI->getData64bitsDirective();
+ break;
+ }
+ //Fall through for pointer size == int size
+ case Type::UIntTyID: case Type::IntTyID:
+ O << TAI->getData32bitsDirective();
+ break;
+ case Type::ULongTyID: case Type::LongTyID:
+ assert(TAI->getData64bitsDirective() &&
+ "Target cannot handle 64-bit constant exprs!");
+ O << TAI->getData64bitsDirective();
+ break;
+ case Type::FloatTyID: case Type::DoubleTyID:
+ assert (0 && "Should have already output floating point constant.");
+ default:
+ assert (0 && "Can't handle printing this type of thing");
+ break;
+ }
+}
Index: llvm/lib/CodeGen/MachineFunction.cpp
diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.97 llvm/lib/CodeGen/MachineFunction.cpp:1.98
--- llvm/lib/CodeGen/MachineFunction.cpp:1.97 Sun Aug 27 07:54:01 2006
+++ llvm/lib/CodeGen/MachineFunction.cpp Tue Sep 12 16:00:35 2006
@@ -351,6 +351,12 @@
// MachineConstantPool implementation
//===----------------------------------------------------------------------===//
+MachineConstantPool::~MachineConstantPool() {
+ for (unsigned i = 0, e = Constants.size(); i != e; ++i)
+ if (Constants[i].isMachineConstantPoolEntry())
+ delete Constants[i].Val.MachineCPVal;
+}
+
/// getConstantPoolIndex - Create a new entry in the constant pool or return
/// an existing one. User must specify an alignment in bytes for the object.
///
@@ -364,13 +370,13 @@
// 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 == C && (Constants[i].Offset & AlignMask) == 0)
+ if (Constants[i].Val.ConstVal == C && (Constants[i].Offset & AlignMask)== 0)
return i;
unsigned Offset = 0;
if (!Constants.empty()) {
Offset = Constants.back().Offset;
- Offset += TD->getTypeSize(Constants.back().Val->getType());
+ Offset += TD->getTypeSize(Constants.back().Val.ConstVal->getType());
Offset = (Offset+AlignMask)&~AlignMask;
}
@@ -378,10 +384,38 @@
return Constants.size()-1;
}
+unsigned MachineConstantPool::getConstantPoolIndex(MachineConstantPoolValue *V,
+ unsigned Alignment) {
+ assert(Alignment && "Alignment must be specified!");
+ if (Alignment > PoolAlignment) PoolAlignment = Alignment;
+
+ // 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().Offset;
+ Offset += TD->getTypeSize(Constants.back().Val.MachineCPVal->getType());
+ Offset = (Offset+AlignMask)&~AlignMask;
+ }
+
+ Constants.push_back(MachineConstantPoolEntry(V, Offset));
+ return Constants.size()-1;
+}
+
void MachineConstantPool::print(std::ostream &OS) const {
for (unsigned i = 0, e = Constants.size(); i != e; ++i) {
- OS << " <cp #" << i << "> is" << *(Value*)Constants[i].Val;
+ OS << " <cp #" << i << "> is";
+ if (Constants[i].isMachineConstantPoolEntry())
+ Constants[i].Val.MachineCPVal->print(OS);
+ else
+ OS << *(Value*)Constants[i].Val.ConstVal;
OS << " , offset=" << Constants[i].Offset;
OS << "\n";
}
More information about the llvm-commits
mailing list