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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 TargetX86Base() = delete; | 52 TargetX86Base() = delete; |
53 TargetX86Base(const TargetX86Base &) = delete; | 53 TargetX86Base(const TargetX86Base &) = delete; |
54 TargetX86Base &operator=(const TargetX86Base &) = delete; | 54 TargetX86Base &operator=(const TargetX86Base &) = delete; |
55 | 55 |
56 public: | 56 public: |
57 using Traits = MachineTraits<Machine>; | 57 using Traits = MachineTraits<Machine>; |
58 using BoolFolding = ::Ice::X86Internal::BoolFolding<Traits>; | 58 using BoolFolding = ::Ice::X86Internal::BoolFolding<Traits>; |
59 | 59 |
60 ~TargetX86Base() override = default; | 60 ~TargetX86Base() override = default; |
61 | 61 |
62 static void staticInit(); | 62 static void staticInit(const ClFlags &Flags); |
63 static TargetX86Base *create(Cfg *Func) { return new TargetX86Base(Func); } | 63 static TargetX86Base *create(Cfg *Func) { return new TargetX86Base(Func); } |
64 | 64 |
65 static FixupKind getPcRelFixup() { return PcRelFixup; } | |
66 static FixupKind getRelFixup() { return RelFixup; } | |
67 | |
65 void translateOm1() override; | 68 void translateOm1() override; |
66 void translateO2() override; | 69 void translateO2() override; |
67 void doLoadOpt(); | 70 void doLoadOpt(); |
68 bool doBranchOpt(Inst *I, const CfgNode *NextNode) override; | 71 bool doBranchOpt(Inst *I, const CfgNode *NextNode) override; |
69 | 72 |
70 SizeT getNumRegisters() const override { | 73 SizeT getNumRegisters() const override { |
71 return Traits::RegisterSet::Reg_NUM; | 74 return Traits::RegisterSet::Reg_NUM; |
72 } | 75 } |
73 Variable *getPhysicalRegister(SizeT RegNum, Type Ty = IceType_void) override; | 76 Variable *getPhysicalRegister(SizeT RegNum, Type Ty = IceType_void) override; |
74 IceString getRegName(SizeT RegNum, Type Ty) const override; | 77 IceString getRegName(SizeT RegNum, Type Ty) const override; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 } | 122 } |
120 | 123 |
121 bool shouldSplitToVariable64On32(Type Ty) const override { | 124 bool shouldSplitToVariable64On32(Type Ty) const override { |
122 return Traits::Is64Bit ? false : Ty == IceType_i64; | 125 return Traits::Is64Bit ? false : Ty == IceType_i64; |
123 } | 126 } |
124 | 127 |
125 SizeT getMinJumpTableSize() const override { return 4; } | 128 SizeT getMinJumpTableSize() const override { return 4; } |
126 | 129 |
127 void emitVariable(const Variable *Var) const override; | 130 void emitVariable(const Variable *Var) const override; |
128 | 131 |
129 const char *getConstantPrefix() const final { return "$"; } | |
130 void emit(const ConstantUndef *C) const final; | |
131 void emit(const ConstantInteger32 *C) const final; | 132 void emit(const ConstantInteger32 *C) const final; |
132 void emit(const ConstantInteger64 *C) const final; | 133 void emit(const ConstantInteger64 *C) const final; |
133 void emit(const ConstantFloat *C) const final; | 134 void emit(const ConstantFloat *C) const final; |
134 void emit(const ConstantDouble *C) const final; | 135 void emit(const ConstantDouble *C) const final; |
136 void emit(const ConstantUndef *C) const final; | |
137 void emit(const ConstantRelocatable *C) const final; | |
135 | 138 |
136 void initNodeForLowering(CfgNode *Node) override; | 139 void initNodeForLowering(CfgNode *Node) override; |
137 | 140 |
138 template <typename T = Traits> | 141 template <typename T = Traits> |
139 typename std::enable_if<!T::Is64Bit, Operand>::type * | 142 typename std::enable_if<!T::Is64Bit, Operand>::type * |
140 loOperand(Operand *Operand); | 143 loOperand(Operand *Operand); |
141 template <typename T = Traits> | 144 template <typename T = Traits> |
142 typename std::enable_if<T::Is64Bit, Operand>::type *loOperand(Operand *) { | 145 typename std::enable_if<T::Is64Bit, Operand>::type *loOperand(Operand *) { |
143 llvm::report_fatal_error( | 146 llvm::report_fatal_error( |
144 "Hey, yo! This is x86-64. Watcha doin'? (loOperand)"); | 147 "Hey, yo! This is x86-64. Watcha doin'? (loOperand)"); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 /// that the Operand kind is one of those indicated by the LegalMask (a | 261 /// that the Operand kind is one of those indicated by the LegalMask (a |
259 /// bitmask of allowed kinds). If the input Operand is known to already meet | 262 /// bitmask of allowed kinds). If the input Operand is known to already meet |
260 /// the constraints, it may be simply returned as the result, without creating | 263 /// the constraints, it may be simply returned as the result, without creating |
261 /// any new instructions or operands. | 264 /// any new instructions or operands. |
262 enum OperandLegalization { | 265 enum OperandLegalization { |
263 Legal_None = 0, | 266 Legal_None = 0, |
264 Legal_Reg = 1 << 0, // physical register, not stack location | 267 Legal_Reg = 1 << 0, // physical register, not stack location |
265 Legal_Imm = 1 << 1, | 268 Legal_Imm = 1 << 1, |
266 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] | 269 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] |
267 Legal_Rematerializable = 1 << 3, | 270 Legal_Rematerializable = 1 << 3, |
268 Legal_All = ~Legal_Rematerializable | 271 Legal_AddrAbs = 1 << 4, // ConstantRelocatable doesn't have to add GotVar |
272 Legal_Default = ~(Legal_Rematerializable | Legal_AddrAbs) | |
273 // TODO(stichnot): Figure out whether this default works for x86-64. | |
269 }; | 274 }; |
270 using LegalMask = uint32_t; | 275 using LegalMask = uint32_t; |
271 Operand *legalize(Operand *From, LegalMask Allowed = Legal_All, | 276 Operand *legalize(Operand *From, LegalMask Allowed = Legal_Default, |
272 int32_t RegNum = Variable::NoRegister); | 277 int32_t RegNum = Variable::NoRegister); |
273 Variable *legalizeToReg(Operand *From, int32_t RegNum = Variable::NoRegister); | 278 Variable *legalizeToReg(Operand *From, int32_t RegNum = Variable::NoRegister); |
274 /// Legalize the first source operand for use in the cmp instruction. | 279 /// Legalize the first source operand for use in the cmp instruction. |
275 Operand *legalizeSrc0ForCmp(Operand *Src0, Operand *Src1); | 280 Operand *legalizeSrc0ForCmp(Operand *Src0, Operand *Src1); |
276 /// Turn a pointer operand into a memory operand that can be used by a real | 281 /// Turn a pointer operand into a memory operand that can be used by a real |
277 /// load/store operation. Legalizes the operand as well. This is a nop if the | 282 /// load/store operation. Legalizes the operand as well. This is a nop if the |
278 /// operand is already a legal memory operand. | 283 /// operand is already a legal memory operand. |
279 typename Traits::X86OperandMem *formMemoryOperand(Operand *Ptr, Type Ty, | 284 typename Traits::X86OperandMem *formMemoryOperand(Operand *Ptr, Type Ty, |
280 bool DoLegalize = true); | 285 bool DoLegalize = true); |
281 | 286 |
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
724 size_t FixedAllocaSizeBytes = 0; | 729 size_t FixedAllocaSizeBytes = 0; |
725 size_t FixedAllocaAlignBytes = 0; | 730 size_t FixedAllocaAlignBytes = 0; |
726 bool PrologEmitsFixedAllocas = false; | 731 bool PrologEmitsFixedAllocas = false; |
727 uint32_t MaxOutArgsSizeBytes = 0; | 732 uint32_t MaxOutArgsSizeBytes = 0; |
728 static std::array<llvm::SmallBitVector, RCX86_NUM> TypeToRegisterSet; | 733 static std::array<llvm::SmallBitVector, RCX86_NUM> TypeToRegisterSet; |
729 static std::array<llvm::SmallBitVector, Traits::RegisterSet::Reg_NUM> | 734 static std::array<llvm::SmallBitVector, Traits::RegisterSet::Reg_NUM> |
730 RegisterAliases; | 735 RegisterAliases; |
731 static llvm::SmallBitVector ScratchRegs; | 736 static llvm::SmallBitVector ScratchRegs; |
732 llvm::SmallBitVector RegsUsed; | 737 llvm::SmallBitVector RegsUsed; |
733 std::array<VarList, IceType_NUM> PhysicalRegisters; | 738 std::array<VarList, IceType_NUM> PhysicalRegisters; |
739 // GotVar is a Variable that holds the GlobalOffsetTable address for Non-SFI | |
740 // mode. | |
741 Variable *GotVar = nullptr; | |
734 | 742 |
735 /// Randomize a given immediate operand | 743 /// Randomize a given immediate operand |
736 Operand *randomizeOrPoolImmediate(Constant *Immediate, | 744 Operand *randomizeOrPoolImmediate(Constant *Immediate, |
737 int32_t RegNum = Variable::NoRegister); | 745 int32_t RegNum = Variable::NoRegister); |
738 typename Traits::X86OperandMem * | 746 typename Traits::X86OperandMem * |
739 randomizeOrPoolImmediate(typename Traits::X86OperandMem *MemOperand, | 747 randomizeOrPoolImmediate(typename Traits::X86OperandMem *MemOperand, |
740 int32_t RegNum = Variable::NoRegister); | 748 int32_t RegNum = Variable::NoRegister); |
741 bool RandomizationPoolingPaused = false; | 749 bool RandomizationPoolingPaused = false; |
742 | 750 |
743 private: | 751 private: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
790 void lowerSelectMove(Variable *Dest, typename Traits::Cond::BrCond Cond, | 798 void lowerSelectMove(Variable *Dest, typename Traits::Cond::BrCond Cond, |
791 Operand *SrcT, Operand *SrcF); | 799 Operand *SrcT, Operand *SrcF); |
792 void lowerSelectIntMove(Variable *Dest, typename Traits::Cond::BrCond Cond, | 800 void lowerSelectIntMove(Variable *Dest, typename Traits::Cond::BrCond Cond, |
793 Operand *SrcT, Operand *SrcF); | 801 Operand *SrcT, Operand *SrcF); |
794 /// Generic helper to move an arbitrary type from Src to Dest. | 802 /// Generic helper to move an arbitrary type from Src to Dest. |
795 void lowerMove(Variable *Dest, Operand *Src, bool IsRedefinition); | 803 void lowerMove(Variable *Dest, Operand *Src, bool IsRedefinition); |
796 | 804 |
797 /// Optimizations for idiom recognition. | 805 /// Optimizations for idiom recognition. |
798 bool lowerOptimizeFcmpSelect(const InstFcmp *Fcmp, const InstSelect *Select); | 806 bool lowerOptimizeFcmpSelect(const InstFcmp *Fcmp, const InstSelect *Select); |
799 | 807 |
808 /// Emit code that initializes the value of the GotVar near the start of the | |
809 /// function. | |
810 void initGotVar(); | |
811 | |
800 /// Complains loudly if invoked because the cpu can handle 64-bit types | 812 /// Complains loudly if invoked because the cpu can handle 64-bit types |
801 /// natively. | 813 /// natively. |
802 template <typename T = Traits> | 814 template <typename T = Traits> |
803 typename std::enable_if<T::Is64Bit, void>::type lowerIcmp64(const InstIcmp *, | 815 typename std::enable_if<T::Is64Bit, void>::type lowerIcmp64(const InstIcmp *, |
804 const Inst *) { | 816 const Inst *) { |
805 llvm::report_fatal_error( | 817 llvm::report_fatal_error( |
806 "Hey, yo! This is x86-64. Watcha doin'? (lowerIcmp64)"); | 818 "Hey, yo! This is x86-64. Watcha doin'? (lowerIcmp64)"); |
807 } | 819 } |
808 /// x86lowerIcmp64 handles 64-bit icmp lowering. | 820 /// x86lowerIcmp64 handles 64-bit icmp lowering. |
809 template <typename T = Traits> | 821 template <typename T = Traits> |
810 typename std::enable_if<!T::Is64Bit, void>::type | 822 typename std::enable_if<!T::Is64Bit, void>::type |
811 lowerIcmp64(const InstIcmp *Icmp, const Inst *Consumer); | 823 lowerIcmp64(const InstIcmp *Icmp, const Inst *Consumer); |
812 | 824 |
813 BoolFolding FoldingInfo; | 825 BoolFolding FoldingInfo; |
826 | |
827 static FixupKind PcRelFixup; | |
John
2015/12/22 15:44:38
This **really** belong in the Traits classes...
Jim Stichnoth
2015/12/28 07:54:07
The issue here is that the fixup kind used for Rel
| |
828 static FixupKind RelFixup; | |
814 }; | 829 }; |
815 } // end of namespace X86Internal | 830 } // end of namespace X86Internal |
816 } // end of namespace Ice | 831 } // end of namespace Ice |
817 | 832 |
818 #include "IceTargetLoweringX86BaseImpl.h" | 833 #include "IceTargetLoweringX86BaseImpl.h" |
819 | 834 |
820 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H | 835 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H |
OLD | NEW |