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

Side by Side Diff: src/IceTargetLoweringX8632.cpp

Issue 463563006: Subzero: Randomly insert nops. (Closed) Base URL: https://gerrit.chromium.org/gerrit/p/native_client/pnacl-subzero.git@master
Patch Set: Remove redundancy and fix formatting. Created 6 years, 4 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 // This file implements the TargetLoweringX8632 class, which 10 // This file implements the TargetLoweringX8632 class, which
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 } 121 }
122 122
123 // The maximum number of arguments to pass in XMM registers 123 // The maximum number of arguments to pass in XMM registers
124 const uint32_t X86_MAX_XMM_ARGS = 4; 124 const uint32_t X86_MAX_XMM_ARGS = 4;
125 // The number of bits in a byte 125 // The number of bits in a byte
126 const uint32_t X86_CHAR_BIT = 8; 126 const uint32_t X86_CHAR_BIT = 8;
127 // Stack alignment 127 // Stack alignment
128 const uint32_t X86_STACK_ALIGNMENT_BYTES = 16; 128 const uint32_t X86_STACK_ALIGNMENT_BYTES = 16;
129 // Size of the return address on the stack 129 // Size of the return address on the stack
130 const uint32_t X86_RET_IP_SIZE_BYTES = 4; 130 const uint32_t X86_RET_IP_SIZE_BYTES = 4;
131 // The maximum supported length of a NOP instruction (all smaller
132 // lengths are also supported)
133 const uint32_t X86_MAX_NOP_LEN = 9;
jvoung (off chromium) 2014/08/14 15:17:17 Does it actually help to add nops of up to 9 bytes
wala 2014/08/14 23:29:50 Thanks for the link. That paper makes it clear th
131 134
132 // Value is a size in bytes. Return Value adjusted to the next highest 135 // Value is a size in bytes. Return Value adjusted to the next highest
133 // multiple of the stack alignment. 136 // multiple of the stack alignment.
134 uint32_t applyStackAlignment(uint32_t Value) { 137 uint32_t applyStackAlignment(uint32_t Value) {
135 // power of 2 138 // power of 2
136 assert((X86_STACK_ALIGNMENT_BYTES & (X86_STACK_ALIGNMENT_BYTES - 1)) == 0); 139 assert((X86_STACK_ALIGNMENT_BYTES & (X86_STACK_ALIGNMENT_BYTES - 1)) == 0);
137 return (Value + X86_STACK_ALIGNMENT_BYTES - 1) & -X86_STACK_ALIGNMENT_BYTES; 140 return (Value + X86_STACK_ALIGNMENT_BYTES - 1) & -X86_STACK_ALIGNMENT_BYTES;
138 } 141 }
139 142
140 // Instruction set options 143 // Instruction set options
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 T_regAlloc.printElapsedUs(Context, "regAlloc()"); 388 T_regAlloc.printElapsedUs(Context, "regAlloc()");
386 Func->dump("After linear scan regalloc"); 389 Func->dump("After linear scan regalloc");
387 390
388 // Stack frame mapping. 391 // Stack frame mapping.
389 Timer T_genFrame; 392 Timer T_genFrame;
390 Func->genFrame(); 393 Func->genFrame();
391 if (Func->hasError()) 394 if (Func->hasError())
392 return; 395 return;
393 T_genFrame.printElapsedUs(Context, "genFrame()"); 396 T_genFrame.printElapsedUs(Context, "genFrame()");
394 Func->dump("After stack frame mapping"); 397 Func->dump("After stack frame mapping");
398
399 // Nop insertion
400 if (shouldDoNopInsertion()) {
401 Func->doNopInsertion();
402 }
395 } 403 }
396 404
397 void TargetX8632::translateOm1() { 405 void TargetX8632::translateOm1() {
398 GlobalContext *Context = Func->getContext(); 406 GlobalContext *Context = Func->getContext();
399 Timer T_placePhiLoads; 407 Timer T_placePhiLoads;
400 Func->placePhiLoads(); 408 Func->placePhiLoads();
401 if (Func->hasError()) 409 if (Func->hasError())
402 return; 410 return;
403 T_placePhiLoads.printElapsedUs(Context, "placePhiLoads()"); 411 T_placePhiLoads.printElapsedUs(Context, "placePhiLoads()");
404 Timer T_placePhiStores; 412 Timer T_placePhiStores;
(...skipping 18 matching lines...) Expand all
423 return; 431 return;
424 T_genCode.printElapsedUs(Context, "genCode()"); 432 T_genCode.printElapsedUs(Context, "genCode()");
425 Func->dump("After initial x8632 codegen"); 433 Func->dump("After initial x8632 codegen");
426 434
427 Timer T_genFrame; 435 Timer T_genFrame;
428 Func->genFrame(); 436 Func->genFrame();
429 if (Func->hasError()) 437 if (Func->hasError())
430 return; 438 return;
431 T_genFrame.printElapsedUs(Context, "genFrame()"); 439 T_genFrame.printElapsedUs(Context, "genFrame()");
432 Func->dump("After stack frame mapping"); 440 Func->dump("After stack frame mapping");
441
442 // Nop insertion
443 if (shouldDoNopInsertion()) {
444 Func->doNopInsertion();
445 }
433 } 446 }
434 447
435 IceString TargetX8632::RegNames[] = { 448 IceString TargetX8632::RegNames[] = {
436 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \ 449 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \
437 frameptr, isI8, isInt, isFP) \ 450 frameptr, isI8, isInt, isFP) \
438 name, 451 name,
439 REGX8632_TABLE 452 REGX8632_TABLE
440 #undef X 453 #undef X
441 }; 454 };
442 455
(...skipping 3147 matching lines...) Expand 10 before | Expand all | Expand 10 after
3590 computeAddressOpt(Base, Index, Shift, Offset); 3603 computeAddressOpt(Base, Index, Shift, Offset);
3591 if (Base && Addr != Base) { 3604 if (Base && Addr != Base) {
3592 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset); 3605 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset);
3593 Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index, 3606 Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index,
3594 Shift, SegmentReg); 3607 Shift, SegmentReg);
3595 Inst->setDeleted(); 3608 Inst->setDeleted();
3596 Context.insert(InstLoad::create(Func, Dest, Addr)); 3609 Context.insert(InstLoad::create(Func, Dest, Addr));
3597 } 3610 }
3598 } 3611 }
3599 3612
3613 void TargetX8632::randomlyInsertNop(float Probability) {
3614 RandomNumberGeneratorWrapper RNG = Ctx->getRNG();
3615 if (RNG.getTrueWithProbability(Probability)) {
3616 _nop(1 + RNG.next(X86_MAX_NOP_LEN));
3617 }
3618 }
3619
3600 void TargetX8632::lowerPhi(const InstPhi * /*Inst*/) { 3620 void TargetX8632::lowerPhi(const InstPhi * /*Inst*/) {
3601 Func->setError("Phi found in regular instruction list"); 3621 Func->setError("Phi found in regular instruction list");
3602 } 3622 }
3603 3623
3604 void TargetX8632::lowerRet(const InstRet *Inst) { 3624 void TargetX8632::lowerRet(const InstRet *Inst) {
3605 Variable *Reg = NULL; 3625 Variable *Reg = NULL;
3606 if (Inst->hasRetValue()) { 3626 if (Inst->hasRetValue()) {
3607 Operand *Src0 = legalize(Inst->getRetValue()); 3627 Operand *Src0 = legalize(Inst->getRetValue());
3608 if (Src0->getType() == IceType_i64) { 3628 if (Src0->getType() == IceType_i64) {
3609 Variable *eax = legalizeToVar(loOperand(Src0), false, Reg_eax); 3629 Variable *eax = legalizeToVar(loOperand(Src0), false, Reg_eax);
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
4249 for (SizeT i = 0; i < Size; ++i) { 4269 for (SizeT i = 0; i < Size; ++i) {
4250 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; 4270 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n";
4251 } 4271 }
4252 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; 4272 Str << "\t.size\t" << MangledName << ", " << Size << "\n";
4253 } 4273 }
4254 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName 4274 Str << "\t" << (IsInternal ? ".local" : ".global") << "\t" << MangledName
4255 << "\n"; 4275 << "\n";
4256 } 4276 }
4257 4277
4258 } // end of namespace Ice 4278 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698