[IR] De-virtualize ~Value to save a vptr
authorReid Kleckner <rnk@google.com>
Thu, 18 May 2017 17:24:10 +0000 (17:24 +0000)
committerReid Kleckner <rnk@google.com>
Thu, 18 May 2017 17:24:10 +0000 (17:24 +0000)
commit96ab8726a3c2676c614b4d38500478046f816ce2
treead37f152381fbffc03042e5d6598ba6a37a80201
parent8848c1e3c7e94eac2b207fa4418419d8d6765e20
[IR] De-virtualize ~Value to save a vptr

Summary:
Implements PR889

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 isn't a big
deal.  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 "DerivedUser" Deleter 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. I've added a static_assert to the appropriate OperandTraits
templates to help people avoid this trap.

Reviewers: chandlerc, mehdi_amini, pete, dberlin, george.burgess.iv

Reviewed By: chandlerc

Subscribers: krytarowski, eraman, george.burgess.iv, mzolotukhin, Prazek, nlewycky, hans, inglorion, pcc, tejohnson, dberlin, llvm-commits

Differential Revision: https://reviews.llvm.org/D31261

llvm-svn: 303362
49 files changed:
llvm/include/llvm/Analysis/MemorySSA.h
llvm/include/llvm/IR/Argument.h
llvm/include/llvm/IR/BasicBlock.h
llvm/include/llvm/IR/Constant.h
llvm/include/llvm/IR/Constants.h
llvm/include/llvm/IR/DerivedUser.h [new file with mode: 0644]
llvm/include/llvm/IR/Function.h
llvm/include/llvm/IR/GlobalValue.h
llvm/include/llvm/IR/GlobalVariable.h
llvm/include/llvm/IR/InlineAsm.h
llvm/include/llvm/IR/InstrTypes.h
llvm/include/llvm/IR/Instruction.def
llvm/include/llvm/IR/Instruction.h
llvm/include/llvm/IR/Instructions.h
llvm/include/llvm/IR/Metadata.h
llvm/include/llvm/IR/OperandTraits.h
llvm/include/llvm/IR/Operator.h
llvm/include/llvm/IR/User.h
llvm/include/llvm/IR/Value.def
llvm/include/llvm/IR/Value.h
llvm/lib/Analysis/MemorySSA.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Reader/ValueList.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/IR/Constants.cpp
llvm/lib/IR/ConstantsContext.h
llvm/lib/IR/Function.cpp
llvm/lib/IR/InlineAsm.cpp
llvm/lib/IR/Instruction.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/LLVMContextImpl.cpp
llvm/lib/IR/User.cpp
llvm/lib/IR/Value.cpp
llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/lib/Transforms/Scalar/LoopRotation.cpp
llvm/lib/Transforms/Scalar/Reassociate.cpp
llvm/lib/Transforms/Scalar/SROA.cpp
llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
llvm/lib/Transforms/Utils/CloneFunction.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/unittests/IR/ConstantsTest.cpp
llvm/unittests/IR/InstructionsTest.cpp
llvm/unittests/IR/MetadataTest.cpp
llvm/unittests/Transforms/Utils/Cloning.cpp
polly/lib/CodeGen/BlockGenerators.cpp