refactor call operand handling to eliminate special cases from printOp.
authorChris Lattner <sabre@nondot.org>
Thu, 17 Nov 2005 19:25:59 +0000 (19:25 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 17 Nov 2005 19:25:59 +0000 (19:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24401 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/PowerPC/PPCAsmPrinter.cpp

index 0b6fa5a3b3030d34571682c842e29ed7bae2d143..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);
@@ -153,7 +153,21 @@ namespace {
     }
     void printCallOperand(const MachineInstr *MI, unsigned OpNo,
                           MVT::ValueType VT) {
-      printOp(MI->getOperand(OpNo), true);
+      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) {
@@ -273,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;
 
@@ -312,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;
 
@@ -325,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())