Skip to content

First attempt at __unique_stable_name #250

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

Merged
merged 7 commits into from
Jul 5, 2019

Conversation

erichkeane
Copy link
Contributor

This implementation uses the keyword __unique_stable_name as an operator
that can take a type or expression, and will result in a constexpr
constant character array that (hopefully) uniquely represents the type
or type-of-expression being passed to it.

The unique representation is the normal mangled name of the type, except
in the cases of a lambda, where the ordinal "number" is just replaced
with LINE->COL. Macro expansions are also appended with '~' followed by
the LINE->COL that it appears in.

For example, a lambda declared in
'main' would look like _ZTSZ4mainEUlvE25->12 (line 25, column 12).

A Lambda that comes from a macro looks like:
_ZTSZ4mainEUlvE45->3~18->32 (macro invoked on 45/3, lambda defined
inside the macro on line 18, column 32).

Template instantiations based on the lambda would result in a name that
contains the lambda mangling, for example:
_ZTSZ3bazIZ4mainEUlvE25->12EvvEUlvE14->12

A function template named 'baz' that is instantiated with a lambda
declared in 'main' on line 25/col 12 has another macro in it, declared
on line 14, column 12.

Signed-off-by: Erich Keane [email protected]

This implementation uses the keyword __unique_stable_name as an operator
that can take a type or expression, and will result in a constexpr
constant character array that (hopefully) uniquely represents the type
or type-of-expression being passed to it.

The unique representation is the normal mangled name of the type, except
in the cases of a lambda, where the ordinal "number" is just replaced
with LINE->COL.  Macro expansions are also appended with '~' followed by
the LINE->COL that it appears in.

For example, a lambda declared in
'main' would look like _ZTSZ4mainEUlvE25->12 (line 25, column 12).

A Lambda that comes from a macro looks like:
_ZTSZ4mainEUlvE45->3~18->32 (macro invoked on 45/3, lambda defined
inside the macro on line 18, column 32).

Template instantiations based on the lambda would result in a name that
contains the lambda mangling, for example:
_ZTSZ3bazIZ4mainEUlvE25->12EvvEUlvE14->12

A function template named 'baz' that is instantiated with a lambda
declared in 'main' on line 25/col 12 has another macro in it, declared
on line 14, column 12.

Signed-off-by: Erich Keane <[email protected]>
@bader
Copy link
Contributor

bader commented Jun 25, 2019

+@hfinkel.
We are planning to use this built-in to make naming kernels by user optional in case both device and host compilers support this built-in function.
You feedback is very welcome.

@hfinkel
Copy link
Contributor

hfinkel commented Jun 25, 2019

+@hfinkel.
We are planning to use this built-in to make naming kernels by user optional in case both device and host compilers support this built-in function.
You feedback is very welcome.

Thanks, @bader (and @erichkeane )! Making the kernel names optional will really help our adoption of SYCL.

Are you also working on Microsoft mangling support? As a quick note, your clang/test/CodeGenSYCL/unique-stable-name.cpp doesn't seem to test multiple nested macros.

@erichkeane
Copy link
Contributor Author

+@hfinkel.
We are planning to use this built-in to make naming kernels by user optional in case both device and host compilers support this built-in function.
You feedback is very welcome.

Thanks, @bader (and @erichkeane )! Making the kernel names optional will really help our adoption of SYCL.

Are you also working on Microsoft mangling support? As a quick note, your clang/test/CodeGenSYCL/unique-stable-name.cpp doesn't seem to test multiple nested macros.

We don't require microsoft mangling, this is simply a "unique" and "stable" name that just so happens to be implemented in terms of the Itanium mangling structure.

I'll add that test when I ge ta shot.

@erichkeane erichkeane force-pushed the private/erichkeane/unique-stable-name branch from 4c30e4a to ddd09b0 Compare June 25, 2019 20:34
@erichkeane
Copy link
Contributor Author

@hfinkel Test Case Added.

bader
bader previously approved these changes Jun 27, 2019
return E;

