This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Fix managed variable linkage
ClosedPublic

Authored by yaxunl on Feb 5 2021, 8:19 PM.

Details

Summary

Currently managed variables are emitted as undefined symbols, which
causes difficulty for diagnosing undefined symbols for non-managed
variables.

This patch transforms managed variables in device compilation so that
they can be emitted as normal variables.

Diff Detail

Event Timeline

yaxunl created this revision.Feb 5 2021, 8:19 PM
yaxunl requested review of this revision.Feb 5 2021, 8:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 5 2021, 8:19 PM
yaxunl updated this revision to Diff 324806.Feb 18 2021, 4:21 PM

keep managed var in llvm.compiler.used since they need runtime handling even if they are not used in device code.

tra added inline comments.Feb 18 2021, 5:49 PM
clang/lib/CodeGen/CGCUDANV.cpp
1019

A comment about how exactly we're transforming the vars would be helpful.

clang/lib/CodeGen/CGCUDARuntime.h
103

Can we fold it into makeModuleCtorFunction ? It does not look like something we would need to customize independently of other glue generating machinery.

clang/lib/CodeGen/CodeGenModule.cpp
463–466

This does not look right.
Was transformManagedVars() supposed to *replace* AddGlobalCtor(CudaCtorFunction)?

I would expect it to be in addition to the ctor we create now.

if (Context.getLangOpts().CUDAIsDevice)
  CUDARuntime->transformManagedVars();
if (llvm::Function *CudaCtorFunction =
             CUDARuntime->makeModuleCtorFunction())
     AddGlobalCtor(CudaCtorFunction);
yaxunl marked 3 inline comments as done.Feb 18 2021, 6:26 PM
yaxunl added inline comments.
clang/lib/CodeGen/CGCUDANV.cpp
1019

done

clang/lib/CodeGen/CGCUDARuntime.h
103

makeModuleCtorFunction is creating module ctor function, but transformManagedVars has nothing to do with module ctor function.

Also, makeModuleCtorFunction is called in host compilation only.

Do we want to rename the API here finalizeModule ? And let it call makeModuleCtorFunction and transformManagedVars as static functions in CGCUDANV.cpp ?

clang/lib/CodeGen/CodeGenModule.cpp
463–466

originally, makeModuleCtorFunction is called for host compilation only.

yaxunl updated this revision to Diff 324971.Feb 19 2021, 7:09 AM
yaxunl marked 3 inline comments as done.

refactor CGCUDARuntime interface not to expose transformManagedVar.

tra accepted this revision.Feb 22 2021, 9:52 AM
tra added inline comments.
clang/lib/CodeGen/CGCUDARuntime.h
103

SGTM.

This revision is now accepted and ready to land.Feb 22 2021, 9:52 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 23 2021, 7:36 PM