ppir.h 16.7 KB
Newer Older
Qiang Yu's avatar
Qiang Yu committed
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
/*
 * Copyright (c) 2017 Lima Project
 * Copyright (c) 2013 Connor Abbott
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#ifndef LIMA_IR_PP_PPIR_H
#define LIMA_IR_PP_PPIR_H

#include "util/u_math.h"
#include "util/list.h"
30
#include "util/set.h"
Qiang Yu's avatar
Qiang Yu committed
31
32
33
34
35

#include "ir/lima_ir.h"

typedef enum {
   ppir_op_mov,
Andreas Baierl's avatar
Andreas Baierl committed
36
   ppir_op_abs,
Andreas Baierl's avatar
Andreas Baierl committed
37
   ppir_op_neg,
Andreas Baierl's avatar
Andreas Baierl committed
38
   ppir_op_sat,
Qiang Yu's avatar
Qiang Yu committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
   ppir_op_add,

   ppir_op_ddx,
   ppir_op_ddy,

   ppir_op_mul,
   ppir_op_rcp,

   ppir_op_sin_lut,
   ppir_op_cos_lut,

   ppir_op_sum3,
   ppir_op_sum4,

   ppir_op_normalize2,
   ppir_op_normalize3,
   ppir_op_normalize4,

57
   ppir_op_sel_cond,
Qiang Yu's avatar
Qiang Yu committed
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
   ppir_op_select,

   ppir_op_sin,
   ppir_op_cos,
   ppir_op_tan,
   ppir_op_asin,
   ppir_op_acos,

   ppir_op_atan,
   ppir_op_atan2,
   ppir_op_atan_pt1,
   ppir_op_atan2_pt1,
   ppir_op_atan_pt2,

   ppir_op_exp,
   ppir_op_log,
   ppir_op_exp2,
   ppir_op_log2,
   ppir_op_sqrt,
   ppir_op_rsqrt,

   ppir_op_sign,
   ppir_op_floor,
   ppir_op_ceil,
   ppir_op_fract,
   ppir_op_mod,
   ppir_op_min,
   ppir_op_max,
Erico Nunes's avatar
Erico Nunes committed
86
   ppir_op_trunc,
Qiang Yu's avatar
Qiang Yu committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

   ppir_op_and,
   ppir_op_or,
   ppir_op_xor,

   ppir_op_lt,
   ppir_op_gt,
   ppir_op_le,
   ppir_op_ge,
   ppir_op_eq,
   ppir_op_ne,
   ppir_op_not,

   ppir_op_load_uniform,
   ppir_op_load_varying,
   ppir_op_load_coords,
103
   ppir_op_load_coords_reg,
104
   ppir_op_load_fragcoord,
105
   ppir_op_load_pointcoord,
106
   ppir_op_load_frontface,
Qiang Yu's avatar
Qiang Yu committed
107
108
109
110
111
112
113
114
   ppir_op_load_texture,
   ppir_op_load_temp,

   ppir_op_store_temp,
   ppir_op_store_color,

   ppir_op_const,

115
116
117
   ppir_op_discard,
   ppir_op_branch,

118
   ppir_op_undef,
119
   ppir_op_dummy,
Vasily Khoruzhick's avatar
Vasily Khoruzhick committed
120

Qiang Yu's avatar
Qiang Yu committed
121
122
123
124
125
126
127
128
129
   ppir_op_num,
} ppir_op;

typedef enum {
   ppir_node_type_alu,
   ppir_node_type_const,
   ppir_node_type_load,
   ppir_node_type_store,
   ppir_node_type_load_texture,
130
131
   ppir_node_type_discard,
   ppir_node_type_branch,
Qiang Yu's avatar
Qiang Yu committed
132
133
134
135
136
137
138
139
140
141
} ppir_node_type;

typedef struct {
   char *name;
   ppir_node_type type;
   int *slots;
} ppir_op_info;

extern const ppir_op_info ppir_op_infos[];

142
143
144
145
146
147
typedef enum {
   ppir_dep_src,
   ppir_dep_write_after_read,
   ppir_dep_sequence,
} ppir_dep_type;

Qiang Yu's avatar
Qiang Yu committed
148
149
typedef struct {
   void *pred, *succ;
150
   ppir_dep_type type;
Qiang Yu's avatar
Qiang Yu committed
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
   struct list_head pred_link;
   struct list_head succ_link;
} ppir_dep;

typedef struct ppir_node {
   struct list_head list;
   ppir_op op;
   ppir_node_type type;
   int index;
   char name[16];
   bool printed;
   struct ppir_instr *instr;
   int instr_pos;
   struct ppir_block *block;

   /* for scheduler */
   struct list_head succ_list;
   struct list_head pred_list;
} ppir_node;

