Skip to content

Commit 9dfe4e7

Browse files
committedJul 13, 2016
Add accelerator code generation pass skeleton
Add a new pass to serve as basis for automatic accelerator mapping in Polly. The pass structure and the analyses preserved are copied from CodeGeneration.cpp, as we will rely on IslNodeBuilder and IslExprBuilder for LLVM-IR code generation. Polly's accelerator code generation is enabled with -polly-target=gpu I would like to use this commit as opportunity to thank Yabin Hu for his work in the context of two Google summer of code projects during which he implemented initial prototypes of the Polly accelerator code generation -- in parts this code is already available in todays Polly (e.g., tools/GPURuntime). More will come as part of the upcoming Polly ACC changes. Reviewers: Meinersbur Subscribers: pollydev, llvm-commits Differential Revision: http://reviews.llvm.org/D22036 llvm-svn: 275275
1 parent a041239 commit 9dfe4e7

File tree

4 files changed

+118
-14
lines changed

4 files changed

+118
-14
lines changed
 

‎polly/include/polly/LinkAllPasses.h

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ llvm::Pass *createScopInfoRegionPassPass();
4242
llvm::Pass *createScopInfoWrapperPassPass();
4343
llvm::Pass *createIslAstInfoPass();
4444
llvm::Pass *createCodeGenerationPass();
45+
llvm::Pass *createPPCGCodeGenerationPass();
4546
llvm::Pass *createIslScheduleOptimizerPass();
4647

4748
extern char &CodePreparationID;
@@ -71,6 +72,7 @@ struct PollyForcePassLinking {
7172
polly::createPollyCanonicalizePass();
7273
polly::createIslAstInfoPass();
7374
polly::createCodeGenerationPass();
75+
polly::createPPCGCodeGenerationPass();
7476
polly::createIslScheduleOptimizerPass();
7577
}
7678
} PollyForcePassLinking; // Force link by creating a global definition.
@@ -84,6 +86,7 @@ void initializeJSONExporterPass(llvm::PassRegistry &);
8486
void initializeJSONImporterPass(llvm::PassRegistry &);
8587
void initializeIslAstInfoPass(llvm::PassRegistry &);
8688
void initializeCodeGenerationPass(llvm::PassRegistry &);
89+
void initializePPCGCodeGenerationPass(llvm::PassRegistry &);
8790
void initializeIslScheduleOptimizerPass(llvm::PassRegistry &);
8891
void initializePollyCanonicalizePass(llvm::PassRegistry &);
8992
} // namespace llvm

‎polly/lib/CMakeLists.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ set(ISL_CODEGEN_FILES
1313
CodeGen/CodeGeneration.cpp)
1414

1515
if (GPU_CODEGEN)
16-
set (GPGPU_CODEGEN_FILES)
16+
set (GPGPU_CODEGEN_FILES
17+
CodeGen/PPCGCodeGeneration.cpp
18+
)
1719
endif (GPU_CODEGEN)
1820

1921
# Compile ISL into a separate library.
+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
//===------ PPCGCodeGeneration.cpp - Polly Accelerator Code Generation. ---===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// Take a scop created by ScopInfo and map it to GPU code using the ppcg
11+
// GPU mapping strategy.
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#include "polly/CodeGen/IslNodeBuilder.h"
16+
#include "polly/DependenceInfo.h"
17+
#include "polly/LinkAllPasses.h"
18+
#include "polly/ScopInfo.h"
19+
#include "llvm/Analysis/AliasAnalysis.h"
20+
#include "llvm/Analysis/BasicAliasAnalysis.h"
21+
#include "llvm/Analysis/GlobalsModRef.h"
22+
#include "llvm/Analysis/PostDominators.h"
23+
#include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
24+
25+
#include "llvm/Support/Debug.h"
26+
27+
using namespace polly;
28+
using namespace llvm;
29+
30+
#define DEBUG_TYPE "polly-codegen-ppcg"
31+
32+
namespace {
33+
class PPCGCodeGeneration : public ScopPass {
34+
public:
35+
static char ID;
36+
37+
PPCGCodeGeneration() : ScopPass(ID) {}
38+
39+
bool runOnScop(Scop &S) override { return true; }
40+
41+
void printScop(raw_ostream &, Scop &) const override {}
42+
43+
void getAnalysisUsage(AnalysisUsage &AU) const override {
44+
AU.addRequired<DominatorTreeWrapperPass>();
45+
AU.addRequired<RegionInfoPass>();
46+
AU.addRequired<ScalarEvolutionWrapperPass>();
47+
AU.addRequired<ScopDetection>();
48+
AU.addRequired<ScopInfoRegionPass>();
49+
AU.addRequired<LoopInfoWrapperPass>();
50+
51+
AU.addPreserved<AAResultsWrapperPass>();
52+
AU.addPreserved<BasicAAWrapperPass>();
53+
AU.addPreserved<LoopInfoWrapperPass>();
54+
AU.addPreserved<DominatorTreeWrapperPass>();
55+
AU.addPreserved<GlobalsAAWrapperPass>();
56+
AU.addPreserved<PostDominatorTreeWrapperPass>();
57+
AU.addPreserved<ScopDetection>();
58+
AU.addPreserved<ScalarEvolutionWrapperPass>();
59+
AU.addPreserved<SCEVAAWrapperPass>();
60+
61+
// FIXME: We do not yet add regions for the newly generated code to the
62+
// region tree.
63+
AU.addPreserved<RegionInfoPass>();
64+
AU.addPreserved<ScopInfoRegionPass>();
65+
}
66+
};
67+
}
68+
69+
char PPCGCodeGeneration::ID = 1;
70+
71+
Pass *polly::createPPCGCodeGenerationPass() { return new PPCGCodeGeneration(); }
72+
73+
INITIALIZE_PASS_BEGIN(PPCGCodeGeneration, "polly-codegen-ppcg",
74+
"Polly - Apply PPCG translation to SCOP", false, false)
75+
INITIALIZE_PASS_DEPENDENCY(DependenceInfo);
76+
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass);
77+
INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass);
78+
INITIALIZE_PASS_DEPENDENCY(RegionInfoPass);
79+
INITIALIZE_PASS_DEPENDENCY(ScalarEvolutionWrapperPass);
80+
INITIALIZE_PASS_DEPENDENCY(ScopDetection);
81+
INITIALIZE_PASS_END(PPCGCodeGeneration, "polly-codegen-ppcg",
82+
"Polly - Apply PPCG translation to SCOP", false, false)

