[Polly][Isl] Replacing isl method `to_str()` with `stringFromIslObj()`. NFC.

This is part of an effort to reduce the differences between the custom C++ bindings used right now by polly in `lib/External/isl/include/isl/isl-noxceptions.h` and the official isl C++ interface.

Changes made:
 - Removing method `to_str()` from all the classes in the isl C++ bindings.
 - Overload method `stringFromIslObj()` so it accepts isl C++ objects.
 - To keep backward compatibility `stringFromIslObj()` now accepts a value that is returned if the isl C object is `null` or doesn't have a string representation (by default it's an empty string). In some cases it's better to have the string "null" instead of an empty string.
 - isl-noexceptions.h has been generated by this d33ec3a3bb

Reviewed By: Meinersbur

Differential Revision: https://reviews.llvm.org/D104211
This commit is contained in:
patacca 2021-06-15 14:21:40 +02:00
parent ccda8c71b2
commit cfe117def7
9 changed files with 102 additions and 596 deletions

View File

@ -150,71 +150,93 @@ inline llvm::APInt APIntFromVal(isl::val V) {
/// Get c++ string from Isl objects. /// Get c++ string from Isl objects.
//@{ //@{
std::string stringFromIslObj(__isl_keep isl_map *map); #define ISL_CPP_OBJECT_TO_STRING(name) \
std::string stringFromIslObj(__isl_keep isl_union_map *umap); inline std::string stringFromIslObj(const name &Obj, \
std::string stringFromIslObj(__isl_keep isl_set *set); std::string DefaultValue = "") { \
std::string stringFromIslObj(__isl_keep isl_union_set *uset); return stringFromIslObj(Obj.get(), DefaultValue); \
std::string stringFromIslObj(__isl_keep isl_schedule *schedule); }
std::string stringFromIslObj(__isl_keep isl_multi_aff *maff);
std::string stringFromIslObj(__isl_keep isl_pw_multi_aff *pma); #define ISL_OBJECT_TO_STRING(name) \
std::string stringFromIslObj(__isl_keep isl_multi_pw_aff *mpa); std::string stringFromIslObj(__isl_keep isl_##name *Obj, \
std::string stringFromIslObj(__isl_keep isl_union_pw_multi_aff *upma); std::string DefaultValue = ""); \
std::string stringFromIslObj(__isl_keep isl_aff *aff); ISL_CPP_OBJECT_TO_STRING(isl::name)
std::string stringFromIslObj(__isl_keep isl_pw_aff *pwaff);
std::string stringFromIslObj(__isl_keep isl_space *space); ISL_OBJECT_TO_STRING(aff)
ISL_OBJECT_TO_STRING(ast_expr)
ISL_OBJECT_TO_STRING(ast_node)
ISL_OBJECT_TO_STRING(basic_map)
ISL_OBJECT_TO_STRING(basic_set)
ISL_OBJECT_TO_STRING(map)
ISL_OBJECT_TO_STRING(set)
ISL_OBJECT_TO_STRING(id)
ISL_OBJECT_TO_STRING(multi_aff)
ISL_OBJECT_TO_STRING(multi_pw_aff)
ISL_OBJECT_TO_STRING(multi_union_pw_aff)
ISL_OBJECT_TO_STRING(point)
ISL_OBJECT_TO_STRING(pw_aff)
ISL_OBJECT_TO_STRING(pw_multi_aff)
ISL_OBJECT_TO_STRING(schedule)
ISL_OBJECT_TO_STRING(schedule_node)
ISL_OBJECT_TO_STRING(space)
ISL_OBJECT_TO_STRING(union_access_info)
ISL_OBJECT_TO_STRING(union_flow)
ISL_OBJECT_TO_STRING(union_set)
ISL_OBJECT_TO_STRING(union_map)
ISL_OBJECT_TO_STRING(union_pw_aff)
ISL_OBJECT_TO_STRING(union_pw_multi_aff)
//@} //@}
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_union_map *Map) { __isl_keep isl_union_map *Map) {
OS << polly::stringFromIslObj(Map); OS << polly::stringFromIslObj(Map, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_map *Map) { __isl_keep isl_map *Map) {
OS << polly::stringFromIslObj(Map); OS << polly::stringFromIslObj(Map, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_set *Set) { __isl_keep isl_set *Set) {
OS << polly::stringFromIslObj(Set); OS << polly::stringFromIslObj(Set, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_pw_aff *Map) { __isl_keep isl_pw_aff *Map) {
OS << polly::stringFromIslObj(Map); OS << polly::stringFromIslObj(Map, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_pw_multi_aff *PMA) { __isl_keep isl_pw_multi_aff *PMA) {
OS << polly::stringFromIslObj(PMA); OS << polly::stringFromIslObj(PMA, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_multi_aff *MA) { __isl_keep isl_multi_aff *MA) {
OS << polly::stringFromIslObj(MA); OS << polly::stringFromIslObj(MA, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_union_pw_multi_aff *UPMA) { __isl_keep isl_union_pw_multi_aff *UPMA) {
OS << polly::stringFromIslObj(UPMA); OS << polly::stringFromIslObj(UPMA, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_schedule *Schedule) { __isl_keep isl_schedule *Schedule) {
OS << polly::stringFromIslObj(Schedule); OS << polly::stringFromIslObj(Schedule, "null");
return OS; return OS;
} }
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
__isl_keep isl_space *Space) { __isl_keep isl_space *Space) {
OS << polly::stringFromIslObj(Space); OS << polly::stringFromIslObj(Space, "null");
return OS; return OS;
} }
@ -263,7 +285,7 @@ std::string getIslCompatibleName(const std::string &Prefix,
inline llvm::DiagnosticInfoOptimizationBase & inline llvm::DiagnosticInfoOptimizationBase &
operator<<(llvm::DiagnosticInfoOptimizationBase &OS, operator<<(llvm::DiagnosticInfoOptimizationBase &OS,
const isl::union_map &Obj) { const isl::union_map &Obj) {
OS << Obj.to_str(); OS << stringFromIslObj(Obj);
return OS; return OS;
} }

View File

@ -10,6 +10,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "polly/Support/GICHelper.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "isl/isl-noexceptions.h" #include "isl/isl-noexceptions.h"
namespace polly { namespace polly {
@ -17,7 +18,7 @@ namespace polly {
#define ADD_OSTREAM_PRINTER(name) \ #define ADD_OSTREAM_PRINTER(name) \
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, \ inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, \
const name &Obj) { \ const name &Obj) { \
OS << Obj.to_str(); \ OS << stringFromIslObj(Obj); \
return OS; \ return OS; \
} }

View File

@ -86,10 +86,12 @@ bool PolyhedralInfo::checkParallel(Loop *L, isl_pw_aff **MinDepDistPtr) const {
Dependences::TYPE_WAR | Dependences::TYPE_RED) Dependences::TYPE_WAR | Dependences::TYPE_RED)
.release(); .release();
LLVM_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps) << "\n"); LLVM_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
<< "\n");
isl_union_map *Schedule = getScheduleForLoop(S, L); isl_union_map *Schedule = getScheduleForLoop(S, L);
LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule) << "\n"); LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
<< "\n");
IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr); IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr);
isl_union_map_free(Schedule); isl_union_map_free(Schedule);

