llvm.org GIT mirror llvm / 6f99776
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 :) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84542 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
4 changed file(s) with 94 addition(s) and 22 deletion(s). Raw diff Collapse all Expand all
13101310 //===----------------------------------------------------------------------===//
13111311
13121312 void ARMAsmPrinter::printInstructionThroughMCStreamer(const MachineInstr *MI) {
1313 ARMMCInstLower MCInstLowering(OutContext, Mang);
1313 ARMMCInstLower MCInstLowering(OutContext, *Mang, getFunctionNumber(), *MAI);
13141314 switch (MI->getOpcode()) {
13151315 case TargetInstrInfo::DBG_LABEL:
13161316 case TargetInstrInfo::EH_LABEL:
1515 #include "ARMAddressingModes.h"
1616 #include "llvm/MC/MCInst.h"
1717 #include "llvm/MC/MCAsmInfo.h"
18 //#include "llvm/MC/MCExpr.h"
19 //#include "llvm/Support/ErrorHandling.h"
20 #include "llvm/Support/FormattedStream.h"
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/Support/raw_ostream.h"
2120 #include "ARMGenInstrNames.inc"
2221 using namespace llvm;
2322
3332
3433 void ARMInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
3534 const char *Modifier) {
36 assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
35 // FIXME: TURN ASSERT ON.
36 //assert((Modifier == 0 || Modifier[0] == 0) && "Cannot print modifiers");
3737
3838 const MCOperand &Op = MI->getOperand(OpNo);
3939 if (Op.isReg()) {
4242 O << '#' << Op.getImm();
4343 } else {
4444 assert(Op.isExpr() && "unknown operand kind in printOperand");
45 assert(0 && "UNIMP");
46 //O << '$';
47 //Op.getExpr()->print(O, &MAI);
45 Op.getExpr()->print(O, &MAI);
4846 }
4947 }
5048
1212 //===----------------------------------------------------------------------===//
1313
1414 #include "ARMMCInstLower.h"
15 //#include "ARMMCAsmInfo.h"
1615 //#include "llvm/CodeGen/MachineModuleInfoImpls.h"
1716 #include "llvm/CodeGen/MachineInstr.h"
18 //#include "llvm/MC/MCContext.h"
19 //#include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCAsmInfo.h"
18 #include "llvm/MC/MCContext.h"
19 #include "llvm/MC/MCExpr.h"
2020 #include "llvm/MC/MCInst.h"
2121 //#include "llvm/MC/MCStreamer.h"
22 //#include "llvm/Support/FormattedStream.h"
23 //#include "llvm/Support/Mangler.h"
24 //#include "llvm/ADT/SmallString.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/Support/Mangler.h"
24 #include "llvm/ADT/SmallString.h"
2525 using namespace llvm;
2626
2727
3535 return AsmPrinter.MMI->getObjFileInfo();
3636 }
3737 #endif
38
39 MCSymbol *ARMMCInstLower::
40 GetGlobalAddressSymbol(const MachineOperand &MO) const {
41 const GlobalValue *GV = MO.getGlobal();
42
43 SmallString<128> Name;
44 Mang.getNameWithPrefix(Name, GV, false);
45
46 // FIXME: HANDLE PLT references how??
47 switch (MO.getTargetFlags()) {
48 default: assert(0 && "Unknown target flag on GV operand");
49 case 0: break;
50 }
51
52 return Ctx.GetOrCreateSymbol(Name.str());
53 }
54
55
56 MCSymbol *ARMMCInstLower::
57 GetJumpTableSymbol(const MachineOperand &MO) const {
58 SmallString<256> Name;
59 raw_svector_ostream(Name) << MAI.getPrivateGlobalPrefix() << "JTI"
60 << CurFunctionNumber << '_' << MO.getIndex();
61
62 #if 0
63 switch (MO.getTargetFlags()) {
64 default: llvm_unreachable("Unknown target flag on GV operand");
65 }
66 #endif
67
68 // Create a symbol for the name.
69 return Ctx.GetOrCreateSymbol(Name.str());
70 }
71
72 MCSymbol *ARMMCInstLower::
73 GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
74 SmallString<256> Name;
75 raw_svector_ostream(Name) << MAI.getPrivateGlobalPrefix() << "CPI"
76 << CurFunctionNumber << '_' << MO.getIndex();
77
78 #if 0
79 switch (MO.getTargetFlags()) {
80 default: llvm_unreachable("Unknown target flag on GV operand");
81 }
82 #endif
83
84 // Create a symbol for the name.
85 return Ctx.GetOrCreateSymbol(Name.str());
86 }
87
88 MCOperand ARMMCInstLower::
89 LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const {
90 // FIXME: We would like an efficient form for this, so we don't have to do a
91 // lot of extra uniquing.
92 const MCExpr *Expr = MCSymbolRefExpr::Create(Sym, Ctx);
93
94 #if 0
95 switch (MO.getTargetFlags()) {
96 default: llvm_unreachable("Unknown target flag on GV operand");
97 }
98 #endif
99
100 if (!MO.isJTI() && MO.getOffset())
101 Expr = MCBinaryExpr::CreateAdd(Expr,
102 MCConstantExpr::Create(MO.getOffset(), Ctx),
103 Ctx);
104 return MCOperand::CreateExpr(Expr);
105 }
38106
39107
40108 void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
59127 MCOp = MCOperand::CreateExpr(MCSymbolRefExpr::Create(
60128 AsmPrinter.GetMBBSymbol(MO.getMBB()->getNumber()), Ctx));
61129 break;
130 #endif
62131 case MachineOperand::MO_GlobalAddress:
63132 MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
64133 break;
134 #if 0
65135 case MachineOperand::MO_ExternalSymbol:
66136 MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
67137 break;
138 #endif
68139 case MachineOperand::MO_JumpTableIndex:
69140 MCOp = LowerSymbolOperand(MO, GetJumpTableSymbol(MO));
70141 break;
71142 case MachineOperand::MO_ConstantPoolIndex:
72143 MCOp = LowerSymbolOperand(MO, GetConstantPoolIndexSymbol(MO));
73144 break;
74 #endif
75145 }
76146
77147 OutMI.addOperand(MCOp);
1212 #include "llvm/Support/Compiler.h"
1313
1414 namespace llvm {
15 class MCAsmInfo;
1516 class MCContext;
1617 class MCInst;
1718 class MCOperand;
2526 /// ARMMCInstLower - This class is used to lower an MachineInstr into an MCInst.
2627 class VISIBILITY_HIDDEN ARMMCInstLower {
2728 MCContext &Ctx;
28 Mangler *Mang;
29 Mangler &Mang;
30
31 const unsigned CurFunctionNumber;
32 const MCAsmInfo &MAI;
2933
3034 //const ARMSubtarget &getSubtarget() const;
3135 public:
32 ARMMCInstLower(MCContext &ctx, Mangler *mang)
33 : Ctx(ctx), Mang(mang) {}
36 ARMMCInstLower(MCContext &ctx, Mangler &mang, unsigned FuncNum,
37 const MCAsmInfo &mai)
38 : Ctx(ctx), Mang(mang), CurFunctionNumber(FuncNum), MAI(mai) {}
3439
3540 void Lower(const MachineInstr *MI, MCInst &OutMI) const;
3641
37 /*
38 MCSymbol *GetPICBaseSymbol() const;
39
42 //MCSymbol *GetPICBaseSymbol() const;
4043 MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
41 MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
44 //MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
4245 MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
4346 MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
4447 MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
4548
49 /*
4650 private:
4751 MachineModuleInfoMachO &getMachOMMI() const;
4852 */