+++ /dev/null
--include config.mak
-
-FIRM_CFLAGS ?= `pkg-config --cflags libfirm`
-FIRM_LIBS ?= `pkg-config --libs libfirm`
-
-CC ?= gcc
-
-CPPFLAGS += $(FIRM_CFLAGS)
-CFLAGS += -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Werror -pedantic
-CFLAGS += -O0 -g3
-LFLAGS += $(FIRM_LIBS)
-
-SOURCES = $(wildcard *.c)
-GOALS = $(basename $(SOURCES))
-
-.PHONY: all
-
-all: $(GOALS)
-
-%: %.c
- $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $< $(LFLAGS)
- strip $@
-
-clean:
- rm -f $(GOALS)
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/array-heap_example.c
- * Purpose: Show representation of dynamically allocated array.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <string.h>
-#include <stdio.h>
-
-#include <libfirm/firm.h>
-
-/**
-* variables of imperative programs.
-* It constructs the IR for the following program:
-*
-*
-* main(): int
-* int *a[10];
-*
-* a = malloc(sizeof(a[10]));
-* return (a[3]);
-* end;
-*
-* The array is placed on the heap. The pointer to the array that
-* is a local variable is represented as a dataflow edge.
-* There are two ways to model allocation to the heap in programs with
-* explicit memory allocation:
-* 1. Model the calls to malloc and free as simple procedure (of compiler
-* known procedures returning a pointer. This is the simpler way of
-* generating FIRM, but restricts the information that can be deduced
-* for the call.
-* 2. Insert an Alloc node. A later pass can lower this to the compiler
-* known function. This makes the allocation explicit in FIRM, supporting
-* optimization.
-* A problem is modeling free. There is no free node in FIRM. Is this
-* a necessary extension?
-* This example shows the second alternative, where the size of the array
-* is explicitly computed.
-**/
-
-#define OPTIMIZE_NODE 0
-
-int
-main(void)
-{
- char *dump_file_suffix = "";
-
- /* describes the method main */
- ir_type *owner;
- ir_type *proc_main;
- ir_entity *proc_main_e;
-
- /* describes types defined by the language */
- ir_type *prim_t_int;
-
- /* describes the array and its fields. */
- ir_type *array_type; /* the ir_type information for the array */
- ir_entity *array_ent; /* the ir_entity representing a field of the array */
-
- /* Needed while finding the element size. */
- ir_type *elt_type;
- ir_mode *elt_type_mode;
- int size;
- ir_node *arr_size;
-
- /* holds the graph and nodes. */
- ir_graph *main_irg;
- ir_node *array, *array_ptr, *c3, *elt, *val, *x;
-
- init_firm (NULL);
-
- /* make basic ir_type information for primitive ir_type int.
- In Sather primitive types are represented by a class.
- This is the modeling appropriate for other languages.
- Mode_i says that all integers shall be implemented as a
- 32 bit integer value. */
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Is);
-
- printf("\nCreating an IR graph: ARRAY-HEAP_EXAMPLE...\n");
-
- /* first build procedure main */
- owner = get_glob_type();
- proc_main = new_type_method(new_id_from_chars("ARRAY-HEAP_EXAMPLE_main", 23), 0, 1);
- set_method_res_type(proc_main, 0, (ir_type *)prim_t_int);
- proc_main_e = new_entity ((ir_type*)owner, new_id_from_chars("ARRAY-HEAP_EXAMPLE_main", 23), (ir_type *)proc_main);
-
- /* make ir_type information for the array and set the bounds */
-# define N_DIMS 1
-# define L_BOUND 0
-# define U_BOUND 9
- current_ir_graph = get_const_code_irg();
- array_type = new_type_array(new_id_from_chars("a", 1), N_DIMS, prim_t_int);
- set_array_bounds(array_type, 0,
- new_Const(mode_Iu, new_tarval_from_long (L_BOUND, mode_Iu)),
- new_Const(mode_Iu, new_tarval_from_long (U_BOUND, mode_Iu)));
- /* As the array is accessed by Sel nodes, we need information about
- the ir_entity the node selects. Entities of an array are it's elements
- which are, in this case, integers. */
- main_irg = new_ir_graph (proc_main_e, 4);
- array_ent = get_array_element_entity(array_type);
-
- /* Allocate the array. All program known variables that
- are not modeled by dataflow edges need an explicit allocate node.
- If the variable shall be placed on the stack, set stack_alloc. */
- /* first compute size in bytes. */
- elt_type = get_array_element_type(array_type);
- elt_type_mode = get_type_mode(elt_type);
- /* better: read bounds out of array ir_type information */
- size = (U_BOUND - L_BOUND + 1) * get_mode_size_bytes(elt_type_mode);
- /* make constant representing the size */
- arr_size = new_Const(mode_Iu, new_tarval_from_long (size, mode_Iu));
- /* allocate and generate the Proj nodes. */
- array = new_Alloc(get_store(), arr_size, (ir_type*)array_type, stack_alloc);
- set_store(new_Proj(array, mode_M, pn_Alloc_M)); /* make the changed memory visible */
- array_ptr = new_Proj(array, mode_P, pn_Alloc_res); /* remember the pointer to the array */
-
- /* Now the "real" program: */
- /* Load element 3 of the array. For this first generate the pointer to this
- array element by a select node. (Alternative: increase array pointer
- by (three * elt_size), but this complicates some optimizations. The
- ir_type information accessible via the ir_entity allows to generate the
- pointer increment later. */
- c3 = new_Const (mode_Iu, new_tarval_from_long (3, mode_Iu));
- {
- ir_node *in[1];
- in[0] = c3;
- elt = new_Sel(get_store(), array_ptr, 1, in, array_ent);
- }
- val = new_Load(get_store(), elt, mode_Is);
- set_store(new_Proj(val, mode_M, pn_Load_M));
- val = new_Proj(val, mode_Is, pn_Load_res);
-
- /* return the result of procedure main */
- {
- ir_node *in[1];
- in[0] = val;
-
- x = new_Return (get_store (), 1, in);
- }
- mature_immBlock (get_irg_current_block(main_irg));
-
- /* complete the end_block */
- add_immBlock_pred (get_irg_end_block(main_irg), x);
- mature_immBlock (get_irg_end_block(main_irg));
-
- irg_finalize_cons (main_irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(main_irg);
-
- /* verify the graph */
- irg_vrfy(main_irg);
-
- printf("Dumping the graph and a ir_type graph.\n");
- dump_ir_block_graph (main_irg, dump_file_suffix);
- dump_type_graph(main_irg, dump_file_suffix);
- dump_all_types(dump_file_suffix);
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-
-/*
- * Project: libFIRM
- * File name: testprograms/array-stack_example.c
- * Purpose: Show representation of array on stack.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-
-#include <string.h>
-#include <stdio.h>
-
-
-
-#include <libfirm/firm.h>
-
-/**
-* imperative programs.
-* It constructs the IR for the following program:
-*
-*
-* main(): int
-* int a[10];
-*
-* return (a[3]);
-* end;
-*
-* The array is placed on the stack, i.e., a pointer to the array
-* is obtained by selecting the ir_entity "a" from the stack. The variables
-* on the stack are considered to be entities of the method, as locals
-* of a method are only visible within the method. (An alternative to
-* make the method owner of the stack variables is to give the ownership
-* to the class representing the C-file. This would extend the visibility
-* of the locals, though.)
-**/
-
-
-#define OPTIMIZE_NODE 0
-
-int
-main(void)
-{
- char *dump_file_suffix = "";
- /* describes the general structure of a C-file */
- ir_type *owner; /* the class standing for everything in this file */
- ir_type *proc_main; /* Typeinformation for method main. */
- ir_entity *proc_main_e; /* The ir_entity describing that method main is an
- ir_entity of the fake class representing the file. */
-
- /* describes types defined by the language */
- ir_type *prim_t_int;
-
- /* describes the array and its fields. */
- ir_entity *array_ent; /* the ir_entity representing the array as member
- of the stack/method */
- ir_type *array_type; /* the ir_type information for the array */
- ir_entity *field_ent; /* the ir_entity representing a field of the
- array */
-
- /* holds the graph and nodes. */
- ir_graph *main_irg;
- ir_node *array_ptr, *c3, *elt, *val, *x;
-
- init_firm (NULL);
-
- printf("\nCreating an IR graph: ARRAY-STACK_EXAMPLE...\n");
-
- /* make basic ir_type information for primitive ir_type int.
- In Sather primitive types are represented by a class.
- This is the modeling appropriate for other languages.
- Mode_i says that all language-integers shall be implemented
- as a 32 bit processor-integer value. */
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Is);
-
- /* build typeinformation of procedure main */
- owner = new_type_class (new_id_from_chars ("ARRAY-STACK_EXAMPLE", 19));
- proc_main = new_type_method(new_id_from_chars("main_tp", 7), 0, 1);
- set_method_res_type(proc_main, 0, prim_t_int);
- proc_main_e = new_entity (owner, new_id_from_chars ("main", 4), proc_main);
- get_entity_ld_name(proc_main_e); /* force name mangling */
-
- /* make ir_type information for the array and set the bounds */
-# define N_DIMS 1
-# define L_BOUND 0
-# define U_BOUND 9
- array_type = new_type_array(new_id_from_chars("a_tp", 4), N_DIMS, prim_t_int);
- current_ir_graph = get_const_code_irg();
- set_array_bounds(array_type, 0,
- new_Const(mode_Iu, new_tarval_from_long (L_BOUND, mode_Iu)),
- new_Const(mode_Iu, new_tarval_from_long (U_BOUND, mode_Iu)));
-
- main_irg = new_ir_graph (proc_main_e, 4);
-
- /* The array is an ir_entity of the method, placed on the mehtod's own memory,
- the stack frame. */
- array_ent = new_entity(get_cur_frame_type(), new_id_from_chars("a", 1), array_type);
- /* As the array is accessed by Sel nodes, we need information about
- the ir_entity the node selects. Entities of an array are it's elements
- which are, in this case, integers. */
- /* change ir_entity owner types. */
- field_ent = get_array_element_entity(array_type);
-
-
-
- /* Now the "real" program: */
- /* Select the array from the stack frame. */
- array_ptr = new_simpleSel(get_store(), get_irg_frame(main_irg), array_ent);
- /* Load element 3 of the array. For this first generate the pointer
- to this the element by a select node. (Alternative: increase
- array pointer by (three * elt_size), but this complicates some
- optimizations.) The ir_type information accessible via the ir_entity
- allows to generate the pointer increment later. */
- c3 = new_Const (mode_Iu, new_tarval_from_long (3, mode_Iu));
- {
- ir_node *in[1];
- in[0] = c3;
- elt = new_Sel(get_store(), array_ptr, 1, in, field_ent);
- }
- val = new_Load(get_store(), elt, mode_Is);
- set_store(new_Proj(val, mode_M, pn_Load_M));
- val = new_Proj(val, mode_Is, pn_Load_res);
-
- /* return the result of procedure main */
- {
- ir_node *in[1];
- in[0] = val;
-
- x = new_Return (get_store (), 1, in);
- }
- mature_immBlock (get_irg_current_block(main_irg));
-
- /* complete the end_block */
- add_immBlock_pred (get_irg_end_block(main_irg), x);
- mature_immBlock (get_irg_end_block(main_irg));
-
- irg_finalize_cons (main_irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(main_irg);
-
- /* verify the graph */
- irg_vrfy(main_irg);
- printf("Dumping the graph and a ir_type graph.\n");
- dump_ir_block_graph (main_irg, dump_file_suffix);
- dump_type_graph(main_irg, dump_file_suffix);
- dump_ir_block_graph_w_types(main_irg, dump_file_suffix);
- dump_all_types(dump_file_suffix);
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/call_str_example.c
- * Purpose: Shows representation of constant string.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <string.h>
-#include <stdio.h>
-
-#include <libfirm/firm.h>
-
-/**
- * This file constructs the ir for the following pseudo-program:
- *
- * void f(char *);
- *
- * void CALL_STR_EXAMPLE_main () {
- * f("Hello World\n");
- * }
- *
- * This program demonstrates how to represent string constants.
- */
-
-int main(void)
-{
- char *dump_file_suffix = "";
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* ir_type information for the method main */
- ir_type *proc_called; /* ir_type information for called method f */
- ir_type *U8, *U8array, *string_ptr; /* ir_type for pointers to strings. */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_entity *const_str; /* represents a constant string. */
- char *str = "Hello World\n"; /* The constant string. */
- ir_node *x, *str_addr, *proc_ptr, *call;
- symconst_symbol sym;
- size_t i;
-
- printf("\nCreating an IR graph: CALL_STR_EXAMPLE...\n");
-
- /* init library */
- init_firm (NULL);
-
- /* An unsinged 8 bit ir_type */
- U8 = new_type_primitive (new_id_from_chars("char", 4), mode_Bu);
- /* An array containing unsigned 8 bit elements. */
- U8array = new_type_array (new_id_from_chars("char_arr", 8), 1, U8);
- set_array_lower_bound_int(U8array, 0, 0);
-
- string_ptr = new_type_pointer (new_id_from_chars ("ptr_to_string", 13), U8array, mode_P);
-
- /* Make a global ir_entity that represents the constant String. */
- const_str = new_entity(get_glob_type(), new_id_from_str("constStr"), U8array);
- set_entity_variability(const_str, variability_constant);
- for (i = 0; i < strlen(str); i++) {
- tarval *val = new_tarval_from_long(str[i], mode_Bu);
- ir_node *con = new_Const(mode_Bu, val);
- add_compound_ent_value(const_str, con, get_array_element_entity(U8array));
- }
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a program as a large class containing
- * all functions of the program as methods in this class. This class is
- * automatically generated.
- * We use the same name for the method ir_type as for the method ir_entity.
- */
-#define METHODNAME "CALL_STR_EXAMPLE_main"
-#define NRARGS 0
-#define NRES 0
- owner = get_glob_type();
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
-
- /* Make ir_type information for called method which also belongs to the
- global ir_type. */
-#define F_METHODNAME "f"
-#define F_NRARGS 1
-#define F_NRES 0
- owner = get_glob_type();
- proc_called = new_type_method(new_id_from_chars(F_METHODNAME, strlen(F_METHODNAME)),
- F_NRARGS, F_NRES);
- set_method_param_type(proc_called, 0, string_ptr);
-
-
- /* Make the ir_entity for main needed for a correct ir_graph. */
-#define ENTITYNAME "CALL_STR_EXAMPLE_main"
- ent = new_entity (owner, new_id_from_chars (ENTITYNAME, strlen(ENTITYNAME)),
- proc_main);
-
- /* Generates the basic graph for the method represented by ir_entity ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know how many local variables the method has.
- */
-#define NUM_OF_LOCAL_VARS 0
- irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
-
- /* get the pointer to the string constant */
- sym.entity_p = const_str;
- str_addr = new_SymConst(mode_P, sym, symconst_addr_ent);
-
- /* get the pointer to the procedure from the class ir_type */
- /* this is how a pointer to be fixed by the linker is represented. */
- sym.ident_p = new_id_from_str (F_METHODNAME);
- proc_ptr = new_SymConst (mode_P, sym, symconst_addr_name);
-
- /* call procedure set_a, first built array with parameters */
- {
- ir_node *in[1];
- in[0] = str_addr;
- call = new_Call(get_store(), proc_ptr, 1, in, proc_called);
- }
- /* make the possible changes by the called method to memory visible */
- set_store(new_Proj(call, mode_M, pn_Call_M));
-
- /* Make the return node returning the memory. */
- x = new_Return (get_store(), 0, NULL);
- /* Now we generated all instructions for this block and all its predecessor blocks
- * so we can mature it. */
- mature_immBlock (get_irg_current_block(irg));
-
- /* This adds the in edge of the end block which originates at the return statement.
- * The return node passes controlflow to the end block. */
- add_immBlock_pred (get_irg_end_block(irg), x);
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock (get_irg_end_block(irg));
-
- irg_finalize_cons (irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, dump_file_suffix);
- dump_all_types(dump_file_suffix);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/cond_example.c
- * Purpose: Shows how to represent boolean expressions.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* main(int a) {
-* if ((a > 2) && (a < 10))
-* { a = 1; }
-*
-* return a;
-**/
-
-int main(void)
-{
- ir_type *prim_t_int;
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *method; /* the ir_type of this method */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *x, *x_then, *arg1, *c2, *c10, *cmpGt, *cmpLt, *and, *f, *t, *b;
-
- printf("\nCreating an IR graph: COND_EXAMPLE...\n");
-
- /* init library */
- init_firm(NULL);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "COND_EXAMPLE" with a method main as an
- * ir_entity.
- */
-#define CLASSNAME "COND_EXAMPLE"
-#define ENTITYNAME "main"
-
- owner = new_type_class(new_id_from_chars(CLASSNAME, strlen(CLASSNAME)));
- method = new_type_method(new_id_from_chars("main", 4), 1, 1);
- set_method_param_type(method, 0, prim_t_int);
- set_method_res_type(method, 0, prim_t_int);
- ent = new_entity(owner, new_id_from_chars(ENTITYNAME, strlen(ENTITYNAME)), method);
- get_entity_ld_name(ent);
-
-
- /* Generates the basic graph for the method represented by ir_entity ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know how many local variables the method has.
- */
-#define NUM_OF_LOCAL_VARS 1
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- /* get the first argument a of method main - see irgraph.h */
- arg1 = new_Proj(get_irg_args(irg), mode_Is, 0);
-
- /* arg1 as first first local variable - makes things simple */
- set_value(0, arg1);
-
- /* the expression that evaluates the condition */
- /* cmpGt = a > 2 */
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- cmpGt = new_Proj(new_Cmp(get_value(0, mode_Is), c2), mode_b, pn_Cmp_Gt);
- cmpGt = new_Conv(cmpGt, mode_Is);
-
- /* cmpLt = a < 10 */
- c10 = new_Const(mode_Is, new_tarval_from_long(10, mode_Is));
- cmpLt = new_Proj(new_Cmp(get_value(0, mode_Is), c10), mode_b, pn_Cmp_Lt);
- cmpLt = new_Conv(cmpLt, mode_Is);
-
- /* cmpGt && cmpLt */
- and = new_And(cmpGt, cmpLt, mode_Is);
- /* compare result and 0 because we have no cast from integer to bool */
- and = new_Cmp(and, new_Const(mode_Is, new_tarval_from_long(0, mode_Is)));
- and = new_Proj(and, mode_b, pn_Cmp_Lg);
-
- /* the conditional branch */
- x = new_Cond(and);
- f = new_Proj(x, mode_X, pn_Cond_false); /* if condition is false */
- t = new_Proj(x, mode_X, pn_Cond_true); /* if condition is true */
-
- mature_immBlock(get_irg_current_block(irg));
-
- /* generate and fill the then block */
- b = new_immBlock();
- add_immBlock_pred(b, t);
- set_value(0, new_Const(mode_Is, new_tarval_from_long(1, mode_Is)));
- mature_immBlock(b);
- x_then = new_Jmp();
-
- /* generate the fall through block and add all cfg edges */
- b = new_immBlock();
- add_immBlock_pred(b, x_then);
- add_immBlock_pred(b, f);
-
-
- /* Generate the return node into current region. */
- {
- ir_node *in[1]; /* this is the array containing the return parameters */
- in[0] = get_value(0, mode_Is);
- x = new_Return(get_store(), 1, in);
- }
- /* Now generate all instructions for this block and all its predecessor blocks
- * so we can mature it. */
- mature_immBlock(get_irg_current_block(irg));
-
- /* This adds the in edge of the end block which originates at the
- return statement. The return node passes controlflow to the end block.*/
- add_immBlock_pred(get_irg_end_block(irg), x);
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph(irg, 0);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-FIRM_HOME = $(HOME)/projects/firm
-FIRM_BUILD = $(FIRM_HOME)/build/i686-pc-linux-gnu/debug/
-FIRM_CFLAGS = -I$(FIRM_HOME)/libfirm/include -I$(FIRM_HOME)/obstack -I$(FIRM_HOME)/libcore -I$(FIRM_HOME)/libcore/libcore -I$(FIRM_HOME)
-FIRM_LIBS = -L$(FIRM_BUILD) -lfirm -llpp -lcore -lm -lz -ldl
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/const_ent_example.c
- * Purpose: Shows how to construct ir_type information for constant entities.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-
-#include <stdio.h>
-#include <string.h>
-
-
-
-#include <libfirm/firm.h>
-
-/**
- * This file constructs ir_type information for constant entities.
- *
- * It constructs the information for a class ir_type with a dispatch
- * table. The class has a field a, and two methods f and g. The
- * class is represented by a class ir_type with two entities for the
- * field a and the reference to the dispatch table. This reference
- * is a constant ir_entity. Ther dispatch table is also represented
- * by a class ir_type that contains the two methods. There is one ir_entity
- * of the dispatch table which is constant.
- *
- * Further the example shows the representation of a constant global
- * array.
- *
- * class C {
- * int a;
- * void f();
- * void g(int);
- * }
- * int[4] arre = (7, 2, 13, 92);
- **/
-
-int main(void)
-{
- ident *Ci, *ai, *fi, *fti, *gi, *gti, *inti, *dipti, *diptpi, *diptpei, *diptei;
- /* suffix i names identifiers */
- ir_type *Ct, *intt, *ft, *gt, *diptt, *diptpt;
- /* t names types */
- ir_entity *ae, *fe, *ge, *dipte, *diptpe; /* e names entities */
- symconst_symbol sym;
- ir_node *n;
-
- printf("\nExample program for constant entites.\n");
- printf("Creating ir_type information...\n");
-
- /** init library */
- init_firm (NULL);
-
- /** make idents for all used identifiers in the program. */
- Ci = new_id_from_chars("C", strlen("C"));
- ai = new_id_from_chars("a", strlen("a"));
- fi = new_id_from_chars("f", strlen("f"));
- fti = new_id_from_chars("f_type", strlen("f_type"));
- gi = new_id_from_chars("g", strlen("g"));
- gti = new_id_from_chars("g_type", strlen("g_type"));
- inti = new_id_from_chars("int", strlen("int"));
- dipti = new_id_from_chars("C_dispatch_table_type", strlen("C_dispatch_table_type"));
- diptei = new_id_from_chars("C_dispatch_table", strlen("C_dispatch_table"));
- diptpi = new_id_from_chars("C_dispatch_table_p_type", strlen("C_dispatch_table_p_type"));
- diptpei = new_id_from_chars("C_dispatch_table_p", strlen("C_dispatch_table_p"));
-
-
- /** make the ir_type information needed */
- /* Language defined types */
- intt = new_type_primitive(inti, mode_Is);
- /* Program defined types */
- Ct = new_type_class(Ci);
- ft = new_type_method(fti, 0, 0); /* 0 parameters, 0 results */
- gt = new_type_method(gti, 1, 0); /* 1 parameter, 0 results */
- /* Compiler defined types: dispatch table and pointer to it */
- diptt = new_type_class(dipti);
- diptpt = new_type_pointer(diptpi, diptt, mode_P);
- /** add structure to ir_type graph **/
- /* parameters of methods */
- set_method_param_type(gt, 0, intt);
-
- /** make entities **/
- ae = new_entity(Ct, ai, intt);
- fe = new_entity(diptt, fi, ft);
- ge = new_entity(diptt, gi, gt);
- dipte = new_entity(get_glob_type(), diptei, diptt);
- diptpe = new_entity(Ct, diptpei, diptpt);
-
- /** Add constant ir_entity information **/
- current_ir_graph = get_const_code_irg();
- /* The pointer to the dispatch table is constant. */
- /* The constant is the address of the given ir_entity */
- sym.entity_p = dipte;
- n = new_SymConst(mode_P, sym, symconst_addr_ent);
- set_entity_variability(diptpe, variability_constant);
- set_atomic_ent_value(diptpe, n);
-
- /* The ir_entity representing the dispatch table is constant, too. */
- set_entity_variability(dipte, variability_constant);
- add_compound_ent_value(dipte, get_atomic_ent_value(fe), fe);
- add_compound_ent_value(dipte, get_atomic_ent_value(ge), ge);
-
-{
- /*** Example with an array ***/
- ident *arrei, *arrti;
- ir_type *arrt;
- ir_entity *arre, *arrelte;
-
- arrei = new_id_from_chars("arr", strlen("arr"));
- arrti = new_id_from_chars("arr_t", strlen("arr_t"));
-
- /** The array ir_type **/
- /* Don't reuse int ir_type so that graph layout is better readable */
- intt = new_type_primitive(inti, mode_Is);
- arrt = new_type_array(arrti, 1, intt);
- set_array_bounds_int(arrt, 0, 0, 4);
- arrelte = get_array_element_entity(arrt);
-
- /** The constant array ir_entity **/
- arre = new_entity(get_glob_type(), arrei, arrt);
- set_entity_variability(arre, variability_constant);
- current_ir_graph = get_const_code_irg();
- n = new_Const(mode_Is, new_tarval_from_long (7, mode_Is));
- add_compound_ent_value(arre, n, arrelte);
- n = new_Const(mode_Is, new_tarval_from_long (2, mode_Is));
- add_compound_ent_value(arre, n, arrelte);
- n = new_Const(mode_Is, new_tarval_from_long (13, mode_Is));
- add_compound_ent_value(arre, n, arrelte);
- n = new_Const(mode_Is, new_tarval_from_long (92, mode_Is));
- add_compound_ent_value(arre, n, arrelte);
-}
- printf("Done building the graph. Dumping it.\n");
- dump_all_types(0);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/const_eval_example.c
- * Purpose: Test constant evaluation.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* main() {
-* int c, d;
-*
-* c = 5 + 7;
-* d = 7 + 5;
-*
-* return (c, d);
-* }
-**/
-
-int
-main(void)
-{
- ir_type *prim_t_int;
- ir_graph *irg;
- ir_type *owner;
- ir_type *method; /* the ir_type of this method */
- ir_entity *ent;
- ir_node *a, *b, *c, *d, *x;
-
- printf("\nCreating an IR graph: CONST_EVAL_EXAMPLE...\n");
-
- init_firm(NULL);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
- /* Try both optimizations: */
- set_opt_constant_folding(1);
- set_opt_cse(1);
-
- owner = new_type_class(new_id_from_chars("CONST_EVAL_EXAMPLE", 18));
- method = new_type_method(new_id_from_chars("main", 4), 0, 2);
- set_method_res_type(method, 0, prim_t_int);
- set_method_res_type(method, 1, prim_t_int);
- ent = new_entity(owner, new_id_from_chars("main", 4), method);
- get_entity_ld_name(ent);
-
- irg = new_ir_graph(ent, 4);
-
- a = new_Const(mode_Is, new_tarval_from_long(7, mode_Is));
- b = new_Const(mode_Is, new_tarval_from_long(5, mode_Is));
-
- x = new_Jmp();
- mature_immBlock(get_irg_current_block(irg));
-
- /* To test const eval on DivMod
- c = new_DivMod(get_store(), a, b);
- set_store(new_Proj(c, mode_M, pn_DivMod_M));
- d = new_Proj(c, mode_Is, pn_DivMod_res_mod);
- c = new_Proj(c, mode_Is, pn_DivMod_res_div);
- */
-
- c = new_Add(new_Const(mode_Is, new_tarval_from_long(5, mode_Is)),
- new_Const(mode_Is, new_tarval_from_long(7, mode_Is)),
- mode_Is);
- d = new_Add(new_Const(mode_Is, new_tarval_from_long(7, mode_Is)),
- new_Const(mode_Is, new_tarval_from_long(5, mode_Is)),
- mode_Is);
-
- {
- ir_node *in[2];
- in[0] = c;
- in[1] = d;
-
- x = new_Return(get_store(), 2, in);
- }
-
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph(irg, 0);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/dead_block_example.c
- * Purpose: Test unreachable code elimination.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-
-
-#include <libfirm/firm.h>
-
-/*
- * a dead block / unreachable code.
- */
-
-/**
-* This file constructs a control flow of following shape:
-*
-*
-* firstBlock
-* / \
-* / \
-* |/_ _\|
-* Block1 Block2 deadBlock
-* \ | /
-* \ | /
-* _\| \ / |/_
-* nextBlock
-*
-*
-* This is a program as, e.g.,
-*
-* if () then
-* { Jmp label1; } // happens anyways
-* else
-* { Jmp label1; } // happens anyways
-* label1:
-* return();
-* Jmp label1;
-*
-**/
-
-int main(void)
-{
- char *dump_file_suffix = "";
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* ir_type information for the method main */
- ir_type *prim_t_int;
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp, *Block2,
- *deadBlock, *x;
-
- /* init library */
- init_firm (NULL);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Is);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "empty" according to the file name
- * with a method main as an ir_entity.
- */
-#define CLASSNAME "DEAD_BLOCK"
-#define METHODNAME "main"
-#define NRARGS 0
-#define NRES 1
- printf("\nCreating an IR graph: %s...\n", CLASSNAME);
-
- owner = new_type_class (new_id_from_chars (CLASSNAME, strlen(CLASSNAME)));
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- set_method_res_type(proc_main, 0, prim_t_int);
- ent = new_entity (owner,
- new_id_from_chars (METHODNAME, strlen(METHODNAME)),
- proc_main);
- get_entity_ld_name(ent); /* To enforce name mangling for vcg graph name */
-#define NUM_OF_LOCAL_VARS 1
-
- irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
-
- /* to make a condition */
- c1 = new_Const (mode_Is, new_tarval_from_long (1, mode_Is));
- c2 = new_Const (mode_Is, new_tarval_from_long (2, mode_Is));
- set_value(0, c2);
-
- cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, pn_Cmp_Eq));
- f = new_Proj(cond, mode_X, 0);
- t = new_Proj(cond, mode_X, 1);
- mature_immBlock(get_irg_current_block(irg));
-
- /* end block to add jmps */
- endBlock = new_immBlock();
-
- /* Block 1 */
- Block1 = new_immBlock();
- add_immBlock_pred(Block1, t);
- mature_immBlock(Block1);
- jmp = new_Jmp();
- add_immBlock_pred(endBlock, jmp);
-
- /* Block 2 */
- Block2 = new_immBlock();
- add_immBlock_pred(Block2, f);
- mature_immBlock(Block2);
- jmp = new_Jmp();
- add_immBlock_pred(endBlock, jmp);
-
- /* dead Block */
- deadBlock = new_immBlock();
- mature_immBlock(deadBlock);
- jmp = new_Jmp();
- add_immBlock_pred(endBlock, jmp);
-
- /* finish end block */
- set_cur_block(endBlock);
- {
- ir_node *in[1];
- in[0] = get_value(0, mode_Is);
- get_store();
- x = new_Return (get_store(), 1, in);
- }
- mature_immBlock (get_irg_current_block(irg));
-
- add_immBlock_pred (get_irg_end_block(irg), x);
- mature_immBlock (get_irg_end_block(irg));
-
- irg_finalize_cons (irg);
-
- printf("Optimizing ...\n");
- local_optimize_graph (irg);
- dead_node_elimination (irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Dumping the graph and a control flow graph.\n");
- dump_ir_block_graph (irg, dump_file_suffix);
- dump_cfg (irg, dump_file_suffix);
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/irr_loop_example.c
- * Purpose: Test Phi construction with irregular control flow.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
- * This file constructs a control flow with an unreachable
- * loop _and_ an unreachable endless loop. This looks like:
- *
- * LoopBlock2 LoopBlock2'
- * | /|\ | /|\
- * | | | |
- * \|/ | \|/ |
- * LoopBlock1 StartBlock LoopBlock1'
- * \ /
- * \ /
- * _\| |/_
- * ReturnBlock
- * |
- * |
- * \|/
- * nextBlock
- *
- *
- **/
-
-int main(void)
-{
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *prim_t_int;
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* typeinformation for the method main */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *returnBlock, *loopBlock1, *loopBlock2, *x, *c1, *c2, *t, *f;
-
-
- /* init library */
- init_firm(NULL);
- /*set_opt_normalize(0); */
- set_opt_constant_folding(0); /* so that the stupid tests are not optimized. */
- set_opt_cse(1);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "empty" according to the file name
- * with a method main as an ir_entity.
- */
-#define CLASSNAME "DEAD_LOOP"
-#define METHODNAME "main"
-#define NRARGS 1
-#define NRES 0
- printf("\nCreating an IR graph: %s...\n", CLASSNAME);
-
- prim_t_int = new_type_primitive(new_id_from_str("int"), mode_Is);
-
- owner = new_type_class(new_id_from_str(CLASSNAME));
- proc_main = new_type_method(new_id_from_str(METHODNAME), NRARGS, NRES);
- set_method_param_type(proc_main, 0, prim_t_int);
- ent = new_entity(owner, new_id_from_str(METHODNAME), proc_main);
- get_entity_ld_name(ent); /* To enforce name mangling for vcg graph name */
-
-#define NUM_OF_LOCAL_VARS 0
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- returnBlock = get_irg_current_block(irg);
-
- /* Make some real stupid stuff: a data loop (without Phi). */
- {
- ir_node *a, *b, *c, *in[2];
- add_immBlock_pred(get_cur_block(), new_Bad());
- a = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
- b = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- c = new_Add(a, b, mode_Is);
- b = new_Sub(c, b, mode_Is);
- in[0] = b;
- in[1] = new_Bad();
- a = new_Phi(2, in, mode_Is);
- set_Add_left(c, a);
- /* add_End_keepalive(get_irg_end(irg), a); */
- set_nodes_block(c, new_Bad());
- set_nodes_block(a, new_Bad());
- }
-
- /* Make the unreachable loop */
- loopBlock1 = new_immBlock();
- loopBlock2 = new_immBlock();
- x = new_Jmp();
- add_immBlock_pred(loopBlock1, x);
- mature_immBlock(loopBlock1);
-
- set_cur_block(loopBlock1);
- c1 = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
- c2 = new_Proj(get_irg_args(irg), mode_Is, 0);
- x = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, pn_Cmp_Eq));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
- add_immBlock_pred(loopBlock2, t);
- add_immBlock_pred(returnBlock, f);
- mature_immBlock(loopBlock2);
-
- /* Make the unreachable, endless loop */
- loopBlock1 = new_immBlock();
- loopBlock2 = new_immBlock();
- x = new_Jmp();
- add_immBlock_pred(loopBlock1, x);
- mature_immBlock(loopBlock1);
-
- set_cur_block(loopBlock1);
- x = new_Jmp();
- add_immBlock_pred(loopBlock2, x);
- add_End_keepalive(get_irg_end(irg), loopBlock1);
- mature_immBlock(loopBlock2);
-
- /* Make the return block */
- set_cur_block(returnBlock);
- x = new_Return(get_store(), 0, NULL);
- mature_immBlock(get_irg_current_block(irg));
-
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
-#if 0
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-#endif
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Dumping the graph and a control flow graph.\n");
- turn_off_edge_labels();
- dump_keepalive_edges(1);
- dump_consts_local(0);
- dump_ir_graph(irg, "-cfg");
- dump_ir_block_graph(irg, "-cfg");
- dump_cfg(irg, "-cfg");
-
- printf("Running analyses.\n");
- compute_irg_outs(irg);
- compute_doms(irg);
- construct_backedges(irg);
-
- printf("Dumping the graph with analyses information.\n");
-
- dump_out_edges(0);
- dump_dominator_information(0);
- dump_loop_information(0);
- dump_backedge_information(1);
-
- dump_ir_graph(irg, "-ana");
- dump_ir_block_graph(irg, "-anablocks");
- dump_cfg(irg, "-ana");
- dump_loop_tree(irg, "-ana");
-
- printf("Optimizing.\n");
- optimize_cf(current_ir_graph);
- local_optimize_graph(current_ir_graph);
-
- printf("Dumping the optimized graph.\n");
- dump_ir_graph(irg, "-opt");
- dump_ir_block_graph(irg, "-opt");
- dump_cfg(irg, "-opt");
- dump_loop_tree(irg, "-opt");
-
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/empty.c
- * Purpose: The smallest possible firm graph.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-
-#include <stdio.h>
-#include <string.h>
-
-
-
-#include <libfirm/firm.h>
-
-/**
-* An empty Firm program.
-*
-* This file constructs the ir for the following pseudo-program:
-*
-* main() {
-* return;
-* }
-*
-*
-**/
-
-int main(void)
-{
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* ir_type information for the method main */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *x; /* to build control flow */
-
- printf("\nCreating an IR graph: EMPTY...\n");
-
- /* init library */
- init_firm (NULL);
-
- /** Build ir_type information for the procedure. **/
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions in this file as methods.
- * This clas is generated automatically.
- */
- owner = get_glob_type();
-
-#define METHODNAME "EMPTY_main"
-#define NRARGS 0
-#define NRES 0
- /* The ir_type of the method */
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- /* An ir_entity representing the method. Owner of the ir_entity is the global class
- ir_type mentioned above. */
- ent = new_entity ((ir_type *)owner,
- new_id_from_chars (METHODNAME, strlen(METHODNAME)),
- (ir_type *)proc_main);
-
- /** Build code for the procedure. **/
-
- /* Generates the basic graph for the method represented by ir_entity ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know the number of local variables (including
- * the arguments) in the method.
- */
-#define NUM_OF_LOCAL_VARS 0
- irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
-
- /* The constructor new_ir_graph() generated a region to place nodes in.
- * This region is accessible via the attribut current_block of irg and
- * it is not matured.
- * Generate the return node into this region. The Return node is needed to
- * return at least the memory. */
- x = new_Return (get_store(), 0, NULL);
- /* Now we generated all instructions for this block and all its predecessor
- * blocks so we can mature it. (There are not too much.) */
- mature_immBlock (get_irg_current_block(irg));
-
- /* This adds the in edge of the end block which originates at the return statement.
- * The return node passes controlflow to the end block. */
- add_immBlock_pred (get_irg_end_block(irg), x);
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock (get_irg_end_block(irg));
-
- /* Verify the graph. Finds some very bad errors in the graph. */
- irg_vrfy(irg);
- irg_finalize_cons (irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, 0);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/endless_loop.c
- * Purpose: Representation of an endless loop.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* VAR_A is some extern variable.
-*
-* main(int a) { // pos 0
-* int b = 1; // pos 1
-* int h; // pos 2
-*
-* while (0 == 0) loop {
-* h = a;
-* a = b;
-* b = h;
-* VAR_A = b;
-* }
-*
-* return a-b;
-* }
-**/
-
-int
-main(void)
-{
- char *dump_file_suffix = "";
- ir_type *prim_t_int;
- ir_graph *irg;
- ir_type *owner;
- ir_type *proc_main;
- ir_entity *ent;
- ir_node *b, *x, *r, *t, *f;
- union symconst_symbol symbol;
-
- printf("\nCreating an IR graph: ENDLESS_LOOP_EXAMPLE...\n");
-
- init_firm(NULL);
-
- set_optimize(1);
- set_opt_constant_folding(1);
- set_opt_cse(1);
- set_opt_global_cse(0);
-
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
-#define METHODNAME "main_tp"
-#define NRARGS 1
-#define NRES 1
-
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- set_method_param_type(proc_main, 0, prim_t_int);
- set_method_res_type(proc_main, 0, prim_t_int);
-
-
- owner = new_type_class(new_id_from_chars("ENDLESS_LOOP_EXAMPLE", 20));
- ent = new_entity(owner, new_id_from_chars("main", strlen("main")), proc_main);
- get_entity_ld_name(ent); /* force name mangling */
-
- /* Generates start and end blocks and nodes and a first, initial block */
- irg = new_ir_graph(ent, 4);
-
- /* Generate two values */
- set_value(0, new_Proj(get_irg_args(irg), mode_Is, 0));
- set_value(1, new_Const(mode_Is, new_tarval_from_long(1, mode_Is)));
-
- x = new_Jmp();
- mature_immBlock(get_irg_current_block(irg));
-
- /* generate a block for the loop header and the conditional branch */
- r = new_immBlock();
- add_immBlock_pred(r, x);
- x = new_Cond(new_Proj(new_Cmp(new_Const(mode_Is, new_tarval_from_long(0, mode_Is)),
- new_Const(mode_Is, new_tarval_from_long(0, mode_Is))),
- mode_b, pn_Cmp_Eq));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate the block for the loop body */
- b = new_immBlock();
- add_immBlock_pred(b, t);
- x = new_Jmp();
- add_immBlock_pred(r, x);
-
- /* The code in the loop body,
- as we are dealing with local variables only the dataflow edges
- are manipulated. */
- set_value(2, get_value(0, mode_Is));
- set_value(0, get_value(1, mode_Is));
- set_value(1, get_value(2, mode_Is));
-
- /* set VAR_A to constant value */
- symbol.entity_p = new_entity(get_glob_type(),new_id_from_chars("VAR_A",6),prim_t_int);
- set_store(new_Proj(new_Store(get_store(),
- new_SymConst(mode_P, symbol, symconst_addr_ent),
- get_value(1, mode_Is)),
- mode_M, pn_Store_M));
-
- mature_immBlock(b);
- mature_immBlock(r);
-
- /* generate the return block */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- mature_immBlock(r);
-
- {
- ir_node *in[1];
- in[0] = new_Sub(get_value(0, mode_Is), get_value(1, mode_Is), mode_Is);
-
- x = new_Return(get_store(), 1, in);
- }
-
- /* finalize the end block generated in new_ir_graph() */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
-
- dead_node_elimination(irg);
- local_optimize_graph(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- /* output the vcg file */
- printf("Done building the graph. Dumping it.\n");
- /* turn_of_edge_labels(); */
- dump_keepalive_edges(1);
- dump_all_types(dump_file_suffix);
- dump_ir_block_graph(irg, dump_file_suffix);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/exception.c
- * Purpose: Shows construction of exceptions.
- * Tests Phi construction.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 2004 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-
-#include <libfirm/firm.h>
-
-
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* main() {
-* int a = 5; // val 0
-* int b = 6; // val 1
-* int c = 7; // val 2
-* int d; // val 3
-*
-* try {
-* d = a/0;
-* c = 8;
-* d = b/0
-* } catch () { return c }
-*
-* return d;
-**/
-
-int main(void)
-{
- ir_type *prim_t_int;
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *method; /* the ir_type of this method */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *x, *catch_block, *block, *zero, *a, *b, *c, *d;
-
- printf("\nCreating an IR graph: EXCEPTION...\n");
-
- /* init library */
- init_firm (NULL);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_str ("int"), mode_Is);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "IF_ELSE_EXAMPLE" with a method main as an
- * ir_entity.
- */
-#define ENTITYNAME "EXCEPTION_main"
-
- owner = get_glob_type();
- method = new_type_method (new_id_from_str(ENTITYNAME), 0, 1);
- set_method_res_type(method, 0, prim_t_int);
-
- ent = new_entity (owner, new_id_from_str (ENTITYNAME), method);
-
- /* Generates the basic graph for the method represented by ir_entity ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know how many local variables the method has.
- */
-#define NUM_OF_LOCAL_VARS 4
-
- irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
-
- /* Initialize a, b, c. */
- zero = new_Const (mode_Is, new_tarval_from_long (0, mode_Is));
- a = new_Const (mode_Is, new_tarval_from_long (5, mode_Is));
- b = new_Const (mode_Is, new_tarval_from_long (6, mode_Is));
- c = new_Const (mode_Is, new_tarval_from_long (7, mode_Is));
-
- /* set a and b to constants */
- set_value (0, a); /* this (0) is variable a */
- set_value (1, b); /* this (1) is variable b */
- set_value (2, c); /* this (2) is variable c */
-
- block = get_cur_block();
- catch_block = new_immBlock();
- set_cur_block(block);
-
- /* d = a / 0 */
- d = new_Div(get_store(), get_value(0, mode_Is), zero, mode_Is, op_pin_state_pinned);
- set_store(new_Proj(d, mode_M, pn_Div_M));
- x = new_Proj(d, mode_X, pn_Div_X_except);
- add_immBlock_pred(catch_block, x);
- d = new_Proj(d, mode_Is, pn_Div_res);
- set_value(3, d); /* this (3) is variable d */
-
- /* c = 8 */
- c = new_Const (mode_Is, new_tarval_from_long (8, mode_Is));
- set_value (2, c); /* this (2) is variable c */
-
- /* d = b / 0 */
- d = new_Div(get_store(), get_value(1, mode_Is), zero, mode_Is, op_pin_state_pinned);
- set_store(new_Proj(d, mode_M, pn_Div_M));
- x = new_Proj(d, mode_X, pn_Div_X_except);
- add_immBlock_pred(catch_block, x);
- d = new_Proj(d, mode_Is, pn_Div_res);
- set_value(3, d); /* this (3) is variable d */
-
- /* return d */
- d = get_value(3, mode_Is);
- x = new_Return (get_store(), 1, &d);
- mature_immBlock(get_cur_block());
- add_immBlock_pred(get_irg_end_block(current_ir_graph), x);
-
- /* return c */
- set_cur_block(catch_block);
- c = get_value(2, mode_Is);
- x = new_Return (get_store(), 1, &c);
- mature_immBlock(get_cur_block());
- add_immBlock_pred(get_irg_end_block(current_ir_graph), x);
-
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock (get_irg_end_block(irg));
-
- irg_finalize_cons (irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, "");
- dump_ir_graph (irg, "");
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/float_example.c
- * Purpose:
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-
-
-#include <libfirm/firm.h>
-
-/**
-* An Firm program to test float values.
-*
-* This file constructs the ir for the following pseudo-program:
-*
-* main() {
-* ...
-* }
-*
-*
-**/
-
-int main(void)
-{
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* ir_type information for the method main */
- ir_type *prim_t_dbl;
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *x; /* to build control flow */
- tarval *tv;
-
- printf("\nCreating an IR graph: FLOAT EXAMPLE...\n");
-
- /* init library */
- init_firm (NULL);
-
- /** Build ir_type information for the procedure. **/
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions in this file as methods.
- * This clas is generated automatically.
- */
- owner = get_glob_type();
-
-#define METHODNAME "FLOAT_EXAMPLE_main"
-#define NRARGS 0
-#define NRES 1
- /* The ir_type of the method */
- prim_t_dbl = new_type_primitive(new_id_from_chars ("dbl", 3), mode_D);
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- set_method_res_type(proc_main, 0, prim_t_dbl);
-
- /* An ir_entity representing the method. Owner of the ir_entity is the global class
- ir_type mentioned above. */
- ent = new_entity ((ir_type *)owner,
- new_id_from_chars (METHODNAME, strlen(METHODNAME)),
- (ir_type *)proc_main);
-
- /** Build code for the procedure. **/
-
- /* Generates the basic graph for the method represented by ir_entity ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know the number of local variables (including
- * the arguments) in the method.
- */
-#define NUM_OF_LOCAL_VARS 0
- irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
-
- tv = new_tarval_from_str ("12345678901234567890.1234567890", 31, mode_D);
-
-
-
-
- {
- ir_node *in[1]; /* this is the array containing the return parameters */
- in[0] = new_Const(mode_D, tv);
- x = new_Return (get_store(), 1, in);
- }
- /* Now we generated all instructions for this block and all its predecessor
- * blocks so we can mature it. (There are not too much.) */
- mature_immBlock (get_irg_current_block(irg));
-
- /* This adds the in edge of the end block which originates at the return statement.
- * The return node passes controlflow to the end block. */
- add_immBlock_pred (get_irg_end_block(irg), x);
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock (get_irg_end_block(irg));
-
- /* Verify the graph. Finds some very bad errors in the graph. */
- irg_vrfy(irg);
- irg_finalize_cons (irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, 0);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/global_cse.c
- * Purpose: Test global cse.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* int main(int a) {
-* int b = 2;
-* if ( a == b ) {
-* a := a - 3;
-* } else {
-* a := a - 3;
-* a := a + 5;
-* }
-* return a;
-* }
-**/
-
-int
-main(void)
-{
- ir_graph *irg;
- ir_type *owner;
- ir_entity *ent;
- ir_type *proc_main; /* ir_type information for the method main */
- ir_type *typ;
- ir_node *x, *r, *t, *f, *a, *cmp;
- int a_pos, b_pos;
-
- printf("\nCreating an IR graph: GLOBAL_CSE_EXAMPLE...\n");
-
- init_firm(NULL);
-
- set_optimize(1);
- set_opt_constant_folding(1);
- set_opt_cse(1);
- set_opt_global_cse(1);
-
-#define CLASSNAME "GLOBAL_CSE_EXAMPLE"
-#define METHODNAME "GLOBAL_CSE_EXAMPLE_main"
-#define NRARGS 1
-#define NRES 1
-
- /** Type information for the procedure **/
-
- owner = get_glob_type();
- /* Type information for the procedure */
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- /* The ir_entity for the procedure */
- ent = new_entity(owner,
- new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- proc_main);
- /* The ir_type int. This ir_type is necessary to model the result and parameters
- the procedure. */
-#define PRIM_NAME "int"
- typ = new_type_primitive(new_id_from_chars(PRIM_NAME, strlen(PRIM_NAME)), mode_Is);
- /* The parameter and result types of the procedure. */
- set_method_param_type(proc_main, 0, typ);
- set_method_res_type(proc_main, 0, typ);
-
- /** The code of the procedure **/
-
- /* Generates start and end blocks and nodes, and a first, initial block */
-#define NRLOCS 2
- irg = new_ir_graph(ent, NRLOCS);
-
- /* The value position used for: */
- a_pos = 0;
- b_pos = 1;
-
- /* Get the procedure parameter and assign it to the parameter variable
- a. */
- set_value(a_pos, new_Proj(get_irg_args(irg), mode_Is, 0));
- /* Generate the constant and assign it to b. The assignment is resovled to a
- dataflow edge. */
- set_value(b_pos, new_Const(mode_Is, new_tarval_from_long(2, mode_Is)));
- /* We know all predecessors of the block and all set_values and set_stores are
- preformed. We can mature the block. */
- mature_immBlock(get_irg_current_block(irg));
-
- /* Generate a conditional branch */
- cmp = new_Cmp(get_value(a_pos, mode_Is), get_value(b_pos, mode_Is)); /*
- cmp = new_Cmp(new_Const(mode_Is, new_tarval_from_long(2, mode_Is)),
- new_Const(mode_Is, new_tarval_from_long(2, mode_Is)));*/
- x = new_Cond(new_Proj(cmp, mode_b, pn_Cmp_Eq));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate and fill the then block */
- r = new_immBlock();
- add_immBlock_pred(r, t);
- a = new_Sub(get_value(a_pos, mode_Is),
- new_Const(mode_Is, new_tarval_from_long(3, mode_Is)),
- mode_Is);
- set_value(a_pos, a);
-
- mature_immBlock(r);
- t = new_Jmp();
-
- /* generate the else block */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- a = new_Sub(get_value(a_pos, mode_Is),
- new_Const(mode_Is, new_tarval_from_long(3, mode_Is)),
- mode_Is);
- a = new_Add(a, new_Const(mode_Is, new_tarval_from_long(5, mode_Is)), mode_Is);
- set_value(a_pos, a);
-
- mature_immBlock(r);
- f = new_Jmp();
-
- /* generate the fall through block and add all cfg edges */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- add_immBlock_pred(r, t);
- mature_immBlock(r);
- /* The Return statement */
- {
- ir_node *in[1], *store ;
- in[0] = get_value(a_pos, mode_Is);
- store = get_store();
-
- x = new_Return(store, 1, in);
- }
-
- /* finalize the end block generated in new_ir_graph() */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- /* verify the graph */
- irg_vrfy(irg);
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
- local_optimize_graph(irg);
-
-
- /* output the vcg file */
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph(irg, 0);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/global_var_example.c
- * Purpose: Illustrates representation of global variable.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/*
- * das leere FIRM Programm
- */
-
-/**
-* This program shows how to build ir for global variables.
-* It constructs the ir for the following pseudo-program:
-*
-* int i;
-*
-* main() {
-* i = 2;
-* return;
-* }
-**/
-
-int main(void)
-{
- char *dump_file_suffix = "";
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* ir_type information for the method main */
- ir_type *prim_t_int; /* describes int ir_type defined by the language */
- ir_entity *main_ent; /* represents this method as ir_entity of owner */
- ir_entity *i_ent; /* the ir_entity representing the global variable i */
- union symconst_symbol symbol;
- ir_node *x, *i_ptr, *store;
-
- printf("\nCreating an IR graph: GLOBAL_VAR ...\n");
-
- /* init library */
- init_firm (NULL);
-
- /* make basic ir_type information for primitive ir_type int.
- In Sather primitive types are represented by a class.
- This is the modeling appropriate for other languages.
- Mode_i says that all integers shall be implemented as a
- 32 bit integer value. */
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Is);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file or compilation unit as
- * a large class containing all functions as methods in this file.
- * This class is automatically generated and can be obtained by get_glob_type().
- */
-#define METHODNAME "GLOBAL_VAR_main"
-#define NRARGS 0
-#define NRES 0
-
- /* Main is an ir_entity of this global class. */
- owner = get_glob_type();
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- main_ent = new_entity (owner,
- new_id_from_chars (METHODNAME, strlen(METHODNAME)),
- proc_main);
-
- /* Generates the basic graph for the method represented by ir_entity main_ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know how many local variables the method has.
- */
-#define NUM_OF_LOCAL_VARS 0
-
- /* Generate the entities for the global variables. */
- i_ent = new_entity (get_glob_type(),
- new_id_from_chars ("i", strlen("i")),
- prim_t_int);
-
- irg = new_ir_graph (main_ent, NUM_OF_LOCAL_VARS);
-
- /* The constructor new_ir_graph() generated a region to place nodes in.
- * This region is accessible via the attribut current_block of irg and
- * it is not matured.
- * Generate the assignment to i and the return node into this region.
- * The Return node is needed to return at least the store. */
- symbol.entity_p = i_ent;
- i_ptr = new_SymConst(mode_P, symbol, symconst_addr_ent);
-
- store = new_Store (get_store(), i_ptr,
- new_Const(mode_Is, new_tarval_from_long (2, mode_Is)));
- set_store(new_Proj(store, mode_M, pn_Store_M));
-
- x = new_Return (get_store(), 0, NULL);
-
- /* Now generate all instructions for this block and all its predecessor blocks
- * so we can mature it. */
- mature_immBlock (get_irg_current_block(irg));
-
- /* This adds the in edge of the end block which originates at the return statement.
- * The return node passes controlflow to the end block. */
- add_immBlock_pred (get_irg_end_block(irg), x);
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock (get_irg_end_block(irg));
-
- irg_finalize_cons (irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, dump_file_suffix);
- dump_ir_graph_w_types (irg, dump_file_suffix);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/indentify_types.c
- * Purpose: Shows use of ir_type identification
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-int main(void)
-{
- ident *i1, *i2;
- ir_type *t1, *t2, *t3;
- firm_parameter_t params;
- type_identify_if_t params2;
-
- printf("\nCreating ir_type information for IDENTIFY_TYPES ...\n");
-
- /** init library */
- memset (¶ms, 0, sizeof(params));
- params.size = sizeof(params);
- params2.cmp = compare_names;
- params2.hash = NULL;
- params.ti_if = ¶ms2;
- init_firm(¶ms);
-
-
- i1 = new_id_from_str("type1");
- i2 = new_id_from_str("type2");
-
- t1 = new_type_class(i1);
- t1 = mature_type(t1);
-
- t1 = mature_type(t1);
-
- t2 = new_type_class(i1);
- t2 = mature_type(t2);
-
- t3 = new_type_class(i2);
- t3 = mature_type(t3);
-
- /*
- printf(" t1: "); DDMT(t1);
- printf(" t2: "); DDMT(t2);
- printf(" t3: "); DDMT(t3);
- */
-
- printf("Done building the graph. Dumping it.\n");
- dump_all_types(0);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/if_else_example.c
- * Purpose: Shows construction of if ... else control flow.
- * Tests Phi construction.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-
-#include <libfirm/firm.h>
-
-
-/**
- * This file constructs the ir for the following pseudo-program:
- *
- * main() {
- * int a = 0;
- * int b = 1;
- *
- * if (a > 2)
- * { a = b; }
- * else
- * { b = 2; }
- *
- * return a, b;
- */
-
-int main(void)
-{
- ir_type *prim_t_int;
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *method; /* the ir_type of this method */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *x, *x_then, *x_else, *c0, *c1, *c2, *cmpGt, *f, *t, *b;
-
- printf("\nCreating an IR graph: IF_ELSE_EXAMPLE...\n");
-
- /* init library */
- init_firm(NULL);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "IF_ELSE_EXAMPLE" with a method main as an
- * ir_entity.
- */
-#define ENTITYNAME "IF_ELSE_EXAMPLE_main"
-
- owner = get_glob_type();
- method = new_type_method(new_id_from_chars(ENTITYNAME, strlen(ENTITYNAME)), 0, 2);
- set_method_res_type(method, 0, prim_t_int);
- set_method_res_type(method, 1, prim_t_int);
-
- ent = new_entity(owner, new_id_from_chars(ENTITYNAME,
- strlen(ENTITYNAME)), method);
-
- /* Generates the basic graph for the method represented by ir_entity ent, that
- * is, generates start and end blocks and nodes and a first, initial block.
- * The constructor needs to know how many local variables the method has.
- */
-#define NUM_OF_LOCAL_VARS 2
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- /* Generate two constants */
- c0 = new_Const(mode_Is, new_tarval_from_long(0, mode_Is));
- c1 = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
-
- /* set a and b to constants */
- set_value(0, c0); /* this (0) is variable a */
- set_value(1, c1); /* this (1) is variable b */
-
- /* the expression that evaluates the condition */
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- cmpGt = new_Proj(new_Cmp(get_value(0, mode_Is), c2), mode_b, pn_Cmp_Gt);
-
- /* the conditional branch */
- x = new_Cond(cmpGt);
- f = new_Proj(x, mode_X, pn_Cond_false); /* if condition is false */
- t = new_Proj(x, mode_X, pn_Cond_true); /* if condition is true */
-
- mature_immBlock(get_irg_current_block(irg));
-
- /* generate and fill the then block */
- b = new_immBlock();
- add_immBlock_pred(b, t);
- set_value(0, get_value(1, mode_Is));
- mature_immBlock(b);
- x_then = new_Jmp();
-
- /* generate and fill the else block */
- b = new_immBlock();
- add_immBlock_pred(b, f);
- set_value(1, new_Const(mode_Is, new_tarval_from_long(2, mode_Is)));
- mature_immBlock(b);
- x_else = new_Jmp();
-
- /* generate the join block and add all cfg edges */
- b = new_immBlock();
- add_immBlock_pred(b, x_then);
- add_immBlock_pred(b, x_else);
-
- /* Generate the return node into current region. */
- {
- ir_node *in[2]; /* this is the array containing the return parameters */
- in[0] = get_value(0, mode_Is);
- in[1] = get_value(1, mode_Is);
- x = new_Return(get_store(), 2, in);
- }
- /* Now generate all instructions for this block and all its predecessor
- blocks so we can mature it. */
- mature_immBlock(get_irg_current_block(irg));
-
- /* This adds the in edge of the end block which originates at the
- return statement. The return node passes control flow to the
- end block. */
- add_immBlock_pred(get_irg_end_block(irg), x);
- /* Now we can mature the end block as all it's predecessors are known. */
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
- local_optimize_graph(irg);
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
- irg_finalize_cons(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph(irg, 0);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/if_example.c
- * Purpose: Shows construction of if.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* int main(int a) {
-* int b = 2;
-* if ( a == b )
-* { a := a - 3; }
-*
-* return a;
-* }
-**/
-
-int
-main(void)
-{
- ir_graph *irg;
- ir_type *owner;
- ir_entity *ent;
- ir_type *proc_main; /* ir_type information for the method main */
- ir_type *typ;
- ir_node *x, *r, *t, *f, *a, *cmp;
- int a_pos, b_pos;
-
- printf("\nCreating an IR graph: IF_EXAMPLE...\n");
-
- init_firm(NULL);
-
-#define CLASSNAME "IF_EXAMPLE"
-#define METHODNAME "IF_EXAMPLE_main"
-#define NRARGS 1
-#define NRES 1
-
- /** Type information for the procedure **/
-
- owner = get_glob_type();
- /* Type information for the procedure */
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- /* The ir_entity for the procedure */
- ent = new_entity(owner,
- new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- proc_main);
- /* The ir_type int. This ir_type is necessary to model the result and parameters
- the procedure. */
-#define PRIM_NAME "int"
- typ = new_type_primitive(new_id_from_chars(PRIM_NAME, strlen(PRIM_NAME)), mode_Is);
- /* The parameter and result types of the procedure. */
- set_method_param_type(proc_main, 0, typ);
- set_method_res_type(proc_main, 0, typ);
-
- /** The code of the procedure **/
-
- /* Generates start and end blocks and nodes, and a first, initial block */
-#define NRLOCS 2
- irg = new_ir_graph(ent, NRLOCS);
-
- /* The value position used for: */
- a_pos = 0;
- b_pos = 1;
-
- /* Get the procedure parameter and assign it to the parameter variable
- a. */
- set_value(a_pos, new_Proj(get_irg_args(irg), mode_Is, 0));
- /* Generate the constant and assign it to b. The assignment is resovled to a
- dataflow edge. */
- set_value(b_pos, new_Const(mode_Is, new_tarval_from_long(2, mode_Is)));
- /* We know all predecessors of the block and all set_values and set_stores are
- preformed. We can mature the block. */
- mature_immBlock(get_irg_current_block(irg));
-
- /* Generate a conditional branch */
- cmp = new_Cmp(get_value(a_pos, mode_Is), get_value(b_pos, mode_Is));
- x = new_Cond(new_Proj(cmp, mode_b, pn_Cmp_Eq));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate and fill the then block */
- r = new_immBlock();
- add_immBlock_pred(r, t);
- {
- ir_node *b,*c;
- c = new_Const(mode_Is, new_tarval_from_long(3, mode_Is));
- b = get_value(a_pos, mode_Is);
- a = new_Sub(b,
- c,
- mode_Is);
- }
- set_value(a_pos, a);
-
- mature_immBlock(r);
- x = new_Jmp();
-
- /* generate the fall through block and add all cfg edges */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- add_immBlock_pred(r, x);
- mature_immBlock(r);
- /* The Return statement */
- {
- ir_node *in[1], *store ;
- in[0] = get_value(a_pos, mode_Is);
- store = get_store();
-
- x = new_Return(store, 1, in);
- }
-
- /* finalize the end block generated in new_ir_graph() */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- /* verify the graph */
- irg_vrfy(irg);
- irg_finalize_cons(irg);
-
- /* output the vcg file */
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph(irg, 0);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/if_while_example.c
- * Purpose: Shows more complex control flow.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* main() {
-* int a = 0; // pos 0
-* int b = 1; // pos 1
-* int h; // pos 2
-*
-* if (0 == 0)
-* { a = 2; }
-*
-* while (0 == 0) loop {
-* h = a;
-* a = b;
-* b = h;
-* }
-*
-* return a-b;
-* }
-**/
-
-int
-main(void)
-{
- ir_graph *irg;
- ir_type *owner;
- ir_type *proc_main;
- ir_type *prim_t_int;
- ir_entity *ent;
- ir_node *b, *x, *r, *t, *f;
-
- printf("\nCreating an IR graph: IF_WHILE_EXAMPLE...\n");
-
- init_firm (NULL);
- turn_off_edge_labels();
-
- set_optimize(1);
- set_opt_constant_folding(0); /* so that the stupid tests are not optimized. */
- /* if optimized no path to End remains!! */
- set_opt_cse(1);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Iu);
-
-#define METHODNAME "main"
-#define NRARGS 0
-#define NRES 1
-
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- set_method_res_type(proc_main, 0, prim_t_int);
- owner = new_type_class (new_id_from_chars ("IF_WHILE_EXAMPLE", 16));
- ent = new_entity (owner, new_id_from_chars ("main", 4), proc_main);
- get_entity_ld_name(ent);
-
- /* Generates start and end blocks and nodes and a first, initial block */
- irg = new_ir_graph (ent, 4);
-
- /* Generate two constants */
- set_value(0, new_Const(mode_Iu, new_tarval_from_long(0, mode_Iu)));
- set_value(1, new_Const(mode_Iu, new_tarval_from_long(1, mode_Iu)));
- mature_immBlock(get_irg_current_block(irg));
-
- /* Generate a conditional branch */
- x = new_Jmp();
-
- /* generate the fall through block and add all cfg edges */
- r = new_immBlock();
- add_immBlock_pred(r, x);
- mature_immBlock(r);
- x = new_Jmp();
-
- /* generate a block for the loop header and the conditional branch */
- r = new_immBlock();
- add_immBlock_pred(r, x);
- x = new_Cond(new_Proj(new_Cmp(new_Const(mode_Iu, new_tarval_from_long(0, mode_Iu)),
- new_Const(mode_Iu, new_tarval_from_long(0, mode_Iu))),
- mode_b, pn_Cmp_Eq));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate the block for the loop body */
- b = new_immBlock();
- add_immBlock_pred(b,t);
- x = new_Jmp();
- add_immBlock_pred(r, x);
- mature_immBlock(r);
-
- /* the code in the loop body,
- as we are dealing with local variables only the dataflow edges
- are manipulated */
- set_value(2, get_value(0, mode_Iu));
- set_value(0, get_value(1, mode_Iu));
- set_value(1, get_value(2, mode_Iu));
- mature_immBlock(b);
-
- /* generate the return block */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- mature_immBlock(r);
-
- {
- ir_node *in[1];
- in[0] = new_Sub(get_value(0, mode_Iu), get_value(1, mode_Iu), mode_Iu);
-
- x = new_Return(get_store(), 1, in);
- }
-
- /* finalize the end block generated in new_ir_graph() */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
-
- local_optimize_graph(irg);
- dead_node_elimination(irg);
-
- compute_irg_outs(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- /* output the vcg file */
- printf("Done building the graph. Dumping it with out-edges.\n");
- dump_out_edges(1);
- dump_ir_graph(irg, 0);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/inheritance_example.c
- * Purpose: Shows ir_type graph with inheritance.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs ir_type information for the following pseudo-program.
-* The procedure code is not constructed.
-*
-* interface I {
-* void m1(void);
-* }
-*
-* class C implements I {
-* void m1(void) {return};
-* void m2(int) {return 0};
-* }
-*
-* class D {
-* int b;
-* }
-*
-* class E extends C, D {
-* void m2(int) {return 1};
-* int a;
-* }
-*
-**/
-
-int main(void)
-{
- ident *ii, *ci, *di, *ei, *m1i, *m2i, *inti, *ai, *bi; /* suffix i names identifiers */
- ir_type *it, *ct, *dt, *et; /* t names types */
- ir_type *m1t, *m2t;
- ir_type *intt;
- ir_entity *i_m1e, *c_m1e, *c_m2e, *e_m2e, *d_be, *e_ae; /* e names entities */
-
- printf("\nCreating ir_type information for INHERITANCE_EXAMPLE ...\n");
-
- /** init library */
- init_firm(NULL);
-
- /** make idents for all used identifiers in the program. */
- ii = new_id_from_chars("i", strlen("i"));
- ci = new_id_from_chars("c", strlen("c"));
- di = new_id_from_chars("d", strlen("d"));
- ei = new_id_from_chars("e", strlen("e"));
- m1i = new_id_from_chars("m1", strlen("m1"));
- m2i = new_id_from_chars("m2", strlen("m2"));
- inti= new_id_from_chars("int",strlen("int"));
- ai = new_id_from_chars("a", strlen("a"));
- bi = new_id_from_chars("b", strlen("b"));
-
- /** make the ir_type information needed */
- /* Language defined types */
- intt = new_type_primitive(inti, mode_Iu);
- /* Program defined types */
- it = new_type_class(ii); /* The fact that this is an interface is
- of no interest. It's just a class without
- fields and implementations. But the
- implementation will never be needed. */
- ct = new_type_class(ci);
- dt = new_type_class(di);
- et = new_type_class(ei);
- /* Methods with the same ir_type should use the same
- method ir_type information! */
- m1t = new_type_method(m1i, 0, 0); /* 0 parameters, 0 results */
- m2t = new_type_method(m2i, 1, 0); /* 1 parameter, 0 results */
-
- /** add structure to ir_type graph **/
- /* parameters of methods */
- set_method_param_type(m2t, 0, intt);
- /* inheritance. The other direction is added automatically. */
- add_class_subtype(it, ct);
- add_class_subtype(ct, et);
- add_class_subtype(dt, et);
-
- /** make entities **/
- i_m1e = new_entity(it, m1i, m1t);
- c_m1e = new_entity(ct, m1i, m1t);
- c_m2e = new_entity(ct, m2i, m2t);
- e_m2e = new_entity(et, m2i, m2t);
- d_be = new_entity(dt, bi, intt);
- e_ae = new_entity(et, ai, intt);
-
- /** Add overwirtes relation **/
- /* How these edges are added depends on the source language. */
- add_entity_overwrites(c_m1e, i_m1e);
- add_entity_overwrites(e_m2e, c_m2e);
-
-
- printf("Done building the graph. Dumping it.\n");
- dump_all_types(0);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/irr_cf_example.c
- * Purpose: Test Phi construction with irregular control flow.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs a control flow of following shape:
-*
-* StartBlock
-* |
-* \|/
-* Block ---> Block
-* | |
-* \|/ \|/
-* Block ---> Block
-* | |
-* \|/ \|/
-* Block ---> Block
-* |
-* \|/
-* EndBlock
-*
-* This is a program as, e.g.,
-*
-* switch (expr){
-* case 1:
-* case 2:
-* break;
-* default:
-* }
-* return
-**/
-
-int main(void)
-{
- char *dump_file_suffix = "";
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* typeinformation for the method main */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *expr, *c1, *c2, *cond, *f, *t, *jmp, *x;
-
- printf("\nCreating an IR graph: IRR_CF...\n");
-
- /* init library */
- init_firm(NULL);
- set_opt_constant_folding(0); /* so that stupid test are not evaluated. */
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "empty" according to the file name
- * with a method main as an ir_entity.
- */
-#define CLASSNAME "IRREGULAR_CF"
-#define METHODNAME "main"
-#define NRARGS 0
-#define NRES 0
-
- owner = new_type_class(new_id_from_chars(CLASSNAME, strlen(CLASSNAME)));
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- ent = new_entity(owner,
- new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- proc_main);
- get_entity_ld_name(ent);
-#define NUM_OF_LOCAL_VARS 0
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- /* two make two conditionals that represent a switch */
- expr = new_Const(mode_Is, new_tarval_from_long(0, mode_Is));
- c1 = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
-
- cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, pn_Cmp_Eq));
- f = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), t);
- jmp = new_Jmp();
- mature_immBlock(get_irg_current_block(irg));
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), f);
- cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, pn_Cmp_Eq));
- f = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), t);
- add_immBlock_pred(get_irg_current_block(irg), jmp);
- jmp = new_Jmp();
- mature_immBlock(get_irg_current_block(irg));
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), f);
- t = new_Jmp();
- mature_immBlock(get_irg_current_block(irg));
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), t);
- add_immBlock_pred(get_irg_current_block(irg), jmp);
-
- x = new_Return(get_store(), 0, NULL);
-
- mature_immBlock(get_irg_current_block(irg));
-
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Dumping the graph and a control flow graph.\n");
- dump_ir_block_graph(irg, dump_file_suffix);
- dump_cfg(irg, dump_file_suffix);
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp IRREGULAR_CF_main.vcg\n\n");
- printf("ycomp IRREGULAR_CF_main-cfg.vcg\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/irr_loop_example.c
- * Purpose: Test Phi construction with irregular control flow.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
- * This file constructs a control flow of following shape:
- *
- * method loop1:
- *
- * firstBlock
- * / \
- * / \
- * |/_ _\|
- * ---->
- * LoopBlock1 LoopBlock2
- * <----
- * \ /
- * \ /
- * _\| |/_
- * nextBlock
- *
- * method loop2:
- *
- * scndBlock <---------- firstBlock
- * / \ \
- * / \ \
- * |/_ _\| _\|
- * ----> ---->
- * LoopBlock1 LoopBlock2 1 LoopBlock3
- * <---- <----
- * \ /
- * \ /
- * _\| /
- * nextBlock <---------- /
- *
- *
- **/
-
-int main(void)
-{
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_tp; /* typeinformation for the method main */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *expr, *c1, *c2, *c3, *c4, *c5, *cond, *f, *t, *f2, *loopBlock1, *f_l1, *t_l1,
- *loopBlock2, *f_l2, *t_l2, *loopBlock3, *f_l3, *t_l3, *x;
- int i;
-
-
- /* init library */
- init_firm(NULL);
- set_opt_constant_folding(0); /* so that the stupid tests are not optimized. */
- set_opt_cse(1);
- turn_off_edge_labels();
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * Therefore we define a class "empty" according to the file name
- * with a method main as an ir_entity.
- */
-#define CLASSNAME "IRR_LOOP"
-#define METHOD_TP_NAME "METH_TP_NOARG_NORES"
-#define NRARGS 0
-#define NRES 0
-#define NUM_OF_LOCAL_VARS 0
-
- owner = new_type_class(new_id_from_str(CLASSNAME));
- printf("\nCreating testprogram: %s...\n", CLASSNAME);
- proc_tp = new_type_method(new_id_from_str(METHOD_TP_NAME), NRARGS, NRES);
-
- /* --- method loop1 ------------------------------------------------------ */
-
-#define METHODNAME "loop1"
-
- ent = new_entity(owner, new_id_from_str(METHODNAME), proc_tp);
- get_entity_ld_name(ent); /* To enforce name mangling for vcg graph name */
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- /* to make three conditionals */
- expr = new_Const(mode_Is, new_tarval_from_long(0, mode_Is));
- c1 = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- c3 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
-
- cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, pn_Cmp_Eq));
- f = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- loopBlock1 = new_immBlock();
- add_immBlock_pred(loopBlock1, t);
- cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, pn_Cmp_Eq));
- f_l1 = new_Proj(cond, mode_X, pn_Cond_false);
- t_l1 = new_Proj(cond, mode_X, pn_Cond_true);
-
- loopBlock2 = new_immBlock();
- add_immBlock_pred(loopBlock2, f);
- cond = new_Cond(new_Proj(new_Cmp(expr, c3), mode_b, pn_Cmp_Eq));
- f_l2 = new_Proj(cond, mode_X, pn_Cond_false);
- t_l2 = new_Proj(cond, mode_X, pn_Cond_true);
-
- add_immBlock_pred(loopBlock1, t_l2);
- add_immBlock_pred(loopBlock2, t_l1);
- mature_immBlock(loopBlock1);
- mature_immBlock(loopBlock2);
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), f_l2);
- add_immBlock_pred(get_irg_current_block(irg), f_l1);
- x = new_Return(get_store(), 0, NULL);
- mature_immBlock(get_irg_current_block(irg));
-
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- /* --- method loop2 ------------------------------------------------------ */
-
-#undef METHODNAME
-#define METHODNAME "loop2"
-
- ent = new_entity(owner, new_id_from_str(METHODNAME), proc_tp);
- get_entity_ld_name(ent); /* To enforce name mangling for vcg graph name */
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- /* to make several conditionals */
- expr = new_Const(mode_Is, new_tarval_from_long(0, mode_Is));
- c1 = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- c3 = new_Const(mode_Is, new_tarval_from_long(3, mode_Is));
- c4 = new_Const(mode_Is, new_tarval_from_long(4, mode_Is));
- c5 = new_Const(mode_Is, new_tarval_from_long(5, mode_Is));
-
- cond = new_Cond(new_Proj(new_Cmp(expr, c1), mode_b, pn_Cmp_Eq));
- f2 = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), t);
- cond = new_Cond(new_Proj(new_Cmp(expr, c5), mode_b, pn_Cmp_Eq));
- f = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- loopBlock1 = new_immBlock();
- add_immBlock_pred(loopBlock1, t);
- cond = new_Cond(new_Proj(new_Cmp(expr, c2), mode_b, pn_Cmp_Eq));
- f_l1 = new_Proj(cond, mode_X, pn_Cond_false);
- t_l1 = new_Proj(cond, mode_X, pn_Cond_true);
-
- loopBlock2 = new_immBlock();
- add_immBlock_pred(loopBlock2, f);
- cond = new_Cond(new_Proj(new_Cmp(expr, c3), mode_b, pn_Cmp_Eq));
- f_l2 = new_Proj(cond, mode_X, pn_Cond_false);
- t_l2 = new_Proj(cond, mode_X, pn_Cond_true);
-
- loopBlock3 = new_immBlock();
- add_immBlock_pred(loopBlock3, f2);
- cond = new_Cond(new_Proj(new_Cmp(expr, c4), mode_b, pn_Cmp_Eq));
- f_l3 = new_Proj(cond, mode_X, pn_Cond_false);
- t_l3 = new_Proj(cond, mode_X, pn_Cond_true);
-
- add_immBlock_pred(loopBlock1, t_l2);
- add_immBlock_pred(loopBlock2, t_l1);
- add_immBlock_pred(loopBlock3, f_l2);
- add_immBlock_pred(loopBlock2, t_l3);
- mature_immBlock(loopBlock1);
- mature_immBlock(loopBlock2);
- mature_immBlock(loopBlock3);
-
- new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), f_l1);
- add_immBlock_pred(get_irg_current_block(irg), f_l3);
- x = new_Return(get_store(), 0, NULL);
- mature_immBlock(get_irg_current_block(irg));
-
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- /* --- more ... ------------------------------------------------------ */
-
- printf("Optimizing ...\n");
-
- for (i = 0; i < get_irp_n_irgs(); ++i) {
- current_ir_graph = get_irp_irg(i);
- /* verify the graph */
- irg_vrfy(current_ir_graph);
- construct_cf_backedges(current_ir_graph);
- dump_loop_tree(current_ir_graph, "");
-
- printf("Dumping the graph and a control flow graph.\n");
- dump_ir_block_graph(current_ir_graph, "");
- dump_cfg(current_ir_graph, "");
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
- }
- /* Error for loop2 */
- compute_execution_frequency(get_irp_irg(0), 10, 0.001);
- dump_interval_graph(get_irp_irg(0), "");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/memory_example.c
- * Purpose: Illustrate memory edges.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-
-#include <stdio.h>
-#include <string.h>
-
-
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* int VAR_A
-* int VAR_B
-*
-* main() {
-*
-* VAR_A = 0
-* VAR_B = 1
-*
-* repeat {
-* h = VAR_A;
-* VAR_A = VAR_B;
-* VAR_B = h;
-* } until (0 == h)
-*
-* return (VAR_A)
-* }
-*
-*
-* A better example would be the following program:
-* (name e.g.: memory-imp_example.c as it models imperative concepts.)
-*
-* In this program a local variable is dereferenced. It has
-* to be modeled as an ir_entity of the stack so that a pointer to it is available.
-* It is also an example where an analysis could find out that the
-* pointer is never actually used.
-*
-* main () {
-* int a;
-* int *p;
-*
-* a = 2;
-* p = &a;
-* return (*p);
-* }
-*
-**/
-
-int
-main(void)
-{
- ir_graph *irg;
- ir_type *owner;
- ir_type *method; /* the ir_type of this method */
- ir_type *prim_t_int;
- ir_entity *ent;
- ir_node *a, *b, *x, *y, *r;
- union symconst_symbol symbol;
-
- printf("\nCreating an IR graph: MEMORY_EXAMPLE...\n");
-
- init_firm (NULL);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Iu);
-
- /* a class to get started with, containing the main procedure */
- owner = new_type_class (new_id_from_chars ("MEMORY_EXAMPLE", 14));
- method = new_type_method (new_id_from_chars("main", 4), 0, 1);
- set_method_res_type(method, 0, prim_t_int);
- ent = new_entity (owner, new_id_from_chars ("main", 4), method);
- get_entity_ld_name(ent); /* To enforce name mangling for vcg graph name */
-
- /* Generates start and end blocks and nodes and a first, initial block */
- irg = new_ir_graph (ent, 4);
-
- /* create two global variables, a and b point to these variables */
- symbol.entity_p = new_entity(get_glob_type(),new_id_from_chars("VAR_A",6),prim_t_int);
- a = new_SymConst(mode_P, symbol, symconst_addr_ent);
-
- symbol.entity_p = new_entity(get_glob_type(),new_id_from_chars("VAR_B",6),prim_t_int);
- b = new_SymConst(mode_P, symbol, symconst_addr_ent);
- /* set VAR_A and VAR_B to constant values */
- set_store (new_Proj (new_Store (get_store (), a,
- new_Const (mode_Iu, new_tarval_from_long (0, mode_Iu))),
- mode_M, pn_Store_M));
-
- set_store (new_Proj (new_Store (get_store (), b,
- new_Const (mode_Iu, new_tarval_from_long (1, mode_Iu))),
- mode_M, pn_Store_M));
-
- /* finish this first block */
- x = new_Jmp ();
- mature_immBlock (get_irg_current_block(irg));
-
- /* a loop body */
- r = new_immBlock ();
- add_immBlock_pred (r, x);
-
- /* exchange the content of the two variables. Exceptions not cached. */
- /* load the value and make it's effects visible. */
- x = new_Load (get_store (), a, mode_Iu);
- set_store (new_Proj (x, mode_M, pn_Load_M));
- x = new_Proj(x, mode_Iu, pn_Load_res);
- /* the same again: load the value and make it's effects visible. */
- y = new_Load (get_store (), b, mode_Iu);
- set_store (new_Proj (y, mode_M, pn_Load_M));
- y = new_Proj(y, mode_Iu, pn_Load_res);
- /* store the exchanged values. */
- set_store (new_Proj (new_Store (get_store (), a, y), mode_M, pn_Store_M));
- set_store (new_Proj (new_Store (get_store (), b, x), mode_M, pn_Store_M));
-
- /* test the condition */
- x = new_Cond (
- new_Proj (
- new_Cmp (
- new_Const (mode_Iu, new_tarval_from_long (0, mode_Iu)),
- x),
- mode_b, pn_Cmp_Gt));
-
- /* build the cfg of the loop */
- add_immBlock_pred (r, new_Proj (x, mode_X, pn_Cond_false));
- x = new_Proj (x, mode_X, pn_Cond_true);
- mature_immBlock(r);
-
- /* generate the block the loop exits to */
- r = new_immBlock ();
- add_immBlock_pred (r, x);
-
- /* generate the return block and return the content of VAR_A */
- {
- ir_node *in[1];
- x = new_Load (get_store (), a, mode_Iu);
- in[0] = new_Proj (x, mode_Iu, pn_Load_res);
-
- x = new_Return (new_Proj(x, mode_M, pn_Load_M), 1, in);
- }
- mature_immBlock (r);
- add_immBlock_pred (get_irg_end_block(irg), x);
- mature_immBlock (get_irg_end_block(irg));
-
- irg_finalize_cons (irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, 0);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/while_example.c
- * Purpose: Construct a loop.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
- * This file constructs the ir for the following pseudo-program:
- *
- * main(int a, int b) { // pos 0, pos 1
- * int c = 1; // pos 2
- * int d = 2; // pos 3
- *
- * while (a < c) {
- * while (a < d) {
- * }
- * }
- *
- * return a-b;
- * }
- */
-
-#define a_pos 0
-#define b_pos 1
-#define c_pos 2
-#define d_pos 3
-
-int
-main(void)
-{
- ir_type *prim_t_int;
- ir_graph *irg;
- ir_type *owner;
- ir_type *proc_main;
- ir_entity *ent;
- ir_node *h1, *b1, *h2, *b2, *x, *r, *t1, *f1, *t2, *f2;
-
- printf("\nCreating an IR graph: NESTED_PHI...\n");
-
- init_firm(NULL);
- set_optimize(1);
- set_opt_constant_folding(1);
- set_opt_cse(1);
-
- prim_t_int = new_type_primitive(new_id_from_str("int"), mode_Is);
-
-#define METHODNAME "main_tp"
-#define NRARGS 1
-#define NRES 1
-
- proc_main = new_type_method(new_id_from_str(METHODNAME), NRARGS, NRES);
- set_method_param_type(proc_main, 0, prim_t_int);
- set_method_res_type(proc_main, 0, prim_t_int);
-
- owner = new_type_class(new_id_from_str("NESTED_PHI"));
- ent = new_entity(owner, new_id_from_str("main"), proc_main);
-
- /* Generates start and end blocks and nodes and a first, initial block */
- irg = new_ir_graph(ent, 4);
-
- /* Generate two values */
- set_value(a_pos, new_Proj(get_irg_args(irg), mode_Is, 0));
- set_value(b_pos, new_Proj(get_irg_args(irg), mode_Is, 0));
- set_value(c_pos, new_Const(mode_Is, new_tarval_from_long(1, mode_Is)));
- set_value(d_pos, new_Const(mode_Is, new_tarval_from_long(2, mode_Is)));
-
- /* a block for the outer loop header and the conditional branch */
- h1 = get_irg_current_block(irg);
- x = new_Cond(new_Proj(new_Cmp(get_value(a_pos, mode_Is), get_value(c_pos, mode_Is)),
- mode_b, pn_Cmp_Le));
- f1 = new_Proj(x, mode_X, pn_Cond_false);
- t1 = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate the block for the loop body */
- b1 = new_immBlock();
- add_immBlock_pred(b1, t1);
-
- /* The loop body is the head of the inner loop */
- h2 = b1;
- x = new_Cond(new_Proj(new_Cmp(get_value(a_pos, mode_Is), get_value(d_pos, mode_Is)),
- mode_b, pn_Cmp_Le));
- f2 = new_Proj(x, mode_X, pn_Cond_false);
- t2 = new_Proj(x, mode_X, pn_Cond_true);
- add_immBlock_pred(h1, f2);
- mature_immBlock(h1);
-
- /* The inner loop body */
- b2 = new_immBlock();
- add_immBlock_pred(b2, t2);
- mature_immBlock(b2);
- x = new_Jmp();
- add_immBlock_pred(h2, x);
- mature_immBlock(h2);
-
- /* generate the return block */
- r = new_immBlock();
- add_immBlock_pred(r, f1);
- mature_immBlock(r);
-
- {
- ir_node *in[1];
- in[0] = new_Sub(get_value(a_pos, mode_Is), get_value(b_pos, mode_Is), mode_Is);
-
- x = new_Return(get_store(), 1, in);
- }
-
- /* finalize the end block generated in new_ir_graph() */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
-
-#if 0
- local_optimize_graph(irg),
- dead_node_elimination(irg);
-#endif
-
- /* verify the graph */
- irg_vrfy(irg);
-
- /* output the vcg file */
- printf("Done building the graph. Dumping it.\n");
- turn_off_edge_labels();
- dump_all_types("");
- dump_ir_block_graph(irg, "");
- printf("Use ycomp to view this graphs:\n");
- printf("ycomp main.vcg\n\n");
- printf("ycomp All_types.vcg\n\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/oo_inline_example.c
- * Purpose: Test inlineing.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* @@@ this is no more correct ...
-* class PRIMA {
-* a: int;
-*
-* int c(d: int) {
-* return (d + self.a);
-* }
-*
-* void set_a(e:int) {
-* self.a = e;
-* }
-*
-* }
-*
-* int main() {
-* o: PRIMA;
-* o = new PRIMA;
-* o.set_a(2);
-* return o.c(5);
-* };
-*
-**/
-
-int
-main(void)
-{
- const char *suffix = "";
- ir_type *prim_t_int;
- ir_type *owner, *class_prima;
- ir_type *proc_main, *proc_set_a, *proc_c;
- ir_type *class_p_ptr;
- ir_entity *proc_main_e, *proc_set_a_e, *proc_c_e, *a_e;
-
- ir_graph *main_irg, *set_a_irg, *c_irg;
- ir_node *c2, *c5, *obj_o, *obj_size, *proc_ptr, *res, *x, *set_a_call, *c_call;
- ir_node *self, *par1, *a_ptr;
- ir_node *a_val, *r, *t, *b, *f;
- symconst_symbol sym;
-
- int o_pos, self_pos, e_pos;
-
- int i;
-
- init_firm(NULL);
-
- set_optimize(1);
- set_opt_constant_folding(1);
- set_opt_cse(1);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
- /*** Make ir_type information for the class (PRIMA). ***/
- /* The ir_type of the class */
- class_prima = new_type_class(new_id_from_str("PRIMA_INLINE"));
- /* We need ir_type information for pointers to the class: */
- class_p_ptr = new_type_pointer(new_id_from_chars("class_prima_ptr", 15),
- class_prima, mode_P);
- /* An ir_entity for the field (a). The ir_entity constructor automatically adds
- the ir_entity as member of the owner. */
- a_e = new_entity(class_prima, new_id_from_chars("a", 1), prim_t_int);
- /* An ir_entity for the method set_a. But first we need ir_type information
- for the method. */
- proc_set_a = new_type_method(new_id_from_chars("set_a", 5), 2, 0);
- set_method_param_type(proc_set_a, 0, class_p_ptr);
- set_method_param_type(proc_set_a, 1, prim_t_int);
- proc_set_a_e = new_entity(class_prima, new_id_from_chars("set_a", 5), proc_set_a);
- /* An ir_entity for the method c. Implicit argument "self" must be modeled
- explicit! */
- proc_c = new_type_method(new_id_from_chars("c", 1 ), 2, 1);
- set_method_param_type(proc_c, 0, class_p_ptr);
- set_method_param_type(proc_c, 1, prim_t_int);
- set_method_res_type(proc_c, 0, prim_t_int);
- proc_c_e = new_entity(class_prima, new_id_from_chars("c", 1), proc_c);
-
- /*** Now build procedure main. ***/
- /** Type information for main. **/
- printf("\nCreating an IR graph: OO_INLINE_EXAMPLE...\n");
- /* Main is not modeled as part of an explicit class here. Therefore the
- owner is the global ir_type. */
- owner = get_glob_type();
- /* Main has zero parameters and one result. */
- proc_main = new_type_method(new_id_from_chars("OO_INLINE_EXAMPLE_main", 22), 0, 1);
- /* The result ir_type is int. */
- set_method_res_type(proc_main, 0, prim_t_int);
-
- /* The ir_entity for main. */
- proc_main_e = new_entity(owner, new_id_from_chars("OO_INLINE_EXAMPLE_main", 22), proc_main);
-
- /** Build code for procedure main. **/
- /* We need one local variable (for "o"). */
- main_irg = new_ir_graph(proc_main_e, 1);
- o_pos = 0;
-
- /* Remark that this irg is the main routine of the program. */
- set_irp_main_irg(main_irg);
-
- /* Make the constants. They are independent of a block. */
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- c5 = new_Const(mode_Is, new_tarval_from_long(5, mode_Is));
-
- /* There is only one block in main, it contains the allocation and the calls. */
- /* Allocate the defined object and generate the ir_type information. */
- sym.type_p = class_prima;
- obj_size = new_SymConst(mode_Iu, sym, symconst_type_size);
- obj_o = new_Alloc(get_store(), obj_size, class_prima, heap_alloc);
- set_store(new_Proj(obj_o, mode_M, pn_Alloc_M)); /* make the changed memory visible */
- obj_o = new_Proj(obj_o, mode_P, pn_Alloc_res); /* remember the pointer to the object */
- set_value(o_pos, obj_o);
-
- /* Get the pointer to the procedure from the object. */
- proc_ptr = new_simpleSel(get_store(), /* The memory containing the object. */
- get_value(o_pos, mode_P),/* The pointer to the object. */
- proc_set_a_e ); /* The feature to select. */
-
- /* Call procedure set_a, first built array with parameters. */
- {
- ir_node *in[2];
- in[0] = get_value(o_pos, mode_P);
- in[1] = c2;
- set_a_call = new_Call(get_store(), proc_ptr, 2, in, proc_set_a);
-
- }
- /* Make the change to memory visible. There are no results. */
- set_store(new_Proj(set_a_call, mode_M, pn_Call_M));
-
- /* Get the pointer to the nest procedure from the object. */
- proc_ptr = new_simpleSel(get_store(), get_value(o_pos, mode_P), proc_c_e);
-
- /* call procedure c, first built array with parameters */
- {
- ir_node *in[2];
- in[0] = get_value(o_pos, mode_P);
- in[1] = c5;
- c_call = new_Call(get_store(), proc_ptr, 2, in, proc_c);
- }
- /* make the change to memory visible */
- set_store(new_Proj(c_call, mode_M, pn_Call_M));
- /* Get the result of the procedure: select the result tuple from the call,
- then the proper result from the tuple. */
- res = new_Proj(new_Proj(c_call, mode_T, pn_Call_T_result), mode_Is, 0);
-
- /* return the results of procedure main */
- {
- ir_node *in[1];
- in[0] = res;
- x = new_Return(get_store(), 1, in);
- }
- mature_immBlock(get_irg_current_block(main_irg));
-
- /* complete the end_block */
- add_immBlock_pred(get_irg_end_block(main_irg), x);
- mature_immBlock(get_irg_end_block(main_irg));
-
- irg_vrfy(main_irg);
- irg_finalize_cons(main_irg);
-
- /****************************************************************************/
-
- printf("Creating IR graph for set_a: \n");
-
- /* Local variables: self, e */
- set_a_irg = new_ir_graph(proc_set_a_e, 2);
- self_pos = 0; e_pos = 1;
-
- /* get the procedure parameter */
- self = new_Proj(get_irg_args(set_a_irg), mode_P, 0);
- set_value(self_pos, self);
- par1 = new_Proj(get_irg_args(set_a_irg), mode_Is, 1);
- set_value(e_pos, par1);
- /* Create and select the ir_entity to set */
- a_ptr = new_simpleSel(get_store(), self, a_e);
- /* perform the assignment */
- set_store(new_Proj(new_Store(get_store(), a_ptr, par1), mode_M, pn_Store_M));
-
- /* return nothing */
- x = new_Return(get_store(), 0, NULL);
- mature_immBlock(get_irg_current_block(set_a_irg));
-
- /* complete the end_block */
- add_immBlock_pred(get_irg_end_block(set_a_irg), x);
- mature_immBlock(get_irg_end_block(set_a_irg));
-
- /* verify the graph */
- irg_vrfy(set_a_irg);
- irg_finalize_cons(set_a_irg);
-
- /****************************************************************************/
-
- printf("Creating IR graph for c: \n");
-
- /* Local variables self, d */
- c_irg = new_ir_graph(proc_c_e, 5);
-
- /* get the procedure parameter */
- self = new_Proj(get_irg_args(c_irg), mode_P, 0);
- set_value(0, self);
- par1 = new_Proj(get_irg_args(c_irg), mode_Is, 1);
- set_value(1, par1);
- set_value(2, new_Const(mode_Is, new_tarval_from_long(0, mode_Is)));
-
- x = new_Jmp();
- mature_immBlock(get_irg_current_block(c_irg));
-
- /* generate a block for the loop header and the conditional branch */
- r = new_immBlock();
- add_immBlock_pred(r, x);
- x = new_Cond(new_Proj(new_Cmp(new_Const(mode_Is, new_tarval_from_long(0, mode_Is)),
- new_Const(mode_Is, new_tarval_from_long(0, mode_Is))),
- mode_b, pn_Cmp_Eq));
-
- /* x = new_Cond(new_Proj(new_Cmp(new_Const(mode_Is, new_tarval_from_long(0, mode_Is)),
- get_value(1, mode_Is)),
- mode_b, pn_Cmp_Eq));*/
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate the block for the loop body */
- b = new_immBlock();
- add_immBlock_pred(b, t);
-
- /* The code in the loop body,
- as we are dealing with local variables only the dataflow edges
- are manipulated. */
- set_value(3, get_value(1, mode_Is));
- set_value(1, get_value(2, mode_Is));
- set_value(2, get_value(3, mode_Is));
- a_ptr = new_simpleSel(get_store(), self, a_e);
- set_store(new_Proj(new_Store(get_store(), a_ptr, get_value(2, mode_Is)), mode_M, pn_Store_M));
- x = new_Jmp();
- add_immBlock_pred(r, x);
- mature_immBlock(b);
- mature_immBlock(r);
-
- /* generate the return block */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- /* Select the ir_entity and load the value */
- a_ptr = new_simpleSel(get_store(), self, a_e);
- a_val = new_Load(get_store(), a_ptr, mode_Is);
- set_store(new_Proj(a_val, mode_M, pn_Load_M));
- a_val = new_Proj(a_val, mode_Is, pn_Load_res);
-
- /* return the result */
- {
- ir_node *in[1];
- in[0] = new_Add(par1, a_val, mode_Is);
-
- x = new_Return(get_store(), 1, in);
- }
- mature_immBlock(r);
-
- /* complete the end_block */
- add_immBlock_pred(get_irg_end_block(c_irg), x);
- mature_immBlock(get_irg_end_block(c_irg));
-
- /* verify the graph */
- irg_vrfy(c_irg);
- irg_finalize_cons(c_irg);
-
- /****************************************************************************/
-
- collect_phiprojs(main_irg);
- current_ir_graph = main_irg;
- printf("Inlining set_a ...\n");
- inline_method(set_a_call, set_a_irg);
- printf("Inlineing c ...\n");
- inline_method(c_call, c_irg);
-
- printf("Optimizing ...\n");
-
- for (i = 0; i < get_irp_n_irgs(); i++) {
- local_optimize_graph(get_irp_irg(i));
- dead_node_elimination(get_irp_irg(i));
- }
-
- printf("Dumping graphs of all procedures and a ir_type graph.\n");
- /* Touch ld names to distinguish names from oo_inline names. */
- get_entity_ld_ident(proc_set_a_e);
- get_entity_ld_ident(proc_c_e);
- turn_off_edge_labels();
- dump_all_ir_graphs(dump_ir_block_graph, suffix);
- dump_all_ir_graphs(dump_ir_block_graph_w_types, suffix);
- dump_all_types(0);
-
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/oo_program_example.c
- * Purpose: A complex example.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-*
-* class PRIMA {
-* a: int;
-*
-* int c(d: int) {
-* return (d + self.a);
-* }
-*
-* void set_a(e:int) {
-* self.a = e;
-* }
-*
-* }
-*
-* int main() {
-* o: PRIMA;
-* o = new PRIMA;
-* o.set_a(2);
-* return o.c(5);
-* };
-*
-**/
-
-int
-main(void)
-{
- ir_type *prim_t_int;
- ir_type *owner, *class_prima;
- ir_type *proc_main, *proc_set_a, *proc_c;
- ir_type *class_p_ptr;
- ir_entity *proc_main_e, *proc_set_a_e, *proc_c_e, *a_e;
-
- ir_graph *main_irg, *set_a_irg, *c_irg;
- ir_node *c2, *c5, *obj_o, *obj_size, *proc_ptr, *call, *res, *x;
- ir_node *self, *par1, *a_ptr;
- ir_node *a_val;
- symconst_symbol sym;
- ir_entity **free_methods;
- int arr_len;
-
- int o_pos, self_pos, e_pos;
-
- int i;
-
- init_firm(NULL);
-
- set_opt_constant_folding(1);
- set_opt_cse(1);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
- /*** Make ir_type information for the class (PRIMA). ***/
- /* The ir_type of the class */
- class_prima = new_type_class(new_id_from_chars("PRIMA", 5));
- /* We need ir_type information for pointers to the class: */
- class_p_ptr = new_type_pointer(new_id_from_chars("class_prima_ptr", 15),
- class_prima, mode_P);
- /* An ir_entity for the field (a). The ir_entity constructor automatically adds
- the ir_entity as member of the owner. */
- a_e = new_entity(class_prima, new_id_from_chars("a", 1), prim_t_int);
- /* An ir_entity for the method set_a. But first we need ir_type information
- for the method. */
- proc_set_a = new_type_method(new_id_from_chars("set_a", 5), 2, 0);
- set_method_param_type(proc_set_a, 0, class_p_ptr);
- set_method_param_type(proc_set_a, 1, prim_t_int);
- proc_set_a_e = new_entity(class_prima, new_id_from_chars("set_a", 5), proc_set_a);
- /* An ir_entity for the method c. Implicit argument "self" must be modeled
- explicit! */
- proc_c = new_type_method(new_id_from_chars("c", 1 ), 2, 1);
- set_method_param_type(proc_c, 0, class_p_ptr);
- set_method_param_type(proc_c, 1, prim_t_int);
- set_method_res_type(proc_c, 0, prim_t_int);
- proc_c_e = new_entity(class_prima, new_id_from_chars("c", 1), proc_c);
-
- /*** Now build procedure main. ***/
- /** Type information for main. **/
- printf("\nCreating an IR graph: OO_PROGRAM_EXAMPLE...\n");
- /* Main is not modeled as part of an explicit class here. Therefore the
- owner is the global ir_type. */
- owner = get_glob_type();
- /* Main has zero parameters and one result. */
- proc_main = new_type_method(new_id_from_chars("OO_PROGRAM_EXAMPLE_main", 23), 0, 1);
- /* The result ir_type is int. */
- set_method_res_type(proc_main, 0, prim_t_int);
-
- /* The ir_entity for main. */
- proc_main_e = new_entity(owner, new_id_from_chars("OO_PROGRAM_EXAMPLE_main", 23), proc_main);
-
- /** Build code for procedure main. **/
- /* We need one local variable (for "o"). */
- main_irg = new_ir_graph(proc_main_e, 1);
- o_pos = 0;
-
- /* Remark that this irg is the main routine of the program. */
- set_irp_main_irg(main_irg);
-
- /* Make the constants. They are independent of a block. */
- c2 = new_Const(mode_Is, new_tarval_from_long(2, mode_Is));
- c5 = new_Const(mode_Is, new_tarval_from_long(5, mode_Is));
-
- /* There is only one block in main, it contains the allocation and the calls. */
- /* Allocate the defined object and generate the ir_type information. */
- sym.type_p = class_prima;
- obj_size = new_SymConst(mode_Iu, sym, symconst_type_size);
- obj_o = new_Alloc(get_store(), obj_size, class_prima, heap_alloc);
- set_store(new_Proj(obj_o, mode_M, pn_Alloc_M)); /* make the changed memory visible */
- obj_o = new_Proj(obj_o, mode_P, pn_Alloc_res); /* remember the pointer to the object */
- set_value(o_pos, obj_o);
-
- /* Get the pointer to the procedure from the object. */
- proc_ptr = new_simpleSel(get_store(), /* The memory containing the object. */
- get_value(o_pos, mode_P),/* The pointer to the object. */
- proc_set_a_e ); /* The feature to select. */
-
- /* Call procedure set_a, first built array with parameters. */
- {
- ir_node *in[2];
- in[0] = get_value(o_pos, mode_P);
- in[1] = c2;
- call = new_Call(get_store(), proc_ptr, 2, in, proc_set_a);
- }
- /* Make the change to memory visible. There are no results. */
- set_store(new_Proj(call, mode_M, pn_Call_M));
-
- /* Get the pointer to the nest procedure from the object. */
- proc_ptr = new_simpleSel(get_store(), get_value(o_pos, mode_P), proc_c_e);
-
- /* call procedure c, first built array with parameters */
- {
- ir_node *in[2];
- in[0] = get_value(o_pos, mode_P);
- in[1] = c5;
- call = new_Call(get_store(), proc_ptr, 2, in, proc_c);
- }
- /* make the change to memory visible */
- set_store(new_Proj(call, mode_M, pn_Call_M));
- /* Get the result of the procedure: select the result tuple from the call,
- then the proper result from the tuple. */
- res = new_Proj(new_Proj(call, mode_T, pn_Call_T_result), mode_Is, 0);
-
- /* return the results of procedure main */
- {
- ir_node *in[1];
- in[0] = res;
- x = new_Return(get_store(), 1, in);
- }
- mature_immBlock(get_irg_current_block(main_irg));
-
- /* complete the end_block */
- add_immBlock_pred(get_irg_end_block(main_irg), x);
- mature_immBlock(get_irg_end_block(main_irg));
-
- irg_vrfy(main_irg);
- irg_finalize_cons(main_irg);
-
- /****************************************************************************/
-
- printf("Creating IR graph for set_a: \n");
-
- /* Local variables: self, e */
- set_a_irg = new_ir_graph(proc_set_a_e, 2);
- self_pos = 0; e_pos = 1;
-
- /* get the procedure parameter */
- self = new_Proj(get_irg_args(set_a_irg), mode_P, 0);
- set_value(self_pos, self);
- par1 = new_Proj(get_irg_args(set_a_irg), mode_Is, 1);
- set_value(e_pos, par1);
- /* Create and select the ir_entity to set */
- a_ptr = new_simpleSel(get_store(), self, a_e);
- /* perform the assignment */
- set_store(new_Proj(new_Store(get_store(), a_ptr, par1), mode_M, pn_Store_M));
-
- /* return nothing */
- x = new_Return(get_store(), 0, NULL);
- mature_immBlock(get_irg_current_block(set_a_irg));
-
- /* complete the end_block */
- add_immBlock_pred(get_irg_end_block(set_a_irg), x);
- mature_immBlock(get_irg_end_block(set_a_irg));
-
- /* verify the graph */
- irg_vrfy(set_a_irg);
- irg_finalize_cons(set_a_irg);
-
- /****************************************************************************/
-
- printf("Creating IR graph for c: \n");
-
- /* Local variables self, d */
- c_irg = new_ir_graph(proc_c_e, 2);
-
- /* get the procedure parameter */
- self = new_Proj(get_irg_args(c_irg), mode_P, 0);
- par1 = new_Proj(get_irg_args(c_irg), mode_Is, 1);
-
- /* Select the ir_entity and load the value */
- a_ptr = new_simpleSel(get_store(), self, a_e);
- a_val = new_Load(get_store(), a_ptr, mode_Is);
- set_store(new_Proj(a_val, mode_M, pn_Load_M));
- a_val = new_Proj(a_val, mode_Is, pn_Load_res);
-
- /* return the result */
- {
- ir_node *in[1];
- in[0] = new_Add(par1, a_val, mode_Is);
-
- x = new_Return(get_store(), 1, in);
- }
- mature_immBlock(get_irg_current_block(c_irg));
-
- /* complete the end_block */
- add_immBlock_pred(get_irg_end_block(c_irg), x);
- mature_immBlock(get_irg_end_block(c_irg));
-
- /* verify the graph */
- irg_vrfy(c_irg);
- irg_finalize_cons(c_irg);
-
- /****************************************************************************/
-
- printf("Optimizing ...\n");
- for (i = 0; i < get_irp_n_irgs(); i++) {
- local_optimize_graph(get_irp_irg(i));
- dead_node_elimination(get_irp_irg(i));
- }
-
- printf("Dumping graphs of all procedures and a ir_type graph.\n");
- /* Touch ld names to distinguish names from oo_inline names. */
- get_entity_ld_ident(proc_set_a_e);
- get_entity_ld_ident(proc_c_e);
-
- dump_consts_local(1);
- turn_off_edge_labels();
-
- dump_all_ir_graphs(dump_ir_graph, "");
- dump_all_ir_graphs(dump_ir_block_graph, "");
- dump_all_ir_graphs(dump_ir_graph_w_types, "");
- dump_all_ir_graphs(dump_ir_block_graph_w_types, "");
- dump_all_ir_graphs(dump_type_graph, "");
- dump_all_ir_graphs(dump_graph_as_text, "");
- dump_all_types("");
- dump_class_hierarchy(1, "");
-
- cgana(&arr_len, &free_methods);
-#ifdef INTERPROCEDURAL_VIEW
- cg_construct(arr_len, free_methods);
-
- set_interprocedural_view(1);
-#endif
- dump_ir_graph(main_irg, "");
- dump_ir_block_graph(main_irg, "");
- dump_ir_graph_w_types(main_irg, "");
- dump_ir_block_graph_w_types(main_irg, "");
-#ifdef INTERPROCEDURAL_VIEW
- dump_all_cg_block_graph("");
-#endif
-
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/
- * Purpose:
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 2004 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-
-#include <libfirm/firm.h>
-
-
-
-/** This file constructs the ir to test a problem with code placement.
- *
- * Global cse and removal of dead code can produce nodes, that depend
- * on live nodes, but originally were placed in dead code. The
- * dominator analyses can not compute dominator information for
- * them, or their block is the Bad node.
- *
- * We must place this nodes in the code, as they could be reached
- * through a live node.
- *
- * This program constructs a graph that can result from the program below
- * by dead node elimination and global cse.
- *
- * class SomeClass {}
- * long main() {
- * long a = 0;
- * int b = sizeof(SomeClass);
- *
- * if (a > 2)
- * { a = (long) b; }
- * else
- * { a = (long) b; }
- *
- * return a;
- * }
- *
- * The Conv node for the cast to long is constructed twice, in each
- * if case once. Global cse visits the Conv in the block that will
- * turn dead first, i.e., it adds this node in the hash table. The
- * assignment in the alive block is replaced by this node. In a next
- * step the dead code is removed, only straight control flow remains.
- * This results in a Conv node that is not placed in an existing node,
- * but needed by the program.
- *
- * Code placememnt (place early) tries to place the node in the Start
- * block, which is illegal. Actually, place late should move the block
- * out of the Start block.
- */
-
-#define PROGNAME "PLACE_WITH_DEAD"
-
-int main(void)
-{
- ir_type *prim_t_int;
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *method; /* the ir_type of this method */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *a, *b, *x;
- symconst_symbol sym;
-
- printf("\nCreating an IR graph: " PROGNAME "...\n");
-
- /* init library */
- init_firm (NULL);
-
- /* Make basic ir_type information for primitive ir_type int. */
- prim_t_int = new_type_primitive(new_id_from_chars ("int", 3), mode_Ls);
-
- /* Make the method ir_type and ir_entity */
- owner = get_glob_type();
- method = new_type_method (new_id_from_str(PROGNAME"_main_tp"), 0, 1);
- set_method_res_type(method, 0, prim_t_int);
- ent = new_entity (owner, new_id_from_str (PROGNAME"_main"), method);
-
- /* The ir graph */
-#define NUM_OF_LOCAL_VARS 2
- irg = new_ir_graph (ent, NUM_OF_LOCAL_VARS);
-
- /* Generate the two constants. A SymConst can not be constant evaluated. */
- sym.type_p = new_type_class(new_id_from_str("SomeClass"));
- a = new_Const (mode_Is, new_tarval_from_long (0, mode_Is));
- b = new_SymConst (mode_Iu, sym, symconst_type_size);
-
- /* Generate the Conv with Bad as block */
- a = new_Conv(b, mode_Ls);
- set_nodes_block(a, new_Bad());
-
- /* Generate the return. */
- x = new_Return (get_store(), 1, &a);
-
- /* Finish the graph. */
- mature_immBlock (get_irg_current_block(irg));
- add_immBlock_pred (get_irg_end_block(irg), x);
- mature_immBlock (get_irg_end_block(irg));
- irg_finalize_cons (irg);
- irg_vrfy(irg);
-
- printf("Done building the graph. Dumping it.\n");
- dump_ir_block_graph (irg, 0);
- dump_ir_graph (irg, 0);
-
- printf("Code placement ...\n");
- set_opt_global_cse(1); /* need this option for code placement */
- place_code(irg);
-
- dump_ir_block_graph (irg, "-placed");
- dump_ir_graph (irg, "-placed");
- irg_vrfy(irg);
-
- printf("Use ycomp to view this graph:\n");
- printf("ycomp GRAPHNAME\n\n");
-
- return (0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/recursion.c
- * Purpose: Empty methods that recur.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 2004 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-*
-
-*
-**/
-
-static ir_graph *make_method(char *name, int n_locs) {
- ir_type *proc_t = new_type_method(new_id_from_str(name), 0, 0);
- /*set_method_param_type(proc_set_a, 0, class_p_ptr);*/
- /*set_method_param_type(proc_set_a, 1, prim_t_int);*/
- ir_entity *proc_e = new_entity(get_glob_type(), new_id_from_str(name), proc_t);
- return new_ir_graph(proc_e, n_locs);
-}
-
-
-static ir_node *make_Call(ir_graph *c, int n_args, ir_node **args) {
- ir_entity *ent = get_irg_entity(c);
- ir_type *mtp = get_entity_type(ent);
- ir_node *addr;
- ir_node *call;
- symconst_symbol sym;
- sym.entity_p = ent;
- addr = new_SymConst(mode_P, sym, symconst_addr_ent);
- call = new_Call(get_store(), addr, n_args, args, mtp);
- set_store(new_Proj(call, mode_M, pn_Call_M_regular));
- if (get_method_n_ress(mtp) == 1) {
- ir_type *restp = get_method_res_type(mtp, 0);
- return new_Proj(new_Proj(call, mode_T, pn_Call_T_result), get_type_mode(restp), 0);
- }
- return NULL;
-}
-
-static void close_method(int n_ins, ir_node **ins) {
- ir_node *x = new_Return(get_store(), n_ins, ins);
- mature_immBlock(get_cur_block());
- add_immBlock_pred(get_cur_end_block(), x);
- mature_immBlock(get_cur_end_block());
- irg_finalize_cons(current_ir_graph);
-}
-
-
-int
-main(void)
-{
- ir_graph *mainp;
- ir_graph *hs;
- ir_graph *ha;
- ir_graph *insert;
- ir_graph *remove;
- ir_graph *unheap;
- ir_graph *downh;
- ir_graph *exc;
- ir_graph *a, *b, *c, *d;
- ir_graph *self, *self1, *self2, *self3, *self4;
- ir_entity **free_methods;
- int arr_len;
-
- init_firm(NULL);
-
- set_opt_constant_folding(0);
- set_opt_cse(0);
-
- set_irp_prog_name(new_id_from_str("recursion"));
-
- /** The callgraph of the heapsort excample */
- mainp = make_method("main", 0);
- hs = make_method("hs", 0);
- ha = make_method("ha", 0);
- insert = make_method("insert", 0);
- remove = make_method("remove", 0);
- unheap = make_method("unheap", 0);
- downh = make_method("downh", 0);
- exc = make_method("exc", 0);
-
- set_irp_main_irg(mainp);
-
- current_ir_graph = mainp;
- make_Call(hs, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = hs;
- make_Call(ha, 0, NULL);
- make_Call(remove, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = ha;
- make_Call(insert, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = insert;
- make_Call(unheap, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = remove;
- make_Call(unheap, 0, NULL);
- make_Call(downh, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = unheap;
- make_Call(exc, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = downh;
- make_Call(downh, 0, NULL);
- make_Call(exc, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = exc;
- close_method(0, NULL);
-
-
- /* A callgraph with a nested recursion. */
- a = make_method("a", 0);
- b = make_method("b", 0);
- c = make_method("c", 0);
- d = make_method("d", 0);
-
- current_ir_graph = a;
- make_Call(b, 0, NULL);
- make_Call(c, 0, NULL);
- make_Call(b, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = b;
- close_method(0, NULL);
-
- current_ir_graph = c;
- make_Call(b, 0, NULL);
- make_Call(d, 0, NULL);
- make_Call(a, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = d;
- make_Call(a, 0, NULL);
- make_Call(d, 0, NULL);
- close_method(0, NULL);
-
- /* A callgraph with a self recursion */
- self = make_method("self", 0);
-
- current_ir_graph = self;
- make_Call(self, 0, NULL);
- close_method(0, NULL);
-
- /* A callgraph with a self recursion over several steps*/
- self1 = make_method("self1", 0);
- self2 = make_method("self2", 0);
- self3 = make_method("self3", 0);
- self4 = make_method("self4", 0);
-
- current_ir_graph = self1;
- make_Call(self2, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = self2;
- make_Call(self3, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = self3;
- make_Call(self4, 0, NULL);
- close_method(0, NULL);
-
- current_ir_graph = self4;
- make_Call(self1, 0, NULL);
- close_method(0, NULL);
-
- printf("Dumping Callgraph.\n");
-
- cgana(&arr_len, &free_methods);
- compute_callgraph();
- find_callgraph_recursions();
- /*dump_callgraph("");*/
- /* Order of edges depends on set.c, which is not deterministic. */
-#ifdef INTERPROCEDURAL_VIEW
- cg_construct(arr_len, free_methods);
-#endif
-
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp GRAPHNAME\n\n");
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/strength_red_example.c
- * Purpose: Shows how strength red works
- * Author: Beyhan Veliev
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 2004 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* int a[10];
-*
-* void main(void) {
-* int i = 0;
-*
-* while (i < 10) {
-* a[i] = 19;
-* i++
-* }
-* }
-**/
-
-#define new_Const_int(n) new_Const(mode_Is, new_tarval_from_long(n, mode_Is))
-
-
-#define CLASSNAME "STRENGTH_RED_EXAMPLE"
-#define METHODNAME1 "STRENGTH_RED_EXAMPLE_m1"
-#define METHODNAME2 "STRENGTH_RED_EXAMPLE_m2"
-#define METHODNAME3 "STRENGTH_RED_EXAMPLE_m3"
-#define METHODNAME4 "STRENGTH_RED_EXAMPLE_m4"
-#define METHODNAME5 "STRENGTH_RED_EXAMPLE_m5"
-#define METHODNAME6 "STRENGTH_RED_EXAMPLE_m6"
-#define METHODNAME7 "STRENGTH_RED_EXAMPLE_m7"
-#define METHODNAME8 "STRENGTH_RED_EXAMPLE_m8"
-#define METHODNAME9 "STRENGTH_RED_EXAMPLE_m9"
-#define METHODTPNAME "STRENGTH_RED_EXAMPLE_meth_tp"
-#define NRARGS 1
-#define NRES 1
-#define L_BOUND 0
-#define U_BOUND 10
-#define N_DIMS 1
- /** The ir_type int. **/
-#define PRIM_NAME "int"
-
-
-
-static int i_pos = 0;
-static int arr_pos = 1;
-static ir_type *typ, *typ2;
-
-static ir_node *r1, *f, *r, *c2;
-
-typedef enum {
- loop_forward,
- loop_backward
-} loop_dir_t;
-
-/**
- * Constructs a new (method-)function of the form
- *
- * typ fct_name(typ arg) {
- * for (i = start_value; i < end_value;) { ... }
- * }
- *
- * After return, the loop body is the current block.
- *
- * @param owner owner-ir_type of this (method-)function
- * @param mtp the method ir_type of this function
- * @param fct_name the name of the function
- * @param loop_dir the loop direction
- */
-static void function_begin(ir_type *owner, ir_type *mtp, char *fct_name, loop_dir_t loop_dir) {
- symconst_symbol sym;
- ir_node *x, *t, *cmp;
- ir_entity *ent;
- ir_entity *array_ent;
- ir_type *array_type;
-
- int start_value, end_value;
- pn_Cmp cmp_dir;
-
- if (loop_dir == loop_forward) {
- start_value = 0;
- end_value = 10;
- cmp_dir = pn_Cmp_Gt;
- }
- else {
- start_value = 10;
- end_value = 0;
- cmp_dir = pn_Cmp_Lt;
- }
-
- /* The ir_entity for the procedure */
- ent = new_entity(owner, new_id_from_str(fct_name), mtp);
-
- /* make ir_type infromation for the array */
- array_type = new_type_array(new_id_from_str("array"), N_DIMS, typ);
-
- /* set the bounds for the array */
- set_array_bounds_int(array_type, 0, L_BOUND, U_BOUND);
-
- /* The array is an ir_entity of the owner ir_type */
- array_ent = new_entity(owner, new_id_from_str("a"), array_type);
-
- /** The code of the procedure **/
-
- /* Generates start and end blocks and nodes, and a first, initial block */
-#define NRLOCS 2
- new_ir_graph(ent, NRLOCS);
-
- /* The value position used for: */
- i_pos = 0;
- if (fct_name == METHODNAME7)
- c2 = new_Const_int(5);
-
- /* Generate the constant and assign it to b. The assignment is resolved to a
- dataflow edge. */
- set_value(i_pos, new_Const_int(start_value));
-
- sym.entity_p = array_ent;
- set_value(arr_pos, new_SymConst(mode_P, sym, symconst_addr_ent));
- x = new_Jmp();
-
- /* We know all predecessors of the block and all set_values and set_stores are
- preformed. We can mature the block. */
- mature_immBlock(get_irg_current_block(current_ir_graph));
-
- /* Generate a conditional branch */
- r1 = new_immBlock();
- add_immBlock_pred(get_irg_current_block(current_ir_graph), x);
-
- cmp = new_Cmp(new_Const_int(end_value), get_value(i_pos, mode_Is));
- x = new_Cond(new_Proj(cmp, mode_b, cmp_dir));
-
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate and fill the loop body block */
- r = new_immBlock();
- add_immBlock_pred(r, t);
-}
-
-int x;
-
-/**
- * finishes a builded function.
- *
- * @param b the return value
- */
-static void function_end(ir_node *b) {
- ir_node *x = new_Jmp();
- mature_immBlock(r);
- add_immBlock_pred(r1, x);
-
-
- new_immBlock();
- add_immBlock_pred(get_cur_block(), f);
- mature_immBlock(get_cur_block());
- /* The Return statement */
- {
- ir_node *in[1], *store ;
- in[0] = b;
- store = get_store();
-
- x = new_Return(store, 1, in);
- }
- add_immBlock_pred(get_irg_end_block(current_ir_graph), x);
-
- mature_immBlock(r1);
- /* finalize the end block generated in new_ir_graph() */
- mature_immBlock(get_irg_end_block(current_ir_graph));
-}
-
-int
-main(void)
-{
- ir_graph *irg;
- ir_type *owner;
- ir_entity *ent, *array_ent, *array_ent2;
- ir_type *proc_tp, *array_type, *array_type2; /* ir_type information for the method main */
- ir_node *x,*x1 , *r, *t, *f, *f1, *t1, *cmp, *r1, *r2;
- ir_node *d2, *res2, *res3, *res5, *res7;
- int i_pos;
- int i, n_irgs;
- ir_node *b, *c, *c1, *d, *res;
- ir_node *b1, *b2, *b3, *b4, *b7, *block;
- ir_node *mul, *q, *q1;
- ir_node *mul4;
- symconst_symbol sym, sym2;
-
- printf("\nCreating an IR graph: IF_EXAMPLE...\n");
-
- init_firm(NULL);
-
- arch_dep_set_opts(arch_dep_none);
-
- do_node_verification(FIRM_VERIFICATION_REPORT);
-
- typ = new_type_primitive(new_id_from_chars(PRIM_NAME, strlen(PRIM_NAME)), mode_Is);
-
- typ2 = new_type_primitive(new_id_from_chars(PRIM_NAME, strlen(PRIM_NAME)), mode_Is);
-
- /** The global array variable a **/
-
-
- /** Type information for the procedure **/
- owner = get_glob_type();
- /* Type information for the procedure */
- proc_tp = new_type_method(new_id_from_chars(METHODTPNAME, strlen(METHODTPNAME)), NRARGS, NRES);
- set_method_param_type(proc_tp, 0, typ);
- set_method_res_type(proc_tp, 0, typ);
-
-
- /* --------------------------------------------------------------------- */
-
- /* The ir_entity for the procedure */
- ent = new_entity(owner,
- new_id_from_str(METHODNAME1),
- proc_tp);
- /* The parameter and result types of the procedure. */
-
- /* make ir_type infromation for the array */
- array_type = new_type_array(new_id_from_chars("array", 5),N_DIMS, typ);
- array_type2 = new_type_array(new_id_from_chars("array2", 6),N_DIMS, typ2);
- /* set the bounds for the array */
- set_array_bounds_int(array_type, 0, L_BOUND, U_BOUND);
- set_array_bounds_int(array_type2, 0, L_BOUND, U_BOUND);
-
- /* The array is an ir_entity of the global typ */
- array_ent = new_entity( owner, new_id_from_str("a"), array_type);
- array_ent2 = new_entity( owner, new_id_from_str("a2"), array_type2);
-
- /** The code of the procedure **/
-
-
- /* Generates start and end blocks and nodes, and a first, initial block */
-#undef NRLOCS
-#define NRLOCS 1
- irg = new_ir_graph(ent, NRLOCS);
-
- /* The value position used for: */
- i_pos = 0;
-
- /* Generate the constant and assign it to b. The assignment is resovled to a
- dataflow edge. */
- set_value(i_pos, new_Const_int(0));
- x = new_Jmp();
-
- /* We know all predecessors of the block and all set_values and set_stores are
- preformed. We can mature the block. */
- mature_immBlock(get_irg_current_block(irg));
-
- /* Generate a conditional branch */
- r1 = new_immBlock();
- add_immBlock_pred(get_irg_current_block(irg), x);
- cmp = new_Cmp(new_Const_int(10), get_value(i_pos, mode_Is));
- x = new_Cond(new_Proj(cmp, mode_b, pn_Cmp_Gt));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate and fill the then block */
- r = new_immBlock();
- add_immBlock_pred(r, t);
-
- c = new_Const_int(1);
- b = new_Const_int(4);
- b2 = new_Const_int(12);
- sym.entity_p = array_ent ;
- sym2.entity_p = array_ent2 ;
- d = new_SymConst(mode_P, sym, symconst_addr_ent);
- d2 = new_SymConst(mode_P, sym2, symconst_addr_ent);
- res = new_Add(d, new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- res2 = new_Add(d2, new_Mul(get_value(i_pos, mode_Is), b2, mode_Is), mode_P);
- set_store(new_Proj(new_Store(get_store(), res, new_Const_int(19)), mode_M, pn_Store_M));
- set_store(new_Proj(new_Store(get_store(), res2, new_Const_int(16)), mode_M, pn_Store_M));
- d = new_SymConst(mode_P, sym, symconst_addr_ent);
- res = new_Add(d, new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- set_store(new_Proj(new_Store(get_store(), res, new_Const_int(15)), mode_M, pn_Store_M));
-
- set_value(i_pos, new_Add(get_value(i_pos, mode_Is), c, mode_Is));
-
- x = new_Jmp();
- mature_immBlock(r);
-
- add_immBlock_pred(r1, x);
- mature_immBlock(r1);
-
- r2 = new_immBlock();
- b1 = new_Const_int(45);
- add_immBlock_pred(get_irg_current_block(irg), f);
- cmp = new_Cmp(new_Const_int(0), b1);
- x = new_Cond(new_Proj(cmp, mode_b, pn_Cmp_Lt));
- f1 = new_Proj(x, mode_X, pn_Cond_false);
- t1 = new_Proj(x, mode_X, pn_Cond_true);
-
- block = new_immBlock();
- add_immBlock_pred(block, t1);
- b1 = new_Sub(b1, get_value(i_pos, mode_Is), mode_Is);
- res = new_Add(d, new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- set_store(new_Proj(new_Store(get_store(), res, new_Const_int(19)), mode_M, pn_Store_M));
- set_value(i_pos, new_Sub(get_value(i_pos, mode_Is), c, mode_Is));
-
- x1 = new_Jmp();
-
- mature_immBlock(block);
-
- add_immBlock_pred(r2, x1);
- mature_immBlock(r2);
-
- block = new_immBlock();
- add_immBlock_pred(block, f1);
- mature_immBlock(block);
- /* The Return statement */
- {
- ir_node *in[1], *store ;
- in[0] = get_value(i_pos, mode_Is);
- store = get_store();
-
- x = new_Return(store, 1, in);
- }
- add_immBlock_pred(get_irg_end_block(irg), x);
-
- /* finalize the end block generated in new_ir_graph() */
- mature_immBlock(get_irg_end_block(irg));
-
-
- /* -------------------------------------------------------------------------------- */
-
- function_begin(owner, proc_tp, METHODNAME2, loop_forward);
- q = new_Const_int(15);
- q1 = new_Const_int(13);
- c = new_Const_int(1);
- b = new_Const_int(4);
- mul = new_Mul(q, get_value(i_pos, mode_Is), mode_Is);
-
- res = new_Add(get_value(arr_pos, mode_P), new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- res = new_Add(q1, res, mode_P);
- set_store(new_Proj(new_Store(get_store(), res, mul), mode_M, pn_Store_M));
-
- set_value(i_pos, new_Add(get_value(i_pos, mode_Is), c, mode_Is));
-
- function_end(b);
-
- /* -------------------------------------------------------------------------- */
-
- function_begin(owner, proc_tp, METHODNAME3, loop_backward);
-
- c = new_Const_int(1);
- b = new_Const_int(4);
- b3 = new_Const_int(8);
-
- res = new_Add(get_value(arr_pos, mode_P), new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- res = new_Add(b, res, mode_P);
- res = new_Add(b3, res, mode_P);
- res3 = new_Add(b3, res, mode_P);
- res = new_Add(res3, res, mode_P);
- set_store(new_Proj(new_Store(get_store(), res, get_value(i_pos, mode_Is)), mode_M, pn_Store_M));
-
-
- set_value(i_pos, new_Sub(get_value(i_pos, mode_Is), c, mode_Is));
-
- function_end(b);
-
- /* -------------------------------------------------------------------------- */
-
- function_begin(owner, proc_tp, METHODNAME4, loop_forward);
-
- c = new_Const_int(1);
- b = new_Const_int(4);
- b4 = new_Const_int(8);
-
- set_value(i_pos, new_Add(get_value(i_pos, mode_Is), c, mode_Is));
- mul4 = new_Mul(get_value(i_pos, mode_Is), b4, mode_Is);
- res = new_Add(mul4, get_value(arr_pos, mode_P), mode_P);
- set_store(new_Proj(new_Store(get_store(), res,get_value(i_pos, mode_Is)),
- mode_M, pn_Store_M));
- res = new_Add(get_value(arr_pos, mode_P), new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- set_store(new_Proj(new_Store(get_store(), res, get_value(i_pos, mode_Is)), mode_M, pn_Store_M));
-
- function_end(b);
-
- /* -------------------------------------------------------------------------- */
-
- function_begin(owner, proc_tp, METHODNAME5, loop_backward);
-
- c = new_Const_int(1);
- b = new_Const_int(4);
-
- set_value(i_pos, new_Sub(get_value(i_pos, mode_Is), c, mode_Is));
-
- res5 = new_Add(c, b, mode_Is);
- res = new_Add(get_value(arr_pos, mode_P), new_Mul(get_value(i_pos, mode_Is), b, mode_Is), mode_P);
- res = new_Add(res, b, mode_P);
- res = new_Add(res, res5, mode_P);
- set_store(new_Proj(new_Store(get_store(), res, new_Const_int(19)), mode_M, pn_Store_M));
-
- function_end(b);
-
- /* -------------------------------------------------------------------------- */
-
- function_begin(owner, proc_tp, METHODNAME6, loop_forward);
-
- c = new_Const_int(1);
- c1 = new_Const_int(5);
- b = new_Const_int(4);
-
- set_value(i_pos, new_Sub(get_value(i_pos, mode_Is), c, mode_Is));
-
- res = new_Add( get_value(arr_pos, mode_P), new_Mul(get_value(i_pos, mode_Is),
- b, mode_Is), mode_P);
- res = new_Sub(c1, res, mode_P);
- res = new_Add( b, res, mode_P);
- res = new_Add(b, res, mode_P);
- set_store(new_Proj(new_Store(get_store(), res, new_Const_int(19)), mode_M, pn_Store_M));
-
- function_end(b);
-
- /* -------------------------------------------------------------------------- */
-
- function_begin(owner, proc_tp, METHODNAME7, loop_backward);
-
- c = new_Const_int(1);
- b = new_Const_int(4);
- b7 = new_Const_int(19);
-
- res = get_value(i_pos, mode_Is);
- res = new_Add(res, b, mode_Is);
- res = new_Add(res, b7, mode_Is);
- res = new_Mul(res, b, mode_Is);
- res = new_Add(get_value(arr_pos, mode_P), res, mode_P);
- res7 = new_Add( get_value(i_pos, mode_Is), b7, mode_Is);
- set_store(new_Proj(new_Store(get_store(), res, res7), mode_M, pn_Store_M));
- set_value(i_pos, new_Sub(get_value(i_pos, mode_Is), c, mode_Is));
- function_end(b);
-
- /* -------------------------------------------------------------------------- */
-
- n_irgs = get_irp_n_irgs();
-
- printf("Done building the graph. Dumping and optimizing it.\n");
- dump_consts_local(1);
- turn_off_edge_labels();
- for (i = 0; i < n_irgs; ++i) {
- current_ir_graph = get_irp_irg(i);
- irg_vrfy(current_ir_graph);
- irg_finalize_cons(current_ir_graph);
-
- /* output the vcg file */
- construct_backedges(current_ir_graph);
- dump_ir_block_graph(current_ir_graph, 0);
- dump_all_types(0);
- optimize_reassociation(current_ir_graph);
- opt_osr(current_ir_graph, osr_flag_default);
-
-#if 0
- remove_critical_cf_edges(current_ir_graph);
- set_opt_global_cse(1);
- place_code(current_ir_graph);
- set_opt_global_cse(0);
- optimize_reassociation(current_ir_graph);
-#endif
-
- dump_loop_tree(current_ir_graph, "");
- dump_ir_block_graph(current_ir_graph, "-strength_reduced");
- }
- printf("Use ycomp to view the graphs\n");
-
- return 0;
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/three_cfpred_example.c
- * Purpose: Construct a block with more than two predecessors.
- * Author: Christian Schaefer, Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
- * This file constructs a control flow of following shape:
- *
- *
- * firstCondBlock
- * / \
- * / \
- * |/_ _\|
- * Block1 scnCondBlock
- * | | |
- * | | |
- * | \ / \ /
- * | Block2 Block3
- * \ | /
- * \ | /
- * _\| \ / |/_
- * nextBlock
- *
- *
- * This is a program as, e.g.,
- *
- * if () then
- * { Jmp label1; } // happens anyways
- * else
- * { Jmp label1; } // happens anyways
- * label1:
- * return();
- * Jmp label1;
- *
- **/
-
-int main(void)
-{
- const char *suffix = "";
- ir_type *prim_t_int;
- ir_graph *irg; /* this variable contains the irgraph */
- ir_type *owner; /* the class in which this method is defined */
- ir_type *proc_main; /* ir_type information for the method main */
- ir_entity *ent; /* represents this method as ir_entity of owner */
- ir_node *c1, *c2, *cond, *f, *t, *endBlock, *Block1, *jmp,
- *scndCondBlock, *Block2, *Block3, *x;
-
- /* init library */
- init_firm(NULL);
-
- set_optimize(1);
-
- /*** Make basic ir_type information for primitive ir_type int. ***/
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
- /* FIRM was designed for oo languages where all methods belong to a class.
- * For imperative languages like C we view a file as a large class containing
- * all functions as methods in this file.
- * This class now is automatically generated.
- */
-#define METHODNAME "THREE_CFPRED_EXAMPLE_main"
-#define NRARGS 1
-#define NRES 1
- printf("\nCreating an IR graph: THREE_CFPRED_EXAMPLE ...\n");
-
- owner = get_glob_type();
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- set_method_param_type(proc_main, 0, prim_t_int);
- set_method_res_type(proc_main, 0, prim_t_int);
-
- ent = new_entity(owner,
- new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- proc_main);
-
-#define NUM_OF_LOCAL_VARS 2
-
- irg = new_ir_graph(ent, NUM_OF_LOCAL_VARS);
-
- /* to make a condition */
- c1 = new_Const(mode_Is, new_tarval_from_long(1, mode_Is));
- c2 = new_Proj(get_irg_args(irg), mode_Is, 0);
- set_value(1, c2);
-
- cond = new_Cond(new_Proj(new_Cmp(c1, c2), mode_b, pn_Cmp_Eq));
- set_value(0, new_Const(mode_Is, new_tarval_from_long(6, mode_Is)));
- f = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- /* end block to add jmps */
- endBlock = new_immBlock();
-
- /* Block 1 */
- Block1 = new_immBlock();
- add_immBlock_pred(Block1, t);
- mature_immBlock(Block1);
- set_value(0, new_Const(mode_Is, new_tarval_from_long(5, mode_Is)));
- jmp = new_Jmp();
- add_immBlock_pred(endBlock, jmp);
-
- /* scndCondBlock */
- scndCondBlock = new_immBlock();
- add_immBlock_pred(scndCondBlock, f);
- mature_immBlock(scndCondBlock);
- c1 = new_Const(mode_Is, new_tarval_from_long(3, mode_Is));
- cond = new_Cond(new_Proj(new_Cmp(c1, get_value(1, mode_Is)), mode_b, pn_Cmp_Eq));
- f = new_Proj(cond, mode_X, pn_Cond_false);
- t = new_Proj(cond, mode_X, pn_Cond_true);
- mature_immBlock(get_irg_current_block(irg));
-
- /* Block 2 */
- Block2 = new_immBlock();
- add_immBlock_pred(Block2, f);
- mature_immBlock(Block2);
- jmp = new_Jmp();
- add_immBlock_pred(endBlock, jmp);
-
- /* Block 3 */
- Block3 = new_immBlock();
- add_immBlock_pred(Block3, t);
- mature_immBlock(Block3);
- jmp = new_Jmp();
- add_immBlock_pred(endBlock, jmp);
-
- /* finish the end Block */
- set_cur_block(endBlock);
- {
- ir_node *in[1];
- in[0] = get_value(0, mode_Is);
- x = new_Return(get_store(), 1, in);
- }
- mature_immBlock(get_irg_current_block(irg));
-
- /* finish the Block with the end node */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- /* verify the graph */
- irg_vrfy(irg);
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
- dead_node_elimination(irg);
-
- printf("Dumping the graph and a control flow graph.\n");
- dump_ir_block_graph(irg, suffix);
- dump_cfg(irg, suffix);
- printf("Use ycomp to view these graphs:\n");
- printf("ycomp THREE_CFPRED_EXAMPLE_main.vcg\n\n");
- printf("ycomp THREE_CFPRED_EXAMPLE_main-cfg.vcg\n\n");
-
- return(0);
-}
+++ /dev/null
-/*
- * Project: libFIRM
- * File name: testprograms/while_example.c
- * Purpose: Construct a loop.
- * Author: Goetz Lindenmaier
- * Modified by:
- * Created:
- * CVS-ID: $Id$
- * Copyright: (c) 1999-2003 Universität Karlsruhe
- * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
- */
-#include <stdio.h>
-#include <string.h>
-
-#include <libfirm/firm.h>
-
-/**
-* This file constructs the ir for the following pseudo-program:
-*
-* main(int a) { // pos 0
-* int b = 1; // pos 1
-* int h; // pos 2
-*
-* while (0 == 2) loop {
-* h = a;
-* a = b;
-* b = h;
-* }
-*
-* return a-b;
-* }
-**/
-
-int
-main(void)
-{
- const char *suffix = "";
- ir_type *prim_t_int;
- ir_graph *irg;
- ir_type *owner;
- ir_type *proc_main;
- ir_entity *ent;
- ir_node *b, *x, *r, *t, *f;
-
- printf("\nCreating an IR graph: WHILE_EXAMPLE...\n");
-
- init_firm(NULL);
-
- set_optimize(1);
- set_opt_constant_folding(1);
- set_opt_cse(1);
-
- prim_t_int = new_type_primitive(new_id_from_chars("int", 3), mode_Is);
-
-#define METHODNAME "main_tp"
-#define NRARGS 1
-#define NRES 1
-
- proc_main = new_type_method(new_id_from_chars(METHODNAME, strlen(METHODNAME)),
- NRARGS, NRES);
- set_method_param_type(proc_main, 0, prim_t_int);
- set_method_res_type(proc_main, 0, prim_t_int);
-
-
- owner = new_type_class(new_id_from_chars("WHILE_EXAMPLE", 13));
- ent = new_entity(owner, new_id_from_chars("main", strlen("main")), proc_main);
- get_entity_ld_name(ent); /* force name mangling */
-
- /* Generates start and end blocks and nodes and a first, initial block */
- irg = new_ir_graph(ent, 4);
-
- /* Generate two values */
- set_value(0, new_Proj(get_irg_args(irg), mode_Is, 0));
- set_value(1, new_Const(mode_Is, new_tarval_from_long(1, mode_Is)));
- x = new_Jmp();
- mature_immBlock(get_irg_current_block(irg));
-
-
- /* generate a block for the loop header and the conditional branch */
- r = new_immBlock();
- add_immBlock_pred(r, x);
- x = new_Cond(new_Proj(new_Cmp(new_Const(mode_Is, new_tarval_from_long(0, mode_Is)),
- get_value(1, mode_Is)),
- mode_b, pn_Cmp_Eq));
- f = new_Proj(x, mode_X, pn_Cond_false);
- t = new_Proj(x, mode_X, pn_Cond_true);
-
- /* generate the block for the loop body */
- b = new_immBlock();
- add_immBlock_pred(b, t);
- x = new_Jmp();
- add_immBlock_pred(r, x);
-
- /* The code in the loop body,
- as we are dealing with local variables only the dataflow edges
- are manipulated. */
- set_value(2, get_value(0, mode_Is));
- set_value(0, get_value(1, mode_Is));
- set_value(1, get_value(2, mode_Is));
- mature_immBlock(b);
- mature_immBlock(r);
-
- /* generate the return block */
- r = new_immBlock();
- add_immBlock_pred(r, f);
- mature_immBlock(r);
-
- {
- ir_node *in[1];
- in[0] = new_Sub(get_value(0, mode_Is), get_value(1, mode_Is), mode_Is);
-
- x = new_Return(get_store(), 1, in);
- }
-
- /* finalize the end block generated in new_ir_graph() */
- add_immBlock_pred(get_irg_end_block(irg), x);
- mature_immBlock(get_irg_end_block(irg));
-
- irg_finalize_cons(irg);
-
- printf("Optimizing ...\n");
-
- local_optimize_graph(irg),
- dead_node_elimination(irg);
-
- /* verify the graph */
- irg_vrfy(irg);
-
- /* output the vcg file */
- printf("Done building the graph. Dumping it.\n");
- turn_off_edge_labels();
- dump_all_types(suffix);
- dump_ir_block_graph(irg, suffix);
- printf("Use ycomp to view this graph:\n");
- printf("ycomp WHILE_EXAMPLE\n\n");
-
- return(0);
-}