Skip to content

Commit cfe117d

Browse files
committed
[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 patacca/isl@d33ec3a Reviewed By: Meinersbur Differential Revision: https://reviews.llvm.org/D104211
1 parent ccda8c7 commit cfe117d

File tree

9 files changed

+102
-596
lines changed

9 files changed

+102
-596
lines changed

polly/include/polly/Support/GICHelper.h

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,71 +150,93 @@ inline llvm::APInt APIntFromVal(isl::val V) {
150150

151151
/// Get c++ string from Isl objects.
152152
//@{
153-
std::string stringFromIslObj(__isl_keep isl_map *map);
154-
std::string stringFromIslObj(__isl_keep isl_union_map *umap);
155-
std::string stringFromIslObj(__isl_keep isl_set *set);
156-
std::string stringFromIslObj(__isl_keep isl_union_set *uset);
157-
std::string stringFromIslObj(__isl_keep isl_schedule *schedule);
158-
std::string stringFromIslObj(__isl_keep isl_multi_aff *maff);
159-
std::string stringFromIslObj(__isl_keep isl_pw_multi_aff *pma);
160-
std::string stringFromIslObj(__isl_keep isl_multi_pw_aff *mpa);
161-
std::string stringFromIslObj(__isl_keep isl_union_pw_multi_aff *upma);
162-
std::string stringFromIslObj(__isl_keep isl_aff *aff);
163-
std::string stringFromIslObj(__isl_keep isl_pw_aff *pwaff);
164-
std::string stringFromIslObj(__isl_keep isl_space *space);
153+
#define ISL_CPP_OBJECT_TO_STRING(name) \
154+
inline std::string stringFromIslObj(const name &Obj, \
155+
std::string DefaultValue = "") { \
156+
return stringFromIslObj(Obj.get(), DefaultValue); \
157+
}
158+
159+
#define ISL_OBJECT_TO_STRING(name) \
160+
std::string stringFromIslObj(__isl_keep isl_##name *Obj, \
161+
std::string DefaultValue = ""); \
162+
ISL_CPP_OBJECT_TO_STRING(isl::name)
163+
164+
ISL_OBJECT_TO_STRING(aff)
165+
ISL_OBJECT_TO_STRING(ast_expr)
166+
ISL_OBJECT_TO_STRING(ast_node)
167+
ISL_OBJECT_TO_STRING(basic_map)
168+
ISL_OBJECT_TO_STRING(basic_set)
169+
ISL_OBJECT_TO_STRING(map)
170+
ISL_OBJECT_TO_STRING(set)
171+
ISL_OBJECT_TO_STRING(id)
172+
ISL_OBJECT_TO_STRING(multi_aff)
173+
ISL_OBJECT_TO_STRING(multi_pw_aff)
174+
ISL_OBJECT_TO_STRING(multi_union_pw_aff)
175+
ISL_OBJECT_TO_STRING(point)
176+
ISL_OBJECT_TO_STRING(pw_aff)
177+
ISL_OBJECT_TO_STRING(pw_multi_aff)
178+
ISL_OBJECT_TO_STRING(schedule)
179+
ISL_OBJECT_TO_STRING(schedule_node)
180+
ISL_OBJECT_TO_STRING(space)
181+
ISL_OBJECT_TO_STRING(union_access_info)
182+
ISL_OBJECT_TO_STRING(union_flow)
183+
ISL_OBJECT_TO_STRING(union_set)
184+
ISL_OBJECT_TO_STRING(union_map)
185+
ISL_OBJECT_TO_STRING(union_pw_aff)
186+
ISL_OBJECT_TO_STRING(union_pw_multi_aff)
165187
//@}
166188

167189
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
168190
__isl_keep isl_union_map *Map) {
169-
OS << polly::stringFromIslObj(Map);
191+
OS << polly::stringFromIslObj(Map, "null");
170192
return OS;
171193
}
172194

173195
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
174196
__isl_keep isl_map *Map) {
175-
OS << polly::stringFromIslObj(Map);
197+
OS << polly::stringFromIslObj(Map, "null");
176198
return OS;
177199
}
178200

179201
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
180202
__isl_keep isl_set *Set) {
181-
OS << polly::stringFromIslObj(Set);
203+
OS << polly::stringFromIslObj(Set, "null");
182204
return OS;
183205
}
184206

185207
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
186208
__isl_keep isl_pw_aff *Map) {
187-
OS << polly::stringFromIslObj(Map);
209+
OS << polly::stringFromIslObj(Map, "null");
188210
return OS;
189211
}
190212

