blob: f6b305eb949c4b866d31e49d51818787f75b8e32 [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 {
28public:
29 static TargetX8632 *create(Cfg *Func) { return new TargetX8632(Func); }
30
Jim Stichnothb56c8f42014-09-26 09:28:46 -070031 void translateOm1() override;
32 void translateO2() override;
33 bool doBranchOpt(Inst *I, const CfgNode *NextNode) override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070034
Jim Stichnothb56c8f42014-09-26 09:28:46 -070035 Variable *getPhysicalRegister(SizeT RegNum) override;
36 IceString getRegName(SizeT RegNum, Type Ty) const override;
37 llvm::SmallBitVector getRegisterSet(RegSetMask Include,
38 RegSetMask Exclude) const override;
39 const llvm::SmallBitVector &getRegisterSetForType(Type Ty) const override {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070040 return TypeToRegisterSet[Ty];
41 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070042 bool hasFramePointer() const override { return IsEbpBasedFrame; }
43 SizeT getFrameOrStackReg() const override {
Jan Voungbd385e42014-09-18 18:18:10 -070044 return IsEbpBasedFrame ? RegX8632::Reg_ebp : RegX8632::Reg_esp;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070045 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070046 size_t typeWidthInBytesOnStack(Type Ty) const override {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070047 // Round up to the next multiple of 4 bytes. In particular, i1,
48 // i8, and i16 are rounded up to 4 bytes.
49 return (typeWidthInBytes(Ty) + 3) & ~3;
50 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070051 SizeT getBundleAlignLog2Bytes() const override { return 5; }
Jim Stichnothf44f3712014-10-01 14:05:51 -070052 llvm::ArrayRef<AsmCodeByte> getNonExecBundlePadding() const override {
53 static const AsmCodeByte Padding[] = { 0xF4 };
54 return llvm::ArrayRef<AsmCodeByte>(Padding, 1);
Jan Voungb17f61d2014-08-28 16:00:53 -070055 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -070056 void emitVariable(const Variable *Var) const override;
57 void lowerArguments() override;
58 void addProlog(CfgNode *Node) override;
59 void addEpilog(CfgNode *Node) override;
60 void emitConstants() const override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070061 SizeT makeNextLabelNumber() { return NextLabelNumber++; }
62 // Ensure that a 64-bit Variable has been split into 2 32-bit
63 // Variables, creating them if necessary. This is needed for all
64 // I64 operations, and it is needed for pushing F64 arguments for
65 // function calls using the 32-bit push instruction (though the
66 // latter could be done by directly writing to the stack).
67 void split64(Variable *Var);
Matt Wala45a06232014-07-09 16:33:22 -070068 void finishArgumentLowering(Variable *Arg, Variable *FramePtr,
69 size_t BasicFrameOffset, size_t &InArgsSizeBytes);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070070 Operand *loOperand(Operand *Operand);
71 Operand *hiOperand(Operand *Operand);
Jan Voung8acded02014-09-22 18:02:25 -070072 x86::Address stackVarToAsmOperand(const Variable *Var) const;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070073
Matt Wala0a450512014-07-30 12:44:39 -070074 enum X86InstructionSet {
75 // SSE2 is the PNaCl baseline instruction set.
76 SSE2,
77 SSE4_1
78 };
79
80 X86InstructionSet getInstructionSet() const { return InstructionSet; }
81
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070082protected:
83 TargetX8632(Cfg *Func);
84
Jim Stichnothb56c8f42014-09-26 09:28:46 -070085 void postLower() override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -070086
Jim Stichnothb56c8f42014-09-26 09:28:46 -070087 void lowerAlloca(const InstAlloca *Inst) override;
88 void lowerArithmetic(const InstArithmetic *Inst) override;
89 void lowerAssign(const InstAssign *Inst) override;
90 void lowerBr(const InstBr *Inst) override;
91 void lowerCall(const InstCall *Inst) override;
92 void lowerCast(const InstCast *Inst) override;
93 void lowerExtractElement(const InstExtractElement *Inst) override;
94 void lowerFcmp(const InstFcmp *Inst) override;
95 void lowerIcmp(const InstIcmp *Inst) override;
96 void lowerIntrinsicCall(const InstIntrinsicCall *Inst) override;
97 void lowerInsertElement(const InstInsertElement *Inst) override;
98 void lowerLoad(const InstLoad *Inst) override;
99 void lowerPhi(const InstPhi *Inst) override;
100 void lowerRet(const InstRet *Inst) override;
101 void lowerSelect(const InstSelect *Inst) override;
102 void lowerStore(const InstStore *Inst) override;
103 void lowerSwitch(const InstSwitch *Inst) override;
104 void lowerUnreachable(const InstUnreachable *Inst) override;
105 void doAddressOptLoad() override;
106 void doAddressOptStore() override;
107 void randomlyInsertNop(float Probability) override;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700108
Jan Voungc820ddf2014-07-29 14:38:51 -0700109 // Naive lowering of cmpxchg.
Jan Vounga3a01a22014-07-14 10:32:41 -0700110 void lowerAtomicCmpxchg(Variable *DestPrev, Operand *Ptr, Operand *Expected,
111 Operand *Desired);
Jan Voungc820ddf2014-07-29 14:38:51 -0700112 // Attempt a more optimized lowering of cmpxchg. Returns true if optimized.
113 bool tryOptimizedCmpxchgCmpBr(Variable *DestPrev, Operand *Ptr,
114 Operand *Expected, Operand *Desired);
Jan Voung5cd240d2014-06-25 10:36:46 -0700115 void lowerAtomicRMW(Variable *Dest, uint32_t Operation, Operand *Ptr,
116 Operand *Val);
Jan Vounge4da26f2014-07-15 17:52:39 -0700117 void lowerCountZeros(bool Cttz, Type Ty, Variable *Dest, Operand *FirstVal,
118 Operand *SecondVal);
Jan Voung5cd240d2014-06-25 10:36:46 -0700119
Jan Vounga3a01a22014-07-14 10:32:41 -0700120 typedef void (TargetX8632::*LowerBinOp)(Variable *, Operand *);
121 void expandAtomicRMWAsCmpxchg(LowerBinOp op_lo, LowerBinOp op_hi,
122 Variable *Dest, Operand *Ptr, Operand *Val);
123
Matt Walace0ca8f2014-07-24 12:34:20 -0700124 void eliminateNextVectorSextInstruction(Variable *SignExtendedResult);
125
Matt Walaafeaee42014-08-07 13:47:30 -0700126 void scalarizeArithmetic(InstArithmetic::OpKind K, Variable *Dest,
127 Operand *Src0, Operand *Src1);
128
Matt Walad4799f42014-08-14 14:24:12 -0700129 void sortByAlignment(VarList &Dest, const VarList &Source) const;
130
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700131 // Operand legalization helpers. To deal with address mode
132 // constraints, the helpers will create a new Operand and emit
133 // instructions that guarantee that the Operand kind is one of those
134 // indicated by the LegalMask (a bitmask of allowed kinds). If the
135 // input Operand is known to already meet the constraints, it may be
136 // simply returned as the result, without creating any new
137 // instructions or operands.
138 enum OperandLegalization {
139 Legal_None = 0,
140 Legal_Reg = 1 << 0, // physical register, not stack location
141 Legal_Imm = 1 << 1,
142 Legal_Mem = 1 << 2, // includes [eax+4*ecx] as well as [esp+12]
Jim Stichnothde4ca712014-06-29 08:13:48 -0700143 // TODO(stichnot): LEAHACK: remove Legal_Reloc once a proper
144 // emitter is used.
145 Legal_Reloc = 1 << 3,
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700146 Legal_All = ~Legal_None
147 };
148 typedef uint32_t LegalMask;
Jim Stichnothde4ca712014-06-29 08:13:48 -0700149 Operand *legalize(Operand *From, LegalMask Allowed = Legal_All & ~Legal_Reloc,
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700150 int32_t RegNum = Variable::NoRegister);
Jim Stichnothad403532014-09-25 12:44:17 -0700151 Variable *legalizeToVar(Operand *From, int32_t RegNum = Variable::NoRegister);
Jan Voung5cd240d2014-06-25 10:36:46 -0700152 // Turn a pointer operand into a memory operand that can be
153 // used by a real load/store operation. Legalizes the operand as well.
154 // This is a nop if the operand is already a legal memory operand.
155 OperandX8632Mem *FormMemoryOperand(Operand *Ptr, Type Ty);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700156
157 Variable *makeReg(Type Ty, int32_t RegNum = Variable::NoRegister);
158 InstCall *makeHelperCall(const IceString &Name, Variable *Dest,
159 SizeT MaxSrcs) {
160 bool SuppressMangling = true;
Matt Walaad8f7262014-07-14 17:37:37 -0700161 const Type FunctionPointerType = IceType_i32;
162 Constant *CallTarget =
163 Ctx->getConstantSym(FunctionPointerType, 0, Name, SuppressMangling);
Karl Schimpf8df26f32014-09-19 09:33:26 -0700164 InstCall *Call = InstCall::create(Func, MaxSrcs, Dest, CallTarget, false);
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700165 return Call;
166 }
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700167 static Type stackSlotType();
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700168
Matt Wala928f1292014-07-07 16:50:46 -0700169 Variable *copyToReg(Operand *Src, int32_t RegNum = Variable::NoRegister);
170
Matt Wala83b80362014-07-16 10:21:30 -0700171 // Returns a vector in a register with the given constant entries.
172 Variable *makeVectorOfZeros(Type Ty, int32_t RegNum = Variable::NoRegister);
173 Variable *makeVectorOfOnes(Type Ty, int32_t RegNum = Variable::NoRegister);
Matt Wala9a0168a2014-07-23 14:56:10 -0700174 Variable *makeVectorOfMinusOnes(Type Ty,
175 int32_t RegNum = Variable::NoRegister);
176 Variable *makeVectorOfHighOrderBits(Type Ty,
177 int32_t RegNum = Variable::NoRegister);
Matt Wala83b80362014-07-16 10:21:30 -0700178
Matt Wala49889232014-07-18 12:45:09 -0700179 // Return a memory operand corresponding to a stack allocated Variable.
180 OperandX8632Mem *getMemoryOperandForStackSlot(Type Ty, Variable *Slot,
181 uint32_t Offset = 0);
182
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700183 // The following are helpers that insert lowered x86 instructions
184 // with minimal syntactic overhead, so that the lowering code can
185 // look as close to assembly as practical.
186 void _adc(Variable *Dest, Operand *Src0) {
187 Context.insert(InstX8632Adc::create(Func, Dest, Src0));
188 }
189 void _add(Variable *Dest, Operand *Src0) {
190 Context.insert(InstX8632Add::create(Func, Dest, Src0));
191 }
Matt Wala105b7042014-08-11 19:56:19 -0700192 void _adjust_stack(int32_t Amount) {
Jim Stichnoth144cdce2014-09-22 16:02:59 -0700193 Context.insert(InstX8632AdjustStack::create(
194 Func, Amount, getPhysicalRegister(RegX8632::Reg_esp)));
Matt Wala105b7042014-08-11 19:56:19 -0700195 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700196 void _addps(Variable *Dest, Operand *Src0) {
197 Context.insert(InstX8632Addps::create(Func, Dest, Src0));
198 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700199 void _addss(Variable *Dest, Operand *Src0) {
200 Context.insert(InstX8632Addss::create(Func, Dest, Src0));
201 }
202 void _and(Variable *Dest, Operand *Src0) {
203 Context.insert(InstX8632And::create(Func, Dest, Src0));
204 }
Matt Wala0a450512014-07-30 12:44:39 -0700205 void _blendvps(Variable *Dest, Operand *Src0, Operand *Src1) {
206 Context.insert(InstX8632Blendvps::create(Func, Dest, Src0, Src1));
207 }
Jan Voungbd385e42014-09-18 18:18:10 -0700208 void _br(CondX86::BrCond Condition, CfgNode *TargetTrue,
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700209 CfgNode *TargetFalse) {
210 Context.insert(
211 InstX8632Br::create(Func, TargetTrue, TargetFalse, Condition));
212 }
213 void _br(CfgNode *Target) {
214 Context.insert(InstX8632Br::create(Func, Target));
215 }
Jan Voungbd385e42014-09-18 18:18:10 -0700216 void _br(CondX86::BrCond Condition, CfgNode *Target) {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700217 Context.insert(InstX8632Br::create(Func, Target, Condition));
218 }
Jan Voungbd385e42014-09-18 18:18:10 -0700219 void _br(CondX86::BrCond Condition, InstX8632Label *Label) {
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700220 Context.insert(InstX8632Br::create(Func, Label, Condition));
221 }
Jan Vounge4da26f2014-07-15 17:52:39 -0700222 void _bsf(Variable *Dest, Operand *Src0) {
223 Context.insert(InstX8632Bsf::create(Func, Dest, Src0));
224 }
225 void _bsr(Variable *Dest, Operand *Src0) {
226 Context.insert(InstX8632Bsr::create(Func, Dest, Src0));
227 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700228 void _bswap(Variable *SrcDest) {
229 Context.insert(InstX8632Bswap::create(Func, SrcDest));
230 }
Matt Walaafeaee42014-08-07 13:47:30 -0700231 void _cbwdq(Variable *Dest, Operand *Src0) {
232 Context.insert(InstX8632Cbwdq::create(Func, Dest, Src0));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700233 }
Jan Voungbd385e42014-09-18 18:18:10 -0700234 void _cmov(Variable *Dest, Operand *Src0, CondX86::BrCond Condition) {
Jan Vounge4da26f2014-07-15 17:52:39 -0700235 Context.insert(InstX8632Cmov::create(Func, Dest, Src0, Condition));
236 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700237 void _cmp(Operand *Src0, Operand *Src1) {
238 Context.insert(InstX8632Icmp::create(Func, Src0, Src1));
239 }
Jan Voungbd385e42014-09-18 18:18:10 -0700240 void _cmpps(Variable *Dest, Operand *Src0, CondX86::CmppsCond Condition) {
Matt Walace0ca8f2014-07-24 12:34:20 -0700241 Context.insert(InstX8632Cmpps::create(Func, Dest, Src0, Condition));
242 }
Jan Vounga3a01a22014-07-14 10:32:41 -0700243 void _cmpxchg(Operand *DestOrAddr, Variable *Eax, Variable *Desired,
244 bool Locked) {
245 Context.insert(
246 InstX8632Cmpxchg::create(Func, DestOrAddr, Eax, Desired, Locked));
247 // Mark eax as possibly modified by cmpxchg.
248 Context.insert(
249 InstFakeDef::create(Func, Eax, llvm::dyn_cast<Variable>(DestOrAddr)));
250 }
Jan Voung03532e52014-09-23 13:32:18 -0700251 void _cmpxchg8b(OperandX8632Mem *Addr, Variable *Edx, Variable *Eax,
Jan Vounga3a01a22014-07-14 10:32:41 -0700252 Variable *Ecx, Variable *Ebx, bool Locked) {
253 Context.insert(
254 InstX8632Cmpxchg8b::create(Func, Addr, Edx, Eax, Ecx, Ebx, Locked));
255 // Mark edx, and eax as possibly modified by cmpxchg8b.
256 Context.insert(InstFakeDef::create(Func, Edx));
257 Context.insert(InstFakeDef::create(Func, Eax));
258 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700259 void _cvt(Variable *Dest, Operand *Src0) {
Jim Stichnothb63cd882014-09-08 10:47:23 -0700260 const bool Trunc = false;
261 Context.insert(InstX8632Cvt::create(Func, Dest, Src0, Trunc));
262 }
263 void _cvtt(Variable *Dest, Operand *Src0) {
264 const bool Trunc = true;
265 Context.insert(InstX8632Cvt::create(Func, Dest, Src0, Trunc));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700266 }
267 void _div(Variable *Dest, Operand *Src0, Operand *Src1) {
268 Context.insert(InstX8632Div::create(Func, Dest, Src0, Src1));
269 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700270 void _divps(Variable *Dest, Operand *Src0) {
271 Context.insert(InstX8632Divps::create(Func, Dest, Src0));
272 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700273 void _divss(Variable *Dest, Operand *Src0) {
274 Context.insert(InstX8632Divss::create(Func, Dest, Src0));
275 }
276 void _fld(Operand *Src0) { Context.insert(InstX8632Fld::create(Func, Src0)); }
277 void _fstp(Variable *Dest) {
278 Context.insert(InstX8632Fstp::create(Func, Dest));
279 }
280 void _idiv(Variable *Dest, Operand *Src0, Operand *Src1) {
281 Context.insert(InstX8632Idiv::create(Func, Dest, Src0, Src1));
282 }
283 void _imul(Variable *Dest, Operand *Src0) {
284 Context.insert(InstX8632Imul::create(Func, Dest, Src0));
285 }
Matt Wala0a450512014-07-30 12:44:39 -0700286 void _insertps(Variable *Dest, Operand *Src0, Operand *Src1) {
287 Context.insert(InstX8632Insertps::create(Func, Dest, Src0, Src1));
288 }
Matt Wala49889232014-07-18 12:45:09 -0700289 void _lea(Variable *Dest, Operand *Src0) {
290 Context.insert(InstX8632Lea::create(Func, Dest, Src0));
291 }
Jan Voung5cd240d2014-06-25 10:36:46 -0700292 void _mfence() { Context.insert(InstX8632Mfence::create(Func)); }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700293 // If Dest=NULL is passed in, then a new variable is created, marked
294 // as infinite register allocation weight, and returned through the
295 // in/out Dest argument.
296 void _mov(Variable *&Dest, Operand *Src0,
297 int32_t RegNum = Variable::NoRegister) {
Jim Stichnothad403532014-09-25 12:44:17 -0700298 if (Dest == NULL)
299 Dest = makeReg(Src0->getType(), RegNum);
300 Context.insert(InstX8632Mov::create(Func, Dest, Src0));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700301 }
Matt Wala49889232014-07-18 12:45:09 -0700302 void _movd(Variable *Dest, Operand *Src0) {
303 Context.insert(InstX8632Movd::create(Func, Dest, Src0));
304 }
Matt Wala928f1292014-07-07 16:50:46 -0700305 void _movp(Variable *Dest, Operand *Src0) {
306 Context.insert(InstX8632Movp::create(Func, Dest, Src0));
307 }
Jan Voung5cd240d2014-06-25 10:36:46 -0700308 void _movq(Variable *Dest, Operand *Src0) {
309 Context.insert(InstX8632Movq::create(Func, Dest, Src0));
310 }
Jan Vounge4dc61b2014-10-06 08:53:52 -0700311 void _movss(Variable *Dest, Variable *Src0) {
312 Context.insert(InstX8632MovssRegs::create(Func, Dest, Src0));
Matt Wala49889232014-07-18 12:45:09 -0700313 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700314 void _movsx(Variable *Dest, Operand *Src0) {
315 Context.insert(InstX8632Movsx::create(Func, Dest, Src0));
316 }
317 void _movzx(Variable *Dest, Operand *Src0) {
318 Context.insert(InstX8632Movzx::create(Func, Dest, Src0));
319 }
320 void _mul(Variable *Dest, Variable *Src0, Operand *Src1) {
321 Context.insert(InstX8632Mul::create(Func, Dest, Src0, Src1));
322 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700323 void _mulps(Variable *Dest, Operand *Src0) {
324 Context.insert(InstX8632Mulps::create(Func, Dest, Src0));
325 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700326 void _mulss(Variable *Dest, Operand *Src0) {
327 Context.insert(InstX8632Mulss::create(Func, Dest, Src0));
328 }
Jan Vounga3a01a22014-07-14 10:32:41 -0700329 void _neg(Variable *SrcDest) {
330 Context.insert(InstX8632Neg::create(Func, SrcDest));
331 }
Matt Walac3302742014-08-15 16:21:56 -0700332 void _nop(SizeT Variant) {
333 Context.insert(InstX8632Nop::create(Func, Variant));
334 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700335 void _or(Variable *Dest, Operand *Src0) {
336 Context.insert(InstX8632Or::create(Func, Dest, Src0));
337 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700338 void _padd(Variable *Dest, Operand *Src0) {
339 Context.insert(InstX8632Padd::create(Func, Dest, Src0));
340 }
Matt Wala83b80362014-07-16 10:21:30 -0700341 void _pand(Variable *Dest, Operand *Src0) {
342 Context.insert(InstX8632Pand::create(Func, Dest, Src0));
343 }
Matt Wala9cb61e22014-07-24 09:44:42 -0700344 void _pandn(Variable *Dest, Operand *Src0) {
345 Context.insert(InstX8632Pandn::create(Func, Dest, Src0));
346 }
Matt Wala0a450512014-07-30 12:44:39 -0700347 void _pblendvb(Variable *Dest, Operand *Src0, Operand *Src1) {
348 Context.insert(InstX8632Pblendvb::create(Func, Dest, Src0, Src1));
349 }
Matt Wala83b80362014-07-16 10:21:30 -0700350 void _pcmpeq(Variable *Dest, Operand *Src0) {
351 Context.insert(InstX8632Pcmpeq::create(Func, Dest, Src0));
352 }
353 void _pcmpgt(Variable *Dest, Operand *Src0) {
354 Context.insert(InstX8632Pcmpgt::create(Func, Dest, Src0));
355 }
Matt Wala0a450512014-07-30 12:44:39 -0700356 void _pextr(Variable *Dest, Operand *Src0, Operand *Src1) {
357 Context.insert(InstX8632Pextr::create(Func, Dest, Src0, Src1));
Matt Wala49889232014-07-18 12:45:09 -0700358 }
Matt Wala0a450512014-07-30 12:44:39 -0700359 void _pinsr(Variable *Dest, Operand *Src0, Operand *Src1) {
360 Context.insert(InstX8632Pinsr::create(Func, Dest, Src0, Src1));
Matt Wala49889232014-07-18 12:45:09 -0700361 }
Matt Wala0a450512014-07-30 12:44:39 -0700362 void _pmull(Variable *Dest, Operand *Src0) {
363 Context.insert(InstX8632Pmull::create(Func, Dest, Src0));
Matt Wala7fa22d82014-07-17 12:41:31 -0700364 }
365 void _pmuludq(Variable *Dest, Operand *Src0) {
366 Context.insert(InstX8632Pmuludq::create(Func, Dest, Src0));
367 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700368 void _pop(Variable *Dest) {
369 Context.insert(InstX8632Pop::create(Func, Dest));
370 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700371 void _por(Variable *Dest, Operand *Src0) {
372 Context.insert(InstX8632Por::create(Func, Dest, Src0));
373 }
374 void _pshufd(Variable *Dest, Operand *Src0, Operand *Src1) {
375 Context.insert(InstX8632Pshufd::create(Func, Dest, Src0, Src1));
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700376 }
Matt Wala83b80362014-07-16 10:21:30 -0700377 void _psll(Variable *Dest, Operand *Src0) {
378 Context.insert(InstX8632Psll::create(Func, Dest, Src0));
379 }
380 void _psra(Variable *Dest, Operand *Src0) {
381 Context.insert(InstX8632Psra::create(Func, Dest, Src0));
382 }
383 void _psub(Variable *Dest, Operand *Src0) {
384 Context.insert(InstX8632Psub::create(Func, Dest, Src0));
385 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700386 void _push(Operand *Src0, bool SuppressStackAdjustment = false) {
387 Context.insert(InstX8632Push::create(Func, Src0, SuppressStackAdjustment));
388 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700389 void _pxor(Variable *Dest, Operand *Src0) {
390 Context.insert(InstX8632Pxor::create(Func, Dest, Src0));
391 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700392 void _ret(Variable *Src0 = NULL) {
393 Context.insert(InstX8632Ret::create(Func, Src0));
394 }
Jan Voung7fa813b2014-07-18 13:01:08 -0700395 void _rol(Variable *Dest, Operand *Src0) {
396 Context.insert(InstX8632Rol::create(Func, Dest, Src0));
397 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700398 void _sar(Variable *Dest, Operand *Src0) {
399 Context.insert(InstX8632Sar::create(Func, Dest, Src0));
400 }
401 void _sbb(Variable *Dest, Operand *Src0) {
402 Context.insert(InstX8632Sbb::create(Func, Dest, Src0));
403 }
404 void _shl(Variable *Dest, Operand *Src0) {
405 Context.insert(InstX8632Shl::create(Func, Dest, Src0));
406 }
407 void _shld(Variable *Dest, Variable *Src0, Variable *Src1) {
408 Context.insert(InstX8632Shld::create(Func, Dest, Src0, Src1));
409 }
410 void _shr(Variable *Dest, Operand *Src0) {
411 Context.insert(InstX8632Shr::create(Func, Dest, Src0));
412 }
413 void _shrd(Variable *Dest, Variable *Src0, Variable *Src1) {
414 Context.insert(InstX8632Shrd::create(Func, Dest, Src0, Src1));
415 }
Matt Wala7fa22d82014-07-17 12:41:31 -0700416 void _shufps(Variable *Dest, Operand *Src0, Operand *Src1) {
417 Context.insert(InstX8632Shufps::create(Func, Dest, Src0, Src1));
418 }
Jan Voungf37fbbe2014-07-09 16:13:13 -0700419 void _sqrtss(Variable *Dest, Operand *Src0) {
420 Context.insert(InstX8632Sqrtss::create(Func, Dest, Src0));
421 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700422 void _store(Operand *Value, OperandX8632 *Mem) {
423 Context.insert(InstX8632Store::create(Func, Value, Mem));
424 }
Jan Vounge4dc61b2014-10-06 08:53:52 -0700425 void _storep(Variable *Value, OperandX8632Mem *Mem) {
Matt Wala105b7042014-08-11 19:56:19 -0700426 Context.insert(InstX8632StoreP::create(Func, Value, Mem));
427 }
Jan Vounge4dc61b2014-10-06 08:53:52 -0700428 void _storeq(Variable *Value, OperandX8632Mem *Mem) {
Jan Voung5cd240d2014-06-25 10:36:46 -0700429 Context.insert(InstX8632StoreQ::create(Func, Value, Mem));
430 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700431 void _sub(Variable *Dest, Operand *Src0) {
432 Context.insert(InstX8632Sub::create(Func, Dest, Src0));
433 }
Matt Wala8d1072e2014-07-11 15:43:51 -0700434 void _subps(Variable *Dest, Operand *Src0) {
435 Context.insert(InstX8632Subps::create(Func, Dest, Src0));
436 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700437 void _subss(Variable *Dest, Operand *Src0) {
438 Context.insert(InstX8632Subss::create(Func, Dest, Src0));
439 }
440 void _test(Operand *Src0, Operand *Src1) {
441 Context.insert(InstX8632Test::create(Func, Src0, Src1));
442 }
443 void _ucomiss(Operand *Src0, Operand *Src1) {
444 Context.insert(InstX8632Ucomiss::create(Func, Src0, Src1));
445 }
Jan Voung3bd9f1a2014-06-18 10:50:57 -0700446 void _ud2() { Context.insert(InstX8632UD2::create(Func)); }
Jan Voung5cd240d2014-06-25 10:36:46 -0700447 void _xadd(Operand *Dest, Variable *Src, bool Locked) {
448 Context.insert(InstX8632Xadd::create(Func, Dest, Src, Locked));
449 // The xadd exchanges Dest and Src (modifying Src).
450 // Model that update with a FakeDef.
Jan Vounga3a01a22014-07-14 10:32:41 -0700451 Context.insert(
452 InstFakeDef::create(Func, Src, llvm::dyn_cast<Variable>(Dest)));
453 }
454 void _xchg(Operand *Dest, Variable *Src) {
455 Context.insert(InstX8632Xchg::create(Func, Dest, Src));
456 // The xchg modifies Dest and Src -- model that update with a FakeDef.
457 Context.insert(
458 InstFakeDef::create(Func, Src, llvm::dyn_cast<Variable>(Dest)));
Jan Voung5cd240d2014-06-25 10:36:46 -0700459 }
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700460 void _xor(Variable *Dest, Operand *Src0) {
461 Context.insert(InstX8632Xor::create(Func, Dest, Src0));
462 }
463
Matt Wala0a450512014-07-30 12:44:39 -0700464 const X86InstructionSet InstructionSet;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700465 bool IsEbpBasedFrame;
Matt Wala105b7042014-08-11 19:56:19 -0700466 bool NeedsStackAlignment;
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700467 size_t FrameSizeLocals;
Matt Walad4799f42014-08-14 14:24:12 -0700468 size_t SpillAreaSizeBytes;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700469 llvm::SmallBitVector TypeToRegisterSet[IceType_NUM];
470 llvm::SmallBitVector ScratchRegs;
471 llvm::SmallBitVector RegsUsed;
472 SizeT NextLabelNumber;
473 bool ComputedLiveRanges;
474 VarList PhysicalRegisters;
475 static IceString RegNames[];
476
477private:
Jim Stichnoth0795ba02014-10-01 14:23:01 -0700478 TargetX8632(const TargetX8632 &) = delete;
479 TargetX8632 &operator=(const TargetX8632 &) = delete;
Jim Stichnothb56c8f42014-09-26 09:28:46 -0700480 ~TargetX8632() override {}
Jim Stichnothf61d5b22014-05-23 13:31:24 -0700481 template <typename T> void emitConstantPool() const;
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700482};
483
Jim Stichnothde4ca712014-06-29 08:13:48 -0700484class TargetGlobalInitX8632 : public TargetGlobalInitLowering {
485public:
486 static TargetGlobalInitLowering *create(GlobalContext *Ctx) {
487 return new TargetGlobalInitX8632(Ctx);
488 }
Jim Stichnothb56c8f42014-09-26 09:28:46 -0700489 void lower(const IceString &Name, SizeT Align, bool IsInternal, bool IsConst,
490 bool IsZeroInitializer, SizeT Size, const char *Data,
491 bool DisableTranslation) override;
Jim Stichnothde4ca712014-06-29 08:13:48 -0700492
493protected:
494 TargetGlobalInitX8632(GlobalContext *Ctx);
495
496private:
Jim Stichnoth0795ba02014-10-01 14:23:01 -0700497 TargetGlobalInitX8632(const TargetGlobalInitX8632 &) = delete;
498 TargetGlobalInitX8632 &operator=(const TargetGlobalInitX8632 &) = delete;
Jim Stichnothb56c8f42014-09-26 09:28:46 -0700499 ~TargetGlobalInitX8632() override {}
Jim Stichnothde4ca712014-06-29 08:13:48 -0700500};
501
Jan Voungbc004632014-09-16 15:09:10 -0700502template <> void ConstantInteger32::emit(GlobalContext *Ctx) const;
503template <> void ConstantInteger64::emit(GlobalContext *Ctx) const;
Jim Stichnothd97c7df2014-06-04 11:57:08 -0700504template <> void ConstantFloat::emit(GlobalContext *Ctx) const;
505template <> void ConstantDouble::emit(GlobalContext *Ctx) const;
Jim Stichnothf61d5b22014-05-23 13:31:24 -0700506
Jim Stichnoth5bc2b1d2014-05-22 13:38:48 -0700507} // end of namespace Ice
508
509#endif // SUBZERO_SRC_ICETARGETLOWERINGX8632_H