Skip to content

Commit 33bc2e9

Browse files
committed
CodePreparation: Comment and format the file properly
llvm-svn: 177781
1 parent 446122e commit 33bc2e9

File tree

1 file changed

+70
-72
lines changed

1 file changed

+70
-72
lines changed

polly/lib/CodePreparation.cpp

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,50 +7,60 @@
77
//
88
//===----------------------------------------------------------------------===//
99
//
10-
// This file implement the code preparation for Scop detect, which will:
11-
// 1. Translate all PHINodes that not induction variable to memory access,
12-
// this will easier parameter and scalar dependencies checking.
10+
// The Polly code preparation pass is executed before SCoP detection. Its only
11+
// use is to translate all PHI nodes that can not be expressed by the code
12+
// generator into explicit memory dependences. Depending of the code generation
13+
// strategy different PHI nodes are translated:
14+
//
15+
// - indvars based code generation:
16+
//
17+
// The indvars based code generation requires explicit canonical induction
18+
// variables. Such variables are generated before scop detection and
19+
// also before the code preparation pass. All PHI nodes that are not canonical
20+
// induction variables are not supported by the indvars based code generation
21+
// and are consequently translated into explict memory accesses.
22+
//
23+
// - scev based code generation:
24+
//
25+
// The scev based code generation can code generate all PHI nodes that do not
26+
// reference parameters within the scop. As the code preparation pass is run
27+
// before scop detection, we can not check this condition, because without
28+
// a detected scop, we do not know SCEVUnknowns that appear in the SCEV of
29+
// a PHI node may later be within or outside of the SCoP. Hence, we follow a
30+
// heuristic and translate all PHI nodes that are either directly SCEVUnknown
31+
// or SCEVCouldNotCompute. This will hopefully get most of the PHI nodes that
32+
// are introduced due to conditional control flow, but not the ones that are
33+
// referencing loop counters.
34+
//
35+
// XXX: In the future, we should remove the need for this pass entirely and
36+
// instead add support for scalar dependences to ScopInfo and code generation.
1337
//
1438
//===----------------------------------------------------------------------===//
39+
1540
#include "polly/LinkAllPasses.h"
1641
#include "polly/CodeGen/BlockGenerators.h"
1742
#include "polly/Support/ScopHelper.h"
1843

19-
#include "llvm/IR/Instruction.h"
20-
#include "llvm/Pass.h"
21-
#include "llvm/Assembly/Writer.h"
2244
#include "llvm/Analysis/LoopInfo.h"
2345
#include "llvm/Analysis/RegionInfo.h"
24-
#include "llvm/Analysis/Dominators.h"
2546
#include "llvm/Analysis/ScalarEvolution.h"
26-
#include "llvm/ADT/DenseMap.h"
27-
#include "llvm/ADT/PointerIntPair.h"
28-
#include "llvm/Support/InstIterator.h"
2947
#include "llvm/Transforms/Utils/Local.h"
3048

31-
#define DEBUG_TYPE "polly-code-prep"
32-
#include "llvm/Support/Debug.h"
33-
34-
3549
using namespace llvm;
3650
using namespace polly;
3751

