[llvm-commits] [llvm] r119078 - in /llvm/trunk/lib/Target/PowerPC: InstPrinter/PPCInstPrinter.cpp InstPrinter/PPCInstPrinter.h PPCMCInstLower.cpp

Chris Lattner sabre at nondot.org
Sun Nov 14 13:20:46 PST 2010


Author: lattner
Date: Sun Nov 14 15:20:46 2010
New Revision: 119078

URL: http://llvm.org/viewvc/llvm-project?rev=119078&view=rev
Log:
implement basic support for symbol operand lowering,
and printing support for call operands.  Down to 77 failures.

Modified:
    llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
    llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h
    llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp

Modified: llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp?rev=119078&r1=119077&r2=119078&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp Sun Nov 14 15:20:46 2010
@@ -88,6 +88,19 @@
 #endif
 }
 
+void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo,
+                                        raw_ostream &O) {
+  if (!MI->getOperand(OpNo).isImm())
+    return printOperand(MI, OpNo, O);
+
+  // Branches can take an immediate operand.  This is used by the branch
+  // selection pass to print $+8, an eight byte displacement from the PC.
+  O << "$+" << MI->getOperand(OpNo).getImm()*4;
+}
+
+
+
+
 void PPCInstPrinter::printcrbitm(const MCInst *MI, unsigned OpNo,
                                  raw_ostream &O) {
   unsigned CCReg = MI->getOperand(OpNo).getReg();

Modified: llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h?rev=119078&r1=119077&r2=119078&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h (original)
+++ llvm/trunk/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.h Sun Nov 14 15:20:46 2010
@@ -51,8 +51,10 @@
   void printS16ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
   void printU16ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
   void printS16X4ImmOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
-  void printBranchOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {}
-  void printCallOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {}
+  void printBranchOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O);
+  void printCallOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {
+    printOperand(MI, OpNo, O);
+  }
   void printAbsAddrOperand(const MCInst *MI, unsigned OpNo, raw_ostream &O) {}
 
   void printcrbitm(const MCInst *MI, unsigned OpNo, raw_ostream &O);

Modified: llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp?rev=119078&r1=119077&r2=119078&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp Sun Nov 14 15:20:46 2010
@@ -17,10 +17,35 @@
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/MC/MCExpr.h"
 #include "llvm/MC/MCInst.h"
+#include "llvm/Target/Mangler.h"
 using namespace llvm;
 
+static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol,
+                              AsmPrinter &Printer) {
+  MCContext &Ctx = Printer.OutContext;
+  const MCExpr *Expr;
+  switch (MO.getTargetFlags()) {
+  default: assert(0 && "Unknown target flag on symbol operand");
+  case 0:
+    Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
+    break;
+#if 0
+  case ARMII::MO_LO16:
+    Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx);
+    break;
+#endif
+  }
+  
+  if (!MO.isJTI() && MO.getOffset())
+    Expr = MCBinaryExpr::CreateAdd(Expr,
+                                   MCConstantExpr::Create(MO.getOffset(), Ctx),
+                                   Ctx);
+  return MCOperand::CreateExpr(Expr);
+  
+}
+
 void llvm::LowerPPCMachineInstrToMCInst(const MachineInstr *MI, MCInst &OutMI,
-                                        AsmPrinter &Printer) {
+                                        AsmPrinter &AP) {
   OutMI.setOpcode(MI->getOpcode());
   
   for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
@@ -38,6 +63,26 @@
     case MachineOperand::MO_Immediate:
       MCOp = MCOperand::CreateImm(MO.getImm());
       break;
+    case MachineOperand::MO_MachineBasicBlock:
+      MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
+                                      MO.getMBB()->getSymbol(), AP.OutContext));
+      break;
+    case MachineOperand::MO_GlobalAddress:
+      MCOp = GetSymbolRef(MO, AP.Mang->getSymbol(MO.getGlobal()), AP);
+      break;
+    case MachineOperand::MO_ExternalSymbol:
+      MCOp = GetSymbolRef(MO, 
+                          AP.GetExternalSymbolSymbol(MO.getSymbolName()), AP);
+      break;
+    case MachineOperand::MO_JumpTableIndex:
+      MCOp = GetSymbolRef(MO, AP.GetJTISymbol(MO.getIndex()), AP);
+      break;
+    case MachineOperand::MO_ConstantPoolIndex:
+      MCOp = GetSymbolRef(MO, AP.GetCPISymbol(MO.getIndex()), AP);
+      break;
+    case MachineOperand::MO_BlockAddress:
+      MCOp = GetSymbolRef(MO,AP.GetBlockAddressSymbol(MO.getBlockAddress()),AP);
+      break;
     }
     
     OutMI.addOperand(MCOp);





More information about the llvm-commits mailing list