@@ -228,6 +228,7 @@ struct OptimizerAdditionalInfoTy {
228
228
bool PatternOpts;
229
229
bool Postopts;
230
230
bool Prevect;
231
+ bool &DepsChanged;
231
232
};
232
233
233
234
class ScheduleTreeOptimizer final {
@@ -526,6 +527,7 @@ ScheduleTreeOptimizer::optimizeBand(__isl_take isl_schedule_node *NodeArg,
526
527
tryOptimizeMatMulPattern (Node, OAI->TTI , OAI->D );
527
528
if (!PatternOptimizedSchedule.is_null ()) {
528
529
MatMulOpts++;
530
+ OAI->DepsChanged = true ;
529
531
return PatternOptimizedSchedule.release ();
530
532
}
531
533
}
@@ -676,21 +678,21 @@ static void walkScheduleTreeForStatistics(isl::schedule Schedule, int Version) {
676
678
&Version);
677
679
}
678
680
679
- static bool runIslScheduleOptimizer (
681
+ static void runIslScheduleOptimizer (
680
682
Scop &S,
681
683
function_ref<const Dependences &(Dependences::AnalysisLevel)> GetDeps,
682
684
TargetTransformInfo *TTI, OptimizationRemarkEmitter *ORE,
683
- isl::schedule &LastSchedule) {
685
+ isl::schedule &LastSchedule, bool &DepsChanged ) {
684
686
685
687
// Skip SCoPs in case they're already optimised by PPCGCodeGeneration
686
688
if (S.isToBeSkipped ())
687
- return false ;
689
+ return ;
688
690
689
691
// Skip empty SCoPs but still allow code generation as it will delete the
690
692
// loops present but not needed.
691
693
if (S.getSize () == 0 ) {
692
694
S.markAsOptimized ();
693
- return false ;
695
+ return ;
694
696
}
695
697
696
698
ScopsProcessed++;
@@ -706,7 +708,7 @@ static bool runIslScheduleOptimizer(
706
708
&S, Schedule, GetDeps (Dependences::AL_Statement), ORE);
707
709
if (ManuallyTransformed.is_null ()) {
708
710
LLVM_DEBUG (dbgs () << " Error during manual optimization\n " );
709
- return false ;
711
+ return ;
710
712
}
711
713
712
714
if (ManuallyTransformed.get () != Schedule.get ()) {
@@ -724,18 +726,18 @@ static bool runIslScheduleOptimizer(
724
726
// metadata earlier in ScopDetection.
725
727
if (!HasUserTransformation && S.hasDisableHeuristicsHint ()) {
726
728
LLVM_DEBUG (dbgs () << " Heuristic optimizations disabled by metadata\n " );
727
- return false ;
729
+ return ;
728
730
}
729
731
730
732
// Get dependency analysis.
731
733
const Dependences &D = GetDeps (Dependences::AL_Statement);
732
734
if (D.getSharedIslCtx () != S.getSharedIslCtx ()) {
733
735
LLVM_DEBUG (dbgs () << " DependenceInfo for another SCoP/isl_ctx\n " );
734
- return false ;
736
+ return ;
735
737
}
736
738
if (!D.hasValidDependences ()) {
737
739
LLVM_DEBUG (dbgs () << " Dependency information not available\n " );
738
- return false ;
740
+ return ;
739
741
}
740
742
741
743
// Apply ISL's algorithm only if not overriden by the user. Note that
@@ -769,7 +771,7 @@ static bool runIslScheduleOptimizer(
769
771
isl::union_set Domain = S.getDomains ();
770
772
771
773
if (Domain.is_null ())
772
- return false ;
774
+ return ;
773
775
774
776
isl::union_map Validity = D.getDependences (ValidityKinds);
775
777
isl::union_map Proximity = D.getDependences (ProximityKinds);
@@ -847,7 +849,7 @@ static bool runIslScheduleOptimizer(
847
849
// In cases the scheduler is not able to optimize the code, we just do not
848
850
// touch the schedule.
849
851
if (Schedule.is_null ())
850
- return false ;
852
+ return ;
851
853
852
854
if (GreedyFusion) {
853
855
isl::union_map Validity = D.getDependences (
@@ -858,10 +860,12 @@ static bool runIslScheduleOptimizer(
858
860
859
861
// Apply post-rescheduling optimizations (if enabled) and/or prevectorization.
860
862
const OptimizerAdditionalInfoTy OAI = {
861
- TTI, const_cast <Dependences *>(&D),
863
+ TTI,
864
+ const_cast <Dependences *>(&D),
862
865
/* PatternOpts=*/ !HasUserTransformation && PMBasedOpts,
863
866
/* Postopts=*/ !HasUserTransformation && EnablePostopts,
864
- /* Prevect=*/ PollyVectorizerChoice != VECTORIZER_NONE};
867
+ /* Prevect=*/ PollyVectorizerChoice != VECTORIZER_NONE,
868
+ DepsChanged};
865
869
if (OAI.PatternOpts || OAI.Postopts || OAI.Prevect ) {
866
870
Schedule = ScheduleTreeOptimizer::optimizeSchedule (Schedule, &OAI);
867
871
Schedule = hoistExtensionNodes (Schedule);
@@ -872,7 +876,7 @@ static bool runIslScheduleOptimizer(
872
876
// Skip profitability check if user transformation(s) have been applied.
873
877
if (!HasUserTransformation &&
874
878
!ScheduleTreeOptimizer::isProfitableSchedule (S, Schedule))
875
- return false ;
879
+ return ;
876
880
877
881
auto ScopStats = S.getStatistics ();
878
882
ScopsOptimized++;
@@ -885,8 +889,6 @@ static bool runIslScheduleOptimizer(
885
889
886
890
if (OptimizedScops)
887
891
errs () << S;
888
-
889
- return false ;
890
892
}
891
893
892
894
bool IslScheduleOptimizerWrapperPass::runOnScop (Scop &S) {
@@ -904,7 +906,13 @@ bool IslScheduleOptimizerWrapperPass::runOnScop(Scop &S) {
904
906
getAnalysis<OptimizationRemarkEmitterWrapperPass>().getORE ();
905
907
TargetTransformInfo *TTI =
906
908
&getAnalysis<TargetTransformInfoWrapperPass>().getTTI (F);
907
- return runIslScheduleOptimizer (S, getDependences, TTI, &ORE, LastSchedule);
909
+
910
+ bool DepsChanged = false ;
911
+ runIslScheduleOptimizer (S, getDependences, TTI, &ORE, LastSchedule,
912
+ DepsChanged);
913
+ if (DepsChanged)
914
+ getAnalysis<DependenceInfo>().abandonDependences ();
915
+ return false ;
908
916
}
909
917
910
918
static void runScheduleOptimizerPrinter (raw_ostream &OS,
@@ -971,22 +979,18 @@ runIslScheduleOptimizerUsingNPM(Scop &S, ScopAnalysisManager &SAM,
971
979
OptimizationRemarkEmitter ORE (&S.getFunction ());
972
980
TargetTransformInfo *TTI = &SAR.TTI ;
973
981
isl::schedule LastSchedule;
974
- bool Modified = runIslScheduleOptimizer (S, GetDeps, TTI, &ORE, LastSchedule);
982
+ bool DepsChanged = false ;
983
+ runIslScheduleOptimizer (S, GetDeps, TTI, &ORE, LastSchedule, DepsChanged);
984
+ if (DepsChanged)
985
+ Deps.abandonDependences ();
986
+
975
987
if (OS) {
976
988
*OS << " Printing analysis 'Polly - Optimize schedule of SCoP' for region: '"
977
989
<< S.getName () << " ' in function '" << S.getFunction ().getName ()
978
990
<< " ':\n " ;
979
991
runScheduleOptimizerPrinter (*OS, LastSchedule);
980
992
}
981
-
982
- if (!Modified)
983
- return PreservedAnalyses::all ();
984
-
985
- PreservedAnalyses PA;
986
- PA.preserveSet <AllAnalysesOn<Module>>();
987
- PA.preserveSet <AllAnalysesOn<Function>>();
988
- PA.preserveSet <AllAnalysesOn<Loop>>();
989
- return PA;
993
+ return PreservedAnalyses::all ();
990
994
}
991
995
992
996
llvm::PreservedAnalyses
0 commit comments