From 09b4a8daa354382c294e736fc9db018621376728 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Thu, 10 Mar 2016 01:28:54 +0000 Subject: Add a flag to the LLVMContext to disable name for Value other than GlobalValue Summary: This is intended to be a performance flag, on the same level as clang cc1 option "--disable-free". LLVM will never initialize it by default, it will be up to the client creating the LLVMContext to request this behavior. Clang will do it by default in Release build (just like --disable-free). "opt" and "llc" can opt-in using -disable-named-value command line option. When performing LTO on llvm-tblgen, the initial merging of IR peaks at 92MB without this patch, and 86MB after this patch,setNameImpl() drops from 6.5MB to 0.5MB. The total link time goes from ~29.5s to ~27.8s. Compared to a compile-time flag (like the IRBuilder one), it performs very close. I profiled on SROA and obtain these results: 420ms with IRBuilder that preserve name 372ms with IRBuilder that strip name 375ms with IRBuilder that preserve name, and a runtime flag to strip Reviewers: chandlerc, dexonsmith, bogner Subscribers: joker.eph, llvm-commits Differential Revision: http://reviews.llvm.org/D17946 From: Mehdi Amini llvm-svn: 263086 --- llvm/lib/IR/LLVMContext.cpp | 6 ++++++ llvm/lib/IR/LLVMContextImpl.h | 4 ++++ llvm/lib/IR/Value.cpp | 4 ++++ 3 files changed, 14 insertions(+) (limited to 'llvm/lib/IR') diff --git a/llvm/lib/IR/LLVMContext.cpp b/llvm/lib/IR/LLVMContext.cpp index 5e6fe69af97..77cefd038d8 100644 --- a/llvm/lib/IR/LLVMContext.cpp +++ b/llvm/lib/IR/LLVMContext.cpp @@ -325,3 +325,9 @@ const std::string &LLVMContext::getGC(const Function &Fn) { void LLVMContext::deleteGC(const Function &Fn) { pImpl->GCNames.erase(&Fn); } + +bool LLVMContext::discardValueNames() { return pImpl->DiscardValueNames; } + +void LLVMContext::setDiscardValueNames(bool Discard) { + pImpl->DiscardValueNames = Discard; +} diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index d42047d4e77..019e2d07e15 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -1034,6 +1034,10 @@ public: /// clients which do use GC. DenseMap GCNames; + /// Flag to indicate if Value (other than GlobalValue) retains their name or + /// not. + bool DiscardValueNames = false; + LLVMContextImpl(LLVMContext &C); ~LLVMContextImpl(); diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 19fb4f8dba2..ca90b4368c4 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -198,6 +198,10 @@ StringRef Value::getName() const { } void Value::setNameImpl(const Twine &NewName) { + // Fast-path: LLVMContext can be set to strip out non-GlobalValue names + if (getContext().discardValueNames() && !isa(this)) + return; + // Fast path for common IRBuilder case of setName("") when there is no name. if (NewName.isTriviallyEmpty() && !hasName()) return; -- cgit v1.2.3