aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvan Cheng <evan.cheng@apple.com>2006-06-29 00:26:09 +0000
committerEvan Cheng <evan.cheng@apple.com>2006-06-29 00:26:09 +0000
commit2d2cec1e9e93a388bd8448f4bad661ac89a49de3 (patch)
tree0d32690f2b8f01045e3d995f4a1daaf482c8a420
parent2c79de8018bb8c77a245d4ccb740affbf1f52319 (diff)
Add support to print 4-, 8-, and 16- byte constant literals in special
sections. e.g. On Darwin that would be .literal4 and .literal8. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28977 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/CodeGen/AsmPrinter.h12
-rw-r--r--lib/CodeGen/AsmPrinter.cpp58
2 files changed, 59 insertions, 11 deletions
diff --git a/include/llvm/CodeGen/AsmPrinter.h b/include/llvm/CodeGen/AsmPrinter.h
index 3b47a8ff94..c90a3eedae 100644
--- a/include/llvm/CodeGen/AsmPrinter.h
+++ b/include/llvm/CodeGen/AsmPrinter.h
@@ -24,6 +24,7 @@ namespace llvm {
class ConstantArray;
class Mangler;
class GlobalVariable;
+ class MachineConstantPoolEntry;
class AsmPrinter : public MachineFunctionPass {
/// FunctionNumber - This provides a unique ID for each function emitted in
@@ -168,6 +169,13 @@ namespace llvm {
/// a section to emit the static destructor list.
/// Defaults to "\t.section .dtors,\"aw\",@progbits".
const char *StaticDtorsSection;
+
+ /// FourByteConstantSection, EightByteConstantSection,
+ /// SixteenByteConstantSection - These are special sections where we place
+ /// 4-, 8-, and 16- byte constant literals.
+ const char *FourByteConstantSection;
+ const char *EightByteConstantSection;
+ const char *SixteenByteConstantSection;
//===--- Global Variable Emission Directives --------------------------===//
@@ -265,7 +273,7 @@ namespace llvm {
/// used to print out constants which have been "spilled to memory" by
/// the code generator.
///
- virtual void EmitConstantPool(MachineConstantPool *MCP);
+ void EmitConstantPool(MachineConstantPool *MCP);
/// EmitJumpTableInfo - Print assembly representations of the jump tables
/// used by the current function to the current output stream.
@@ -311,6 +319,8 @@ namespace llvm {
private:
void EmitXXStructorList(Constant *List);
+ void EmitConstantPool(unsigned Alignment, const char *Section,
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP);
};
}
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index 9f00fb2bff..d4facd27a4 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -55,6 +55,9 @@ AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
JumpTableSection("\t.section .rodata\n"),
StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
+ FourByteConstantSection(0),
+ EightByteConstantSection(0),
+ SixteenByteConstantSection(0),
LCOMMDirective(0),
COMMDirective("\t.comm\t"),
COMMDirectiveTakesAlignment(true),
@@ -147,19 +150,54 @@ void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
if (CP.empty()) return;
-
- SwitchToDataSection(ConstantPoolSection, 0);
- EmitAlignment(MCP->getConstantPoolAlignment());
+
+ // Some targets require 4-, 8-, and 16- byte constant literals to be placed
+ // in special sections.
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
+ for (unsigned i = 0, e = CP.size(); i != e; ++i) {
+ MachineConstantPoolEntry CPE = CP[i];
+ const Constant *CV = CPE.Val;
+ const Type *Ty = CV->getType();
+ if (FourByteConstantSection &&
+ TM.getTargetData()->getTypeSize(Ty) == 4)
+ FourByteCPs.push_back(std::make_pair(CPE, i));
+ else if (EightByteConstantSection &&
+ TM.getTargetData()->getTypeSize(Ty) == 8)
+ EightByteCPs.push_back(std::make_pair(CPE, i));
+ else if (SixteenByteConstantSection &&
+ TM.getTargetData()->getTypeSize(Ty) == 16)
+ SixteenByteCPs.push_back(std::make_pair(CPE, i));
+ else
+ OtherCPs.push_back(std::make_pair(CPE, i));
+ }
+
+ unsigned Alignment = MCP->getConstantPoolAlignment();
+ EmitConstantPool(Alignment, FourByteConstantSection, FourByteCPs);
+ EmitConstantPool(Alignment, EightByteConstantSection, EightByteCPs);
+ EmitConstantPool(Alignment, SixteenByteConstantSection, SixteenByteCPs);
+ EmitConstantPool(Alignment, ConstantPoolSection, OtherCPs);
+}
+
+void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
+ std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
+ if (CP.empty()) return;
+
+ SwitchToDataSection(Section, 0);
+ EmitAlignment(Alignment);
for (unsigned i = 0, e = CP.size(); i != e; ++i) {
- O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_' << i
- << ":\t\t\t\t\t" << CommentString << " ";
- WriteTypeSymbolic(O, CP[i].Val->getType(), 0) << '\n';
- EmitGlobalConstant(CP[i].Val);
+ O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_'
+ << CP[i].second << ":\t\t\t\t\t" << CommentString << " ";
+ WriteTypeSymbolic(O, CP[i].first.Val->getType(), 0) << '\n';
+ EmitGlobalConstant(CP[i].first.Val);
if (i != e-1) {
- unsigned EntSize = TM.getTargetData()->getTypeSize(CP[i].Val->getType());
- unsigned ValEnd = CP[i].Offset + EntSize;
+ unsigned EntSize =
+ TM.getTargetData()->getTypeSize(CP[i].first.Val->getType());
+ unsigned ValEnd = CP[i].first.Offset + EntSize;
// Emit inter-object padding for alignment.
- EmitZeros(CP[i+1].Offset-ValEnd);
+ EmitZeros(CP[i+1].first.Offset-ValEnd);
}
}
}