1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00

[Delinearization][NewPM] Port delinearization to NPM

Also make tests in Analysis/Delinearization work under NPM.

Reviewed By: asbirlea

Differential Revision: https://reviews.llvm.org/D87741
This commit is contained in:
Arthur Eubanks 2020-09-15 21:10:22 -07:00
parent c5c94111c8
commit 9eb1a32643
23 changed files with 105 additions and 35 deletions

View File

@ -0,0 +1,33 @@
//===---- Delinearization.h - MultiDimensional Index Delinearization ------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This implements an analysis pass that tries to delinearize all GEP
// instructions in all loops using the SCEV analysis functionality. This pass is
// only used for testing purposes: if your pass needs delinearization, please
// use the on-demand SCEVAddRecExpr::delinearize() function.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_ANALYSIS_DELINEARIZATION_H
#define LLVM_ANALYSIS_DELINEARIZATION_H
#include "llvm/IR/PassManager.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
struct DelinearizationPrinterPass
: public PassInfoMixin<DelinearizationPrinterPass> {
explicit DelinearizationPrinterPass(raw_ostream &OS);
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
private:
raw_ostream &OS;
};
} // namespace llvm
#endif // LLVM_ANALYSIS_DELINEARIZATION_H

View File

@ -13,6 +13,7 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Analysis/Delinearization.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/ScalarEvolution.h"
@ -23,6 +24,7 @@
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
@ -54,22 +56,8 @@ public:
void print(raw_ostream &O, const Module *M = nullptr) const override;
};
} // end anonymous namespace
void Delinearization::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<ScalarEvolutionWrapperPass>();
}
bool Delinearization::runOnFunction(Function &F) {
this->F = &F;
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
return false;
}
void Delinearization::print(raw_ostream &O, const Module *) const {
void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
ScalarEvolution *SE) {
O << "Delinearization on function " << F->getName() << ":\n";
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
Instruction *Inst = &(*I);
@ -120,6 +108,25 @@ void Delinearization::print(raw_ostream &O, const Module *) const {
}
}
} // end anonymous namespace
void Delinearization::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
AU.addRequired<LoopInfoWrapperPass>();
AU.addRequired<ScalarEvolutionWrapperPass>();
}
bool Delinearization::runOnFunction(Function &F) {
this->F = &F;
SE = &getAnalysis<ScalarEvolutionWrapperPass>().getSE();
LI = &getAnalysis<LoopInfoWrapperPass>().getLoopInfo();
return false;
}
void Delinearization::print(raw_ostream &O, const Module *) const {
printDelinearization(O, F, LI, SE);
}
char Delinearization::ID = 0;
static const char delinearization_name[] = "Delinearization";
INITIALIZE_PASS_BEGIN(Delinearization, DL_NAME, delinearization_name, true,
@ -128,3 +135,12 @@ INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)
INITIALIZE_PASS_END(Delinearization, DL_NAME, delinearization_name, true, true)
FunctionPass *llvm::createDelinearizationPass() { return new Delinearization; }
DelinearizationPrinterPass::DelinearizationPrinterPass(raw_ostream &OS)
: OS(OS) {}
PreservedAnalyses DelinearizationPrinterPass::run(Function &F,
FunctionAnalysisManager &AM) {
printDelinearization(OS, &F, &AM.getResult<LoopAnalysis>(F),
&AM.getResult<ScalarEvolutionAnalysis>(F));
return PreservedAnalyses::all();
}

View File

@ -29,6 +29,7 @@
#include "llvm/Analysis/CGSCCPassManager.h"
#include "llvm/Analysis/CallGraph.h"
#include "llvm/Analysis/DDG.h"
#include "llvm/Analysis/Delinearization.h"
#include "llvm/Analysis/DemandedBits.h"
#include "llvm/Analysis/DependenceAnalysis.h"
#include "llvm/Analysis/DominanceFrontier.h"

View File

