Convert XO XS and XFX forms to use isPPC64
[oota-llvm.git] / lib / Target / PowerPC / PPCAsmPrinter.cpp
index f4e36bab2e8c458be93b90cdf17e7640197d24c0..4acaca7b51c6de7b01a0ea80760a06810111b2d9 100644 (file)
@@ -107,7 +107,7 @@ namespace {
       // Branches can take an immediate operand.  This is used by the branch
       // selection pass to print $+8, an eight byte displacement from the PC.
       if (MI->getOperand(OpNo).isImmediate()) {
-        O << "$+" << MI->getOperand(OpNo).getImmedValue() << '\n';
+        O << "$+" << MI->getOperand(OpNo).getImmedValue();
       } else {
         printOp(MI->getOperand(OpNo), 
                 TM.getInstrInfo()->isCall(MI->getOpcode()));
@@ -138,6 +138,26 @@ namespace {
         O << "-\"L0000" << LabelNumber << "$pb\")";
       }
     }
+    void printcrbit(const MachineInstr *MI, unsigned OpNo,
+                       MVT::ValueType VT) {
+      unsigned char value = MI->getOperand(OpNo).getImmedValue();
+      assert(value <= 3 && "Invalid crbit argument!");
+      unsigned RegNo, CCReg = MI->getOperand(OpNo-1).getReg();
+      switch (CCReg) {
+      case PPC::CR0:  RegNo = 0; break;
+      case PPC::CR1:  RegNo = 1; break;
+      case PPC::CR2:  RegNo = 2; break;
+      case PPC::CR3:  RegNo = 3; break;
+      case PPC::CR4:  RegNo = 4; break;
+      case PPC::CR5:  RegNo = 5; break;
+      case PPC::CR6:  RegNo = 6; break;
+      case PPC::CR7:  RegNo = 7; break;
+      default:
+        std::cerr << "Unhandled reg in enumRegToRealReg!\n";
+        abort();
+      }
+      O << 4 * RegNo + value;
+    }
   
     virtual void printConstantPool(MachineConstantPool *MCP) = 0;
     virtual bool runOnMachineFunction(MachineFunction &F) = 0;    
@@ -349,7 +369,13 @@ void PowerPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
     return;
 
   case MachineOperand::MO_ExternalSymbol:
-    O << MO.getSymbolName();
+    if (IsCallOp) {
+      std::string Name(GlobalPrefix); Name += MO.getSymbolName();
+      FnStubs.insert(Name);
+      O << "L" << Name << "$stub";
+      return;
+    }
+    O << GlobalPrefix << MO.getSymbolName();
     return;
 
   case MachineOperand::MO_GlobalAddress: {
@@ -360,15 +386,14 @@ void PowerPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
     // 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 && F->isExternal() && IsCallOp && getTM().CalledFunctions.count(F)) {
+    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())
-         && getTM().AddressTaken.count(GV)) {
+    if ((GV->isExternal() || GV->hasWeakLinkage() || GV->hasLinkOnceLinkage())){
       if (GV->hasLinkOnceLinkage())
         LinkOnceStubs.insert(Name);
       else
@@ -392,6 +417,28 @@ void PowerPCAsmPrinter::printOp(const MachineOperand &MO, bool IsCallOp) {
 ///
 void PowerPCAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
   ++EmittedInsts;
+  // Check for slwi/srwi mnemonics.
+  if (MI->getOpcode() == PPC::RLWINM) {
+    bool FoundMnemonic = false;
+    unsigned char SH = MI->getOperand(2).getImmedValue();
+    unsigned char MB = MI->getOperand(3).getImmedValue();
+    unsigned char ME = MI->getOperand(4).getImmedValue();
+    if (SH <= 31 && MB == 0 && ME == (31-SH)) {
+      O << "slwi "; FoundMnemonic = true;
+    }
+    if (SH <= 31 && MB == (32-SH) && ME == 31) {
+      O << "srwi "; FoundMnemonic = true;
+      SH = 32-SH;
+    }
+    if (FoundMnemonic) {
+      printOperand(MI, 0, MVT::i64); 
+      O << ", "; 
+      printOperand(MI, 1, MVT::i64); 
+      O << ", " << (unsigned int)SH << "\n";
+      return;
+    }
+  }
+  
   if (printInstruction(MI))
     return; // Printer was automatically generated
   
@@ -460,7 +507,7 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
   std::string CurSection;
 
   // Print out module-level global variables here.
-  for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I)
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I)
     if (I->hasInitializer()) {   // External global require no code
       O << '\n';
       std::string name = Mang->getValueName(I);
@@ -472,11 +519,11 @@ bool DarwinAsmPrinter::doFinalization(Module &M) {
           (I->hasInternalLinkage() || I->hasWeakLinkage() || 
            I->hasLinkOnceLinkage())) {
         SwitchSection(O, CurSection, ".data");
+        if (Size == 0) Size = 1;   // .comm Foo, 0 is undefined, avoid it.
         if (I->hasInternalLinkage())
-          O << ".lcomm " << name << "," << TD.getTypeSize(C->getType())
-            << "," << Align;
+          O << ".lcomm " << name << "," << Size << "," << Align;
         else 
-          O << ".comm " << name << "," << TD.getTypeSize(C->getType());
+          O << ".comm " << name << "," << Size;
         O << "\t\t; ";
         WriteAsOperand(O, I, true, true, &M);
         O << '\n';
@@ -647,7 +694,7 @@ bool AIXAsmPrinter::doInitialization(Module &M) {
     << "\t.csect .text[PR]\n";
 
   // Print out module-level global variables
-  for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) {
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
     if (!I->hasInitializer())
       continue;
  
@@ -665,8 +712,8 @@ bool AIXAsmPrinter::doInitialization(Module &M) {
   }
 
   // Output labels for globals
-  if (M.gbegin() != M.gend()) O << "\t.toc\n";
-  for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) {
+  if (M.global_begin() != M.global_end()) O << "\t.toc\n";
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
     const GlobalVariable *GV = I;
     // Do not output labels for unused variables
     if (GV->isExternal() && GV->use_begin() == GV->use_end())
@@ -688,7 +735,7 @@ bool AIXAsmPrinter::doInitialization(Module &M) {
 bool AIXAsmPrinter::doFinalization(Module &M) {
   const TargetData &TD = TM.getTargetData();
   // Print out module-level global variables
-  for (Module::const_giterator I = M.gbegin(), E = M.gend(); I != E; ++I) {
+  for (Module::const_global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) {
     if (I->hasInitializer() || I->hasExternalLinkage())
       continue;