typedef enum {
   ppir_pipeline_reg_const0,
   ppir_pipeline_reg_const1,
   ppir_pipeline_reg_sampler,
   ppir_pipeline_reg_uniform,
   ppir_pipeline_reg_vmul,
   ppir_pipeline_reg_fmul,
   ppir_pipeline_reg_discard, /* varying load */
} ppir_pipeline;

typedef struct ppir_reg {
   struct list_head list;
   int index;
184
   int regalloc_index;
Qiang Yu's avatar
Qiang Yu committed
185
   int num_components;
186

Qiang Yu's avatar
Qiang Yu committed
187
188
   /* whether this reg has to start from the x component
    * of a full physical reg, this is true for reg used
189
    * in load/store instr which has no swizzle field */
Qiang Yu's avatar
Qiang Yu committed
190
191
   bool is_head;
   bool spilled;
Andreas Baierl's avatar
Andreas Baierl committed
192
   bool undef;
Qiang Yu's avatar
Qiang Yu committed
193
194
195
196
197
198
199
200
201
202
} ppir_reg;

typedef enum {
   ppir_target_ssa,
   ppir_target_pipeline,
   ppir_target_register,
} ppir_target;

typedef struct ppir_src {
   ppir_target type;
203
   ppir_node *node;
Qiang Yu's avatar
Qiang Yu committed
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

   union {
      ppir_reg *ssa;
      ppir_reg *reg;
      ppir_pipeline pipeline;
   };

   uint8_t swizzle[4];
   bool absolute, negate;
} ppir_src;

typedef enum {
   ppir_outmod_none,
   ppir_outmod_clamp_fraction,
   ppir_outmod_clamp_positive,
   ppir_outmod_round,
} ppir_outmod;

typedef struct ppir_dest {
   ppir_target type;

   union {
      ppir_reg ssa;
      ppir_reg *reg;
      ppir_pipeline pipeline;
   };

   ppir_outmod modifier;
   unsigned write_mask : 4;
} ppir_dest;

typedef struct {
   ppir_node node;
   ppir_dest dest;
   ppir_src src[3];
   int num_src;
   int shift : 3; /* Only used for ppir_op_mul */
} ppir_alu_node;

typedef struct ppir_const {
   union fi value[4];
   int num;
} ppir_const;

typedef struct {
   ppir_node node;
   ppir_const constant;
   ppir_dest dest;
} ppir_const_node;

typedef struct {
   ppir_node node;
   int index;
   int num_components;
   ppir_dest dest;
   ppir_src src;
260
   int num_src;
Qiang Yu's avatar
Qiang Yu committed
261
262
263
264
265
266
267
268
269
270
271
272
} ppir_load_node;

typedef struct {
   ppir_node node;
   int index;
   int num_components;
   ppir_src src;
} ppir_store_node;

typedef struct {
   ppir_node node;
   ppir_dest dest;
Erico Nunes's avatar
Erico Nunes committed
273
274
275
   ppir_src src[2]; /* src[0] temporarily stores src_coords,
                       not to be used after lowering */
   int num_src;
Qiang Yu's avatar
Qiang Yu committed
276
277
   int sampler;
   int sampler_dim;
278
279
   bool lod_bias_en;
   bool explicit_lod;
Qiang Yu's avatar
Qiang Yu committed
280
281
} ppir_load_texture_node;

282
283
284
285
typedef struct {
   ppir_node node;
} ppir_discard_node;

