This is an archive of the discontinued LLVM Phabricator instance.

[HIP] Emit amdgpu_code_object_version module flag
ClosedPublic

Authored by yaxunl on Feb 4 2022, 11:35 AM.

Details

Summary

code object version determines ABI, therefore should not be mixed.

This patch emits amdgpu_code_object_version module flag in LLVM IR
based on code object version (default 4).

The amdgpu_code_object_version value is code object version times 100.

LLVM IR with different amdgpu_code_object_version module flag cannot
be linked.

The -cc1 option -mcode-object-version=none is for ROCm device library use
only, which supports multiple ABI.

Diff Detail

Event Timeline

yaxunl created this revision.Feb 4 2022, 11:35 AM
yaxunl requested review of this revision.Feb 4 2022, 11:36 AM
tra added inline comments.Feb 4 2022, 12:07 PM
clang/lib/CodeGen/CodeGenModule.cpp
575

When will it ever be set to none? Does the new option parser enforce the default & version values specified in the tablegen?
If so, then it should never be none.
If the Values specified for the option are not enforced, then the condition will be true if user specifies any invalid value other than none.

yaxunl added inline comments.Feb 4 2022, 3:09 PM
clang/lib/CodeGen/CodeGenModule.cpp
575

Normal HIP programs should only use -mcode-object-version={2|3|4|5}. clang driver enforces that.

ROCm device library need to be compiled with -Xclang -mcode-object-version=none so that the module flag is not emitted. Since this use case is not for common users, -mcode-object-version=none can only be used with -cc1.

tra added inline comments.Feb 4 2022, 4:37 PM
clang/lib/CodeGen/CodeGenModule.cpp
575

I'm surprised that cc1 does not check option validity. It does check them at the driver level: https://godbolt.org/z/9T6n47es9

Assuming that's intentional, and there are no checks in cc1, then we should probably remove the now-useless Values from the option tablegen and add a test to verify what happens with invalid values.

yaxunl marked an inline comment as done.Feb 5 2022, 5:37 PM
yaxunl added inline comments.
clang/lib/CodeGen/CodeGenModule.cpp
575

I will use MarshallingInfoEnum, which will check the values. Will add a test for invalid values.

yaxunl updated this revision to Diff 406221.Feb 5 2022, 5:41 PM
yaxunl marked an inline comment as done.

marshalling the arg as enum. fix test failures for -cc1as. temporarily disable it except v5.

tra added inline comments.Feb 7 2022, 10:27 AM
clang/include/clang/Driver/Options.td
3453–3458

none is missing. I'm not sure if we need to enumerate all values -- the list will eventually grow unacceptably long.
Does the option parser print allowed values on error? That would be sufficient, IMO.
Up to you.

clang/lib/Driver/ToolChains/Clang.cpp
1166

Do we really need a special case for -cc1as? What happens if we do pass the option to it?

If cc1as does need a special case handling, we may want to add a test case for that.

yaxunl marked 2 inline comments as done.Feb 7 2022, 10:56 AM
yaxunl added inline comments.
clang/include/clang/Driver/Options.td
3453–3458

The help text is for clang driver, where 'none' is not allowed. 'none' is only allowed with clang -cc1.

clang/lib/Driver/ToolChains/Clang.cpp
1166

TargetOptions are for -cc1 only. when passed to -cc1as, they are treated as unknown options and cause error. will add a test for that.

yaxunl updated this revision to Diff 406536.Feb 7 2022, 11:12 AM
yaxunl marked 2 inline comments as done.

add a test for -cc1as

tra accepted this revision.Feb 7 2022, 11:39 AM
tra added inline comments.
clang/lib/Driver/ToolChains/Clang.cpp
1166

does not need -mcode-object-version --> does not accept...

clang/test/CodeGenCUDA/amdgpu-code-object-version.cu
25–26

I think what we want to check is that if top-level driver decides t invoke cc1as, that we do not pass the -mcode-object-version to it.

That cc1as would not accept that option is not very interesting -- it's a CC1-only option, after all.
I guess that makes my test idea also not very interesting -- if we were to accidentally pass that option, it would cause an error.

OK, let's just update the comment above cc1as check and remove this test.

This revision is now accepted and ready to land.Feb 7 2022, 11:39 AM
yaxunl marked 2 inline comments as done.Feb 7 2022, 2:13 PM
yaxunl added inline comments.
clang/lib/Driver/ToolChains/Clang.cpp
1166

will do

clang/test/CodeGenCUDA/amdgpu-code-object-version.cu
25–26

will remove this test and add a driver test for -cc1as

yaxunl updated this revision to Diff 406605.Feb 7 2022, 2:14 PM
yaxunl marked 2 inline comments as done.

fix comments and add a driver test for -cc1as

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 6:59 PM