<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 2, 2015, at 6:08 AM, Benjamin Kramer <<a href="mailto:benny.kra@gmail.com" class="">benny.kra@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On 02.06.2015, at 00:24, Owen Anderson <<a href="mailto:resistor@mac.com" class="">resistor@mac.com</a>> wrote:<br class=""><br class="">Author: resistor<br class="">Date: Mon Jun  1 17:24:01 2015<br class="">New Revision: 238791<br class=""><br class="">URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D238791-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=i1GdBdbGABoQnppfBqBhvEUcPJD1HSTVZZuwxgMHZzs&s=wCSRI4cnBEZ4N6F0RRYqZlN4R1sHSVKNfb60KHEv2ic&e=" class="">http://llvm.org/viewvc/llvm-project?rev=238791&view=rev</a><br class="">Log:<br class="">Move the name pointer out of Value into a map that lives on the<br class="">LLVMContext.  Production builds of clang do not set names on most<br class="">Value's, so this is wasted space on almost all subclasses of Value.<br class="">This reduces the size of all Value subclasses by 8 bytes on 64 bit<br class="">hosts.<br class=""><br class="">The one tricky part of this change is averting compile time regression<br class="">by keeping Value::hasName() fast.  This required stealing bits out of<br class="">NumOperands.<br class=""><br class="">With this change, peak memory usage on verify-uselistorder-nodbg.lto.bc<br class="">is decreased by approximately 2.3% (~3MB absolute on my machine).<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Nice savings. PR889 is still there if you want to shave another pointer off Value, I think the PseudoSourceValue problem is solved so this may be a matter of rewriting virtual functions into switches.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote>I didn’t know that PR existed.  I have a patch ready to do this that I can send out soon.  I just need to clean up some of the switches to use a .def file instead of lots of duplication.</div><div><br class=""></div><div>Cheers,</div><div>Pete<br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">- Ben</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">Modified:<br class="">  llvm/trunk/include/llvm/IR/Value.h<br class="">  llvm/trunk/lib/IR/LLVMContextImpl.h<br class="">  llvm/trunk/lib/IR/Metadata.cpp<br class="">  llvm/trunk/lib/IR/Value.cpp<br class=""><br class="">Modified: llvm/trunk/include/llvm/IR/Value.h<br class="">URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_include_llvm_IR_Value.h-3Frev-3D238791-26r1-3D238790-26r2-3D238791-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=i1GdBdbGABoQnppfBqBhvEUcPJD1HSTVZZuwxgMHZzs&s=JFwSZRlX0Sfc70k6mw7VD_Ex8doZmYQWLnIGHh1AqNM&e=" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Value.h?rev=238791&r1=238790&r2=238791&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/include/llvm/IR/Value.h (original)<br class="">+++ llvm/trunk/include/llvm/IR/Value.h Mon Jun  1 17:24:01 2015<br class="">@@ -69,9 +69,8 @@ class Value {<br class=""> Type *VTy;<br class=""> Use *UseList;<br class=""><br class="">-  friend class ValueAsMetadata; // Allow access to NameAndIsUsedByMD.<br class="">+  friend class ValueAsMetadata; // Allow access to IsUsedByMD.<br class=""> friend class ValueHandleBase;<br class="">-  PointerIntPair<ValueName *, 1> NameAndIsUsedByMD;<br class=""><br class=""> const unsigned char SubclassID;   // Subclass identifier (for isa/dyn_cast)<br class=""> unsigned char HasValueHandle : 1; // Has a ValueHandle pointing to this?<br class="">@@ -101,7 +100,10 @@ protected:<br class=""> /// This is stored here to save space in User on 64-bit hosts.  Since most<br class=""> /// instances of Value have operands, 32-bit hosts aren't significantly<br class=""> /// affected.<br class="">-  unsigned NumOperands;<br class="">+  unsigned NumOperands : 30;<br class="">+<br class="">+  bool IsUsedByMD : 1;<br class="">+  bool HasName : 1;<br class=""><br class="">private:<br class=""> template <typename UseT> // UseT == 'Use' or 'const Use'<br class="">@@ -210,9 +212,9 @@ public:<br class=""> LLVMContext &getContext() const;<br class=""><br class=""> // \brief All values can potentially be named.<br class="">-  bool hasName() const { return getValueName() != nullptr; }<br class="">-  ValueName *getValueName() const { return NameAndIsUsedByMD.getPointer(); }<br class="">-  void setValueName(ValueName *VN) { NameAndIsUsedByMD.setPointer(VN); }<br class="">+  bool hasName() const { return HasName; }<br class="">+  ValueName *getValueName() const;<br class="">+  void setValueName(ValueName *VN);<br class=""><br class="">private:<br class=""> void destroyValueName();<br class="">@@ -394,7 +396,7 @@ public:<br class=""> bool hasValueHandle() const { return HasValueHandle; }<br class=""><br class=""> /// \brief Return true if there is metadata referencing this value.<br class="">-  bool isUsedByMetadata() const { return NameAndIsUsedByMD.getInt(); }<br class="">+  bool isUsedByMetadata() const { return IsUsedByMD; }<br class=""><br class=""> /// \brief Strip off pointer casts, all-zero GEPs, and aliases.<br class=""> ///<br class=""><br class="">Modified: llvm/trunk/lib/IR/LLVMContextImpl.h<br class="">URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_IR_LLVMContextImpl.h-3Frev-3D238791-26r1-3D238790-26r2-3D238791-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=i1GdBdbGABoQnppfBqBhvEUcPJD1HSTVZZuwxgMHZzs&s=_woR3HPe7BY0hwlh3_znZvyEqGvvdhYwCwE7IVxAKp0&e=" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.h?rev=238791&r1=238790&r2=238791&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/IR/LLVMContextImpl.h (original)<br class="">+++ llvm/trunk/lib/IR/LLVMContextImpl.h Mon Jun  1 17:24:01 2015<br class="">@@ -922,6 +922,8 @@ public:<br class=""> DenseMap<Value *, ValueAsMetadata *> ValuesAsMetadata;<br class=""> DenseMap<Metadata *, MetadataAsValue *> MetadataAsValues;<br class=""><br class="">+  DenseMap<const Value*, ValueName*> ValueNames;<br class="">+<br class="">#define HANDLE_MDNODE_LEAF(CLASS) DenseSet<CLASS *, CLASS##Info> CLASS##s;<br class="">#include "llvm/IR/Metadata.def"<br class=""><br class=""><br class="">Modified: llvm/trunk/lib/IR/Metadata.cpp<br class="">URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_IR_Metadata.cpp-3Frev-3D238791-26r1-3D238790-26r2-3D238791-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=i1GdBdbGABoQnppfBqBhvEUcPJD1HSTVZZuwxgMHZzs&s=Vh6rDk7gHRvkQPtITNp_ulCXDVc0DrkJqWCmdzSmb3k&e=" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=238791&r1=238790&r2=238791&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/IR/Metadata.cpp (original)<br class="">+++ llvm/trunk/lib/IR/Metadata.cpp Mon Jun  1 17:24:01 2015<br class="">@@ -256,9 +256,9 @@ ValueAsMetadata *ValueAsMetadata::get(Va<br class=""> if (!Entry) {<br class="">   assert((isa<Constant>(V) || isa<Argument>(V) || isa<Instruction>(V)) &&<br class="">          "Expected constant or function-local value");<br class="">-    assert(!V->NameAndIsUsedByMD.getInt() &&<br class="">+    assert(!V->IsUsedByMD &&<br class="">          "Expected this to be the only metadata use");<br class="">-    V->NameAndIsUsedByMD.setInt(true);<br class="">+    V->IsUsedByMD = true;<br class="">   if (auto *C = dyn_cast<Constant>(V))<br class="">     Entry = new ConstantAsMetadata(C);<br class="">   else<br class="">@@ -302,15 +302,15 @@ void ValueAsMetadata::handleRAUW(Value *<br class=""> auto &Store = Context.pImpl->ValuesAsMetadata;<br class=""> auto I = Store.find(From);<br class=""> if (I == Store.end()) {<br class="">-    assert(!From->NameAndIsUsedByMD.getInt() &&<br class="">+    assert(!From->IsUsedByMD &&<br class="">          "Expected From not to be used by metadata");<br class="">   return;<br class=""> }<br class=""><br class=""> // Remove old entry from the map.<br class="">-  assert(From->NameAndIsUsedByMD.getInt() &&<br class="">+  assert(From->IsUsedByMD &&<br class="">        "Expected From to be used by metadata");<br class="">-  From->NameAndIsUsedByMD.setInt(false);<br class="">+  From->IsUsedByMD = false;<br class=""> ValueAsMetadata *MD = I->second;<br class=""> assert(MD && "Expected valid metadata");<br class=""> assert(MD->getValue() == From && "Expected valid mapping");<br class="">@@ -346,9 +346,9 @@ void ValueAsMetadata::handleRAUW(Value *<br class=""> }<br class=""><br class=""> // Update MD in place (and update the map entry).<br class="">-  assert(!To->NameAndIsUsedByMD.getInt() &&<br class="">+  assert(!To->IsUsedByMD &&<br class="">        "Expected this to be the only metadata use");<br class="">-  To->NameAndIsUsedByMD.setInt(true);<br class="">+  To->IsUsedByMD = true;<br class=""> MD->V = To;<br class=""> Entry = MD;<br class="">}<br class=""><br class="">Modified: llvm/trunk/lib/IR/Value.cpp<br class="">URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_IR_Value.cpp-3Frev-3D238791-26r1-3D238790-26r2-3D238791-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=i1GdBdbGABoQnppfBqBhvEUcPJD1HSTVZZuwxgMHZzs&s=OZAGoFTQ7FEQM5RrYwq4wkmiKtw4s9TwRsxlIJRW_ZE&e=" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Value.cpp?rev=238791&r1=238790&r2=238791&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/IR/Value.cpp (original)<br class="">+++ llvm/trunk/lib/IR/Value.cpp Mon Jun  1 17:24:01 2015<br class="">@@ -46,8 +46,9 @@ static inline Type *checkType(Type *Ty)<br class="">}<br class=""><br class="">Value::Value(Type *ty, unsigned scid)<br class="">-    : VTy(checkType(ty)), UseList(nullptr), SubclassID(scid), HasValueHandle(0),<br class="">-      SubclassOptionalData(0), SubclassData(0), NumOperands(0) {<br class="">+    : VTy(checkType(ty)), UseList(nullptr), SubclassID(scid),<br class="">+      HasValueHandle(0), SubclassOptionalData(0), SubclassData(0),<br class="">+      NumOperands(0), IsUsedByMD(false), HasName(false) {<br class=""> // FIXME: Why isn't this in the subclass gunk??<br class=""> // Note, we cannot call isa<CallInst> before the CallInst has been<br class=""> // constructed.<br class="">@@ -157,11 +158,39 @@ static bool getSymTab(Value *V, ValueSym<br class=""> return false;<br class="">}<br class=""><br class="">+ValueName *Value::getValueName() const {<br class="">+  if (!HasName) return nullptr;<br class="">+<br class="">+  LLVMContext &Ctx = getContext();<br class="">+  auto I = Ctx.pImpl->ValueNames.find(this);<br class="">+  assert(I != Ctx.pImpl->ValueNames.end() &&<br class="">+         "No name entry found!");<br class="">+<br class="">+  return I->second;<br class="">+}<br class="">+<br class="">+void Value::setValueName(ValueName *VN) {<br class="">+  LLVMContext &Ctx = getContext();<br class="">+<br class="">+  assert(HasName == Ctx.pImpl->ValueNames.count(this) &&<br class="">+         "HasName bit out of sync!");<br class="">+<br class="">+  if (!VN) {<br class="">+    if (HasName)<br class="">+      Ctx.pImpl->ValueNames.erase(this);<br class="">+    HasName = false;<br class="">+    return;<br class="">+  }<br class="">+<br class="">+  HasName = true;<br class="">+  Ctx.pImpl->ValueNames[this] = VN;<br class="">+}<br class="">+<br class="">StringRef Value::getName() const {<br class=""> // Make sure the empty string is still a C string. For historical reasons,<br class=""> // some clients want to call .data() on the result and expect it to be null<br class=""> // terminated.<br class="">-  if (!getValueName())<br class="">+  if (!hasName())<br class="">   return StringRef("", 0);<br class=""> return getValueName()->getKey();<br class="">}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">llvm-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-commits@cs.uiuc.edu" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">llvm-commits@cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br class=""></body></html>