llvm.org GIT mirror llvm / 10b22c8
[PM] Port LoopAccessInfo analysis to new PM It is implemented as a LoopAnalysis pass as discussed and agreed upon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274452 91177308-0d34-0410-b5e6-96231b3b80d8 Xinliang David Li 4 years ago
25 changed file(s) with 75 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
771771 LoopInfo *LI;
772772 };
773773
774 /// \brief LoopAccessInfoAnalysis
775 class LoopAccessInfoAnalysis
776 : public AnalysisInfoMixin {
777 friend AnalysisInfoMixin;
778 static char PassID;
779
780 public:
781 typedef LoopAccessInfo Result;
782 Result run(Loop &, AnalysisManager &);
783 static StringRef name() { return "LoopAccessInfoAnalysis"; }
784 };
785
786 /// \brief Printer pass for the \c BlockFrequencyInfo results.
787 class LoopAccessInfoPrinterPass
788 : public PassInfoMixin {
789 raw_ostream &OS;
790
791 public:
792 explicit LoopAccessInfoPrinterPass(raw_ostream &OS) : OS(OS) {}
793 PreservedAnalyses run(Loop &L, AnalysisManager &AM);
794 };
795
774796 inline Instruction *MemoryDepChecker::Dependence::getSource(
775797 const LoopAccessInfo &LAI) const {
776798 return LAI.getDepChecker().getMemoryInstructions()[Source];
1313
1414 #include "llvm/Analysis/LoopAccessAnalysis.h"
1515 #include "llvm/Analysis/LoopInfo.h"
16 #include "llvm/Analysis/LoopPassManager.h"
1617 #include "llvm/Analysis/ScalarEvolutionExpander.h"
1718 #include "llvm/Analysis/TargetLibraryInfo.h"
1819 #include "llvm/Analysis/ValueTracking.h"
2021 #include "llvm/IR/DiagnosticInfo.h"
2122 #include "llvm/IR/Dominators.h"
2223 #include "llvm/IR/IRBuilder.h"
24 #include "llvm/IR/PassManager.h"
2325 #include "llvm/Support/Debug.h"
2426 #include "llvm/Support/raw_ostream.h"
2527 using namespace llvm;
20212023 INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
20222024 INITIALIZE_PASS_END(LoopAccessAnalysis, LAA_NAME, laa_name, false, true)
20232025
2026 char LoopAccessInfoAnalysis::PassID;
2027
2028 LoopAccessInfo LoopAccessInfoAnalysis::run(Loop &L, AnalysisManager &AM) {
2029 // FIXME: ugly const cast
2030 AnalysisManager &FAM = const_cast(
2031 AM.getResult(L).getManager());
2032 Function &F = *L.getHeader()->getParent();
2033 auto *SE = &FAM.getResult(F);
2034 auto *TLI = FAM.getCachedResult(F);
2035 auto *AA = &FAM.getResult(F);
2036 auto *DT = &FAM.getResult(F);
2037 auto *LI = &FAM.getResult(F);
2038 const DataLayout &DL = F.getParent()->getDataLayout();
2039 return LoopAccessInfo(&L, SE, DL, TLI, AA, DT, LI);
2040 }
2041
2042 PreservedAnalyses LoopAccessInfoPrinterPass::run(Loop &L,
2043 AnalysisManager &AM) {
2044 Function &F = *L.getHeader()->getParent();
2045 auto &LAI = AM.getResult(L);
2046 OS << "Loop access info in function '" << F.getName() << "':\n";
2047 OS.indent(2) << L.getHeader()->getName() << ":\n";
2048 LAI.print(OS, 4);
2049 return PreservedAnalyses::all();
2050 }
2051
20242052 namespace llvm {
20252053 Pass *createLAAPass() {
20262054 return new LoopAccessAnalysis();
3232 #include "llvm/Analysis/GlobalsModRef.h"
3333 #include "llvm/Analysis/LazyCallGraph.h"
3434 #include "llvm/Analysis/LazyValueInfo.h"
35 #include "llvm/Analysis/LoopAccessAnalysis.h"
3536 #include "llvm/Analysis/LoopInfo.h"
3637 #include "llvm/Analysis/MemoryDependenceAnalysis.h"
3738 #include "llvm/Analysis/PostDominators.h"
170170 #define LOOP_ANALYSIS(NAME, CREATE_PASS)
171171 #endif
172172 LOOP_ANALYSIS("no-op-loop", NoOpLoopAnalysis())
173 LOOP_ANALYSIS("access-info", LoopAccessInfoAnalysis())
173174 #undef LOOP_ANALYSIS
174175
175176 #ifndef LOOP_PASS
181182 LOOP_PASS("print", PrintLoopPass(dbgs()))
182183 LOOP_PASS("simplify-cfg", LoopSimplifyCFGPass())
183184 LOOP_PASS("indvars", IndVarSimplifyPass())
185 LOOP_PASS("print-access-info", LoopAccessInfoPrinterPass(dbgs()))
184186 #undef LOOP_PASS
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; In this loop just because we access A through different types (int, float)
34 ; we still have a dependence cycle:
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; for (unsigned i = 0; i < 100; i++) {
34 ; A[i+8] = B[i] + 2;
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Check that loop-indepedent forward dependences are discovered properly.
34 ;
0 ; RUN: opt < %s -store-to-load-forwarding-conflict-detection=false -loop-accesses -analyze | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -store-to-load-forwarding-conflict-detection=false -disable-output < %s 2>&1 | FileCheck %s
12
23 ; This test checks that we prove the strided accesses to be independent before
34 ; concluding that there is a forward dependence.
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Handle memchecks involving loop-invariant addresses:
34 ;
0 ; RUN: opt -loop-accesses -analyze -S < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; This is the test case from PR26314.
34 ; When we were retrying dependence checking with memchecks only,
0 ; RUN: opt -basicaa -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='require,loop(print-access-info)' -aa-pipeline='basic-aa' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; For this loop:
34 ; for (int i = 0; i < n; i++)
0 ; RUN: opt -loop-accesses -analyze %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Test that the loop accesses are proven safe in this case.
34 ; The analyzer uses to be confused by the "diamond" because GetUnderlyingObjects
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
34 target triple = "aarch64--linux-gnueabi"
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
34
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; We give up analyzing the dependences in this loop due to non-constant
34 ; distance between A[i+offset] and A[i] and add memchecks to prove
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; The runtime memory check code and the access grouping
34 ; algorithm both assume that the start and end values
0 ; RUN: opt -basicaa -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='require,loop(print-access-info)' -aa-pipeline='basic-aa' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; If the arrays don't alias this loop is safe with no memchecks:
34 ; for (i = 0; i < n; i++)
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Analyze this loop:
34 ; for (i = 0; i < n; i++)
0 ; RUN: opt < %s -loop-accesses -analyze | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Test to confirm LAA will not find store to invariant address.
34 ; Inner loop has no store to invariant address.
0 ; RUN: opt < %s -loop-accesses -analyze | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Test to confirm LAA will find store to invariant address.
34 ; Inner loop has a store to invariant address.
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
34
383384 ; return sum;
384385 ; }
385386
386 ; CHECK: for function 'vectorizable_unscaled_Write_Read':
387 ; CHECK: function 'vectorizable_unscaled_Write_Read':
387388 ; CHECK-NEXT: for.body:
388389 ; CHECK-NEXT: Memory dependences are safe
389390 ; CHECK-NEXT: Dependences:
0 ; RUN: opt -basicaa -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; In:
34 ;
0 ; RUN: opt -basicaa -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; This loop:
34 ;
0 ; RUN: opt -loop-accesses -analyze < %s | FileCheck %s
1 ; RUN: opt -passes='loop(print-access-info)' -disable-output < %s 2>&1 | FileCheck %s
12
23 ; Analyze this loop:
34 ; for (i = 0; i < n; i++)
0 ; RUN: opt -basicaa -loop-accesses -analyze < %s | FileCheck %s -check-prefix=LAA
1 ; RUN: opt -passes='require,loop(print-access-info)' -aa-pipeline='basic-aa' -disable-output < %s 2>&1 | FileCheck %s --check-prefix=LAA
12 ; RUN: opt -loop-versioning -S < %s | FileCheck %s -check-prefix=LV
23
34 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"