[llvm-commits] CVS: llvm/lib/CodeGen/AsmPrinter.cpp

Evan Cheng evan.cheng at apple.com
Wed Jun 28 17:26:22 PDT 2006



Changes in directory llvm/lib/CodeGen:

AsmPrinter.cpp updated: 1.82 -> 1.83
---
Log message:

Add support to print 4-, 8-, and 16- byte constant literals in special
sections. e.g. On Darwin that would be .literal4 and .literal8.


---
Diffs of the changes:  (+48 -10)

 AsmPrinter.cpp |   58 +++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 48 insertions(+), 10 deletions(-)


Index: llvm/lib/CodeGen/AsmPrinter.cpp
diff -u llvm/lib/CodeGen/AsmPrinter.cpp:1.82 llvm/lib/CodeGen/AsmPrinter.cpp:1.83
--- llvm/lib/CodeGen/AsmPrinter.cpp:1.82	Thu Jun 15 14:37:14 2006
+++ llvm/lib/CodeGen/AsmPrinter.cpp	Wed Jun 28 19:26:09 2006
@@ -55,6 +55,9 @@
   JumpTableSection("\t.section .rodata\n"),
   StaticCtorsSection("\t.section .ctors,\"aw\", at progbits"),
   StaticDtorsSection("\t.section .dtors,\"aw\", at progbits"),
+  FourByteConstantSection(0),
+  EightByteConstantSection(0),
+  SixteenByteConstantSection(0),
   LCOMMDirective(0),
   COMMDirective("\t.comm\t"),
   COMMDirectiveTakesAlignment(true),
@@ -147,19 +150,54 @@
 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);
     }
   }
 }






More information about the llvm-commits mailing list