[PATCH] D31261: [IR] De-virtualize ~Value to save a vptr

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 22 14:32:16 PDT 2017


rnk created this revision.
Herald added subscribers: Prazek, mzolotukhin.

Implements PR889

This patch is intended as an overview of all the changes required to
devirtualize Value. This patch needs to be split up and parts of it
aren't acceptable at all, but I'm posting this to get some discussion
started.

Removing the virtual table pointer from Value saves 1% of RSS when doing
LTO of llc on Linux. The impact on time was positive, but too noisy to
conclusively say that performance improved. Here is a link to the
spreadsheet with the original data:

https://docs.google.com/spreadsheets/d/1F4FHir0qYnV0MEp2sYYp_BuvnJgWlWPhWOwZ6LbW7W4/edit?usp=sharing

This change makes it invalid to directly delete a Value, User, or
Instruction pointer. Instead, such code can be rewritten to a null check
and a call Value::deleteValue(). Value objects tend to have their
lifetimes managed through iplist, so for the most part, this is an
internal implementation detail. However, there are some places where
LLVM deletes values, and those places had to be migrated to deleteValue.
I have also created llvm::unique_value, which has a custom deleter, so
it can be used in place of std::unique_ptr<Value>.

I had to add the "ValueCallbacks" escape hatch for MemorySSA, which
derives from User outside of lib/IR. Code in IR cannot include MemorySSA
headers or call the MemoryAccess object destructors without introducing
a circular dependency, so we need some level of indirection.
Unfortunately, no class derived from User may have any virtual methods,
because adding a virtual method would break User::getHungOffOperands(),
which assumes that it can find the use list immediately prior to the
User object. Adding virtual methods anywhere in the hierarchy will
compile, but any attempt to use the use list will crash with confusing
assertions. I think we need some way of checking this at compile time,
because developers are going to trip over this.


https://reviews.llvm.org/D31261

Files:
  include/llvm/IR/Argument.h
  include/llvm/IR/BasicBlock.h
  include/llvm/IR/Constant.h
  include/llvm/IR/Constants.h
  include/llvm/IR/DerivedUser.h
  include/llvm/IR/Function.h
  include/llvm/IR/GlobalAlias.h
  include/llvm/IR/GlobalIFunc.h
  include/llvm/IR/GlobalObject.h
  include/llvm/IR/GlobalValue.h
  include/llvm/IR/GlobalVariable.h
  include/llvm/IR/InlineAsm.h
  include/llvm/IR/InstrTypes.h
  include/llvm/IR/Instruction.def
  include/llvm/IR/Instruction.h
  include/llvm/IR/Instructions.h
  include/llvm/IR/Metadata.h
  include/llvm/IR/Operator.h
  include/llvm/IR/User.h
  include/llvm/IR/Value.def
  include/llvm/IR/Value.h
  include/llvm/Transforms/Utils/MemorySSA.h
  lib/AsmParser/LLParser.cpp
  lib/Bitcode/Reader/BitcodeReader.cpp
  lib/Bitcode/Reader/ValueList.cpp
  lib/CodeGen/CodeGenPrepare.cpp
  lib/IR/Constants.cpp
  lib/IR/ConstantsContext.h
  lib/IR/Function.cpp
  lib/IR/Globals.cpp
  lib/IR/InlineAsm.cpp
  lib/IR/Instruction.cpp
  lib/IR/Instructions.cpp
  lib/IR/LLVMContextImpl.cpp
  lib/IR/User.cpp
  lib/IR/Value.cpp
  lib/Linker/IRMover.cpp
  lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
  lib/Transforms/Scalar/GVN.cpp
  lib/Transforms/Scalar/JumpThreading.cpp
  lib/Transforms/Scalar/LoopRotation.cpp
  lib/Transforms/Scalar/Reassociate.cpp
  lib/Transforms/Scalar/SROA.cpp
  lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
  lib/Transforms/Utils/CloneFunction.cpp
  lib/Transforms/Utils/MemorySSA.cpp
  lib/Transforms/Utils/SimplifyCFG.cpp
  lib/Transforms/Vectorize/SLPVectorizer.cpp
  unittests/IR/ConstantsTest.cpp
  unittests/IR/InstructionsTest.cpp
  unittests/IR/MetadataTest.cpp
  unittests/Transforms/Utils/Cloning.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31261.92713.patch
Type: text/x-patch
Size: 68223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170322/62bb64b8/attachment-0001.bin>


More information about the llvm-commits mailing list