191213
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
192214
__isl_keep isl_pw_multi_aff *PMA) {
193-
OS << polly::stringFromIslObj(PMA);
215+
OS << polly::stringFromIslObj(PMA, "null");
194216
return OS;
195217
}
196218

197219
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
198220
__isl_keep isl_multi_aff *MA) {
199-
OS << polly::stringFromIslObj(MA);
221+
OS << polly::stringFromIslObj(MA, "null");
200222
return OS;
201223
}
202224

203225
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
204226
__isl_keep isl_union_pw_multi_aff *UPMA) {
205-
OS << polly::stringFromIslObj(UPMA);
227+
OS << polly::stringFromIslObj(UPMA, "null");
206228
return OS;
207229
}
208230

209231
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
210232
__isl_keep isl_schedule *Schedule) {
211-
OS << polly::stringFromIslObj(Schedule);
233+
OS << polly::stringFromIslObj(Schedule, "null");
212234
return OS;
213235
}
214236

215237
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
216238
__isl_keep isl_space *Space) {
217-
OS << polly::stringFromIslObj(Space);
239+
OS << polly::stringFromIslObj(Space, "null");
218240
return OS;
219241
}
220242

@@ -263,7 +285,7 @@ std::string getIslCompatibleName(const std::string &Prefix,
263285
inline llvm::DiagnosticInfoOptimizationBase &
264286
operator<<(llvm::DiagnosticInfoOptimizationBase &OS,
265287
const isl::union_map &Obj) {
266-
OS << Obj.to_str();
288+
OS << stringFromIslObj(Obj);
267289
return OS;
268290
}
269291

polly/include/polly/Support/ISLOStream.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
#include "polly/Support/GICHelper.h"
1314
#include "llvm/Support/raw_ostream.h"
1415
#include "isl/isl-noexceptions.h"
1516
namespace polly {
1617

1718
#define ADD_OSTREAM_PRINTER(name) \
1819
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, \
1920
const name &Obj) { \
20-
OS << Obj.to_str(); \
21+
OS << stringFromIslObj(Obj); \
2122
return OS; \
2223
}
2324

polly/lib/Analysis/PolyhedralInfo.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ bool PolyhedralInfo::checkParallel(Loop *L, isl_pw_aff **MinDepDistPtr) const {
8686
Dependences::TYPE_WAR | Dependences::TYPE_RED)
8787
.release();
8888

89-
LLVM_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps) << "\n");
89+
LLVM_DEBUG(dbgs() << "Dependences :\t" << stringFromIslObj(Deps, "null")
90+
<< "\n");
9091

9192
isl_union_map *Schedule = getScheduleForLoop(S, L);
92-
LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule) << "\n");
93+
LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
94+
<< "\n");
9395

9496
IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr);
9597
isl_union_map_free(Schedule);

