Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / core / CodegenLIR-inlines.h
blobf52ca26125518d3e4eea31c29fa02f3c1f191baa
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 2004-2008
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
25 * leon.sha@sun.com
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 namespace avmplus {
43 using namespace nanojit;
45 REALLY_INLINE BuiltinType LirHelper::bt(Traits *t)
47 return Traits::getBuiltinType(t);
50 REALLY_INLINE LIns* CodegenLIR::loadIns(LOpcode op, int32_t disp, LIns *base, AccSet accSet, LoadQual loadQual)
52 return lirout->insLoad(op, base, disp, accSet, loadQual);
55 REALLY_INLINE LIns* CodegenLIR::storeIns(LOpcode op, LIns* val, int32_t disp, LIns *base, AccSet accSet)
57 return lirout->insStore(op, val, base, disp, accSet);
60 REALLY_INLINE LIns* CodegenLIR::Ins(LOpcode op)
62 return lirout->ins0(op);
65 REALLY_INLINE LIns* CodegenLIR::Ins(LOpcode op, LIns *a)
67 return lirout->ins1(op, a);
70 REALLY_INLINE LIns* CodegenLIR::i2dIns(LIns* v)
72 return lirout->ins1(LIR_i2d, v);
75 REALLY_INLINE LIns* CodegenLIR::ui2dIns(LIns* v)
77 return lirout->ins1(LIR_ui2d, v);
80 REALLY_INLINE LIns* CodegenLIR::p2dIns(LIns* v)
82 #ifdef NANOJIT_64BIT
83 // Not yet implemented on 64-bit platforms.
84 (void)v;
85 AvmAssert(false);
86 return NULL;
87 #else
88 return lirout->ins1(LIR_i2d, v);
89 #endif
92 REALLY_INLINE LIns* CodegenLIR::binaryIns(LOpcode op, LIns *a, LIns *b)
94 return lirout->ins2(op,a,b);
97 REALLY_INLINE LIns* LirHelper::InsConst(int32_t c)
99 return lirout->insImmI(c);
102 REALLY_INLINE LIns* LirHelper::InsConstPtr(const void *p)
104 return lirout->insImmP(p);
107 REALLY_INLINE LIns* LirHelper::InsConstAtom(Atom c)
109 return lirout->insImmP((void*)c);
112 REALLY_INLINE LIns* LirHelper::i2p(LIns *i)
114 return lirout->insI2P(i);
117 REALLY_INLINE LIns* LirHelper::ui2p(LIns *i)
119 return lirout->insUI2P(i);
122 REALLY_INLINE LIns* LirHelper::p2i(LIns *i)
124 #ifdef NANOJIT_64BIT
125 return lirout->ins1(LIR_q2i, i);
126 #else
127 return i;
128 #endif
131 #if NJ_SOFTFLOAT_SUPPORTED
132 REALLY_INLINE LIns* LirHelper::qlo(LIns* q)
134 return lirout->ins1(LIR_dlo2i, q);
136 #endif
138 REALLY_INLINE LIns* LirHelper::eqp0(LIns* ptr)
140 return lirout->insEqP_0(ptr);
143 REALLY_INLINE LIns* LirHelper::eqi0(LIns* ptr)
145 return lirout->insEqI_0(ptr);
148 REALLY_INLINE LIns* LirHelper::eqp(LIns* a, Atom b)
150 return eqp(a, InsConstAtom(b));
153 REALLY_INLINE LIns* LirHelper::eqp(LIns* a, LIns* b)
155 return lirout->ins2(LIR_eqp, a, b);
158 REALLY_INLINE LIns* LirHelper::ltup(LIns* a, LIns* b)
160 return lirout->ins2(LIR_ltup, a, b);
163 REALLY_INLINE LIns* LirHelper::choose(LIns* cond, Atom t, LIns* f)
165 return lirout->insChoose(cond, InsConstAtom(t), f, use_cmov);
168 REALLY_INLINE LIns* LirHelper::addp(LIns* a, Atom mask)
170 return lirout->ins2(LIR_addp, a, InsConstAtom(mask));
173 REALLY_INLINE LIns* LirHelper::andp(LIns* a, Atom mask)
175 return lirout->ins2(LIR_andp, a, InsConstAtom(mask));
178 REALLY_INLINE LIns* LirHelper::orp(LIns* a, Atom mask)
180 return lirout->ins2(LIR_orp, a, InsConstAtom(mask));
183 REALLY_INLINE LIns* LirHelper::addi(LIns* a, int32_t mask)
185 return lirout->ins2(LIR_addi, a, InsConst(mask));
188 REALLY_INLINE LIns* LirHelper::ori(LIns* a, int32_t mask)
190 return lirout->ins2(LIR_ori, a, InsConst(mask));
193 REALLY_INLINE LIns* LirHelper::xorp(LIns* a, Atom mask)
195 return lirout->ins2(LIR_xorp, a, InsConstAtom(mask));
198 REALLY_INLINE LIns* LirHelper::subp(LIns* a, int32_t offset)
200 return lirout->ins2(LIR_subp, a, InsConstAtom(offset));
203 REALLY_INLINE LIns* LirHelper::retp(LIns* a)
205 return lirout->ins1(LIR_retp, a);
208 REALLY_INLINE LIns* LirHelper::label()
210 return lirout->ins0(LIR_label);
213 REALLY_INLINE LIns* LirHelper::jlti(LIns *a, int32_t b)
215 return lirout->insBranch(LIR_jt, lirout->ins2(LIR_lti, a, InsConst(b)), NULL);
218 REALLY_INLINE LIns* LirHelper::jgti(LIns *a, int32_t b)
220 return lirout->insBranch(LIR_jt, lirout->ins2(LIR_gti, a, InsConst(b)), NULL);
223 REALLY_INLINE LIns* LirHelper::jnei(LIns *a, int32_t b)
225 return lirout->insBranch(LIR_jf, lirout->ins2(LIR_eqi, a, InsConst(b)), NULL);
228 REALLY_INLINE LIns* LirHelper::stp(LIns* val, LIns* p, int32_t d, AccSet accSet)
230 AvmAssert(val->isP());
231 return lirout->insStore(LIR_stp, val, p, d, accSet);
234 REALLY_INLINE LIns* LirHelper::sti(LIns* val, LIns* p, int32_t d, AccSet accSet)
236 AvmAssert(val->isI());
237 return lirout->insStore(LIR_sti, val, p, d, accSet);
240 REALLY_INLINE LIns* LirHelper::std(LIns* val, LIns* p, int32_t d, AccSet accSet)
242 AvmAssert(val->isD());
243 return lirout->insStore(LIR_std, val, p, d, accSet);
246 REALLY_INLINE LIns* LirHelper::ldi(LIns* p, int32_t d, AccSet accSet)
248 return lirout->insLoad(LIR_ldi, p, d, accSet);
251 REALLY_INLINE LIns* LirHelper::ldd(LIns* p, int32_t d, AccSet accSet)
253 return lirout->insLoad(LIR_ldd, p, d, accSet);
256 REALLY_INLINE LIns* LirHelper::ldp(LIns* p, int32_t d, AccSet accSet)
258 return lirout->insLoad(LIR_ldp, p, d, accSet);
261 REALLY_INLINE LIns* LirHelper::livep(LIns* a)
263 return lirout->ins1(LIR_livep, a);
266 REALLY_INLINE LIns* LirHelper::param(int id, const char *name)
268 LIns* param = lirout->insParam(id, 0);
269 #ifdef NJ_VERBOSE
270 if (frag->lirbuf->printer)
271 frag->lirbuf->printer->lirNameMap->addName(param, name);
272 #else
273 (void)name;
274 #endif
275 return param;
278 REALLY_INLINE LIns* LirHelper::lshi(LIns* a, int32_t b)
280 return lirout->ins2(LIR_lshi, a, InsConst(b));
283 REALLY_INLINE LIns* LirHelper::rshi(LIns* a, int32_t b)
285 return lirout->ins2(LIR_rshi, a, InsConst(b));
288 REALLY_INLINE LIns* LirHelper::lshp(LIns* a, int32_t b)
290 return lirout->ins2(LIR_lshp, a, InsConst(b));
293 REALLY_INLINE LIns* LirHelper::rshp(LIns* a, int32_t b)
295 return lirout->ins2(LIR_rshp, a, InsConst(b));
298 REALLY_INLINE LIns* LirHelper::rshup(LIns* a, int32_t b)
300 return lirout->ins2(LIR_rshup, a, InsConst(b));
303 inline bool InvokerCompiler::copyArgs()
305 return args_out->isop(LIR_allocp);
308 // Return true if JIT failure can be predicted from method signature prior to JIT invocation.
309 // This supports a fast-fail mechanism to avoid blowup of non-linear JIT algorithms on atypical
310 // methods, e.g., very long or with many variables.
312 REALLY_INLINE bool CodegenLIR::jitWillFail(const MethodSignaturep ms)
314 // Assembly cannot succeed if frame is too large for NanoJIT.
315 // Large frame sizes can lead to pathological VarTracker behavior -- see bug 601794.
316 return ms->frame_size() * 2 > NJ_MAX_STACK_ENTRY;
319 } // namespace