This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Make getInstSizeInBytes() use instruction size from InstrInfo.td
ClosedPublic

Authored by tyb0807 on Jan 23 2022, 2:42 PM.

Details

Summary

Currently, ARMBaseInstrInfo::getInstSizeInBytes() uses hard-coded
instruction size for some pseudo-instructions, while this
information should ideally be found in ARMInstrInfo.td,
ARMInstrThumb(2).td files (which can be accessed via MCInstrDesc). Hence,
the .td files should be updated and no hard-coded instruction sizes
should be used by getInstSizeInBytes() anymore.

Diff Detail

Event Timeline

tyb0807 created this revision.Jan 23 2022, 2:42 PM
tyb0807 requested review of this revision.Jan 23 2022, 2:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 23 2022, 2:42 PM
tyb0807 updated this revision to Diff 402377.Jan 23 2022, 2:44 PM
tyb0807 edited the summary of this revision. (Show Details)

Fix typo in commit message

Please appease the linter for the newly added tests.

Other reviewers should be careful with review here. My major concern that I have not yet verified is whether these pseudo's always expand to the same number of instructions or not, which would affect their corresponding size.

llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
758–763

so the Aarch64 version of this patch does the opposite. It checks the getSize() first, then returns early before the switch.
https://reviews.llvm.org/D117970
Is there a reason we can't or shouldn't be consistent between the two targets?

llvm/unittests/Target/ARM/CMakeLists.txt
13

should this be a separate change?

llvm/utils/gn/secondary/llvm/unittests/Target/ARM/BUILD.gn
5

different change?

tyb0807 marked 2 inline comments as done.Jan 25 2022, 1:57 AM
tyb0807 added inline comments.
llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
758–763

So in the AArch64 version, the default size of an expanded pseudo-instruction is 4 bytes, while for ARM, it is more complicated to define such a default size: Thumb1 instructions are 2 bytes, Thumb2 instructions are 2-4 bytes, and ARM instructions are 4 bytes. As a result, we return 0 for pseudo-instructions that we don't have any information about the size.

I'll move the AArch64 code into the default case as well, to make the comparison easier, and add a comment explaining this

llvm/unittests/Target/ARM/CMakeLists.txt
13

Do you mean the test should be in a separate change? Any reason for doing this?

llvm/utils/gn/secondary/llvm/unittests/Target/ARM/BUILD.gn
5

See reply above

tyb0807 updated this revision to Diff 402805.Jan 25 2022, 2:11 AM
tyb0807 marked 2 inline comments as done.

clang-format, update comment to clarify the intention of the code, and add new
comments specifying fixed constant sizes of pseudo-instructions

Indeed, the pseudo's that are updated in the .td files always expand to the same instruction sequence, hence their size in bytes are fixed. Or maybe you mean you are not sure if the expansion would change in the future (i.e. the pseudo's will be expanded to a different instruction sequence)?

Other reviewers should be careful with review here. My major concern that I have not yet verified is whether these pseudo's always expand to the same number of instructions or not, which would affect their corresponding size.

If these sizes are wrong, then this patch doesn't make that worse (but this is a good opportunity to verify that the sizes are correct). This override tends to only be required for pseudos that are expanded very late (usually in the Asm Printer), and problems with it tend to affect branch relaxation, iirc.

llvm/unittests/Target/ARM/CMakeLists.txt
13

Adding tests with these changes seems like the right thing to do, and these tests need a MIR parser, so this change is required.

llvm/unittests/Target/ARM/InstSizes.cpp
88

Can you add tests for the instructions remaining in the switch block, each of which has more complex logic for calculating its size? Right now you're only testing the things you moved out of the switch block.

tyb0807 updated this revision to Diff 403176.Jan 26 2022, 1:58 AM
tyb0807 marked 3 inline comments as done.

Update new tests for variable-sized pseudo-instructions

lenary accepted this revision.Jan 28 2022, 3:49 AM
This revision is now accepted and ready to land.Jan 28 2022, 3:49 AM
This revision was landed with ongoing or failed builds.Feb 1 2022, 2:39 AM
This revision was automatically updated to reflect the committed changes.
AaronLiu added a subscriber: AaronLiu.EditedFeb 1 2022, 4:21 PM

Looks like linking the following test caused many(57 for now) LoP-LE build failures (first build failure: https://lab.llvm.org/buildbot/#/builders/57/builds/14559):

186.515 [21/53/841] Linking CXX executable unittests/Target/ARM/ARMTests
FAILED: unittests/Target/ARM/ARMTests 
: && /home/buildbots/clang.11.0.0/bin/clang++ --gcc-toolchain=/opt/rh/devtoolset-7/root/usr  -fPIC -fvisibility-inlines-hidden -Werror -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG  -Wl,--gc-sections unittests/Target/ARM/CMakeFiles/ARMTests.dir/MachineInstrTest.cpp.o unittests/Target/ARM/CMakeFiles/ARMTests.dir/InstSizes.cpp.o  -o unittests/Target/ARM/ARMTests  -Wl,-rpath,/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/lib  lib/libLLVMARMCodeGen.so.14git  lib/libLLVMARMDesc.so.14git  lib/libLLVMARMInfo.so.14git  lib/libLLVMGlobalISel.so.14git  lib/libLLVMMIRParser.so.14git  lib/libLLVMSelectionDAG.so.14git  -lpthread  lib/libgtest_main.so.14git  lib/libgtest.so.14git  -lpthread  lib/libLLVMCodeGen.so.14git  lib/libLLVMTarget.so.14git  lib/libLLVMMC.so.14git  lib/libLLVMSupport.so.14git  -Wl,-rpath-link,/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/lib && :
/opt/rh/devtoolset-7/root/usr/lib/gcc/ppc64le-redhat-linux/7/../../../../bin/ld: unittests/Target/ARM/CMakeFiles/ARMTests.dir/InstSizes.cpp.o: undefined reference to symbol '_ZN4llvm10DataLayout5clearEv'
/home/buildbots/docker-RHEL-buildbot/SetupBot/worker_env/ppc64le-clang-rhel-test/clang-ppc64le-rhel/build/lib/libLLVMCore.so.14git: error adding symbols: DSO missing from command line
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
289.769 [21/2/892] Building CXX object tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/SourceCodeTest.cpp.o
ninja: build stopped: subcommand failed.
program finished with exit code 1
elapsedTime=424.974897

Sorry for the linking issue, this has been fixed in commit ec00c9cdeb5ee9fc7846cb3d2a4d53eba2c35a43