aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/cil32/cil-stmt-inline.h
blob: 0bd42c01e692e7cf42b4f3b1d6ef4231ec29bd04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
/* Inlined functions for manipulating CIL statements.

   Copyright (C) 2006-2008 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING.  If not, write to the Free
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.

Authors:
   Andrea Ornstein
   Erven Rohou
   Gabriele Svelto

Contact information at STMicroelectronics:
Andrea C. Ornstein      <andrea.ornstein@st.com>
Erven Rohou             <erven.rohou@st.com>
*/

#ifndef CIL_STMT_INLINE_H
#define CIL_STMT_INLINE_H

/******************************************************************************
 * CIL statement inlined functions                                            *
 ******************************************************************************/

/* Return the code for CIL statement STMT. */

static inline enum cil_opcode
cil_opcode (const_cil_stmt stmt)
{
  return stmt->opcode;
}

/* Return the basic block holding the statement STMT.  */

static inline basic_block
cil_bb (const_cil_stmt stmt)
{
  return stmt->bb;
}

/* Set the basic block holding the statement STMT to BB. */

static inline void
cil_set_bb (cil_stmt stmt, basic_block bb)
{
  stmt->bb = bb;
}

/* Return locus information for statement STMT. */

static inline source_locus
cil_locus (const_cil_stmt stmt)
{
  return stmt->locus;
}

/* Set locus information for statement STMT. */

static inline void
cil_set_locus (cil_stmt stmt, source_locus locus)
{
  stmt->locus = locus;
}

/* Return the variable declaration (VAR_DECL) held by a CIL statement.  */

static inline tree
cil_var (const_cil_stmt stmt)
{
  gcc_assert (opcode_arg_type (stmt->opcode) == CIL_VAR);

  return stmt->arg.var;
}

/* Return the type definition (TYPE_DECL) held by a CIL statement.  */

static inline tree
cil_type (const_cil_stmt stmt)
{
  gcc_assert (opcode_arg_type (stmt->opcode) == CIL_TYPE);

  return stmt->arg.type;
}

/* Return the field declaration (FIELD_DECL) held by a CIL statement.  */

static inline tree
cil_field (const_cil_stmt stmt)
{
  gcc_assert (opcode_arg_type (stmt->opcode) == CIL_FIELD);

  return stmt->arg.field;
}

/* Return the label declaration (LABEL_DECL) held by a CIL statement.  */

static inline tree
cil_label (const_cil_stmt stmt)
{
  gcc_assert (opcode_arg_type (stmt->opcode) == CIL_LABEL);

  return stmt->arg.label;
}

/* Return the number of cases of a CIL switch statment.  */

static inline size_t
cil_switch_ncases (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_SWITCH);

  return stmt->arg.labels->ncases;
}

/* Return the I-th case of a CIL switch statement.  The last entry is the
   default case.  */

static inline tree
cil_switch_case (const_cil_stmt stmt, size_t i)
{
  gcc_assert (stmt->opcode == CIL_SWITCH);
  gcc_assert (i < stmt->arg.labels->ncases);

  return stmt->arg.labels->cases[i];
}

/* Return the default case of a CIL switch statement.  */

static inline tree
cil_switch_default (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_SWITCH);

  return stmt->arg.labels->cases[stmt->arg.labels->ncases - 1];
}

/* Return the I-th case label of CIL switch statement.  */

static inline tree
cil_switch_case_label (const_cil_stmt stmt, size_t i)
{
  gcc_assert (stmt->opcode == CIL_SWITCH);
  gcc_assert (i < stmt->arg.labels->ncases);

  return CASE_LABEL (stmt->arg.labels->cases[i]);
}

/* Return the low value of the I-th case of CIL switch statement as an
   HOST_WIDE_INT instead of a tree.  */

static inline HOST_WIDE_INT
cil_switch_case_low (const_cil_stmt stmt, size_t i)
{
  gcc_assert (stmt->opcode == CIL_SWITCH);
  gcc_assert (i < stmt->arg.labels->ncases);

  return tree_low_cst (CASE_LOW (stmt->arg.labels->cases[i]), 0);
}

