diff options
author | Yaxun Liu <Yaxun.Liu@amd.com> | 2017-04-11 17:24:23 +0000 |
---|---|---|
committer | Yaxun Liu <Yaxun.Liu@amd.com> | 2017-04-11 17:24:23 +0000 |
commit | b34ec829beb543358ffb1bf6e51a18e5ce9265d3 (patch) | |
tree | b2d9a65ffcda8041f7eaee464aa4485b1b045a84 /clang/lib/AST/ASTContext.cpp | |
parent | e95df719e1eeb62df169c757370c48c5910ca675 (diff) | |
download | bcm5719-llvm-b34ec829beb543358ffb1bf6e51a18e5ce9265d3.tar.gz bcm5719-llvm-b34ec829beb543358ffb1bf6e51a18e5ce9265d3.zip |
[OpenCL] Map default address space to alloca address space
For OpenCL, the private address space qualifier is 0 in AST. Before this change, 0 address space qualifier
is always mapped to target address space 0. As now target private address space is specified by
alloca address space in data layout, address space qualifier 0 needs to be mapped to alloca addr space specified by the data layout.
This change has no impact on targets whose alloca addr space is 0.
With contributions from Matt Arsenault, Tony Tye and Wen-Heng (Jack) Chung
Differential Revision: https://reviews.llvm.org/D31404
llvm-svn: 299965
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b4423b00469..0c069cc80b1 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -703,6 +703,7 @@ static const LangAS::Map *getAddressSpaceMap(const TargetInfo &T, // The fake address space map must have a distinct entry for each // language-specific address space. static const unsigned FakeAddrSpaceMap[] = { + 0, // Default 1, // opencl_global 3, // opencl_local 2, // opencl_constant @@ -8727,7 +8728,8 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context, char *End; unsigned AddrSpace = strtoul(Str, &End, 10); if (End != Str && AddrSpace != 0) { - Type = Context.getAddrSpaceQualType(Type, AddrSpace); + Type = Context.getAddrSpaceQualType(Type, AddrSpace + + LangAS::Count); Str = End; } if (c == '*') @@ -9546,6 +9548,18 @@ uint64_t ASTContext::getTargetNullPointerValue(QualType QT) const { return getTargetInfo().getNullPointerValue(AS); } +unsigned ASTContext::getTargetAddressSpace(unsigned AS) const { + // For OpenCL, only function local variables are not explicitly marked with + // an address space in the AST, and these need to be the address space of + // alloca. + if (!AS && LangOpts.OpenCL) + return getTargetInfo().getDataLayout().getAllocaAddrSpace(); + if (AS >= LangAS::Count) + return AS - LangAS::Count; + else + return (*AddrSpaceMap)[AS]; +} + // Explicitly instantiate this in case a Redeclarable<T> is used from a TU that // doesn't include ASTContext.h template |