3852
namespace {
39-
//===----------------------------------------------------------------------===//
40-
/// @brief Scop Code Preparation - Perform some transforms to make scop detect
41-
/// easier.
53+
/// @brief Prepare the IR for the scop detection.
4254
///
4355
class CodePreparation : public FunctionPass {
4456
// DO NOT IMPLEMENT.
4557
CodePreparation(const CodePreparation &);
4658
// DO NOT IMPLEMENT.
4759
const CodePreparation &operator=(const CodePreparation &);
4860

49-
// LoopInfo to compute canonical induction variable.
5061
LoopInfo *LI;
5162
ScalarEvolution *SE;
5263

53-
// Clear the context.
5464
void clear();
5565

5666
bool eliminatePHINodes(Function &F);
@@ -72,66 +82,58 @@ class CodePreparation : public FunctionPass {
7282
};
7383
}
7484

75-
//===----------------------------------------------------------------------===//
76-
/// CodePreparation implement.
77-
78-
void CodePreparation::clear() {
79-
}
85+
void CodePreparation::clear() {}
8086

81-
CodePreparation::~CodePreparation() {
82-
clear();
83-
}
87+
CodePreparation::~CodePreparation() { clear(); }
8488

8589
bool CodePreparation::eliminatePHINodes(Function &F) {
8690
// The PHINodes that will be deleted.
87-
std::vector<PHINode*> PNtoDel;
91+
std::vector<PHINode *> PNtoDelete;
8892
// The PHINodes that will be preserved.
89-
std::vector<PHINode*> PreservedPNs;
93+
std::vector<PHINode *> PreservedPNs;
9094

9195
// Scan the PHINodes in this function.
92-
for (Function::iterator ibb = F.begin(), ibe = F.end();
93-
ibb != ibe; ++ibb)
94-
for (BasicBlock::iterator iib = ibb->begin(), iie = ibb->getFirstNonPHI();
95-
iib != iie; ++iib)
96-
if (PHINode *PN = cast<PHINode>(iib)) {
97-
if (SCEVCodegen) {
98-
if (SE->isSCEVable(PN->getType())) {
99-
const SCEV *S = SE->getSCEV(PN);
100-
if (!isa<SCEVUnknown>(S) && !isa<SCEVCouldNotCompute>(S)) {
101-
PreservedPNs.push_back(PN);
102-
continue;
103-
}
96+
for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI)
97+
for (BasicBlock::iterator II = BI->begin(), IE = BI->getFirstNonPHI();
98+
II != IE; ++II) {
99+
PHINode *PN = cast<PHINode>(II);
100+
if (SCEVCodegen) {
101+
if (SE->isSCEVable(PN->getType())) {
102+
const SCEV *S = SE->getSCEV(PN);
103+
if (!isa<SCEVUnknown>(S) && !isa<SCEVCouldNotCompute>(S)) {
104+
PreservedPNs.push_back(PN);
105+
continue;
104106
}
105-
} else {
106-
if (Loop *L = LI->getLoopFor(ibb)) {
107-
// Induction variable will be preserved.
108-
if (L->getCanonicalInductionVariable() == PN) {
109-
PreservedPNs.push_back(PN);
110-
continue;
111-
}
107+
}
108+
} else {
109+
if (Loop *L = LI->getLoopFor(BI)) {
110+
// Induction variables will be preserved.
111+
if (L->getCanonicalInductionVariable() == PN) {
112+
PreservedPNs.push_back(PN);
113+
continue;
112114
}
113115
}
114-
115-
// As DemotePHIToStack does not support invoke edges, we preserve
116-
// PHINodes that have invoke edges.
117-
if (hasInvokeEdge(PN))
118-
PreservedPNs.push_back(PN);
119-
else
120-
PNtoDel.push_back(PN);
121116
}
122117

123-
if (PNtoDel.empty())
118+
// As DemotePHIToStack does not support invoke edges, we preserve
119+
// PHINodes that have invoke edges.
120+
if (hasInvokeEdge(PN))
121+
PreservedPNs.push_back(PN);
122+
else
123+
PNtoDelete.push_back(PN);
124+
}
125+
126+
if (PNtoDelete.empty())
124127
return false;
125128

126-
// Eliminate the PHINodes that not an Induction variable.
127-
while (!PNtoDel.empty()) {
128-
PHINode *PN = PNtoDel.back();
129-
PNtoDel.pop_back();
129+
while (!PNtoDelete.empty()) {
130+
PHINode *PN = PNtoDelete.back();
131+
PNtoDelete.pop_back();
130132

131133
DemotePHIToStack(PN);
132134
}
133135

134-
// Move all preserved PHINodes to the beginning of the BasicBlock.
136+
// Move preserved PHINodes to the beginning of the BasicBlock.
135137
while (!PreservedPNs.empty()) {
136138
PHINode *PN = PreservedPNs.back();
137139
PreservedPNs.pop_back();
@@ -167,22 +169,18 @@ bool CodePreparation::runOnFunction(Function &F) {
167169
return false;
168170
}
169171

170-
void CodePreparation::releaseMemory() {
171-
clear();
172-
}
172+
void CodePreparation::releaseMemory() { clear(); }
173173

174-
void CodePreparation::print(raw_ostream &OS, const Module *) const {
175-
}
174+
void CodePreparation::print(raw_ostream &OS, const Module *) const {}
176175

177176
char CodePreparation::ID = 0;
178177
char &polly::CodePreparationID = CodePreparation::ID;
179178

179+
Pass *polly::createCodePreparationPass() { return new CodePreparation(); }
180+
180181
INITIALIZE_PASS_BEGIN(CodePreparation, "polly-prepare",
181-
"Polly - Prepare code for polly", false, false)
182-
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
182+
"Polly - Prepare code for polly", false, false);
183+
INITIALIZE_PASS_DEPENDENCY(LoopInfo);
183184
INITIALIZE_PASS_END(CodePreparation, "polly-prepare",
184-
"Polly - Prepare code for polly", false, false)
185+
"Polly - Prepare code for polly", false, false)
185186

186-
Pass *polly::createCodePreparationPass() {
187-
return new CodePreparation();
188-
}

0 commit comments

Comments
 (0)