Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceTargetLoweringX8632.h - x86-32 lowering ---*- C++ -*-===// |
| 2 | // |
| 3 | // The Subzero Code Generator |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the TargetLoweringX8632 class, which |
| 11 | // implements the TargetLowering interface for the x86-32 |
| 12 | // architecture. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICETARGETLOWERINGX8632_H |
| 17 | #define SUBZERO_SRC_ICETARGETLOWERINGX8632_H |
| 18 | |
| 19 | #include "IceDefs.h" |
| 20 | #include "IceTargetLowering.h" |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 21 | #include "assembler_ia32.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 22 | #include "IceInstX8632.h" |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 23 | #include "IceRegistersX8632.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 24 | |
| 25 | namespace Ice { |
| 26 | |
| 27 | class TargetX8632 : public TargetLowering { |
| 28 | public: |
| 29 | static TargetX8632 *create(Cfg *Func) { return new TargetX8632(Func); } |
| 30 | |
| 31 | virtual void translateOm1(); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 32 | virtual void translateO2(); |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 33 | virtual bool doBranchOpt(Inst *I, const CfgNode *NextNode); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 34 | |
| 35 | virtual Variable *getPhysicalRegister(SizeT RegNum); |
| 36 | virtual IceString getRegName(SizeT RegNum, Type Ty) const; |
| 37 | virtual llvm::SmallBitVector getRegisterSet(RegSetMask Include, |
| 38 | RegSetMask Exclude) const; |
| 39 | virtual const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const { |
| 40 | return TypeToRegisterSet[Ty]; |
| 41 | } |
| 42 | virtual bool hasFramePointer() const { return IsEbpBasedFrame; } |
| 43 | virtual SizeT getFrameOrStackReg() const { |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 44 | return IsEbpBasedFrame ? RegX8632::Reg_ebp : RegX8632::Reg_esp; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 45 | } |
Matt Wala | d4799f4 | 2014-08-14 14:24:12 -0700 | [diff] [blame] | 46 | virtual size_t typeWidthInBytesOnStack(Type Ty) const { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 47 | // Round up to the next multiple of 4 bytes. In particular, i1, |
| 48 | // i8, and i16 are rounded up to 4 bytes. |
| 49 | return (typeWidthInBytes(Ty) + 3) & ~3; |
| 50 | } |
Jan Voung | b17f61d | 2014-08-28 16:00:53 -0700 | [diff] [blame] | 51 | virtual SizeT getBundleAlignLog2Bytes() const { return 5; } |
| 52 | virtual llvm::ArrayRef<uint8_t> getNonExecBundlePadding() const { |
| 53 | static const uint8_t Padding[] = { 0xF4 }; |
| 54 | return llvm::ArrayRef<uint8_t>(Padding, 1); |
| 55 | } |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 56 | virtual void emitVariable(const Variable *Var) const; |
Matt Wala | 45a0623 | 2014-07-09 16:33:22 -0700 | [diff] [blame] | 57 | virtual void lowerArguments(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 58 | virtual void addProlog(CfgNode *Node); |
| 59 | virtual void addEpilog(CfgNode *Node); |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 60 | virtual void emitConstants() const; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 61 | SizeT makeNextLabelNumber() { return NextLabelNumber++; } |
| 62 | // Ensure that a 64-bit Variable has been split into 2 32-bit |
| 63 | // Variables, creating them if necessary. This is needed for all |
| 64 | // I64 operations, and it is needed for pushing F64 arguments for |
| 65 | // function calls using the 32-bit push instruction (though the |
| 66 | // latter could be done by directly writing to the stack). |
| 67 | void split64(Variable *Var); |
Matt Wala | 45a0623 | 2014-07-09 16:33:22 -0700 | [diff] [blame] | 68 | void finishArgumentLowering(Variable *Arg, Variable *FramePtr, |
| 69 | size_t BasicFrameOffset, size_t &InArgsSizeBytes); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 70 | Operand *loOperand(Operand *Operand); |
| 71 | Operand *hiOperand(Operand *Operand); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 72 | x86::Address stackVarToAsmOperand(const Variable *Var) const; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 73 | |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 74 | enum X86InstructionSet { |
| 75 | // SSE2 is the PNaCl baseline instruction set. |
| 76 | SSE2, |
| 77 | SSE4_1 |
| 78 | }; |
| 79 | |
| 80 | X86InstructionSet getInstructionSet() const { return InstructionSet; } |
| 81 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 82 | protected: |
| 83 | TargetX8632(Cfg *Func); |
| 84 | |
| 85 | virtual void postLower(); |
| 86 | |
| 87 | virtual void lowerAlloca(const InstAlloca *Inst); |
| 88 | virtual void lowerArithmetic(const InstArithmetic *Inst); |
| 89 | virtual void lowerAssign(const InstAssign *Inst); |
| 90 | virtual void lowerBr(const InstBr *Inst); |
| 91 | virtual void lowerCall(const InstCall *Inst); |
| 92 | virtual void lowerCast(const InstCast *Inst); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 93 | virtual void lowerExtractElement(const InstExtractElement *Inst); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 94 | virtual void lowerFcmp(const InstFcmp *Inst); |
| 95 | virtual void lowerIcmp(const InstIcmp *Inst); |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 96 | virtual void lowerIntrinsicCall(const InstIntrinsicCall *Inst); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 97 | virtual void lowerInsertElement(const InstInsertElement *Inst); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 98 | virtual void lowerLoad(const InstLoad *Inst); |
| 99 | virtual void lowerPhi(const InstPhi *Inst); |
| 100 | virtual void lowerRet(const InstRet *Inst); |
| 101 | virtual void lowerSelect(const InstSelect *Inst); |
| 102 | virtual void lowerStore(const InstStore *Inst); |
| 103 | virtual void lowerSwitch(const InstSwitch *Inst); |
| 104 | virtual void lowerUnreachable(const InstUnreachable *Inst); |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 105 | virtual void doAddressOptLoad(); |
| 106 | virtual void doAddressOptStore(); |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 107 | virtual void randomlyInsertNop(float Probability); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 108 | |
Jan Voung | c820ddf | 2014-07-29 14:38:51 -0700 | [diff] [blame] | 109 | // Naive lowering of cmpxchg. |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 110 | void lowerAtomicCmpxchg(Variable *DestPrev, Operand *Ptr, Operand *Expected, |
| 111 | Operand *Desired); |
Jan Voung | c820ddf | 2014-07-29 14:38:51 -0700 | [diff] [blame] | 112 | // Attempt a more optimized lowering of cmpxchg. Returns true if optimized. |
| 113 | bool tryOptimizedCmpxchgCmpBr(Variable *DestPrev, Operand *Ptr, |
| 114 | Operand *Expected, Operand *Desired); |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 115 | void lowerAtomicRMW(Variable *Dest, uint32_t Operation, Operand *Ptr, |
| 116 | Operand *Val); |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 117 | void lowerCountZeros(bool Cttz, Type Ty, Variable *Dest, Operand *FirstVal, |
| 118 | Operand *SecondVal); |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 119 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 120 | typedef void (TargetX8632::*LowerBinOp)(Variable *, Operand *); |
| 121 | void expandAtomicRMWAsCmpxchg(LowerBinOp op_lo, LowerBinOp op_hi, |
| 122 | Variable *Dest, Operand *Ptr, Operand *Val); |
| 123 | |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 124 | void eliminateNextVectorSextInstruction(Variable *SignExtendedResult); |
| 125 | |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 126 | void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest, |
| 127 | Operand *Src0, Operand *Src1); |
| 128 | |
Matt Wala | d4799f4 | 2014-08-14 14:24:12 -0700 | [diff] [blame] | 129 | void sortByAlignment(VarList &Dest, const VarList &Source) const; |
| 130 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 131 | // Operand legalization helpers. To deal with address mode |
| 132 | // constraints, the helpers will create a new Operand and emit |
| 133 | // instructions that guarantee that the Operand kind is one of those |
| 134 | // indicated by the LegalMask (a bitmask of allowed kinds). If the |
| 135 | // input Operand is known to already meet the constraints, it may be |
| 136 | // simply returned as the result, without creating any new |
| 137 | // instructions or operands. |
| 138 | enum OperandLegalization { |
| 139 | Legal_None = 0, |
| 140 | Legal_Reg = 1 << 0, // physical register, not stack location |
| 141 | Legal_Imm = 1 << 1, |
| 142 | Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12] |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 143 | // TODO(stichnot): LEAHACK: remove Legal_Reloc once a proper |
| 144 | // emitter is used. |
| 145 | Legal_Reloc = 1 << 3, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 146 | Legal_All = ~Legal_None |
| 147 | }; |
| 148 | typedef uint32_t LegalMask; |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 149 | Operand *legalize(Operand *From, LegalMask Allowed = Legal_All & ~Legal_Reloc, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 150 | bool AllowOverlap = false, |
| 151 | int32_t RegNum = Variable::NoRegister); |
| 152 | Variable *legalizeToVar(Operand *From, bool AllowOverlap = false, |
| 153 | int32_t RegNum = Variable::NoRegister); |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 154 | // Turn a pointer operand into a memory operand that can be |
| 155 | // used by a real load/store operation. Legalizes the operand as well. |
| 156 | // This is a nop if the operand is already a legal memory operand. |
| 157 | OperandX8632Mem *FormMemoryOperand(Operand *Ptr, Type Ty); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 158 | |
| 159 | Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister); |
| 160 | InstCall *makeHelperCall(const IceString &Name, Variable *Dest, |
| 161 | SizeT MaxSrcs) { |
| 162 | bool SuppressMangling = true; |
Matt Wala | ad8f726 | 2014-07-14 17:37:37 -0700 | [diff] [blame] | 163 | const Type FunctionPointerType = IceType_i32; |
| 164 | Constant *CallTarget = |
| 165 | Ctx->getConstantSym(FunctionPointerType, 0, Name, SuppressMangling); |
Karl Schimpf | 8df26f3 | 2014-09-19 09:33:26 -0700 | [diff] [blame] | 166 | InstCall *Call = InstCall::create(Func, MaxSrcs, Dest, CallTarget, false); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 167 | return Call; |
| 168 | } |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 169 | static Type stackSlotType(); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 170 | |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 171 | Variable *copyToReg(Operand *Src, int32_t RegNum = Variable::NoRegister); |
| 172 | |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 173 | // Returns a vector in a register with the given constant entries. |
| 174 | Variable *makeVectorOfZeros(Type Ty, int32_t RegNum = Variable::NoRegister); |
| 175 | Variable *makeVectorOfOnes(Type Ty, int32_t RegNum = Variable::NoRegister); |
Matt Wala | 9a0168a | 2014-07-23 14:56:10 -0700 | [diff] [blame] | 176 | Variable *makeVectorOfMinusOnes(Type Ty, |
| 177 | int32_t RegNum = Variable::NoRegister); |
| 178 | Variable *makeVectorOfHighOrderBits(Type Ty, |
| 179 | int32_t RegNum = Variable::NoRegister); |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 180 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 181 | // Return a memory operand corresponding to a stack allocated Variable. |
| 182 | OperandX8632Mem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot, |
| 183 | uint32_t Offset = 0); |
| 184 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 185 | // The following are helpers that insert lowered x86 instructions |
| 186 | // with minimal syntactic overhead, so that the lowering code can |
| 187 | // look as close to assembly as practical. |
| 188 | void _adc(Variable *Dest, Operand *Src0) { |
| 189 | Context.insert(InstX8632Adc::create(Func, Dest, Src0)); |
| 190 | } |
| 191 | void _add(Variable *Dest, Operand *Src0) { |
| 192 | Context.insert(InstX8632Add::create(Func, Dest, Src0)); |
| 193 | } |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 194 | void _adjust_stack(int32_t Amount) { |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 195 | Context.insert(InstX8632AdjustStack::create( |
| 196 | Func, Amount, getPhysicalRegister(RegX8632::Reg_esp))); |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 197 | } |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 198 | void _addps(Variable *Dest, Operand *Src0) { |
| 199 | Context.insert(InstX8632Addps::create(Func, Dest, Src0)); |
| 200 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 201 | void _addss(Variable *Dest, Operand *Src0) { |
| 202 | Context.insert(InstX8632Addss::create(Func, Dest, Src0)); |
| 203 | } |
| 204 | void _and(Variable *Dest, Operand *Src0) { |
| 205 | Context.insert(InstX8632And::create(Func, Dest, Src0)); |
| 206 | } |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 207 | void _blendvps(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 208 | Context.insert(InstX8632Blendvps::create(Func, Dest, Src0, Src1)); |
| 209 | } |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 210 | void _br(CondX86::BrCond Condition, CfgNode *TargetTrue, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 211 | CfgNode *TargetFalse) { |
| 212 | Context.insert( |
| 213 | InstX8632Br::create(Func, TargetTrue, TargetFalse, Condition)); |
| 214 | } |
| 215 | void _br(CfgNode *Target) { |
| 216 | Context.insert(InstX8632Br::create(Func, Target)); |
| 217 | } |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 218 | void _br(CondX86::BrCond Condition, CfgNode *Target) { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 219 | Context.insert(InstX8632Br::create(Func, Target, Condition)); |
| 220 | } |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 221 | void _br(CondX86::BrCond Condition, InstX8632Label *Label) { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 222 | Context.insert(InstX8632Br::create(Func, Label, Condition)); |
| 223 | } |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 224 | void _bsf(Variable *Dest, Operand *Src0) { |
| 225 | Context.insert(InstX8632Bsf::create(Func, Dest, Src0)); |
| 226 | } |
| 227 | void _bsr(Variable *Dest, Operand *Src0) { |
| 228 | Context.insert(InstX8632Bsr::create(Func, Dest, Src0)); |
| 229 | } |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 230 | void _bswap(Variable *SrcDest) { |
| 231 | Context.insert(InstX8632Bswap::create(Func, SrcDest)); |
| 232 | } |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 233 | void _cbwdq(Variable *Dest, Operand *Src0) { |
| 234 | Context.insert(InstX8632Cbwdq::create(Func, Dest, Src0)); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 235 | } |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 236 | void _cmov(Variable *Dest, Operand *Src0, CondX86::BrCond Condition) { |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 237 | Context.insert(InstX8632Cmov::create(Func, Dest, Src0, Condition)); |
| 238 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 239 | void _cmp(Operand *Src0, Operand *Src1) { |
| 240 | Context.insert(InstX8632Icmp::create(Func, Src0, Src1)); |
| 241 | } |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 242 | void _cmpps(Variable *Dest, Operand *Src0, CondX86::CmppsCond Condition) { |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 243 | Context.insert(InstX8632Cmpps::create(Func, Dest, Src0, Condition)); |
| 244 | } |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 245 | void _cmpxchg(Operand *DestOrAddr, Variable *Eax, Variable *Desired, |
| 246 | bool Locked) { |
| 247 | Context.insert( |
| 248 | InstX8632Cmpxchg::create(Func, DestOrAddr, Eax, Desired, Locked)); |
| 249 | // Mark eax as possibly modified by cmpxchg. |
| 250 | Context.insert( |
| 251 | InstFakeDef::create(Func, Eax, llvm::dyn_cast<Variable>(DestOrAddr))); |
| 252 | } |
Jan Voung | 03532e5 | 2014-09-23 13:32:18 -0700 | [diff] [blame^] | 253 | void _cmpxchg8b(OperandX8632Mem *Addr, Variable *Edx, Variable *Eax, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 254 | Variable *Ecx, Variable *Ebx, bool Locked) { |
| 255 | Context.insert( |
| 256 | InstX8632Cmpxchg8b::create(Func, Addr, Edx, Eax, Ecx, Ebx, Locked)); |
| 257 | // Mark edx, and eax as possibly modified by cmpxchg8b. |
| 258 | Context.insert(InstFakeDef::create(Func, Edx)); |
| 259 | Context.insert(InstFakeDef::create(Func, Eax)); |
| 260 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 261 | void _cvt(Variable *Dest, Operand *Src0) { |
Jim Stichnoth | b63cd88 | 2014-09-08 10:47:23 -0700 | [diff] [blame] | 262 | const bool Trunc = false; |
| 263 | Context.insert(InstX8632Cvt::create(Func, Dest, Src0, Trunc)); |
| 264 | } |
| 265 | void _cvtt(Variable *Dest, Operand *Src0) { |
| 266 | const bool Trunc = true; |
| 267 | Context.insert(InstX8632Cvt::create(Func, Dest, Src0, Trunc)); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 268 | } |
| 269 | void _div(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 270 | Context.insert(InstX8632Div::create(Func, Dest, Src0, Src1)); |
| 271 | } |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 272 | void _divps(Variable *Dest, Operand *Src0) { |
| 273 | Context.insert(InstX8632Divps::create(Func, Dest, Src0)); |
| 274 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 275 | void _divss(Variable *Dest, Operand *Src0) { |
| 276 | Context.insert(InstX8632Divss::create(Func, Dest, Src0)); |
| 277 | } |
| 278 | void _fld(Operand *Src0) { Context.insert(InstX8632Fld::create(Func, Src0)); } |
| 279 | void _fstp(Variable *Dest) { |
| 280 | Context.insert(InstX8632Fstp::create(Func, Dest)); |
| 281 | } |
| 282 | void _idiv(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 283 | Context.insert(InstX8632Idiv::create(Func, Dest, Src0, Src1)); |
| 284 | } |
| 285 | void _imul(Variable *Dest, Operand *Src0) { |
| 286 | Context.insert(InstX8632Imul::create(Func, Dest, Src0)); |
| 287 | } |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 288 | void _insertps(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 289 | Context.insert(InstX8632Insertps::create(Func, Dest, Src0, Src1)); |
| 290 | } |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 291 | void _lea(Variable *Dest, Operand *Src0) { |
| 292 | Context.insert(InstX8632Lea::create(Func, Dest, Src0)); |
| 293 | } |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 294 | void _mfence() { Context.insert(InstX8632Mfence::create(Func)); } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 295 | // If Dest=NULL is passed in, then a new variable is created, marked |
| 296 | // as infinite register allocation weight, and returned through the |
| 297 | // in/out Dest argument. |
| 298 | void _mov(Variable *&Dest, Operand *Src0, |
| 299 | int32_t RegNum = Variable::NoRegister) { |
| 300 | if (Dest == NULL) { |
| 301 | Dest = legalizeToVar(Src0, false, RegNum); |
| 302 | } else { |
| 303 | Context.insert(InstX8632Mov::create(Func, Dest, Src0)); |
| 304 | } |
| 305 | } |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 306 | void _movd(Variable *Dest, Operand *Src0) { |
| 307 | Context.insert(InstX8632Movd::create(Func, Dest, Src0)); |
| 308 | } |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 309 | void _movp(Variable *Dest, Operand *Src0) { |
| 310 | Context.insert(InstX8632Movp::create(Func, Dest, Src0)); |
| 311 | } |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 312 | void _movq(Variable *Dest, Operand *Src0) { |
| 313 | Context.insert(InstX8632Movq::create(Func, Dest, Src0)); |
| 314 | } |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 315 | void _movss(Variable *Dest, Operand *Src0) { |
| 316 | Context.insert(InstX8632Movss::create(Func, Dest, Src0)); |
| 317 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 318 | void _movsx(Variable *Dest, Operand *Src0) { |
| 319 | Context.insert(InstX8632Movsx::create(Func, Dest, Src0)); |
| 320 | } |
| 321 | void _movzx(Variable *Dest, Operand *Src0) { |
| 322 | Context.insert(InstX8632Movzx::create(Func, Dest, Src0)); |
| 323 | } |
| 324 | void _mul(Variable *Dest, Variable *Src0, Operand *Src1) { |
| 325 | Context.insert(InstX8632Mul::create(Func, Dest, Src0, Src1)); |
| 326 | } |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 327 | void _mulps(Variable *Dest, Operand *Src0) { |
| 328 | Context.insert(InstX8632Mulps::create(Func, Dest, Src0)); |
| 329 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 330 | void _mulss(Variable *Dest, Operand *Src0) { |
| 331 | Context.insert(InstX8632Mulss::create(Func, Dest, Src0)); |
| 332 | } |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 333 | void _neg(Variable *SrcDest) { |
| 334 | Context.insert(InstX8632Neg::create(Func, SrcDest)); |
| 335 | } |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 336 | void _nop(SizeT Variant) { |
| 337 | Context.insert(InstX8632Nop::create(Func, Variant)); |
| 338 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 339 | void _or(Variable *Dest, Operand *Src0) { |
| 340 | Context.insert(InstX8632Or::create(Func, Dest, Src0)); |
| 341 | } |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 342 | void _padd(Variable *Dest, Operand *Src0) { |
| 343 | Context.insert(InstX8632Padd::create(Func, Dest, Src0)); |
| 344 | } |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 345 | void _pand(Variable *Dest, Operand *Src0) { |
| 346 | Context.insert(InstX8632Pand::create(Func, Dest, Src0)); |
| 347 | } |
Matt Wala | 9cb61e2 | 2014-07-24 09:44:42 -0700 | [diff] [blame] | 348 | void _pandn(Variable *Dest, Operand *Src0) { |
| 349 | Context.insert(InstX8632Pandn::create(Func, Dest, Src0)); |
| 350 | } |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 351 | void _pblendvb(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 352 | Context.insert(InstX8632Pblendvb::create(Func, Dest, Src0, Src1)); |
| 353 | } |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 354 | void _pcmpeq(Variable *Dest, Operand *Src0) { |
| 355 | Context.insert(InstX8632Pcmpeq::create(Func, Dest, Src0)); |
| 356 | } |
| 357 | void _pcmpgt(Variable *Dest, Operand *Src0) { |
| 358 | Context.insert(InstX8632Pcmpgt::create(Func, Dest, Src0)); |
| 359 | } |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 360 | void _pextr(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 361 | Context.insert(InstX8632Pextr::create(Func, Dest, Src0, Src1)); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 362 | } |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 363 | void _pinsr(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 364 | Context.insert(InstX8632Pinsr::create(Func, Dest, Src0, Src1)); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 365 | } |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 366 | void _pmull(Variable *Dest, Operand *Src0) { |
| 367 | Context.insert(InstX8632Pmull::create(Func, Dest, Src0)); |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 368 | } |
| 369 | void _pmuludq(Variable *Dest, Operand *Src0) { |
| 370 | Context.insert(InstX8632Pmuludq::create(Func, Dest, Src0)); |
| 371 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 372 | void _pop(Variable *Dest) { |
| 373 | Context.insert(InstX8632Pop::create(Func, Dest)); |
| 374 | } |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 375 | void _por(Variable *Dest, Operand *Src0) { |
| 376 | Context.insert(InstX8632Por::create(Func, Dest, Src0)); |
| 377 | } |
| 378 | void _pshufd(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 379 | Context.insert(InstX8632Pshufd::create(Func, Dest, Src0, Src1)); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 380 | } |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 381 | void _psll(Variable *Dest, Operand *Src0) { |
| 382 | Context.insert(InstX8632Psll::create(Func, Dest, Src0)); |
| 383 | } |
| 384 | void _psra(Variable *Dest, Operand *Src0) { |
| 385 | Context.insert(InstX8632Psra::create(Func, Dest, Src0)); |
| 386 | } |
| 387 | void _psub(Variable *Dest, Operand *Src0) { |
| 388 | Context.insert(InstX8632Psub::create(Func, Dest, Src0)); |
| 389 | } |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 390 | void _push(Operand *Src0, bool SuppressStackAdjustment = false) { |
| 391 | Context.insert(InstX8632Push::create(Func, Src0, SuppressStackAdjustment)); |
| 392 | } |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 393 | void _pxor(Variable *Dest, Operand *Src0) { |
| 394 | Context.insert(InstX8632Pxor::create(Func, Dest, Src0)); |
| 395 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 396 | void _ret(Variable *Src0 = NULL) { |
| 397 | Context.insert(InstX8632Ret::create(Func, Src0)); |
| 398 | } |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 399 | void _rol(Variable *Dest, Operand *Src0) { |
| 400 | Context.insert(InstX8632Rol::create(Func, Dest, Src0)); |
| 401 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 402 | void _sar(Variable *Dest, Operand *Src0) { |
| 403 | Context.insert(InstX8632Sar::create(Func, Dest, Src0)); |
| 404 | } |
| 405 | void _sbb(Variable *Dest, Operand *Src0) { |
| 406 | Context.insert(InstX8632Sbb::create(Func, Dest, Src0)); |
| 407 | } |
| 408 | void _shl(Variable *Dest, Operand *Src0) { |
| 409 | Context.insert(InstX8632Shl::create(Func, Dest, Src0)); |
| 410 | } |
| 411 | void _shld(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 412 | Context.insert(InstX8632Shld::create(Func, Dest, Src0, Src1)); |
| 413 | } |
| 414 | void _shr(Variable *Dest, Operand *Src0) { |
| 415 | Context.insert(InstX8632Shr::create(Func, Dest, Src0)); |
| 416 | } |
| 417 | void _shrd(Variable *Dest, Variable *Src0, Variable *Src1) { |
| 418 | Context.insert(InstX8632Shrd::create(Func, Dest, Src0, Src1)); |
| 419 | } |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 420 | void _shufps(Variable *Dest, Operand *Src0, Operand *Src1) { |
| 421 | Context.insert(InstX8632Shufps::create(Func, Dest, Src0, Src1)); |
| 422 | } |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 423 | void _sqrtss(Variable *Dest, Operand *Src0) { |
| 424 | Context.insert(InstX8632Sqrtss::create(Func, Dest, Src0)); |
| 425 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 426 | void _store(Operand *Value, OperandX8632 *Mem) { |
| 427 | Context.insert(InstX8632Store::create(Func, Value, Mem)); |
| 428 | } |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 429 | void _storep(Operand *Value, OperandX8632 *Mem) { |
| 430 | Context.insert(InstX8632StoreP::create(Func, Value, Mem)); |
| 431 | } |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 432 | void _storeq(Operand *Value, OperandX8632 *Mem) { |
| 433 | Context.insert(InstX8632StoreQ::create(Func, Value, Mem)); |
| 434 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 435 | void _sub(Variable *Dest, Operand *Src0) { |
| 436 | Context.insert(InstX8632Sub::create(Func, Dest, Src0)); |
| 437 | } |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 438 | void _subps(Variable *Dest, Operand *Src0) { |
| 439 | Context.insert(InstX8632Subps::create(Func, Dest, Src0)); |
| 440 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 441 | void _subss(Variable *Dest, Operand *Src0) { |
| 442 | Context.insert(InstX8632Subss::create(Func, Dest, Src0)); |
| 443 | } |
| 444 | void _test(Operand *Src0, Operand *Src1) { |
| 445 | Context.insert(InstX8632Test::create(Func, Src0, Src1)); |
| 446 | } |
| 447 | void _ucomiss(Operand *Src0, Operand *Src1) { |
| 448 | Context.insert(InstX8632Ucomiss::create(Func, Src0, Src1)); |
| 449 | } |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 450 | void _ud2() { Context.insert(InstX8632UD2::create(Func)); } |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 451 | void _xadd(Operand *Dest, Variable *Src, bool Locked) { |
| 452 | Context.insert(InstX8632Xadd::create(Func, Dest, Src, Locked)); |
| 453 | // The xadd exchanges Dest and Src (modifying Src). |
| 454 | // Model that update with a FakeDef. |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 455 | Context.insert( |
| 456 | InstFakeDef::create(Func, Src, llvm::dyn_cast<Variable>(Dest))); |
| 457 | } |
| 458 | void _xchg(Operand *Dest, Variable *Src) { |
| 459 | Context.insert(InstX8632Xchg::create(Func, Dest, Src)); |
| 460 | // The xchg modifies Dest and Src -- model that update with a FakeDef. |
| 461 | Context.insert( |
| 462 | InstFakeDef::create(Func, Src, llvm::dyn_cast<Variable>(Dest))); |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 463 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 464 | void _xor(Variable *Dest, Operand *Src0) { |
| 465 | Context.insert(InstX8632Xor::create(Func, Dest, Src0)); |
| 466 | } |
| 467 | |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 468 | const X86InstructionSet InstructionSet; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 469 | bool IsEbpBasedFrame; |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 470 | bool NeedsStackAlignment; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 471 | size_t FrameSizeLocals; |
Matt Wala | d4799f4 | 2014-08-14 14:24:12 -0700 | [diff] [blame] | 472 | size_t SpillAreaSizeBytes; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 473 | llvm::SmallBitVector TypeToRegisterSet[IceType_NUM]; |
| 474 | llvm::SmallBitVector ScratchRegs; |
| 475 | llvm::SmallBitVector RegsUsed; |
| 476 | SizeT NextLabelNumber; |
| 477 | bool ComputedLiveRanges; |
| 478 | VarList PhysicalRegisters; |
| 479 | static IceString RegNames[]; |
| 480 | |
| 481 | private: |
| 482 | TargetX8632(const TargetX8632 &) LLVM_DELETED_FUNCTION; |
| 483 | TargetX8632 &operator=(const TargetX8632 &) LLVM_DELETED_FUNCTION; |
| 484 | virtual ~TargetX8632() {} |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 485 | template <typename T> void emitConstantPool() const; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 486 | }; |
| 487 | |
Jim Stichnoth | de4ca71 | 2014-06-29 08:13:48 -0700 | [diff] [blame] | 488 | class TargetGlobalInitX8632 : public TargetGlobalInitLowering { |
| 489 | public: |
| 490 | static TargetGlobalInitLowering *create(GlobalContext *Ctx) { |
| 491 | return new TargetGlobalInitX8632(Ctx); |
| 492 | } |
| 493 | virtual void lower(const IceString &Name, SizeT Align, bool IsInternal, |
| 494 | bool IsConst, bool IsZeroInitializer, SizeT Size, |
| 495 | const char *Data, bool DisableTranslation); |
| 496 | |
| 497 | protected: |
| 498 | TargetGlobalInitX8632(GlobalContext *Ctx); |
| 499 | |
| 500 | private: |
| 501 | TargetGlobalInitX8632(const TargetGlobalInitX8632 &) LLVM_DELETED_FUNCTION; |
| 502 | TargetGlobalInitX8632 & |
| 503 | operator=(const TargetGlobalInitX8632 &) LLVM_DELETED_FUNCTION; |
| 504 | virtual ~TargetGlobalInitX8632() {} |
| 505 | }; |
| 506 | |
Jan Voung | bc00463 | 2014-09-16 15:09:10 -0700 | [diff] [blame] | 507 | template <> void ConstantInteger32::emit(GlobalContext *Ctx) const; |
| 508 | template <> void ConstantInteger64::emit(GlobalContext *Ctx) const; |
Jim Stichnoth | d97c7df | 2014-06-04 11:57:08 -0700 | [diff] [blame] | 509 | template <> void ConstantFloat::emit(GlobalContext *Ctx) const; |
| 510 | template <> void ConstantDouble::emit(GlobalContext *Ctx) const; |
Jim Stichnoth | f61d5b2 | 2014-05-23 13:31:24 -0700 | [diff] [blame] | 511 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 512 | } // end of namespace Ice |
| 513 | |
| 514 | #endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H |