[llvm] ade190c - [Attributor] AACallEdges, Add a way to ask nonasm unknown callees
Kuter Dinel via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 14 20:10:53 PDT 2021
Author: Kuter Dinel
Date: 2021-07-15T06:10:42+03:00
New Revision: ade190c5eabfb432fa273b354d371f84a312052b
URL: https://github.com/llvm/llvm-project/commit/ade190c5eabfb432fa273b354d371f84a312052b
DIFF: https://github.com/llvm/llvm-project/commit/ade190c5eabfb432fa273b354d371f84a312052b.diff
LOG: [Attributor] AACallEdges, Add a way to ask nonasm unknown callees
This patch adds a feature to AACallEdges AbstractAttribute that allows
users to ask if there is a unknown callee that isn't a inline assembly.
This feature is needed by some of it's users.
Reviewed By: jdoerfert
Differential Revision: https://reviews.llvm.org/D105992
Added:
Modified:
llvm/include/llvm/Transforms/IPO/Attributor.h
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h
index 7d10464e59a3c..fd5d252aafb35 100644
--- a/llvm/include/llvm/Transforms/IPO/Attributor.h
+++ b/llvm/include/llvm/Transforms/IPO/Attributor.h
@@ -4186,9 +4186,12 @@ struct AACallEdges : public StateWrapper<BooleanState, AbstractAttribute>,
/// Get the optimistic edges.
virtual const SetVector<Function *> &getOptimisticEdges() const = 0;
- /// Is there in this function call with a unknown Callee.
+ /// Is there any call with a unknown callee.
virtual bool hasUnknownCallee() const = 0;
+ /// Is there any call with a unknown callee, excluding any inline asm.
+ virtual bool hasNonAsmUnknownCallee() const = 0;
+
/// Iterator for exploring the call graph.
AACallEdgeIterator optimisticEdgesBegin() const override {
return AACallEdgeIterator(A, getOptimisticEdges().begin());
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 77d11e964b450..83cd1ee4de66b 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -8443,6 +8443,7 @@ struct AACallEdgesFunction : public AACallEdges {
ChangeStatus updateImpl(Attributor &A) override {
ChangeStatus Change = ChangeStatus::UNCHANGED;
bool OldHasUnknownCallee = HasUnknownCallee;
+ bool OldHasUnknownCalleeNonAsm = HasUnknownCalleeNonAsm;
auto AddCalledFunction = [&](Function *Fn) {
if (CalledFunctions.insert(Fn)) {
@@ -8459,6 +8460,7 @@ struct AACallEdgesFunction : public AACallEdges {
} else {
LLVM_DEBUG(dbgs() << "[AACallEdges] Unrecognized value: " << V << "\n");
HasUnknown = true;
+ HasUnknownCalleeNonAsm = true;
}
// Explore all values.
@@ -8467,16 +8469,22 @@ struct AACallEdgesFunction : public AACallEdges {
// Process any value that we might call.
auto ProcessCalledOperand = [&](Value *V, Instruction *Ctx) {
- if (!genericValueTraversal<bool>(A, IRPosition::value(*V), *this,
- HasUnknownCallee, VisitValue, nullptr,
- false))
+ if (!genericValueTraversal<bool>(
+ A, IRPosition::value(*V), *this, HasUnknownCallee, VisitValue,
+ nullptr, false)) {
// If we haven't gone through all values, assume that there are unknown
// callees.
HasUnknownCallee = true;
+ HasUnknownCalleeNonAsm = true;
+ }
};
auto ProcessCallInst = [&](Instruction &Inst) {
CallBase &CB = static_cast<CallBase &>(Inst);
+ if (CB.isInlineAsm()) {
+ HasUnknownCallee = true;
+ return true;
+ }
// Process callee metadata if available.
if (auto *MD = Inst.getMetadata(LLVMContext::MD_callees)) {
@@ -8505,12 +8513,16 @@ struct AACallEdgesFunction : public AACallEdges {
// Visit all callable instructions.
bool UsedAssumedInformation = false;
if (!A.checkForAllCallLikeInstructions(ProcessCallInst, *this,
- UsedAssumedInformation))
+ UsedAssumedInformation)) {
// If we haven't looked at all call like instructions, assume that there
// are unknown callees.
HasUnknownCallee = true;
+ HasUnknownCalleeNonAsm = true;
+ }
+
// Track changes.
- if (OldHasUnknownCallee != HasUnknownCallee)
+ if (OldHasUnknownCallee != HasUnknownCallee ||
+ OldHasUnknownCalleeNonAsm != HasUnknownCalleeNonAsm)
Change = ChangeStatus::CHANGED;
return Change;
@@ -8522,6 +8534,10 @@ struct AACallEdgesFunction : public AACallEdges {
virtual bool hasUnknownCallee() const override { return HasUnknownCallee; }
+ virtual bool hasNonAsmUnknownCallee() const override {
+ return HasUnknownCalleeNonAsm;
+ }
+
const std::string getAsStr() const override {
return "CallEdges[" + std::to_string(HasUnknownCallee) + "," +
std::to_string(CalledFunctions.size()) + "]";
@@ -8532,8 +8548,11 @@ struct AACallEdgesFunction : public AACallEdges {
/// Optimistic set of functions that might be called by this function.
SetVector<Function *> CalledFunctions;
- /// Does this function have a call to a function that we don't know about.
+ /// Is there any call with a unknown callee.
bool HasUnknownCallee = false;
+
+ /// Is there any call with a unknown callee, excluding any inline asm.
+ bool HasUnknownCalleeNonAsm = false;
};
struct AAFunctionReachabilityFunction : public AAFunctionReachability {
More information about the llvm-commits
mailing list