-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[Clang] Use TargetInfo when deciding if an address space is compatible #115777
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| #include "clang/Basic/PointerAuthOptions.h" | ||
| #include "clang/Basic/SourceLocation.h" | ||
| #include "clang/Basic/Specifiers.h" | ||
| #include "clang/Basic/TargetInfo.h" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dropped this include again in bc3b0fa because it was causing a significant build time regression. I assume this was a leftover from some earlier iteration of the patch.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't be necessary, I can make a PR to remove it again. Ah you meant you did it already, nevermind. Thanks for cleaning that up. Doing the change that was requested was really annoying so I did it off of the diff and forgot to delete that. |
||
| #include "clang/Basic/Visibility.h" | ||
| #include "llvm/ADT/APInt.h" | ||
| #include "llvm/ADT/APSInt.h" | ||
|
|
@@ -323,6 +324,7 @@ class PointerAuthQualifier { | |
| /// * Objective C: the GC attributes (none, weak, or strong) | ||
| class Qualifiers { | ||
| public: | ||
| Qualifiers() = default; | ||
| enum TQ : uint64_t { | ||
| // NOTE: These flags must be kept in sync with DeclSpec::TQ. | ||
| Const = 0x1, | ||
|
|
@@ -697,45 +699,27 @@ class Qualifiers { | |
| /// every address space is a superset of itself. | ||
| /// CL2.0 adds: | ||
| /// __generic is a superset of any address space except for __constant. | ||
| static bool isAddressSpaceSupersetOf(LangAS A, LangAS B) { | ||
| static bool isAddressSpaceSupersetOf(LangAS A, LangAS B, | ||
| const ASTContext &Ctx) { | ||
| // Address spaces must match exactly. | ||
| return A == B || | ||
| // Otherwise in OpenCLC v2.0 s6.5.5: every address space except | ||
| // for __constant can be used as __generic. | ||
| (A == LangAS::opencl_generic && B != LangAS::opencl_constant) || | ||
| // We also define global_device and global_host address spaces, | ||
| // to distinguish global pointers allocated on host from pointers | ||
| // allocated on device, which are a subset of __global. | ||
| (A == LangAS::opencl_global && (B == LangAS::opencl_global_device || | ||
| B == LangAS::opencl_global_host)) || | ||
| (A == LangAS::sycl_global && (B == LangAS::sycl_global_device || | ||
| B == LangAS::sycl_global_host)) || | ||
| // Consider pointer size address spaces to be equivalent to default. | ||
| ((isPtrSizeAddressSpace(A) || A == LangAS::Default) && | ||
| (isPtrSizeAddressSpace(B) || B == LangAS::Default)) || | ||
| // Default is a superset of SYCL address spaces. | ||
| (A == LangAS::Default && | ||
| (B == LangAS::sycl_private || B == LangAS::sycl_local || | ||
| B == LangAS::sycl_global || B == LangAS::sycl_global_device || | ||
| B == LangAS::sycl_global_host)) || | ||
| // In HIP device compilation, any cuda address space is allowed | ||
| // to implicitly cast into the default address space. | ||
| (A == LangAS::Default && | ||
| (B == LangAS::cuda_constant || B == LangAS::cuda_device || | ||
| B == LangAS::cuda_shared)); | ||
| return A == B || isTargetAddressSpaceSupersetOf(A, B, Ctx); | ||
| } | ||
|
|
||
| static bool isTargetAddressSpaceSupersetOf(LangAS A, LangAS B, | ||
| const ASTContext &Ctx); | ||
|
|
||
| /// Returns true if the address space in these qualifiers is equal to or | ||
| /// a superset of the address space in the argument qualifiers. | ||
| bool isAddressSpaceSupersetOf(Qualifiers other) const { | ||
| return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace()); | ||
| bool isAddressSpaceSupersetOf(Qualifiers other, const ASTContext &Ctx) const { | ||
| return isAddressSpaceSupersetOf(getAddressSpace(), other.getAddressSpace(), | ||
| Ctx); | ||
| } | ||
|
|
||
| /// Determines if these qualifiers compatibly include another set. | ||
| /// Generally this answers the question of whether an object with the other | ||
| /// qualifiers can be safely used as an object with these qualifiers. | ||
| bool compatiblyIncludes(Qualifiers other) const { | ||
| return isAddressSpaceSupersetOf(other) && | ||
| bool compatiblyIncludes(Qualifiers other, const ASTContext &Ctx) const { | ||
| return isAddressSpaceSupersetOf(other, Ctx) && | ||
| // ObjC GC qualifiers can match, be added, or be removed, but can't | ||
| // be changed. | ||
| (getObjCGCAttr() == other.getObjCGCAttr() || !hasObjCGCAttr() || | ||
|
|
@@ -1273,11 +1257,11 @@ class QualType { | |
|
|
||
| /// Determine whether this type is more qualified than the other | ||
| /// given type, requiring exact equality for non-CVR qualifiers. | ||
| bool isMoreQualifiedThan(QualType Other) const; | ||
| bool isMoreQualifiedThan(QualType Other, const ASTContext &Ctx) const; | ||
|
|
||
| /// Determine whether this type is at least as qualified as the other | ||
| /// given type, requiring exact equality for non-CVR qualifiers. | ||
| bool isAtLeastAsQualifiedAs(QualType Other) const; | ||
| bool isAtLeastAsQualifiedAs(QualType Other, const ASTContext &Ctx) const; | ||
|
|
||
| QualType getNonReferenceType() const; | ||
|
|
||
|
|
@@ -1425,11 +1409,12 @@ class QualType { | |
| /// address spaces overlap iff they are they same. | ||
| /// OpenCL C v2.0 s6.5.5 adds: | ||
| /// __generic overlaps with any address space except for __constant. | ||
| bool isAddressSpaceOverlapping(QualType T) const { | ||
| bool isAddressSpaceOverlapping(QualType T, const ASTContext &Ctx) const { | ||
| Qualifiers Q = getQualifiers(); | ||
| Qualifiers TQ = T.getQualifiers(); | ||
| // Address spaces overlap if at least one of them is a superset of another | ||
| return Q.isAddressSpaceSupersetOf(TQ) || TQ.isAddressSpaceSupersetOf(Q); | ||
| return Q.isAddressSpaceSupersetOf(TQ, Ctx) || | ||
| TQ.isAddressSpaceSupersetOf(Q, Ctx); | ||
| } | ||
|
|
||
| /// Returns gc attribute of this type. | ||
|
|
@@ -8112,24 +8097,26 @@ inline FunctionType::ExtInfo getFunctionExtInfo(QualType t) { | |
| /// is more qualified than "const int", "volatile int", and | ||
| /// "int". However, it is not more qualified than "const volatile | ||
| /// int". | ||
| inline bool QualType::isMoreQualifiedThan(QualType other) const { | ||
| inline bool QualType::isMoreQualifiedThan(QualType other, | ||
| const ASTContext &Ctx) const { | ||
| Qualifiers MyQuals = getQualifiers(); | ||
| Qualifiers OtherQuals = other.getQualifiers(); | ||
| return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals)); | ||
| return (MyQuals != OtherQuals && MyQuals.compatiblyIncludes(OtherQuals, Ctx)); | ||
| } | ||
|
|
||
| /// Determine whether this type is at last | ||
| /// as qualified as the Other type. For example, "const volatile | ||
| /// int" is at least as qualified as "const int", "volatile int", | ||
| /// "int", and "const volatile int". | ||
| inline bool QualType::isAtLeastAsQualifiedAs(QualType other) const { | ||
| inline bool QualType::isAtLeastAsQualifiedAs(QualType other, | ||
| const ASTContext &Ctx) const { | ||
| Qualifiers OtherQuals = other.getQualifiers(); | ||
|
|
||
| // Ignore __unaligned qualifier if this type is a void. | ||
| if (getUnqualifiedType()->isVoidType()) | ||
| OtherQuals.removeUnaligned(); | ||
|
|
||
| return getQualifiers().compatiblyIncludes(OtherQuals); | ||
| return getQualifiers().compatiblyIncludes(OtherQuals, Ctx); | ||
| } | ||
|
|
||
| /// If Type is a reference type (e.g., const | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,6 +111,18 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo { | |
| return getPointerWidthV(AddrSpace); | ||
| } | ||
|
|
||
| virtual bool isAddressSpaceSupersetOf(LangAS A, LangAS B) const override { | ||
| // The flat address space AS(0) is a superset of all the other address | ||
| // spaces used by the backend target. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should exclude several address spaces. Should exclude region. Arguably also the fat pointers
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic should only permit 0-5, I was torn on rejecting AS(2), can edit that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should reject it, it's not flat addressable. We don't have a magic aperture constant for it and the addrspacecast codegen will fail |
||
| return A == B || | ||
| ((A == LangAS::Default || | ||
| (isTargetAddressSpace(A) && | ||
| toTargetAddressSpace(A) == llvm::AMDGPUAS::FLAT_ADDRESS)) && | ||
| isTargetAddressSpace(B) && | ||
| toTargetAddressSpace(B) >= llvm::AMDGPUAS::FLAT_ADDRESS && | ||
| toTargetAddressSpace(B) <= llvm::AMDGPUAS::PRIVATE_ADDRESS); | ||
| } | ||
|
|
||
| uint64_t getMaxPointerWidth() const override { | ||
| return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.