Skip to content

Commit

Permalink
[Attributor] Allow lookupAAFor to return null on invalid state
Browse files Browse the repository at this point in the history
This patch adds an option to `lookupAAFor` that allows it to return a
nullptr if the state of the looked up attribute is invalid. This is so
future passes can use this to query other attributes with the guarantee
that they are valid.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D103556
  • Loading branch information
jhuber6 committed Jun 4, 2021
1 parent 56dd158 commit 8bb7132
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions llvm/include/llvm/Transforms/IPO/Attributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,8 @@ struct Attributor {
if (!shouldPropagateCallBaseContext(IRP))
IRP = IRP.stripCallBaseContext();

if (AAType *AAPtr = lookupAAFor<AAType>(IRP, QueryingAA, DepClass)) {
if (AAType *AAPtr = lookupAAFor<AAType>(IRP, QueryingAA, DepClass,
/* AllowInvalidState */ true)) {
if (ForceUpdate && Phase == AttributorPhase::UPDATE)
updateAA(*AAPtr);
return *AAPtr;
Expand Down Expand Up @@ -1218,12 +1219,13 @@ struct Attributor {
DepClassTy::NONE);
}

/// Return the attribute of \p AAType for \p IRP if existing. This also allows
/// non-AA users lookup.
/// Return the attribute of \p AAType for \p IRP if existing and valid. This
/// also allows non-AA users lookup.
template <typename AAType>
AAType *lookupAAFor(const IRPosition &IRP,
const AbstractAttribute *QueryingAA = nullptr,
DepClassTy DepClass = DepClassTy::OPTIONAL) {
DepClassTy DepClass = DepClassTy::OPTIONAL,
bool AllowInvalidState = false) {
static_assert(std::is_base_of<AbstractAttribute, AAType>::value,
"Cannot query an attribute with a type not derived from "
"'AbstractAttribute'!");
Expand All @@ -1240,6 +1242,10 @@ struct Attributor {
AA->getState().isValidState())
recordDependence(*AA, const_cast<AbstractAttribute &>(*QueryingAA),
DepClass);

// Return nullptr if this attribute has an invalid state.
if (!AllowInvalidState && !AA->getState().isValidState())
return nullptr;
return AA;
}

Expand Down

0 comments on commit 8bb7132

Please sign in to comment.