blob: de0e925342acd3564c47ceb68a05ba6ca9d5ab49 [file] [log] [blame]
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -07001//===- subzero/src/IceTargetLoweringX8632.h - x86-32 lowering ---*- C++ -*-===//
2//
3// The Subzero Code Generator
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares the TargetLoweringX8632 class, which
11// implements the TargetLowering interface for the x86-32
12// architecture.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef SUBZERO_SRC_ICETARGETLOWERINGX8632_H
17#define SUBZERO_SRC_ICETARGETLOWERINGX8632_H
18
Jan Voung8acded02014-09-22 18:02:25 -070019#include "assembler_ia32.h"
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070020#include "IceDefs.h"
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070021#include "IceInstX8632.h"
Jan Voungbd385e42014-09-18 18:18:10 -070022#include "IceRegistersX8632.h"
Jim Stichnotha18cc9c2014-09-30 19:10:22 -070023#include "IceTargetLowering.h"
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070024
25namespace Ice {
26
27class TargetX8632 : public TargetLowering {
Jim Stichnoth7b451a92014-10-15 14:39:23 -070028 TargetX8632(const TargetX8632 &) = delete;
29 TargetX8632 &operator=(const TargetX8632 &) = delete;
30
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070031public:
32 static TargetX8632 *create(Cfg *Func) { return new TargetX8632(Func); }
33
Jim Stichnothb56c8f42014-09-26 09:28:46 -070034 void translateOm1() override;
35 void translateO2() override;
36 bool doBranchOpt(Inst *I, const CfgNode *NextNode) override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070037
Jim Stichnoth3d44fe82014-11-01 10:10:18 -070038 SizeT getNumRegisters() const override { return RegX8632::Reg_NUM; }
Jim Stichnoth98712a32014-10-24 10:59:02 -070039 Variable *getPhysicalRegister(SizeT RegNum, Type Ty = IceType_void) override;
Jim Stichnothb56c8f42014-09-26 09:28:46 -070040 IceString getRegName(SizeT RegNum, Type Ty) const override;
41 llvm::SmallBitVector getRegisterSet(RegSetMask Include,
42 RegSetMask Exclude) const override;
43 const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const override {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070044 return TypeToRegisterSet[Ty];
45 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070046 bool hasFramePointer() const override { return IsEbpBasedFrame; }
47 SizeT getFrameOrStackReg() const override {
Jan Voungbd385e42014-09-18 18:18:10 -070048 return IsEbpBasedFrame ? RegX8632::Reg_ebp : RegX8632::Reg_esp;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070049 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070050 size_t typeWidthInBytesOnStack(Type Ty) const override {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070051 // Round up to the next multiple of 4 bytes. In particular, i1,
52 // i8, and i16 are rounded up to 4 bytes.
53 return (typeWidthInBytes(Ty) + 3) & ~3;
54 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070055 void emitVariable(const Variable *Var) const override;
56 void lowerArguments() override;
57 void addProlog(CfgNode *Node) override;
58 void addEpilog(CfgNode *Node) override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070059 SizeT makeNextLabelNumber() { return NextLabelNumber++; }
60 // Ensure that a 64-bit Variable has been split into 2 32-bit
61 // Variables, creating them if necessary. This is needed for all
62 // I64 operations, and it is needed for pushing F64 arguments for
63 // function calls using the 32-bit push instruction (though the
64 // latter could be done by directly writing to the stack).
65 void split64(Variable *Var);
Matt Wala45a06232014-07-09 16:33:22 -070066 void finishArgumentLowering(Variable *Arg, Variable *FramePtr,
67 size_t BasicFrameOffset, size_t &InArgsSizeBytes);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070068 Operand *loOperand(Operand *Operand);
69 Operand *hiOperand(Operand *Operand);
Jan Voung8acded02014-09-22 18:02:25 -070070 x86::Address stackVarToAsmOperand(const Variable *Var) const;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070071
Matt Wala0a450512014-07-30 12:44:39 -070072 enum X86InstructionSet {
73 // SSE2 is the PNaCl baseline instruction set.
74 SSE2,
75 SSE4_1
76 };
77
78 X86InstructionSet getInstructionSet() const { return InstructionSet; }
79
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070080protected:
81 TargetX8632(Cfg *Func);
82
Jim Stichnothb56c8f42014-09-26 09:28:46 -070083 void postLower() override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070084
Jim Stichnothb56c8f42014-09-26 09:28:46 -070085 void lowerAlloca(const InstAlloca *Inst) override;
86 void lowerArithmetic(const InstArithmetic *Inst) override;
87 void lowerAssign(const InstAssign *Inst) override;
88 void lowerBr(const InstBr *Inst) override;
89 void lowerCall(const InstCall *Inst) override;
90 void lowerCast(const InstCast *Inst) override;
91 void lowerExtractElement(const InstExtractElement *Inst) override;
92 void lowerFcmp(const InstFcmp *Inst) override;
93 void lowerIcmp(const InstIcmp *Inst) override;
94 void lowerIntrinsicCall(const InstIntrinsicCall *Inst) override;
95 void lowerInsertElement(const InstInsertElement *Inst) override;
96 void lowerLoad(const InstLoad *Inst) override;
97 void lowerPhi(const InstPhi *Inst) override;
98 void lowerRet(const InstRet *Inst) override;
99 void lowerSelect(const InstSelect *Inst) override;
100 void lowerStore(const InstStore *Inst) override;
101 void lowerSwitch(const InstSwitch *Inst) override;
102 void lowerUnreachable(const InstUnreachable *Inst) override;
Jim Stichnoth336f6c42014-10-30 15:01:31 -0700103 void prelowerPhis() override;
104 void lowerPhiAssignments(CfgNode *Node,
105 const AssignList &Assignments) override;
Jim Stichnothb56c8f42014-09-26 09:28:46 -0700106 void doAddressOptLoad() override;
107 void doAddressOptStore() override;
108 void randomlyInsertNop(float Probability) override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700109
Jan Voungc820ddf2014-07-29 14:38:51 -0700110 // Naive lowering of cmpxchg.
Jan Vounga3a01a22014-07-14 10:32:41 -0700111 void lowerAtomicCmpxchg(Variable *DestPrev, Operand *Ptr, Operand *Expected,
112 Operand *Desired);
Jan Voungc820ddf2014-07-29 14:38:51 -0700113 // Attempt a more optimized lowering of cmpxchg. Returns true if optimized.
114 bool tryOptimizedCmpxchgCmpBr(Variable *DestPrev, Operand *Ptr,
115 Operand *Expected, Operand *Desired);
Jan Voung5cd240d2014-06-25 10:36:46 -0700116 void lowerAtomicRMW(Variable *Dest, uint32_t Operation, Operand *Ptr,
117 Operand *Val);
Jan Vounge4da26f2014-07-15 17:52:39 -0700118 void lowerCountZeros(bool Cttz, Type Ty, Variable *Dest, Operand *FirstVal,
119 Operand *SecondVal);
Jan Voung5cd240d2014-06-25 10:36:46 -0700120
Jan Vounga3a01a22014-07-14 10:32:41 -0700121 typedef void (TargetX8632::*LowerBinOp)(Variable *, Operand *);
122 void expandAtomicRMWAsCmpxchg(LowerBinOp op_lo, LowerBinOp op_hi,
123 Variable *Dest, Operand *Ptr, Operand *Val);
124
Matt Walace0ca8f2014-07-24 12:34:20 -0700125 void eliminateNextVectorSextInstruction(Variable *SignExtendedResult);
126
Matt Walaafeaee42014-08-07 13:47:30 -0700127 void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest,
128 Operand *Src0, Operand *Src1);
129
Matt Walad4799f42014-08-14 14:24:12 -0700130 void sortByAlignment(VarList &Dest, const VarList &Source) const;
131
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700132 // Operand legalization helpers. To deal with address mode
133 // constraints, the helpers will create a new Operand and emit
134 // instructions that guarantee that the Operand kind is one of those
135 // indicated by the LegalMask (a bitmask of allowed kinds). If the
136 // input Operand is known to already meet the constraints, it may be
137 // simply returned as the result, without creating any new
138 // instructions or operands.
139 enum OperandLegalization {
140 Legal_None = 0,
141 Legal_Reg = 1 << 0, // physical register, not stack location
142 Legal_Imm = 1 << 1,
143 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12]
144 Legal_All = ~Legal_None
145 };
146 typedef uint32_t LegalMask;
Jim Stichnothdd165072014-11-02 09:41:45 -0800147 Operand *legalize(Operand *From, LegalMask Allowed = Legal_All,
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700148 int32_t RegNum = Variable::NoRegister);
Jim Stichnothad403532014-09-25 12:44:17 -0700149 Variable *legalizeToVar(Operand *From, int32_t RegNum = Variable::NoRegister);
Jan Voung5cd240d2014-06-25 10:36:46 -0700150 // Turn a pointer operand into a memory operand that can be
151 // used by a real load/store operation. Legalizes the operand as well.
152 // This is a nop if the operand is already a legal memory operand.
153 OperandX8632Mem *FormMemoryOperand(Operand *Ptr, Type Ty);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700154
155 Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister);
156 InstCall *makeHelperCall(const IceString &Name, Variable *Dest,
157 SizeT MaxSrcs) {
Jim Stichnothd2cb4362014-11-20 11:24:42 -0800158 const bool SuppressMangling = true;
159 const bool HasTailCall = false;
160 const RelocOffsetT Offset = 0;
161 Constant *CallTarget = Ctx->getConstantSym(Offset, Name, SuppressMangling);
162 InstCall *Call =
163 InstCall::create(Func, MaxSrcs, Dest, CallTarget, HasTailCall);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700164 return Call;
165 }
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700166 static Type stackSlotType();
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700167
Matt Wala928f1292014-07-07 16:50:46 -0700168 Variable *copyToReg(Operand *Src, int32_t RegNum = Variable::NoRegister);
169
Matt Wala83b80362014-07-16 10:21:30 -0700170 // Returns a vector in a register with the given constant entries.
171 Variable *makeVectorOfZeros(Type Ty, int32_t RegNum = Variable::NoRegister);
172 Variable *makeVectorOfOnes(Type Ty, int32_t RegNum = Variable::NoRegister);
Matt Wala9a0168a2014-07-23 14:56:10 -0700173 Variable *makeVectorOfMinusOnes(Type Ty,
174 int32_t RegNum = Variable::NoRegister);
175 Variable *makeVectorOfHighOrderBits(Type Ty,
176 int32_t RegNum = Variable::NoRegister);
Matt Wala83b80362014-07-16 10:21:30 -0700177
Matt Wala49889232014-07-18 12:45:09 -0700178 // Return a memory operand corresponding to a stack allocated Variable.
179 OperandX8632Mem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot,
180 uint32_t Offset = 0);
181
Jim Stichnothe6d24782014-12-19 05:42:24 -0800182 void makeRandomRegisterPermutation(
183 llvm::SmallVectorImpl<int32_t> &Permutation,
184 const llvm::SmallBitVector &ExcludeRegisters) const;
185
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700186 // The following are helpers that insert lowered x86 instructions
187 // with minimal syntactic overhead, so that the lowering code can
188 // look as close to assembly as practical.
189 void _adc(Variable *Dest, Operand *Src0) {
190 Context.insert(InstX8632Adc::create(Func, Dest, Src0));
191 }
192 void _add(Variable *Dest, Operand *Src0) {
193 Context.insert(InstX8632Add::create(Func, Dest, Src0));
194 }
Matt Wala105b7042014-08-11 19:56:19 -0700195 void _adjust_stack(int32_t Amount) {
Jim Stichnoth144cdce2014-09-22 16:02:59 -0700196 Context.insert(InstX8632AdjustStack::create(
197 Func, Amount, getPhysicalRegister(RegX8632::Reg_esp)));
Matt Wala105b7042014-08-11 19:56:19 -0700198 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700199 void _addps(Variable *Dest, Operand *Src0) {
200 Context.insert(InstX8632Addps::create(Func, Dest, Src0));
201 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700202 void _addss(Variable *Dest, Operand *Src0) {
203 Context.insert(InstX8632Addss::create(Func, Dest, Src0));
204 }
205 void _and(Variable *Dest, Operand *Src0) {
206 Context.insert(InstX8632And::create(Func, Dest, Src0));
207 }
Matt Wala0a450512014-07-30 12:44:39 -0700208 void _blendvps(Variable *Dest, Operand *Src0, Operand *Src1) {
209 Context.insert(InstX8632Blendvps::create(Func, Dest, Src0, Src1));
210 }
Jan Voungbd385e42014-09-18 18:18:10 -0700211 void _br(CondX86::BrCond Condition, CfgNode *TargetTrue,
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700212 CfgNode *TargetFalse) {
213 Context.insert(
214 InstX8632Br::create(Func, TargetTrue, TargetFalse, Condition));
215 }
216 void _br(CfgNode *Target) {
217 Context.insert(InstX8632Br::create(Func, Target));
218 }
Jan Voungbd385e42014-09-18 18:18:10 -0700219 void _br(CondX86::BrCond Condition, CfgNode *Target) {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700220 Context.insert(InstX8632Br::create(Func, Target, Condition));
221 }
Jan Voungbd385e42014-09-18 18:18:10 -0700222 void _br(CondX86::BrCond Condition, InstX8632Label *Label) {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700223 Context.insert(InstX8632Br::create(Func, Label, Condition));
224 }
Jan Vounge4da26f2014-07-15 17:52:39 -0700225 void _bsf(Variable *Dest, Operand *Src0) {
226 Context.insert(InstX8632Bsf::create(Func, Dest, Src0));
227 }
228 void _bsr(Variable *Dest, Operand *Src0) {
229 Context.insert(InstX8632Bsr::create(Func, Dest, Src0));
230 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700231 void _bswap(Variable *SrcDest) {
232 Context.insert(InstX8632Bswap::create(Func, SrcDest));
233 }
Matt Walaafeaee42014-08-07 13:47:30 -0700234 void _cbwdq(Variable *Dest, Operand *Src0) {
235 Context.insert(InstX8632Cbwdq::create(Func, Dest, Src0));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700236 }
Jan Voungbd385e42014-09-18 18:18:10 -0700237 void _cmov(Variable *Dest, Operand *Src0, CondX86::BrCond Condition) {
Jan Vounge4da26f2014-07-15 17:52:39 -0700238 Context.insert(InstX8632Cmov::create(Func, Dest, Src0, Condition));
239 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700240 void _cmp(Operand *Src0, Operand *Src1) {
241 Context.insert(InstX8632Icmp::create(Func, Src0, Src1));
242 }
Jan Voungbd385e42014-09-18 18:18:10 -0700243 void _cmpps(Variable *Dest, Operand *Src0, CondX86::CmppsCond Condition) {
Matt Walace0ca8f2014-07-24 12:34:20 -0700244 Context.insert(InstX8632Cmpps::create(Func, Dest, Src0, Condition));
245 }
Jan Vounga3a01a22014-07-14 10:32:41 -0700246 void _cmpxchg(Operand *DestOrAddr, Variable *Eax, Variable *Desired,
247 bool Locked) {
248 Context.insert(
249 InstX8632Cmpxchg::create(Func, DestOrAddr, Eax, Desired, Locked));
250 // Mark eax as possibly modified by cmpxchg.
251 Context.insert(
252 InstFakeDef::create(Func, Eax, llvm::dyn_cast<Variable>(DestOrAddr)));
Jim Stichnoth47752552014-10-13 17:15:08 -0700253 _set_dest_nonkillable();
Jan Vounga3a01a22014-07-14 10:32:41 -0700254 }
Jan Voung03532e52014-09-23 13:32:18 -0700255 void _cmpxchg8b(OperandX8632Mem *Addr, Variable *Edx, Variable *Eax,
Jan Vounga3a01a22014-07-14 10:32:41 -0700256 Variable *Ecx, Variable *Ebx, bool Locked) {
257 Context.insert(
258 InstX8632Cmpxchg8b::create(Func, Addr, Edx, Eax, Ecx, Ebx, Locked));
259 // Mark edx, and eax as possibly modified by cmpxchg8b.
260 Context.insert(InstFakeDef::create(Func, Edx));
Jim Stichnoth47752552014-10-13 17:15:08 -0700261 _set_dest_nonkillable();
Jan Vounga3a01a22014-07-14 10:32:41 -0700262 Context.insert(InstFakeDef::create(Func, Eax));
Jim Stichnoth47752552014-10-13 17:15:08 -0700263 _set_dest_nonkillable();
Jan Vounga3a01a22014-07-14 10:32:41 -0700264 }
Jan Voung699bf022014-10-08 13:52:10 -0700265 void _cvt(Variable *Dest, Operand *Src0, InstX8632Cvt::CvtVariant Variant) {
266 Context.insert(InstX8632Cvt::create(Func, Dest, Src0, Variant));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700267 }
268 void _div(Variable *Dest, Operand *Src0, Operand *Src1) {
269 Context.insert(InstX8632Div::create(Func, Dest, Src0, Src1));
270 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700271 void _divps(Variable *Dest, Operand *Src0) {
272 Context.insert(InstX8632Divps::create(Func, Dest, Src0));
273 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700274 void _divss(Variable *Dest, Operand *Src0) {
275 Context.insert(InstX8632Divss::create(Func, Dest, Src0));
276 }
277 void _fld(Operand *Src0) { Context.insert(InstX8632Fld::create(Func, Src0)); }
278 void _fstp(Variable *Dest) {
279 Context.insert(InstX8632Fstp::create(Func, Dest));
280 }
281 void _idiv(Variable *Dest, Operand *Src0, Operand *Src1) {
282 Context.insert(InstX8632Idiv::create(Func, Dest, Src0, Src1));
283 }
284 void _imul(Variable *Dest, Operand *Src0) {
285 Context.insert(InstX8632Imul::create(Func, Dest, Src0));
286 }
Matt Wala0a450512014-07-30 12:44:39 -0700287 void _insertps(Variable *Dest, Operand *Src0, Operand *Src1) {
288 Context.insert(InstX8632Insertps::create(Func, Dest, Src0, Src1));
289 }
Matt Wala49889232014-07-18 12:45:09 -0700290 void _lea(Variable *Dest, Operand *Src0) {
291 Context.insert(InstX8632Lea::create(Func, Dest, Src0));
292 }
Jan Voung5cd240d2014-06-25 10:36:46 -0700293 void _mfence() { Context.insert(InstX8632Mfence::create(Func)); }
Jim Stichnothae953202014-12-20 06:17:49 -0800294 // If Dest=nullptr is passed in, then a new variable is created,
295 // marked as infinite register allocation weight, and returned
296 // through the in/out Dest argument.
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700297 void _mov(Variable *&Dest, Operand *Src0,
298 int32_t RegNum = Variable::NoRegister) {
Jim Stichnothae953202014-12-20 06:17:49 -0800299 if (Dest == nullptr)
Jim Stichnothad403532014-09-25 12:44:17 -0700300 Dest = makeReg(Src0->getType(), RegNum);
301 Context.insert(InstX8632Mov::create(Func, Dest, Src0));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700302 }
Jim Stichnoth47752552014-10-13 17:15:08 -0700303 void _mov_nonkillable(Variable *Dest, Operand *Src0) {
304 Inst *NewInst = InstX8632Mov::create(Func, Dest, Src0);
305 NewInst->setDestNonKillable();
306 Context.insert(NewInst);
307 }
Matt Wala49889232014-07-18 12:45:09 -0700308 void _movd(Variable *Dest, Operand *Src0) {
309 Context.insert(InstX8632Movd::create(Func, Dest, Src0));
310 }
Matt Wala928f1292014-07-07 16:50:46 -0700311 void _movp(Variable *Dest, Operand *Src0) {
312 Context.insert(InstX8632Movp::create(Func, Dest, Src0));
313 }
Jan Voung5cd240d2014-06-25 10:36:46 -0700314 void _movq(Variable *Dest, Operand *Src0) {
315 Context.insert(InstX8632Movq::create(Func, Dest, Src0));
316 }
Jan Vounge4dc61b2014-10-06 08:53:52 -0700317 void _movss(Variable *Dest, Variable *Src0) {
318 Context.insert(InstX8632MovssRegs::create(Func, Dest, Src0));
Matt Wala49889232014-07-18 12:45:09 -0700319 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700320 void _movsx(Variable *Dest, Operand *Src0) {
321 Context.insert(InstX8632Movsx::create(Func, Dest, Src0));
322 }
323 void _movzx(Variable *Dest, Operand *Src0) {
324 Context.insert(InstX8632Movzx::create(Func, Dest, Src0));
325 }
326 void _mul(Variable *Dest, Variable *Src0, Operand *Src1) {
327 Context.insert(InstX8632Mul::create(Func, Dest, Src0, Src1));
328 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700329 void _mulps(Variable *Dest, Operand *Src0) {
330 Context.insert(InstX8632Mulps::create(Func, Dest, Src0));
331 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700332 void _mulss(Variable *Dest, Operand *Src0) {
333 Context.insert(InstX8632Mulss::create(Func, Dest, Src0));
334 }
Jan Vounga3a01a22014-07-14 10:32:41 -0700335 void _neg(Variable *SrcDest) {
336 Context.insert(InstX8632Neg::create(Func, SrcDest));
337 }
Matt Walac3302742014-08-15 16:21:56 -0700338 void _nop(SizeT Variant) {
339 Context.insert(InstX8632Nop::create(Func, Variant));
340 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700341 void _or(Variable *Dest, Operand *Src0) {
342 Context.insert(InstX8632Or::create(Func, Dest, Src0));
343 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700344 void _padd(Variable *Dest, Operand *Src0) {
345 Context.insert(InstX8632Padd::create(Func, Dest, Src0));
346 }
Matt Wala83b80362014-07-16 10:21:30 -0700347 void _pand(Variable *Dest, Operand *Src0) {
348 Context.insert(InstX8632Pand::create(Func, Dest, Src0));
349 }
Matt Wala9cb61e22014-07-24 09:44:42 -0700350 void _pandn(Variable *Dest, Operand *Src0) {
351 Context.insert(InstX8632Pandn::create(Func, Dest, Src0));
352 }
Matt Wala0a450512014-07-30 12:44:39 -0700353 void _pblendvb(Variable *Dest, Operand *Src0, Operand *Src1) {
354 Context.insert(InstX8632Pblendvb::create(Func, Dest, Src0, Src1));
355 }
Matt Wala83b80362014-07-16 10:21:30 -0700356 void _pcmpeq(Variable *Dest, Operand *Src0) {
357 Context.insert(InstX8632Pcmpeq::create(Func, Dest, Src0));
358 }
359 void _pcmpgt(Variable *Dest, Operand *Src0) {
360 Context.insert(InstX8632Pcmpgt::create(Func, Dest, Src0));
361 }
Matt Wala0a450512014-07-30 12:44:39 -0700362 void _pextr(Variable *Dest, Operand *Src0, Operand *Src1) {
363 Context.insert(InstX8632Pextr::create(Func, Dest, Src0, Src1));
Matt Wala49889232014-07-18 12:45:09 -0700364 }
Matt Wala0a450512014-07-30 12:44:39 -0700365 void _pinsr(Variable *Dest, Operand *Src0, Operand *Src1) {
366 Context.insert(InstX8632Pinsr::create(Func, Dest, Src0, Src1));
Matt Wala49889232014-07-18 12:45:09 -0700367 }
Matt Wala0a450512014-07-30 12:44:39 -0700368 void _pmull(Variable *Dest, Operand *Src0) {
369 Context.insert(InstX8632Pmull::create(Func, Dest, Src0));
Matt Wala7fa22d82014-07-17 12:41:31 -0700370 }
371 void _pmuludq(Variable *Dest, Operand *Src0) {
372 Context.insert(InstX8632Pmuludq::create(Func, Dest, Src0));
373 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700374 void _pop(Variable *Dest) {
375 Context.insert(InstX8632Pop::create(Func, Dest));
376 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700377 void _por(Variable *Dest, Operand *Src0) {
378 Context.insert(InstX8632Por::create(Func, Dest, Src0));
379 }
380 void _pshufd(Variable *Dest, Operand *Src0, Operand *Src1) {
381 Context.insert(InstX8632Pshufd::create(Func, Dest, Src0, Src1));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700382 }
Matt Wala83b80362014-07-16 10:21:30 -0700383 void _psll(Variable *Dest, Operand *Src0) {
384 Context.insert(InstX8632Psll::create(Func, Dest, Src0));
385 }
386 void _psra(Variable *Dest, Operand *Src0) {
387 Context.insert(InstX8632Psra::create(Func, Dest, Src0));
388 }
389 void _psub(Variable *Dest, Operand *Src0) {
390 Context.insert(InstX8632Psub::create(Func, Dest, Src0));
391 }
Jan Voung0b9eee52014-10-07 11:20:10 -0700392 void _push(Variable *Src0) {
393 Context.insert(InstX8632Push::create(Func, Src0));
Matt Wala7fa22d82014-07-17 12:41:31 -0700394 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700395 void _pxor(Variable *Dest, Operand *Src0) {
396 Context.insert(InstX8632Pxor::create(Func, Dest, Src0));
397 }
Jim Stichnothae953202014-12-20 06:17:49 -0800398 void _ret(Variable *Src0 = nullptr) {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700399 Context.insert(InstX8632Ret::create(Func, Src0));
400 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700401 void _rol(Variable *Dest, Operand *Src0) {
402 Context.insert(InstX8632Rol::create(Func, Dest, Src0));
403 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700404 void _sar(Variable *Dest, Operand *Src0) {
405 Context.insert(InstX8632Sar::create(Func, Dest, Src0));
406 }
407 void _sbb(Variable *Dest, Operand *Src0) {
408 Context.insert(InstX8632Sbb::create(Func, Dest, Src0));
409 }
410 void _shl(Variable *Dest, Operand *Src0) {
411 Context.insert(InstX8632Shl::create(Func, Dest, Src0));
412 }
413 void _shld(Variable *Dest, Variable *Src0, Variable *Src1) {
414 Context.insert(InstX8632Shld::create(Func, Dest, Src0, Src1));
415 }
416 void _shr(Variable *Dest, Operand *Src0) {
417 Context.insert(InstX8632Shr::create(Func, Dest, Src0));
418 }
419 void _shrd(Variable *Dest, Variable *Src0, Variable *Src1) {
420 Context.insert(InstX8632Shrd::create(Func, Dest, Src0, Src1));
421 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700422 void _shufps(Variable *Dest, Operand *Src0, Operand *Src1) {
423 Context.insert(InstX8632Shufps::create(Func, Dest, Src0, Src1));
424 }
Jan Voungf37fbbe2014-07-09 16:13:13 -0700425 void _sqrtss(Variable *Dest, Operand *Src0) {
426 Context.insert(InstX8632Sqrtss::create(Func, Dest, Src0));
427 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700428 void _store(Operand *Value, OperandX8632 *Mem) {
429 Context.insert(InstX8632Store::create(Func, Value, Mem));
430 }
Jan Vounge4dc61b2014-10-06 08:53:52 -0700431 void _storep(Variable *Value, OperandX8632Mem *Mem) {
Matt Wala105b7042014-08-11 19:56:19 -0700432 Context.insert(InstX8632StoreP::create(Func, Value, Mem));
433 }
Jan Vounge4dc61b2014-10-06 08:53:52 -0700434 void _storeq(Variable *Value, OperandX8632Mem *Mem) {
Jan Voung5cd240d2014-06-25 10:36:46 -0700435 Context.insert(InstX8632StoreQ::create(Func, Value, Mem));
436 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700437 void _sub(Variable *Dest, Operand *Src0) {
438 Context.insert(InstX8632Sub::create(Func, Dest, Src0));
439 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700440 void _subps(Variable *Dest, Operand *Src0) {
441 Context.insert(InstX8632Subps::create(Func, Dest, Src0));
442 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700443 void _subss(Variable *Dest, Operand *Src0) {
444 Context.insert(InstX8632Subss::create(Func, Dest, Src0));
445 }
446 void _test(Operand *Src0, Operand *Src1) {
447 Context.insert(InstX8632Test::create(Func, Src0, Src1));
448 }
449 void _ucomiss(Operand *Src0, Operand *Src1) {
450 Context.insert(InstX8632Ucomiss::create(Func, Src0, Src1));
451 }
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700452 void _ud2() { Context.insert(InstX8632UD2::create(Func)); }
Jan Voung5cd240d2014-06-25 10:36:46 -0700453 void _xadd(Operand *Dest, Variable *Src, bool Locked) {
454 Context.insert(InstX8632Xadd::create(Func, Dest, Src, Locked));
455 // The xadd exchanges Dest and Src (modifying Src).
456 // Model that update with a FakeDef.
Jan Vounga3a01a22014-07-14 10:32:41 -0700457 Context.insert(
458 InstFakeDef::create(Func, Src, llvm::dyn_cast<Variable>(Dest)));
Jim Stichnoth47752552014-10-13 17:15:08 -0700459 _set_dest_nonkillable();
Jan Vounga3a01a22014-07-14 10:32:41 -0700460 }
461 void _xchg(Operand *Dest, Variable *Src) {
462 Context.insert(InstX8632Xchg::create(Func, Dest, Src));
463 // The xchg modifies Dest and Src -- model that update with a FakeDef.
464 Context.insert(
465 InstFakeDef::create(Func, Src, llvm::dyn_cast<Variable>(Dest)));
Jim Stichnoth47752552014-10-13 17:15:08 -0700466 _set_dest_nonkillable();
Jan Voung5cd240d2014-06-25 10:36:46 -0700467 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700468 void _xor(Variable *Dest, Operand *Src0) {
469 Context.insert(InstX8632Xor::create(Func, Dest, Src0));
470 }
Jim Stichnoth47752552014-10-13 17:15:08 -0700471 void _set_dest_nonkillable() {
472 Context.getLastInserted()->setDestNonKillable();
473 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700474
Matt Wala0a450512014-07-30 12:44:39 -0700475 const X86InstructionSet InstructionSet;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700476 bool IsEbpBasedFrame;
Matt Wala105b7042014-08-11 19:56:19 -0700477 bool NeedsStackAlignment;
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700478 size_t FrameSizeLocals;
Matt Walad4799f42014-08-14 14:24:12 -0700479 size_t SpillAreaSizeBytes;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700480 llvm::SmallBitVector TypeToRegisterSet[IceType_NUM];
481 llvm::SmallBitVector ScratchRegs;
482 llvm::SmallBitVector RegsUsed;
483 SizeT NextLabelNumber;
Jim Stichnoth336f6c42014-10-30 15:01:31 -0700484 VarList PhysicalRegisters[IceType_NUM];
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700485 static IceString RegNames[];
486
487private:
Jim Stichnothb56c8f42014-09-26 09:28:46 -0700488 ~TargetX8632() override {}
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700489};
490
Jan Voung72984d82015-01-29 14:42:38 -0800491class TargetDataX8632 : public TargetDataLowering {
492 TargetDataX8632() = delete;
493 TargetDataX8632(const TargetDataX8632 &) = delete;
494 TargetDataX8632 &operator=(const TargetDataX8632 &) = delete;
Jim Stichnoth7b451a92014-10-15 14:39:23 -0700495
Jim Stichnothde4ca712014-06-29 08:13:48 -0700496public:
Jan Voung72984d82015-01-29 14:42:38 -0800497 static TargetDataLowering *create(GlobalContext *Ctx) {
498 return new TargetDataX8632(Ctx);
Jim Stichnothde4ca712014-06-29 08:13:48 -0700499 }
Karl Schimpfe3f64d02014-10-07 10:38:22 -0700500
Jan Voung72984d82015-01-29 14:42:38 -0800501 void lowerGlobal(const VariableDeclaration &Var) const final;
502 void lowerGlobalsELF(const VariableDeclarationList &Vars) const final;
503 void lowerConstants(GlobalContext *Ctx) const final;
Jim Stichnothde4ca712014-06-29 08:13:48 -0700504
505protected:
Jan Voung72984d82015-01-29 14:42:38 -0800506 TargetDataX8632(GlobalContext *Ctx);
Jim Stichnothde4ca712014-06-29 08:13:48 -0700507
508private:
Jan Voung72984d82015-01-29 14:42:38 -0800509 ~TargetDataX8632() override {}
Jim Stichnothfa4efea2015-01-27 05:06:03 -0800510 template <typename T> static void emitConstantPool(GlobalContext *Ctx);
Jim Stichnothde4ca712014-06-29 08:13:48 -0700511};
512
Jan Voungbc004632014-09-16 15:09:10 -0700513template <> void ConstantInteger32::emit(GlobalContext *Ctx) const;
514template <> void ConstantInteger64::emit(GlobalContext *Ctx) const;
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700515template <> void ConstantFloat::emit(GlobalContext *Ctx) const;
516template <> void ConstantDouble::emit(GlobalContext *Ctx) const;
Jim Stichnothf61d5b22014-05-23 13:31:24 -0700517
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700518} // end of namespace Ice
519
520#endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H