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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 1605103002: Subzero. X86. Refactors Address Mode formation. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Minor changes. 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
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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SandboxPtr. 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 *SandboxPtrR = legalizeToReg(SandboxPtr);
168 static constexpr bool IsRebased = true;
169 return Traits::X86OperandMem::create(
170 Func, Mem->getType(), SandboxPtrR, 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::lowerIndirectJump(Variable *JumpTarget) { 183 void TargetX8632::lowerIndirectJump(Variable *JumpTarget) {
145 AutoBundle _(this); 184 AutoBundle _(this);
146 185
147 if (NeedSandboxing) { 186 if (NeedSandboxing) {
148 const SizeT BundleSize = 187 const SizeT BundleSize =
149 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes(); 188 1 << Func->getAssembler<>()->getBundleAlignLog2Bytes();
150 _and(JumpTarget, Ctx->getConstantInt32(~(BundleSize - 1))); 189 _and(JumpTarget, Ctx->getConstantInt32(~(BundleSize - 1)));
151 } 190 }
152 191
153 _jmp(JumpTarget); 192 _jmp(JumpTarget);
154 } 193 }
155 194
195 void TargetX8632::initSandboxPtr() {
196 if (SandboxingType == ST_Nonsfi) {
197 SandboxPtr = Func->makeVariable(IceType_i32);
198 }
199 }
200
201 void TargetX8632::initSandbox() {
202 if (SandboxingType != ST_Nonsfi) {
203 return;
204 }
205 // Insert the SandboxPtr assignment as the very first lowered instruction.
206 // Later, it will be moved into the right place - after the stack frame is
207 // set up but before in-args are copied into registers.
208 Context.init(Func->getEntryNode());
209 Context.setInsertPoint(Context.getCur());
210 Context.insert<Traits::Insts::GetIP>(SandboxPtr);
211 }
212
213 bool TargetX8632::legalizeOptAddrForSandbox(OptAddr *Addr) {
214 if (Addr->Relocatable == nullptr || SandboxingType != ST_Nonsfi) {
215 return true;
216 }
217
218 if (Addr->Base == SandboxPtr || Addr->Index == SandboxPtr) {
219 return true;
220 }
221
222 if (Addr->Base == nullptr) {
223 Addr->Base = SandboxPtr;
224 return true;
225 }
226
227 if (Addr->Index == nullptr) {
228 Addr->Index = SandboxPtr;
229 Addr->Shift = 0;
230 return true;
231 }
232
233 return false;
234 }
235
156 Inst *TargetX8632::emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) { 236 Inst *TargetX8632::emitCallToTarget(Operand *CallTarget, Variable *ReturnReg) {
157 std::unique_ptr<AutoBundle> Bundle; 237 std::unique_ptr<AutoBundle> Bundle;
158 if (NeedSandboxing) { 238 if (NeedSandboxing) {
159 if (llvm::isa<Constant>(CallTarget)) { 239 if (llvm::isa<Constant>(CallTarget)) {
160 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd); 240 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd);
161 } else { 241 } else {
162 Variable *CallTargetVar = nullptr; 242 Variable *CallTargetVar = nullptr;
163 _mov(CallTargetVar, CallTarget); 243 _mov(CallTargetVar, CallTarget);
164 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd); 244 Bundle = makeUnique<AutoBundle>(this, InstBundleLock::Opt_AlignToEnd);
165 const SizeT BundleSize = 245 const SizeT BundleSize =
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 #define X(tag, sizeLog2, align, elts, elty, str) \ 959 #define X(tag, sizeLog2, align, elts, elty, str) \
880 static_assert(_table1_##tag == _table2_##tag, \ 960 static_assert(_table1_##tag == _table2_##tag, \
881 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); 961 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE");
882 ICETYPE_TABLE 962 ICETYPE_TABLE
883 #undef X 963 #undef X
884 } // end of namespace dummy3 964 } // end of namespace dummy3
885 } // end of anonymous namespace 965 } // end of anonymous namespace
886 966
887 } // end of namespace X8632 967 } // end of namespace X8632
888 } // end of namespace Ice 968 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698