refactor call operand handling to eliminate special cases from printOp.
[oota-llvm.git] / lib / Target / PowerPC / PPCAsmPrinter.cpp
index 4b1404b2021d44b8b38f5a918c68abc29e779763..7367c41274caca55b091f55564f093bac05e263a 100644 (file)
@@ -103,7 +103,7 @@ namespace {
     bool printInstruction(const MachineInstr *MI);
 
     void printMachineInstruction(const MachineInstr *MI);
-    void printOp(const MachineOperand &MO, bool IsCallOp = false);
+    void printOp(const MachineOperand &MO);
 
     void printOperand(const MachineInstr *MI, unsigned OpNo, MVT::ValueType VT){
       const MachineOperand &MO = MI->getOperand(OpNo);
@@ -148,10 +148,31 @@ namespace {
       if (MI->getOperand(OpNo).isImmediate()) {
         O << "$+" << MI->getOperand(OpNo).getImmedValue();
       } else {
-        printOp(MI->getOperand(OpNo),
-                TM.getInstrInfo()->isCall(MI->getOpcode()));
+        printOp(MI->getOperand(OpNo));
+      }
+    }
+    void printCallOperand(const MachineInstr *MI, unsigned OpNo,
+                          MVT::ValueType VT) {
+      const MachineOperand &MO = MI->getOperand(OpNo);
+      if (MO.getType() == MachineOperand::MO_ExternalSymbol) {
+        std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+        FnStubs.insert(Name);
+        O << "L" << Name << "$stub";
+      } else if (MO.getType() == MachineOperand::MO_GlobalAddress &&
+                 isa<Function>(MO.getGlobal()) && 
+                 cast<Function>(MO.getGlobal())->isExternal()) {
+        // Dynamically-resolved functions need a stub for the function.
+        std::string Name = Mang->getValueName(MO.getGlobal());
+        FnStubs.insert(Name);
+        O << "L" << Name << "$stub";
+      } else {
+        printOp(MI->getOperand(OpNo));
       }
     }
+    void printAbsAddrOperand(const MachineInstr *MI, unsigned OpNo,
+                             MVT::ValueType VT) {
+     O << (int)MI->getOperand(OpNo).getImmedValue()*4;
+    }
     void printPICLabel(const MachineInstr *MI, unsigned OpNo,
                        MVT::ValueType VT) {
       // FIXME: should probably be converted to cout.width and cout.fill
@@ -266,7 +287,7 @@ FunctionPass *llvm::createAIXAsmPrinter(std::ostream &o, TargetMachine &tm) {
 // Include the auto-generated portion of the assembly writer
 #include "PPCGenAsmWriter.inc"
 
-void PPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
+void PPCAsmPrinter::printOp(const MachineOperand &MO) {
   const MRegisterInfo &RI = *TM.getRegisterInfo();
   int new_symbol;
 
@@ -305,12 +326,6 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
     return;
 
   case MachineOperand::MO_ExternalSymbol:
-    if (IsCallOp) {
-      std::string Name(GlobalPrefix); Name += MO.getSymbolName();
-      FnStubs.insert(Name);
-      O << "L" << Name << "$stub";
-      return;
-    }
     O << GlobalPrefix << MO.getSymbolName();
     return;
 
@@ -318,16 +333,6 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
     GlobalValue *GV = MO.getGlobal();
     std::string Name = Mang->getValueName(GV);
 
-    // Dynamically-resolved functions need a stub for the function.  Be
-    // wary however not to output $stub for external functions whose addresses
-    // are taken.  Those should be emitted as $non_lazy_ptr below.
-    Function *F = dyn_cast<Function>(GV);
-    if (F && IsCallOp && F->isExternal()) {
-      FnStubs.insert(Name);
-      O << "L" << Name << "$stub";
-      return;
-    }
-
     // External or weakly linked global variables need non-lazily-resolved stubs
     if ((GV->isExternal() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())){
       if (GV->hasLinkOnceLinkage())
@@ -437,7 +442,7 @@ void DarwinAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
   if (CP.empty()) return;
 
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    O << "\t.const\n";
+    SwitchSection(".const", 0);
     // FIXME: force doubles to be naturally aligned.  We should handle this
     // more correctly in the future.
     if (Type::DoubleTy == CP[i]->getType())
@@ -487,6 +492,7 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
       } else {
         switch (I->getLinkage()) {
         case GlobalValue::LinkOnceLinkage:
+          SwitchSection("", 0);
           O << ".section __TEXT,__textcoal_nt,coalesced,no_toc\n"
             << ".weak_definition " << name << '\n'
             << ".private_extern " << name << '\n'
@@ -649,7 +655,7 @@ void AIXAsmPrinter::printConstantPool(MachineConstantPool *MCP) {
   if (CP.empty()) return;
 
   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
-    O << "\t.const\n";
+    SwitchSection(".const", 0);
     O << "\t.align " << (unsigned)TD.getTypeAlignment(CP[i]->getType())
       << "\n";
     O << "LCPI" << FunctionNumber << '_' << i << ":\t\t\t\t\t;"