Esempio n. 1
0
void
PC_PrintLoop (FILE * f, PC_Loop lp)
{
#if 0
  return;
#endif

  if (lp == NULL)
    P_punt ("PC_PrintLoop: lp is NULL.");
  if (f == NULL)
    P_punt ("PC_PrintLoop: file f is NULL.");

  fprintf (f, "Loop ID: %d.\n", lp->ID);
  fprintf (f, "Loop Header: %d.\n", lp->head);
  Set_print (f, "Loop Body:", lp->body);
  Set_print (f, "Loop Exits:", lp->exits);
  fprintf (f, "\n\n");
}
Esempio n. 2
0
int main() {
    //Set console default size.
    system(CONSOLE_SIZE);
    //Testing fields
    int testSize = 10;
    Set_T * mainSet = Set_new(testSize);

    //Fill the set
    Set_fill(mainSet);
    //Print it out
    puts("**********");
    printf("Creating a new set...\n"
           "Filling it with non-repeatable numbers...\n");
    Set_print(mainSet);
    puts("**********");
    //Get some elements
    printf("Getting element on the index 4...\n");
    int test_a = Set_getValueAt(mainSet,4);
    printf("Element with the index 4 is %d\n", test_a);
    printf("Getting element on the index 10...\n");
    int test_b = Set_getValueAt(mainSet,10);
    printf("Element with the index 10 is %d\n", test_b);
    //Set some elements
    printf("Setting element with index 3 to \"123\"\n");
    Set_setValueAt(mainSet, 3, 123);
    printf("Setting element with index 10 to \"123\"\n");
    Set_setValueAt(mainSet, 10, 123);
    //Print set again
    puts("**********");
    Set_print(mainSet);
    //Delete some elements
    printf("Deleting element index 3\n");
    Set_removeValueAt(mainSet, 3);

    //Print the set again
    puts("**********");
    Set_print(mainSet);
    //In the end - free allocated memory
    puts("----------------------------------------------------------------------");
    printf("Creating two more sets.\n");
    Set_T * first = Set_new(testSize+1);
    Set_T * second = Set_new(testSize+4); //15
    Set_fill(first);
    Set_fill(second);
    puts("**********");
    printf("First set:\n");
    Set_print(first);
    printf("Second set:\n");
    Set_print(second);
    puts("**********");
    printf("Union with the first set and the second set.\n");
    Set_T * test_unionSet = Set_union(first, second);
    printf("The 'union' set:\n");
    Set_print(test_unionSet);
    puts("**********");
    printf("Intersection with the first and the second set.\n");
    Set_T * test_intersectionSet = Set_intersection(first, second);
    printf("The 'intersection' set:\n");
    Set_print(test_intersectionSet);
    puts("**********");
    printf("Difference between the first and the second set.\n");
    for(int i = 0; i < Set_getSize(first); i++) {
        Set_setValueAt(first, i, 8+i);
    }
    printf("Changed first set:\n");
    Set_print(first);
    Set_T * test_differenceSet = Set_difference(first, second);
    printf("The 'difference' set:\n");
    Set_print(test_differenceSet);
    puts("**********");
    //free allocated memory
    Set_delete(first);
    Set_delete(second);
    Set_delete(mainSet);
    Set_delete(test_unionSet);
    Set_delete(test_intersectionSet);
    Set_delete(test_differenceSet);
    puts("allocated memory was deleted.");
    return (0);
}
Esempio n. 3
0
static int
O_spill_fill_around_sync (L_Func * fn, L_Cb * cb, L_Oper * op,
			  int *int_spill_start, int *int_spill_end)
{
  L_Oper *op_list;
  L_Operand *spill_reg;
  Set live_variables;
  Set live_regs;
  int *live_reg_ids;
  int num_live_regs;
  Set live_macros;
  int *live_macro_ids;
  int num_live_macros;
  int variable;
  int int_offset, fp_offset;

  int_offset = *int_spill_start;

  fp_offset = fn->s_local;

  live_variables = L_get_oper_IN_set (op);

  /* registers */
  live_regs = L_unmap_reg_set (live_variables);
  num_live_regs = Set_size (live_regs);
  live_reg_ids = calloc (num_live_regs, sizeof (int));
  Set_2array (live_regs, live_reg_ids);

  /* macros */
  live_macros = L_unmap_macro_set (live_variables);
  num_live_macros = Set_size (live_macros);
  live_macro_ids = calloc (num_live_macros, sizeof (int));
  Set_2array (live_macros, live_macro_ids);

#ifdef DEBUG
#  ifdef DEBUG1
  L_print_cb (stderr, fn, cb);
  Set_print (stderr, "Live OUT set", live_variables);
  Set_print (stderr, "Registers", live_regs);
  Set_print (stderr, "Macros", live_macros);
#  endif
  fprintf (stderr, "fp setjmp spill/fill ops: ");
#endif

  /*
   * Spill the floating point registers and macros into
   * newly-allocated local variable space
   */

  /* first spill the floating point registers */
  /* create an operand, the id of it will be altered later. */
  spill_reg = L_new_register_operand (0, L_CTYPE_DOUBLE, L_PTYPE_NULL);

  for (variable = 0; variable < num_live_regs; variable++)
    {
      if (IS_FP_REGISTER (live_reg_ids[variable]))
	{
	  spill_reg->value.r = live_reg_ids[variable];
	  op_list = O_spill_reg (live_reg_ids[variable], L_OPERAND_REGISTER,
				 spill_reg, fp_offset, NULL, R_JSR_SAVE_CODE);
	  O_insert_spill_sequence (cb, op, op_list);
	  op_list = O_fill_reg (live_reg_ids[variable], L_OPERAND_REGISTER,
				spill_reg, fp_offset, NULL, R_JSR_SAVE_CODE);
	  O_insert_fill_sequence (cb, op, op_list);
	  fp_offset += 16;
	}
    }
#ifdef DEBUG
  fprintf (stderr, "\n");
  fprintf (stderr, "fp macro setjmp spill/fill ops: ");
#endif

  /* spill the floating point macros */
  /* change the operand to a macro operand. */
  L_assign_type_float_macro (spill_reg);
  for (variable = 0; variable < num_live_macros; variable++)
    {
      if (IS_FP_MACRO_TO_SPILL (live_macro_ids[variable]))
	{
	  spill_reg->value.r = live_macro_ids[variable];
	  op_list = O_spill_reg (live_macro_ids[variable], L_OPERAND_MACRO,
				 spill_reg, fp_offset, NULL, R_JSR_SAVE_CODE);
	  O_insert_spill_sequence (cb, op, op_list);
	  op_list = O_fill_reg (live_macro_ids[variable], L_OPERAND_MACRO,
				spill_reg, fp_offset, NULL, R_JSR_SAVE_CODE);
	  O_insert_fill_sequence (cb, op, op_list);
	  fp_offset += 16;
	}
    }

#ifdef DEBUG
  fprintf (stderr, "\n");
  fprintf (stderr, "int setjmp spill/fill ops: ");
#endif

  /*
   * Spill the integer registers and macros into sync space
   */

  L_assign_type_int_register (spill_reg);
  for (variable = 0; variable < num_live_regs; variable++)
    {
      if (IS_INT_REGISTER (live_reg_ids[variable]))
	{
	  int_offset += 8;
	  spill_reg->value.r = live_reg_ids[variable];
	  op_list = O_spill_reg (live_reg_ids[variable], L_OPERAND_REGISTER,
				 spill_reg, -int_offset,
				 NULL, R_JSR_SAVE_CODE);
	  O_insert_spill_sequence (cb, op, op_list);
	  op_list = O_fill_reg (live_reg_ids[variable], L_OPERAND_REGISTER,
				spill_reg, -int_offset,
				NULL, R_JSR_SAVE_CODE);
	  O_insert_fill_sequence (cb, op, op_list);
	}
    }

#ifdef DEBUG
  fprintf (stderr, "\n");
  fprintf (stderr, "int macro setjmp spill/fill ops: ");
#endif

  L_assign_type_int_macro (spill_reg);
  for (variable = 0; variable < num_live_macros; variable++)
    {
      if (IS_INT_MACRO_TO_SPILL (live_macro_ids[variable]))
	{
	  int_offset += 8;
	  spill_reg->value.r = live_macro_ids[variable];
	  op_list = O_spill_reg (live_macro_ids[variable], L_OPERAND_MACRO,
				 spill_reg, -int_offset, NULL,
				 R_JSR_SAVE_CODE);
	  O_insert_spill_sequence (cb, op, op_list);
	  op_list = O_fill_reg (live_macro_ids[variable], L_OPERAND_MACRO,
				spill_reg, -int_offset, NULL,
				R_JSR_SAVE_CODE);
	  O_insert_fill_sequence (cb, op, op_list);
	}
    }
#ifdef DEBUG
  fprintf (stderr, "\n");
#endif

  L_delete_operand (spill_reg);

  /*
   * Put fp regs into local variable space.
   */

  L_update_local_space_size (fn, fp_offset);

  /*
   * Put int regs into sync space -- must be managed by the UNAT
   */

  if (*int_spill_start == int_offset)
    {
      /* No integers spilled */
      *int_spill_end = *int_spill_start;
      return (0);
    }
  else
    {
      *int_spill_end = int_offset;
      return (1);
    }
}
Esempio n. 4
0
int
L_global_memflow_multiloadstore_load (L_Func * fn, L_Cb * cb, L_Oper * oper)
{
  return 0;

#if 0
  int change = 0;
  Set RAMB_ST, RAMB_JSR;
  Set RDEF_ST, RDEF_LD;

  if (!L_general_load_opcode (oper))
    return 0;

  /* 02/07/03 REK Adding a check to make sure we don't touch a volatile
   *              oper. */
  if (L_EXTRACT_BIT_VAL (oper->flags, L_OPER_VOLATILE))
    return 0;

  RDEF_ST = NULL;
  RDEF_LD = NULL;
  RAMB_ST = NULL;
  RAMB_JSR = NULL;

  /* Get all reaching stores */
  RDEF_ST =
    L_get_mem_oper_RIN_defining_opers (oper, (MDF_RET_DEP | MDF_RET_STORES));

  /* Get all reaching loads */
  RDEF_LD =
    L_get_mem_oper_RIN_defining_opers (oper, (MDF_RET_DEP | MDF_RET_LOADS));

  if (!Set_size (RDEF_LD) || !Set_size (RDEF_ST))
    return change;


  fprintf (stderr, "\n\nMFMLSL: Examining load %d\n", oper->id);

  /* Are there any reaching, ambiguous stores */
  RAMB_ST =
    L_get_mem_oper_RIN_defining_opers (oper, (MDF_RET_AMB | MDF_RET_STORES));

  /* Are there any reaching, unsafe jsrs */
  RAMB_JSR =
    L_get_mem_oper_RIN_defining_opers (oper, (MDF_RET_AMB | MDF_RET_JSRS));

  fprintf (stderr, "MFMLSL: Dep Stores reach load %d ", oper->id);
  Set_print (stderr, "MSMLSL: ", RDEF_ST);
  fprintf (stderr, "MFMLSL: Dep Loads reach load %d ", oper->id);
  Set_print (stderr, "MSMLSL: ", RDEF_LD);
  fprintf (stderr, "MFMLSL: Amb Stores reach load %d ", oper->id);
  Set_print (stderr, "MSMLSL: ", RAMB_ST);
  fprintf (stderr, "MFMLSL: Unsafe jsrs reach load %d ", oper->id);
  Set_print (stderr, "MSMLSL: ", RAMB_JSR);

  if (!L_load_compatible_each_store (fn, oper, RDEF_ST))
    {
      fprintf (stderr, "MFMLSL: Load is incompatible with a store\n");
      Set_dispose (RDEF);
      Set_dispose (RDEF_LD);
      Set_dispose (RAMB_ST);
      Set_dispose (RAMB_JSR);
      return change;
    }

  if (!L_load_compatible_each_load (fn, oper, RDEF_LD))
    {
      fprintf (stderr, "MFMLSL: Load is incompatible with a store\n");
      Set_dispose (RDEF);
      Set_dispose (RDEF_LD);
      Set_dispose (RAMB_ST);
      Set_dispose (RAMB_JSR);
      return change;
    }

  if (!L_store_union_dominates_load
      (fn, cb, oper, Set_union (RDEF_LD, RDEF_ST)))
    {
      fprintf (stderr,
               "MFMLSL: Path to load exists not through a store/load\n");
      Set_dispose (RDEF);
      Set_dispose (RDEF_LD);
      Set_dispose (RAMB_ST);
      Set_dispose (RAMB_JSR);
      return change;
    }

  if (!L_loadstore_union_postdominates_amb (fn, cb, oper,
                                            Set_union (RDEF_LD, RDEF_ST),
                                            Set_union (RAMB_ST, RAMB_JSR)))
    {
      fprintf (stderr, "MFMLSL: A amb st/jsr lies between ld/st and load \n");
      Set_dispose (RDEF);
      Set_dispose (RDEF_LD);
      Set_dispose (RAMB_ST);
      Set_dispose (RAMB_JSR);
      return change;
    }


  /* Load can be removed, moves added */
  fprintf (stderr, "MFMLSL: red Load %d can be converted\n", oper->id);

  Set_dispose (RDEF);
  Set_dispose (RDEF_LD);
  Set_dispose (RAMB_ST);
  Set_dispose (RAMB_JSR);
  return change;
#endif
}
Esempio n. 5
0
void
LB_elim_loop_backedges (L_Func * fn, L_Loop * loop)
{
  L_Cb *loop_header_cb = loop->header, *loop_end_cb, *cb;
  L_Flow *src_flow, *dst_flow, *back_edge_flow, *header_src_flow;
  L_Oper *oper, *branch;
  int num_back_edges, *back_edge_cb, i;

  /* We will only modify loops with more than one back edge */
  if ((num_back_edges = Set_size (loop->back_edge_cb)) <= 1)
    return;

#ifdef DEBUG
  fprintf (stderr, "Loop %d has %d backedges\n", loop->id, num_back_edges);
  Set_print (stderr, "backedges", loop->back_edge_cb);
#endif

  if (LB_functionally_equivalent_cbs (loop->back_edge_cb) &&
      !Set_in (loop->back_edge_cb, loop->header->id))
    {
#ifdef DEBUG
      fprintf (stderr, "Loop backedge cbs are equivalent!!\n");
#endif
      LB_combine_equivalent_backedges (loop);
      return;
    }

#ifdef DEBUG
  fprintf (stderr, "Loop backedge cbs are NOT equivalent!!\n");
#endif

  /* Create a cb with a back-edge to the loop header cb. */
  loop_end_cb = L_create_cb (0.0);
  header_src_flow = L_new_flow (1, loop_end_cb, loop_header_cb, 0.0);
  loop_header_cb->src_flow =
    L_concat_flow (loop_header_cb->src_flow, header_src_flow);
  back_edge_flow = L_new_flow (1, loop_end_cb, loop_header_cb, 0.0);
  loop_end_cb->dest_flow =
    L_concat_flow (loop_end_cb->dest_flow, back_edge_flow);
  L_insert_cb_after (fn, fn->last_cb, loop_end_cb);

  /* Create the jump instruction that leads to the header cb */
  oper = L_create_new_op (Lop_JUMP);
  oper->src[0] = L_new_cb_operand (loop_header_cb);
  L_insert_oper_after (loop_end_cb, loop_end_cb->first_op, oper);
#ifdef DEBUG
  fprintf (stderr, "created cb %d, placed it after cb %d\n",
	   loop_end_cb->id, loop_end_cb->prev_cb->id);
#endif

  /* 
   * Loop through all loop back-edge cbs and make them branch to the
   * to the new end loop cb.
   */

  back_edge_cb = (int *) Lcode_malloc (sizeof (int) * num_back_edges);
  Set_2array (loop->back_edge_cb, back_edge_cb);

  for (i = 0; i < num_back_edges; i++)
    {
      cb = L_cb_hash_tbl_find (fn->cb_hash_tbl, back_edge_cb[i]);

      /* 
       * Find the destination flow arc in the current cb corresponding to the 
       * loop back edge.
       */
      for (dst_flow = cb->dest_flow; dst_flow; dst_flow = dst_flow->next_flow)
	{
	  if (dst_flow->dst_cb != loop_header_cb)
	    continue;

	  /*
	   * Find the src flow arc in the loop header cb corresponding to the
	   * current back edge and delete it.
	   */
	  src_flow = L_find_flow (loop_header_cb->src_flow, dst_flow->cc,
				  dst_flow->src_cb, dst_flow->dst_cb);
	  loop_header_cb->src_flow = L_delete_flow (loop_header_cb->src_flow,
						    src_flow);

	  /* Modify the flow arc and branch target for the branch */
	  branch = L_find_branch_for_flow (cb, dst_flow);

#ifdef DEBUG
	  fprintf (stderr, "\t (cb %d) branch oper %d\n", cb->id, branch->id);
	  fprintf (stderr, "\t");
	  L_print_oper (stderr, branch);
#endif
	  if (branch)
	    {
	      L_change_branch_dest (branch, dst_flow->dst_cb, loop_end_cb);
	    }
	  else
	    {
	      L_Oper *new_op;
	      new_op = L_create_new_op (Lop_JUMP);
	      new_op->src[0] = L_new_cb_operand (loop_end_cb);
	      L_insert_oper_after (cb, cb->last_op, new_op);
	    }

	  dst_flow->dst_cb = loop_end_cb;

	  src_flow =
	    L_new_flow (dst_flow->cc, dst_flow->src_cb, dst_flow->dst_cb,
			dst_flow->weight);
	  loop_end_cb->src_flow =
	    L_concat_flow (loop_end_cb->src_flow, src_flow);
	  loop_end_cb->weight += src_flow->weight;

	  back_edge_flow->weight += src_flow->weight;
	  header_src_flow->weight += src_flow->weight;
	}
    }

  /* Add the new back-edge cb to the back edge cb list for the loop */
  loop->back_edge_cb = Set_dispose (loop->back_edge_cb);
  loop->back_edge_cb = Set_add (loop->back_edge_cb, loop_end_cb->id);
  loop->loop_cb = Set_add (loop->loop_cb, loop_end_cb->id);

  /* free up space */
  Lcode_free (back_edge_cb);

}