summaryrefslogtreecommitdiffstats
path: root/polly/lib/Exchange/ScopLibExporter.cpp
blob: 583240d51cb5160ef1f3e8cc1a5cd7f0eafed400 (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
//===-- ScopLibExporter.cpp  - Export Scops with scoplib   ----------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// Export the Scops build by ScopInfo pass to text file.
//
//===----------------------------------------------------------------------===//

#include "polly/LinkAllPasses.h"

#ifdef SCOPLIB_FOUND

#include "polly/ScopInfo.h"
#include "polly/ScopPass.h"
#include "polly/ScopLib.h"

#include "llvm/Support/CommandLine.h"
#include "llvm/Assembly/Writer.h"

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

using namespace llvm;
using namespace polly;

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

  class ScopLibExporter : public ScopPass {
    Scop *S;

    std::string getFileName(Scop *S) const;
  public:
    static char ID;
    explicit ScopLibExporter() : ScopPass(ID) {}

    virtual bool runOnScop(Scop &scop);
    void getAnalysisUsage(AnalysisUsage &AU) const;
  };

}

char ScopLibExporter::ID = 0;

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

bool ScopLibExporter::runOnScop(Scop &scop) {
  S = &scop;
  Region *R = &S->getRegion();

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

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

  ScopLib scoplib(S);
  scoplib.print(F);
  fclose(F);

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

  return false;
}

void ScopLibExporter::getAnalysisUsage(AnalysisUsage &AU) const {
  ScopPass::getAnalysisUsage(AU);
}

static RegisterPass<ScopLibExporter> A("polly-export-scoplib",
                                    "Polly - Export Scops with ScopLib library"
                                    " (Writes a .scoplib file for each Scop)"
                                    );

Pass *polly::createScopLibExporterPass() {
  return new ScopLibExporter();
}

#endif
OpenPOWER on IntegriCloud