forked from OSchip/llvm-project
stub out PPCMCInstLowering, add a new option that uses it and the new
instprinter when -enable-ppc-inst-printer is passed to llc. llvm-svn: 119061
This commit is contained in:
parent
b05ef7377a
commit
686a095d89
|
@ -21,6 +21,7 @@ add_llvm_target(PowerPCCodeGen
|
|||
PPCISelLowering.cpp
|
||||
PPCJITInfo.cpp
|
||||
PPCMCAsmInfo.cpp
|
||||
PPCMCInstLower.cpp
|
||||
PPCPredicates.cpp
|
||||
PPCRegisterInfo.cpp
|
||||
PPCSubtarget.cpp
|
||||
|
|
|
@ -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 @@ void PPCAsmPrinter::printPredicateOperand(const MachineInstr *MI, unsigned OpNo,
|
|||
/// 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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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
|
Loading…
Reference in New Issue