/* Return the high value of the I-th case of CIL switch statement as an
   HOST_WIDE_INT instead of a tree. If the case doesn't represent a range then
   this function will return the case value (i.e. the low value). */

static inline HOST_WIDE_INT
cil_switch_case_high (const_cil_stmt stmt, size_t i)
{
  gcc_assert (stmt->opcode == CIL_SWITCH);
  gcc_assert (i < stmt->arg.labels->ncases);

  if (CASE_HIGH (stmt->arg.labels->cases[i]))
    return tree_low_cst (CASE_HIGH (stmt->arg.labels->cases[i]), 0);
  else
    return tree_low_cst (CASE_LOW (stmt->arg.labels->cases[i]), 0);
}

/* Return the function declaration of a CIL LDFTN statement.  */

static inline
tree cil_func (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_LDFTN);

  return stmt->arg.func;
}

/* Builds a CIL CALL statement. The FDECL field holds the callee
   declaration.  */

static inline cil_stmt
cil_build_call (tree fdecl)
{
  return cil_build_call_generic (CIL_CALL, fdecl);
}

/* Builds a CIL CALLI statement. The FTYPE field holds the callee type.  */

static inline cil_stmt
cil_build_calli (tree ftype)
{
  return cil_build_call_generic (CIL_CALLI, ftype);
}

/* Builds a CIL JMP statement. The FDECL field holds the callee declaration.  */

static inline cil_stmt
cil_build_jmp (tree fdecl)
{
  return cil_build_call_generic (CIL_JMP, fdecl);
}

/* Builds a CIL CALL statement. The FDECL field holds the callee declaration.
   The ARGLIST must be a pointer to a VEC (tree, heap) holding the types of the
   arguments passed to the callee after the ellipsis.  */

static inline cil_stmt
cil_build_call_va (tree fdecl, VEC (tree, heap) *arglist)
{
  return cil_build_call_generic_list (CIL_CALL, true, fdecl, arglist);
}

/* Builds a CIL CALLI statement. The FTYPE field holds the callee type. The
   ARGLIST must be a pointer to a VEC (tree, heap) holding the types of the
   arguments passed to the callee after the ellipsis.  */

static inline cil_stmt
cil_build_calli_va (tree ftype, VEC (tree, heap) *arglist)
{
  return cil_build_call_generic_list (CIL_CALLI, true, ftype, arglist);
}

/* Builds a CIL JMP statement. The FDECL field holds the callee declaration.
   The ARGLIST must be a pointer to a VEC (tree, heap) holding the types of the
   arguments passed to the callee after the ellipsis.  */

static inline cil_stmt
cil_build_jmp_va (tree fdecl, VEC (tree, heap) *arglist)
{
  return cil_build_call_generic_list (CIL_JMP, true, fdecl, arglist);
}

/* Builds a CIL CALL statement for a function without a prototype. The FDECL
   field holds the callee declaration. The ARGLIST must be a pointer to a
   VEC (tree, heap) holding the types of all the arguments passed to the
   callee.  */

static inline cil_stmt
cil_build_call_mp (tree fdecl, VEC (tree, heap) *arglist)
{
  return cil_build_call_generic_list (CIL_CALL, false, fdecl, arglist);
}

/* Builds a CIL CALL statement for a function without a prototype. The FTYPE
   field holds the callee type. The ARGLIST must be a pointer to a
   VEC (tree, heap) holding the types of all the arguments passed to the
   callee.  */

static inline cil_stmt
cil_build_calli_mp (tree ftype, VEC (tree, heap) *arglist)
{
  return cil_build_call_generic_list (CIL_CALLI, false, ftype, arglist);
}

/* Builds a CIL CALL statement for a function without a prototype. The FDECL
   field holds the callee declaration. The ARGLIST must be a pointer to a
   VEC (tree, heap) holding the types of all the arguments passed to the
   callee.  */

