r319883 - [OpenCL] Fix layering violation by getOpenCLTypeAddrSpace
Sven van Haastregt via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 6 02:11:28 PST 2017
Author: svenvh
Date: Wed Dec 6 02:11:28 2017
New Revision: 319883
URL: http://llvm.org/viewvc/llvm-project?rev=319883&view=rev
Log:
[OpenCL] Fix layering violation by getOpenCLTypeAddrSpace
Commit 7ac28eb0a5 / r310911 ("[OpenCL] Allow targets to select address
space per type", 2017-08-15) made Basic depend on AST, introducing a
circular dependency. Break this dependency by adding the
OpenCLTypeKind enum in Basic and map from AST types to this enum in
ASTContext.
Differential Revision: https://reviews.llvm.org/D40838
Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets/AMDGPU.h
cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=319883&r1=319882&r2=319883&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Wed Dec 6 02:11:28 2017
@@ -1224,6 +1224,12 @@ public:
/// pointer to blocks.
QualType getBlockDescriptorExtendedType() const;
+ /// Map an AST Type to an OpenCLTypeKind enum value.
+ TargetInfo::OpenCLTypeKind getOpenCLTypeKind(const Type *T) const;
+
+ /// Get address space for OpenCL type.
+ LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+
void setcudaConfigureCallDecl(FunctionDecl *FD) {
cudaConfigureCallDecl = FD;
}
Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=319883&r1=319882&r2=319883&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Wed Dec 6 02:11:28 2017
@@ -46,7 +46,6 @@ class MacroBuilder;
class QualType;
class SourceLocation;
class SourceManager;
-class Type;
namespace Builtin { struct Info; }
@@ -1057,8 +1056,19 @@ public:
return getTargetOpts().SupportedOpenCLOptions;
}
+ enum OpenCLTypeKind {
+ OCLTK_Default,
+ OCLTK_ClkEvent,
+ OCLTK_Event,
+ OCLTK_Image,
+ OCLTK_Pipe,
+ OCLTK_Queue,
+ OCLTK_ReserveID,
+ OCLTK_Sampler,
+ };
+
/// \brief Get address space for OpenCL type.
- virtual LangAS getOpenCLTypeAddrSpace(const Type *T) const;
+ virtual LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const;
/// \returns Target specific vtbl ptr address space.
virtual unsigned getVtblPtrAddressSpace() const {
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=319883&r1=319882&r2=319883&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed Dec 6 02:11:28 2017
@@ -1826,7 +1826,8 @@ TypeInfo ASTContext::getTypeInfoImpl(con
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
case BuiltinType::Id:
#include "clang/Basic/OpenCLImageTypes.def"
- AS = getTargetAddressSpace(Target->getOpenCLTypeAddrSpace(T));
+ AS = getTargetAddressSpace(
+ Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T)));
Width = Target->getPointerWidth(AS);
Align = Target->getPointerAlign(AS);
break;
@@ -5720,6 +5721,46 @@ QualType ASTContext::getBlockDescriptorE
return getTagDeclType(BlockDescriptorExtendedType);
}
+TargetInfo::OpenCLTypeKind ASTContext::getOpenCLTypeKind(const Type *T) const {
+ auto BT = dyn_cast<BuiltinType>(T);
+
+ if (!BT) {
+ if (isa<PipeType>(T))
+ return TargetInfo::OCLTK_Pipe;
+
+ return TargetInfo::OCLTK_Default;
+ }
+
+ switch (BT->getKind()) {
+#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
+ case BuiltinType::Id: \
+ return TargetInfo::OCLTK_Image;
+#include "clang/Basic/OpenCLImageTypes.def"
+
+ case BuiltinType::OCLClkEvent:
+ return TargetInfo::OCLTK_ClkEvent;
+
+ case BuiltinType::OCLEvent:
+ return TargetInfo::OCLTK_Event;
+
+ case BuiltinType::OCLQueue:
+ return TargetInfo::OCLTK_Queue;
+
+ case BuiltinType::OCLReserveID:
+ return TargetInfo::OCLTK_ReserveID;
+
+ case BuiltinType::OCLSampler:
+ return TargetInfo::OCLTK_Sampler;
+
+ default:
+ return TargetInfo::OCLTK_Default;
+ }
+}
+
+LangAS ASTContext::getOpenCLTypeAddrSpace(const Type *T) const {
+ return Target->getOpenCLTypeAddrSpace(getOpenCLTypeKind(T));
+}
+
/// BlockRequiresCopying - Returns true if byref variable "D" of type "Ty"
/// requires copy/dispose. Note that this must match the logic
/// in buildByrefHelpers.
Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=319883&r1=319882&r2=319883&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Wed Dec 6 02:11:28 2017
@@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//
#include "clang/Basic/TargetInfo.h"
-#include "clang/AST/Type.h"
#include "clang/Basic/AddressSpaces.h"
#include "clang/Basic/CharInfo.h"
#include "clang/Basic/LangOptions.h"
@@ -357,23 +356,13 @@ bool TargetInfo::initFeatureMap(
return true;
}
-LangAS TargetInfo::getOpenCLTypeAddrSpace(const Type *T) const {
- auto BT = dyn_cast<BuiltinType>(T);
-
- if (!BT) {
- if (isa<PipeType>(T))
- return LangAS::opencl_global;
-
- return LangAS::Default;
- }
-
- switch (BT->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
- case BuiltinType::Id: \
+LangAS TargetInfo::getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const {
+ switch (TK) {
+ case OCLTK_Image:
+ case OCLTK_Pipe:
return LangAS::opencl_global;
-#include "clang/Basic/OpenCLImageTypes.def"
- case BuiltinType::OCLSampler:
+ case OCLTK_Sampler:
return LangAS::opencl_constant;
default:
Modified: cfe/trunk/lib/Basic/Targets/AMDGPU.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets/AMDGPU.h?rev=319883&r1=319882&r2=319883&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/Targets/AMDGPU.h (original)
+++ cfe/trunk/lib/Basic/Targets/AMDGPU.h Wed Dec 6 02:11:28 2017
@@ -14,7 +14,6 @@
#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
#define LLVM_CLANG_LIB_BASIC_TARGETS_AMDGPU_H
-#include "clang/AST/Type.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Basic/TargetOptions.h"
#include "llvm/ADT/StringSet.h"
@@ -258,24 +257,18 @@ public:
}
}
- LangAS getOpenCLTypeAddrSpace(const Type *T) const override {
- auto BT = dyn_cast<BuiltinType>(T);
-
- if (!BT)
- return TargetInfo::getOpenCLTypeAddrSpace(T);
-
- switch (BT->getKind()) {
-#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
- case BuiltinType::Id: \
- return LangAS::opencl_constant;
-#include "clang/Basic/OpenCLImageTypes.def"
- case BuiltinType::OCLClkEvent:
- case BuiltinType::OCLQueue:
- case BuiltinType::OCLReserveID:
+ LangAS getOpenCLTypeAddrSpace(OpenCLTypeKind TK) const override {
+ switch (TK) {
+ case OCLTK_Image:
+ return LangAS::opencl_constant;
+
+ case OCLTK_ClkEvent:
+ case OCLTK_Queue:
+ case OCLTK_ReserveID:
return LangAS::opencl_global;
default:
- return TargetInfo::getOpenCLTypeAddrSpace(T);
+ return TargetInfo::getOpenCLTypeAddrSpace(TK);
}
}
Modified: cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp?rev=319883&r1=319882&r2=319883&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenCLRuntime.cpp Wed Dec 6 02:11:28 2017
@@ -37,7 +37,7 @@ llvm::Type *CGOpenCLRuntime::convertOpen
llvm::LLVMContext& Ctx = CGM.getLLVMContext();
uint32_t AddrSpc = CGM.getContext().getTargetAddressSpace(
- CGM.getTarget().getOpenCLTypeAddrSpace(T));
+ CGM.getContext().getOpenCLTypeAddrSpace(T));
switch (cast<BuiltinType>(T)->getKind()) {
default:
llvm_unreachable("Unexpected opencl builtin type!");
@@ -68,7 +68,7 @@ llvm::Type *CGOpenCLRuntime::convertOpen
llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) {
if (!PipeTy){
uint32_t PipeAddrSpc = CGM.getContext().getTargetAddressSpace(
- CGM.getTarget().getOpenCLTypeAddrSpace(T));
+ CGM.getContext().getOpenCLTypeAddrSpace(T));
PipeTy = llvm::PointerType::get(llvm::StructType::create(
CGM.getLLVMContext(), "opencl.pipe_t"), PipeAddrSpc);
}
@@ -81,7 +81,7 @@ llvm::PointerType *CGOpenCLRuntime::getS
SamplerTy = llvm::PointerType::get(llvm::StructType::create(
CGM.getLLVMContext(), "opencl.sampler_t"),
CGM.getContext().getTargetAddressSpace(
- CGM.getTarget().getOpenCLTypeAddrSpace(T)));
+ CGM.getContext().getOpenCLTypeAddrSpace(T)));
return SamplerTy;
}
More information about the cfe-commits
mailing list