This is an archive of the discontinued LLVM Phabricator instance.

[TargetLowering][NFC] More efficient emitPatchpoint().
ClosedPublic

Authored by dantrushin on Jun 4 2020, 11:36 AM.

Details

Summary

Current implementation of emitPatchpoint() is very inefficient:
for every FrameIndex operand if creates new MachineInstr with
that operand expanded and all other copies as is.
Since PATCHPOINT/STATEPOINT instructions may have *a lot* of
FrameIndex operands, we end up creating and erasing many
machine instructions. But we can do it in single pass, with only
one new machine instruction generated.

Diff Detail

Event Timeline

dantrushin created this revision.Jun 4 2020, 11:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 11:36 AM
efriedma added inline comments.Jun 4 2020, 11:59 AM
llvm/lib/CodeGen/TargetLoweringBase.cpp
1029

You're making this code a lot harder to follow with the whole OperIdx thing, and it only saves one branch per MachineOperand. Please just do if (!llvm::any_of(MI->operands(), [](MachineOperand &Operand) { return Operand.isFI(); }) return MBB;

reames requested changes to this revision.Jun 4 2020, 12:32 PM

Agreed with Eli, simply having two passes over operands would be much cleaner.

I do like the removal of the multi pass copy. Definitely moving in the right direction.

This revision now requires changes to proceed.Jun 4 2020, 12:32 PM
dantrushin updated this revision to Diff 268578.Jun 4 2020, 1:22 PM

Address comments

reames accepted this revision.Jun 4 2020, 2:29 PM

LGTM w/minor change suggested.

llvm/lib/CodeGen/TargetLoweringBase.cpp
1034

Minor, optional: I believe you can rewrite this as:
for (auto &Op : MI->operands()) { ...

This revision is now accepted and ready to land.Jun 4 2020, 2:29 PM
stuij added a subscriber: stuij.Jun 5 2020, 5:18 AM

Seems like this is breaking on buildbot (and also my local checkout): http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/16759

This revision was automatically updated to reflect the committed changes.

Seems like this is breaking on buildbot (and also my local checkout): http://lab.llvm.org:8011/builders/lldb-x64-windows-ninja/builds/16759

Are you sure? In your logs I see

E:\build_slave\lldb-x64-windows-ninja\llvm-project\llvm\include\llvm/CodeGen/TargetLowering.h(2971): fatal error C1088: Cannot flush compiler intermediate file: 'C:\Users\BUILDS~1\AppData\Local\Temp\_CL_ea8c083eex': No space left on device

which cannot be caused by my fix, I believe ;)
I'll double check buildbot

Ah, I see. I indeed broke the build. Will fix in a moment

stuij added a comment.Jun 5 2020, 5:46 AM

ah sorry, I guess that might have been the wrong link. My copy pasting skills are flaky.

what I'm seeing is this:

FAILED: lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o 
/usr/local/bin/c++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/CodeGen -I/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen -I/usr/include/libxml2 -Iinclude -I/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3     -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o -MF lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o.d -o lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o -c /home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp: In member function ‘llvm::MachineBasicBlock* llvm::TargetLoweringBase::emitPatchPoint(llvm::MachineInstr&, llvm::MachineBasicBlock*) const’:
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp:1037:30: error: ‘OperIdx’ was not declared in this scope
 1037 |       MIB.add(MI->getOperand(OperIdx));
      |                              ^~~~~~~
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp:1054:30: error: ‘OperIdx’ was not declared in this scope
 1054 |       MIB.add(MI->getOperand(OperIdx));
      |                              ^~~~~~~
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp:1060:30: error: ‘OperIdx’ was not declared in this scope
 1060 |       MIB.add(MI->getOperand(OperIdx));

from: http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/23856/steps/build%20stage%201/logs/stdio

ah sorry, I guess that might have been the wrong link. My copy pasting skills are flaky.

what I'm seeing is this:

FAILED: lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o 
/usr/local/bin/c++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Ilib/CodeGen -I/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen -I/usr/include/libxml2 -Iinclude -I/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/include -fPIC -fvisibility-inlines-hidden -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3     -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MD -MT lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o -MF lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o.d -o lib/CodeGen/CMakeFiles/LLVMCodeGen.dir/TargetLoweringBase.cpp.o -c /home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp: In member function ‘llvm::MachineBasicBlock* llvm::TargetLoweringBase::emitPatchPoint(llvm::MachineInstr&, llvm::MachineBasicBlock*) const’:
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp:1037:30: error: ‘OperIdx’ was not declared in this scope
 1037 |       MIB.add(MI->getOperand(OperIdx));
      |                              ^~~~~~~
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp:1054:30: error: ‘OperIdx’ was not declared in this scope
 1054 |       MIB.add(MI->getOperand(OperIdx));
      |                              ^~~~~~~
/home/tcwg-buildslave/worker/clang-cmake-aarch64-quick/llvm/llvm/lib/CodeGen/TargetLoweringBase.cpp:1060:30: error: ‘OperIdx’ was not declared in this scope
 1060 |       MIB.add(MI->getOperand(OperIdx));

from: http://lab.llvm.org:8011/builders/clang-cmake-aarch64-quick/builds/23856/steps/build%20stage%201/logs/stdio

Should be fixed now. Can you try again?
Sorry for the inconvenience.

stuij added a comment.Jun 5 2020, 6:22 AM

Yup, LLVM now builds and check-all's. Thanks for fixing!