Qiang Yu's avatar
Qiang Yu committed
286
287
288
289
290
291
292
293
294
295
enum ppir_instr_slot {
   PPIR_INSTR_SLOT_VARYING,
   PPIR_INSTR_SLOT_TEXLD,
   PPIR_INSTR_SLOT_UNIFORM,
   PPIR_INSTR_SLOT_ALU_VEC_MUL,
   PPIR_INSTR_SLOT_ALU_SCL_MUL,
   PPIR_INSTR_SLOT_ALU_VEC_ADD,
   PPIR_INSTR_SLOT_ALU_SCL_ADD,
   PPIR_INSTR_SLOT_ALU_COMBINE,
   PPIR_INSTR_SLOT_STORE_TEMP,
296
   PPIR_INSTR_SLOT_BRANCH,
Qiang Yu's avatar
Qiang Yu committed
297
298
299
300
301
302
   PPIR_INSTR_SLOT_NUM,
   PPIR_INSTR_SLOT_END,
   PPIR_INSTR_SLOT_ALU_START = PPIR_INSTR_SLOT_ALU_VEC_MUL,
   PPIR_INSTR_SLOT_ALU_END = PPIR_INSTR_SLOT_ALU_COMBINE,
};

303
304
305
306
307
struct ppir_liveness {
   ppir_reg *reg;
   unsigned mask : 4;
};

Qiang Yu's avatar
Qiang Yu committed
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
typedef struct ppir_instr {
   struct list_head list;
   int index;
   bool printed;
   int seq; /* command sequence after schedule */

   ppir_node *slots[PPIR_INSTR_SLOT_NUM];
   ppir_const constant[2];
   bool is_end;

   /* for scheduler */
   struct list_head succ_list;
   struct list_head pred_list;
   float reg_pressure;
   int est; /* earliest start time */
   int parent_index;
   bool scheduled;
kszaq's avatar
kszaq committed
325
   int offset;
326
   int encode_size;
327
328
329
330
331
332

   /* for liveness analysis */
   struct ppir_liveness *live_in;
   struct ppir_liveness *live_out;
   struct set *live_in_set;
   struct set *live_out_set;
Qiang Yu's avatar
Qiang Yu committed
333
334
335
336
337
338
} ppir_instr;

typedef struct ppir_block {
   struct list_head list;
   struct list_head node_list;
   struct list_head instr_list;
339
340
341

   struct ppir_block *successors[2];

Qiang Yu's avatar
Qiang Yu committed
342
343
344
345
346
   struct ppir_compiler *comp;

   /* for scheduler */
   int sched_instr_index;
   int sched_instr_base;
347
   int index;
348

349
350
351
352
353
   /* for liveness analysis */
   struct ppir_liveness *live_in;
   struct ppir_liveness *live_out;
   struct set *live_in_set;
   struct set *live_out_set;
Qiang Yu's avatar
Qiang Yu committed
354
355
} ppir_block;

356
357
358
typedef struct {
   ppir_node node;
   ppir_src src[2];
359
   int num_src;
360
361
362
   bool cond_gt;
   bool cond_eq;
   bool cond_lt;
363
   bool negate;
364
365
366
   ppir_block *target;
} ppir_branch_node;

Qiang Yu's avatar
Qiang Yu committed
367
368
369
370
371
struct ra_regs;
struct lima_fs_shader_state;

typedef struct ppir_compiler {
   struct list_head block_list;
372
   struct hash_table_u64 *blocks;
Qiang Yu's avatar
Qiang Yu committed
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
   int cur_index;
   int cur_instr_index;

   struct list_head reg_list;

   /* array for searching ssa/reg node */
   ppir_node **var_nodes;
   unsigned reg_base;

   struct ra_regs *ra;
   struct lima_fs_shader_state *prog;

   /* for scheduler */
   int sched_instr_base;

   /* for regalloc spilling debug */
   int force_spilling;
390

391
392
393
394
395
   /* shaderdb */
   int num_loops;
   int num_spills;
   int num_fills;

396
   ppir_block *discard_block;
397
398
399
   ppir_block *current_block;
   ppir_block *loop_break_block;
   ppir_block *loop_cont_block;
Qiang Yu's avatar
Qiang Yu committed
400
401
402
} ppir_compiler;

