2011-04-29 14:27:02 +08:00
|
|
|
//===-- JSONExporter.cpp - Export Scops as JSON -------------------------===//
|
|
|
|
//
|
|
|
|
// 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 as a JSON file.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-03-05 06:43:40 +08:00
|
|
|
#include "polly/DependenceInfo.h"
|
2015-12-21 20:38:56 +08:00
|
|
|
#include "polly/LinkAllPasses.h"
|
2013-05-07 15:31:10 +08:00
|
|
|
#include "polly/Options.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "polly/ScopInfo.h"
|
|
|
|
#include "polly/ScopPass.h"
|
2015-05-03 13:21:36 +08:00
|
|
|
#include "polly/Support/ScopLocation.h"
|
2011-07-13 01:14:03 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2015-03-02 02:51:51 +08:00
|
|
|
#include "llvm/Analysis/RegionInfo.h"
|
2015-03-05 17:48:20 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2014-04-30 15:26:28 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2013-05-07 16:11:54 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/ToolOutputFile.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "isl/constraint.h"
|
2015-05-09 17:13:42 +08:00
|
|
|
#include "isl/map.h"
|
2011-04-29 14:27:02 +08:00
|
|
|
#include "isl/printer.h"
|
2015-05-09 17:13:42 +08:00
|
|
|
#include "isl/set.h"
|
2015-07-14 17:33:13 +08:00
|
|
|
#include "isl/union_map.h"
|
2015-05-09 17:13:42 +08:00
|
|
|
#include "json/reader.h"
|
|
|
|
#include "json/writer.h"
|
2014-05-19 11:55:49 +08:00
|
|
|
#include <memory>
|
2011-04-29 14:27:02 +08:00
|
|
|
#include <string>
|
2014-06-13 03:22:17 +08:00
|
|
|
#include <system_error>
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
using namespace polly;
|
|
|
|
|
2014-04-22 11:30:19 +08:00
|
|
|
#define DEBUG_TYPE "polly-import-jscop"
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
STATISTIC(NewAccessMapFound, "Number of updated access functions");
|
2011-07-13 01:14:03 +08:00
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
namespace {
|
2013-05-07 15:30:56 +08:00
|
|
|
static cl::opt<std::string>
|
2014-07-09 18:50:10 +08:00
|
|
|
ImportDir("polly-import-jscop-dir",
|
|
|
|
cl::desc("The directory to import the .jscop files from."),
|
|
|
|
cl::Hidden, cl::value_desc("Directory path"), cl::ValueRequired,
|
|
|
|
cl::init("."), cl::cat(PollyCategory));
|
2013-03-23 09:05:07 +08:00
|
|
|
|
2013-05-07 15:30:56 +08:00
|
|
|
static cl::opt<std::string>
|
2014-07-09 18:50:10 +08:00
|
|
|
ImportPostfix("polly-import-jscop-postfix",
|
|
|
|
cl::desc("Postfix to append to the import .jsop files."),
|
|
|
|
cl::Hidden, cl::value_desc("File postfix"), cl::ValueRequired,
|
|
|
|
cl::init(""), cl::cat(PollyCategory));
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
struct JSONExporter : public ScopPass {
|
|
|
|
static char ID;
|
|
|
|
explicit JSONExporter() : ScopPass(ID) {}
|
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
std::string getFileName(Scop &S) const;
|
|
|
|
Json::Value getJSON(Scop &S) const;
|
2015-09-27 23:43:29 +08:00
|
|
|
|
|
|
|
/// @brief Export the SCoP @p S to a JSON file.
|
|
|
|
bool runOnScop(Scop &S) override;
|
|
|
|
|
|
|
|
/// @brief Print the SCoP @p S as it is exported.
|
|
|
|
void printScop(raw_ostream &OS, Scop &S) const override;
|
|
|
|
|
|
|
|
/// @brief Register all analyses and transformation required.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
2011-04-29 14:27:02 +08:00
|
|
|
};
|
2011-04-29 14:52:36 +08:00
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
struct JSONImporter : public ScopPass {
|
|
|
|
static char ID;
|
2011-08-03 21:47:59 +08:00
|
|
|
std::vector<std::string> newAccessStrings;
|
2011-04-29 14:27:02 +08:00
|
|
|
explicit JSONImporter() : ScopPass(ID) {}
|
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
std::string getFileName(Scop &S) const;
|
2015-09-27 23:43:29 +08:00
|
|
|
|
|
|
|
/// @brief Import new access functions for SCoP @p S from a JSON file.
|
|
|
|
bool runOnScop(Scop &S) override;
|
|
|
|
|
|
|
|
/// @brief Print the SCoP @p S and the imported access functions.
|
|
|
|
void printScop(raw_ostream &OS, Scop &S) const override;
|
|
|
|
|
|
|
|
/// @brief Register all analyses and transformation required.
|
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override;
|
2011-04-29 14:27:02 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
char JSONExporter::ID = 0;
|
2015-03-02 02:44:57 +08:00
|
|
|
std::string JSONExporter::getFileName(Scop &S) const {
|
2016-05-23 20:38:05 +08:00
|
|
|
std::string FunctionName = S.getFunction().getName();
|
2015-03-02 02:44:57 +08:00
|
|
|
std::string FileName = FunctionName + "___" + S.getNameStr() + ".jscop";
|
2011-04-29 14:27:02 +08:00
|
|
|
return FileName;
|
|
|
|
}
|
|
|
|
|
2015-03-02 02:40:25 +08:00
|
|
|
void JSONExporter::printScop(raw_ostream &OS, Scop &S) const { S.print(OS); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
Json::Value JSONExporter::getJSON(Scop &S) const {
|
2011-04-29 14:27:02 +08:00
|
|
|
Json::Value root;
|
2015-05-03 13:21:36 +08:00
|
|
|
unsigned LineBegin, LineEnd;
|
|
|
|
std::string FileName;
|
|
|
|
|
|
|
|
getDebugLocation(&S.getRegion(), LineBegin, LineEnd, FileName);
|
|
|
|
std::string Location;
|
|
|
|
if (LineBegin != (unsigned)-1)
|
|
|
|
Location = FileName + ":" + std::to_string(LineBegin) + "-" +
|
|
|
|
std::to_string(LineEnd);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-05-23 20:38:05 +08:00
|
|
|
root["name"] = S.getNameStr();
|
2015-03-02 02:44:57 +08:00
|
|
|
root["context"] = S.getContextStr();
|
2015-05-03 13:21:36 +08:00
|
|
|
if (LineBegin != (unsigned)-1)
|
|
|
|
root["location"] = Location;
|
2011-04-29 14:27:02 +08:00
|
|
|
root["statements"];
|
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
2011-04-29 14:27:02 +08:00
|
|
|
Json::Value statement;
|
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
statement["name"] = Stmt.getBaseName();
|
|
|
|
statement["domain"] = Stmt.getDomainStr();
|
|
|
|
statement["schedule"] = Stmt.getScheduleStr();
|
2011-04-29 14:27:02 +08:00
|
|
|
statement["accesses"];
|
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
for (MemoryAccess *MA : Stmt) {
|
2011-04-29 14:27:02 +08:00
|
|
|
Json::Value access;
|
|
|
|
|
2014-06-14 02:01:45 +08:00
|
|
|
access["kind"] = MA->isRead() ? "read" : "write";
|
2014-10-13 20:58:03 +08:00
|
|
|
access["relation"] = MA->getOriginalAccessRelationStr();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
statement["accesses"].append(access);
|
|
|
|
}
|
|
|
|
|
|
|
|
root["statements"].append(statement);
|
|
|
|
}
|
|
|
|
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
bool JSONExporter::runOnScop(Scop &S) {
|
2011-04-29 14:27:02 +08:00
|
|
|
std::string FileName = ImportDir + "/" + getFileName(S);
|
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
Json::Value jscop = getJSON(S);
|
2011-04-29 14:27:02 +08:00
|
|
|
Json::StyledWriter writer;
|
|
|
|
std::string fileContent = writer.write(jscop);
|
|
|
|
|
|
|
|
// Write to file.
|
2014-08-26 02:16:52 +08:00
|
|
|
std::error_code EC;
|
|
|
|
tool_output_file F(FileName, EC, llvm::sys::fs::F_Text);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2016-05-23 20:38:05 +08:00
|
|
|
std::string FunctionName = S.getFunction().getName();
|
|
|
|
errs() << "Writing JScop '" << S.getNameStr() << "' in function '"
|
2013-03-23 09:05:07 +08:00
|
|
|
<< FunctionName << "' to '" << FileName << "'.\n";
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2014-08-26 02:16:52 +08:00
|
|
|
if (!EC) {
|
2011-04-29 14:27:02 +08:00
|
|
|
F.os() << fileContent;
|
|
|
|
F.os().close();
|
|
|
|
if (!F.os().has_error()) {
|
|
|
|
errs() << "\n";
|
|
|
|
F.keep();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errs() << " error opening file for writing!\n";
|
|
|
|
F.os().clear_error();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSONExporter::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
AU.setPreservesAll();
|
|
|
|
AU.addRequired<ScopInfo>();
|
|
|
|
}
|
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
Pass *polly::createJSONExporterPass() { return new JSONExporter(); }
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
char JSONImporter::ID = 0;
|
2015-03-02 02:44:57 +08:00
|
|
|
std::string JSONImporter::getFileName(Scop &S) const {
|
2016-05-23 20:38:05 +08:00
|
|
|
std::string FunctionName = S.getFunction().getName();
|
2015-03-02 02:44:57 +08:00
|
|
|
std::string FileName = FunctionName + "___" + S.getNameStr() + ".jscop";
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
if (ImportPostfix != "")
|
|
|
|
FileName += "." + ImportPostfix;
|
|
|
|
|
|
|
|
return FileName;
|
|
|
|
}
|
2011-04-29 14:52:36 +08:00
|
|
|
|
2015-03-02 02:40:25 +08:00
|
|
|
void JSONImporter::printScop(raw_ostream &OS, Scop &S) const {
|
|
|
|
S.print(OS);
|
2011-08-03 21:47:59 +08:00
|
|
|
for (std::vector<std::string>::const_iterator I = newAccessStrings.begin(),
|
2013-03-23 09:05:07 +08:00
|
|
|
E = newAccessStrings.end();
|
|
|
|
I != E; I++)
|
2011-08-03 21:47:59 +08:00
|
|
|
OS << "New access function '" << *I << "'detected in JSCOP file\n";
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2015-03-05 08:43:48 +08:00
|
|
|
typedef Dependences::StatementToIslMapTy StatementToIslMapTy;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
bool JSONImporter::runOnScop(Scop &S) {
|
2016-03-03 16:15:33 +08:00
|
|
|
const Dependences &D =
|
|
|
|
getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement);
|
2016-05-23 20:38:05 +08:00
|
|
|
const DataLayout &DL = S.getFunction().getParent()->getDataLayout();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
std::string FileName = ImportDir + "/" + getFileName(S);
|
|
|
|
|
2016-05-23 20:38:05 +08:00
|
|
|
std::string FunctionName = S.getFunction().getName();
|
|
|
|
errs() << "Reading JScop '" << S.getNameStr() << "' in function '"
|
2013-03-23 09:05:07 +08:00
|
|
|
<< FunctionName << "' from '" << FileName << "'.\n";
|
2014-07-07 02:11:46 +08:00
|
|
|
ErrorOr<std::unique_ptr<MemoryBuffer>> result =
|
|
|
|
MemoryBuffer::getFile(FileName);
|
|
|
|
std::error_code ec = result.getError();
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
if (ec) {
|
|
|
|
errs() << "File could not be read: " << ec.message() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Json::Reader reader;
|
|
|
|
Json::Value jscop;
|
|
|
|
|
2014-07-07 02:11:46 +08:00
|
|
|
bool parsingSuccessful = reader.parse(result.get()->getBufferStart(), jscop);
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
if (!parsingSuccessful) {
|
|
|
|
errs() << "JSCoP file could not be parsed\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-02 02:44:57 +08:00
|
|
|
isl_set *OldContext = S.getContext();
|
2013-03-23 09:05:07 +08:00
|
|
|
isl_set *NewContext =
|
2015-03-02 02:44:57 +08:00
|
|
|
isl_set_read_from_str(S.getIslCtx(), jscop["context"].asCString());
|
2011-11-15 19:38:44 +08:00
|
|
|
|
|
|
|
for (unsigned i = 0; i < isl_set_dim(OldContext, isl_dim_param); i++) {
|
|
|
|
isl_id *id = isl_set_get_dim_id(OldContext, isl_dim_param, i);
|
|
|
|
NewContext = isl_set_set_dim_id(NewContext, isl_dim_param, i, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
isl_set_free(OldContext);
|
2015-03-02 02:44:57 +08:00
|
|
|
S.setContext(NewContext);
|
2011-11-15 19:38:44 +08:00
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
StatementToIslMapTy NewSchedule;
|
2011-04-29 14:27:02 +08:00
|
|
|
|
|
|
|
int index = 0;
|
2011-04-29 14:52:36 +08:00
|
|
|
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
2011-04-29 14:27:02 +08:00
|
|
|
Json::Value schedule = jscop["statements"][index]["schedule"];
|
2015-03-02 02:44:57 +08:00
|
|
|
isl_map *m = isl_map_read_from_str(S.getIslCtx(), schedule.asCString());
|
2015-05-27 13:16:57 +08:00
|
|
|
isl_space *Space = Stmt.getDomainSpace();
|
2012-05-29 17:29:44 +08:00
|
|
|
|
|
|
|
// Copy the old tuple id. This is necessary to retain the user pointer,
|
2015-04-21 19:37:25 +08:00
|
|
|
// that stores the reference to the ScopStmt this schedule belongs to.
|
2012-05-29 17:29:44 +08:00
|
|
|
m = isl_map_set_tuple_id(m, isl_dim_in,
|
|
|
|
isl_space_get_tuple_id(Space, isl_dim_set));
|
2015-04-23 20:23:56 +08:00
|
|
|
for (unsigned i = 0; i < isl_space_dim(Space, isl_dim_param); i++) {
|
|
|
|
isl_id *id = isl_space_get_dim_id(Space, isl_dim_param, i);
|
|
|
|
m = isl_map_set_dim_id(m, isl_dim_param, i, id);
|
|
|
|
}
|
2012-05-29 17:29:44 +08:00
|
|
|
isl_space_free(Space);
|
2015-05-27 13:16:57 +08:00
|
|
|
NewSchedule[&Stmt] = m;
|
2011-04-29 14:27:02 +08:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
2015-04-21 19:37:25 +08:00
|
|
|
if (!D.isValidSchedule(S, &NewSchedule)) {
|
|
|
|
errs() << "JScop file contains a schedule that changes the "
|
2011-04-29 14:27:02 +08:00
|
|
|
<< "dependences. Use -disable-polly-legality to continue anyways\n";
|
2015-04-21 19:37:25 +08:00
|
|
|
for (StatementToIslMapTy::iterator SI = NewSchedule.begin(),
|
|
|
|
SE = NewSchedule.end();
|
2013-07-29 13:12:01 +08:00
|
|
|
SI != SE; ++SI)
|
|
|
|
isl_map_free(SI->second);
|
2011-04-29 14:27:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-14 17:33:13 +08:00
|
|
|
auto ScheduleMap = isl_union_map_empty(S.getParamSpace());
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
|
|
|
if (NewSchedule.find(&Stmt) != NewSchedule.end())
|
2015-07-14 17:33:13 +08:00
|
|
|
ScheduleMap = isl_union_map_add_map(ScheduleMap, NewSchedule[&Stmt]);
|
|
|
|
else
|
|
|
|
ScheduleMap = isl_union_map_add_map(ScheduleMap, Stmt.getSchedule());
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
|
|
|
|
2015-07-14 17:33:13 +08:00
|
|
|
S.setSchedule(ScheduleMap);
|
|
|
|
|
2011-07-13 01:14:03 +08:00
|
|
|
int statementIdx = 0;
|
2015-05-27 13:16:57 +08:00
|
|
|
for (ScopStmt &Stmt : S) {
|
2011-07-16 12:55:09 +08:00
|
|
|
int memoryAccessIdx = 0;
|
2015-05-27 13:16:57 +08:00
|
|
|
for (MemoryAccess *MA : Stmt) {
|
2013-07-14 00:58:07 +08:00
|
|
|
Json::Value accesses = jscop["statements"][statementIdx]["accesses"]
|
|
|
|
[memoryAccessIdx]["relation"];
|
2013-03-23 09:05:07 +08:00
|
|
|
isl_map *newAccessMap =
|
2015-03-02 02:44:57 +08:00
|
|
|
isl_map_read_from_str(S.getIslCtx(), accesses.asCString());
|
2014-06-14 02:01:45 +08:00
|
|
|
isl_map *currentAccessMap = MA->getAccessRelation();
|
2011-11-15 19:38:59 +08:00
|
|
|
|
|
|
|
if (isl_map_dim(newAccessMap, isl_dim_param) !=
|
2013-04-10 14:55:45 +08:00
|
|
|
isl_map_dim(currentAccessMap, isl_dim_param)) {
|
2011-11-15 19:38:59 +08:00
|
|
|
errs() << "JScop file changes the number of parameter dimensions\n";
|
|
|
|
isl_map_free(currentAccessMap);
|
|
|
|
isl_map_free(newAccessMap);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-05 19:32:18 +08:00
|
|
|
isl_id *OutId = isl_map_get_tuple_id(currentAccessMap, isl_dim_out);
|
|
|
|
newAccessMap = isl_map_set_tuple_id(newAccessMap, isl_dim_out, OutId);
|
|
|
|
|
2016-01-16 00:49:33 +08:00
|
|
|
if (MA->isArrayKind()) {
|
|
|
|
// We keep the old alignment, thus we cannot allow accesses to memory
|
|
|
|
// locations that were not accessed before if the alignment of the
|
|
|
|
// access is not the default alignment.
|
|
|
|
bool SpecialAlignment = true;
|
|
|
|
if (LoadInst *LoadI = dyn_cast<LoadInst>(MA->getAccessInstruction())) {
|
|
|
|
SpecialAlignment =
|
|
|
|
DL.getABITypeAlignment(LoadI->getType()) != LoadI->getAlignment();
|
|
|
|
} else if (StoreInst *StoreI =
|
|
|
|
dyn_cast<StoreInst>(MA->getAccessInstruction())) {
|
|
|
|
SpecialAlignment =
|
|
|
|
DL.getABITypeAlignment(StoreI->getValueOperand()->getType()) !=
|
|
|
|
StoreI->getAlignment();
|
|
|
|
}
|
2014-10-10 23:14:29 +08:00
|
|
|
|
2016-01-16 00:49:33 +08:00
|
|
|
if (SpecialAlignment) {
|
|
|
|
isl_set *newAccessSet = isl_map_range(isl_map_copy(newAccessMap));
|
|
|
|
isl_set *currentAccessSet =
|
|
|
|
isl_map_range(isl_map_copy(currentAccessMap));
|
|
|
|
bool isSubset = isl_set_is_subset(newAccessSet, currentAccessSet);
|
|
|
|
isl_set_free(newAccessSet);
|
|
|
|
isl_set_free(currentAccessSet);
|
|
|
|
|
|
|
|
if (!isSubset) {
|
|
|
|
errs() << "JScop file changes the accessed memory\n";
|
|
|
|
isl_map_free(currentAccessMap);
|
|
|
|
isl_map_free(newAccessMap);
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-10 23:14:29 +08:00
|
|
|
}
|
2014-10-03 00:22:19 +08:00
|
|
|
}
|
|
|
|
|
2011-11-15 19:38:59 +08:00
|
|
|
// We need to copy the isl_ids for the parameter dimensions to the new
|
|
|
|
// map. Without doing this the current map would have different
|
|
|
|
// ids then the new one, even though both are named identically.
|
|
|
|
for (unsigned i = 0; i < isl_map_dim(currentAccessMap, isl_dim_param);
|
|
|
|
i++) {
|
|
|
|
isl_id *id = isl_map_get_dim_id(currentAccessMap, isl_dim_param, i);
|
|
|
|
newAccessMap = isl_map_set_dim_id(newAccessMap, isl_dim_param, i, id);
|
|
|
|
}
|
|
|
|
|
2012-05-29 17:29:44 +08:00
|
|
|
// Copy the old tuple id. This is necessary to retain the user pointer,
|
|
|
|
// that stores the reference to the ScopStmt this access belongs to.
|
|
|
|
isl_id *Id = isl_map_get_tuple_id(currentAccessMap, isl_dim_in);
|
|
|
|
newAccessMap = isl_map_set_tuple_id(newAccessMap, isl_dim_in, Id);
|
|
|
|
|
2011-10-06 08:03:35 +08:00
|
|
|
if (!isl_map_has_equal_space(currentAccessMap, newAccessMap)) {
|
2011-08-15 10:33:39 +08:00
|
|
|
errs() << "JScop file contains access function with incompatible "
|
|
|
|
<< "dimensions\n";
|
2011-10-06 08:04:11 +08:00
|
|
|
isl_map_free(currentAccessMap);
|
2011-08-20 19:11:25 +08:00
|
|
|
isl_map_free(newAccessMap);
|
2011-08-15 10:33:39 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-04 15:44:35 +08:00
|
|
|
|
|
|
|
auto NewAccessDomain = isl_map_domain(isl_map_copy(newAccessMap));
|
|
|
|
auto CurrentAccessDomain = isl_map_domain(isl_map_copy(currentAccessMap));
|
|
|
|
|
|
|
|
NewAccessDomain =
|
|
|
|
isl_set_intersect_params(NewAccessDomain, S.getContext());
|
|
|
|
CurrentAccessDomain =
|
|
|
|
isl_set_intersect_params(CurrentAccessDomain, S.getContext());
|
|
|
|
|
|
|
|
if (isl_set_is_subset(CurrentAccessDomain, NewAccessDomain) ==
|
|
|
|
isl_bool_false) {
|
|
|
|
errs() << "Mapping not defined for all iteration domain elements\n";
|
|
|
|
isl_set_free(CurrentAccessDomain);
|
|
|
|
isl_set_free(NewAccessDomain);
|
|
|
|
isl_map_free(currentAccessMap);
|
|
|
|
isl_map_free(newAccessMap);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
isl_set_free(CurrentAccessDomain);
|
|
|
|
isl_set_free(NewAccessDomain);
|
|
|
|
|
2011-07-13 01:14:03 +08:00
|
|
|
if (!isl_map_is_equal(newAccessMap, currentAccessMap)) {
|
|
|
|
// Statistics.
|
|
|
|
++NewAccessMapFound;
|
2011-08-20 19:11:25 +08:00
|
|
|
newAccessStrings.push_back(accesses.asCString());
|
2014-06-14 02:01:45 +08:00
|
|
|
MA->setNewAccessRelation(newAccessMap);
|
2011-08-20 19:11:25 +08:00
|
|
|
} else {
|
|
|
|
isl_map_free(newAccessMap);
|
2011-07-13 01:14:03 +08:00
|
|
|
}
|
2011-10-06 08:04:11 +08:00
|
|
|
isl_map_free(currentAccessMap);
|
2011-07-13 01:14:03 +08:00
|
|
|
memoryAccessIdx++;
|
|
|
|
}
|
|
|
|
statementIdx++;
|
|
|
|
}
|
|
|
|
|
2011-04-29 14:27:02 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JSONImporter::getAnalysisUsage(AnalysisUsage &AU) const {
|
|
|
|
ScopPass::getAnalysisUsage(AU);
|
2015-03-05 06:43:40 +08:00
|
|
|
AU.addRequired<DependenceInfo>();
|
2011-04-29 14:27:02 +08:00
|
|
|
}
|
2015-09-27 23:43:29 +08:00
|
|
|
|
2013-03-23 09:05:07 +08:00
|
|
|
Pass *polly::createJSONImporterPass() { return new JSONImporter(); }
|
|
|
|
|
|
|
|
INITIALIZE_PASS_BEGIN(JSONExporter, "polly-export-jscop",
|
|
|
|
"Polly - Export Scops as JSON"
|
|
|
|
" (Writes a .jscop file for each Scop)",
|
|
|
|
false, false);
|
2015-03-05 06:43:40 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DependenceInfo)
|
2013-03-23 09:05:07 +08:00
|
|
|
INITIALIZE_PASS_END(JSONExporter, "polly-export-jscop",
|
|
|
|
"Polly - Export Scops as JSON"
|
|
|
|
" (Writes a .jscop file for each Scop)",
|
|
|
|
false, false)
|
|
|
|
|
2011-11-15 19:38:36 +08:00
|
|
|
INITIALIZE_PASS_BEGIN(JSONImporter, "polly-import-jscop",
|
|
|
|
"Polly - Import Scops from JSON"
|
2013-03-23 09:05:07 +08:00
|
|
|
" (Reads a .jscop file for each Scop)",
|
|
|
|
false, false);
|
2015-03-05 06:43:40 +08:00
|
|
|
INITIALIZE_PASS_DEPENDENCY(DependenceInfo)
|
2011-11-15 19:38:36 +08:00
|
|
|
INITIALIZE_PASS_END(JSONImporter, "polly-import-jscop",
|
|
|
|
"Polly - Import Scops from JSON"
|
2013-03-23 09:05:07 +08:00
|
|
|
" (Reads a .jscop file for each Scop)",
|
|
|
|
false, false)
|