OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [or1ksim/] [cuc/] [cuc.h] - Blame information for rev 1646

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

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

powered by: WebSVN 2.1.0

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