llvm-project/llvm/lib/Transforms/Utils
Reid Kleckner 96ab8726a3 [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
2017-05-18 17:24:10 +00:00
..
ASanStackFrameLayout.cpp [asan] Replace std::to_string with llvm::to_string 2016-10-19 00:16:56 +00:00
AddDiscriminators.cpp [AddDiscriminators] Assign discriminators to MemIntrinsic calls. 2017-04-11 19:07:30 +00:00
BasicBlockUtils.cpp Rename WeakVH to WeakTrackingVH; NFC 2017-05-01 17:07:49 +00:00
BreakCriticalEdges.cpp [PM] Port BreakCriticalEdges to the new PM. 2016-07-22 18:04:25 +00:00
BuildLibCalls.cpp TargetLibraryInfo: Introduce wcslen 2017-05-05 20:25:50 +00:00
BypassSlowDivision.cpp [KnownBits] Add bit counting methods to KnownBits struct and use them where possible 2017-05-12 17:20:30 +00:00
CMakeLists.txt MemorySSA: Move to Analysis, from Transforms/Utils. It's used as 2017-04-11 20:06:36 +00:00
CloneFunction.cpp [IR] De-virtualize ~Value to save a vptr 2017-05-18 17:24:10 +00:00
CloneModule.cpp Remove spurious cast of nullptr. NFC. 2017-05-11 08:53:00 +00:00
CmpInstAnalysis.cpp [APInt] Rename getSignBit to getSignMask 2017-04-20 16:56:25 +00:00
CodeExtractor.cpp [CodeExtractor]: Fixup use refs of the old phi. 2017-04-25 04:51:19 +00:00
CtorUtils.cpp [CtorUtils] Modernize. No functional changes intended. 2016-10-22 01:21:24 +00:00
DemoteRegToStack.cpp Allow DataLayout to specify addrspace for allocas. 2017-04-10 22:27:50 +00:00
EscapeEnumerator.cpp Suppress all uses of LLVM_END_WITH_NULL. NFC. 2017-05-09 19:31:13 +00:00
Evaluator.cpp [IR] Redesign the case iterator in SwitchInst to actually be an iterator 2017-04-12 07:27:28 +00:00
FlattenCFG.cpp [FlattenCFG] Simplify + remove unused variable. NFCI. 2016-08-05 20:53:35 +00:00
FunctionComparator.cpp Rename AttributeSet to AttributeList 2017-03-21 16:57:19 +00:00
FunctionImportUtils.cpp FunctionImport: Use IRMover directly. 2017-02-03 16:56:27 +00:00
GlobalStatus.cpp [Transforms/Utils] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-01-14 00:32:38 +00:00
ImportedFunctionsInliningStatistics.cpp [ThinLTO] Correct counting of functions in inliner stats 2017-03-24 17:59:06 +00:00
InlineFunction.cpp [ProfileSummary] Make getProfileCount a non-static member function. 2017-05-09 23:21:10 +00:00
InstructionNamer.cpp [InstNamer] Use range-for 2017-05-08 23:18:43 +00:00
IntegerDivision.cpp
LCSSA.cpp [LCSSA] Don't insert tokens into the worklist at all. 2017-04-17 14:32:05 +00:00
LLVMBuild.txt
LibCallsShrinkWrap.cpp [LibCallsShrinkWrap] Remove an unnecessary class member variable. 2017-04-26 21:28:40 +00:00
Local.cpp PR32288: Describe a bool parameter's DWARF location with a simple register 2017-05-15 21:34:01 +00:00
LoopSimplify.cpp Kill off the old SimplifyInstruction API by converting remaining users. 2017-04-28 19:55:38 +00:00
LoopUnroll.cpp Rename WeakVH to WeakTrackingVH; NFC 2017-05-01 17:07:49 +00:00
LoopUnrollPeel.cpp [LoopPeeling] Get rid of Phis that become invariant after N steps 2017-04-17 09:52:02 +00:00
LoopUnrollRuntime.cpp Avoid warning of unused variable in release builds. NFC 2017-05-03 19:25:04 +00:00
LoopUtils.cpp Add a late IR expansion pass for the experimental reduction intrinsics. 2017-05-10 09:42:49 +00:00
LoopVersioning.cpp [LoopVersioning] Require loop-simplify form for loop versioning. 2016-12-19 17:13:37 +00:00
LowerInvoke.cpp [PM] Port LowerInvoke to the new pass manager 2016-08-12 17:28:27 +00:00
LowerMemIntrinsics.cpp NVPTX: Extract mem intrinsic expansions into utilities 2017-02-08 17:49:52 +00:00
LowerSwitch.cpp LowerSwitch: Fix producing invalid IR on unreachable code 2017-04-21 23:54:12 +00:00
Mem2Reg.cpp [Mem2Reg] Remove AliasSetTracker updating logic from the pass. 2017-04-09 20:47:14 +00:00
MetaRenamer.cpp [MetaRenamer] Don't rename library functions. 2017-03-23 23:21:07 +00:00
ModuleUtils.cpp Suppress all uses of LLVM_END_WITH_NULL. NFC. 2017-05-09 19:31:13 +00:00
NameAnonGlobals.cpp Use StringRef in Pass/PassManager APIs (NFC) 2016-10-01 02:56:57 +00:00
PredicateInfo.cpp Simplify the code and remove dead code 2017-04-11 08:21:27 +00:00
PromoteMemoryToRegister.cpp Kill off the old SimplifyInstruction API by converting remaining users. 2017-04-28 19:55:38 +00:00
SSAUpdater.cpp [Target, Transforms] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC). 2017-01-18 00:57:48 +00:00
SanitizerStats.cpp
SimplifyCFG.cpp [IR] De-virtualize ~Value to save a vptr 2017-05-18 17:24:10 +00:00
SimplifyIndVar.cpp Rename WeakVH to WeakTrackingVH; NFC 2017-05-01 17:07:49 +00:00
SimplifyInstructions.cpp Kill off the old SimplifyInstruction API by converting remaining users. 2017-04-28 19:55:38 +00:00
SimplifyLibCalls.cpp Suppress all uses of LLVM_END_WITH_NULL. NFC. 2017-05-09 19:31:13 +00:00
SplitModule.cpp Move instances of std::function. 2016-06-12 16:13:55 +00:00
StripGCRelocates.cpp [StripGCRelocates] New pass to remove gc.relocates added by RS4GC 2016-10-21 18:43:16 +00:00
StripNonLineTableDebugInfo.cpp Add -strip-nonlinetable-debuginfo capability 2016-10-25 18:44:13 +00:00
SymbolRewriter.cpp [PM] Port SymbolRewriter to the new PM 2016-07-25 20:52:00 +00:00
UnifyFunctionExitNodes.cpp Apply clang-tidy's modernize-loop-convert to most of lib/Transforms. 2016-06-26 12:28:59 +00:00
Utils.cpp MemorySSA: Move to Analysis, from Transforms/Utils. It's used as 2017-04-11 20:06:36 +00:00
VNCoercion.cpp [GVN] Fix a crash on encountering non-integral pointers 2017-05-09 21:07:20 +00:00
ValueMapper.cpp Suppress all uses of LLVM_END_WITH_NULL. NFC. 2017-05-09 19:31:13 +00:00