[PATCH] D66129: [Attributor] Add WillReturn call site abstract attribute
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 12 22:57:48 PDT 2019
jdoerfert created this revision.
jdoerfert added reviewers: uenoku, sstefan1.
Herald added subscribers: bollu, hiraditya.
Herald added a project: LLVM.
As a preparation to "on-demand" abstract attribute generation we need
implementations for all attributes (as they can be queried and then
created on-demand where we now fail to find one).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66129
Files:
llvm/lib/Transforms/IPO/Attributor.cpp
Index: llvm/lib/Transforms/IPO/Attributor.cpp
===================================================================
--- llvm/lib/Transforms/IPO/Attributor.cpp
+++ llvm/lib/Transforms/IPO/Attributor.cpp
@@ -1350,34 +1350,27 @@
// endless loop
// FIXME: Any cycle is regarded as endless loop for now.
// We have to allow some patterns.
-static bool containsPossiblyEndlessLoop(Function &F) {
- return containsCycle(F);
+static bool containsPossiblyEndlessLoop(Function *F) {
+ return !F || !F->hasExactDefinition() || containsCycle(*F);
}
struct AAWillReturnImpl : public AAWillReturn {
AAWillReturnImpl(const IRPosition &IRP) : AAWillReturn(IRP) {}
- /// See AbstractAttribute::getAsStr()
- const std::string getAsStr() const override {
- return getAssumed() ? "willreturn" : "may-noreturn";
- }
-};
-
-struct AAWillReturnFunction final : AAWillReturnImpl {
- AAWillReturnFunction(const IRPosition &IRP) : AAWillReturnImpl(IRP) {}
-
/// See AbstractAttribute::initialize(...).
void initialize(Attributor &A) override {
- Function &F = *getAnchorScope();
+ if (hasAttr({Attribute::WillReturn})) {
+ indicateOptimisticFixpoint();
+ return;
+ }
+ Function *F = getAssociatedFunction();
if (containsPossiblyEndlessLoop(F))
indicatePessimisticFixpoint();
}
/// See AbstractAttribute::updateImpl(...).
ChangeStatus updateImpl(Attributor &A) override {
- // The map from instruction opcodes to those instructions in the function.
-
auto CheckForWillReturn = [&](Instruction &I) {
ImmutableCallSite ICS(&I);
if (ICS.hasFnAttr(Attribute::WillReturn))
@@ -1402,12 +1395,25 @@
return ChangeStatus::UNCHANGED;
}
+ /// See AbstractAttribute::getAsStr()
+ const std::string getAsStr() const override {
+ return getAssumed() ? "willreturn" : "may-noreturn";
+ }
+};
+
+struct AAWillReturnFunction final : AAWillReturnImpl {
+ AAWillReturnFunction(const IRPosition &IRP) : AAWillReturnImpl(IRP) {}
+
/// See AbstractAttribute::trackStatistics()
- void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(norecurse) }
+ void trackStatistics() const override { STATS_DECLTRACK_FN_ATTR(willreturn) }
};
-/// WillReturn attribute deduction for a call sites.
-using AAWillReturnCallSite = AAWillReturnFunction;
+struct AAWillReturnCallSite final : AAWillReturnImpl {
+ AAWillReturnCallSite(const IRPosition &IRP) : AAWillReturnImpl(IRP) {}
+
+ /// See AbstractAttribute::trackStatistics()
+ void trackStatistics() const override { STATS_DECLTRACK_CS_ATTR(willreturn) }
+};
/// ------------------------ NoAlias Argument Attribute ------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66129.214764.patch
Type: text/x-patch
Size: 2673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190813/75720231/attachment.bin>
More information about the llvm-commits
mailing list