This is an archive of the discontinued LLVM Phabricator instance.

[CUDA] emit vtables only for classes with methods usable on this side of compilation.
ClosedPublic

Authored by tra on Dec 7 2015, 2:44 PM.

Details

Summary

C++ emits vtables for classes that have key function present in the
current TU. While we compile CUDA the fact that key function was found
in this TU does not mean that we are going to generate code for it. E.g.
vtable for a class with host-only methods should not be generated on
device side, because we are not going to generate any code for the
host-only methods during device-side compilation.

For classes that mix host and device virtual methods, nvcc generates vtable
with null pointers for methods that are not available on the current side.

  • During key method calculation only considers methods valid for the current CUDA compilation. This prevents vtable generation for classes that have no virtual methods usable on this side of CUDA compilation.
  • For vtables we emit during current CUDA compilation, entries for the methods that are not valid in this mode are set to null. This allows us to generate valid vtables for classes that have mix of host/device virtual methods.

Diff Detail

Repository
rL LLVM

Event Timeline

tra updated this revision to Diff 42110.Dec 7 2015, 2:44 PM
tra retitled this revision from to [CUDA] emit vtables only for classes with methods usable on this side of compilation..
tra updated this object.
tra added reviewers: rsmith, jingyue, jpienaar.
tra added a subscriber: cfe-commits.
tra updated this revision to Diff 42122.Dec 7 2015, 4:14 PM

Removed unnecessary temporary variable and 'else'.

jpienaar edited edge metadata.Dec 9 2015, 3:10 AM

Looks good to me.

lib/AST/RecordLayoutBuilder.cpp
2003 ↗(On Diff #42122)

Add a comment to explain asymmetry. Perhaps a general comment at the start of this section explaining would be the most useful.

test/CodeGenCUDA/device-vtable.cu
36 ↗(On Diff #42122)

What is the current behavior in this case? Should an error be reported?

tra added inline comments.Dec 9 2015, 10:41 AM
test/CodeGenCUDA/device-vtable.cu
36 ↗(On Diff #42122)

Hmm. nvcc actually accepts mixed virtual methods and generates vtable with NULL pointers for methods that are not available on particular side. That shifts responsibility to end-user which is
reasonable in this situation. A warning about partial availability of some virtual method would be helpful here, I think.

OK. Let me try matching nvcc's behavior and add a warning.

tra updated this revision to Diff 42341.Dec 9 2015, 2:38 PM
tra updated this object.
tra edited edge metadata.

Changed key method algorithm to ignore methods that we will not emit during this compilation (previous version didn't allow mixed host/device virtual methods).

For vtables with mixed host/device virtual methods, use NULL for methods we're not going to codegen.

tra added a comment.Dec 16 2015, 3:43 PM

Ping.
@rsmith -- Richard, can you take a look at this change as well?

jpienaar accepted this revision.Dec 17 2015, 12:09 AM
jpienaar edited edge metadata.

Looks good, thanks

test/CodeGenCUDA/device-vtable.cu
37 ↗(On Diff #42341)

Does the comment need to be updated to reflect vtable with NULL pointers?

This revision is now accepted and ready to land.Dec 17 2015, 12:09 AM
This revision was automatically updated to reflect the committed changes.