summaryrefslogtreecommitdiffstats
path: root/polly/lib/Exchange/ScopLibImporter.cpp
blob: 381e6a406321e43bd9e6225d8c86c51c2673e246 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//===-- ScopLibImporter.cpp  - Import Scops with scoplib. -----------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Import modified .scop files into Polly. This allows to change the schedule of
// statements.
//
//===----------------------------------------------------------------------===//

#include "polly/LinkAllPasses.h"

#ifdef SCOPLIB_FOUND

#include "polly/Dependences.h"
#include "polly/Options.h"
#include "polly/ScopInfo.h"
#include "polly/ScopLib.h"

#include "llvm/Assembly/Writer.h"

#define SCOPLIB_INT_T_IS_MP
#include "scoplib/scop.h"

#include "isl/set.h"
#include "isl/constraint.h"

using namespace llvm;
using namespace polly;

namespace {
static cl::opt<std::string>
ImportDir("polly-import-scoplib-dir",
          cl::desc("The directory to import the .scoplib files from."),
          cl::Hidden, cl::value_desc("Directory path"), cl::ValueRequired,
          cl::init("."), cl::cat(PollyCategory));

static cl::opt<std::string>
ImportPostfix("polly-import-scoplib-postfix",
              cl::desc("Postfix to append to the import .scoplib files."),
              cl::Hidden, cl::value_desc("File postfix"), cl::ValueRequired,
              cl::init(""), cl::cat(PollyCategory));

struct ScopLibImporter : public RegionPass {
  static char ID;
  Scop *S;
  Dependences *D;
  explicit ScopLibImporter() : RegionPass(ID) {}

  bool updateScattering(Scop *S, scoplib_scop_p OScop);
  std::string getFileName(Scop *S) const;
  virtual bool runOnRegion(Region *R, RGPassManager &RGM);
  virtual void print(raw_ostream &OS, const Module *) const;
  void getAnalysisUsage(AnalysisUsage &AU) const;
};
}

char ScopLibImporter::ID = 0;

namespace {
std::string ScopLibImporter::getFileName(Scop *S) const {
  std::string FunctionName = S->getRegion().getEntry()->getParent()->getName();
  std::string FileName = FunctionName + "___" + S->getNameStr() + ".scoplib";
  return FileName;
}

void ScopLibImporter::print(raw_ostream &OS, const Module *) const {}

bool ScopLibImporter::runOnRegion(Region *R, RGPassManager &RGM) {
  S = getAnalysis<ScopInfo>().getScop();
  D = &getAnalysis<Dependences>();

  if (!S)
    return false;

  std::string FileName = ImportDir + "/" + getFileName(S) + ImportPostfix;
  FILE *F = fopen(FileName.c_str(), "r");

  if (!F) {
    errs() << "Cannot open file: " << FileName << "\n";
    errs() << "Skipping import.\n";
    return false;
  }

  std::string FunctionName = R->getEntry()->getParent()->getName();
  errs() << "Reading Scop '" << R->getNameStr() << "' in function '"
         << FunctionName << "' from '" << FileName << "'.\n";

  ScopLib scoplib(S, F, D);
  bool UpdateSuccessfull = scoplib.updateScattering();
  fclose(F);

  if (!UpdateSuccessfull) {
    errs() << "Update failed"
           << "\n";
  }

  return false;
}

void ScopLibImporter::getAnalysisUsage(AnalysisUsage &AU) const {
  AU.setPreservesAll();
  AU.addRequired<ScopInfo>();
  AU.addRequired<Dependences>();
}

}

static RegisterPass<ScopLibImporter>
A("polly-import-scoplib", "Polly - Import Scops with ScopLib library"
                          " (Reads a .scoplib file for each Scop)");

Pass *polly::createScopLibImporterPass() { return new ScopLibImporter(); }

#endif
OpenPOWER on IntegriCloud