forked from OSchip/llvm-project
Add experimental MSP430 MCInstLowering stuff
llvm-svn: 84703
This commit is contained in:
parent
daaa2f0c31
commit
6e78029d82
|
@ -3,5 +3,6 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/
|
|||
add_llvm_library(LLVMMSP430AsmPrinter
|
||||
MSP430InstPrinter.cpp
|
||||
MSP430AsmPrinter.cpp
|
||||
MSP430MCInstLower.cpp
|
||||
)
|
||||
add_dependencies(LLVMMSP430AsmPrinter MSP430CodeGenTable_gen)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "MSP430InstrInfo.h"
|
||||
#include "MSP430InstPrinter.h"
|
||||
#include "MSP430MCAsmInfo.h"
|
||||
#include "MSP430MCInstLower.h"
|
||||
#include "MSP430TargetMachine.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
|
@ -27,12 +28,14 @@
|
|||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||
#include "llvm/CodeGen/MachineConstantPool.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/MC/MCStreamer.h"
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#include "llvm/Target/TargetLoweringObjectFile.h"
|
||||
#include "llvm/Target/TargetRegistry.h"
|
||||
#include "llvm/ADT/Statistic.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/Mangler.h"
|
||||
|
@ -42,6 +45,10 @@ using namespace llvm;
|
|||
|
||||
STATISTIC(EmittedInsts, "Number of machine instrs printed");
|
||||
|
||||
static cl::opt<bool>
|
||||
EnableMCInst("enable-msp430-mcinst-printer", cl::Hidden,
|
||||
cl::desc("enable experimental mcinst gunk in the msp430 backend"));
|
||||
|
||||
namespace {
|
||||
class VISIBILITY_HIDDEN MSP430AsmPrinter : public AsmPrinter {
|
||||
public:
|
||||
|
@ -71,6 +78,7 @@ namespace {
|
|||
bool PrintAsmMemoryOperand(const MachineInstr *MI,
|
||||
unsigned OpNo, unsigned AsmVariant,
|
||||
const char *ExtraCode);
|
||||
void printInstructionThroughMCStreamer(const MachineInstr *MI);
|
||||
|
||||
void emitFunctionHeader(const MachineFunction &MF);
|
||||
bool runOnMachineFunction(MachineFunction &F);
|
||||
|
@ -152,7 +160,11 @@ void MSP430AsmPrinter::printMachineInstruction(const MachineInstr *MI) {
|
|||
processDebugLoc(MI, true);
|
||||
|
||||
// Call the autogenerated instruction printer routines.
|
||||
printInstruction(MI);
|
||||
if (EnableMCInst) {
|
||||
printInstructionThroughMCStreamer(MI);
|
||||
} else {
|
||||
printInstruction(MI);
|
||||
}
|
||||
|
||||
if (VerboseAsm && !MI->getDebugLoc().isUnknown())
|
||||
EmitComments(*MI);
|
||||
|
@ -279,6 +291,36 @@ bool MSP430AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
|
|||
return false;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
void MSP430AsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI)
|
||||
{
|
||||
|
||||
MSP430MCInstLower MCInstLowering(OutContext, Mang);
|
||||
|
||||
switch (MI->getOpcode()) {
|
||||
case TargetInstrInfo::DBG_LABEL:
|
||||
case TargetInstrInfo::EH_LABEL:
|
||||
case TargetInstrInfo::GC_LABEL:
|
||||
printLabel(MI);
|
||||
return;
|
||||
case TargetInstrInfo::KILL:
|
||||
return;
|
||||
case TargetInstrInfo::INLINEASM:
|
||||
O << '\t';
|
||||
printInlineAsm(MI);
|
||||
return;
|
||||
case TargetInstrInfo::IMPLICIT_DEF:
|
||||
printImplicitDef(MI);
|
||||
return;
|
||||
default: break;
|
||||
}
|
||||
|
||||
MCInst TmpInst;
|
||||
MCInstLowering.Lower(MI, TmpInst);
|
||||
|
||||
printMCInst(&TmpInst);
|
||||
}
|
||||
|
||||
// Force static initialization.
|
||||
extern "C" void LLVMInitializeMSP430AsmPrinter() {
|
||||
RegisterAsmPrinter<MSP430AsmPrinter> X(TheMSP430Target);
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
//===-- MSP430MCInstLower.cpp - Convert MSP430 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 MSP430 MachineInstrs to their corresponding
|
||||
// MCInst records.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "MSP430MCInstLower.h"
|
||||
#include "llvm/CodeGen/MachineInstr.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/MC/MCContext.h"
|
||||
#include "llvm/MC/MCExpr.h"
|
||||
#include "llvm/MC/MCInst.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/Mangler.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
using namespace llvm;
|
||||
|
||||
void MSP430MCInstLower::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:
|
||||
MCOp = MCOperand::CreateReg(MO.getReg());
|
||||
break;
|
||||
case MachineOperand::MO_Immediate:
|
||||
MCOp = MCOperand::CreateImm(MO.getImm());
|
||||
break;
|
||||
#if 0
|
||||
case MachineOperand::MO_MachineBasicBlock:
|
||||
MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
|
||||
AsmPrinter.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
|
||||
break;
|
||||
case MachineOperand::MO_GlobalAddress:
|
||||
MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
|
||||
break;
|
||||
case MachineOperand::MO_ExternalSymbol:
|
||||
MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
|
||||
break;
|
||||
case MachineOperand::MO_JumpTableIndex:
|
||||
MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
|
||||
break;
|
||||
case MachineOperand::MO_ConstantPoolIndex:
|
||||
MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
OutMI.addOperand(MCOp);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
//===-- MSP430MCInstLower.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 MSP430_MCINSTLOWER_H
|
||||
#define MSP430_MCINSTLOWER_H
|
||||
|
||||
#include "llvm/Support/Compiler.h"
|
||||
|
||||
namespace llvm {
|
||||
class MCAsmInfo;
|
||||
class MCContext;
|
||||
class MCInst;
|
||||
class MCOperand;
|
||||
class MCSymbol;
|
||||
class MachineInstr;
|
||||
class MachineModuleInfoMachO;
|
||||
class MachineOperand;
|
||||
class Mangler;
|
||||
|
||||
/// MSP430MCInstLower - This class is used to lower an MachineInstr
|
||||
/// into an MCInst.
|
||||
class VISIBILITY_HIDDEN MSP430MCInstLower {
|
||||
MCContext &Ctx;
|
||||
Mangler *Mang;
|
||||
|
||||
#if 0
|
||||
const unsigned CurFunctionNumber;
|
||||
const MCAsmInfo &MAI;
|
||||
#endif
|
||||
|
||||
public:
|
||||
MSP430MCInstLower(MCContext &ctx, Mangler *mang) : Ctx(ctx), Mang(mang) {}
|
||||
|
||||
void Lower(const MachineInstr *MI, MCInst &OutMI) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue