Skip to content

Commit

Permalink
odin - initial hierarchy for named and generate blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
ademmings committed Aug 28, 2019
1 parent e2f3f72 commit 5b01866
Show file tree
Hide file tree
Showing 12 changed files with 652 additions and 371 deletions.
565 changes: 331 additions & 234 deletions ODIN_II/SRC/ast_elaborate.cpp

Large diffs are not rendered by default.

123 changes: 87 additions & 36 deletions ODIN_II/SRC/ast_loop_unroll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,105 @@
#include "ast_util.h"
#include "ast_elaborate.h"
#include "parse_making_ast.h"
#include "netlist_create_from_ast.h"
#include "odin_util.h"
#include "vtr_memory.h"
#include "vtr_util.h"

/* This files header */
#include "ast_loop_unroll.h"

ast_node_t *unroll_for_loop(ast_node_t* node, ast_node_t *parent, sc_hierarchy *local_ref)
ast_node_t *unroll_for_loop(ast_node_t* node, ast_node_t *parent, int *num_unrolled, sc_hierarchy *local_ref, bool is_generate)
{
oassert(node && node->type == FOR);

char *module_id = local_ref->instance_name_prefix;
long sc_spot = sc_lookup_string(module_names_to_idx, module_id);
oassert(sc_spot > -1);
ast_node_t *ast_module = (ast_node_t *)module_names_to_idx->data[sc_spot];

ast_node_t* unrolled_for = resolve_for(ast_module, node);
ast_node_t* unrolled_for = resolve_for(node);
oassert(unrolled_for != nullptr);

*num_unrolled = unrolled_for->num_children;

/* update parent */
int i;
int this_genblk = 0;
for (i = 0; i < parent->num_children; i++)
{
if (node == parent->children[i])
{
int j;
for (j = i; j < (unrolled_for->num_children + i); j++)
{
add_child_to_node_at_index(parent, unrolled_for->children[j-i], j);
ast_node_t *child = unrolled_for->children[j-i];
add_child_to_node_at_index(parent, child, j);
unrolled_for->children[j-i] = NULL;

/* create scopes as necessary */
if (is_generate)
{
oassert(child->type == BLOCK);

/* generate blocks always have scopes; parent has access to named block
but not unnamed, and child always has access to parent */
sc_hierarchy *child_hierarchy = init_sc_hierarchy();
child->types.hierarchy = child_hierarchy;

child_hierarchy->top_node = child;
child_hierarchy->parent = local_ref;

if (child->types.identifier != NULL)
{
local_ref->block_children = (sc_hierarchy **)vtr::realloc(local_ref->block_children, sizeof(sc_hierarchy)*(local_ref->num_block_children + 1));
local_ref->block_children[local_ref->num_block_children] = child_hierarchy;
local_ref->num_block_children++;

/* add an array reference to this label */
std::string new_id(child->types.identifier);
new_id = new_id + "[" + std::to_string(j-i) + "]";
vtr::free(child->types.identifier);
child->types.identifier = vtr::strdup(new_id.c_str());

child_hierarchy->scope_id = node->types.identifier;
child_hierarchy->instance_name_prefix = make_full_ref_name(local_ref->instance_name_prefix, NULL, child->types.identifier, NULL, -1);
}
else
{
/* create a unique scope id/instance name prefix for internal use */
this_genblk = local_ref->num_unnamed_genblks + 1;
std::string new_scope_id("genblk");
new_scope_id = new_scope_id + std::to_string(this_genblk) + "[" + std::to_string(j-i) + "]";
child_hierarchy->scope_id = vtr::strdup(new_scope_id.c_str());
child_hierarchy->instance_name_prefix = make_full_ref_name(local_ref->instance_name_prefix, NULL, child_hierarchy->scope_id, NULL, -1);
}

/* string caches */
create_param_table_for_scope(child, child_hierarchy);
create_symbol_table_for_scope(child, child_hierarchy);
}
else if (child->type == BLOCK && child->types.identifier != NULL)
{
/* only create scope if child is named block */
sc_hierarchy *child_hierarchy = init_sc_hierarchy();
child->types.hierarchy = child_hierarchy;

child_hierarchy->top_node = child;
child_hierarchy->parent = local_ref;

local_ref->block_children = (sc_hierarchy **)vtr::realloc(local_ref->block_children, sizeof(sc_hierarchy)*(local_ref->num_block_children + 1));
local_ref->block_children[local_ref->num_block_children] = child_hierarchy;
local_ref->num_block_children++;

/* add an array reference to this label */
std::string new_id(child->types.identifier);
new_id = new_id + "[" + std::to_string(j-i) + "]";
vtr::free(child->types.identifier);
child->types.identifier = vtr::strdup(new_id.c_str());

child_hierarchy->scope_id = node->types.identifier;
child_hierarchy->instance_name_prefix = make_full_ref_name(local_ref->instance_name_prefix, NULL, child->types.identifier, NULL, -1);

/* string caches */
create_param_table_for_scope(child, child_hierarchy);
create_symbol_table_for_scope(child, child_hierarchy);
}
}

oassert(j == (unrolled_for->num_children + i) && parent->children[j] == node);
Expand All @@ -46,6 +115,11 @@ ast_node_t *unroll_for_loop(ast_node_t* node, ast_node_t *parent, sc_hierarchy *
break;
}
}

if (this_genblk > 0)
{
local_ref->num_unnamed_genblks++;
}

free_whole_tree(unrolled_for);
return parent->children[i];
Expand All @@ -54,7 +128,7 @@ ast_node_t *unroll_for_loop(ast_node_t* node, ast_node_t *parent, sc_hierarchy *
/*
* (function: resolve_for)
*/
ast_node_t* resolve_for(ast_node_t *ast_module, ast_node_t* node)
ast_node_t* resolve_for(ast_node_t* node)
{
oassert(is_for_node(node));
oassert(node != nullptr);
Expand Down Expand Up @@ -87,7 +161,7 @@ ast_node_t* resolve_for(ast_node_t *ast_module, ast_node_t* node)
bool dup_body = cond_func(value->types.vnumber->get_value());
while(dup_body)
{
ast_node_t* new_body = dup_and_fill_body(ast_module, body, pre, &value, &error_code);
ast_node_t* new_body = dup_and_fill_body(body, pre, &value, &error_code);
if(error_code)
{
error_message(PARSE_ERROR, pre->line_number, pre->file_number, "%s", "Unsupported pre-condition node in for loop");
Expand Down Expand Up @@ -355,26 +429,7 @@ post_condition_function resolve_post_condition(ast_node_t* assignment, ast_node_
return resolve_binary_operation(node);
}

ast_node_t* replace_named_module(ast_node_t* module, ast_node_t** value)
{
ast_node_t* copy = ast_node_deep_copy(module);

oassert( value && "Value node reference is NULL");
oassert( *value && "Value node is NULL");
oassert( (*value)->type == NUMBERS && "Value node type is not a NUMBER");

long int val = (*value)->types.vnumber->get_value();
std::string concat_string(copy->children[0]->types.identifier);
concat_string = concat_string + "[" + std::to_string(val) + "]";

vtr::free(copy->children[0]->types.identifier);
copy->children[0]->types.identifier = vtr::strdup(concat_string.c_str());

free_whole_tree(module);
return copy;
}

ast_node_t* dup_and_fill_body(ast_node_t *ast_module, ast_node_t* body, ast_node_t* pre, ast_node_t** value, int* error_code)
ast_node_t* dup_and_fill_body(ast_node_t* body, ast_node_t* pre, ast_node_t** value, int* error_code)
{
ast_node_t* copy = ast_node_deep_copy(body);
for(long i = 0; i<copy->num_children; i++)
Expand All @@ -395,13 +450,9 @@ ast_node_t* dup_and_fill_body(ast_node_t *ast_module, ast_node_t* body, ast_node
}
else if(child->type == MODULE_INSTANCE && child->children[0]->type != MODULE_INSTANCE)
{
/* give this unrolled instance a unique name */
copy->children[i]->children[1] = replace_named_module(child->children[1], value);
oassert(copy->children[i]->children[1]);

/* find and replace iteration symbol for port connections and parameters */
ast_node_t *named_instance = child->children[1];
copy->children[i]->children[1] = dup_and_fill_body(ast_module, named_instance, pre, value, error_code);
copy->children[i]->children[1] = dup_and_fill_body(named_instance, pre, value, error_code);
free_whole_tree(named_instance);

is_unrolled = true;
Expand All @@ -416,7 +467,7 @@ ast_node_t* dup_and_fill_body(ast_node_t *ast_module, ast_node_t* body, ast_node
if (copy->children[i]->children[j] != child->children[j]) free_whole_tree(copy->children[i]->children[j]);
}

copy->children[i] = dup_and_fill_body(ast_module, child, pre, value, error_code);
copy->children[i] = dup_and_fill_body(child, pre, value, error_code);
free_whole_tree(child);
}
}
Expand Down
46 changes: 18 additions & 28 deletions ODIN_II/SRC/ast_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,6 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
int j;
ast_node_t *rnode[3] = { 0 };

STRING_CACHE *local_symbol_table_sc = local_ref->local_symbol_table_sc;

concat_top->types.concat.num_bit_strings = 0;
concat_top->types.concat.bit_strings = NULL;

Expand All @@ -405,14 +403,13 @@ void make_concat_into_list_of_strings(ast_node_t *concat_top, char *instance_nam
if (concat_top->children[i]->type == IDENTIFIERS)
{
char *temp_string = make_full_ref_name(NULL, NULL, NULL, concat_top->children[i]->types.identifier, -1);
long sc_spot;
if ((sc_spot = sc_lookup_string(local_symbol_table_sc, temp_string)) == -1)
ast_node_t *var_declare = resolve_hierarchical_name_reference(local_ref, temp_string);
if (var_declare == NULL)
{
error_message(NETLIST_ERROR, concat_top->line_number, concat_top->file_number, "Missing declaration of this symbol %s\n", temp_string);
}
else
{
ast_node_t *var_declare = (ast_node_t*)local_symbol_table_sc->data[sc_spot];
if (var_declare->children[1] == NULL)
{
concat_top->types.concat.num_bit_strings ++;
Expand Down Expand Up @@ -566,7 +563,7 @@ char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_
char *return_string = NULL;
ast_node_t *rnode[3] = { 0 };

STRING_CACHE *local_symbol_table_sc = local_ref->local_symbol_table_sc;
// STRING_CACHE *local_symbol_table_sc = local_ref->local_symbol_table_sc;

if (var_node->type == ARRAY_REF)
{
Expand Down Expand Up @@ -594,22 +591,22 @@ char *get_name_of_pin_at_bit(ast_node_t *var_node, int bit, char *instance_name_
}
else if (var_node->type == IDENTIFIERS)
{
long sc_spot;
ast_node_t *symbol_node;
int pin_index = 0;

if ((sc_spot = sc_lookup_string(local_symbol_table_sc, var_node->types.identifier)) == -1)
if ((symbol_node = resolve_hierarchical_name_reference(local_ref, var_node->types.identifier)) == NULL)
{
error_message(NETLIST_ERROR, var_node->line_number, var_node->file_number, "Missing declaration of this symbol %s\n", var_node->types.identifier);
}

if (((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[1] == NULL)
if (symbol_node->children[1] == NULL)
{
pin_index = bit;
}
else if (((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[3] == NULL)
else if (symbol_node->children[3] == NULL)
{
oassert(((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[2]->type == NUMBERS);
pin_index = ((ast_node_t*)local_symbol_table_sc->data[sc_spot])->children[2]->types.vnumber->get_value() + bit;
oassert(symbol_node->children[2]->type == NUMBERS);
pin_index = symbol_node->children[2]->types.vnumber->get_value() + bit;
}
else
oassert(false);
Expand Down Expand Up @@ -704,8 +701,6 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix,
int i;
int width = 0;

STRING_CACHE *local_symbol_table_sc = local_ref->local_symbol_table_sc;

if (var_node->type == ARRAY_REF)
{
width = 1;
Expand Down Expand Up @@ -740,16 +735,11 @@ char_list_t *get_name_of_pins(ast_node_t *var_node, char *instance_name_prefix,
else if (var_node->type == IDENTIFIERS)
{
/* need to look in the symbol table for details about this identifier (i.e. is it a port) */
long sc_spot;

ast_node_t *sym_node = NULL;
char *temp_string = make_full_ref_name(NULL, NULL, NULL, var_node->types.identifier, -1);
ast_node_t *sym_node = resolve_hierarchical_name_reference(local_ref, temp_string);

if ((sc_spot = sc_lookup_string(local_symbol_table_sc, temp_string)) > -1)
{
sym_node = (ast_node_t*)local_symbol_table_sc->data[sc_spot];
}
else
if (sym_node == NULL)
{
error_message(NETLIST_ERROR, var_node->line_number, var_node->file_number, "Missing declaration of this symbol %s\n", temp_string);
}
Expand Down Expand Up @@ -859,7 +849,6 @@ long get_size_of_variable(ast_node_t *node, sc_hierarchy *local_ref)
long sc_spot = 0;
ast_node_t *var_declare = NULL;

STRING_CACHE *local_symbol_table_sc = local_ref->local_symbol_table_sc;
STRING_CACHE *local_param_table_sc = local_ref->local_param_table_sc;

switch(node->type)
Expand All @@ -884,10 +873,10 @@ long get_size_of_variable(ast_node_t *node, sc_hierarchy *local_ref)
return assignment_size;
}

sc_spot = sc_lookup_string(local_symbol_table_sc, node->types.identifier);
if (sc_spot > -1)
ast_node_t *sym_node = resolve_hierarchical_name_reference(local_ref, node->types.identifier);
if (sym_node != NULL)
{
var_declare = (ast_node_t *)local_symbol_table_sc->data[sc_spot];
var_declare = sym_node; // (ast_node_t *)local_symbol_table_sc->data[sc_spot];
break;
}

Expand All @@ -897,10 +886,10 @@ long get_size_of_variable(ast_node_t *node, sc_hierarchy *local_ref)

case ARRAY_REF:
{
sc_spot = sc_lookup_string(local_symbol_table_sc, node->children[0]->types.identifier);
if (sc_spot > -1)
ast_node_t *sym_node = resolve_hierarchical_name_reference(local_ref, node->children[0]->types.identifier);
if (sym_node != NULL)
{
var_declare = (ast_node_t *)local_symbol_table_sc->data[sc_spot];
var_declare = sym_node;
break;
}

Expand Down Expand Up @@ -1421,6 +1410,7 @@ void initial_node(ast_node_t *new_node, ids id, int line_number, int file_number
new_node->net_node = 0;
new_node->types.vnumber = nullptr;
new_node->types.identifier = NULL;
new_node->types.hierarchy = NULL;
new_node->chunk_size = 1;
}

Expand Down
Loading

0 comments on commit 5b01866

Please sign in to comment.