Missed a couple of places where new instructions are added due to spill / restore.
[oota-llvm.git] / lib / CodeGen / AsmPrinter.cpp
index 771d64ca239417672a76f7ce5a3cc302b9807305..586472c38ef9b17f2021b7c36a7bc797a43eef7e 100644 (file)
@@ -32,9 +32,10 @@ using namespace llvm;
 static cl::opt<bool>
 AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
 
+char AsmPrinter::ID = 0;
 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
                        const TargetAsmInfo *T)
-: FunctionNumber(0), O(o), TM(tm), TAI(T)
+  : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
 {}
 
 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
@@ -111,7 +112,7 @@ bool AsmPrinter::doInitialization(Module &M) {
 
 bool AsmPrinter::doFinalization(Module &M) {
   if (TAI->getWeakRefDirective()) {
-    if (ExtWeakSymbols.begin() != ExtWeakSymbols.end())
+    if (!ExtWeakSymbols.empty())
       SwitchToDataSection("");
 
     for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
@@ -122,6 +123,32 @@ bool AsmPrinter::doFinalization(Module &M) {
     }
   }
 
+  if (TAI->getSetDirective()) {
+    if (!M.alias_empty())
+      SwitchToTextSection(TAI->getTextSection());
+
+    O << "\n";
+    for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
+         I!=E; ++I) {
+      std::string Name = Mang->getValueName(I);
+      std::string Target;
+      
+      if (const GlobalValue *GV = I->getAliasedGlobal())
+        Target = Mang->getValueName(GV);
+      else
+        assert(0 && "Unsupported aliasee");
+      
+      if (I->hasExternalLinkage())
+        O << "\t.globl\t" << Name << "\n";
+      else if (I->hasWeakLinkage())
+        O << TAI->getWeakRefDirective() << Name << "\n";
+      else if (!I->hasInternalLinkage())
+        assert(0 && "Invalid alias linkage");
+      
+      O << TAI->getSetDirective() << Name << ", " << Target << "\n";
+    }
+  }
+
   delete Mang; Mang = 0;
   return false;
 }
@@ -300,16 +327,18 @@ bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
     return true;
   }
 
+  const TargetData *TD = TM.getTargetData();
+  unsigned Align = Log2_32(TD->getPointerPrefAlignment());
   if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
     SwitchToDataSection(TAI->getStaticCtorsSection());
-    EmitAlignment(2, 0);
+    EmitAlignment(Align, 0);
     EmitXXStructorList(GV->getInitializer());
     return true;
   } 
   
   if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
     SwitchToDataSection(TAI->getStaticDtorsSection());
-    EmitAlignment(2, 0);
+    EmitAlignment(Align, 0);
     EmitXXStructorList(GV->getInitializer());
     return true;
   }
@@ -370,6 +399,14 @@ const std::string AsmPrinter::getGlobalLinkName(const GlobalVariable *GV) const{
   return LinkName;
 }
 
+/// EmitExternalGlobal - Emit the external reference to a global variable.
+/// Should be overridden if an indirect reference should be used.
+void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
+  O << getGlobalLinkName(GV);
+}
+
+
+
 //===----------------------------------------------------------------------===//
 /// LEB 128 number encoding.
 
@@ -440,6 +477,9 @@ void AsmPrinter::PrintHex(int Value) const {
 
 /// EOL - Print a newline character to asm stream.  If a comment is present
 /// then it will be printed first.  Comments should not contain '\n'.
+void AsmPrinter::EOL() const {
+  O << "\n";
+}
 void AsmPrinter::EOL(const std::string &Comment) const {
   if (AsmVerbose && !Comment.empty()) {
     O << "\t"
@@ -548,27 +588,50 @@ static void printStringChar(std::ostream &O, unsigned char C) {
 /// Special characters are emitted properly.
 /// \literal (Eg. '\t') \endliteral
 void AsmPrinter::EmitString(const std::string &String) const {
-  O << TAI->getAsciiDirective()
-    << "\"";
+  const char* AscizDirective = TAI->getAscizDirective();
+  if (AscizDirective)
+    O << AscizDirective;
+  else
+    O << TAI->getAsciiDirective();
+  O << "\"";
   for (unsigned i = 0, N = String.size(); i < N; ++i) {
     unsigned char C = String[i];
     printStringChar(O, C);
   }
-  O << "\\0\"";
+  if (AscizDirective)
+    O << "\"";
+  else
+    O << "\\0\"";
 }
 
 
 //===----------------------------------------------------------------------===//
 
-// EmitAlignment - Emit an alignment directive to the specified power of two.
-void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
+// EmitAlignment - Emit an alignment directive to the specified power of
+// two boundary.  For example, if you pass in 3 here, you will get an 8
+// byte alignment.  If a global value is specified, and if that global has
+// an explicit alignment requested, it will unconditionally override the
+// alignment request.  However, if ForcedAlignBits is specified, this value
+// has final say: the ultimate alignment will be the max of ForcedAlignBits
+// and the alignment computed with NumBits and the global.
+//
+// The algorithm is:
+//     Align = NumBits;
+//     if (GV && GV->hasalignment) Align = GV->getalignment();
+//     Align = std::max(Align, ForcedAlignBits);
+//
+void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
+                               unsigned ForcedAlignBits) const {
   if (GV && GV->getAlignment())
     NumBits = Log2_32(GV->getAlignment());
+  NumBits = std::max(NumBits, ForcedAlignBits);
+  
   if (NumBits == 0) return;   // No need to emit alignment.
   if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
   O << TAI->getAlignDirective() << NumBits << "\n";
 }
 
+    
 /// EmitZeros - Emit a block of zeros.
 ///
 void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
@@ -907,7 +970,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
     }
     case '\n':
       ++LastEmitted;   // Consume newline character.
-      O << "\n\t";     // Indent code with newline.
+      O << "\n";       // Indent code with newline.
       break;
     case '$': {
       ++LastEmitted;   // Consume '$' character.
@@ -1047,7 +1110,7 @@ void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
 void AsmPrinter::printLabel(const MachineInstr *MI) const {
   O << "\n"
     << TAI->getPrivateGlobalPrefix()
-    << "label_"
+    << "label"
     << MI->getOperand(0).getImmedValue()
     << ":\n";
 }