OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [or1ksim/] [cuc/] [cuc.h] - Blame information for rev 169

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jeremybenn
/* cuc.h -- OpenRISC Custom Unit Compiler, main header file
2
 
3
   Copyright (C) 2002 Marko Mlinar, markom@opencores.org
4
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
#ifndef CUC__H
28
#define CUC__H
29
 
30
/* Package includes */
31
#include "abstract.h"
32
 
33
 
34
/* Maximum number of instructions per function */
35
#define MAX_INSNS       0x10000
36
#define MAX_BB          0x1000
37
#define MAX_REGS        34
38
#define FLAG_REG        (MAX_REGS - 2)
39
#define LRBB_REG        (MAX_REGS - 1)
40
#define CUC_MAX_STACK   0x1000  /* if more, not converted */
41
#define MAX_PREROLL     32
42
#define MAX_UNROLL      32
43
 
44
#define IT_BRANCH       0x0001  /* Branch instruction */
45
#define IT_INDELAY      0x0002  /* Instruction is in delay slot */
46
#define IT_BBSTART      0x0004  /* BB start marker */
47
#define IT_BBEND        0x0008  /* BB end marker */
48
#define IT_OUTPUT       0x0010  /* this instruction holds final value of the register */
49
#define IT_SIGNED       0x0020  /* Instruction is signed */
50
#define IT_MEMORY       0x0040  /* Instruction does memory access */
51
#define IT_UNUSED       0x0080  /* dead instruction marker */
52
#define IT_FLAG1        0x0100  /* misc flags */
53
#define IT_FLAG2        0x0200
54
#define IT_VOLATILE     0x0400  /* Should not be moved/removed */
55
#define IT_MEMADD       0x0800  /* add before the load -- should not be removed */
56
#define IT_COND         0x1000  /* Conditional */
57
#define IT_LATCHED      0x2000  /* Output of this instruction is latched/registered */
58
#define IT_CUT          0x4000  /* After this instruction register is placed */
59
 
60
#define OPT_NONE        0x00
61
#define OPT_CONST       0x01
62
#define OPT_REGISTER    0x02
63
#define OPT_REF         0x04
64
#define OPT_JUMP        0x08    /* Jump to an instruction index */
65
#define OPT_DEST        0x10    /* This operand is dest */
66
#define OPT_BB          0x20    /* Jumpt to BB */
67
#define OPT_LRBB        0x40    /* 0 if we came in from left BB, or 1 otherwise */
68
 
69
#define MT_WIDTH        0x007   /* These bits hold memory access width in bytes */
70
#define MT_BURST        0x008   /* burst start & end markers */
71
#define MT_BURSTE       0x010
72
#define MT_CALL         0x020   /* This is a call */
73
#define MT_LOAD         0x040   /* This memory access does a read */
74
#define MT_STORE        0x080   /* This memory access does a write */
75
#define MT_SIGNED       0x100   /* Signed memory access */
76
 
77
#define MO_NONE         0       /* different memory ordering, even if there are dependencies,
78
                                   burst can be made, width can change */
79
#define MO_WEAK         1       /* different memory ordering, if there cannot be dependencies,
80
                                   burst can be made, width can change */
81
#define MO_STRONG       2       /* Same memory ordering, burst can be made, width can change */
82
#define MO_EXACT        3       /* Exacltly the same memory ordering and widths */
83
 
84
#define BB_INLOOP       0x01    /* This block is inside a loop */
85
#define BB_OPTIONAL     0x02
86
#define BB_DEAD         0x08    /* This block is unaccessible -> to be removed */
87
 
88
#define BBID_START      MAX_BB  /* Start BB pointer */
89
#define BBID_END        (MAX_BB + 1)    /* End BB pointer */
90
 
91
/* Various macros to minimize code size */
92
#define REF(bb,i)       (((bb) * MAX_INSNS) + (i))
93
#define REF_BB(r)       ((r) / MAX_INSNS)
94
#define REF_I(r)        ((r) % MAX_INSNS)
95
#define INSN(ref)       bb[REF_BB(ref)].insn[REF_I(ref)]
96
 
97
#ifndef MIN
98
# define MIN(x,y)          ((x) < (y) ? (x) : (y))
99
#endif
100
 
101
#ifndef MAX
102
# define MAX(x,y)          ((x) > (y) ? (x) : (y))
103
#endif
104
 
