[Attributor][NFCI] Avoid unnecessary work except for testing
Trying to deduce information for declarations and calls sites of
declarations is not useful in practice but only for testing. Add a flag
that disables this by default but also enable it in the tests.
The misc.ll test will verify the flag "works" as expected.
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 6f0a4a8..ddd2ff0 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -120,6 +120,10 @@
cl::desc("Disable the attributor inter-procedural deduction pass."),
cl::init(true));
+static cl::opt<bool> AnnotateDeclarationCallSites(
+ "attributor-annotate-decl-cs", cl::Hidden,
+ cl::desc("Annoate call sites of function declarations."), cl::init(false));
+
static cl::opt<bool> ManifestInternal(
"attributor-manifest-internal", cl::Hidden,
cl::desc("Manifest Attributor internal string attributes."),
@@ -5074,6 +5078,8 @@
void Attributor::identifyDefaultAbstractAttributes(Function &F) {
if (!VisitedFunctions.insert(&F).second)
return;
+ if (F.isDeclaration())
+ return;
IRPosition FPos = IRPosition::function(F);
@@ -5170,7 +5176,12 @@
auto CallSitePred = [&](Instruction &I) -> bool {
CallSite CS(&I);
if (Function *Callee = CS.getCalledFunction()) {
- if (!Callee->getReturnType()->isVoidTy()) {
+ // Skip declerations except if annotations on their call sites were
+ // explicitly requested.
+ if (!AnnotateDeclarationCallSites && Callee->isDeclaration())
+ return true;
+
+ if (!Callee->getReturnType()->isVoidTy() && !CS->use_empty()) {
IRPosition CSRetPos = IRPosition::callsite_returned(CS);
// Call site return values might be dead.