static inline cil_stmt
cil_build_jmp_mp (tree fdecl, VEC (tree, heap) *arglist)
{
  return cil_build_call_generic_list (CIL_JMP, false, fdecl, arglist);
}

/* Return the type of the callee of a CIL CALL, CALLI or JMP statement.  */

static inline tree
cil_call_ftype (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);

  return stmt->arg.fcall->ftype;
}

/* Return the function declaration of the callee of a CIL CALL or JMP
   statement.  */

static inline tree
cil_call_fdecl (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL || stmt->opcode == CIL_JMP);

  return stmt->arg.fcall->fdecl;
}

/* Return the number of arguments passed to the callee of a CIL CALL, CALLI or
   JMP statement.  */

static inline size_t
cil_call_nargs (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL || stmt->opcode == CIL_CALLI);

  return stmt->arg.fcall->nargs;
}

/* Return the I-th argument passed to the callee of a CIL CALL, CALLI or JMP
   statement.  */

static inline tree
cil_call_arg_type (const_cil_stmt stmt, size_t i)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);
  gcc_assert (i < stmt->arg.fcall->nargs);

  return stmt->arg.fcall->arguments[i];
}

/* Set the type SC_TYPE of the static chain for the call STMT.  */

static inline void
cil_call_set_static_chain (cil_stmt stmt, tree sc_type)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);

  stmt->arg.fcall->static_chain_p = true;
  stmt->arg.fcall->static_chain = sc_type;
}

/* Return the type of the static chain for the call STMT if present.  */

static inline tree
cil_call_static_chain (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);

  if (stmt->arg.fcall->static_chain_p)
    return stmt->arg.fcall->static_chain;
  else
    return NULL_TREE;
}

/* Sets the type DUMMY_TYPE of a dummy argument passed to the call. This is
   currently used for passing the type of a va_arg() call. */

static inline void
cil_call_set_dummy_arg (cil_stmt stmt, tree dummy_type)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);

  stmt->arg.fcall->static_chain = dummy_type;
}

/* Returns the type of the dummy argument passed to a call. This is currently
   used for passing the type of a va_arg() call. */

static inline tree
cil_call_dummy_arg (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);
  gcc_assert (!stmt->arg.fcall->static_chain_p);

  return stmt->arg.fcall->static_chain;
}

/* Return true if the callee accepts a variable number of arguments.  */

static inline bool
cil_call_vararg_p (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);

  return stmt->arg.fcall->vararg_p;
}

/* Return true if the callee doesn't have a prototype.  */

static inline bool
cil_call_missing_proto_p (const_cil_stmt stmt)
{
  gcc_assert (stmt->opcode == CIL_CALL
	      || stmt->opcode == CIL_CALLI
	      || stmt->opcode == CIL_JMP);

  return stmt->arg.fcall->missing_proto_p;
}

/* Return a constant held by a CIL statement.  */

static inline tree
cil_cst (const_cil_stmt stmt)
{
  gcc_assert (opcode_arg_type (stmt->opcode) == CIL_CST);

  return stmt->arg.cst;
}

/* Return a string held by a CIL statement.  */

static inline tree
cil_string (const_cil_stmt stmt)
{
  gcc_assert (opcode_arg_type (stmt->opcode) == CIL_STRING);

  return stmt->arg.str;
}

/******************************************************************************
 * CIL sequence inlined functions                                             *
 ******************************************************************************/

/* Return the first node in CIL sequence S.  */

static inline cil_seq_node
cil_seq_first (const_cil_seq s)
{
  return s ? s->first : NULL;
}

/* Return the first statement in CIL sequence S.  */

static inline cil_stmt
cil_seq_first_stmt (const_cil_seq s)
{
  cil_seq_node n = cil_seq_first (s);
  return (n) ? n->stmt : NULL;
}

/* Return the last node in CIL sequence S.  */

static inline cil_seq_node
cil_seq_last (const_cil_seq s)
{
  return s ? s->last : NULL;
}

