OLD | NEW |
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
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 /// \file | 10 /// \file |
(...skipping 17 matching lines...) Loading... |
28 Ctx); | 28 Ctx); |
29 } | 29 } |
30 | 30 |
31 std::unique_ptr<::Ice::TargetHeaderLowering> | 31 std::unique_ptr<::Ice::TargetHeaderLowering> |
32 createTargetHeaderLowering(::Ice::GlobalContext *Ctx) { | 32 createTargetHeaderLowering(::Ice::GlobalContext *Ctx) { |
33 return ::Ice::X8632::TargetHeaderX86::create(Ctx); | 33 return ::Ice::X8632::TargetHeaderX86::create(Ctx); |
34 } | 34 } |
35 | 35 |
36 void staticInit(::Ice::GlobalContext *Ctx) { | 36 void staticInit(::Ice::GlobalContext *Ctx) { |
37 ::Ice::X8632::TargetX8632::staticInit(Ctx); | 37 ::Ice::X8632::TargetX8632::staticInit(Ctx); |
| 38 if (Ctx->getFlags().getUseNonsfi()) { |
| 39 // In nonsfi, we need to reference the _GLOBAL_OFFSET_TABLE_ for accessing |
| 40 // globals. The GOT is an external symbol (i.e., it is not defined in the |
| 41 // pexe) so we need to register it as such so that ELF emission won't barf |
| 42 // on an "unknown" symbol. The GOT is added to the External symbols list |
| 43 // here because staticInit() is invoked in a single-thread context. |
| 44 Ctx->getConstantExternSym(::Ice::GlobalOffsetTable); |
| 45 } |
38 } | 46 } |
39 } // end of namespace X8632 | 47 } // end of namespace X8632 |
40 | 48 |
41 namespace Ice { | 49 namespace Ice { |
42 namespace X8632 { | 50 namespace X8632 { |
43 | 51 |
44 //------------------------------------------------------------------------------ | 52 //------------------------------------------------------------------------------ |
45 // ______ ______ ______ __ ______ ______ | 53 // ______ ______ ______ __ ______ ______ |
46 // /\__ _\ /\ == \ /\ __ \ /\ \ /\__ _\ /\ ___\ | 54 // /\__ _\ /\ == \ /\ __ \ /\ \ /\__ _\ /\ ___\ |
47 // \/_/\ \/ \ \ __< \ \ __ \ \ \ \ \/_/\ \/ \ \___ \ | 55 // \/_/\ \/ \ \ __< \ \ __ \ \ \ \ \/_/\ \/ \ \___ \ |
(...skipping 178 matching lines...) Loading... |
226 } | 234 } |
227 // Delete any existing InstX86GetIP instruction and reinsert it here. Also, | 235 // Delete any existing InstX86GetIP instruction and reinsert it here. Also, |
228 // insert the call to the helper function and the spill to the stack, to | 236 // insert the call to the helper function and the spill to the stack, to |
229 // simplify emission. | 237 // simplify emission. |
230 if (GetIPInst) { | 238 if (GetIPInst) { |
231 GetIPInst->setDeleted(); | 239 GetIPInst->setDeleted(); |
232 Variable *Dest = GetIPInst->getDest(); | 240 Variable *Dest = GetIPInst->getDest(); |
233 Variable *CallDest = | 241 Variable *CallDest = |
234 Dest->hasReg() ? Dest | 242 Dest->hasReg() ? Dest |
235 : getPhysicalRegister(Traits::RegisterSet::Reg_eax); | 243 : getPhysicalRegister(Traits::RegisterSet::Reg_eax); |
236 // Call the getIP_<reg> helper. | 244 auto *BeforeAddReloc = RelocOffset::create(Ctx); |
237 IceString RegName = Traits::getRegName(CallDest->getRegNum()); | 245 BeforeAddReloc->setSubtract(true); |
238 Constant *CallTarget = Ctx->getConstantExternSym(H_getIP_prefix + RegName); | 246 auto *BeforeAdd = InstX86Label::create(Func, this); |
239 Context.insert<Traits::Insts::Call>(CallDest, CallTarget); | 247 BeforeAdd->setRelocOffset(BeforeAddReloc); |
| 248 |
| 249 auto *AfterAddReloc = RelocOffset::create(Ctx); |
| 250 auto *AfterAdd = InstX86Label::create(Func, this); |
| 251 AfterAdd->setRelocOffset(AfterAddReloc); |
| 252 |
| 253 auto *ImmSize = RelocOffset::create(Ctx, -typeWidthInBytes(IceType_i32)); |
| 254 |
| 255 auto *GotFromPc = llvm::cast<ConstantRelocatable>( |
| 256 Ctx->getConstantSym({AfterAddReloc, BeforeAddReloc, ImmSize}, |
| 257 GlobalOffsetTable, GlobalOffsetTable, true)); |
| 258 |
240 // Insert a new version of InstX86GetIP. | 259 // Insert a new version of InstX86GetIP. |
241 Context.insert<Traits::Insts::GetIP>(CallDest); | 260 Context.insert<Traits::Insts::GetIP>(CallDest); |
| 261 |
| 262 Context.insert(BeforeAdd); |
| 263 _add(CallDest, GotFromPc); |
| 264 Context.insert(AfterAdd); |
| 265 |
242 // Spill the register to its home stack location if necessary. | 266 // Spill the register to its home stack location if necessary. |
243 if (!Dest->hasReg()) { | 267 if (Dest != CallDest) { |
244 _mov(Dest, CallDest); | 268 _mov(Dest, CallDest); |
245 } | 269 } |
246 } | 270 } |
247 } | 271 } |
248 | 272 |
249 void TargetX8632::lowerIndirectJump(Variable *JumpTarget) { | 273 void TargetX8632::lowerIndirectJump(Variable *JumpTarget) { |
250 AutoBundle _(this); | 274 AutoBundle _(this); |
251 | 275 |
252 if (NeedSandboxing) { | 276 if (NeedSandboxing) { |
253 const SizeT BundleSize = | 277 const SizeT BundleSize = |
(...skipping 199 matching lines...) Loading... |
453 #define X(tag, sizeLog2, align, elts, elty, str, rcstr) \ | 477 #define X(tag, sizeLog2, align, elts, elty, str, rcstr) \ |
454 static_assert(_table1_##tag == _table2_##tag, \ | 478 static_assert(_table1_##tag == _table2_##tag, \ |
455 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); | 479 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); |
456 ICETYPE_TABLE | 480 ICETYPE_TABLE |
457 #undef X | 481 #undef X |
458 } // end of namespace dummy3 | 482 } // end of namespace dummy3 |
459 } // end of anonymous namespace | 483 } // end of anonymous namespace |
460 | 484 |
461 } // end of namespace X8632 | 485 } // end of namespace X8632 |
462 } // end of namespace Ice | 486 } // end of namespace Ice |
OLD | NEW |