Add a version of Intrinsic::getName which is more efficient when there are no overloads.
authorPete Cooper <peter_cooper@apple.com>
Thu, 18 Aug 2016 18:30:54 +0000 (18:30 +0000)
committerPete Cooper <peter_cooper@apple.com>
Thu, 18 Aug 2016 18:30:54 +0000 (18:30 +0000)
When running 'opt -O2 verify-uselistorder-nodbg.lto.bc', there are 33m allocations.  8.2m
come from std::string allocations in Intrinsic::getName().  Turns out this method only
returns a std::string because it needs to handle overloads, but that is not the common case.

This adds an overload of getName which just returns a StringRef when there are no overloads
and so saves on the allocations.

llvm-svn: 279113

llvm/include/llvm/IR/Intrinsics.h
llvm/lib/IR/Function.cpp

index 7a87c21..29760b2 100644 (file)
@@ -45,7 +45,10 @@ namespace Intrinsic {
   };
 
   /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
-  std::string getName(ID id, ArrayRef<Type*> Tys = None);
+  StringRef getName(ID id);
+
+  /// Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".
+  std::string getName(ID id, ArrayRef<Type*> Tys);
 
   /// Return the function type for an intrinsic.
   FunctionType *getType(LLVMContext &Context, ID id,
index f1546f1..90f94e6 100644 (file)
@@ -551,6 +551,11 @@ static std::string getMangledTypeStr(Type* Ty) {
   return Result;
 }
 
+StringRef Intrinsic::getName(ID id) {
+  assert(id < num_intrinsics && "Invalid intrinsic ID!");
+  return IntrinsicNameTable[id];
+}
+
 std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
   assert(id < num_intrinsics && "Invalid intrinsic ID!");
   std::string Result(IntrinsicNameTable[id]);