Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion analyze/aps-analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Several phases:

// Boolean indicating whether to use SCC chunk scheduling
bool static_scc_schedule = false;
bool anc_analysis = false;

static void *analyze_thing(void *ignore, void *node)
{
Expand All @@ -29,7 +30,16 @@ static void *analyze_thing(void *ignore, void *node)
{
default: break;
case KEYmodule_decl:
s = compute_dnc(decl);
s = compute_dnc(decl, anc_analysis);
if (anc_analysis) {
if (cycle_debug & PRINT_CYCLE)
{
print_cycles(s, stdout);
}
d = (s->original_state_dependency = analysis_state_cycle(s));
s->loop_required = !(d & DEPENDENCY_MAYBE_SIMPLE);
break;
}
if (!(d = (s->original_state_dependency = analysis_state_cycle(s))))
{
// Do nothing; no cycle to remove
Expand Down
1 change: 1 addition & 0 deletions analyze/aps-analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(STATE*)(Declaration_info(md)->analysis_state)

extern bool static_scc_schedule;
extern bool anc_analysis;

extern void analyze_Program(Program); /* decorate modules with STATE */

Expand Down
3 changes: 2 additions & 1 deletion analyze/aps-dnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2828,9 +2828,10 @@ void dnc_close(STATE*s) {
}
}

STATE *compute_dnc(Declaration module) {
STATE *compute_dnc(Declaration module, bool anc_analysis) {
STATE *s=(STATE *)HALLOC(sizeof(STATE));
Declaration_info(module)->analysis_state = s;
s->anc_analysis = anc_analysis;
init_analysis_state(s,module);
dnc_close(s);
if (analysis_debug & (DNC_ITERATE|DNC_FINAL)) {
Expand Down
3 changes: 2 additions & 1 deletion analyze/aps-dnc.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef struct analysis_state {
VECTOR(FIBER) fibers;
CYCLES cycles;
BOOL loop_required;
BOOL anc_analysis;
DEPENDENCY original_state_dependency; // This is value of analysis_state_cycle
// before removing fiber cycle or
// linearization of phases in summary graph
Expand All @@ -129,7 +130,7 @@ extern INSTANCE *get_instance(Declaration attr, FIBER fiber,

extern void assert_closed(AUG_GRAPH*);
extern void dnc_close(STATE *);
extern STATE *compute_dnc(Declaration module);
extern STATE *compute_dnc(Declaration module, bool anc_analysis);

/* Low level routines: use with caution */
extern void free_edge(EDGESET old, AUG_GRAPH *aug_graph);
Expand Down
3 changes: 3 additions & 0 deletions analyze/apsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void usage() {
fprintf(stderr,"apsc: usage: %s [-DH] [-D...] [-p apspath] file...\n",argv0);
fprintf(stderr," schedule APS files (omit '.aps' extension)\n");
fprintf(stderr," -C SCC chunk static scheduling\n");
fprintf(stderr," -F ANC analysis\n");
fprintf(stderr," -DH print debug options\n");
exit(1);
}
Expand All @@ -26,6 +27,8 @@ int main(int argc,char **argv) {
set_aps_path(argv[++i]);
} else if (*options == 'C') {
static_scc_schedule = true;
} else if (*options == 'F') {
anc_analysis = true;
} else usage();
} else {
Program p = find_Program(make_string(argv[i]));
Expand Down
5 changes: 4 additions & 1 deletion aps2scala/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CPP=g++
CPPFLAGS=-Wall -g -Wno-unused-variable -DUSING_CXX -DAPS2SCALA -I../parse -I../analyze -I../codegen -I../utilities

APS2SCALAOBJS = aps2scala.o dump-scala.o implement.o dyn-impl.o static-impl.o static-scc-impl.o
APS2SCALAOBJS = aps2scala.o dump-scala.o implement.o dyn-impl.o static-impl.o static-scc-impl.o synth-impl.o
APS2SCALALIBS = ../lib/aps-lib.o ../lib/aps-ag.a ../utilities/utilities.o
aps2scala : ${APS2SCALAOBJS} ${APS2SCALALIBS}
${CPP} ${CPPFLAGS} ${APS2SCALAOBJS} ${APS2SCALALIBS} -o aps2scala
Expand All @@ -11,6 +11,9 @@ ${APS2SCALAOBJS} : dump-scala.h
install: aps2scala
mv aps2scala ../bin/.

synth-impl.o : ../codegen/synth-impl.cc
${CPP} -c ${CPPFLAGS} $< -o $@

static-impl.o : ../codegen/static-impl.cc
${CPP} -c ${CPPFLAGS} $< -o $@

Expand Down
13 changes: 11 additions & 2 deletions aps2scala/aps2scala.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern int aps_yyparse(void);
Implementation* impl;
bool static_schedule = false;
bool is_tree_only_program = false;
bool synth_implementation = false;

static void* program_is_tree_only(void *scope, void *node) {
if (ABSTRACT_APS_tnode_phylum(node) == KEYDeclaration) {
Expand Down Expand Up @@ -82,6 +83,10 @@ int main(int argc,char **argv) {
static_schedule = true;
static_scc_schedule = true;
continue;
} else if (streq(argv[i],"-F") || streq(argv[i],"--synth")) {
synth_implementation = true;
anc_analysis = true;
continue;
} else if (streq(argv[i],"-V") || streq(argv[i],"--verbose")) {
++verbose;
continue;
Expand Down Expand Up @@ -110,8 +115,12 @@ int main(int argc,char **argv) {
type_Program(p);
traverse_Program(program_is_tree_only, p, p);
aps_check_error("type");
if (static_schedule) {
impl = static_scc_schedule ? static_scc_impl : static_impl;
if (static_schedule || synth_implementation) {
if (static_schedule) {
impl = static_scc_schedule ? static_scc_impl : static_impl;
} else {
impl = synth_impl;
}
analyze_Program(p);
aps_check_error("analysis");
if (!impl) {
Expand Down
22 changes: 20 additions & 2 deletions aps2scala/dump-scala.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ void dump_scala_Declaration(Declaration decl,ostream& oss)
++nesting_level;

STATE *s = (STATE*)Declaration_info(decl)->analysis_state;
if (static_scc_schedule && s != NULL)
if ((static_scc_schedule || anc_analysis) && s != NULL)
{
activate_static_circular = s->loop_required;
}
Expand Down Expand Up @@ -2455,6 +2455,11 @@ void dump_Expression(Expression e, ostream& o)
dump_collect_Actuals(infer_expr_type(e),funcall_actuals(e),o);
return;
}

if (auto* synth = dynamic_cast<SynthImplementation*>(impl)) {
if (synth->try_dump_funcall(e, o)) return;
}

bool dump_anchor_actual = false;
if (should_include_ast_for_objects()) {
Expression fexpr = funcall_f(e);
Expand Down Expand Up @@ -2689,7 +2694,7 @@ string operator+(string s, int i)
string indent(int nl) { return string(indent_multiple*nl,' '); }

bool check_surrounding_decl(void* node, KEYTYPE_Declaration decl_key, Declaration* result_decl) {
while (node != NULL) {
while (node != NULL && ABSTRACT_APS_tnode_phylum(node) != KEY_ABSTRACT_APS_None) {
if (ABSTRACT_APS_tnode_phylum(node) == KEYDeclaration) {
Declaration decl = (Declaration)node;
if (Declaration_KEY(decl) == decl_key) {
Expand All @@ -2703,3 +2708,16 @@ bool check_surrounding_decl(void* node, KEYTYPE_Declaration decl_key, Declaratio
*result_decl = NULL;
return false;
}

bool check_surrounding_node(void* node, KEYTYPE_ABSTRACT_APS_Phylum ast_key, void** result_node) {
while (node != NULL && ABSTRACT_APS_tnode_phylum(node) != KEY_ABSTRACT_APS_None) {
if (ABSTRACT_APS_tnode_phylum(node) == ast_key) {
*result_node = node;
return true;
}
node = tnode_parent(node);
}

*result_node = NULL;
return false;
}
1 change: 1 addition & 0 deletions aps2scala/dump-scala.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ extern int verbose;
extern int debug;
extern bool include_comments;
extern bool static_scc_schedule;
extern bool anc_analysis;

class Implementation;

Expand Down
6 changes: 6 additions & 0 deletions codegen/dump.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef DUMP_H
#include "implement.h"
#include <iostream>
#include <string>
#include <vector>

using std::ostream;
using std::string;
Expand Down Expand Up @@ -196,4 +198,8 @@ inline const output_streams& operator<< <header_end>
}
#endif /* APS2SCALA */

// Common code generation utility functions
extern bool check_surrounding_decl(void* node, KEYTYPE_Declaration decl_key, Declaration* result_decl);
extern bool check_surrounding_node(void* node, KEYTYPE_ABSTRACT_APS_Phylum ast_key, void** result_node);

#endif
7 changes: 7 additions & 0 deletions codegen/implement.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,16 @@ class Implementation {
virtual void implement_value_use(Declaration vd, ostream&) = 0;
};

class SynthImplementation : public Implementation {
public:
virtual bool try_dump_funcall(Expression, ostream&) = 0;
virtual void dump_synth_instance(INSTANCE*, ostream&) = 0;
};

extern Implementation *dynamic_impl;
extern Implementation *static_impl;
extern Implementation *static_scc_impl;
extern Implementation *synth_impl;

#define IMPLEMENTATION_MARKS (127<<24)

Expand Down
Loading