void *ppir_node_create(ppir_block *block, ppir_op op, int index, unsigned mask);
403
void ppir_node_add_dep(ppir_node *succ, ppir_node *pred, ppir_dep_type type);
Qiang Yu's avatar
Qiang Yu committed
404
405
406
407
408
409
void ppir_node_remove_dep(ppir_dep *dep);
void ppir_node_delete(ppir_node *node);
void ppir_node_print_prog(ppir_compiler *comp);
void ppir_node_replace_child(ppir_node *parent, ppir_node *old_child, ppir_node *new_child);
void ppir_node_replace_all_succ(ppir_node *dst, ppir_node *src);
void ppir_node_replace_pred(ppir_dep *dep, ppir_node *new_pred);
410
void ppir_delete_if_orphan(ppir_block *block, ppir_node *node);
411
ppir_dep *ppir_dep_for_pred(ppir_node *node, ppir_node *pred);
412
ppir_node *ppir_node_clone(ppir_block *block, ppir_node *node);
413
414
/* Assumes that node successors are in the same block */
ppir_node *ppir_node_insert_mov(ppir_node *node);
Qiang Yu's avatar
Qiang Yu committed
415
416
417

static inline bool ppir_node_is_root(ppir_node *node)
{
418
   return list_is_empty(&node->succ_list);
Qiang Yu's avatar
Qiang Yu committed
419
420
421
422
}

static inline bool ppir_node_is_leaf(ppir_node *node)
{
423
   return list_is_empty(&node->pred_list);
Qiang Yu's avatar
Qiang Yu committed
424
425
426
427
428
429
430
}

static inline bool ppir_node_has_single_succ(ppir_node *node)
{
   return list_is_singular(&node->succ_list);
}

431
432
bool ppir_node_has_single_src_succ(ppir_node *node);

Qiang Yu's avatar
Qiang Yu committed
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
static inline ppir_node *ppir_node_first_succ(ppir_node *node)
{
   return list_first_entry(&node->succ_list, ppir_dep, succ_link)->succ;
}

static inline bool ppir_node_has_single_pred(ppir_node *node)
{
   return list_is_singular(&node->pred_list);
}

static inline ppir_node *ppir_node_first_pred(ppir_node *node)
{
   return list_first_entry(&node->pred_list, ppir_dep, pred_link)->pred;
}

#define ppir_node_foreach_succ(node, dep) \
   list_for_each_entry(ppir_dep, dep, &node->succ_list, succ_link)
#define ppir_node_foreach_succ_safe(node, dep) \
   list_for_each_entry_safe(ppir_dep, dep, &node->succ_list, succ_link)
#define ppir_node_foreach_pred(node, dep) \
   list_for_each_entry(ppir_dep, dep, &node->pred_list, pred_link)
#define ppir_node_foreach_pred_safe(node, dep) \
   list_for_each_entry_safe(ppir_dep, dep, &node->pred_list, pred_link)

#define ppir_node_to_alu(node) ((ppir_alu_node *)(node))
#define ppir_node_to_const(node) ((ppir_const_node *)(node))
#define ppir_node_to_load(node) ((ppir_load_node *)(node))
#define ppir_node_to_store(node) ((ppir_store_node *)(node))
#define ppir_node_to_load_texture(node) ((ppir_load_texture_node *)(node))
462
463
#define ppir_node_to_discard(node) ((ppir_discard_node *)(node))
#define ppir_node_to_branch(node) ((ppir_branch_node *)(node))
Qiang Yu's avatar
Qiang Yu committed
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480

static inline ppir_dest *ppir_node_get_dest(ppir_node *node)
{
   switch (node->type) {
   case ppir_node_type_alu:
      return &ppir_node_to_alu(node)->dest;
   case ppir_node_type_load:
      return &ppir_node_to_load(node)->dest;
   case ppir_node_type_const:
      return &ppir_node_to_const(node)->dest;
   case ppir_node_type_load_texture:
      return &ppir_node_to_load_texture(node)->dest;
   default:
      return NULL;
   }
}

