clang 24.0.0git
CIRGenBuiltinAMDGPU.cpp
Go to the documentation of this file.
1//===---- CIRGenBuiltinAMDGPU.cpp - Emit CIR for AMDGPU builtins ----------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code to emit AMDGPU Builtin calls.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CIRGenFunction.h"
14
15#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
16#include "mlir/Dialect/LLVMIR/LLVMDialectDecl.h"
17#include "mlir/IR/Value.h"
19#include "llvm/IR/IntrinsicsAMDGPU.h"
20#include "llvm/Support/AMDGPUAddrSpace.h"
21#include "llvm/Support/ErrorHandling.h"
22#include "llvm/TargetParser/AtomicScope.h"
23
24using namespace clang;
25using namespace clang::CIRGen;
26using namespace cir;
27
28// Emit a no-operand intrinsic returning a pointer in the constant AS.
30 mlir::Location loc,
31 llvm::StringRef name) {
32 CIRGenBuilderTy &builder = cgf.getBuilder();
33 mlir::Type retTy = builder.getVoidPtrTy(cir::TargetAddressSpaceAttr::get(
34 builder.getContext(), llvm::AMDGPUAS::CONSTANT_ADDRESS));
35 return builder.emitIntrinsicCallOp(loc, name, retTy, mlir::ValueRange{});
36}
37
38/// Map a constant integral to memory order.
39static cir::MemOrder decodeAtomicOrder(const Expr *arg, ASTContext &ctx) {
40 Expr::EvalResult orderRes;
41 if (!arg->EvaluateAsInt(orderRes, ctx))
42 return cir::MemOrder::SequentiallyConsistent;
43 switch (orderRes.Val.getInt().getZExtValue()) {
44 case 0:
45 return cir::MemOrder::Relaxed;
46 case 1: // consume -> acquire
47 case 2:
48 return cir::MemOrder::Acquire;
49 case 3:
50 return cir::MemOrder::Release;
51 case 4:
52 return cir::MemOrder::AcquireRelease;
53 default:
54 return cir::MemOrder::SequentiallyConsistent;
55 }
56}
57
58/// Map an AMDGPU sync-scope string-literal argument onto cir::SyncScopeKind.
59/// An absent or unrecognized scope is system scope, which is the conservative
60/// choice and matches what an empty syncscope string means in LLVM.
61static cir::SyncScopeKind decodeAMDGPUSyncScope(const Expr *arg) {
62 const auto *sl =
63 llvm::dyn_cast<clang::StringLiteral>(arg->IgnoreParenCasts());
64 if (!sl)
65 return cir::SyncScopeKind::System;
66 return llvm::StringSwitch<cir::SyncScopeKind>(sl->getString())
67 .Case("singlethread", cir::SyncScopeKind::SingleThread)
68 .Case("wavefront", cir::SyncScopeKind::Wavefront)
69 .Case("workgroup", cir::SyncScopeKind::Workgroup)
70 .Case("agent", cir::SyncScopeKind::Device)
71 .Default(cir::SyncScopeKind::System);
72}
73
74static cir::SyncScopeKind convertAtomicScopeToCIR(llvm::AtomicScope scope) {
75 switch (scope) {
76 case llvm::AtomicScope::Single:
77 return cir::SyncScopeKind::SingleThread;
78 case llvm::AtomicScope::Wavefront:
79 return cir::SyncScopeKind::Wavefront;
80 case llvm::AtomicScope::Workgroup:
81 return cir::SyncScopeKind::Workgroup;
82 case llvm::AtomicScope::Cluster:
83 return cir::SyncScopeKind::Cluster;
84 case llvm::AtomicScope::Device:
85 return cir::SyncScopeKind::Device;
86 case llvm::AtomicScope::System:
87 return cir::SyncScopeKind::System;
88 }
89 llvm_unreachable("unknown atomic scope");
90}
91
92/// Emit one of the AMDGPU raw hardware atomic builtins as a cir.atomic.fetch.
93static mlir::Value emitAMDGPUAtomicRMW(CIRGenFunction &cgf,
94 const CallExpr *expr,
95 cir::AtomicFetchKind binOp,
96 bool hasVolatileArg) {
97 CIRGenBuilderTy &builder = cgf.getBuilder();
98 mlir::Location loc = cgf.getLoc(expr->getExprLoc());
99
100 Address ptr = cgf.emitPointerWithAlignment(expr->getArg(0));
101 mlir::Value val = cgf.emitScalarExpr(expr->getArg(1));
102
103 bool isVolatile;
104 if (hasVolatileArg) {
105 assert(expr->getNumArgs() >= 5);
106 // ds_faddf/fminf/fmaxf spell the volatile flag out as a constant argument.
107 Expr::EvalResult volRes;
108 isVolatile = expr->getArg(4)->EvaluateAsInt(volRes, cgf.getContext()) &&
109 volRes.Val.getInt().getBoolValue();
110 } else {
111 // Everything else infers it from the pointee type.
112 QualType argTy = expr->getArg(0)->IgnoreImpCasts()->getType();
113 isVolatile = argTy->castAs<clang::PointerType>()
116 }
117
118 // Some of these builtins spell out the ordering and scope; the rest take the
119 // monotonic/agent default described above.
120 cir::MemOrder order = cir::MemOrder::Relaxed;
121 cir::SyncScopeKind scope = cir::SyncScopeKind::Device;
122 if (expr->getNumArgs() >= 4) {
123 order = decodeAtomicOrder(expr->getArg(2), cgf.getContext());
124 scope = decodeAMDGPUSyncScope(expr->getArg(3));
125 }
126
127 mlir::Type origTy = val.getType();
128 if (auto vecTy = mlir::dyn_cast<cir::VectorType>(origTy);
129 vecTy && mlir::isa<cir::IntType>(vecTy.getElementType())) {
130 auto bf16VecTy =
131 cir::VectorType::get(builder.getBfloat16Ty(), vecTy.getSize());
132 val = builder.createBitcast(loc, val, bf16VecTy);
133 ptr = ptr.withElementType(builder, bf16VecTy);
134 }
135
136 auto rmw = cir::AtomicFetchOp::create(
137 builder, loc, ptr.emitRawPointer(), val, binOp, order, scope,
138 /*alignment=*/nullptr, isVolatile, /*fetch_first=*/true);
139 rmw->setAttr(cir::CIRDialect::getAMDGPURawAtomicAttrName(),
140 builder.getUnitAttr());
141 return builder.createBitcast(loc, rmw->getResult(0), origTy);
142}
143
144// Emit the `amdgcn.dispatch.ptr` intrinsic, address-space-casting the
145// result to match \p e's return type when needed.
146// If \p e is null, returns the raw AS-4 pointer.
147static mlir::Value emitAMDGPUDispatchPtr(CIRGenFunction &cgf,
148 mlir::Location loc,
149 const CallExpr *e = nullptr) {
150 CIRGenBuilderTy &builder = cgf.getBuilder();
151 mlir::Value call =
152 emitAMDGPUConstantPtrIntrinsic(cgf, loc, "amdgcn.dispatch.ptr");
153 if (!e)
154 return call;
155 // Only cast when the caller-visible AS differs from the intrinsic's AS;
156 auto expectedPtrTy =
157 mlir::cast<cir::PointerType>(cgf.convertType(e->getType()));
158 auto callPtrTy = mlir::cast<cir::PointerType>(call.getType());
159 if (expectedPtrTy.getAddrSpace() == callPtrTy.getAddrSpace())
160 return call;
161 return builder.createAddrSpaceCast(loc, call, expectedPtrTy);
162}
163
165 mlir::Location loc) {
166 // OG also marks the result align 8 dereferenceable(256).
168 return emitAMDGPUConstantPtrIntrinsic(cgf, loc, "amdgcn.implicitarg.ptr");
169}
170
171static mlir::Value emitAMDGPUWorkGroupID(CIRGenFunction &cgf,
172 mlir::Location loc, unsigned index) {
173 static constexpr llvm::StringLiteral names[] = {"amdgcn.workgroup.id.x",
174 "amdgcn.workgroup.id.y",
175 "amdgcn.workgroup.id.z"};
176 CIRGenBuilderTy &builder = cgf.getBuilder();
177 return builder.emitIntrinsicCallOp(loc, names[index], builder.getUInt32Ty(),
178 mlir::ValueRange{});
179}
180
181// Load a \p ty value at byte \p offset from \p base as an invariant load.
182// \p flags are the no-wrap flags of the address computation.
183static mlir::Value
185 mlir::Value base, mlir::Value offset, mlir::Type ty,
186 CharUnits align,
188 CIRGenBuilderTy &builder = cgf.getBuilder();
189 mlir::Value addr = builder.createPtrStride(loc, base, offset, flags);
190 cir::LoadOp load = builder.createAlignedLoad(loc, ty, addr, align);
191 load.setInvariant(true);
193 return load;
194}
195
196static mlir::Value emitAMDGPUGridSize(CIRGenFunction &cgf, mlir::Location loc,
197 unsigned index) {
198 CIRGenBuilderTy &builder = cgf.getBuilder();
199 const unsigned xOffset = 12;
200 mlir::Value dispatchPtr = emitAMDGPUDispatchPtr(cgf, loc);
201 // Indexing the HSA kernel_dispatch_packet struct.
203 cgf, loc, dispatchPtr, builder.getUInt64(xOffset + index * 4, loc),
205}
206
208 mlir::Location loc,
209 unsigned index) {
210 CIRGenBuilderTy &builder = cgf.getBuilder();
211 mlir::Value implicitArgPtr = emitAMDGPUImplicitArgPtr(cgf, loc);
212
213 // offsetof(amdhsa_implicit_kernarg_v5, block_count[index])
214 unsigned blockCountOffset = 0 + index * 4;
215 // offsetof(amdhsa_implicit_kernarg_v5, group_size[index])
216 unsigned groupSizeOffset = 12 + index * 2;
217 // offsetof(amdhsa_implicit_kernarg_v5, remainder[index])
218 unsigned remainderOffset = 18 + index * 2;
219
220 mlir::Value sizeOffset;
221 if (cgf.getLangOpts().OffloadUniformBlock) {
222 sizeOffset = builder.getUInt64(groupSizeOffset, loc);
223 } else {
224 mlir::Value blockCount = emitAMDGPUInvariantLoad(
225 cgf, loc, implicitArgPtr, builder.getUInt64(blockCountOffset, loc),
227 mlir::Value workgroupID = emitAMDGPUWorkGroupID(cgf, loc, index);
228 mlir::Value isFull =
229 builder.createCompare(loc, cir::CmpOpKind::lt, workgroupID, blockCount);
230 sizeOffset = builder.createSelect(loc, isFull,
231 builder.getUInt64(groupSizeOffset, loc),
232 builder.getUInt64(remainderOffset, loc));
233 }
234
235 mlir::Value size = emitAMDGPUInvariantLoad(
236 cgf, loc, implicitArgPtr, sizeOffset, builder.getUInt16Ty(),
238 return builder.createIntCast(size, builder.getUInt32Ty());
239}
240
242 mlir::Location loc,
243 unsigned index) {
244 CIRGenBuilderTy &builder = cgf.getBuilder();
245 mlir::Value dispatchPtr = emitAMDGPUDispatchPtr(cgf, loc);
246
247 // Indexing the HSA kernel_dispatch_packet struct.
248 mlir::Value groupSizeLd = emitAMDGPUInvariantLoad(
249 cgf, loc, dispatchPtr, builder.getUInt64(4 + index * 2, loc),
252 mlir::Value groupSize =
253 builder.createIntCast(groupSizeLd, builder.getUInt32Ty());
254
255 if (cgf.getLangOpts().OffloadUniformBlock)
256 return groupSize;
257
258 mlir::Value workgroupID = emitAMDGPUWorkGroupID(cgf, loc, index);
259 mlir::Value gridSize = emitAMDGPUInvariantLoad(
260 cgf, loc, dispatchPtr, builder.getUInt64(12 + index * 4, loc),
263 mlir::Value mul = builder.createMul(loc, workgroupID, groupSize);
264 mlir::Value remainder = builder.createSub(loc, gridSize, mul);
265 mlir::Value isPartial =
266 builder.createCompare(loc, cir::CmpOpKind::lt, remainder, groupSize);
267 return builder.createSelect(loc, isPartial, remainder, groupSize);
268}
269
270// \p index is 0, 1, and 2 for x, y, and z dimension, respectively.
271// Emit code based on Code Object ABI version.
272// COV_4 : Emit code to use dispatch ptr
273// COV_5+ : Emit code to use implicitarg ptr
274// COV_NONE : Emit code to load a global variable "__oclc_ABI_version"
275// and use its value for COV_4 or COV_5+ approach. It is used for
276// compiling device libraries in an ABI-agnostic way.
278 mlir::Location loc, unsigned index) {
279 llvm::CodeObjectVersionKind cov =
281
282 // Do not emit __oclc_ABI_version references with non-empty environment.
283 if (cov == llvm::CodeObjectVersionKind::COV_None &&
284 cgf.getTarget().getTriple().hasEnvironment())
285 cov = llvm::CodeObjectVersionKind::COV_6;
286
287 if (cov != llvm::CodeObjectVersionKind::COV_None)
288 return cov >= llvm::CodeObjectVersionKind::COV_5
290 : emitAMDGPUWorkGroupSizeV4(cgf, loc, index);
291
292 CIRGenBuilderTy &builder = cgf.getBuilder();
293 CIRGenModule &cgm = cgf.cgm;
294 StringRef name = "__oclc_ABI_version";
295 mlir::Type int32Ty = builder.getSInt32Ty();
296 auto abiVersionGV =
297 mlir::dyn_cast_or_null<cir::GlobalOp>(cgm.getGlobalValue(name));
298 if (!abiVersionGV)
299 abiVersionGV =
300 cgm.createGlobalOp(loc, name, int32Ty, /*isConstant=*/false,
303 mlir::Value abiVersionPtr = builder.createGetGlobal(loc, abiVersionGV);
304 mlir::Value abiVersion = builder.createAlignedLoad(
305 loc, int32Ty, abiVersionPtr,
307 mlir::Value isCOV5 = builder.createCompare(
308 loc, cir::CmpOpKind::ge, abiVersion,
309 builder.getConstantInt(loc, int32Ty, llvm::CodeObjectVersionKind::COV_5));
310 mlir::Value v5Impl = emitAMDGPUWorkGroupSizeV5(cgf, loc, index);
311 mlir::Value v4Impl = emitAMDGPUWorkGroupSizeV4(cgf, loc, index);
312 return builder.createSelect(loc, isCOV5, v5Impl, v4Impl);
313}
314
316 CIRGenFunction &cgf, const CallExpr *e, llvm::StringRef intrinsicName,
317 llvm::StringRef constrainedIntrinsicName) {
318 mlir::Value src0 = cgf.emitScalarExpr(e->getArg(0));
319 mlir::Value src1 = cgf.emitScalarExpr(e->getArg(1));
320 mlir::Location loc = cgf.getLoc(e->getExprLoc());
321
322 CIRGenBuilderTy &builder = cgf.getBuilder();
323
324 CIRGenFunction::CIRGenFPOptionsRAII fpOptsRAII(cgf, e);
325
326 if (builder.getIsFPConstrained()) {
327 cgf.cgm.errorNYI(e->getSourceRange(),
328 "constrained FP intrinsic support is NYI.");
329 }
330
331 return builder.emitIntrinsicCallOp(loc, intrinsicName, src0.getType(),
332 mlir::ValueRange{src0, src1});
333}
334
335static mlir::Value emitLogbBuiltin(CIRGenFunction &cgf, const CallExpr *e,
336 const llvm::fltSemantics &fSem) {
337 CIRGenBuilderTy &builder = cgf.getBuilder();
338 mlir::Location loc = cgf.getLoc(e->getExprLoc());
339
340 mlir::Value src0 = cgf.emitScalarExpr(e->getArg(0));
341 mlir::Type srcTy = src0.getType();
342 mlir::Type int32Ty = builder.getSInt32Ty();
343
344 mlir::Type frExpResMembers[] = {srcTy, int32Ty};
345 cir::RecordType frExpResTy = builder.getAnonRecordTy(
346 frExpResMembers, /*packed=*/false,
347 cir::RecordType::getAllDataKinds(frExpResMembers));
348
349 mlir::Value frExpResult = builder.emitIntrinsicCallOp(
350 loc, "frexp", frExpResTy, mlir::ValueRange{src0});
351
352 mlir::Value exp =
353 cir::ExtractMemberOp::create(builder, loc, int32Ty, frExpResult, 1);
354
355 mlir::Value negativeOne =
356 builder.getConstant(loc, cir::IntAttr::get(int32Ty, -1));
357 mlir::Value expMinus1 = builder.createNSWAdd(loc, exp, negativeOne);
358
359 mlir::Value siToFp = cir::CastOp::create(
360 builder, loc, srcTy, cir::CastKind::int_to_float, expMinus1);
361
362 mlir::Value fabs = cir::FAbsOp::create(builder, loc, src0);
363
364 llvm::APFloat infVal = llvm::APFloat::getInf(fSem);
365 mlir::Value inf = builder.getConstant(loc, cir::FPAttr::get(srcTy, infVal));
366
367 mlir::Value fabsNegInf =
368 builder.createCompare(loc, cir::CmpOpKind::one, fabs, inf);
369
370 mlir::Value sel = builder.createSelect(loc, fabsNegInf, siToFp, fabs);
371
372 llvm::APFloat zeroValue = llvm::APFloat::getZero(fSem);
373 mlir::Value zero =
374 builder.getConstant(loc, cir::FPAttr::get(srcTy, zeroValue));
375
376 mlir::Value srcEqZero =
377 builder.createCompare(loc, cir::CmpOpKind::eq, src0, zero);
378
379 llvm::APFloat negInfVal = llvm::APFloat::getInf(fSem, true);
380 mlir::Value negInf =
381 builder.getConstant(loc, cir::FPAttr::get(srcTy, negInfVal));
382
383 mlir::Value res = builder.createSelect(loc, srcEqZero, negInf, sel);
384
385 return res;
386}
387
388static mlir::Value
390 llvm::StringRef intrinsicName,
391 bool isImageStore) {
392 auto &builder = cgf.getBuilder();
393
395 for (unsigned i = 0, n = e->getNumArgs(); i < n; ++i)
396 args.push_back(cgf.emitScalarExpr(e->getArg(i)));
397
398 mlir::Type retTy = isImageStore ? cir::VoidType::get(builder.getContext())
399 : cgf.convertType(e->getType());
400
401 auto callOp = cir::LLVMIntrinsicCallOp::create(
402 builder, cgf.getLoc(e->getExprLoc()),
403 builder.getStringAttr(intrinsicName), retTy, args);
404
405 return callOp.getResult();
406}
407
408static mlir::Value emitAMDGPUPredicate(CIRGenFunction &cgf, const CallExpr *e,
409 const llvm::Twine &name) {
410 CIRGenBuilderTy &builder = cgf.getBuilder();
411 mlir::Location loc = cgf.getLoc(e->getExprLoc());
412 mlir::Value result = cir::AMDGPUFeaturePredicateOp::create(
413 builder, loc, builder.getBoolTy(), builder.getStringAttr(name));
414 // Sema retypes the call to the logical operation type, which is int in C.
415 return builder.createBoolToInt(result, cgf.convertType(e->getType()));
416}
417
418std::optional<mlir::Value>
420 const CallExpr *expr) {
421 switch (builtinId) {
422 case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_u32:
423 case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_u32:
424 case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i32:
425 case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_u32:
426 case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i32:
427 case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_u32:
428 case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_b32:
429 case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_b32:
430 case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_b32:
431 case AMDGPU::BI__builtin_amdgcn_wave_reduce_add_u64:
432 case AMDGPU::BI__builtin_amdgcn_wave_reduce_sub_u64:
433 case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_i64:
434 case AMDGPU::BI__builtin_amdgcn_wave_reduce_min_u64:
435 case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_i64:
436 case AMDGPU::BI__builtin_amdgcn_wave_reduce_max_u64:
437 case AMDGPU::BI__builtin_amdgcn_wave_reduce_and_b64:
438 case AMDGPU::BI__builtin_amdgcn_wave_reduce_or_b64:
439 case AMDGPU::BI__builtin_amdgcn_wave_reduce_xor_b64: {
440 cgm.errorNYI(expr->getSourceRange(),
441 std::string("unimplemented AMDGPU builtin call: ") +
442 getContext().BuiltinInfo.getName(builtinId));
443 return mlir::Value{};
444 }
445 case AMDGPU::BI__builtin_amdgcn_div_scale:
446 case AMDGPU::BI__builtin_amdgcn_div_scalef: {
447 Address flagOutPtr = emitPointerWithAlignment(expr->getArg(3));
448 llvm::StringRef intrinsicName = "amdgcn.div.scale";
449 mlir::Value x = emitScalarExpr(expr->getArg(0));
450 mlir::Value y = emitScalarExpr(expr->getArg(1));
451 mlir::Value z = emitScalarExpr(expr->getArg(2));
452
453 auto i1Ty = builder.getUIntNTy(1);
454 mlir::Type resMembers[] = {x.getType(), i1Ty};
455 cir::RecordType resTy =
456 builder.getAnonRecordTy(resMembers, /*packed=*/false,
458
459 mlir::Value structResult =
460 cir::LLVMIntrinsicCallOp::create(builder, getLoc(expr->getExprLoc()),
461 builder.getStringAttr(intrinsicName),
462 resTy, {x, y, z})
463 .getResult();
464
465 mlir::Value result = cir::ExtractMemberOp::create(
466 builder, getLoc(expr->getExprLoc()), x.getType(), structResult, 0);
467 mlir::Value flag = cir::ExtractMemberOp::create(
468 builder, getLoc(expr->getExprLoc()), i1Ty, structResult, 1);
469
470 mlir::Type flagType = flagOutPtr.getElementType();
471 mlir::Value flagToStore =
472 cir::CastOp::create(builder, getLoc(expr->getExprLoc()), flagType,
473 cir::CastKind::int_to_bool, flag);
474 builder.createStore(getLoc(expr->getExprLoc()), flagToStore, flagOutPtr);
475 return result;
476 }
477 case AMDGPU::BI__builtin_amdgcn_div_fmas:
478 case AMDGPU::BI__builtin_amdgcn_div_fmasf:
479 return emitBuiltinWithOneOverloadedType<4>(expr, "amdgcn.div.fmas")
480 .getValue();
481 case AMDGPU::BI__builtin_amdgcn_mov_dpp8:
482 case AMDGPU::BI__builtin_amdgcn_mov_dpp:
483 case AMDGPU::BI__builtin_amdgcn_update_dpp: {
484 mlir::Location loc = getLoc(expr->getExprLoc());
485 unsigned iceArguments = 0;
487 getContext().GetBuiltinType(builtinId, error, &iceArguments);
488 assert(error == ASTContext::GE_None && "Should not codegen an error");
489 assert(expr->getNumArgs() == 5 || expr->getNumArgs() == 6 ||
490 expr->getNumArgs() == 2);
491
492 mlir::Type dataTy = convertType(expr->getArg(0)->getType());
493 unsigned size = cgm.getDataLayout().getTypeSizeInBits(dataTy);
494 cir::IntType intTy = builder.getUIntNTy(std::max(size, 32u));
495
496 bool isMovDpp8 = builtinId == AMDGPU::BI__builtin_amdgcn_mov_dpp8;
497 bool isMovDpp = builtinId == AMDGPU::BI__builtin_amdgcn_mov_dpp;
498 bool isUpdateDpp = builtinId == AMDGPU::BI__builtin_amdgcn_update_dpp;
499 llvm::StringRef intrinsicName =
500 isMovDpp8 ? "amdgcn.mov.dpp8" : "amdgcn.update.dpp";
501 cir::FuncType intrinsicTy =
502 getIntrinsicType(isMovDpp8 ? llvm::Intrinsic::amdgcn_mov_dpp8
503 : llvm::Intrinsic::amdgcn_update_dpp,
504 {intTy});
505
506 auto coerceTo = [&](mlir::Value from, mlir::Type to) -> mlir::Value {
507 if (from.getType() == to)
508 return from;
509 if (mlir::isa<cir::IntType>(from.getType()) &&
510 mlir::isa<cir::IntType>(to))
511 return builder.createIntCast(from, to);
512 return builder.createBitcast(from, to);
513 };
514
516 // __builtin_amdgcn_mov_dpp has no "old" operand at the source level, but
517 // the real intrinsic it lowers to requires one, so we synthesize a poison
518 // value for it since it is never meaningfully read.
519 if (isMovDpp)
520 args.push_back(builder.getConstant(loc, cir::PoisonAttr::get(intTy)));
521
522 // Number of builtin-level leading args that need zero-extend promotion when
523 // the data type is narrower than 32 bits.
524 unsigned numPromotedArgs = isUpdateDpp ? 2u : 1u;
525 for (unsigned i = 0; i != expr->getNumArgs(); ++i) {
526 mlir::Value v =
527 emitScalarOrConstFoldImmArg(iceArguments, i, expr->getArg(i));
528 if (i < numPromotedArgs && size < 32) {
529 mlir::Type sameWidthUTy = builder.getUIntNTy(size);
530 if (v.getType() != sameWidthUTy)
531 v = builder.createBitcast(v, sameWidthUTy);
532 v = builder.createIntCast(v, intTy);
533 }
534 args.push_back(coerceTo(v, intrinsicTy.getInput(i + unsigned(isMovDpp))));
535 }
536
537 mlir::Value result = builder.emitIntrinsicCallOp(loc, intrinsicName, intTy,
538 mlir::ValueRange(args));
539 if (size < 32 && !mlir::isa<cir::IntType>(dataTy))
540 result = builder.createIntCast(result, builder.getUIntNTy(size));
541 return coerceTo(result, dataTy);
542 }
543 case AMDGPU::BI__builtin_amdgcn_permlane16:
544 case AMDGPU::BI__builtin_amdgcn_permlanex16: {
545 llvm::StringRef intrinsicName =
546 builtinId == AMDGPU::BI__builtin_amdgcn_permlane16
547 ? "amdgcn.permlane16"
548 : "amdgcn.permlanex16";
549 return emitBuiltinWithOneOverloadedType<6>(expr, intrinsicName).getValue();
550 }
551 case AMDGPU::BI__builtin_amdgcn_permlane64:
552 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.permlane64")
553 .getValue();
554 case AMDGPU::BI__builtin_amdgcn_permlane_bcast:
555 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.permlane.bcast")
556 .getValue();
557 case AMDGPU::BI__builtin_amdgcn_permlane_up:
558 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.permlane.up")
559 .getValue();
560 case AMDGPU::BI__builtin_amdgcn_permlane_down:
561 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.permlane.down")
562 .getValue();
563 case AMDGPU::BI__builtin_amdgcn_permlane_xor:
564 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.permlane.xor")
565 .getValue();
566 case AMDGPU::BI__builtin_amdgcn_readlane:
567 return emitBuiltinWithOneOverloadedType<2>(expr, "amdgcn.readlane")
568 .getValue();
569 case AMDGPU::BI__builtin_amdgcn_readfirstlane:
570 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.readfirstlane")
571 .getValue();
572 case AMDGPU::BI__builtin_amdgcn_wave_shuffle:
573 return emitBuiltinWithOneOverloadedType<2>(expr, "amdgcn.wave.shuffle")
574 .getValue();
575 case AMDGPU::BI__builtin_amdgcn_div_fixup:
576 case AMDGPU::BI__builtin_amdgcn_div_fixupf:
577 case AMDGPU::BI__builtin_amdgcn_div_fixuph: {
578 mlir::Value src0 = emitScalarExpr(expr->getArg(0));
579 mlir::Value src1 = emitScalarExpr(expr->getArg(1));
580 mlir::Value src2 = emitScalarExpr(expr->getArg(2));
581 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()),
582 "amdgcn.div.fixup", src0.getType(),
583 mlir::ValueRange{src0, src1, src2});
584 }
585 case AMDGPU::BI__builtin_amdgcn_trig_preop:
586 case AMDGPU::BI__builtin_amdgcn_trig_preopf:
587 return emitBuiltinWithOneOverloadedType<2>(expr, "amdgcn.trig.preop")
588 .getValue();
589 case AMDGPU::BI__builtin_amdgcn_rcp:
590 case AMDGPU::BI__builtin_amdgcn_rcpf:
591 case AMDGPU::BI__builtin_amdgcn_rcph:
592 case AMDGPU::BI__builtin_amdgcn_rcp_bf16: {
593 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.rcp").getValue();
594 }
595 case AMDGPU::BI__builtin_amdgcn_sqrt:
596 case AMDGPU::BI__builtin_amdgcn_sqrtf:
597 case AMDGPU::BI__builtin_amdgcn_sqrth:
598 case AMDGPU::BI__builtin_amdgcn_sqrt_bf16: {
599 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.sqrt").getValue();
600 }
601 case AMDGPU::BI__builtin_amdgcn_rsq:
602 case AMDGPU::BI__builtin_amdgcn_rsqf:
603 case AMDGPU::BI__builtin_amdgcn_rsqh:
604 case AMDGPU::BI__builtin_amdgcn_rsq_bf16: {
605 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.rsq").getValue();
606 }
607 case AMDGPU::BI__builtin_amdgcn_rsq_clamp:
608 case AMDGPU::BI__builtin_amdgcn_rsq_clampf: {
609 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.rsq.clamp")
610 .getValue();
611 }
612 case AMDGPU::BI__builtin_amdgcn_sinf:
613 case AMDGPU::BI__builtin_amdgcn_sinh:
614 case AMDGPU::BI__builtin_amdgcn_sin_bf16: {
615 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.sin").getValue();
616 }
617 case AMDGPU::BI__builtin_amdgcn_cosf:
618 case AMDGPU::BI__builtin_amdgcn_cosh:
619 case AMDGPU::BI__builtin_amdgcn_cos_bf16: {
620 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.cos").getValue();
621 }
622 case AMDGPU::BI__builtin_amdgcn_dispatch_ptr:
623 return emitAMDGPUDispatchPtr(*this, getLoc(expr->getExprLoc()), expr);
624 case AMDGPU::BI__builtin_amdgcn_logf:
625 case AMDGPU::BI__builtin_amdgcn_log_bf16: {
626 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.log").getValue();
627 }
628 case AMDGPU::BI__builtin_amdgcn_exp2f:
629 case AMDGPU::BI__builtin_amdgcn_exp2_bf16: {
630 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.exp2").getValue();
631 }
632 case AMDGPU::BI__builtin_amdgcn_log_clampf: {
633 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.log.clamp")
634 .getValue();
635 }
636 case AMDGPU::BI__builtin_amdgcn_ldexp:
637 case AMDGPU::BI__builtin_amdgcn_ldexpf:
638 case AMDGPU::BI__builtin_amdgcn_ldexph: {
639 mlir::Value src0 = emitScalarExpr(expr->getArg(0));
640 mlir::Value src1 = emitScalarExpr(expr->getArg(1));
641 // For ldexph, the raw instruction has different behavior for out-of-bounds
642 // exponent values (implicit truncation instead of saturate to
643 // short_min/short_max), so truncate the exponent to i16 first.
644 mlir::Value exp =
645 builtinId == AMDGPU::BI__builtin_amdgcn_ldexph
646 ? cir::CastOp::create(builder, getLoc(expr->getExprLoc()),
647 builder.getSInt16Ty(),
648 cir::CastKind::integral, src1)
649 : src1;
650 return builder.emitIntrinsicCallOp(getLoc(expr->getExprLoc()), "ldexp",
651 src0.getType(),
652 mlir::ValueRange{src0, exp});
653 }
654 case AMDGPU::BI__builtin_amdgcn_frexp_mant:
655 case AMDGPU::BI__builtin_amdgcn_frexp_mantf:
656 case AMDGPU::BI__builtin_amdgcn_frexp_manth: {
657 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.frexp.mant")
658 .getValue();
659 }
660 case AMDGPU::BI__builtin_amdgcn_frexp_exp:
661 case AMDGPU::BI__builtin_amdgcn_frexp_expf:
662 case AMDGPU::BI__builtin_amdgcn_frexp_exph:
663 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.frexp.exp",
664 convertType(expr->getType()))
665 .getValue();
666 case AMDGPU::BI__builtin_amdgcn_fract:
667 case AMDGPU::BI__builtin_amdgcn_fractf:
668 case AMDGPU::BI__builtin_amdgcn_fracth:
669 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.fract").getValue();
670 case AMDGPU::BI__builtin_amdgcn_ubfe:
671 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.ubfe").getValue();
672 case AMDGPU::BI__builtin_amdgcn_sbfe:
673 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.sbfe").getValue();
674 case AMDGPU::BI__builtin_amdgcn_ballot_w32:
675 case AMDGPU::BI__builtin_amdgcn_ballot_w64:
676 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ballot",
677 convertType(expr->getType()))
678 .getValue();
679 case AMDGPU::BI__builtin_amdgcn_inverse_ballot_w32:
680 case AMDGPU::BI__builtin_amdgcn_inverse_ballot_w64:
681 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.inverse.ballot",
682 convertType(expr->getType()))
683 .getValue();
684 case AMDGPU::BI__builtin_amdgcn_tanhf:
685 case AMDGPU::BI__builtin_amdgcn_tanhh:
686 case AMDGPU::BI__builtin_amdgcn_tanh_bf16: {
687 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.tanh").getValue();
688 }
689 case AMDGPU::BI__builtin_amdgcn_uicmp:
690 case AMDGPU::BI__builtin_amdgcn_uicmpl:
691 case AMDGPU::BI__builtin_amdgcn_sicmp:
692 case AMDGPU::BI__builtin_amdgcn_sicmpl:
693 case AMDGPU::BI__builtin_amdgcn_fcmp:
694 case AMDGPU::BI__builtin_amdgcn_fcmpf: {
695 mlir::Value lhs = emitScalarExpr(expr->getArg(0));
696 mlir::Value rhs = emitScalarExpr(expr->getArg(1));
697
698 uint64_t imm =
699 expr->getArg(2)->EvaluateKnownConstInt(getContext()).getZExtValue();
700
701 cir::CmpOpKind pred;
702 switch (imm) {
703 case 0x1: // FCMP_OEQ
704 case 0x20: // ICMP_EQ
705 pred = cir::CmpOpKind::eq;
706 break;
707 case 0xe: // FCMP_UNE
708 case 0x21: // ICMP_NE
709 pred = cir::CmpOpKind::ne;
710 break;
711 case 0x2: // FCMP_OGT
712 case 0x22: // ICMP_UGT
713 case 0x26: // ICMP_SGT
714 pred = cir::CmpOpKind::gt;
715 break;
716 case 0x3: // FCMP_OGE
717 case 0x23: // ICMP_UGE
718 case 0x27: // ICMP_SGE
719 pred = cir::CmpOpKind::ge;
720 break;
721 case 0x4: // FCMP_OLT
722 case 0x24: // ICMP_ULT
723 case 0x28: // ICMP_SLT
724 pred = cir::CmpOpKind::lt;
725 break;
726 case 0x5: // FCMP_OLE
727 case 0x25: // ICMP_ULE
728 case 0x29: // ICMP_SLE
729 pred = cir::CmpOpKind::le;
730 break;
731 case 0x6: // FCMP_ONE
732 pred = cir::CmpOpKind::one;
733 break;
734 case 0x8: // FCMP_UNO
735 pred = cir::CmpOpKind::uno;
736 break;
737 default:
738 cgm.errorNYI(expr->getSourceRange(),
739 "amdgcn compare with unsupported predicate");
740 return mlir::Value{};
741 }
742
743 mlir::Location loc = getLoc(expr->getExprLoc());
744 mlir::Value cmp = builder.createCompare(loc, pred, lhs, rhs);
745 return builder.emitIntrinsicCallOp(loc, "amdgcn.ballot",
746 convertType(expr->getType()), cmp);
747 }
748 case AMDGPU::BI__builtin_amdgcn_class:
749 case AMDGPU::BI__builtin_amdgcn_classf:
750 case AMDGPU::BI__builtin_amdgcn_classh:
751 return emitBuiltinWithOneOverloadedType<2>(expr, "amdgcn.class",
752 convertType(expr->getType()))
753 .getValue();
754 case AMDGPU::BI__builtin_amdgcn_fmed3f:
755 case AMDGPU::BI__builtin_amdgcn_fmed3h:
756 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.fmed3").getValue();
757 case AMDGPU::BI__builtin_amdgcn_ds_append:
758 case AMDGPU::BI__builtin_amdgcn_ds_consume: {
759 mlir::Location loc = getLoc(expr->getExprLoc());
760 llvm::StringRef intrinsicName =
761 builtinId == AMDGPU::BI__builtin_amdgcn_ds_append ? "amdgcn.ds.append"
762 : "amdgcn.ds.consume";
763
764 mlir::Value ptr = emitScalarExpr(expr->getArg(0));
765 mlir::Value isVolatile = builder.getFalse(loc);
766 return builder.emitIntrinsicCallOp(loc, intrinsicName,
767 convertType(expr->getType()),
768 mlir::ValueRange{ptr, isVolatile});
769 }
770 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
771 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_v2i32:
772 case AMDGPU::BI__builtin_amdgcn_global_load_tr8_b64_v2i32:
774 expr, "amdgcn.global.load.tr.b64", convertType(expr->getType()))
775 .getValue();
776 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4i16:
777 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4f16:
778 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
779 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
780 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
781 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
782 case AMDGPU::BI__builtin_amdgcn_global_load_tr16_b128_v8i16:
783 case AMDGPU::BI__builtin_amdgcn_global_load_tr16_b128_v8f16:
784 case AMDGPU::BI__builtin_amdgcn_global_load_tr16_b128_v8bf16:
786 expr, "amdgcn.global.load.tr.b128", convertType(expr->getType()))
787 .getValue();
788 case AMDGPU::BI__builtin_amdgcn_global_load_tr4_b64_v2i32:
790 expr, "amdgcn.global.load.tr4.b64", convertType(expr->getType()))
791 .getValue();
792 case AMDGPU::BI__builtin_amdgcn_global_load_tr6_b96_v3i32:
794 expr, "amdgcn.global.load.tr6.b96", convertType(expr->getType()))
795 .getValue();
796 case AMDGPU::BI__builtin_amdgcn_ds_load_tr4_b64_v2i32:
797 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.load.tr4.b64",
798 convertType(expr->getType()))
799 .getValue();
800 case AMDGPU::BI__builtin_amdgcn_ds_load_tr6_b96_v3i32:
801 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.load.tr6.b96",
802 convertType(expr->getType()))
803 .getValue();
804 case AMDGPU::BI__builtin_amdgcn_ds_load_tr8_b64_v2i32:
805 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.load.tr8.b64",
806 convertType(expr->getType()))
807 .getValue();
808 case AMDGPU::BI__builtin_amdgcn_ds_load_tr16_b128_v8i16:
809 case AMDGPU::BI__builtin_amdgcn_ds_load_tr16_b128_v8f16:
810 case AMDGPU::BI__builtin_amdgcn_ds_load_tr16_b128_v8bf16:
811 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.load.tr16.b128",
812 convertType(expr->getType()))
813 .getValue();
814 case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
815 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.read.tr4.b64",
816 convertType(expr->getType()))
817 .getValue();
818 case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
819 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.read.tr8.b64",
820 convertType(expr->getType()))
821 .getValue();
822 case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
823 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.read.tr6.b96",
824 convertType(expr->getType()))
825 .getValue();
826 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16:
827 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4f16:
828 case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4bf16:
829 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.ds.read.tr16.b64",
830 convertType(expr->getType()))
831 .getValue();
832 case AMDGPU::BI__builtin_amdgcn_global_load_monitor_b32:
833 case AMDGPU::BI__builtin_amdgcn_global_load_monitor_b64:
834 case AMDGPU::BI__builtin_amdgcn_global_load_monitor_b128:
835 case AMDGPU::BI__builtin_amdgcn_flat_load_monitor_b32:
836 case AMDGPU::BI__builtin_amdgcn_flat_load_monitor_b64:
837 case AMDGPU::BI__builtin_amdgcn_flat_load_monitor_b128: {
838 cgm.errorNYI(expr->getSourceRange(),
839 std::string("unimplemented AMDGPU builtin call: ") +
840 getContext().BuiltinInfo.getName(builtinId));
841 return mlir::Value{};
842 }
843 case AMDGPU::BI__builtin_amdgcn_cluster_load_b32:
844 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.cluster.load.b32",
845 convertType(expr->getType()))
846 .getValue();
847 case AMDGPU::BI__builtin_amdgcn_cluster_load_b64:
848 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.cluster.load.b64",
849 convertType(expr->getType()))
850 .getValue();
851 case AMDGPU::BI__builtin_amdgcn_cluster_load_b128:
852 return emitBuiltinWithOneOverloadedType<3>(expr, "amdgcn.cluster.load.b128",
853 convertType(expr->getType()))
854 .getValue();
855 case AMDGPU::BI__builtin_amdgcn_load_to_lds:
857 expr, "amdgcn.load.to.lds",
858 cir::VoidType::get(builder.getContext()))
859 .getValue();
860 case AMDGPU::BI__builtin_amdgcn_load_async_to_lds:
862 expr, "amdgcn.load.async.to.lds",
863 cir::VoidType::get(builder.getContext()))
864 .getValue();
865 case AMDGPU::BI__builtin_amdgcn_cooperative_atomic_load_32x4B:
866 case AMDGPU::BI__builtin_amdgcn_cooperative_atomic_store_32x4B:
867 case AMDGPU::BI__builtin_amdgcn_cooperative_atomic_load_16x8B:
868 case AMDGPU::BI__builtin_amdgcn_cooperative_atomic_store_16x8B:
869 case AMDGPU::BI__builtin_amdgcn_cooperative_atomic_load_8x16B:
870 case AMDGPU::BI__builtin_amdgcn_cooperative_atomic_store_8x16B: {
871 cgm.errorNYI(expr->getSourceRange(),
872 std::string("unimplemented AMDGPU builtin call: ") +
873 getContext().BuiltinInfo.getName(builtinId));
874 return mlir::Value{};
875 }
876 case AMDGPU::BI__builtin_amdgcn_get_fpenv:
877 case AMDGPU::BI__builtin_amdgcn_set_fpenv: {
878 cgm.errorNYI(expr->getSourceRange(),
879 std::string("unimplemented AMDGPU builtin call: ") +
880 getContext().BuiltinInfo.getName(builtinId));
881 return mlir::Value{};
882 }
883 case AMDGPU::BI__builtin_amdgcn_processor_is: {
884 assert(cgm.getTriple().isSPIRV() &&
885 "__builtin_amdgcn_processor_is should never reach CodeGen for "
886 "concrete targets!");
887 StringRef proc = cast<clang::StringLiteral>(expr->getArg(0))->getString();
888 return emitAMDGPUPredicate(*this, expr, "is." + proc);
889 }
890 case AMDGPU::BI__builtin_amdgcn_is_invocable: {
891 assert(cgm.getTriple().isSPIRV() &&
892 "__builtin_amdgcn_is_invocable should never reach CodeGen for "
893 "concrete targets!");
894 auto *fd = cast<FunctionDecl>(
895 cast<DeclRefExpr>(expr->getArg(0))->getReferencedDeclOfCallee());
896 StringRef rf =
897 getContext().BuiltinInfo.getRequiredFeatures(fd->getBuiltinID());
898 return emitAMDGPUPredicate(*this, expr, "has." + rf);
899 }
900 case AMDGPU::BI__builtin_amdgcn_read_exec:
901 case AMDGPU::BI__builtin_amdgcn_read_exec_lo:
902 case AMDGPU::BI__builtin_amdgcn_read_exec_hi: {
903 // The exec mask is read as a ballot over an all-true predicate. The
904 // ballot is at least as wide as the wavefront, so that a wave64 target
905 // still reports both halves for the _lo/_hi forms.
906 mlir::Location loc = getLoc(expr->getExprLoc());
907 unsigned registerWidth =
908 builtinId == AMDGPU::BI__builtin_amdgcn_read_exec_lo ? 32 : 64;
909 unsigned ballotWidth =
910 std::max(getTarget().getGridValue().GV_Warp_Size, registerWidth);
911 cir::IntType ballotTy = builder.getUIntNTy(ballotWidth);
912
913 mlir::Value truePred = builder.getBool(true, loc).getResult();
914 mlir::Value result =
915 builder.emitIntrinsicCallOp(loc, "amdgcn.ballot", ballotTy, truePred);
916
917 if (builtinId == AMDGPU::BI__builtin_amdgcn_read_exec_hi)
918 result = builder.createShiftRight(loc, result, 32);
919 return builder.createIntCast(result, convertType(expr->getType()));
920 }
921 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray:
922 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_h:
923 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_l:
924 case AMDGPU::BI__builtin_amdgcn_image_bvh_intersect_ray_lh: {
925 cgm.errorNYI(expr->getSourceRange(),
926 std::string("unimplemented AMDGPU builtin call: ") +
927 getContext().BuiltinInfo.getName(builtinId));
928 return mlir::Value{};
929 }
930 case AMDGPU::BI__builtin_amdgcn_image_bvh8_intersect_ray:
931 case AMDGPU::BI__builtin_amdgcn_image_bvh_dual_intersect_ray: {
932 cgm.errorNYI(expr->getSourceRange(),
933 std::string("unimplemented AMDGPU builtin call: ") +
934 getContext().BuiltinInfo.getName(builtinId));
935 return mlir::Value{};
936 }
937 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_rtn:
938 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_push4_pop1_rtn:
939 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_push8_pop1_rtn:
940 case AMDGPU::BI__builtin_amdgcn_ds_bvh_stack_push8_pop2_rtn: {
941 cgm.errorNYI(expr->getSourceRange(),
942 std::string("unimplemented AMDGPU builtin call: ") +
943 getContext().BuiltinInfo.getName(builtinId));
944 return mlir::Value{};
945 }
946 case AMDGPU::BI__builtin_amdgcn_image_load_1d_v4f32_i32:
947 case AMDGPU::BI__builtin_amdgcn_image_load_1d_v4f16_i32:
949 "amdgcn.image.load.1d", false);
950 case AMDGPU::BI__builtin_amdgcn_image_load_1darray_v4f32_i32:
951 case AMDGPU::BI__builtin_amdgcn_image_load_1darray_v4f16_i32:
953 *this, expr, "amdgcn.image.load.1darray", false);
954 case AMDGPU::BI__builtin_amdgcn_image_load_2d_f32_i32:
955 case AMDGPU::BI__builtin_amdgcn_image_load_2d_v4f32_i32:
956 case AMDGPU::BI__builtin_amdgcn_image_load_2d_v4f16_i32:
958 "amdgcn.image.load.2d", false);
959 case AMDGPU::BI__builtin_amdgcn_image_load_2darray_f32_i32:
960 case AMDGPU::BI__builtin_amdgcn_image_load_2darray_v4f32_i32:
961 case AMDGPU::BI__builtin_amdgcn_image_load_2darray_v4f16_i32:
963 *this, expr, "amdgcn.image.load.2darray", false);
964 case AMDGPU::BI__builtin_amdgcn_image_load_3d_v4f32_i32:
965 case AMDGPU::BI__builtin_amdgcn_image_load_3d_v4f16_i32:
967 "amdgcn.image.load.3d", false);
968 case AMDGPU::BI__builtin_amdgcn_image_load_cube_v4f32_i32:
969 case AMDGPU::BI__builtin_amdgcn_image_load_cube_v4f16_i32:
971 "amdgcn.image.load.cube", false);
972 case AMDGPU::BI__builtin_amdgcn_image_load_mip_1d_v4f32_i32:
973 case AMDGPU::BI__builtin_amdgcn_image_load_mip_1d_v4f16_i32:
975 *this, expr, "amdgcn.image.load.mip.1d", false);
976 case AMDGPU::BI__builtin_amdgcn_image_load_mip_1darray_v4f32_i32:
977 case AMDGPU::BI__builtin_amdgcn_image_load_mip_1darray_v4f16_i32:
979 *this, expr, "amdgcn.image.load.mip.1darray", false);
980 case AMDGPU::BI__builtin_amdgcn_image_load_mip_2d_f32_i32:
981 case AMDGPU::BI__builtin_amdgcn_image_load_mip_2d_v4f32_i32:
982 case AMDGPU::BI__builtin_amdgcn_image_load_mip_2d_v4f16_i32:
984 *this, expr, "amdgcn.image.load.mip.2d", false);
985 case AMDGPU::BI__builtin_amdgcn_image_load_mip_2darray_f32_i32:
986 case AMDGPU::BI__builtin_amdgcn_image_load_mip_2darray_v4f32_i32:
987 case AMDGPU::BI__builtin_amdgcn_image_load_mip_2darray_v4f16_i32:
989 *this, expr, "amdgcn.image.load.mip.2darray", false);
990 case AMDGPU::BI__builtin_amdgcn_image_load_mip_3d_v4f32_i32:
991 case AMDGPU::BI__builtin_amdgcn_image_load_mip_3d_v4f16_i32:
993 *this, expr, "amdgcn.image.load.mip.3d", false);
994 case AMDGPU::BI__builtin_amdgcn_image_load_mip_cube_v4f32_i32:
995 case AMDGPU::BI__builtin_amdgcn_image_load_mip_cube_v4f16_i32:
997 *this, expr, "amdgcn.image.load.mip.cube", false);
998 case AMDGPU::BI__builtin_amdgcn_image_store_1d_v4f32_i32:
999 case AMDGPU::BI__builtin_amdgcn_image_store_1d_v4f16_i32:
1001 "amdgcn.image.store.1d", true);
1002 case AMDGPU::BI__builtin_amdgcn_image_store_1darray_v4f32_i32:
1003 case AMDGPU::BI__builtin_amdgcn_image_store_1darray_v4f16_i32:
1005 *this, expr, "amdgcn.image.store.1darray", true);
1006 case AMDGPU::BI__builtin_amdgcn_image_store_2d_f32_i32:
1007 case AMDGPU::BI__builtin_amdgcn_image_store_2d_v4f32_i32:
1008 case AMDGPU::BI__builtin_amdgcn_image_store_2d_v4f16_i32:
1010 "amdgcn.image.store.2d", true);
1011 case AMDGPU::BI__builtin_amdgcn_image_store_2darray_f32_i32:
1012 case AMDGPU::BI__builtin_amdgcn_image_store_2darray_v4f32_i32:
1013 case AMDGPU::BI__builtin_amdgcn_image_store_2darray_v4f16_i32:
1015 *this, expr, "amdgcn.image.store.2darray", true);
1016 case AMDGPU::BI__builtin_amdgcn_image_store_3d_v4f32_i32:
1017 case AMDGPU::BI__builtin_amdgcn_image_store_3d_v4f16_i32:
1019 "amdgcn.image.store.3d", true);
1020 case AMDGPU::BI__builtin_amdgcn_image_store_cube_v4f32_i32:
1021 case AMDGPU::BI__builtin_amdgcn_image_store_cube_v4f16_i32:
1023 "amdgcn.image.store.cube", true);
1024 case AMDGPU::BI__builtin_amdgcn_image_store_mip_1d_v4f32_i32:
1025 case AMDGPU::BI__builtin_amdgcn_image_store_mip_1d_v4f16_i32:
1027 *this, expr, "amdgcn.image.store.mip.1d", true);
1028 case AMDGPU::BI__builtin_amdgcn_image_store_mip_1darray_v4f32_i32:
1029 case AMDGPU::BI__builtin_amdgcn_image_store_mip_1darray_v4f16_i32:
1031 *this, expr, "amdgcn.image.store.mip.1darray", true);
1032 case AMDGPU::BI__builtin_amdgcn_image_store_mip_2d_f32_i32:
1033 case AMDGPU::BI__builtin_amdgcn_image_store_mip_2d_v4f32_i32:
1034 case AMDGPU::BI__builtin_amdgcn_image_store_mip_2d_v4f16_i32:
1036 *this, expr, "amdgcn.image.store.mip.2d", true);
1037 case AMDGPU::BI__builtin_amdgcn_image_store_mip_2darray_f32_i32:
1038 case AMDGPU::BI__builtin_amdgcn_image_store_mip_2darray_v4f32_i32:
1039 case AMDGPU::BI__builtin_amdgcn_image_store_mip_2darray_v4f16_i32:
1041 *this, expr, "amdgcn.image.store.mip.2darray", true);
1042 case AMDGPU::BI__builtin_amdgcn_image_store_mip_3d_v4f32_i32:
1043 case AMDGPU::BI__builtin_amdgcn_image_store_mip_3d_v4f16_i32:
1045 *this, expr, "amdgcn.image.store.mip.3d", true);
1046 case AMDGPU::BI__builtin_amdgcn_image_store_mip_cube_v4f32_i32:
1047 case AMDGPU::BI__builtin_amdgcn_image_store_mip_cube_v4f16_i32:
1049 *this, expr, "amdgcn.image.store.mip.cube", true);
1050 case AMDGPU::BI__builtin_amdgcn_image_sample_1d_v4f32_f32:
1051 case AMDGPU::BI__builtin_amdgcn_image_sample_1d_v4f16_f32:
1053 "amdgcn.image.sample.1d", false);
1054 case AMDGPU::BI__builtin_amdgcn_image_sample_1darray_v4f32_f32:
1055 case AMDGPU::BI__builtin_amdgcn_image_sample_1darray_v4f16_f32:
1057 *this, expr, "amdgcn.image.sample.1darray", false);
1058 case AMDGPU::BI__builtin_amdgcn_image_sample_2d_f32_f32:
1059 case AMDGPU::BI__builtin_amdgcn_image_sample_2d_v4f32_f32:
1060 case AMDGPU::BI__builtin_amdgcn_image_sample_2d_v4f16_f32:
1062 "amdgcn.image.sample.2d", false);
1063 case AMDGPU::BI__builtin_amdgcn_image_sample_2darray_f32_f32:
1064 case AMDGPU::BI__builtin_amdgcn_image_sample_2darray_v4f32_f32:
1065 case AMDGPU::BI__builtin_amdgcn_image_sample_2darray_v4f16_f32:
1067 *this, expr, "amdgcn.image.sample.2darray", false);
1068 case AMDGPU::BI__builtin_amdgcn_image_sample_3d_v4f32_f32:
1069 case AMDGPU::BI__builtin_amdgcn_image_sample_3d_v4f16_f32:
1071 "amdgcn.image.sample.3d", false);
1072 case AMDGPU::BI__builtin_amdgcn_image_sample_cube_v4f32_f32:
1073 case AMDGPU::BI__builtin_amdgcn_image_sample_cube_v4f16_f32:
1075 *this, expr, "amdgcn.image.sample.cube", false);
1076 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_1d_v4f32_f32:
1077 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_1d_v4f16_f32:
1079 *this, expr, "amdgcn.image.sample.lz.1d", false);
1080 case AMDGPU::BI__builtin_amdgcn_image_sample_l_1d_v4f32_f32:
1081 case AMDGPU::BI__builtin_amdgcn_image_sample_l_1d_v4f16_f32:
1083 *this, expr, "amdgcn.image.sample.l.1d", false);
1084 case AMDGPU::BI__builtin_amdgcn_image_sample_d_1d_v4f32_f32:
1085 case AMDGPU::BI__builtin_amdgcn_image_sample_d_1d_v4f16_f32:
1087 *this, expr, "amdgcn.image.sample.d.1d", false);
1088 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_2d_v4f32_f32:
1089 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_2d_v4f16_f32:
1090 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_2d_f32_f32:
1092 *this, expr, "amdgcn.image.sample.lz.2d", false);
1093 case AMDGPU::BI__builtin_amdgcn_image_sample_l_2d_v4f32_f32:
1094 case AMDGPU::BI__builtin_amdgcn_image_sample_l_2d_v4f16_f32:
1095 case AMDGPU::BI__builtin_amdgcn_image_sample_l_2d_f32_f32:
1097 *this, expr, "amdgcn.image.sample.l.2d", false);
1098 case AMDGPU::BI__builtin_amdgcn_image_sample_d_2d_v4f32_f32:
1099 case AMDGPU::BI__builtin_amdgcn_image_sample_d_2d_v4f16_f32:
1100 case AMDGPU::BI__builtin_amdgcn_image_sample_d_2d_f32_f32:
1102 *this, expr, "amdgcn.image.sample.d.2d", false);
1103 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_3d_v4f32_f32:
1104 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_3d_v4f16_f32:
1106 *this, expr, "amdgcn.image.sample.lz.3d", false);
1107 case AMDGPU::BI__builtin_amdgcn_image_sample_l_3d_v4f32_f32:
1108 case AMDGPU::BI__builtin_amdgcn_image_sample_l_3d_v4f16_f32:
1110 *this, expr, "amdgcn.image.sample.l.3d", false);
1111 case AMDGPU::BI__builtin_amdgcn_image_sample_d_3d_v4f32_f32:
1112 case AMDGPU::BI__builtin_amdgcn_image_sample_d_3d_v4f16_f32:
1114 *this, expr, "amdgcn.image.sample.d.3d", false);
1115 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_cube_v4f32_f32:
1116 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_cube_v4f16_f32:
1118 *this, expr, "amdgcn.image.sample.lz.cube", false);
1119 case AMDGPU::BI__builtin_amdgcn_image_sample_l_cube_v4f32_f32:
1120 case AMDGPU::BI__builtin_amdgcn_image_sample_l_cube_v4f16_f32:
1122 *this, expr, "amdgcn.image.sample.l.cube", false);
1123 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_1darray_v4f32_f32:
1124 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_1darray_v4f16_f32:
1126 *this, expr, "amdgcn.image.sample.lz.1darray", false);
1127 case AMDGPU::BI__builtin_amdgcn_image_sample_l_1darray_v4f32_f32:
1128 case AMDGPU::BI__builtin_amdgcn_image_sample_l_1darray_v4f16_f32:
1130 *this, expr, "amdgcn.image.sample.l.1darray", false);
1131 case AMDGPU::BI__builtin_amdgcn_image_sample_d_1darray_v4f32_f32:
1132 case AMDGPU::BI__builtin_amdgcn_image_sample_d_1darray_v4f16_f32:
1134 *this, expr, "amdgcn.image.sample.d.1darray", false);
1135 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_2darray_v4f32_f32:
1136 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_2darray_v4f16_f32:
1137 case AMDGPU::BI__builtin_amdgcn_image_sample_lz_2darray_f32_f32:
1139 *this, expr, "amdgcn.image.sample.lz.2darray", false);
1140 case AMDGPU::BI__builtin_amdgcn_image_sample_l_2darray_v4f32_f32:
1141 case AMDGPU::BI__builtin_amdgcn_image_sample_l_2darray_v4f16_f32:
1142 case AMDGPU::BI__builtin_amdgcn_image_sample_l_2darray_f32_f32:
1144 *this, expr, "amdgcn.image.sample.l.2darray", false);
1145 case AMDGPU::BI__builtin_amdgcn_image_sample_d_2darray_v4f32_f32:
1146 case AMDGPU::BI__builtin_amdgcn_image_sample_d_2darray_v4f16_f32:
1147 case AMDGPU::BI__builtin_amdgcn_image_sample_d_2darray_f32_f32:
1149 *this, expr, "amdgcn.image.sample.d.2darray", false);
1150 case AMDGPU::BI__builtin_amdgcn_image_gather4_lz_2d_v4f32_f32:
1151 case AMDGPU::BI__builtin_amdgcn_image_gather4_lz_2d_v4f16_f32:
1153 *this, expr, "amdgcn.image.gather4.lz.2d", false);
1154 case AMDGPU::BI__builtin_amdgcn_mfma_scale_f32_16x16x128_f8f6f4:
1155 case AMDGPU::BI__builtin_amdgcn_mfma_scale_f32_32x32x64_f8f6f4: {
1156 cgm.errorNYI(expr->getSourceRange(),
1157 std::string("unimplemented AMDGPU builtin call: ") +
1158 getContext().BuiltinInfo.getName(builtinId));
1159 return mlir::Value{};
1160 }
1161 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32:
1162 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w32:
1163 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64:
1164 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_tied_w64:
1165 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32:
1166 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w32:
1167 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64:
1168 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_tied_w64:
1169 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32:
1170 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64:
1171 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32:
1172 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64:
1173 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32:
1174 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64:
1175 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32:
1176 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64:
1177 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w32_gfx12:
1178 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x16_bf16_w64_gfx12:
1179 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w32_gfx12:
1180 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x16_f16_w64_gfx12:
1181 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12:
1182 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf16_w64_gfx12:
1183 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w32_gfx12:
1184 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_f16_w64_gfx12:
1185 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w32_gfx12:
1186 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu4_w64_gfx12:
1187 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w32_gfx12:
1188 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x16_iu8_w64_gfx12:
1189 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w32_gfx12:
1190 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_fp8_w64_gfx12:
1191 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w32_gfx12:
1192 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_fp8_bf8_w64_gfx12:
1193 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w32_gfx12:
1194 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_fp8_w64_gfx12:
1195 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w32_gfx12:
1196 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x16_bf8_bf8_w64_gfx12:
1197 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w32_gfx12:
1198 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x32_iu4_w64_gfx12: {
1199 cgm.errorNYI(expr->getSourceRange(),
1200 std::string("unimplemented AMDGPU builtin call: ") +
1201 getContext().BuiltinInfo.getName(builtinId));
1202 return mlir::Value{};
1203 }
1204 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w32:
1205 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_f16_w64:
1206 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w32:
1207 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf16_w64:
1208 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w32:
1209 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x32_f16_w64:
1210 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w32:
1211 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x32_bf16_w64:
1212 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w32:
1213 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu8_w64:
1214 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w32:
1215 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x32_iu4_w64:
1216 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w32:
1217 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x64_iu4_w64:
1218 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w32:
1219 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_fp8_w64:
1220 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w32:
1221 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_fp8_bf8_w64:
1222 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w32:
1223 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_fp8_w64:
1224 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w32:
1225 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x32_bf8_bf8_w64: {
1226 cgm.errorNYI(expr->getSourceRange(),
1227 std::string("unimplemented AMDGPU builtin call: ") +
1228 getContext().BuiltinInfo.getName(builtinId));
1229 return mlir::Value{};
1230 }
1231 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x4_f32:
1232 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x32_bf16:
1233 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x32_f16:
1234 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x32_f16:
1235 case AMDGPU::BI__builtin_amdgcn_wmma_bf16_16x16x32_bf16:
1236 case AMDGPU::BI__builtin_amdgcn_wmma_bf16f32_16x16x32_bf16:
1237 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_fp8_fp8:
1238 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_fp8_bf8:
1239 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_bf8_fp8:
1240 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x64_bf8_bf8:
1241 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_fp8_fp8:
1242 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_fp8_bf8:
1243 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_bf8_fp8:
1244 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x64_bf8_bf8:
1245 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_fp8_fp8:
1246 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_fp8_bf8:
1247 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_bf8_fp8:
1248 case AMDGPU::BI__builtin_amdgcn_wmma_f16_16x16x128_bf8_bf8:
1249 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_fp8_fp8:
1250 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_fp8_bf8:
1251 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_bf8_fp8:
1252 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_bf8_bf8:
1253 case AMDGPU::BI__builtin_amdgcn_wmma_i32_16x16x64_iu8:
1254 case AMDGPU::BI__builtin_amdgcn_wmma_f32_16x16x128_f8f6f4:
1255 case AMDGPU::BI__builtin_amdgcn_wmma_f32_32x16x128_f4:
1256 case AMDGPU::BI__builtin_amdgcn_wmma_scale_f32_16x16x128_f8f6f4:
1257 case AMDGPU::BI__builtin_amdgcn_wmma_scale16_f32_16x16x128_f8f6f4:
1258 case AMDGPU::BI__builtin_amdgcn_wmma_scale_f32_32x16x128_f4:
1259 case AMDGPU::BI__builtin_amdgcn_wmma_scale16_f32_32x16x128_f4: {
1260 cgm.errorNYI(expr->getSourceRange(),
1261 std::string("unimplemented AMDGPU builtin call: ") +
1262 getContext().BuiltinInfo.getName(builtinId));
1263 return mlir::Value{};
1264 }
1265 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x64_f16:
1266 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x64_bf16:
1267 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x64_f16:
1268 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16_16x16x64_bf16:
1269 case AMDGPU::BI__builtin_amdgcn_swmmac_bf16f32_16x16x64_bf16:
1270 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_fp8_fp8:
1271 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_fp8_bf8:
1272 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_bf8_fp8:
1273 case AMDGPU::BI__builtin_amdgcn_swmmac_f32_16x16x128_bf8_bf8:
1274 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_fp8_fp8:
1275 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_fp8_bf8:
1276 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_bf8_fp8:
1277 case AMDGPU::BI__builtin_amdgcn_swmmac_f16_16x16x128_bf8_bf8:
1278 case AMDGPU::BI__builtin_amdgcn_swmmac_i32_16x16x128_iu8: {
1279 cgm.errorNYI(expr->getSourceRange(),
1280 std::string("unimplemented AMDGPU builtin call: ") +
1281 getContext().BuiltinInfo.getName(builtinId));
1282 return mlir::Value{};
1283 }
1284 // amdgcn workgroup size
1285 case AMDGPU::BI__builtin_amdgcn_workgroup_size_x:
1286 return emitAMDGPUWorkGroupSize(*this, getLoc(expr->getExprLoc()), 0);
1287 case AMDGPU::BI__builtin_amdgcn_workgroup_size_y:
1288 return emitAMDGPUWorkGroupSize(*this, getLoc(expr->getExprLoc()), 1);
1289 case AMDGPU::BI__builtin_amdgcn_workgroup_size_z:
1290 return emitAMDGPUWorkGroupSize(*this, getLoc(expr->getExprLoc()), 2);
1291 // amdgcn grid size
1292 case AMDGPU::BI__builtin_amdgcn_grid_size_x:
1293 return emitAMDGPUGridSize(*this, getLoc(expr->getExprLoc()), 0);
1294 case AMDGPU::BI__builtin_amdgcn_grid_size_y:
1295 return emitAMDGPUGridSize(*this, getLoc(expr->getExprLoc()), 1);
1296 case AMDGPU::BI__builtin_amdgcn_grid_size_z:
1297 return emitAMDGPUGridSize(*this, getLoc(expr->getExprLoc()), 2);
1298 case AMDGPU::BI__builtin_amdgcn_alignbit: {
1299 mlir::Value arg0 = emitScalarExpr(expr->getArg(0));
1300 mlir::Value arg1 = emitScalarExpr(expr->getArg(1));
1301 mlir::Value arg2 = emitScalarExpr(expr->getArg(2));
1302 mlir::Location loc = getLoc(expr->getExprLoc());
1303 mlir::Type ty = convertType(expr->getType());
1304 return cir::FshrOp::create(builder, loc, ty, arg0, arg1, arg2).getResult();
1305 }
1306 case AMDGPU::BI__builtin_amdgcn_fence: {
1307 // The scope uses AMDGPU spelling on every target, like mapScopeToSPIRV.
1308 const llvm::Triple &triple = getTarget().getTriple();
1309 std::optional<std::pair<llvm::AtomicScope, bool>> parsed;
1310 if (std::optional<std::string> name =
1311 expr->getArg(1)->tryEvaluateString(getContext())) {
1312 parsed = llvm::parseAMDGPUAtomicScopeIRString(*name);
1313 if (!parsed && triple.isSPIRV())
1314 parsed = llvm::parseAtomicScopeIRString(triple, *name);
1315 }
1316 // SPIR-V drops one-as, AMDGPU needs a CIR sync scope for it.
1317 if (!parsed || (parsed->second && !triple.isSPIRV())) {
1318 cgm.errorNYI(expr->getSourceRange(), "__builtin_amdgcn_fence scope");
1319 return mlir::Value{};
1320 }
1321 // Sorted and unique, like MMRAMetadata::appendTags.
1323 addrSpaces.reserve(expr->getNumArgs() - 2);
1324 for (unsigned i = 2; i < expr->getNumArgs(); ++i) {
1325 if (std::optional<std::string> as =
1326 expr->getArg(i)->tryEvaluateString(getContext()))
1327 addrSpaces.push_back(std::move(*as));
1328 else
1329 cgm.error(expr->getExprLoc(),
1330 "expected an address space name as a string literal");
1331 }
1332 llvm::sort(addrSpaces);
1333 addrSpaces.erase(llvm::unique(addrSpaces), addrSpaces.end());
1335 mmras.reserve(addrSpaces.size());
1336 for (const std::string &as : addrSpaces)
1337 mmras.push_back(mlir::LLVM::MMRATagAttr::get(
1338 &getMLIRContext(), "amdgpu-synchronize-as", as));
1339
1340 auto fence = cir::AtomicFenceOp::create(
1341 builder, getLoc(expr->getExprLoc()),
1342 decodeAtomicOrder(expr->getArg(0), getContext()),
1343 cir::SyncScopeKindAttr::get(&getMLIRContext(),
1344 convertAtomicScopeToCIR(parsed->first)));
1345 if (!mmras.empty())
1346 fence->setAttr(mlir::LLVM::LLVMDialect::getMmraAttrName(),
1347 mmras.size() == 1 ? mmras.front()
1348 : builder.getArrayAttr(mmras));
1349 return mlir::Value{};
1350 }
1351 case AMDGPU::BI__builtin_amdgcn_atomic_inc32:
1352 case AMDGPU::BI__builtin_amdgcn_atomic_inc64:
1353 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::UIncWrap,
1354 /*hasVolatileArg=*/false);
1355 case AMDGPU::BI__builtin_amdgcn_atomic_dec32:
1356 case AMDGPU::BI__builtin_amdgcn_atomic_dec64:
1357 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::UDecWrap,
1358 /*hasVolatileArg=*/false);
1359 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f64:
1360 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_f32:
1361 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f32:
1362 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_f64:
1363 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f32:
1364 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_f64:
1365 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2f16:
1366 case AMDGPU::BI__builtin_amdgcn_ds_atomic_fadd_v2bf16:
1367 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2f16:
1368 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2f16:
1369 case AMDGPU::BI__builtin_amdgcn_global_atomic_fadd_v2bf16:
1370 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fadd_v2bf16:
1371 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::Add,
1372 /*hasVolatileArg=*/false);
1373 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmin_f64:
1374 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmin_f64:
1375 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::Min,
1376 /*hasVolatileArg=*/false);
1377 case AMDGPU::BI__builtin_amdgcn_global_atomic_fmax_f64:
1378 case AMDGPU::BI__builtin_amdgcn_flat_atomic_fmax_f64:
1379 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::Max,
1380 /*hasVolatileArg=*/false);
1381 // The ds_ float forms are the same operations with the volatile flag spelled
1382 // out as an argument.
1383 case AMDGPU::BI__builtin_amdgcn_ds_faddf:
1384 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::Add,
1385 /*hasVolatileArg=*/true);
1386 case AMDGPU::BI__builtin_amdgcn_ds_fminf:
1387 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::Min,
1388 /*hasVolatileArg=*/true);
1389 case AMDGPU::BI__builtin_amdgcn_ds_fmaxf:
1390 return emitAMDGPUAtomicRMW(*this, expr, cir::AtomicFetchKind::Max,
1391 /*hasVolatileArg=*/true);
1392 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtn:
1393 case AMDGPU::BI__builtin_amdgcn_s_sendmsg_rtnl:
1394 return emitBuiltinWithOneOverloadedType<1>(expr, "amdgcn.s.sendmsg.rtn",
1395 convertType(expr->getType()))
1396 .getValue();
1397 case AMDGPU::BI__builtin_amdgcn_permlane16_swap:
1398 case AMDGPU::BI__builtin_amdgcn_permlane32_swap: {
1399 cgm.errorNYI(expr->getSourceRange(),
1400 std::string("unimplemented AMDGPU builtin call: ") +
1401 getContext().BuiltinInfo.getName(builtinId));
1402 return mlir::Value{};
1403 }
1404 case AMDGPU::BI__builtin_amdgcn_bitop3_b32:
1405 case AMDGPU::BI__builtin_amdgcn_bitop3_b16:
1406 return emitBuiltinWithOneOverloadedType<4>(expr, "amdgcn.bitop3")
1407 .getValue();
1408 case AMDGPU::BI__builtin_amdgcn_make_buffer_rsrc: {
1409 cgm.errorNYI(expr->getSourceRange(),
1410 std::string("unimplemented AMDGPU builtin call: ") +
1411 getContext().BuiltinInfo.getName(builtinId));
1412 return mlir::Value{};
1413 }
1414 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b8:
1415 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b16:
1416 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b32:
1417 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b64:
1418 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b96:
1419 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_b128: {
1420 cgm.errorNYI(expr->getSourceRange(),
1421 std::string("unimplemented AMDGPU builtin call: ") +
1422 getContext().BuiltinInfo.getName(builtinId));
1423 return mlir::Value{};
1424 }
1425 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_format_v4f32:
1426 case AMDGPU::BI__builtin_amdgcn_raw_buffer_store_format_v4f16:
1428 expr, "amdgcn.raw.ptr.buffer.store.format",
1429 cir::VoidType::get(builder.getContext()))
1430 .getValue();
1431 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_format_v4f32:
1432 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_format_v4f16:
1434 expr, "amdgcn.raw.ptr.buffer.load.format",
1435 convertType(expr->getType()))
1436 .getValue();
1437 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b8:
1438 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b16:
1439 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b32:
1440 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b64:
1441 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b96:
1442 case AMDGPU::BI__builtin_amdgcn_raw_buffer_load_b128: {
1443 cgm.errorNYI(expr->getSourceRange(),
1444 std::string("unimplemented AMDGPU builtin call: ") +
1445 getContext().BuiltinInfo.getName(builtinId));
1446 return mlir::Value{};
1447 }
1448 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_add_i32:
1450 expr, "amdgcn.raw.ptr.buffer.atomic.add")
1451 .getValue();
1452 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fadd_f32:
1453 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fadd_f64:
1454 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fadd_v2f16:
1456 expr, "amdgcn.raw.ptr.buffer.atomic.fadd")
1457 .getValue();
1458 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fmin_f32:
1459 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fmin_f64:
1461 expr, "amdgcn.raw.ptr.buffer.atomic.fmin")
1462 .getValue();
1463 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fmax_f32:
1464 case AMDGPU::BI__builtin_amdgcn_raw_ptr_buffer_atomic_fmax_f64:
1466 expr, "amdgcn.raw.ptr.buffer.atomic.fmax")
1467 .getValue();
1468 case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
1470 expr, "amdgcn.s.prefetch.data",
1471 cir::VoidType::get(builder.getContext()))
1472 .getValue();
1473 case AMDGPU::BI__builtin_amdgcn_s_prefetch_inst:
1475 expr, "amdgcn.s.prefetch.inst",
1476 cir::VoidType::get(builder.getContext()))
1477 .getValue();
1478 case Builtin::BIlogbf:
1479 case Builtin::BI__builtin_logbf:
1480 return emitLogbBuiltin(*this, expr, llvm::APFloat::IEEEsingle());
1481 case Builtin::BIlogb:
1482 case Builtin::BI__builtin_logb:
1483 return emitLogbBuiltin(*this, expr, llvm::APFloat::IEEEdouble());
1484 case Builtin::BIscalbnf:
1485 case Builtin::BI__builtin_scalbnf:
1486 case Builtin::BIscalbn:
1487 case Builtin::BI__builtin_scalbn: {
1489 *this, expr, "ldexp", "experimental.constrained.ldexp");
1490 }
1491 default:
1492 return std::nullopt;
1493 }
1494}
static mlir::Value emitAMDGPUWorkGroupID(CIRGenFunction &cgf, mlir::Location loc, unsigned index)
static mlir::Value emitLogbBuiltin(CIRGenFunction &cgf, const CallExpr *e, const llvm::fltSemantics &fSem)
static mlir::Value emitAMDGCNImageOverloadedReturnType(CIRGenFunction &cgf, const CallExpr *e, llvm::StringRef intrinsicName, bool isImageStore)
static mlir::Value emitAMDGPUInvariantLoad(CIRGenFunction &cgf, mlir::Location loc, mlir::Value base, mlir::Value offset, mlir::Type ty, CharUnits align, cir::PtrOffsetFlags flags=cir::PtrOffsetFlags::None)
static mlir::Value emitAMDGPUWorkGroupSizeV5(CIRGenFunction &cgf, mlir::Location loc, unsigned index)
static cir::SyncScopeKind convertAtomicScopeToCIR(llvm::AtomicScope scope)
static mlir::Value emitAMDGPUImplicitArgPtr(CIRGenFunction &cgf, mlir::Location loc)
static mlir::Value emitAMDGPUGridSize(CIRGenFunction &cgf, mlir::Location loc, unsigned index)
static mlir::Value emitAMDGPUWorkGroupSizeV4(CIRGenFunction &cgf, mlir::Location loc, unsigned index)
static mlir::Value emitAMDGPUWorkGroupSize(CIRGenFunction &cgf, mlir::Location loc, unsigned index)
static cir::SyncScopeKind decodeAMDGPUSyncScope(const Expr *arg)
Map an AMDGPU sync-scope string-literal argument onto cir::SyncScopeKind.
static mlir::Value emitAMDGPUConstantPtrIntrinsic(CIRGenFunction &cgf, mlir::Location loc, llvm::StringRef name)
static mlir::Value emitAMDGPUAtomicRMW(CIRGenFunction &cgf, const CallExpr *expr, cir::AtomicFetchKind binOp, bool hasVolatileArg)
Emit one of the AMDGPU raw hardware atomic builtins as a cir.atomic.fetch.
static mlir::Value emitAMDGPUPredicate(CIRGenFunction &cgf, const CallExpr *e, const llvm::Twine &name)
static mlir::Value emitAMDGPUDispatchPtr(CIRGenFunction &cgf, mlir::Location loc, const CallExpr *e=nullptr)
static cir::MemOrder decodeAtomicOrder(const Expr *arg, ASTContext &ctx)
Map a constant integral to memory order.
static mlir::Value emitBinaryExpMaybeConstrainedFPBuiltin(CIRGenFunction &cgf, const CallExpr *e, llvm::StringRef intrinsicName, llvm::StringRef constrainedIntrinsicName)
static QualType getPointeeType(const MemRegion *R)
Enumerates target-specific builtins in their own namespaces within namespace clang.
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowFlags flags=OverflowFlags::None)
mlir::Value createNSWAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
mlir::Value createBoolToInt(mlir::Value src, mlir::Type newTy)
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowFlags flags=OverflowFlags::None)
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride, cir::PtrOffsetFlags flags=cir::PtrOffsetFlags::None)
cir::GetGlobalOp createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)
mlir::Value createIntCast(mlir::Value src, mlir::Type newTy)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
cir::CmpOp createCompare(mlir::Location loc, cir::CmpOpKind kind, mlir::Value lhs, mlir::Value rhs)
mlir::Value createSelect(mlir::Location loc, mlir::Value condition, mlir::Value trueValue, mlir::Value falseValue)
cir::ConstantOp getConstantInt(mlir::Location loc, mlir::Type ty, int64_t value)
cir::PointerType getVoidPtrTy(clang::LangAS langAS=clang::LangAS::Default)
bool getIsFPConstrained() const
Query for the use of constrained floating point math.
mlir::Value createAddrSpaceCast(mlir::Location loc, mlir::Value src, mlir::Type newTy)
cir::BoolType getBoolTy()
C++ view class that accepts both !cir.struct and !cir.union types.
Definition CIRTypes.h:153
static llvm::SmallVector< RecordMemberKind > getAllDataKinds(llvm::ArrayRef< mlir::Type > members)
One Data kind per member.
Definition CIRTypes.cpp:161
APSInt & getInt()
Definition APValue.h:577
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:246
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
Builtin::Context & BuiltinInfo
Definition ASTContext.h:864
CanQualType IntTy
QualType GetBuiltinType(unsigned ID, GetBuiltinTypeError &Error, unsigned *IntegerConstantArgs=nullptr) const
Return the type for the specified builtin.
@ GE_None
No error.
const char * getRequiredFeatures(unsigned ID) const
Definition Builtins.cpp:105
mlir::Type getElementType() const
Definition Address.h:125
Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const
Return address with different element type, a bitcast pointer, and the same alignment.
mlir::Value emitRawPointer() const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
Definition Address.h:112
cir::ConstantOp getUInt64(uint64_t c, mlir::Location loc)
mlir::Value emitIntrinsicCallOp(mlir::Location loc, const llvm::StringRef str, const mlir::Type &resTy, Operands &&...op)
cir::LoadOp createAlignedLoad(mlir::Location loc, mlir::Type ty, mlir::Value ptr, llvm::MaybeAlign align)
cir::StructType getAnonRecordTy(llvm::ArrayRef< mlir::Type > members, bool packed, llvm::ArrayRef< cir::RecordMemberKind > memberKinds)
Get a CIR anonymous struct type.
mlir::Type convertType(clang::QualType t)
const clang::LangOptions & getLangOpts() const
const TargetInfo & getTarget() const
Address emitPointerWithAlignment(const clang::Expr *expr, LValueBaseInfo *baseInfo=nullptr, TBAAAccessInfo *tbaaInfo=nullptr)
Given an expression with a pointer type, emit the value and compute our best estimate of the alignmen...
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
RValue emitBuiltinWithOneOverloadedType(const CallExpr *e, llvm::StringRef intrinName, mlir::Type resultType={})
Emit a simple LLVM intrinsic that takes N scalar arguments.
std::optional< mlir::Value > emitAMDGPUBuiltinExpr(unsigned builtinID, const CallExpr *expr)
Emit a call to an AMDGPU builtin function.
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
CIRGenBuilderTy & getBuilder()
cir::FuncType getIntrinsicType(llvm::Intrinsic::ID id, llvm::ArrayRef< mlir::Type > overloadTys={})
Return the CIR signature of the LLVM intrinsic id, resolving its overloaded types to overloadTys.
mlir::MLIRContext & getMLIRContext()
clang::ASTContext & getContext() const
mlir::Value emitScalarOrConstFoldImmArg(unsigned iceArguments, unsigned idx, const Expr *argExpr)
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
cir::GlobalOp createGlobalOp(mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::ptr::MemorySpaceAttrInterface addrSpace={}, mlir::Operation *insertPoint=nullptr)
mlir::Operation * getGlobalValue(llvm::StringRef ref)
mlir::MLIRContext & getMLIRContext()
mlir::Value getValue() const
Return the value of this scalar value.
Definition CIRGenValue.h:58
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition Expr.h:3012
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Definition Expr.h:3216
unsigned getNumArgs() const
getNumArgs - Return the number of actual arguments to this call.
Definition Expr.h:3203
This is an opaque type for sizes expressed in character units.
Definition CharUnits.h:38
static constexpr CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:58
This represents one expression.
Definition Expr.h:114
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:283
QualType getType() const
Definition Expr.h:146
PointerType - C99 6.7.5.1 - Pointer Declarators.
Definition TypeBase.h:3404
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isVolatileQualified() const
Determine whether this type is volatile-qualified.
Definition TypeBase.h:8764
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:343
TargetOptions & getTargetOpts() const
Retrieve the target options.
Definition TargetInfo.h:334
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
llvm::CodeObjectVersionKind CodeObjectVersion
Code object version for AMDGPU.
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9604
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
PtrOffsetFlags
No-wrap flags of a pointer offset computation: the subset of llvm::GEPNoWrapFlags that cir....
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
Top level wrappers for InstallAPI frontend operations.
U cast(CodeGen::Address addr)
Definition Address.h:327
static bool opCallAttrs()
static bool opLoadRangeNoundefMetadata()
EvalResult is a struct with detailed info about an evaluated expression.
Definition Expr.h:667
APValue Val
Val - This is the value the expression can be folded to.
Definition Expr.h:669
#define exp(__x)
Definition tgmath.h:431
#define fabs(__x)
Definition tgmath.h:549
#define remainder(__x, __y)
Definition tgmath.h:1090