Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Side by Side Diff: lib/Target/Mips/MipsMCInstLower.cpp

Issue 27690005: [MIPS] Modify LongBranch expansion to work with sandboxing (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Changes per code review. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===-- MipsMCInstLower.cpp - Convert Mips MachineInstr to MCInst ---------===// 1 //===-- MipsMCInstLower.cpp - Convert Mips MachineInstr to MCInst ---------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This file contains code to lower Mips MachineInstrs to their corresponding 10 // This file contains code to lower Mips MachineInstrs to their corresponding
11 // MCInst records. 11 // MCInst records.
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 #include "MipsMCInstLower.h" 14 #include "MipsMCInstLower.h"
15 #include "MCTargetDesc/MipsBaseInfo.h" 15 #include "MCTargetDesc/MipsBaseInfo.h"
16 #include "MipsAsmPrinter.h" 16 #include "MipsAsmPrinter.h"
17 #include "MipsInstrInfo.h" 17 #include "MipsInstrInfo.h"
18 #include "llvm/CodeGen/MachineFunction.h" 18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineInstr.h" 19 #include "llvm/CodeGen/MachineInstr.h"
20 #include "llvm/CodeGen/MachineOperand.h" 20 #include "llvm/CodeGen/MachineOperand.h"
21 #include "llvm/MC/MCContext.h" 21 #include "llvm/MC/MCContext.h"
22 #include "llvm/MC/MCExpr.h" 22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/MC/MCInst.h" 23 #include "llvm/MC/MCInst.h"
24 // @LOCALMOD-START
25 #include "llvm/MC/MCELFStreamer.h"
26 #include "llvm/MC/MCSymbol.h"
27 // @LOCALMOD-END
24 #include "llvm/Target/Mangler.h" 28 #include "llvm/Target/Mangler.h"
25 29
26 using namespace llvm; 30 using namespace llvm;
27 31
28 MipsMCInstLower::MipsMCInstLower(MipsAsmPrinter &asmprinter) 32 MipsMCInstLower::MipsMCInstLower(MipsAsmPrinter &asmprinter)
29 : AsmPrinter(asmprinter) {} 33 : AsmPrinter(asmprinter) {}
30 34
31 void MipsMCInstLower::Initialize(Mangler *M, MCContext *C) { 35 void MipsMCInstLower::Initialize(Mangler *M, MCContext *C) {
32 Mang = M; 36 Mang = M;
33 Ctx = C; 37 Ctx = C;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 case MachineOperand::MO_ConstantPoolIndex: 149 case MachineOperand::MO_ConstantPoolIndex:
146 case MachineOperand::MO_BlockAddress: 150 case MachineOperand::MO_BlockAddress:
147 return LowerSymbolOperand(MO, MOTy, offset); 151 return LowerSymbolOperand(MO, MOTy, offset);
148 case MachineOperand::MO_RegisterMask: 152 case MachineOperand::MO_RegisterMask:
149 break; 153 break;
150 } 154 }
151 155
152 return MCOperand(); 156 return MCOperand();
153 } 157 }
154 158
159 // @LOCALMOD-START
160
161 // TempSymbol cannot be member of MipsMCInstLower since Lower methods are const.
162 static MCSymbol *TempSymbol = NULL;
163
164 void MipsMCInstLower::LowerNaClLongBranchLUi(const MachineInstr *MI,
165 MCInst &OutMI) const {
166 OutMI.setOpcode(Mips::LUi);
167
168 // Lower register operand.
169 MCOperand Reg = LowerOperand(MI->getOperand(0));
170 if (Reg.isValid())
171 OutMI.addOperand(Reg);
172
173 // Create %hi($tgt-$baltgt). Since Mips backend currently doesn't support
174 // %hi(sym1-sym2) expressions, we first create temp symbol
175 // tmp = $tgt-$baltgt, and then create %hi(tmp) expression.
176 const MCSymbol *Symbol1 = MI->getOperand(1).getMBB()->getSymbol();
177 const MCSymbolRefExpr *MCSym1 = MCSymbolRefExpr::Create(Symbol1, *Ctx);
178 const MCSymbol *Symbol2 = MI->getOperand(2).getMBB()->getSymbol();
179 const MCSymbolRefExpr *MCSym2 = MCSymbolRefExpr::Create(Symbol2, *Ctx);
180
181 assert(TempSymbol == NULL);
182 TempSymbol = Ctx->CreateTempSymbol();
183 TempSymbol->setVariableValue(MCBinaryExpr::CreateSub(MCSym1, MCSym2, *Ctx));
184
185 const MCSymbolRefExpr *TempHi = MCSymbolRefExpr::Create(TempSymbol,
186 MCSymbolRefExpr::VK_Mips_ABS_HI, *Ctx);
187 OutMI.addOperand(MCOperand::CreateExpr(TempHi));
188
189 if (AsmPrinter.OutStreamer.hasRawTextSupport()) {
190 // For .s files, emit directive ".set $tmp, $tgt-$baltgt"
191 AsmPrinter.OutStreamer.EmitRawText(StringRef("\t.set\t")
192 + TempSymbol->getName()
193 + StringRef(", ")
194 + Symbol1->getName()
195 + StringRef("-")
196 + Symbol2->getName());
197 }
198 }
199
200 void MipsMCInstLower::LowerNaClLongBranchADDiu(const MachineInstr *MI,
201 MCInst &OutMI) const {
202 OutMI.setOpcode(Mips::ADDiu);
203
204 // Lower two register operands.
205 for (unsigned i = 0, e = 2; i != e; ++i) {
206 const MachineOperand &MO = MI->getOperand(i);
207 MCOperand Reg = LowerOperand(MO);
208
209 if (Reg.isValid())
210 OutMI.addOperand(Reg);
211 }
212
213 // Create %lo($tgt-$baltgt). See the comment above for %hi version.
214 assert(TempSymbol != NULL);
215 const MCSymbolRefExpr *TempLo = MCSymbolRefExpr::Create(TempSymbol,
216 MCSymbolRefExpr::VK_Mips_ABS_LO, *Ctx);
217 OutMI.addOperand(MCOperand::CreateExpr(TempLo));
218 TempSymbol = NULL;
219 }
220 // @LOCALMOD-END
221
155 void MipsMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const { 222 void MipsMCInstLower::Lower(const MachineInstr *MI, MCInst &OutMI) const {
223 // @LOCALMOD-START
224 if (MI->getOpcode() == Mips::NACL_LONG_BRANCH_LUi) {
225 LowerNaClLongBranchLUi(MI, OutMI);
226 return;
227 }
228 if (MI->getOpcode() == Mips::NACL_LONG_BRANCH_ADDiu) {
229 LowerNaClLongBranchADDiu(MI, OutMI);
230 return;
231 }
232 // @LOCALMOD-END
233
156 OutMI.setOpcode(MI->getOpcode()); 234 OutMI.setOpcode(MI->getOpcode());
157 235
158 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) { 236 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
159 const MachineOperand &MO = MI->getOperand(i); 237 const MachineOperand &MO = MI->getOperand(i);
160 MCOperand MCOp = LowerOperand(MO); 238 MCOperand MCOp = LowerOperand(MO);
161 239
162 if (MCOp.isValid()) 240 if (MCOp.isValid())
163 OutMI.addOperand(MCOp); 241 OutMI.addOperand(MCOp);
164 } 242 }
165 } 243 }
166 244
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698