Darwin puts float and double literal constants into literal4 and literal8 sections.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 28 Jun 2006 07:35:41 +0000 (07:35 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 28 Jun 2006 07:35:41 +0000 (07:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28957 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86AsmPrinter.cpp
lib/Target/X86/X86AsmPrinter.h

index c366acc2f621e3ccbf97994637d3cd938f0869e9..5e35487a21e779f82a141d7609b0db6dfcc26e94 100644 (file)
@@ -222,6 +222,58 @@ bool X86SharedAsmPrinter::doFinalization(Module &M) {
   return false; // success
 }
 
+void X86SharedAsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
+  if (!Subtarget->TargetType == X86Subtarget::isDarwin) {
+    AsmPrinter::EmitConstantPool(MCP);
+    return;
+  }
+
+  const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
+  if (CP.empty()) return;
+
+  std::vector<MachineConstantPoolEntry> FloatCPs;
+  std::vector<MachineConstantPoolEntry> DoubleCPs;
+  std::vector<MachineConstantPoolEntry> OtherCPs;
+  //  const TargetData *TD = TM.getTargetData();
+  //  unsigned Align = MCP->getConstantPoolAlignment();
+  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 (Ty->getTypeID() == Type::FloatTyID)
+      FloatCPs.push_back(CPE);
+    else if (Ty->getTypeID() == Type::DoubleTyID)
+      DoubleCPs.push_back(CPE);
+    else
+      OtherCPs.push_back(CPE);
+  }
+  EmitConstantPool(MCP, FloatCPs,  "\t.literal4");
+  EmitConstantPool(MCP, DoubleCPs, "\t.literal8");
+  EmitConstantPool(MCP, OtherCPs,  ConstantPoolSection);
+}
+
+void
+X86SharedAsmPrinter::EmitConstantPool(MachineConstantPool *MCP,
+                                      std::vector<MachineConstantPoolEntry> &CP,
+                                      const char *Section) {
+  if (CP.empty()) return;
+
+  SwitchToDataSection(Section, 0);
+  EmitAlignment(MCP->getConstantPoolAlignment());
+  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);
+    if (i != e-1) {
+      unsigned EntSize = TM.getTargetData()->getTypeSize(CP[i].Val->getType());
+      unsigned ValEnd = CP[i].Offset + EntSize;
+      // Emit inter-object padding for alignment.
+      EmitZeros(CP[i+1].Offset-ValEnd);
+    }
+  }
+}
+
 /// createX86CodePrinterPass - Returns a pass that prints the X86 assembly code
 /// for a MachineFunction to the given output stream, using the given target
 /// machine description.
index eee956cd43b457c9a62da19367e0126563158e13..7c1b6244246c30cae6632ae5204990f3915aaee2 100755 (executable)
@@ -20,6 +20,7 @@
 #include "X86TargetMachine.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/CodeGen/DwarfWriter.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
 #include "llvm/CodeGen/MachineDebugInfo.h"
 #include "llvm/ADT/Statistic.h"
 #include <set>
@@ -92,6 +93,11 @@ struct X86SharedAsmPrinter : public AsmPrinter {
        MI->getOperand(Op+3).isGlobalAddress() ||
        MI->getOperand(Op+3).isConstantPoolIndex());
   }
+
+  virtual void EmitConstantPool(MachineConstantPool *MCP);
+  void EmitConstantPool(MachineConstantPool *MCP,
+                        std::vector<MachineConstantPoolEntry> &CP,
+                        const char *Section);
 };
 
 } // end namespace llvm