‎polly/lib/Support/RegisterPasses.cpp

+30-13
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ static cl::opt<CodeGenChoice> CodeGenerator(
8686
clEnumValEnd),
8787
cl::Hidden, cl::init(CODEGEN_ISL), cl::ZeroOrMore, cl::cat(PollyCategory));
8888

89+
enum TargetChoice { TARGET_CPU, TARGET_GPU };
90+
static cl::opt<TargetChoice>
91+
Target("polly-target", cl::desc("The hardware to target"),
92+
cl::values(clEnumValN(TARGET_CPU, "cpu", "generate CPU code"),
93+
clEnumValN(TARGET_GPU, "gpu", "generate GPU code"),
94+
clEnumValEnd),
95+
cl::init(TARGET_CPU), cl::ZeroOrMore, cl::cat(PollyCategory));
96+
8997
VectorizerChoice polly::PollyVectorizerChoice;
9098
static cl::opt<polly::VectorizerChoice, true> Vectorizer(
9199
"polly-vectorizer", cl::desc("Select the vectorization strategy"),
@@ -145,6 +153,7 @@ static cl::opt<bool>
145153
namespace polly {
146154
void initializePollyPasses(PassRegistry &Registry) {
147155
initializeCodeGenerationPass(Registry);
156+
initializePPCGCodeGenerationPass(Registry);
148157
initializeCodePreparationPass(Registry);
149158
initializeDeadCodeElimPass(Registry);
150159
initializeDependenceInfoPass(Registry);
@@ -209,24 +218,32 @@ void registerPollyPasses(llvm::legacy::PassManagerBase &PM) {
209218
if (DeadCodeElim)
210219
PM.add(polly::createDeadCodeElimPass());
211220

212-
switch (Optimizer) {
213-
case OPTIMIZER_NONE:
214-
break; /* Do nothing */
215-
216-
case OPTIMIZER_ISL:
217-
PM.add(polly::createIslScheduleOptimizerPass());
218-
break;
221+
if (Target == TARGET_GPU) {
222+
// GPU generation provides its own scheduling optimization strategy.
223+
} else {
224+
switch (Optimizer) {
225+
case OPTIMIZER_NONE:
226+
break; /* Do nothing */
227+
228+
case OPTIMIZER_ISL:
229+
PM.add(polly::createIslScheduleOptimizerPass());
230+
break;
231+
}
219232
}
220233

221234
if (ExportJScop)
222235
PM.add(polly::createJSONExporterPass());
223236

224-
switch (CodeGenerator) {
225-
case CODEGEN_ISL:
226-
PM.add(polly::createCodeGenerationPass());
227-
break;
228-
case CODEGEN_NONE:
229-
break;
237+
if (Target == TARGET_GPU) {
238+
PM.add(polly::createPPCGCodeGenerationPass());
239+
} else {
240+
switch (CodeGenerator) {
241+
case CODEGEN_ISL:
242+
PM.add(polly::createCodeGenerationPass());
243+
break;
244+
case CODEGEN_NONE:
245+
break;
246+
}
230247
}
231248

232249
// FIXME: This dummy ModulePass keeps some programs from miscompiling,

0 commit comments

Comments
 (0)
Please sign in to comment.