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