-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathTypeScriptOps.td
More file actions
2415 lines (1890 loc) · 72 KB
/
Copy pathTypeScriptOps.td
File metadata and controls
2415 lines (1890 loc) · 72 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
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef TYPESCRIPT_OPS
#define TYPESCRIPT_OPS
include "TypeScriptDialect.td"
include "TypeScriptTypes.td"
include "TypeScriptInterfaces.td"
include "mlir/Dialect/LLVMIR/LLVMEnums.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"
include "mlir/IR/RegionKindInterface.td"
include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/ControlFlowInterfaces.td"
include "mlir/Interfaces/FunctionInterfaces.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/CastInterfaces.td"
include "mlir/Interfaces/LoopLikeInterface.td"
// info:
// Commutative - it actually represents. MLIR's Commutative trait tells canonicalizers/CSE "operand order doesn't matter,
// feel free to reorder to canonicalize/match commuted forms" — that's true for +, *, &, |, ^, but definitely false
// for -, /, %, **, and the shifts.
//===----------------------------------------------------------------------===//
// TypeScript op definitions
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// ConstantOp
//===----------------------------------------------------------------------===//
def ConstantOp : TypeScript_Op<"Constant",
[ConstantLike, Pure]> {
let summary = "constant";
let description = [{
The `constant` operation produces an SSA value equal to some constant
specified by an attribute.
}];
let arguments = (ins AnyAttr:$value);
let results = (outs AnyType:$constValue);
let builders = [
OpBuilder<(ins "TypedAttr":$value), [{
build($_builder, $_state, value.getType(), value);
}]>
];
let hasFolder = 1;
}
def SymbolRefOp : TypeScript_Op<"SymbolRef",
[Pure]> {
let summary = "symbol reference as constant";
let arguments = (ins FlatSymbolRefAttr:$identifier);
let results = (outs AnyType:$value);
let hasCanonicalizer = 1;
}
def ThisSymbolRefOp : TypeScript_Op<"ThisSymbolRef",
[Pure]> {
let summary = "symbol reference as to this member";
let arguments = (ins TypeScript_AnyRefLike:$thisVal, FlatSymbolRefAttr:$identifier);
let results = (outs TypeScript_AnyRefOrCallableOrNone:$value);
let hasCanonicalizer = 1;
}
def VTableOffsetRefOp : TypeScript_Op<"VTableOffsetRef",
[Pure]> {
let summary = "gets reference in vtable";
let arguments = (ins TypeScript_AnyRefLike:$vtable, I32Attr:$index);
let results = (outs TypeScript_AnyRefLike:$value);
}
def VirtualSymbolRefOp : TypeScript_Op<"VirtualSymbolRef",
[Pure]> {
let summary = "symbol reference as to virtual static member";
let arguments = (ins TypeScript_AnyRefLike:$vtable, I32Attr:$index, FlatSymbolRefAttr:$identifier);
let results = (outs TypeScript_AnyRefOrCallable:$value);
let hasCanonicalizer = 1;
}
def ThisVirtualSymbolRefOp : TypeScript_Op<"ThisVirtualSymbolRef",
[Pure]> {
let summary = "symbol reference as to virtual this member";
let arguments = (ins TypeScript_AnyRefLike:$thisVal, TypeScript_AnyRefLike:$vtable, I32Attr:$index, FlatSymbolRefAttr:$identifier);
let results = (outs TypeScript_AnyRefOrCallable:$value);
let hasCanonicalizer = 1;
}
def AccessorOp : TypeScript_Op<"Accessor",
[]> {
let summary = "symbol reference as to static accessor";
let arguments = (ins OptionalAttr<FlatSymbolRefAttr>:$getAccessor, OptionalAttr<FlatSymbolRefAttr>:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def ThisAccessorOp : TypeScript_Op<"ThisAccessor",
[]> {
let summary = "accessor of class";
let arguments = (ins AnyType:$thisVal, OptionalAttr<FlatSymbolRefAttr>:$getAccessor, OptionalAttr<FlatSymbolRefAttr>:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def ThisIndirectAccessorOp : TypeScript_Op<"ThisIndirectAccessor",
[]> {
let summary = "accessor of object";
let arguments = (ins AnyType:$thisVal, TypeScript_Function:$getAccessor, TypeScript_Function:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def ThisIndexAccessorOp : TypeScript_Op<"ThisIndexAccessor",
[]> {
let summary = "index accessor of class";
let arguments = (ins AnyType:$thisVal, AnyType:$index, OptionalAttr<FlatSymbolRefAttr>:$getAccessor, OptionalAttr<FlatSymbolRefAttr>:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def ThisIndirectIndexAccessorOp : TypeScript_Op<"ThisIndirectIndexAccessor",
[]> {
let summary = "index accessor of object";
let arguments = (ins AnyType:$thisVal, AnyType:$index, TypeScript_Function:$getAccessor, TypeScript_Function:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def BoundIndirectAccessorOp : TypeScript_Op<"BoundIndirectAccessor",
[]> {
let summary = "accessor of interface";
let arguments = (ins TypeScript_BoundFunction:$getAccessor, TypeScript_BoundFunction:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def BoundIndirectIndexAccessorOp : TypeScript_Op<"BoundIndirectIndexAccessor",
[]> {
let summary = "index accessor of interface";
let arguments = (ins AnyType:$index, TypeScript_BoundFunction:$getAccessor, TypeScript_BoundFunction:$setAccessor, Optional<AnyType>:$setValue);
let results = (outs Optional<AnyType>:$value);
let hasCanonicalizer = 1;
}
def InterfaceSymbolRefOp : TypeScript_Op<"InterfaceSymbolRef",
[Pure]> {
let summary = "symbol reference as to interface member";
let arguments = (ins TypeScript_Interface:$interfaceVal, I32Attr:$index, AnyAttr:$identifier, OptionalAttr<BoolAttr>:$optional);
let results = (outs TypeScript_AnyRefOrCallable:$funcOrFieldReference);
let hasCanonicalizer = 1;
}
def TypeRefOp : TypeScript_Op<"TypeRef",
[Pure]> {
let summary = "symbol reference to type";
let results = (outs AnyType:$value);
let hasCanonicalizer = 1;
}
def NamespaceRefOp : TypeScript_Op<"NamespaceRef",
[Pure]> {
let summary = "symbol reference to namespace";
let arguments = (ins FlatSymbolRefAttr:$identifier);
let results = (outs AnyType:$value);
let hasCanonicalizer = 1;
}
def ClassRefOp : TypeScript_Op<"ClassRef",
[Pure]> {
let summary = "symbol reference to class";
let arguments = (ins FlatSymbolRefAttr:$identifier);
let results = (outs TypeScript_Class:$value);
let hasCanonicalizer = 1;
}
def InterfaceRefOp : TypeScript_Op<"InterfaceRef",
[Pure]> {
let summary = "symbol reference to interface";
let arguments = (ins FlatSymbolRefAttr:$identifier);
let results = (outs TypeScript_Interface:$value);
let hasCanonicalizer = 1;
}
def TypeScript_FuncOp : TypeScript_Op<"Func", [
AffineScope, AutomaticAllocationScope, CallableOpInterface, FunctionOpInterface,
IsolatedFromAbove, Symbol, RegionKindInterface
]> {
let description = [{
Example:
```mlir
// External function definitions.
ts.func @abort()
```
}];
let arguments = (ins SymbolNameAttr:$sym_name,
TypeAttrOf<TypeScript_Function>:$function_type,
OptionalAttr<StrAttr>:$sym_visibility,
OptionalAttr<BoolAttr>:$personality,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs
);
let regions = (region AnyRegion:$body);
let builders = [OpBuilder<(ins
"StringRef":$name, "FunctionType":$type,
CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs,
CArg<"ArrayRef<DictionaryAttr>", "{}">:$argAttrs)
>];
let hasVerifier = 1;
let extraClassDeclaration = [{
Block *addEntryBlock();
static FuncOp create(Location location, StringRef name, FunctionType type,
ArrayRef<NamedAttribute> attrs = {});
static FuncOp create(Location location, StringRef name, FunctionType type,
ArrayRef<NamedAttribute> attrs,
ArrayRef<DictionaryAttr> argAttrs);
bool isVarArg() {
return getFunctionType().isVarArg();
}
/// Create a deep copy of this function and all of its blocks, remapping any
/// operands that use values outside of the function using the map that is
/// provided (leaving them alone if no entry is present). If the mapper
/// contains entries for function arguments, these arguments are not
/// included in the new function. Replaces references to cloned sub-values
/// with the corresponding value that is copied, and adds those mappings to
/// the mapper.
FuncOp clone(IRMapping &mapper);
FuncOp clone();
/// Clone the internal blocks and attributes from this function into dest.
/// Any cloned blocks are appended to the back of dest. This function
/// asserts that the attributes of the current function and dest are
/// compatible.
void cloneInto(FuncOp dest, IRMapping &mapper);
//===------------------------------------------------------------------===//
// CallableOpInterface
//===------------------------------------------------------------------===//
/// Returns the region on the current operation that is callable. This may
/// return null in the case of an external callable object, e.g. an external
/// function.
Region *getCallableRegion() { return isExternal() ? nullptr : &getBody(); }
/// Returns the results types that the callable region produces when
/// executed.
ArrayRef<Type> getCallableResults() { return getFunctionType().getResults(); }
/// Returns the argument attributes for all callable region arguments or
/// null if there are none.
ArrayAttr getCallableArgAttrs() {
return getArgAttrs().value_or(nullptr);
}
/// Returns the result attributes for all callable region results or
/// null if there are none.
ArrayAttr getCallableResAttrs() {
return getResAttrs().value_or(nullptr);
}
//===------------------------------------------------------------------===//
// RegionKindInterface Methods
//===------------------------------------------------------------------===//
static ::mlir::RegionKind getRegionKind(unsigned index) {
return ::mlir::RegionKind::SSACFG;
}
//===------------------------------------------------------------------===//
// SymbolOpInterface Methods
//===------------------------------------------------------------------===//
bool isDeclaration() { return isExternal(); }
//===------------------------------------------------------------------===//
// FunctionOpInterface Methods
//===------------------------------------------------------------------===//
/// Returns the argument types of this function.
ArrayRef<Type> getArgumentTypes() { return getFunctionType().getInputs(); }
/// Returns the result types of this function.
ArrayRef<Type> getResultTypes() { return getFunctionType().getResults(); }
}];
let assemblyFormat =
[{ $sym_name $function_type $body attr-dict }];
}
def TypeScript_NullOp : TypeScript_Op<"Null", [Pure]> {
let summary = "Make an intermediate object whose value is null.";
let description = [{
```
null-op ::= `ts.null` `:` any-type
```
#### Example:
```mlir
%0 = ts.null : ts.any
```
}];
let arguments = (ins);
let results = (outs
TypeScript_Null:$result
);
let hasCanonicalizer = 1;
}
def TypeScript_UndefOp : TypeScript_Op<"Undef", [Pure]> {
let summary = "Make an intermediate object whose value is undefined.";
let description = [{
Result Type is the type of object to make.
```
undef-op ::= `ts.undef` `:` any-type
```
#### Example:
```mlir
%0 = ts.undef : f32
```
}];
let arguments = (ins);
let results = (outs
AnyType:$result
);
let hasCanonicalizer = 1;
}
def TypeScript_PrintOp : TypeScript_Op<"Print"> {
let summary = "print operation";
let description = [{
The "print" builtin operation prints a given input string, and produces no results.
}];
let arguments = (ins Variadic<TypeScript_String>:$inputs);
}
def TypeScript_ConvertFOp : TypeScript_Op<"ConvertF"> {
let summary = "format convert operation";
let description = [{
The "convertf" builtin operation to convert values into string with format.
}];
let arguments = (ins Index:$bufferSize, TypeScript_String:$format, Variadic<AnyType>:$inputs);
let results = (outs TypeScript_String:$result);
}
def TypeScript_AssertOp : TypeScript_Op<"Assert"> {
let summary = "Assert operation";
let description = [{
Assert operation
Example:
```mlir
assert %b, "Expected ... to be true"
```
}];
let arguments = (ins TypeScript_Boolean:$arg, StrAttr:$msg);
let hasCanonicalizer = 1;
}
def TypeScript_ParseIntOp : TypeScript_Op<"parseInt"> {
let summary = "Parse int operation";
let description = [{
Parse int operation
Example:
```mlir
%0 = parseInt %b, %base
```
}];
let arguments = (ins TypeScript_String:$arg, Optional<I32>:$base);
let results = (outs AnyInteger:$res);
}
def TypeScript_ParseFloatOp : TypeScript_Op<"parseFloat"> {
let summary = "Parse float operation";
let description = [{
Parse float operation
Example:
```mlir
%0 = parseFloat %b
```
}];
let arguments = (ins TypeScript_String:$arg);
let results = (outs TypeScript_Number:$res);
}
def TypeScript_IsNaNOp : TypeScript_Op<"isNaN"> {
let summary = "isNaN float operation";
let description = [{
isNaN float operation
Example:
```mlir
%0 = isNaN %b
```
}];
let arguments = (ins TypeScript_Number:$arg);
let results = (outs TypeScript_Boolean:$res);
}
def TypeScript_TypeOfOp : TypeScript_Op<"TypeOf", [Pure]> {
let summary = "name of type";
let description = [{
name of type
}];
let arguments = (ins AnyType:$value);
let results = (outs TypeScript_String:$typeOf);
}
def TypeScript_TypeOfAnyOp : TypeScript_Op<"TypeOfAny", [Pure]> {
let summary = "name of type from any";
let description = [{
name of type from any
}];
let arguments = (ins AnyType:$value);
let results = (outs TypeScript_String:$typeOf);
}
def TypeScript_SizeOfOp : TypeScript_Op<"SizeOf", [Pure]> {
let summary = "size of type";
let description = [{
size of type
}];
let arguments = (ins TypeAttr:$type);
let results = (outs Index:$size);
}
def TypeScript_NewOp : TypeScript_Op<"New"> {
let summary = "allocate in memory";
let description = [{
allocate in memory
}];
let arguments = (ins OptionalAttr<BoolAttr>:$stackAlloc);
let results = (outs Res<TypeScript_AnyClassOrValueRef, "", [MemAlloc]>:$instance);
}
def TypeScript_NewInterfaceOp : TypeScript_Op<"NewInterface"> {
let summary = "create new interface";
let description = [{
create new interface
}];
let arguments = (ins TypeScript_AnyRefLike:$thisVal, TypeScript_AnyRefLike:$interfaceVTable);
let results = (outs TypeScript_Interface:$instance);
}
def ExtractInterfaceThisOp : TypeScript_Op<"ExtractInterfaceThis",
[Pure]> {
let summary = "extract interface this ref.";
let arguments = (ins TypeScript_Interface:$interfaceVal);
let results = (outs TypeScript_Opaque:$thisVal);
}
def ExtractInterfaceVTableOp : TypeScript_Op<"ExtractInterfaceVTable",
[Pure]> {
let summary = "extract interface vtable";
let arguments = (ins TypeScript_Interface:$interfaceVal);
let results = (outs TypeScript_Opaque:$vtableVal);
}
def TypeScript_CreateTupleOp : TypeScript_Op<"CreateTuple"> {
let summary = "create tuple";
let description = [{
create tuple
}];
let arguments = (ins Variadic<AnyType>:$items);
let results = (outs TypeScript_Tuple:$instance);
}
def TypeScript_DeconstructTupleOp : TypeScript_Op<"DeconstructTuple"> {
let summary = "deconstruct tuple";
let description = [{
deconstruct tuple
}];
let arguments = (ins TypeScript_TupleLike:$instance);
let results = (outs Variadic<AnyType>:$results);
}
def TypeScript_CreateArrayOp : TypeScript_Op<"CreateArray", [
AllTypesMatch<["items"]>
]> {
let summary = "create array";
let description = [{
create array
}];
let arguments = (ins Variadic<AnyType>:$items);
let results = (outs Res<TypeScript_Array, "", [MemAlloc]>:$instance);
}
def TypeScript_NewEmptyArrayOp : TypeScript_Op<"NewEmptyArray"> {
let summary = "create empty array";
let description = [{
create empty array
}];
let arguments = (ins );
let results = (outs Res<TypeScript_Array, "", [MemAlloc]>:$instance);
}
def TypeScript_NewArrayOp : TypeScript_Op<"NewArray"> {
let summary = "allocate in memory few instances";
let description = [{
allocate in memory few instances
}];
let arguments = (ins Index:$count);
let results = (outs Res<TypeScript_Array, "", [MemAlloc]>:$instance);
}
def TypeScript_DeleteOp : TypeScript_Op<"Delete"> {
let summary = "delete allocated in memory";
let description = [{
delete allocated in memory
}];
let arguments = (ins Arg<TypeScript_AnyRefLike, "", [MemFree]>:$reference);
let results = (outs );
}
def TypeScript_CallOp : TypeScript_Op<"Call", [CallOpInterface, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
let summary = "call operation";
let description = [{
The `call` operation represents a direct call to a function that is within
the same symbol scope as the call.
Example:
```mlir
%2 = call @my_add(%0, %1) : (f32, f32) -> f32
```
}];
let arguments = (ins FlatSymbolRefAttr:$callee, Variadic<AnyType>:$callOperands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs Variadic<AnyType>:$results);
let builders = [
OpBuilder<(ins "FuncOp":$callee, CArg<"ValueRange", "{}">:$callOperands), [{
$_state.addOperands(callOperands);
$_state.addAttribute("callee", SymbolRefAttr::get(callee));
$_state.addTypes(callee.getFunctionType().getResults());
}]>,
OpBuilder<(ins "SymbolRefAttr":$callee, "TypeRange":$results,
CArg<"ValueRange", "{}">:$callOperands), [{
$_state.addOperands(callOperands);
$_state.addAttribute("callee", callee);
$_state.addTypes(results);
}]>,
OpBuilder<(ins "StringAttr":$callee, "TypeRange":$results,
CArg<"ValueRange", "{}">:$callOperands), [{
build($_builder, $_state, SymbolRefAttr::get(callee), results, callOperands);
}]>,
OpBuilder<(ins "StringRef":$callee, "TypeRange":$results,
CArg<"ValueRange", "{}">:$callOperands), [{
build($_builder, $_state, SymbolRefAttr::get($_builder.getContext(), callee), results,
callOperands);
}]>];
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
operand_range getArgOperands()
{
return {arg_operand_begin(), arg_operand_end()};
}
MutableOperandRange getArgOperandsMutable() {
return getCallOperandsMutable();
}
operand_iterator arg_operand_begin() { return operand_begin(); }
operand_iterator arg_operand_end() { return operand_end(); }
/// Return the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return (*this)->getAttrOfType<SymbolRefAttr>("callee"); }
void setCalleeFromCallable(CallInterfaceCallable callee) { (*this)->setAttr("callee", callee.get<SymbolRefAttr>()); }
}];
}
def TypeScript_CallIndirectOp : TypeScript_Op<"CallIndirect", [
CallOpInterface,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
TypesMatchWith<"callee result types match result types",
"callee", "results",
"(isa<HybridFunctionType>($_self) ? cast<HybridFunctionType>($_self).getResults() : cast<FunctionType>($_self).getResults())">
]> {
let summary = "indirect call operation";
let description = [{
The `call_indirect` operation represents an indirect call to a value of
function type. Functions are first class types in MLIR, and may be passed as
arguments and merged together with block arguments. The operands and result
types of the call must match the specified function type.
}];
let arguments = (ins TypeScript_Callable:$callee, Variadic<AnyType>:$callOperands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs Variadic<AnyType>:$results);
let builders = [
OpBuilder<(ins "Value":$callee, CArg<"ValueRange", "{}">:$callOperands), [{
$_state.operands.push_back(callee);
$_state.addOperands(callOperands);
if (auto funcType = dyn_cast<FunctionType>(callee.getType()))
{
$_state.addTypes(funcType.getResults());
}
else if (auto hybridFuncType = dyn_cast<mlir::typescript::HybridFunctionType>(callee.getType()))
{
$_state.addTypes(hybridFuncType.getResults());
}
else
{
// every current caller of this builder already guarantees callee is one
// of the two cases above (or passes an explicit TypeRange via the other
// builder instead); leave results empty rather than crash if that ever
// stops being true.
}
}]>,
OpBuilder<(ins "TypeRange":$results, "Value":$callee,
CArg<"ValueRange", "{}">:$callOperands), [{
build($_builder, $_state, results, callee, callOperands, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr);
}]>];
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
operand_range getArgOperands() {
return {arg_operand_begin(), arg_operand_end()};
}
MutableOperandRange getArgOperandsMutable() {
return getCallOperandsMutable();
}
operand_iterator arg_operand_begin() { return ++operand_begin(); }
operand_iterator arg_operand_end() { return operand_end(); }
/// Return the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getCallee(); }
void setCalleeFromCallable(CallInterfaceCallable callee) {
setOperand(0, callee.get<Value>());
}
}];
let hasCanonicalizer = 1;
}
def TypeScript_InvokeOp : TypeScript_Op<"Invoke", [
AttrSizedOperandSegments,
DeclareOpInterfaceMethods<BranchOpInterface>,
Terminator
]> {
let arguments = (ins OptionalAttr<FlatSymbolRefAttr>:$callee,
Variadic<AnyType>:$callOperands,
Variadic<AnyType>:$normalDestOperands,
Variadic<AnyType>:$unwindDestOperands);
let results = (outs Variadic<AnyType>:$results);
let successors = (successor AnySuccessor:$normalDest,
AnySuccessor:$unwindDest);
let builders = [
OpBuilder<(ins "TypeRange":$tys, "FlatSymbolRefAttr":$callee,
"ValueRange":$ops, "Block*":$normal, "ValueRange":$normalOps,
"Block*":$unwind, "ValueRange":$unwindOps),
[{
$_state.addAttribute("callee", callee);
build($_builder, $_state, tys, ops, normal, normalOps, unwind, unwindOps);
}]>,
OpBuilder<(ins "TypeRange":$tys, "ValueRange":$ops, "Block*":$normal,
"ValueRange":$normalOps, "Block*":$unwind, "ValueRange":$unwindOps),
[{
build($_builder, $_state, tys, /*callee=*/FlatSymbolRefAttr(), ops, normalOps,
unwindOps, normal, unwind);
}]>];
let hasVerifier = 1;
}
def TypeScript_InvokeHybridOp : TypeScript_Op<"InvokeHybrid", [
AttrSizedOperandSegments,
DeclareOpInterfaceMethods<BranchOpInterface>,
Terminator]> {
let arguments = (ins TypeScript_HybridFunction:$callee,
Variadic<AnyType>:$callOperands,
Variadic<AnyType>:$normalDestOperands,
Variadic<AnyType>:$unwindDestOperands);
let results = (outs Variadic<AnyType>:$results);
let successors = (successor AnySuccessor:$normalDest,
AnySuccessor:$unwindDest);
}
def TypeScript_SymbolCallInternalOp : TypeScript_Op<"SymbolCallInternal",
[CallOpInterface, DeclareOpInterfaceMethods<SymbolUserOpInterface>]> {
let summary = "symbol call internal operation";
let description = [{
}];
let arguments = (ins FlatSymbolRefAttr:$callee, Variadic<AnyType>:$callOperands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs Variadic<AnyType>:$results);
let builders = [
OpBuilder<(ins "FuncOp":$callee, CArg<"ValueRange", "{}">:$callOperands), [{
$_state.addOperands(callOperands);
$_state.addAttribute("callee", SymbolRefAttr::get(callee));
$_state.addTypes(callee.getFunctionType().getResults());
}]>,
OpBuilder<(ins "SymbolRefAttr":$callee, "TypeRange":$results,
CArg<"ValueRange", "{}">:$callOperands), [{
$_state.addOperands(callOperands);
$_state.addAttribute("callee", callee);
$_state.addTypes(results);
}]>,
OpBuilder<(ins "StringRef":$callee, "TypeRange":$results,
CArg<"ValueRange", "{}">:$callOperands), [{
build($_builder, $_state, SymbolRefAttr::get($_builder.getContext(), callee), results,
callOperands);
}]>,
OpBuilder<(ins "TypeRange":$results, "FlatSymbolRefAttr":$callee,
CArg<"ValueRange", "{}">:$callOperands), [{
build($_builder, $_state, results, callee, callOperands, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr);
}]>];
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
operand_range getArgOperands()
{
return {arg_operand_begin(), arg_operand_end()};
}
MutableOperandRange getArgOperandsMutable() {
return getCallOperandsMutable();
}
operand_iterator arg_operand_begin() { return operand_begin(); }
operand_iterator arg_operand_end() { return operand_end(); }
/// Return the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return (*this)->getAttrOfType<SymbolRefAttr>("callee"); }
void setCalleeFromCallable(CallInterfaceCallable callee) { (*this)->setAttr("callee", callee.get<SymbolRefAttr>()); }
}];
}
def TypeScript_CallInternalOp : TypeScript_Op<"CallInternal",
[CallOpInterface]> {
let summary = "call internal operation";
let description = [{
}];
let arguments = (ins Variadic<AnyType>:$callOperands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs Variadic<AnyType>:$results);
let builders = [
OpBuilder<(ins "Value":$callee, CArg<"ValueRange", "{}">:$callOperands), [{
$_state.operands.push_back(callee);
$_state.addOperands(callOperands);
$_state.addTypes(cast<FunctionType>(callee.getType()).getResults());
}]>];
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
operand_range getArgOperands()
{
return {arg_operand_begin(), arg_operand_end()};
}
MutableOperandRange getArgOperandsMutable() {
return getCallOperandsMutable();
}
operand_iterator arg_operand_begin() { return operand_begin(); }
operand_iterator arg_operand_end() { return operand_end(); }
/// Return the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getOperand(0); }
void setCalleeFromCallable(CallInterfaceCallable callee) {
setOperand(0, callee.get<Value>());
}
}];
}
def TypeScript_CallHybridInternalOp : TypeScript_Op<"CallHybridInternal",
[CallOpInterface, MemRefsNormalizable,
DeclareOpInterfaceMethods<SymbolUserOpInterface>,
TypesMatchWith<"callee input types match argument types",
"callee", "callOperands",
"cast<mlir::typescript::HybridFunctionType>($_self).getInputs()">,
TypesMatchWith<"callee result types match result types",
"callee", "results",
"cast<mlir::typescript::HybridFunctionType>($_self).getResults()">
]> {
let summary = "call (hybrid) internal operation";
let description = [{
}];
let arguments = (ins TypeScript_HybridFunction:$callee, Variadic<AnyType>:$callOperands,
OptionalAttr<DictArrayAttr>:$arg_attrs,
OptionalAttr<DictArrayAttr>:$res_attrs);
let results = (outs Variadic<AnyType>:$results);
let builders = [
OpBuilder<(ins "TypeRange":$results, "Value":$callee,
CArg<"ValueRange", "{}">:$callOperands), [{
build($_builder, $_state, results, callee, callOperands, /*arg_attrs=*/nullptr, /*res_attrs=*/nullptr);
}]>];
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
operand_range getArgOperands()
{
return {arg_operand_begin(), arg_operand_end()};
}
MutableOperandRange getArgOperandsMutable() {
return getCallOperandsMutable();
}
operand_iterator arg_operand_begin() { return operand_begin(); }
operand_iterator arg_operand_end() { return operand_end(); }
/// Return the callee of this operation.
CallInterfaceCallable getCallableForCallee() { return getCallee(); }
void setCalleeFromCallable(CallInterfaceCallable callee) {
setOperand(0, callee.get<Value>());
}
}];
}
def TypeScript_CaptureOp : TypeScript_Op<"Capture", []> {
let summary = "capture variables";
let arguments = (ins Arg<Variadic<AnyType>, "", [MemRead]>:$captured);
let results = (outs Res<AnyType, "", [MemAlloc, MemWrite]>);
}
def TypeScript_ParamOp : TypeScript_Op<"Param", []> {
let summary = [{
Allocate an parameter object in memory.
}];
let description = [{
```mlir
%0 = ts.param : f32
```
}];
let arguments = (ins
AnyType:$argValue, OptionalAttr<BoolAttr>:$captured, OptionalAttr<IndexAttr>:$diArgNumber
);
let results = (outs
Res<TypeScript_AnyRefLike, "", [MemAlloc]>:$reference
);
}
def TypeScript_ParamOptionalOp : TypeScript_Op<"ParamOpt", [SingleBlockImplicitTerminator<"typescript::ParamDefaultValueOp">]> {
let summary = [{
Allocate an parameter object in memory.
}];
let description = [{
```mlir
%0 = ts.param_opt : !ts.optional<f32>
```
}];
let arguments = (ins
TypeScript_AnyOptional:$argValue, OptionalAttr<BoolAttr>:$captured, OptionalAttr<IndexAttr>:$diArgNumber
);
let results = (outs
Res<TypeScript_AnyRefLike, "", [MemAlloc]>:$reference
);
let regions = (region AnyRegion:$defaultValueRegion);
let extraClassDeclaration = [{
OpBuilder getDefaultValueBuilder(OpBuilder::Listener *listener = nullptr) {
Block* body = getBody(0);