3 Star 0 Fork 1

Gitee 极速下载/isl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://repo.or.cz/isl.git
克隆/下载
isl_schedule_read.c 16.89 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
#include <isl/id.h>
#include <isl/val.h>
#include <isl/schedule.h>
#include <isl/stream.h>
#include <isl_schedule_private.h>
#include <isl_schedule_tree.h>
/* An enumeration of the various keys that may appear in a YAML mapping
* of a schedule.
*/
enum isl_schedule_key {
isl_schedule_key_error = -1,
isl_schedule_key_child,
isl_schedule_key_coincident,
isl_schedule_key_context,
isl_schedule_key_contraction,
isl_schedule_key_domain,
isl_schedule_key_expansion,
isl_schedule_key_extension,
isl_schedule_key_filter,
isl_schedule_key_guard,
isl_schedule_key_leaf,
isl_schedule_key_mark,
isl_schedule_key_options,
isl_schedule_key_permutable,
isl_schedule_key_schedule,
isl_schedule_key_sequence,
isl_schedule_key_set,
isl_schedule_key_end
};
/* Textual representations of the YAML keys for an isl_schedule object.
*/
static char *key_str[] = {
[isl_schedule_key_child] = "child",
[isl_schedule_key_coincident] = "coincident",
[isl_schedule_key_context] = "context",
[isl_schedule_key_contraction] = "contraction",
[isl_schedule_key_domain] = "domain",
[isl_schedule_key_expansion] = "expansion",
[isl_schedule_key_extension] = "extension",
[isl_schedule_key_filter] = "filter",
[isl_schedule_key_guard] = "guard",
[isl_schedule_key_leaf] = "leaf",
[isl_schedule_key_mark] = "mark",
[isl_schedule_key_options] = "options",
[isl_schedule_key_permutable] = "permutable",
[isl_schedule_key_schedule] = "schedule",
[isl_schedule_key_sequence] = "sequence",
[isl_schedule_key_set] = "set",
};
#undef KEY
#define KEY enum isl_schedule_key
#undef KEY_ERROR
#define KEY_ERROR isl_schedule_key_error
#undef KEY_END
#define KEY_END isl_schedule_key_end
#undef KEY_STR
#define KEY_STR key_str
#undef KEY_EXTRACT
#define KEY_EXTRACT extract_key
#undef KEY_GET
#define KEY_GET get_key
#include "extract_key.c"
static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
__isl_keep isl_stream *s);
/* Read a subtree with context root node from "s".
*/
static __isl_give isl_schedule_tree *read_context(__isl_keep isl_stream *s)
{
isl_set *context = NULL;
isl_schedule_tree *tree;
isl_ctx *ctx;
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_bool more;
ctx = isl_stream_get_ctx(s);
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
return NULL;
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
}
str = isl_token_get_str(ctx, tok);
context = isl_set_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
more = isl_stream_yaml_next(s);
if (more < 0)
goto error;
if (!more) {
tree = isl_schedule_tree_from_context(context);
} else {
key = get_key(s);
if (key != isl_schedule_key_child)
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
if (isl_stream_yaml_next(s) < 0)
goto error;
tree = isl_stream_read_schedule_tree(s);
tree = isl_schedule_tree_insert_context(tree, context);
}
return tree;
error:
isl_set_free(context);
return NULL;
}
/* Read a subtree with domain root node from "s".
*/
static __isl_give isl_schedule_tree *read_domain(__isl_keep isl_stream *s)
{
isl_union_set *domain = NULL;
isl_schedule_tree *tree;
isl_ctx *ctx;
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_bool more;
ctx = isl_stream_get_ctx(s);
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
return NULL;
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
}
str = isl_token_get_str(ctx, tok);
domain = isl_union_set_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
more = isl_stream_yaml_next(s);
if (more < 0)
goto error;
if (!more) {
tree = isl_schedule_tree_from_domain(domain);
} else {
key = get_key(s);
if (key != isl_schedule_key_child)
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
if (isl_stream_yaml_next(s) < 0)
goto error;
tree = isl_stream_read_schedule_tree(s);
tree = isl_schedule_tree_insert_domain(tree, domain);
}
return tree;
error:
isl_union_set_free(domain);
return NULL;
}
/* Read a subtree with expansion root node from "s".
*/
static __isl_give isl_schedule_tree *read_expansion(isl_stream *s)
{
isl_ctx *ctx;
isl_union_pw_multi_aff *contraction = NULL;
isl_union_map *expansion = NULL;
isl_schedule_tree *tree = NULL;
isl_bool more;
ctx = isl_stream_get_ctx(s);
do {
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
goto error;
switch (key) {
case isl_schedule_key_contraction:
isl_union_pw_multi_aff_free(contraction);
tok = isl_stream_next_token(s);
str = isl_token_get_str(ctx, tok);
contraction = isl_union_pw_multi_aff_read_from_str(ctx,
str);
free(str);
isl_token_free(tok);
if (!contraction)
goto error;
break;
case isl_schedule_key_expansion:
isl_union_map_free(expansion);
tok = isl_stream_next_token(s);
str = isl_token_get_str(ctx, tok);
expansion = isl_union_map_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
if (!expansion)
goto error;
break;
case isl_schedule_key_child:
isl_schedule_tree_free(tree);
tree = isl_stream_read_schedule_tree(s);
if (!tree)
goto error;
break;
default:
isl_die(ctx, isl_error_invalid, "unexpected key",
goto error);
}
} while ((more = isl_stream_yaml_next(s)) == isl_bool_true);
if (more < 0)
goto error;
if (!contraction)
isl_die(ctx, isl_error_invalid, "missing contraction",
goto error);
if (!expansion)
isl_die(ctx, isl_error_invalid, "missing expansion",
goto error);
if (!tree)
return isl_schedule_tree_from_expansion(contraction, expansion);
return isl_schedule_tree_insert_expansion(tree, contraction, expansion);
error:
isl_schedule_tree_free(tree);
isl_union_pw_multi_aff_free(contraction);
isl_union_map_free(expansion);
return NULL;
}
/* Read a subtree with extension root node from "s".
*/
static __isl_give isl_schedule_tree *read_extension(isl_stream *s)
{
isl_union_map *extension = NULL;
isl_schedule_tree *tree;
isl_ctx *ctx;
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_bool more;
ctx = isl_stream_get_ctx(s);
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
return NULL;
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
}
str = isl_token_get_str(ctx, tok);
extension = isl_union_map_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
more = isl_stream_yaml_next(s);
if (more < 0)
goto error;
if (!more) {
tree = isl_schedule_tree_from_extension(extension);
} else {
key = get_key(s);
if (key != isl_schedule_key_child)
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
if (isl_stream_yaml_next(s) < 0)
goto error;
tree = isl_stream_read_schedule_tree(s);
tree = isl_schedule_tree_insert_extension(tree, extension);
}
return tree;
error:
isl_union_map_free(extension);
return NULL;
}
/* Read a subtree with filter root node from "s".
*/
static __isl_give isl_schedule_tree *read_filter(__isl_keep isl_stream *s)
{
isl_union_set *filter = NULL;
isl_schedule_tree *tree;
isl_ctx *ctx;
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_bool more;
ctx = isl_stream_get_ctx(s);
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
return NULL;
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
}
str = isl_token_get_str(ctx, tok);
filter = isl_union_set_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
more = isl_stream_yaml_next(s);
if (more < 0)
goto error;
if (!more) {
tree = isl_schedule_tree_from_filter(filter);
} else {
key = get_key(s);
if (key != isl_schedule_key_child)
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
if (isl_stream_yaml_next(s) < 0)
goto error;
tree = isl_stream_read_schedule_tree(s);
tree = isl_schedule_tree_insert_filter(tree, filter);
}
return tree;
error:
isl_union_set_free(filter);
return NULL;
}
/* Read a subtree with guard root node from "s".
*/
static __isl_give isl_schedule_tree *read_guard(isl_stream *s)
{
isl_set *guard = NULL;
isl_schedule_tree *tree;
isl_ctx *ctx;
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_bool more;
ctx = isl_stream_get_ctx(s);
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
return NULL;
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
}
str = isl_token_get_str(ctx, tok);
guard = isl_set_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
more = isl_stream_yaml_next(s);
if (more < 0)
goto error;
if (!more) {
tree = isl_schedule_tree_from_guard(guard);
} else {
key = get_key(s);
if (key != isl_schedule_key_child)
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
if (isl_stream_yaml_next(s) < 0)
goto error;
tree = isl_stream_read_schedule_tree(s);
tree = isl_schedule_tree_insert_guard(tree, guard);
}
return tree;
error:
isl_set_free(guard);
return NULL;
}
/* Read a subtree with mark root node from "s".
*/
static __isl_give isl_schedule_tree *read_mark(isl_stream *s)
{
isl_id *mark;
isl_schedule_tree *tree;
isl_ctx *ctx;
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_bool more;
ctx = isl_stream_get_ctx(s);
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
return NULL;
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
return NULL;
}
str = isl_token_get_str(ctx, tok);
mark = isl_id_alloc(ctx, str, NULL);
free(str);
isl_token_free(tok);
more = isl_stream_yaml_next(s);
if (more < 0)
goto error;
if (!more) {
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
} else {
key = get_key(s);
if (key != isl_schedule_key_child)
isl_die(ctx, isl_error_invalid, "expecting child",
goto error);
if (isl_stream_yaml_next(s) < 0)
goto error;
tree = isl_stream_read_schedule_tree(s);
tree = isl_schedule_tree_insert_mark(tree, mark);
}
return tree;
error:
isl_id_free(mark);
return NULL;
}
#undef EL_BASE
#define EL_BASE val
#include <isl_list_read_yaml_templ.c>
/* Read a sequence of integers from "s" (representing the coincident
* property of a band node).
*/
static __isl_give isl_val_list *read_coincident(__isl_keep isl_stream *s)
{
return isl_stream_yaml_read_val_list(s);
}
/* Set the (initial) coincident properties of "band" according to
* the (initial) elements of "coincident".
*/
static __isl_give isl_schedule_band *set_coincident(
__isl_take isl_schedule_band *band, __isl_take isl_val_list *coincident)
{
int i;
isl_size n, m;
n = isl_schedule_band_n_member(band);
m = isl_val_list_n_val(coincident);
if (n < 0 || m < 0)
band = isl_schedule_band_free(band);
for (i = 0; i < n && i < m; ++i) {
isl_val *v;
v = isl_val_list_get_val(coincident, i);
if (!v)
band = isl_schedule_band_free(band);
band = isl_schedule_band_member_set_coincident(band, i,
!isl_val_is_zero(v));
isl_val_free(v);
}
isl_val_list_free(coincident);
return band;
}
/* Read a subtree with band root node from "s".
*/
static __isl_give isl_schedule_tree *read_band(isl_stream *s)
{
isl_multi_union_pw_aff *schedule = NULL;
isl_schedule_tree *tree = NULL;
isl_val_list *coincident = NULL;
isl_union_set *options = NULL;
isl_ctx *ctx;
isl_schedule_band *band;
int permutable = 0;
isl_bool more;
ctx = isl_stream_get_ctx(s);
do {
struct isl_token *tok;
enum isl_schedule_key key;
char *str;
isl_val *v;
key = get_key(s);
if (isl_stream_yaml_next(s) < 0)
goto error;
switch (key) {
case isl_schedule_key_schedule:
schedule = isl_multi_union_pw_aff_free(schedule);
tok = isl_stream_next_token(s);
if (!tok) {
isl_stream_error(s, NULL, "unexpected EOF");
goto error;
}
str = isl_token_get_str(ctx, tok);
schedule = isl_multi_union_pw_aff_read_from_str(ctx,
str);
free(str);
isl_token_free(tok);
if (!schedule)
goto error;
break;
case isl_schedule_key_coincident:
coincident = read_coincident(s);
if (!coincident)
goto error;
break;
case isl_schedule_key_permutable:
v = isl_stream_read_val(s);
permutable = !isl_val_is_zero(v);
isl_val_free(v);
break;
case isl_schedule_key_options:
isl_union_set_free(options);
tok = isl_stream_next_token(s);
str = isl_token_get_str(ctx, tok);
options = isl_union_set_read_from_str(ctx, str);
free(str);
isl_token_free(tok);
if (!options)
goto error;
break;
case isl_schedule_key_child:
isl_schedule_tree_free(tree);
tree = isl_stream_read_schedule_tree(s);
if (!tree)
goto error;
break;
default:
isl_die(ctx, isl_error_invalid, "unexpected key",
goto error);
}
} while ((more = isl_stream_yaml_next(s)) == isl_bool_true);
if (more < 0)
goto error;
if (!schedule)
isl_die(ctx, isl_error_invalid, "missing schedule", goto error);
band = isl_schedule_band_from_multi_union_pw_aff(schedule);
band = isl_schedule_band_set_permutable(band, permutable);
if (coincident)
band = set_coincident(band, coincident);
if (options)
band = isl_schedule_band_set_ast_build_options(band, options);
if (tree)
tree = isl_schedule_tree_insert_band(tree, band);
else
tree = isl_schedule_tree_from_band(band);
return tree;
error:
isl_val_list_free(coincident);
isl_union_set_free(options);
isl_schedule_tree_free(tree);
isl_multi_union_pw_aff_free(schedule);
return NULL;
}
#undef EL_BASE
#define EL_BASE schedule_tree
#include <isl_list_read_yaml_templ.c>
/* Read a subtree with root node of type "type" from "s".
* The node is represented by a sequence of children.
*/
static __isl_give isl_schedule_tree *read_children(isl_stream *s,
enum isl_schedule_node_type type)
{
isl_schedule_tree_list *list;
isl_token_free(isl_stream_next_token(s));
if (isl_stream_yaml_next(s) < 0)
return NULL;
list = isl_stream_yaml_read_schedule_tree_list(s);
return isl_schedule_tree_from_children(type, list);
}
/* Read a subtree with sequence root node from "s".
*/
static __isl_give isl_schedule_tree *read_sequence(isl_stream *s)
{
return read_children(s, isl_schedule_node_sequence);
}
/* Read a subtree with set root node from "s".
*/
static __isl_give isl_schedule_tree *read_set(isl_stream *s)
{
return read_children(s, isl_schedule_node_set);
}
/* Read a schedule (sub)tree from "s".
*
* We first determine the type of the root node based on the first
* mapping key and then hand over to a function tailored to reading
* nodes of this type.
*/
static __isl_give isl_schedule_tree *isl_stream_read_schedule_tree(
struct isl_stream *s)
{
enum isl_schedule_key key;
struct isl_token *tok;
isl_schedule_tree *tree = NULL;
isl_bool more;
if (isl_stream_yaml_read_start_mapping(s) < 0)
return NULL;
more = isl_stream_yaml_next(s);
if (more < 0)
return NULL;
if (!more) {
isl_stream_error(s, NULL, "missing key");
return NULL;
}
tok = isl_stream_next_token(s);
key = extract_key(s, tok);
isl_stream_push_token(s, tok);
if (key < 0)
return NULL;
switch (key) {
case isl_schedule_key_context:
tree = read_context(s);
break;
case isl_schedule_key_domain:
tree = read_domain(s);
break;
case isl_schedule_key_contraction:
case isl_schedule_key_expansion:
tree = read_expansion(s);
break;
case isl_schedule_key_extension:
tree = read_extension(s);
break;
case isl_schedule_key_filter:
tree = read_filter(s);
break;
case isl_schedule_key_guard:
tree = read_guard(s);
break;
case isl_schedule_key_leaf:
isl_token_free(isl_stream_next_token(s));
tree = isl_schedule_tree_leaf(isl_stream_get_ctx(s));
break;
case isl_schedule_key_mark:
tree = read_mark(s);
break;
case isl_schedule_key_sequence:
tree = read_sequence(s);
break;
case isl_schedule_key_set:
tree = read_set(s);
break;
case isl_schedule_key_schedule:
case isl_schedule_key_coincident:
case isl_schedule_key_options:
case isl_schedule_key_permutable:
tree = read_band(s);
break;
case isl_schedule_key_child:
isl_die(isl_stream_get_ctx(s), isl_error_unsupported,
"cannot identify node type", return NULL);
case isl_schedule_key_end:
case isl_schedule_key_error:
return NULL;
}
if (isl_stream_yaml_read_end_mapping(s) < 0)
return isl_schedule_tree_free(tree);
return tree;
}
/* Read an isl_schedule from "s".
*/
__isl_give isl_schedule *isl_stream_read_schedule(isl_stream *s)
{
isl_ctx *ctx;
isl_schedule_tree *tree;
if (!s)
return NULL;
ctx = isl_stream_get_ctx(s);
tree = isl_stream_read_schedule_tree(s);
return isl_schedule_from_schedule_tree(ctx, tree);
}
/* Read an isl_schedule from "input".
*/
__isl_give isl_schedule *isl_schedule_read_from_file(isl_ctx *ctx, FILE *input)
{
struct isl_stream *s;
isl_schedule *schedule;
s = isl_stream_new_file(ctx, input);
if (!s)
return NULL;
schedule = isl_stream_read_schedule(s);
isl_stream_free(s);
return schedule;
}
#undef TYPE_BASE
#define TYPE_BASE schedule
#include "isl_read_from_str_templ.c"
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/mirrors/isl.git
git@gitee.com:mirrors/isl.git
mirrors
isl
isl
master

搜索帮助