481
482
483
484
485
486
static inline int ppir_node_get_src_num(ppir_node *node)
{
   switch (node->type) {
   case ppir_node_type_alu:
      return ppir_node_to_alu(node)->num_src;
   case ppir_node_type_branch:
487
      return ppir_node_to_branch(node)->num_src;
488
   case ppir_node_type_load:
489
490
      return ppir_node_to_load(node)->num_src;
   case ppir_node_type_load_texture:
Erico Nunes's avatar
Erico Nunes committed
491
      return ppir_node_to_load_texture(node)->num_src;
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
   case ppir_node_type_store:
      return 1;
   default:
      return 0;
   }

   return 0;
}

static inline ppir_src *ppir_node_get_src(ppir_node *node, int idx)
{
   if (idx < 0 || idx >= ppir_node_get_src_num(node))
      return NULL;

   switch (node->type) {
   case ppir_node_type_alu:
      return &ppir_node_to_alu(node)->src[idx];
   case ppir_node_type_branch:
      return &ppir_node_to_branch(node)->src[idx];
   case ppir_node_type_load_texture:
Erico Nunes's avatar
Erico Nunes committed
512
      return &ppir_node_to_load_texture(node)->src[idx];
513
514
515
516
517
518
519
520
521
522
523
   case ppir_node_type_load:
      return &ppir_node_to_load(node)->src;
   case ppir_node_type_store:
      return &ppir_node_to_store(node)->src;
   default:
      break;
   }

   return NULL;
}

524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
static inline ppir_reg *ppir_src_get_reg(ppir_src *src)
{
   switch (src->type) {
   case ppir_target_ssa:
      return src->ssa;
   case ppir_target_register:
      return src->reg;
   default:
      return NULL;
   }
}

static inline ppir_reg *ppir_dest_get_reg(ppir_dest *dest)
{
   switch (dest->type) {
   case ppir_target_ssa:
      return &dest->ssa;
   case ppir_target_register:
      return dest->reg;
   default:
      return NULL;
   }
}

548
549
550
551
552
553
554
555
556
557
558
static inline ppir_src *ppir_node_get_src_for_pred(ppir_node *node, ppir_node *pred)
{
   for (int i = 0; i < ppir_node_get_src_num(node); i++) {
      ppir_src *src = ppir_node_get_src(node, i);
      if (src && src->node == pred)
         return src;
   }

   return NULL;
}

559
static inline void ppir_node_target_assign(ppir_src *src, ppir_node *node)
Qiang Yu's avatar
Qiang Yu committed
560
{
561
   ppir_dest *dest = ppir_node_get_dest(node);
Qiang Yu's avatar
Qiang Yu committed
562
563
564
565
   src->type = dest->type;
   switch (src->type) {
   case ppir_target_ssa:
      src->ssa = &dest->ssa;
566
      src->node = node;
Qiang Yu's avatar
Qiang Yu committed
567
568
569
      break;
   case ppir_target_register:
      src->reg = dest->reg;
570
571
572
573
      /* Registers can be assigned from multiple nodes, so don't keep
       * pointer to the node here
       */
      src->node = NULL;
Qiang Yu's avatar
Qiang Yu committed
574
575
576
      break;
   case ppir_target_pipeline:
      src->pipeline = dest->pipeline;
577
      src->node = node;
Qiang Yu's avatar
Qiang Yu committed
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
      break;
   }
}

static inline bool ppir_node_target_equal(ppir_src *src, ppir_dest *dest)
{
   if (src->type != dest->type ||
       (src->type == ppir_target_ssa && src->ssa != &dest->ssa) ||
       (src->type == ppir_target_register && src->reg != dest->reg) ||
       (src->type == ppir_target_pipeline && src->pipeline != dest->pipeline))
      return false;

   return true;
}

