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 // This file implements the TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // The number of bits in a byte | 127 // The number of bits in a byte |
128 const uint32_t X86_CHAR_BIT = 8; | 128 const uint32_t X86_CHAR_BIT = 8; |
129 // Stack alignment | 129 // Stack alignment |
130 const uint32_t X86_STACK_ALIGNMENT_BYTES = 16; | 130 const uint32_t X86_STACK_ALIGNMENT_BYTES = 16; |
131 // Size of the return address on the stack | 131 // Size of the return address on the stack |
132 const uint32_t X86_RET_IP_SIZE_BYTES = 4; | 132 const uint32_t X86_RET_IP_SIZE_BYTES = 4; |
133 // The base 2 logarithm of the width in bytes of the smallest stack slot | 133 // The base 2 logarithm of the width in bytes of the smallest stack slot |
134 const uint32_t X86_LOG2_OF_MIN_STACK_SLOT_SIZE = 2; | 134 const uint32_t X86_LOG2_OF_MIN_STACK_SLOT_SIZE = 2; |
135 // The base 2 logarithm of the width in bytes of the largest stack slot | 135 // The base 2 logarithm of the width in bytes of the largest stack slot |
136 const uint32_t X86_LOG2_OF_MAX_STACK_SLOT_SIZE = 4; | 136 const uint32_t X86_LOG2_OF_MAX_STACK_SLOT_SIZE = 4; |
| 137 // The number of different NOP instructions |
| 138 const uint32_t X86_NUM_NOP_VARIANTS = 5; |
137 | 139 |
138 // Value and Alignment are in bytes. Return Value adjusted to the next | 140 // Value and Alignment are in bytes. Return Value adjusted to the next |
139 // highest multiple of Alignment. | 141 // highest multiple of Alignment. |
140 uint32_t applyAlignment(uint32_t Value, uint32_t Alignment) { | 142 uint32_t applyAlignment(uint32_t Value, uint32_t Alignment) { |
141 // power of 2 | 143 // power of 2 |
142 assert((Alignment & (Alignment - 1)) == 0); | 144 assert((Alignment & (Alignment - 1)) == 0); |
143 return (Value + Alignment - 1) & -Alignment; | 145 return (Value + Alignment - 1) & -Alignment; |
144 } | 146 } |
145 | 147 |
146 // Value is in bytes. Return Value adjusted to the next highest multiple | 148 // Value is in bytes. Return Value adjusted to the next highest multiple |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 T_regAlloc.printElapsedUs(Context, "regAlloc()"); | 386 T_regAlloc.printElapsedUs(Context, "regAlloc()"); |
385 Func->dump("After linear scan regalloc"); | 387 Func->dump("After linear scan regalloc"); |
386 | 388 |
387 // Stack frame mapping. | 389 // Stack frame mapping. |
388 Timer T_genFrame; | 390 Timer T_genFrame; |
389 Func->genFrame(); | 391 Func->genFrame(); |
390 if (Func->hasError()) | 392 if (Func->hasError()) |
391 return; | 393 return; |
392 T_genFrame.printElapsedUs(Context, "genFrame()"); | 394 T_genFrame.printElapsedUs(Context, "genFrame()"); |
393 Func->dump("After stack frame mapping"); | 395 Func->dump("After stack frame mapping"); |
| 396 |
| 397 // Nop insertion |
| 398 if (shouldDoNopInsertion()) { |
| 399 Func->doNopInsertion(); |
| 400 } |
394 } | 401 } |
395 | 402 |
396 void TargetX8632::translateOm1() { | 403 void TargetX8632::translateOm1() { |
397 GlobalContext *Context = Func->getContext(); | 404 GlobalContext *Context = Func->getContext(); |
398 Timer T_placePhiLoads; | 405 Timer T_placePhiLoads; |
399 Func->placePhiLoads(); | 406 Func->placePhiLoads(); |
400 if (Func->hasError()) | 407 if (Func->hasError()) |
401 return; | 408 return; |
402 T_placePhiLoads.printElapsedUs(Context, "placePhiLoads()"); | 409 T_placePhiLoads.printElapsedUs(Context, "placePhiLoads()"); |
403 Timer T_placePhiStores; | 410 Timer T_placePhiStores; |
(...skipping 18 matching lines...) Expand all Loading... |
422 return; | 429 return; |
423 T_genCode.printElapsedUs(Context, "genCode()"); | 430 T_genCode.printElapsedUs(Context, "genCode()"); |
424 Func->dump("After initial x8632 codegen"); | 431 Func->dump("After initial x8632 codegen"); |
425 | 432 |
426 Timer T_genFrame; | 433 Timer T_genFrame; |
427 Func->genFrame(); | 434 Func->genFrame(); |
428 if (Func->hasError()) | 435 if (Func->hasError()) |
429 return; | 436 return; |
430 T_genFrame.printElapsedUs(Context, "genFrame()"); | 437 T_genFrame.printElapsedUs(Context, "genFrame()"); |
431 Func->dump("After stack frame mapping"); | 438 Func->dump("After stack frame mapping"); |
| 439 |
| 440 // Nop insertion |
| 441 if (shouldDoNopInsertion()) { |
| 442 Func->doNopInsertion(); |
| 443 } |
432 } | 444 } |
433 | 445 |
434 IceString TargetX8632::RegNames[] = { | 446 IceString TargetX8632::RegNames[] = { |
435 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \ | 447 #define X(val, init, name, name16, name8, scratch, preserved, stackptr, \ |
436 frameptr, isI8, isInt, isFP) \ | 448 frameptr, isI8, isInt, isFP) \ |
437 name, | 449 name, |
438 REGX8632_TABLE | 450 REGX8632_TABLE |
439 #undef X | 451 #undef X |
440 }; | 452 }; |
441 | 453 |
(...skipping 3221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3663 computeAddressOpt(Base, Index, Shift, Offset); | 3675 computeAddressOpt(Base, Index, Shift, Offset); |
3664 if (Base && Addr != Base) { | 3676 if (Base && Addr != Base) { |
3665 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset); | 3677 Constant *OffsetOp = Ctx->getConstantInt(IceType_i32, Offset); |
3666 Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index, | 3678 Addr = OperandX8632Mem::create(Func, Dest->getType(), Base, OffsetOp, Index, |
3667 Shift, SegmentReg); | 3679 Shift, SegmentReg); |
3668 Inst->setDeleted(); | 3680 Inst->setDeleted(); |
3669 Context.insert(InstLoad::create(Func, Dest, Addr)); | 3681 Context.insert(InstLoad::create(Func, Dest, Addr)); |
3670 } | 3682 } |
3671 } | 3683 } |
3672 | 3684 |
| 3685 void TargetX8632::randomlyInsertNop(float Probability) { |
| 3686 RandomNumberGeneratorWrapper RNG(Ctx->getRNG()); |
| 3687 if (RNG.getTrueWithProbability(Probability)) { |
| 3688 _nop(RNG.next(X86_NUM_NOP_VARIANTS)); |
| 3689 } |
| 3690 } |
| 3691 |
3673 void TargetX8632::lowerPhi(const InstPhi * /*Inst*/) { | 3692 void TargetX8632::lowerPhi(const InstPhi * /*Inst*/) { |
3674 Func->setError("Phi found in regular instruction list"); | 3693 Func->setError("Phi found in regular instruction list"); |
3675 } | 3694 } |
3676 | 3695 |
3677 void TargetX8632::lowerRet(const InstRet *Inst) { | 3696 void TargetX8632::lowerRet(const InstRet *Inst) { |
3678 Variable *Reg = NULL; | 3697 Variable *Reg = NULL; |
3679 if (Inst->hasRetValue()) { | 3698 if (Inst->hasRetValue()) { |
3680 Operand *Src0 = legalize(Inst->getRetValue()); | 3699 Operand *Src0 = legalize(Inst->getRetValue()); |
3681 if (Src0->getType() == IceType_i64) { | 3700 if (Src0->getType() == IceType_i64) { |
3682 Variable *eax = legalizeToVar(loOperand(Src0), false, Reg_eax); | 3701 Variable *eax = legalizeToVar(loOperand(Src0), false, Reg_eax); |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4317 Str << "\t.align\t" << Align << "\n"; | 4336 Str << "\t.align\t" << Align << "\n"; |
4318 Str << MangledName << ":\n"; | 4337 Str << MangledName << ":\n"; |
4319 for (SizeT i = 0; i < Size; ++i) { | 4338 for (SizeT i = 0; i < Size; ++i) { |
4320 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | 4339 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
4321 } | 4340 } |
4322 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4341 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
4323 } | 4342 } |
4324 } | 4343 } |
4325 | 4344 |
4326 } // end of namespace Ice | 4345 } // end of namespace Ice |
OLD | NEW |