Beispiel #1
0
/* DEFINE */ 
Expr* EvalDefine(Env* env, Expr* expr, Expr* cont){
  Expr* symbol_expr = GetSecond(expr);
  char* symbol = symbol_expr->u.symbol;

  //  Expr* value_expr = get_third(expr);
  Expr* value_expr = Eval(env, GetThird(expr), cont);
//  int value = value_expr->u.int_value;
  Expr* value = value_expr;
  record_expr(env, symbol, value);
  return value;

}
Beispiel #2
0
void
avail_exprs_stack::record_cond (cond_equivalence *p)
{
  class expr_hash_elt *element = new expr_hash_elt (&p->cond, p->value);
  expr_hash_elt **slot;

  slot = m_avail_exprs->find_slot_with_hash (element, element->hash (), INSERT);
  if (*slot == NULL)
    {
      *slot = element;
      record_expr (element, NULL, '1');
    }
  else
    delete element;
}
Beispiel #3
0
Expr* EvalLet(Env* env, Expr* expr, Expr* cont){
  Expr* bindings = expr->next;
  Expr* bind;
  Env* new_env = malloc(sizeof(Env));
  init_env(new_env, env);

  PrintExpr(bindings);
  while(bindings != NULL){
      printf("type is %d\n", bindings->type);
    if(bindings->type == Pair_Exp){

      bind = bindings->u.list->u.list;
      char *symbol = get_symbol_element(bind);
      printf("symbolis %s", symbol);
      printf("type is %d\n", bind->next->type);
      Expr* val_expr = Eval(env,dup( bind->next), cont);
       PrintExpr(val_expr);
       
       puts("Bindings");
       PrintExpr(bindings);
       record_expr(new_env, symbol, val_expr);
       puts("Bindings 2");
       PrintExpr(bindings);
    }
    //    puts("aaa");
    //    printf("bindings->next is %d\n", bindings->next == NULL);
    //    printf("next bind expr's type is %d\n", bindings->type);
    puts("DEBUG");
    PrintExpr(bindings);
   bindings = GetSecond(bindings); 
   PrintExpr(bind->next->next);

  }
  puts("out let");
  return Eval(new_env, expr->next->next, cont);
}
Beispiel #4
0
Expr* EvalFunction(Env* env, Expr* expr, Expr* cont){
  Expr *args, *body, *function;
  Env new_env;

  //  PrintExpr(expr);
  init_env(&new_env, env); // tmp env, it exists only while executing this function
  //  puts("DEBUG");
  //  PrintExpr(expr);
  //  puts("");



  function = Eval(env, expr, cont);

  //puts("DEBUG2");
  expr = GetSecond(expr); // get real function argument list
  args = get_expr_element(function); // get imaginary function argument list
  body = GetSecond(function); // get imaginary function body

  while(args != NULL){ // set environment
    //    puts("set arg");
    char *symbol = get_symbol_element(args);
    Expr* val_expr = Eval(env, expr, cont);
    //    int value = val_expr->u.int_value;
    record_expr(new_env, symbol, val_expr);
    args = GetSecond(args);
    expr = GetSecond(expr);
  }
  //  Expr*  tmp =lookup_expr_symbol(&new_env, "x");
  //  printf("x is %d\n", tmp->u.int_value);
  //  printf("BODY\n");
  //    PrintExpr(body);
  //  puts("BODYend");

  return EvalPair(&new_env, body, cont);
}
Beispiel #5
0
tree
avail_exprs_stack::lookup_avail_expr (gimple *stmt, bool insert, bool tbaa_p)
{
  expr_hash_elt **slot;
  tree lhs;

  /* Get LHS of phi, assignment, or call; else NULL_TREE.  */
  if (gimple_code (stmt) == GIMPLE_PHI)
    lhs = gimple_phi_result (stmt);
  else
    lhs = gimple_get_lhs (stmt);

  class expr_hash_elt element (stmt, lhs);

  if (dump_file && (dump_flags & TDF_DETAILS))
    {
      fprintf (dump_file, "LKUP ");
      element.print (dump_file);
    }

  /* Don't bother remembering constant assignments and copy operations.
     Constants and copy operations are handled by the constant/copy propagator
     in optimize_stmt.  */
  if (element.expr()->kind == EXPR_SINGLE
      && (TREE_CODE (element.expr()->ops.single.rhs) == SSA_NAME
          || is_gimple_min_invariant (element.expr()->ops.single.rhs)))
    return NULL_TREE;

  /* Finally try to find the expression in the main expression hash table.  */
  slot = m_avail_exprs->find_slot (&element, (insert ? INSERT : NO_INSERT));
  if (slot == NULL)
    {
      return NULL_TREE;
    }
  else if (*slot == NULL)
    {
      class expr_hash_elt *element2 = new expr_hash_elt (element);
      *slot = element2;

      record_expr (element2, NULL, '2');
      return NULL_TREE;
    }

  /* If we found a redundant memory operation do an alias walk to
     check if we can re-use it.  */
  if (gimple_vuse (stmt) != (*slot)->vop ())
    {
      tree vuse1 = (*slot)->vop ();
      tree vuse2 = gimple_vuse (stmt);
      /* If we have a load of a register and a candidate in the
	 hash with vuse1 then try to reach its stmt by walking
	 up the virtual use-def chain using walk_non_aliased_vuses.
	 But don't do this when removing expressions from the hash.  */
      ao_ref ref;
      if (!(vuse1 && vuse2
	    && gimple_assign_single_p (stmt)
	    && TREE_CODE (gimple_assign_lhs (stmt)) == SSA_NAME
	    && (ao_ref_init (&ref, gimple_assign_rhs1 (stmt)),
		ref.base_alias_set = ref.ref_alias_set = tbaa_p ? -1 : 0, true)
	    && walk_non_aliased_vuses (&ref, vuse2,
				       vuse_eq, NULL, NULL, vuse1) != NULL))
	{
	  if (insert)
	    {
	      class expr_hash_elt *element2 = new expr_hash_elt (element);

	      /* Insert the expr into the hash by replacing the current
		 entry and recording the value to restore in the
		 avail_exprs_stack.  */
	      record_expr (element2, *slot, '2');
	      *slot = element2;
	    }
	  return NULL_TREE;
	}
    }

  /* Extract the LHS of the assignment so that it can be used as the current
     definition of another variable.  */
  lhs = (*slot)->lhs ();

  /* Valueize the result.  */
  if (TREE_CODE (lhs) == SSA_NAME)
    {
      tree tem = SSA_NAME_VALUE (lhs);
      if (tem)
	lhs = tem;
    }

  if (dump_file && (dump_flags & TDF_DETAILS))
    {
      fprintf (dump_file, "FIND: ");
      print_generic_expr (dump_file, lhs, 0);
      fprintf (dump_file, "\n");
    }

  return lhs;
}