| 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 |
| 11 /// This file declares the TargetLoweringX86 template class, which | 11 /// This file declares the TargetLoweringX86 template class, which |
| 12 /// implements the TargetLowering base interface for the x86 | 12 /// implements the TargetLowering base interface for the x86 |
| 13 /// architecture. | 13 /// architecture. |
| 14 /// | 14 /// |
| 15 //===----------------------------------------------------------------------===// | 15 //===----------------------------------------------------------------------===// |
| 16 | 16 |
| 17 #ifndef SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H | 17 #ifndef SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H |
| 18 #define SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H | 18 #define SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H |
| 19 | 19 |
| 20 #include "IceDefs.h" | 20 #include "IceDefs.h" |
| 21 #include "IceInst.h" | 21 #include "IceInst.h" |
| 22 #include "IceSwitchLowering.h" | 22 #include "IceSwitchLowering.h" |
| 23 #include "IceTargetLowering.h" | 23 #include "IceTargetLowering.h" |
| 24 #include "IceUtils.h" |
| 24 | 25 |
| 25 #include <type_traits> | 26 #include <type_traits> |
| 26 #include <unordered_map> | 27 #include <unordered_map> |
| 27 #include <utility> | 28 #include <utility> |
| 28 | 29 |
| 29 namespace Ice { | 30 namespace Ice { |
| 30 namespace X86Internal { | 31 namespace X86Internal { |
| 31 | 32 |
| 32 template <class MachineTraits> class BoolFolding; | 33 template <class MachineTraits> class BoolFolding; |
| 33 | 34 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 RegSetMask Exclude) const override; | 75 RegSetMask Exclude) const override; |
| 75 const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const override { | 76 const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const override { |
| 76 return TypeToRegisterSet[Ty]; | 77 return TypeToRegisterSet[Ty]; |
| 77 } | 78 } |
| 78 bool hasFramePointer() const override { return IsEbpBasedFrame; } | 79 bool hasFramePointer() const override { return IsEbpBasedFrame; } |
| 79 SizeT getFrameOrStackReg() const override { | 80 SizeT getFrameOrStackReg() const override { |
| 80 return IsEbpBasedFrame ? Traits::RegisterSet::Reg_ebp | 81 return IsEbpBasedFrame ? Traits::RegisterSet::Reg_ebp |
| 81 : Traits::RegisterSet::Reg_esp; | 82 : Traits::RegisterSet::Reg_esp; |
| 82 } | 83 } |
| 83 size_t typeWidthInBytesOnStack(Type Ty) const override { | 84 size_t typeWidthInBytesOnStack(Type Ty) const override { |
| 84 // Round up to the next multiple of 4 bytes. In particular, i1, | 85 // Round up to the next multiple of WordType bytes. |
| 85 // i8, and i16 are rounded up to 4 bytes. | 86 const uint32_t WordSizeInBytes = typeWidthInBytes(Traits::WordType); |
| 86 // TODO(jpp): this needs to round to multiples of 8 bytes in x86-64. | 87 return Utils::applyAlignment(typeWidthInBytes(Ty), WordSizeInBytes); |
| 87 return (typeWidthInBytes(Ty) + 3) & ~3; | |
| 88 } | 88 } |
| 89 | 89 |
| 90 SizeT getMinJumpTableSize() const override { return 4; } | 90 SizeT getMinJumpTableSize() const override { return 4; } |
| 91 | 91 |
| 92 void emitVariable(const Variable *Var) const override; | 92 void emitVariable(const Variable *Var) const override; |
| 93 | 93 |
| 94 const char *getConstantPrefix() const final { return "$"; } | 94 const char *getConstantPrefix() const final { return "$"; } |
| 95 void emit(const ConstantUndef *C) const final; | 95 void emit(const ConstantUndef *C) const final; |
| 96 void emit(const ConstantInteger32 *C) const final; | 96 void emit(const ConstantInteger32 *C) const final; |
| 97 void emit(const ConstantInteger64 *C) const final; | 97 void emit(const ConstantInteger64 *C) const final; |
| 98 void emit(const ConstantFloat *C) const final; | 98 void emit(const ConstantFloat *C) const final; |
| 99 void emit(const ConstantDouble *C) const final; | 99 void emit(const ConstantDouble *C) const final; |
| 100 | 100 |
| 101 void initNodeForLowering(CfgNode *Node) override; | 101 void initNodeForLowering(CfgNode *Node) override; |
| 102 /// Ensure that a 64-bit Variable has been split into 2 32-bit | 102 /// x86-32: Ensure that a 64-bit Variable has been split into 2 32-bit |
| 103 /// Variables, creating them if necessary. This is needed for all | 103 /// Variables, creating them if necessary. This is needed for all |
| 104 /// I64 operations, and it is needed for pushing F64 arguments for | 104 /// I64 operations, and it is needed for pushing F64 arguments for |
| 105 /// function calls using the 32-bit push instruction (though the | 105 /// function calls using the 32-bit push instruction (though the |
| 106 /// latter could be done by directly writing to the stack). | 106 /// latter could be done by directly writing to the stack). |
| 107 void split64(Variable *Var); | 107 /// |
| 108 Operand *loOperand(Operand *Operand); | 108 /// x86-64: Complains loudly if invoked because the cpu can handle |
| 109 Operand *hiOperand(Operand *Operand); | 109 /// 64-bit types natively. |
| 110 template <typename T = Traits> |
| 111 typename std::enable_if<!T::Is64Bit, void>::type split64(Variable *Var); |
| 112 template <typename T = Traits> |
| 113 typename std::enable_if<T::Is64Bit, void>::type split64(Variable *) { |
| 114 llvm::report_fatal_error( |
| 115 "Hey, yo! This is x86-64. Watcha doin'? (split64)"); |
| 116 } |
| 117 |
| 118 template <typename T = Traits> |
| 119 typename std::enable_if<!T::Is64Bit, Operand>::type * |
| 120 loOperand(Operand *Operand); |
| 121 template <typename T = Traits> |
| 122 typename std::enable_if<T::Is64Bit, Operand>::type *loOperand(Operand *) { |
| 123 llvm::report_fatal_error( |
| 124 "Hey, yo! This is x86-64. Watcha doin'? (loOperand)"); |
| 125 } |
| 126 |
| 127 template <typename T = Traits> |
| 128 typename std::enable_if<!T::Is64Bit, Operand>::type * |
| 129 hiOperand(Operand *Operand); |
| 130 template <typename T = Traits> |
| 131 typename std::enable_if<T::Is64Bit, Operand>::type *hiOperand(Operand *) { |
| 132 llvm::report_fatal_error( |
| 133 "Hey, yo! This is x86-64. Watcha doin'? (hiOperand)"); |
| 134 } |
| 135 |
| 110 void finishArgumentLowering(Variable *Arg, Variable *FramePtr, | 136 void finishArgumentLowering(Variable *Arg, Variable *FramePtr, |
| 111 size_t BasicFrameOffset, size_t &InArgsSizeBytes); | 137 size_t BasicFrameOffset, size_t &InArgsSizeBytes); |
| 112 typename Traits::Address stackVarToAsmOperand(const Variable *Var) const; | 138 typename Traits::Address stackVarToAsmOperand(const Variable *Var) const; |
| 113 | 139 |
| 114 typename Traits::InstructionSet getInstructionSet() const { | 140 typename Traits::InstructionSet getInstructionSet() const { |
| 115 return InstructionSet; | 141 return InstructionSet; |
| 116 } | 142 } |
| 117 Operand *legalizeUndef(Operand *From, int32_t RegNum = Variable::NoRegister); | 143 Operand *legalizeUndef(Operand *From, int32_t RegNum = Variable::NoRegister); |
| 118 | 144 |
| 119 protected: | 145 protected: |
| 120 explicit TargetX86Base(Cfg *Func); | 146 explicit TargetX86Base(Cfg *Func); |
| 121 | 147 |
| 122 void postLower() override; | 148 void postLower() override; |
| 123 | 149 |
| 124 void lowerAlloca(const InstAlloca *Inst) override; | 150 void lowerAlloca(const InstAlloca *Inst) override; |
| 125 void lowerArithmetic(const InstArithmetic *Inst) override; | 151 void lowerArithmetic(const InstArithmetic *Inst) override; |
| 126 void lowerAssign(const InstAssign *Inst) override; | 152 void lowerAssign(const InstAssign *Inst) override; |
| 127 void lowerBr(const InstBr *Inst) override; | 153 void lowerBr(const InstBr *Inst) override; |
| 128 void lowerCast(const InstCast *Inst) override; | 154 void lowerCast(const InstCast *Inst) override; |
| 129 void lowerExtractElement(const InstExtractElement *Inst) override; | 155 void lowerExtractElement(const InstExtractElement *Inst) override; |
| 130 void lowerFcmp(const InstFcmp *Inst) override; | 156 void lowerFcmp(const InstFcmp *Inst) override; |
| 131 void lowerIcmp(const InstIcmp *Inst) override; | 157 void lowerIcmp(const InstIcmp *Inst) override; |
| 158 /// Complains loudly if invoked because the cpu can handle 64-bit types |
| 159 /// natively. |
| 160 template <typename T = Traits> |
| 161 typename std::enable_if<T::Is64Bit, void>::type |
| 162 lowerIcmp64(const InstIcmp *) { |
| 163 llvm::report_fatal_error( |
| 164 "Hey, yo! This is x86-64. Watcha doin'? (lowerIcmp64)"); |
| 165 } |
| 166 /// x86lowerIcmp64 handles 64-bit icmp lowering. |
| 167 template <typename T = Traits> |
| 168 typename std::enable_if<!T::Is64Bit, void>::type |
| 169 lowerIcmp64(const InstIcmp *Inst); |
| 170 |
| 132 void lowerIntrinsicCall(const InstIntrinsicCall *Inst) override; | 171 void lowerIntrinsicCall(const InstIntrinsicCall *Inst) override; |
| 133 void lowerInsertElement(const InstInsertElement *Inst) override; | 172 void lowerInsertElement(const InstInsertElement *Inst) override; |
| 134 void lowerLoad(const InstLoad *Inst) override; | 173 void lowerLoad(const InstLoad *Inst) override; |
| 135 void lowerPhi(const InstPhi *Inst) override; | 174 void lowerPhi(const InstPhi *Inst) override; |
| 136 void lowerSelect(const InstSelect *Inst) override; | 175 void lowerSelect(const InstSelect *Inst) override; |
| 137 void lowerStore(const InstStore *Inst) override; | 176 void lowerStore(const InstStore *Inst) override; |
| 138 void lowerSwitch(const InstSwitch *Inst) override; | 177 void lowerSwitch(const InstSwitch *Inst) override; |
| 139 void lowerUnreachable(const InstUnreachable *Inst) override; | 178 void lowerUnreachable(const InstUnreachable *Inst) override; |
| 140 void lowerOther(const Inst *Instr) override; | 179 void lowerOther(const Inst *Instr) override; |
| 141 void lowerRMW(const typename Traits::Insts::FakeRMW *RMW); | 180 void lowerRMW(const typename Traits::Insts::FakeRMW *RMW); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 } | 662 } |
| 624 | 663 |
| 625 BoolFolding FoldingInfo; | 664 BoolFolding FoldingInfo; |
| 626 }; | 665 }; |
| 627 } // end of namespace X86Internal | 666 } // end of namespace X86Internal |
| 628 } // end of namespace Ice | 667 } // end of namespace Ice |
| 629 | 668 |
| 630 #include "IceTargetLoweringX86BaseImpl.h" | 669 #include "IceTargetLoweringX86BaseImpl.h" |
| 631 | 670 |
| 632 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H | 671 #endif // SUBZERO_SRC_ICETARGETLOWERINGX86BASE_H |
| OLD | NEW |