llvm.org GIT mirror llvm / c686e33
handle the upper16/lower16 target operand flags on symbol references for MC instruction lowering. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114191 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 9 years ago
5 changed file(s) with 62 addition(s) and 25 deletion(s). Raw diff Collapse all Expand all
14651465 V1 = MCOperand::CreateImm(ImmVal & 65535);
14661466 V2 = MCOperand::CreateImm(ImmVal >> 16);
14671467 } else if (MO.isGlobal()) {
1468 MCSymbol *Symbol = MCInstLowering.GetGlobalAddressSymbol(MO);
1468 MCSymbol *Symbol = MCInstLowering.GetGlobalAddressSymbol(MO.getGlobal());
14691469 const MCSymbolRefExpr *SymRef1 =
14701470 MCSymbolRefExpr::Create(Symbol,
14711471 MCSymbolRefExpr::VK_ARM_LO16, OutContext);
166166 }
167167 }
168168
169 namespace ARMII {
170 /// Target Operand Flag enum.
171 enum TOF {
172 //===------------------------------------------------------------------===//
173 // ARM Specific MachineOperand flags.
174
175 MO_NO_FLAG,
176
177 /// MO_LO16 - On a symbol operand, this represents a relocation containing
178 /// lower 16 bit of the address. Used only via movw instruction.
179 MO_LO16,
180
181 /// MO_HI16 - On a symbol operand, this represents a relocation containing
182 /// higher 16 bit of the address. Used only via movt instruction.
183 MO_HI16
184 };
185 } // end namespace ARMII
186
169187 } // end namespace llvm;
170188
171189 #endif
180180 I_BitShift = 25,
181181 CondShift = 28
182182 };
183
184 /// Target Operand Flag enum.
185 enum TOF {
186 //===------------------------------------------------------------------===//
187 // ARM Specific MachineOperand flags.
188
189 MO_NO_FLAG,
190
191 /// MO_LO16 - On a symbol operand, this represents a relocation containing
192 /// lower 16 bit of the address. Used only via movw instruction.
193 MO_LO16,
194
195 /// MO_HI16 - On a symbol operand, this represents a relocation containing
196 /// higher 16 bit of the address. Used only via movt instruction.
197 MO_HI16
198 };
199183 }
200184
201185 class ARMBaseInstrInfo : public TargetInstrInfoImpl {
3939 }
4040 #endif
4141
42 MCSymbol *ARMMCInstLower::
43 GetGlobalAddressSymbol(const MachineOperand &MO) const {
42 MCSymbol *ARMMCInstLower::GetGlobalAddressSymbol(const GlobalValue *GV) const {
43 return Printer.Mang->getSymbol(GV);
44 }
45
46 const MCSymbolRefExpr *ARMMCInstLower::
47 GetSymbolRef(const MachineOperand &MO) const {
48 assert(MO.isGlobal() && "Isn't a global address reference?");
4449 // FIXME: HANDLE PLT references how??
50
51 const MCSymbolRefExpr *SymRef;
52 const MCSymbol *Symbol = GetGlobalAddressSymbol(MO.getGlobal());
53
4554 switch (MO.getTargetFlags()) {
4655 default: assert(0 && "Unknown target flag on GV operand");
47 case 0: break;
48 }
49
50 return Printer.Mang->getSymbol(MO.getGlobal());
56 case 0:
57 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_None, Ctx);
58 break;
59 case ARMII::MO_LO16:
60 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_LO16, Ctx);
61 break;
62 case ARMII::MO_HI16:
63 SymRef = MCSymbolRefExpr::Create(Symbol, MCSymbolRefExpr::VK_ARM_HI16, Ctx);
64 break;
65 }
66
67 return SymRef;
5168 }
5269
5370 MCSymbol *ARMMCInstLower::
5471 GetExternalSymbolSymbol(const MachineOperand &MO) const {
5572 // FIXME: HANDLE PLT references how??
73 // FIXME: This probably needs to be merged with the above SymbolRef stuff
74 // to handle :lower16: and :upper16: (?)
5675 switch (MO.getTargetFlags()) {
5776 default: assert(0 && "Unknown target flag on GV operand");
5877 case 0: break;
107126 }
108127 #endif
109128
129 if (!MO.isJTI() && MO.getOffset())
130 Expr = MCBinaryExpr::CreateAdd(Expr,
131 MCConstantExpr::Create(MO.getOffset(), Ctx),
132 Ctx);
133 return MCOperand::CreateExpr(Expr);
134 }
135
136 MCOperand ARMMCInstLower::
137 LowerSymbolRefOperand(const MachineOperand &MO,
138 const MCSymbolRefExpr *Sym) const {
139 const MCExpr *Expr = Sym;
110140 if (!MO.isJTI() && MO.getOffset())
111141 Expr = MCBinaryExpr::CreateAdd(Expr,
112142 MCConstantExpr::Create(MO.getOffset(), Ctx),
140170 MO.getMBB()->getSymbol(), Ctx));
141171 break;
142172 case MachineOperand::MO_GlobalAddress:
143 MCOp = LowerSymbolOperand(MO, GetGlobalAddressSymbol(MO));
173 MCOp = LowerSymbolRefOperand(MO, GetSymbolRef(MO));
144174 break;
145175 case MachineOperand::MO_ExternalSymbol:
146176 MCOp = LowerSymbolOperand(MO, GetExternalSymbolSymbol(MO));
1313
1414 namespace llvm {
1515 class AsmPrinter;
16 class GlobalValue;
1617 class MCAsmInfo;
1718 class MCContext;
1819 class MCInst;
1920 class MCOperand;
2021 class MCSymbol;
22 class MCSymbolRefExpr;
2123 class MachineInstr;
2224 class MachineModuleInfoMachO;
2325 class MachineOperand;
3840 void Lower(const MachineInstr *MI, MCInst &OutMI) const;
3941
4042 //MCSymbol *GetPICBaseSymbol() const;
41 MCSymbol *GetGlobalAddressSymbol(const MachineOperand &MO) const;
43 MCSymbol *GetGlobalAddressSymbol(const GlobalValue *GV) const;
44 const MCSymbolRefExpr *GetSymbolRef(const MachineOperand &MO) const;
4245 MCSymbol *GetExternalSymbolSymbol(const MachineOperand &MO) const;
4346 MCSymbol *GetJumpTableSymbol(const MachineOperand &MO) const;
4447 MCSymbol *GetConstantPoolIndexSymbol(const MachineOperand &MO) const;
48 MCOperand LowerSymbolRefOperand(const MachineOperand &MO,
49 const MCSymbolRefExpr *Expr) const;
4550 MCOperand LowerSymbolOperand(const MachineOperand &MO, MCSymbol *Sym) const;
4651
4752 /*