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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 1585843007: Subzero. RAII NaCl Bundling. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Created 4 years, 11 months 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
« no previous file with comments | « src/IceTargetLoweringARM32.cpp ('k') | src/IceTargetLoweringX8664.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); 139 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp);
140 _redefined(_mov(esp, NewValue)); 140 _redefined(_mov(esp, NewValue));
141 } 141 }
142 142
143 void TargetX8632::_sub_sp(Operand *Adjustment) { 143 void TargetX8632::_sub_sp(Operand *Adjustment) {
144 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp); 144 Variable *esp = getPhysicalRegister(Traits::RegisterSet::Reg_esp);
145 _sub(esp, Adjustment); 145 _sub(esp, Adjustment);
146 } 146 }
147 147
148 void TargetX8632::lowerIndirectJump(Variable *JumpTarget) { 148 void TargetX8632::lowerIndirectJump(Variable *JumpTarget) {
149 AutoBundle _(this);
150
149 if (NeedSandboxing) { 151 if (NeedSandboxing) {
150 _bundle_lock();
151 const SizeT BundleSize = 152 const SizeT BundleSize =
152 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes(); 153 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes();
153 _and(JumpTarget, Ctx->getConstantInt32(~(BundleSize - 1))); 154 _and(JumpTarget, Ctx->getConstantInt32(~(BundleSize - 1)));
154 } 155 }
156
155 _jmp(JumpTarget); 157 _jmp(JumpTarget);
156 if (NeedSandboxing)
157 _bundle_unlock();
158 } 158 }
159 159
160 void TargetX8632::lowerCall(const InstCall *Instr) { 160 void TargetX8632::lowerCall(const InstCall *Instr) {
161 // x86-32 calling convention: 161 // x86-32 calling convention:
162 // 162 //
163 // * At the point before the call, the stack must be aligned to 16 bytes. 163 // * At the point before the call, the stack must be aligned to 16 bytes.
164 // 164 //
165 // * The first four arguments of vector type, regardless of their position 165 // * The first four arguments of vector type, regardless of their position
166 // relative to the other arguments in the argument list, are placed in 166 // relative to the other arguments in the argument list, are placed in
167 // registers xmm0 - xmm3. 167 // registers xmm0 - xmm3.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 case IceType_v8i1: 271 case IceType_v8i1:
272 case IceType_v16i1: 272 case IceType_v16i1:
273 case IceType_v16i8: 273 case IceType_v16i8:
274 case IceType_v8i16: 274 case IceType_v8i16:
275 case IceType_v4i32: 275 case IceType_v4i32:
276 case IceType_v4f32: 276 case IceType_v4f32:
277 ReturnReg = makeReg(DestTy, Traits::RegisterSet::Reg_xmm0); 277 ReturnReg = makeReg(DestTy, Traits::RegisterSet::Reg_xmm0);
278 break; 278 break;
279 } 279 }
280 } 280 }
281
281 Operand *CallTarget = 282 Operand *CallTarget =
282 legalize(Instr->getCallTarget(), Legal_Reg | Legal_Imm | Legal_AddrAbs); 283 legalize(Instr->getCallTarget(), Legal_Reg | Legal_Imm | Legal_AddrAbs);
283 if (NeedSandboxing) { 284
284 if (llvm::isa<Constant>(CallTarget)) { 285 Traits::Insts::Call *NewCall;
285 _bundle_lock(InstBundleLock::Opt_AlignToEnd); 286 /* AutoBundle scoping */ {
286 } else { 287 std::unique_ptr<AutoBundle> Bundle;
287 Variable *CallTargetVar = nullptr; 288 if (NeedSandboxing) {
288 _mov(CallTargetVar, CallTarget); 289 if (llvm::isa<Constant>(CallTarget)) {
289 _bundle_lock(InstBundleLock::Opt_AlignToEnd); 290 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd);
290 const SizeT BundleSize = 291 } else {
291 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes(); 292 Variable *CallTargetVar = nullptr;
292 _and(CallTargetVar, Ctx->getConstantInt32(~(BundleSize - 1))); 293 _mov(CallTargetVar, CallTarget);
293 CallTarget = CallTargetVar; 294 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd);
295 const SizeT BundleSize =
296 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes();
297 _and(CallTargetVar, Ctx->getConstantInt32(~(BundleSize - 1)));
298 CallTarget = CallTargetVar;
299 }
294 } 300 }
301 NewCall = Context.insert<Traits::Insts::Call>(ReturnReg, CallTarget);
295 } 302 }
296 auto *NewCall = Context.insert<Traits::Insts::Call>(ReturnReg, CallTarget); 303
297 if (NeedSandboxing)
298 _bundle_unlock();
299 if (ReturnRegHi) 304 if (ReturnRegHi)
300 Context.insert<InstFakeDef>(ReturnRegHi); 305 Context.insert<InstFakeDef>(ReturnRegHi);
301 306
302 // Insert a register-kill pseudo instruction. 307 // Insert a register-kill pseudo instruction.
303 Context.insert<InstFakeKill>(NewCall); 308 Context.insert<InstFakeKill>(NewCall);
304 309
305 if (Dest != nullptr && isScalarFloatingType(Dest->getType())) { 310 if (Dest != nullptr && isScalarFloatingType(Dest->getType())) {
306 // Special treatment for an FP function which returns its result in st(0). 311 // Special treatment for an FP function which returns its result in st(0).
307 // If Dest ends up being a physical xmm register, the fstp emit code will 312 // If Dest ends up being a physical xmm register, the fstp emit code will
308 // route st(0) through the space reserved in the function argument area 313 // route st(0) through the space reserved in the function argument area
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 for (SizeT i = 0; i < Popped.size(); ++i) { 747 for (SizeT i = 0; i < Popped.size(); ++i) {
743 SizeT j = Popped.size() - i - 1; 748 SizeT j = Popped.size() - i - 1;
744 SizeT Canonical = Traits::getBaseReg(j); 749 SizeT Canonical = Traits::getBaseReg(j);
745 if (j == Traits::RegisterSet::Reg_ebp && IsEbpBasedFrame) 750 if (j == Traits::RegisterSet::Reg_ebp && IsEbpBasedFrame)
746 continue; 751 continue;
747 if (Popped[j]) { 752 if (Popped[j]) {
748 _pop(getPhysicalRegister(Canonical)); 753 _pop(getPhysicalRegister(Canonical));
749 } 754 }
750 } 755 }
751 756
752 if (!NeedSandboxing) 757 if (!NeedSandboxing) {
753 return; 758 return;
759 }
760
754 // Change the original ret instruction into a sandboxed return sequence. 761 // Change the original ret instruction into a sandboxed return sequence.
755 // t:ecx = pop 762 // t:ecx = pop
756 // bundle_lock 763 // bundle_lock
757 // and t, ~31 764 // and t, ~31
758 // jmp *t 765 // jmp *t
759 // bundle_unlock 766 // bundle_unlock
760 // FakeUse <original_ret_operand> 767 // FakeUse <original_ret_operand>
761 Variable *T_ecx = makeReg(IceType_i32, Traits::RegisterSet::Reg_ecx); 768 Variable *T_ecx = makeReg(IceType_i32, Traits::RegisterSet::Reg_ecx);
762 _pop(T_ecx); 769 _pop(T_ecx);
763 lowerIndirectJump(T_ecx); 770 lowerIndirectJump(T_ecx);
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1089 #define X(tag, sizeLog2, align, elts, elty, str) \ 1096 #define X(tag, sizeLog2, align, elts, elty, str) \
1090 static_assert(_table1_##tag == _table2_##tag, \ 1097 static_assert(_table1_##tag == _table2_##tag, \
1091 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); 1098 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE");
1092 ICETYPE_TABLE 1099 ICETYPE_TABLE
1093 #undef X 1100 #undef X
1094 } // end of namespace dummy3 1101 } // end of namespace dummy3
1095 } // end of anonymous namespace 1102 } // end of anonymous namespace
1096 1103
1097 } // end of namespace X8632 1104 } // end of namespace X8632
1098 } // end of namespace Ice 1105 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/IceTargetLoweringARM32.cpp ('k') | src/IceTargetLoweringX8664.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698