105
#define log(x...)       {fprintf (flog, x); fflush (flog); }
106
 
107
#define cucdebug(x,s...) {if ((x) <= cuc_debug) PRINTF (s);}
108
 
109
#define CUC_WIDTH_ITERATIONS  256
110
 
111
/* Options */
112
/* Whether we are debugging cuc (0-9) */
113
extern int cuc_debug;
114
 
115
/* Temporary registers by software convention */
116
extern const int caller_saved[MAX_REGS];
117
 
118
typedef struct _dep_list_t
119
{
120
  unsigned long ref;
121
  struct _dep_list_t *next;
122
} dep_list;
123
 
124
/* Shared list, if marked dead, entry is not used */
125
typedef struct _csm_list
126
{
127
  int ref;
128
  int cnt;
129
  int cmovs;
130
  double size, osize;
131
  int cmatch;
132
  int dead;
133
  int ninsn;                    /* Number of associated instructions */
134
  struct _csm_list *from;
135
  struct _csm_list *next;
136
} cuc_shared_list;
137
 
138
/* Shared resource item definition */
139
typedef struct
140
{
141
  int ref;
142
  int cmatch;
143
} cuc_shared_item;
144
 
145
/* Implementation specific timings */
146
typedef struct
147
{
148
  int b;                        /* Basic block # this timing is referring to */
149
  int preroll;                  /* How many times was this BB pre/unrolled */
150
  int unroll;
151
  int nshared;
152
  cuc_shared_item *shared;      /* List of shared resources */
153
  int new_time;
154
  double size;
155
} cuc_timings;
156
 
157
/* Instructionn entity */
158
typedef struct
159
{
160
  int type;                     /* type of the instruction */
161
  int index;                    /* Instruction index */
162
  int opt[MAX_OPERANDS];        /* operand types */
163
  unsigned long op[MAX_OPERANDS];       /* operand values */
164
  dep_list *dep;                /* instruction dependencies */
165
  unsigned long insn;           /* Instruction opcode */
166
  char disasm[40];              /* disassembled string */
167
  unsigned long max;            /* max result value */
168
  int tmp;
169
} cuc_insn;
170
 
171
/* Basic block entity */
172
typedef struct
173
{
174
  unsigned long type;           /* Type of the bb */
175
  int first, last;              /* Where this block lies */
176
  int prev[2], next[2];
177
  int tmp;
178
  cuc_insn *insn;               /* Instructions lie here */
179
  int ninsn;                    /* Number of instructions */
180
  int last_used_reg[MAX_REGS];
181
  dep_list *mdep;               /* Last memory access dependencies */
182
  int nmemory;
183
  int cnt;                      /* how many times was this block executed */
184
  int unrolled;                 /* how many times has been this block unrolled */
185
 
186
  int ntim;                     /* Basic block options */
187
  cuc_timings *tim;
188
  int selected_tim;             /* Selected option, -1 if none */
189
} cuc_bb;
190
 
191
/* Function entity */
192
typedef struct _cuc_func
193
{
194
  /* Basic blocks */
195
  int num_bb;
196
  cuc_bb bb[MAX_BB];
197
  int saved_regs[MAX_REGS];     /* Whether this register was saved */
198
  int lur[MAX_REGS];            /* Location of last use */
199
  int used_regs[MAX_REGS];      /* Nonzero if it was used */
200
 
201
  /* Schedule of memory instructions */
202
  int nmsched;
203
  int msched[MAX_INSNS];
204
  int mtype[MAX_INSNS];
205
 
206
  /* initial bb and their relocations to new block numbers */
207
  int num_init_bb;
208
  int *init_bb_reloc;
209
  int orig_time;                /* time in cyc required for SW implementation */
210
  int num_runs;                 /* Number times this function was run */
211
  cuc_timings timings;          /* Base timings */
212
  unsigned long start_addr;     /* Address of first instruction inn function */
213
  unsigned long end_addr;       /* Address of last instruction inn function */
214
  int memory_order;             /* Memory order */
215
 
216
  int nfdeps;                   /* Function dependencies */
217
  struct _cuc_func **fdeps;
218
 
219
  int tmp;
220
} cuc_func;
221
 
222
/* Instructions from function */
223
extern cuc_insn insn[MAX_INSNS];
224
extern int num_insn;
225
extern int reloc[MAX_INSNS];
226
extern FILE *flog;
227
 
