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