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