228
/* Loads from file into global array insn */
229
int cuc_load (char *in_fn);
230
 
231
/* Negates conditional instruction */
232
void negate_conditional (cuc_insn * ii);
233
 
234
/* Scans sequence of BBs and set bb[].cnt */
235
void generate_bb_seq (cuc_func * f, char *mp_filename, char *bb_filename);
236
 
237
/* Prints out instructions */
238
void print_insns (int bb, cuc_insn * insn, int size, int verbose);
239
 
240
/* prints out bb string */
241
void print_bb_num (int num);
242
 
243
/* Print out basic blocks */
244
void print_cuc_bb (cuc_func * func, char *s);
245
 
246
/* Duplicates function */
247
cuc_func *dup_func (cuc_func * f);
248
 
249
/* Releases memory allocated by function */
250
void free_func (cuc_func * f);
251
 
252
/* Common subexpression matching -- resource sharing, analysis pass */
253
void csm (cuc_func * f);
254
 
255
/* Common subexpression matching -- resource sharing, generation pass */
256
void csm_gen (cuc_func * f, cuc_func * rf, cuc_shared_item * shared,
257
              int nshared);
258
 
259
/* Set the BB limits */
260
void detect_bb (cuc_func * func);
261
 
262
/* Optimize basic blocks */
263
int optimize_bb (cuc_func * func);
264
 
265
/* Search and optimize complex cmov assignments */
266
int optimize_cmovs (cuc_func * func);
267
 
268
/* Optimizes dataflow tree */
269
int optimize_tree (cuc_func * func);
270
 
271
/* Remove nop instructions */
272
int remove_nops (cuc_func * func);
273
 
274
/* Removes dead instruction */
275
int remove_dead (cuc_func * func);
276
 
277
/* Removes trivial register assignments */
278
int remove_trivial_regs (cuc_func * f);
279
 
280
/* Determine inputs and outputs */
281
void set_io (cuc_func * func);
282
 
283
/* Removes BBs marked as dead */
284
int remove_dead_bb (cuc_func * func);
285
 
286
/* Common subexpression elimination */
287
int cse (cuc_func * f);
288
 
289
/* Detect register dependencies */
290
void reg_dep (cuc_func * func);
291
 
292
/* Cuts the tree and marks registers */
293
void mark_cut (cuc_func * f);
294
 
295
/* Unroll loop b times times and return new function. Original
296
   function is unmodified. */
297
cuc_func *preunroll_loop (cuc_func * func, int b, int preroll, int unroll,
298
                          char *bb_filename);
299
 
300
/* Clean memory and data dependencies */
301
void clean_deps (cuc_func * func);
302
 
303
/* Schedule memory accesses
304
 
305
int schedule_memory (cuc_func * func, int otype);
306
 
307
/* Recalculates bb[].cnt values, based on generated profile file */
308
void recalc_cnts (cuc_func * f, char *bb_filename);
309
 
310
/* Calculate timings */
311
void analyse_timings (cuc_func * func, cuc_timings * timings);
312
 
313
/* Calculates facts, that are determined by conditionals */
314
void insert_conditional_facts (cuc_func * func);
315
 
316
/* Width optimization -- detect maximum values */
317
void detect_max_values (cuc_func * f);
318
 
319
/* Inserts n nops before insn 'ref' */
320
void insert_insns (cuc_func * f, int ref, int n);
321
 
322
/* Checks for some anomalies with references */
323
void cuc_check (cuc_func * f);
324
 
325
/* Adds memory dependencies based on ordering type */
326
void add_memory_dep (cuc_func * f, int otype);
327
 
328
/* Prints out instructions */
329
void print_cuc_insns (char *s, int verbose);
330
 
331
/* Build basic blocks */
332
void build_bb (cuc_func * f);
333
 
334
/* Latch outputs in loops */
335
void add_latches (cuc_func * f);
336
 
337
/* split the BB, based on the group numbers in .tmp */
338
void expand_bb (cuc_func * f, int b);
339
 
340
void add_dep (dep_list ** list, int dep);
341
 
342
void dispose_list (dep_list ** list);
343
 
344
void main_cuc (char *filename);
345
 
346
void add_data_dep (cuc_func * f);
347
 
348
void  reg_cuc_sec ();
349
 
350
#endif /* CUC__H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.