/* Return the last statement in CIL sequence S.  */

static inline cil_stmt
cil_seq_last_stmt (const_cil_seq s)
{
  cil_seq_node n = cil_seq_last (s);
  return (n) ? n->stmt : NULL;
}

/* Set the last node in CIL sequence S to LAST.  */

static inline void
cil_seq_set_last (cil_seq s, cil_seq_node last)
{
  s->last = last;
}

/* Set the first node in CIL sequence S to FIRST.  */

static inline void
cil_seq_set_first (cil_seq s, cil_seq_node first)
{
  s->first = first;
}

/* Return true if CIL sequence S is empty.  */

static inline bool
cil_seq_empty_p (const_cil_seq s)
{
  return s == NULL || s->first == NULL;
}

/******************************************************************************
 * CIL statement iterator inlined functions                                   *
 ******************************************************************************/

/* Return a new iterator pointing to SEQ's first statement.  */

static inline cil_stmt_iterator
csi_start (cil_seq seq)
{
  cil_stmt_iterator i;

  i.ptr = cil_seq_first (seq);
  i.seq = seq;
  i.bb = (i.ptr && i.ptr->stmt) ? cil_bb (i.ptr->stmt) : NULL;

  return i;
}

/* Return a new iterator pointing to the first statement in basic block BB.  */

static inline cil_stmt_iterator
csi_start_bb (basic_block bb)
{
  cil_stmt_iterator i;
  cil_seq seq;

  seq = cil_bb_seq (bb);
  i.ptr = cil_seq_first (seq);
  i.seq = seq;
  i.bb = bb;

  return i;
}

/* Return a new iterator initially pointing to SEQ's last statement.  */

static inline cil_stmt_iterator
csi_last (cil_seq seq)
{
  cil_stmt_iterator i;

  i.ptr = cil_seq_last (seq);
  i.seq = seq;
  i.bb = (i.ptr && i.ptr->stmt) ? cil_bb (i.ptr->stmt) : NULL;

  return i;
}


/* Return a new iterator pointing to the last statement in basic block BB.  */

static inline cil_stmt_iterator
csi_last_bb (basic_block bb)
{
  cil_stmt_iterator i;
  cil_seq seq;

  seq = cil_bb_seq (bb);
  i.ptr = cil_seq_last (seq);
  i.seq = seq;
  i.bb = bb;

  return i;
}

/* Return true if I is at the end of its sequence.  */

static inline bool
csi_end_p (cil_stmt_iterator i)
{
  return i.ptr == NULL;
}

/* Return true if I is one statement before the end of its sequence.  */

static inline bool
csi_one_before_end_p (cil_stmt_iterator i)
{
  return i.ptr != NULL && i.ptr->next == NULL;
}

/* Return true if I points to the first statement of its sequence.  */

static inline bool
csi_first_p (cil_stmt_iterator i)
{
  return i.ptr == cil_seq_first (i.seq);
}

/* Advance the iterator to the next CIL statement.  */

static inline void
csi_next (cil_stmt_iterator *i)
{
  i->ptr = i->ptr->next;
}

/* Advance the iterator to the previous CIL statement.  */

static inline void
csi_prev (cil_stmt_iterator *i)
{
  i->ptr = i->ptr->prev;
}

/* Return the current stmt.  */

static inline cil_stmt
csi_stmt (cil_stmt_iterator i)
{
  return i.ptr->stmt;
}

/* Return a pointer to the current stmt.  */

static inline cil_stmt *
csi_stmt_ptr (cil_stmt_iterator *i)
{
  return &i->ptr->stmt;
}

/* Return the basic block associated with this iterator.  */

static inline basic_block
csi_bb (cil_stmt_iterator i)
{
  return i.bb;
}

/* Return the sequence associated with this iterator.  */

static inline cil_seq
csi_seq (cil_stmt_iterator i)
{
  return i.seq;
}

#endif /* !CIL_STMT_INLINE_H */