This is an archive of the discontinued LLVM Phabricator instance.

[BPF] Make BPFAbstractMemberAccessPass required
ClosedPublic

Authored by aeubanks on Oct 8 2020, 4:48 PM.

Details

Summary

Or else on optnone functions we get the following during instruction selection:

fatal error: error in backend: Cannot select: intrinsic %llvm.preserve.struct.access.index

Currently the -O0 pipeline doesn't properly run passes registered via
TargetMachine::registerPassBuilderCallbacks(), so don't add that RUN
line yet. That will be fixed after this.

Diff Detail

Event Timeline

aeubanks created this revision.Oct 8 2020, 4:48 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 8 2020, 4:48 PM
aeubanks requested review of this revision.Oct 8 2020, 4:48 PM
yonghong-song added inline comments.Oct 8 2020, 10:21 PM
llvm/lib/Target/BPF/BPF.h
50

Could you explain what is the purpose of the above line?

llvm/test/CodeGen/BPF/CORE/store-addr-optnone.ll
2

Currently, for BPF ecosystem, we only recommend -O2, and all our major CI tests and kernel self tests are all compiled with -O2. It is known that -O0 (optnone) does not work for bpf programs as it may pass compilation, but it won't pass kernel verifier, and we have not extensively verified correctness of -O0 generated code either (esp. related to relocations). So I think this optnone thing is really a lower priority and it should not impct anyone.

But yes, even if -O0 is not recommended to developer and practically nobody uses it. But failing compilation still bad. Currently BPF unit test only has one optnone test optnone-1.ll which did not check generated code except ensure it passes compilation.

If you really want a test case, you can add an
optnone-2.ll.

The code can be
-bash-4.4$ cat t.c
int foo() { return __builtin_btf_type_id(0, 0); }
and to generate IR for opt:
clang -target bpf -g -S -emit-llvm t.c -Xclang -disable-llvm-passes

And just to check whether compilation is successful or not.

In my opinion, NPM does not support optnone yet, I think you can add the test (if you want) later once the support is there. Adding this test won't add coverage right now.

If I understand correctly, "isRequired()" means this pass has to run. In this regard, BPFPreserveDIType also need isRequired().
Could you explain a little bit what if one pass does not have "isRequired()"? How PassManager deals with it?

aeubanks updated this revision to Diff 297277.Oct 9 2020, 10:29 AM

also make BPFPreserveDITypePass required and add test

If I understand correctly, "isRequired()" means this pass has to run. In this regard, BPFPreserveDIType also need isRequired().

Ah I didn't know both were required. I added that and added your test case. Your test case seems to only cover BPFPreserveDITypePass, the one already added here covers BPFAbstractMemberAccessPass.

Could you explain a little bit what if one pass does not have "isRequired()"? How PassManager deals with it?

http://llvm.org/docs/WritingAnLLVMNewPMPass.html#required-passes has some explanation.
If a pass doesn't have isRequired() { return true; }, pass managers will skip it if something says to skip optional passes, like optnone.

llvm/test/CodeGen/BPF/CORE/store-addr-optnone.ll
2

NPM does support optnone as of https://reviews.llvm.org/D87869, we now just have to make sure that all required passes are marked so.

Yes I think compilation failing is quite bad. Currently BPF is the only target that adds required passes via registerPassBuilderCallbacks, but likely others will in the future. Currently all the -O0 pipeline (in clang and opt) don't run passes added by registerPassBuilderCallbacks and I'd like a test case once that's fixed. Currently the only test case I can come up with is BPF related tests, like the opt -passes=default<O2> in this patch, but instead opt -passes=default<O0>.

If the generated code from -O0 is not well tested, that's fine, again I'm just looking for a test case to show that we actually run passes added by
registerPassBuilderCallbacks in all circumstances.

Thanks for explanation for IsRequired(), really appreciated.

Could you change optnone-2.ll with the following source:
-bash-4.4$ cat t.c
struct ss { int a; };
int foo() { return builtin_btf_type_id(0, 0) + builtin_preserve_type_info(*(struct ss *)0, 0); }
-bash-4.4$

This will cover both BPFAbstractMemberAccess.cpp and BPFPreserveDIType.cpp. This way, we do not need store-addr-optnone.ll.

aeubanks updated this revision to Diff 297284.Oct 9 2020, 11:08 AM

update test in accordance with comments

yonghong-song accepted this revision.Oct 9 2020, 11:20 AM

LGTM. Thanks!

This revision is now accepted and ready to land.Oct 9 2020, 11:20 AM
This revision was landed with ongoing or failed builds.Oct 9 2020, 11:27 AM
This revision was automatically updated to reflect the committed changes.