reimplement ppc asmprinter "toc" handling to use a VariantKind
authorChris Lattner <sabre@nondot.org>
Sun, 14 Nov 2010 22:22:59 +0000 (22:22 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 14 Nov 2010 22:22:59 +0000 (22:22 +0000)
on the operand, required for .o file writing and fixing
the PowerPC/mult-alt-generic-powerpc64.ll failure with the new
instprinter.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119087 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCExpr.h
lib/MC/MCExpr.cpp
lib/Target/PowerPC/PPCAsmPrinter.cpp
lib/Target/PowerPC/PPCInstr64Bit.td

index 3f25dc05628c6fe8f6ab0a476ad7e1908922d36a..22b1447b95ef7bf1ad6e4dd7a69d886efd6e0dd4 100644 (file)
@@ -141,6 +141,7 @@ public:
     VK_TLSLDM,
     VK_TPOFF,
     VK_DTPOFF,
+    VK_TLVP,      // Mach-O thread local variable relocation
     VK_ARM_HI16,  // The R_ARM_MOVT_ABS relocation (:upper16: in the .s file)
     VK_ARM_LO16,  // The R_ARM_MOVW_ABS_NC relocation (:lower16: in the .w file)
     // FIXME: We'd really like to use the generic Kinds listed above for these.
@@ -150,7 +151,8 @@ public:
     VK_ARM_GOTOFF,
     VK_ARM_TPOFF,
     VK_ARM_GOTTPOFF,
-    VK_TLVP // Mach-O thread local variable relocation
+    
+    VK_PPC_TOC
   };
 
 private:
index fa98b55dde82e125c29b470f6abf13573a4eb49a..e6f2a8f7908726dea6615a05529d32ac1cf006cc 100644 (file)
@@ -187,6 +187,7 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
   case VK_TLSLDM: return "TLSLDM";
   case VK_TPOFF: return "TPOFF";
   case VK_DTPOFF: return "DTPOFF";
+  case VK_TLVP: return "TLVP";
   case VK_ARM_HI16: return ":upper16:";
   case VK_ARM_LO16: return ":lower16:";
   case VK_ARM_PLT: return "(PLT)";
@@ -195,7 +196,7 @@ StringRef MCSymbolRefExpr::getVariantKindName(VariantKind Kind) {
   case VK_ARM_TPOFF: return "(tpoff)";
   case VK_ARM_GOTTPOFF: return "(gottpoff)";
   case VK_ARM_TLSGD: return "(tldgd)";
-  case VK_TLVP: return "TLVP";
+  case VK_PPC_TOC: return "toc";
   }
 }
 
index 8cd87de66d436b6a81caaabbde06ab2dbbb0bce3..d694b430178c8942dd93852729d7fc2cb22bbdd7 100644 (file)
@@ -560,6 +560,32 @@ void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
     switch (MI->getOpcode()) {
     default: break;
         
+    case PPC::LDtoc: {
+      // Transform %X3 = LDtoc <ga:@min1>, %X2
+      LowerPPCMachineInstrToMCInst(MI, TmpInst, *this);
+        
+      // Change the opcode to LD, and the global address operand to be a
+      // reference to the TOC entry we will synthesize later.
+      TmpInst.setOpcode(PPC::LD);
+      const MachineOperand &MO = MI->getOperand(1);
+      assert(MO.isGlobal());
+        
+      // Map symbol -> label of TOC entry.
+      MCSymbol *&TOCEntry = TOC[Mang->getSymbol(MO.getGlobal())];
+      if (TOCEntry == 0) {
+        TOCEntry = OutContext.
+          GetOrCreateSymbol(StringRef(MAI->getPrivateGlobalPrefix()) +
+                            "C" + Twine(LabelID++));
+      }
+        
+      const MCExpr *Exp =
+        MCSymbolRefExpr::Create(TOCEntry, MCSymbolRefExpr::VK_PPC_TOC,
+                                OutContext);
+      TmpInst.getOperand(1) = MCOperand::CreateExpr(Exp);
+      OutStreamer.EmitInstruction(TmpInst);
+      return;
+    }
+        
     case PPC::MFCRpseud:
       // Transform: %R3 = MFCRpseud %CR7
       // Into:      %R3 = MFCR      ;; cr7
index a0781b9870567a3caba68b30a84bfb13561ebc41..3cae32642ca107f4c58b7f5a9a3b7f64d3eb6b34 100644 (file)
@@ -566,7 +566,7 @@ def LDinto_toc: DSForm_1<58, 0, (outs), (ins G8RC:$reg),
 let RST = 2, DS = 40, RA = 1 in
 def LDtoc_restore : DSForm_1<58, 0, (outs), (ins),
                     "ld 2, 40(1)", LdStLD,
-                    []>, isPPC64;
+                    [(PPCtoc_restore)]>, isPPC64;
 def LDX  : XForm_1<31,  21, (outs G8RC:$rD), (ins memrr:$src),
                    "ldx $rD, $src", LdStLD,
                    [(set G8RC:$rD, (load xaddr:$src))]>, isPPC64;
@@ -579,8 +579,6 @@ def LDU  : DSForm_1<58, 1, (outs G8RC:$rD, ptr_rc:$ea_result), (ins memrix:$addr
 
 }
 
-def : Pat<(PPCtoc_restore),
-          (LDtoc_restore)>;
 def : Pat<(PPCload ixaddr:$src),
           (LD ixaddr:$src)>;
 def : Pat<(PPCload xaddr:$src),