aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/Targets
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/CodeGen/Targets')
-rw-r--r--clang/lib/CodeGen/Targets/DirectX.cpp9
-rw-r--r--clang/lib/CodeGen/Targets/SPIR.cpp19
2 files changed, 17 insertions, 11 deletions
diff --git a/clang/lib/CodeGen/Targets/DirectX.cpp b/clang/lib/CodeGen/Targets/DirectX.cpp
index b4cebb9..f30b302 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -29,14 +29,13 @@ public:
DirectXTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)
: TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(CGT)) {}
- llvm::Type *
- getHLSLType(CodeGenModule &CGM, const Type *T,
- const SmallVector<int32_t> *Packoffsets = nullptr) const override;
+ llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *T,
+ const CGHLSLOffsetInfo &OffsetInfo) const override;
};
llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
CodeGenModule &CGM, const Type *Ty,
- const SmallVector<int32_t> *Packoffsets) const {
+ const CGHLSLOffsetInfo &OffsetInfo) const {
auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
if (!ResType)
return nullptr;
@@ -78,7 +77,7 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
llvm::Type *BufferLayoutTy =
HLSLBufferLayoutBuilder(CGM, "dx.Layout")
.createLayoutType(ContainedTy->castAsCanonical<RecordType>(),
- Packoffsets);
+ OffsetInfo);
if (!BufferLayoutTy)
return nullptr;
diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp b/clang/lib/CodeGen/Targets/SPIR.cpp
index abd049a..be7e9cc 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -53,9 +53,8 @@ public:
unsigned getDeviceKernelCallingConv() const override;
llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const override;
- llvm::Type *
- getHLSLType(CodeGenModule &CGM, const Type *Ty,
- const SmallVector<int32_t> *Packoffsets = nullptr) const override;
+ llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *Ty,
+ const CGHLSLOffsetInfo &OffsetInfo) const override;
llvm::Type *getSPIRVImageTypeFromHLSLResource(
const HLSLAttributedResourceType::Attributes &attributes,
QualType SampledType, CodeGenModule &CGM) const;
@@ -260,8 +259,16 @@ CommonSPIRTargetCodeGenInfo::getNullPointer(const CodeGen::CodeGenModule &CGM,
LangAS AS = QT->getUnqualifiedDesugaredType()->isNullPtrType()
? LangAS::Default
: QT->getPointeeType().getAddressSpace();
+ unsigned ASAsInt = static_cast<unsigned>(AS);
+ unsigned FirstTargetASAsInt =
+ static_cast<unsigned>(LangAS::FirstTargetAddressSpace);
+ unsigned CodeSectionINTELAS = FirstTargetASAsInt + 9;
+ // As per SPV_INTEL_function_pointers, it is illegal to addrspacecast
+ // function pointers to/from the generic AS.
+ bool IsFunctionPtrAS =
+ CGM.getTriple().isSPIRV() && ASAsInt == CodeSectionINTELAS;
if (AS == LangAS::Default || AS == LangAS::opencl_generic ||
- AS == LangAS::opencl_constant)
+ AS == LangAS::opencl_constant || IsFunctionPtrAS)
return llvm::ConstantPointerNull::get(PT);
auto &Ctx = CGM.getContext();
@@ -510,7 +517,7 @@ static llvm::Type *getInlineSpirvType(CodeGenModule &CGM,
llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(
CodeGenModule &CGM, const Type *Ty,
- const SmallVector<int32_t> *Packoffsets) const {
+ const CGHLSLOffsetInfo &OffsetInfo) const {
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
if (auto *SpirvType = dyn_cast<HLSLInlineSpirvType>(Ty))
@@ -559,7 +566,7 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(
llvm::Type *BufferLayoutTy =
HLSLBufferLayoutBuilder(CGM, "spirv.Layout")
.createLayoutType(ContainedTy->castAsCanonical<RecordType>(),
- Packoffsets);
+ OffsetInfo);
uint32_t StorageClass = /* Uniform storage class */ 2;
return llvm::TargetExtType::get(Ctx, "spirv.VulkanBuffer", {BufferLayoutTy},
{StorageClass, false});