@ -247,6 +247,7 @@ FUNCTION_PASS("print<branch-prob>", BranchProbabilityPrinterPass(dbgs()))
FUNCTION_PASS("print<da>", DependenceAnalysisPrinterPass(dbgs()))
FUNCTION_PASS("print<domtree>", DominatorTreePrinterPass(dbgs()))
FUNCTION_PASS("print<postdomtree>", PostDominatorTreePrinterPass(dbgs()))
FUNCTION_PASS("print<delinearization>", DelinearizationPrinterPass(dbgs()))
FUNCTION_PASS("print<demanded-bits>", DemandedBitsPrinterPass(dbgs()))
FUNCTION_PASS("print<domfrontier>", DominanceFrontierPrinterPass(dbgs()))
FUNCTION_PASS("print<func-properties>", FunctionPropertiesPrinterPass(dbgs()))

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
;
; void foo(long n, long m, long o, int A[n][m][o]) {
; for (long i = 0; i < n; i++)

View File

@ -1,4 +1,5 @@
; RUN: opt -delinearize -analyze < %s | FileCheck %s
; RUN: opt -delinearize -analyze -enable-new-pm=0 < %s | FileCheck %s
; RUN: opt -passes='print<delinearization>' -disable-output < %s 2>&1 | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
target datalayout = "e-m:e-p:32:32-i1:32-i64:64-a:0-n32"

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -basic-aa -da -analyze -delinearize
; RUN: opt < %s -basic-aa -da -analyze -enable-new-pm=0 -delinearize
; RUN: opt < %s -aa-pipeline=basic-aa -passes='require<da>,print<delinearization>' -disable-output
;
; a, b, c, d, g, h;
; char *f;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; #define MR(mt,n,r,c,d) mt->m[(n) * mt->mrows * mt->mcols * mt->mdeps + (r) * mt->mcols* mt->mdeps + (c) * mt->mdeps + (d)]
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; #define MR(mt,n,r,c,d) mt->m[(n) * mt->mrows * mt->mcols * mt->mdeps + (r) * mt->mcols* mt->mdeps + (c) * mt->mdeps + (d)]
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; Derived from the following code:
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; void foo(long n, long m, long o, double A[n][m][o]) {
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; void foo(long n, long m, long o, long p, double A[n][m][o+p]) {
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; void foo(long n, long m, long o, double A[n][m][o], long p, long q, long r) {
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; Derived from the following code:
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; XFAIL: *
; We do not recognize anymore variable size arrays.

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; void foo(long n, long m, long o, double A[n][m][o]) {
;

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output 2>&1 | FileCheck %s
; void foo(int n, int m, int o, double A[n][m][o]) {
;
; for (int i = 0; i < n; i++)

View File

@ -1,4 +1,5 @@
; RUN: opt -basic-aa -da -analyze < %s
; RUN: opt -basic-aa -da -analyze -enable-new-pm=0 < %s
; RUN: opt -aa-pipeline=basic-aa -passes='require<da>,print<delinearization>' -disable-output < %s
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

View File

@ -1,4 +1,5 @@
; RUN: opt -delinearize -analyze < %s | FileCheck %s
; RUN: opt -delinearize -analyze -enable-new-pm=0 < %s | FileCheck %s
; RUN: opt -passes='print<delinearization>' -disable-output < %s 2>&1 | FileCheck %s
;
; void foo(float *A, long *p) {
; for (long i = 0; i < 100; i++)

View File

@ -1,5 +1,6 @@
; REQUIRES: asserts
; RUN: opt < %s -analyze -delinearize -debug 2>&1 | FileCheck %s
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize -debug 2>&1 | FileCheck %s
; RUN: opt < %s -passes='print<delinearization>' -disable-output -debug 2>&1 2>&1 | FileCheck %s
; void foo (int m, int n, char *A) {
; for (int i=0; i < m; i++)
; for(int j=0; j< n; j++)

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize
; RUN: opt < %s -passes='print<delinearization>' -disable-output
; REQUIRES: asserts
; Test that SCEV divide code doesn't crash when attempting to create a SCEV

View File

@ -1,4 +1,5 @@
; RUN: opt < %s -analyze -delinearize
; RUN: opt < %s -analyze -enable-new-pm=0 -delinearize
; RUN: opt < %s -passes='print<delinearization>' -disable-output
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"