Пример #1
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);
}
Пример #2
0
L_Loop *
LB_hb_do_collapse_loops (LB_TraceRegion_Header *trh,
			 L_Func * fn, L_Loop * loop)
{
  L_Loop *child_loop;
  L_Cb *par_hdr, *chi_hdr, *back_cb;
  L_Oper *new_op;
  LB_TraceRegion *child_tr;
  L_Flow *src_flow, *dst_flow, *nxt_flow;
  double back_wt;

  if (!(child_loop = loop->child_loop))
    return 0;
  if (child_loop->sibling_loop)
    return 0;

  par_hdr = loop->header;
  chi_hdr = child_loop->header;

  if (!(child_tr = LB_find_traceregion_by_header (trh, chi_hdr)))
    return 0;

  if (!par_hdr->dest_flow || par_hdr->dest_flow->dst_cb != chi_hdr)
    return 0;

  /*
   * Restructure control flow to move outer loop header into
   * inner loop tail
   */

  back_wt = par_hdr->weight - loop->num_invocation;
  par_hdr->weight = loop->num_invocation;

  back_cb = L_create_cb (par_hdr->weight);

  L_insert_cb_after (fn, fn->last_cb, back_cb);
  L_copy_block_contents (par_hdr, back_cb);
  back_cb->dest_flow = L_copy_flow (par_hdr->dest_flow);
  src_flow = L_find_matching_flow (chi_hdr->src_flow, back_cb->dest_flow);
  src_flow = L_copy_flow (src_flow);
  back_cb->dest_flow->weight = back_wt;
  src_flow->weight = back_wt;
  chi_hdr->src_flow = L_concat_flow (chi_hdr->src_flow, src_flow);
  src_flow->src_cb = back_cb;
  L_change_src (back_cb->dest_flow, par_hdr, back_cb);

  if (L_uncond_branch (back_cb->last_op))
    {
      L_delete_operand (back_cb->last_op->src[0]);
      back_cb->last_op->src[0] = L_new_cb_operand (chi_hdr);
    }
  else
    {
      new_op = L_create_new_op (Lop_JUMP);
      new_op->src[0] = L_new_cb_operand (chi_hdr);
      L_insert_oper_after (back_cb, back_cb->last_op, new_op);
    }

  {
    L_Cb *src_cb;
    L_Oper *op, *br;

    /* Change all loop body->header flows to the new header copy
     */

    for (src_flow = par_hdr->src_flow; src_flow; src_flow = nxt_flow)
      {
	nxt_flow = src_flow->next_flow;
	src_cb = src_flow->src_cb;
	if (Set_in (loop->back_edge_cb, src_cb->id) && (src_cb != par_hdr))
	  {
	    dst_flow = L_find_matching_flow (src_cb->dest_flow, src_flow);
	    br = L_find_branch_for_flow (src_cb, dst_flow);
	    if (br)
	      {
		L_change_branch_dest (br, par_hdr, back_cb);
	      }
	    else
	      {
		op = L_create_new_op (Lop_JUMP);
		op->src[0] = L_new_cb_operand (back_cb);
		L_insert_oper_after (src_cb, src_cb->last_op, op);
	      }
	    dst_flow->dst_cb = back_cb;
	    par_hdr->src_flow = L_remove_flow (par_hdr->src_flow, src_flow);
	    src_flow->dst_cb = back_cb;
	    back_cb->src_flow = L_concat_flow (back_cb->src_flow, src_flow);
	    loop->back_edge_cb = Set_delete (loop->back_edge_cb, src_cb->id);
	  }
      }
  }

  loop->header = child_loop->header;
  loop->loop_cb = Set_add (loop->loop_cb, back_cb->id);
  loop->loop_cb = Set_delete (loop->loop_cb, par_hdr->id);
  loop->back_edge_cb = Set_add (loop->back_edge_cb, back_cb->id);
  loop->nested_loops = Set_delete (loop->nested_loops, child_loop->id);
  loop->child_loop = NULL;
  L_merge_two_loops (fn, loop, child_loop);

  /*
   * Clear HB selection flags on child region's cbs, if not included in
   * other regions
   */

  {
    LB_TraceRegion *tr;
    L_Cb *cb_iter;
    Set uncov, test, chi;

    uncov = LB_return_cbs_region_as_set (child_tr);

    chi = Set_copy (uncov);

    List_start (trh->traceregions);

    while ((tr = (LB_TraceRegion *) List_next (trh->traceregions)))
      {
	if (tr == child_tr)
	  {
	    trh->traceregions = List_delete_current(trh->traceregions);
	    LB_free_traceregion (tr);
	  }
	else
	  {
	    test = LB_return_cbs_region_as_set (tr);
	    uncov = Set_subtract_acc (uncov, test);
	    Set_dispose (test);
	  }
      }

    for (cb_iter = fn->first_cb; cb_iter; cb_iter = cb_iter->next_cb)
      {
	if (Set_in(uncov, cb_iter->id))
	  cb_iter->flags = L_CLR_BIT_FLAG (cb_iter->flags,
					   L_CB_HYPERBLOCK_LOOP);
      }


    Set_dispose (uncov);
    Set_dispose (chi);
  }

  return loop;
}