Jan Voung | b36ad9b | 2015-04-21 17:01:49 -0700 | [diff] [blame] | 1 | //===- subzero/src/IceInstX8632.h - x86-32 machine instructions -*- C++ -*-===// |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 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 InstX8632 and OperandX8632 classes and |
| 11 | // their subclasses. This represents the machine instructions and |
| 12 | // operands used for x86-32 code selection. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef SUBZERO_SRC_ICEINSTX8632_H |
| 17 | #define SUBZERO_SRC_ICEINSTX8632_H |
| 18 | |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 19 | #include "assembler_ia32.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 20 | #include "IceDefs.h" |
| 21 | #include "IceInst.h" |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 22 | #include "IceConditionCodesX8632.h" |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 23 | #include "IceInstX8632.def" |
| 24 | #include "IceOperand.h" |
| 25 | |
| 26 | namespace Ice { |
| 27 | |
| 28 | class TargetX8632; |
| 29 | |
| 30 | // OperandX8632 extends the Operand hierarchy. Its subclasses are |
| 31 | // OperandX8632Mem and VariableSplit. |
| 32 | class OperandX8632 : public Operand { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 33 | OperandX8632() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 34 | OperandX8632(const OperandX8632 &) = delete; |
| 35 | OperandX8632 &operator=(const OperandX8632 &) = delete; |
| 36 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 37 | public: |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 38 | enum OperandKindX8632 { k__Start = Operand::kTarget, kMem, kSplit }; |
Jim Stichnoth | 2e8bfbb | 2014-09-16 10:16:00 -0700 | [diff] [blame] | 39 | using Operand::dump; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 40 | void dump(const Cfg *, Ostream &Str) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 41 | if (ALLOW_DUMP) |
| 42 | Str << "<OperandX8632>"; |
Jim Stichnoth | 2e8bfbb | 2014-09-16 10:16:00 -0700 | [diff] [blame] | 43 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 44 | |
| 45 | protected: |
| 46 | OperandX8632(OperandKindX8632 Kind, Type Ty) |
| 47 | : Operand(static_cast<OperandKind>(Kind), Ty) {} |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 48 | ~OperandX8632() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // OperandX8632Mem represents the m32 addressing mode, with optional |
| 52 | // base and index registers, a constant offset, and a fixed shift |
| 53 | // value for the index register. |
| 54 | class OperandX8632Mem : public OperandX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 55 | OperandX8632Mem() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 56 | OperandX8632Mem(const OperandX8632Mem &) = delete; |
| 57 | OperandX8632Mem &operator=(const OperandX8632Mem &) = delete; |
| 58 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 59 | public: |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 60 | enum SegmentRegisters { |
| 61 | DefaultSegment = -1, |
Jan Voung | fe14fb8 | 2014-10-13 15:56:32 -0700 | [diff] [blame] | 62 | #define X(val, name, prefix) val, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 63 | SEG_REGX8632_TABLE |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 64 | #undef X |
| 65 | SegReg_NUM |
| 66 | }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 67 | static OperandX8632Mem *create(Cfg *Func, Type Ty, Variable *Base, |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 68 | Constant *Offset, Variable *Index = nullptr, |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 69 | uint16_t Shift = 0, |
| 70 | SegmentRegisters SegmentReg = DefaultSegment) { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 71 | return new (Func->allocate<OperandX8632Mem>()) |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 72 | OperandX8632Mem(Func, Ty, Base, Offset, Index, Shift, SegmentReg); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 73 | } |
| 74 | Variable *getBase() const { return Base; } |
| 75 | Constant *getOffset() const { return Offset; } |
| 76 | Variable *getIndex() const { return Index; } |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 77 | uint16_t getShift() const { return Shift; } |
| 78 | SegmentRegisters getSegmentRegister() const { return SegmentReg; } |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 79 | void emitSegmentOverride(X8632::AssemblerX8632 *Asm) const; |
| 80 | X8632::Address toAsmAddress(Assembler *Asm) const; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 81 | void emit(const Cfg *Func) const override; |
Jim Stichnoth | 2e8bfbb | 2014-09-16 10:16:00 -0700 | [diff] [blame] | 82 | using OperandX8632::dump; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 83 | void dump(const Cfg *Func, Ostream &Str) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 84 | |
| 85 | static bool classof(const Operand *Operand) { |
| 86 | return Operand->getKind() == static_cast<OperandKind>(kMem); |
| 87 | } |
| 88 | |
| 89 | private: |
| 90 | OperandX8632Mem(Cfg *Func, Type Ty, Variable *Base, Constant *Offset, |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 91 | Variable *Index, uint16_t Shift, SegmentRegisters SegmentReg); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 92 | ~OperandX8632Mem() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 93 | Variable *Base; |
| 94 | Constant *Offset; |
| 95 | Variable *Index; |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 96 | uint16_t Shift; |
| 97 | SegmentRegisters SegmentReg : 16; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | // VariableSplit is a way to treat an f64 memory location as a pair |
| 101 | // of i32 locations (Low and High). This is needed for some cases |
| 102 | // of the Bitcast instruction. Since it's not possible for integer |
| 103 | // registers to access the XMM registers and vice versa, the |
| 104 | // lowering forces the f64 to be spilled to the stack and then |
| 105 | // accesses through the VariableSplit. |
| 106 | class VariableSplit : public OperandX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 107 | VariableSplit() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 108 | VariableSplit(const VariableSplit &) = delete; |
| 109 | VariableSplit &operator=(const VariableSplit &) = delete; |
| 110 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 111 | public: |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 112 | enum Portion { Low, High }; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 113 | static VariableSplit *create(Cfg *Func, Variable *Var, Portion Part) { |
| 114 | return new (Func->allocate<VariableSplit>()) VariableSplit(Func, Var, Part); |
| 115 | } |
Jan Voung | fe14fb8 | 2014-10-13 15:56:32 -0700 | [diff] [blame] | 116 | int32_t getOffset() const { return Part == High ? 4 : 0; } |
| 117 | |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 118 | X8632::Address toAsmAddress(const Cfg *Func) const; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 119 | void emit(const Cfg *Func) const override; |
Jim Stichnoth | 2e8bfbb | 2014-09-16 10:16:00 -0700 | [diff] [blame] | 120 | using OperandX8632::dump; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 121 | void dump(const Cfg *Func, Ostream &Str) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 122 | |
| 123 | static bool classof(const Operand *Operand) { |
| 124 | return Operand->getKind() == static_cast<OperandKind>(kSplit); |
| 125 | } |
| 126 | |
| 127 | private: |
| 128 | VariableSplit(Cfg *Func, Variable *Var, Portion Part) |
| 129 | : OperandX8632(kSplit, IceType_i32), Func(Func), Var(Var), Part(Part) { |
| 130 | assert(Var->getType() == IceType_f64); |
| 131 | Vars = Func->allocateArrayOf<Variable *>(1); |
| 132 | Vars[0] = Var; |
| 133 | NumVars = 1; |
| 134 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 135 | ~VariableSplit() override { Func->deallocateArrayOf<Variable *>(Vars); } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 136 | Cfg *Func; // Held only for the destructor. |
| 137 | Variable *Var; |
| 138 | Portion Part; |
| 139 | }; |
| 140 | |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 141 | // SpillVariable decorates a Variable by linking it to another |
| 142 | // Variable. When stack frame offsets are computed, the SpillVariable |
| 143 | // is given a distinct stack slot only if its linked Variable has a |
| 144 | // register. If the linked Variable has a stack slot, then the |
| 145 | // Variable and SpillVariable share that slot. |
| 146 | class SpillVariable : public Variable { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 147 | SpillVariable() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 148 | SpillVariable(const SpillVariable &) = delete; |
| 149 | SpillVariable &operator=(const SpillVariable &) = delete; |
| 150 | |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 151 | public: |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 152 | static SpillVariable *create(Cfg *Func, Type Ty, SizeT Index) { |
| 153 | return new (Func->allocate<SpillVariable>()) SpillVariable(Ty, Index); |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 154 | } |
| 155 | const static OperandKind SpillVariableKind = |
| 156 | static_cast<OperandKind>(kVariable_Target); |
| 157 | static bool classof(const Operand *Operand) { |
| 158 | return Operand->getKind() == SpillVariableKind; |
| 159 | } |
| 160 | void setLinkedTo(Variable *Var) { LinkedTo = Var; } |
| 161 | Variable *getLinkedTo() const { return LinkedTo; } |
| 162 | // Inherit dump() and emit() from Variable. |
| 163 | private: |
Jim Stichnoth | 9a04c07 | 2014-12-11 15:51:42 -0800 | [diff] [blame] | 164 | SpillVariable(Type Ty, SizeT Index) |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 165 | : Variable(SpillVariableKind, Ty, Index), LinkedTo(nullptr) {} |
Jim Stichnoth | 800dab2 | 2014-09-20 12:25:02 -0700 | [diff] [blame] | 166 | Variable *LinkedTo; |
| 167 | }; |
| 168 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 169 | class InstX8632 : public InstTarget { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 170 | InstX8632() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 171 | InstX8632(const InstX8632 &) = delete; |
| 172 | InstX8632 &operator=(const InstX8632 &) = delete; |
| 173 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 174 | public: |
| 175 | enum InstKindX8632 { |
| 176 | k__Start = Inst::Target, |
| 177 | Adc, |
| 178 | Add, |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 179 | Addps, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 180 | Addss, |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 181 | Adjuststack, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 182 | And, |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 183 | Blendvps, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 184 | Br, |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 185 | Bsf, |
| 186 | Bsr, |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 187 | Bswap, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 188 | Call, |
Matt Wala | afeaee4 | 2014-08-07 13:47:30 -0700 | [diff] [blame] | 189 | Cbwdq, |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 190 | Cmov, |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 191 | Cmpps, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 192 | Cmpxchg, |
| 193 | Cmpxchg8b, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 194 | Cvt, |
| 195 | Div, |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 196 | Divps, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 197 | Divss, |
| 198 | Fld, |
| 199 | Fstp, |
| 200 | Icmp, |
| 201 | Idiv, |
| 202 | Imul, |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 203 | Insertps, |
Jim Stichnoth | 9f42d8c | 2015-02-20 09:20:14 -0800 | [diff] [blame] | 204 | Jmp, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 205 | Label, |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 206 | Lea, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 207 | Load, |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 208 | Mfence, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 209 | Mov, |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 210 | Movd, |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 211 | Movp, |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 212 | Movq, |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 213 | MovssRegs, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 214 | Movsx, |
| 215 | Movzx, |
| 216 | Mul, |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 217 | Mulps, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 218 | Mulss, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 219 | Neg, |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 220 | Nop, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 221 | Or, |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 222 | Padd, |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 223 | Pand, |
Matt Wala | 9cb61e2 | 2014-07-24 09:44:42 -0700 | [diff] [blame] | 224 | Pandn, |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 225 | Pblendvb, |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 226 | Pcmpeq, |
| 227 | Pcmpgt, |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 228 | Pextr, |
| 229 | Pinsr, |
| 230 | Pmull, |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 231 | Pmuludq, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 232 | Pop, |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 233 | Por, |
| 234 | Pshufd, |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 235 | Psll, |
| 236 | Psra, |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 237 | Psrl, |
Matt Wala | 83b8036 | 2014-07-16 10:21:30 -0700 | [diff] [blame] | 238 | Psub, |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 239 | Push, |
Matt Wala | 928f129 | 2014-07-07 16:50:46 -0700 | [diff] [blame] | 240 | Pxor, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 241 | Ret, |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 242 | Rol, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 243 | Sar, |
| 244 | Sbb, |
Jim Stichnoth | f48b320 | 2015-05-04 10:22:17 -0700 | [diff] [blame] | 245 | Setcc, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 246 | Shl, |
| 247 | Shld, |
| 248 | Shr, |
| 249 | Shrd, |
Matt Wala | 7fa22d8 | 2014-07-17 12:41:31 -0700 | [diff] [blame] | 250 | Shufps, |
Jan Voung | f37fbbe | 2014-07-09 16:13:13 -0700 | [diff] [blame] | 251 | Sqrtss, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 252 | Store, |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 253 | StoreP, |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 254 | StoreQ, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 255 | Sub, |
Matt Wala | 8d1072e | 2014-07-11 15:43:51 -0700 | [diff] [blame] | 256 | Subps, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 257 | Subss, |
| 258 | Test, |
| 259 | Ucomiss, |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 260 | UD2, |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 261 | Xadd, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 262 | Xchg, |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 263 | Xor |
| 264 | }; |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 265 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 266 | static const char *getWidthString(Type Ty); |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 267 | static const char *getFldString(Type Ty); |
Jim Stichnoth | 537b5ba | 2015-05-19 09:48:44 -0700 | [diff] [blame^] | 268 | static CondX86::BrCond getOppositeCondition(CondX86::BrCond Cond); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 269 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 270 | |
| 271 | protected: |
| 272 | InstX8632(Cfg *Func, InstKindX8632 Kind, SizeT Maxsrcs, Variable *Dest) |
| 273 | : InstTarget(Func, static_cast<InstKind>(Kind), Maxsrcs, Dest) {} |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 274 | ~InstX8632() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 275 | static bool isClassof(const Inst *Inst, InstKindX8632 MyKind) { |
| 276 | return Inst->getKind() == static_cast<InstKind>(MyKind); |
| 277 | } |
Jim Stichnoth | f79d2cb | 2015-03-23 15:10:54 -0700 | [diff] [blame] | 278 | // Most instructions that operate on vector arguments require vector |
| 279 | // memory operands to be fully aligned (16-byte alignment for PNaCl |
| 280 | // vector types). The stack frame layout and call ABI ensure proper |
| 281 | // alignment for stack operands, but memory operands (originating |
| 282 | // from load/store bitcode instructions) only have element-size |
| 283 | // alignment guarantees. This function validates that none of the |
| 284 | // operands is a memory operand of vector type, calling |
| 285 | // report_fatal_error() if one is found. This function should be |
| 286 | // called during emission, and maybe also in the ctor (as long as |
| 287 | // that fits the lowering style). |
| 288 | void validateVectorAddrMode() const { |
| 289 | if (getDest()) |
| 290 | validateVectorAddrModeOpnd(getDest()); |
| 291 | for (SizeT i = 0; i < getSrcSize(); ++i) { |
| 292 | validateVectorAddrModeOpnd(getSrc(i)); |
| 293 | } |
| 294 | } |
Jan Voung | 44c3a80 | 2015-03-27 16:29:08 -0700 | [diff] [blame] | 295 | |
Jim Stichnoth | f79d2cb | 2015-03-23 15:10:54 -0700 | [diff] [blame] | 296 | private: |
| 297 | static void validateVectorAddrModeOpnd(const Operand *Opnd) { |
| 298 | if (llvm::isa<OperandX8632Mem>(Opnd) && isVectorType(Opnd->getType())) { |
| 299 | llvm::report_fatal_error("Possible misaligned vector memory operation"); |
| 300 | } |
| 301 | } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Jan Voung | 7e1e485 | 2014-10-24 10:29:30 -0700 | [diff] [blame] | 304 | // InstX8632Label represents an intra-block label that is the target |
| 305 | // of an intra-block branch. The offset between the label and the |
| 306 | // branch must be fit into one byte (considered "near"). These are |
| 307 | // used for lowering i1 calculations, Select instructions, and 64-bit |
| 308 | // compares on a 32-bit architecture, without basic block splitting. |
| 309 | // Basic block splitting is not so desirable for several reasons, one |
| 310 | // of which is the impact on decisions based on whether a variable's |
| 311 | // live range spans multiple basic blocks. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 312 | // |
| 313 | // Intra-block control flow must be used with caution. Consider the |
| 314 | // sequence for "c = (a >= b ? x : y)". |
| 315 | // cmp a, b |
| 316 | // br lt, L1 |
| 317 | // mov c, x |
| 318 | // jmp L2 |
| 319 | // L1: |
| 320 | // mov c, y |
| 321 | // L2: |
| 322 | // |
| 323 | // Labels L1 and L2 are intra-block labels. Without knowledge of the |
| 324 | // intra-block control flow, liveness analysis will determine the "mov |
| 325 | // c, x" instruction to be dead. One way to prevent this is to insert |
| 326 | // a "FakeUse(c)" instruction anywhere between the two "mov c, ..." |
| 327 | // instructions, e.g.: |
| 328 | // |
| 329 | // cmp a, b |
| 330 | // br lt, L1 |
| 331 | // mov c, x |
| 332 | // jmp L2 |
| 333 | // FakeUse(c) |
| 334 | // L1: |
| 335 | // mov c, y |
| 336 | // L2: |
| 337 | // |
| 338 | // The down-side is that "mov c, x" can never be dead-code eliminated |
| 339 | // even if there are no uses of c. As unlikely as this situation is, |
| 340 | // it may be prevented by running dead code elimination before |
| 341 | // lowering. |
| 342 | class InstX8632Label : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 343 | InstX8632Label() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 344 | InstX8632Label(const InstX8632Label &) = delete; |
| 345 | InstX8632Label &operator=(const InstX8632Label &) = delete; |
| 346 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 347 | public: |
| 348 | static InstX8632Label *create(Cfg *Func, TargetX8632 *Target) { |
| 349 | return new (Func->allocate<InstX8632Label>()) InstX8632Label(Func, Target); |
| 350 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 351 | uint32_t getEmitInstCount() const override { return 0; } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 352 | IceString getName(const Cfg *Func) const; |
Jan Voung | 7e1e485 | 2014-10-24 10:29:30 -0700 | [diff] [blame] | 353 | SizeT getNumber() const { return Number; } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 354 | void emit(const Cfg *Func) const override; |
Jan Voung | 7e1e485 | 2014-10-24 10:29:30 -0700 | [diff] [blame] | 355 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 356 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 357 | |
| 358 | private: |
| 359 | InstX8632Label(Cfg *Func, TargetX8632 *Target); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 360 | ~InstX8632Label() override {} |
Jan Voung | 7e1e485 | 2014-10-24 10:29:30 -0700 | [diff] [blame] | 361 | SizeT Number; // used for unique label generation. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 362 | }; |
| 363 | |
| 364 | // Conditional and unconditional branch instruction. |
| 365 | class InstX8632Br : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 366 | InstX8632Br() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 367 | InstX8632Br(const InstX8632Br &) = delete; |
| 368 | InstX8632Br &operator=(const InstX8632Br &) = delete; |
| 369 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 370 | public: |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 371 | // Create a conditional branch to a node. |
| 372 | static InstX8632Br *create(Cfg *Func, CfgNode *TargetTrue, |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 373 | CfgNode *TargetFalse, CondX86::BrCond Condition) { |
Jim Stichnoth | 98712a3 | 2014-10-24 10:59:02 -0700 | [diff] [blame] | 374 | assert(Condition != CondX86::Br_None); |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 375 | const InstX8632Label *NoLabel = nullptr; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 376 | return new (Func->allocate<InstX8632Br>()) |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 377 | InstX8632Br(Func, TargetTrue, TargetFalse, NoLabel, Condition); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 378 | } |
| 379 | // Create an unconditional branch to a node. |
| 380 | static InstX8632Br *create(Cfg *Func, CfgNode *Target) { |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 381 | const CfgNode *NoCondTarget = nullptr; |
| 382 | const InstX8632Label *NoLabel = nullptr; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 383 | return new (Func->allocate<InstX8632Br>()) |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 384 | InstX8632Br(Func, NoCondTarget, Target, NoLabel, CondX86::Br_None); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 385 | } |
| 386 | // Create a non-terminator conditional branch to a node, with a |
| 387 | // fallthrough to the next instruction in the current node. This is |
| 388 | // used for switch lowering. |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 389 | static InstX8632Br *create(Cfg *Func, CfgNode *Target, |
| 390 | CondX86::BrCond Condition) { |
Jim Stichnoth | 98712a3 | 2014-10-24 10:59:02 -0700 | [diff] [blame] | 391 | assert(Condition != CondX86::Br_None); |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 392 | const CfgNode *NoUncondTarget = nullptr; |
| 393 | const InstX8632Label *NoLabel = nullptr; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 394 | return new (Func->allocate<InstX8632Br>()) |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 395 | InstX8632Br(Func, Target, NoUncondTarget, NoLabel, Condition); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 396 | } |
| 397 | // Create a conditional intra-block branch (or unconditional, if |
Jim Stichnoth | 1873560 | 2014-09-16 19:59:35 -0700 | [diff] [blame] | 398 | // Condition==Br_None) to a label in the current block. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 399 | static InstX8632Br *create(Cfg *Func, InstX8632Label *Label, |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 400 | CondX86::BrCond Condition) { |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 401 | const CfgNode *NoCondTarget = nullptr; |
| 402 | const CfgNode *NoUncondTarget = nullptr; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 403 | return new (Func->allocate<InstX8632Br>()) |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 404 | InstX8632Br(Func, NoCondTarget, NoUncondTarget, Label, Condition); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 405 | } |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 406 | const CfgNode *getTargetTrue() const { return TargetTrue; } |
| 407 | const CfgNode *getTargetFalse() const { return TargetFalse; } |
| 408 | bool optimizeBranch(const CfgNode *NextNode); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 409 | uint32_t getEmitInstCount() const override { |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 410 | uint32_t Sum = 0; |
Jim Stichnoth | 1873560 | 2014-09-16 19:59:35 -0700 | [diff] [blame] | 411 | if (Label) |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 412 | ++Sum; |
| 413 | if (getTargetTrue()) |
| 414 | ++Sum; |
Jim Stichnoth | 1873560 | 2014-09-16 19:59:35 -0700 | [diff] [blame] | 415 | if (getTargetFalse()) |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 416 | ++Sum; |
| 417 | return Sum; |
Jim Stichnoth | 1873560 | 2014-09-16 19:59:35 -0700 | [diff] [blame] | 418 | } |
Jim Stichnoth | 336f6c4 | 2014-10-30 15:01:31 -0700 | [diff] [blame] | 419 | bool isUnconditionalBranch() const override { |
| 420 | return !Label && Condition == CondX86::Br_None; |
| 421 | } |
| 422 | bool repointEdge(CfgNode *OldNode, CfgNode *NewNode) override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 423 | void emit(const Cfg *Func) const override; |
Jan Voung | 7e1e485 | 2014-10-24 10:29:30 -0700 | [diff] [blame] | 424 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 425 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 426 | static bool classof(const Inst *Inst) { return isClassof(Inst, Br); } |
| 427 | |
| 428 | private: |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 429 | InstX8632Br(Cfg *Func, const CfgNode *TargetTrue, const CfgNode *TargetFalse, |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 430 | const InstX8632Label *Label, CondX86::BrCond Condition); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 431 | ~InstX8632Br() override {} |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 432 | CondX86::BrCond Condition; |
Jim Stichnoth | ff9c706 | 2014-09-18 04:50:49 -0700 | [diff] [blame] | 433 | const CfgNode *TargetTrue; |
| 434 | const CfgNode *TargetFalse; |
| 435 | const InstX8632Label *Label; // Intra-block branch target |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 436 | }; |
| 437 | |
Jim Stichnoth | 9f42d8c | 2015-02-20 09:20:14 -0800 | [diff] [blame] | 438 | // Jump to a target outside this function, such as tailcall, nacljump, |
| 439 | // naclret, unreachable. This is different from a Branch instruction |
| 440 | // in that there is no intra-function control flow to represent. |
| 441 | class InstX8632Jmp : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 442 | InstX8632Jmp() = delete; |
Jim Stichnoth | 9f42d8c | 2015-02-20 09:20:14 -0800 | [diff] [blame] | 443 | InstX8632Jmp(const InstX8632Jmp &) = delete; |
| 444 | InstX8632Jmp &operator=(const InstX8632Jmp &) = delete; |
| 445 | |
| 446 | public: |
| 447 | static InstX8632Jmp *create(Cfg *Func, Operand *Target) { |
| 448 | return new (Func->allocate<InstX8632Jmp>()) InstX8632Jmp(Func, Target); |
| 449 | } |
| 450 | Operand *getJmpTarget() const { return getSrc(0); } |
| 451 | void emit(const Cfg *Func) const override; |
| 452 | void emitIAS(const Cfg *Func) const override; |
| 453 | void dump(const Cfg *Func) const override; |
| 454 | static bool classof(const Inst *Inst) { return isClassof(Inst, Jmp); } |
| 455 | |
| 456 | private: |
| 457 | InstX8632Jmp(Cfg *Func, Operand *Target); |
| 458 | }; |
| 459 | |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 460 | // AdjustStack instruction - subtracts esp by the given amount and |
| 461 | // updates the stack offset during code emission. |
| 462 | class InstX8632AdjustStack : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 463 | InstX8632AdjustStack() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 464 | InstX8632AdjustStack(const InstX8632AdjustStack &) = delete; |
| 465 | InstX8632AdjustStack &operator=(const InstX8632AdjustStack &) = delete; |
| 466 | |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 467 | public: |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 468 | static InstX8632AdjustStack *create(Cfg *Func, SizeT Amount, Variable *Esp) { |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 469 | return new (Func->allocate<InstX8632AdjustStack>()) |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 470 | InstX8632AdjustStack(Func, Amount, Esp); |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 471 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 472 | void emit(const Cfg *Func) const override; |
| 473 | void emitIAS(const Cfg *Func) const override; |
| 474 | void dump(const Cfg *Func) const override; |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 475 | static bool classof(const Inst *Inst) { return isClassof(Inst, Adjuststack); } |
| 476 | |
| 477 | private: |
Jim Stichnoth | 144cdce | 2014-09-22 16:02:59 -0700 | [diff] [blame] | 478 | InstX8632AdjustStack(Cfg *Func, SizeT Amount, Variable *Esp); |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 479 | SizeT Amount; |
| 480 | }; |
| 481 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 482 | // Call instruction. Arguments should have already been pushed. |
| 483 | class InstX8632Call : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 484 | InstX8632Call() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 485 | InstX8632Call(const InstX8632Call &) = delete; |
| 486 | InstX8632Call &operator=(const InstX8632Call &) = delete; |
| 487 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 488 | public: |
| 489 | static InstX8632Call *create(Cfg *Func, Variable *Dest, Operand *CallTarget) { |
| 490 | return new (Func->allocate<InstX8632Call>()) |
| 491 | InstX8632Call(Func, Dest, CallTarget); |
| 492 | } |
| 493 | Operand *getCallTarget() const { return getSrc(0); } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 494 | void emit(const Cfg *Func) const override; |
Jan Voung | 198b294 | 2014-10-16 09:40:02 -0700 | [diff] [blame] | 495 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 496 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 497 | static bool classof(const Inst *Inst) { return isClassof(Inst, Call); } |
| 498 | |
| 499 | private: |
| 500 | InstX8632Call(Cfg *Func, Variable *Dest, Operand *CallTarget); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 501 | ~InstX8632Call() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 502 | }; |
| 503 | |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 504 | // Emit a one-operand (GPR) instruction. |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 505 | void emitIASOpTyGPR(const Cfg *Func, Type Ty, const Operand *Var, |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 506 | const X8632::AssemblerX8632::GPREmitterOneOp &Emitter); |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 507 | |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 508 | // Instructions of the form x := op(x). |
| 509 | template <InstX8632::InstKindX8632 K> |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 510 | class InstX8632InplaceopGPR : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 511 | InstX8632InplaceopGPR() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 512 | InstX8632InplaceopGPR(const InstX8632InplaceopGPR &) = delete; |
| 513 | InstX8632InplaceopGPR &operator=(const InstX8632InplaceopGPR &) = delete; |
| 514 | |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 515 | public: |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 516 | static InstX8632InplaceopGPR *create(Cfg *Func, Operand *SrcDest) { |
| 517 | return new (Func->allocate<InstX8632InplaceopGPR>()) |
| 518 | InstX8632InplaceopGPR(Func, SrcDest); |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 519 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 520 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 521 | if (!ALLOW_DUMP) |
| 522 | return; |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 523 | Ostream &Str = Func->getContext()->getStrEmit(); |
| 524 | assert(getSrcSize() == 1); |
| 525 | Str << "\t" << Opcode << "\t"; |
| 526 | getSrc(0)->emit(Func); |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 527 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 528 | void emitIAS(const Cfg *Func) const override { |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 529 | assert(getSrcSize() == 1); |
| 530 | const Variable *Var = getDest(); |
| 531 | Type Ty = Var->getType(); |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 532 | emitIASOpTyGPR(Func, Ty, Var, Emitter); |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 533 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 534 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 535 | if (!ALLOW_DUMP) |
| 536 | return; |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 537 | Ostream &Str = Func->getContext()->getStrDump(); |
| 538 | dumpDest(Func); |
| 539 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 540 | dumpSources(Func); |
| 541 | } |
| 542 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 543 | |
| 544 | private: |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 545 | InstX8632InplaceopGPR(Cfg *Func, Operand *SrcDest) |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 546 | : InstX8632(Func, K, 1, llvm::dyn_cast<Variable>(SrcDest)) { |
| 547 | addSource(SrcDest); |
| 548 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 549 | ~InstX8632InplaceopGPR() override {} |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 550 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 551 | static const X8632::AssemblerX8632::GPREmitterOneOp Emitter; |
Jan Voung | 7fa813b | 2014-07-18 13:01:08 -0700 | [diff] [blame] | 552 | }; |
| 553 | |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 554 | // Emit a two-operand (GPR) instruction, where the dest operand is a |
| 555 | // Variable that's guaranteed to be a register. |
Jan Voung | 39d4aca | 2014-10-15 15:16:54 -0700 | [diff] [blame] | 556 | template <bool VarCanBeByte = true, bool SrcCanBeByte = true> |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 557 | void emitIASRegOpTyGPR(const Cfg *Func, Type Ty, const Variable *Dst, |
| 558 | const Operand *Src, |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 559 | const X8632::AssemblerX8632::GPREmitterRegOp &Emitter); |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 560 | |
Jan Voung | 39d4aca | 2014-10-15 15:16:54 -0700 | [diff] [blame] | 561 | // Instructions of the form x := op(y). |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 562 | template <InstX8632::InstKindX8632 K> |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 563 | class InstX8632UnaryopGPR : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 564 | InstX8632UnaryopGPR() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 565 | InstX8632UnaryopGPR(const InstX8632UnaryopGPR &) = delete; |
| 566 | InstX8632UnaryopGPR &operator=(const InstX8632UnaryopGPR &) = delete; |
| 567 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 568 | public: |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 569 | static InstX8632UnaryopGPR *create(Cfg *Func, Variable *Dest, Operand *Src) { |
| 570 | return new (Func->allocate<InstX8632UnaryopGPR>()) |
| 571 | InstX8632UnaryopGPR(Func, Dest, Src); |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 572 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 573 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 574 | if (!ALLOW_DUMP) |
| 575 | return; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 576 | Ostream &Str = Func->getContext()->getStrEmit(); |
| 577 | assert(getSrcSize() == 1); |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 578 | Type SrcTy = getSrc(0)->getType(); |
| 579 | Type DestTy = getDest()->getType(); |
| 580 | Str << "\t" << Opcode << getWidthString(SrcTy); |
| 581 | // Movsx and movzx need both the source and dest type width letter |
| 582 | // to define the operation. The other unary operations have the |
| 583 | // same source and dest type and as a result need only one letter. |
| 584 | if (SrcTy != DestTy) |
| 585 | Str << getWidthString(DestTy); |
| 586 | Str << "\t"; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 587 | getSrc(0)->emit(Func); |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 588 | Str << ", "; |
| 589 | getDest()->emit(Func); |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 590 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 591 | void emitIAS(const Cfg *Func) const override { |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 592 | assert(getSrcSize() == 1); |
| 593 | const Variable *Var = getDest(); |
| 594 | Type Ty = Var->getType(); |
| 595 | const Operand *Src = getSrc(0); |
| 596 | emitIASRegOpTyGPR(Func, Ty, Var, Src, Emitter); |
| 597 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 598 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 599 | if (!ALLOW_DUMP) |
| 600 | return; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 601 | Ostream &Str = Func->getContext()->getStrDump(); |
| 602 | dumpDest(Func); |
Jan Voung | 39d4aca | 2014-10-15 15:16:54 -0700 | [diff] [blame] | 603 | Str << " = " << Opcode << "." << getSrc(0)->getType() << " "; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 604 | dumpSources(Func); |
| 605 | } |
| 606 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 607 | |
| 608 | private: |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 609 | InstX8632UnaryopGPR(Cfg *Func, Variable *Dest, Operand *Src) |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 610 | : InstX8632(Func, K, 1, Dest) { |
| 611 | addSource(Src); |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 612 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 613 | ~InstX8632UnaryopGPR() override {} |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 614 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 615 | static const X8632::AssemblerX8632::GPREmitterRegOp Emitter; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 616 | }; |
| 617 | |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 618 | void emitIASRegOpTyXMM(const Cfg *Func, Type Ty, const Variable *Var, |
| 619 | const Operand *Src, |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 620 | const X8632::AssemblerX8632::XmmEmitterRegOp &Emitter); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 621 | |
| 622 | template <InstX8632::InstKindX8632 K> |
| 623 | class InstX8632UnaryopXmm : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 624 | InstX8632UnaryopXmm() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 625 | InstX8632UnaryopXmm(const InstX8632UnaryopXmm &) = delete; |
| 626 | InstX8632UnaryopXmm &operator=(const InstX8632UnaryopXmm &) = delete; |
| 627 | |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 628 | public: |
| 629 | static InstX8632UnaryopXmm *create(Cfg *Func, Variable *Dest, Operand *Src) { |
| 630 | return new (Func->allocate<InstX8632UnaryopXmm>()) |
| 631 | InstX8632UnaryopXmm(Func, Dest, Src); |
| 632 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 633 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 634 | if (!ALLOW_DUMP) |
| 635 | return; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 636 | Ostream &Str = Func->getContext()->getStrEmit(); |
| 637 | assert(getSrcSize() == 1); |
| 638 | Str << "\t" << Opcode << "\t"; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 639 | getSrc(0)->emit(Func); |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 640 | Str << ", "; |
| 641 | getDest()->emit(Func); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 642 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 643 | void emitIAS(const Cfg *Func) const override { |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 644 | Type Ty = getDest()->getType(); |
| 645 | assert(getSrcSize() == 1); |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 646 | emitIASRegOpTyXMM(Func, Ty, getDest(), getSrc(0), Emitter); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 647 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 648 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 649 | if (!ALLOW_DUMP) |
| 650 | return; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 651 | Ostream &Str = Func->getContext()->getStrDump(); |
| 652 | dumpDest(Func); |
| 653 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 654 | dumpSources(Func); |
| 655 | } |
| 656 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 657 | |
| 658 | private: |
| 659 | InstX8632UnaryopXmm(Cfg *Func, Variable *Dest, Operand *Src) |
| 660 | : InstX8632(Func, K, 1, Dest) { |
| 661 | addSource(Src); |
| 662 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 663 | ~InstX8632UnaryopXmm() override {} |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 664 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 665 | static const X8632::AssemblerX8632::XmmEmitterRegOp Emitter; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 666 | }; |
| 667 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 668 | // See the definition of emitTwoAddress() for a description of |
| 669 | // ShiftHack. |
| 670 | void emitTwoAddress(const char *Opcode, const Inst *Inst, const Cfg *Func, |
| 671 | bool ShiftHack = false); |
| 672 | |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 673 | void emitIASGPRShift(const Cfg *Func, Type Ty, const Variable *Var, |
| 674 | const Operand *Src, |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 675 | const X8632::AssemblerX8632::GPREmitterShiftOp &Emitter); |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 676 | |
| 677 | template <InstX8632::InstKindX8632 K> |
| 678 | class InstX8632BinopGPRShift : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 679 | InstX8632BinopGPRShift() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 680 | InstX8632BinopGPRShift(const InstX8632BinopGPRShift &) = delete; |
| 681 | InstX8632BinopGPRShift &operator=(const InstX8632BinopGPRShift &) = delete; |
| 682 | |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 683 | public: |
| 684 | // Create a binary-op GPR shift instruction. |
| 685 | static InstX8632BinopGPRShift *create(Cfg *Func, Variable *Dest, |
| 686 | Operand *Source) { |
| 687 | return new (Func->allocate<InstX8632BinopGPRShift>()) |
| 688 | InstX8632BinopGPRShift(Func, Dest, Source); |
| 689 | } |
| 690 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 691 | if (!ALLOW_DUMP) |
| 692 | return; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 693 | const bool ShiftHack = true; |
| 694 | emitTwoAddress(Opcode, this, Func, ShiftHack); |
| 695 | } |
| 696 | void emitIAS(const Cfg *Func) const override { |
| 697 | Type Ty = getDest()->getType(); |
| 698 | assert(getSrcSize() == 2); |
| 699 | emitIASGPRShift(Func, Ty, getDest(), getSrc(1), Emitter); |
| 700 | } |
| 701 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 702 | if (!ALLOW_DUMP) |
| 703 | return; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 704 | Ostream &Str = Func->getContext()->getStrDump(); |
| 705 | dumpDest(Func); |
| 706 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 707 | dumpSources(Func); |
| 708 | } |
| 709 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 710 | |
| 711 | private: |
| 712 | InstX8632BinopGPRShift(Cfg *Func, Variable *Dest, Operand *Source) |
| 713 | : InstX8632(Func, K, 2, Dest) { |
| 714 | addSource(Dest); |
| 715 | addSource(Source); |
| 716 | } |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 717 | ~InstX8632BinopGPRShift() override {} |
| 718 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 719 | static const X8632::AssemblerX8632::GPREmitterShiftOp Emitter; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 720 | }; |
| 721 | |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 722 | template <InstX8632::InstKindX8632 K> |
| 723 | class InstX8632BinopGPR : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 724 | InstX8632BinopGPR() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 725 | InstX8632BinopGPR(const InstX8632BinopGPR &) = delete; |
| 726 | InstX8632BinopGPR &operator=(const InstX8632BinopGPR &) = delete; |
| 727 | |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 728 | public: |
| 729 | // Create an ordinary binary-op instruction like add or sub. |
| 730 | static InstX8632BinopGPR *create(Cfg *Func, Variable *Dest, Operand *Source) { |
| 731 | return new (Func->allocate<InstX8632BinopGPR>()) |
| 732 | InstX8632BinopGPR(Func, Dest, Source); |
| 733 | } |
| 734 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 735 | if (!ALLOW_DUMP) |
| 736 | return; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 737 | const bool ShiftHack = false; |
| 738 | emitTwoAddress(Opcode, this, Func, ShiftHack); |
| 739 | } |
| 740 | void emitIAS(const Cfg *Func) const override { |
| 741 | Type Ty = getDest()->getType(); |
| 742 | assert(getSrcSize() == 2); |
| 743 | emitIASRegOpTyGPR(Func, Ty, getDest(), getSrc(1), Emitter); |
| 744 | } |
| 745 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 746 | if (!ALLOW_DUMP) |
| 747 | return; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 748 | Ostream &Str = Func->getContext()->getStrDump(); |
| 749 | dumpDest(Func); |
| 750 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 751 | dumpSources(Func); |
| 752 | } |
| 753 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 754 | |
| 755 | private: |
| 756 | InstX8632BinopGPR(Cfg *Func, Variable *Dest, Operand *Source) |
| 757 | : InstX8632(Func, K, 2, Dest) { |
| 758 | addSource(Dest); |
| 759 | addSource(Source); |
| 760 | } |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 761 | ~InstX8632BinopGPR() override {} |
| 762 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 763 | static const X8632::AssemblerX8632::GPREmitterRegOp Emitter; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 764 | }; |
| 765 | |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 766 | template <InstX8632::InstKindX8632 K, bool NeedsElementType> |
| 767 | class InstX8632BinopXmm : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 768 | InstX8632BinopXmm() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 769 | InstX8632BinopXmm(const InstX8632BinopXmm &) = delete; |
| 770 | InstX8632BinopXmm &operator=(const InstX8632BinopXmm &) = delete; |
| 771 | |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 772 | public: |
| 773 | // Create an XMM binary-op instruction like addss or addps. |
| 774 | static InstX8632BinopXmm *create(Cfg *Func, Variable *Dest, Operand *Source) { |
| 775 | return new (Func->allocate<InstX8632BinopXmm>()) |
| 776 | InstX8632BinopXmm(Func, Dest, Source); |
| 777 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 778 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 779 | if (!ALLOW_DUMP) |
| 780 | return; |
Jim Stichnoth | f79d2cb | 2015-03-23 15:10:54 -0700 | [diff] [blame] | 781 | validateVectorAddrMode(); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 782 | const bool ShiftHack = false; |
| 783 | emitTwoAddress(Opcode, this, Func, ShiftHack); |
| 784 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 785 | void emitIAS(const Cfg *Func) const override { |
Jim Stichnoth | f79d2cb | 2015-03-23 15:10:54 -0700 | [diff] [blame] | 786 | validateVectorAddrMode(); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 787 | Type Ty = getDest()->getType(); |
| 788 | if (NeedsElementType) |
| 789 | Ty = typeElementType(Ty); |
| 790 | assert(getSrcSize() == 2); |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 791 | emitIASRegOpTyXMM(Func, Ty, getDest(), getSrc(1), Emitter); |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 792 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 793 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 794 | if (!ALLOW_DUMP) |
| 795 | return; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 796 | Ostream &Str = Func->getContext()->getStrDump(); |
| 797 | dumpDest(Func); |
| 798 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 799 | dumpSources(Func); |
| 800 | } |
| 801 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 802 | |
| 803 | private: |
| 804 | InstX8632BinopXmm(Cfg *Func, Variable *Dest, Operand *Source) |
| 805 | : InstX8632(Func, K, 2, Dest) { |
| 806 | addSource(Dest); |
| 807 | addSource(Source); |
| 808 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 809 | ~InstX8632BinopXmm() override {} |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 810 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 811 | static const X8632::AssemblerX8632::XmmEmitterRegOp Emitter; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 812 | }; |
| 813 | |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 814 | void emitIASXmmShift(const Cfg *Func, Type Ty, const Variable *Var, |
| 815 | const Operand *Src, |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 816 | const X8632::AssemblerX8632::XmmEmitterShiftOp &Emitter); |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 817 | |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 818 | template <InstX8632::InstKindX8632 K, bool AllowAllTypes = false> |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 819 | class InstX8632BinopXmmShift : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 820 | InstX8632BinopXmmShift() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 821 | InstX8632BinopXmmShift(const InstX8632BinopXmmShift &) = delete; |
| 822 | InstX8632BinopXmmShift &operator=(const InstX8632BinopXmmShift &) = delete; |
| 823 | |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 824 | public: |
| 825 | // Create an XMM binary-op shift operation. |
| 826 | static InstX8632BinopXmmShift *create(Cfg *Func, Variable *Dest, |
| 827 | Operand *Source) { |
| 828 | return new (Func->allocate<InstX8632BinopXmmShift>()) |
| 829 | InstX8632BinopXmmShift(Func, Dest, Source); |
| 830 | } |
| 831 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 832 | if (!ALLOW_DUMP) |
| 833 | return; |
Jim Stichnoth | f79d2cb | 2015-03-23 15:10:54 -0700 | [diff] [blame] | 834 | validateVectorAddrMode(); |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 835 | const bool ShiftHack = false; |
| 836 | emitTwoAddress(Opcode, this, Func, ShiftHack); |
| 837 | } |
| 838 | void emitIAS(const Cfg *Func) const override { |
Jim Stichnoth | f79d2cb | 2015-03-23 15:10:54 -0700 | [diff] [blame] | 839 | validateVectorAddrMode(); |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 840 | Type Ty = getDest()->getType(); |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 841 | assert(AllowAllTypes || isVectorType(Ty)); |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 842 | Type ElementTy = typeElementType(Ty); |
| 843 | assert(getSrcSize() == 2); |
| 844 | emitIASXmmShift(Func, ElementTy, getDest(), getSrc(1), Emitter); |
| 845 | } |
| 846 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 847 | if (!ALLOW_DUMP) |
| 848 | return; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 849 | Ostream &Str = Func->getContext()->getStrDump(); |
| 850 | dumpDest(Func); |
| 851 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 852 | dumpSources(Func); |
| 853 | } |
| 854 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 855 | |
| 856 | private: |
| 857 | InstX8632BinopXmmShift(Cfg *Func, Variable *Dest, Operand *Source) |
| 858 | : InstX8632(Func, K, 2, Dest) { |
| 859 | addSource(Dest); |
| 860 | addSource(Source); |
| 861 | } |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 862 | ~InstX8632BinopXmmShift() override {} |
| 863 | static const char *Opcode; |
Jan Voung | 90ccc3f | 2015-04-30 14:15:10 -0700 | [diff] [blame] | 864 | static const X8632::AssemblerX8632::XmmEmitterShiftOp Emitter; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 865 | }; |
| 866 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 867 | template <InstX8632::InstKindX8632 K> class InstX8632Ternop : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 868 | InstX8632Ternop() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 869 | InstX8632Ternop(const InstX8632Ternop &) = delete; |
| 870 | InstX8632Ternop &operator=(const InstX8632Ternop &) = delete; |
| 871 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 872 | public: |
| 873 | // Create a ternary-op instruction like div or idiv. |
| 874 | static InstX8632Ternop *create(Cfg *Func, Variable *Dest, Operand *Source1, |
| 875 | Operand *Source2) { |
| 876 | return new (Func->allocate<InstX8632Ternop>()) |
| 877 | InstX8632Ternop(Func, Dest, Source1, Source2); |
| 878 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 879 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 880 | if (!ALLOW_DUMP) |
| 881 | return; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 882 | Ostream &Str = Func->getContext()->getStrEmit(); |
| 883 | assert(getSrcSize() == 3); |
| 884 | Str << "\t" << Opcode << "\t"; |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 885 | getSrc(2)->emit(Func); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 886 | Str << ", "; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 887 | getSrc(1)->emit(Func); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 888 | Str << ", "; |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 889 | getDest()->emit(Func); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 890 | } |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 891 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 892 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 893 | if (!ALLOW_DUMP) |
| 894 | return; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 895 | Ostream &Str = Func->getContext()->getStrDump(); |
| 896 | dumpDest(Func); |
| 897 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 898 | dumpSources(Func); |
| 899 | } |
| 900 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 901 | |
| 902 | private: |
| 903 | InstX8632Ternop(Cfg *Func, Variable *Dest, Operand *Source1, Operand *Source2) |
| 904 | : InstX8632(Func, K, 3, Dest) { |
| 905 | addSource(Dest); |
| 906 | addSource(Source1); |
| 907 | addSource(Source2); |
| 908 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 909 | ~InstX8632Ternop() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 910 | static const char *Opcode; |
| 911 | }; |
| 912 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 913 | // Instructions of the form x := y op z |
| 914 | template <InstX8632::InstKindX8632 K> |
| 915 | class InstX8632ThreeAddressop : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 916 | InstX8632ThreeAddressop() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 917 | InstX8632ThreeAddressop(const InstX8632ThreeAddressop &) = delete; |
| 918 | InstX8632ThreeAddressop &operator=(const InstX8632ThreeAddressop &) = delete; |
| 919 | |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 920 | public: |
| 921 | static InstX8632ThreeAddressop *create(Cfg *Func, Variable *Dest, |
| 922 | Operand *Source0, Operand *Source1) { |
| 923 | return new (Func->allocate<InstX8632ThreeAddressop>()) |
| 924 | InstX8632ThreeAddressop(Func, Dest, Source0, Source1); |
| 925 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 926 | void emit(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 927 | if (!ALLOW_DUMP) |
| 928 | return; |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 929 | Ostream &Str = Func->getContext()->getStrEmit(); |
| 930 | assert(getSrcSize() == 2); |
| 931 | Str << "\t" << Opcode << "\t"; |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 932 | getSrc(1)->emit(Func); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 933 | Str << ", "; |
| 934 | getSrc(0)->emit(Func); |
| 935 | Str << ", "; |
Jim Stichnoth | bca2f65 | 2014-11-01 10:13:54 -0700 | [diff] [blame] | 936 | getDest()->emit(Func); |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 937 | } |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 938 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 939 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 940 | if (!ALLOW_DUMP) |
| 941 | return; |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 942 | Ostream &Str = Func->getContext()->getStrDump(); |
| 943 | dumpDest(Func); |
| 944 | Str << " = " << Opcode << "." << getDest()->getType() << " "; |
| 945 | dumpSources(Func); |
| 946 | } |
| 947 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 948 | |
| 949 | private: |
| 950 | InstX8632ThreeAddressop(Cfg *Func, Variable *Dest, Operand *Source0, |
| 951 | Operand *Source1) |
| 952 | : InstX8632(Func, K, 2, Dest) { |
| 953 | addSource(Source0); |
| 954 | addSource(Source1); |
| 955 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 956 | ~InstX8632ThreeAddressop() override {} |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 957 | static const char *Opcode; |
| 958 | }; |
| 959 | |
Matt Wala | e58178a | 2014-08-12 13:15:04 -0700 | [diff] [blame] | 960 | // Base class for assignment instructions |
| 961 | template <InstX8632::InstKindX8632 K> |
| 962 | class InstX8632Movlike : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 963 | InstX8632Movlike() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 964 | InstX8632Movlike(const InstX8632Movlike &) = delete; |
| 965 | InstX8632Movlike &operator=(const InstX8632Movlike &) = delete; |
| 966 | |
Matt Wala | e58178a | 2014-08-12 13:15:04 -0700 | [diff] [blame] | 967 | public: |
| 968 | static InstX8632Movlike *create(Cfg *Func, Variable *Dest, Operand *Source) { |
| 969 | return new (Func->allocate<InstX8632Movlike>()) |
| 970 | InstX8632Movlike(Func, Dest, Source); |
| 971 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 972 | bool isRedundantAssign() const override { |
Matt Wala | e58178a | 2014-08-12 13:15:04 -0700 | [diff] [blame] | 973 | return checkForRedundantAssign(getDest(), getSrc(0)); |
| 974 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 975 | bool isSimpleAssign() const override { return true; } |
| 976 | void emit(const Cfg *Func) const override; |
Jan Voung | fe14fb8 | 2014-10-13 15:56:32 -0700 | [diff] [blame] | 977 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 978 | void dump(const Cfg *Func) const override { |
Karl Schimpf | b6c96af | 2014-11-17 10:58:39 -0800 | [diff] [blame] | 979 | if (!ALLOW_DUMP) |
| 980 | return; |
Matt Wala | e58178a | 2014-08-12 13:15:04 -0700 | [diff] [blame] | 981 | Ostream &Str = Func->getContext()->getStrDump(); |
| 982 | Str << Opcode << "." << getDest()->getType() << " "; |
| 983 | dumpDest(Func); |
| 984 | Str << ", "; |
| 985 | dumpSources(Func); |
| 986 | } |
| 987 | static bool classof(const Inst *Inst) { return isClassof(Inst, K); } |
| 988 | |
| 989 | private: |
| 990 | InstX8632Movlike(Cfg *Func, Variable *Dest, Operand *Source) |
| 991 | : InstX8632(Func, K, 1, Dest) { |
| 992 | addSource(Source); |
| 993 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 994 | ~InstX8632Movlike() override {} |
Matt Wala | e58178a | 2014-08-12 13:15:04 -0700 | [diff] [blame] | 995 | |
| 996 | static const char *Opcode; |
| 997 | }; |
| 998 | |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 999 | typedef InstX8632InplaceopGPR<InstX8632::Bswap> InstX8632Bswap; |
| 1000 | typedef InstX8632InplaceopGPR<InstX8632::Neg> InstX8632Neg; |
| 1001 | typedef InstX8632UnaryopGPR<InstX8632::Bsf> InstX8632Bsf; |
| 1002 | typedef InstX8632UnaryopGPR<InstX8632::Bsr> InstX8632Bsr; |
| 1003 | typedef InstX8632UnaryopGPR<InstX8632::Lea> InstX8632Lea; |
Matt Wala | 51e8cfb | 2014-08-08 08:39:40 -0700 | [diff] [blame] | 1004 | // Cbwdq instruction - wrapper for cbw, cwd, and cdq |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 1005 | typedef InstX8632UnaryopGPR<InstX8632::Cbwdq> InstX8632Cbwdq; |
Jan Voung | 39d4aca | 2014-10-15 15:16:54 -0700 | [diff] [blame] | 1006 | typedef InstX8632UnaryopGPR<InstX8632::Movsx> InstX8632Movsx; |
| 1007 | typedef InstX8632UnaryopGPR<InstX8632::Movzx> InstX8632Movzx; |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 1008 | typedef InstX8632UnaryopXmm<InstX8632::Movd> InstX8632Movd; |
| 1009 | typedef InstX8632UnaryopXmm<InstX8632::Sqrtss> InstX8632Sqrtss; |
Matt Wala | e58178a | 2014-08-12 13:15:04 -0700 | [diff] [blame] | 1010 | // Move/assignment instruction - wrapper for mov/movss/movsd. |
| 1011 | typedef InstX8632Movlike<InstX8632::Mov> InstX8632Mov; |
| 1012 | // Move packed - copy 128 bit values between XMM registers, or mem128 |
| 1013 | // and XMM registers. |
| 1014 | typedef InstX8632Movlike<InstX8632::Movp> InstX8632Movp; |
| 1015 | // Movq - copy between XMM registers, or mem64 and XMM registers. |
| 1016 | typedef InstX8632Movlike<InstX8632::Movq> InstX8632Movq; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1017 | typedef InstX8632BinopGPR<InstX8632::Add> InstX8632Add; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1018 | typedef InstX8632BinopXmm<InstX8632::Addps, true> InstX8632Addps; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1019 | typedef InstX8632BinopGPR<InstX8632::Adc> InstX8632Adc; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1020 | typedef InstX8632BinopXmm<InstX8632::Addss, false> InstX8632Addss; |
| 1021 | typedef InstX8632BinopXmm<InstX8632::Padd, true> InstX8632Padd; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1022 | typedef InstX8632BinopGPR<InstX8632::Sub> InstX8632Sub; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1023 | typedef InstX8632BinopXmm<InstX8632::Subps, true> InstX8632Subps; |
| 1024 | typedef InstX8632BinopXmm<InstX8632::Subss, false> InstX8632Subss; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1025 | typedef InstX8632BinopGPR<InstX8632::Sbb> InstX8632Sbb; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1026 | typedef InstX8632BinopXmm<InstX8632::Psub, true> InstX8632Psub; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1027 | typedef InstX8632BinopGPR<InstX8632::And> InstX8632And; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1028 | typedef InstX8632BinopXmm<InstX8632::Pand, false> InstX8632Pand; |
| 1029 | typedef InstX8632BinopXmm<InstX8632::Pandn, false> InstX8632Pandn; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1030 | typedef InstX8632BinopGPR<InstX8632::Or> InstX8632Or; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1031 | typedef InstX8632BinopXmm<InstX8632::Por, false> InstX8632Por; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1032 | typedef InstX8632BinopGPR<InstX8632::Xor> InstX8632Xor; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1033 | typedef InstX8632BinopXmm<InstX8632::Pxor, false> InstX8632Pxor; |
Jan Voung | 0ac50dc | 2014-09-30 08:36:06 -0700 | [diff] [blame] | 1034 | typedef InstX8632BinopGPR<InstX8632::Imul> InstX8632Imul; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1035 | typedef InstX8632BinopXmm<InstX8632::Mulps, true> InstX8632Mulps; |
| 1036 | typedef InstX8632BinopXmm<InstX8632::Mulss, false> InstX8632Mulss; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 1037 | typedef InstX8632BinopXmm<InstX8632::Pmull, true> InstX8632Pmull; |
Jan Voung | 8acded0 | 2014-09-22 18:02:25 -0700 | [diff] [blame] | 1038 | typedef InstX8632BinopXmm<InstX8632::Pmuludq, false> InstX8632Pmuludq; |
| 1039 | typedef InstX8632BinopXmm<InstX8632::Divps, true> InstX8632Divps; |
| 1040 | typedef InstX8632BinopXmm<InstX8632::Divss, false> InstX8632Divss; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 1041 | typedef InstX8632BinopGPRShift<InstX8632::Rol> InstX8632Rol; |
| 1042 | typedef InstX8632BinopGPRShift<InstX8632::Shl> InstX8632Shl; |
| 1043 | typedef InstX8632BinopXmmShift<InstX8632::Psll> InstX8632Psll; |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 1044 | typedef InstX8632BinopXmmShift<InstX8632::Psrl, true> InstX8632Psrl; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 1045 | typedef InstX8632BinopGPRShift<InstX8632::Shr> InstX8632Shr; |
| 1046 | typedef InstX8632BinopGPRShift<InstX8632::Sar> InstX8632Sar; |
| 1047 | typedef InstX8632BinopXmmShift<InstX8632::Psra> InstX8632Psra; |
Jan Voung | 0ac50dc | 2014-09-30 08:36:06 -0700 | [diff] [blame] | 1048 | typedef InstX8632BinopXmm<InstX8632::Pcmpeq, true> InstX8632Pcmpeq; |
| 1049 | typedef InstX8632BinopXmm<InstX8632::Pcmpgt, true> InstX8632Pcmpgt; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1050 | // movss is only a binary operation when the source and dest |
| 1051 | // operands are both registers (the high bits of dest are left untouched). |
| 1052 | // In other cases, it behaves like a copy (mov-like) operation (and the |
| 1053 | // high bits of dest are cleared). |
| 1054 | // InstX8632Movss will assert that both its source and dest operands are |
| 1055 | // registers, so the lowering code should use _mov instead of _movss |
| 1056 | // in cases where a copy operation is intended. |
| 1057 | typedef InstX8632BinopXmm<InstX8632::MovssRegs, false> InstX8632MovssRegs; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1058 | typedef InstX8632Ternop<InstX8632::Idiv> InstX8632Idiv; |
| 1059 | typedef InstX8632Ternop<InstX8632::Div> InstX8632Div; |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 1060 | typedef InstX8632Ternop<InstX8632::Insertps> InstX8632Insertps; |
| 1061 | typedef InstX8632Ternop<InstX8632::Pinsr> InstX8632Pinsr; |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 1062 | typedef InstX8632Ternop<InstX8632::Shufps> InstX8632Shufps; |
Matt Wala | 0a45051 | 2014-07-30 12:44:39 -0700 | [diff] [blame] | 1063 | typedef InstX8632Ternop<InstX8632::Blendvps> InstX8632Blendvps; |
| 1064 | typedef InstX8632Ternop<InstX8632::Pblendvb> InstX8632Pblendvb; |
| 1065 | typedef InstX8632ThreeAddressop<InstX8632::Pextr> InstX8632Pextr; |
Matt Wala | 4988923 | 2014-07-18 12:45:09 -0700 | [diff] [blame] | 1066 | typedef InstX8632ThreeAddressop<InstX8632::Pshufd> InstX8632Pshufd; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1067 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1068 | // Base class for a lockable x86-32 instruction (emits a locked prefix). |
| 1069 | class InstX8632Lockable : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1070 | InstX8632Lockable() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1071 | InstX8632Lockable(const InstX8632Lockable &) = delete; |
| 1072 | InstX8632Lockable &operator=(const InstX8632Lockable &) = delete; |
| 1073 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1074 | protected: |
| 1075 | bool Locked; |
| 1076 | |
| 1077 | InstX8632Lockable(Cfg *Func, InstKindX8632 Kind, SizeT Maxsrcs, |
| 1078 | Variable *Dest, bool Locked) |
| 1079 | : InstX8632(Func, Kind, Maxsrcs, Dest), Locked(Locked) { |
| 1080 | // Assume that such instructions are used for Atomics and be careful |
| 1081 | // with optimizations. |
| 1082 | HasSideEffects = Locked; |
| 1083 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1084 | ~InstX8632Lockable() override {} |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1085 | }; |
| 1086 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1087 | // Mul instruction - unsigned multiply. |
| 1088 | class InstX8632Mul : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1089 | InstX8632Mul() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1090 | InstX8632Mul(const InstX8632Mul &) = delete; |
| 1091 | InstX8632Mul &operator=(const InstX8632Mul &) = delete; |
| 1092 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1093 | public: |
| 1094 | static InstX8632Mul *create(Cfg *Func, Variable *Dest, Variable *Source1, |
| 1095 | Operand *Source2) { |
| 1096 | return new (Func->allocate<InstX8632Mul>()) |
| 1097 | InstX8632Mul(Func, Dest, Source1, Source2); |
| 1098 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1099 | void emit(const Cfg *Func) const override; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1100 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1101 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1102 | static bool classof(const Inst *Inst) { return isClassof(Inst, Mul); } |
| 1103 | |
| 1104 | private: |
| 1105 | InstX8632Mul(Cfg *Func, Variable *Dest, Variable *Source1, Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1106 | ~InstX8632Mul() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1107 | }; |
| 1108 | |
Jan Voung | 8835576 | 2014-11-01 09:40:20 -0700 | [diff] [blame] | 1109 | // Shld instruction - shift across a pair of operands. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1110 | class InstX8632Shld : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1111 | InstX8632Shld() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1112 | InstX8632Shld(const InstX8632Shld &) = delete; |
| 1113 | InstX8632Shld &operator=(const InstX8632Shld &) = delete; |
| 1114 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1115 | public: |
| 1116 | static InstX8632Shld *create(Cfg *Func, Variable *Dest, Variable *Source1, |
| 1117 | Variable *Source2) { |
| 1118 | return new (Func->allocate<InstX8632Shld>()) |
| 1119 | InstX8632Shld(Func, Dest, Source1, Source2); |
| 1120 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1121 | void emit(const Cfg *Func) const override; |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 1122 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1123 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1124 | static bool classof(const Inst *Inst) { return isClassof(Inst, Shld); } |
| 1125 | |
| 1126 | private: |
| 1127 | InstX8632Shld(Cfg *Func, Variable *Dest, Variable *Source1, |
| 1128 | Variable *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1129 | ~InstX8632Shld() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1130 | }; |
| 1131 | |
Jan Voung | 8835576 | 2014-11-01 09:40:20 -0700 | [diff] [blame] | 1132 | // Shrd instruction - shift across a pair of operands. |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1133 | class InstX8632Shrd : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1134 | InstX8632Shrd() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1135 | InstX8632Shrd(const InstX8632Shrd &) = delete; |
| 1136 | InstX8632Shrd &operator=(const InstX8632Shrd &) = delete; |
| 1137 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1138 | public: |
| 1139 | static InstX8632Shrd *create(Cfg *Func, Variable *Dest, Variable *Source1, |
| 1140 | Variable *Source2) { |
| 1141 | return new (Func->allocate<InstX8632Shrd>()) |
| 1142 | InstX8632Shrd(Func, Dest, Source1, Source2); |
| 1143 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1144 | void emit(const Cfg *Func) const override; |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 1145 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1146 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1147 | static bool classof(const Inst *Inst) { return isClassof(Inst, Shrd); } |
| 1148 | |
| 1149 | private: |
| 1150 | InstX8632Shrd(Cfg *Func, Variable *Dest, Variable *Source1, |
| 1151 | Variable *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1152 | ~InstX8632Shrd() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1153 | }; |
| 1154 | |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 1155 | // Conditional move instruction. |
| 1156 | class InstX8632Cmov : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1157 | InstX8632Cmov() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1158 | InstX8632Cmov(const InstX8632Cmov &) = delete; |
| 1159 | InstX8632Cmov &operator=(const InstX8632Cmov &) = delete; |
| 1160 | |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 1161 | public: |
| 1162 | static InstX8632Cmov *create(Cfg *Func, Variable *Dest, Operand *Source, |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 1163 | CondX86::BrCond Cond) { |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 1164 | return new (Func->allocate<InstX8632Cmov>()) |
| 1165 | InstX8632Cmov(Func, Dest, Source, Cond); |
| 1166 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1167 | void emit(const Cfg *Func) const override; |
| 1168 | void emitIAS(const Cfg *Func) const override; |
| 1169 | void dump(const Cfg *Func) const override; |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 1170 | static bool classof(const Inst *Inst) { return isClassof(Inst, Cmov); } |
| 1171 | |
| 1172 | private: |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 1173 | InstX8632Cmov(Cfg *Func, Variable *Dest, Operand *Source, |
| 1174 | CondX86::BrCond Cond); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1175 | ~InstX8632Cmov() override {} |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 1176 | |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 1177 | CondX86::BrCond Condition; |
Jan Voung | e4da26f | 2014-07-15 17:52:39 -0700 | [diff] [blame] | 1178 | }; |
| 1179 | |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1180 | // Cmpps instruction - compare packed singled-precision floating point |
| 1181 | // values |
| 1182 | class InstX8632Cmpps : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1183 | InstX8632Cmpps() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1184 | InstX8632Cmpps(const InstX8632Cmpps &) = delete; |
| 1185 | InstX8632Cmpps &operator=(const InstX8632Cmpps &) = delete; |
| 1186 | |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1187 | public: |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1188 | static InstX8632Cmpps *create(Cfg *Func, Variable *Dest, Operand *Source, |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 1189 | CondX86::CmppsCond Condition) { |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1190 | return new (Func->allocate<InstX8632Cmpps>()) |
| 1191 | InstX8632Cmpps(Func, Dest, Source, Condition); |
| 1192 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1193 | void emit(const Cfg *Func) const override; |
| 1194 | void emitIAS(const Cfg *Func) const override; |
| 1195 | void dump(const Cfg *Func) const override; |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1196 | static bool classof(const Inst *Inst) { return isClassof(Inst, Cmpps); } |
| 1197 | |
| 1198 | private: |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 1199 | InstX8632Cmpps(Cfg *Func, Variable *Dest, Operand *Source, |
| 1200 | CondX86::CmppsCond Cond); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1201 | ~InstX8632Cmpps() override {} |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1202 | |
Jan Voung | bd385e4 | 2014-09-18 18:18:10 -0700 | [diff] [blame] | 1203 | CondX86::CmppsCond Condition; |
Matt Wala | ce0ca8f | 2014-07-24 12:34:20 -0700 | [diff] [blame] | 1204 | }; |
| 1205 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1206 | // Cmpxchg instruction - cmpxchg <dest>, <desired> will compare if <dest> |
| 1207 | // equals eax. If so, the ZF is set and <desired> is stored in <dest>. |
| 1208 | // If not, ZF is cleared and <dest> is copied to eax (or subregister). |
| 1209 | // <dest> can be a register or memory, while <desired> must be a register. |
| 1210 | // It is the user's responsiblity to mark eax with a FakeDef. |
| 1211 | class InstX8632Cmpxchg : public InstX8632Lockable { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1212 | InstX8632Cmpxchg() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1213 | InstX8632Cmpxchg(const InstX8632Cmpxchg &) = delete; |
| 1214 | InstX8632Cmpxchg &operator=(const InstX8632Cmpxchg &) = delete; |
| 1215 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1216 | public: |
| 1217 | static InstX8632Cmpxchg *create(Cfg *Func, Operand *DestOrAddr, Variable *Eax, |
| 1218 | Variable *Desired, bool Locked) { |
| 1219 | return new (Func->allocate<InstX8632Cmpxchg>()) |
| 1220 | InstX8632Cmpxchg(Func, DestOrAddr, Eax, Desired, Locked); |
| 1221 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1222 | void emit(const Cfg *Func) const override; |
| 1223 | void emitIAS(const Cfg *Func) const override; |
| 1224 | void dump(const Cfg *Func) const override; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1225 | static bool classof(const Inst *Inst) { return isClassof(Inst, Cmpxchg); } |
| 1226 | |
| 1227 | private: |
| 1228 | InstX8632Cmpxchg(Cfg *Func, Operand *DestOrAddr, Variable *Eax, |
| 1229 | Variable *Desired, bool Locked); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1230 | ~InstX8632Cmpxchg() override {} |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1231 | }; |
| 1232 | |
| 1233 | // Cmpxchg8b instruction - cmpxchg8b <m64> will compare if <m64> |
| 1234 | // equals edx:eax. If so, the ZF is set and ecx:ebx is stored in <m64>. |
| 1235 | // If not, ZF is cleared and <m64> is copied to edx:eax. |
| 1236 | // The caller is responsible for inserting FakeDefs to mark edx |
| 1237 | // and eax as modified. |
| 1238 | // <m64> must be a memory operand. |
| 1239 | class InstX8632Cmpxchg8b : public InstX8632Lockable { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1240 | InstX8632Cmpxchg8b() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1241 | InstX8632Cmpxchg8b(const InstX8632Cmpxchg8b &) = delete; |
| 1242 | InstX8632Cmpxchg8b &operator=(const InstX8632Cmpxchg8b &) = delete; |
| 1243 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1244 | public: |
Jan Voung | 03532e5 | 2014-09-23 13:32:18 -0700 | [diff] [blame] | 1245 | static InstX8632Cmpxchg8b *create(Cfg *Func, OperandX8632Mem *Dest, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1246 | Variable *Edx, Variable *Eax, Variable *Ecx, |
| 1247 | Variable *Ebx, bool Locked) { |
| 1248 | return new (Func->allocate<InstX8632Cmpxchg8b>()) |
| 1249 | InstX8632Cmpxchg8b(Func, Dest, Edx, Eax, Ecx, Ebx, Locked); |
| 1250 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1251 | void emit(const Cfg *Func) const override; |
| 1252 | void emitIAS(const Cfg *Func) const override; |
| 1253 | void dump(const Cfg *Func) const override; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1254 | static bool classof(const Inst *Inst) { return isClassof(Inst, Cmpxchg8b); } |
| 1255 | |
| 1256 | private: |
Jan Voung | 03532e5 | 2014-09-23 13:32:18 -0700 | [diff] [blame] | 1257 | InstX8632Cmpxchg8b(Cfg *Func, OperandX8632Mem *Dest, Variable *Edx, |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1258 | Variable *Eax, Variable *Ecx, Variable *Ebx, bool Locked); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1259 | ~InstX8632Cmpxchg8b() override {} |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1260 | }; |
| 1261 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1262 | // Cvt instruction - wrapper for cvtsX2sY where X and Y are in {s,d,i} |
| 1263 | // as appropriate. s=float, d=double, i=int. X and Y are determined |
| 1264 | // from dest/src types. Sign and zero extension on the integer |
| 1265 | // operand needs to be done separately. |
| 1266 | class InstX8632Cvt : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1267 | InstX8632Cvt() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1268 | InstX8632Cvt(const InstX8632Cvt &) = delete; |
| 1269 | InstX8632Cvt &operator=(const InstX8632Cvt &) = delete; |
| 1270 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1271 | public: |
Jan Voung | 699bf02 | 2014-10-08 13:52:10 -0700 | [diff] [blame] | 1272 | enum CvtVariant { Si2ss, Tss2si, Float2float, Dq2ps, Tps2dq }; |
Jim Stichnoth | b63cd88 | 2014-09-08 10:47:23 -0700 | [diff] [blame] | 1273 | static InstX8632Cvt *create(Cfg *Func, Variable *Dest, Operand *Source, |
Jan Voung | 699bf02 | 2014-10-08 13:52:10 -0700 | [diff] [blame] | 1274 | CvtVariant Variant) { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1275 | return new (Func->allocate<InstX8632Cvt>()) |
Jan Voung | 699bf02 | 2014-10-08 13:52:10 -0700 | [diff] [blame] | 1276 | InstX8632Cvt(Func, Dest, Source, Variant); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1277 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1278 | void emit(const Cfg *Func) const override; |
Jan Voung | 699bf02 | 2014-10-08 13:52:10 -0700 | [diff] [blame] | 1279 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1280 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1281 | static bool classof(const Inst *Inst) { return isClassof(Inst, Cvt); } |
Jan Voung | 699bf02 | 2014-10-08 13:52:10 -0700 | [diff] [blame] | 1282 | bool isTruncating() const { return Variant == Tss2si || Variant == Tps2dq; } |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1283 | |
| 1284 | private: |
Jan Voung | 699bf02 | 2014-10-08 13:52:10 -0700 | [diff] [blame] | 1285 | CvtVariant Variant; |
| 1286 | InstX8632Cvt(Cfg *Func, Variable *Dest, Operand *Source, CvtVariant Variant); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1287 | ~InstX8632Cvt() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1288 | }; |
| 1289 | |
| 1290 | // cmp - Integer compare instruction. |
| 1291 | class InstX8632Icmp : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1292 | InstX8632Icmp() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1293 | InstX8632Icmp(const InstX8632Icmp &) = delete; |
| 1294 | InstX8632Icmp &operator=(const InstX8632Icmp &) = delete; |
| 1295 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1296 | public: |
| 1297 | static InstX8632Icmp *create(Cfg *Func, Operand *Src1, Operand *Src2) { |
| 1298 | return new (Func->allocate<InstX8632Icmp>()) |
| 1299 | InstX8632Icmp(Func, Src1, Src2); |
| 1300 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1301 | void emit(const Cfg *Func) const override; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1302 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1303 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1304 | static bool classof(const Inst *Inst) { return isClassof(Inst, Icmp); } |
| 1305 | |
| 1306 | private: |
| 1307 | InstX8632Icmp(Cfg *Func, Operand *Src1, Operand *Src2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1308 | ~InstX8632Icmp() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1309 | }; |
| 1310 | |
| 1311 | // ucomiss/ucomisd - floating-point compare instruction. |
| 1312 | class InstX8632Ucomiss : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1313 | InstX8632Ucomiss() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1314 | InstX8632Ucomiss(const InstX8632Ucomiss &) = delete; |
| 1315 | InstX8632Ucomiss &operator=(const InstX8632Ucomiss &) = delete; |
| 1316 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1317 | public: |
| 1318 | static InstX8632Ucomiss *create(Cfg *Func, Operand *Src1, Operand *Src2) { |
| 1319 | return new (Func->allocate<InstX8632Ucomiss>()) |
| 1320 | InstX8632Ucomiss(Func, Src1, Src2); |
| 1321 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1322 | void emit(const Cfg *Func) const override; |
| 1323 | void emitIAS(const Cfg *Func) const override; |
| 1324 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1325 | static bool classof(const Inst *Inst) { return isClassof(Inst, Ucomiss); } |
| 1326 | |
| 1327 | private: |
| 1328 | InstX8632Ucomiss(Cfg *Func, Operand *Src1, Operand *Src2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1329 | ~InstX8632Ucomiss() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1330 | }; |
| 1331 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 1332 | // UD2 instruction. |
| 1333 | class InstX8632UD2 : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1334 | InstX8632UD2() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1335 | InstX8632UD2(const InstX8632UD2 &) = delete; |
| 1336 | InstX8632UD2 &operator=(const InstX8632UD2 &) = delete; |
| 1337 | |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 1338 | public: |
| 1339 | static InstX8632UD2 *create(Cfg *Func) { |
| 1340 | return new (Func->allocate<InstX8632UD2>()) InstX8632UD2(Func); |
| 1341 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1342 | void emit(const Cfg *Func) const override; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1343 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1344 | void dump(const Cfg *Func) const override; |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 1345 | static bool classof(const Inst *Inst) { return isClassof(Inst, UD2); } |
| 1346 | |
| 1347 | private: |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1348 | explicit InstX8632UD2(Cfg *Func); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1349 | ~InstX8632UD2() override {} |
Jan Voung | 3bd9f1a | 2014-06-18 10:50:57 -0700 | [diff] [blame] | 1350 | }; |
| 1351 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1352 | // Test instruction. |
| 1353 | class InstX8632Test : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1354 | InstX8632Test() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1355 | InstX8632Test(const InstX8632Test &) = delete; |
| 1356 | InstX8632Test &operator=(const InstX8632Test &) = delete; |
| 1357 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1358 | public: |
| 1359 | static InstX8632Test *create(Cfg *Func, Operand *Source1, Operand *Source2) { |
| 1360 | return new (Func->allocate<InstX8632Test>()) |
| 1361 | InstX8632Test(Func, Source1, Source2); |
| 1362 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1363 | void emit(const Cfg *Func) const override; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1364 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1365 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1366 | static bool classof(const Inst *Inst) { return isClassof(Inst, Test); } |
| 1367 | |
| 1368 | private: |
| 1369 | InstX8632Test(Cfg *Func, Operand *Source1, Operand *Source2); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1370 | ~InstX8632Test() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1371 | }; |
| 1372 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1373 | // Mfence instruction. |
| 1374 | class InstX8632Mfence : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1375 | InstX8632Mfence() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1376 | InstX8632Mfence(const InstX8632Mfence &) = delete; |
| 1377 | InstX8632Mfence &operator=(const InstX8632Mfence &) = delete; |
| 1378 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1379 | public: |
| 1380 | static InstX8632Mfence *create(Cfg *Func) { |
| 1381 | return new (Func->allocate<InstX8632Mfence>()) InstX8632Mfence(Func); |
| 1382 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1383 | void emit(const Cfg *Func) const override; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1384 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1385 | void dump(const Cfg *Func) const override; |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1386 | static bool classof(const Inst *Inst) { return isClassof(Inst, Mfence); } |
| 1387 | |
| 1388 | private: |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1389 | explicit InstX8632Mfence(Cfg *Func); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1390 | ~InstX8632Mfence() override {} |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1391 | }; |
| 1392 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1393 | // This is essentially a "mov" instruction with an OperandX8632Mem |
| 1394 | // operand instead of Variable as the destination. It's important |
| 1395 | // for liveness that there is no Dest operand. |
| 1396 | class InstX8632Store : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1397 | InstX8632Store() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1398 | InstX8632Store(const InstX8632Store &) = delete; |
| 1399 | InstX8632Store &operator=(const InstX8632Store &) = delete; |
| 1400 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1401 | public: |
| 1402 | static InstX8632Store *create(Cfg *Func, Operand *Value, OperandX8632 *Mem) { |
| 1403 | return new (Func->allocate<InstX8632Store>()) |
| 1404 | InstX8632Store(Func, Value, Mem); |
| 1405 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1406 | void emit(const Cfg *Func) const override; |
Jan Voung | 198b294 | 2014-10-16 09:40:02 -0700 | [diff] [blame] | 1407 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1408 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1409 | static bool classof(const Inst *Inst) { return isClassof(Inst, Store); } |
| 1410 | |
| 1411 | private: |
| 1412 | InstX8632Store(Cfg *Func, Operand *Value, OperandX8632 *Mem); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1413 | ~InstX8632Store() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1414 | }; |
| 1415 | |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1416 | // This is essentially a vector "mov" instruction with an OperandX8632Mem |
| 1417 | // operand instead of Variable as the destination. It's important |
| 1418 | // for liveness that there is no Dest operand. The source must be an |
| 1419 | // Xmm register, since Dest is mem. |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 1420 | class InstX8632StoreP : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1421 | InstX8632StoreP() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1422 | InstX8632StoreP(const InstX8632StoreP &) = delete; |
| 1423 | InstX8632StoreP &operator=(const InstX8632StoreP &) = delete; |
| 1424 | |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 1425 | public: |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1426 | static InstX8632StoreP *create(Cfg *Func, Variable *Value, |
| 1427 | OperandX8632Mem *Mem) { |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 1428 | return new (Func->allocate<InstX8632StoreP>()) |
| 1429 | InstX8632StoreP(Func, Value, Mem); |
| 1430 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1431 | void emit(const Cfg *Func) const override; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1432 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1433 | void dump(const Cfg *Func) const override; |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 1434 | static bool classof(const Inst *Inst) { return isClassof(Inst, StoreP); } |
| 1435 | |
| 1436 | private: |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1437 | InstX8632StoreP(Cfg *Func, Variable *Value, OperandX8632Mem *Mem); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1438 | ~InstX8632StoreP() override {} |
Matt Wala | 105b704 | 2014-08-11 19:56:19 -0700 | [diff] [blame] | 1439 | }; |
| 1440 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1441 | class InstX8632StoreQ : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1442 | InstX8632StoreQ() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1443 | InstX8632StoreQ(const InstX8632StoreQ &) = delete; |
| 1444 | InstX8632StoreQ &operator=(const InstX8632StoreQ &) = delete; |
| 1445 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1446 | public: |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1447 | static InstX8632StoreQ *create(Cfg *Func, Variable *Value, |
| 1448 | OperandX8632Mem *Mem) { |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1449 | return new (Func->allocate<InstX8632StoreQ>()) |
| 1450 | InstX8632StoreQ(Func, Value, Mem); |
| 1451 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1452 | void emit(const Cfg *Func) const override; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1453 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1454 | void dump(const Cfg *Func) const override; |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1455 | static bool classof(const Inst *Inst) { return isClassof(Inst, StoreQ); } |
| 1456 | |
| 1457 | private: |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1458 | InstX8632StoreQ(Cfg *Func, Variable *Value, OperandX8632Mem *Mem); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1459 | ~InstX8632StoreQ() override {} |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1460 | }; |
| 1461 | |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 1462 | // Nop instructions of varying length |
| 1463 | class InstX8632Nop : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1464 | InstX8632Nop() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1465 | InstX8632Nop(const InstX8632Nop &) = delete; |
| 1466 | InstX8632Nop &operator=(const InstX8632Nop &) = delete; |
| 1467 | |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 1468 | public: |
| 1469 | // TODO: Replace with enum. |
| 1470 | typedef unsigned NopVariant; |
| 1471 | |
| 1472 | static InstX8632Nop *create(Cfg *Func, NopVariant Variant) { |
| 1473 | return new (Func->allocate<InstX8632Nop>()) InstX8632Nop(Func, Variant); |
| 1474 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1475 | void emit(const Cfg *Func) const override; |
| 1476 | void emitIAS(const Cfg *Func) const override; |
| 1477 | void dump(const Cfg *Func) const override; |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 1478 | static bool classof(const Inst *Inst) { return isClassof(Inst, Nop); } |
| 1479 | |
| 1480 | private: |
| 1481 | InstX8632Nop(Cfg *Func, SizeT Length); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1482 | ~InstX8632Nop() override {} |
Matt Wala | c330274 | 2014-08-15 16:21:56 -0700 | [diff] [blame] | 1483 | |
| 1484 | NopVariant Variant; |
| 1485 | }; |
| 1486 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1487 | // Fld - load a value onto the x87 FP stack. |
| 1488 | class InstX8632Fld : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1489 | InstX8632Fld() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1490 | InstX8632Fld(const InstX8632Fld &) = delete; |
| 1491 | InstX8632Fld &operator=(const InstX8632Fld &) = delete; |
| 1492 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1493 | public: |
| 1494 | static InstX8632Fld *create(Cfg *Func, Operand *Src) { |
| 1495 | return new (Func->allocate<InstX8632Fld>()) InstX8632Fld(Func, Src); |
| 1496 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1497 | void emit(const Cfg *Func) const override; |
Jan Voung | 479e563 | 2014-10-08 21:05:27 -0700 | [diff] [blame] | 1498 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1499 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1500 | static bool classof(const Inst *Inst) { return isClassof(Inst, Fld); } |
| 1501 | |
| 1502 | private: |
| 1503 | InstX8632Fld(Cfg *Func, Operand *Src); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1504 | ~InstX8632Fld() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1505 | }; |
| 1506 | |
| 1507 | // Fstp - store x87 st(0) into memory and pop st(0). |
| 1508 | class InstX8632Fstp : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1509 | InstX8632Fstp() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1510 | InstX8632Fstp(const InstX8632Fstp &) = delete; |
| 1511 | InstX8632Fstp &operator=(const InstX8632Fstp &) = delete; |
| 1512 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1513 | public: |
| 1514 | static InstX8632Fstp *create(Cfg *Func, Variable *Dest) { |
| 1515 | return new (Func->allocate<InstX8632Fstp>()) InstX8632Fstp(Func, Dest); |
| 1516 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1517 | void emit(const Cfg *Func) const override; |
Jan Voung | 479e563 | 2014-10-08 21:05:27 -0700 | [diff] [blame] | 1518 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1519 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1520 | static bool classof(const Inst *Inst) { return isClassof(Inst, Fstp); } |
| 1521 | |
| 1522 | private: |
| 1523 | InstX8632Fstp(Cfg *Func, Variable *Dest); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1524 | ~InstX8632Fstp() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1525 | }; |
| 1526 | |
| 1527 | class InstX8632Pop : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1528 | InstX8632Pop() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1529 | InstX8632Pop(const InstX8632Pop &) = delete; |
| 1530 | InstX8632Pop &operator=(const InstX8632Pop &) = delete; |
| 1531 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1532 | public: |
| 1533 | static InstX8632Pop *create(Cfg *Func, Variable *Dest) { |
| 1534 | return new (Func->allocate<InstX8632Pop>()) InstX8632Pop(Func, Dest); |
| 1535 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1536 | void emit(const Cfg *Func) const override; |
| 1537 | void emitIAS(const Cfg *Func) const override; |
| 1538 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1539 | static bool classof(const Inst *Inst) { return isClassof(Inst, Pop); } |
| 1540 | |
| 1541 | private: |
| 1542 | InstX8632Pop(Cfg *Func, Variable *Dest); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1543 | ~InstX8632Pop() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1544 | }; |
| 1545 | |
| 1546 | class InstX8632Push : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1547 | InstX8632Push() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1548 | InstX8632Push(const InstX8632Push &) = delete; |
| 1549 | InstX8632Push &operator=(const InstX8632Push &) = delete; |
| 1550 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1551 | public: |
Jan Voung | 0b9eee5 | 2014-10-07 11:20:10 -0700 | [diff] [blame] | 1552 | static InstX8632Push *create(Cfg *Func, Variable *Source) { |
Jim Stichnoth | dd842db | 2015-01-27 12:53:53 -0800 | [diff] [blame] | 1553 | return new (Func->allocate<InstX8632Push>()) InstX8632Push(Func, Source); |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1554 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1555 | void emit(const Cfg *Func) const override; |
Jan Voung | 0b9eee5 | 2014-10-07 11:20:10 -0700 | [diff] [blame] | 1556 | void emitIAS(const Cfg *Func) const override; |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1557 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1558 | static bool classof(const Inst *Inst) { return isClassof(Inst, Push); } |
| 1559 | |
| 1560 | private: |
Jan Voung | 0b9eee5 | 2014-10-07 11:20:10 -0700 | [diff] [blame] | 1561 | InstX8632Push(Cfg *Func, Variable *Source); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1562 | ~InstX8632Push() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1563 | }; |
| 1564 | |
| 1565 | // Ret instruction. Currently only supports the "ret" version that |
| 1566 | // does not pop arguments. This instruction takes a Source operand |
| 1567 | // (for non-void returning functions) for liveness analysis, though |
| 1568 | // a FakeUse before the ret would do just as well. |
| 1569 | class InstX8632Ret : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1570 | InstX8632Ret() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1571 | InstX8632Ret(const InstX8632Ret &) = delete; |
| 1572 | InstX8632Ret &operator=(const InstX8632Ret &) = delete; |
| 1573 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1574 | public: |
Jim Stichnoth | ae95320 | 2014-12-20 06:17:49 -0800 | [diff] [blame] | 1575 | static InstX8632Ret *create(Cfg *Func, Variable *Source = nullptr) { |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1576 | return new (Func->allocate<InstX8632Ret>()) InstX8632Ret(Func, Source); |
| 1577 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1578 | void emit(const Cfg *Func) const override; |
| 1579 | void emitIAS(const Cfg *Func) const override; |
| 1580 | void dump(const Cfg *Func) const override; |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1581 | static bool classof(const Inst *Inst) { return isClassof(Inst, Ret); } |
| 1582 | |
| 1583 | private: |
| 1584 | InstX8632Ret(Cfg *Func, Variable *Source); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1585 | ~InstX8632Ret() override {} |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1586 | }; |
| 1587 | |
Jim Stichnoth | f48b320 | 2015-05-04 10:22:17 -0700 | [diff] [blame] | 1588 | // Conditional set-byte instruction. |
| 1589 | class InstX8632Setcc : public InstX8632 { |
| 1590 | InstX8632Setcc() = delete; |
| 1591 | InstX8632Setcc(const InstX8632Cmov &) = delete; |
| 1592 | InstX8632Setcc &operator=(const InstX8632Setcc &) = delete; |
| 1593 | |
| 1594 | public: |
| 1595 | static InstX8632Setcc *create(Cfg *Func, Variable *Dest, |
| 1596 | CondX86::BrCond Cond) { |
| 1597 | return new (Func->allocate<InstX8632Setcc>()) |
| 1598 | InstX8632Setcc(Func, Dest, Cond); |
| 1599 | } |
| 1600 | void emit(const Cfg *Func) const override; |
| 1601 | void emitIAS(const Cfg *Func) const override; |
| 1602 | void dump(const Cfg *Func) const override; |
| 1603 | static bool classof(const Inst *Inst) { return isClassof(Inst, Setcc); } |
| 1604 | |
| 1605 | private: |
| 1606 | InstX8632Setcc(Cfg *Func, Variable *Dest, CondX86::BrCond Cond); |
| 1607 | ~InstX8632Setcc() override {} |
| 1608 | |
| 1609 | const CondX86::BrCond Condition; |
| 1610 | }; |
| 1611 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1612 | // Exchanging Add instruction. Exchanges the first operand (destination |
| 1613 | // operand) with the second operand (source operand), then loads the sum |
| 1614 | // of the two values into the destination operand. The destination may be |
| 1615 | // a register or memory, while the source must be a register. |
| 1616 | // |
| 1617 | // Both the dest and source are updated. The caller should then insert a |
| 1618 | // FakeDef to reflect the second udpate. |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1619 | class InstX8632Xadd : public InstX8632Lockable { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1620 | InstX8632Xadd() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1621 | InstX8632Xadd(const InstX8632Xadd &) = delete; |
| 1622 | InstX8632Xadd &operator=(const InstX8632Xadd &) = delete; |
| 1623 | |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1624 | public: |
| 1625 | static InstX8632Xadd *create(Cfg *Func, Operand *Dest, Variable *Source, |
| 1626 | bool Locked) { |
| 1627 | return new (Func->allocate<InstX8632Xadd>()) |
| 1628 | InstX8632Xadd(Func, Dest, Source, Locked); |
| 1629 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1630 | void emit(const Cfg *Func) const override; |
| 1631 | void emitIAS(const Cfg *Func) const override; |
| 1632 | void dump(const Cfg *Func) const override; |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1633 | static bool classof(const Inst *Inst) { return isClassof(Inst, Xadd); } |
| 1634 | |
| 1635 | private: |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1636 | InstX8632Xadd(Cfg *Func, Operand *Dest, Variable *Source, bool Locked); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1637 | ~InstX8632Xadd() override {} |
Jan Voung | 5cd240d | 2014-06-25 10:36:46 -0700 | [diff] [blame] | 1638 | }; |
| 1639 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1640 | // Exchange instruction. Exchanges the first operand (destination |
| 1641 | // operand) with the second operand (source operand). At least one of |
| 1642 | // the operands must be a register (and the other can be reg or mem). |
| 1643 | // Both the Dest and Source are updated. If there is a memory operand, |
| 1644 | // then the instruction is automatically "locked" without the need for |
| 1645 | // a lock prefix. |
| 1646 | class InstX8632Xchg : public InstX8632 { |
Jim Stichnoth | c6ead20 | 2015-02-24 09:30:30 -0800 | [diff] [blame] | 1647 | InstX8632Xchg() = delete; |
Jim Stichnoth | 7b451a9 | 2014-10-15 14:39:23 -0700 | [diff] [blame] | 1648 | InstX8632Xchg(const InstX8632Xchg &) = delete; |
| 1649 | InstX8632Xchg &operator=(const InstX8632Xchg &) = delete; |
| 1650 | |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1651 | public: |
| 1652 | static InstX8632Xchg *create(Cfg *Func, Operand *Dest, Variable *Source) { |
| 1653 | return new (Func->allocate<InstX8632Xchg>()) |
| 1654 | InstX8632Xchg(Func, Dest, Source); |
| 1655 | } |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1656 | void emit(const Cfg *Func) const override; |
| 1657 | void emitIAS(const Cfg *Func) const override; |
| 1658 | void dump(const Cfg *Func) const override; |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1659 | static bool classof(const Inst *Inst) { return isClassof(Inst, Xchg); } |
| 1660 | |
| 1661 | private: |
| 1662 | InstX8632Xchg(Cfg *Func, Operand *Dest, Variable *Source); |
Jim Stichnoth | b56c8f4 | 2014-09-26 09:28:46 -0700 | [diff] [blame] | 1663 | ~InstX8632Xchg() override {} |
Jan Voung | a3a01a2 | 2014-07-14 10:32:41 -0700 | [diff] [blame] | 1664 | }; |
| 1665 | |
Jim Stichnoth | 6e99214 | 2014-07-30 14:45:20 -0700 | [diff] [blame] | 1666 | // Declare partial template specializations of emit() methods that |
| 1667 | // already have default implementations. Without this, there is the |
| 1668 | // possibility of ODR violations and link errors. |
| 1669 | template <> void InstX8632Addss::emit(const Cfg *Func) const; |
| 1670 | template <> void InstX8632Blendvps::emit(const Cfg *Func) const; |
Matt Wala | 51e8cfb | 2014-08-08 08:39:40 -0700 | [diff] [blame] | 1671 | template <> void InstX8632Cbwdq::emit(const Cfg *Func) const; |
Jim Stichnoth | 6e99214 | 2014-07-30 14:45:20 -0700 | [diff] [blame] | 1672 | template <> void InstX8632Div::emit(const Cfg *Func) const; |
| 1673 | template <> void InstX8632Divss::emit(const Cfg *Func) const; |
| 1674 | template <> void InstX8632Idiv::emit(const Cfg *Func) const; |
| 1675 | template <> void InstX8632Imul::emit(const Cfg *Func) const; |
| 1676 | template <> void InstX8632Lea::emit(const Cfg *Func) const; |
| 1677 | template <> void InstX8632Mulss::emit(const Cfg *Func) const; |
| 1678 | template <> void InstX8632Padd::emit(const Cfg *Func) const; |
| 1679 | template <> void InstX8632Pblendvb::emit(const Cfg *Func) const; |
| 1680 | template <> void InstX8632Pcmpeq::emit(const Cfg *Func) const; |
| 1681 | template <> void InstX8632Pcmpgt::emit(const Cfg *Func) const; |
| 1682 | template <> void InstX8632Pextr::emit(const Cfg *Func) const; |
| 1683 | template <> void InstX8632Pinsr::emit(const Cfg *Func) const; |
| 1684 | template <> void InstX8632Pmull::emit(const Cfg *Func) const; |
| 1685 | template <> void InstX8632Pmuludq::emit(const Cfg *Func) const; |
| 1686 | template <> void InstX8632Psll::emit(const Cfg *Func) const; |
| 1687 | template <> void InstX8632Psra::emit(const Cfg *Func) const; |
Jim Stichnoth | 8c980d0 | 2015-03-19 13:01:50 -0700 | [diff] [blame] | 1688 | template <> void InstX8632Psrl::emit(const Cfg *Func) const; |
Jim Stichnoth | 6e99214 | 2014-07-30 14:45:20 -0700 | [diff] [blame] | 1689 | template <> void InstX8632Psub::emit(const Cfg *Func) const; |
| 1690 | template <> void InstX8632Sqrtss::emit(const Cfg *Func) const; |
| 1691 | template <> void InstX8632Subss::emit(const Cfg *Func) const; |
| 1692 | |
Jan Voung | d026c44 | 2014-10-13 14:06:50 -0700 | [diff] [blame] | 1693 | template <> void InstX8632Blendvps::emitIAS(const Cfg *Func) const; |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 1694 | template <> void InstX8632Cbwdq::emitIAS(const Cfg *Func) const; |
Jan Voung | af2780c | 2014-09-26 11:14:30 -0700 | [diff] [blame] | 1695 | template <> void InstX8632Div::emitIAS(const Cfg *Func) const; |
| 1696 | template <> void InstX8632Idiv::emitIAS(const Cfg *Func) const; |
Jan Voung | 0ac50dc | 2014-09-30 08:36:06 -0700 | [diff] [blame] | 1697 | template <> void InstX8632Imul::emitIAS(const Cfg *Func) const; |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 1698 | template <> void InstX8632Insertps::emitIAS(const Cfg *Func) const; |
Jan Voung | 3b43b89 | 2014-09-24 13:32:39 -0700 | [diff] [blame] | 1699 | template <> void InstX8632Movd::emitIAS(const Cfg *Func) const; |
Jan Voung | e4dc61b | 2014-10-06 08:53:52 -0700 | [diff] [blame] | 1700 | template <> void InstX8632MovssRegs::emitIAS(const Cfg *Func) const; |
Jan Voung | d026c44 | 2014-10-13 14:06:50 -0700 | [diff] [blame] | 1701 | template <> void InstX8632Pblendvb::emitIAS(const Cfg *Func) const; |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 1702 | template <> void InstX8632Pextr::emitIAS(const Cfg *Func) const; |
| 1703 | template <> void InstX8632Pinsr::emitIAS(const Cfg *Func) const; |
Jan Voung | 39d4aca | 2014-10-15 15:16:54 -0700 | [diff] [blame] | 1704 | template <> void InstX8632Movsx::emitIAS(const Cfg *Func) const; |
| 1705 | template <> void InstX8632Movzx::emitIAS(const Cfg *Func) const; |
Jan Voung | 8bcca04 | 2014-10-03 21:58:02 -0700 | [diff] [blame] | 1706 | template <> void InstX8632Pmull::emitIAS(const Cfg *Func) const; |
Jan Voung | 962befa | 2014-10-15 09:32:58 -0700 | [diff] [blame] | 1707 | template <> void InstX8632Pshufd::emitIAS(const Cfg *Func) const; |
| 1708 | template <> void InstX8632Shufps::emitIAS(const Cfg *Func) const; |
Jan Voung | 03532e5 | 2014-09-23 13:32:18 -0700 | [diff] [blame] | 1709 | |
Jim Stichnoth | 5bc2b1d | 2014-05-22 13:38:48 -0700 | [diff] [blame] | 1710 | } // end of namespace Ice |
| 1711 | |
| 1712 | #endif // SUBZERO_SRC_ICEINSTX8632_H |