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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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. | |
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? |
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 |
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)?
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. |
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
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?