polly/lib/Analysis/ScopBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,8 @@ void ScopBuilder::addUserAssumptions(
16151615
}
16161616
}
16171617
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "UserAssumption", CI)
1618-
<< "Use user assumption: " << stringFromIslObj(AssumptionCtx));
1618+
<< "Use user assumption: "
1619+
<< stringFromIslObj(AssumptionCtx, "null"));
16191620
isl::set newContext =
16201621
scop->getContext().intersect(isl::manage(AssumptionCtx));
16211622
scop->setContext(newContext);
@@ -2869,7 +2870,7 @@ void ScopBuilder::addUserContext() {
28692870
isl::set UserContext = isl::set(scop->getIslCtx(), UserContextStr.c_str());
28702871
isl::space Space = scop->getParamSpace();
28712872
if (Space.dim(isl::dim::param) != UserContext.dim(isl::dim::param)) {
2872-
std::string SpaceStr = Space.to_str();
2873+
std::string SpaceStr = stringFromIslObj(Space, "null");
28732874
errs() << "Error: the context provided in -polly-context has not the same "
28742875
<< "number of dimensions than the computed context. Due to this "
28752876
<< "mismatch, the -polly-context option is ignored. Please provide "
@@ -2883,7 +2884,7 @@ void ScopBuilder::addUserContext() {
28832884
std::string NameUserContext = UserContext.get_dim_name(isl::dim::param, i);
28842885

28852886
if (NameContext != NameUserContext) {
2886-
std::string SpaceStr = Space.to_str();
2887+
std::string SpaceStr = stringFromIslObj(Space, "null");
28872888
errs() << "Error: the name of dimension " << i
28882889
<< " provided in -polly-context "
28892890
<< "is '" << NameUserContext << "', but the name in the computed "

polly/lib/Analysis/ScopInfo.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ isl::map MemoryAccess::getOriginalAccessRelation() const {
618618
}
619619

620620
std::string MemoryAccess::getOriginalAccessRelationStr() const {
621-
return AccessRelation.to_str();
621+
return stringFromIslObj(AccessRelation);
622622
}
623623

624624
isl::space MemoryAccess::getOriginalAccessRelationSpace() const {
@@ -630,11 +630,11 @@ isl::map MemoryAccess::getNewAccessRelation() const {
630630
}
631631

632632
std::string MemoryAccess::getNewAccessRelationStr() const {
633-
return NewAccessRelation.to_str();
633+
return stringFromIslObj(NewAccessRelation);
634634
}
635635

636636
std::string MemoryAccess::getAccessRelationStr() const {
637-
return getAccessRelation().to_str();
637+
return stringFromIslObj(getAccessRelation());
638638
}
639639

640640
isl::basic_map MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
@@ -1233,15 +1233,10 @@ ScopStmt::ScopStmt(Scop &parent, isl::map SourceRel, isl::map TargetRel,
12331233

12341234
ScopStmt::~ScopStmt() = default;
12351235

1236-
std::string ScopStmt::getDomainStr() const { return Domain.to_str(); }
1236+
std::string ScopStmt::getDomainStr() const { return stringFromIslObj(Domain); }
12371237

12381238
std::string ScopStmt::getScheduleStr() const {
1239-
auto *S = getSchedule().release();
1240-
if (!S)
1241-
return {};
1242-
auto Str = stringFromIslObj(S);
1243-
isl_map_free(S);
1244-
return Str;
1239+
return stringFromIslObj(getSchedule());
12451240
}
12461241

12471242
void ScopStmt::setInvalidDomain(isl::set ID) { InvalidDomain = ID; }
@@ -1892,15 +1887,17 @@ ScopArrayInfo *Scop::getScopArrayInfo(Value *BasePtr, MemoryKind Kind) {
18921887
return SAI;
18931888
}
18941889

1895-
std::string Scop::getContextStr() const { return getContext().to_str(); }
1890+
std::string Scop::getContextStr() const {
1891+
return stringFromIslObj(getContext());
1892+
}
18961893

18971894
std::string Scop::getAssumedContextStr() const {
18981895
assert(!AssumedContext.is_null() && "Assumed context not yet built");
1899-
return AssumedContext.to_str();
1896+
return stringFromIslObj(AssumedContext);
19001897
}
19011898

19021899
std::string Scop::getInvalidContextStr() const {
1903-
return InvalidContext.to_str();
1900+
return stringFromIslObj(InvalidContext);
19041901
}
19051902

19061903
std::string Scop::getNameStr() const {
@@ -2103,7 +2100,7 @@ bool Scop::trackAssumption(AssumptionKind Kind, isl::set Set, DebugLoc Loc,
21032100
}
21042101

21052102
auto Suffix = Sign == AS_ASSUMPTION ? " assumption:\t" : " restriction:\t";
2106-
std::string Msg = toString(Kind) + Suffix + Set.to_str();
2103+
std::string Msg = toString(Kind) + Suffix + stringFromIslObj(Set);
21072104
if (BB)
21082105
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AssumpRestrict", Loc, BB)
21092106
<< Msg);

polly/lib/CodeGen/IslAst.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -766,11 +766,9 @@ void IslAstInfo::print(raw_ostream &OS) {
766766
P = isl_ast_node_print(RootNode.get(), P, Options);
767767
AstStr = isl_printer_get_str(P);
768768

769-
auto *Schedule = S.getScheduleTree().release();
770-
771769
LLVM_DEBUG({
772770
dbgs() << S.getContextStr() << "\n";
773-
dbgs() << stringFromIslObj(Schedule);
771+
dbgs() << stringFromIslObj(S.getScheduleTree(), "null");
774772
});
775773
OS << "\nif (" << RtCStr << ")\n\n";
776774
OS << AstStr << "\n";
@@ -780,7 +778,6 @@ void IslAstInfo::print(raw_ostream &OS) {
780778
free(RtCStr);
781779
free(AstStr);
782780

783-
isl_schedule_free(Schedule);
784781
isl_printer_free(P);
785782
}
786783

0 commit comments

Comments
 (0)