clang 23.0.0git
CIRGenCUDANV.cpp
Go to the documentation of this file.
1//========- CIRGenCUDANV.cpp - Interface to NVIDIA CUDA Runtime -----=========//
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 provides a class for CUDA code generation targeting the NVIDIA CUDA
10// runtime library.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CIRGenCUDARuntime.h"
15#include "CIRGenCXXABI.h"
16#include "CIRGenFunction.h"
17#include "CIRGenModule.h"
18#include "mlir/IR/Operation.h"
20#include "clang/AST/Attrs.inc"
21#include "clang/AST/Decl.h"
24#include "clang/Basic/Cuda.h"
27#include "llvm/Support/Casting.h"
28
29using namespace clang;
30using namespace clang::CIRGen;
31
32namespace {
33
34class CIRGenNVCUDARuntime : public CIRGenCUDARuntime {
35protected:
36 StringRef prefix;
37
38 // Map a device stub function to a symbol for identifying kernel in host
39 // code. For CUDA, the symbol for identifying the kernel is the same as the
40 // device stub function. For HIP, they are different.
41 llvm::StringMap<mlir::Operation *> kernelHandles;
42
43 // Map a kernel handle to the kernel stub.
44 llvm::DenseMap<mlir::Operation *, mlir::Operation *> kernelStubs;
45
46 struct VarInfo {
47 cir::GlobalOp var;
48 const VarDecl *d;
49 cir::CUDADeviceVarKind flags;
50 };
51 llvm::SmallVector<VarInfo, 16> deviceVars;
52
53 // Mangle context for device.
54 std::unique_ptr<MangleContext> deviceMC;
55
56private:
57 void emitDeviceStubBodyNew(CIRGenFunction &cgf, cir::FuncOp fn,
58 FunctionArgList &args);
59 mlir::Value prepareKernelArgs(CIRGenFunction &cgf, mlir::Location loc,
60 FunctionArgList &args);
61 mlir::Operation *getKernelHandle(cir::FuncOp fn, GlobalDecl gd) override;
62
63 mlir::Operation *getKernelStub(mlir::Operation *handle) override {
64 auto it = kernelStubs.find(handle);
65 assert(it != kernelStubs.end());
66 return it->second;
67 }
68 std::string addPrefixToName(StringRef funcName) const;
69 std::string addUnderscoredPrefixToName(StringRef funcName) const;
70
71public:
72 CIRGenNVCUDARuntime(CIRGenModule &cgm);
73 ~CIRGenNVCUDARuntime();
74
75 void emitDeviceStub(CIRGenFunction &cgf, cir::FuncOp fn,
76 FunctionArgList &args) override;
77
78 void handleVarRegistration(const VarDecl *vd, cir::GlobalOp var) override;
79 void finalizeModule() override;
80 void handleGlobalReplace(cir::GlobalOp oldGV, cir::GlobalOp newGV) override;
81
82 void internalizeDeviceSideVar(const VarDecl *d,
83 cir::GlobalLinkageKind &linkage) override;
84
85 std::string getDeviceSideName(const NamedDecl *nd) override;
86
87 void registerDeviceVar(const VarDecl *vd, cir::GlobalOp &var, bool isExtern,
88 bool isConstant) {
89 // Attach the device var attribute to the GlobalOp
90 auto &builder = cgm.getBuilder();
91 var->setAttr(cir::CUDAVarRegistrationInfoAttr::getMnemonic(),
92 cir::CUDAVarRegistrationInfoAttr::get(
93 builder.getContext(),
94 getDeviceSideName(cast<NamedDecl>(vd)),
95 cir::CUDADeviceVarKind::Variable, isExtern, isConstant,
96 vd->hasAttr<HIPManagedAttr>()));
97 deviceVars.push_back({
98 var,
99 vd,
100 cir::CUDADeviceVarKind::Variable,
101 });
102 }
103};
104
105} // namespace
106
107std::string CIRGenNVCUDARuntime::addPrefixToName(StringRef funcName) const {
108 return (prefix + funcName).str();
109}
110
111std::string
112CIRGenNVCUDARuntime::addUnderscoredPrefixToName(StringRef funcName) const {
113 return ("__" + prefix + funcName).str();
114}
115
116CIRGenNVCUDARuntime::CIRGenNVCUDARuntime(CIRGenModule &cgm)
117 : CIRGenCUDARuntime(cgm),
118 deviceMC(cgm.getASTContext().cudaNVInitDeviceMC()) {
119 if (cgm.getLangOpts().OffloadViaLLVM)
120 cgm.errorNYI("CIRGenNVCUDARuntime: Offload via LLVM");
121 else if (cgm.getLangOpts().HIP)
122 prefix = "hip";
123 else
124 prefix = "cuda";
125}
126
127mlir::Value CIRGenNVCUDARuntime::prepareKernelArgs(CIRGenFunction &cgf,
128 mlir::Location loc,
129 FunctionArgList &args) {
130 CIRGenBuilderTy &builder = cgm.getBuilder();
131
132 // Build void *args[] and populate with the addresses of kernel arguments.
133 auto voidPtrArrayTy = cir::ArrayType::get(cgm.voidPtrTy, args.size());
134 mlir::Value kernelArgs = builder.createAlloca(
135 loc, cir::PointerType::get(voidPtrArrayTy), voidPtrArrayTy, "kernel_args",
137
138 mlir::Value kernelArgsDecayed =
139 builder.createCast(cir::CastKind::array_to_ptrdecay, kernelArgs,
140 cir::PointerType::get(cgm.voidPtrTy));
141
142 for (const auto &[i, arg] : llvm::enumerate(args)) {
143 mlir::Value index =
144 builder.getConstInt(loc, llvm::APInt(/*numBits=*/32, i));
145 mlir::Value storePos =
146 builder.createPtrStride(loc, kernelArgsDecayed, index);
147 mlir::Value argAddr = cgf.getAddrOfLocalVar(arg).getPointer();
148 mlir::Value argAsVoid = builder.createBitcast(argAddr, cgm.voidPtrTy);
149
150 builder.CIRBaseBuilderTy::createStore(loc, argAsVoid, storePos);
151 }
152
153 return kernelArgsDecayed;
154}
155
156// CUDA 9.0+ uses new way to launch kernels. Parameters are packed in a local
157// array and kernels are launched using cudaLaunchKernel().
158void CIRGenNVCUDARuntime::emitDeviceStubBodyNew(CIRGenFunction &cgf,
159 cir::FuncOp fn,
160 FunctionArgList &args) {
161
162 // This requires arguments to be sent to kernels in a different way.
163 if (cgm.getLangOpts().OffloadViaLLVM)
164 cgm.errorNYI("CIRGenNVCUDARuntime: Offload via LLVM");
165
166 CIRGenBuilderTy &builder = cgm.getBuilder();
167 mlir::Location loc = fn.getLoc();
168
169 // For [cuda|hip]LaunchKernel, we must add another layer of indirection
170 // to arguments. For example, for function `add(int a, float b)`,
171 // we need to pass it as `void *args[2] = { &a, &b }`.
172 mlir::Value kernelArgs = prepareKernelArgs(cgf, loc, args);
173
174 // Lookup cudaLaunchKernel/hipLaunchKernel function.
175 // HIP kernel launching API name depends on -fgpu-default-stream option. For
176 // the default value 'legacy', it is hipLaunchKernel. For 'per-thread',
177 // it is hipLaunchKernel_spt.
178 // cudaError_t cudaLaunchKernel(const void *func, dim3 gridDim, dim3 blockDim,
179 // void **args, size_t sharedMem,
180 // cudaStream_t stream);
181 // hipError_t hipLaunchKernel[_spt](const void *func, dim3 gridDim,
182 // dim3 blockDim, void **args,
183 // size_t sharedMem, hipStream_t stream);
184 TranslationUnitDecl *tuDecl = cgm.getASTContext().getTranslationUnitDecl();
185 DeclContext *dc = TranslationUnitDecl::castToDeclContext(tuDecl);
186
187 // The default stream is usually stream 0 (the legacy default stream).
188 // For per-thread default stream, we need a different LaunchKernel function.
189 std::string kernelLaunchAPI = "LaunchKernel";
190 if (cgm.getLangOpts().GPUDefaultStream ==
191 LangOptions::GPUDefaultStreamKind::PerThread) {
192 if (cgm.getLangOpts().HIP)
193 kernelLaunchAPI += "_spt";
194 else if (cgm.getLangOpts().CUDA)
195 kernelLaunchAPI += "_ptsz";
196 }
197
198 std::string launchKernelName = addPrefixToName(kernelLaunchAPI);
199 const IdentifierInfo &launchII =
200 cgm.getASTContext().Idents.get(launchKernelName);
201 FunctionDecl *cudaLaunchKernelFD = nullptr;
202 for (NamedDecl *result : dc->lookup(&launchII)) {
203 if (FunctionDecl *fd = dyn_cast<FunctionDecl>(result))
204 cudaLaunchKernelFD = fd;
205 }
206
207 if (cudaLaunchKernelFD == nullptr) {
208 cgm.error(cgf.curFuncDecl->getLocation(),
209 "Can't find declaration for " + launchKernelName);
210 return;
211 }
212
213 // Use this function to retrieve arguments for cudaLaunchKernel:
214 // int __[cuda|hip]PopCallConfiguration(dim3 *gridDim, dim3 *blockDim, size_t
215 // *sharedMem, cudaStream_t *stream)
216 //
217 // Here [cuda|hip]Stream_t, while also being the 6th argument of
218 // [cuda|hip]LaunchKernel, is a pointer to some opaque struct.
219
220 mlir::Type dim3Ty = cgf.getTypes().convertType(
221 cudaLaunchKernelFD->getParamDecl(1)->getType());
222 mlir::Type streamTy = cgf.getTypes().convertType(
223 cudaLaunchKernelFD->getParamDecl(5)->getType());
224
225 mlir::Value gridDim =
226 builder.createAlloca(loc, cir::PointerType::get(dim3Ty), dim3Ty,
227 "grid_dim", CharUnits::fromQuantity(8));
228 mlir::Value blockDim =
229 builder.createAlloca(loc, cir::PointerType::get(dim3Ty), dim3Ty,
230 "block_dim", CharUnits::fromQuantity(8));
231 mlir::Value sharedMem =
232 builder.createAlloca(loc, cir::PointerType::get(cgm.sizeTy), cgm.sizeTy,
233 "shared_mem", cgm.getSizeAlign());
234 mlir::Value stream =
235 builder.createAlloca(loc, cir::PointerType::get(streamTy), streamTy,
236 "stream", cgm.getPointerAlign());
237
238 cir::FuncOp popConfig = cgm.createRuntimeFunction(
239 cir::FuncType::get({gridDim.getType(), blockDim.getType(),
240 sharedMem.getType(), stream.getType()},
241 cgm.sInt32Ty),
242 addUnderscoredPrefixToName("PopCallConfiguration"));
243 cgf.emitRuntimeCall(loc, popConfig, {gridDim, blockDim, sharedMem, stream});
244
245 // Now emit the call to cudaLaunchKernel
246 // [cuda|hip]Error_t [cuda|hip]LaunchKernel(const void *func, dim3 gridDim,
247 // dim3 blockDim,
248 // void **args, size_t sharedMem,
249 // [cuda|hip]Stream_t stream);
250
251 // We now either pick the function or the stub global for cuda, hip
252 // respectively.
253 mlir::Value kernel = [&]() -> mlir::Value {
254 if (cir::GlobalOp globalOp = llvm::dyn_cast_or_null<cir::GlobalOp>(
255 kernelHandles[fn.getSymName()])) {
256 cir::PointerType kernelTy = cir::PointerType::get(globalOp.getSymType());
257 mlir::Value kernelVal = cir::GetGlobalOp::create(builder, loc, kernelTy,
258 globalOp.getSymName());
259 mlir::Value func = builder.createBitcast(kernelVal, cgm.voidPtrTy);
260 return func;
261 }
262 if (cir::FuncOp funcOp = llvm::dyn_cast_or_null<cir::FuncOp>(
263 kernelHandles[fn.getSymName()])) {
264 cir::PointerType kernelTy =
265 cir::PointerType::get(funcOp.getFunctionType());
266 mlir::Value kernelVal =
267 cir::GetGlobalOp::create(builder, loc, kernelTy, funcOp.getSymName());
268 mlir::Value func = builder.createBitcast(kernelVal, cgm.voidPtrTy);
269 return func;
270 }
271 llvm_unreachable("Expected stub handle to be cir::GlobalOp or FuncOp");
272 }();
273
274 CallArgList launchArgs;
275 launchArgs.add(RValue::get(kernel),
276 cudaLaunchKernelFD->getParamDecl(0)->getType());
277 launchArgs.add(
279 cudaLaunchKernelFD->getParamDecl(1)->getType());
280 launchArgs.add(
282 cudaLaunchKernelFD->getParamDecl(2)->getType());
283 launchArgs.add(RValue::get(kernelArgs),
284 cudaLaunchKernelFD->getParamDecl(3)->getType());
285 launchArgs.add(
286 RValue::get(builder.CIRBaseBuilderTy::createLoad(loc, sharedMem)),
287 cudaLaunchKernelFD->getParamDecl(4)->getType());
288 launchArgs.add(RValue::get(builder.CIRBaseBuilderTy::createLoad(loc, stream)),
289 cudaLaunchKernelFD->getParamDecl(5)->getType());
290
291 mlir::Type launchTy =
292 cgm.getTypes().convertType(cudaLaunchKernelFD->getType());
293 mlir::Operation *cudaKernelLauncherFn = cgm.createRuntimeFunction(
294 cast<cir::FuncType>(launchTy), launchKernelName);
295 const CIRGenFunctionInfo &callInfo =
296 cgm.getTypes().arrangeFunctionDeclaration(cudaLaunchKernelFD);
297 cgf.emitCall(callInfo, CIRGenCallee::forDirect(cudaKernelLauncherFn),
298 ReturnValueSlot(), launchArgs);
299
301 !cgf.getLangOpts().HIP)
302 cgm.errorNYI("MSVC CUDA stub handling");
303}
304
305void CIRGenNVCUDARuntime::emitDeviceStub(CIRGenFunction &cgf, cir::FuncOp fn,
306 FunctionArgList &args) {
307
308 if (auto globalOp =
309 llvm::dyn_cast<cir::GlobalOp>(kernelHandles[fn.getSymName()])) {
310 CIRGenBuilderTy &builder = cgm.getBuilder();
311 mlir::Type fnPtrTy = globalOp.getSymType();
312 auto sym = mlir::FlatSymbolRefAttr::get(fn.getSymNameAttr());
313 auto gv = cir::GlobalViewAttr::get(fnPtrTy, sym);
314
315 globalOp->setAttr("initial_value", gv);
316 globalOp->removeAttr("sym_visibility");
317 globalOp->setAttr("alignment", builder.getI64IntegerAttr(
319 }
320
321 // CUDA 9.0 changed the way to launch kernels.
323 CudaFeature::CUDA_USES_NEW_LAUNCH) ||
324 (cgm.getLangOpts().HIP && cgm.getLangOpts().HIPUseNewLaunchAPI) ||
325 cgm.getLangOpts().OffloadViaLLVM)
326 emitDeviceStubBodyNew(cgf, fn, args);
327 else
328 cgm.errorNYI("Emit Stub Body Legacy");
329}
330
332 return new CIRGenNVCUDARuntime(cgm);
333}
334
335CIRGenNVCUDARuntime::~CIRGenNVCUDARuntime() {}
336
337mlir::Operation *CIRGenNVCUDARuntime::getKernelHandle(cir::FuncOp fn,
338 GlobalDecl gd) {
339
340 // Check if we already have a kernel handle for this function
341 auto it = kernelHandles.find(fn.getSymName());
342 if (it != kernelHandles.end()) {
343 mlir::Operation *oldHandle = it->second;
344 // Here we know that the fn did not change. Return it
345 if (kernelStubs[oldHandle] == fn)
346 return oldHandle;
347
348 // We've found the function name, but F itself has changed, so we need to
349 // update the references.
350 if (cgm.getLangOpts().HIP) {
351 // For HIP compilation the handle itself does not change, so we only need
352 // to update the Stub value.
353 kernelStubs[oldHandle] = fn;
354 return oldHandle;
355 }
356 // For non-HIP compilation, erase the old Stub and fall-through to creating
357 // new entries.
358 kernelStubs.erase(oldHandle);
359 }
360
361 // If not targeting HIP, store the function itself
362 if (!cgm.getLangOpts().HIP) {
363 kernelHandles[fn.getSymName()] = fn;
364 kernelStubs[fn] = fn;
365 return fn;
366 }
367
368 // Create a new CIR global variable to represent the kernel handle
369 CIRGenBuilderTy &builder = cgm.getBuilder();
370 StringRef globalName = cgm.getMangledName(
371 gd.getWithKernelReferenceKind(KernelReferenceKind::Kernel));
372 cir::PointerType fnPtrTy = builder.getPointerTo(fn.getFunctionType());
373 cir::GlobalOp globalOp =
374 cgm.createGlobalOp(fn.getLoc(), globalName, fnPtrTy, /*isConstant=*/true);
375
376 globalOp->setAttr("alignment", builder.getI64IntegerAttr(
378
379 // Store references
380 kernelHandles[fn.getSymName()] = globalOp;
381 kernelStubs[globalOp] = fn;
382
383 return globalOp;
384}
385
386void CIRGenNVCUDARuntime::internalizeDeviceSideVar(
387 const VarDecl *d, cir::GlobalLinkageKind &linkage) {
388 if (cgm.getLangOpts().GPURelocatableDeviceCode)
389 cgm.errorNYI(d->getSourceRange(),
390 "internalizeDeviceSideVar: GPU Relocatable Device Code (RDC)");
391
392 // __shared__ variables are odd. Shadows do get created, but
393 // they are not registered with the CUDA runtime, so they
394 // can't really be used to access their device-side
395 // counterparts. It's not clear yet whether it's nvcc's bug or
396 // a feature, but we've got to do the same for compatibility.
397 if (d->hasAttr<CUDADeviceAttr>() || d->hasAttr<CUDAConstantAttr>() ||
398 d->hasAttr<CUDASharedAttr>()) {
399 linkage = cir::GlobalLinkageKind::InternalLinkage;
400 }
401
404 cgm.errorNYI(d->getSourceRange(),
405 "internalizeDeviceSideVar: CUDA Surface/Texture support");
406}
407
408std::string CIRGenNVCUDARuntime::getDeviceSideName(const NamedDecl *nd) {
409 GlobalDecl gd;
410 // nd could be either a kernel or a variable.
411 if (auto *fd = dyn_cast<FunctionDecl>(nd))
412 gd = GlobalDecl(fd, KernelReferenceKind::Kernel);
413 else
414 gd = GlobalDecl(nd);
415 std::string deviceSideName;
416 MangleContext *mc;
417 if (cgm.getLangOpts().CUDAIsDevice)
418 mc = &cgm.getCXXABI().getMangleContext();
419 else
420 mc = deviceMC.get();
421 if (mc->shouldMangleDeclName(nd)) {
422 SmallString<256> buffer;
423 llvm::raw_svector_ostream out(buffer);
424 mc->mangleName(gd, out);
425 deviceSideName = std::string(out.str());
426 } else
427 deviceSideName = std::string(nd->getIdentifier()->getName());
428
429 // Make unique name for device side static file-scope variable for HIP.
430 if (cgm.getASTContext().shouldExternalize(nd) &&
431 cgm.getLangOpts().GPURelocatableDeviceCode) {
432 SmallString<256> buffer;
433 llvm::raw_svector_ostream out(buffer);
434 out << deviceSideName;
436 deviceSideName = std::string(out.str());
437 }
438 return deviceSideName;
439}
440
441void CIRGenNVCUDARuntime::handleVarRegistration(const VarDecl *vd,
442 cir::GlobalOp var) {
443 if (vd->hasAttr<CUDADeviceAttr>() || vd->hasAttr<CUDAConstantAttr>()) {
444 // Shadow variables and their properties must be registered with CUDA
445 // runtime. Skip Extern global variables, which will be registered in
446 // the TU where they are defined.
447 //
448 // Don't register a C++17 inline variable. The local symbol can be
449 // discarded and referencing a discarded local symbol from outside the
450 // comdat (__cuda_register_globals) is disallowed by the ELF spec.
451 //
452 // HIP managed variables need to be always recorded in device and host
453 // compilations for transformation.
454 //
455 // HIP managed variables and variables in CUDADeviceVarODRUsedByHost are
456 // added to llvm.compiler-used, therefore they are safe to be registered.
457 if ((!vd->hasExternalStorage() && !vd->isInline()) ||
458 cgm.getASTContext().CUDADeviceVarODRUsedByHost.contains(vd) ||
459 vd->hasAttr<HIPManagedAttr>()) {
460 registerDeviceVar(vd, var, !vd->hasDefinition(),
461 vd->hasAttr<CUDAConstantAttr>());
462 }
463 } else if (vd->getType()->isCUDADeviceBuiltinSurfaceType() ||
465 // Builtin surfaces and textures and their template arguments are
466 // also registered with CUDA runtime.
467 cgm.errorNYI(vd->getSourceRange(),
468 "handleVarRegistration: Surface and Texture registration");
469 }
470}
471
472void CIRGenNVCUDARuntime::handleGlobalReplace(cir::GlobalOp oldGV,
473 cir::GlobalOp newGV) {
474 for (auto &info : deviceVars) {
475 if (info.var == oldGV)
476 info.var = newGV;
477 }
478}
479
480void CIRGenNVCUDARuntime::finalizeModule() {
481 if (!cgm.getLangOpts().CUDAIsDevice)
482 return;
483
484 // Mark ODR-used device variables as compiler used to prevent them from being
485 // eliminated by optimization. This is necessary for device variables
486 // ODR-used by host functions. Sema correctly marks them as ODR-used no
487 // matter whether they are ODR-used by device or host functions.
488 //
489 // We do not need to do this if the variable has used attribute since it
490 // has already been added.
491 //
492 // Static device variables have been externalized at this point, therefore
493 // variables with private or internal linkage need not be added.
494 for (auto &&info : deviceVars) {
495 auto kind = info.flags;
496 bool isDecl = info.var.isDeclaration();
497 bool isLocalLinkage = cir::isLocalLinkage(info.var.getLinkage());
498 bool isVarOrSurfaceOrTexture = (kind == cir::CUDADeviceVarKind::Variable ||
499 kind == cir::CUDADeviceVarKind::Surface ||
500 kind == cir::CUDADeviceVarKind::Texture);
501 bool isUsed = info.d->isUsed();
502 bool hasUsedAttr = info.d->hasAttr<UsedAttr>();
503 if (!isDecl && !isLocalLinkage && isVarOrSurfaceOrTexture && isUsed &&
504 !hasUsedAttr) {
505 if (auto globalValue = mlir::dyn_cast<cir::CIRGlobalValueInterface>(
506 info.var.getOperation())) {
507 cgm.addCompilerUsedGlobal(globalValue);
508 }
509 }
510 }
511}
Defines the clang::ASTContext interface.
Provides definitions for the various language-specific address spaces.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
__CUDA_BUILTIN_VAR __cuda_builtin_blockDim_t blockDim
__CUDA_BUILTIN_VAR __cuda_builtin_gridDim_t gridDim
mlir::Value createCast(mlir::Location loc, cir::CastKind kind, mlir::Value src, mlir::Type newTy)
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
cir::PointerType getPointerTo(mlir::Type ty)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, mlir::Type type, llvm::StringRef name, mlir::IntegerAttr alignment, mlir::Value dynAllocSize)
TranslationUnitDecl * getTranslationUnitDecl() const
bool shouldExternalize(const Decl *D) const
Whether a C++ static variable or CUDA/HIP kernel should be externalized.
IdentifierTable & Idents
Definition ASTContext.h:806
llvm::SetVector< const VarDecl * > CUDADeviceVarODRUsedByHost
Keep track of CUDA/HIP device-side variables ODR-used by host code.
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:925
mlir::Value getPointer() const
Definition Address.h:98
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
clang::MangleContext & getMangleContext()
Gets the mangle context.
static CIRGenCallee forDirect(mlir::Operation *funcPtr, const CIRGenCalleeInfo &abstractInfo=CIRGenCalleeInfo())
Definition CIRGenCall.h:92
CIRGenTypes & getTypes() const
const clang::LangOptions & getLangOpts() const
const clang::Decl * curFuncDecl
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOp, mlir::Location loc)
mlir::Value emitRuntimeCall(mlir::Location loc, cir::FuncOp callee, llvm::ArrayRef< mlir::Value > args={}, mlir::NamedAttrList attrs={})
This class organizes the cross-function state that is used while generating CIR code.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
CIRGenBuilderTy & getBuilder()
const clang::TargetInfo & getTarget() const
void error(SourceLocation loc, llvm::StringRef error)
Emit a general error that something can't be done.
cir::FuncOp createRuntimeFunction(cir::FuncType ty, llvm::StringRef name, mlir::NamedAttrList extraAttrs={}, bool isLocal=false, bool assumeConvergent=false)
const clang::LangOptions & getLangOpts() const
void printPostfixForExternalizedDecl(llvm::raw_ostream &os, const Decl *d)
Print the postfix for externalized static variable or kernels for single source offloading languages ...
cir::GlobalOp createGlobalOp(mlir::Location loc, llvm::StringRef name, mlir::Type t, bool isConstant=false, mlir::ptr::MemorySpaceAttrInterface addrSpace={}, mlir::Operation *insertPoint=nullptr)
void addCompilerUsedGlobal(cir::CIRGlobalValueInterface gv)
Add a global value to the llvmCompilerUsed list.
CIRGenCXXABI & getCXXABI() const
const CIRGenFunctionInfo & arrangeFunctionDeclaration(const clang::FunctionDecl *fd)
Free functions are functions that are compatible with an ordinary C function pointer type.
mlir::Type convertType(clang::QualType type)
Convert a Clang type into a mlir::Type.
void add(RValue rvalue, clang::QualType type)
Definition CIRGenCall.h:239
Type for representing both the decl and type of parameters to a function.
Definition CIRGenCall.h:193
static RValue get(mlir::Value v)
Definition CIRGenValue.h:83
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition CharUnits.h:185
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Definition CharUnits.h:63
lookup_result lookup(DeclarationName Name) const
lookup - Find the declarations (if any) with the given Name in this context.
SourceLocation getLocation() const
Definition DeclBase.h:447
bool hasAttr() const
Definition DeclBase.h:585
const ParmVarDecl * getParamDecl(unsigned i) const
Definition Decl.h:2815
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
GlobalDecl getWithKernelReferenceKind(KernelReferenceKind Kind)
Definition GlobalDecl.h:203
StringRef getName() const
Return the actual identifier string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
GPUDefaultStreamKind GPUDefaultStream
The default stream kind used for HIP kernel launching.
bool shouldMangleDeclName(const NamedDecl *D)
Definition Mangle.cpp:127
void mangleName(GlobalDecl GD, raw_ostream &)
Definition Mangle.cpp:190
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
Definition Decl.h:295
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
const llvm::VersionTuple & getSDKVersion() const
static DeclContext * castToDeclContext(const TranslationUnitDecl *D)
Definition Decl.h:151
bool isCUDADeviceBuiltinSurfaceType() const
Check if the type is the CUDA device builtin surface type.
Definition Type.cpp:5460
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition Type.cpp:5469
QualType getType() const
Definition Decl.h:723
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
Definition Decl.cpp:2169
bool isInline() const
Whether this variable is (C++1z) inline.
Definition Decl.h:1564
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
Definition Decl.h:1230
DefinitionKind hasDefinition(ASTContext &) const
Check whether this variable is defined in this translation unit.
Definition Decl.cpp:2354
static bool isLocalLinkage(GlobalLinkageKind linkage)
Definition CIROpsEnums.h:51
CIRGenCUDARuntime * createNVCUDARuntime(CIRGenModule &cgm)
constexpr Variable var(Literal L)
Returns the variable of L.
Definition CNFFormula.h:64
@ Address
A pointer to a ValueDecl.
Definition Primitives.h:28
The JSON file list parser is used to communicate input to InstallAPI.
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
bool CudaFeatureEnabled(llvm::VersionTuple, CudaFeature)
Definition Cuda.cpp:172
U cast(CodeGen::Address addr)
Definition Address.h:327
clang::CharUnits getPointerAlign() const
clang::CharUnits getSizeAlign() const
cir::PointerType voidPtrTy
void* in address space 0