OLD | NEW |
1 //===- subzero/src/IceTargetLoweringX86Base.h - x86 lowering ----*- C++ -*-===// | 1 //===- subzero/src/IceTargetLoweringX86Base.h - x86 lowering ----*- 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 213 } |
214 | 214 |
215 void addProlog(CfgNode *Node) override; | 215 void addProlog(CfgNode *Node) override; |
216 void finishArgumentLowering(Variable *Arg, Variable *FramePtr, | 216 void finishArgumentLowering(Variable *Arg, Variable *FramePtr, |
217 size_t BasicFrameOffset, size_t StackAdjBytes, | 217 size_t BasicFrameOffset, size_t StackAdjBytes, |
218 size_t &InArgsSizeBytes); | 218 size_t &InArgsSizeBytes); |
219 void addEpilog(CfgNode *Node) override; | 219 void addEpilog(CfgNode *Node) override; |
220 X86Address stackVarToAsmOperand(const Variable *Var) const; | 220 X86Address stackVarToAsmOperand(const Variable *Var) const; |
221 | 221 |
222 InstructionSetEnum getInstructionSet() const { return InstructionSet; } | 222 InstructionSetEnum getInstructionSet() const { return InstructionSet; } |
223 Operand *legalizeUndef(Operand *From, RegNumT RegNum = RegNumT::NoRegister); | 223 Operand *legalizeUndef(Operand *From, RegNumT RegNum = RegNumT()); |
224 | 224 |
225 protected: | 225 protected: |
226 const bool NeedSandboxing; | 226 const bool NeedSandboxing; |
227 | 227 |
228 explicit TargetX86Base(Cfg *Func); | 228 explicit TargetX86Base(Cfg *Func); |
229 | 229 |
230 void postLower() override; | 230 void postLower() override; |
231 | 231 |
232 /// Initializes the RebasePtr member variable -- if so required by | 232 /// Initializes the RebasePtr member variable -- if so required by |
233 /// SandboxingType for the concrete Target. | 233 /// SandboxingType for the concrete Target. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 Legal_Reg = 1 << 0, // physical register, not stack location | 382 Legal_Reg = 1 << 0, // physical register, not stack location |
383 Legal_Imm = 1 << 1, | 383 Legal_Imm = 1 << 1, |
384 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] | 384 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] |
385 Legal_Rematerializable = 1 << 3, | 385 Legal_Rematerializable = 1 << 3, |
386 Legal_AddrAbs = 1 << 4, // ConstantRelocatable doesn't have to add RebasePtr | 386 Legal_AddrAbs = 1 << 4, // ConstantRelocatable doesn't have to add RebasePtr |
387 Legal_Default = ~(Legal_Rematerializable | Legal_AddrAbs) | 387 Legal_Default = ~(Legal_Rematerializable | Legal_AddrAbs) |
388 // TODO(stichnot): Figure out whether this default works for x86-64. | 388 // TODO(stichnot): Figure out whether this default works for x86-64. |
389 }; | 389 }; |
390 using LegalMask = uint32_t; | 390 using LegalMask = uint32_t; |
391 Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default, | 391 Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default, |
392 RegNumT RegNum = RegNumT::NoRegister); | 392 RegNumT RegNum = RegNumT()); |
393 Variable *legalizeToReg(Operand *From, RegNumT RegNum = RegNumT::NoRegister); | 393 Variable *legalizeToReg(Operand *From, RegNumT RegNum = RegNumT()); |
394 /// Legalize the first source operand for use in the cmp instruction. | 394 /// Legalize the first source operand for use in the cmp instruction. |
395 Operand *legalizeSrc0ForCmp(Operand *Src0, Operand *Src1); | 395 Operand *legalizeSrc0ForCmp(Operand *Src0, Operand *Src1); |
396 /// Turn a pointer operand into a memory operand that can be used by a real | 396 /// Turn a pointer operand into a memory operand that can be used by a real |
397 /// load/store operation. Legalizes the operand as well. This is a nop if the | 397 /// load/store operation. Legalizes the operand as well. This is a nop if the |
398 /// operand is already a legal memory operand. | 398 /// operand is already a legal memory operand. |
399 X86OperandMem *formMemoryOperand(Operand *Ptr, Type Ty, | 399 X86OperandMem *formMemoryOperand(Operand *Ptr, Type Ty, |
400 bool DoLegalize = true); | 400 bool DoLegalize = true); |
401 | 401 |
402 Variable *makeReg(Type Ty, RegNumT RegNum = RegNumT::NoRegister); | 402 Variable *makeReg(Type Ty, RegNumT RegNum = RegNumT()); |
403 static Type stackSlotType(); | 403 static Type stackSlotType(); |
404 | 404 |
405 static constexpr uint32_t NoSizeLimit = 0; | 405 static constexpr uint32_t NoSizeLimit = 0; |
406 static const Type TypeForSize[]; | 406 static const Type TypeForSize[]; |
407 /// Returns the largest type which is equal to or larger than Size bytes. The | 407 /// Returns the largest type which is equal to or larger than Size bytes. The |
408 /// type is suitable for copying memory i.e. a load and store will be a single | 408 /// type is suitable for copying memory i.e. a load and store will be a single |
409 /// instruction (for example x86 will get f64 not i64). | 409 /// instruction (for example x86 will get f64 not i64). |
410 static Type largestTypeInSize(uint32_t Size, uint32_t MaxSize = NoSizeLimit); | 410 static Type largestTypeInSize(uint32_t Size, uint32_t MaxSize = NoSizeLimit); |
411 /// Returns the smallest type which is equal to or larger than Size bytes. If | 411 /// Returns the smallest type which is equal to or larger than Size bytes. If |
412 /// one doesn't exist then the largest type smaller than Size bytes is | 412 /// one doesn't exist then the largest type smaller than Size bytes is |
413 /// returned. The type is suitable for memory copies as described at | 413 /// returned. The type is suitable for memory copies as described at |
414 /// largestTypeInSize. | 414 /// largestTypeInSize. |
415 static Type firstTypeThatFitsSize(uint32_t Size, | 415 static Type firstTypeThatFitsSize(uint32_t Size, |
416 uint32_t MaxSize = NoSizeLimit); | 416 uint32_t MaxSize = NoSizeLimit); |
417 | 417 |
418 Variable *copyToReg8(Operand *Src, RegNumT RegNum = RegNumT::NoRegister); | 418 Variable *copyToReg8(Operand *Src, RegNumT RegNum = RegNumT()); |
419 Variable *copyToReg(Operand *Src, RegNumT RegNum = RegNumT::NoRegister); | 419 Variable *copyToReg(Operand *Src, RegNumT RegNum = RegNumT()); |
420 | 420 |
421 /// Returns a register containing all zeros, without affecting the FLAGS | 421 /// Returns a register containing all zeros, without affecting the FLAGS |
422 /// register, using the best instruction for the type. | 422 /// register, using the best instruction for the type. |
423 Variable *makeZeroedRegister(Type Ty, RegNumT RegNum = RegNumT::NoRegister); | 423 Variable *makeZeroedRegister(Type Ty, RegNumT RegNum = RegNumT()); |
424 | 424 |
425 /// \name Returns a vector in a register with the given constant entries. | 425 /// \name Returns a vector in a register with the given constant entries. |
426 /// @{ | 426 /// @{ |
427 Variable *makeVectorOfZeros(Type Ty, RegNumT RegNum = RegNumT::NoRegister); | 427 Variable *makeVectorOfZeros(Type Ty, RegNumT RegNum = RegNumT()); |
428 Variable *makeVectorOfOnes(Type Ty, RegNumT RegNum = RegNumT::NoRegister); | 428 Variable *makeVectorOfOnes(Type Ty, RegNumT RegNum = RegNumT()); |
429 Variable *makeVectorOfMinusOnes(Type Ty, | 429 Variable *makeVectorOfMinusOnes(Type Ty, RegNumT RegNum = RegNumT()); |
430 RegNumT RegNum = RegNumT::NoRegister); | 430 Variable *makeVectorOfHighOrderBits(Type Ty, RegNumT RegNum = RegNumT()); |
431 Variable *makeVectorOfHighOrderBits(Type Ty, | 431 Variable *makeVectorOfFabsMask(Type Ty, RegNumT RegNum = RegNumT()); |
432 RegNumT RegNum = RegNumT::NoRegister); | |
433 Variable *makeVectorOfFabsMask(Type Ty, RegNumT RegNum = RegNumT::NoRegister); | |
434 /// @} | 432 /// @} |
435 | 433 |
436 /// Return a memory operand corresponding to a stack allocated Variable. | 434 /// Return a memory operand corresponding to a stack allocated Variable. |
437 X86OperandMem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot, | 435 X86OperandMem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot, |
438 uint32_t Offset = 0); | 436 uint32_t Offset = 0); |
439 | 437 |
440 void | 438 void |
441 makeRandomRegisterPermutation(llvm::SmallVectorImpl<RegNumT> &Permutation, | 439 makeRandomRegisterPermutation(llvm::SmallVectorImpl<RegNumT> &Permutation, |
442 const llvm::SmallBitVector &ExcludeRegisters, | 440 const llvm::SmallBitVector &ExcludeRegisters, |
443 uint64_t Salt) const override; | 441 uint64_t Salt) const override; |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 /// Moves can be used to redefine registers, creating "partial kills" for | 667 /// Moves can be used to redefine registers, creating "partial kills" for |
670 /// liveness. Mark where moves are used in this way. | 668 /// liveness. Mark where moves are used in this way. |
671 void _redefined(Inst *MovInst, bool IsRedefinition = true) { | 669 void _redefined(Inst *MovInst, bool IsRedefinition = true) { |
672 if (IsRedefinition) | 670 if (IsRedefinition) |
673 MovInst->setDestRedefined(); | 671 MovInst->setDestRedefined(); |
674 } | 672 } |
675 /// If Dest=nullptr is passed in, then a new variable is created, marked as | 673 /// If Dest=nullptr is passed in, then a new variable is created, marked as |
676 /// infinite register allocation weight, and returned through the in/out Dest | 674 /// infinite register allocation weight, and returned through the in/out Dest |
677 /// argument. | 675 /// argument. |
678 typename Traits::Insts::Mov *_mov(Variable *&Dest, Operand *Src0, | 676 typename Traits::Insts::Mov *_mov(Variable *&Dest, Operand *Src0, |
679 RegNumT RegNum = RegNumT::NoRegister) { | 677 RegNumT RegNum = RegNumT()) { |
680 if (Dest == nullptr) | 678 if (Dest == nullptr) |
681 Dest = makeReg(Src0->getType(), RegNum); | 679 Dest = makeReg(Src0->getType(), RegNum); |
682 AutoMemorySandboxer<> _(this, &Dest, &Src0); | 680 AutoMemorySandboxer<> _(this, &Dest, &Src0); |
683 return Context.insert<typename Traits::Insts::Mov>(Dest, Src0); | 681 return Context.insert<typename Traits::Insts::Mov>(Dest, Src0); |
684 } | 682 } |
685 void _mov_sp(Operand *NewValue) { | 683 void _mov_sp(Operand *NewValue) { |
686 dispatchToConcrete(&Traits::ConcreteTarget::_mov_sp, std::move(NewValue)); | 684 dispatchToConcrete(&Traits::ConcreteTarget::_mov_sp, std::move(NewValue)); |
687 } | 685 } |
688 typename Traits::Insts::Movp *_movp(Variable *Dest, Operand *Src0) { | 686 typename Traits::Insts::Movp *_movp(Variable *Dest, Operand *Src0) { |
689 AutoMemorySandboxer<> _(this, &Dest, &Src0); | 687 AutoMemorySandboxer<> _(this, &Dest, &Src0); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 static std::array<llvm::SmallBitVector, Traits::RegisterSet::Reg_NUM> | 991 static std::array<llvm::SmallBitVector, Traits::RegisterSet::Reg_NUM> |
994 RegisterAliases; | 992 RegisterAliases; |
995 llvm::SmallBitVector RegsUsed; | 993 llvm::SmallBitVector RegsUsed; |
996 std::array<VarList, IceType_NUM> PhysicalRegisters; | 994 std::array<VarList, IceType_NUM> PhysicalRegisters; |
997 // RebasePtr is a Variable that holds the Rebasing pointer (if any) for the | 995 // RebasePtr is a Variable that holds the Rebasing pointer (if any) for the |
998 // current sandboxing type. | 996 // current sandboxing type. |
999 Variable *RebasePtr = nullptr; | 997 Variable *RebasePtr = nullptr; |
1000 | 998 |
1001 /// Randomize a given immediate operand | 999 /// Randomize a given immediate operand |
1002 Operand *randomizeOrPoolImmediate(Constant *Immediate, | 1000 Operand *randomizeOrPoolImmediate(Constant *Immediate, |
1003 RegNumT RegNum = RegNumT::NoRegister); | 1001 RegNumT RegNum = RegNumT()); |
1004 X86OperandMem *randomizeOrPoolImmediate(X86OperandMem *MemOperand, | 1002 X86OperandMem *randomizeOrPoolImmediate(X86OperandMem *MemOperand, |
1005 RegNumT RegNum = RegNumT::NoRegister); | 1003 RegNumT RegNum = RegNumT()); |
1006 bool RandomizationPoolingPaused = false; | 1004 bool RandomizationPoolingPaused = false; |
1007 | 1005 |
1008 private: | 1006 private: |
1009 /// dispatchToConcrete is the template voodoo that allows TargetX86Base to | 1007 /// dispatchToConcrete is the template voodoo that allows TargetX86Base to |
1010 /// invoke methods in Machine (which inherits from TargetX86Base) without | 1008 /// invoke methods in Machine (which inherits from TargetX86Base) without |
1011 /// having to rely on virtual method calls. There are two overloads, one for | 1009 /// having to rely on virtual method calls. There are two overloads, one for |
1012 /// non-void types, and one for void types. We need this becase, for non-void | 1010 /// non-void types, and one for void types. We need this becase, for non-void |
1013 /// types, we need to return the method result, where as for void, we don't. | 1011 /// types, we need to return the method result, where as for void, we don't. |
1014 /// While it is true that the code compiles without the void "version", there | 1012 /// While it is true that the code compiles without the void "version", there |
1015 /// used to be a time when compilers would reject such code. | 1013 /// used to be a time when compilers would reject such code. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 | 1123 |
1126 explicit TargetHeaderX86(GlobalContext *Ctx) : TargetHeaderLowering(Ctx) {} | 1124 explicit TargetHeaderX86(GlobalContext *Ctx) : TargetHeaderLowering(Ctx) {} |
1127 }; | 1125 }; |
1128 | 1126 |
1129 } // end of namespace X86NAMESPACE | 1127 } // end of namespace X86NAMESPACE |
1130 } // end of namespace Ice | 1128 } // end of namespace Ice |
1131 | 1129 |
1132 #include "IceTargetLoweringX86BaseImpl.h" | 1130 #include "IceTargetLoweringX86BaseImpl.h" |
1133 | 1131 |
1134 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H | 1132 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H |
OLD | NEW |