[llvm-commits] [llvm] r119061 - in /llvm/trunk/lib/Target/PowerPC: CMakeLists.txt PPCAsmPrinter.cpp PPCMCInstLower.cpp PPCMCInstLower.h

Chris Lattner sabre at nondot.org
Sun Nov 14 11:53:02 PST 2010


Author: lattner
Date: Sun Nov 14 13:53:02 2010
New Revision: 119061

URL: http://llvm.org/viewvc/llvm-project?rev=119061&view=rev
Log:
stub out PPCMCInstLowering, add a new option that uses it and the new
instprinter when -enable-ppc-inst-printer is passed to llc.

Added:
    llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp
    llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.h
Modified:
    llvm/trunk/lib/Target/PowerPC/CMakeLists.txt
    llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp

Modified: llvm/trunk/lib/Target/PowerPC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/CMakeLists.txt?rev=119061&r1=119060&r2=119061&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/PowerPC/CMakeLists.txt Sun Nov 14 13:53:02 2010
@@ -21,6 +21,7 @@
   PPCISelLowering.cpp
   PPCJITInfo.cpp
   PPCMCAsmInfo.cpp
+  PPCMCInstLower.cpp
   PPCPredicates.cpp
   PPCRegisterInfo.cpp
   PPCSubtarget.cpp

Modified: llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp?rev=119061&r1=119060&r2=119061&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCAsmPrinter.cpp Sun Nov 14 13:53:02 2010
@@ -20,6 +20,7 @@
 #include "PPC.h"
 #include "PPCPredicates.h"
 #include "PPCTargetMachine.h"
+#include "PPCMCInstLower.h"
 #include "PPCSubtarget.h"
 #include "llvm/Analysis/DebugInfo.h"
 #include "llvm/Constants.h"
@@ -35,6 +36,7 @@
 #include "llvm/MC/MCAsmInfo.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSymbol.h"
@@ -43,6 +45,7 @@
 #include "llvm/Target/TargetInstrInfo.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetRegistry.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -53,6 +56,11 @@
 #include "InstPrinter/PPCInstPrinter.h"
 using namespace llvm;
 
+// This option tells the asmprinter to use the new (experimental) MCInstPrinter
+// path.
+static cl::opt<bool> UseInstPrinter("enable-ppc-inst-printer",
+                                    cl::ReallyHidden);
+
 namespace {
   class PPCAsmPrinter : public AsmPrinter {
   protected:
@@ -544,6 +552,22 @@
 /// the current output stream.
 ///
 void PPCAsmPrinter::EmitInstruction(const MachineInstr *MI) {
+  if (UseInstPrinter) {
+    PPCMCInstLower MCInstLowering(OutContext, *Mang, *this);
+    
+    // Lower multi-instruction pseudo operations.
+    switch (MI->getOpcode()) {
+    default: break;
+    // TODO: implement me.
+    }
+
+    MCInst TmpInst;
+    MCInstLowering.Lower(MI, TmpInst);
+    OutStreamer.EmitInstruction(TmpInst);
+    return;
+  }
+  
+  
   SmallString<128> Str;
   raw_svector_ostream O(Str);
 

Added: llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp?rev=119061&view=auto
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp (added)
+++ llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.cpp Sun Nov 14 13:53:02 2010
@@ -0,0 +1,75 @@
+//===-- PPCMCInstLower.cpp - Convert PPC MachineInstr to an MCInst --------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains code to lower PPC MachineInstrs to their corresponding
+// MCInst records.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PPCMCInstLower.h"
+#include "llvm/CodeGen/AsmPrinter.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInst.h"
+
+using namespace llvm;
+
+void PPCMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
+  OutMI.setOpcode(MI->getOpcode());
+  
+  for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
+    const MachineOperand &MO = MI->getOperand(i);
+    
+    MCOperand MCOp;
+    switch (MO.getType()) {
+    default:
+      MI->dump();
+      assert(0 && "unknown operand type");
+    case MachineOperand::MO_Register:
+      assert(!MO.getSubReg() && "Subregs should be eliminated!");
+      MCOp = MCOperand::CreateReg(MO.getReg());
+      break;
+    case MachineOperand::MO_Immediate:
+      MCOp = MCOperand::CreateImm(MO.getImm());
+      break;
+    case MachineOperand::MO_MachineBasicBlock:
+      MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
+                                              MO.getMBB()->getSymbol(), Ctx));
+      break;
+#if 0
+    case MachineOperand::MO_GlobalAddress:
+      MCOp = LowerSymbolRefOperand(MO, GetSymbolRef(MO));
+      break;
+    case MachineOperand::MO_ExternalSymbol:
+      MCOp = LowerSymbolRefOperand(MO, GetExternalSymbolSymbol(MO));
+      break;
+    case MachineOperand::MO_JumpTableIndex:
+      MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
+      break;
+    case MachineOperand::MO_ConstantPoolIndex:
+      MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
+      break;
+    case MachineOperand::MO_BlockAddress:
+      MCOp = LowerSymbolOperand(MO, Printer.GetBlockAddressSymbol(
+                                                       MO.getBlockAddress()));
+      break;
+#endif
+#if 0
+    case MachineOperand::MO_FPImmediate:
+      APFloat Val = MO.getFPImm()->getValueAPF();
+      bool ignored;
+      Val.convert(APFloat::IEEEdouble, APFloat::rmTowardZero, &ignored);
+      MCOp = MCOperand::CreateFPImm(Val.convertToDouble());
+      break;
+#endif
+    }
+    
+    OutMI.addOperand(MCOp);
+  }
+}

Added: llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.h?rev=119061&view=auto
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.h (added)
+++ llvm/trunk/lib/Target/PowerPC/PPCMCInstLower.h Sun Nov 14 13:53:02 2010
@@ -0,0 +1,54 @@
+//===-- PPCMCInstLower.h - Lower MachineInstr to MCInst -------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef PPC_MCINSTLOWER_H
+#define PPC_MCINSTLOWER_H
+
+#include "llvm/Support/Compiler.h"
+
+namespace llvm {
+  class AsmPrinter;
+  class GlobalValue;
+  class MCAsmInfo;
+  class MCContext;
+  class MCInst;
+  class MCOperand;
+  class MCSymbol;
+  class MCSymbolRefExpr;
+  class MachineInstr;
+  class MachineModuleInfoMachO;
+  class MachineOperand;
+  class Mangler;
+  
+/// PPCMCInstLower - This class is used to lower an MachineInstr into an MCInst.
+class LLVM_LIBRARY_VISIBILITY PPCMCInstLower {
+  MCContext &Ctx;
+  Mangler &Mang;
+  AsmPrinter &Printer;
+public:
+  PPCMCInstLower(MCContext &ctx, Mangler &mang, AsmPrinter &printer)
+  : Ctx(ctx), Mang(mang), Printer(printer) {}
+  
+  void Lower(const MachineInstr *MI, MCInst &OutMI) const;
+  
+private:
+  MCSymbol *GetGlobalAddressSymbol(const GlobalValue *GV) const;
+  const MCSymbolRefExpr *GetSymbolRef(const MachineOperand &MO) const;
+  const MCSymbolRefExpr *GetExternalSymbolSymbol(const MachineOperand &MO)
+  const;
+  MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
+  MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
+  MCOperand LowerSymbolRefOperand(const MachineOperand &MO,
+                                  const MCSymbolRefExpr *Expr) const;
+  MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
+  
+};
+} // end namespace llvm
+
+#endif





More information about the llvm-commits mailing list