[PATCH] D22949: Speed up Function::isIntrinsic() by adding a bit to GlobalValue. NFC

Justin Lebar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 28 15:10:32 PST 2016


This revision was automatically updated to reflect the committed changes.
Closed by commit rL290691: Speed up Function::isIntrinsic() by adding a bit to GlobalValue. NFC (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D22949?vs=66062&id=82623#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22949

Files:
  llvm/trunk/include/llvm/IR/Function.h
  llvm/trunk/include/llvm/IR/GlobalValue.h
  llvm/trunk/lib/IR/Function.cpp


Index: llvm/trunk/include/llvm/IR/GlobalValue.h
===================================================================
--- llvm/trunk/include/llvm/IR/GlobalValue.h
+++ llvm/trunk/include/llvm/IR/GlobalValue.h
@@ -80,7 +80,7 @@
         ValueType(Ty), Linkage(Linkage), Visibility(DefaultVisibility),
         UnnamedAddrVal(unsigned(UnnamedAddr::None)),
         DllStorageClass(DefaultStorageClass), ThreadLocal(NotThreadLocal),
-        IntID((Intrinsic::ID)0U), Parent(nullptr) {
+        IntID((Intrinsic::ID)0U), HasLLVMReservedName(false), Parent(nullptr) {
     setName(Name);
   }
 
@@ -137,7 +137,12 @@
   /// Subclasses can use it to store their intrinsic ID, if they have one.
   ///
   /// This is stored here to save space in Function on 64-bit hosts.
-  Intrinsic::ID IntID;
+  Intrinsic::ID IntID : 31;
+
+  /// True if the function's name starts with "llvm.".  This corresponds to the
+  /// value of Function::isIntrinsic(), which may be true even if
+  /// Function::intrinsicID() returns Intrinsic::not_intrinsic.
+  bool HasLLVMReservedName : 1;
 
   unsigned getGlobalValueSubClassData() const {
     return SubClassData;
Index: llvm/trunk/include/llvm/IR/Function.h
===================================================================
--- llvm/trunk/include/llvm/IR/Function.h
+++ llvm/trunk/include/llvm/IR/Function.h
@@ -144,7 +144,11 @@
   /// The particular intrinsic functions which correspond to this value are
   /// defined in llvm/Intrinsics.h.
   Intrinsic::ID getIntrinsicID() const LLVM_READONLY { return IntID; }
-  bool isIntrinsic() const { return getName().startswith("llvm."); }
+
+  /// isIntrinsic - Returns true if the function's name starts with "llvm.".
+  /// It's possible for this function to return true while getIntrinsicID()
+  /// returns Intrinsic::not_intrinsic!
+  bool isIntrinsic() const { return HasLLVMReservedName; }
 
   static Intrinsic::ID lookupIntrinsicID(StringRef Name);
 
Index: llvm/trunk/lib/IR/Function.cpp
===================================================================
--- llvm/trunk/lib/IR/Function.cpp
+++ llvm/trunk/lib/IR/Function.cpp
@@ -270,6 +270,7 @@
   if (ParentModule)
     ParentModule->getFunctionList().push_back(this);
 
+  HasLLVMReservedName = getName().startswith("llvm.");
   // Ensure intrinsics have the right parameter attributes.
   // Note, the IntID field will have been set in Value::setName if this function
   // name is a valid intrinsic ID.
@@ -500,12 +501,14 @@
 }
 
 void Function::recalculateIntrinsicID() {
-  const ValueName *ValName = this->getValueName();
-  if (!ValName || !isIntrinsic()) {
+  StringRef Name = getName();
+  if (!Name.startswith("llvm.")) {
+    HasLLVMReservedName = false;
     IntID = Intrinsic::not_intrinsic;
     return;
   }
-  IntID = lookupIntrinsicID(ValName->getKey());
+  HasLLVMReservedName = true;
+  IntID = lookupIntrinsicID(Name);
 }
 
 /// Returns a stable mangling for the type specified for use in the name


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22949.82623.patch
Type: text/x-patch
Size: 2955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161228/0e43476a/attachment.bin>


More information about the llvm-commits mailing list