[Utils] Avoid a hash table lookup in salvageDI, NFC
authorVedant Kumar <vsk@apple.com>
Thu, 22 Feb 2018 01:29:41 +0000 (01:29 +0000)
committerVedant Kumar <vsk@apple.com>
Thu, 22 Feb 2018 01:29:41 +0000 (01:29 +0000)
According to the current coverage report salvageDebugInfo() is called
5.12 million times during testing and almost always returns early.

The early return depends on LocalAsMetadata::getIfExists returning null,
which involves a DenseMap lookup in an LLVMContextImpl. We can probably
speed this up by simply checking the IsUsedByMD bit in Value.

llvm-svn: 325738

llvm/lib/Transforms/Utils/Local.cpp

index e75127f..7573fc3 100644 (file)
@@ -1486,6 +1486,11 @@ void llvm::replaceDbgValueForAlloca(AllocaInst *AI, Value *NewAllocaAddress,
 }
 
 void llvm::salvageDebugInfo(Instruction &I) {
+  // This function is hot. An early check to determine whether the instruction
+  // has any metadata to save allows it to return earlier on average.
+  if (!I.isUsedByMetadata())
+    return;
+
   SmallVector<DbgInfoIntrinsic *, 1> DbgUsers;
   findDbgUsers(DbgUsers, &I);
   if (DbgUsers.empty())