llvm.org GIT mirror llvm / 754b83a
[LPM] Conclude my immediate work by making the LoopVectorizer a FunctionPass. With this change the loop vectorizer no longer is a loop pass and can readily depend on function analyses. In particular, with this change we no longer have to form a loop pass manager to run the loop vectorizer which simplifies the entire pass management of LLVM. The next step here is to teach the loop vectorizer to leverage profile information through the profile information providing analysis passes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200074 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 6 years ago
1 changed file(s) with 37 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
929929 }
930930 };
931931
932 static void addInnerLoop(Loop *L, SmallVectorImpl &V) {
933 if (L->empty())
934 return V.push_back(L);
935
936 for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I)
937 addInnerLoop(*I, V);
938 }
939
932940 /// The LoopVectorize Pass.
933 struct LoopVectorize : public LoopPass {
941 struct LoopVectorize : public FunctionPass {
934942 /// Pass identification, replacement for typeid
935943 static char ID;
936944
937945 explicit LoopVectorize(bool NoUnrolling = false, bool AlwaysVectorize = true)
938 : LoopPass(ID),
946 : FunctionPass(ID),
939947 DisableUnrolling(NoUnrolling),
940948 AlwaysVectorize(AlwaysVectorize) {
941949 initializeLoopVectorizePass(*PassRegistry::getPassRegistry());
950958 bool DisableUnrolling;
951959 bool AlwaysVectorize;
952960
953 virtual bool runOnLoop(Loop *L, LPPassManager &LPM) {
954 // We only vectorize innermost loops.
955 if (!L->empty())
956 return false;
957
961 virtual bool runOnFunction(Function &F) {
958962 SE = &getAnalysis();
959963 DL = getAnalysisIfAvailable();
960964 LI = &getAnalysis();
970974 if (DL == NULL) {
971975 DEBUG(dbgs() << "LV: Not vectorizing: Missing data layout\n");
972976 return false;
977 }
978
979 // Build up a worklist of inner-loops to vectorize. This is necessary as
980 // the act of vectorizing or partially unrolling a loop creates new loops
981 // and can invalidate iterators across the loops.
982 SmallVector Worklist;
983
984 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I)
985 addInnerLoop(*I, Worklist);
986
987 // Now walk the identified inner loops.
988 bool Changed = false;
989 while (!Worklist.empty())
990 Changed |= processLoop(Worklist.pop_back_val());
991
992 // Process each loop nest in the function.
993 return Changed;
994 }
995
996 bool processLoop(Loop *L) {
997 // We only handle inner loops, so if there are children just recurse.
998 if (!L->empty()) {
999 bool Changed = false;
1000 for (Loop::iterator I = L->begin(), E = L->begin(); I != E; ++I)
1001 Changed |= processLoop(*I);
1002 return Changed;
9731003 }
9741004
9751005 DEBUG(dbgs() << "LV: Checking a loop in \"" <<
10511081 }
10521082
10531083 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
1054 LoopPass::getAnalysisUsage(AU);
10551084 AU.addRequiredID(LoopSimplifyID);
10561085 AU.addRequiredID(LCSSAID);
10571086 AU.addRequired();