This is an archive of the discontinued LLVM Phabricator instance.

[NFC][CUDA] Refactor registering device variable
ClosedPublic

Authored by yaxunl on Jan 27 2021, 1:47 PM.

Details

Summary

Extract registering device variable to CUDA runtime codegen function since it
will be called in multiple places.

Diff Detail

Event Timeline

yaxunl requested review of this revision.Jan 27 2021, 1:47 PM
yaxunl created this revision.
tra added inline comments.Jan 27 2021, 4:58 PM
clang/lib/CodeGen/CGCUDANV.cpp
158

clang-format it? void hanging all by itself looks odd.

925

The name and the functionality do not match -- despite what the name says, the function will set internal linkage on any var with device-side attributes.

Rename to internalizeDeviceSideVars ?

clang/lib/CodeGen/CGCUDARuntime.h
85

handleVarRegistration to make it distinct from the implementation of specific registration kinds.

Maybe, move registerDevice* functions under private: as they will only be used from the top-level handler called by CGM.

88

Just registerDeviceVar would do.

yaxunl marked 4 inline comments as done.Feb 1 2021, 10:51 AM
yaxunl added inline comments.
clang/lib/CodeGen/CGCUDANV.cpp
158

Although it looks strange, it is a result of clang-format.

925

done

clang/lib/CodeGen/CGCUDARuntime.h
85

done

88

done

yaxunl updated this revision to Diff 320526.Feb 1 2021, 10:54 AM
yaxunl marked 4 inline comments as done.

Revised by Artem's comments

tra accepted this revision.Feb 1 2021, 12:45 PM

Couple of minor nits LGTM otherwise,

clang/lib/CodeGen/CGCUDANV.cpp
925

My suggestion could be improved, too. Vars -> Var as we're dealing with only one VarDecl here.

clang/lib/CodeGen/CodeGenModule.cpp
4300–4302

Should we fold internalizeDeviceSideVar into handleVarRegistration or call it from there?
I don't think we'll have any independent use for it in CGM. It seems to be an implementation detail for handleVarRegistration and may not even need to be virtual.

This revision is now accepted and ready to land.Feb 1 2021, 12:45 PM
yaxunl marked 2 inline comments as done.Feb 1 2021, 5:50 PM
yaxunl added inline comments.
clang/lib/CodeGen/CGCUDANV.cpp
925

will do

clang/lib/CodeGen/CodeGenModule.cpp
4300–4302

For function scope static variable, I only need to call handleVarRegistration since the variable already has internal linkage. If internalizeDeviceSideVars is absorbed into handleVarRegistration, there be useless work and I also need to define a useless automatic variable Linkage and pass it to handleVarRegistration.

tra added inline comments.Feb 2 2021, 10:30 AM
clang/lib/CodeGen/CodeGenModule.cpp
4300–4302

internalizeDeviceSideVars is nearly trivial. I doubt that it will have any measureable impact, either way.

At the moment handleVarRegistration() is called only from here. Are you saying that separate internalization and registration will be needed in the future changes? If that's the case I'm fine keeping them separate.

As things are in the patch, I do not see why internalizeDeviceSideVars needs to be a base class interface. It's always used along with handleVarRegistration and we have no need to be able to override it independently of it. Folding it into or calling it from handleVarRegistration looks like a natural fit.

yaxunl marked 3 inline comments as done.Feb 2 2021, 10:39 AM
yaxunl added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
4300–4302

It is used differently in https://reviews.llvm.org/D95560, where only handleVarRegistration is called.

tra added a comment.Feb 2 2021, 11:26 AM

LGTM.

clang/lib/CodeGen/CodeGenModule.cpp
4300–4302

Got it.

This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2021, 11:30 AM