]> git.saurik.com Git - apple/javascriptcore.git/blame - ftl/FTLAbbreviations.h
JavaScriptCore-7600.1.4.16.1.tar.gz
[apple/javascriptcore.git] / ftl / FTLAbbreviations.h
CommitLineData
81345200
A
1/*
2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef FTLAbbreviations_h
27#define FTLAbbreviations_h
28
29#if ENABLE(FTL_JIT)
30
31#include "FTLAbbreviatedTypes.h"
32#include "FTLValueFromBlock.h"
33#include "LLVMAPI.h"
34#include <cstring>
35
36namespace JSC { namespace FTL {
37
38// This file contains short-form calls into the LLVM C API. It is meant to
39// save typing and make the lowering code clearer. If we ever call an LLVM C API
40// function more than once in the FTL lowering code, we should add a shortcut for
41// it here.
42
43#if USE(JSVALUE32_64)
44#error "The FTL backend assumes that pointers are 64-bit."
45#endif
46
47static inline LType voidType(LContext context) { return llvm->VoidTypeInContext(context); }
48static inline LType int1Type(LContext context) { return llvm->Int1TypeInContext(context); }
49static inline LType int8Type(LContext context) { return llvm->Int8TypeInContext(context); }
50static inline LType int16Type(LContext context) { return llvm->Int16TypeInContext(context); }
51static inline LType int32Type(LContext context) { return llvm->Int32TypeInContext(context); }
52static inline LType int64Type(LContext context) { return llvm->Int64TypeInContext(context); }
53static inline LType intPtrType(LContext context) { return llvm->Int64TypeInContext(context); }
54static inline LType floatType(LContext context) { return llvm->FloatTypeInContext(context); }
55static inline LType doubleType(LContext context) { return llvm->DoubleTypeInContext(context); }
56
57static inline LType pointerType(LType type) { return llvm->PointerType(type, 0); }
58static inline LType arrayType(LType type, unsigned count) { return llvm->ArrayType(type, count); }
59static inline LType vectorType(LType type, unsigned count) { return llvm->VectorType(type, count); }
60
61enum PackingMode { NotPacked, Packed };
62static inline LType structType(LContext context, LType* elementTypes, unsigned elementCount, PackingMode packing = NotPacked)
63{
64 return llvm->StructTypeInContext(context, elementTypes, elementCount, packing == Packed);
65}
66static inline LType structType(LContext context, PackingMode packing = NotPacked)
67{
68 return structType(context, 0, 0, packing);
69}
70static inline LType structType(LContext context, LType element1, PackingMode packing = NotPacked)
71{
72 return structType(context, &element1, 1, packing);
73}
74static inline LType structType(LContext context, LType element1, LType element2, PackingMode packing = NotPacked)
75{
76 LType elements[] = { element1, element2 };
77 return structType(context, elements, 2, packing);
78}
79
80enum Variadicity { NotVariadic, Variadic };
81static inline LType functionType(LType returnType, const LType* paramTypes, unsigned paramCount, Variadicity variadicity)
82{
83 return llvm->FunctionType(returnType, const_cast<LType*>(paramTypes), paramCount, variadicity == Variadic);
84}
85template<typename VectorType>
86inline LType functionType(LType returnType, const VectorType& vector, Variadicity variadicity = NotVariadic)
87{
88 return functionType(returnType, vector.begin(), vector.size(), variadicity);
89}
90static inline LType functionType(LType returnType, Variadicity variadicity = NotVariadic)
91{
92 return functionType(returnType, 0, 0, variadicity);
93}
94static inline LType functionType(LType returnType, LType param1, Variadicity variadicity = NotVariadic)
95{
96 return functionType(returnType, &param1, 1, variadicity);
97}
98static inline LType functionType(LType returnType, LType param1, LType param2, Variadicity variadicity = NotVariadic)
99{
100 LType paramTypes[] = { param1, param2 };
101 return functionType(returnType, paramTypes, 2, variadicity);
102}
103static inline LType functionType(LType returnType, LType param1, LType param2, LType param3, Variadicity variadicity = NotVariadic)
104{
105 LType paramTypes[] = { param1, param2, param3 };
106 return functionType(returnType, paramTypes, 3, variadicity);
107}
108static inline LType functionType(LType returnType, LType param1, LType param2, LType param3, LType param4, Variadicity variadicity = NotVariadic)
109{
110 LType paramTypes[] = { param1, param2, param3, param4 };
111 return functionType(returnType, paramTypes, 4, variadicity);
112}
113
114static inline LType typeOf(LValue value) { return llvm->TypeOf(value); }
115
116static inline unsigned mdKindID(LContext context, const char* string) { return llvm->GetMDKindIDInContext(context, string, std::strlen(string)); }
117static inline LValue mdString(LContext context, const char* string, unsigned length) { return llvm->MDStringInContext(context, string, length); }
118static inline LValue mdString(LContext context, const char* string) { return mdString(context, string, std::strlen(string)); }
119static inline LValue mdNode(LContext context, LValue* args, unsigned numArgs) { return llvm->MDNodeInContext(context, args, numArgs); }
120template<typename VectorType>
121static inline LValue mdNode(LContext context, const VectorType& vector) { return mdNode(context, const_cast<LValue*>(vector.begin()), vector.size()); }
122static inline LValue mdNode(LContext context) { return mdNode(context, 0, 0); }
123static inline LValue mdNode(LContext context, LValue arg1) { return mdNode(context, &arg1, 1); }
124static inline LValue mdNode(LContext context, LValue arg1, LValue arg2)
125{
126 LValue args[] = { arg1, arg2 };
127 return mdNode(context, args, 2);
128}
129static inline LValue mdNode(LContext context, LValue arg1, LValue arg2, LValue arg3)
130{
131 LValue args[] = { arg1, arg2, arg3 };
132 return mdNode(context, args, 3);
133}
134
135static inline void setMetadata(LValue instruction, unsigned kind, LValue metadata) { llvm->SetMetadata(instruction, kind, metadata); }
136
137static inline LValue addFunction(LModule module, const char* name, LType type) { return llvm->AddFunction(module, name, type); }
138static inline void setLinkage(LValue global, LLinkage linkage) { llvm->SetLinkage(global, linkage); }
139static inline void setFunctionCallingConv(LValue function, LCallConv convention) { llvm->SetFunctionCallConv(function, convention); }
140static inline void addTargetDependentFunctionAttr(LValue function, const char* key, const char* value) { llvm->AddTargetDependentFunctionAttr(function, key, value); }
141
142static inline LValue addExternFunction(LModule module, const char* name, LType type)
143{
144 LValue result = addFunction(module, name, type);
145 setLinkage(result, LLVMExternalLinkage);
146 return result;
147}
148
149static inline LValue getParam(LValue function, unsigned index) { return llvm->GetParam(function, index); }
150static inline LValue getUndef(LType type) { return llvm->GetUndef(type); }
151
152enum BitExtension { ZeroExtend, SignExtend };
153static inline LValue constInt(LType type, unsigned long long value, BitExtension extension = ZeroExtend) { return llvm->ConstInt(type, value, extension == SignExtend); }
154static inline LValue constReal(LType type, double value) { return llvm->ConstReal(type, value); }
155static inline LValue constIntToPtr(LValue value, LType type) { return llvm->ConstIntToPtr(value, type); }
156static inline LValue constNull(LType type) { return llvm->ConstNull(type); }
157static inline LValue constBitCast(LValue value, LType type) { return llvm->ConstBitCast(value, type); }
158
159static inline LBasicBlock appendBasicBlock(LContext context, LValue function, const char* name = "") { return llvm->AppendBasicBlockInContext(context, function, name); }
160static inline LBasicBlock insertBasicBlock(LContext context, LBasicBlock beforeBasicBlock, const char* name = "") { return llvm->InsertBasicBlockInContext(context, beforeBasicBlock, name); }
161
162static inline LValue buildPhi(LBuilder builder, LType type) { return llvm->BuildPhi(builder, type, ""); }
163static inline void addIncoming(LValue phi, const LValue* values, const LBasicBlock* blocks, unsigned numPredecessors)
164{
165 llvm->AddIncoming(phi, const_cast<LValue*>(values), const_cast<LBasicBlock*>(blocks), numPredecessors);
166}
167static inline void addIncoming(LValue phi, ValueFromBlock value1)
168{
169 LValue value = value1.value();
170 LBasicBlock block = value1.block();
171 addIncoming(phi, &value, &block, 1);
172}
173static inline void addIncoming(LValue phi, ValueFromBlock value1, ValueFromBlock value2)
174{
175 LValue values[] = { value1.value(), value2.value() };
176 LBasicBlock blocks[] = { value1.block(), value2.block() };
177 addIncoming(phi, values, blocks, 2);
178}
179static inline LValue buildPhi(LBuilder builder, LType type, ValueFromBlock value1)
180{
181 LValue result = buildPhi(builder, type);
182 addIncoming(result, value1);
183 return result;
184}
185static inline LValue buildPhi(
186 LBuilder builder, LType type, ValueFromBlock value1, ValueFromBlock value2)
187{
188 LValue result = buildPhi(builder, type);
189 addIncoming(result, value1, value2);
190 return result;
191}
192
193static inline LValue buildAlloca(LBuilder builder, LType type) { return llvm->BuildAlloca(builder, type, ""); }
194static inline LValue buildAdd(LBuilder builder, LValue left, LValue right) { return llvm->BuildAdd(builder, left, right, ""); }
195static inline LValue buildSub(LBuilder builder, LValue left, LValue right) { return llvm->BuildSub(builder, left, right, ""); }
196static inline LValue buildMul(LBuilder builder, LValue left, LValue right) { return llvm->BuildMul(builder, left, right, ""); }
197static inline LValue buildDiv(LBuilder builder, LValue left, LValue right) { return llvm->BuildSDiv(builder, left, right, ""); }
198static inline LValue buildRem(LBuilder builder, LValue left, LValue right) { return llvm->BuildSRem(builder, left, right, ""); }
199static inline LValue buildNeg(LBuilder builder, LValue value) { return llvm->BuildNeg(builder, value, ""); }
200static inline LValue buildFAdd(LBuilder builder, LValue left, LValue right) { return llvm->BuildFAdd(builder, left, right, ""); }
201static inline LValue buildFSub(LBuilder builder, LValue left, LValue right) { return llvm->BuildFSub(builder, left, right, ""); }
202static inline LValue buildFMul(LBuilder builder, LValue left, LValue right) { return llvm->BuildFMul(builder, left, right, ""); }
203static inline LValue buildFDiv(LBuilder builder, LValue left, LValue right) { return llvm->BuildFDiv(builder, left, right, ""); }
204static inline LValue buildFRem(LBuilder builder, LValue left, LValue right) { return llvm->BuildFRem(builder, left, right, ""); }
205static inline LValue buildFNeg(LBuilder builder, LValue value) { return llvm->BuildFNeg(builder, value, ""); }
206static inline LValue buildAnd(LBuilder builder, LValue left, LValue right) { return llvm->BuildAnd(builder, left, right, ""); }
207static inline LValue buildOr(LBuilder builder, LValue left, LValue right) { return llvm->BuildOr(builder, left, right, ""); }
208static inline LValue buildXor(LBuilder builder, LValue left, LValue right) { return llvm->BuildXor(builder, left, right, ""); }
209static inline LValue buildShl(LBuilder builder, LValue left, LValue right) { return llvm->BuildShl(builder, left, right, ""); }
210static inline LValue buildAShr(LBuilder builder, LValue left, LValue right) { return llvm->BuildAShr(builder, left, right, ""); }
211static inline LValue buildLShr(LBuilder builder, LValue left, LValue right) { return llvm->BuildLShr(builder, left, right, ""); }
212static inline LValue buildNot(LBuilder builder, LValue value) { return llvm->BuildNot(builder, value, ""); }
213static inline LValue buildLoad(LBuilder builder, LValue pointer) { return llvm->BuildLoad(builder, pointer, ""); }
214static inline LValue buildStore(LBuilder builder, LValue value, LValue pointer) { return llvm->BuildStore(builder, value, pointer); }
215static inline LValue buildSExt(LBuilder builder, LValue value, LType type) { return llvm->BuildSExt(builder, value, type, ""); }
216static inline LValue buildZExt(LBuilder builder, LValue value, LType type) { return llvm->BuildZExt(builder, value, type, ""); }
217static inline LValue buildFPToSI(LBuilder builder, LValue value, LType type) { return llvm->BuildFPToSI(builder, value, type, ""); }
218static inline LValue buildFPToUI(LBuilder builder, LValue value, LType type) { return llvm->BuildFPToUI(builder, value, type, ""); }
219static inline LValue buildSIToFP(LBuilder builder, LValue value, LType type) { return llvm->BuildSIToFP(builder, value, type, ""); }
220static inline LValue buildUIToFP(LBuilder builder, LValue value, LType type) { return llvm->BuildUIToFP(builder, value, type, ""); }
221static inline LValue buildIntCast(LBuilder builder, LValue value, LType type) { return llvm->BuildIntCast(builder, value, type, ""); }
222static inline LValue buildFPCast(LBuilder builder, LValue value, LType type) { return llvm->BuildFPCast(builder, value, type, ""); }
223static inline LValue buildIntToPtr(LBuilder builder, LValue value, LType type) { return llvm->BuildIntToPtr(builder, value, type, ""); }
224static inline LValue buildPtrToInt(LBuilder builder, LValue value, LType type) { return llvm->BuildPtrToInt(builder, value, type, ""); }
225static inline LValue buildBitCast(LBuilder builder, LValue value, LType type) { return llvm->BuildBitCast(builder, value, type, ""); }
226static inline LValue buildICmp(LBuilder builder, LIntPredicate cond, LValue left, LValue right) { return llvm->BuildICmp(builder, cond, left, right, ""); }
227static inline LValue buildFCmp(LBuilder builder, LRealPredicate cond, LValue left, LValue right) { return llvm->BuildFCmp(builder, cond, left, right, ""); }
228static inline LValue buildInsertElement(LBuilder builder, LValue vector, LValue element, LValue index) { return llvm->BuildInsertElement(builder, vector, element, index, ""); }
229
230enum SynchronizationScope { SingleThread, CrossThread };
231static inline LValue buildFence(LBuilder builder, LAtomicOrdering ordering, SynchronizationScope scope = CrossThread)
232{
233 return llvm->BuildFence(builder, ordering, scope == SingleThread, "");
234}
235
236static inline LValue buildCall(LBuilder builder, LValue function, const LValue* args, unsigned numArgs)
237{
238 return llvm->BuildCall(builder, function, const_cast<LValue*>(args), numArgs, "");
239}
240template<typename VectorType>
241inline LValue buildCall(LBuilder builder, LValue function, const VectorType& vector)
242{
243 return buildCall(builder, function, vector.begin(), vector.size());
244}
245static inline LValue buildCall(LBuilder builder, LValue function)
246{
247 return buildCall(builder, function, 0, 0);
248}
249static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1)
250{
251 return buildCall(builder, function, &arg1, 1);
252}
253static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2)
254{
255 LValue args[] = { arg1, arg2 };
256 return buildCall(builder, function, args, 2);
257}
258static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2, LValue arg3)
259{
260 LValue args[] = { arg1, arg2, arg3 };
261 return buildCall(builder, function, args, 3);
262}
263static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2, LValue arg3, LValue arg4)
264{
265 LValue args[] = { arg1, arg2, arg3, arg4 };
266 return buildCall(builder, function, args, 4);
267}
268static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2, LValue arg3, LValue arg4, LValue arg5)
269{
270 LValue args[] = { arg1, arg2, arg3, arg4, arg5 };
271 return buildCall(builder, function, args, 5);
272}
273static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2, LValue arg3, LValue arg4, LValue arg5, LValue arg6)
274{
275 LValue args[] = { arg1, arg2, arg3, arg4, arg5, arg6 };
276 return buildCall(builder, function, args, 6);
277}
278static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2, LValue arg3, LValue arg4, LValue arg5, LValue arg6, LValue arg7)
279{
280 LValue args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7 };
281 return buildCall(builder, function, args, 7);
282}
283static inline LValue buildCall(LBuilder builder, LValue function, LValue arg1, LValue arg2, LValue arg3, LValue arg4, LValue arg5, LValue arg6, LValue arg7, LValue arg8)
284{
285 LValue args[] = { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 };
286 return buildCall(builder, function, args, 8);
287}
288static inline void setInstructionCallingConvention(LValue instruction, LCallConv callingConvention) { llvm->SetInstructionCallConv(instruction, callingConvention); }
289static inline LValue buildExtractValue(LBuilder builder, LValue aggVal, unsigned index) { return llvm->BuildExtractValue(builder, aggVal, index, ""); }
290static inline LValue buildSelect(LBuilder builder, LValue condition, LValue taken, LValue notTaken) { return llvm->BuildSelect(builder, condition, taken, notTaken, ""); }
291static inline LValue buildBr(LBuilder builder, LBasicBlock destination) { return llvm->BuildBr(builder, destination); }
292static inline LValue buildCondBr(LBuilder builder, LValue condition, LBasicBlock taken, LBasicBlock notTaken) { return llvm->BuildCondBr(builder, condition, taken, notTaken); }
293static inline LValue buildSwitch(LBuilder builder, LValue value, LBasicBlock fallThrough, unsigned numCases) { return llvm->BuildSwitch(builder, value, fallThrough, numCases); }
294static inline void addCase(LValue switchInst, LValue value, LBasicBlock target) { llvm->AddCase(switchInst, value, target); }
295template<typename VectorType>
296static inline LValue buildSwitch(LBuilder builder, LValue value, const VectorType& cases, LBasicBlock fallThrough)
297{
298 LValue result = buildSwitch(builder, value, fallThrough, cases.size());
299 for (unsigned i = 0; i < cases.size(); ++i)
300 addCase(result, cases[i].value(), cases[i].target());
301 return result;
302}
303static inline LValue buildRet(LBuilder builder, LValue value) { return llvm->BuildRet(builder, value); }
304static inline LValue buildUnreachable(LBuilder builder) { return llvm->BuildUnreachable(builder); }
305
306static inline void dumpModule(LModule module) { llvm->DumpModule(module); }
307static inline void verifyModule(LModule module)
308{
309 char* error = 0;
310 llvm->VerifyModule(module, LLVMAbortProcessAction, &error);
311 llvm->DisposeMessage(error);
312}
313
314} } // namespace JSC::FTL
315
316#endif // ENABLE(FTL_JIT)
317
318#endif // FTLAbbreviations_h
319