34#include "llvm/IR/IntrinsicsAArch64.h"
35#include "llvm/IR/IntrinsicsARM.h"
36#include "llvm/IR/IntrinsicsNVPTX.h"
37#include "llvm/IR/IntrinsicsRISCV.h"
38#include "llvm/IR/IntrinsicsWebAssembly.h"
39#include "llvm/IR/IntrinsicsX86.h"
60 cl::desc(
"Disable autoupgrade of debug info"));
70 Type *Arg0Type =
F->getFunctionType()->getParamType(0);
85 Type *LastArgType =
F->getFunctionType()->getParamType(
86 F->getFunctionType()->getNumParams() - 1);
101 if (
F->getReturnType()->isVectorTy())
111 if (
F->getReturnType()->getScalarType()->isBFloatTy())
121 if (
F->getFunctionType()->getParamType(1)->getScalarType()->isBFloatTy())
135 if (
Name.consume_front(
"avx."))
136 return (
Name.starts_with(
"blend.p") ||
137 Name ==
"cvt.ps2.pd.256" ||
138 Name ==
"cvtdq2.pd.256" ||
139 Name ==
"cvtdq2.ps.256" ||
140 Name.starts_with(
"movnt.") ||
141 Name.starts_with(
"sqrt.p") ||
142 Name.starts_with(
"storeu.") ||
143 Name.starts_with(
"vbroadcast.s") ||
144 Name.starts_with(
"vbroadcastf128") ||
145 Name.starts_with(
"vextractf128.") ||
146 Name.starts_with(
"vinsertf128.") ||
147 Name.starts_with(
"vperm2f128.") ||
148 Name.starts_with(
"vpermil."));
150 if (
Name.consume_front(
"avx2."))
151 return (
Name ==
"movntdqa" ||
152 Name.starts_with(
"pabs.") ||
153 Name.starts_with(
"padds.") ||
154 Name.starts_with(
"paddus.") ||
155 Name.starts_with(
"pblendd.") ||
157 Name.starts_with(
"pbroadcast") ||
158 Name.starts_with(
"pcmpeq.") ||
159 Name.starts_with(
"pcmpgt.") ||
160 Name.starts_with(
"pmax") ||
161 Name.starts_with(
"pmin") ||
162 Name.starts_with(
"pmovsx") ||
163 Name.starts_with(
"pmovzx") ||
165 Name ==
"pmulu.dq" ||
166 Name.starts_with(
"psll.dq") ||
167 Name.starts_with(
"psrl.dq") ||
168 Name.starts_with(
"psubs.") ||
169 Name.starts_with(
"psubus.") ||
170 Name.starts_with(
"vbroadcast") ||
171 Name ==
"vbroadcasti128" ||
172 Name ==
"vextracti128" ||
173 Name ==
"vinserti128" ||
174 Name ==
"vperm2i128");
176 if (
Name.consume_front(
"avx512.")) {
177 if (
Name.consume_front(
"mask."))
179 return (
Name.starts_with(
"add.p") ||
180 Name.starts_with(
"and.") ||
181 Name.starts_with(
"andn.") ||
182 Name.starts_with(
"broadcast.s") ||
183 Name.starts_with(
"broadcastf32x4.") ||
184 Name.starts_with(
"broadcastf32x8.") ||
185 Name.starts_with(
"broadcastf64x2.") ||
186 Name.starts_with(
"broadcastf64x4.") ||
187 Name.starts_with(
"broadcasti32x4.") ||
188 Name.starts_with(
"broadcasti32x8.") ||
189 Name.starts_with(
"broadcasti64x2.") ||
190 Name.starts_with(
"broadcasti64x4.") ||
191 Name.starts_with(
"cmp.b") ||
192 Name.starts_with(
"cmp.d") ||
193 Name.starts_with(
"cmp.q") ||
194 Name.starts_with(
"cmp.w") ||
195 Name.starts_with(
"compress.b") ||
196 Name.starts_with(
"compress.d") ||
197 Name.starts_with(
"compress.p") ||
198 Name.starts_with(
"compress.q") ||
199 Name.starts_with(
"compress.store.") ||
200 Name.starts_with(
"compress.w") ||
201 Name.starts_with(
"conflict.") ||
202 Name.starts_with(
"cvtdq2pd.") ||
203 Name.starts_with(
"cvtdq2ps.") ||
204 Name ==
"cvtpd2dq.256" ||
205 Name ==
"cvtpd2ps.256" ||
206 Name ==
"cvtps2pd.128" ||
207 Name ==
"cvtps2pd.256" ||
208 Name.starts_with(
"cvtqq2pd.") ||
209 Name ==
"cvtqq2ps.256" ||
210 Name ==
"cvtqq2ps.512" ||
211 Name ==
"cvttpd2dq.256" ||
212 Name ==
"cvttps2dq.128" ||
213 Name ==
"cvttps2dq.256" ||
214 Name.starts_with(
"cvtudq2pd.") ||
215 Name.starts_with(
"cvtudq2ps.") ||
216 Name.starts_with(
"cvtuqq2pd.") ||
217 Name ==
"cvtuqq2ps.256" ||
218 Name ==
"cvtuqq2ps.512" ||
219 Name.starts_with(
"dbpsadbw.") ||
220 Name.starts_with(
"div.p") ||
221 Name.starts_with(
"expand.b") ||
222 Name.starts_with(
"expand.d") ||
223 Name.starts_with(
"expand.load.") ||
224 Name.starts_with(
"expand.p") ||
225 Name.starts_with(
"expand.q") ||
226 Name.starts_with(
"expand.w") ||
227 Name.starts_with(
"fpclass.p") ||
228 Name.starts_with(
"insert") ||
229 Name.starts_with(
"load.") ||
230 Name.starts_with(
"loadu.") ||
231 Name.starts_with(
"lzcnt.") ||
232 Name.starts_with(
"max.p") ||
233 Name.starts_with(
"min.p") ||
234 Name.starts_with(
"movddup") ||
235 Name.starts_with(
"move.s") ||
236 Name.starts_with(
"movshdup") ||
237 Name.starts_with(
"movsldup") ||
238 Name.starts_with(
"mul.p") ||
239 Name.starts_with(
"or.") ||
240 Name.starts_with(
"pabs.") ||
241 Name.starts_with(
"packssdw.") ||
242 Name.starts_with(
"packsswb.") ||
243 Name.starts_with(
"packusdw.") ||
244 Name.starts_with(
"packuswb.") ||
245 Name.starts_with(
"padd.") ||
246 Name.starts_with(
"padds.") ||
247 Name.starts_with(
"paddus.") ||
248 Name.starts_with(
"palignr.") ||
249 Name.starts_with(
"pand.") ||
250 Name.starts_with(
"pandn.") ||
251 Name.starts_with(
"pavg") ||
252 Name.starts_with(
"pbroadcast") ||
253 Name.starts_with(
"pcmpeq.") ||
254 Name.starts_with(
"pcmpgt.") ||
255 Name.starts_with(
"perm.df.") ||
256 Name.starts_with(
"perm.di.") ||
257 Name.starts_with(
"permvar.") ||
258 Name.starts_with(
"pmaddubs.w.") ||
259 Name.starts_with(
"pmaddw.d.") ||
260 Name.starts_with(
"pmax") ||
261 Name.starts_with(
"pmin") ||
262 Name ==
"pmov.qd.256" ||
263 Name ==
"pmov.qd.512" ||
264 Name ==
"pmov.wb.256" ||
265 Name ==
"pmov.wb.512" ||
266 Name.starts_with(
"pmovsx") ||
267 Name.starts_with(
"pmovzx") ||
268 Name.starts_with(
"pmul.dq.") ||
269 Name.starts_with(
"pmul.hr.sw.") ||
270 Name.starts_with(
"pmulh.w.") ||
271 Name.starts_with(
"pmulhu.w.") ||
272 Name.starts_with(
"pmull.") ||
273 Name.starts_with(
"pmultishift.qb.") ||
274 Name.starts_with(
"pmulu.dq.") ||
275 Name.starts_with(
"por.") ||
276 Name.starts_with(
"prol.") ||
277 Name.starts_with(
"prolv.") ||
278 Name.starts_with(
"pror.") ||
279 Name.starts_with(
"prorv.") ||
280 Name.starts_with(
"pshuf.b.") ||
281 Name.starts_with(
"pshuf.d.") ||
282 Name.starts_with(
"pshufh.w.") ||
283 Name.starts_with(
"pshufl.w.") ||
284 Name.starts_with(
"psll.d") ||
285 Name.starts_with(
"psll.q") ||
286 Name.starts_with(
"psll.w") ||
287 Name.starts_with(
"pslli") ||
288 Name.starts_with(
"psllv") ||
289 Name.starts_with(
"psra.d") ||
290 Name.starts_with(
"psra.q") ||
291 Name.starts_with(
"psra.w") ||
292 Name.starts_with(
"psrai") ||
293 Name.starts_with(
"psrav") ||
294 Name.starts_with(
"psrl.d") ||
295 Name.starts_with(
"psrl.q") ||
296 Name.starts_with(
"psrl.w") ||
297 Name.starts_with(
"psrli") ||
298 Name.starts_with(
"psrlv") ||
299 Name.starts_with(
"psub.") ||
300 Name.starts_with(
"psubs.") ||
301 Name.starts_with(
"psubus.") ||
302 Name.starts_with(
"pternlog.") ||
303 Name.starts_with(
"punpckh") ||
304 Name.starts_with(
"punpckl") ||
305 Name.starts_with(
"pxor.") ||
306 Name.starts_with(
"shuf.f") ||
307 Name.starts_with(
"shuf.i") ||
308 Name.starts_with(
"shuf.p") ||
309 Name.starts_with(
"sqrt.p") ||
310 Name.starts_with(
"store.b.") ||
311 Name.starts_with(
"store.d.") ||
312 Name.starts_with(
"store.p") ||
313 Name.starts_with(
"store.q.") ||
314 Name.starts_with(
"store.w.") ||
315 Name ==
"store.ss" ||
316 Name.starts_with(
"storeu.") ||
317 Name.starts_with(
"sub.p") ||
318 Name.starts_with(
"ucmp.") ||
319 Name.starts_with(
"unpckh.") ||
320 Name.starts_with(
"unpckl.") ||
321 Name.starts_with(
"valign.") ||
322 Name ==
"vcvtph2ps.128" ||
323 Name ==
"vcvtph2ps.256" ||
324 Name.starts_with(
"vextract") ||
325 Name.starts_with(
"vfmadd.") ||
326 Name.starts_with(
"vfmaddsub.") ||
327 Name.starts_with(
"vfnmadd.") ||
328 Name.starts_with(
"vfnmsub.") ||
329 Name.starts_with(
"vpdpbusd.") ||
330 Name.starts_with(
"vpdpbusds.") ||
331 Name.starts_with(
"vpdpwssd.") ||
332 Name.starts_with(
"vpdpwssds.") ||
333 Name.starts_with(
"vpermi2var.") ||
334 Name.starts_with(
"vpermil.p") ||
335 Name.starts_with(
"vpermilvar.") ||
336 Name.starts_with(
"vpermt2var.") ||
337 Name.starts_with(
"vpmadd52") ||
338 Name.starts_with(
"vpshld.") ||
339 Name.starts_with(
"vpshldv.") ||
340 Name.starts_with(
"vpshrd.") ||
341 Name.starts_with(
"vpshrdv.") ||
342 Name.starts_with(
"vpshufbitqmb.") ||
343 Name.starts_with(
"xor."));
345 if (
Name.consume_front(
"mask3."))
347 return (
Name.starts_with(
"vfmadd.") ||
348 Name.starts_with(
"vfmaddsub.") ||
349 Name.starts_with(
"vfmsub.") ||
350 Name.starts_with(
"vfmsubadd.") ||
351 Name.starts_with(
"vfnmsub."));
353 if (
Name.consume_front(
"maskz."))
355 return (
Name.starts_with(
"pternlog.") ||
356 Name.starts_with(
"vfmadd.") ||
357 Name.starts_with(
"vfmaddsub.") ||
358 Name.starts_with(
"vpdpbusd.") ||
359 Name.starts_with(
"vpdpbusds.") ||
360 Name.starts_with(
"vpdpwssd.") ||
361 Name.starts_with(
"vpdpwssds.") ||
362 Name.starts_with(
"vpermt2var.") ||
363 Name.starts_with(
"vpmadd52") ||
364 Name.starts_with(
"vpshldv.") ||
365 Name.starts_with(
"vpshrdv."));
368 return (
Name ==
"movntdqa" ||
369 Name ==
"pmul.dq.512" ||
370 Name ==
"pmulu.dq.512" ||
371 Name.starts_with(
"broadcastm") ||
372 Name.starts_with(
"cmp.p") ||
373 Name.starts_with(
"cvtb2mask.") ||
374 Name.starts_with(
"cvtd2mask.") ||
375 Name.starts_with(
"cvtmask2") ||
376 Name.starts_with(
"cvtq2mask.") ||
377 Name ==
"cvtusi2sd" ||
378 Name.starts_with(
"cvtw2mask.") ||
383 Name ==
"kortestc.w" ||
384 Name ==
"kortestz.w" ||
385 Name.starts_with(
"kunpck") ||
388 Name.starts_with(
"padds.") ||
389 Name.starts_with(
"pbroadcast") ||
390 Name.starts_with(
"prol") ||
391 Name.starts_with(
"pror") ||
392 Name.starts_with(
"psll.dq") ||
393 Name.starts_with(
"psrl.dq") ||
394 Name.starts_with(
"psubs.") ||
395 Name.starts_with(
"ptestm") ||
396 Name.starts_with(
"ptestnm") ||
397 Name.starts_with(
"storent.") ||
398 Name.starts_with(
"vbroadcast.s") ||
399 Name.starts_with(
"vpshld.") ||
400 Name.starts_with(
"vpshrd."));
403 if (
Name.consume_front(
"fma."))
404 return (
Name.starts_with(
"vfmadd.") ||
405 Name.starts_with(
"vfmsub.") ||
406 Name.starts_with(
"vfmsubadd.") ||
407 Name.starts_with(
"vfnmadd.") ||
408 Name.starts_with(
"vfnmsub."));
410 if (
Name.consume_front(
"fma4."))
411 return Name.starts_with(
"vfmadd.s");
413 if (
Name.consume_front(
"sse."))
414 return (
Name ==
"add.ss" ||
415 Name ==
"cvtsi2ss" ||
416 Name ==
"cvtsi642ss" ||
419 Name.starts_with(
"sqrt.p") ||
421 Name.starts_with(
"storeu.") ||
424 if (
Name.consume_front(
"sse2."))
425 return (
Name ==
"add.sd" ||
426 Name ==
"cvtdq2pd" ||
427 Name ==
"cvtdq2ps" ||
428 Name ==
"cvtps2pd" ||
429 Name ==
"cvtsi2sd" ||
430 Name ==
"cvtsi642sd" ||
431 Name ==
"cvtss2sd" ||
434 Name.starts_with(
"padds.") ||
435 Name.starts_with(
"paddus.") ||
436 Name.starts_with(
"pcmpeq.") ||
437 Name.starts_with(
"pcmpgt.") ||
442 Name ==
"pmulu.dq" ||
443 Name.starts_with(
"pshuf") ||
444 Name.starts_with(
"psll.dq") ||
445 Name.starts_with(
"psrl.dq") ||
446 Name.starts_with(
"psubs.") ||
447 Name.starts_with(
"psubus.") ||
448 Name.starts_with(
"sqrt.p") ||
450 Name ==
"storel.dq" ||
451 Name.starts_with(
"storeu.") ||
454 if (
Name.consume_front(
"sse41."))
455 return (
Name.starts_with(
"blendp") ||
456 Name ==
"movntdqa" ||
466 Name.starts_with(
"pmovsx") ||
467 Name.starts_with(
"pmovzx") ||
470 if (
Name.consume_front(
"sse42."))
471 return Name ==
"crc32.64.8";
473 if (
Name.consume_front(
"sse4a."))
474 return Name.starts_with(
"movnt.");
476 if (
Name.consume_front(
"ssse3."))
477 return (
Name ==
"pabs.b.128" ||
478 Name ==
"pabs.d.128" ||
479 Name ==
"pabs.w.128");
481 if (
Name.consume_front(
"xop."))
482 return (
Name ==
"vpcmov" ||
483 Name ==
"vpcmov.256" ||
484 Name.starts_with(
"vpcom") ||
485 Name.starts_with(
"vprot"));
487 return (
Name ==
"addcarry.u32" ||
488 Name ==
"addcarry.u64" ||
489 Name ==
"addcarryx.u32" ||
490 Name ==
"addcarryx.u64" ||
491 Name ==
"subborrow.u32" ||
492 Name ==
"subborrow.u64" ||
493 Name.starts_with(
"vcvtph2ps."));
499 if (!
Name.consume_front(
"x86."))
507 if (
Name ==
"rdtscp") {
509 if (
F->getFunctionType()->getNumParams() == 0)
514 Intrinsic::x86_rdtscp);
521 if (
Name.consume_front(
"sse41.ptest")) {
523 .
Case(
"c", Intrinsic::x86_sse41_ptestc)
524 .
Case(
"z", Intrinsic::x86_sse41_ptestz)
525 .
Case(
"nzc", Intrinsic::x86_sse41_ptestnzc)
538 .
Case(
"sse41.insertps", Intrinsic::x86_sse41_insertps)
539 .
Case(
"sse41.dppd", Intrinsic::x86_sse41_dppd)
540 .
Case(
"sse41.dpps", Intrinsic::x86_sse41_dpps)
541 .
Case(
"sse41.mpsadbw", Intrinsic::x86_sse41_mpsadbw)
542 .
Case(
"avx.dp.ps.256", Intrinsic::x86_avx_dp_ps_256)
543 .
Case(
"avx2.mpsadbw", Intrinsic::x86_avx2_mpsadbw)
548 if (
Name.consume_front(
"avx512.mask.cmp.")) {
551 .
Case(
"pd.128", Intrinsic::x86_avx512_mask_cmp_pd_128)
552 .
Case(
"pd.256", Intrinsic::x86_avx512_mask_cmp_pd_256)
553 .
Case(
"pd.512", Intrinsic::x86_avx512_mask_cmp_pd_512)
554 .
Case(
"ps.128", Intrinsic::x86_avx512_mask_cmp_ps_128)
555 .
Case(
"ps.256", Intrinsic::x86_avx512_mask_cmp_ps_256)
556 .
Case(
"ps.512", Intrinsic::x86_avx512_mask_cmp_ps_512)
563 if (
Name.consume_front(
"avx512bf16.")) {
566 .
Case(
"cvtne2ps2bf16.128",
567 Intrinsic::x86_avx512bf16_cvtne2ps2bf16_128)
568 .
Case(
"cvtne2ps2bf16.256",
569 Intrinsic::x86_avx512bf16_cvtne2ps2bf16_256)
570 .
Case(
"cvtne2ps2bf16.512",
571 Intrinsic::x86_avx512bf16_cvtne2ps2bf16_512)
572 .
Case(
"mask.cvtneps2bf16.128",
573 Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128)
574 .
Case(
"cvtneps2bf16.256",
575 Intrinsic::x86_avx512bf16_cvtneps2bf16_256)
576 .
Case(
"cvtneps2bf16.512",
577 Intrinsic::x86_avx512bf16_cvtneps2bf16_512)
584 .
Case(
"dpbf16ps.128", Intrinsic::x86_avx512bf16_dpbf16ps_128)
585 .
Case(
"dpbf16ps.256", Intrinsic::x86_avx512bf16_dpbf16ps_256)
586 .
Case(
"dpbf16ps.512", Intrinsic::x86_avx512bf16_dpbf16ps_512)
593 if (
Name.consume_front(
"xop.")) {
595 if (
Name.starts_with(
"vpermil2")) {
598 auto Idx =
F->getFunctionType()->getParamType(2);
599 if (
Idx->isFPOrFPVectorTy()) {
600 unsigned IdxSize =
Idx->getPrimitiveSizeInBits();
601 unsigned EltSize =
Idx->getScalarSizeInBits();
602 if (EltSize == 64 && IdxSize == 128)
603 ID = Intrinsic::x86_xop_vpermil2pd;
604 else if (EltSize == 32 && IdxSize == 128)
605 ID = Intrinsic::x86_xop_vpermil2ps;
606 else if (EltSize == 64 && IdxSize == 256)
607 ID = Intrinsic::x86_xop_vpermil2pd_256;
609 ID = Intrinsic::x86_xop_vpermil2ps_256;
611 }
else if (
F->arg_size() == 2)
614 .
Case(
"vfrcz.ss", Intrinsic::x86_xop_vfrcz_ss)
615 .
Case(
"vfrcz.sd", Intrinsic::x86_xop_vfrcz_sd)
626 if (
Name ==
"seh.recoverfp") {
628 Intrinsic::eh_recoverfp);
640 if (
Name.starts_with(
"rbit")) {
643 F->getParent(), Intrinsic::bitreverse,
F->arg_begin()->getType());
647 if (
Name ==
"thread.pointer") {
650 F->getParent(), Intrinsic::thread_pointer,
F->getReturnType());
654 bool Neon =
Name.consume_front(
"neon.");
659 if (
Name.consume_front(
"bfdot.")) {
663 .
Cases(
"v2f32.v8i8",
"v4f32.v16i8",
668 size_t OperandWidth =
F->getReturnType()->getPrimitiveSizeInBits();
669 assert((OperandWidth == 64 || OperandWidth == 128) &&
670 "Unexpected operand width");
672 std::array<Type *, 2> Tys{
683 if (
Name.consume_front(
"bfm")) {
685 if (
Name.consume_back(
".v4f32.v16i8")) {
731 F->arg_begin()->getType());
735 if (
Name.consume_front(
"vst")) {
737 static const Regex vstRegex(
"^([1234]|[234]lane)\\.v[a-z0-9]*$");
741 Intrinsic::arm_neon_vst1, Intrinsic::arm_neon_vst2,
742 Intrinsic::arm_neon_vst3, Intrinsic::arm_neon_vst4};
745 Intrinsic::arm_neon_vst2lane, Intrinsic::arm_neon_vst3lane,
746 Intrinsic::arm_neon_vst4lane};
748 auto fArgs =
F->getFunctionType()->params();
749 Type *Tys[] = {fArgs[0], fArgs[1]};
752 F->getParent(), StoreInts[fArgs.size() - 3], Tys);
755 F->getParent(), StoreLaneInts[fArgs.size() - 5], Tys);
764 if (
Name.consume_front(
"mve.")) {
766 if (
Name ==
"vctp64") {
767 if (cast<FixedVectorType>(
F->getReturnType())->getNumElements() == 4) {
776 if (
Name.starts_with(
"vrintn.v")) {
778 F->getParent(), Intrinsic::roundeven,
F->arg_begin()->getType());
783 if (
Name.consume_back(
".v4i1")) {
785 if (
Name.consume_back(
".predicated.v2i64.v4i32"))
787 return Name ==
"mull.int" ||
Name ==
"vqdmull";
789 if (
Name.consume_back(
".v2i64")) {
791 bool IsGather =
Name.consume_front(
"vldr.gather.");
792 if (IsGather ||
Name.consume_front(
"vstr.scatter.")) {
793 if (
Name.consume_front(
"base.")) {
795 Name.consume_front(
"wb.");
798 return Name ==
"predicated.v2i64";
801 if (
Name.consume_front(
"offset.predicated."))
802 return Name == (IsGather ?
"v2i64.p0i64" :
"p0i64.v2i64") ||
803 Name == (IsGather ?
"v2i64.p0" :
"p0.v2i64");
816 if (
Name.consume_front(
"cde.vcx")) {
818 if (
Name.consume_back(
".predicated.v2i64.v4i1"))
835 F->arg_begin()->getType());
839 if (
Name.starts_with(
"addp")) {
841 if (
F->arg_size() != 2)
843 VectorType *Ty = dyn_cast<VectorType>(
F->getReturnType());
844 if (Ty && Ty->getElementType()->isFloatingPointTy()) {
846 F->getParent(), Intrinsic::aarch64_neon_faddp, Ty);
852 if (
Name.starts_with(
"bfcvt")) {
859 if (
Name.consume_front(
"sve.")) {
861 if (
Name.consume_front(
"bf")) {
862 if (
Name.consume_back(
".lane")) {
866 .
Case(
"dot", Intrinsic::aarch64_sve_bfdot_lane_v2)
867 .
Case(
"mlalb", Intrinsic::aarch64_sve_bfmlalb_lane_v2)
868 .
Case(
"mlalt", Intrinsic::aarch64_sve_bfmlalt_lane_v2)
880 if (
Name ==
"fcvt.bf16f32" ||
Name ==
"fcvtnt.bf16f32") {
885 if (
Name.consume_front(
"addqv")) {
887 if (!
F->getReturnType()->isFPOrFPVectorTy())
890 auto Args =
F->getFunctionType()->params();
891 Type *Tys[] = {
F->getReturnType(), Args[1]};
893 F->getParent(), Intrinsic::aarch64_sve_faddqv, Tys);
897 if (
Name.consume_front(
"ld")) {
899 static const Regex LdRegex(
"^[234](.nxv[a-z0-9]+|$)");
902 cast<VectorType>(
F->getReturnType())->getElementType();
904 cast<VectorType>(
F->arg_begin()->getType())->getElementCount();
905 Type *Ty = VectorType::get(ScalarTy, EC);
907 Intrinsic::aarch64_sve_ld2_sret,
908 Intrinsic::aarch64_sve_ld3_sret,
909 Intrinsic::aarch64_sve_ld4_sret,
912 LoadIDs[
Name[0] -
'2'], Ty);
918 if (
Name.consume_front(
"tuple.")) {
920 if (
Name.starts_with(
"get")) {
922 Type *Tys[] = {
F->getReturnType(),
F->arg_begin()->getType()};
924 F->getParent(), Intrinsic::vector_extract, Tys);
928 if (
Name.starts_with(
"set")) {
930 auto Args =
F->getFunctionType()->params();
931 Type *Tys[] = {Args[0], Args[2], Args[1]};
933 F->getParent(), Intrinsic::vector_insert, Tys);
937 static const Regex CreateTupleRegex(
"^create[234](.nxv[a-z0-9]+|$)");
940 auto Args =
F->getFunctionType()->params();
941 Type *Tys[] = {
F->getReturnType(), Args[1]};
943 F->getParent(), Intrinsic::vector_insert, Tys);
956 if (
Name.consume_front(
"cp.async.bulk.tensor.g2s.")) {
960 Intrinsic::nvvm_cp_async_bulk_tensor_g2s_im2col_3d)
962 Intrinsic::nvvm_cp_async_bulk_tensor_g2s_im2col_4d)
964 Intrinsic::nvvm_cp_async_bulk_tensor_g2s_im2col_5d)
965 .
Case(
"tile.1d", Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_1d)
966 .
Case(
"tile.2d", Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_2d)
967 .
Case(
"tile.3d", Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_3d)
968 .
Case(
"tile.4d", Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_4d)
969 .
Case(
"tile.5d", Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_5d)
978 if (
F->getArg(0)->getType()->getPointerAddressSpace() ==
992 size_t FlagStartIndex =
F->getFunctionType()->getNumParams() - 3;
993 Type *ArgType =
F->getFunctionType()->getParamType(FlagStartIndex);
1003 if (
Name.consume_front(
"mapa.shared.cluster"))
1004 if (
F->getReturnType()->getPointerAddressSpace() ==
1006 return Intrinsic::nvvm_mapa_shared_cluster;
1008 if (
Name.consume_front(
"cp.async.bulk.")) {
1011 .
Case(
"global.to.shared.cluster",
1012 Intrinsic::nvvm_cp_async_bulk_global_to_shared_cluster)
1013 .
Case(
"shared.cta.to.cluster",
1014 Intrinsic::nvvm_cp_async_bulk_shared_cta_to_cluster)
1018 if (
F->getArg(0)->getType()->getPointerAddressSpace() ==
1027 if (
Name.consume_front(
"fma.rn."))
1029 .
Case(
"bf16", Intrinsic::nvvm_fma_rn_bf16)
1030 .
Case(
"bf16x2", Intrinsic::nvvm_fma_rn_bf16x2)
1031 .
Case(
"ftz.bf16", Intrinsic::nvvm_fma_rn_ftz_bf16)
1032 .
Case(
"ftz.bf16x2", Intrinsic::nvvm_fma_rn_ftz_bf16x2)
1033 .
Case(
"ftz.relu.bf16", Intrinsic::nvvm_fma_rn_ftz_relu_bf16)
1034 .
Case(
"ftz.relu.bf16x2", Intrinsic::nvvm_fma_rn_ftz_relu_bf16x2)
1035 .
Case(
"ftz.sat.bf16", Intrinsic::nvvm_fma_rn_ftz_sat_bf16)
1036 .
Case(
"ftz.sat.bf16x2", Intrinsic::nvvm_fma_rn_ftz_sat_bf16x2)
1037 .
Case(
"relu.bf16", Intrinsic::nvvm_fma_rn_relu_bf16)
1038 .
Case(
"relu.bf16x2", Intrinsic::nvvm_fma_rn_relu_bf16x2)
1039 .
Case(
"sat.bf16", Intrinsic::nvvm_fma_rn_sat_bf16)
1040 .
Case(
"sat.bf16x2", Intrinsic::nvvm_fma_rn_sat_bf16x2)
1043 if (
Name.consume_front(
"fmax."))
1045 .
Case(
"bf16", Intrinsic::nvvm_fmax_bf16)
1046 .
Case(
"bf16x2", Intrinsic::nvvm_fmax_bf16x2)
1047 .
Case(
"ftz.bf16", Intrinsic::nvvm_fmax_ftz_bf16)
1048 .
Case(
"ftz.bf16x2", Intrinsic::nvvm_fmax_ftz_bf16x2)
1049 .
Case(
"ftz.nan.bf16", Intrinsic::nvvm_fmax_ftz_nan_bf16)
1050 .
Case(
"ftz.nan.bf16x2", Intrinsic::nvvm_fmax_ftz_nan_bf16x2)
1051 .
Case(
"ftz.nan.xorsign.abs.bf16",
1052 Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_bf16)
1053 .
Case(
"ftz.nan.xorsign.abs.bf16x2",
1054 Intrinsic::nvvm_fmax_ftz_nan_xorsign_abs_bf16x2)
1055 .
Case(
"ftz.xorsign.abs.bf16", Intrinsic::nvvm_fmax_ftz_xorsign_abs_bf16)
1056 .
Case(
"ftz.xorsign.abs.bf16x2",
1057 Intrinsic::nvvm_fmax_ftz_xorsign_abs_bf16x2)
1058 .
Case(
"nan.bf16", Intrinsic::nvvm_fmax_nan_bf16)
1059 .
Case(
"nan.bf16x2", Intrinsic::nvvm_fmax_nan_bf16x2)
1060 .
Case(
"nan.xorsign.abs.bf16", Intrinsic::nvvm_fmax_nan_xorsign_abs_bf16)
1061 .
Case(
"nan.xorsign.abs.bf16x2",
1062 Intrinsic::nvvm_fmax_nan_xorsign_abs_bf16x2)
1063 .
Case(
"xorsign.abs.bf16", Intrinsic::nvvm_fmax_xorsign_abs_bf16)
1064 .
Case(
"xorsign.abs.bf16x2", Intrinsic::nvvm_fmax_xorsign_abs_bf16x2)
1067 if (
Name.consume_front(
"fmin."))
1069 .
Case(
"bf16", Intrinsic::nvvm_fmin_bf16)
1070 .
Case(
"bf16x2", Intrinsic::nvvm_fmin_bf16x2)
1071 .
Case(
"ftz.bf16", Intrinsic::nvvm_fmin_ftz_bf16)
1072 .
Case(
"ftz.bf16x2", Intrinsic::nvvm_fmin_ftz_bf16x2)
1073 .
Case(
"ftz.nan.bf16", Intrinsic::nvvm_fmin_ftz_nan_bf16)
1074 .
Case(
"ftz.nan.bf16x2", Intrinsic::nvvm_fmin_ftz_nan_bf16x2)
1075 .
Case(
"ftz.nan.xorsign.abs.bf16",
1076 Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_bf16)
1077 .
Case(
"ftz.nan.xorsign.abs.bf16x2",
1078 Intrinsic::nvvm_fmin_ftz_nan_xorsign_abs_bf16x2)
1079 .
Case(
"ftz.xorsign.abs.bf16", Intrinsic::nvvm_fmin_ftz_xorsign_abs_bf16)
1080 .
Case(
"ftz.xorsign.abs.bf16x2",
1081 Intrinsic::nvvm_fmin_ftz_xorsign_abs_bf16x2)
1082 .
Case(
"nan.bf16", Intrinsic::nvvm_fmin_nan_bf16)
1083 .
Case(
"nan.bf16x2", Intrinsic::nvvm_fmin_nan_bf16x2)
1084 .
Case(
"nan.xorsign.abs.bf16", Intrinsic::nvvm_fmin_nan_xorsign_abs_bf16)
1085 .
Case(
"nan.xorsign.abs.bf16x2",
1086 Intrinsic::nvvm_fmin_nan_xorsign_abs_bf16x2)
1087 .
Case(
"xorsign.abs.bf16", Intrinsic::nvvm_fmin_xorsign_abs_bf16)
1088 .
Case(
"xorsign.abs.bf16x2", Intrinsic::nvvm_fmin_xorsign_abs_bf16x2)
1091 if (
Name.consume_front(
"neg."))
1093 .
Case(
"bf16", Intrinsic::nvvm_neg_bf16)
1094 .
Case(
"bf16x2", Intrinsic::nvvm_neg_bf16x2)
1101 return Name.consume_front(
"local") ||
Name.consume_front(
"shared") ||
1102 Name.consume_front(
"global") ||
Name.consume_front(
"constant") ||
1103 Name.consume_front(
"param");
1107 bool CanUpgradeDebugIntrinsicsToRecords) {
1108 assert(
F &&
"Illegal to upgrade a non-existent Function.");
1113 if (!
Name.consume_front(
"llvm.") ||
Name.empty())
1119 bool IsArm =
Name.consume_front(
"arm.");
1120 if (IsArm ||
Name.consume_front(
"aarch64.")) {
1126 if (
Name.consume_front(
"amdgcn.")) {
1127 if (
Name ==
"alignbit") {
1130 F->getParent(), Intrinsic::fshr, {F->getReturnType()});
1134 if (
Name.consume_front(
"atomic.")) {
1135 if (
Name.starts_with(
"inc") ||
Name.starts_with(
"dec")) {
1144 if (
Name.consume_front(
"ds.") ||
Name.consume_front(
"global.atomic.") ||
1145 Name.consume_front(
"flat.atomic.")) {
1146 if (
Name.starts_with(
"fadd") ||
1148 (
Name.starts_with(
"fmin") && !
Name.starts_with(
"fmin.num")) ||
1149 (
Name.starts_with(
"fmax") && !
Name.starts_with(
"fmax.num"))) {
1157 if (
Name.starts_with(
"ldexp.")) {
1160 F->getParent(), Intrinsic::ldexp,
1161 {F->getReturnType(), F->getArg(1)->getType()});
1170 if (
F->arg_size() == 1) {
1178 F->arg_begin()->getType());
1183 if (
F->arg_size() == 2 &&
Name ==
"coro.end") {
1186 Intrinsic::coro_end);
1193 if (
Name.consume_front(
"dbg.")) {
1195 if (CanUpgradeDebugIntrinsicsToRecords) {
1196 if (
Name ==
"addr" ||
Name ==
"value" ||
Name ==
"assign" ||
1197 Name ==
"declare" ||
Name ==
"label") {
1206 if (
Name ==
"addr" || (
Name ==
"value" &&
F->arg_size() == 4)) {
1209 Intrinsic::dbg_value);
1216 if (
Name.consume_front(
"experimental.vector.")) {
1222 .
StartsWith(
"extract.", Intrinsic::vector_extract)
1223 .
StartsWith(
"insert.", Intrinsic::vector_insert)
1224 .
StartsWith(
"splice.", Intrinsic::vector_splice)
1225 .
StartsWith(
"reverse.", Intrinsic::vector_reverse)
1226 .
StartsWith(
"interleave2.", Intrinsic::vector_interleave2)
1227 .
StartsWith(
"deinterleave2.", Intrinsic::vector_deinterleave2)
1230 const auto *FT =
F->getFunctionType();
1232 if (
ID == Intrinsic::vector_extract ||
1233 ID == Intrinsic::vector_interleave2)
1236 if (
ID != Intrinsic::vector_interleave2)
1238 if (
ID == Intrinsic::vector_insert)
1246 if (
Name.consume_front(
"reduce.")) {
1248 static const Regex R(
"^([a-z]+)\\.[a-z][0-9]+");
1251 .
Case(
"add", Intrinsic::vector_reduce_add)
1252 .
Case(
"mul", Intrinsic::vector_reduce_mul)
1253 .
Case(
"and", Intrinsic::vector_reduce_and)
1254 .
Case(
"or", Intrinsic::vector_reduce_or)
1255 .
Case(
"xor", Intrinsic::vector_reduce_xor)
1256 .
Case(
"smax", Intrinsic::vector_reduce_smax)
1257 .
Case(
"smin", Intrinsic::vector_reduce_smin)
1258 .
Case(
"umax", Intrinsic::vector_reduce_umax)
1259 .
Case(
"umin", Intrinsic::vector_reduce_umin)
1260 .
Case(
"fmax", Intrinsic::vector_reduce_fmax)
1261 .
Case(
"fmin", Intrinsic::vector_reduce_fmin)
1266 static const Regex R2(
"^v2\\.([a-z]+)\\.[fi][0-9]+");
1271 .
Case(
"fadd", Intrinsic::vector_reduce_fadd)
1272 .
Case(
"fmul", Intrinsic::vector_reduce_fmul)
1277 auto Args =
F->getFunctionType()->params();
1279 {Args[V2 ? 1 : 0]});
1286 if (
Name.consume_front(
"experimental.stepvector.")) {
1290 F->getParent(),
ID,
F->getFunctionType()->getReturnType());
1295 if (
Name.starts_with(
"flt.rounds")) {
1298 Intrinsic::get_rounding);
1303 if (
Name.starts_with(
"invariant.group.barrier")) {
1305 auto Args =
F->getFunctionType()->params();
1306 Type* ObjectPtr[1] = {Args[0]};
1309 F->getParent(), Intrinsic::launder_invariant_group, ObjectPtr);
1314 if ((
Name.starts_with(
"lifetime.start") ||
1315 Name.starts_with(
"lifetime.end")) &&
1316 F->arg_size() == 2) {
1318 ? Intrinsic::lifetime_start
1319 : Intrinsic::lifetime_end;
1322 F->getArg(0)->getType());
1331 .StartsWith(
"memcpy.", Intrinsic::memcpy)
1332 .StartsWith(
"memmove.", Intrinsic::memmove)
1334 if (
F->arg_size() == 5) {
1338 F->getFunctionType()->params().slice(0, 3);
1344 if (
Name.starts_with(
"memset.") &&
F->arg_size() == 5) {
1347 const auto *FT =
F->getFunctionType();
1348 Type *ParamTypes[2] = {
1349 FT->getParamType(0),
1353 Intrinsic::memset, ParamTypes);
1359 if (
Name.consume_front(
"nvvm.")) {
1361 if (
F->arg_size() == 1) {
1364 .
Cases(
"brev32",
"brev64", Intrinsic::bitreverse)
1365 .
Case(
"clz.i", Intrinsic::ctlz)
1366 .
Case(
"popc.i", Intrinsic::ctpop)
1370 {F->getReturnType()});
1376 if (!
F->getReturnType()->getScalarType()->isBFloatTy()) {
1404 bool Expand =
false;
1405 if (
Name.consume_front(
"abs."))
1409 else if (
Name.consume_front(
"fabs."))
1411 Expand =
Name ==
"f" ||
Name ==
"ftz.f" ||
Name ==
"d";
1412 else if (
Name.consume_front(
"max.") ||
Name.consume_front(
"min."))
1416 else if (
Name.consume_front(
"atomic.load."))
1425 else if (
Name.consume_front(
"bitcast."))
1429 else if (
Name.consume_front(
"rotate."))
1431 Expand =
Name ==
"b32" ||
Name ==
"b64" ||
Name ==
"right.b64";
1432 else if (
Name.consume_front(
"ptr.gen.to."))
1435 else if (
Name.consume_front(
"ptr."))
1438 else if (
Name.consume_front(
"ldg.global."))
1440 Expand = (
Name.starts_with(
"i.") ||
Name.starts_with(
"f.") ||
1441 Name.starts_with(
"p."));
1444 .
Case(
"barrier0",
true)
1445 .
Case(
"barrier.n",
true)
1446 .
Case(
"barrier.sync.cnt",
true)
1447 .
Case(
"barrier.sync",
true)
1448 .
Case(
"barrier",
true)
1449 .
Case(
"bar.sync",
true)
1450 .
Case(
"clz.ll",
true)
1451 .
Case(
"popc.ll",
true)
1453 .
Case(
"swap.lo.hi.b64",
true)
1454 .
Case(
"tanh.approx.f32",
true)
1466 if (
Name.starts_with(
"objectsize.")) {
1467 Type *Tys[2] = {
F->getReturnType(),
F->arg_begin()->getType() };
1468 if (
F->arg_size() == 2 ||
F->arg_size() == 3) {
1471 Intrinsic::objectsize, Tys);
1478 if (
Name.starts_with(
"ptr.annotation.") &&
F->arg_size() == 4) {
1481 F->getParent(), Intrinsic::ptr_annotation,
1482 {F->arg_begin()->getType(), F->getArg(1)->getType()});
1488 if (
Name.consume_front(
"riscv.")) {
1491 .
Case(
"aes32dsi", Intrinsic::riscv_aes32dsi)
1492 .
Case(
"aes32dsmi", Intrinsic::riscv_aes32dsmi)
1493 .
Case(
"aes32esi", Intrinsic::riscv_aes32esi)
1494 .
Case(
"aes32esmi", Intrinsic::riscv_aes32esmi)
1497 if (!
F->getFunctionType()->getParamType(2)->isIntegerTy(32)) {
1510 if (!
F->getFunctionType()->getParamType(2)->isIntegerTy(32) ||
1511 F->getFunctionType()->getReturnType()->isIntegerTy(64)) {
1520 .
StartsWith(
"sha256sig0", Intrinsic::riscv_sha256sig0)
1521 .
StartsWith(
"sha256sig1", Intrinsic::riscv_sha256sig1)
1522 .
StartsWith(
"sha256sum0", Intrinsic::riscv_sha256sum0)
1523 .
StartsWith(
"sha256sum1", Intrinsic::riscv_sha256sum1)
1528 if (
F->getFunctionType()->getReturnType()->isIntegerTy(64)) {
1540 if (
Name ==
"stackprotectorcheck") {
1547 if (
Name ==
"thread.pointer") {
1549 F->getParent(), Intrinsic::thread_pointer,
F->getReturnType());
1555 if (
Name ==
"var.annotation" &&
F->arg_size() == 4) {
1558 F->getParent(), Intrinsic::var_annotation,
1559 {{F->arg_begin()->getType(), F->getArg(1)->getType()}});
1566 if (
Name.consume_front(
"wasm.")) {
1569 .
StartsWith(
"fma.", Intrinsic::wasm_relaxed_madd)
1570 .
StartsWith(
"fms.", Intrinsic::wasm_relaxed_nmadd)
1571 .
StartsWith(
"laneselect.", Intrinsic::wasm_relaxed_laneselect)
1576 F->getReturnType());
1580 if (
Name.consume_front(
"dot.i8x16.i7x16.")) {
1582 .
Case(
"signed", Intrinsic::wasm_relaxed_dot_i8x16_i7x16_signed)
1584 Intrinsic::wasm_relaxed_dot_i8x16_i7x16_add_signed)
1602 auto *
ST = dyn_cast<StructType>(
F->getReturnType());
1603 if (ST && (!
ST->isLiteral() ||
ST->isPacked()) &&
1612 auto *FT =
F->getFunctionType();
1614 auto *NewFT = FunctionType::get(NewST, FT->params(), FT->isVarArg());
1615 std::string
Name =
F->getName().str();
1618 Name,
F->getParent());
1629 if (Result != std::nullopt) {
1642 bool CanUpgradeDebugIntrinsicsToRecords) {
1662 GV->
getName() ==
"llvm.global_dtors")) ||
1677 unsigned N =
Init->getNumOperands();
1678 std::vector<Constant *> NewCtors(
N);
1679 for (
unsigned i = 0; i !=
N; ++i) {
1680 auto Ctor = cast<Constant>(
Init->getOperand(i));
1682 Ctor->getAggregateElement(1),
1695 auto *ResultTy = cast<FixedVectorType>(
Op->getType());
1696 unsigned NumElts = ResultTy->getNumElements() * 8;
1710 for (
unsigned l = 0; l != NumElts; l += 16)
1711 for (
unsigned i = 0; i != 16; ++i) {
1712 unsigned Idx = NumElts + i - Shift;
1714 Idx -= NumElts - 16;
1715 Idxs[l + i] =
Idx + l;
1729 auto *ResultTy = cast<FixedVectorType>(
Op->getType());
1730 unsigned NumElts = ResultTy->getNumElements() * 8;
1744 for (
unsigned l = 0; l != NumElts; l += 16)
1745 for (
unsigned i = 0; i != 16; ++i) {
1746 unsigned Idx = i + Shift;
1748 Idx += NumElts - 16;
1749 Idxs[l + i] =
Idx + l;
1770 for (
unsigned i = 0; i != NumElts; ++i)
1782 if (
const auto *
C = dyn_cast<Constant>(Mask))
1783 if (
C->isAllOnesValue())
1787 cast<FixedVectorType>(Op0->
getType())->getNumElements());
1794 if (
const auto *
C = dyn_cast<Constant>(Mask))
1795 if (
C->isAllOnesValue())
1799 Mask->getType()->getIntegerBitWidth());
1812 unsigned ShiftVal = cast<llvm::ConstantInt>(Shift)->getZExtValue();
1814 unsigned NumElts = cast<FixedVectorType>(Op0->
getType())->getNumElements();
1815 assert((IsVALIGN || NumElts % 16 == 0) &&
"Illegal NumElts for PALIGNR!");
1816 assert((!IsVALIGN || NumElts <= 16) &&
"NumElts too large for VALIGN!");
1821 ShiftVal &= (NumElts - 1);
1830 if (ShiftVal > 16) {
1838 for (
unsigned l = 0; l < NumElts; l += 16) {
1839 for (
unsigned i = 0; i != 16; ++i) {
1840 unsigned Idx = ShiftVal + i;
1841 if (!IsVALIGN &&
Idx >= 16)
1842 Idx += NumElts - 16;
1843 Indices[l + i] =
Idx + l;
1848 Op1, Op0,
ArrayRef(Indices, NumElts),
"palignr");
1854 bool ZeroMask,
bool IndexForm) {
1860 if (VecWidth == 128 && EltWidth == 32 && IsFloat)
1861 IID = Intrinsic::x86_avx512_vpermi2var_ps_128;
1862 else if (VecWidth == 128 && EltWidth == 32 && !IsFloat)
1863 IID = Intrinsic::x86_avx512_vpermi2var_d_128;
1864 else if (VecWidth == 128 && EltWidth == 64 && IsFloat)
1865 IID = Intrinsic::x86_avx512_vpermi2var_pd_128;
1866 else if (VecWidth == 128 && EltWidth == 64 && !IsFloat)
1867 IID = Intrinsic::x86_avx512_vpermi2var_q_128;
1868 else if (VecWidth == 256 && EltWidth == 32 && IsFloat)
1869 IID = Intrinsic::x86_avx512_vpermi2var_ps_256;
1870 else if (VecWidth == 256 && EltWidth == 32 && !IsFloat)
1871 IID = Intrinsic::x86_avx512_vpermi2var_d_256;
1872 else if (VecWidth == 256 && EltWidth == 64 && IsFloat)
1873 IID = Intrinsic::x86_avx512_vpermi2var_pd_256;
1874 else if (VecWidth == 256 && EltWidth == 64 && !IsFloat)
1875 IID = Intrinsic::x86_avx512_vpermi2var_q_256;
1876 else if (VecWidth == 512 && EltWidth == 32 && IsFloat)
1877 IID = Intrinsic::x86_avx512_vpermi2var_ps_512;
1878 else if (VecWidth == 512 && EltWidth == 32 && !IsFloat)
1879 IID = Intrinsic::x86_avx512_vpermi2var_d_512;
1880 else if (VecWidth == 512 && EltWidth == 64 && IsFloat)
1881 IID = Intrinsic::x86_avx512_vpermi2var_pd_512;
1882 else if (VecWidth == 512 && EltWidth == 64 && !IsFloat)
1883 IID = Intrinsic::x86_avx512_vpermi2var_q_512;
1884 else if (VecWidth == 128 && EltWidth == 16)
1885 IID = Intrinsic::x86_avx512_vpermi2var_hi_128;
1886 else if (VecWidth == 256 && EltWidth == 16)
1887 IID = Intrinsic::x86_avx512_vpermi2var_hi_256;
1888 else if (VecWidth == 512 && EltWidth == 16)
1889 IID = Intrinsic::x86_avx512_vpermi2var_hi_512;
1890 else if (VecWidth == 128 && EltWidth == 8)
1891 IID = Intrinsic::x86_avx512_vpermi2var_qi_128;
1892 else if (VecWidth == 256 && EltWidth == 8)
1893 IID = Intrinsic::x86_avx512_vpermi2var_qi_256;
1894 else if (VecWidth == 512 && EltWidth == 8)
1895 IID = Intrinsic::x86_avx512_vpermi2var_qi_512;
1929 bool IsRotateRight) {
1938 unsigned NumElts = cast<FixedVectorType>(Ty)->getNumElements();
1943 Intrinsic::ID IID = IsRotateRight ? Intrinsic::fshr : Intrinsic::fshl;
1963 Pred = IsSigned ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
1966 Pred = IsSigned ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
1969 Pred = IsSigned ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
1972 Pred = IsSigned ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
1975 Pred = ICmpInst::ICMP_EQ;
1978 Pred = ICmpInst::ICMP_NE;
1994 bool IsShiftRight,
bool ZeroMask) {
2007 unsigned NumElts = cast<FixedVectorType>(Ty)->getNumElements();
2012 Intrinsic::ID IID = IsShiftRight ? Intrinsic::fshr : Intrinsic::fshl;
2028 const Align Alignment =
2030 ?
Align(Data->getType()->getPrimitiveSizeInBits().getFixedValue() / 8)
2034 if (
const auto *
C = dyn_cast<Constant>(Mask))
2035 if (
C->isAllOnesValue())
2039 unsigned NumElts = cast<FixedVectorType>(Data->getType())->getNumElements();
2047 const Align Alignment =
2055 if (
const auto *
C = dyn_cast<Constant>(Mask))
2056 if (
C->isAllOnesValue())
2060 unsigned NumElts = cast<FixedVectorType>(ValTy)->getNumElements();
2069 {Op0, Builder.
getInt1(
false)});
2084 Constant *ShiftAmt = ConstantInt::get(Ty, 32);
2091 Constant *Mask = ConstantInt::get(Ty, 0xffffffff);
2107 unsigned NumElts = cast<FixedVectorType>(Vec->
getType())->getNumElements();
2109 const auto *
C = dyn_cast<Constant>(Mask);
2110 if (!
C || !
C->isAllOnesValue())
2116 for (
unsigned i = 0; i != NumElts; ++i)
2118 for (
unsigned i = NumElts; i != 8; ++i)
2119 Indices[i] = NumElts + i % NumElts;
2128 unsigned CC,
bool Signed) {
2130 unsigned NumElts = cast<FixedVectorType>(Op0->
getType())->getNumElements();
2136 }
else if (CC == 7) {
2143 case 0: Pred = ICmpInst::ICMP_EQ;
break;
2144 case 1: Pred =
Signed ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT;
break;
2145 case 2: Pred =
Signed ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE;
break;
2146 case 4: Pred = ICmpInst::ICMP_NE;
break;
2147 case 5: Pred =
Signed ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE;
break;
2148 case 6: Pred =
Signed ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT;
break;
2183 unsigned NumElts = cast<FixedVectorType>(CI.
getType())->getNumElements();
2185 return Builder.
CreateSExt(Mask, ReturnOp,
"vpmovm2");
2196 if (
Name.starts_with(
"max.p")) {
2197 if (VecWidth == 128 && EltWidth == 32)
2198 IID = Intrinsic::x86_sse_max_ps;
2199 else if (VecWidth == 128 && EltWidth == 64)
2200 IID = Intrinsic::x86_sse2_max_pd;
2201 else if (VecWidth == 256 && EltWidth == 32)
2202 IID = Intrinsic::x86_avx_max_ps_256;
2203 else if (VecWidth == 256 && EltWidth == 64)
2204 IID = Intrinsic::x86_avx_max_pd_256;
2207 }
else if (
Name.starts_with(
"min.p")) {
2208 if (VecWidth == 128 && EltWidth == 32)
2209 IID = Intrinsic::x86_sse_min_ps;
2210 else if (VecWidth == 128 && EltWidth == 64)
2211 IID = Intrinsic::x86_sse2_min_pd;
2212 else if (VecWidth == 256 && EltWidth == 32)
2213 IID = Intrinsic::x86_avx_min_ps_256;
2214 else if (VecWidth == 256 && EltWidth == 64)
2215 IID = Intrinsic::x86_avx_min_pd_256;
2218 }
else if (
Name.starts_with(
"pshuf.b.")) {
2219 if (VecWidth == 128)
2220 IID = Intrinsic::x86_ssse3_pshuf_b_128;
2221 else if (VecWidth == 256)
2222 IID = Intrinsic::x86_avx2_pshuf_b;
2223 else if (VecWidth == 512)
2224 IID = Intrinsic::x86_avx512_pshuf_b_512;
2227 }
else if (
Name.starts_with(
"pmul.hr.sw.")) {
2228 if (VecWidth == 128)
2229 IID = Intrinsic::x86_ssse3_pmul_hr_sw_128;
2230 else if (VecWidth == 256)
2231 IID = Intrinsic::x86_avx2_pmul_hr_sw;
2232 else if (VecWidth == 512)
2233 IID = Intrinsic::x86_avx512_pmul_hr_sw_512;
2236 }
else if (
Name.starts_with(
"pmulh.w.")) {
2237 if (VecWidth == 128)
2238 IID = Intrinsic::x86_sse2_pmulh_w;
2239 else if (VecWidth == 256)
2240 IID = Intrinsic::x86_avx2_pmulh_w;
2241 else if (VecWidth == 512)
2242 IID = Intrinsic::x86_avx512_pmulh_w_512;
2245 }
else if (
Name.starts_with(
"pmulhu.w.")) {
2246 if (VecWidth == 128)
2247 IID = Intrinsic::x86_sse2_pmulhu_w;
2248 else if (VecWidth == 256)
2249 IID = Intrinsic::x86_avx2_pmulhu_w;
2250 else if (VecWidth == 512)
2251 IID = Intrinsic::x86_avx512_pmulhu_w_512;
2254 }
else if (
Name.starts_with(
"pmaddw.d.")) {
2255 if (VecWidth == 128)
2256 IID = Intrinsic::x86_sse2_pmadd_wd;
2257 else if (VecWidth == 256)
2258 IID = Intrinsic::x86_avx2_pmadd_wd;
2259 else if (VecWidth == 512)
2260 IID = Intrinsic::x86_avx512_pmaddw_d_512;
2263 }
else if (
Name.starts_with(
"pmaddubs.w.")) {
2264 if (VecWidth == 128)
2265 IID = Intrinsic::x86_ssse3_pmadd_ub_sw_128;
2266 else if (VecWidth == 256)
2267 IID = Intrinsic::x86_avx2_pmadd_ub_sw;
2268 else if (VecWidth == 512)
2269 IID = Intrinsic::x86_avx512_pmaddubs_w_512;
2272 }
else if (
Name.starts_with(
"packsswb.")) {
2273 if (VecWidth == 128)
2274 IID = Intrinsic::x86_sse2_packsswb_128;
2275 else if (VecWidth == 256)
2276 IID = Intrinsic::x86_avx2_packsswb;
2277 else if (VecWidth == 512)
2278 IID = Intrinsic::x86_avx512_packsswb_512;
2281 }
else if (
Name.starts_with(
"packssdw.")) {
2282 if (VecWidth == 128)
2283 IID = Intrinsic::x86_sse2_packssdw_128;
2284 else if (VecWidth == 256)
2285 IID = Intrinsic::x86_avx2_packssdw;
2286 else if (VecWidth == 512)
2287 IID = Intrinsic::x86_avx512_packssdw_512;
2290 }
else if (
Name.starts_with(
"packuswb.")) {
2291 if (VecWidth == 128)
2292 IID = Intrinsic::x86_sse2_packuswb_128;
2293 else if (VecWidth == 256)
2294 IID = Intrinsic::x86_avx2_packuswb;
2295 else if (VecWidth == 512)
2296 IID = Intrinsic::x86_avx512_packuswb_512;
2299 }
else if (
Name.starts_with(
"packusdw.")) {
2300 if (VecWidth == 128)
2301 IID = Intrinsic::x86_sse41_packusdw;
2302 else if (VecWidth == 256)
2303 IID = Intrinsic::x86_avx2_packusdw;
2304 else if (VecWidth == 512)
2305 IID = Intrinsic::x86_avx512_packusdw_512;
2308 }
else if (
Name.starts_with(
"vpermilvar.")) {
2309 if (VecWidth == 128 && EltWidth == 32)
2310 IID = Intrinsic::x86_avx_vpermilvar_ps;
2311 else if (VecWidth == 128 && EltWidth == 64)
2312 IID = Intrinsic::x86_avx_vpermilvar_pd;
2313 else if (VecWidth == 256 && EltWidth == 32)
2314 IID = Intrinsic::x86_avx_vpermilvar_ps_256;
2315 else if (VecWidth == 256 && EltWidth == 64)
2316 IID = Intrinsic::x86_avx_vpermilvar_pd_256;
2317 else if (VecWidth == 512 && EltWidth == 32)
2318 IID = Intrinsic::x86_avx512_vpermilvar_ps_512;
2319 else if (VecWidth == 512 && EltWidth == 64)
2320 IID = Intrinsic::x86_avx512_vpermilvar_pd_512;
2323 }
else if (
Name ==
"cvtpd2dq.256") {
2324 IID = Intrinsic::x86_avx_cvt_pd2dq_256;
2325 }
else if (
Name ==
"cvtpd2ps.256") {
2326 IID = Intrinsic::x86_avx_cvt_pd2_ps_256;
2327 }
else if (
Name ==
"cvttpd2dq.256") {
2328 IID = Intrinsic::x86_avx_cvtt_pd2dq_256;
2329 }
else if (
Name ==
"cvttps2dq.128") {
2330 IID = Intrinsic::x86_sse2_cvttps2dq;
2331 }
else if (
Name ==
"cvttps2dq.256") {
2332 IID = Intrinsic::x86_avx_cvtt_ps2dq_256;
2333 }
else if (
Name.starts_with(
"permvar.")) {
2335 if (VecWidth == 256 && EltWidth == 32 && IsFloat)
2336 IID = Intrinsic::x86_avx2_permps;
2337 else if (VecWidth == 256 && EltWidth == 32 && !IsFloat)
2338 IID = Intrinsic::x86_avx2_permd;
2339 else if (VecWidth == 256 && EltWidth == 64 && IsFloat)
2340 IID = Intrinsic::x86_avx512_permvar_df_256;
2341 else if (VecWidth == 256 && EltWidth == 64 && !IsFloat)
2342 IID = Intrinsic::x86_avx512_permvar_di_256;
2343 else if (VecWidth == 512 && EltWidth == 32 && IsFloat)
2344 IID = Intrinsic::x86_avx512_permvar_sf_512;
2345 else if (VecWidth == 512 && EltWidth == 32 && !IsFloat)
2346 IID = Intrinsic::x86_avx512_permvar_si_512;
2347 else if (VecWidth == 512 && EltWidth == 64 && IsFloat)
2348 IID = Intrinsic::x86_avx512_permvar_df_512;
2349 else if (VecWidth == 512 && EltWidth == 64 && !IsFloat)
2350 IID = Intrinsic::x86_avx512_permvar_di_512;
2351 else if (VecWidth == 128 && EltWidth == 16)
2352 IID = Intrinsic::x86_avx512_permvar_hi_128;
2353 else if (VecWidth == 256 && EltWidth == 16)
2354 IID = Intrinsic::x86_avx512_permvar_hi_256;
2355 else if (VecWidth == 512 && EltWidth == 16)
2356 IID = Intrinsic::x86_avx512_permvar_hi_512;
2357 else if (VecWidth == 128 && EltWidth == 8)
2358 IID = Intrinsic::x86_avx512_permvar_qi_128;
2359 else if (VecWidth == 256 && EltWidth == 8)
2360 IID = Intrinsic::x86_avx512_permvar_qi_256;
2361 else if (VecWidth == 512 && EltWidth == 8)
2362 IID = Intrinsic::x86_avx512_permvar_qi_512;
2365 }
else if (
Name.starts_with(
"dbpsadbw.")) {
2366 if (VecWidth == 128)
2367 IID = Intrinsic::x86_avx512_dbpsadbw_128;
2368 else if (VecWidth == 256)
2369 IID = Intrinsic::x86_avx512_dbpsadbw_256;
2370 else if (VecWidth == 512)
2371 IID = Intrinsic::x86_avx512_dbpsadbw_512;
2374 }
else if (
Name.starts_with(
"pmultishift.qb.")) {
2375 if (VecWidth == 128)
2376 IID = Intrinsic::x86_avx512_pmultishift_qb_128;
2377 else if (VecWidth == 256)
2378 IID = Intrinsic::x86_avx512_pmultishift_qb_256;
2379 else if (VecWidth == 512)
2380 IID = Intrinsic::x86_avx512_pmultishift_qb_512;
2383 }
else if (
Name.starts_with(
"conflict.")) {
2384 if (
Name[9] ==
'd' && VecWidth == 128)
2385 IID = Intrinsic::x86_avx512_conflict_d_128;
2386 else if (
Name[9] ==
'd' && VecWidth == 256)
2387 IID = Intrinsic::x86_avx512_conflict_d_256;
2388 else if (
Name[9] ==
'd' && VecWidth == 512)
2389 IID = Intrinsic::x86_avx512_conflict_d_512;
2390 else if (
Name[9] ==
'q' && VecWidth == 128)
2391 IID = Intrinsic::x86_avx512_conflict_q_128;
2392 else if (
Name[9] ==
'q' && VecWidth == 256)
2393 IID = Intrinsic::x86_avx512_conflict_q_256;
2394 else if (
Name[9] ==
'q' && VecWidth == 512)
2395 IID = Intrinsic::x86_avx512_conflict_q_512;
2398 }
else if (
Name.starts_with(
"pavg.")) {
2399 if (
Name[5] ==
'b' && VecWidth == 128)
2400 IID = Intrinsic::x86_sse2_pavg_b;
2401 else if (
Name[5] ==
'b' && VecWidth == 256)
2402 IID = Intrinsic::x86_avx2_pavg_b;
2403 else if (
Name[5] ==
'b' && VecWidth == 512)
2404 IID = Intrinsic::x86_avx512_pavg_b_512;
2405 else if (
Name[5] ==
'w' && VecWidth == 128)
2406 IID = Intrinsic::x86_sse2_pavg_w;
2407 else if (
Name[5] ==
'w' && VecWidth == 256)
2408 IID = Intrinsic::x86_avx2_pavg_w;
2409 else if (
Name[5] ==
'w' && VecWidth == 512)
2410 IID = Intrinsic::x86_avx512_pavg_w_512;
2430 if (AsmStr->find(
"mov\tfp") == 0 &&
2431 AsmStr->find(
"objc_retainAutoreleaseReturnValue") != std::string::npos &&
2432 (Pos = AsmStr->find(
"# marker")) != std::string::npos) {
2433 AsmStr->replace(Pos, 1,
";");
2439 Value *Rep =
nullptr;
2441 if (
Name ==
"abs.i" ||
Name ==
"abs.ll") {
2447 }
else if (
Name ==
"abs.bf16" ||
Name ==
"abs.bf16x2") {
2454 }
else if (
Name ==
"fabs.f" ||
Name ==
"fabs.ftz.f" ||
Name ==
"fabs.d") {
2456 : Intrinsic::nvvm_fabs;
2458 }
else if (
Name.starts_with(
"atomic.load.add.f32.p") ||
2459 Name.starts_with(
"atomic.load.add.f64.p")) {
2463 AtomicOrdering::SequentiallyConsistent);
2464 }
else if (
Name.starts_with(
"atomic.load.inc.32.p") ||
2465 Name.starts_with(
"atomic.load.dec.32.p")) {
2471 AtomicOrdering::SequentiallyConsistent);
2472 }
else if (
Name.consume_front(
"max.") &&
2481 }
else if (
Name.consume_front(
"min.") &&
2490 }
else if (
Name ==
"clz.ll") {
2497 }
else if (
Name ==
"popc.ll") {
2502 Arg,
nullptr,
"ctpop");
2504 }
else if (
Name ==
"h2f") {
2508 }
else if (
Name.consume_front(
"bitcast.") &&
2512 }
else if (
Name ==
"rotate.b32") {
2516 {Arg, Arg, ShiftAmt});
2517 }
else if (
Name ==
"rotate.b64") {
2522 {Arg, Arg, ZExtShiftAmt});
2523 }
else if (
Name ==
"rotate.right.b64") {
2528 {Arg, Arg, ZExtShiftAmt});
2529 }
else if (
Name ==
"swap.lo.hi.b64") {
2534 }
else if ((
Name.consume_front(
"ptr.gen.to.") &&
2537 Name.starts_with(
".to.gen"))) {
2539 }
else if (
Name.consume_front(
"ldg.global")) {
2546 LD->setMetadata(LLVMContext::MD_invariant_load, MD);
2548 }
else if (
Name ==
"tanh.approx.f32") {
2554 }
else if (
Name ==
"barrier0" ||
Name ==
"barrier.n" ||
Name ==
"bar.sync") {
2557 Rep = Builder.
CreateIntrinsic(Intrinsic::nvvm_barrier_cta_sync_aligned_all,
2559 }
else if (
Name ==
"barrier") {
2561 Intrinsic::nvvm_barrier_cta_sync_aligned_count, {},
2563 }
else if (
Name ==
"barrier.sync") {
2564 Rep = Builder.
CreateIntrinsic(Intrinsic::nvvm_barrier_cta_sync_all, {},
2566 }
else if (
Name ==
"barrier.sync.cnt") {
2567 Rep = Builder.
CreateIntrinsic(Intrinsic::nvvm_barrier_cta_sync_count, {},
2572 !
F->getReturnType()->getScalarType()->isBFloatTy()) {
2586 if (
F->getReturnType()->isIntegerTy())
2597 Value *Rep =
nullptr;
2599 if (
Name.starts_with(
"sse4a.movnt.")) {
2614 SI->setMetadata(LLVMContext::MD_nontemporal,
Node);
2615 }
else if (
Name.starts_with(
"avx.movnt.") ||
2616 Name.starts_with(
"avx512.storent.")) {
2628 SI->setMetadata(LLVMContext::MD_nontemporal,
Node);
2629 }
else if (
Name ==
"sse2.storel.dq") {
2637 }
else if (
Name.starts_with(
"sse.storeu.") ||
2638 Name.starts_with(
"sse2.storeu.") ||
2639 Name.starts_with(
"avx.storeu.")) {
2643 }
else if (
Name ==
"avx512.mask.store.ss") {
2647 }
else if (
Name.starts_with(
"avx512.mask.store")) {
2652 }
else if (
Name.starts_with(
"sse2.pcmp") ||
Name.starts_with(
"avx2.pcmp")) {
2655 bool CmpEq =
Name[9] ==
'e';
2656 Rep = Builder.
CreateICmp(CmpEq ? ICmpInst::ICMP_EQ : ICmpInst::ICMP_SGT,
2659 }
else if (
Name.starts_with(
"avx512.broadcastm")) {
2667 }
else if (
Name ==
"sse.sqrt.ss" ||
Name ==
"sse2.sqrt.sd") {
2672 }
else if (
Name.starts_with(
"avx.sqrt.p") ||
2673 Name.starts_with(
"sse2.sqrt.p") ||
2674 Name.starts_with(
"sse.sqrt.p")) {
2676 {CI->getArgOperand(0)});
2677 }
else if (
Name.starts_with(
"avx512.mask.sqrt.p")) {
2680 cast<ConstantInt>(CI->
getArgOperand(3))->getZExtValue() != 4)) {
2682 : Intrinsic::x86_avx512_sqrt_pd_512;
2688 {CI->getArgOperand(0)});
2692 }
else if (
Name.starts_with(
"avx512.ptestm") ||
2693 Name.starts_with(
"avx512.ptestnm")) {
2702 : ICmpInst::ICMP_EQ;
2705 }
else if (
Name.starts_with(
"avx512.mask.pbroadcast")) {
2711 }
else if (
Name.starts_with(
"avx512.kunpck")) {
2716 for (
unsigned i = 0; i != NumElts; ++i)
2727 }
else if (
Name ==
"avx512.kand.w") {
2732 }
else if (
Name ==
"avx512.kandn.w") {
2738 }
else if (
Name ==
"avx512.kor.w") {
2743 }
else if (
Name ==
"avx512.kxor.w") {
2748 }
else if (
Name ==
"avx512.kxnor.w") {
2754 }
else if (
Name ==
"avx512.knot.w") {
2758 }
else if (
Name ==
"avx512.kortestz.w" ||
Name ==
"avx512.kortestc.w") {
2764 if (
Name[14] ==
'c')
2765 C = ConstantInt::getAllOnesValue(Builder.
getInt16Ty());
2767 C = ConstantInt::getNullValue(Builder.
getInt16Ty());
2770 }
else if (
Name ==
"sse.add.ss" ||
Name ==
"sse2.add.sd" ||
2771 Name ==
"sse.sub.ss" ||
Name ==
"sse2.sub.sd" ||
2772 Name ==
"sse.mul.ss" ||
Name ==
"sse2.mul.sd" ||
2773 Name ==
"sse.div.ss" ||
Name ==
"sse2.div.sd") {
2776 ConstantInt::get(I32Ty, 0));
2778 ConstantInt::get(I32Ty, 0));
2780 if (
Name.contains(
".add."))
2782 else if (
Name.contains(
".sub."))
2784 else if (
Name.contains(
".mul."))
2789 ConstantInt::get(I32Ty, 0));
2790 }
else if (
Name.starts_with(
"avx512.mask.pcmp")) {
2792 bool CmpEq =
Name[16] ==
'e';
2794 }
else if (
Name.starts_with(
"avx512.mask.vpshufbitqmb.")) {
2802 IID = Intrinsic::x86_avx512_vpshufbitqmb_128;
2805 IID = Intrinsic::x86_avx512_vpshufbitqmb_256;
2808 IID = Intrinsic::x86_avx512_vpshufbitqmb_512;
2815 }
else if (
Name.starts_with(
"avx512.mask.fpclass.p")) {
2820 if (VecWidth == 128 && EltWidth == 32)
2821 IID = Intrinsic::x86_avx512_fpclass_ps_128;
2822 else if (VecWidth == 256 && EltWidth == 32)
2823 IID = Intrinsic::x86_avx512_fpclass_ps_256;
2824 else if (VecWidth == 512 && EltWidth == 32)
2825 IID = Intrinsic::x86_avx512_fpclass_ps_512;
2826 else if (VecWidth == 128 && EltWidth == 64)
2827 IID = Intrinsic::x86_avx512_fpclass_pd_128;
2828 else if (VecWidth == 256 && EltWidth == 64)
2829 IID = Intrinsic::x86_avx512_fpclass_pd_256;
2830 else if (VecWidth == 512 && EltWidth == 64)
2831 IID = Intrinsic::x86_avx512_fpclass_pd_512;
2838 }
else if (
Name.starts_with(
"avx512.cmp.p")) {
2840 Type *OpTy = Args[0]->getType();
2844 if (VecWidth == 128 && EltWidth == 32)
2845 IID = Intrinsic::x86_avx512_mask_cmp_ps_128;
2846 else if (VecWidth == 256 && EltWidth == 32)
2847 IID = Intrinsic::x86_avx512_mask_cmp_ps_256;
2848 else if (VecWidth == 512 && EltWidth == 32)
2849 IID = Intrinsic::x86_avx512_mask_cmp_ps_512;
2850 else if (VecWidth == 128 && EltWidth == 64)
2851 IID = Intrinsic::x86_avx512_mask_cmp_pd_128;
2852 else if (VecWidth == 256 && EltWidth == 64)
2853 IID = Intrinsic::x86_avx512_mask_cmp_pd_256;
2854 else if (VecWidth == 512 && EltWidth == 64)
2855 IID = Intrinsic::x86_avx512_mask_cmp_pd_512;
2860 if (VecWidth == 512)
2862 Args.push_back(Mask);
2865 }
else if (
Name.starts_with(
"avx512.mask.cmp.")) {
2867 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2869 }
else if (
Name.starts_with(
"avx512.mask.ucmp.")) {
2870 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
2872 }
else if (
Name.starts_with(
"avx512.cvtb2mask.") ||
2873 Name.starts_with(
"avx512.cvtw2mask.") ||
2874 Name.starts_with(
"avx512.cvtd2mask.") ||
2875 Name.starts_with(
"avx512.cvtq2mask.")) {
2878 Rep = Builder.
CreateICmp(ICmpInst::ICMP_SLT,
Op, Zero);
2880 }
else if (
Name ==
"ssse3.pabs.b.128" ||
Name ==
"ssse3.pabs.w.128" ||
2881 Name ==
"ssse3.pabs.d.128" ||
Name.starts_with(
"avx2.pabs") ||
2882 Name.starts_with(
"avx512.mask.pabs")) {
2884 }
else if (
Name ==
"sse41.pmaxsb" ||
Name ==
"sse2.pmaxs.w" ||
2885 Name ==
"sse41.pmaxsd" ||
Name.starts_with(
"avx2.pmaxs") ||
2886 Name.starts_with(
"avx512.mask.pmaxs")) {
2888 }
else if (
Name ==
"sse2.pmaxu.b" ||
Name ==
"sse41.pmaxuw" ||
2889 Name ==
"sse41.pmaxud" ||
Name.starts_with(
"avx2.pmaxu") ||
2890 Name.starts_with(
"avx512.mask.pmaxu")) {
2892 }
else if (
Name ==
"sse41.pminsb" ||
Name ==
"sse2.pmins.w" ||
2893 Name ==
"sse41.pminsd" ||
Name.starts_with(
"avx2.pmins") ||
2894 Name.starts_with(
"avx512.mask.pmins")) {
2896 }
else if (
Name ==
"sse2.pminu.b" ||
Name ==
"sse41.pminuw" ||
2897 Name ==
"sse41.pminud" ||
Name.starts_with(
"avx2.pminu") ||
2898 Name.starts_with(
"avx512.mask.pminu")) {
2900 }
else if (
Name ==
"sse2.pmulu.dq" ||
Name ==
"avx2.pmulu.dq" ||
2901 Name ==
"avx512.pmulu.dq.512" ||
2902 Name.starts_with(
"avx512.mask.pmulu.dq.")) {
2904 }
else if (
Name ==
"sse41.pmuldq" ||
Name ==
"avx2.pmul.dq" ||
2905 Name ==
"avx512.pmul.dq.512" ||
2906 Name.starts_with(
"avx512.mask.pmul.dq.")) {
2908 }
else if (
Name ==
"sse.cvtsi2ss" ||
Name ==
"sse2.cvtsi2sd" ||
2909 Name ==
"sse.cvtsi642ss" ||
Name ==
"sse2.cvtsi642sd") {
2912 cast<VectorType>(CI->
getType())->getElementType());
2914 }
else if (
Name ==
"avx512.cvtusi2sd") {
2917 cast<VectorType>(CI->
getType())->getElementType());
2919 }
else if (
Name ==
"sse2.cvtss2sd") {
2922 Rep, cast<VectorType>(CI->
getType())->getElementType());
2924 }
else if (
Name ==
"sse2.cvtdq2pd" ||
Name ==
"sse2.cvtdq2ps" ||
2925 Name ==
"avx.cvtdq2.pd.256" ||
Name ==
"avx.cvtdq2.ps.256" ||
2926 Name.starts_with(
"avx512.mask.cvtdq2pd.") ||
2927 Name.starts_with(
"avx512.mask.cvtudq2pd.") ||
2928 Name.starts_with(
"avx512.mask.cvtdq2ps.") ||
2929 Name.starts_with(
"avx512.mask.cvtudq2ps.") ||
2930 Name.starts_with(
"avx512.mask.cvtqq2pd.") ||
2931 Name.starts_with(
"avx512.mask.cvtuqq2pd.") ||
2932 Name ==
"avx512.mask.cvtqq2ps.256" ||
2933 Name ==
"avx512.mask.cvtqq2ps.512" ||
2934 Name ==
"avx512.mask.cvtuqq2ps.256" ||
2935 Name ==
"avx512.mask.cvtuqq2ps.512" ||
Name ==
"sse2.cvtps2pd" ||
2936 Name ==
"avx.cvt.ps2.pd.256" ||
2937 Name ==
"avx512.mask.cvtps2pd.128" ||
2938 Name ==
"avx512.mask.cvtps2pd.256") {
2939 auto *DstTy = cast<FixedVectorType>(CI->
getType());
2941 auto *SrcTy = cast<FixedVectorType>(Rep->
getType());
2943 unsigned NumDstElts = DstTy->getNumElements();
2945 assert(NumDstElts == 2 &&
"Unexpected vector size");
2949 bool IsPS2PD = SrcTy->getElementType()->isFloatTy();
2950 bool IsUnsigned =
Name.contains(
"cvtu");
2952 Rep = Builder.
CreateFPExt(Rep, DstTy,
"cvtps2pd");
2955 cast<ConstantInt>(CI->
getArgOperand(3))->getZExtValue() != 4)) {
2956 Intrinsic::ID IID = IsUnsigned ? Intrinsic::x86_avx512_uitofp_round
2957 : Intrinsic::x86_avx512_sitofp_round;
2961 Rep = IsUnsigned ? Builder.
CreateUIToFP(Rep, DstTy,
"cvt")
2968 }
else if (
Name.starts_with(
"avx512.mask.vcvtph2ps.") ||
2969 Name.starts_with(
"vcvtph2ps.")) {
2970 auto *DstTy = cast<FixedVectorType>(CI->
getType());
2972 auto *SrcTy = cast<FixedVectorType>(Rep->
getType());
2973 unsigned NumDstElts = DstTy->getNumElements();
2974 if (NumDstElts != SrcTy->getNumElements()) {
2975 assert(NumDstElts == 4 &&
"Unexpected vector size");
2980 Rep = Builder.
CreateFPExt(Rep, DstTy,
"cvtph2ps");
2984 }
else if (
Name.starts_with(
"avx512.mask.load")) {
2989 }
else if (
Name.starts_with(
"avx512.mask.expand.load.")) {
2990 auto *ResultTy = cast<FixedVectorType>(CI->
getType());
2992 ResultTy->getNumElements());
2995 Intrinsic::masked_expandload, ResultTy,
2997 }
else if (
Name.starts_with(
"avx512.mask.compress.store.")) {
3001 cast<FixedVectorType>(ResultTy)->getNumElements());
3004 Intrinsic::masked_compressstore, ResultTy,
3006 }
else if (
Name.starts_with(
"avx512.mask.compress.") ||
3007 Name.starts_with(
"avx512.mask.expand.")) {
3008 auto *ResultTy = cast<FixedVectorType>(CI->
getType());
3011 ResultTy->getNumElements());
3013 bool IsCompress =
Name[12] ==
'c';
3014 Intrinsic::ID IID = IsCompress ? Intrinsic::x86_avx512_mask_compress
3015 : Intrinsic::x86_avx512_mask_expand;
3018 }
else if (
Name.starts_with(
"xop.vpcom")) {
3020 if (
Name.ends_with(
"ub") ||
Name.ends_with(
"uw") ||
Name.ends_with(
"ud") ||
3021 Name.ends_with(
"uq"))
3023 else if (
Name.ends_with(
"b") ||
Name.ends_with(
"w") ||
3024 Name.ends_with(
"d") ||
Name.ends_with(
"q"))
3031 Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3034 if (
Name.starts_with(
"lt"))
3036 else if (
Name.starts_with(
"le"))
3038 else if (
Name.starts_with(
"gt"))
3040 else if (
Name.starts_with(
"ge"))
3042 else if (
Name.starts_with(
"eq"))
3044 else if (
Name.starts_with(
"ne"))
3046 else if (
Name.starts_with(
"false"))
3048 else if (
Name.starts_with(
"true"))
3055 }
else if (
Name.starts_with(
"xop.vpcmov")) {
3060 Rep = Builder.
CreateOr(Sel0, Sel1);
3061 }
else if (
Name.starts_with(
"xop.vprot") ||
Name.starts_with(
"avx512.prol") ||
3062 Name.starts_with(
"avx512.mask.prol")) {
3064 }
else if (
Name.starts_with(
"avx512.pror") ||
3065 Name.starts_with(
"avx512.mask.pror")) {
3067 }
else if (
Name.starts_with(
"avx512.vpshld.") ||
3068 Name.starts_with(
"avx512.mask.vpshld") ||
3069 Name.starts_with(
"avx512.maskz.vpshld")) {
3070 bool ZeroMask =
Name[11] ==
'z';
3072 }
else if (
Name.starts_with(
"avx512.vpshrd.") ||
3073 Name.starts_with(
"avx512.mask.vpshrd") ||
3074 Name.starts_with(
"avx512.maskz.vpshrd")) {
3075 bool ZeroMask =
Name[11] ==
'z';
3077 }
else if (
Name ==
"sse42.crc32.64.8") {
3083 }
else if (
Name.starts_with(
"avx.vbroadcast.s") ||
3084 Name.starts_with(
"avx512.vbroadcast.s")) {
3086 auto *VecTy = cast<FixedVectorType>(CI->
getType());
3087 Type *EltTy = VecTy->getElementType();
3088 unsigned EltNum = VecTy->getNumElements();
3092 for (
unsigned I = 0;
I < EltNum; ++
I)
3094 }
else if (
Name.starts_with(
"sse41.pmovsx") ||
3095 Name.starts_with(
"sse41.pmovzx") ||
3096 Name.starts_with(
"avx2.pmovsx") ||
3097 Name.starts_with(
"avx2.pmovzx") ||
3098 Name.starts_with(
"avx512.mask.pmovsx") ||
3099 Name.starts_with(
"avx512.mask.pmovzx")) {
3100 auto *DstTy = cast<FixedVectorType>(CI->
getType());
3101 unsigned NumDstElts = DstTy->getNumElements();
3105 for (
unsigned i = 0; i != NumDstElts; ++i)
3110 bool DoSext =
Name.contains(
"pmovsx");
3117 }
else if (
Name ==
"avx512.mask.pmov.qd.256" ||
3118 Name ==
"avx512.mask.pmov.qd.512" ||
3119 Name ==
"avx512.mask.pmov.wb.256" ||
3120 Name ==
"avx512.mask.pmov.wb.512") {
3125 }
else if (
Name.starts_with(
"avx.vbroadcastf128") ||
3126 Name ==
"avx2.vbroadcasti128") {
3128 Type *EltTy = cast<VectorType>(CI->
getType())->getElementType();
3132 if (NumSrcElts == 2)
3137 }
else if (
Name.starts_with(
"avx512.mask.shuf.i") ||
3138 Name.starts_with(
"avx512.mask.shuf.f")) {
3139 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3143 unsigned ControlBitsMask = NumLanes - 1;
3144 unsigned NumControlBits = NumLanes / 2;
3147 for (
unsigned l = 0; l != NumLanes; ++l) {
3148 unsigned LaneMask = (Imm >> (l * NumControlBits)) & ControlBitsMask;
3150 if (l >= NumLanes / 2)
3151 LaneMask += NumLanes;
3152 for (
unsigned i = 0; i != NumElementsInLane; ++i)
3153 ShuffleMask.
push_back(LaneMask * NumElementsInLane + i);
3159 }
else if (
Name.starts_with(
"avx512.mask.broadcastf") ||
3160 Name.starts_with(
"avx512.mask.broadcasti")) {
3163 unsigned NumDstElts =
3164 cast<FixedVectorType>(CI->
getType())->getNumElements();
3167 for (
unsigned i = 0; i != NumDstElts; ++i)
3168 ShuffleMask[i] = i % NumSrcElts;
3174 }
else if (
Name.starts_with(
"avx2.pbroadcast") ||
3175 Name.starts_with(
"avx2.vbroadcast") ||
3176 Name.starts_with(
"avx512.pbroadcast") ||
3177 Name.starts_with(
"avx512.mask.broadcast.s")) {
3189 }
else if (
Name.starts_with(
"sse2.padds.") ||
3190 Name.starts_with(
"avx2.padds.") ||
3191 Name.starts_with(
"avx512.padds.") ||
3192 Name.starts_with(
"avx512.mask.padds.")) {
3194 }
else if (
Name.starts_with(
"sse2.psubs.") ||
3195 Name.starts_with(
"avx2.psubs.") ||
3196 Name.starts_with(
"avx512.psubs.") ||
3197 Name.starts_with(
"avx512.mask.psubs.")) {
3199 }
else if (
Name.starts_with(
"sse2.paddus.") ||
3200 Name.starts_with(
"avx2.paddus.") ||
3201 Name.starts_with(
"avx512.mask.paddus.")) {
3203 }
else if (
Name.starts_with(
"sse2.psubus.") ||
3204 Name.starts_with(
"avx2.psubus.") ||
3205 Name.starts_with(
"avx512.mask.psubus.")) {
3207 }
else if (
Name.starts_with(
"avx512.mask.palignr.")) {
3212 }
else if (
Name.starts_with(
"avx512.mask.valign.")) {
3216 }
else if (
Name ==
"sse2.psll.dq" ||
Name ==
"avx2.psll.dq") {
3218 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3221 }
else if (
Name ==
"sse2.psrl.dq" ||
Name ==
"avx2.psrl.dq") {
3223 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3226 }
else if (
Name ==
"sse2.psll.dq.bs" ||
Name ==
"avx2.psll.dq.bs" ||
3227 Name ==
"avx512.psll.dq.512") {
3229 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3231 }
else if (
Name ==
"sse2.psrl.dq.bs" ||
Name ==
"avx2.psrl.dq.bs" ||
3232 Name ==
"avx512.psrl.dq.512") {
3234 unsigned Shift = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3236 }
else if (
Name ==
"sse41.pblendw" ||
Name.starts_with(
"sse41.blendp") ||
3237 Name.starts_with(
"avx.blend.p") ||
Name ==
"avx2.pblendw" ||
3238 Name.starts_with(
"avx2.pblendd.")) {
3241 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3242 auto *VecTy = cast<FixedVectorType>(CI->
getType());
3243 unsigned NumElts = VecTy->getNumElements();
3246 for (
unsigned i = 0; i != NumElts; ++i)
3247 Idxs[i] = ((Imm >> (i % 8)) & 1) ? i + NumElts : i;
3250 }
else if (
Name.starts_with(
"avx.vinsertf128.") ||
3251 Name ==
"avx2.vinserti128" ||
3252 Name.starts_with(
"avx512.mask.insert")) {
3255 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3256 unsigned DstNumElts =
3257 cast<FixedVectorType>(CI->
getType())->getNumElements();
3258 unsigned SrcNumElts =
3259 cast<FixedVectorType>(Op1->
getType())->getNumElements();
3260 unsigned Scale = DstNumElts / SrcNumElts;
3267 for (
unsigned i = 0; i != SrcNumElts; ++i)
3269 for (
unsigned i = SrcNumElts; i != DstNumElts; ++i)
3270 Idxs[i] = SrcNumElts;
3285 for (
unsigned i = 0; i != DstNumElts; ++i)
3288 for (
unsigned i = 0; i != SrcNumElts; ++i)
3289 Idxs[i + Imm * SrcNumElts] = i + DstNumElts;
3296 }
else if (
Name.starts_with(
"avx.vextractf128.") ||
3297 Name ==
"avx2.vextracti128" ||
3298 Name.starts_with(
"avx512.mask.vextract")) {
3300 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3301 unsigned DstNumElts =
3302 cast<FixedVectorType>(CI->
getType())->getNumElements();
3303 unsigned SrcNumElts =
3304 cast<FixedVectorType>(Op0->
getType())->getNumElements();
3305 unsigned Scale = SrcNumElts / DstNumElts;
3312 for (
unsigned i = 0; i != DstNumElts; ++i) {
3313 Idxs[i] = i + (Imm * DstNumElts);
3321 }
else if (
Name.starts_with(
"avx512.mask.perm.df.") ||
3322 Name.starts_with(
"avx512.mask.perm.di.")) {
3324 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3325 auto *VecTy = cast<FixedVectorType>(CI->
getType());
3326 unsigned NumElts = VecTy->getNumElements();
3329 for (
unsigned i = 0; i != NumElts; ++i)
3330 Idxs[i] = (i & ~0x3) + ((Imm >> (2 * (i & 0x3))) & 3);
3337 }
else if (
Name.starts_with(
"avx.vperm2f128.") ||
Name ==
"avx2.vperm2i128") {
3348 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3349 unsigned HalfSize = NumElts / 2;
3361 unsigned StartIndex = (Imm & 0x01) ? HalfSize : 0;
3362 for (
unsigned i = 0; i < HalfSize; ++i)
3363 ShuffleMask[i] = StartIndex + i;
3366 StartIndex = (Imm & 0x10) ? HalfSize : 0;
3367 for (
unsigned i = 0; i < HalfSize; ++i)
3368 ShuffleMask[i + HalfSize] = NumElts + StartIndex + i;
3372 }
else if (
Name.starts_with(
"avx.vpermil.") ||
Name ==
"sse2.pshuf.d" ||
3373 Name.starts_with(
"avx512.mask.vpermil.p") ||
3374 Name.starts_with(
"avx512.mask.pshuf.d.")) {
3376 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3377 auto *VecTy = cast<FixedVectorType>(CI->
getType());
3378 unsigned NumElts = VecTy->getNumElements();
3380 unsigned IdxSize = 64 / VecTy->getScalarSizeInBits();
3381 unsigned IdxMask = ((1 << IdxSize) - 1);
3387 for (
unsigned i = 0; i != NumElts; ++i)
3388 Idxs[i] = ((Imm >> ((i * IdxSize) % 8)) & IdxMask) | (i & ~IdxMask);
3395 }
else if (
Name ==
"sse2.pshufl.w" ||
3396 Name.starts_with(
"avx512.mask.pshufl.w.")) {
3398 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3399 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3402 for (
unsigned l = 0; l != NumElts; l += 8) {
3403 for (
unsigned i = 0; i != 4; ++i)
3404 Idxs[i + l] = ((Imm >> (2 * i)) & 0x3) + l;
3405 for (
unsigned i = 4; i != 8; ++i)
3406 Idxs[i + l] = i + l;
3414 }
else if (
Name ==
"sse2.pshufh.w" ||
3415 Name.starts_with(
"avx512.mask.pshufh.w.")) {
3417 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
3418 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3421 for (
unsigned l = 0; l != NumElts; l += 8) {
3422 for (
unsigned i = 0; i != 4; ++i)
3423 Idxs[i + l] = i + l;
3424 for (
unsigned i = 0; i != 4; ++i)
3425 Idxs[i + l + 4] = ((Imm >> (2 * i)) & 0x3) + 4 + l;
3433 }
else if (
Name.starts_with(
"avx512.mask.shuf.p")) {
3436 unsigned Imm = cast<ConstantInt>(CI->
getArgOperand(2))->getZExtValue();
3437 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3440 unsigned HalfLaneElts = NumLaneElts / 2;
3443 for (
unsigned i = 0; i != NumElts; ++i) {
3445 Idxs[i] = i - (i % NumLaneElts);
3447 if ((i % NumLaneElts) >= HalfLaneElts)
3451 Idxs[i] += (Imm >> ((i * HalfLaneElts) % 8)) & ((1 << HalfLaneElts) - 1);
3458 }
else if (
Name.starts_with(
"avx512.mask.movddup") ||
3459 Name.starts_with(
"avx512.mask.movshdup") ||
3460 Name.starts_with(
"avx512.mask.movsldup")) {
3462 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3466 if (
Name.starts_with(
"avx512.mask.movshdup."))
3470 for (
unsigned l = 0; l != NumElts; l += NumLaneElts)
3471 for (
unsigned i = 0; i != NumLaneElts; i += 2) {
3472 Idxs[i + l + 0] = i + l +
Offset;
3473 Idxs[i + l + 1] = i + l +
Offset;
3480 }
else if (
Name.starts_with(
"avx512.mask.punpckl") ||
3481 Name.starts_with(
"avx512.mask.unpckl.")) {
3484 int NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3488 for (
int l = 0; l != NumElts; l += NumLaneElts)
3489 for (
int i = 0; i != NumLaneElts; ++i)
3490 Idxs[i + l] = l + (i / 2) + NumElts * (i % 2);
3496 }
else if (
Name.starts_with(
"avx512.mask.punpckh") ||
3497 Name.starts_with(
"avx512.mask.unpckh.")) {
3500 int NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
3504 for (
int l = 0; l != NumElts; l += NumLaneElts)
3505 for (
int i = 0; i != NumLaneElts; ++i)
3506 Idxs[i + l] = (NumLaneElts / 2) + l + (i / 2) + NumElts * (i % 2);
3512 }
else if (
Name.starts_with(
"avx512.mask.and.") ||
3513 Name.starts_with(
"avx512.mask.pand.")) {
3515 VectorType *ITy = VectorType::getInteger(FTy);
3521 }
else if (
Name.starts_with(
"avx512.mask.andn.") ||
3522 Name.starts_with(
"avx512.mask.pandn.")) {
3524 VectorType *ITy = VectorType::getInteger(FTy);
3531 }
else if (
Name.starts_with(
"avx512.mask.or.") ||
3532 Name.starts_with(
"avx512.mask.por.")) {
3534 VectorType *ITy = VectorType::getInteger(FTy);
3540 }
else if (
Name.starts_with(
"avx512.mask.xor.") ||
3541 Name.starts_with(
"avx512.mask.pxor.")) {
3543 VectorType *ITy = VectorType::getInteger(FTy);
3549 }
else if (
Name.starts_with(
"avx512.mask.padd.")) {
3553 }
else if (
Name.starts_with(
"avx512.mask.psub.")) {
3557 }
else if (
Name.starts_with(
"avx512.mask.pmull.")) {
3561 }
else if (
Name.starts_with(
"avx512.mask.add.p")) {
3562 if (
Name.ends_with(
".512")) {
3564 if (
Name[17] ==
's')
3565 IID = Intrinsic::x86_avx512_add_ps_512;
3567 IID = Intrinsic::x86_avx512_add_pd_512;
3577 }
else if (
Name.starts_with(
"avx512.mask.div.p")) {
3578 if (
Name.ends_with(
".512")) {
3580 if (
Name[17] ==
's')
3581 IID = Intrinsic::x86_avx512_div_ps_512;
3583 IID = Intrinsic::x86_avx512_div_pd_512;
3593 }
else if (
Name.starts_with(
"avx512.mask.mul.p")) {
3594 if (
Name.ends_with(
".512")) {
3596 if (
Name[17] ==
's')
3597 IID = Intrinsic::x86_avx512_mul_ps_512;
3599 IID = Intrinsic::x86_avx512_mul_pd_512;
3609 }
else if (
Name.starts_with(
"avx512.mask.sub.p")) {
3610 if (
Name.ends_with(
".512")) {
3612 if (
Name[17] ==
's')
3613 IID = Intrinsic::x86_avx512_sub_ps_512;
3615 IID = Intrinsic::x86_avx512_sub_pd_512;
3625 }
else if ((
Name.starts_with(
"avx512.mask.max.p") ||
3626 Name.starts_with(
"avx512.mask.min.p")) &&
3627 Name.drop_front(18) ==
".512") {
3628 bool IsDouble =
Name[17] ==
'd';
3629 bool IsMin =
Name[13] ==
'i';
3631 {Intrinsic::x86_avx512_max_ps_512, Intrinsic::x86_avx512_max_pd_512},
3632 {Intrinsic::x86_avx512_min_ps_512, Intrinsic::x86_avx512_min_pd_512}};
3640 }
else if (
Name.starts_with(
"avx512.mask.lzcnt.")) {
3643 {CI->getArgOperand(0), Builder.getInt1(false)});
3646 }
else if (
Name.starts_with(
"avx512.mask.psll")) {
3647 bool IsImmediate =
Name[16] ==
'i' || (
Name.size() > 18 &&
Name[18] ==
'i');
3648 bool IsVariable =
Name[16] ==
'v';
3655 if (IsVariable &&
Name[17] !=
'.') {
3656 if (
Size ==
'd' &&
Name[17] ==
'2')
3657 IID = Intrinsic::x86_avx2_psllv_q;
3658 else if (
Size ==
'd' &&
Name[17] ==
'4')
3659 IID = Intrinsic::x86_avx2_psllv_q_256;
3660 else if (
Size ==
's' &&
Name[17] ==
'4')
3661 IID = Intrinsic::x86_avx2_psllv_d;
3662 else if (
Size ==
's' &&
Name[17] ==
'8')
3663 IID = Intrinsic::x86_avx2_psllv_d_256;
3664 else if (
Size ==
'h' &&
Name[17] ==
'8')
3665 IID = Intrinsic::x86_avx512_psllv_w_128;
3666 else if (
Size ==
'h' &&
Name[17] ==
'1')
3667 IID = Intrinsic::x86_avx512_psllv_w_256;
3668 else if (
Name[17] ==
'3' &&
Name[18] ==
'2')
3669 IID = Intrinsic::x86_avx512_psllv_w_512;
3672 }
else if (
Name.ends_with(
".128")) {
3674 IID = IsImmediate ? Intrinsic::x86_sse2_pslli_d
3675 : Intrinsic::x86_sse2_psll_d;
3676 else if (
Size ==
'q')
3677 IID = IsImmediate ? Intrinsic::x86_sse2_pslli_q
3678 : Intrinsic::x86_sse2_psll_q;
3679 else if (
Size ==
'w')
3680 IID = IsImmediate ? Intrinsic::x86_sse2_pslli_w
3681 : Intrinsic::x86_sse2_psll_w;
3684 }
else if (
Name.ends_with(
".256")) {
3686 IID = IsImmediate ? Intrinsic::x86_avx2_pslli_d
3687 : Intrinsic::x86_avx2_psll_d;
3688 else if (
Size ==
'q')
3689 IID = IsImmediate ? Intrinsic::x86_avx2_pslli_q
3690 : Intrinsic::x86_avx2_psll_q;
3691 else if (
Size ==
'w')
3692 IID = IsImmediate ? Intrinsic::x86_avx2_pslli_w
3693 : Intrinsic::x86_avx2_psll_w;
3698 IID = IsImmediate ? Intrinsic::x86_avx512_pslli_d_512
3699 : IsVariable ? Intrinsic::x86_avx512_psllv_d_512
3700 : Intrinsic::x86_avx512_psll_d_512;
3701 else if (
Size ==
'q')
3702 IID = IsImmediate ? Intrinsic::x86_avx512_pslli_q_512
3703 : IsVariable ? Intrinsic::x86_avx512_psllv_q_512
3704 : Intrinsic::x86_avx512_psll_q_512;
3705 else if (
Size ==
'w')
3706 IID = IsImmediate ? Intrinsic::x86_avx512_pslli_w_512
3707 : Intrinsic::x86_avx512_psll_w_512;
3713 }
else if (
Name.starts_with(
"avx512.mask.psrl")) {
3714 bool IsImmediate =
Name[16] ==
'i' || (
Name.size() > 18 &&
Name[18] ==
'i');
3715 bool IsVariable =
Name[16] ==
'v';
3722 if (IsVariable &&
Name[17] !=
'.') {
3723 if (
Size ==
'd' &&
Name[17] ==
'2')
3724 IID = Intrinsic::x86_avx2_psrlv_q;
3725 else if (
Size ==
'd' &&
Name[17] ==
'4')
3726 IID = Intrinsic::x86_avx2_psrlv_q_256;
3727 else if (
Size ==
's' &&
Name[17] ==
'4')
3728 IID = Intrinsic::x86_avx2_psrlv_d;
3729 else if (
Size ==
's' &&
Name[17] ==
'8')
3730 IID = Intrinsic::x86_avx2_psrlv_d_256;
3731 else if (
Size ==
'h' &&
Name[17] ==
'8')
3732 IID = Intrinsic::x86_avx512_psrlv_w_128;
3733 else if (
Size ==
'h' &&
Name[17] ==
'1')
3734 IID = Intrinsic::x86_avx512_psrlv_w_256;
3735 else if (
Name[17] ==
'3' &&
Name[18] ==
'2')
3736 IID = Intrinsic::x86_avx512_psrlv_w_512;
3739 }
else if (
Name.ends_with(
".128")) {
3741 IID = IsImmediate ? Intrinsic::x86_sse2_psrli_d
3742 : Intrinsic::x86_sse2_psrl_d;
3743 else if (
Size ==
'q')
3744 IID = IsImmediate ? Intrinsic::x86_sse2_psrli_q
3745 : Intrinsic::x86_sse2_psrl_q;
3746 else if (
Size ==
'w')
3747 IID = IsImmediate ? Intrinsic::x86_sse2_psrli_w
3748 : Intrinsic::x86_sse2_psrl_w;
3751 }
else if (
Name.ends_with(
".256")) {
3753 IID = IsImmediate ? Intrinsic::x86_avx2_psrli_d
3754 : Intrinsic::x86_avx2_psrl_d;
3755 else if (
Size ==
'q')
3756 IID = IsImmediate ? Intrinsic::x86_avx2_psrli_q
3757 : Intrinsic::x86_avx2_psrl_q;
3758 else if (
Size ==
'w')
3759 IID = IsImmediate ? Intrinsic::x86_avx2_psrli_w
3760 : Intrinsic::x86_avx2_psrl_w;
3765 IID = IsImmediate ? Intrinsic::x86_avx512_psrli_d_512
3766 : IsVariable ? Intrinsic::x86_avx512_psrlv_d_512
3767 : Intrinsic::x86_avx512_psrl_d_512;
3768 else if (
Size ==
'q')
3769 IID = IsImmediate ? Intrinsic::x86_avx512_psrli_q_512
3770 : IsVariable ? Intrinsic::x86_avx512_psrlv_q_512
3771 : Intrinsic::x86_avx512_psrl_q_512;
3772 else if (
Size ==
'w')
3773 IID = IsImmediate ? Intrinsic::x86_avx512_psrli_w_512
3774 : Intrinsic::x86_avx512_psrl_w_512;
3780 }
else if (
Name.starts_with(
"avx512.mask.psra")) {
3781 bool IsImmediate =
Name[16] ==
'i' || (
Name.size() > 18 &&
Name[18] ==
'i');
3782 bool IsVariable =
Name[16] ==
'v';
3789 if (IsVariable &&
Name[17] !=
'.') {
3790 if (
Size ==
's' &&
Name[17] ==
'4')
3791 IID = Intrinsic::x86_avx2_psrav_d;
3792 else if (
Size ==
's' &&
Name[17] ==
'8')
3793 IID = Intrinsic::x86_avx2_psrav_d_256;
3794 else if (
Size ==
'h' &&
Name[17] ==
'8')
3795 IID = Intrinsic::x86_avx512_psrav_w_128;
3796 else if (
Size ==
'h' &&
Name[17] ==
'1')
3797 IID = Intrinsic::x86_avx512_psrav_w_256;
3798 else if (
Name[17] ==
'3' &&
Name[18] ==
'2')
3799 IID = Intrinsic::x86_avx512_psrav_w_512;
3802 }
else if (
Name.ends_with(
".128")) {
3804 IID = IsImmediate ? Intrinsic::x86_sse2_psrai_d
3805 : Intrinsic::x86_sse2_psra_d;
3806 else if (
Size ==
'q')
3807 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_q_128
3808 : IsVariable ? Intrinsic::x86_avx512_psrav_q_128
3809 : Intrinsic::x86_avx512_psra_q_128;
3810 else if (
Size ==
'w')
3811 IID = IsImmediate ? Intrinsic::x86_sse2_psrai_w
3812 : Intrinsic::x86_sse2_psra_w;
3815 }
else if (
Name.ends_with(
".256")) {
3817 IID = IsImmediate ? Intrinsic::x86_avx2_psrai_d
3818 : Intrinsic::x86_avx2_psra_d;
3819 else if (
Size ==
'q')
3820 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_q_256
3821 : IsVariable ? Intrinsic::x86_avx512_psrav_q_256
3822 : Intrinsic::x86_avx512_psra_q_256;
3823 else if (
Size ==
'w')
3824 IID = IsImmediate ? Intrinsic::x86_avx2_psrai_w
3825 : Intrinsic::x86_avx2_psra_w;
3830 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_d_512
3831 : IsVariable ? Intrinsic::x86_avx512_psrav_d_512
3832 : Intrinsic::x86_avx512_psra_d_512;
3833 else if (
Size ==
'q')
3834 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_q_512
3835 : IsVariable ? Intrinsic::x86_avx512_psrav_q_512
3836 : Intrinsic::x86_avx512_psra_q_512;
3837 else if (
Size ==
'w')
3838 IID = IsImmediate ? Intrinsic::x86_avx512_psrai_w_512
3839 : Intrinsic::x86_avx512_psra_w_512;
3845 }
else if (
Name.starts_with(
"avx512.mask.move.s")) {
3847 }
else if (
Name.starts_with(
"avx512.cvtmask2")) {
3849 }
else if (
Name.ends_with(
".movntdqa")) {
3858 }
else if (
Name.starts_with(
"fma.vfmadd.") ||
3859 Name.starts_with(
"fma.vfmsub.") ||
3860 Name.starts_with(
"fma.vfnmadd.") ||
3861 Name.starts_with(
"fma.vfnmsub.")) {
3862 bool NegMul =
Name[6] ==
'n';
3863 bool NegAcc = NegMul ?
Name[8] ==
's' :
Name[7] ==
's';
3864 bool IsScalar = NegMul ?
Name[12] ==
's' :
Name[11] ==
's';
3875 if (NegMul && !IsScalar)
3877 if (NegMul && IsScalar)
3886 }
else if (
Name.starts_with(
"fma4.vfmadd.s")) {
3898 }
else if (
Name.starts_with(
"avx512.mask.vfmadd.s") ||
3899 Name.starts_with(
"avx512.maskz.vfmadd.s") ||
3900 Name.starts_with(
"avx512.mask3.vfmadd.s") ||
3901 Name.starts_with(
"avx512.mask3.vfmsub.s") ||
3902 Name.starts_with(
"avx512.mask3.vfnmsub.s")) {
3903 bool IsMask3 =
Name[11] ==
'3';
3904 bool IsMaskZ =
Name[11] ==
'z';
3906 Name =
Name.drop_front(IsMask3 || IsMaskZ ? 13 : 12);
3907 bool NegMul =
Name[2] ==
'n';
3908 bool NegAcc = NegMul ?
Name[4] ==
's' :
Name[3] ==
's';
3914 if (NegMul && (IsMask3 || IsMaskZ))
3916 if (NegMul && !(IsMask3 || IsMaskZ))
3926 cast<ConstantInt>(CI->
getArgOperand(4))->getZExtValue() != 4) {
3930 if (
Name.back() ==
'd')
3931 IID = Intrinsic::x86_avx512_vfmadd_f64;
3933 IID = Intrinsic::x86_avx512_vfmadd_f32;
3945 if (NegAcc && IsMask3)
3952 }
else if (
Name.starts_with(
"avx512.mask.vfmadd.p") ||
3953 Name.starts_with(
"avx512.mask.vfnmadd.p") ||
3954 Name.starts_with(
"avx512.mask.vfnmsub.p") ||
3955 Name.starts_with(
"avx512.mask3.vfmadd.p") ||
3956 Name.starts_with(
"avx512.mask3.vfmsub.p") ||
3957 Name.starts_with(
"avx512.mask3.vfnmsub.p") ||
3958 Name.starts_with(
"avx512.maskz.vfmadd.p")) {
3959 bool IsMask3 =
Name[11] ==
'3';
3960 bool IsMaskZ =
Name[11] ==
'z';
3962 Name =
Name.drop_front(IsMask3 || IsMaskZ ? 13 : 12);
3963 bool NegMul =
Name[2] ==
'n';
3964 bool NegAcc = NegMul ?
Name[4] ==
's' :
Name[3] ==
's';
3970 if (NegMul && (IsMask3 || IsMaskZ))
3972 if (NegMul && !(IsMask3 || IsMaskZ))
3979 cast<ConstantInt>(CI->
getArgOperand(4))->getZExtValue() != 4)) {
3983 IID = Intrinsic::x86_avx512_vfmadd_ps_512;
3985 IID = Intrinsic::x86_avx512_vfmadd_pd_512;
3997 }
else if (
Name.starts_with(
"fma.vfmsubadd.p")) {
4001 if (VecWidth == 128 && EltWidth == 32)
4002 IID = Intrinsic::x86_fma_vfmaddsub_ps;
4003 else if (VecWidth == 256 && EltWidth == 32)
4004 IID = Intrinsic::x86_fma_vfmaddsub_ps_256;
4005 else if (VecWidth == 128 && EltWidth == 64)
4006 IID = Intrinsic::x86_fma_vfmaddsub_pd;
4007 else if (VecWidth == 256 && EltWidth == 64)
4008 IID = Intrinsic::x86_fma_vfmaddsub_pd_256;
4016 }
else if (
Name.starts_with(
"avx512.mask.vfmaddsub.p") ||
4017 Name.starts_with(
"avx512.mask3.vfmaddsub.p") ||
4018 Name.starts_with(
"avx512.maskz.vfmaddsub.p") ||
4019 Name.starts_with(
"avx512.mask3.vfmsubadd.p")) {
4020 bool IsMask3 =
Name[11] ==
'3';
4021 bool IsMaskZ =
Name[11] ==
'z';
4023 Name =
Name.drop_front(IsMask3 || IsMaskZ ? 13 : 12);
4024 bool IsSubAdd =
Name[3] ==
's';
4029 IID = Intrinsic::x86_avx512_vfmaddsub_ps_512;
4031 IID = Intrinsic::x86_avx512_vfmaddsub_pd_512;
4040 int NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
4055 for (
int i = 0; i != NumElts; ++i)
4056 Idxs[i] = i + (i % 2) * NumElts;
4066 }
else if (
Name.starts_with(
"avx512.mask.pternlog.") ||
4067 Name.starts_with(
"avx512.maskz.pternlog.")) {
4068 bool ZeroMask =
Name[11] ==
'z';
4072 if (VecWidth == 128 && EltWidth == 32)
4073 IID = Intrinsic::x86_avx512_pternlog_d_128;
4074 else if (VecWidth == 256 && EltWidth == 32)
4075 IID = Intrinsic::x86_avx512_pternlog_d_256;
4076 else if (VecWidth == 512 && EltWidth == 32)
4077 IID = Intrinsic::x86_avx512_pternlog_d_512;
4078 else if (VecWidth == 128 && EltWidth == 64)
4079 IID = Intrinsic::x86_avx512_pternlog_q_128;
4080 else if (VecWidth == 256 && EltWidth == 64)
4081 IID = Intrinsic::x86_avx512_pternlog_q_256;
4082 else if (VecWidth == 512 && EltWidth == 64)
4083 IID = Intrinsic::x86_avx512_pternlog_q_512;
4093 }
else if (
Name.starts_with(
"avx512.mask.vpmadd52") ||
4094 Name.starts_with(
"avx512.maskz.vpmadd52")) {
4095 bool ZeroMask =
Name[11] ==
'z';
4099 if (VecWidth == 128 && !
High)
4100 IID = Intrinsic::x86_avx512_vpmadd52l_uq_128;
4101 else if (VecWidth == 256 && !
High)
4102 IID = Intrinsic::x86_avx512_vpmadd52l_uq_256;
4103 else if (VecWidth == 512 && !
High)
4104 IID = Intrinsic::x86_avx512_vpmadd52l_uq_512;
4105 else if (VecWidth == 128 &&
High)
4106 IID = Intrinsic::x86_avx512_vpmadd52h_uq_128;
4107 else if (VecWidth == 256 &&
High)
4108 IID = Intrinsic::x86_avx512_vpmadd52h_uq_256;
4109 else if (VecWidth == 512 &&
High)
4110 IID = Intrinsic::x86_avx512_vpmadd52h_uq_512;
4120 }
else if (
Name.starts_with(
"avx512.mask.vpermi2var.") ||
4121 Name.starts_with(
"avx512.mask.vpermt2var.") ||
4122 Name.starts_with(
"avx512.maskz.vpermt2var.")) {
4123 bool ZeroMask =
Name[11] ==
'z';
4124 bool IndexForm =
Name[17] ==
'i';
4126 }
else if (
Name.starts_with(
"avx512.mask.vpdpbusd.") ||
4127 Name.starts_with(
"avx512.maskz.vpdpbusd.") ||
4128 Name.starts_with(
"avx512.mask.vpdpbusds.") ||
4129 Name.starts_with(
"avx512.maskz.vpdpbusds.")) {
4130 bool ZeroMask =
Name[11] ==
'z';
4131 bool IsSaturating =
Name[ZeroMask ? 21 : 20] ==
's';
4134 if (VecWidth == 128 && !IsSaturating)
4135 IID = Intrinsic::x86_avx512_vpdpbusd_128;
4136 else if (VecWidth == 256 && !IsSaturating)
4137 IID = Intrinsic::x86_avx512_vpdpbusd_256;
4138 else if (VecWidth == 512 && !IsSaturating)
4139 IID = Intrinsic::x86_avx512_vpdpbusd_512;
4140 else if (VecWidth == 128 && IsSaturating)
4141 IID = Intrinsic::x86_avx512_vpdpbusds_128;
4142 else if (VecWidth == 256 && IsSaturating)
4143 IID = Intrinsic::x86_avx512_vpdpbusds_256;
4144 else if (VecWidth == 512 && IsSaturating)
4145 IID = Intrinsic::x86_avx512_vpdpbusds_512;
4155 }
else if (
Name.starts_with(
"avx512.mask.vpdpwssd.") ||
4156 Name.starts_with(
"avx512.maskz.vpdpwssd.") ||
4157 Name.starts_with(
"avx512.mask.vpdpwssds.") ||
4158 Name.starts_with(
"avx512.maskz.vpdpwssds.")) {
4159 bool ZeroMask =
Name[11] ==
'z';
4160 bool IsSaturating =
Name[ZeroMask ? 21 : 20] ==
's';
4163 if (VecWidth == 128 && !IsSaturating)
4164 IID = Intrinsic::x86_avx512_vpdpwssd_128;
4165 else if (VecWidth == 256 && !IsSaturating)
4166 IID = Intrinsic::x86_avx512_vpdpwssd_256;
4167 else if (VecWidth == 512 && !IsSaturating)
4168 IID = Intrinsic::x86_avx512_vpdpwssd_512;
4169 else if (VecWidth == 128 && IsSaturating)
4170 IID = Intrinsic::x86_avx512_vpdpwssds_128;
4171 else if (VecWidth == 256 && IsSaturating)
4172 IID = Intrinsic::x86_avx512_vpdpwssds_256;
4173 else if (VecWidth == 512 && IsSaturating)
4174 IID = Intrinsic::x86_avx512_vpdpwssds_512;
4184 }
else if (
Name ==
"addcarryx.u32" ||
Name ==
"addcarryx.u64" ||
4185 Name ==
"addcarry.u32" ||
Name ==
"addcarry.u64" ||
4186 Name ==
"subborrow.u32" ||
Name ==
"subborrow.u64") {
4188 if (
Name[0] ==
'a' &&
Name.back() ==
'2')
4189 IID = Intrinsic::x86_addcarry_32;
4190 else if (
Name[0] ==
'a' &&
Name.back() ==
'4')
4191 IID = Intrinsic::x86_addcarry_64;
4192 else if (
Name[0] ==
's' &&
Name.back() ==
'2')
4193 IID = Intrinsic::x86_subborrow_32;
4194 else if (
Name[0] ==
's' &&
Name.back() ==
'4')
4195 IID = Intrinsic::x86_subborrow_64;
4212 }
else if (
Name.starts_with(
"avx512.mask.") &&
4222 if (
Name.starts_with(
"neon.bfcvt")) {
4223 if (
Name.starts_with(
"neon.bfcvtn2")) {
4225 std::iota(LoMask.
begin(), LoMask.
end(), 0);
4227 std::iota(ConcatMask.
begin(), ConcatMask.
end(), 0);
4232 }
else if (
Name.starts_with(
"neon.bfcvtn")) {
4234 std::iota(ConcatMask.
begin(), ConcatMask.
end(), 0);
4238 dbgs() <<
"Trunc: " << *Trunc <<
"\n";
4245 }
else if (
Name.starts_with(
"sve.fcvt")) {
4248 .
Case(
"sve.fcvt.bf16f32", Intrinsic::aarch64_sve_fcvt_bf16f32_v2)
4249 .
Case(
"sve.fcvtnt.bf16f32",
4250 Intrinsic::aarch64_sve_fcvtnt_bf16f32_v2)
4262 if (Args[1]->
getType() != BadPredTy)
4265 Args[1] = Builder.
CreateIntrinsic(Intrinsic::aarch64_sve_convert_to_svbool,
4266 BadPredTy, Args[1]);
4268 Intrinsic::aarch64_sve_convert_from_svbool, GoodPredTy, Args[1]);
4279 if (
Name ==
"mve.vctp64.old") {
4286 Intrinsic::arm_mve_pred_v2i,
4287 {VectorType::get(Builder.
getInt1Ty(), 2,
false)}, VCTP);
4289 Intrinsic::arm_mve_pred_i2v,
4290 {VectorType::get(Builder.
getInt1Ty(), 4,
false)}, C1);
4291 }
else if (
Name ==
"mve.mull.int.predicated.v2i64.v4i32.v4i1" ||
4292 Name ==
"mve.vqdmull.predicated.v2i64.v4i32.v4i1" ||
4293 Name ==
"mve.vldr.gather.base.predicated.v2i64.v2i64.v4i1" ||
4294 Name ==
"mve.vldr.gather.base.wb.predicated.v2i64.v2i64.v4i1" ||
4296 "mve.vldr.gather.offset.predicated.v2i64.p0i64.v2i64.v4i1" ||
4297 Name ==
"mve.vldr.gather.offset.predicated.v2i64.p0.v2i64.v4i1" ||
4298 Name ==
"mve.vstr.scatter.base.predicated.v2i64.v2i64.v4i1" ||
4299 Name ==
"mve.vstr.scatter.base.wb.predicated.v2i64.v2i64.v4i1" ||
4301 "mve.vstr.scatter.offset.predicated.p0i64.v2i64.v2i64.v4i1" ||
4302 Name ==
"mve.vstr.scatter.offset.predicated.p0.v2i64.v2i64.v4i1" ||
4303 Name ==
"cde.vcx1q.predicated.v2i64.v4i1" ||
4304 Name ==
"cde.vcx1qa.predicated.v2i64.v4i1" ||
4305 Name ==
"cde.vcx2q.predicated.v2i64.v4i1" ||
4306 Name ==
"cde.vcx2qa.predicated.v2i64.v4i1" ||
4307 Name ==
"cde.vcx3q.predicated.v2i64.v4i1" ||
4308 Name ==
"cde.vcx3qa.predicated.v2i64.v4i1") {
4309 std::vector<Type *> Tys;
4313 case Intrinsic::arm_mve_mull_int_predicated:
4314 case Intrinsic::arm_mve_vqdmull_predicated:
4315 case Intrinsic::arm_mve_vldr_gather_base_predicated:
4318 case Intrinsic::arm_mve_vldr_gather_base_wb_predicated:
4319 case Intrinsic::arm_mve_vstr_scatter_base_predicated:
4320 case Intrinsic::arm_mve_vstr_scatter_base_wb_predicated:
4324 case Intrinsic::arm_mve_vldr_gather_offset_predicated:
4328 case Intrinsic::arm_mve_vstr_scatter_offset_predicated:
4332 case Intrinsic::arm_cde_vcx1q_predicated:
4333 case Intrinsic::arm_cde_vcx1qa_predicated:
4334 case Intrinsic::arm_cde_vcx2q_predicated:
4335 case Intrinsic::arm_cde_vcx2qa_predicated:
4336 case Intrinsic::arm_cde_vcx3q_predicated:
4337 case Intrinsic::arm_cde_vcx3qa_predicated:
4344 std::vector<Value *> Ops;
4346 Type *Ty =
Op->getType();
4349 Intrinsic::arm_mve_pred_v2i,
4350 {VectorType::get(Builder.
getInt1Ty(), 4,
false)},
Op);
4384 if (NumOperands < 3)
4397 bool IsVolatile =
false;
4401 if (NumOperands > 3)
4406 if (NumOperands > 5) {
4408 IsVolatile = !VolatileArg || !VolatileArg->
isZero();
4414 if (Order == AtomicOrdering::NotAtomic || Order == AtomicOrdering::Unordered)
4415 Order = AtomicOrdering::SequentiallyConsistent;
4422 if (VT->getElementType()->isIntegerTy(16)) {
4435 unsigned AddrSpace = PtrTy->getAddressSpace();
4438 RMW->
setMetadata(
"amdgpu.no.fine.grained.memory", EmptyMD);
4440 RMW->
setMetadata(
"amdgpu.ignore.denormal.mode", EmptyMD);
4445 MDNode *RangeNotPrivate =
4448 RMW->
setMetadata(LLVMContext::MD_noalias_addrspace, RangeNotPrivate);
4461 if (Op < CI->arg_size()) {
4465 return dyn_cast_if_present<MDNode>(MD);
4473 if (Op < CI->arg_size())
4475 return MAV->getMetadata();
4482 return I->getDebugLoc().getAsMDNode();
4490 if (
Name ==
"label") {
4493 }
else if (
Name ==
"assign") {
4500 }
else if (
Name ==
"declare") {
4505 }
else if (
Name ==
"addr") {
4510 if (
DIExpression *Expr = dyn_cast<DIExpression>(ExprNode)) {
4515 unwrapMAVOp(CI, 1), ExprNode,
nullptr,
nullptr,
nullptr,
4517 }
else if (
Name ==
"value") {
4520 unsigned ExprOp = 2;
4534 assert(DR &&
"Unhandled intrinsic kind in upgrade to DbgRecord");
4556 assert(
Name.starts_with(
"llvm.") &&
"Intrinsic doesn't start with 'llvm.'");
4559 bool IsX86 =
Name.consume_front(
"x86.");
4560 bool IsNVVM =
Name.consume_front(
"nvvm.");
4561 bool IsAArch64 =
Name.consume_front(
"aarch64.");
4562 bool IsARM =
Name.consume_front(
"arm.");
4563 bool IsAMDGCN =
Name.consume_front(
"amdgcn.");
4564 bool IsDbg =
Name.consume_front(
"dbg.");
4565 Value *Rep =
nullptr;
4567 if (!IsX86 &&
Name ==
"stackprotectorcheck") {
4569 }
else if (IsNVVM) {
4573 }
else if (IsAArch64) {
4577 }
else if (IsAMDGCN) {
4591 const auto &DefaultCase = [&]() ->
void {
4599 "Unknown function for CallBase upgrade and isn't just a name change");
4605 if (
auto *OldST = dyn_cast<StructType>(CI->
getType())) {
4607 "Return type must have changed");
4608 assert(OldST->getNumElements() ==
4609 cast<StructType>(NewFn->
getReturnType())->getNumElements() &&
4610 "Must have same number of elements");
4616 for (
unsigned Idx = 0;
Idx < OldST->getNumElements(); ++
Idx) {
4637 case Intrinsic::arm_neon_vst1:
4638 case Intrinsic::arm_neon_vst2:
4639 case Intrinsic::arm_neon_vst3:
4640 case Intrinsic::arm_neon_vst4:
4641 case Intrinsic::arm_neon_vst2lane:
4642 case Intrinsic::arm_neon_vst3lane:
4643 case Intrinsic::arm_neon_vst4lane: {
4648 case Intrinsic::aarch64_sve_bfmlalb_lane_v2:
4649 case Intrinsic::aarch64_sve_bfmlalt_lane_v2:
4650 case Intrinsic::aarch64_sve_bfdot_lane_v2: {
4654 cast<ConstantInt>(Args[3])->getZExtValue());
4658 case Intrinsic::aarch64_sve_ld3_sret:
4659 case Intrinsic::aarch64_sve_ld4_sret:
4660 case Intrinsic::aarch64_sve_ld2_sret: {
4668 auto *
RetTy = cast<ScalableVectorType>(
F->getReturnType());
4669 unsigned MinElts =
RetTy->getMinNumElements() /
N;
4673 for (
unsigned I = 0;
I <
N;
I++) {
4677 NewCall = dyn_cast<CallInst>(Ret);
4681 case Intrinsic::coro_end: {
4688 case Intrinsic::vector_extract: {
4691 if (!
Name.starts_with(
"aarch64.sve.tuple.get")) {
4695 auto *
RetTy = cast<ScalableVectorType>(
F->getReturnType());
4696 unsigned MinElts =
RetTy->getMinNumElements();
4697 unsigned I = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
4703 case Intrinsic::vector_insert: {
4706 if (!
Name.starts_with(
"aarch64.sve.tuple")) {
4710 if (
Name.starts_with(
"aarch64.sve.tuple.set")) {
4711 unsigned I = cast<ConstantInt>(CI->
getArgOperand(1))->getZExtValue();
4719 if (
Name.starts_with(
"aarch64.sve.tuple.create")) {
4725 assert(
N > 1 &&
"Create is expected to be between 2-4");
4726 auto *
RetTy = cast<ScalableVectorType>(
F->getReturnType());
4728 unsigned MinElts =
RetTy->getMinNumElements() /
N;
4729 for (
unsigned I = 0;
I <
N;
I++) {
4733 NewCall = dyn_cast<CallInst>(Ret);
4738 case Intrinsic::arm_neon_bfdot:
4739 case Intrinsic::arm_neon_bfmmla:
4740 case Intrinsic::arm_neon_bfmlalb:
4741 case Intrinsic::arm_neon_bfmlalt:
4742 case Intrinsic::aarch64_neon_bfdot:
4743 case Intrinsic::aarch64_neon_bfmmla:
4744 case Intrinsic::aarch64_neon_bfmlalb:
4745 case Intrinsic::aarch64_neon_bfmlalt: {
4748 "Mismatch between function args and call args");
4749 size_t OperandWidth =
4751 assert((OperandWidth == 64 || OperandWidth == 128) &&
4752 "Unexpected operand width");
4754 auto Iter = CI->
args().begin();
4755 Args.push_back(*Iter++);
4762 case Intrinsic::bitreverse:
4766 case Intrinsic::ctlz:
4767 case Intrinsic::cttz:
4769 "Mismatch between function args and call args");
4774 case Intrinsic::objectsize: {
4775 Value *NullIsUnknownSize =
4784 case Intrinsic::ctpop:
4788 case Intrinsic::convert_from_fp16:
4792 case Intrinsic::dbg_value: {
4796 if (
Name.starts_with(
"dbg.addr")) {
4798 cast<MetadataAsValue>(CI->
getArgOperand(2))->getMetadata());
4810 if (
Offset->isZeroValue()) {
4820 case Intrinsic::ptr_annotation:
4837 case Intrinsic::var_annotation:
4853 case Intrinsic::riscv_aes32dsi:
4854 case Intrinsic::riscv_aes32dsmi:
4855 case Intrinsic::riscv_aes32esi:
4856 case Intrinsic::riscv_aes32esmi:
4857 case Intrinsic::riscv_sm4ks:
4858 case Intrinsic::riscv_sm4ed: {
4873 cast<ConstantInt>(Arg2)->getZExtValue());
4875 NewCall = Builder.
CreateCall(NewFn, {Arg0, Arg1, Arg2});
4876 Value *Res = NewCall;
4884 case Intrinsic::nvvm_mapa_shared_cluster: {
4888 Value *Res = NewCall;
4896 case Intrinsic::nvvm_cp_async_bulk_global_to_shared_cluster:
4897 case Intrinsic::nvvm_cp_async_bulk_shared_cta_to_cluster: {
4909 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_im2col_3d:
4910 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_im2col_4d:
4911 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_im2col_5d:
4912 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_1d:
4913 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_2d:
4914 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_3d:
4915 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_4d:
4916 case Intrinsic::nvvm_cp_async_bulk_tensor_g2s_tile_5d: {
4932 Args.push_back(ConstantInt::get(Builder.
getInt32Ty(), 0));
4940 case Intrinsic::riscv_sha256sig0:
4941 case Intrinsic::riscv_sha256sig1:
4942 case Intrinsic::riscv_sha256sum0:
4943 case Intrinsic::riscv_sha256sum1:
4944 case Intrinsic::riscv_sm3p0:
4945 case Intrinsic::riscv_sm3p1: {
4963 case Intrinsic::x86_xop_vfrcz_ss:
4964 case Intrinsic::x86_xop_vfrcz_sd:
4968 case Intrinsic::x86_xop_vpermil2pd:
4969 case Intrinsic::x86_xop_vpermil2ps:
4970 case Intrinsic::x86_xop_vpermil2pd_256:
4971 case Intrinsic::x86_xop_vpermil2ps_256: {
4974 VectorType *IntIdxTy = VectorType::getInteger(FltIdxTy);
4980 case Intrinsic::x86_sse41_ptestc:
4981 case Intrinsic::x86_sse41_ptestz:
4982 case Intrinsic::x86_sse41_ptestnzc: {
4999 NewCall = Builder.
CreateCall(NewFn, {BC0, BC1});
5003 case Intrinsic::x86_rdtscp: {
5022 case Intrinsic::x86_sse41_insertps:
5023 case Intrinsic::x86_sse41_dppd:
5024 case Intrinsic::x86_sse41_dpps:
5025 case Intrinsic::x86_sse41_mpsadbw:
5026 case Intrinsic::x86_avx_dp_ps_256:
5027 case Intrinsic::x86_avx2_mpsadbw: {
5038 case Intrinsic::x86_avx512_mask_cmp_pd_128:
5039 case Intrinsic::x86_avx512_mask_cmp_pd_256:
5040 case Intrinsic::x86_avx512_mask_cmp_pd_512:
5041 case Intrinsic::x86_avx512_mask_cmp_ps_128:
5042 case Intrinsic::x86_avx512_mask_cmp_ps_256:
5043 case Intrinsic::x86_avx512_mask_cmp_ps_512: {
5046 cast<FixedVectorType>(Args[0]->
getType())->getNumElements();
5058 case Intrinsic::x86_avx512bf16_cvtne2ps2bf16_128:
5059 case Intrinsic::x86_avx512bf16_cvtne2ps2bf16_256:
5060 case Intrinsic::x86_avx512bf16_cvtne2ps2bf16_512:
5061 case Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128:
5062 case Intrinsic::x86_avx512bf16_cvtneps2bf16_256:
5063 case Intrinsic::x86_avx512bf16_cvtneps2bf16_512: {
5065 unsigned NumElts = cast<FixedVectorType>(CI->
getType())->getNumElements();
5067 Intrinsic::x86_avx512bf16_mask_cvtneps2bf16_128)
5080 case Intrinsic::x86_avx512bf16_dpbf16ps_128:
5081 case Intrinsic::x86_avx512bf16_dpbf16ps_256:
5082 case Intrinsic::x86_avx512bf16_dpbf16ps_512:{
5085 cast<FixedVectorType>(CI->
getType())->getNumElements() * 2;
5095 case Intrinsic::thread_pointer: {
5100 case Intrinsic::memcpy:
5101 case Intrinsic::memmove:
5102 case Intrinsic::memset: {
5122 {OldAttrs.getParamAttrs(0), OldAttrs.getParamAttrs(1),
5123 OldAttrs.getParamAttrs(2), OldAttrs.getParamAttrs(4)});
5125 auto *MemCI = cast<MemIntrinsic>(NewCall);
5128 MemCI->setDestAlignment(
Align->getMaybeAlignValue());
5130 if (
auto *MTI = dyn_cast<MemTransferInst>(MemCI))
5131 MTI->setSourceAlignment(
Align->getMaybeAlignValue());
5135 case Intrinsic::lifetime_start:
5136 case Intrinsic::lifetime_end: {
5144 Ptr =
Ptr->stripPointerCasts();
5145 if (isa<AllocaInst>(
Ptr)) {
5159 assert(NewCall &&
"Should have either set this variable or returned through "
5160 "the default case");
5167 assert(
F &&
"Illegal attempt to upgrade a non-existent intrinsic.");
5176 if (
CallBase *CB = dyn_cast<CallBase>(U))
5181 F->eraseFromParent();
5187 if (NumOperands == 0)
5191 if (isa<MDNode>(MD.
getOperand(0)) && NumOperands >= 3)
5195 if (NumOperands == 3) {
5199 Metadata *Elts2[] = {ScalarType, ScalarType,
5213 if (
Opc != Instruction::BitCast)
5217 Type *SrcTy = V->getType();
5234 if (
Opc != Instruction::BitCast)
5237 Type *SrcTy =
C->getType();
5262 unsigned Version = 0;
5263 if (
NamedMDNode *ModFlags = M.getModuleFlagsMetadata()) {
5264 auto OpIt =
find_if(ModFlags->operands(), [](
const MDNode *Flag) {
5265 if (Flag->getNumOperands() < 3)
5267 if (MDString *K = dyn_cast_or_null<MDString>(Flag->getOperand(1)))
5268 return K->getString() ==
"Debug Info Version";
5271 if (OpIt != ModFlags->op_end()) {
5272 const MDOperand &ValOp = (*OpIt)->getOperand(2);
5273 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(ValOp))
5274 Version = CI->getZExtValue();
5279 bool BrokenDebugInfo =
false;
5282 if (!BrokenDebugInfo)
5288 M.getContext().diagnose(Diag);
5295 M.getContext().diagnose(DiagVersion);
5305 StringRef Vect3[3] = {DefaultValue, DefaultValue, DefaultValue};
5308 if (
F->hasFnAttribute(Attr)) {
5311 StringRef S =
F->getFnAttribute(Attr).getValueAsString();
5313 auto [Part, Rest] = S.
split(
',');
5319 const unsigned Dim = DimC -
'x';
5320 assert(Dim < 3 &&
"Unexpected dim char");
5322 const uint64_t VInt = mdconst::extract<ConstantInt>(V)->getZExtValue();
5325 const std::string VStr = llvm::utostr(VInt);
5329 const std::string NewAttr = llvm::join(
ArrayRef(Vect3,
Length),
",");
5330 F->addFnAttr(Attr, NewAttr);
5334 return S ==
"x" || S ==
"y" || S ==
"z";
5339 if (K ==
"kernel") {
5340 if (!mdconst::extract<ConstantInt>(V)->
isZero())
5350 mdconst::extract<ConstantInt>(V)->getZExtValue();
5351 const unsigned Idx = (AlignIdxValuePair >> 16);
5352 const Align StackAlign =
Align(AlignIdxValuePair & 0xFFFF);
5353 cast<Function>(GV)->addAttributeAtIndex(
5357 if (K ==
"maxclusterrank" || K ==
"cluster_max_blocks") {
5358 const auto CV = mdconst::extract<ConstantInt>(V)->getZExtValue();
5359 cast<Function>(GV)->addFnAttr(
"nvvm.maxclusterrank", llvm::utostr(CV));
5362 if (K ==
"minctasm") {
5363 const auto CV = mdconst::extract<ConstantInt>(V)->getZExtValue();
5364 cast<Function>(GV)->addFnAttr(
"nvvm.minctasm", llvm::utostr(CV));
5367 if (K ==
"maxnreg") {
5368 const auto CV = mdconst::extract<ConstantInt>(V)->getZExtValue();
5369 cast<Function>(GV)->addFnAttr(
"nvvm.maxnreg", llvm::utostr(CV));
5372 if (K.consume_front(
"maxntid") &&
isXYZ(K)) {
5376 if (K.consume_front(
"reqntid") &&
isXYZ(K)) {
5380 if (K.consume_front(
"cluster_dim_") &&
isXYZ(K)) {
5384 if (K ==
"grid_constant") {
5386 for (
const auto &
Op : cast<MDNode>(V)->operands()) {
5389 const auto Index = mdconst::extract<ConstantInt>(
Op)->getZExtValue() - 1;
5390 cast<Function>(GV)->addParamAttr(Index, Attr);
5399 NamedMDNode *NamedMD = M.getNamedMetadata(
"nvvm.annotations");
5406 if (!SeenNodes.
insert(MD).second)
5409 auto *GV = mdconst::dyn_extract_or_null<GlobalValue>(MD->getOperand(0));
5413 assert((MD->getNumOperands() % 2) == 1 &&
"Invalid number of operands");
5420 for (
unsigned j = 1, je = MD->getNumOperands(); j < je; j += 2) {
5421 MDString *K = cast<MDString>(MD->getOperand(j));
5422 const MDOperand &V = MD->getOperand(j + 1);
5425 NewOperands.append({K, V});
5428 if (NewOperands.size() > 1)
5440 bool Changed =
false;
5441 const char *MarkerKey =
"clang.arc.retainAutoreleasedReturnValueMarker";
5442 NamedMDNode *ModRetainReleaseMarker = M.getNamedMetadata(MarkerKey);
5443 if (ModRetainReleaseMarker) {
5446 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(0));
5449 ID->getString().split(ValueComp,
"#");
5450 if (ValueComp.
size() == 2) {
5451 std::string NewValue = ValueComp[0].str() +
";" + ValueComp[1].str();
5455 M.eraseNamedMetadata(ModRetainReleaseMarker);
5466 auto UpgradeToIntrinsic = [&](
const char *OldFunc,
5468 Function *Fn = M.getFunction(OldFunc);
5477 CallInst *CI = dyn_cast<CallInst>(U);
5492 bool InvalidCast =
false;
5494 for (
unsigned I = 0, E = CI->
arg_size();
I != E; ++
I) {
5499 if (I < NewFuncTy->getNumParams()) {
5509 Args.push_back(Arg);
5534 UpgradeToIntrinsic(
"clang.arc.use", llvm::Intrinsic::objc_clang_arc_use);
5542 std::pair<const char *, llvm::Intrinsic::ID> RuntimeFuncs[] = {
5543 {
"objc_autorelease", llvm::Intrinsic::objc_autorelease},
5544 {
"objc_autoreleasePoolPop", llvm::Intrinsic::objc_autoreleasePoolPop},
5545 {
"objc_autoreleasePoolPush", llvm::Intrinsic::objc_autoreleasePoolPush},
5546 {
"objc_autoreleaseReturnValue",
5547 llvm::Intrinsic::objc_autoreleaseReturnValue},
5548 {
"objc_copyWeak", llvm::Intrinsic::objc_copyWeak},
5549 {
"objc_destroyWeak", llvm::Intrinsic::objc_destroyWeak},
5550 {
"objc_initWeak", llvm::Intrinsic::objc_initWeak},
5551 {
"objc_loadWeak", llvm::Intrinsic::objc_loadWeak},
5552 {
"objc_loadWeakRetained", llvm::Intrinsic::objc_loadWeakRetained},
5553 {
"objc_moveWeak", llvm::Intrinsic::objc_moveWeak},
5554 {
"objc_release", llvm::Intrinsic::objc_release},
5555 {
"objc_retain", llvm::Intrinsic::objc_retain},
5556 {
"objc_retainAutorelease", llvm::Intrinsic::objc_retainAutorelease},
5557 {
"objc_retainAutoreleaseReturnValue",
5558 llvm::Intrinsic::objc_retainAutoreleaseReturnValue},
5559 {
"objc_retainAutoreleasedReturnValue",
5560 llvm::Intrinsic::objc_retainAutoreleasedReturnValue},
5561 {
"objc_retainBlock", llvm::Intrinsic::objc_retainBlock},
5562 {
"objc_storeStrong", llvm::Intrinsic::objc_storeStrong},
5563 {
"objc_storeWeak", llvm::Intrinsic::objc_storeWeak},
5564 {
"objc_unsafeClaimAutoreleasedReturnValue",
5565 llvm::Intrinsic::objc_unsafeClaimAutoreleasedReturnValue},
5566 {
"objc_retainedObject", llvm::Intrinsic::objc_retainedObject},
5567 {
"objc_unretainedObject", llvm::Intrinsic::objc_unretainedObject},
5568 {
"objc_unretainedPointer", llvm::Intrinsic::objc_unretainedPointer},
5569 {
"objc_retain_autorelease", llvm::Intrinsic::objc_retain_autorelease},
5570 {
"objc_sync_enter", llvm::Intrinsic::objc_sync_enter},
5571 {
"objc_sync_exit", llvm::Intrinsic::objc_sync_exit},
5572 {
"objc_arc_annotation_topdown_bbstart",
5573 llvm::Intrinsic::objc_arc_annotation_topdown_bbstart},
5574 {
"objc_arc_annotation_topdown_bbend",
5575 llvm::Intrinsic::objc_arc_annotation_topdown_bbend},
5576 {
"objc_arc_annotation_bottomup_bbstart",
5577 llvm::Intrinsic::objc_arc_annotation_bottomup_bbstart},
5578 {
"objc_arc_annotation_bottomup_bbend",
5579 llvm::Intrinsic::objc_arc_annotation_bottomup_bbend}};
5581 for (
auto &
I : RuntimeFuncs)
5582 UpgradeToIntrinsic(
I.first,
I.second);
5586 NamedMDNode *ModFlags = M.getModuleFlagsMetadata();
5590 bool HasObjCFlag =
false, HasClassProperties =
false, Changed =
false;
5591 bool HasSwiftVersionFlag =
false;
5592 uint8_t SwiftMajorVersion, SwiftMinorVersion;
5601 MDString *
ID = dyn_cast_or_null<MDString>(
Op->getOperand(1));
5613 if (
ID->getString() ==
"Objective-C Image Info Version")
5615 if (
ID->getString() ==
"Objective-C Class Properties")
5616 HasClassProperties =
true;
5618 if (
ID->getString() ==
"PIC Level") {
5619 if (
auto *Behavior =
5620 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0))) {
5621 uint64_t V = Behavior->getLimitedValue();
5627 if (
ID->getString() ==
"PIE Level")
5628 if (
auto *Behavior =
5629 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0)))
5635 if (
ID->getString() ==
"branch-target-enforcement" ||
5636 ID->getString().starts_with(
"sign-return-address")) {
5637 if (
auto *Behavior =
5638 mdconst::dyn_extract_or_null<ConstantInt>(
Op->getOperand(0))) {
5643 Op->getOperand(1),
Op->getOperand(2)};
5653 if (
ID->getString() ==
"Objective-C Image Info Section") {
5654 if (
auto *
Value = dyn_cast_or_null<MDString>(
Op->getOperand(2))) {
5656 Value->getString().split(ValueComp,
" ");
5657 if (ValueComp.
size() != 1) {
5658 std::string NewValue;
5659 for (
auto &S : ValueComp)
5660 NewValue += S.str();
5661 Metadata *Ops[3] = {
Op->getOperand(0),
Op->getOperand(1),
5671 if (
ID->getString() ==
"Objective-C Garbage Collection") {
5672 auto Md = dyn_cast<ConstantAsMetadata>(
Op->getOperand(2));
5674 assert(Md->getValue() &&
"Expected non-empty metadata");
5675 auto Type = Md->getValue()->getType();
5678 unsigned Val = Md->getValue()->getUniqueInteger().getZExtValue();
5679 if ((Val & 0xff) != Val) {
5680 HasSwiftVersionFlag =
true;
5681 SwiftABIVersion = (Val & 0xff00) >> 8;
5682 SwiftMajorVersion = (Val & 0xff000000) >> 24;
5683 SwiftMinorVersion = (Val & 0xff0000) >> 16;
5694 if (
ID->getString() ==
"amdgpu_code_object_version") {
5697 MDString::get(M.getContext(),
"amdhsa_code_object_version"),
5709 if (HasObjCFlag && !HasClassProperties) {
5715 if (HasSwiftVersionFlag) {
5719 ConstantInt::get(Int8Ty, SwiftMajorVersion));
5721 ConstantInt::get(Int8Ty, SwiftMinorVersion));
5729 auto TrimSpaces = [](
StringRef Section) -> std::string {
5731 Section.split(Components,
',');
5736 for (
auto Component : Components)
5737 OS <<
',' << Component.trim();
5739 return std::string(
OS.str().substr(1));
5742 for (
auto &GV : M.globals()) {
5743 if (!GV.hasSection())
5748 if (!Section.starts_with(
"__DATA, __objc_catlist"))
5753 GV.setSection(TrimSpaces(Section));
5769struct StrictFPUpgradeVisitor :
public InstVisitor<StrictFPUpgradeVisitor> {
5770 StrictFPUpgradeVisitor() =
default;
5773 if (!Call.isStrictFP())
5775 if (isa<ConstrainedFPIntrinsic>(&Call))
5779 Call.removeFnAttr(Attribute::StrictFP);
5780 Call.addFnAttr(Attribute::NoBuiltin);
5785struct AMDGPUUnsafeFPAtomicsUpgradeVisitor
5786 :
public InstVisitor<AMDGPUUnsafeFPAtomicsUpgradeVisitor> {
5787 AMDGPUUnsafeFPAtomicsUpgradeVisitor() =
default;
5794 RMW.
setMetadata(
"amdgpu.no.fine.grained.host.memory", Empty);
5795 RMW.
setMetadata(
"amdgpu.no.remote.memory.access", Empty);
5796 RMW.
setMetadata(
"amdgpu.ignore.denormal.mode", Empty);
5804 if (!
F.isDeclaration() && !
F.hasFnAttribute(Attribute::StrictFP)) {
5805 StrictFPUpgradeVisitor SFPV;
5811 F.getReturnType(),
F.getAttributes().getRetAttrs()));
5812 for (
auto &Arg :
F.args())
5818 if (
Attribute A =
F.getFnAttribute(
"implicit-section-name");
5819 A.isValid() &&
A.isStringAttribute()) {
5820 F.setSection(
A.getValueAsString());
5821 F.removeFnAttr(
"implicit-section-name");
5828 if (
Attribute A =
F.getFnAttribute(
"amdgpu-unsafe-fp-atomics");
5831 if (
A.getValueAsBool()) {
5832 AMDGPUUnsafeFPAtomicsUpgradeVisitor Visitor;
5838 F.removeFnAttr(
"amdgpu-unsafe-fp-atomics");
5844 auto *
T = dyn_cast_or_null<MDTuple>(MD);
5847 if (
T->getNumOperands() < 1)
5849 auto *S = dyn_cast_or_null<MDString>(
T->getOperand(0));
5852 return S->getString().starts_with(
"llvm.vectorizer.");
5856 StringRef OldPrefix =
"llvm.vectorizer.";
5859 if (OldTag ==
"llvm.vectorizer.unroll")
5868 auto *
T = dyn_cast_or_null<MDTuple>(MD);
5871 if (
T->getNumOperands() < 1)
5873 auto *OldTag = dyn_cast_or_null<MDString>(
T->getOperand(0));
5876 if (!OldTag->getString().starts_with(
"llvm.vectorizer."))
5883 for (
unsigned I = 1, E =
T->getNumOperands();
I != E; ++
I)
5890 auto *
T = dyn_cast<MDTuple>(&
N);
5909 if (((
T.isAMDGPU() && !
T.isAMDGCN()) ||
5910 (
T.isSPIR() || (
T.isSPIRV() && !
T.isSPIRVLogical()))) &&
5911 !
DL.contains(
"-G") && !
DL.starts_with(
"G")) {
5912 return DL.
empty() ? std::string(
"G1") : (
DL +
"-G1").str();
5915 if (
T.isLoongArch64() ||
T.isRISCV64()) {
5917 auto I =
DL.find(
"-n64-");
5919 return (
DL.take_front(
I) +
"-n32:64-" +
DL.drop_front(
I + 5)).str();
5923 std::string Res =
DL.str();
5927 if (!
DL.contains(
"-G") && !
DL.starts_with(
"G"))
5928 Res.append(Res.empty() ?
"G1" :
"-G1");
5933 if (!
DL.contains(
"-ni") && !
DL.starts_with(
"ni"))
5934 Res.append(
"-ni:7:8:9");
5936 if (
DL.ends_with(
"ni:7"))
5938 if (
DL.ends_with(
"ni:7:8"))
5943 if (!
DL.contains(
"-p7") && !
DL.starts_with(
"p7"))
5944 Res.append(
"-p7:160:256:256:32");
5945 if (!
DL.contains(
"-p8") && !
DL.starts_with(
"p8"))
5946 Res.append(
"-p8:128:128:128:48");
5947 constexpr StringRef OldP8(
"-p8:128:128-");
5948 if (
DL.contains(OldP8))
5949 Res.replace(Res.find(OldP8), OldP8.
size(),
"-p8:128:128:128:48-");
5950 if (!
DL.contains(
"-p9") && !
DL.starts_with(
"p9"))
5951 Res.append(
"-p9:192:256:256:32");
5956 auto AddPtr32Ptr64AddrSpaces = [&
DL, &Res]() {
5959 StringRef AddrSpaces{
"-p270:32:32-p271:32:32-p272:64:64"};
5960 if (!
DL.contains(AddrSpaces)) {
5962 Regex R(
"^([Ee]-m:[a-z](-p:32:32)?)(-.*)$");
5963 if (R.match(Res, &
Groups))
5969 if (
T.isAArch64()) {
5971 if (!
DL.
empty() && !
DL.contains(
"-Fn32"))
5972 Res.append(
"-Fn32");
5973 AddPtr32Ptr64AddrSpaces();
5977 if (
T.isSPARC() || (
T.isMIPS64() && !
DL.contains(
"m:m")) ||
T.isPPC64() ||
5981 std::string I64 =
"-i64:64";
5982 std::string I128 =
"-i128:128";
5984 size_t Pos = Res.find(I64);
5985 if (Pos !=
size_t(-1))
5986 Res.insert(Pos + I64.size(), I128);
5994 AddPtr32Ptr64AddrSpaces();
6002 if (!
T.isOSIAMCU()) {
6003 std::string I128 =
"-i128:128";
6006 Regex R(
"^(e(-[mpi][^-]*)*)((-[^mpi][^-]*)*)$");
6007 if (R.match(Res, &
Groups))
6015 if (
T.isWindowsMSVCEnvironment() && !
T.isArch64Bit()) {
6017 auto I =
Ref.find(
"-f80:32-");
6019 Res = (
Ref.take_front(
I) +
"-f80:128-" +
Ref.drop_front(
I + 8)).str();
6027 Attribute A =
B.getAttribute(
"no-frame-pointer-elim");
6030 FramePointer =
A.getValueAsString() ==
"true" ?
"all" :
"none";
6031 B.removeAttribute(
"no-frame-pointer-elim");
6033 if (
B.contains(
"no-frame-pointer-elim-non-leaf")) {
6035 if (FramePointer !=
"all")
6036 FramePointer =
"non-leaf";
6037 B.removeAttribute(
"no-frame-pointer-elim-non-leaf");
6039 if (!FramePointer.
empty())
6040 B.addAttribute(
"frame-pointer", FramePointer);
6042 A =
B.getAttribute(
"null-pointer-is-valid");
6045 bool NullPointerIsValid =
A.getValueAsString() ==
"true";
6046 B.removeAttribute(
"null-pointer-is-valid");
6047 if (NullPointerIsValid)
6048 B.addAttribute(Attribute::NullPointerIsValid);
6058 return OBD.
getTag() ==
"clang.arc.attachedcall" &&
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU address space definition.
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static Value * upgradeX86VPERMT2Intrinsics(IRBuilder<> &Builder, CallBase &CI, bool ZeroMask, bool IndexForm)
static Metadata * upgradeLoopArgument(Metadata *MD)
static bool isXYZ(StringRef S)
static bool upgradeIntrinsicFunction1(Function *F, Function *&NewFn, bool CanUpgradeDebugIntrinsicsToRecords)
static Value * upgradeX86PSLLDQIntrinsics(IRBuilder<> &Builder, Value *Op, unsigned Shift)
static Intrinsic::ID shouldUpgradeNVPTXSharedClusterIntrinsic(Function *F, StringRef Name)
static bool upgradeRetainReleaseMarker(Module &M)
This checks for objc retain release marker which should be upgraded.
static Value * upgradeX86vpcom(IRBuilder<> &Builder, CallBase &CI, unsigned Imm, bool IsSigned)
static Value * upgradeMaskToInt(IRBuilder<> &Builder, CallBase &CI)
static Value * upgradeX86Rotate(IRBuilder<> &Builder, CallBase &CI, bool IsRotateRight)
static Intrinsic::ID shouldUpgradeNVPTXBF16Intrinsic(StringRef Name)
static bool upgradeSingleNVVMAnnotation(GlobalValue *GV, StringRef K, const Metadata *V)
static MDNode * unwrapMAVOp(CallBase *CI, unsigned Op)
Helper to unwrap intrinsic call MetadataAsValue operands.
static MDString * upgradeLoopTag(LLVMContext &C, StringRef OldTag)
static void upgradeNVVMFnVectorAttr(const StringRef Attr, const char DimC, GlobalValue *GV, const Metadata *V)
static bool upgradeX86MaskedFPCompare(Function *F, Intrinsic::ID IID, Function *&NewFn)
static Value * upgradeX86ALIGNIntrinsics(IRBuilder<> &Builder, Value *Op0, Value *Op1, Value *Shift, Value *Passthru, Value *Mask, bool IsVALIGN)
static Value * upgradeAbs(IRBuilder<> &Builder, CallBase &CI)
static Value * emitX86Select(IRBuilder<> &Builder, Value *Mask, Value *Op0, Value *Op1)
static Value * upgradeAArch64IntrinsicCall(StringRef Name, CallBase *CI, Function *F, IRBuilder<> &Builder)
static Value * upgradeMaskedMove(IRBuilder<> &Builder, CallBase &CI)
static bool upgradeX86IntrinsicFunction(Function *F, StringRef Name, Function *&NewFn)
static Value * applyX86MaskOn1BitsVec(IRBuilder<> &Builder, Value *Vec, Value *Mask)
static bool consumeNVVMPtrAddrSpace(StringRef &Name)
static bool shouldUpgradeX86Intrinsic(Function *F, StringRef Name)
static Value * upgradeX86PSRLDQIntrinsics(IRBuilder<> &Builder, Value *Op, unsigned Shift)
static Intrinsic::ID shouldUpgradeNVPTXTMAG2SIntrinsics(Function *F, StringRef Name)
static bool isOldLoopArgument(Metadata *MD)
static Value * upgradeARMIntrinsicCall(StringRef Name, CallBase *CI, Function *F, IRBuilder<> &Builder)
static bool upgradeX86IntrinsicsWith8BitMask(Function *F, Intrinsic::ID IID, Function *&NewFn)
static Value * upgradeAMDGCNIntrinsicCall(StringRef Name, CallBase *CI, Function *F, IRBuilder<> &Builder)
static Value * upgradeMaskedLoad(IRBuilder<> &Builder, Value *Ptr, Value *Passthru, Value *Mask, bool Aligned)
static Metadata * unwrapMAVMetadataOp(CallBase *CI, unsigned Op)
Helper to unwrap Metadata MetadataAsValue operands, such as the Value field.
static bool upgradeX86BF16Intrinsic(Function *F, Intrinsic::ID IID, Function *&NewFn)
static bool upgradeArmOrAarch64IntrinsicFunction(bool IsArm, Function *F, StringRef Name, Function *&NewFn)
static Value * getX86MaskVec(IRBuilder<> &Builder, Value *Mask, unsigned NumElts)
static Value * emitX86ScalarSelect(IRBuilder<> &Builder, Value *Mask, Value *Op0, Value *Op1)
static Value * upgradeX86ConcatShift(IRBuilder<> &Builder, CallBase &CI, bool IsShiftRight, bool ZeroMask)
static void rename(GlobalValue *GV)
static bool upgradePTESTIntrinsic(Function *F, Intrinsic::ID IID, Function *&NewFn)
static bool upgradeX86BF16DPIntrinsic(Function *F, Intrinsic::ID IID, Function *&NewFn)
static cl::opt< bool > DisableAutoUpgradeDebugInfo("disable-auto-upgrade-debug-info", cl::desc("Disable autoupgrade of debug info"))
static Value * upgradeMaskedCompare(IRBuilder<> &Builder, CallBase &CI, unsigned CC, bool Signed)
static Value * upgradeX86BinaryIntrinsics(IRBuilder<> &Builder, CallBase &CI, Intrinsic::ID IID)
static Value * upgradeNVVMIntrinsicCall(StringRef Name, CallBase *CI, Function *F, IRBuilder<> &Builder)
static Value * upgradeX86MaskedShift(IRBuilder<> &Builder, CallBase &CI, Intrinsic::ID IID)
static bool upgradeAVX512MaskToSelect(StringRef Name, IRBuilder<> &Builder, CallBase &CI, Value *&Rep)
static void upgradeDbgIntrinsicToDbgRecord(StringRef Name, CallBase *CI)
Convert debug intrinsic calls to non-instruction debug records.
static Value * upgradePMULDQ(IRBuilder<> &Builder, CallBase &CI, bool IsSigned)
static Value * upgradeMaskedStore(IRBuilder<> &Builder, Value *Ptr, Value *Data, Value *Mask, bool Aligned)
static MDNode * getDebugLocSafe(const Instruction *I)
static Value * upgradeX86IntrinsicCall(StringRef Name, CallBase *CI, Function *F, IRBuilder<> &Builder)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file contains constants used for implementing Dwarf debug support.
Module.h This file contains the declarations for the Module class.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
NVPTX address space definition.
static unsigned getNumElements(Type *Ty)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
static SymbolRef::Type getType(const Symbol *Sym)
static const X86InstrFMA3Group Groups[]
Class for arbitrary precision integers.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Class to represent array types.
Type * getElementType() const
an instruction that atomically reads a memory location, combines it with another value,...
void setVolatile(bool V)
Specify whether this is a volatile RMW or not.
BinOp
This enumeration lists the possible modifications atomicrmw can make.
@ UIncWrap
Increment one up to a maximum value.
@ FMin
*p = minnum(old, v) minnum matches the behavior of llvm.minnum.
@ FMax
*p = maxnum(old, v) maxnum matches the behavior of llvm.maxnum.
@ UDecWrap
Decrement one until a minimum value or zero.
bool isFloatingPointOperation() const
LLVM_ABI AttributeSet getFnAttrs() const
The function attributes are returned.
static LLVM_ABI AttributeList get(LLVMContext &C, ArrayRef< std::pair< unsigned, Attribute > > Attrs)
Create an AttributeList with the specified parameters in it.
LLVM_ABI AttributeSet getRetAttrs() const
The attributes for the ret value are returned.
static LLVM_ABI Attribute getWithStackAlignment(LLVMContext &Context, Align Alignment)
static LLVM_ABI Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Value * getCalledOperand() const
void setAttributes(AttributeList A)
Set the attributes for this call.
Value * getArgOperand(unsigned i) const
FunctionType * getFunctionType() const
LLVM_ABI Intrinsic::ID getIntrinsicID() const
Returns the intrinsic ID of the intrinsic called or Intrinsic::not_intrinsic if the called function i...
iterator_range< User::op_iterator > args()
Iteration adapter for range-for loops.
void setCalledOperand(Value *V)
unsigned arg_size() const
AttributeList getAttributes() const
Return the attributes for this call.
void setCalledFunction(Function *Fn)
Sets the function called, including updating the function type.
This class represents a function call, abstracting a target machine's calling convention.
void setTailCallKind(TailCallKind TCK)
static LLVM_ABI CastInst * Create(Instruction::CastOps, Value *S, Type *Ty, const Twine &Name="", InsertPosition InsertBefore=nullptr)
Provides a way to construct any of the CastInst subclasses using an opcode instead of the subclass's ...
static LLVM_ABI bool castIsValid(Instruction::CastOps op, Type *SrcTy, Type *DstTy)
This method can be used to determine if a cast from SrcTy to DstTy using Opcode op is valid or not.
Predicate
This enumeration lists the possible predicates for CmpInst subclasses.
static LLVM_ABI ConstantAggregateZero * get(Type *Ty)
static LLVM_ABI Constant * get(ArrayType *T, ArrayRef< Constant * > V)
static LLVM_ABI Constant * getIntToPtr(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static LLVM_ABI Constant * getPointerCast(Constant *C, Type *Ty)
Create a BitCast, AddrSpaceCast, or a PtrToInt cast constant expression.
static LLVM_ABI Constant * getPtrToInt(Constant *C, Type *Ty, bool OnlyIfReduced=false)
This is the shared class of boolean and integer constants.
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static LLVM_ABI ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static LLVM_ABI Constant * get(StructType *T, ArrayRef< Constant * > V)
static LLVM_ABI ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
static LLVM_ABI DIExpression * append(const DIExpression *Expr, ArrayRef< uint64_t > Ops)
Append the opcodes Ops to DIExpr.
This class represents an Operation in the Expression.
uint64_t getNumOperands() const
static LLVM_ABI DbgLabelRecord * createUnresolvedDbgLabelRecord(MDNode *Label, MDNode *DL)
For use during parsing; creates a DbgLabelRecord from as-of-yet unresolved MDNodes.
Base class for non-instruction debug metadata records that have positions within IR.
static LLVM_ABI DbgVariableRecord * createUnresolvedDbgVariableRecord(LocationType Type, Metadata *Val, MDNode *Variable, MDNode *Expression, MDNode *AssignID, Metadata *Address, MDNode *AddressExpression, MDNode *DI)
Used to create DbgVariableRecords during parsing, where some metadata references may still be unresol...
Convenience struct for specifying and reasoning about fast-math flags.
void setApproxFunc(bool B=true)
static LLVM_ABI FixedVectorType * get(Type *ElementType, unsigned NumElts)
Class to represent function types.
Type * getParamType(unsigned i) const
Parameter type accessors.
Type * getReturnType() const
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Intrinsic::ID getIntrinsicID() const LLVM_READONLY
getIntrinsicID - This method returns the ID number of the specified function, or Intrinsic::not_intri...
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Type * getReturnType() const
Returns the type of the ret val.
Argument * getArg(unsigned i) const
LinkageTypes getLinkage() const
Type * getValueType() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
ConstantInt * getInt1(bool V)
Get a constant value representing either true or false.
Value * CreateFSub(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Value * CreateInsertElement(Type *VecTy, Value *NewElt, Value *Idx, const Twine &Name="")
IntegerType * getInt1Ty()
Fetch the type representing a single bit.
Value * CreateInsertValue(Value *Agg, Value *Val, ArrayRef< unsigned > Idxs, const Twine &Name="")
Value * CreateFDiv(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
LLVM_ABI CallInst * CreateLifetimeStart(Value *Ptr)
Create a lifetime.start intrinsic.
CallInst * CreateInsertVector(Type *DstType, Value *SrcVec, Value *SubVec, Value *Idx, const Twine &Name="")
Create a call to the vector.insert intrinsic.
Value * CreateSIToFP(Value *V, Type *DestTy, const Twine &Name="")
Value * CreateExtractElement(Value *Vec, Value *Idx, const Twine &Name="")
IntegerType * getIntNTy(unsigned N)
Fetch the type representing an N-bit integer.
LLVM_ABI CallInst * CreateLifetimeEnd(Value *Ptr)
Create a lifetime.end intrinsic.
LoadInst * CreateAlignedLoad(Type *Ty, Value *Ptr, MaybeAlign Align, const char *Name)
Value * CreateFAdd(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Value * CreateFPTrunc(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
LLVM_ABI Value * CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name="")
Return a vector value that contains.
Value * CreateExtractValue(Value *Agg, ArrayRef< unsigned > Idxs, const Twine &Name="")
LLVM_ABI CallInst * CreateMaskedLoad(Type *Ty, Value *Ptr, Align Alignment, Value *Mask, Value *PassThru=nullptr, const Twine &Name="")
Create a call to Masked Load intrinsic.
Value * CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name="")
LLVM_ABI Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
Value * CreateSExt(Value *V, Type *DestTy, const Twine &Name="")
IntegerType * getInt32Ty()
Fetch the type representing a 32-bit integer.
ConstantInt * getInt8(uint8_t C)
Get a constant 8-bit value.
Value * CreateUIToFP(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
IntegerType * getInt64Ty()
Fetch the type representing a 64-bit integer.
IntegerType * getInt16Ty()
Fetch the type representing a 16-bit integer.
ConstantInt * getInt64(uint64_t C)
Get a constant 64-bit value.
Value * CreateNeg(Value *V, const Twine &Name="", bool HasNSW=false)
LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with Args, mangled using Types.
ConstantInt * getInt32(uint32_t C)
Get a constant 32-bit value.
Value * CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateNot(Value *V, const Twine &Name="")
Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateFMA(Value *Factor1, Value *Factor2, Value *Summand, FMFSource FMFSource={}, const Twine &Name="")
Create call to the fma intrinsic.
Value * CreateBitCast(Value *V, Type *DestTy, const Twine &Name="")
LLVM_ABI CallInst * CreateUnaryIntrinsic(Intrinsic::ID ID, Value *V, FMFSource FMFSource={}, const Twine &Name="")
Create a call to intrinsic ID with 1 operand which is mangled on its type.
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Value * CreateZExt(Value *V, Type *DestTy, const Twine &Name="", bool IsNonNeg=false)
Value * CreateShuffleVector(Value *V1, Value *V2, Value *Mask, const Twine &Name="")
LLVMContext & getContext() const
Value * CreateAnd(Value *LHS, Value *RHS, const Twine &Name="")
LLVM_ABI CallInst * CreateMaskedStore(Value *Val, Value *Ptr, Align Alignment, Value *Mask)
Create a call to Masked Store intrinsic.
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
ConstantInt * getFalse()
Get the constant value for i1 false.
Type * getFloatTy()
Fetch the type representing a 32-bit floating point value.
Value * CreateIsNotNull(Value *Arg, const Twine &Name="")
Return a boolean value testing if Arg != 0.
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)
AtomicRMWInst * CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val, MaybeAlign Align, AtomicOrdering Ordering, SyncScope::ID SSID=SyncScope::System)
Value * CreateTrunc(Value *V, Type *DestTy, const Twine &Name="", bool IsNUW=false, bool IsNSW=false)
PointerType * getPtrTy(unsigned AddrSpace=0)
Fetch the type representing a pointer.
Value * CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateIntCast(Value *V, Type *DestTy, bool isSigned, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
StoreInst * CreateAlignedStore(Value *Val, Value *Ptr, MaybeAlign Align, bool isVolatile=false)
Value * CreateFPExt(Value *V, Type *DestTy, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateAShr(Value *LHS, Value *RHS, const Twine &Name="", bool isExact=false)
Value * CreateXor(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS, const Twine &Name="")
Value * CreateFMul(Value *L, Value *R, const Twine &Name="", MDNode *FPMD=nullptr)
Value * CreateFNeg(Value *V, const Twine &Name="", MDNode *FPMathTag=nullptr)
Value * CreateOr(Value *LHS, Value *RHS, const Twine &Name="", bool IsDisjoint=false)
IntegerType * getInt8Ty()
Fetch the type representing an 8-bit integer.
Value * CreateAddrSpaceCast(Value *V, Type *DestTy, const Twine &Name="")
Type * getBFloatTy()
Fetch the type representing a 16-bit brain floating point value.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Base class for instruction visitors.
RetTy visitCallBase(CallBase &I)
RetTy visitAtomicRMWInst(AtomicRMWInst &I)
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
unsigned getBitWidth() const
Get the number of bits in this IntegerType.
This is an important class for using LLVM in a threaded context.
LLVM_ABI SyncScope::ID getOrInsertSyncScopeID(StringRef SSN)
getOrInsertSyncScopeID - Maps synchronization scope name to synchronization scope ID.
An instruction for reading from memory.
LLVM_ABI MDNode * createRange(const APInt &Lo, const APInt &Hi)
Return metadata describing the range [Lo, Hi).
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
LLVMContext & getContext() const
Tracking metadata reference owned by Metadata.
static LLVM_ABI MDString * get(LLVMContext &Context, StringRef Str)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
@ Min
Takes the min of the two values, which are required to be integers.
@ Max
Takes the max of the two values, which are required to be integers.
LLVM_ABI void setOperand(unsigned I, MDNode *New)
LLVM_ABI MDNode * getOperand(unsigned i) const
LLVM_ABI unsigned getNumOperands() const
LLVM_ABI void clearOperands()
Drop all references to this node's operands.
iterator_range< op_iterator > operands()
LLVM_ABI void addOperand(MDNode *M)
A container for an operand bundle being viewed as a set of values rather than a set of uses.
ArrayRef< InputTy > inputs() const
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
LLVM_ABI bool match(StringRef String, SmallVectorImpl< StringRef > *Matches=nullptr, std::string *Error=nullptr) const
matches - Match the regex against a given String.
static LLVM_ABI ScalableVectorType * get(Type *ElementType, unsigned MinNumElts)
ArrayRef< int > getShuffleMask() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
constexpr size_t size() const
size - Get the string size.
StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
static constexpr size_t npos
A switch()-like statement whose cases are string literals.
StringSwitch & Case(StringLiteral S, T Value)
StringSwitch & StartsWith(StringLiteral S, T Value)
StringSwitch & Cases(StringLiteral S0, StringLiteral S1, T Value)
Class to represent struct types.
static LLVM_ABI StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
unsigned getNumElements() const
Random access to the elements.
Type * getElementType(unsigned N) const
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
bool isBFloatTy() const
Return true if this is 'bfloat', a 16-bit bfloat type.
static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isPtrOrPtrVectorTy() const
Return true if this is a pointer type or a vector of pointer types.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isFPOrFPVectorTy() const
Return true if this is a FP type or a vector of FP.
Type * getScalarType() const
If this is a vector type, return the element type, otherwise return 'this'.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void setName(const Twine &Name)
Change the name of the value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
iterator_range< user_iterator > users()
LLVM_ABI LLVMContext & getContext() const
All values hold a context through their type.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
LLVM_ABI void takeName(Value *V)
Transfer the name from V to this value.
Base class of all SIMD vector types.
constexpr ScalarTy getFixedValue() const
const ParentTy * getParent() const
self_iterator getIterator()
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ LOCAL_ADDRESS
Address space for local memory.
@ FLAT_ADDRESS
Address space for flat memory.
@ PRIVATE_ADDRESS
Address space for private memory.
LLVM_ABI AttributeMask typeIncompatible(Type *Ty, AttributeSet AS, AttributeSafetyKind ASK=ASK_ALL)
Which attributes cannot be applied to a type.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ PTX_Kernel
Call to a PTX kernel. Passes all arguments in parameter space.
@ C
The default llvm calling convention, compatible with C.
LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})
Look up the Function declaration of the intrinsic id in the Module M.
LLVM_ABI void getIntrinsicInfoTableEntries(ID id, SmallVectorImpl< IITDescriptor > &T)
Return the IIT table descriptor for the specified intrinsic into an array of IITDescriptors.
LLVM_ABI std::optional< Function * > remangleIntrinsicFunction(Function *F)
LLVM_ABI AttributeList getAttributes(LLVMContext &C, ID id, FunctionType *FT)
Return the attributes for an intrinsic.
LLVM_ABI bool getIntrinsicSignature(Intrinsic::ID, FunctionType *FT, SmallVectorImpl< Type * > &ArgTys)
Gets the type arguments of an intrinsic call by matching type contraints specified by the ....
@ ADDRESS_SPACE_SHARED_CLUSTER
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void UpgradeIntrinsicCall(CallBase *CB, Function *NewFn)
This is the complement to the above, replacing a specific call to an intrinsic function with a call t...
LLVM_ABI void UpgradeSectionAttributes(Module &M)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
LLVM_ABI void UpgradeInlineAsmString(std::string *AsmStr)
Upgrade comment in call to inline asm that represents an objc retain release marker.
bool isValidAtomicOrdering(Int I)
LLVM_ABI bool UpgradeIntrinsicFunction(Function *F, Function *&NewFn, bool CanUpgradeDebugIntrinsicsToRecords=true)
This is a more granular function that simply checks an intrinsic function for upgrading,...
LLVM_ABI MDNode * upgradeInstructionLoopAttachment(MDNode &N)
Upgrade the loop attachment metadata node.
LLVM_ABI void UpgradeAttributes(AttrBuilder &B)
Upgrade attributes that changed format or kind.
LLVM_ABI void UpgradeCallsToIntrinsic(Function *F)
This is an auto-upgrade hook for any old intrinsic function syntaxes which need to have both the func...
LLVM_ABI void UpgradeNVVMAnnotations(Module &M)
Convert legacy nvvm.annotations metadata to appropriate function attributes.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
LLVM_ABI bool UpgradeModuleFlags(Module &M)
This checks for module flags which should be upgraded.
LLVM_ABI void UpgradeOperandBundles(std::vector< OperandBundleDef > &OperandBundles)
Upgrade operand bundles (without knowing about their user instruction).
LLVM_ABI Constant * UpgradeBitCastExpr(unsigned Opc, Constant *C, Type *DestTy)
This is an auto-upgrade for bitcast constant expression between pointers with different address space...
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI std::string UpgradeDataLayoutString(StringRef DL, StringRef Triple)
Upgrade the datalayout string by adding a section for address space pointers.
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
LLVM_ABI GlobalVariable * UpgradeGlobalVariable(GlobalVariable *GV)
This checks for global variables which should be upgraded.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
AtomicOrdering
Atomic ordering for LLVM's memory model.
@ Ref
The access may reference the value stored in memory.
LLVM_ABI Instruction * UpgradeBitCastInst(unsigned Opc, Value *V, Type *DestTy, Instruction *&Temp)
This is an auto-upgrade for bitcast between pointers with different address spaces: the instruction i...
DWARFExpression::Operation Op
@ Dynamic
Denotes mode unknown at compile time.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
LLVM_ABI bool UpgradeDebugInfo(Module &M)
Check the debug info version number, if it is out-dated, drop the debug info.
LLVM_ABI void UpgradeFunctionAttributes(Function &F)
Correct any IR that is relying on old function attribute behavior.
LLVM_ABI MDNode * UpgradeTBAANode(MDNode &TBAANode)
If the given TBAA tag uses the scalar TBAA format, create a new node corresponding to the upgrade to ...
LLVM_ABI void UpgradeARCRuntime(Module &M)
Convert calls to ARC runtime functions to intrinsic calls and upgrade the old retain release marker t...
LLVM_ABI bool verifyModule(const Module &M, raw_ostream *OS=nullptr, bool *BrokenDebugInfo=nullptr)
Check a module for errors.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
This struct is a compact representation of a valid (non-zero power of two) alignment.
Description of the encoding of one expression Op.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.