Beispiel #1
0
CloogUnionDomain *Cloog::buildCloogUnionDomain() {
  CloogUnionDomain *DU = cloog_union_domain_alloc(S->getNumParams());

  for (Scop::iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI) {
    ScopStmt *Stmt = *SI;
    CloogScattering *Scattering;
    CloogDomain *Domain;

    Scattering = cloog_scattering_from_isl_map(Stmt->getScattering());
    Domain = cloog_domain_from_isl_set(Stmt->getDomain());

    std::string entryName = Stmt->getBaseName();

    DU = cloog_union_domain_add_domain(DU, entryName.c_str(), Domain,
                                       Scattering, Stmt);
  }

  return DU;
}
Beispiel #2
0
CloogUnionDomain *Cloog::buildCloogUnionDomain() {
  CloogUnionDomain *DU = cloog_union_domain_alloc(S->getNumParams());

  for (Scop::iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI) {
    ScopStmt *Stmt = *SI;

    if (Stmt->isFinalRead())
      continue;

    CloogScattering *Scattering=
      cloog_scattering_from_isl_map(isl_map_copy(Stmt->getScattering()));
    CloogDomain *Domain =
      cloog_domain_from_isl_set(isl_set_copy(Stmt->getDomain()));

    std::string entryName = Stmt->getBaseName();
    char *Name = (char*)malloc(sizeof(char) * (entryName.size() + 1));
    strcpy(Name, entryName.c_str());

    DU = cloog_union_domain_add_domain(DU, Name, Domain, Scattering, Stmt);
  }

  return DU;
}
Beispiel #3
0
bool Pocc::runTransform(Scop &S) {
  Dependences *D = &getAnalysis<Dependences>();

  // Create the scop file.
  SmallString<128> TempDir;
  SmallString<128> ScopFile;
  llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/true, TempDir);
  ScopFile = TempDir;
  llvm::sys::path::append(ScopFile, "polly.scop");

  FILE *F = fopen(ScopFile.c_str(), "w");

  arguments.clear();

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

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

  // Execute pocc
  std::string pocc = sys::FindProgramByName("pocc");

  arguments.push_back("pocc");
  arguments.push_back("--read-scop");
  arguments.push_back(ScopFile.c_str());
  arguments.push_back("--pluto-tile-scat");
  arguments.push_back("--candl-dep-isl-simp");
  arguments.push_back("--cloogify-scheds");
  arguments.push_back("--output-scop");
  arguments.push_back("--pluto");
  arguments.push_back("--pluto-bounds");
  arguments.push_back("10");
  arguments.push_back("--pluto-fuse");

  arguments.push_back(PlutoFuse.c_str());

  if (!DisablePollyTiling)
    arguments.push_back("--pluto-tile");

  if (PollyVectorizerChoice != VECTORIZER_NONE)
    arguments.push_back("--pluto-prevector");

  arguments.push_back(0);

  PlutoStdout = TempDir;
  llvm::sys::path::append(PlutoStdout, "pluto.stdout");
  PlutoStderr = TempDir;
  llvm::sys::path::append(PlutoStderr, "pluto.stderr");

  std::vector<llvm::StringRef> Redirect;
  Redirect.push_back(0);
  Redirect.push_back(PlutoStdout.c_str());
  Redirect.push_back(PlutoStderr.c_str());

  sys::ExecuteAndWait(pocc, &arguments[0], 0,
                      (const llvm::StringRef **)&Redirect[0]);

  // Read the created scop file
  SmallString<128> NewScopFile;
  NewScopFile = TempDir;
  llvm::sys::path::append(NewScopFile, "polly.pocc.c.scop");

  FILE *poccFile = fopen(NewScopFile.c_str(), "r");
  ScopLib newScoplib(&S, poccFile, D);

  if (!newScoplib.updateScattering()) {
    errs() << "Failure when calculating the optimization with "
              "the following command: ";
    for (std::vector<const char *>::const_iterator AI = arguments.begin(),
                                                   AE = arguments.end();
         AI != AE; ++AI)
      if (*AI)
        errs() << " " << *AI;
    errs() << "\n";
    return false;
  } else
    fclose(poccFile);

  if (PollyVectorizerChoice == VECTORIZER_NONE)
    return false;

  // Find the innermost dimension that is not a constant dimension. This
  // dimension will be vectorized.
  unsigned scatterDims = S.getScatterDim();
  int lastLoop = scatterDims - 1;

  while (lastLoop) {
    bool isSingleValued = true;

    for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
      isl_map *scat = (*SI)->getScattering();
      isl_map *projected = isl_map_project_out(scat, isl_dim_out, lastLoop,
                                               scatterDims - lastLoop);

      if (!isl_map_is_bijective(projected)) {
        isSingleValued = false;
        break;
      }
    }

    if (!isSingleValued)
      break;

    lastLoop--;
  }

  // Strip mine the innermost loop.
  for (Scop::iterator SI = S.begin(), SE = S.end(); SI != SE; ++SI) {
    isl_map *scat = (*SI)->getScattering();
    int scatDims = (*SI)->getNumScattering();
    isl_space *Space = isl_space_alloc(S.getIslCtx(), S.getNumParams(),
                                       scatDims, scatDims + 1);
    isl_basic_map *map = isl_basic_map_universe(isl_space_copy(Space));
    isl_local_space *LSpace = isl_local_space_from_space(Space);

    for (int i = 0; i <= lastLoop - 1; i++) {
      isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LSpace));

      isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1);
      isl_constraint_set_coefficient_si(c, isl_dim_out, i, -1);

      map = isl_basic_map_add_constraint(map, c);
    }

    for (int i = lastLoop; i < scatDims; i++) {
      isl_constraint *c = isl_equality_alloc(isl_local_space_copy(LSpace));

      isl_constraint_set_coefficient_si(c, isl_dim_in, i, 1);
      isl_constraint_set_coefficient_si(c, isl_dim_out, i + 1, -1);

      map = isl_basic_map_add_constraint(map, c);
    }

    isl_constraint *c;

    int vectorWidth = 4;
    c = isl_inequality_alloc(isl_local_space_copy(LSpace));
    isl_constraint_set_coefficient_si(c, isl_dim_out, lastLoop, -vectorWidth);
    isl_constraint_set_coefficient_si(c, isl_dim_out, lastLoop + 1, 1);
    map = isl_basic_map_add_constraint(map, c);

    c = isl_inequality_alloc(LSpace);
    isl_constraint_set_coefficient_si(c, isl_dim_out, lastLoop, vectorWidth);
    isl_constraint_set_coefficient_si(c, isl_dim_out, lastLoop + 1, -1);
    isl_constraint_set_constant_si(c, vectorWidth - 1);
    map = isl_basic_map_add_constraint(map, c);

    isl_map *transform = isl_map_from_basic_map(map);
    transform = isl_map_set_tuple_name(transform, isl_dim_out, "scattering");
    transform = isl_map_set_tuple_name(transform, isl_dim_in, "scattering");

    scat = isl_map_apply_range(scat, isl_map_copy(transform));
    (*SI)->setScattering(scat);
  }

  return false;
}