mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
[NPM] Port -slsr to NPM
`-separate-const-offset-from-gep` has not yet be ported, so some tests are not updated. Reviewed By: aeubanks Differential Revision: https://reviews.llvm.org/D90149
This commit is contained in:
parent
8696d90356
commit
6b4f0b5bdf
@ -409,7 +409,7 @@ void initializeStackProtectorPass(PassRegistry&);
|
||||
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &);
|
||||
void initializeStackSafetyInfoWrapperPassPass(PassRegistry &);
|
||||
void initializeStackSlotColoringPass(PassRegistry&);
|
||||
void initializeStraightLineStrengthReducePass(PassRegistry&);
|
||||
void initializeStraightLineStrengthReduceLegacyPassPass(PassRegistry &);
|
||||
void initializeStripDeadDebugInfoPass(PassRegistry&);
|
||||
void initializeStripDeadPrototypesLegacyPassPass(PassRegistry&);
|
||||
void initializeStripDebugDeclarePass(PassRegistry&);
|
||||
|
24
include/llvm/Transforms/Scalar/StraightLineStrengthReduce.h
Normal file
24
include/llvm/Transforms/Scalar/StraightLineStrengthReduce.h
Normal file
@ -0,0 +1,24 @@
|
||||
//===- StraightLineStrengthReduce.h - -----------------------------------===//
|
||||
//
|
||||
// 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_SCALAR_STRAIGHTLINESTRENGTHREDUCE_H
|
||||
#define LLVM_TRANSFORMS_SCALAR_STRAIGHTLINESTRENGTHREDUCE_H
|
||||
|
||||
#include "llvm/IR/PassManager.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class StraightLineStrengthReducePass
|
||||
: public PassInfoMixin<StraightLineStrengthReducePass> {
|
||||
public:
|
||||
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
|
||||
};
|
||||
|
||||
} // namespace llvm
|
||||
|
||||
#endif // LLVM_TRANSFORMS_SCALAR_STRAIGHTLINESTRENGTHREDUCE_H
|
@ -192,6 +192,7 @@
|
||||
#include "llvm/Transforms/Scalar/Sink.h"
|
||||
#include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h"
|
||||
#include "llvm/Transforms/Scalar/SpeculativeExecution.h"
|
||||
#include "llvm/Transforms/Scalar/StraightLineStrengthReduce.h"
|
||||
#include "llvm/Transforms/Scalar/StructurizeCFG.h"
|
||||
#include "llvm/Transforms/Scalar/TailRecursionElimination.h"
|
||||
#include "llvm/Transforms/Scalar/WarnMissedTransforms.h"
|
||||
|
@ -283,6 +283,7 @@ FUNCTION_PASS("sccp", SCCPPass())
|
||||
FUNCTION_PASS("simplifycfg", SimplifyCFGPass())
|
||||
FUNCTION_PASS("sink", SinkingPass())
|
||||
FUNCTION_PASS("slp-vectorizer", SLPVectorizerPass())
|
||||
FUNCTION_PASS("slsr", StraightLineStrengthReducePass())
|
||||
FUNCTION_PASS("speculative-execution", SpeculativeExecutionPass())
|
||||
FUNCTION_PASS("spec-phis", SpeculateAroundPHIsPass())
|
||||
FUNCTION_PASS("sroa", SROA())
|
||||
|
@ -103,7 +103,7 @@ void llvm::initializeScalarOpts(PassRegistry &Registry) {
|
||||
initializeTailCallElimPass(Registry);
|
||||
initializeSeparateConstOffsetFromGEPPass(Registry);
|
||||
initializeSpeculativeExecutionLegacyPassPass(Registry);
|
||||
initializeStraightLineStrengthReducePass(Registry);
|
||||
initializeStraightLineStrengthReduceLegacyPassPass(Registry);
|
||||
initializePlaceBackedgeSafepointsImplPass(Registry);
|
||||
initializePlaceSafepointsPass(Registry);
|
||||
initializeFloat2IntLegacyPassPass(Registry);
|
||||
|
@ -55,6 +55,7 @@
|
||||
// - When (i' - i) is constant but i and i' are not, we could still perform
|
||||
// SLSR.
|
||||
|
||||
#include "llvm/Transforms/Scalar/StraightLineStrengthReduce.h"
|
||||
#include "llvm/ADT/APInt.h"
|
||||
#include "llvm/ADT/DepthFirstIterator.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
@ -95,8 +96,39 @@ static const unsigned UnknownAddressSpace =
|
||||
|
||||
namespace {
|
||||
|
||||
class StraightLineStrengthReduce : public FunctionPass {
|
||||
class StraightLineStrengthReduceLegacyPass : public FunctionPass {
|
||||
const DataLayout *DL = nullptr;
|
||||
|
||||
public:
|
||||
static char ID;
|
||||
|
||||
StraightLineStrengthReduceLegacyPass() : FunctionPass(ID) {
|
||||
initializeStraightLineStrengthReduceLegacyPassPass(
|
||||
*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<ScalarEvolutionWrapperPass>();
|
||||
AU.addRequired<TargetTransformInfoWrapperPass>();
|
||||
// We do not modify the shape of the CFG.
|
||||
AU.setPreservesCFG();
|
||||
}
|
||||
|
||||
bool doInitialization(Module &M) override {
|
||||
DL = &M.getDataLayout();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override;
|
||||
};
|
||||
|
||||
class StraightLineStrengthReduce {
|
||||
public:
|
||||
StraightLineStrengthReduce(const DataLayout *DL, DominatorTree *DT,
|
||||
ScalarEvolution *SE, TargetTransformInfo *TTI)
|
||||
: DL(DL), DT(DT), SE(SE), TTI(TTI) {}
|
||||
|
||||
// SLSR candidate. Such a candidate must be in one of the forms described in
|
||||
// the header comments.
|
||||
struct Candidate {
|
||||
@ -144,26 +176,7 @@ public:
|
||||
Candidate *Basis = nullptr;
|
||||
};
|
||||
|
||||
static char ID;
|
||||
|
||||
StraightLineStrengthReduce() : FunctionPass(ID) {
|
||||
initializeStraightLineStrengthReducePass(*PassRegistry::getPassRegistry());
|
||||
}
|
||||
|
||||
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
||||
AU.addRequired<DominatorTreeWrapperPass>();
|
||||
AU.addRequired<ScalarEvolutionWrapperPass>();
|
||||
AU.addRequired<TargetTransformInfoWrapperPass>();
|
||||
// We do not modify the shape of the CFG.
|
||||
AU.setPreservesCFG();
|
||||
}
|
||||
|
||||
bool doInitialization(Module &M) override {
|
||||
DL = &M.getDataLayout();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool runOnFunction(Function &F) override;
|
||||
bool runOnFunction(Function &F);
|
||||
|
||||
private:
|
||||
// Returns true if Basis is a basis for C, i.e., Basis dominates C and they
|
||||
@ -243,18 +256,18 @@ private:
|
||||
|
||||
} // end anonymous namespace
|
||||
|
||||
char StraightLineStrengthReduce::ID = 0;
|
||||
char StraightLineStrengthReduceLegacyPass::ID = 0;
|
||||
|
||||
INITIALIZE_PASS_BEGIN(StraightLineStrengthReduce, "slsr",
|
||||
INITIALIZE_PASS_BEGIN(StraightLineStrengthReduceLegacyPass, "slsr",
|
||||
"Straight line strength reduction", false, false)
|
||||
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass)
|
||||
INITIALIZE_PASS_DEPENDENCY(TargetTransformInfoWrapperPass)
|
||||
INITIALIZE_PASS_END(StraightLineStrengthReduce, "slsr",
|
||||
INITIALIZE_PASS_END(StraightLineStrengthReduceLegacyPass, "slsr",
|
||||
"Straight line strength reduction", false, false)
|
||||
|
||||
FunctionPass *llvm::createStraightLineStrengthReducePass() {
|
||||
return new StraightLineStrengthReduce();
|
||||
return new StraightLineStrengthReduceLegacyPass();
|
||||
}
|
||||
|
||||
bool StraightLineStrengthReduce::isBasisFor(const Candidate &Basis,
|
||||
@ -704,13 +717,17 @@ void StraightLineStrengthReduce::rewriteCandidateWithBasis(
|
||||
UnlinkedInstructions.push_back(C.Ins);
|
||||
}
|
||||
|
||||
bool StraightLineStrengthReduce::runOnFunction(Function &F) {
|
||||
bool StraightLineStrengthReduceLegacyPass::runOnFunction(Function &F) {
|
||||
if (skipFunction(F))
|
||||
return false;
|
||||
|
||||
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
|
||||
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||
auto *TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
|
||||
auto *DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
|
||||
auto *SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
|
||||
return StraightLineStrengthReduce(DL, DT, SE, TTI).runOnFunction(F);
|
||||
}
|
||||
|
||||
bool StraightLineStrengthReduce::runOnFunction(Function &F) {
|
||||
// Traverse the dominator tree in the depth-first order. This order makes sure
|
||||
// all bases of a candidate are in Candidates when we process it.
|
||||
for (const auto Node : depth_first(DT))
|
||||
@ -740,3 +757,25 @@ bool StraightLineStrengthReduce::runOnFunction(Function &F) {
|
||||
UnlinkedInstructions.clear();
|
||||
return Ret;
|
||||
}
|
||||
|
||||
namespace llvm {
|
||||
|
||||
PreservedAnalyses
|
||||
StraightLineStrengthReducePass::run(Function &F, FunctionAnalysisManager &AM) {
|
||||
const DataLayout *DL = &F.getParent()->getDataLayout();
|
||||
auto *DT = &AM.getResult<DominatorTreeAnalysis>(F);
|
||||
auto *SE = &AM.getResult<ScalarEvolutionAnalysis>(F);
|
||||
auto *TTI = &AM.getResult<TargetIRAnalysis>(F);
|
||||
|
||||
if (!StraightLineStrengthReduce(DL, DT, SE, TTI).runOnFunction(F))
|
||||
return PreservedAnalyses::all();
|
||||
|
||||
PreservedAnalyses PA;
|
||||
PA.preserveSet<CFGAnalyses>();
|
||||
PA.preserve<DominatorTreeAnalysis>();
|
||||
PA.preserve<ScalarEvolutionAnalysis>();
|
||||
PA.preserve<TargetIRAnalysis>();
|
||||
return PA;
|
||||
}
|
||||
|
||||
} // namespace llvm
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt < %s -slsr -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='slsr' -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-p:32:32-p1:64:64-p2:64:64-p3:32:32-p4:64:64-p5:32:32-p24:64:64-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64"
|
||||
target triple = "amdgcn--"
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt < %s -slsr -gvn -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='slsr,gvn' -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
@ -1,5 +1,6 @@
|
||||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
||||
; RUN: opt < %s -slsr -gvn -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='slsr,gvn' -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt < %s -slsr -gvn -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='slsr,gvn' -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64-p:64:64:64-p1:32:32:32"
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
; RUN: opt < %s -slsr -gvn -S | FileCheck %s
|
||||
; RUN: opt < %s -passes='slsr,gvn' -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user