mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[NPM] port -unify-loop-exits to NPM
Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D89774
This commit is contained in:
parent
07346b8487
commit
3a711be325
@ -429,7 +429,7 @@ void initializeTwoAddressInstructionPassPass(PassRegistry&);
|
||||
void initializeTypeBasedAAWrapperPassPass(PassRegistry&);
|
||||
void initializeTypePromotionPass(PassRegistry&);
|
||||
void initializeUnifyFunctionExitNodesLegacyPassPass(PassRegistry &);
|
||||
void initializeUnifyLoopExitsPass(PassRegistry &);
|
||||
void initializeUnifyLoopExitsLegacyPassPass(PassRegistry &);
|
||||
void initializeUnpackMachineBundlesPass(PassRegistry&);
|
||||
void initializeUnreachableBlockElimLegacyPassPass(PassRegistry&);
|
||||
void initializeUnreachableMachineBlockElimPass(PassRegistry&);
|
||||
|
22
include/llvm/Transforms/Utils/UnifyLoopExits.h
Normal file
22
include/llvm/Transforms/Utils/UnifyLoopExits.h
Normal file
@ -0,0 +1,22 @@
|
||||
//===- UnifyLoopExits.h - Redirect exiting edges to one block -*- C++ -*-===//
|
||||
//
|
||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
||||
// See https://llvm.org/LICENSE.txt for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_TRANSFORMS_UTILS_UNIFYLOOPEXITS_H
|
||||
#define LLVM_TRANSFORMS_UTILS_UNIFYLOOPEXITS_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class UnifyLoopExitsPass : public PassInfoMixin<UnifyLoopExitsPass> {
|
||||
public:
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_TRANSFORMS_UTILS_UNIFYLOOPEXITS_H
|
@ -213,6 +213,7 @@
|
||||
#include "llvm/Transforms/Utils/StripNonLineTableDebugInfo.h"
|
||||
#include "llvm/Transforms/Utils/SymbolRewriter.h"
|
||||
#include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h"
|
||||
#include "llvm/Transforms/Utils/UnifyLoopExits.h"
|
||||
#include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
|
||||
#include "llvm/Transforms/Vectorize/LoopVectorize.h"
|
||||
#include "llvm/Transforms/Vectorize/SLPVectorizer.h"
|
||||
|
@ -286,6 +286,7 @@ FUNCTION_PASS("spec-phis", SpeculateAroundPHIsPass())
|
||||
FUNCTION_PASS("sroa", SROA())
|
||||
FUNCTION_PASS("strip-gc-relocates", StripGCRelocates())
|
||||
FUNCTION_PASS("tailcallelim", TailCallElimPass())
|
||||
FUNCTION_PASS("unify-loop-exits", UnifyLoopExitsPass())
|
||||
FUNCTION_PASS("vector-combine", VectorCombinePass())
|
||||
FUNCTION_PASS("verify", VerifierPass())
|
||||
FUNCTION_PASS("verify<domtree>", DominatorTreeVerifierPass())
|
||||
|
@ -16,10 +16,12 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Transforms/Utils/UnifyLoopExits.h"
|
||||
#include "llvm/ADT/MapVector.h"
|
||||
#include "llvm/Analysis/LoopInfo.h"
|
||||
#include "llvm/IR/Dominators.h"
|
||||
#include "llvm/InitializePasses.h"
|
||||
#include "llvm/Transforms/Scalar/LoopPassManager.h"
|
||||
#include "llvm/Transforms/Utils.h"
|
||||
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
||||
|
||||
@ -28,10 +30,10 @@
|
||||
using namespace llvm;
|
||||
|
||||
namespace {
|
||||
struct UnifyLoopExits : public FunctionPass {
|
||||
struct UnifyLoopExitsLegacyPass : public FunctionPass {
|
||||
static char ID;
|
||||
UnifyLoopExits() : FunctionPass(ID) {
|
||||
initializeUnifyLoopExitsPass(*PassRegistry::getPassRegistry());
|
||||
UnifyLoopExitsLegacyPass() : FunctionPass(ID) {
|
||||
initializeUnifyLoopExitsLegacyPassPass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
@ -47,17 +49,19 @@ struct UnifyLoopExits : public FunctionPass {
|
||||
};
|
||||
} // namespace
|
||||
|
||||
char UnifyLoopExits::ID = 0;
|
||||
char UnifyLoopExitsLegacyPass::ID = 0;
|
||||
|
||||
FunctionPass *llvm::createUnifyLoopExitsPass() { return new UnifyLoopExits(); }
|
||||
FunctionPass *llvm::createUnifyLoopExitsPass() {
|
||||
return new UnifyLoopExitsLegacyPass();
|
||||
}
|
||||
|
||||
INITIALIZE_PASS_BEGIN(UnifyLoopExits, "unify-loop-exits",
|
||||
INITIALIZE_PASS_BEGIN(UnifyLoopExitsLegacyPass, "unify-loop-exits",
|
||||
"Fixup each natural loop to have a single exit block",
|
||||
false /* Only looks at CFG */, false /* Analysis Pass */)
|
||||
INITIALIZE_PASS_DEPENDENCY(LowerSwitchLegacyPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
|
||||
INITIALIZE_PASS_END(UnifyLoopExits, "unify-loop-exits",
|
||||
INITIALIZE_PASS_END(UnifyLoopExitsLegacyPass, "unify-loop-exits",
|
||||
"Fixup each natural loop to have a single exit block",
|
||||
false /* Only looks at CFG */, false /* Analysis Pass */)
|
||||
|
||||
@ -204,11 +208,7 @@ static bool unifyLoopExits(DominatorTree &DT, LoopInfo &LI, Loop *L) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool UnifyLoopExits::runOnFunction(Function &F) {
|
||||
LLVM_DEBUG(dbgs() << "===== Unifying loop exits in function " << F.getName()
|
||||
<< "\n");
|
||||
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
static bool runImpl(LoopInfo &LI, DominatorTree &DT) {
|
||||
|
||||
bool Changed = false;
|
||||
auto Loops = LI.getLoopsInPreorder();
|
||||
@ -219,3 +219,28 @@ bool UnifyLoopExits::runOnFunction(Function &F) {
|
||||
}
|
||||
return Changed;
|
||||
}
|
||||
|
||||
bool UnifyLoopExitsLegacyPass::runOnFunction(Function &F) {
|
||||
LLVM_DEBUG(dbgs() << "===== Unifying loop exits in function " << F.getName()
|
||||
<< "\n");
|
||||
auto &LI = getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
|
||||
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
|
||||
return runImpl(LI, DT);
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
|
||||
PreservedAnalyses UnifyLoopExitsPass::run(Function &F,
|
||||
FunctionAnalysisManager &AM) {
|
||||
auto &LI = AM.getResult<LoopAnalysis>(F);
|
||||
auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
|
||||
|
||||
if (!runImpl(LI, DT))
|
||||
return PreservedAnalyses::all();
|
||||
PreservedAnalyses PA;
|
||||
PA.preserve<LoopAnalysis>();
|
||||
PA.preserve<DominatorTreeAnalysis>();
|
||||
return PA;
|
||||
}
|
||||
} // namespace llvm
|
||||
|
@ -44,7 +44,7 @@ void llvm::initializeTransformUtils(PassRegistry &Registry) {
|
||||
initializePredicateInfoPrinterLegacyPassPass(Registry);
|
||||
initializeInjectTLIMappingsLegacyPass(Registry);
|
||||
initializeFixIrreduciblePass(Registry);
|
||||
initializeUnifyLoopExitsPass(Registry);
|
||||
initializeUnifyLoopExitsLegacyPassPass(Registry);
|
||||
initializeUniqueInternalLinkageNamesLegacyPassPass(Registry);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -unify-loop-exits -enable-new-pm=0 -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='lowerswitch,unify-loop-exits' -S | FileCheck %s
|
||||
|
||||
define void @loop_1(i1 %PredEntry, i1 %PredB, i1 %PredC, i1 %PredD) {
|
||||
; CHECK-LABEL: @loop_1(
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -unify-loop-exits -enable-new-pm=0 -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='lowerswitch,unify-loop-exits' -S | FileCheck %s
|
||||
|
||||
define void @nested(i1 %PredB3, i1 %PredB4, i1 %PredA4, i1 %PredA3, i32 %X, i32 %Y, i32 %Z) {
|
||||
; CHECK-LABEL: @nested(
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -unify-loop-exits -enable-new-pm=0 -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='lowerswitch,unify-loop-exits' -S | FileCheck %s
|
||||
|
||||
; Loop consists of A and B:
|
||||
; - A is the header
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -unify-loop-exits -enable-new-pm=0 -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='lowerswitch,unify-loop-exits' -S | FileCheck %s
|
||||
|
||||
define void @loop_1(i32 %Value, i1 %PredEntry, i1 %PredD) {
|
||||
; CHECK-LABEL: @loop_1(
|
||||
|
Loading…
x
Reference in New Issue
Block a user