@@ -61,71 +61,56 @@ CallInst *coro::LowererBase::makeSubFnCall(Value *Arg, int Index,
61
61
return CallInst::Create (Fn, {Arg, IndexVal}, " " , InsertPt->getIterator ());
62
62
}
63
63
64
- // NOTE: Must be sorted!
65
- static const char *const CoroIntrinsics[] = {
66
- " llvm.coro.align" ,
67
- " llvm.coro.alloc" ,
68
- " llvm.coro.async.context.alloc" ,
69
- " llvm.coro.async.context.dealloc" ,
70
- " llvm.coro.async.resume" ,
71
- " llvm.coro.async.size.replace" ,
72
- " llvm.coro.await.suspend.bool" ,
73
- " llvm.coro.await.suspend.handle" ,
74
- " llvm.coro.await.suspend.void" ,
75
- " llvm.coro.begin" ,
76
- " llvm.coro.begin.custom.abi" ,
77
- " llvm.coro.destroy" ,
78
- " llvm.coro.done" ,
79
- " llvm.coro.end" ,
80
- " llvm.coro.end.async" ,
81
- " llvm.coro.frame" ,
82
- " llvm.coro.free" ,
83
- " llvm.coro.id" ,
84
- " llvm.coro.id.async" ,
85
- " llvm.coro.id.retcon" ,
86
- " llvm.coro.id.retcon.once" ,
87
- " llvm.coro.noop" ,
88
- " llvm.coro.prepare.async" ,
89
- " llvm.coro.prepare.retcon" ,
90
- " llvm.coro.promise" ,
91
- " llvm.coro.resume" ,
92
- " llvm.coro.save" ,
93
- " llvm.coro.size" ,
94
- " llvm.coro.subfn.addr" ,
95
- " llvm.coro.suspend" ,
96
- " llvm.coro.suspend.async" ,
97
- " llvm.coro.suspend.retcon" ,
64
+ // We can only efficiently check for non-overloaded intrinsics.
65
+ // The following intrinsics are absent for that reason:
66
+ // coro_align, coro_size, coro_suspend_async, coro_suspend_retcon
67
+ static Intrinsic::ID NonOverloadedCoroIntrinsics[] = {
68
+ Intrinsic::coro_alloc,
69
+ Intrinsic::coro_async_context_alloc,
70
+ Intrinsic::coro_async_context_dealloc,
71
+ Intrinsic::coro_async_resume,
72
+ Intrinsic::coro_async_size_replace,
73
+ Intrinsic::coro_await_suspend_bool,
74
+ Intrinsic::coro_await_suspend_handle,
75
+ Intrinsic::coro_await_suspend_void,
76
+ Intrinsic::coro_begin,
77
+ Intrinsic::coro_begin_custom_abi,
78
+ Intrinsic::coro_destroy,
79
+ Intrinsic::coro_done,
80
+ Intrinsic::coro_end,
81
+ Intrinsic::coro_end_async,
82
+ Intrinsic::coro_frame,
83
+ Intrinsic::coro_free,
84
+ Intrinsic::coro_id,
85
+ Intrinsic::coro_id_async,
86
+ Intrinsic::coro_id_retcon,
87
+ Intrinsic::coro_id_retcon_once,
88
+ Intrinsic::coro_promise,
89
+ Intrinsic::coro_resume,
90
+ Intrinsic::coro_save,
91
+ Intrinsic::coro_subfn_addr,
92
+ Intrinsic::coro_suspend,
98
93
};
99
94
100
- #ifndef NDEBUG
101
- static bool isCoroutineIntrinsicName (StringRef Name) {
102
- return llvm::binary_search (CoroIntrinsics, Name);
103
- }
104
- #endif
105
-
106
95
bool coro::isSuspendBlock (BasicBlock *BB) {
107
96
return isa<AnyCoroSuspendInst>(BB->front ());
108
97
}
109
98
110
99
bool coro::declaresAnyIntrinsic (const Module &M) {
111
- for (StringRef Name : CoroIntrinsics) {
112
- if (M.getNamedValue (Name))
113
- return true ;
114
- }
115
-
116
- return false ;
100
+ return declaresIntrinsics (M, NonOverloadedCoroIntrinsics);
117
101
}
118
102
119
- // Verifies if a module has named values listed. Also, in debug mode verifies
120
- // that names are intrinsic names.
121
- bool coro::declaresIntrinsics (const Module &M,
122
- const std::initializer_list<StringRef> List) {
123
- for (StringRef Name : List) {
124
- assert (isCoroutineIntrinsicName (Name) && " not a coroutine intrinsic" );
125
- if (M.getNamedValue (Name))
126
- return true ;
127
- }
103
+ // Checks whether the module declares any of the listed intrinsics.
104
+ bool coro::declaresIntrinsics (const Module &M, ArrayRef<Intrinsic::ID> List) {
105
+ #ifndef NDEBUG
106
+ for (Intrinsic::ID ID : List)
107
+ assert (!Intrinsic::isOverloaded (ID) &&
108
+ " Only non-overloaded intrinsics supported" );
109
+ #endif
128
110
111
+ for (Intrinsic::ID ID : List)
112
+ if (Intrinsic::getDeclarationIfExists (&M, ID))
113
+ return true ;
129
114
return false ;
130
115
}
131
116
0 commit comments