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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 void TargetX8632::_add_sp(Operand *Adjustment) { | 129 void TargetX8632::_add_sp(Operand *Adjustment) { |
130 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); | 130 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); |
131 _add(esp, Adjustment); | 131 _add(esp, Adjustment); |
132 } | 132 } |
133 | 133 |
134 void TargetX8632::_mov_sp(Operand *NewValue) { | 134 void TargetX8632::_mov_sp(Operand *NewValue) { |
135 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); | 135 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); |
136 _redefined(_mov(esp, NewValue)); | 136 _redefined(_mov(esp, NewValue)); |
137 } | 137 } |
138 | 138 |
| 139 Traits::X86OperandMem *TargetX8632::_sandbox_mem_reference(X86OperandMem *Mem) { |
| 140 switch (SandboxingType) { |
| 141 case ST_None: |
| 142 case ST_NaCl: |
| 143 return Mem; |
| 144 case ST_Nonsfi: { |
| 145 if (Mem->getIsRebased()) { |
| 146 return Mem; |
| 147 } |
| 148 // For Non-SFI mode, if the Offset field is a ConstantRelocatable, we |
| 149 // replace either Base or Index with a legalized RebasePtr. At emission |
| 150 // time, the ConstantRelocatable will be emitted with the @GOTOFF |
| 151 // relocation. |
| 152 if (llvm::dyn_cast_or_null<ConstantRelocatable>(Mem->getOffset()) == |
| 153 nullptr) { |
| 154 return Mem; |
| 155 } |
| 156 Variable *T; |
| 157 uint16_t Shift = 0; |
| 158 if (Mem->getIndex() == nullptr) { |
| 159 T = Mem->getBase(); |
| 160 } else if (Mem->getBase() == nullptr) { |
| 161 T = Mem->getIndex(); |
| 162 Shift = Mem->getShift(); |
| 163 } else { |
| 164 llvm::report_fatal_error( |
| 165 "Either Base or Index must be unused in Non-SFI mode"); |
| 166 } |
| 167 Variable *RebasePtrR = legalizeToReg(RebasePtr); |
| 168 static constexpr bool IsRebased = true; |
| 169 return Traits::X86OperandMem::create( |
| 170 Func, Mem->getType(), RebasePtrR, Mem->getOffset(), T, Shift, |
| 171 Traits::X86OperandMem::DefaultSegment, IsRebased); |
| 172 } |
| 173 } |
| 174 llvm::report_fatal_error("Unhandled sandboxing type: " + |
| 175 std::to_string(SandboxingType)); |
| 176 } |
| 177 |
139 void TargetX8632::_sub_sp(Operand *Adjustment) { | 178 void TargetX8632::_sub_sp(Operand *Adjustment) { |
140 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); | 179 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); |
141 _sub(esp, Adjustment); | 180 _sub(esp, Adjustment); |
142 } | 181 } |
143 | 182 |
144 void TargetX8632::_link_bp() { | 183 void TargetX8632::_link_bp() { |
145 Variable *ebp = getPhysicalRegister(Traits::RegisterSet::Reg_ebp); | 184 Variable *ebp = getPhysicalRegister(Traits::RegisterSet::Reg_ebp); |
146 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); | 185 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); |
147 _push(ebp); | 186 _push(ebp); |
148 _mov(ebp, esp); | 187 _mov(ebp, esp); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 | 246 |
208 if (NeedSandboxing) { | 247 if (NeedSandboxing) { |
209 const SizeT BundleSize = | 248 const SizeT BundleSize = |
210 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes(); | 249 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes(); |
211 _and(JumpTarget, Ctx->getConstantInt32(~(BundleSize - 1))); | 250 _and(JumpTarget, Ctx->getConstantInt32(~(BundleSize - 1))); |
212 } | 251 } |
213 | 252 |
214 _jmp(JumpTarget); | 253 _jmp(JumpTarget); |
215 } | 254 } |
216 | 255 |
| 256 void TargetX8632::initRebasePtr() { |
| 257 if (SandboxingType == ST_Nonsfi) { |
| 258 RebasePtr = Func->makeVariable(IceType_i32); |
| 259 } |
| 260 } |
| 261 |
| 262 void TargetX8632::initSandbox() { |
| 263 if (SandboxingType != ST_Nonsfi) { |
| 264 return; |
| 265 } |
| 266 // Insert the RebasePtr assignment as the very first lowered instruction. |
| 267 // Later, it will be moved into the right place - after the stack frame is set |
| 268 // up but before in-args are copied into registers. |
| 269 Context.init(Func->getEntryNode()); |
| 270 Context.setInsertPoint(Context.getCur()); |
| 271 Context.insert<Traits::Insts::GetIP>(RebasePtr); |
| 272 } |
| 273 |
| 274 bool TargetX8632::legalizeOptAddrForSandbox(OptAddr *Addr) { |
| 275 if (Addr->Relocatable == nullptr || SandboxingType != ST_Nonsfi) { |
| 276 return true; |
| 277 } |
| 278 |
| 279 if (Addr->Base == RebasePtr || Addr->Index == RebasePtr) { |
| 280 return true; |
| 281 } |
| 282 |
| 283 if (Addr->Base == nullptr) { |
| 284 Addr->Base = RebasePtr; |
| 285 return true; |
| 286 } |
| 287 |
| 288 if (Addr->Index == nullptr) { |
| 289 Addr->Index = RebasePtr; |
| 290 Addr->Shift = 0; |
| 291 return true; |
| 292 } |
| 293 |
| 294 return false; |
| 295 } |
| 296 |
217 Inst *TargetX8632::emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) { | 297 Inst *TargetX8632::emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) { |
218 std::unique_ptr<AutoBundle> Bundle; | 298 std::unique_ptr<AutoBundle> Bundle; |
219 if (NeedSandboxing) { | 299 if (NeedSandboxing) { |
220 if (llvm::isa<Constant>(CallTarget)) { | 300 if (llvm::isa<Constant>(CallTarget)) { |
221 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd); | 301 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd); |
222 } else { | 302 } else { |
223 Variable *CallTargetVar = nullptr; | 303 Variable *CallTargetVar = nullptr; |
224 _mov(CallTargetVar, CallTarget); | 304 _mov(CallTargetVar, CallTarget); |
225 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd); | 305 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd); |
226 const SizeT BundleSize = | 306 const SizeT BundleSize = |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 #define X(tag, sizeLog2, align, elts, elty, str) \ | 670 #define X(tag, sizeLog2, align, elts, elty, str) \ |
591 static_assert(_table1_##tag == _table2_##tag, \ | 671 static_assert(_table1_##tag == _table2_##tag, \ |
592 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); | 672 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); |
593 ICETYPE_TABLE | 673 ICETYPE_TABLE |
594 #undef X | 674 #undef X |
595 } // end of namespace dummy3 | 675 } // end of namespace dummy3 |
596 } // end of anonymous namespace | 676 } // end of anonymous namespace |
597 | 677 |
598 } // end of namespace X8632 | 678 } // end of namespace X8632 |
599 } // end of namespace Ice | 679 } // end of namespace Ice |
OLD | NEW |