forked from OSchip/llvm-project
add jump tables, constant pools and some trivial global
lowering stuff. We can now compile hello world to: _main: stm , mov r7, sp sub sp, sp, #4 mov r0, #0 str r0, ldr r0, bl _printf ldr r0, mov sp, r7 ldm , Almost looks like arm code :) llvm-svn: 84542
This commit is contained in:
parent
5c704d505c
commit
889a6217fa
|
@ -1311,7 +1311,7 @@ extern "C" void LLVMInitializeARMAsmPrinter() {
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) {
|
||||||
ARMMCInstLower MCInstLowering(OutContext, Mang);
|
ARMMCInstLower MCInstLowering(OutContext, *Mang, getFunctionNumber(), *MAI);
|
||||||
switch (MI->getOpcode()) {
|
switch (MI->getOpcode()) {
|
||||||
case TargetInstrInfo::DBG_LABEL:
|
case TargetInstrInfo::DBG_LABEL:
|
||||||
case TargetInstrInfo::EH_LABEL:
|
case TargetInstrInfo::EH_LABEL:
|
||||||
|
|
|
@ -16,9 +16,8 @@
|
||||||
#include "ARMAddressingModes.h"
|
#include "ARMAddressingModes.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
//#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
//#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Support/FormattedStream.h"
|
|
||||||
#include "ARMGenInstrNames.inc"
|
#include "ARMGenInstrNames.inc"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
@ -34,7 +33,8 @@ void ARMInstPrinter::printInst(const MCInst *MI) { printInstruction(MI); }
|
||||||
|
|
||||||
void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
||||||
const char *Modifier) {
|
const char *Modifier) {
|
||||||
assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
|
// FIXME: TURN ASSERT ON.
|
||||||
|
//assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
|
||||||
|
|
||||||
const MCOperand &Op = MI->getOperand(OpNo);
|
const MCOperand &Op = MI->getOperand(OpNo);
|
||||||
if (Op.isReg()) {
|
if (Op.isReg()) {
|
||||||
|
@ -43,9 +43,7 @@ void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
||||||
O << '#' << Op.getImm();
|
O << '#' << Op.getImm();
|
||||||
} else {
|
} else {
|
||||||
assert(Op.isExpr() && "unknown operand kind in printOperand");
|
assert(Op.isExpr() && "unknown operand kind in printOperand");
|
||||||
assert(0 && "UNIMP");
|
Op.getExpr()->print(O, &MAI);
|
||||||
//O << '$';
|
|
||||||
//Op.getExpr()->print(O, &MAI);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,16 +13,16 @@
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
#include "ARMMCInstLower.h"
|
#include "ARMMCInstLower.h"
|
||||||
//#include "ARMMCAsmInfo.h"
|
|
||||||
//#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
//#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.h"
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
//#include "llvm/MC/MCContext.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
//#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCContext.h"
|
||||||
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
//#include "llvm/MC/MCStreamer.h"
|
//#include "llvm/MC/MCStreamer.h"
|
||||||
//#include "llvm/Support/FormattedStream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
//#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
//#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,6 +37,74 @@ MachineModuleInfoMachO &ARMMCInstLower::getMachOMMI() const {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
MCSymbol *ARMMCInstLower::
|
||||||
|
GetGlobalAddressSymbol(const MachineOperand &MO) const {
|
||||||
|
const GlobalValue *GV = MO.getGlobal();
|
||||||
|
|
||||||
|
SmallString<128> Name;
|
||||||
|
Mang.getNameWithPrefix(Name, GV, false);
|
||||||
|
|
||||||
|
// FIXME: HANDLE PLT references how??
|
||||||
|
switch (MO.getTargetFlags()) {
|
||||||
|
default: assert(0 && "Unknown target flag on GV operand");
|
||||||
|
case 0: break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ctx.GetOrCreateSymbol(Name.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MCSymbol *ARMMCInstLower::
|
||||||
|
GetJumpTableSymbol(const MachineOperand &MO) const {
|
||||||
|
SmallString<256> Name;
|
||||||
|
raw_svector_ostream(Name) << MAI.getPrivateGlobalPrefix() << "JTI"
|
||||||
|
<< CurFunctionNumber << '_' << MO.getIndex();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
switch (MO.getTargetFlags()) {
|
||||||
|
default: llvm_unreachable("Unknown target flag on GV operand");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Create a symbol for the name.
|
||||||
|
return Ctx.GetOrCreateSymbol(Name.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
MCSymbol *ARMMCInstLower::
|
||||||
|
GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
|
||||||
|
SmallString<256> Name;
|
||||||
|
raw_svector_ostream(Name) << MAI.getPrivateGlobalPrefix() << "CPI"
|
||||||
|
<< CurFunctionNumber << '_' << MO.getIndex();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
switch (MO.getTargetFlags()) {
|
||||||
|
default: llvm_unreachable("Unknown target flag on GV operand");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Create a symbol for the name.
|
||||||
|
return Ctx.GetOrCreateSymbol(Name.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
MCOperand ARMMCInstLower::
|
||||||
|
LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const {
|
||||||
|
// FIXME: We would like an efficient form for this, so we don't have to do a
|
||||||
|
// lot of extra uniquing.
|
||||||
|
const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, Ctx);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
switch (MO.getTargetFlags()) {
|
||||||
|
default: llvm_unreachable("Unknown target flag on GV operand");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (!MO.isJTI() && MO.getOffset())
|
||||||
|
Expr = MCBinaryExpr::CreateAdd(Expr,
|
||||||
|
MCConstantExpr::Create(MO.getOffset(), Ctx),
|
||||||
|
Ctx);
|
||||||
|
return MCOperand::CreateExpr(Expr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
|
void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
|
||||||
OutMI.setOpcode(MI->getOpcode());
|
OutMI.setOpcode(MI->getOpcode());
|
||||||
|
@ -60,19 +128,21 @@ void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
|
||||||
MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
|
MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
|
||||||
AsmPrinter.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
|
AsmPrinter.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case MachineOperand::MO_GlobalAddress:
|
case MachineOperand::MO_GlobalAddress:
|
||||||
MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
|
MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
|
||||||
break;
|
break;
|
||||||
|
#if 0
|
||||||
case MachineOperand::MO_ExternalSymbol:
|
case MachineOperand::MO_ExternalSymbol:
|
||||||
MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
|
MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case MachineOperand::MO_JumpTableIndex:
|
case MachineOperand::MO_JumpTableIndex:
|
||||||
MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
|
MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
|
||||||
break;
|
break;
|
||||||
case MachineOperand::MO_ConstantPoolIndex:
|
case MachineOperand::MO_ConstantPoolIndex:
|
||||||
MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
|
MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OutMI.addOperand(MCOp);
|
OutMI.addOperand(MCOp);
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
class MCAsmInfo;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCInst;
|
class MCInst;
|
||||||
class MCOperand;
|
class MCOperand;
|
||||||
|
@ -26,24 +27,27 @@ namespace llvm {
|
||||||
/// ARMMCInstLower - This class is used to lower an MachineInstr into an MCInst.
|
/// ARMMCInstLower - This class is used to lower an MachineInstr into an MCInst.
|
||||||
class VISIBILITY_HIDDEN ARMMCInstLower {
|
class VISIBILITY_HIDDEN ARMMCInstLower {
|
||||||
MCContext &Ctx;
|
MCContext &Ctx;
|
||||||
Mangler *Mang;
|
Mangler &Mang;
|
||||||
|
|
||||||
|
const unsigned CurFunctionNumber;
|
||||||
|
const MCAsmInfo &MAI;
|
||||||
|
|
||||||
//const ARMSubtarget &getSubtarget() const;
|
//const ARMSubtarget &getSubtarget() const;
|
||||||
public:
|
public:
|
||||||
ARMMCInstLower(MCContext &ctx, Mangler *mang)
|
ARMMCInstLower(MCContext &ctx, Mangler &mang, unsigned FuncNum,
|
||||||
: Ctx(ctx), Mang(mang) {}
|
const MCAsmInfo &mai)
|
||||||
|
: Ctx(ctx), Mang(mang), CurFunctionNumber(FuncNum), MAI(mai) {}
|
||||||
|
|
||||||
void Lower(const MachineInstr *MI, MCInst &OutMI) const;
|
void Lower(const MachineInstr *MI, MCInst &OutMI) const;
|
||||||
|
|
||||||
/*
|
//MCSymbol *GetPICBaseSymbol() const;
|
||||||
MCSymbol *GetPICBaseSymbol() const;
|
|
||||||
|
|
||||||
MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
|
MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
|
||||||
MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
|
//MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
|
||||||
MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
|
MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
|
||||||
MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
|
MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
|
||||||
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
|
MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
|
||||||
|
|
||||||
|
/*
|
||||||
private:
|
private:
|
||||||
MachineModuleInfoMachO &getMachOMMI() const;
|
MachineModuleInfoMachO &getMachOMMI() const;
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue