llvm.org GIT mirror llvm / de36af4
more simplifications. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119067 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 9 years ago
2 changed file(s) with 18 addition(s) and 92 deletion(s). Raw diff Collapse all Expand all
2929 return Printer.Mang->getSymbol(GV);
3030 }
3131
32 const MCSymbolRefExpr *ARMMCInstLower::
33 GetSymbolRef(const MachineOperand &MO) const {
34 assert(MO.isGlobal() && "Isn't a global address reference?");
35
36 const MCSymbolRefExpr *SymRef;
37 const MCSymbol *Symbol = GetGlobalAddressSymbol(MO.getGlobal());
38
32 MCOperand ARMMCInstLower::
33 GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol) const {
34 const MCExpr *Expr;
3935 switch (MO.getTargetFlags()) {
40 default: assert(0 && "Unknown target flag on GV operand");
36 default: assert(0 && "Unknown target flag on symbol operand");
4137 case 0:
42 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
38 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
4339 break;
4440 case ARMII::MO_LO16:
45 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx);
41 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx);
4642 break;
4743 case ARMII::MO_HI16:
48 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx);
44 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx);
4945 break;
5046 case ARMII::MO_PLT:
51 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_PLT, Ctx);
47 Expr = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_PLT, Ctx);
5248 break;
5349 }
54
55 return SymRef;
56 }
57
58 const MCSymbolRefExpr *ARMMCInstLower::
59 GetExternalSymbolSymbol(const MachineOperand &MO) const {
60 const MCSymbolRefExpr *SymRef;
61 const MCSymbol *Symbol = Printer.GetExternalSymbolSymbol(MO.getSymbolName());
62
63 switch (MO.getTargetFlags()) {
64 default: assert(0 && "Unknown target flag on external symbol operand");
65 case 0:
66 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
67 break;
68 case ARMII::MO_LO16:
69 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx);
70 break;
71 case ARMII::MO_HI16:
72 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx);
73 break;
74 case ARMII::MO_PLT:
75 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_PLT, Ctx);
76 break;
77 }
78
79 return SymRef;
80 }
81
82
83
84 const MCSymbolRefExpr *ARMMCInstLower::
85 GetJumpTableSymbol(const MachineOperand &MO) const {
86 SmallString<256> Name;
87 raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "JTI"
88 << Printer.getFunctionNumber() << '_' << MO.getIndex();
89
90 switch (MO.getTargetFlags()) {
91 default: assert(0 && "Unknown target flag on jump table operand");
92 case 0: break;
93 }
94
95 // Create a symbol for the name.
96 return MCSymbolRefExpr::Create(Ctx.GetOrCreateSymbol(Name.str()), Ctx);
97 }
98
99 const MCSymbolRefExpr *ARMMCInstLower::
100 GetConstantPoolIndexSymbol(const MachineOperand &MO) const {
101 SmallString<256> Name;
102 raw_svector_ostream(Name) << Printer.MAI->getPrivateGlobalPrefix() << "CPI"
103 << Printer.getFunctionNumber() << '_' << MO.getIndex();
104
105 switch (MO.getTargetFlags()) {
106 default: assert(0 && "Unknown target flag on CPI operand");
107 case 0: break;
108 }
109
110 // Create a symbol for the name.
111 return MCSymbolRefExpr::Create(Ctx.GetOrCreateSymbol(Name.str()), Ctx);
112 }
113
114 MCOperand ARMMCInstLower::
115 LowerSymbolRefOperand(const MachineOperand &MO,
116 const MCSymbolRefExpr *Sym) const {
117 const MCExpr *Expr = Sym;
50
11851 if (!MO.isJTI() && MO.getOffset())
11952 Expr = MCBinaryExpr::CreateAdd(Expr,
12053 MCConstantExpr::Create(MO.getOffset(), Ctx),
12154 Ctx);
12255 return MCOperand::CreateExpr(Expr);
56
12357 }
124
12558
12659 void ARMMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
12760 OutMI.setOpcode(MI->getOpcode());
14881 MO.getMBB()->getSymbol(), Ctx));
14982 break;
15083 case MachineOperand::MO_GlobalAddress:
151 MCOp = LowerSymbolRefOperand(MO, GetSymbolRef(MO));
84 MCOp = GetSymbolRef(MO, GetGlobalAddressSymbol(MO.getGlobal()));
15285 break;
15386 case MachineOperand::MO_ExternalSymbol:
154 MCOp = LowerSymbolRefOperand(MO, GetExternalSymbolSymbol(MO));
87 MCOp = GetSymbolRef(MO,
88 Printer.GetExternalSymbolSymbol(MO.getSymbolName()));
15589 break;
15690 case MachineOperand::MO_JumpTableIndex:
157 MCOp = LowerSymbolRefOperand(MO, GetJumpTableSymbol(MO));
91 MCOp = GetSymbolRef(MO, Printer.GetJTISymbol(MO.getIndex()));
15892 break;
15993 case MachineOperand::MO_ConstantPoolIndex:
160 MCOp = LowerSymbolRefOperand(MO, GetConstantPoolIndexSymbol(MO));
94 MCOp = GetSymbolRef(MO, Printer.GetCPISymbol(MO.getIndex()));
16195 break;
16296 case MachineOperand::MO_BlockAddress:
163 MCOp = LowerSymbolRefOperand(MO,
164 MCSymbolRefExpr::Create(Printer.GetBlockAddressSymbol(
165 MO.getBlockAddress()), Ctx));
97 MCOp = GetSymbolRef(MO,
98 Printer.GetBlockAddressSymbol(MO.getBlockAddress()));
16699 break;
167100 case MachineOperand::MO_FPImmediate:
168101 APFloat Val = MO.getFPImm()->getValueAPF();
3939
4040 private:
4141 MCSymbol *GetGlobalAddressSymbol(const GlobalValue *GV) const;
42 const MCSymbolRefExpr *GetSymbolRef(const MachineOperand &MO) const;
43 const MCSymbolRefExpr *GetExternalSymbolSymbol(const MachineOperand &MO)
44 const;
45 const MCSymbolRefExpr *GetJumpTableSymbol(const MachineOperand &MO) const;
46 const MCSymbolRefExpr *
47 GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
48 MCOperand LowerSymbolRefOperand(const MachineOperand &MO,
49 const MCSymbolRefExpr *Expr) const;
42 MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Sym) const;
5043 };
5144
5245 } // end namespace llvm