Skip to content

Commit 23f41f1

Browse files
committed
[Attributor] Use fine-grained liveness in all helpers
We used coarse-grained liveness before, thus we looked if the instruction was executed, but we did not use fine-grained liveness, hence if the instruction was needed or could be deleted even if the surrounding ones are live. This patches introduces this level of liveness checks together with other liveness queries, e.g., for uses. For more control we enforce that all liveness queries go through the Attributor. Test have been adjusted to reflect the changes or augmented to prevent deletion of the parts we want to check. Reviewed By: sstefan1 Differential Revision: https://reviews.llvm.org/D73313
1 parent b2c7600 commit 23f41f1

35 files changed

+530
-245
lines changed

llvm/include/llvm/Transforms/IPO/Attributor.h

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,14 +852,41 @@ struct Attributor {
852852
/// Return true if \p AA (or its context instruction) is assumed dead.
853853
///
854854
/// If \p LivenessAA is not provided it is queried.
855-
bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA);
855+
bool isAssumedDead(const AbstractAttribute &AA, const AAIsDead *LivenessAA,
856+
bool CheckBBLivenessOnly = false,
857+
DepClassTy DepClass = DepClassTy::OPTIONAL);
858+
859+
/// Return true if \p I is assumed dead.
860+
///
861+
/// If \p LivenessAA is not provided it is queried.
862+
bool isAssumedDead(const Instruction &I, const AbstractAttribute *QueryingAA,
863+
const AAIsDead *LivenessAA,
864+
bool CheckBBLivenessOnly = false,
865+
DepClassTy DepClass = DepClassTy::OPTIONAL);
866+
867+
/// Return true if \p U is assumed dead.
868+
///
869+
/// If \p FnLivenessAA is not provided it is queried.
870+
bool isAssumedDead(const Use &U, const AbstractAttribute *QueryingAA,
871+
const AAIsDead *FnLivenessAA,
872+
bool CheckBBLivenessOnly = false,
873+
DepClassTy DepClass = DepClassTy::OPTIONAL);
874+
875+
/// Return true if \p IRP is assumed dead.
876+
///
877+
/// If \p FnLivenessAA is not provided it is queried.
878+
bool isAssumedDead(const IRPosition &IRP, const AbstractAttribute *QueryingAA,
879+
const AAIsDead *FnLivenessAA,
880+
bool CheckBBLivenessOnly = false,
881+
DepClassTy DepClass = DepClassTy::OPTIONAL);
856882

857883
/// Check \p Pred on all (transitive) uses of \p V.
858884
///
859885
/// This method will evaluate \p Pred on all (transitive) uses of the
860886
/// associated value and return true if \p Pred holds every time.
861887
bool checkForAllUses(const function_ref<bool(const Use &, bool &)> &Pred,
862-
const AbstractAttribute &QueryingAA, const Value &V);
888+
const AbstractAttribute &QueryingAA, const Value &V,
889+
DepClassTy LivenessDepClass = DepClassTy::OPTIONAL);
863890

864891
/// Helper struct used in the communication between an abstract attribute (AA)
865892
/// that wants to change the signature of a function and the Attributor which
@@ -997,7 +1024,8 @@ struct Attributor {
9971024
/// present in \p Opcode and return true if \p Pred holds on all of them.
9981025
bool checkForAllInstructions(const function_ref<bool(Instruction &)> &Pred,
9991026
const AbstractAttribute &QueryingAA,
1000-
const ArrayRef<unsigned> &Opcodes);
1027+
const ArrayRef<unsigned> &Opcodes,
1028+
bool CheckBBLivenessOnly = false);
10011029

10021030
/// Check \p Pred on all call-like instructions (=CallBased derived).
10031031
///
@@ -2109,6 +2137,10 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute>,
21092137
public IRPosition {
21102138
AAIsDead(const IRPosition &IRP) : IRPosition(IRP) {}
21112139

2140+
protected:
2141+
/// The query functions are protected such that other attributes need to go
2142+
/// through the Attributor interfaces: `Attributor::isAssumedDead(...)`
2143+
21122144
/// Returns true if the underlying value is assumed dead.
21132145
virtual bool isAssumedDead() const = 0;
21142146

@@ -2141,6 +2173,7 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute>,
21412173
return false;
21422174
}
21432175

2176+
public:
21442177
/// Return an IR position, see struct IRPosition.
21452178
const IRPosition &getIRPosition() const override { return *this; }
21462179

@@ -2149,6 +2182,8 @@ struct AAIsDead : public StateWrapper<BooleanState, AbstractAttribute>,
21492182

21502183
/// Unique ID (due to the unique address)
21512184
static const char ID;
2185+
2186+
friend struct Attributor;
21522187
};
21532188

21542189
/// State for dereferenceable attribute

0 commit comments

Comments
 (0)