return getSema().BuildUniqueStableName(E->getLocation(), SubExpr.get());
} else if (E->getIdentKind() == PredefinedExpr::UniqueStableNameType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No else after return.

Copy link
Contributor

@keryell keryell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super useful!
I would love more comments.
Add some documentation so it can land to https://clang.llvm.org/docs/LanguageExtensions.html
It would be nice to work with ISO C++ SG7 to have this feature in the standard.

@@ -436,6 +436,9 @@ KEYWORD(L__FUNCSIG__ , KEYMS)
TYPE_TRAIT_1(__is_interface_class, IsInterfaceClass, KEYMS)
TYPE_TRAIT_1(__is_sealed, IsSealed, KEYMS)

// Extensions for SYCL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elaborate the comment to say what it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a category heading, it isn't directly associated with the keyword itself. If you see the rest of the file, that is the format of comments in this file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, we can move this built-in to some "generic" clang built-ins category.

@@ -3205,6 +3205,65 @@ ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc,

return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New line

Copy link
Contributor

@bader bader Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to Ronan's comment to add a new line here.

Signed-off-by: Erich Keane <[email protected]>
@erichkeane
Copy link
Contributor Author

Super useful!
I would love more comments.
Add some documentation so it can land to https://clang.llvm.org/docs/LanguageExtensions.html
It would be nice to work with ISO C++ SG7 to have this feature in the standard.

Patch incoming.

A feature like this fits very well in with the Reflection work, though I haven't been participating in SG7 very much lately. This is implemented more like a builtin that would be used as a building block for such a proposal.

As far as putting this in LangExtensions, Clang typically doesn't document builtins in lang-extensions. This is a building block for omitting the kernel name in SYCL functions, so I suspect this is best documented as a part of that.

The intent of this patch is to unblock that kernel naming effort, so I suspect this is a first-of-many patch for this builtin.

@hfinkel
Copy link
Contributor

hfinkel commented Jun 28, 2019

Super useful!
I would love more comments.
Add some documentation so it can land to https://clang.llvm.org/docs/LanguageExtensions.html
It would be nice to work with ISO C++ SG7 to have this feature in the standard.

Patch incoming.

A feature like this fits very well in with the Reflection work, though I haven't been participating in SG7 very much lately. This is implemented more like a builtin that would be used as a building block for such a proposal.

As far as putting this in LangExtensions, Clang typically doesn't document builtins in lang-extensions. This is a building block for omitting the kernel name in SYCL functions, so I suspect this is best documented as a part of that.

The intent of this patch is to unblock that kernel naming effort, so I suspect this is a first-of-many patch for this builtin.

@erichkeane , we do, see https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions - and we should document this as well.

Regarding a proposal for WG21, I'm happy to work with you and anyone else interested on a proposal. For those of you attending the next WG21 meeting, I'm also happy to chat about this in person. That seems useful.

@erichkeane
Copy link
Contributor Author

Super useful!
I would love more comments.
Add some documentation so it can land to https://clang.llvm.org/docs/LanguageExtensions.html
It would be nice to work with ISO C++ SG7 to have this feature in the standard.

Patch incoming.
A feature like this fits very well in with the Reflection work, though I haven't been participating in SG7 very much lately. This is implemented more like a builtin that would be used as a building block for such a proposal.
As far as putting this in LangExtensions, Clang typically doesn't document builtins in lang-extensions. This is a building block for omitting the kernel name in SYCL functions, so I suspect this is best documented as a part of that.
The intent of this patch is to unblock that kernel naming effort, so I suspect this is a first-of-many patch for this builtin.

@erichkeane , we do, see https://clang.llvm.org/docs/LanguageExtensions.html#builtin-functions - and we should document this as well.

Regarding a proposal for WG21, I'm happy to work with you and anyone else interested on a proposal. For those of you attending the next WG21 meeting, I'm also happy to chat about this in person. That seems useful.

Huh, I've never documented one there before! I'll work on it then. As for the proposal, perhaps the 3 of us should discuss it in Cologne. I'd presume that we'd need to find a way to fit this into the Reflection TS/Reflection Constexpr proposals in a way that didn't look terrible.

Additionally, we'd likely wish to propose an actual standardized naming convention here. This patch chooses a modified Itanium ABI, but any string would work.

@keryell
Copy link
Contributor

keryell commented Jun 28, 2019

I will skip the Köln meeting unfortunately... :-( Belfast?

@erichkeane
Copy link
Contributor Author

I will skip the Köln meeting unfortunately... :-( Belfast?

Cya there.

@bader bader self-assigned this Jun 28, 2019
@erichkeane
Copy link
Contributor Author

erichkeane commented Jun 30, 2019 via email

@@ -436,6 +436,9 @@ KEYWORD(L__FUNCSIG__ , KEYMS)
TYPE_TRAIT_1(__is_interface_class, IsInterfaceClass, KEYMS)
TYPE_TRAIT_1(__is_sealed, IsSealed, KEYMS)

// Extensions for SYCL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, we can move this built-in to some "generic" clang built-ins category.

@@ -3205,6 +3205,65 @@ ExprResult Sema::BuildPredefinedExpr(SourceLocation Loc,

return PredefinedExpr::Create(Context, Loc, ResTy, IK, SL);
}
Copy link
Contributor

@bader bader Jul 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to Ronan's comment to add a new line here.

@erichkeane
Copy link
Contributor Author

I'm not authorized to merge this pull request, so I don't know should be doing it.

@bader
Copy link
Contributor

bader commented Jul 2, 2019

I'd like to wait a bit to see if other reviewers have additional comments to the latest version of the patch and if there are no objections, I'll merge this patch tomorrow.
@erichkeane, thanks for working on this!

@bader bader merged commit 44d6030 into sycl Jul 5, 2019
@bader bader deleted the private/erichkeane/unique-stable-name branch July 31, 2019 19:50
vladimirlaz pushed a commit to vladimirlaz/llvm that referenced this pull request Nov 21, 2019
  CONFLICT (content): Merge conflict in clang/lib/CodeGen/CGExpr.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants