Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
07cdaf8
Synth scheduling implementation PR
amir734jj Apr 21, 2026
a6a637d
simplified the analysis
amir734jj Apr 21, 2026
07eb4a2
expose synth internals things to synth only
amir734jj Apr 21, 2026
67f5570
code improvements
amir734jj Apr 21, 2026
8351c28
just code improvement to avoid re-calculation of assignments
amir734jj Apr 21, 2026
ab3e1c0
basic code improvements
amir734jj Apr 21, 2026
c75b89d
fixed issue with codegen
amir734jj Apr 24, 2026
1e2d31c
Testing
amir734jj Apr 24, 2026
6f5421c
revert unnessary change
amir734jj Apr 24, 2026
2d6e165
smaller fixes
amir734jj May 12, 2026
02c406a
handle objects
amir734jj May 15, 2026
5003a86
Merge remote-tracking branch 'boyland/master' into user/amir734jj/syn…
amir734jj May 15, 2026
91cabc9
improved the Makefile
amir734jj May 15, 2026
ce5f91f
tiny change
amir734jj May 16, 2026
f4e13ea
Merge remote-tracking branch 'boyland/master' into user/amir734jj/syn…
amir734jj Jun 2, 2026
c83257a
Merge remote-tracking branch 'origin/master' into user/amir734jj/synt…
amir734jj Jun 16, 2026
cf786ee
Revert unnessary changes
amir734jj Jun 16, 2026
fc8695f
Merge remote-tracking branch 'origin/master' into user/amir734jj/synt…
amir734jj Jun 16, 2026
84a511e
add bigger outer fixed point loop
amir734jj Jun 16, 2026
f623302
more progress
amir734jj Jun 18, 2026
3d67e84
Merge remote-tracking branch 'origin/master' into user/amir734jj/synt…
amir734jj Jun 19, 2026
ed8f8e2
working
amir734jj Jun 20, 2026
43acc2e
added some TODOs
amir734jj Jun 21, 2026
beee561
WIP
amir734jj Jun 22, 2026
31d755b
Updated the code to allow local cycles
amir734jj Jun 29, 2026
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 @@ -2839,9 +2839,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 @@ -2691,7 +2696,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 @@ -2705,3 +2710,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