View File

@ -1615,7 +1615,8 @@ void ScopBuilder::addUserAssumptions(
} }
} }
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "UserAssumption", CI) ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "UserAssumption", CI)
<< "Use user assumption: " << stringFromIslObj(AssumptionCtx)); << "Use user assumption: "
<< stringFromIslObj(AssumptionCtx, "null"));
isl::set newContext = isl::set newContext =
scop->getContext().intersect(isl::manage(AssumptionCtx)); scop->getContext().intersect(isl::manage(AssumptionCtx));
scop->setContext(newContext); scop->setContext(newContext);
@ -2869,7 +2870,7 @@ void ScopBuilder::addUserContext() {
isl::set UserContext = isl::set(scop->getIslCtx(), UserContextStr.c_str()); isl::set UserContext = isl::set(scop->getIslCtx(), UserContextStr.c_str());
isl::space Space = scop->getParamSpace(); isl::space Space = scop->getParamSpace();
if (Space.dim(isl::dim::param) != UserContext.dim(isl::dim::param)) { if (Space.dim(isl::dim::param) != UserContext.dim(isl::dim::param)) {
std::string SpaceStr = Space.to_str(); std::string SpaceStr = stringFromIslObj(Space, "null");
errs() << "Error: the context provided in -polly-context has not the same " errs() << "Error: the context provided in -polly-context has not the same "
<< "number of dimensions than the computed context. Due to this " << "number of dimensions than the computed context. Due to this "
<< "mismatch, the -polly-context option is ignored. Please provide " << "mismatch, the -polly-context option is ignored. Please provide "
@ -2883,7 +2884,7 @@ void ScopBuilder::addUserContext() {
std::string NameUserContext = UserContext.get_dim_name(isl::dim::param, i); std::string NameUserContext = UserContext.get_dim_name(isl::dim::param, i);
if (NameContext != NameUserContext) { if (NameContext != NameUserContext) {
std::string SpaceStr = Space.to_str(); std::string SpaceStr = stringFromIslObj(Space, "null");
errs() << "Error: the name of dimension " << i errs() << "Error: the name of dimension " << i
<< " provided in -polly-context " << " provided in -polly-context "
<< "is '" << NameUserContext << "', but the name in the computed " << "is '" << NameUserContext << "', but the name in the computed "

View File

@ -618,7 +618,7 @@ isl::map MemoryAccess::getOriginalAccessRelation() const {
} }
std::string MemoryAccess::getOriginalAccessRelationStr() const { std::string MemoryAccess::getOriginalAccessRelationStr() const {
return AccessRelation.to_str(); return stringFromIslObj(AccessRelation);
} }
isl::space MemoryAccess::getOriginalAccessRelationSpace() const { isl::space MemoryAccess::getOriginalAccessRelationSpace() const {
@ -630,11 +630,11 @@ isl::map MemoryAccess::getNewAccessRelation() const {
} }
std::string MemoryAccess::getNewAccessRelationStr() const { std::string MemoryAccess::getNewAccessRelationStr() const {
return NewAccessRelation.to_str(); return stringFromIslObj(NewAccessRelation);
} }
std::string MemoryAccess::getAccessRelationStr() const { std::string MemoryAccess::getAccessRelationStr() const {
return getAccessRelation().to_str(); return stringFromIslObj(getAccessRelation());
} }
isl::basic_map MemoryAccess::createBasicAccessMap(ScopStmt *Statement) { isl::basic_map MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
@ -1233,15 +1233,10 @@ ScopStmt::ScopStmt(Scop &parent, isl::map SourceRel, isl::map TargetRel,
ScopStmt::~ScopStmt() = default; ScopStmt::~ScopStmt() = default;
std::string ScopStmt::getDomainStr() const { return Domain.to_str(); } std::string ScopStmt::getDomainStr() const { return stringFromIslObj(Domain); }
std::string ScopStmt::getScheduleStr() const { std::string ScopStmt::getScheduleStr() const {
auto *S = getSchedule().release(); return stringFromIslObj(getSchedule());
if (!S)
return {};
auto Str = stringFromIslObj(S);
isl_map_free(S);
return Str;
} }
void ScopStmt::setInvalidDomain(isl::set ID) { InvalidDomain = ID; } void ScopStmt::setInvalidDomain(isl::set ID) { InvalidDomain = ID; }
@ -1892,15 +1887,17 @@ ScopArrayInfo *Scop::getScopArrayInfo(Value *BasePtr, MemoryKind Kind) {
return SAI; return SAI;
} }
std::string Scop::getContextStr() const { return getContext().to_str(); } std::string Scop::getContextStr() const {
return stringFromIslObj(getContext());
}
std::string Scop::getAssumedContextStr() const { std::string Scop::getAssumedContextStr() const {
assert(!AssumedContext.is_null() && "Assumed context not yet built"); assert(!AssumedContext.is_null() && "Assumed context not yet built");
return AssumedContext.to_str(); return stringFromIslObj(AssumedContext);
} }
std::string Scop::getInvalidContextStr() const { std::string Scop::getInvalidContextStr() const {
return InvalidContext.to_str(); return stringFromIslObj(InvalidContext);
} }
std::string Scop::getNameStr() const { std::string Scop::getNameStr() const {
@ -2103,7 +2100,7 @@ bool Scop::trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
} }
auto Suffix = Sign == AS_ASSUMPTION ? " assumption:\t" : " restriction:\t"; auto Suffix = Sign == AS_ASSUMPTION ? " assumption:\t" : " restriction:\t";
std::string Msg = toString(Kind) + Suffix + Set.to_str(); std::string Msg = toString(Kind) + Suffix + stringFromIslObj(Set);
if (BB) if (BB)
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AssumpRestrict", Loc, BB) ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AssumpRestrict", Loc, BB)
<< Msg); << Msg);

View File

@ -766,11 +766,9 @@ void IslAstInfo::print(raw_ostream &OS) {
P = isl_ast_node_print(RootNode.get(), P, Options); P = isl_ast_node_print(RootNode.get(), P, Options);
AstStr = isl_printer_get_str(P); AstStr = isl_printer_get_str(P);
auto *Schedule = S.getScheduleTree().release();
LLVM_DEBUG({ LLVM_DEBUG({
dbgs() << S.getContextStr() << "\n"; dbgs() << S.getContextStr() << "\n";
dbgs() << stringFromIslObj(Schedule); dbgs() << stringFromIslObj(S.getScheduleTree(), "null");
}); });
OS << "\nif (" << RtCStr << ")\n\n"; OS << "\nif (" << RtCStr << ")\n\n";
OS << AstStr << "\n"; OS << AstStr << "\n";
@ -780,7 +778,6 @@ void IslAstInfo::print(raw_ostream &OS) {
free(RtCStr); free(RtCStr);
free(AstStr); free(AstStr);
isl_schedule_free(Schedule);
isl_printer_free(P); isl_printer_free(P);
} }

File diff suppressed because it is too large Load Diff

View File

@ -85,9 +85,10 @@ APInt polly::APIntFromVal(__isl_take isl_val *Val) {
template <typename ISLTy, typename ISL_CTX_GETTER, typename ISL_PRINTER> template <typename ISLTy, typename ISL_CTX_GETTER, typename ISL_PRINTER>
static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj, static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
ISL_CTX_GETTER ctx_getter_fn, ISL_CTX_GETTER ctx_getter_fn,
ISL_PRINTER printer_fn) { ISL_PRINTER printer_fn,
std::string DefaultValue) {
if (!isl_obj) if (!isl_obj)
return "null"; return DefaultValue;
isl_ctx *ctx = ctx_getter_fn(isl_obj); isl_ctx *ctx = ctx_getter_fn(isl_obj);
isl_printer *p = isl_printer_to_str(ctx); isl_printer *p = isl_printer_to_str(ctx);
p = printer_fn(p, isl_obj); p = printer_fn(p, isl_obj);
@ -96,68 +97,42 @@ static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
if (char_str) if (char_str)
string = char_str; string = char_str;
else else
string = "null"; string = DefaultValue;
free(char_str); free(char_str);
isl_printer_free(p); isl_printer_free(p);
return string; return string;
} }
std::string polly::stringFromIslObj(__isl_keep isl_map *map) { #define ISL_C_OBJECT_TO_STRING(name) \
return stringFromIslObjInternal(map, isl_map_get_ctx, isl_printer_print_map); std::string polly::stringFromIslObj(__isl_keep isl_##name *Obj, \
} std::string DefaultValue) { \
return stringFromIslObjInternal(Obj, isl_##name##_get_ctx, \
isl_printer_print_##name, DefaultValue); \
}
std::string polly::stringFromIslObj(__isl_keep isl_set *set) { ISL_C_OBJECT_TO_STRING(aff)
return stringFromIslObjInternal(set, isl_set_get_ctx, isl_printer_print_set); ISL_C_OBJECT_TO_STRING(ast_expr)
} ISL_C_OBJECT_TO_STRING(ast_node)
ISL_C_OBJECT_TO_STRING(basic_map)
std::string polly::stringFromIslObj(__isl_keep isl_union_map *umap) { ISL_C_OBJECT_TO_STRING(basic_set)
return stringFromIslObjInternal(umap, isl_union_map_get_ctx, ISL_C_OBJECT_TO_STRING(map)
isl_printer_print_union_map); ISL_C_OBJECT_TO_STRING(set)
} ISL_C_OBJECT_TO_STRING(id)
ISL_C_OBJECT_TO_STRING(multi_aff)
std::string polly::stringFromIslObj(__isl_keep isl_union_set *uset) { ISL_C_OBJECT_TO_STRING(multi_pw_aff)
return stringFromIslObjInternal(uset, isl_union_set_get_ctx, ISL_C_OBJECT_TO_STRING(multi_union_pw_aff)
isl_printer_print_union_set); ISL_C_OBJECT_TO_STRING(point)
} ISL_C_OBJECT_TO_STRING(pw_aff)
ISL_C_OBJECT_TO_STRING(pw_multi_aff)
std::string polly::stringFromIslObj(__isl_keep isl_schedule *schedule) { ISL_C_OBJECT_TO_STRING(schedule)
return stringFromIslObjInternal(schedule, isl_schedule_get_ctx, ISL_C_OBJECT_TO_STRING(schedule_node)
isl_printer_print_schedule); ISL_C_OBJECT_TO_STRING(space)
} ISL_C_OBJECT_TO_STRING(union_access_info)
ISL_C_OBJECT_TO_STRING(union_flow)
std::string polly::stringFromIslObj(__isl_keep isl_multi_aff *maff) { ISL_C_OBJECT_TO_STRING(union_set)
return stringFromIslObjInternal(maff, isl_multi_aff_get_ctx, ISL_C_OBJECT_TO_STRING(union_map)
isl_printer_print_multi_aff); ISL_C_OBJECT_TO_STRING(union_pw_aff)
} ISL_C_OBJECT_TO_STRING(union_pw_multi_aff)
std::string polly::stringFromIslObj(__isl_keep isl_pw_multi_aff *pma) {
return stringFromIslObjInternal(pma, isl_pw_multi_aff_get_ctx,
isl_printer_print_pw_multi_aff);
}
std::string polly::stringFromIslObj(__isl_keep isl_multi_pw_aff *mpa) {
return stringFromIslObjInternal(mpa, isl_multi_pw_aff_get_ctx,
isl_printer_print_multi_pw_aff);
}
std::string polly::stringFromIslObj(__isl_keep isl_union_pw_multi_aff *upma) {
return stringFromIslObjInternal(upma, isl_union_pw_multi_aff_get_ctx,
isl_printer_print_union_pw_multi_aff);
}
std::string polly::stringFromIslObj(__isl_keep isl_aff *aff) {
return stringFromIslObjInternal(aff, isl_aff_get_ctx, isl_printer_print_aff);
}
std::string polly::stringFromIslObj(__isl_keep isl_pw_aff *pwaff) {
return stringFromIslObjInternal(pwaff, isl_pw_aff_get_ctx,
isl_printer_print_pw_aff);
}
std::string polly::stringFromIslObj(__isl_keep isl_space *space) {
return stringFromIslObjInternal(space, isl_space_get_ctx,
isl_printer_print_space);
}
static void replace(std::string &str, const std::string &find, static void replace(std::string &str, const std::string &find,
const std::string &replace) { const std::string &replace) {

View File

@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "polly/Support/ISLTools.h" #include "polly/Support/ISLTools.h"
#include "polly/Support/GICHelper.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include <cassert> #include <cassert>
#include <vector> #include <vector>
@ -760,9 +761,9 @@ static void printSortedPolyhedra(isl::union_set USet, llvm::raw_ostream &OS,
for (const isl::basic_set &BSet : BSets) { for (const isl::basic_set &BSet : BSets) {
std::string Str; std::string Str;
if (IsMap) if (IsMap)
Str = isl::map(BSet.unwrap()).to_str(); Str = stringFromIslObj(isl::map(BSet.unwrap()));
else else
Str = isl::set(BSet).to_str(); Str = stringFromIslObj(isl::set(BSet));
size_t OpenPos = Str.find_first_of('{'); size_t OpenPos = Str.find_first_of('{');
assert(OpenPos != std::string::npos); assert(OpenPos != std::string::npos);
size_t ClosePos = Str.find_last_of('}'); size_t ClosePos = Str.find_last_of('}');