mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 22:00:10 +00:00
[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:
parent
ccda8c71b2
commit
cfe117def7
@ -150,71 +150,93 @@ inline llvm::APInt APIntFromVal(isl::val V) {
|
||||
|
||||
/// Get c++ string from Isl objects.
|
||||
//@{
|
||||
std::string stringFromIslObj(__isl_keep isl_map *map);
|
||||
std::string stringFromIslObj(__isl_keep isl_union_map *umap);
|
||||
std::string stringFromIslObj(__isl_keep isl_set *set);
|
||||
std::string stringFromIslObj(__isl_keep isl_union_set *uset);
|
||||
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);
|
||||
std::string stringFromIslObj(__isl_keep isl_multi_pw_aff *mpa);
|
||||
std::string stringFromIslObj(__isl_keep isl_union_pw_multi_aff *upma);
|
||||
std::string stringFromIslObj(__isl_keep isl_aff *aff);
|
||||
std::string stringFromIslObj(__isl_keep isl_pw_aff *pwaff);
|
||||
std::string stringFromIslObj(__isl_keep isl_space *space);
|
||||
#define ISL_CPP_OBJECT_TO_STRING(name) \
|
||||
inline std::string stringFromIslObj(const name &Obj, \
|
||||
std::string DefaultValue = "") { \
|
||||
return stringFromIslObj(Obj.get(), DefaultValue); \
|
||||
}
|
||||
|
||||
#define ISL_OBJECT_TO_STRING(name) \
|
||||
std::string stringFromIslObj(__isl_keep isl_##name *Obj, \
|
||||
std::string DefaultValue = ""); \
|
||||
ISL_CPP_OBJECT_TO_STRING(isl::name)
|
||||
|
||||
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,
|
||||
__isl_keep isl_union_map *Map) {
|
||||
OS << polly::stringFromIslObj(Map);
|
||||
OS << polly::stringFromIslObj(Map, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_map *Map) {
|
||||
OS << polly::stringFromIslObj(Map);
|
||||
OS << polly::stringFromIslObj(Map, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_set *Set) {
|
||||
OS << polly::stringFromIslObj(Set);
|
||||
OS << polly::stringFromIslObj(Set, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_pw_aff *Map) {
|
||||
OS << polly::stringFromIslObj(Map);
|
||||
OS << polly::stringFromIslObj(Map, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_pw_multi_aff *PMA) {
|
||||
OS << polly::stringFromIslObj(PMA);
|
||||
OS << polly::stringFromIslObj(PMA, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_multi_aff *MA) {
|
||||
OS << polly::stringFromIslObj(MA);
|
||||
OS << polly::stringFromIslObj(MA, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_union_pw_multi_aff *UPMA) {
|
||||
OS << polly::stringFromIslObj(UPMA);
|
||||
OS << polly::stringFromIslObj(UPMA, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_schedule *Schedule) {
|
||||
OS << polly::stringFromIslObj(Schedule);
|
||||
OS << polly::stringFromIslObj(Schedule, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
|
||||
__isl_keep isl_space *Space) {
|
||||
OS << polly::stringFromIslObj(Space);
|
||||
OS << polly::stringFromIslObj(Space, "null");
|
||||
return OS;
|
||||
}
|
||||
|
||||
@ -263,7 +285,7 @@ std::string getIslCompatibleName(const std::string &Prefix,
|
||||
inline llvm::DiagnosticInfoOptimizationBase &
|
||||
operator<<(llvm::DiagnosticInfoOptimizationBase &OS,
|
||||
const isl::union_map &Obj) {
|
||||
OS << Obj.to_str();
|
||||
OS << stringFromIslObj(Obj);
|
||||
return OS;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "polly/Support/GICHelper.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "isl/isl-noexceptions.h"
|
||||
namespace polly {
|
||||
@ -17,7 +18,7 @@ namespace polly {
|
||||
#define ADD_OSTREAM_PRINTER(name) \
|
||||
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS, \
|
||||
const name &Obj) { \
|
||||
OS << Obj.to_str(); \
|
||||
OS << stringFromIslObj(Obj); \
|
||||
return OS; \
|
||||
}
|
||||
|
||||
|
@ -86,10 +86,12 @@ bool PolyhedralInfo::checkParallel(Loop *L, isl_pw_aff **MinDepDistPtr) const {
|
||||
Dependences::TYPE_WAR | Dependences::TYPE_RED)
|
||||
.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);
|
||||
LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule) << "\n");
|
||||
LLVM_DEBUG(dbgs() << "Schedule: \t" << stringFromIslObj(Schedule, "null")
|
||||
<< "\n");
|
||||
|
||||
IsParallel = D.isParallel(Schedule, Deps, MinDepDistPtr);
|
||||
isl_union_map_free(Schedule);
|
||||
|
@ -1615,7 +1615,8 @@ void ScopBuilder::addUserAssumptions(
|
||||
}
|
||||
}
|
||||
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "UserAssumption", CI)
|
||||
<< "Use user assumption: " << stringFromIslObj(AssumptionCtx));
|
||||
<< "Use user assumption: "
|
||||
<< stringFromIslObj(AssumptionCtx, "null"));
|
||||
isl::set newContext =
|
||||
scop->getContext().intersect(isl::manage(AssumptionCtx));
|
||||
scop->setContext(newContext);
|
||||
@ -2869,7 +2870,7 @@ void ScopBuilder::addUserContext() {
|
||||
isl::set UserContext = isl::set(scop->getIslCtx(), UserContextStr.c_str());
|
||||
isl::space Space = scop->getParamSpace();
|
||||
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 "
|
||||
<< "number of dimensions than the computed context. Due to this "
|
||||
<< "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);
|
||||
|
||||
if (NameContext != NameUserContext) {
|
||||
std::string SpaceStr = Space.to_str();
|
||||
std::string SpaceStr = stringFromIslObj(Space, "null");
|
||||
errs() << "Error: the name of dimension " << i
|
||||
<< " provided in -polly-context "
|
||||
<< "is '" << NameUserContext << "', but the name in the computed "
|
||||
|
@ -618,7 +618,7 @@ isl::map MemoryAccess::getOriginalAccessRelation() const {
|
||||
}
|
||||
|
||||
std::string MemoryAccess::getOriginalAccessRelationStr() const {
|
||||
return AccessRelation.to_str();
|
||||
return stringFromIslObj(AccessRelation);
|
||||
}
|
||||
|
||||
isl::space MemoryAccess::getOriginalAccessRelationSpace() const {
|
||||
@ -630,11 +630,11 @@ isl::map MemoryAccess::getNewAccessRelation() const {
|
||||
}
|
||||
|
||||
std::string MemoryAccess::getNewAccessRelationStr() const {
|
||||
return NewAccessRelation.to_str();
|
||||
return stringFromIslObj(NewAccessRelation);
|
||||
}
|
||||
|
||||
std::string MemoryAccess::getAccessRelationStr() const {
|
||||
return getAccessRelation().to_str();
|
||||
return stringFromIslObj(getAccessRelation());
|
||||
}
|
||||
|
||||
isl::basic_map MemoryAccess::createBasicAccessMap(ScopStmt *Statement) {
|
||||
@ -1233,15 +1233,10 @@ ScopStmt::ScopStmt(Scop &parent, isl::map SourceRel, isl::map TargetRel,
|
||||
|
||||
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 {
|
||||
auto *S = getSchedule().release();
|
||||
if (!S)
|
||||
return {};
|
||||
auto Str = stringFromIslObj(S);
|
||||
isl_map_free(S);
|
||||
return Str;
|
||||
return stringFromIslObj(getSchedule());
|
||||
}
|
||||
|
||||
void ScopStmt::setInvalidDomain(isl::set ID) { InvalidDomain = ID; }
|
||||
@ -1892,15 +1887,17 @@ ScopArrayInfo *Scop::getScopArrayInfo(Value *BasePtr, MemoryKind Kind) {
|
||||
return SAI;
|
||||
}
|
||||
|
||||
std::string Scop::getContextStr() const { return getContext().to_str(); }
|
||||
std::string Scop::getContextStr() const {
|
||||
return stringFromIslObj(getContext());
|
||||
}
|
||||
|
||||
std::string Scop::getAssumedContextStr() const {
|
||||
assert(!AssumedContext.is_null() && "Assumed context not yet built");
|
||||
return AssumedContext.to_str();
|
||||
return stringFromIslObj(AssumedContext);
|
||||
}
|
||||
|
||||
std::string Scop::getInvalidContextStr() const {
|
||||
return InvalidContext.to_str();
|
||||
return stringFromIslObj(InvalidContext);
|
||||
}
|
||||
|
||||
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";
|
||||
std::string Msg = toString(Kind) + Suffix + Set.to_str();
|
||||
std::string Msg = toString(Kind) + Suffix + stringFromIslObj(Set);
|
||||
if (BB)
|
||||
ORE.emit(OptimizationRemarkAnalysis(DEBUG_TYPE, "AssumpRestrict", Loc, BB)
|
||||
<< Msg);
|
||||
|
@ -766,11 +766,9 @@ void IslAstInfo::print(raw_ostream &OS) {
|
||||
P = isl_ast_node_print(RootNode.get(), P, Options);
|
||||
AstStr = isl_printer_get_str(P);
|
||||
|
||||
auto *Schedule = S.getScheduleTree().release();
|
||||
|
||||
LLVM_DEBUG({
|
||||
dbgs() << S.getContextStr() << "\n";
|
||||
dbgs() << stringFromIslObj(Schedule);
|
||||
dbgs() << stringFromIslObj(S.getScheduleTree(), "null");
|
||||
});
|
||||
OS << "\nif (" << RtCStr << ")\n\n";
|
||||
OS << AstStr << "\n";
|
||||
@ -780,7 +778,6 @@ void IslAstInfo::print(raw_ostream &OS) {
|
||||
free(RtCStr);
|
||||
free(AstStr);
|
||||
|
||||
isl_schedule_free(Schedule);
|
||||
isl_printer_free(P);
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -85,9 +85,10 @@ APInt polly::APIntFromVal(__isl_take isl_val *Val) {
|
||||
template <typename ISLTy, typename ISL_CTX_GETTER, typename ISL_PRINTER>
|
||||
static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
|
||||
ISL_CTX_GETTER ctx_getter_fn,
|
||||
ISL_PRINTER printer_fn) {
|
||||
ISL_PRINTER printer_fn,
|
||||
std::string DefaultValue) {
|
||||
if (!isl_obj)
|
||||
return "null";
|
||||
return DefaultValue;
|
||||
isl_ctx *ctx = ctx_getter_fn(isl_obj);
|
||||
isl_printer *p = isl_printer_to_str(ctx);
|
||||
p = printer_fn(p, isl_obj);
|
||||
@ -96,68 +97,42 @@ static inline std::string stringFromIslObjInternal(__isl_keep ISLTy *isl_obj,
|
||||
if (char_str)
|
||||
string = char_str;
|
||||
else
|
||||
string = "null";
|
||||
string = DefaultValue;
|
||||
free(char_str);
|
||||
isl_printer_free(p);
|
||||
return string;
|
||||
}
|
||||
|
||||
std::string polly::stringFromIslObj(__isl_keep isl_map *map) {
|
||||
return stringFromIslObjInternal(map, isl_map_get_ctx, isl_printer_print_map);
|
||||
}
|
||||
#define ISL_C_OBJECT_TO_STRING(name) \
|
||||
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) {
|
||||
return stringFromIslObjInternal(set, isl_set_get_ctx, isl_printer_print_set);
|
||||
}
|
||||
|
||||
std::string polly::stringFromIslObj(__isl_keep isl_union_map *umap) {
|
||||
return stringFromIslObjInternal(umap, isl_union_map_get_ctx,
|
||||
isl_printer_print_union_map);
|
||||
}
|
||||
|
||||
std::string polly::stringFromIslObj(__isl_keep isl_union_set *uset) {
|
||||
return stringFromIslObjInternal(uset, isl_union_set_get_ctx,
|
||||
isl_printer_print_union_set);
|
||||
}
|
||||
|
||||
std::string polly::stringFromIslObj(__isl_keep isl_schedule *schedule) {
|
||||
return stringFromIslObjInternal(schedule, isl_schedule_get_ctx,
|
||||
isl_printer_print_schedule);
|
||||
}
|
||||
|
||||
std::string polly::stringFromIslObj(__isl_keep isl_multi_aff *maff) {
|
||||
return stringFromIslObjInternal(maff, isl_multi_aff_get_ctx,
|
||||
isl_printer_print_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);
|
||||
}
|
||||
ISL_C_OBJECT_TO_STRING(aff)
|
||||
ISL_C_OBJECT_TO_STRING(ast_expr)
|
||||
ISL_C_OBJECT_TO_STRING(ast_node)
|
||||
ISL_C_OBJECT_TO_STRING(basic_map)
|
||||
ISL_C_OBJECT_TO_STRING(basic_set)
|
||||
ISL_C_OBJECT_TO_STRING(map)
|
||||
ISL_C_OBJECT_TO_STRING(set)
|
||||
ISL_C_OBJECT_TO_STRING(id)
|
||||
ISL_C_OBJECT_TO_STRING(multi_aff)
|
||||
ISL_C_OBJECT_TO_STRING(multi_pw_aff)
|
||||
ISL_C_OBJECT_TO_STRING(multi_union_pw_aff)
|
||||
ISL_C_OBJECT_TO_STRING(point)
|
||||
ISL_C_OBJECT_TO_STRING(pw_aff)
|
||||
ISL_C_OBJECT_TO_STRING(pw_multi_aff)
|
||||
ISL_C_OBJECT_TO_STRING(schedule)
|
||||
ISL_C_OBJECT_TO_STRING(schedule_node)
|
||||
ISL_C_OBJECT_TO_STRING(space)
|
||||
ISL_C_OBJECT_TO_STRING(union_access_info)
|
||||
ISL_C_OBJECT_TO_STRING(union_flow)
|
||||
ISL_C_OBJECT_TO_STRING(union_set)
|
||||
ISL_C_OBJECT_TO_STRING(union_map)
|
||||
ISL_C_OBJECT_TO_STRING(union_pw_aff)
|
||||
ISL_C_OBJECT_TO_STRING(union_pw_multi_aff)
|
||||
|
||||
static void replace(std::string &str, const std::string &find,
|
||||
const std::string &replace) {
|
||||
|
@ -12,6 +12,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "polly/Support/ISLTools.h"
|
||||
#include "polly/Support/GICHelper.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
@ -760,9 +761,9 @@ static void printSortedPolyhedra(isl::union_set USet, llvm::raw_ostream &OS,
|
||||
for (const isl::basic_set &BSet : BSets) {
|
||||
std::string Str;
|
||||
if (IsMap)
|
||||
Str = isl::map(BSet.unwrap()).to_str();
|
||||
Str = stringFromIslObj(isl::map(BSet.unwrap()));
|
||||
else
|
||||
Str = isl::set(BSet).to_str();
|
||||
Str = stringFromIslObj(isl::set(BSet));
|
||||
size_t OpenPos = Str.find_first_of('{');
|
||||
assert(OpenPos != std::string::npos);
|
||||
size_t ClosePos = Str.find_last_of('}');
|
||||
|
Loading…
Reference in New Issue
Block a user