Misc. SSE2 intrinsics: clflush, lfench, mfence
[oota-llvm.git] / lib / Target / Alpha / AlphaAsmPrinter.cpp
index d9f1f88c59b2eedc90c8b6eb16182bcd5e9bdac6..6f45fb5497f98df0e6486c857456dff551724278 100644 (file)
 #include "llvm/Module.h"
 #include "llvm/Type.h"
 #include "llvm/Assembly/Writer.h"
-#include "llvm/CodeGen/MachineConstantPool.h"
-#include "llvm/CodeGen/ValueTypes.h"
 #include "llvm/CodeGen/AsmPrinter.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Support/Mangler.h"
 #include "llvm/ADT/Statistic.h"
-
+#include <iostream>
 using namespace llvm;
 
 namespace {
@@ -55,8 +53,7 @@ namespace {
     }
     bool printInstruction(const MachineInstr *MI);
     void printOp(const MachineOperand &MO, bool IsCallOp = false);
-    void printConstantPool(MachineConstantPool *MCP);
-    void printOperand(const MachineInstr *MI, int opNum, MVT::ValueType VT);
+    void printOperand(const MachineInstr *MI, int opNum);
     void printBaseOffsetPair (const MachineInstr *MI, int i, bool brackets=true);
     void printMachineInstruction(const MachineInstr *MI);
     bool runOnMachineFunction(MachineFunction &F);
@@ -77,7 +74,7 @@ FunctionPass *llvm::createAlphaCodePrinterPass (std::ostream &o,
 
 #include "AlphaGenAsmWriter.inc"
 
-void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum, MVT::ValueType VT)
+void AlphaAsmPrinter::printOperand(const MachineInstr *MI, int opNum)
 {
   const MachineOperand &MO = MI->getOperand(opNum);
   if (MO.getType() == MachineOperand::MO_MachineRegister) {
@@ -128,7 +125,7 @@ void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
   }
 
   case MachineOperand::MO_ConstantPoolIndex:
-    O << PrivateGlobalPrefix << "CPI" << CurrentFnName << "_"
+    O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << "_"
       << MO.getConstantPoolIndex();
     return;
 
@@ -139,9 +136,9 @@ void AlphaAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
   case MachineOperand::MO_GlobalAddress:
     //Abuse PCrel to specify pcrel calls
     //calls are the only thing that use this flag
-    if (MO.isPCRelative())
-      O << PrivateGlobalPrefix << Mang->getValueName(MO.getGlobal()) << "..ng";
-    else
+//     if (MO.isPCRelative())
+//       O << PrivateGlobalPrefix << Mang->getValueName(MO.getGlobal()) << "..ng";
+//     else
       O << Mang->getValueName(MO.getGlobal());
     return;
 
@@ -173,12 +170,25 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   O << "\n\n";
 
   // Print out constants referenced by the function
-  printConstantPool(MF.getConstantPool());
+  EmitConstantPool(MF.getConstantPool());
 
   // Print out labels for the function.
-  SwitchSection("\t.section .text", MF.getFunction());
-  EmitAlignment(4);
-  O << "\t.globl " << CurrentFnName << "\n";
+  const Function *F = MF.getFunction();
+  SwitchSection(".text", F);
+  EmitAlignment(4, F);
+  switch (F->getLinkage()) {
+  default: assert(0 && "Unknown linkage type!");
+  case Function::InternalLinkage:  // Symbols default to internal.
+    break;
+   case Function::ExternalLinkage:
+     O << "\t.globl " << CurrentFnName << "\n";
+     break;
+  case Function::WeakLinkage:
+  case Function::LinkOnceLinkage:
+    O << "\t.weak " << CurrentFnName << "\n";
+    break;
+  }
+
   O << "\t.ent " << CurrentFnName << "\n";
 
   O << CurrentFnName << ":\n";
@@ -204,27 +214,6 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
   return false;
 }
 
-
-/// printConstantPool - 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 AlphaAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
-  const std::vector<Constant*> &CP = MCP->getConstants();
-  const TargetData &TD = TM.getTargetData();
-
-  if (CP.empty()) return;
-
-  SwitchSection("\t.section .rodata", 0);
-  for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    EmitAlignment(TD.getTypeAlignmentShift(CP[i]->getType()));
-    O << PrivateGlobalPrefix << "CPI" << CurrentFnName << "_" << i 
-      << ":\t\t\t\t\t" << CommentString << *CP[i] << "\n";
-    EmitGlobalConstant(CP[i]);
-  }
-}
-
 bool AlphaAsmPrinter::doInitialization(Module &M)
 {
   AsmPrinter::doInitialization(M);
@@ -242,11 +231,16 @@ bool AlphaAsmPrinter::doFinalization(Module &M) {
 
   for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
     if (I->hasInitializer()) {   // External global require no code
+      // Check to see if this is a special global used by LLVM, if so, emit it.
+      if (EmitSpecialLLVMGlobal(I))
+        continue;
+      
       O << "\n\n";
       std::string name = Mang->getValueName(I);
       Constant *C = I->getInitializer();
       unsigned Size = TD.getTypeSize(C->getType());
-      unsigned Align = TD.getTypeAlignmentShift(C->getType());
+      //      unsigned Align = TD.getTypeAlignmentShift(C->getType());
+      unsigned Align = getPreferredAlignmentLog(I);
 
       if (C->isNullValue() &&
           (I->hasLinkOnceLinkage() || I->hasInternalLinkage() ||
@@ -256,10 +250,8 @@ bool AlphaAsmPrinter::doFinalization(Module &M) {
           O << "\t.local " << name << "\n";
 
         O << "\t.comm " << name << "," << TD.getTypeSize(C->getType())
-          << "," << (1 << Align);
-        O << "\t\t# ";
-        WriteAsOperand(O, I, true, true, &M);
-        O << "\n";
+          << "," << (1 << Align)
+          <<  "\n";
       } else {
         switch (I->getLinkage()) {
         case GlobalValue::LinkOnceLinkage:
@@ -288,11 +280,7 @@ bool AlphaAsmPrinter::doFinalization(Module &M) {
         EmitAlignment(Align);
         O << "\t.type " << name << ",@object\n";
         O << "\t.size " << name << "," << Size << "\n";
-        O << name << ":\t\t\t\t# ";
-        WriteAsOperand(O, I, true, true, &M);
-        O << " = ";
-        WriteAsOperand(O, C, false, false, &M);
-        O << "\n";
+        O << name << ":\n";
         EmitGlobalConstant(C);
       }
     }