static inline int ppir_target_get_src_reg_index(ppir_src *src)
{
   switch (src->type) {
   case ppir_target_ssa:
597
598
599
      if (src->ssa)
         return src->ssa->index;
      break;
Qiang Yu's avatar
Qiang Yu committed
600
   case ppir_target_register:
601
602
603
      if (src->reg)
         return src->reg->index;
      break;
Qiang Yu's avatar
Qiang Yu committed
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
   case ppir_target_pipeline:
      if (src->pipeline == ppir_pipeline_reg_discard)
         return 15 * 4;
      return (src->pipeline + 12) * 4;
   }

   return -1;
}

static inline int ppir_target_get_dest_reg_index(ppir_dest *dest)
{
   switch (dest->type) {
   case ppir_target_ssa:
      return dest->ssa.index;
   case ppir_target_register:
      return dest->reg->index;
   case ppir_target_pipeline:
      if (dest->pipeline == ppir_pipeline_reg_discard)
         return 15 * 4;
      return (dest->pipeline + 12) * 4;
   }

   return -1;
}

629
630
631
632
633
634
635
636
637
638
639
static inline int ppir_src_get_mask(ppir_src *src)
{
   ppir_reg *reg = ppir_src_get_reg(src);
   int mask = 0;

   for (int i = 0; i < reg->num_components; i++)
      mask |= (1 << src->swizzle[i]);

   return mask;
}

Qiang Yu's avatar
Qiang Yu committed
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
static inline bool ppir_target_is_scaler(ppir_dest *dest)
{
   switch (dest->type) {
   case ppir_target_ssa:
      return dest->ssa.num_components == 1;
   case ppir_target_register:
      /* only one bit in mask is set */
      if ((dest->write_mask & 0x3) == 0x3 ||
          (dest->write_mask & 0x5) == 0x5 ||
          (dest->write_mask & 0x9) == 0x9 ||
          (dest->write_mask & 0x6) == 0x6 ||
          (dest->write_mask & 0xa) == 0xa ||
          (dest->write_mask & 0xc) == 0xc)
         return false;
      else
         return true;
   case ppir_target_pipeline:
      if (dest->pipeline == ppir_pipeline_reg_fmul)
         return true;
      else
         return false;
   default:
      return false;
   }
}

ppir_instr *ppir_instr_create(ppir_block *block);
bool ppir_instr_insert_node(ppir_instr *instr, ppir_node *node);
void ppir_instr_add_dep(ppir_instr *succ, ppir_instr *pred);
void ppir_instr_print_list(ppir_compiler *comp);
void ppir_instr_print_dep(ppir_compiler *comp);
void ppir_instr_insert_mul_node(ppir_node *add, ppir_node *mul);

#define ppir_instr_foreach_succ(instr, dep) \
   list_for_each_entry(ppir_dep, dep, &instr->succ_list, succ_link)
#define ppir_instr_foreach_succ_safe(instr, dep) \
   list_for_each_entry_safe(ppir_dep, dep, &instr->succ_list, succ_link)
#define ppir_instr_foreach_pred(instr, dep) \
   list_for_each_entry(ppir_dep, dep, &instr->pred_list, pred_link)
#define ppir_instr_foreach_pred_safe(instr, dep) \
   list_for_each_entry_safe(ppir_dep, dep, &instr->pred_list, pred_link)

static inline bool ppir_instr_is_root(ppir_instr *instr)
{
684
   return list_is_empty(&instr->succ_list);
Qiang Yu's avatar
Qiang Yu committed
685
686
687
688
}

static inline bool ppir_instr_is_leaf(ppir_instr *instr)
{
689
   return list_is_empty(&instr->pred_list);
Qiang Yu's avatar
Qiang Yu committed
690
691
692
693
694
695
696
}

bool ppir_lower_prog(ppir_compiler *comp);
bool ppir_node_to_instr(ppir_compiler *comp);
bool ppir_schedule_prog(ppir_compiler *comp);
bool ppir_regalloc_prog(ppir_compiler *comp);
bool ppir_codegen_prog(ppir_compiler *comp);
697
void ppir_liveness_analysis(ppir_compiler *comp);
Qiang Yu's avatar
Qiang Yu committed
698
699

#endif