diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -1213,6 +1213,22 @@ BumpPtrAllocator &Allocator; private: + /// This method will do fixpoint iteration until fixpoint or the + /// maximum iteration count is reached. + /// + /// If the maximum iteration count is reached, This method will + /// indicate pessimistic fixpoint on attributes that transitively depend + /// on attributes that were scheduled for an update. + void runTillFixpoint(); + + /// Gets called after scheduling, manifests attributes to the LLVM IR. + ChangeStatus manifestAttributes(); + + /// Gets called after attributes have been manifested, cleans up the IR. + /// Deletes dead functions, blocks and instructions. + /// Rewrites function signitures and updates the call graph. + ChangeStatus cleanupIR(); + /// Run `::update` on \p AA and track the dependences queried while doing so. /// Also adjust the state if we know further updates are not necessary. ChangeStatus updateAA(AbstractAttribute &AA); diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -894,7 +894,7 @@ return true; } -ChangeStatus Attributor::run() { +void Attributor::runTillFixpoint() { LLVM_DEBUG(dbgs() << "[Attributor] Identified and initialized " << AllAbstractAttributes.size() << " abstract attributes.\n"); @@ -988,8 +988,6 @@ << IterationCounter << "/" << MaxFixpointIterations << " iterations\n"); - size_t NumFinalAAs = AllAbstractAttributes.size(); - // Reset abstract arguments not settled in a sound fixpoint by now. This // happens when we stopped the fixpoint iteration early. Note that only the // ones marked as "changed" *and* the ones transitively depending on them @@ -1020,6 +1018,19 @@ << " abstract attributes.\n"; }); + if (VerifyMaxFixpointIterations && + IterationCounter != MaxFixpointIterations) { + errs() << "\n[Attributor] Fixpoint iteration done after: " + << IterationCounter << "/" << MaxFixpointIterations + << " iterations\n"; + llvm_unreachable("The fixpoint was not reached with exactly the number of " + "specified iterations!"); + } +} + +ChangeStatus Attributor::manifestAttributes() { + size_t NumFinalAAs = AllAbstractAttributes.size(); + unsigned NumManifested = 0; unsigned NumAtFixpoint = 0; ChangeStatus ManifestChange = ChangeStatus::UNCHANGED; @@ -1072,9 +1083,11 @@ llvm_unreachable("Expected the final number of abstract attributes to " "remain unchanged!"); } + return ManifestChange; +} +ChangeStatus Attributor::cleanupIR() { // Delete stuff at the end to avoid invalid references and a nice order. - { LLVM_DEBUG(dbgs() << "\n[Attributor] Delete at least " << ToBeDeletedFunctions.size() << " functions and " << ToBeDeletedBlocks.size() << " blocks and " @@ -1212,28 +1225,18 @@ FoundDeadFn = true; } } - } // Rewrite the functions as requested during manifest. - ManifestChange = - ManifestChange | rewriteFunctionSignatures(CGModifiedFunctions); + ChangeStatus ManifestChange = + rewriteFunctionSignatures(CGModifiedFunctions); - for (Function *Fn : CGModifiedFunctions) - CGUpdater.reanalyzeFunction(*Fn); + for (Function *Fn : CGModifiedFunctions) + CGUpdater.reanalyzeFunction(*Fn); - for (Function *Fn : ToBeDeletedFunctions) - CGUpdater.removeFunction(*Fn); + for (Function *Fn : ToBeDeletedFunctions) + CGUpdater.removeFunction(*Fn); - NumFnDeleted += ToBeDeletedFunctions.size(); - - if (VerifyMaxFixpointIterations && - IterationCounter != MaxFixpointIterations) { - errs() << "\n[Attributor] Fixpoint iteration done after: " - << IterationCounter << "/" << MaxFixpointIterations - << " iterations\n"; - llvm_unreachable("The fixpoint was not reached with exactly the number of " - "specified iterations!"); - } + NumFnDeleted += ToBeDeletedFunctions.size(); #ifdef EXPENSIVE_CHECKS for (Function *F : Functions) { @@ -1246,6 +1249,13 @@ return ManifestChange; } +ChangeStatus Attributor::run() { + runTillFixpoint(); + ChangeStatus ManifestChange = manifestAttributes(); + ChangeStatus CleanupChange = cleanupIR(); + return ManifestChange | CleanupChange; +} + ChangeStatus Attributor::updateAA(AbstractAttribute &AA) { // Use a new dependence vector for this update. DependenceVector DV;