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 =
135 builder.createAlloca(loc, cir::PointerType::get(voidPtrArrayTy),
136 "kernel_args", CharUnits::fromQuantity(16));
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), "grid_dim",
228 mlir::Value blockDim =
229 builder.createAlloca(loc, cir::PointerType::get(dim3Ty), "block_dim",
231 mlir::Value sharedMem = builder.createAlloca(
232 loc, cir::PointerType::get(cgm.sizeTy), "shared_mem", cgm.getSizeAlign());
233 mlir::Value stream = builder.createAlloca(
234 loc, cir::PointerType::get(streamTy), "stream", cgm.getPointerAlign());
235
236 cir::FuncOp popConfig = cgm.createRuntimeFunction(
237 cir::FuncType::get({gridDim.getType(), blockDim.getType(),
238 sharedMem.getType(), stream.getType()},
239 cgm.sInt32Ty),
240 addUnderscoredPrefixToName("PopCallConfiguration"));
241 cgf.emitRuntimeCall(loc, popConfig, {gridDim, blockDim, sharedMem, stream});
242
243 // Now emit the call to cudaLaunchKernel
244 // [cuda|hip]Error_t [cuda|hip]LaunchKernel(const void *func, dim3 gridDim,
245 // dim3 blockDim,
246 // void **args, size_t sharedMem,
247 // [cuda|hip]Stream_t stream);
248
249 // We now either pick the function or the stub global for cuda, hip
250 // respectively.
251 mlir::Value kernel = [&]() -> mlir::Value {
252 if (cir::GlobalOp globalOp = llvm::dyn_cast_or_null<cir::GlobalOp>(
253 kernelHandles[fn.getSymName()])) {
254 cir::PointerType kernelTy = cir::PointerType::get(globalOp.getSymType());
255 mlir::Value kernelVal = cir::GetGlobalOp::create(builder, loc, kernelTy,
256 globalOp.getSymName());
257 mlir::Value func = builder.createBitcast(kernelVal, cgm.voidPtrTy);
258 return func;
259 }
260 if (cir::FuncOp funcOp = llvm::dyn_cast_or_null<cir::FuncOp>(
261 kernelHandles[fn.getSymName()])) {
262 cir::PointerType kernelTy =
263 cir::PointerType::get(funcOp.getFunctionType());
264 mlir::Value kernelVal =
265 cir::GetGlobalOp::create(builder, loc, kernelTy, funcOp.getSymName());
266 mlir::Value func = builder.createBitcast(kernelVal, cgm.voidPtrTy);
267 return func;
268 }
269 llvm_unreachable("Expected stub handle to be cir::GlobalOp or FuncOp");
270 }();
271
272 CallArgList launchArgs;
273 launchArgs.add(RValue::get(kernel),
274 cudaLaunchKernelFD->getParamDecl(0)->getType());
275 launchArgs.add(
277 cudaLaunchKernelFD->getParamDecl(1)->getType());
278 launchArgs.add(
280 cudaLaunchKernelFD->getParamDecl(2)->getType());
281 launchArgs.add(RValue::get(kernelArgs),
282 cudaLaunchKernelFD->getParamDecl(3)->getType());
283 launchArgs.add(
284 RValue::get(builder.CIRBaseBuilderTy::createLoad(loc, sharedMem)),
285 cudaLaunchKernelFD->getParamDecl(4)->getType());
286 launchArgs.add(RValue::get(builder.CIRBaseBuilderTy::createLoad(loc, stream)),
287 cudaLaunchKernelFD->getParamDecl(5)->getType());
288
289 mlir::Type launchTy =
290 cgm.getTypes().convertType(cudaLaunchKernelFD->getType());
291 mlir::Operation *cudaKernelLauncherFn = cgm.createRuntimeFunction(
292 cast<cir::FuncType>(launchTy), launchKernelName);
293 const CIRGenFunctionInfo &callInfo =
294 cgm.getTypes().arrangeFunctionDeclaration(cudaLaunchKernelFD);
295 cgf.emitCall(callInfo, CIRGenCallee::forDirect(cudaKernelLauncherFn),
296 ReturnValueSlot(), launchArgs);
297
299 !cgf.getLangOpts().HIP)
300 cgm.errorNYI("MSVC CUDA stub handling");
301}
302
303void CIRGenNVCUDARuntime::emitDeviceStub(CIRGenFunction &cgf, cir::FuncOp fn,
304 FunctionArgList &args) {
305
306 if (auto globalOp =
307 llvm::dyn_cast<cir::GlobalOp>(kernelHandles[fn.getSymName()])) {
308 CIRGenBuilderTy &builder = cgm.getBuilder();
309 mlir::Type fnPtrTy = globalOp.getSymType();
310 auto sym = mlir::FlatSymbolRefAttr::get(fn.getSymNameAttr());
311 auto gv = cir::GlobalViewAttr::get(fnPtrTy, sym);
312
313 globalOp->setAttr("initial_value", gv);
314 globalOp->removeAttr("sym_visibility");
315 globalOp->setAttr("alignment", builder.getI64IntegerAttr(
317 }
318
319 // CUDA 9.0 changed the way to launch kernels.
321 CudaFeature::CUDA_USES_NEW_LAUNCH) ||
322 (cgm.getLangOpts().HIP && cgm.getLangOpts().HIPUseNewLaunchAPI) ||
323 cgm.getLangOpts().OffloadViaLLVM)
324 emitDeviceStubBodyNew(cgf, fn, args);
325 else
326 cgm.errorNYI("Emit Stub Body Legacy");
327}
328
330 return new CIRGenNVCUDARuntime(cgm);
331}
332
333CIRGenNVCUDARuntime::~CIRGenNVCUDARuntime() {}
334
335mlir::Operation *CIRGenNVCUDARuntime::getKernelHandle(cir::FuncOp fn,
336 GlobalDecl gd) {
337
338 // Check if we already have a kernel handle for this function
339 auto it = kernelHandles.find(fn.getSymName());
340 if (it != kernelHandles.end()) {
341 mlir::Operation *oldHandle = it->second;
342 // Here we know that the fn did not change. Return it
343 if (kernelStubs[oldHandle] == fn)
344 return oldHandle;
345
346 // We've found the function name, but F itself has changed, so we need to
347 // update the references.
348 if (cgm.getLangOpts().HIP) {
349 // For HIP compilation the handle itself does not change, so we only need
350 // to update the Stub value.
351 kernelStubs[oldHandle] = fn;
352 return oldHandle;
353 }
354 // For non-HIP compilation, erase the old Stub and fall-through to creating
355 // new entries.
356 kernelStubs.erase(oldHandle);
357 }
358
359 // If not targeting HIP, store the function itself
360 if (!cgm.getLangOpts().HIP) {
361 kernelHandles[fn.getSymName()] = fn;
362 kernelStubs[fn] = fn;
363 return fn;
364 }
365
366 // Create a new CIR global variable to represent the kernel handle
367 CIRGenBuilderTy &builder = cgm.getBuilder();
368 StringRef globalName = cgm.getMangledName(
369 gd.getWithKernelReferenceKind(KernelReferenceKind::Kernel));
370 cir::PointerType fnPtrTy = builder.getPointerTo(fn.getFunctionType());
371 cir::GlobalOp globalOp =
372 cgm.createGlobalOp(fn.getLoc(), globalName, fnPtrTy, /*isConstant=*/true);
373
374 globalOp->setAttr("alignment", builder.getI64IntegerAttr(
376
377 // Store references
378 kernelHandles[fn.getSymName()] = globalOp;
379 kernelStubs[globalOp] = fn;
380
381 return globalOp;
382}
383
384void CIRGenNVCUDARuntime::internalizeDeviceSideVar(
385 const VarDecl *d, cir::GlobalLinkageKind &linkage) {
386 if (cgm.getLangOpts().GPURelocatableDeviceCode)
387 cgm.errorNYI(d->getSourceRange(),
388 "internalizeDeviceSideVar: GPU Relocatable Device Code (RDC)");
389
390 // __shared__ variables are odd. Shadows do get created, but
391 // they are not registered with the CUDA runtime, so they
392 // can't really be used to access their device-side
393 // counterparts. It's not clear yet whether it's nvcc's bug or
394 // a feature, but we've got to do the same for compatibility.
395 if (d->hasAttr<CUDADeviceAttr>() || d->hasAttr<CUDAConstantAttr>() ||
396 d->hasAttr<CUDASharedAttr>()) {
397 linkage = cir::GlobalLinkageKind::InternalLinkage;
398 }
399
402 cgm.errorNYI(d->getSourceRange(),
403 "internalizeDeviceSideVar: CUDA Surface/Texture support");
404}
405
406std::string CIRGenNVCUDARuntime::getDeviceSideName(const NamedDecl *nd) {
407 GlobalDecl gd;
408 // nd could be either a kernel or a variable.
409 if (auto *fd = dyn_cast<FunctionDecl>(nd))
410 gd = GlobalDecl(fd, KernelReferenceKind::Kernel);
411 else
412 gd = GlobalDecl(nd);
413 std::string deviceSideName;
414 MangleContext *mc;
415 if (cgm.getLangOpts().CUDAIsDevice)
416 mc = &cgm.getCXXABI().getMangleContext();
417 else
418 mc = deviceMC.get();
419 if (mc->shouldMangleDeclName(nd)) {
420 SmallString<256> buffer;
421 llvm::raw_svector_ostream out(buffer);
422 mc->mangleName(gd, out);
423 deviceSideName = std::string(out.str());
424 } else
425 deviceSideName = std::string(nd->getIdentifier()->getName());
426
427 // Make unique name for device side static file-scope variable for HIP.
428 if (cgm.getASTContext().shouldExternalize(nd) &&
429 cgm.getLangOpts().GPURelocatableDeviceCode) {
430 SmallString<256> buffer;
431 llvm::raw_svector_ostream out(buffer);
432 out << deviceSideName;
434 deviceSideName = std::string(out.str());
435 }
436 return deviceSideName;
437}
438
439void CIRGenNVCUDARuntime::handleVarRegistration(const VarDecl *vd,
440 cir::GlobalOp var) {
441 if (vd->hasAttr<CUDADeviceAttr>() || vd->hasAttr<CUDAConstantAttr>()) {
442 // Shadow variables and their properties must be registered with CUDA
443 // runtime. Skip Extern global variables, which will be registered in
444 // the TU where they are defined.
445 //
446 // Don't register a C++17 inline variable. The local symbol can be
447 // discarded and referencing a discarded local symbol from outside the
448 // comdat (__cuda_register_globals) is disallowed by the ELF spec.
449 //
450 // HIP managed variables need to be always recorded in device and host
451 // compilations for transformation.
452 //
453 // HIP managed variables and variables in CUDADeviceVarODRUsedByHost are
454 // added to llvm.compiler-used, therefore they are safe to be registered.
455 if ((!vd->hasExternalStorage() && !vd->isInline()) ||
456 cgm.getASTContext().CUDADeviceVarODRUsedByHost.contains(vd) ||
457 vd->hasAttr<HIPManagedAttr>()) {
458 registerDeviceVar(vd, var, !vd->hasDefinition(),
459 vd->hasAttr<CUDAConstantAttr>());
460 }
461 } else if (vd->getType()->isCUDADeviceBuiltinSurfaceType() ||
463 // Builtin surfaces and textures and their template arguments are
464 // also registered with CUDA runtime.
465 cgm.errorNYI(vd->getSourceRange(),
466 "handleVarRegistration: Surface and Texture registration");
467 }
468}
469
470void CIRGenNVCUDARuntime::handleGlobalReplace(cir::GlobalOp oldGV,
471 cir::GlobalOp newGV) {
472 for (auto &info : deviceVars) {
473 if (info.var == oldGV)
474 info.var = newGV;
475 }
476}
477
478void CIRGenNVCUDARuntime::finalizeModule() {
479 if (!cgm.getLangOpts().CUDAIsDevice)
480 return;
481
482 // Mark ODR-used device variables as compiler used to prevent them from being
483 // eliminated by optimization. This is necessary for device variables
484 // ODR-used by host functions. Sema correctly marks them as ODR-used no
485 // matter whether they are ODR-used by device or host functions.
486 //
487 // We do not need to do this if the variable has used attribute since it
488 // has already been added.
489 //
490 // Static device variables have been externalized at this point, therefore
491 // variables with private or internal linkage need not be added.
492 for (auto &&info : deviceVars) {
493 auto kind = info.flags;
494 bool isDecl = info.var.isDeclaration();
495 bool isLocalLinkage = cir::isLocalLinkage(info.var.getLinkage());
496 bool isVarOrSurfaceOrTexture = (kind == cir::CUDADeviceVarKind::Variable ||
497 kind == cir::CUDADeviceVarKind::Surface ||
498 kind == cir::CUDADeviceVarKind::Texture);
499 bool isUsed = info.d->isUsed();
500 bool hasUsedAttr = info.d->hasAttr<UsedAttr>();
501 if (!isDecl && !isLocalLinkage && isVarOrSurfaceOrTexture && isUsed &&
502 !hasUsedAttr) {
503 if (auto globalValue = mlir::dyn_cast<cir::CIRGlobalValueInterface>(
504 info.var.getOperation())) {
505 cgm.addCompilerUsedGlobal(globalValue);
506 }
507 }
508 }
509}
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 createAlloca(mlir::Location loc, cir::PointerType addrType, llvm::StringRef name, mlir::IntegerAttr alignment, mlir::Value dynAllocSize)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
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:802
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:921
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:5475
bool isCUDADeviceBuiltinTextureType() const
Check if the type is the CUDA device builtin texture type.
Definition Type.cpp:5484
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