[llvm] df880b7 - [StackProtector] Speed up RequiresStackProtector

Nadav Rotem via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 27 10:14:07 PDT 2020


Author: Nadav Rotem
Date: 2020-07-27T10:07:47-07:00
New Revision: df880b77302d2e12d988e620eba242defdd6d4a7

URL: https://github.com/llvm/llvm-project/commit/df880b77302d2e12d988e620eba242defdd6d4a7
DIFF: https://github.com/llvm/llvm-project/commit/df880b77302d2e12d988e620eba242defdd6d4a7.diff

LOG: [StackProtector] Speed up RequiresStackProtector

Speed up the method RequiresStackProtector by checking the intrinsic
value of the call. The original code calls getName() that returns an
allocating std::string on each check. This change removes about 96072
std::string instances when compiling sqlite3.c; The function was
discovered with a Facebook-internal performance tool.

Differential Revision: https://reviews.llvm.org/D84620

Added: 
    

Modified: 
    llvm/lib/CodeGen/StackProtector.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/StackProtector.cpp b/llvm/lib/CodeGen/StackProtector.cpp
index a343791807e6..e246c2e5f55c 100644
--- a/llvm/lib/CodeGen/StackProtector.cpp
+++ b/llvm/lib/CodeGen/StackProtector.cpp
@@ -251,10 +251,9 @@ bool StackProtector::HasAddressTaken(const Instruction *AI,
 static const CallInst *findStackProtectorIntrinsic(Function &F) {
   for (const BasicBlock &BB : F)
     for (const Instruction &I : BB)
-      if (const CallInst *CI = dyn_cast<CallInst>(&I))
-        if (CI->getCalledFunction() ==
-            Intrinsic::getDeclaration(F.getParent(), Intrinsic::stackprotector))
-          return CI;
+      if (const auto *II = dyn_cast<IntrinsicInst>(&I))
+        if (II->getIntrinsicID() == Intrinsic::stackprotector)
+          return II;
   return nullptr;
 }
 


        


More information about the llvm-commits mailing list