LLVM: include/llvm/Transforms/Coroutines/CoroInstr.h Source File (original) (raw)
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#ifndef LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
26#define LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
27
32
33namespace llvm {
34
35
37 enum { FrameArg, IndexArg };
38
39public:
48
53 "unexpected CoroSubFnInst index argument");
54 return static_cast<ResumeKind>(Index);
55 }
56
60
61
63 return I->getIntrinsicID() == Intrinsic::coro_subfn_addr;
64 }
68};
69
70
72public:
73
75 return I->getIntrinsicID() == Intrinsic::coro_alloc;
76 }
80};
81
82
83
84
85
87 enum { AwaiterArg, FrameArg, WrapperArg };
88
89public:
91
93
97
98
101 auto IID = CF->getIntrinsicID();
102 return IID == Intrinsic::coro_await_suspend_void ||
103 IID == Intrinsic::coro_await_suspend_bool ||
104 IID == Intrinsic::coro_await_suspend_handle;
105 }
106
107 return false;
108 }
109
113};
114
115
117public:
121 return CA;
122 return nullptr;
123 }
124
128 if (II->getIntrinsicID() == Intrinsic::coro_begin ||
129 II->getIntrinsicID() == Intrinsic::coro_begin_custom_abi)
130 return II;
132 }
133
134
136 auto ID = I->getIntrinsicID();
137 return ID == Intrinsic::coro_id || ID == Intrinsic::coro_id_retcon ||
138 ID == Intrinsic::coro_id_retcon_once ||
139 ID == Intrinsic::coro_id_async;
140 }
141
145};
146
147
149 enum { AlignArg, PromiseArg, CoroutineArg, InfoArg };
150
151public:
158
164 return;
166 "unexpected instruction designating the promise");
167
168
170 if (Inst->use_empty()) {
171 Inst->eraseFromParent();
172 return;
173 }
175 }
176
177
178
179
180
181
182
183
184
185
186
187
188
200 if (!GV)
201 return Result;
202
203 assert(GV->isConstant() && GV->hasDefinitiveInitializer());
204 Constant *Initializer = GV->getInitializer();
206 return Result;
207
209 return Result;
210 }
214
216
225
226
228 return I->getIntrinsicID() == Intrinsic::coro_id;
229 }
233};
234
235
236
238 enum { SizeArg, AlignArg, StorageArg, PrototypeArg, AllocArg, DeallocArg };
239
240public:
242
246
250
252
253
254
255
259
260
264
265
269
270
272 auto ID = I->getIntrinsicID();
273 return ID == Intrinsic::coro_id_retcon ||
274 ID == Intrinsic::coro_id_retcon_once;
275 }
279};
280
281
283public:
284
286 return I->getIntrinsicID() == Intrinsic::coro_id_retcon;
287 }
291};
292
293
295public:
296
298 return I->getIntrinsicID() == Intrinsic::coro_id_retcon_once;
299 }
303};
304
305
307 enum { SizeArg, AlignArg, StorageArg, AsyncFuncPtrArg };
308
309public:
311
312
313
314
318
319
323
324
328
331 return Arg->getZExtValue();
332 }
333
334
335
336
337
338
339
344
345
347 auto ID = I->getIntrinsicID();
348 return ID == Intrinsic::coro_id_async;
349 }
350
354};
355
356
358 enum { AsyncFuncPtrArg };
359
360public:
365
366
368 return I->getIntrinsicID() == Intrinsic::coro_async_context_alloc;
369 }
373};
374
375
377 enum { AsyncContextArg };
378
379public:
383
384
386 return I->getIntrinsicID() == Intrinsic::coro_async_context_dealloc;
387 }
391};
392
393
394
395
397public:
398
400 return I->getIntrinsicID() == Intrinsic::coro_async_resume;
401 }
405};
406
407
409public:
410
412 return I->getIntrinsicID() == Intrinsic::coro_async_size_replace;
413 }
417};
418
419
421public:
422
424 return I->getIntrinsicID() == Intrinsic::coro_frame;
425 }
429};
430
431
433public:
434
436 return I->getIntrinsicID() == Intrinsic::coro_is_in_ramp;
437 }
441};
442
443
445 enum { IdArg, FrameArg };
446
447public:
449
450
452 return I->getIntrinsicID() == Intrinsic::coro_free;
453 }
457};
458
459
460
462 enum { IdArg, MemArg, CustomABIArg };
463
464public:
468
470 return getIntrinsicID() == Intrinsic::coro_begin_custom_abi;
471 }
472
476
478
479
481 return I->getIntrinsicID() == Intrinsic::coro_begin ||
482 I->getIntrinsicID() == Intrinsic::coro_begin_custom_abi;
483 }
487};
488
489
491public:
492
494 return I->getIntrinsicID() == Intrinsic::coro_save;
495 }
499};
500
501
503 enum { FrameArg, AlignArg, FromArg };
504
505public:
506
507
511
512
513
517
518
520 return I->getIntrinsicID() == Intrinsic::coro_promise;
521 }
525};
526
528public:
530
531
533 return I->getIntrinsicID() == Intrinsic::coro_suspend ||
534 I->getIntrinsicID() == Intrinsic::coro_suspend_async ||
535 I->getIntrinsicID() == Intrinsic::coro_suspend_retcon;
536 }
540};
541
542
544 enum { SaveArg, FinalArg };
545
546public:
550 return SI;
552 return nullptr;
553 }
554
558
559
561 return I->getIntrinsicID() == Intrinsic::coro_suspend;
562 }
566};
567
570 return Suspend->getCoroSave();
571 return nullptr;
572}
573
574
576public:
577 enum {
582 };
583
585
588 return Arg->getZExtValue();
589 }
590
595
600
605
606
608 return I->getIntrinsicID() == Intrinsic::coro_suspend_async;
609 }
613};
614
615
617public:
620
623
630
631
633 return I->getIntrinsicID() == Intrinsic::coro_suspend_retcon;
634 }
638};
639
640
642public:
643
645 return I->getIntrinsicID() == Intrinsic::coro_size;
646 }
650};
651
652
654public:
655
657 return I->getIntrinsicID() == Intrinsic::coro_align;
658 }
662};
663
664
666public:
669
672
679
683
684
686 return I->getIntrinsicID() == Intrinsic::coro_end_results;
687 }
691};
692
694 enum { FrameArg, UnwindArg, TokenArg };
695
696public:
701
705
710
711
713 auto ID = I->getIntrinsicID();
714 return ID == Intrinsic::coro_end || ID == Intrinsic::coro_end_async;
715 }
719};
720
721
723public:
724
726 return I->getIntrinsicID() == Intrinsic::coro_end;
727 }
731};
732
733
735 enum { FrameArg, UnwindArg, MustTailCallFuncArg };
736
737public:
739
742 return nullptr;
743
746 }
747
748
750 return I->getIntrinsicID() == Intrinsic::coro_end_async;
751 }
755};
756
757
759 enum { SizeArg, AlignArg };
760
761public:
766
767
769 return I->getIntrinsicID() == Intrinsic::coro_alloca_alloc;
770 }
774};
775
776
778 enum { AllocArg };
779
780public:
784
785
787 return I->getIntrinsicID() == Intrinsic::coro_alloca_get;
788 }
792};
793
794
796 enum { AllocArg };
797
798public:
802
803
805 return I->getIntrinsicID() == Intrinsic::coro_alloca_free;
806 }
810};
811
812}
813
814#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t IntrinsicInst * II
int64_t getSExtValue() const
Get sign extended value.
an instruction to allocate memory on the stack
Definition CoroInstr.h:693
bool isFallthrough() const
Definition CoroInstr.h:697
static bool classof(const Value *V)
Definition CoroInstr.h:716
bool hasResults() const
Definition CoroInstr.h:702
bool isUnwind() const
Definition CoroInstr.h:698
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:712
CoroEndResults * getResults() const
Definition CoroInstr.h:706
This represents a common base class for llvm.coro.id instructions.
Definition CoroInstr.h:116
IntrinsicInst * getCoroBegin()
Definition CoroInstr.h:125
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:135
static bool classof(const Value *V)
Definition CoroInstr.h:142
CoroAllocInst * getCoroAlloc()
Definition CoroInstr.h:118
This represents either the llvm.coro.id.retcon or llvm.coro.id.retcon.once instruction.
Definition CoroInstr.h:237
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:271
Value * getStorage() const
Definition CoroInstr.h:251
Align getStorageAlignment() const
Definition CoroInstr.h:247
Function * getPrototype() const
Return the prototype for the continuation function.
Definition CoroInstr.h:256
uint64_t getStorageSize() const
Definition CoroInstr.h:243
LLVM_ABI void checkWellFormed() const
Function * getAllocFunction() const
Return the function to use for allocating memory.
Definition CoroInstr.h:261
static bool classof(const Value *V)
Definition CoroInstr.h:276
Function * getDeallocFunction() const
Return the function to use for deallocating memory.
Definition CoroInstr.h:266
Definition CoroInstr.h:527
static bool classof(const Value *V)
Definition CoroInstr.h:537
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:532
CoroSaveInst * getCoroSave() const
Definition CoroInstr.h:568
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
Value * getArgOperand(unsigned i) const
void setArgOperand(unsigned i, Value *v)
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
unsigned arg_size() const
ConstantArray - Constant Array Declarations.
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
This is an important base class in LLVM.
This represents the llvm.coro.align instruction.
Definition CoroInstr.h:653
static bool classof(const Value *V)
Definition CoroInstr.h:659
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:656
This represents the llvm.coro.alloc instruction.
Definition CoroInstr.h:71
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:74
static bool classof(const Value *V)
Definition CoroInstr.h:77
This represents the llvm.coro.alloca.alloc instruction.
Definition CoroInstr.h:758
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:768
Align getAlignment() const
Definition CoroInstr.h:763
static bool classof(const Value *V)
Definition CoroInstr.h:771
Value * getSize() const
Definition CoroInstr.h:762
This represents the llvm.coro.alloca.free instruction.
Definition CoroInstr.h:795
static bool classof(const Value *V)
Definition CoroInstr.h:807
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:804
CoroAllocaAllocInst * getAlloc() const
Definition CoroInstr.h:799
This represents the llvm.coro.alloca.get instruction.
Definition CoroInstr.h:777
static bool classof(const Value *V)
Definition CoroInstr.h:789
CoroAllocaAllocInst * getAlloc() const
Definition CoroInstr.h:781
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:786
This represents the llvm.coro.context.alloc instruction.
Definition CoroInstr.h:357
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:367
static bool classof(const Value *V)
Definition CoroInstr.h:370
GlobalVariable * getAsyncFunctionPointer() const
Definition CoroInstr.h:361
This represents the llvm.coro.context.dealloc instruction.
Definition CoroInstr.h:376
Value * getAsyncContext() const
Definition CoroInstr.h:380
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:385
static bool classof(const Value *V)
Definition CoroInstr.h:388
This represents the llvm.coro.end instruction.
Definition CoroInstr.h:734
Function * getMustTailCallFunction() const
Definition CoroInstr.h:740
LLVM_ABI void checkWellFormed() const
static bool classof(const Value *V)
Definition CoroInstr.h:752
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:749
This represents the llvm.coro.async.resume instruction.
Definition CoroInstr.h:396
static bool classof(const Value *V)
Definition CoroInstr.h:402
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:399
This represents the llvm.coro.async.size.replace instruction.
Definition CoroInstr.h:408
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:411
static bool classof(const Value *V)
Definition CoroInstr.h:414
This represents the llvm.coro.await.suspend.{void,bool,handle} instructions.
Definition CoroInstr.h:86
static bool classof(const CallBase *CB)
Definition CoroInstr.h:99
Value * getFrame() const
Definition CoroInstr.h:92
static bool classof(const Value *V)
Definition CoroInstr.h:110
Value * getAwaiter() const
Definition CoroInstr.h:90
Function * getWrapperFunction() const
Definition CoroInstr.h:94
This class represents the llvm.coro.begin or llvm.coro.begin.custom.abi instructions.
Definition CoroInstr.h:461
AnyCoroIdInst * getId() const
Definition CoroInstr.h:465
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:480
static bool classof(const Value *V)
Definition CoroInstr.h:484
bool hasCustomABI() const
Definition CoroInstr.h:469
int getCustomABI() const
Definition CoroInstr.h:473
Value * getMem() const
Definition CoroInstr.h:477
This represents the llvm.coro.end instruction.
Definition CoroInstr.h:722
static bool classof(const Value *V)
Definition CoroInstr.h:728
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:725
This represents the llvm.end.results instruction.
Definition CoroInstr.h:665
op_iterator retval_begin()
Definition CoroInstr.h:667
const_op_iterator retval_begin() const
Definition CoroInstr.h:668
iterator_range< const_op_iterator > return_values() const
Definition CoroInstr.h:676
iterator_range< op_iterator > return_values()
Definition CoroInstr.h:673
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:685
const_op_iterator retval_end() const
Definition CoroInstr.h:671
static bool classof(const Value *V)
Definition CoroInstr.h:688
op_iterator retval_end()
Definition CoroInstr.h:670
unsigned numReturns() const
Definition CoroInstr.h:680
This represents the llvm.coro.frame instruction.
Definition CoroInstr.h:420
static bool classof(const Value *V)
Definition CoroInstr.h:426
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:423
This represents the llvm.coro.free instruction.
Definition CoroInstr.h:444
Value * getFrame() const
Definition CoroInstr.h:448
static bool classof(const Value *V)
Definition CoroInstr.h:454
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:451
This represents the llvm.coro.id.async instruction.
Definition CoroInstr.h:306
Align getStorageAlignment() const
The alignment of the initial async function context.
Definition CoroInstr.h:320
uint64_t getStorageSize() const
The initial async function context size.
Definition CoroInstr.h:315
LLVM_ABI void checkWellFormed() const
GlobalVariable * getAsyncFunctionPointer() const
Return the async function pointer address.
Definition CoroInstr.h:340
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:346
Value * getStorage() const
The async context parameter.
Definition CoroInstr.h:325
unsigned getStorageArgumentIndex() const
Definition CoroInstr.h:329
static bool classof(const Value *V)
Definition CoroInstr.h:351
This represents the llvm.coro.id instruction.
Definition CoroInstr.h:148
static bool classof(const Value *V)
Definition CoroInstr.h:230
void setInfo(Constant *C)
Definition CoroInstr.h:215
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:227
Info getInfo() const
Definition CoroInstr.h:197
Function * getCoroutine() const
Definition CoroInstr.h:217
Constant * getRawInfo() const
Definition CoroInstr.h:211
AllocaInst * getPromise() const
Definition CoroInstr.h:152
void setCoroutineSelf()
Definition CoroInstr.h:220
void clearPromise()
Definition CoroInstr.h:159
This represents the llvm.coro.id.retcon instruction.
Definition CoroInstr.h:282
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:285
static bool classof(const Value *V)
Definition CoroInstr.h:288
This represents the llvm.coro.id.retcon.once instruction.
Definition CoroInstr.h:294
static bool classof(const Value *V)
Definition CoroInstr.h:300
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:297
This represents the llvm.coro.is_in_ramp instruction.
Definition CoroInstr.h:432
static bool classof(const Value *V)
Definition CoroInstr.h:438
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:435
This represents the llvm.coro.promise instruction.
Definition CoroInstr.h:502
static bool classof(const Value *V)
Definition CoroInstr.h:522
Align getAlignment() const
The required alignment of the promise.
Definition CoroInstr.h:514
bool isFromPromise() const
Are we translating from the frame to the promise (false) or from the promise to the frame (true)?
Definition CoroInstr.h:508
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:519
This represents the llvm.coro.save instruction.
Definition CoroInstr.h:490
static bool classof(const Value *V)
Definition CoroInstr.h:496
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:493
This represents the llvm.coro.size instruction.
Definition CoroInstr.h:641
static bool classof(const Value *V)
Definition CoroInstr.h:647
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:644
This class represents the llvm.coro.subfn.addr instruction.
Definition CoroInstr.h:36
static bool classof(const Value *V)
Definition CoroInstr.h:65
Value * getFrame() const
Definition CoroInstr.h:49
ResumeKind getIndex() const
Definition CoroInstr.h:50
ConstantInt * getRawIndex() const
Definition CoroInstr.h:57
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:62
ResumeKind
Definition CoroInstr.h:40
@ RestartTrigger
Definition CoroInstr.h:41
@ DestroyIndex
Definition CoroInstr.h:43
@ IndexLast
Definition CoroInstr.h:45
@ IndexFirst
Definition CoroInstr.h:46
@ ResumeIndex
Definition CoroInstr.h:42
@ CleanupIndex
Definition CoroInstr.h:44
This represents the llvm.coro.suspend.async instruction.
Definition CoroInstr.h:575
Function * getAsyncContextProjectionFunction() const
Definition CoroInstr.h:591
static bool classof(const Value *V)
Definition CoroInstr.h:610
@ StorageArgNoArg
Definition CoroInstr.h:578
@ ResumeFunctionArg
Definition CoroInstr.h:579
@ MustTailCallFuncArg
Definition CoroInstr.h:581
@ AsyncContextProjectionArg
Definition CoroInstr.h:580
unsigned getStorageArgumentIndex() const
Definition CoroInstr.h:586
LLVM_ABI void checkWellFormed() const
CoroAsyncResumeInst * getResumeFunction() const
Definition CoroInstr.h:596
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:607
Function * getMustTailCallFunction() const
Definition CoroInstr.h:601
This represents the llvm.coro.suspend instruction.
Definition CoroInstr.h:543
bool isFinal() const
Definition CoroInstr.h:555
CoroSaveInst * getCoroSave() const
Definition CoroInstr.h:547
static bool classof(const Value *V)
Definition CoroInstr.h:563
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:560
This represents the llvm.coro.suspend.retcon instruction.
Definition CoroInstr.h:616
op_iterator value_begin()
Definition CoroInstr.h:618
static bool classof(const Value *V)
Definition CoroInstr.h:635
op_iterator value_end()
Definition CoroInstr.h:621
const_op_iterator value_begin() const
Definition CoroInstr.h:619
const_op_iterator value_end() const
Definition CoroInstr.h:622
iterator_range< const_op_iterator > value_operands() const
Definition CoroInstr.h:627
iterator_range< op_iterator > value_operands()
Definition CoroInstr.h:624
static bool classof(const IntrinsicInst *I)
Definition CoroInstr.h:632
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
const Use * const_op_iterator
LLVM Value Representation.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
const ilist_detail::compute_node_options< Instruction, Options... >::type::parent_ty * getParent() const
self_iterator getIterator()
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition CoroInstr.h:189
ConstantArray * Resumers
Definition CoroInstr.h:191
bool hasOutlinedParts() const
Definition CoroInstr.h:193
bool isPostSplit() const
Definition CoroInstr.h:194
bool isPreSplit() const
Definition CoroInstr.h:195
ConstantStruct * OutlinedParts
Definition CoroInstr.h:190