clang 24.0.0git
SPIR.cpp
Go to the documentation of this file.
1//===- SPIR.cpp -----------------------------------------------------------===//
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#include "ABIInfoImpl.h"
11#include "TargetInfo.h"
12#include "clang/AST/DeclCXX.h"
14#include "llvm/IR/DerivedTypes.h"
15#include "llvm/IR/LLVMContext.h"
16
17#include <stdint.h>
18#include <utility>
19
20using namespace clang;
21using namespace clang::CodeGen;
22
23//===----------------------------------------------------------------------===//
24// Base ABI and target codegen info implementation common between SPIR and
25// SPIR-V.
26//===----------------------------------------------------------------------===//
27
28namespace {
29class CommonSPIRABIInfo : public DefaultABIInfo {
30public:
31 CommonSPIRABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) { setCCs(); }
32
33private:
34 void setCCs();
35};
36
37class SPIRVABIInfo : public CommonSPIRABIInfo {
38public:
39 SPIRVABIInfo(CodeGenTypes &CGT) : CommonSPIRABIInfo(CGT) {}
40 void computeInfo(CGFunctionInfo &FI) const override;
41 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
42 AggValueSlot Slot) const override;
43
44 llvm::FixedVectorType *
45 getOptimalVectorMemoryType(llvm::FixedVectorType *Ty,
46 const LangOptions &LangOpt) const override;
47
48private:
49 ABIArgInfo classifyKernelArgumentType(QualType Ty) const;
50};
51
52class AMDGCNSPIRVABIInfo : public SPIRVABIInfo {
53 // TODO: this should be unified / shared with AMDGPU, ideally we'd like to
54 // re-use AMDGPUABIInfo eventually, rather than duplicate.
55 static constexpr unsigned MaxNumRegsForArgsRet = 16; // 16 32-bit registers
56 mutable unsigned NumRegsLeft = 0;
57
58 uint64_t numRegsForType(QualType Ty) const;
59
60 bool isHomogeneousAggregateBaseType(QualType Ty) const override {
61 return true;
62 }
63 bool isHomogeneousAggregateSmallEnough(const Type *Base,
64 uint64_t Members) const override {
65 uint32_t NumRegs = (getContext().getTypeSize(Base) + 31) / 32;
66
67 // Homogeneous Aggregates may occupy at most 16 registers.
68 return Members * NumRegs <= MaxNumRegsForArgsRet;
69 }
70
71 // Coerce HIP scalar pointer arguments from generic pointers to global ones.
72 llvm::Type *coerceKernelArgumentType(llvm::Type *Ty, unsigned FromAS,
73 unsigned ToAS) const;
74
75 ABIArgInfo classifyReturnType(QualType RetTy) const;
76 ABIArgInfo classifyKernelArgumentType(QualType Ty) const;
77 ABIArgInfo classifyArgumentType(QualType Ty, bool Variadic) const;
78
79public:
80 AMDGCNSPIRVABIInfo(CodeGenTypes &CGT) : SPIRVABIInfo(CGT) {}
81 void computeInfo(CGFunctionInfo &FI) const override;
82
83 llvm::FixedVectorType *
84 getOptimalVectorMemoryType(llvm::FixedVectorType *Ty,
85 const LangOptions &LangOpt) const override;
86};
87} // end anonymous namespace
88namespace {
89class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
90public:
91 CommonSPIRTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
92 : TargetCodeGenInfo(std::make_unique<CommonSPIRABIInfo>(CGT)) {}
93 CommonSPIRTargetCodeGenInfo(std::unique_ptr<ABIInfo> ABIInfo)
94 : TargetCodeGenInfo(std::move(ABIInfo)) {}
95
96 unsigned getDeviceKernelCallingConv() const override;
97 llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const override;
98 llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *Ty,
99 const CGHLSLOffsetInfo &OffsetInfo) const override;
100
101 llvm::Type *getHLSLPadding(CodeGenModule &CGM,
102 CharUnits NumBytes) const override {
103 unsigned Size = NumBytes.getQuantity();
104 return llvm::TargetExtType::get(CGM.getLLVMContext(), "spirv.Padding", {},
105 {Size});
106 }
107
108 bool isHLSLPadding(llvm::Type *Ty) const override {
109 if (auto *TET = dyn_cast<llvm::TargetExtType>(Ty))
110 return TET->getName() == "spirv.Padding";
111 return false;
112 }
113
114 llvm::Type *getSPIRVImageTypeFromHLSLResource(
115 const HLSLAttributedResourceType::Attributes &attributes,
116 QualType SampledType, CodeGenModule &CGM) const;
117 void
118 setOCLKernelStubCallingConvention(const FunctionType *&FT) const override;
119 llvm::Constant *getNullPointer(const CodeGen::CodeGenModule &CGM,
120 llvm::PointerType *T,
121 QualType QT) const override;
122};
123class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
124public:
125 SPIRVTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
126 : CommonSPIRTargetCodeGenInfo(
127 (CGT.getTarget().getTriple().getVendor() == llvm::Triple::AMD)
128 ? std::make_unique<AMDGCNSPIRVABIInfo>(CGT)
129 : std::make_unique<SPIRVABIInfo>(CGT)) {}
130 void setCUDAKernelCallingConvention(const FunctionType *&FT) const override;
131 LangAS getGlobalVarAddressSpace(CodeGenModule &CGM,
132 const VarDecl *D) const override;
133 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
134 CodeGen::CodeGenModule &M) const override;
135 StringRef getLLVMSyncScopeStr(const LangOptions &LangOpts, SyncScope Scope,
136 llvm::AtomicOrdering Ordering) const override;
137 void setTargetAtomicMetadata(CodeGenFunction &CGF,
138 llvm::Instruction &AtomicInst,
139 const AtomicExpr *Expr = nullptr) const override;
140 bool supportsLibCall() const override {
141 return getABIInfo().getTarget().getTriple().getVendor() !=
142 llvm::Triple::AMD;
143 }
144
145 LangAS getSRetAddrSpace(const CXXRecordDecl *RD) const override;
146};
147} // End anonymous namespace.
148
149void CommonSPIRABIInfo::setCCs() {
150 assert(getRuntimeCC() == llvm::CallingConv::C);
151 RuntimeCC = llvm::CallingConv::SPIR_FUNC;
152}
153
154ABIArgInfo SPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
155 // Coerce pointer arguments with default address space to CrossWorkGroup
156 // pointers as default address space kernel
157 // arguments are not allowed. We use the opencl_global language address
158 // space which always maps to CrossWorkGroup.
159 llvm::Type *LTy = CGT.ConvertType(Ty);
160 auto DefaultAS = getContext().getTargetAddressSpace(LangAS::Default);
161 auto GlobalAS = getContext().getTargetAddressSpace(LangAS::opencl_global);
162 auto *PtrTy = llvm::dyn_cast<llvm::PointerType>(LTy);
163 if (PtrTy && PtrTy->getAddressSpace() == DefaultAS) {
164 LTy = llvm::PointerType::get(PtrTy->getContext(), GlobalAS);
165 return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
166 }
167
168 if (getContext().getLangOpts().isTargetDevice() &&
170 // Force copying aggregate type in kernel arguments by value when
171 // compiling CUDA targeting SPIR-V. This is required for the object
172 // copied to be valid on the device.
173 // This behavior follows the CUDA spec
174 // https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#global-function-argument-processing,
175 // and matches the NVPTX implementation. TODO: hardcoding to 0 should be
176 // revisited if HIPSPV / byval starts making use of the AS of an indirect
177 // arg.
178 return getNaturalAlignIndirect(Ty, /*AddrSpace=*/0, /*byval=*/true);
179 }
180 return classifyArgumentType(Ty);
181}
182
183void SPIRVABIInfo::computeInfo(CGFunctionInfo &FI) const {
184 // The logic is same as in DefaultABIInfo with an exception on the kernel
185 // arguments handling.
186 llvm::CallingConv::ID CC = FI.getCallingConvention();
187
188 for (auto &&[ArgumentsCount, I] : llvm::enumerate(FI.arguments()))
189 I.info = ArgumentsCount < FI.getNumRequiredArgs()
190 ? classifyArgumentType(I.type)
191 : ABIArgInfo::getDirect();
192
193 if (!getCXXABI().classifyReturnType(FI))
195
196 for (auto &I : FI.arguments()) {
197 if (CC == llvm::CallingConv::SPIR_KERNEL) {
198 I.info = classifyKernelArgumentType(I.type);
199 } else {
200 I.info = classifyArgumentType(I.type);
201 }
202 }
203}
204
205RValue SPIRVABIInfo::EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
206 QualType Ty, AggValueSlot Slot) const {
207 return emitVoidPtrVAArg(CGF, VAListAddr, Ty, /*IsIndirect=*/false,
208 getContext().getTypeInfoInChars(Ty),
210 /*AllowHigherAlign=*/true, Slot);
211}
212
213uint64_t AMDGCNSPIRVABIInfo::numRegsForType(QualType Ty) const {
214 // This duplicates the AMDGPUABI computation.
215 uint64_t NumRegs = 0;
216
217 if (const VectorType *VT = Ty->getAs<VectorType>()) {
218 // Compute from the number of elements. The reported size is based on the
219 // in-memory size, which includes the padding 4th element for 3-vectors.
220 QualType EltTy = VT->getElementType();
221 uint64_t EltSize = getContext().getTypeSize(EltTy);
222
223 // 16-bit element vectors should be passed as packed.
224 if (EltSize == 16)
225 return (VT->getNumElements() + 1) / 2;
226
227 uint64_t EltNumRegs = (EltSize + 31) / 32;
228 return EltNumRegs * VT->getNumElements();
229 }
230
231 if (const auto *RD = Ty->getAsRecordDecl()) {
232 assert(!RD->hasFlexibleArrayMember());
233
234 for (const FieldDecl *Field : RD->fields()) {
235 QualType FieldTy = Field->getType();
236 NumRegs += numRegsForType(FieldTy);
237 }
238
239 return NumRegs;
240 }
241
242 return (getContext().getTypeSize(Ty) + 31) / 32;
243}
244
245llvm::Type *AMDGCNSPIRVABIInfo::coerceKernelArgumentType(llvm::Type *Ty,
246 unsigned FromAS,
247 unsigned ToAS) const {
248 // Single value types.
249 auto *PtrTy = llvm::dyn_cast<llvm::PointerType>(Ty);
250 if (PtrTy && PtrTy->getAddressSpace() == FromAS)
251 return llvm::PointerType::get(Ty->getContext(), ToAS);
252 return Ty;
253}
254
255ABIArgInfo AMDGCNSPIRVABIInfo::classifyReturnType(QualType RetTy) const {
256 if (!isAggregateTypeForABI(RetTy) || getRecordArgABI(RetTy, getCXXABI()))
258
259 // Ignore empty structs/unions.
260 if (isEmptyRecord(getContext(), RetTy, true))
261 return ABIArgInfo::getIgnore();
262
263 // Lower single-element structs to just return a regular value.
264 if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext()))
265 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
266
267 if (const auto *RD = RetTy->getAsRecordDecl();
268 RD && RD->hasFlexibleArrayMember())
270
271 // Pack aggregates <= 4 bytes into single VGPR or pair.
272 uint64_t Size = getContext().getTypeSize(RetTy);
273 if (Size <= 16)
274 return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext()));
275
276 if (Size <= 32)
277 return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
278
279 // TODO: This carried over from AMDGPU oddity, we retain it to
280 // ensure consistency, but it might be reasonable to return Int64.
281 if (Size <= 64) {
282 llvm::Type *I32Ty = llvm::Type::getInt32Ty(getVMContext());
283 return ABIArgInfo::getDirect(llvm::ArrayType::get(I32Ty, 2));
284 }
285
286 if (numRegsForType(RetTy) <= MaxNumRegsForArgsRet)
287 return ABIArgInfo::getDirect();
289}
290
291/// For kernels all parameters are really passed in a special buffer. It doesn't
292/// make sense to pass anything byval, so everything must be direct.
293ABIArgInfo AMDGCNSPIRVABIInfo::classifyKernelArgumentType(QualType Ty) const {
295
296 // TODO: Can we omit empty structs?
297
298 if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
299 Ty = QualType(SeltTy, 0);
300
301 llvm::Type *OrigLTy = CGT.ConvertType(Ty);
302 llvm::Type *LTy = OrigLTy;
303 if (getContext().getLangOpts().isTargetDevice()) {
304 LTy = coerceKernelArgumentType(
305 OrigLTy, /*FromAS=*/getContext().getTargetAddressSpace(LangAS::Default),
306 /*ToAS=*/getContext().getTargetAddressSpace(LangAS::opencl_global));
307 }
308
309 // FIXME: This doesn't apply the optimization of coercing pointers in structs
310 // to global address space when using byref. This would require implementing a
311 // new kind of coercion of the in-memory type when for indirect arguments.
312 if (LTy == OrigLTy && isAggregateTypeForABI(Ty)) {
314 getContext().getTypeAlignInChars(Ty),
315 getContext().getTargetAddressSpace(LangAS::opencl_constant),
316 false /*Realign*/, nullptr /*Padding*/);
317 }
318
319 // TODO: inhibiting flattening is an AMDGPU workaround for Clover, which might
320 // be vestigial and should be revisited.
321 return ABIArgInfo::getDirect(LTy, 0, nullptr, false);
322}
323
324ABIArgInfo AMDGCNSPIRVABIInfo::classifyArgumentType(QualType Ty,
325 bool Variadic) const {
326 assert(NumRegsLeft <= MaxNumRegsForArgsRet && "register estimate underflow");
327
329
330 if (Variadic) {
331 return ABIArgInfo::getDirect(/*T=*/nullptr,
332 /*Offset=*/0,
333 /*Padding=*/nullptr,
334 /*CanBeFlattened=*/false,
335 /*Align=*/0);
336 }
337
338 if (!isAggregateTypeForABI(Ty)) {
339 ABIArgInfo ArgInfo = DefaultABIInfo::classifyArgumentType(Ty);
340 if (!ArgInfo.isIndirect()) {
341 uint64_t NumRegs = numRegsForType(Ty);
342 NumRegsLeft -= std::min(NumRegs, uint64_t{NumRegsLeft});
343 }
344
345 return ArgInfo;
346 }
347
348 // Records with non-trivial destructors/copy-constructors should not be
349 // passed by value.
350 if (auto RAA = getRecordArgABI(Ty, getCXXABI()))
351 return getNaturalAlignIndirect(Ty, getDataLayout().getAllocaAddrSpace(),
353
354 // Ignore empty structs/unions.
355 if (isEmptyRecord(getContext(), Ty, true))
356 return ABIArgInfo::getIgnore();
357
358 // Lower single-element structs to just pass a regular value. TODO: We
359 // could do reasonable-size multiple-element structs too, using getExpand(),
360 // though watch out for things like bitfields.
361 if (const Type *SeltTy = isSingleElementStruct(Ty, getContext()))
362 return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0)));
363
364 if (const auto *RD = Ty->getAsRecordDecl();
365 RD && RD->hasFlexibleArrayMember())
367
368 uint64_t Size = getContext().getTypeSize(Ty);
369 if (Size <= 64) {
370 // Pack aggregates <= 8 bytes into single VGPR or pair.
371 unsigned NumRegs = (Size + 31) / 32;
372 NumRegsLeft -= std::min(NumRegsLeft, NumRegs);
373
374 if (Size <= 16)
375 return ABIArgInfo::getDirect(llvm::Type::getInt16Ty(getVMContext()));
376
377 if (Size <= 32)
378 return ABIArgInfo::getDirect(llvm::Type::getInt32Ty(getVMContext()));
379
380 // TODO: This is an AMDGPU oddity, and might be vestigial, we retain it to
381 // ensure consistency, but it should be revisited.
382 llvm::Type *I32Ty = llvm::Type::getInt32Ty(getVMContext());
383 return ABIArgInfo::getDirect(llvm::ArrayType::get(I32Ty, 2));
384 }
385
386 if (NumRegsLeft > 0) {
387 uint64_t NumRegs = numRegsForType(Ty);
388 if (NumRegsLeft >= NumRegs) {
389 NumRegsLeft -= NumRegs;
390 return ABIArgInfo::getDirect();
391 }
392 }
393
394 // Use pass-by-reference in stead of pass-by-value for struct arguments in
395 // function ABI.
397 getContext().getTypeAlignInChars(Ty),
398 getContext().getTargetAddressSpace(LangAS::opencl_private));
399}
400
401void AMDGCNSPIRVABIInfo::computeInfo(CGFunctionInfo &FI) const {
402 llvm::CallingConv::ID CC = FI.getCallingConvention();
403
404 if (!getCXXABI().classifyReturnType(FI))
406
407 unsigned ArgumentIndex = 0;
408 const unsigned NumRequiredArgs = FI.getNumRequiredArgs();
409
410 NumRegsLeft = MaxNumRegsForArgsRet;
411 for (auto &I : FI.arguments()) {
412 if (CC == llvm::CallingConv::SPIR_KERNEL) {
413 I.info = classifyKernelArgumentType(I.type);
414 } else {
415 bool FixedArgument = ArgumentIndex++ < NumRequiredArgs;
416 I.info = classifyArgumentType(I.type, !FixedArgument);
417 }
418 }
419}
420
421llvm::FixedVectorType *
422SPIRVABIInfo::getOptimalVectorMemoryType(llvm::FixedVectorType *Ty,
423 const LangOptions &LangOpt) const {
424 // For Logical SPIR-V, we don't know the underlying hardware or layout.
425 // This means we don't know which vector size is better, and also cannot
426 // assume a smaller vector size is stored in a larger vector size.
427 if (getTarget().getTriple().isSPIRVLogical())
428 return Ty;
429 return DefaultABIInfo::getOptimalVectorMemoryType(Ty, LangOpt);
430}
431
432llvm::FixedVectorType *AMDGCNSPIRVABIInfo::getOptimalVectorMemoryType(
433 llvm::FixedVectorType *Ty, const LangOptions &LangOpt) const {
434 // AMDGPU has legal instructions for 96-bit so 3x32 can be supported.
435 if (Ty->getNumElements() == 3 && getDataLayout().getTypeSizeInBits(Ty) == 96)
436 return Ty;
437 return DefaultABIInfo::getOptimalVectorMemoryType(Ty, LangOpt);
438}
439
440namespace clang {
441namespace CodeGen {
443 if (CGM.getTarget().getTriple().isSPIRV()) {
444 if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::AMD)
445 AMDGCNSPIRVABIInfo(CGM.getTypes()).computeInfo(FI);
446 else
447 SPIRVABIInfo(CGM.getTypes()).computeInfo(FI);
448 } else {
449 CommonSPIRABIInfo(CGM.getTypes()).computeInfo(FI);
450 }
451}
452}
453}
454
455unsigned CommonSPIRTargetCodeGenInfo::getDeviceKernelCallingConv() const {
456 return llvm::CallingConv::SPIR_KERNEL;
457}
458
459LangAS SPIRVTargetCodeGenInfo::getSRetAddrSpace(const CXXRecordDecl *RD) const {
460 // Types with no viable copy/move must be constructed in-place, use the
461 // default AS so the sret pointer matches the "this" convention.
462 if (RD && !RD->canPassInRegisters())
463 return LangAS::Default;
465 getABIInfo().getDataLayout().getAllocaAddrSpace());
466}
467
468void SPIRVTargetCodeGenInfo::setCUDAKernelCallingConvention(
469 const FunctionType *&FT) const {
470 // Convert HIP kernels to SPIR-V kernels.
471 if (getABIInfo().getContext().getLangOpts().HIP) {
472 FT = getABIInfo().getContext().adjustFunctionType(
474 return;
475 }
476}
477
478void CommonSPIRTargetCodeGenInfo::setOCLKernelStubCallingConvention(
479 const FunctionType *&FT) const {
480 FT = getABIInfo().getContext().adjustFunctionType(
481 FT, FT->getExtInfo().withCallingConv(CC_C));
482}
483
484// LLVM currently assumes a null pointer has the bit pattern 0, but some GPU
485// targets use a non-zero encoding for null in certain address spaces.
486// Because SPIR(-V) is a generic target and the bit pattern of null in
487// non-generic AS is unspecified, materialize null in non-generic AS via an
488// addrspacecast from null in generic AS. This allows later lowering to
489// substitute the target's real sentinel value.
490llvm::Constant *
491CommonSPIRTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
492 llvm::PointerType *PT,
493 QualType QT) const {
495 ? LangAS::Default
497 unsigned ASAsInt = static_cast<unsigned>(AS);
498 unsigned FirstTargetASAsInt =
499 static_cast<unsigned>(LangAS::FirstTargetAddressSpace);
500 unsigned CodeSectionINTELAS = FirstTargetASAsInt + 9;
501 // As per SPV_INTEL_function_pointers, it is illegal to addrspacecast
502 // function pointers to/from the generic AS.
503 bool IsFunctionPtrAS =
504 CGM.getTriple().isSPIRV() && ASAsInt == CodeSectionINTELAS;
505 if (AS == LangAS::Default || AS == LangAS::opencl_generic ||
506 AS == LangAS::opencl_constant || IsFunctionPtrAS)
507 return llvm::ConstantPointerNull::get(PT);
508
509 auto &Ctx = CGM.getContext();
510 auto NPT = llvm::PointerType::get(
511 PT->getContext(), Ctx.getTargetAddressSpace(LangAS::opencl_generic));
512 return llvm::ConstantExpr::getAddrSpaceCast(
513 llvm::ConstantPointerNull::get(NPT), PT);
514}
515
516LangAS
517SPIRVTargetCodeGenInfo::getGlobalVarAddressSpace(CodeGenModule &CGM,
518 const VarDecl *D) const {
519 assert(!CGM.getLangOpts().OpenCL &&
520 !(CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) &&
521 "Address space agnostic languages only");
522 // If we're here it means that we're using the SPIRDefIsGen ASMap, hence for
523 // the global AS we can rely on either cuda_device or sycl_global to be
524 // correct; however, since this is not a CUDA Device context, we use
525 // sycl_global to prevent confusion with the assertion.
526 LangAS DefaultGlobalAS = getLangASFromTargetAS(
527 CGM.getContext().getTargetAddressSpace(LangAS::sycl_global));
528 if (!D)
529 return DefaultGlobalAS;
530
531 LangAS AddrSpace = D->getType().getAddressSpace();
532 if (AddrSpace != LangAS::Default)
533 return AddrSpace;
534
535 return DefaultGlobalAS;
536}
537
538void SPIRVTargetCodeGenInfo::setTargetAttributes(
539 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
540 if (GV->isDeclaration())
541 return;
542
543 const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D);
544 if (!FD)
545 return;
546
547 llvm::Function *F = dyn_cast<llvm::Function>(GV);
548 assert(F && "Expected GlobalValue to be a Function");
549
550 if (!M.getLangOpts().HIP ||
551 M.getTarget().getTriple().getVendor() != llvm::Triple::AMD)
552 return;
553
554 if (!FD->hasAttr<CUDAGlobalAttr>())
555 return;
556
557 unsigned N = M.getLangOpts().GPUMaxThreadsPerBlock;
558 if (auto FlatWGS = FD->getAttr<AMDGPUFlatWorkGroupSizeAttr>()) {
559 N = FlatWGS->getMax()->EvaluateKnownConstInt(M.getContext()).getExtValue();
560 } else if (auto LB = FD->getAttr<CUDALaunchBoundsAttr>()) {
561 if (uint64_t MaxThreads = LB->getMaxThreads()
562 ->EvaluateKnownConstInt(M.getContext())
563 .getExtValue())
564 N = MaxThreads;
565 }
566
567 // We encode the maximum flat WG size in the first component of the 3D
568 // max_work_group_size attribute, which will get reverse translated into the
569 // original AMDGPU attribute when targeting AMDGPU.
570 auto Int32Ty = llvm::IntegerType::getInt32Ty(M.getLLVMContext());
571 llvm::Metadata *AttrMDArgs[] = {
572 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, N)),
573 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1)),
574 llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(Int32Ty, 1))};
575
576 F->setMetadata("max_work_group_size",
577 llvm::MDNode::get(M.getLLVMContext(), AttrMDArgs));
578}
579
580StringRef SPIRVTargetCodeGenInfo::getLLVMSyncScopeStr(
581 const LangOptions &, SyncScope Scope, llvm::AtomicOrdering) const {
582 return *llvm::getAtomicScopeIRString(getABIInfo().getTarget().getTriple(),
583 getAtomicScope(Scope));
584}
585
586void SPIRVTargetCodeGenInfo::setTargetAtomicMetadata(
587 CodeGenFunction &CGF, llvm::Instruction &AtomicInst,
588 const AtomicExpr *AE) const {
589 if (CGF.CGM.getTriple().getVendor() != llvm::Triple::VendorType::AMD)
590 return;
591
592 auto *RMW = dyn_cast<llvm::AtomicRMWInst>(&AtomicInst);
593 if (!RMW)
594 return;
595
596 AtomicOptions AO = CGF.CGM.getAtomicOpts();
597 llvm::MDNode *Empty = llvm::MDNode::get(CGF.getLLVMContext(), {});
599 RMW->setMetadata("amdgpu.no.fine.grained.memory", Empty);
601 RMW->setMetadata("amdgpu.no.remote.memory", Empty);
603 RMW->getOperation() == llvm::AtomicRMWInst::FAdd &&
604 RMW->getType()->isFloatTy())
605 RMW->setMetadata(llvm::LLVMContext::MD_atomic_ignore_denormal_mode, Empty);
606}
607
608/// Construct a SPIR-V target extension type for the given OpenCL image type.
609static llvm::Type *getSPIRVImageType(llvm::LLVMContext &Ctx, StringRef BaseType,
610 StringRef OpenCLName,
611 unsigned AccessQualifier) {
612 // These parameters compare to the operands of OpTypeImage (see
613 // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypeImage
614 // for more details). The first 6 integer parameters all default to 0, and
615 // will be changed to 1 only for the image type(s) that set the parameter to
616 // one. The 7th integer parameter is the access qualifier, which is tacked on
617 // at the end.
618 SmallVector<unsigned, 7> IntParams = {0, 0, 0, 0, 0, 0};
619
620 // Choose the dimension of the image--this corresponds to the Dim enum in
621 // SPIR-V (first integer parameter of OpTypeImage).
622 if (OpenCLName.starts_with("image2d"))
623 IntParams[0] = 1;
624 else if (OpenCLName.starts_with("image3d"))
625 IntParams[0] = 2;
626 else if (OpenCLName == "image1d_buffer")
627 IntParams[0] = 5; // Buffer
628 else
629 assert(OpenCLName.starts_with("image1d") && "Unknown image type");
630
631 // Set the other integer parameters of OpTypeImage if necessary. Note that the
632 // OpenCL image types don't provide any information for the Sampled or
633 // Image Format parameters.
634 if (OpenCLName.contains("_depth"))
635 IntParams[1] = 1;
636 if (OpenCLName.contains("_array"))
637 IntParams[2] = 1;
638 if (OpenCLName.contains("_msaa"))
639 IntParams[3] = 1;
640
641 // Access qualifier
642 IntParams.push_back(AccessQualifier);
643
644 return llvm::TargetExtType::get(Ctx, BaseType, {llvm::Type::getVoidTy(Ctx)},
645 IntParams);
646}
647
648llvm::Type *CommonSPIRTargetCodeGenInfo::getOpenCLType(CodeGenModule &CGM,
649 const Type *Ty) const {
650 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
651 if (auto *PipeTy = dyn_cast<PipeType>(Ty))
652 return llvm::TargetExtType::get(Ctx, "spirv.Pipe", {},
653 {!PipeTy->isReadOnly()});
654 if (auto *BuiltinTy = dyn_cast<BuiltinType>(Ty)) {
655 enum AccessQualifier : unsigned { AQ_ro = 0, AQ_wo = 1, AQ_rw = 2 };
656 switch (BuiltinTy->getKind()) {
657#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
658 case BuiltinType::Id: \
659 return getSPIRVImageType(Ctx, "spirv.Image", #ImgType, AQ_##Suffix);
660#include "clang/Basic/OpenCLImageTypes.def"
661 case BuiltinType::OCLSampler:
662 return llvm::TargetExtType::get(Ctx, "spirv.Sampler");
663 case BuiltinType::OCLEvent:
664 return llvm::TargetExtType::get(Ctx, "spirv.Event");
665 case BuiltinType::OCLClkEvent:
666 return llvm::TargetExtType::get(Ctx, "spirv.DeviceEvent");
667 case BuiltinType::OCLQueue:
668 return llvm::TargetExtType::get(Ctx, "spirv.Queue");
669 case BuiltinType::OCLReserveID:
670 return llvm::TargetExtType::get(Ctx, "spirv.ReserveId");
671#define INTEL_SUBGROUP_AVC_TYPE(Name, Id) \
672 case BuiltinType::OCLIntelSubgroupAVC##Id: \
673 return llvm::TargetExtType::get(Ctx, "spirv.Avc" #Id "INTEL");
674#include "clang/Basic/OpenCLExtensionTypes.def"
675 default:
676 return nullptr;
677 }
678 }
679
680 return nullptr;
681}
682
683// Gets a spirv.IntegralConstant or spirv.Literal. If IntegralType is present,
684// returns an IntegralConstant, otherwise returns a Literal.
685static llvm::Type *getInlineSpirvConstant(CodeGenModule &CGM,
686 llvm::Type *IntegralType,
687 llvm::APInt Value) {
688 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
689
690 // Convert the APInt value to an array of uint32_t words
692
693 while (Value.ugt(0)) {
694 uint32_t Word = Value.trunc(32).getZExtValue();
695 Value.lshrInPlace(32);
696
697 Words.push_back(Word);
698 }
699 if (Words.size() == 0)
700 Words.push_back(0);
701
702 if (IntegralType)
703 return llvm::TargetExtType::get(Ctx, "spirv.IntegralConstant",
704 {IntegralType}, Words);
705 return llvm::TargetExtType::get(Ctx, "spirv.Literal", {}, Words);
706}
707
708static llvm::Type *getInlineSpirvType(CodeGenModule &CGM,
709 const HLSLInlineSpirvType *SpirvType) {
710 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
711
713
714 for (auto &Operand : SpirvType->getOperands()) {
715 using SpirvOperandKind = SpirvOperand::SpirvOperandKind;
716
717 llvm::Type *Result = nullptr;
718 switch (Operand.getKind()) {
719 case SpirvOperandKind::ConstantId: {
720 llvm::Type *IntegralType =
721 CGM.getTypes().ConvertType(Operand.getResultType());
722
723 Result = getInlineSpirvConstant(CGM, IntegralType, Operand.getValue());
724 break;
725 }
726 case SpirvOperandKind::Literal: {
727 Result = getInlineSpirvConstant(CGM, nullptr, Operand.getValue());
728 break;
729 }
730 case SpirvOperandKind::TypeId: {
731 QualType TypeOperand = Operand.getResultType();
732 if (const auto *RD = TypeOperand->getAsRecordDecl()) {
733 assert(RD->isCompleteDefinition() &&
734 "Type completion should have been required in Sema");
735
736 const FieldDecl *HandleField = RD->findFirstNamedDataMember();
737 if (HandleField) {
738 QualType ResourceType = HandleField->getType();
739 if (ResourceType->getAs<HLSLAttributedResourceType>()) {
740 TypeOperand = ResourceType;
741 }
742 }
743 }
744 Result = CGM.getTypes().ConvertType(TypeOperand);
745 break;
746 }
747 default:
748 llvm_unreachable("HLSLInlineSpirvType had invalid operand!");
749 break;
750 }
751
752 assert(Result);
753 Operands.push_back(Result);
754 }
755
756 return llvm::TargetExtType::get(Ctx, "spirv.Type", Operands,
757 {SpirvType->getOpcode(), SpirvType->getSize(),
758 SpirvType->getAlignment()});
759}
760
761llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(
762 CodeGenModule &CGM, const Type *Ty,
763 const CGHLSLOffsetInfo &OffsetInfo) const {
764 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
765
766 if (auto *SpirvType = dyn_cast<HLSLInlineSpirvType>(Ty))
767 return getInlineSpirvType(CGM, SpirvType);
768
769 auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
770 if (!ResType)
771 return nullptr;
772
773 const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
774 switch (ResAttrs.ResourceClass) {
775 case llvm::dxil::ResourceClass::UAV:
776 case llvm::dxil::ResourceClass::SRV: {
777 // TypedBuffer and RawBuffer both need element type
778 QualType ContainedTy = ResType->getContainedType();
779 if (ContainedTy.isNull())
780 return nullptr;
781
782 assert(!ResAttrs.IsROV &&
783 "Rasterizer order views not implemented for SPIR-V yet");
784
785 if (!ResAttrs.RawBuffer) {
786 // convert element type
787 return getSPIRVImageTypeFromHLSLResource(ResAttrs, ContainedTy, CGM);
788 }
789
790 if (ResAttrs.IsCounter) {
791 llvm::Type *ElemType = llvm::Type::getInt32Ty(Ctx);
792 uint32_t StorageClass = /* StorageBuffer storage class */ 12;
793 return llvm::TargetExtType::get(Ctx, "spirv.VulkanBuffer", {ElemType},
794 {StorageClass, true});
795 }
796 llvm::Type *ElemType = CGM.getTypes().ConvertTypeForMem(ContainedTy);
797 llvm::ArrayType *RuntimeArrayType = llvm::ArrayType::get(ElemType, 0);
798 uint32_t StorageClass = /* StorageBuffer storage class */ 12;
799 bool IsWritable = ResAttrs.ResourceClass == llvm::dxil::ResourceClass::UAV;
800 return llvm::TargetExtType::get(Ctx, "spirv.VulkanBuffer",
801 {RuntimeArrayType},
802 {StorageClass, IsWritable});
803 }
804 case llvm::dxil::ResourceClass::CBuffer: {
805 QualType ContainedTy = ResType->getContainedType();
806 if (ContainedTy.isNull() || !ContainedTy->isStructureType())
807 return nullptr;
808
809 llvm::StructType *BufferLayoutTy =
810 HLSLBufferLayoutBuilder(CGM).layOutStruct(
811 ContainedTy->getAsCanonical<RecordType>(), OffsetInfo);
812 uint32_t StorageClass = /* Uniform storage class */ 2;
813 return llvm::TargetExtType::get(Ctx, "spirv.VulkanBuffer", {BufferLayoutTy},
814 {StorageClass, false});
815 break;
816 }
817 case llvm::dxil::ResourceClass::Sampler:
818 return llvm::TargetExtType::get(Ctx, "spirv.Sampler");
819 }
820 return nullptr;
821}
822
823static unsigned
825 const HLSLAttributedResourceType::Attributes &attributes,
826 llvm::Type *SampledType, QualType Ty, unsigned NumChannels) {
827 // For images with `Sampled` operand equal to 2, there are restrictions on
828 // using the Unknown image format. To avoid these restrictions in common
829 // cases, we guess an image format for them based on the sampled type and the
830 // number of channels. This is intended to match the behaviour of DXC.
831 if (LangOpts.HLSLSpvUseUnknownImageFormat ||
832 attributes.ResourceClass != llvm::dxil::ResourceClass::UAV) {
833 return 0; // Unknown
834 }
835
836 if (SampledType->isIntegerTy(32)) {
837 if (Ty->isSignedIntegerType()) {
838 if (NumChannels == 1)
839 return 24; // R32i
840 if (NumChannels == 2)
841 return 25; // Rg32i
842 if (NumChannels == 4)
843 return 21; // Rgba32i
844 } else {
845 if (NumChannels == 1)
846 return 33; // R32ui
847 if (NumChannels == 2)
848 return 35; // Rg32ui
849 if (NumChannels == 4)
850 return 30; // Rgba32ui
851 }
852 } else if (SampledType->isIntegerTy(64)) {
853 if (NumChannels == 1) {
854 if (Ty->isSignedIntegerType()) {
855 return 41; // R64i
856 }
857 return 40; // R64ui
858 }
859 } else if (SampledType->isFloatTy()) {
860 if (NumChannels == 1)
861 return 3; // R32f
862 if (NumChannels == 2)
863 return 6; // Rg32f
864 if (NumChannels == 4)
865 return 1; // Rgba32f
866 }
867
868 return 0; // Unknown
869}
870
871llvm::Type *CommonSPIRTargetCodeGenInfo::getSPIRVImageTypeFromHLSLResource(
872 const HLSLAttributedResourceType::Attributes &attributes, QualType Ty,
873 CodeGenModule &CGM) const {
874 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
875
876 unsigned NumChannels = 1;
878 if (const VectorType *V = dyn_cast<VectorType>(Ty)) {
879 NumChannels = V->getNumElements();
880 Ty = V->getElementType();
881 }
882 assert(!Ty->isVectorType() && "We still have a vector type.");
883
884 llvm::Type *SampledType = CGM.getTypes().ConvertTypeForMem(Ty);
885
886 assert((SampledType->isIntegerTy() || SampledType->isFloatingPointTy()) &&
887 "The element type for a SPIR-V resource must be a scalar integer or "
888 "floating point type.");
889
890 assert((!SampledType->isIntegerTy(64) || NumChannels <= 2) &&
891 "A 64-bit SPIR-V resource element can have at most 2 components.");
892
893 // SPIR-V has no 64-bit multi-component image format, so pack a 2-component
894 // 64-bit typed buffer into a 4-component 32-bit image. The backend
895 // reinterprets it with OpBitcast on load and store.
896 if (SampledType->isIntegerTy(64) && NumChannels == 2) {
897 SampledType = llvm::Type::getInt32Ty(Ctx);
898 NumChannels = 4;
899 }
900
901 // These parameters correspond to the operands to the OpTypeImage SPIR-V
902 // instruction. See
903 // https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypeImage.
904 SmallVector<unsigned, 6> IntParams(6, 0);
905
906 const char *Name =
907 Ty->isSignedIntegerType() ? "spirv.SignedImage" : "spirv.Image";
908
909 // Dim
910 switch (attributes.ResourceDimension) {
911 case llvm::dxil::ResourceDimension::Dim1D:
912 IntParams[0] = 0;
913 break;
914 case llvm::dxil::ResourceDimension::Dim2D:
915 IntParams[0] = 1;
916 break;
917 case llvm::dxil::ResourceDimension::Dim3D:
918 IntParams[0] = 2;
919 break;
920 case llvm::dxil::ResourceDimension::Cube:
921 IntParams[0] = 3;
922 break;
923 case llvm::dxil::ResourceDimension::Unknown:
924 IntParams[0] = 5;
925 break;
926 }
927
928 // Depth
929 // HLSL does not indicate if it is a depth texture or not, so we use unknown.
930 IntParams[1] = 2;
931
932 // Arrayed
933 IntParams[2] = static_cast<unsigned>(attributes.IsArray);
934
935 // MS
936 IntParams[3] = static_cast<unsigned>(attributes.isMultiSampled());
937
938 // Sampled
939 IntParams[4] =
940 attributes.ResourceClass == llvm::dxil::ResourceClass::UAV ? 2 : 1;
941
942 // Image format.
943 IntParams[5] = getImageFormat(CGM.getLangOpts(), attributes, SampledType, Ty,
944 NumChannels);
945
946 llvm::TargetExtType *ImageType =
947 llvm::TargetExtType::get(Ctx, Name, {SampledType}, IntParams);
948 return ImageType;
949}
950
951std::unique_ptr<TargetCodeGenInfo>
953 return std::make_unique<CommonSPIRTargetCodeGenInfo>(CGM.getTypes());
954}
955
956std::unique_ptr<TargetCodeGenInfo>
958 return std::make_unique<SPIRVTargetCodeGenInfo>(CGM.getTypes());
959}
#define V(N, I)
static void setCUDAKernelCallingConvention(CanQualType &funcTy, CIRGenModule &cgm, const FunctionDecl *fd)
Set calling convention for CUDA/HIP kernel.
static llvm::Type * getInlineSpirvType(CodeGenModule &CGM, const HLSLInlineSpirvType *SpirvType)
Definition SPIR.cpp:708
static llvm::Type * getSPIRVImageType(llvm::LLVMContext &Ctx, StringRef BaseType, StringRef OpenCLName, unsigned AccessQualifier)
Construct a SPIR-V target extension type for the given OpenCL image type.
Definition SPIR.cpp:609
static unsigned getImageFormat(const LangOptions &LangOpts, const HLSLAttributedResourceType::Attributes &attributes, llvm::Type *SampledType, QualType Ty, unsigned NumChannels)
Definition SPIR.cpp:824
static llvm::Type * getInlineSpirvConstant(CodeGenModule &CGM, llvm::Type *IntegralType, llvm::APInt Value)
Definition SPIR.cpp:685
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Result
Implement __builtin_bit_cast and related operations.
Defines the clang::LangOptions interface.
static StringRef getTriple(const Command &Job)
unsigned getTargetAddressSpace(LangAS AS) const
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
static ABIArgInfo getIgnore()
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
static ABIArgInfo getIndirectAliased(CharUnits Alignment, unsigned AddrSpace, bool Realign=false, llvm::Type *Padding=nullptr)
Pass this in memory using the IR byref attribute.
@ RAA_DirectInMemory
Pass it on the stack using its defined layout.
Definition CGCXXABI.h:158
CGFunctionInfo - Class to encapsulate the information about a function definition.
unsigned getCallingConvention() const
getCallingConvention - Return the user specified calling convention, which has been translated into a...
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
llvm::LLVMContext & getLLVMContext()
This class organizes the cross-function state that is used while generating LLVM code.
const LangOptions & getLangOpts() const
const TargetInfo & getTarget() const
const llvm::Triple & getTriple() const
AtomicOptions getAtomicOpts()
Get the current Atomic options.
ASTContext & getContext() const
llvm::LLVMContext & getLLVMContext()
llvm::Type * ConvertType(QualType T)
ConvertType - Convert type T into a llvm::Type.
llvm::Type * ConvertTypeForMem(QualType T)
ConvertTypeForMem - Convert type T into a llvm::Type.
DefaultABIInfo - The default implementation for ABI specific details.
Definition ABIInfoImpl.h:21
ABIArgInfo classifyArgumentType(QualType RetTy) const
ABIArgInfo classifyReturnType(QualType RetTy) const
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition TargetInfo.h:80
T * getAttr() const
Definition DeclBase.h:581
bool hasAttr() const
Definition DeclBase.h:585
Represents a member of a struct/union/class.
Definition Decl.h:3295
ExtInfo withCallingConv(CallingConv cc) const
Definition TypeBase.h:4817
ExtInfo getExtInfo() const
Definition TypeBase.h:4950
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A (possibly-)qualified type.
Definition TypeBase.h:938
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1005
LangAS getAddressSpace() const
Return the address space of this type.
Definition TypeBase.h:8554
bool canPassInRegisters() const
Determine whether this class can be passed in registers.
Definition Decl.h:4597
bool hasFlexibleArrayMember() const
Definition Decl.h:4493
const FieldDecl * findFirstNamedDataMember() const
Finds the first data member which has a name.
Definition Decl.cpp:5469
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition Decl.h:3953
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
bool isStructureType() const
Definition Type.cpp:807
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char,...
Definition Type.cpp:2388
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
CanQualType getCanonicalTypeUnqualified() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
Definition Type.cpp:881
bool isVectorType() const
Definition TypeBase.h:8804
const T * getAsCanonical() const
If this type is canonically the specified type, return its canonical type cast to that specified type...
Definition TypeBase.h:2998
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9264
const Type * getUnqualifiedDesugaredType() const
Return the specified type with any "sugar" removed from the type, removing any typedefs,...
Definition Type.cpp:782
bool isNullPtrType() const
Definition TypeBase.h:9074
QualType getType() const
Definition Decl.h:724
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Definition CGValue.h:146
CGCXXABI::RecordArgABI getRecordArgABI(const RecordType *RT, CGCXXABI &CXXABI)
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
void computeSPIRKernelABIInfo(CodeGenModule &CGM, CGFunctionInfo &FI)
Definition SPIR.cpp:442
RValue emitVoidPtrVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType ValueTy, bool IsIndirect, TypeInfoChars ValueInfo, CharUnits SlotSizeAndAlign, bool AllowHigherAlign, AggValueSlot Slot, bool ForceRightAdjust=false)
Emit va_arg for a platform using the common void* representation, where arguments are simply emitted ...
bool isAggregateTypeForABI(QualType T)
const Type * isSingleElementStruct(QualType T, ASTContext &Context)
isSingleElementStruct - Determine if a structure is a "singleelement struct", i.e.
std::unique_ptr< TargetCodeGenInfo > createSPIRVTargetCodeGenInfo(CodeGenModule &CGM)
Definition SPIR.cpp:957
QualType useFirstFieldIfTransparentUnion(QualType Ty)
Pass transparent unions as if they were the type of the first element.
std::unique_ptr< TargetCodeGenInfo > createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM)
Definition SPIR.cpp:952
bool isEmptyRecord(ASTContext &Context, QualType T, bool AllowArrays, bool AsIfNoUniqueAddr=false)
isEmptyRecord - Return true iff a structure contains only empty fields.
Top level wrappers for InstallAPI frontend operations.
StorageClass
Storage classes.
Definition Specifiers.h:249
const FunctionProtoType * T
@ Type
The name was classified as a type.
Definition Sema.h:558
LangAS
Defines the address space values used by the address space qualifier of QualType.
llvm::AtomicScope getAtomicScope(SyncScope S)
Collapses a clang sync scope onto the target-neutral llvm::AtomicScope.
Definition TargetInfo.h:40
for(const auto &A :T->param_types())
SyncScope
Defines sync scope values used internally by clang.
Definition SyncScope.h:43
@ CC_DeviceKernel
Definition Specifiers.h:292
LangAS getLangASFromTargetAS(unsigned TargetAS)
unsigned long uint64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_t
bool getOption(AtomicOptionKind Kind) const