-
Notifications
You must be signed in to change notification settings - Fork 769
[SYCL][Clang] Add __sycl_detail__::add_ir_annotations_member attribute #5879
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
bader
merged 6 commits into
intel:sycl
from
steffenlarsen:steffen/add_ir_member_annotation
Apr 5, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
69b2f6c
[SYCL][Clang] Add __sycl_detail__::add_ir_annotations_member attribute
steffenlarsen d9619fe
Apply suggestions, fix value reuse with filter, and add filter and va…
steffenlarsen a33df27
Fix formatting
steffenlarsen 725823f
Apply suggestions and test annotations on scalars fields
steffenlarsen 562d63e
Move away from deprecated ctor and remove gnu std from test
steffenlarsen 1baa8a3
Remove another gnu std
steffenlarsen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2873,6 +2873,55 @@ void CodeGenModule::AddGlobalAnnotations(const ValueDecl *D, | |
Annotations.push_back(EmitAnnotateAttr(GV, I, D->getLocation())); | ||
} | ||
|
||
llvm::Constant *CodeGenModule::EmitSYCLAnnotationArgs( | ||
const SYCLAddIRAnnotationsMemberAttr *Attr) { | ||
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 would appreciate some comments in this code. 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. Absolutely! I have added comments. Let me know if you think it is sufficient. |
||
llvm::SmallVector<std::pair<std::string, std::string>, 4> | ||
AnnotationNameValPairs = | ||
Attr->getFilteredAttributeNameValuePairs(getContext()); | ||
if (AnnotationNameValPairs.empty()) | ||
return llvm::ConstantPointerNull::get(GlobalsInt8PtrTy); | ||
|
||
// For each name-value pair of the SYCL annotation attribute, create an | ||
// annotation string for it. This will be the annotation arguments. If the | ||
// value is the empty string, use a null-pointer instead. | ||
llvm::SmallVector<llvm::Constant *, 4> LLVMArgs; | ||
llvm::FoldingSetNodeID ID; | ||
LLVMArgs.reserve(AnnotationNameValPairs.size() * 2); | ||
for (const std::pair<std::string, std::string> &NVP : | ||
AnnotationNameValPairs) { | ||
llvm::Constant *NameStrC = EmitAnnotationString(NVP.first); | ||
llvm::Constant *ValueStrC = | ||
NVP.second == "" ? llvm::ConstantPointerNull::get(GlobalsInt8PtrTy) | ||
: EmitAnnotationString(NVP.second); | ||
LLVMArgs.push_back(NameStrC); | ||
LLVMArgs.push_back(ValueStrC); | ||
ID.Add(NameStrC); | ||
ID.Add(ValueStrC); | ||
} | ||
|
||
// If another SYCL annotation had the same arguments we can reuse the | ||
// annotation value it created. | ||
llvm::Constant *&LookupRef = SYCLAnnotationArgs[ID.ComputeHash()]; | ||
if (LookupRef) | ||
return LookupRef; | ||
|
||
// Create an anonymous struct global variable pointing to the annotation | ||
// arguments in the order they were added above. This is the final constant | ||
// used as the annotation value. | ||
auto *Struct = llvm::ConstantStruct::getAnon(LLVMArgs); | ||
auto *GV = new llvm::GlobalVariable(getModule(), Struct->getType(), true, | ||
llvm::GlobalValue::PrivateLinkage, Struct, | ||
".args"); | ||
GV->setSection(AnnotationSection); | ||
GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global); | ||
auto *Bitcasted = llvm::ConstantExpr::getBitCast(GV, GlobalsInt8PtrTy); | ||
|
||
// Set the look-up reference to the final annotation value for future | ||
// annotations to reuse. | ||
LookupRef = Bitcasted; | ||
return Bitcasted; | ||
} | ||
|
||
void CodeGenModule::AddGlobalSYCLIRAttributes(llvm::GlobalVariable *GV, | ||
const RecordDecl *RD) { | ||
const auto *A = RD->getAttr<SYCLAddIRAttributesGlobalVariableAttr>(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.