This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Make sure, unused hip-pinned-shadow global var is kept within device code
ClosedPublic

Authored by hsmhsm on Feb 29 2020, 12:19 AM.

Details

Summary

hip-pinned-shadow global var should remain in the final code object irrespective
of whether it is used or not within the code. Add it to used list, so that it
will not get eliminated when it is unused.

Diff Detail

Event Timeline

hsmhsm created this revision.Feb 29 2020, 12:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 29 2020, 12:19 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
yaxunl added a comment.Mar 1 2020, 7:12 AM

LGTM. Thanks.

hliao added a subscriber: hliao.Mar 2 2020, 9:07 AM

the assertion in addUsedGlobal should not be removed. that will remove the guard for potential bugs

clang/lib/CodeGen/CodeGenModule.cpp
1919

This check should be removed completely instead it should be revised for the exceptions.

yaxunl added inline comments.Mar 2 2020, 9:38 AM
clang/lib/CodeGen/CodeGenModule.cpp
1919

How about add back this assertion but make an exception for global variables with hip_pinned_shadow attribute.

hsmhsm marked an inline comment as done.Mar 2 2020, 9:47 AM
hsmhsm added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
1919

Yeah, that is what I was thinking of initially - to remove this assertion only to hip_pinned_shadow vars, may, be creating a clone of this function something like - CodeGenModule::addUsedGlobalForHipPinnedShadows(), without assertion statement.

@hliao

What do you say?

hliao added inline comments.Mar 2 2020, 9:52 AM
clang/lib/CodeGen/CodeGenModule.cpp
1919

how about change that function prototype to

void addUsedGlobal(llvm::GlobalValue *GV, bool SkipCheck = false)

and assert check to

assert ((SkipCheck || !GV->isDeclaration()) && "");

hliao added a comment.Mar 2 2020, 9:53 AM

BTW, why that variable cannot have an initializer? Suppose that initializer is a trivial one, initializing to 0, would that cause any issue in the compilation?

hsmhsm marked an inline comment as done.Mar 2 2020, 9:56 AM
hsmhsm added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
1919

This also looks fine to me, and I can make these changes and submit the changes.

BTW, why that variable cannot have an initializer? Suppose that initializer is a trivial one, initializing to 0, would that cause any issue in the compilation?

Initialization makes the global extern var declaration to become a global definition. And. moreover, it is not a new change from my side, I just happen to add a comment.

BTW, why that variable cannot have an initializer? Suppose that initializer is a trivial one, initializing to 0, would that cause any issue in the compilation?

Initialization makes the global extern var declaration to become a global definition. And. moreover, it is not a new change from my side, I just happen to add a comment.

This kind of variable is supposed to be an external variable which is initialized by runtime at run time.

hsmhsm updated this revision to Diff 247689.Mar 2 2020, 10:50 AM

Take care review comments by hliao.

Take care review comments by hliao.

ping

yaxunl accepted this revision.Mar 3 2020, 10:57 AM

LGTM. Thanks!

This revision is now accepted and ready to land.Mar 3 2020, 10:57 AM
This revision was automatically updated to reflect the committed changes.