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