Skip to content

Commit

Permalink
[Attributor] Guarantee getAAFor not to update AA in the manifestation…
Browse files Browse the repository at this point in the history
… stage

If we query an AA with `Attributor::getAAFor` in `AbstractAttribute::manifest`, the AA may be updated.
This patch makes use of the phase flag in Attributor, and handle `getAAFor` behavior according to the flag.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D86635
  • Loading branch information
okuraofvegetable committed Aug 27, 2020
1 parent 28a7dfa commit c5e6872
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion llvm/include/llvm/Transforms/IPO/Attributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -969,14 +969,15 @@ struct Attributor {
/// attribute. Using this after Attributor started running is restricted to
/// only the Attributor itself. Initial seeding of AAs can be done via this
/// function.
/// NOTE: ForceUpdate is ignored in any stage other than the update stage.
template <typename AAType>
const AAType &getOrCreateAAFor(const IRPosition &IRP,
const AbstractAttribute *QueryingAA = nullptr,
bool TrackDependence = false,
DepClassTy DepClass = DepClassTy::OPTIONAL,
bool ForceUpdate = false) {
if (AAType *AAPtr = lookupAAFor<AAType>(IRP, QueryingAA, TrackDependence)) {
if (ForceUpdate)
if (ForceUpdate && Phase == AttributorPhase::UPDATE)
updateAA(*AAPtr);
return *AAPtr;
}
Expand Down Expand Up @@ -1020,6 +1021,13 @@ struct Attributor {
return AA;
}

// If this is queried in the manifest stage, we force the AA to indicate
// pessimistic fixpoint immediately.
if (Phase == AttributorPhase::MANIFEST) {
AA.getState().indicatePessimisticFixpoint();
return AA;
}

// Allow seeded attributes to declare dependencies.
// Remember the seeding state.
AttributorPhase OldPhase = Phase;
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Transforms/IPO/Attributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,8 @@ ChangeStatus Attributor::run() {

ChangeStatus Attributor::updateAA(AbstractAttribute &AA) {
TimeTraceScope TimeScope(AA.getName() + "::updateAA");
assert(Phase == AttributorPhase::UPDATE &&
"We can update AA only in the update stage!");

// Use a new dependence vector for this update.
DependenceVector DV;
Expand Down

0 comments on commit c5e6872

Please sign in to comment.