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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_57/] [or1ksim/] [cuc/] [cuc.h] - Blame information for rev 1062

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

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

powered by: WebSVN 2.1.0

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