pto_util.c 3.53 KB
Newer Older
Florian Liekweg's avatar
Florian Liekweg committed
1
2
3
/* -*- c -*- */

/*
Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
4
5
6
7
8
9
10
11
12
13
   Project:     libFIRM
   File name:   ir/ana/pto_util.c
   Purpose:     Utilitites for PTO
   Author:      Florian
   Modified by:
   Created:     Sat Nov 13 19:35:27 CET 2004
   CVS-ID:      $Id$
   Copyright:   (c) 1999-2004 Universitt Karlsruhe
   Licence:     This file is protected by the GPL -  GNU GENERAL PUBLIC LICENSE.
*/
Florian Liekweg's avatar
Florian Liekweg committed
14

Michael Beck's avatar
Michael Beck committed
15
16
17
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
Florian Liekweg's avatar
Florian Liekweg committed
18
19

/*
Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
20
 pto_util: Utilitites for PTO
Florian Liekweg's avatar
Florian Liekweg committed
21
22
*/

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
23
# include "pto_util.h"
Florian Liekweg's avatar
Florian Liekweg committed
24

Michael Beck's avatar
Michael Beck committed
25
# include "irnode_t.h"
Florian Liekweg's avatar
Florian Liekweg committed
26
# include "irgwalk.h"
Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
27
# include "xmalloc.h"
Florian Liekweg's avatar
Florian Liekweg committed
28

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
29
# include "pto_debug.h"
30

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
31
/* Local Defines: */
Florian Liekweg's avatar
Florian Liekweg committed
32
33
34
35
# ifndef TRUE
#  define TRUE 1
#  define FALSE 0
# endif /* not defined TRUE */
36

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
37
/* Local Data Types: */
Florian Liekweg's avatar
Florian Liekweg committed
38
39
40
41
42
43
/* Environment for find_irg_args */
typedef struct find_irg_args_env {
  ir_node **args;
  ir_node *arg;
} find_irg_args_env_t;

44

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
45
/* Local Variables: */
46

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
47
/* Local Prototypes: */
48

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
49
50
51
/* ===================================================
   Local Implementation:
   =================================================== */
Florian Liekweg's avatar
Florian Liekweg committed
52
53
54
55
/* Helper for find_irg_args */
static void find_irg_arg (ir_node *node, void *env)
{
  find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env;
56

Florian Liekweg's avatar
Florian Liekweg committed
57
58
59
60
61
62
63
64
65
66
  if (iro_Proj == get_irn_opcode (node)) {
    if (arg_env->arg == get_Proj_pred (node)) {
      long n = get_Proj_proj (node);

      assert (! arg_env->args [n]);

      arg_env->args [n] = node;
    }
  }
}
67

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
68
69
70
/* ===================================================
   Exported Implementation:
   =================================================== */
Florian Liekweg's avatar
Florian Liekweg committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* Find the arguments of a graph. For a method that has n args, the
  result array has 'n+1' entries, the last of which is written NULL. */
ir_node **find_irg_args (ir_graph *graph)
{
  type *tp = get_entity_type (get_irg_entity (graph));
  const int n_args = get_method_n_params (tp);
  ir_node **args = (ir_node**) xmalloc (sizeof (ir_node*) * (n_args+1));
  ir_node *arg = get_irg_args (graph);
  find_irg_args_env_t *arg_env =
    (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t));

  arg_env->args = args;
  arg_env->arg  = arg;

  /* or use get_irg_end ?!? */
  {
    ir_graph *save = get_current_ir_graph ();
    set_current_ir_graph (graph);
    irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env);
    set_current_ir_graph (save);
  }

  free (arg_env);

  args [n_args] = NULL;

  return (args);
}
Florian Liekweg's avatar
Florian Liekweg committed
99

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
100
/* Get the entity of a ptr */
101
102
103
104
105
entity *get_ptr_ent (ir_node *ptr)
{
  entity *ent = NULL;
  const opcode ptr_op = get_irn_opcode (ptr);
  switch (ptr_op) {
Florian Liekweg's avatar
Florian Liekweg committed
106
107
108
  case (iro_Cast): {
    ent = get_ptr_ent (get_Cast_op (ptr));
  } break;
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  case (iro_Sel): {
    ent = get_Sel_entity (ptr);
  } break;

  case (iro_SymConst): {
    ent = get_SymConst_entity (ptr);
  } break;

  default: {
    fprintf (stderr, "%s: no ent for ptr=%s[%ld]\n",
             __FUNCTION__,
             get_op_name (get_irn_op (ptr)),
             get_irn_node_nr (ptr));
    assert (0);
  }
  }

  return (ent);
}

Florian Liekweg's avatar
Florian Liekweg committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* Check whether the load of the given ptr is a dummy */
int is_dummy_load_ptr (ir_node *ptr)
{
  const opcode ptr_op = get_irn_opcode (ptr);

  switch (ptr_op) {
  case (iro_Cast): {
    return (is_dummy_load_ptr (get_Cast_op (ptr)));
  } break;
  case (iro_Sel):
  case (iro_SymConst): {
    return (FALSE);
  } break;

  default: {
    return (TRUE);
  }
  }
}

Florian Liekweg's avatar
Florian Liekweg committed
149
150
151

/*
  $Log$
Florian Liekweg's avatar
Florian Liekweg committed
152
153
154
  Revision 1.10  2004/12/06 12:55:06  liekweg
  actually iterate

Michael Beck's avatar
Michael Beck committed
155
156
157
  Revision 1.9  2004/12/02 16:17:51  beck
  fixed config.h include

Florian Liekweg's avatar
Florian Liekweg committed
158
159
160
  Revision 1.8  2004/11/26 15:59:14  liekweg
  recognize dummy loads

Florian Liekweg's avatar
Florian Liekweg committed
161
162
163
  Revision 1.7  2004/11/24 14:53:56  liekweg
  Bugfixes

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
164
165
  Revision 1.6  2004/11/18 16:37:07  liekweg
  rewrite
166

Florian Liekweg's avatar
Florian Liekweg committed
167

Florian Liekweg's avatar
rewrite    
Florian Liekweg committed
168
*/