[llvm-commits] [polly] r159734 - /polly/trunk/lib/Support/GICHelper.cpp
Hongbin Zheng
etherzhhb at gmail.com
Thu Jul 5 01:42:39 PDT 2012
Author: ether
Date: Thu Jul 5 03:42:39 2012
New Revision: 159734
URL: http://llvm.org/viewvc/llvm-project?rev=159734&view=rev
Log:
Refactor: Use generic internal function template in GICHelper.cpp to avoid duplication.
Modified:
polly/trunk/lib/Support/GICHelper.cpp
Modified: polly/trunk/lib/Support/GICHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Support/GICHelper.cpp?rev=159734&r1=159733&r2=159734&view=diff
==============================================================================
--- polly/trunk/lib/Support/GICHelper.cpp (original)
+++ polly/trunk/lib/Support/GICHelper.cpp Thu Jul 5 03:42:39 2012
@@ -60,9 +60,12 @@
}
}
-std::string polly::stringFromIslObj(/*__isl_keep*/ isl_map *map) {
- isl_printer *p = isl_printer_to_str(isl_map_get_ctx(map));
- isl_printer_print_map(p, map);
+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_ctx *ctx = ctx_getter_fn(isl_obj);
+ isl_printer *p = isl_printer_to_str(ctx);
+ printer_fn(p, isl_obj);
char *char_str = isl_printer_get_str(p);
std::string string(char_str);
free(char_str);
@@ -70,43 +73,31 @@
return string;
}
+static inline isl_ctx *schedule_get_ctx(/*__isl_keep*/ isl_schedule *schedule) {
+ return isl_union_map_get_ctx(isl_schedule_get_map(schedule));
+}
+
+std::string polly::stringFromIslObj(/*__isl_keep*/ isl_map *map) {
+ return stringFromIslObjInternal(map, isl_map_get_ctx,
+ isl_printer_print_map);
+}
+
std::string polly::stringFromIslObj(/*__isl_keep*/ isl_set *set) {
- isl_printer *p = isl_printer_to_str(isl_set_get_ctx(set));
- isl_printer_print_set(p, set);
- char *char_str = isl_printer_get_str(p);
- std::string string(char_str);
- free(char_str);
- isl_printer_free(p);
- return string;
+ return stringFromIslObjInternal(set, isl_set_get_ctx,
+ isl_printer_print_set);
}
std::string polly::stringFromIslObj(/*__isl_keep*/ isl_union_map *umap) {
- isl_printer *p = isl_printer_to_str(isl_union_map_get_ctx(umap));
- isl_printer_print_union_map(p, umap);
- char *char_str = isl_printer_get_str(p);
- std::string string(char_str);
- free(char_str);
- isl_printer_free(p);
- return string;
+ return stringFromIslObjInternal(umap, isl_union_map_get_ctx,
+ isl_printer_print_union_map);
}
std::string polly::stringFromIslObj(/*__isl_keep*/ isl_union_set *uset) {
- isl_printer *p = isl_printer_to_str(isl_union_set_get_ctx(uset));
- isl_printer_print_union_set(p, uset);
- char *char_str = isl_printer_get_str(p);
- std::string string(char_str);
- free(char_str);
- isl_printer_free(p);
- return string;
+ return stringFromIslObjInternal(uset, isl_union_set_get_ctx,
+ isl_printer_print_union_set);
}
std::string polly::stringFromIslObj(/*__isl_keep*/ isl_schedule *schedule) {
- isl_ctx *ctx = isl_union_map_get_ctx(isl_schedule_get_map(schedule));
- isl_printer *p = isl_printer_to_str(ctx);
- isl_printer_print_schedule(p, schedule);
- char *char_str = isl_printer_get_str(p);
- std::string string(char_str);
- free(char_str);
- isl_printer_free(p);
- return string;
+ return stringFromIslObjInternal(schedule, schedule_get_ctx,
+ isl_printer_print_schedule);
}
More information about the llvm-commits
mailing list