Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang: add cheerp language address spaces (NFC) #276

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/AddressSpaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ enum class LangAS : unsigned {
// HLSL specific address spaces.
hlsl_groupshared,

// Cheerp specific address spaces.
cheerp_client,
cheerp_genericjs,
cheerp_bytelayout,
cheerp_wasm,

// This denotes the count of language-specific address spaces and also
// the offset added to the target-specific address spaces, which are usually
// specified by address space attributes __attribute__(address_space(n))).
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ static const LangASMap *getAddressSpaceMap(const TargetInfo &T,
11, // ptr32_uptr
12, // ptr64
13, // hlsl_groupshared
14, // cheerp_client
15, // cheerp_genericjs
16, // cheerp_bytelayout
17, // cheerp_wasm
};
return &FakeAddrSpaceMap;
} else {
Expand Down
25 changes: 24 additions & 1 deletion clang/lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,11 @@ void CXXNameMangler::mangleNestedName(GlobalDecl GD,
// We do not consider restrict a distinguishing attribute for overloading
// purposes so we must not mangle it.
MethodQuals.removeRestrict();
// CHEERP: c++filt does not like an AS on methods. We also don't really need it
// since we don't overload based on AS.
if (Context.getASTContext().getLangOpts().Cheerp) {
MethodQuals.removeAddressSpace();
}
mangleQualifiers(MethodQuals);
mangleRefQualifier(Method->getRefQualifier());
}
Expand Down Expand Up @@ -2688,6 +2693,18 @@ void CXXNameMangler::mangleQualifiers(Qualifiers Quals, const DependentAddressSp
case LangAS::ptr64:
ASString = "ptr64";
break;
case LangAS::cheerp_client:
ASString = "client";
break;
case LangAS::cheerp_genericjs:
ASString = "js";
break;
case LangAS::cheerp_bytelayout:
ASString = "bl";
break;
case LangAS::cheerp_wasm:
ASString = "wasm";
break;
}
}
if (!ASString.empty())
Expand Down Expand Up @@ -3244,7 +3261,13 @@ void CXXNameMangler::mangleType(const FunctionProtoType *T) {

// Mangle CV-qualifiers, if present. These are 'this' qualifiers,
// e.g. "const" in "int (A::*)() const".
mangleQualifiers(T->getMethodQuals());
Qualifiers Quals = T->getMethodQuals();
// CHEERP: c++filt does not like an AS on methods. We also don't really need it
// since we don't overload based on AS.
if (Context.getASTContext().getLangOpts().Cheerp) {
Quals.removeAddressSpace();
}
mangleQualifiers(Quals);

// Mangle instantiation-dependent exception-specification, if present,
// per cxx-abi-dev proposal on 2016-10-11.
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/AST/TypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,14 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
return "__ptr64";
case LangAS::hlsl_groupshared:
return "groupshared";
case LangAS::cheerp_client:
return "__client";
case LangAS::cheerp_genericjs:
return "__js";
case LangAS::cheerp_bytelayout:
return "__bl";
case LangAS::cheerp_wasm:
return "__wasm";
default:
return std::to_string(toTargetAddressSpace(AS));
}
Expand Down
9 changes: 8 additions & 1 deletion clang/lib/Basic/Targets/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
Generic, // ptr32_uptr
Generic, // ptr64
Generic, // hlsl_groupshared
Generic, // cheerp_client
Generic, // cheerp_genericjs
Generic, // cheerp_bl
Generic, // cheerp_wasm
};

const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
Expand All @@ -81,7 +85,10 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
Generic, // ptr32_uptr
Generic, // ptr64
Generic, // hlsl_groupshared

Generic, // cheerp_client
Generic, // cheerp_genericjs
Generic, // cheerp_bl
Generic, // cheerp_wasm
};
} // namespace targets
} // namespace clang
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets/DirectX.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ static const unsigned DirectXAddrSpaceMap[] = {
0, // ptr32_uptr
0, // ptr64
3, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

class LLVM_LIBRARY_VISIBILITY DirectXTargetInfo : public TargetInfo {
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets/NVPTX.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ static const unsigned NVPTXAddrSpaceMap[] = {
0, // ptr32_uptr
0, // ptr64
0, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

/// The DWARF address class. Taken from
Expand Down
8 changes: 8 additions & 0 deletions clang/lib/Basic/Targets/SPIR.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ static const unsigned SPIRDefIsPrivMap[] = {
0, // ptr32_uptr
0, // ptr64
0, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

// Used by both the SPIR and SPIR-V targets.
Expand Down Expand Up @@ -74,6 +78,10 @@ static const unsigned SPIRDefIsGenMap[] = {
0, // ptr32_uptr
0, // ptr64
0, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

// Base class for SPIR and SPIR-V target info.
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets/TCE.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ static const unsigned TCEOpenCLAddrSpaceMap[] = {
0, // ptr32_uptr
0, // ptr64
0, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

class LLVM_LIBRARY_VISIBILITY TCETargetInfo : public TargetInfo {
Expand Down
28 changes: 28 additions & 0 deletions clang/lib/Basic/Targets/WebAssembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,33 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly64TargetInfo
MacroBuilder &Builder) const override;
};

static const unsigned CheerpAddrSpaceMap[] = {
0, // Default
0, // opencl_global
0, // opencl_local
0, // opencl_constant
0, // opencl_private
0, // opencl_generic
0, // opencl_global_device
0, // opencl_global_host
0, // cuda_device
0, // cuda_constant
0, // cuda_shared
0, // sycl_global
0, // sycl_global_device
0, // sycl_global_host
0, // sycl_local
0, // sycl_private
0, // ptr32_sptr
0, // ptr32_uptr
0, // ptr64
0, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

// Cheerp base class
class CheerpTargetInfo : public TargetInfo {
private:
Expand Down Expand Up @@ -223,6 +250,7 @@ class CheerpTargetInfo : public TargetInfo {
// We don't have multiple asm variants, and we want to be able to use
// '{' and '}' in the asm code
NoAsmVariants = true;
AddrSpaceMap = & CheerpAddrSpaceMap;
}

virtual ArrayRef<Builtin::Info> getTargetBuiltins() const override;
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Basic/Targets/X86.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ static const unsigned X86AddrSpaceMap[] = {
271, // ptr32_uptr
272, // ptr64
0, // hlsl_groupshared
0, // cheerp_client
0, // cheerp_genericjs
0, // cheerp_bl
0, // cheerp_wasm
};

// X86 target abstract base class; x86-32 and x86-64 are very close, so
Expand Down
4 changes: 2 additions & 2 deletions clang/test/SemaTemplate/address_space-dependent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void neg() {

template <long int I>
void tooBig() {
__attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388587)}}
__attribute__((address_space(I))) int *bounds; // expected-error {{address space is larger than the maximum supported (8388583)}}
}

template <long int I>
Expand Down Expand Up @@ -101,7 +101,7 @@ int main() {
car<1, 2, 3>(); // expected-note {{in instantiation of function template specialization 'car<1, 2, 3>' requested here}}
HasASTemplateFields<1> HASTF;
neg<-1>(); // expected-note {{in instantiation of function template specialization 'neg<-1>' requested here}}
correct<0x7FFFEB>();
correct<0x7FFFE7>();
tooBig<8388650>(); // expected-note {{in instantiation of function template specialization 'tooBig<8388650L>' requested here}}

__attribute__((address_space(1))) char *x;
Expand Down
Loading