OLD | NEW |
---|---|
1 //===- subzero/src/IceInstX86BaseImpl.h - Generic X86 instructions -*- C++ -*=// | 1 //===- subzero/src/IceInstX86BaseImpl.h - Generic X86 instructions -*- C++ -*=// |
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
50 InstArithmetic::OpKind Op, | 50 InstArithmetic::OpKind Op, |
51 Variable *Beacon) | 51 Variable *Beacon) |
52 : InstX86Base<Machine>(Func, InstX86Base<Machine>::FakeRMW, 3, nullptr), | 52 : InstX86Base<Machine>(Func, InstX86Base<Machine>::FakeRMW, 3, nullptr), |
53 Op(Op) { | 53 Op(Op) { |
54 this->addSource(Data); | 54 this->addSource(Data); |
55 this->addSource(Addr); | 55 this->addSource(Addr); |
56 this->addSource(Beacon); | 56 this->addSource(Beacon); |
57 } | 57 } |
58 | 58 |
59 template <class Machine> | 59 template <class Machine> |
60 InstX86AdjustStack<Machine>::InstX86AdjustStack(Cfg *Func, SizeT Amount, | 60 InstX86AdjustStack<Machine>::InstX86AdjustStack(Cfg *Func, int32_t Amount, |
61 Variable *Esp) | 61 Variable *Esp) |
62 : InstX86Base<Machine>(Func, InstX86Base<Machine>::Adjuststack, 1, Esp), | 62 : InstX86Base<Machine>(Func, InstX86Base<Machine>::Adjuststack, 1, Esp), |
63 Amount(Amount) { | 63 Amount(Amount) { |
64 this->addSource(Esp); | 64 this->addSource(Esp); |
65 } | 65 } |
66 | 66 |
67 template <class Machine> | 67 template <class Machine> |
68 InstX86Mul<Machine>::InstX86Mul(Cfg *Func, Variable *Dest, Variable *Source1, | 68 InstX86Mul<Machine>::InstX86Mul(Cfg *Func, Variable *Dest, Variable *Source1, |
69 Operand *Source2) | 69 Operand *Source2) |
70 : InstX86Base<Machine>(Func, InstX86Base<Machine>::Mul, 2, Dest) { | 70 : InstX86Base<Machine>(Func, InstX86Base<Machine>::Mul, 2, Dest) { |
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(CallTarget)) { | 574 if (const auto *CI = llvm::dyn_cast<ConstantInteger32>(CallTarget)) { |
575 // Emit without a leading '$'. | 575 // Emit without a leading '$'. |
576 Str << CI->getValue(); | 576 Str << CI->getValue(); |
577 } else if (const auto DirectCallTarget = | 577 } else if (const auto DirectCallTarget = |
578 llvm::dyn_cast<ConstantRelocatable>(CallTarget)) { | 578 llvm::dyn_cast<ConstantRelocatable>(CallTarget)) { |
579 DirectCallTarget->emitWithoutPrefix(Target); | 579 DirectCallTarget->emitWithoutPrefix(Target); |
580 } else { | 580 } else { |
581 Str << "*"; | 581 Str << "*"; |
582 CallTarget->emit(Func); | 582 CallTarget->emit(Func); |
583 } | 583 } |
584 Target->resetStackAdjustment(); | |
585 } | 584 } |
586 | 585 |
587 template <class Machine> | 586 template <class Machine> |
588 void InstX86Call<Machine>::emitIAS(const Cfg *Func) const { | 587 void InstX86Call<Machine>::emitIAS(const Cfg *Func) const { |
589 typename InstX86Base<Machine>::Traits::Assembler *Asm = | 588 typename InstX86Base<Machine>::Traits::Assembler *Asm = |
590 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); | 589 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); |
591 Operand *CallTarget = getCallTarget(); | 590 Operand *CallTarget = getCallTarget(); |
592 auto *Target = InstX86Base<Machine>::getTarget(Func); | 591 auto *Target = InstX86Base<Machine>::getTarget(Func); |
593 if (const auto *Var = llvm::dyn_cast<Variable>(CallTarget)) { | 592 if (const auto *Var = llvm::dyn_cast<Variable>(CallTarget)) { |
594 if (Var->hasReg()) { | 593 if (Var->hasReg()) { |
595 Asm->call(InstX86Base<Machine>::Traits::getEncodedGPR(Var->getRegNum())); | 594 Asm->call(InstX86Base<Machine>::Traits::getEncodedGPR(Var->getRegNum())); |
596 } else { | 595 } else { |
597 Asm->call(Target->stackVarToAsmOperand(Var)); | 596 Asm->call(Target->stackVarToAsmOperand(Var)); |
598 } | 597 } |
599 } else if (const auto *Mem = llvm::dyn_cast< | 598 } else if (const auto *Mem = llvm::dyn_cast< |
600 typename InstX86Base<Machine>::Traits::X86OperandMem>( | 599 typename InstX86Base<Machine>::Traits::X86OperandMem>( |
601 CallTarget)) { | 600 CallTarget)) { |
602 assert(Mem->getSegmentRegister() == | 601 assert(Mem->getSegmentRegister() == |
603 InstX86Base<Machine>::Traits::X86OperandMem::DefaultSegment); | 602 InstX86Base<Machine>::Traits::X86OperandMem::DefaultSegment); |
604 Asm->call(Mem->toAsmAddress(Asm, Target)); | 603 Asm->call(Mem->toAsmAddress(Asm, Target)); |
605 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(CallTarget)) { | 604 } else if (const auto *CR = llvm::dyn_cast<ConstantRelocatable>(CallTarget)) { |
606 assert(CR->getOffset() == 0 && "We only support calling a function"); | 605 assert(CR->getOffset() == 0 && "We only support calling a function"); |
607 Asm->call(CR); | 606 Asm->call(CR); |
608 } else if (const auto *Imm = llvm::dyn_cast<ConstantInteger32>(CallTarget)) { | 607 } else if (const auto *Imm = llvm::dyn_cast<ConstantInteger32>(CallTarget)) { |
609 Asm->call(Immediate(Imm->getValue())); | 608 Asm->call(Immediate(Imm->getValue())); |
610 } else { | 609 } else { |
611 llvm_unreachable("Unexpected operand type"); | 610 llvm_unreachable("Unexpected operand type"); |
612 } | 611 } |
613 Target->resetStackAdjustment(); | |
614 } | 612 } |
615 | 613 |
616 template <class Machine> | 614 template <class Machine> |
617 void InstX86Call<Machine>::dump(const Cfg *Func) const { | 615 void InstX86Call<Machine>::dump(const Cfg *Func) const { |
618 if (!BuildDefs::dump()) | 616 if (!BuildDefs::dump()) |
619 return; | 617 return; |
620 Ostream &Str = Func->getContext()->getStrDump(); | 618 Ostream &Str = Func->getContext()->getStrDump(); |
621 if (this->getDest()) { | 619 if (this->getDest()) { |
622 this->dumpDest(Func); | 620 this->dumpDest(Func); |
623 Str << " = "; | 621 Str << " = "; |
(...skipping 2004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2628 Ostream &Str = Func->getContext()->getStrEmit(); | 2626 Ostream &Str = Func->getContext()->getStrEmit(); |
2629 assert(this->getSrcSize() == 0); | 2627 assert(this->getSrcSize() == 0); |
2630 // TODO(jvoung,stichnot): Utilize this by setting Dest to nullptr to | 2628 // TODO(jvoung,stichnot): Utilize this by setting Dest to nullptr to |
2631 // "partially" delete the fstp if the Dest is unused. Even if Dest is unused, | 2629 // "partially" delete the fstp if the Dest is unused. Even if Dest is unused, |
2632 // the fstp should be kept for the SideEffects of popping the stack. | 2630 // the fstp should be kept for the SideEffects of popping the stack. |
2633 if (!this->getDest()) { | 2631 if (!this->getDest()) { |
2634 Str << "\tfstp\tst(0)"; | 2632 Str << "\tfstp\tst(0)"; |
2635 return; | 2633 return; |
2636 } | 2634 } |
2637 Type Ty = this->getDest()->getType(); | 2635 Type Ty = this->getDest()->getType(); |
2638 size_t Width = typeWidthInBytes(Ty); | |
2639 if (!this->getDest()->hasReg()) { | 2636 if (!this->getDest()->hasReg()) { |
2640 Str << "\tfstp" << this->getFldString(Ty) << "\t"; | 2637 Str << "\tfstp" << this->getFldString(Ty) << "\t"; |
2641 this->getDest()->emit(Func); | 2638 this->getDest()->emit(Func); |
2642 return; | 2639 return; |
2643 } | 2640 } |
2644 // Dest is a physical (xmm) register, so st(0) needs to go through memory. | 2641 // Dest is a physical (xmm) register, so st(0) needs to go through memory. |
2645 // Hack this by creating a temporary stack slot, spilling st(0) there, | 2642 // Hack this by caller-reserved memory at the top of stack, spilling st(0) |
Jim Stichnoth
2015/11/13 23:30:33
by using
sehr
2015/11/14 00:30:56
Done.
| |
2646 // loading it into the xmm register, and deallocating the stack slot. | 2643 // there, and loading it into the xmm register. |
2647 Str << "\tsubl\t$" << Width << ", %esp\n"; | |
2648 Str << "\tfstp" << this->getFldString(Ty) << "\t" | 2644 Str << "\tfstp" << this->getFldString(Ty) << "\t" |
2649 << "(%esp)\n"; | 2645 << "(%esp)\n"; |
2650 Str << "\tmov" << InstX86Base<Machine>::Traits::TypeAttributes[Ty].SdSsString | 2646 Str << "\tmov" << InstX86Base<Machine>::Traits::TypeAttributes[Ty].SdSsString |
2651 << "\t" | 2647 << "\t" |
2652 << "(%esp), "; | 2648 << "(%esp), "; |
2653 this->getDest()->emit(Func); | 2649 this->getDest()->emit(Func); |
2654 Str << "\n"; | 2650 Str << "\n"; |
2655 Str << "\taddl\t$" << Width << ", %esp"; | |
2656 } | 2651 } |
2657 | 2652 |
2658 template <class Machine> | 2653 template <class Machine> |
2659 void InstX86Fstp<Machine>::emitIAS(const Cfg *Func) const { | 2654 void InstX86Fstp<Machine>::emitIAS(const Cfg *Func) const { |
2660 typename InstX86Base<Machine>::Traits::Assembler *Asm = | 2655 typename InstX86Base<Machine>::Traits::Assembler *Asm = |
2661 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); | 2656 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); |
2662 assert(this->getSrcSize() == 0); | 2657 assert(this->getSrcSize() == 0); |
2663 const Variable *Dest = this->getDest(); | 2658 const Variable *Dest = this->getDest(); |
2664 // TODO(jvoung,stichnot): Utilize this by setting Dest to nullptr to | 2659 // TODO(jvoung,stichnot): Utilize this by setting Dest to nullptr to |
2665 // "partially" delete the fstp if the Dest is unused. Even if Dest is unused, | 2660 // "partially" delete the fstp if the Dest is unused. Even if Dest is unused, |
2666 // the fstp should be kept for the SideEffects of popping the stack. | 2661 // the fstp should be kept for the SideEffects of popping the stack. |
2667 if (!Dest) { | 2662 if (!Dest) { |
2668 Asm->fstp(InstX86Base<Machine>::Traits::RegisterSet::getEncodedSTReg(0)); | 2663 Asm->fstp(InstX86Base<Machine>::Traits::RegisterSet::getEncodedSTReg(0)); |
2669 return; | 2664 return; |
2670 } | 2665 } |
2671 auto *Target = InstX86Base<Machine>::getTarget(Func); | 2666 auto *Target = InstX86Base<Machine>::getTarget(Func); |
2672 Type Ty = Dest->getType(); | 2667 Type Ty = Dest->getType(); |
2673 if (!Dest->hasReg()) { | 2668 if (!Dest->hasReg()) { |
2674 typename InstX86Base<Machine>::Traits::Address StackAddr( | 2669 typename InstX86Base<Machine>::Traits::Address StackAddr( |
2675 Target->stackVarToAsmOperand(Dest)); | 2670 Target->stackVarToAsmOperand(Dest)); |
2676 Asm->fstp(Ty, StackAddr); | 2671 Asm->fstp(Ty, StackAddr); |
2677 } else { | 2672 } else { |
2678 // Dest is a physical (xmm) register, so st(0) needs to go through memory. | 2673 // Dest is a physical (xmm) register, so st(0) needs to go through memory. |
2679 // Hack this by creating a temporary stack slot, spilling st(0) there, | 2674 // Hack this by using caller-reserved memory at the top of stack, spilling |
2680 // loading it into the xmm register, and deallocating the stack slot. | 2675 // st(0) there, and loading it into the xmm register. |
2681 Immediate Width(typeWidthInBytes(Ty)); | |
2682 Asm->sub(IceType_i32, | |
2683 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, Width); | |
2684 typename InstX86Base<Machine>::Traits::Address StackSlot = | 2676 typename InstX86Base<Machine>::Traits::Address StackSlot = |
2685 typename InstX86Base<Machine>::Traits::Address( | 2677 typename InstX86Base<Machine>::Traits::Address( |
2686 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, 0, | 2678 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, 0, |
2687 AssemblerFixup::NoFixup); | 2679 AssemblerFixup::NoFixup); |
2688 Asm->fstp(Ty, StackSlot); | 2680 Asm->fstp(Ty, StackSlot); |
2689 Asm->movss(Ty, | 2681 Asm->movss(Ty, |
2690 InstX86Base<Machine>::Traits::getEncodedXmm(Dest->getRegNum()), | 2682 InstX86Base<Machine>::Traits::getEncodedXmm(Dest->getRegNum()), |
2691 StackSlot); | 2683 StackSlot); |
2692 Asm->add(IceType_i32, | |
2693 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, Width); | |
2694 } | 2684 } |
2695 } | 2685 } |
2696 | 2686 |
2697 template <class Machine> | 2687 template <class Machine> |
2698 void InstX86Fstp<Machine>::dump(const Cfg *Func) const { | 2688 void InstX86Fstp<Machine>::dump(const Cfg *Func) const { |
2699 if (!BuildDefs::dump()) | 2689 if (!BuildDefs::dump()) |
2700 return; | 2690 return; |
2701 Ostream &Str = Func->getContext()->getStrDump(); | 2691 Ostream &Str = Func->getContext()->getStrDump(); |
2702 this->dumpDest(Func); | 2692 this->dumpDest(Func); |
2703 Str << " = fstp." << this->getDest()->getType() << ", st(0)"; | 2693 Str << " = fstp." << this->getDest()->getType() << ", st(0)"; |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2925 Ostream &Str = Func->getContext()->getStrDump(); | 2915 Ostream &Str = Func->getContext()->getStrDump(); |
2926 this->dumpDest(Func); | 2916 this->dumpDest(Func); |
2927 Str << " = pop." << this->getDest()->getType() << " "; | 2917 Str << " = pop." << this->getDest()->getType() << " "; |
2928 } | 2918 } |
2929 | 2919 |
2930 template <class Machine> | 2920 template <class Machine> |
2931 void InstX86AdjustStack<Machine>::emit(const Cfg *Func) const { | 2921 void InstX86AdjustStack<Machine>::emit(const Cfg *Func) const { |
2932 if (!BuildDefs::dump()) | 2922 if (!BuildDefs::dump()) |
2933 return; | 2923 return; |
2934 Ostream &Str = Func->getContext()->getStrEmit(); | 2924 Ostream &Str = Func->getContext()->getStrEmit(); |
2935 Str << "\tsubl\t$" << Amount << ", %esp"; | 2925 if (Amount > 0) |
2926 Str << "\tsubl\t$" << Amount << ", %esp"; | |
2927 else | |
2928 Str << "\taddl\t$" << -Amount << ", %esp"; | |
2936 auto *Target = InstX86Base<Machine>::getTarget(Func); | 2929 auto *Target = InstX86Base<Machine>::getTarget(Func); |
2937 Target->updateStackAdjustment(Amount); | 2930 Target->updateStackAdjustment(Amount); |
2938 } | 2931 } |
2939 | 2932 |
2940 template <class Machine> | 2933 template <class Machine> |
2941 void InstX86AdjustStack<Machine>::emitIAS(const Cfg *Func) const { | 2934 void InstX86AdjustStack<Machine>::emitIAS(const Cfg *Func) const { |
2942 typename InstX86Base<Machine>::Traits::Assembler *Asm = | 2935 typename InstX86Base<Machine>::Traits::Assembler *Asm = |
2943 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); | 2936 Func->getAssembler<typename InstX86Base<Machine>::Traits::Assembler>(); |
2944 Asm->sub(IceType_i32, | 2937 if (Amount > 0) |
2945 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, | 2938 Asm->sub(IceType_i32, |
2946 Immediate(Amount)); | 2939 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, |
2940 Immediate(Amount)); | |
2941 else | |
2942 Asm->add(IceType_i32, | |
2943 InstX86Base<Machine>::Traits::RegisterSet::Encoded_Reg_esp, | |
2944 Immediate(-Amount)); | |
2947 auto *Target = InstX86Base<Machine>::getTarget(Func); | 2945 auto *Target = InstX86Base<Machine>::getTarget(Func); |
2948 Target->updateStackAdjustment(Amount); | 2946 Target->updateStackAdjustment(Amount); |
2949 } | 2947 } |
2950 | 2948 |
2951 template <class Machine> | 2949 template <class Machine> |
2952 void InstX86AdjustStack<Machine>::dump(const Cfg *Func) const { | 2950 void InstX86AdjustStack<Machine>::dump(const Cfg *Func) const { |
2953 if (!BuildDefs::dump()) | 2951 if (!BuildDefs::dump()) |
2954 return; | 2952 return; |
2955 Ostream &Str = Func->getContext()->getStrDump(); | 2953 Ostream &Str = Func->getContext()->getStrDump(); |
2956 Str << "esp = sub.i32 esp, " << Amount; | 2954 if (Amount > 0) |
2955 Str << "esp = sub.i32 esp, " << Amount; | |
2956 else | |
2957 Str << "esp = add.i32 esp, " << -Amount; | |
2957 } | 2958 } |
2958 | 2959 |
2959 template <class Machine> | 2960 template <class Machine> |
2960 void InstX86Push<Machine>::emit(const Cfg *Func) const { | 2961 void InstX86Push<Machine>::emit(const Cfg *Func) const { |
2961 if (!BuildDefs::dump()) | 2962 if (!BuildDefs::dump()) |
2962 return; | 2963 return; |
2963 Ostream &Str = Func->getContext()->getStrEmit(); | 2964 Ostream &Str = Func->getContext()->getStrEmit(); |
2964 assert(this->getSrcSize() == 1); | 2965 assert(this->getSrcSize() == 1); |
2965 // Push is currently only used for saving GPRs. | 2966 // Push is currently only used for saving GPRs. |
2966 const auto *Var = llvm::cast<Variable>(this->getSrc(0)); | 2967 const auto *Var = llvm::cast<Variable>(this->getSrc(0)); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3244 return; | 3245 return; |
3245 Ostream &Str = Func->getContext()->getStrDump(); | 3246 Ostream &Str = Func->getContext()->getStrDump(); |
3246 Str << "IACA_END"; | 3247 Str << "IACA_END"; |
3247 } | 3248 } |
3248 | 3249 |
3249 } // end of namespace X86Internal | 3250 } // end of namespace X86Internal |
3250 | 3251 |
3251 } // end of namespace Ice | 3252 } // end of namespace Ice |
3252 | 3253 |
3253 #endif // SUBZERO_SRC_ICEINSTX86BASEIMPL_H | 3254 #endif // SUBZERO_SRC_ICEINSTX86BASEIMPL_H |
OLD | NEW |