diff options
author | Chris Lattner <sabre@nondot.org> | 2005-11-21 08:25:09 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2005-11-21 08:25:09 +0000 |
commit | 3b4fd32a41a90ea67fd09a020d480c20e9c40daf (patch) | |
tree | 698aefd5a2eea9f9e142e54b3609ea509126f5f8 | |
parent | 97e32e3239c0f065698f8c004b2b3009162f5ed6 (diff) |
Allow target to customize directive used to switch to arbitrary section in SwitchSection,
add generic constant pool emitter
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24464 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/AsmPrinter.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp index 86c3f4bb95..0e9802d5c1 100644 --- a/lib/CodeGen/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter.cpp @@ -14,6 +14,7 @@ #include "llvm/CodeGen/AsmPrinter.h" #include "llvm/Constants.h" #include "llvm/Module.h" +#include "llvm/CodeGen/MachineConstantPool.h" #include "llvm/Support/Mangler.h" #include "llvm/Support/MathExtras.h" #include "llvm/Target/TargetMachine.h" @@ -26,7 +27,7 @@ void AsmPrinter::SwitchSection(const char *NewSection, const GlobalValue *GV) { std::string NS; if (GV && GV->hasSection()) - NS = ".section " + GV->getSection(); + NS = SwitchToSectionDirective + GV->getSection(); else NS = NewSection; @@ -54,6 +55,32 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) { IncrementFunctionNumber(); } +/// 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 +/// the code generator. +/// +void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) { + const std::vector<Constant*> &CP = MCP->getConstants(); + if (CP.empty()) return; + const TargetData &TD = TM.getTargetData(); + + SwitchSection(ConstantPoolSection, 0); + 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; + + EmitAlignment(Alignment); + O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i + << ":\t\t\t\t\t" << CommentString << *CP[i] << '\n'; + EmitGlobalConstant(CP[i]); + } +} + + + // EmitAlignment - Emit an alignment directive to the specified power of two. void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const { if (GV && GV->getAlignment()) |