-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBuiltInFunctionImpl.h
More file actions
792 lines (619 loc) · 24.6 KB
/
BuiltInFunctionImpl.h
File metadata and controls
792 lines (619 loc) · 24.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
#pragma once
#include "wnt_Type.h"
#include "Value.h"
#include <utils/Reference.h>
#include <utils/ThreadSafeRefCounted.h>
namespace llvm { class Value; }
namespace Winter
{
class Value;
class VMState;
class EmitLLVMCodeParams;
class EmitOpenCLCodeParams;
class ASTNode;
class TraversalPayload;
struct GetTimeBoundParams;
struct GetSpaceBoundParams;
struct GetSpaceBoundResults;
class BuiltInFunctionImpl : public ThreadSafeRefCounted
{
public:
enum BuiltInFunctionImplType
{
BuiltInType_Constructor,
BuiltInType_GetField,
BuiltInType_UpdateElementBuiltInFunc,
BuiltInType_GetTupleElementBuiltInFunc,
BuiltInType_GetVectorElement,
BuiltInType_ArrayMapBuiltInFunc,
BuiltInType_ArrayFoldBuiltInFunc,
BuiltInType_ArraySubscriptBuiltInFunc,
BuiltInType_VArraySubscriptBuiltInFunc,
BuiltInType_MakeVArrayBuiltInFunc,
BuiltInType_VectorSubscriptBuiltInFunc,
BuiltInType_ArrayInBoundsBuiltInFunc,
BuiltInType_VectorInBoundsBuiltInFunc,
BuiltInType_IterateBuiltInFunc,
BuiltInType_DotProductBuiltInFunc,
BuiltInType_VectorMinBuiltInFunc,
BuiltInType_VectorMaxBuiltInFunc,
BuiltInType_ShuffleBuiltInFunc,
BuiltInType_PowBuiltInFunc,
BuiltInType_SqrtBuiltInFunc,
BuiltInType_ExpBuiltInFunc,
BuiltInType_LogBuiltInFunc,
BuiltInType_SinBuiltInFunc,
BuiltInType_CosBuiltInFunc,
BuiltInType_AbsBuiltInFunc,
BuiltInType_FloorBuiltInFunc,
BuiltInType_CeilBuiltInFunc,
BuiltInType_SignBuiltInFunc,
BuiltInType_FRemBuiltInFunc,
BuiltInType_TruncateToIntBuiltInFunc,
BuiltInType_ToFloatBuiltInFunc,
BuiltInType_ToDoubleBuiltInFunc,
BuiltInType_ToInt64BuiltInFunc,
BuiltInType_ToInt32BuiltInFunc,
BuiltInType_VoidPtrToInt64BuiltInFunc,
BuiltInType_LengthBuiltInFunc,
BuiltInType_CompareEqualBuiltInFunc,
BuiltInType_NaNBuiltInFunc
};
BuiltInFunctionImpl(BuiltInFunctionImplType builtin_type_) : builtin_type(builtin_type_) {}
virtual ~BuiltInFunctionImpl(){}
virtual ValueRef invoke(VMState& vmstate) = 0;
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const = 0;
// Should this call be considered expensive, when considering possible duplication during inlining?
virtual bool callIsExpensive() const { return true; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const = 0;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const = 0;
// Built-in functions may call other functions, so we need to be able to traverse them when getting set of alive functions.
virtual void deadFunctionEliminationTraverse(TraversalPayload& payload) const {}
virtual void linkInCalledFunctions(TraversalPayload& payload) const {}
virtual size_t getSubtreeCodeComplexity() const { return 1; } // TEMP HACK
BuiltInFunctionImplType builtInType() const { return builtin_type; }
private:
BuiltInFunctionImplType builtin_type;
};
typedef Reference<BuiltInFunctionImpl> BuiltInFunctionImplRef;
// Construct a struct value
class Constructor : public BuiltInFunctionImpl
{
public:
Constructor(VRef<StructureType>& struct_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return true; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<StructureType> struct_type;
};
// Return a field value or pointer to a field from a structure.
class GetField : public BuiltInFunctionImpl
{
public:
GetField(VRef<StructureType>& struct_type_, unsigned int index_) : BuiltInFunctionImpl(BuiltInType_GetField), struct_type(struct_type_), index(index_) {}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return false; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
//private:
VRef<StructureType> struct_type;
unsigned int index;
};
// Returns a new collection value with the value at the given index updated to the new value.
class UpdateElementBuiltInFunc : public BuiltInFunctionImpl
{
public:
/*
def update(CollectionType c, int index, T newval) CollectionType
is equivalent to
def update(CollectionType c, int index, T newval) CollectionType
new_c = clone(c)
new_c[index] = newval
return new_c
end
*/
UpdateElementBuiltInFunc(const TypeVRef& collection_type/*, const TypeRef& value_type*/);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
TypeVRef collection_type; // Should be one of array, vector, or tuple
//TypeRef value_type; // T
};
// Return a field value or pointer to a field from a tuple.
class GetTupleElementBuiltInFunc : public BuiltInFunctionImpl
{
public:
GetTupleElementBuiltInFunc(const VRef<TupleType>& tuple_type_, unsigned int index_) : BuiltInFunctionImpl(BuiltInType_GetTupleElementBuiltInFunc), tuple_type(tuple_type_), index(index_) {}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return false; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
void setIndex(unsigned int i) { index = i; }
//private:
VRef<TupleType> tuple_type;
unsigned int index;
};
// Return an element with given fixed index from a vector.
class GetVectorElement : public BuiltInFunctionImpl
{
public:
GetVectorElement(VRef<VectorType>& vector_type_, unsigned int index_) : BuiltInFunctionImpl(BuiltInType_GetVectorElement), vector_type(vector_type_), index(index_) {}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return false; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VectorType> vector_type;
unsigned int index;
};
class ArrayMapBuiltInFunc : public BuiltInFunctionImpl
{
public:
ArrayMapBuiltInFunc(const VRef<ArrayType>& from_type_, const VRef<Function>& func_type_) : BuiltInFunctionImpl(BuiltInType_ArrayMapBuiltInFunc), from_type(from_type_), func_type(func_type_), specialised_f(NULL) {}
/*
map(function<T, R>, array<T, N>) array<R, N>
*/
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
// Specialise for a particular first argument.
void specialiseForFunctionArg(FunctionDefinition* f);
private:
llvm::Value* insertWorkFunction(EmitLLVMCodeParams& params) const;
VRef<ArrayType> from_type; // from array type
VRef<Function> func_type;
FunctionDefinition* specialised_f;
};
class ArrayFoldBuiltInFunc : public BuiltInFunctionImpl
{
public:
/*
suppose T = array_elem_type
then fold is
fold(function<State, T, State> f, array<T> array, State initial_state) State
Where f is
def f(State current_state, T array_element) : State
and returns the new state.
Fold is equivalent to:
State state = initial_state;
for each element elem in array:
{
state = f(state, elem);
}
*/
ArrayFoldBuiltInFunc(const VRef<Function>& func_type_, const VRef<ArrayType>& array_type_, const TypeVRef& state_type_);
// Specialise for a particular first argument.
void specialiseForFunctionArg(FunctionDefinition* f);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<Function> func_type;
VRef<ArrayType> array_type;
TypeVRef state_type;
FunctionDefinition* specialised_f;
};
// Get the i-th element from an array.
class ArraySubscriptBuiltInFunc : public BuiltInFunctionImpl
{
public:
ArraySubscriptBuiltInFunc(const VRef<ArrayType>& array_type, const TypeVRef& index_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return false; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<ArrayType> array_type;
TypeVRef index_type;
};
// Get the i-th element from a varray.
class VArraySubscriptBuiltInFunc : public BuiltInFunctionImpl
{
public:
VArraySubscriptBuiltInFunc(const VRef<VArrayType>& array_type, const TypeVRef& index_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return false; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VArrayType> array_type;
TypeVRef index_type;
};
// Make a varray of count elements.
class MakeVArrayBuiltInFunc : public BuiltInFunctionImpl
{
public:
MakeVArrayBuiltInFunc(const VRef<VArrayType>& array_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VArrayType> array_type;
};
// Get the i-th element from a vector.
class VectorSubscriptBuiltInFunc : public BuiltInFunctionImpl
{
public:
VectorSubscriptBuiltInFunc(const VRef<VectorType>& vec_type, const TypeVRef& index_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual bool callIsExpensive() const { return false; }
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VectorType> vec_type;
TypeVRef index_type;
};
// Check if the index is in bounds for this array.
class ArrayInBoundsBuiltInFunc : public BuiltInFunctionImpl
{
public:
ArrayInBoundsBuiltInFunc(const VRef<ArrayType>& array_type, const TypeVRef& index_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<ArrayType> array_type;
TypeVRef index_type;
};
// Check if the index is in bounds for this vector.
class VectorInBoundsBuiltInFunc : public BuiltInFunctionImpl
{
public:
VectorInBoundsBuiltInFunc(const VRef<VectorType>& vector_type, const TypeVRef& index_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VectorType> vector_type;
TypeVRef index_type;
};
class IterateBuiltInFunc : public BuiltInFunctionImpl
{
public:
/*
iterate(function<State, int, tuple<State, bool>> f, State initial_state) State
or a different version that takes an additional LoopInvariantData argument(s):
iterate(function<State, int, LoopInvariantData0, LoopInvariantData1, ..., LoopInvariantDataN, tuple<State, bool>> f, State initial_state, LoopInvariantData0, LoopInvariantData1, ..., LoopInvariantDataN) State
Where f is
def f(State current_state, int iteration) : tuple<State, bool>
and returns the new state, and if iteration should continue.
equivalent to
State state = initial_state;
iteration = 0;
while(1)
{
res = f(state, iteration);
if(res.second == false)
return res.first;
iteration++;
state = res.first;
}
*/
IterateBuiltInFunc(const VRef<Function>& func_type_, const TypeVRef& state_type_, const std::vector<TypeVRef>& invariant_data_types);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
const std::string emitOpenCLForFunctionArg(EmitOpenCLCodeParams& params,
const FunctionDefinition* f, // arg 0
const std::vector<Reference<ASTNode> >& argument_expressions
);
private:
VRef<Function> func_type;
TypeVRef state_type;
std::vector<TypeVRef> invariant_data_types; // may be empty.
};
// Take the dot product of two vectors.
class DotProductBuiltInFunc : public BuiltInFunctionImpl
{
public:
DotProductBuiltInFunc(const VRef<VectorType>& vector_type_, int num_components_ = -1) :
BuiltInFunctionImpl(BuiltInType_DotProductBuiltInFunc), vector_type(vector_type_),
num_components(num_components_)
{}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VectorType> vector_type;
int num_components; // -1 if default
};
// Element-wise min of two vectors
class VectorMinBuiltInFunc : public BuiltInFunctionImpl
{
public:
VectorMinBuiltInFunc(const VRef<VectorType>& vector_type_) : BuiltInFunctionImpl(BuiltInType_VectorMinBuiltInFunc), vector_type(vector_type_) {}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VectorType> vector_type;
};
// Element-wise max of two vectors
class VectorMaxBuiltInFunc : public BuiltInFunctionImpl
{
public:
VectorMaxBuiltInFunc(const VRef<VectorType>& vector_type_) : BuiltInFunctionImpl(BuiltInType_VectorMaxBuiltInFunc), vector_type(vector_type_) {}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
VRef<VectorType> vector_type;
};
// Shuffle(vector<T, m>, vector<int, n) -> vector<T, n>
class ShuffleBuiltInFunc : public BuiltInFunctionImpl
{
public:
ShuffleBuiltInFunc(const VRef<VectorType>& vector_type_,
//const std::vector<int>& shuffle_mask_
const VRef<VectorType>& index_type_
) : BuiltInFunctionImpl(BuiltInType_ShuffleBuiltInFunc),
vector_type(vector_type_),
//shuffle_mask(shuffle_mask_)
index_type(index_type_)
{}
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
void setShuffleMask(const std::vector<int>& shuffle_mask);
private:
VRef<VectorType> vector_type;
VRef<VectorType> index_type;
std::vector<int> shuffle_mask;
};
class PowBuiltInFunc : public BuiltInFunctionImpl
{
public:
PowBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class SqrtBuiltInFunc : public BuiltInFunctionImpl
{
public:
SqrtBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class ExpBuiltInFunc : public BuiltInFunctionImpl
{
public:
ExpBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class LogBuiltInFunc : public BuiltInFunctionImpl
{
public:
LogBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class SinBuiltInFunc : public BuiltInFunctionImpl
{
public:
SinBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class CosBuiltInFunc : public BuiltInFunctionImpl
{
public:
CosBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class AbsBuiltInFunc : public BuiltInFunctionImpl
{
public:
AbsBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class FloorBuiltInFunc : public BuiltInFunctionImpl
{
public:
FloorBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class CeilBuiltInFunc : public BuiltInFunctionImpl
{
public:
CeilBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class SignBuiltInFunc : public BuiltInFunctionImpl
{
public:
SignBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
// Exposed as '_frem_' for now, until I decide the proper name to expose it as. Maybe 'rem'?
class FRemBuiltInFunc : public BuiltInFunctionImpl
{
public:
FRemBuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
class TruncateToIntBuiltInFunc : public BuiltInFunctionImpl
{
public:
TruncateToIntBuiltInFunc(const TypeVRef& type);
static TypeVRef getReturnType(const TypeVRef& arg_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
// Integer to float conversion
class ToFloatBuiltInFunc : public BuiltInFunctionImpl
{
public:
ToFloatBuiltInFunc(const TypeVRef& type);
static TypeVRef getReturnType(const TypeVRef& arg_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
// Integer to double conversion
class ToDoubleBuiltInFunc : public BuiltInFunctionImpl
{
public:
ToDoubleBuiltInFunc(const TypeVRef& type);
static TypeVRef getReturnType(const TypeVRef& arg_type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
// int32 -> int64 conversion
class ToInt64BuiltInFunc : public BuiltInFunctionImpl
{
public:
ToInt64BuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
// int64 -> int32 conversion
class ToInt32BuiltInFunc : public BuiltInFunctionImpl
{
public:
ToInt32BuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
private:
TypeVRef type;
};
// Opaque/voidptr to int64 conversion
class VoidPtrToInt64BuiltInFunc : public BuiltInFunctionImpl
{
public:
VoidPtrToInt64BuiltInFunc(const TypeVRef& type);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
};
class LengthBuiltInFunc : public BuiltInFunctionImpl
{
public:
LengthBuiltInFunc(const TypeVRef& type_);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
TypeVRef type;
};
class CompareEqualBuiltInFunc : public BuiltInFunctionImpl
{
public:
CompareEqualBuiltInFunc(const TypeVRef& arg_type_, bool is_compare_not_equal);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
virtual void deadFunctionEliminationTraverse(TraversalPayload& payload) const;
virtual void linkInCalledFunctions(TraversalPayload& payload) const;
TypeVRef arg_type;
bool is_compare_not_equal;
};
class NaNBuiltInFunc : public BuiltInFunctionImpl
{
public:
NaNBuiltInFunc(const TypeVRef& type_);
virtual ValueRef invoke(VMState& vmstate);
virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
virtual size_t getTimeBound(GetTimeBoundParams& params) const;
virtual GetSpaceBoundResults getSpaceBound(GetSpaceBoundParams& params) const;
TypeVRef type;
};
//class AllocateRefCountedStructure : public BuiltInFunctionImpl
//{
//public:
// AllocateRefCountedStructure() {}
//
// virtual ValueRef invoke(VMState& vmstate);
// virtual llvm::Value* emitLLVMCode(EmitLLVMCodeParams& params) const;
//private:
//};
}