summaryrefslogtreecommitdiffstats
path: root/polly/lib/Exchange/JSONExporter.cpp
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2016-07-21 06:56:28 +0000
committerTobias Grosser <tobias@grosser.es>2016-07-21 06:56:28 +0000
commitc602d3bc8438533e06787b1d8d2474648d265b61 (patch)
tree6128b460a763f4fa22ca40e80a23a6c2b36222f7 /polly/lib/Exchange/JSONExporter.cpp
parent076fe157578c76684bd743e1551958cbe91b6fcb (diff)
downloadbcm5719-llvm-c602d3bc8438533e06787b1d8d2474648d265b61.tar.gz
bcm5719-llvm-c602d3bc8438533e06787b1d8d2474648d265b61.zip
JScop: Factor out importSchedule [NFC]
This makes the structure of the code clearer and reduces the size of runOnScop. We also adjust the coding style to the latest LLVM style guide. llvm-svn: 276244
Diffstat (limited to 'polly/lib/Exchange/JSONExporter.cpp')
-rw-r--r--polly/lib/Exchange/JSONExporter.cpp97
1 files changed, 58 insertions, 39 deletions
diff --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp
index 11ee29761a8..6dd2749d72e 100644
--- a/polly/lib/Exchange/JSONExporter.cpp
+++ b/polly/lib/Exchange/JSONExporter.cpp
@@ -76,6 +76,18 @@ struct JSONImporter : public ScopPass {
std::vector<std::string> newAccessStrings;
explicit JSONImporter() : ScopPass(ID) {}
+ /// Import a new schedule from JScop.
+ ///
+ /// ... and verify that the new schedule does preserve existing data
+ /// dependences.
+ ///
+ /// @param S The scop to update.
+ /// @param JScop The JScop file describing the new schedule.
+ /// @param D The data dependences of the @p S.
+ ///
+ /// @returns True if the import succeeded, otherwise False.
+ bool importSchedule(Scop &S, Json::Value &JScop, const Dependences &D);
+
std::string getFileName(Scop &S) const;
/// @brief Import new access functions for SCoP @p S from a JSON file.
@@ -197,6 +209,50 @@ void JSONImporter::printScop(raw_ostream &OS, Scop &S) const {
typedef Dependences::StatementToIslMapTy StatementToIslMapTy;
+bool JSONImporter::importSchedule(Scop &S, Json::Value &JScop,
+ const Dependences &D) {
+ StatementToIslMapTy NewSchedule;
+
+ int Index = 0;
+ for (ScopStmt &Stmt : S) {
+ Json::Value Schedule = JScop["statements"][Index]["schedule"];
+ isl_map *Map = isl_map_read_from_str(S.getIslCtx(), Schedule.asCString());
+ isl_space *Space = Stmt.getDomainSpace();
+
+ // Copy the old tuple id. This is necessary to retain the user pointer,
+ // that stores the reference to the ScopStmt this schedule belongs to.
+ Map = isl_map_set_tuple_id(Map, isl_dim_in,
+ isl_space_get_tuple_id(Space, isl_dim_set));
+ 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);
+ Map = isl_map_set_dim_id(Map, isl_dim_param, i, Id);
+ }
+ isl_space_free(Space);
+ NewSchedule[&Stmt] = Map;
+ Index++;
+ }
+
+ if (!D.isValidSchedule(S, &NewSchedule)) {
+ errs() << "JScop file contains a schedule that changes the "
+ << "dependences. Use -disable-polly-legality to continue anyways\n";
+ for (auto Element : NewSchedule)
+ isl_map_free(Element.second);
+ return false;
+ }
+
+ auto ScheduleMap = isl_union_map_empty(S.getParamSpace());
+ for (ScopStmt &Stmt : S) {
+ if (NewSchedule.find(&Stmt) != NewSchedule.end())
+ ScheduleMap = isl_union_map_add_map(ScheduleMap, NewSchedule[&Stmt]);
+ else
+ ScheduleMap = isl_union_map_add_map(ScheduleMap, Stmt.getSchedule());
+ }
+
+ S.setSchedule(ScheduleMap);
+
+ return true;
+}
+
bool JSONImporter::runOnScop(Scop &S) {
const Dependences &D =
getAnalysis<DependenceInfo>().getDependences(Dependences::AL_Statement);
@@ -238,47 +294,10 @@ bool JSONImporter::runOnScop(Scop &S) {
isl_set_free(OldContext);
S.setContext(NewContext);
- StatementToIslMapTy NewSchedule;
-
- int index = 0;
-
- for (ScopStmt &Stmt : S) {
- Json::Value schedule = jscop["statements"][index]["schedule"];
- isl_map *m = isl_map_read_from_str(S.getIslCtx(), schedule.asCString());
- isl_space *Space = Stmt.getDomainSpace();
-
- // Copy the old tuple id. This is necessary to retain the user pointer,
- // that stores the reference to the ScopStmt this schedule belongs to.
- m = isl_map_set_tuple_id(m, isl_dim_in,
- isl_space_get_tuple_id(Space, isl_dim_set));
- 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);
- }
- isl_space_free(Space);
- NewSchedule[&Stmt] = m;
- index++;
- }
+ bool Success = importSchedule(S, jscop, D);
- if (!D.isValidSchedule(S, &NewSchedule)) {
- errs() << "JScop file contains a schedule that changes the "
- << "dependences. Use -disable-polly-legality to continue anyways\n";
- for (StatementToIslMapTy::iterator SI = NewSchedule.begin(),
- SE = NewSchedule.end();
- SI != SE; ++SI)
- isl_map_free(SI->second);
+ if (!Success)
return false;
- }
-
- auto ScheduleMap = isl_union_map_empty(S.getParamSpace());
- for (ScopStmt &Stmt : S) {
- if (NewSchedule.find(&Stmt) != NewSchedule.end())
- ScheduleMap = isl_union_map_add_map(ScheduleMap, NewSchedule[&Stmt]);
- else
- ScheduleMap = isl_union_map_add_map(ScheduleMap, Stmt.getSchedule());
- }
-
- S.setSchedule(ScheduleMap);
int statementIdx = 0;
for (ScopStmt &Stmt : S) {
OpenPOWER on IntegriCloud