LLVM 22.0.0git
CoroInstr.h
Go to the documentation of this file.
1//===-- CoroInstr.h - Coroutine Intrinsics Instruction Wrappers -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8// This file defines classes that make it really easy to deal with intrinsic
9// functions with the isa/dyncast family of functions. In particular, this
10// allows you to do things like:
11//
12// if (auto *SF = dyn_cast<CoroSubFnInst>(Inst))
13// ... SF->getFrame() ...
14//
15// All intrinsic function calls are instances of the call instruction, so these
16// are all subclasses of the CallInst class. Note that none of these classes
17// has state or virtual methods, which is an important part of this gross/neat
18// hack working.
19//
20// The helpful comment above is borrowed from llvm/IntrinsicInst.h, we keep
21// coroutine intrinsic wrappers here since they are only used by the passes in
22// the Coroutine library.
23//===----------------------------------------------------------------------===//
24
25#ifndef LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
26#define LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
27
32
33namespace llvm {
34
35/// This class represents the llvm.coro.subfn.addr instruction.
37 enum { FrameArg, IndexArg };
38
39public:
47 };
48
49 Value *getFrame() const { return getArgOperand(FrameArg); }
51 int64_t Index = getRawIndex()->getValue().getSExtValue();
53 "unexpected CoroSubFnInst index argument");
54 return static_cast<ResumeKind>(Index);
55 }
56
58 return cast<ConstantInt>(getArgOperand(IndexArg));
59 }
60
61 // Methods to support type inquiry through isa, cast, and dyn_cast:
62 static bool classof(const IntrinsicInst *I) {
63 return I->getIntrinsicID() == Intrinsic::coro_subfn_addr;
64 }
65 static bool classof(const Value *V) {
66 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
67 }
68};
69
70/// This represents the llvm.coro.alloc instruction.
72public:
73 // Methods to support type inquiry through isa, cast, and dyn_cast:
74 static bool classof(const IntrinsicInst *I) {
75 return I->getIntrinsicID() == Intrinsic::coro_alloc;
76 }
77 static bool classof(const Value *V) {
78 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
79 }
80};
81
82/// This represents the llvm.coro.await.suspend.{void,bool,handle} instructions.
83// FIXME: add callback metadata
84// FIXME: make a proper IntrinisicInst. Currently this is not possible,
85// because llvm.coro.await.suspend.* can be invoked.
87 enum { AwaiterArg, FrameArg, WrapperArg };
88
89public:
90 Value *getAwaiter() const { return getArgOperand(AwaiterArg); }
91
92 Value *getFrame() const { return getArgOperand(FrameArg); }
93
95 return cast<Function>(getArgOperand(WrapperArg));
96 }
97
98 // Methods to support type inquiry through isa, cast, and dyn_cast:
99 static bool classof(const CallBase *CB) {
100 if (const Function *CF = CB->getCalledFunction()) {
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
110 static bool classof(const Value *V) {
111 return isa<CallBase>(V) && classof(cast<CallBase>(V));
112 }
113};
114
115/// This represents a common base class for llvm.coro.id instructions.
117public:
119 for (User *U : users())
120 if (auto *CA = dyn_cast<CoroAllocInst>(U))
121 return CA;
122 return nullptr;
123 }
124
126 for (User *U : users())
127 if (auto *II = dyn_cast<IntrinsicInst>(U))
128 if (II->getIntrinsicID() == Intrinsic::coro_begin ||
129 II->getIntrinsicID() == Intrinsic::coro_begin_custom_abi)
130 return II;
131 llvm_unreachable("no coro.begin associated with coro.id");
132 }
133
134 // Methods to support type inquiry through isa, cast, and dyn_cast:
135 static bool classof(const IntrinsicInst *I) {
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
142 static bool classof(const Value *V) {
143 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
144 }
145};
146
147/// This represents the llvm.coro.id instruction.
148class CoroIdInst : public AnyCoroIdInst {
149 enum { AlignArg, PromiseArg, CoroutineArg, InfoArg };
150
151public:
153 Value *Arg = getArgOperand(PromiseArg);
154 return isa<ConstantPointerNull>(Arg)
155 ? nullptr
156 : cast<AllocaInst>(Arg->stripPointerCasts());
157 }
158
160 Value *Arg = getArgOperand(PromiseArg);
163 if (isa<AllocaInst>(Arg))
164 return;
165 assert((isa<BitCastInst>(Arg) || isa<GetElementPtrInst>(Arg)) &&
166 "unexpected instruction designating the promise");
167 // TODO: Add a check that any remaining users of Inst are after coro.begin
168 // or add code to move the users after coro.begin.
169 auto *Inst = cast<Instruction>(Arg);
170 if (Inst->use_empty()) {
171 Inst->eraseFromParent();
172 return;
173 }
174 Inst->moveBefore(std::next(getCoroBegin()->getIterator()));
175 }
176
177 // Info argument of coro.id is
178 // fresh out of the frontend: null ;
179 // outlined : {Init, Return, Susp1, Susp2, ...} ;
180 // postsplit : [resume, destroy, cleanup] ;
181 //
182 // If parts of the coroutine were outlined to protect against undesirable
183 // code motion, these functions will be stored in a struct literal referred to
184 // by the Info parameter. Note: this is only needed before coroutine is split.
185 //
186 // After coroutine is split, resume functions are stored in an array
187 // referred to by this parameter.
188
189 struct Info {
192
193 bool hasOutlinedParts() const { return OutlinedParts != nullptr; }
194 bool isPostSplit() const { return Resumers != nullptr; }
195 bool isPreSplit() const { return !isPostSplit(); }
196 };
197 Info getInfo() const {
198 Info Result;
199 auto *GV = dyn_cast<GlobalVariable>(getRawInfo());
200 if (!GV)
201 return Result;
202
203 assert(GV->isConstant() && GV->hasDefinitiveInitializer());
204 Constant *Initializer = GV->getInitializer();
205 if ((Result.OutlinedParts = dyn_cast<ConstantStruct>(Initializer)))
206 return Result;
207
208 Result.Resumers = cast<ConstantArray>(Initializer);
209 return Result;
210 }
212 return cast<Constant>(getArgOperand(InfoArg)->stripPointerCasts());
213 }
214
215 void setInfo(Constant *C) { setArgOperand(InfoArg, C); }
216
218 return cast<Function>(getArgOperand(CoroutineArg)->stripPointerCasts());
219 }
221 if (!isa<ConstantPointerNull>(getArgOperand(CoroutineArg)))
222 assert(getCoroutine() == getFunction() && "Don't change coroutine.");
223 setArgOperand(CoroutineArg, getFunction());
224 }
225
226 // Methods to support type inquiry through isa, cast, and dyn_cast:
227 static bool classof(const IntrinsicInst *I) {
228 return I->getIntrinsicID() == Intrinsic::coro_id;
229 }
230 static bool classof(const Value *V) {
231 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
232 }
233};
234
235/// This represents either the llvm.coro.id.retcon or
236/// llvm.coro.id.retcon.once instruction.
238 enum { SizeArg, AlignArg, StorageArg, PrototypeArg, AllocArg, DeallocArg };
239
240public:
241 LLVM_ABI void checkWellFormed() const;
242
244 return cast<ConstantInt>(getArgOperand(SizeArg))->getZExtValue();
245 }
246
248 return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
249 }
250
251 Value *getStorage() const { return getArgOperand(StorageArg); }
252
253 /// Return the prototype for the continuation function. The type,
254 /// attributes, and calling convention of the continuation function(s)
255 /// are taken from this declaration.
257 return cast<Function>(getArgOperand(PrototypeArg)->stripPointerCasts());
258 }
259
260 /// Return the function to use for allocating memory.
262 return cast<Function>(getArgOperand(AllocArg)->stripPointerCasts());
263 }
264
265 /// Return the function to use for deallocating memory.
267 return cast<Function>(getArgOperand(DeallocArg)->stripPointerCasts());
268 }
269
270 // Methods to support type inquiry through isa, cast, and dyn_cast:
271 static bool classof(const IntrinsicInst *I) {
272 auto ID = I->getIntrinsicID();
273 return ID == Intrinsic::coro_id_retcon ||
274 ID == Intrinsic::coro_id_retcon_once;
275 }
276 static bool classof(const Value *V) {
277 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
278 }
279};
280
281/// This represents the llvm.coro.id.retcon instruction.
283public:
284 // Methods to support type inquiry through isa, cast, and dyn_cast:
285 static bool classof(const IntrinsicInst *I) {
286 return I->getIntrinsicID() == Intrinsic::coro_id_retcon;
287 }
288 static bool classof(const Value *V) {
289 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
290 }
291};
292
293/// This represents the llvm.coro.id.retcon.once instruction.
295public:
296 // Methods to support type inquiry through isa, cast, and dyn_cast:
297 static bool classof(const IntrinsicInst *I) {
298 return I->getIntrinsicID() == Intrinsic::coro_id_retcon_once;
299 }
300 static bool classof(const Value *V) {
301 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
302 }
303};
304
305/// This represents the llvm.coro.id.async instruction.
307 enum { SizeArg, AlignArg, StorageArg, AsyncFuncPtrArg };
308
309public:
310 LLVM_ABI void checkWellFormed() const;
311
312 /// The initial async function context size. The fields of which are reserved
313 /// for use by the frontend. The frame will be allocated as a tail of this
314 /// context.
316 return cast<ConstantInt>(getArgOperand(SizeArg))->getZExtValue();
317 }
318
319 /// The alignment of the initial async function context.
321 return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
322 }
323
324 /// The async context parameter.
325 Value *getStorage() const {
326 return getParent()->getParent()->getArg(getStorageArgumentIndex());
327 }
328
329 unsigned getStorageArgumentIndex() const {
330 auto *Arg = cast<ConstantInt>(getArgOperand(StorageArg));
331 return Arg->getZExtValue();
332 }
333
334 /// Return the async function pointer address. This should be the address of
335 /// a async function pointer struct for the current async function.
336 /// struct async_function_pointer {
337 /// uint32_t context_size;
338 /// uint32_t relative_async_function_pointer;
339 /// };
341 return cast<GlobalVariable>(
342 getArgOperand(AsyncFuncPtrArg)->stripPointerCasts());
343 }
344
345 // Methods to support type inquiry through isa, cast, and dyn_cast:
346 static bool classof(const IntrinsicInst *I) {
347 auto ID = I->getIntrinsicID();
348 return ID == Intrinsic::coro_id_async;
349 }
350
351 static bool classof(const Value *V) {
352 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
353 }
354};
355
356/// This represents the llvm.coro.context.alloc instruction.
358 enum { AsyncFuncPtrArg };
359
360public:
362 return cast<GlobalVariable>(
363 getArgOperand(AsyncFuncPtrArg)->stripPointerCasts());
364 }
365
366 // Methods to support type inquiry through isa, cast, and dyn_cast:
367 static bool classof(const IntrinsicInst *I) {
368 return I->getIntrinsicID() == Intrinsic::coro_async_context_alloc;
369 }
370 static bool classof(const Value *V) {
371 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
372 }
373};
374
375/// This represents the llvm.coro.context.dealloc instruction.
377 enum { AsyncContextArg };
378
379public:
381 return getArgOperand(AsyncContextArg)->stripPointerCasts();
382 }
383
384 // Methods to support type inquiry through isa, cast, and dyn_cast:
385 static bool classof(const IntrinsicInst *I) {
386 return I->getIntrinsicID() == Intrinsic::coro_async_context_dealloc;
387 }
388 static bool classof(const Value *V) {
389 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
390 }
391};
392
393/// This represents the llvm.coro.async.resume instruction.
394/// During lowering this is replaced by the resume function of a suspend point
395/// (the continuation function).
397public:
398 // Methods to support type inquiry through isa, cast, and dyn_cast:
399 static bool classof(const IntrinsicInst *I) {
400 return I->getIntrinsicID() == Intrinsic::coro_async_resume;
401 }
402 static bool classof(const Value *V) {
403 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
404 }
405};
406
407/// This represents the llvm.coro.async.size.replace instruction.
409public:
410 // Methods to support type inquiry through isa, cast, and dyn_cast:
411 static bool classof(const IntrinsicInst *I) {
412 return I->getIntrinsicID() == Intrinsic::coro_async_size_replace;
413 }
414 static bool classof(const Value *V) {
415 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
416 }
417};
418
419/// This represents the llvm.coro.frame instruction.
421public:
422 // Methods to support type inquiry through isa, cast, and dyn_cast:
423 static bool classof(const IntrinsicInst *I) {
424 return I->getIntrinsicID() == Intrinsic::coro_frame;
425 }
426 static bool classof(const Value *V) {
427 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
428 }
429};
430
431/// This represents the llvm.coro.free instruction.
433 enum { IdArg, FrameArg };
434
435public:
436 Value *getFrame() const { return getArgOperand(FrameArg); }
437
438 // Methods to support type inquiry through isa, cast, and dyn_cast:
439 static bool classof(const IntrinsicInst *I) {
440 return I->getIntrinsicID() == Intrinsic::coro_free;
441 }
442 static bool classof(const Value *V) {
443 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
444 }
445};
446
447/// This class represents the llvm.coro.begin or llvm.coro.begin.custom.abi
448/// instructions.
450 enum { IdArg, MemArg, CustomABIArg };
451
452public:
454 return cast<AnyCoroIdInst>(getArgOperand(IdArg));
455 }
456
457 bool hasCustomABI() const {
458 return getIntrinsicID() == Intrinsic::coro_begin_custom_abi;
459 }
460
461 int getCustomABI() const {
462 return cast<ConstantInt>(getArgOperand(CustomABIArg))->getZExtValue();
463 }
464
465 Value *getMem() const { return getArgOperand(MemArg); }
466
467 // Methods for support type inquiry through isa, cast, and dyn_cast:
468 static bool classof(const IntrinsicInst *I) {
469 return I->getIntrinsicID() == Intrinsic::coro_begin ||
470 I->getIntrinsicID() == Intrinsic::coro_begin_custom_abi;
471 }
472 static bool classof(const Value *V) {
473 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
474 }
475};
476
477/// This represents the llvm.coro.save instruction.
479public:
480 // Methods to support type inquiry through isa, cast, and dyn_cast:
481 static bool classof(const IntrinsicInst *I) {
482 return I->getIntrinsicID() == Intrinsic::coro_save;
483 }
484 static bool classof(const Value *V) {
485 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
486 }
487};
488
489/// This represents the llvm.coro.promise instruction.
491 enum { FrameArg, AlignArg, FromArg };
492
493public:
494 /// Are we translating from the frame to the promise (false) or from
495 /// the promise to the frame (true)?
496 bool isFromPromise() const {
497 return cast<Constant>(getArgOperand(FromArg))->isOneValue();
498 }
499
500 /// The required alignment of the promise. This must match the
501 /// alignment of the promise alloca in the coroutine.
503 return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
504 }
505
506 // Methods to support type inquiry through isa, cast, and dyn_cast:
507 static bool classof(const IntrinsicInst *I) {
508 return I->getIntrinsicID() == Intrinsic::coro_promise;
509 }
510 static bool classof(const Value *V) {
511 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
512 }
513};
514
516public:
517 CoroSaveInst *getCoroSave() const;
518
519 // Methods to support type inquiry through isa, cast, and dyn_cast:
520 static bool classof(const IntrinsicInst *I) {
521 return I->getIntrinsicID() == Intrinsic::coro_suspend ||
522 I->getIntrinsicID() == Intrinsic::coro_suspend_async ||
523 I->getIntrinsicID() == Intrinsic::coro_suspend_retcon;
524 }
525 static bool classof(const Value *V) {
526 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
527 }
528};
529
530/// This represents the llvm.coro.suspend instruction.
532 enum { SaveArg, FinalArg };
533
534public:
536 Value *Arg = getArgOperand(SaveArg);
537 if (auto *SI = dyn_cast<CoroSaveInst>(Arg))
538 return SI;
539 assert(isa<ConstantTokenNone>(Arg));
540 return nullptr;
541 }
542
543 bool isFinal() const {
544 return cast<Constant>(getArgOperand(FinalArg))->isOneValue();
545 }
546
547 // Methods to support type inquiry through isa, cast, and dyn_cast:
548 static bool classof(const IntrinsicInst *I) {
549 return I->getIntrinsicID() == Intrinsic::coro_suspend;
550 }
551 static bool classof(const Value *V) {
552 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
553 }
554};
555
557 if (auto Suspend = dyn_cast<CoroSuspendInst>(this))
558 return Suspend->getCoroSave();
559 return nullptr;
560}
561
562/// This represents the llvm.coro.suspend.async instruction.
564public:
565 enum {
570 };
571
572 LLVM_ABI void checkWellFormed() const;
573
574 unsigned getStorageArgumentIndex() const {
575 auto *Arg = cast<ConstantInt>(getArgOperand(StorageArgNoArg));
576 return Arg->getZExtValue();
577 }
578
580 return cast<Function>(
582 }
583
585 return cast<CoroAsyncResumeInst>(
587 }
588
590 return cast<Function>(
592 }
593
594 // Methods to support type inquiry through isa, cast, and dyn_cast:
595 static bool classof(const IntrinsicInst *I) {
596 return I->getIntrinsicID() == Intrinsic::coro_suspend_async;
597 }
598 static bool classof(const Value *V) {
599 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
600 }
601};
602
603/// This represents the llvm.coro.suspend.retcon instruction.
605public:
608
610 const_op_iterator value_end() const { return arg_end(); }
611
613 return make_range(value_begin(), value_end());
614 }
616 return make_range(value_begin(), value_end());
617 }
618
619 // Methods to support type inquiry through isa, cast, and dyn_cast:
620 static bool classof(const IntrinsicInst *I) {
621 return I->getIntrinsicID() == Intrinsic::coro_suspend_retcon;
622 }
623 static bool classof(const Value *V) {
624 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
625 }
626};
627
628/// This represents the llvm.coro.size instruction.
630public:
631 // Methods to support type inquiry through isa, cast, and dyn_cast:
632 static bool classof(const IntrinsicInst *I) {
633 return I->getIntrinsicID() == Intrinsic::coro_size;
634 }
635 static bool classof(const Value *V) {
636 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
637 }
638};
639
640/// This represents the llvm.coro.align instruction.
642public:
643 // Methods to support type inquiry through isa, cast, and dyn_cast:
644 static bool classof(const IntrinsicInst *I) {
645 return I->getIntrinsicID() == Intrinsic::coro_align;
646 }
647 static bool classof(const Value *V) {
648 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
649 }
650};
651
652/// This represents the llvm.end.results instruction.
654public:
657
660
663 }
666 }
667
668 unsigned numReturns() const {
669 return std::distance(retval_begin(), retval_end());
670 }
671
672 // Methods to support type inquiry through isa, cast, and dyn_cast:
673 static bool classof(const IntrinsicInst *I) {
674 return I->getIntrinsicID() == Intrinsic::coro_end_results;
675 }
676 static bool classof(const Value *V) {
677 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
678 }
679};
680
682 enum { FrameArg, UnwindArg, TokenArg };
683
684public:
685 bool isFallthrough() const { return !isUnwind(); }
686 bool isUnwind() const {
687 return cast<Constant>(getArgOperand(UnwindArg))->isOneValue();
688 }
689
690 bool hasResults() const {
691 return !isa<ConstantTokenNone>(getArgOperand(TokenArg));
692 }
693
696 return cast<CoroEndResults>(getArgOperand(TokenArg));
697 }
698
699 // Methods to support type inquiry through isa, cast, and dyn_cast:
700 static bool classof(const IntrinsicInst *I) {
701 auto ID = I->getIntrinsicID();
702 return ID == Intrinsic::coro_end || ID == Intrinsic::coro_end_async;
703 }
704 static bool classof(const Value *V) {
705 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
706 }
707};
708
709/// This represents the llvm.coro.end instruction.
711public:
712 // Methods to support type inquiry through isa, cast, and dyn_cast:
713 static bool classof(const IntrinsicInst *I) {
714 return I->getIntrinsicID() == Intrinsic::coro_end;
715 }
716 static bool classof(const Value *V) {
717 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
718 }
719};
720
721/// This represents the llvm.coro.end instruction.
723 enum { FrameArg, UnwindArg, MustTailCallFuncArg };
724
725public:
726 LLVM_ABI void checkWellFormed() const;
727
729 if (arg_size() < 3)
730 return nullptr;
731
732 return cast<Function>(
733 getArgOperand(MustTailCallFuncArg)->stripPointerCasts());
734 }
735
736 // Methods to support type inquiry through isa, cast, and dyn_cast:
737 static bool classof(const IntrinsicInst *I) {
738 return I->getIntrinsicID() == Intrinsic::coro_end_async;
739 }
740 static bool classof(const Value *V) {
741 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
742 }
743};
744
745/// This represents the llvm.coro.alloca.alloc instruction.
747 enum { SizeArg, AlignArg };
748
749public:
750 Value *getSize() const { return getArgOperand(SizeArg); }
752 return cast<ConstantInt>(getArgOperand(AlignArg))->getAlignValue();
753 }
754
755 // Methods to support type inquiry through isa, cast, and dyn_cast:
756 static bool classof(const IntrinsicInst *I) {
757 return I->getIntrinsicID() == Intrinsic::coro_alloca_alloc;
758 }
759 static bool classof(const Value *V) {
760 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
761 }
762};
763
764/// This represents the llvm.coro.alloca.get instruction.
766 enum { AllocArg };
767
768public:
770 return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
771 }
772
773 // Methods to support type inquiry through isa, cast, and dyn_cast:
774 static bool classof(const IntrinsicInst *I) {
775 return I->getIntrinsicID() == Intrinsic::coro_alloca_get;
776 }
777 static bool classof(const Value *V) {
778 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
779 }
780};
781
782/// This represents the llvm.coro.alloca.free instruction.
784 enum { AllocArg };
785
786public:
788 return cast<CoroAllocaAllocInst>(getArgOperand(AllocArg));
789 }
790
791 // Methods to support type inquiry through isa, cast, and dyn_cast:
792 static bool classof(const IntrinsicInst *I) {
793 return I->getIntrinsicID() == Intrinsic::coro_alloca_free;
794 }
795 static bool classof(const Value *V) {
796 return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
797 }
798};
799
800} // End namespace llvm.
801
802#endif // LLVM_TRANSFORMS_COROUTINES_COROINSTR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI
Definition: Compiler.h:213
uint32_t Index
iv users
Definition: IVUsers.cpp:48
#define I(x, y, z)
Definition: MD5.cpp:58
uint64_t IntrinsicInst * II
int64_t getSExtValue() const
Get sign extended value.
Definition: APInt.h:1562
an instruction to allocate memory on the stack
Definition: Instructions.h:64
bool isFallthrough() const
Definition: CoroInstr.h:685
static bool classof(const Value *V)
Definition: CoroInstr.h:704
bool hasResults() const
Definition: CoroInstr.h:690
bool isUnwind() const
Definition: CoroInstr.h:686
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:700
CoroEndResults * getResults() const
Definition: CoroInstr.h:694
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
Definition: Coroutines.cpp:637
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
static bool classof(const Value *V)
Definition: CoroInstr.h:525
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:520
CoroSaveInst * getCoroSave() const
Definition: CoroInstr.h:556
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1116
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Definition: InstrTypes.h:1348
User::op_iterator arg_begin()
Return the iterator pointing to the beginning of the argument list.
Definition: InstrTypes.h:1267
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1292
void setArgOperand(unsigned i, Value *v)
Definition: InstrTypes.h:1297
User::op_iterator arg_end()
Return the iterator pointing to the end of the argument list.
Definition: InstrTypes.h:1273
unsigned arg_size() const
Definition: InstrTypes.h:1290
ConstantArray - Constant Array Declarations.
Definition: Constants.h:433
This is the shared class of boolean and integer constants.
Definition: Constants.h:87
const APInt & getValue() const
Return the constant as an APInt value reference.
Definition: Constants.h:154
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
Definition: Constants.cpp:1833
This is an important base class in LLVM.
Definition: Constant.h:43
This represents the llvm.coro.align 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 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:746
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:756
Align getAlignment() const
Definition: CoroInstr.h:751
static bool classof(const Value *V)
Definition: CoroInstr.h:759
Value * getSize() const
Definition: CoroInstr.h:750
This represents the llvm.coro.alloca.free instruction.
Definition: CoroInstr.h:783
static bool classof(const Value *V)
Definition: CoroInstr.h:795
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:792
CoroAllocaAllocInst * getAlloc() const
Definition: CoroInstr.h:787
This represents the llvm.coro.alloca.get instruction.
Definition: CoroInstr.h:765
static bool classof(const Value *V)
Definition: CoroInstr.h:777
CoroAllocaAllocInst * getAlloc() const
Definition: CoroInstr.h:769
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:774
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
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:722
Function * getMustTailCallFunction() const
Definition: CoroInstr.h:728
LLVM_ABI void checkWellFormed() const
Definition: Coroutines.cpp:682
static bool classof(const Value *V)
Definition: CoroInstr.h:740
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:737
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:449
AnyCoroIdInst * getId() const
Definition: CoroInstr.h:453
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:468
static bool classof(const Value *V)
Definition: CoroInstr.h:472
bool hasCustomABI() const
Definition: CoroInstr.h:457
int getCustomABI() const
Definition: CoroInstr.h:461
Value * getMem() const
Definition: CoroInstr.h:465
This represents the llvm.coro.end instruction.
Definition: CoroInstr.h:710
static bool classof(const Value *V)
Definition: CoroInstr.h:716
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:713
This represents the llvm.end.results instruction.
Definition: CoroInstr.h:653
op_iterator retval_begin()
Definition: CoroInstr.h:655
const_op_iterator retval_begin() const
Definition: CoroInstr.h:656
iterator_range< const_op_iterator > return_values() const
Definition: CoroInstr.h:664
iterator_range< op_iterator > return_values()
Definition: CoroInstr.h:661
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:673
const_op_iterator retval_end() const
Definition: CoroInstr.h:659
static bool classof(const Value *V)
Definition: CoroInstr.h:676
op_iterator retval_end()
Definition: CoroInstr.h:658
unsigned numReturns() const
Definition: CoroInstr.h:668
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:432
Value * getFrame() const
Definition: CoroInstr.h:436
static bool classof(const Value *V)
Definition: CoroInstr.h:442
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:439
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
Definition: Coroutines.cpp:653
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.promise instruction.
Definition: CoroInstr.h:490
static bool classof(const Value *V)
Definition: CoroInstr.h:510
Align getAlignment() const
The required alignment of the promise.
Definition: CoroInstr.h:502
bool isFromPromise() const
Are we translating from the frame to the promise (false) or from the promise to the frame (true)?
Definition: CoroInstr.h:496
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:507
This represents the llvm.coro.save instruction.
Definition: CoroInstr.h:478
static bool classof(const Value *V)
Definition: CoroInstr.h:484
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:481
This represents the llvm.coro.size instruction.
Definition: CoroInstr.h:629
static bool classof(const Value *V)
Definition: CoroInstr.h:635
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:632
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
This represents the llvm.coro.suspend.async instruction.
Definition: CoroInstr.h:563
Function * getAsyncContextProjectionFunction() const
Definition: CoroInstr.h:579
static bool classof(const Value *V)
Definition: CoroInstr.h:598
unsigned getStorageArgumentIndex() const
Definition: CoroInstr.h:574
LLVM_ABI void checkWellFormed() const
Definition: Coroutines.cpp:678
CoroAsyncResumeInst * getResumeFunction() const
Definition: CoroInstr.h:584
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:595
Function * getMustTailCallFunction() const
Definition: CoroInstr.h:589
This represents the llvm.coro.suspend instruction.
Definition: CoroInstr.h:531
bool isFinal() const
Definition: CoroInstr.h:543
CoroSaveInst * getCoroSave() const
Definition: CoroInstr.h:535
static bool classof(const Value *V)
Definition: CoroInstr.h:551
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:548
This represents the llvm.coro.suspend.retcon instruction.
Definition: CoroInstr.h:604
op_iterator value_begin()
Definition: CoroInstr.h:606
static bool classof(const Value *V)
Definition: CoroInstr.h:623
const_op_iterator value_begin() const
Definition: CoroInstr.h:607
const_op_iterator value_end() const
Definition: CoroInstr.h:610
iterator_range< const_op_iterator > value_operands() const
Definition: CoroInstr.h:615
iterator_range< op_iterator > value_operands()
Definition: CoroInstr.h:612
static bool classof(const IntrinsicInst *I)
Definition: CoroInstr.h:620
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
Definition: Instruction.cpp:82
A wrapper class for inspecting calls to intrinsic functions.
Definition: IntrinsicInst.h:49
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
Definition: IntrinsicInst.h:56
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:720
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
LLVM Value Representation.
Definition: Value.h:75
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Definition: Value.cpp:701
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
Definition: Value.cpp:1098
const ParentTy * getParent() const
Definition: ilist_node.h:34
A range adaptor for a pair of iterators.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
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