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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0/] [or1ksim/] [cuc/] [cuc.h] - Blame information for rev 925

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
#define MAX_BB          0x100
27
#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 907 markom
#define MT_WIDTH        0x007   /* These bits hold memory access width in bytes  1 << x */
60
#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 925 markom
#define BB_END          0x04    /* Whether this block is last */
77 879 markom
#define BB_DEAD         0x08    /* This block is unaccessible -> to be removed */
78
 
79 925 markom
#define BBID_END        MAX_BB  /* End pointer */
80
 
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 883 markom
#define cucdebug(x,s...) {if ((x) <= cuc_debug) printf (s);}
98
 
99 879 markom
/* Options */
100 883 markom
/* Whether we are debugging cuc (0-9) */
101
extern int cuc_debug;
102 879 markom
 
103
/* Temporary registers by software convention */
104
extern const int call_saved[MAX_REGS];
105
 
106
typedef struct _dep_list_t {
107
        unsigned long ref;
108
        struct _dep_list_t *next;
109
} dep_list;
110
 
111 883 markom
/* Shared list, if marked dead, entry is not used */
112
typedef struct _csm_list {
113
  int ref;
114
  int cnt;
115
  int cmovs;
116
  double size, osize;
117
  int cmatch;
118
  int dead;
119
  int ninsn;                /* Number of associated instructions */
120
  struct _csm_list *from;
121
  struct _csm_list *next;
122 897 markom
} cuc_shared_list;
123 883 markom
 
124 897 markom
/* Shared resource item definition */
125
typedef struct {
126
  int ref;
127
  int cmatch;
128
} cuc_shared_item;
129
 
130 879 markom
/* Implementation specific timings */
131
typedef struct {
132
        int b;                    /* Basic block # this timing is referring to */
133
        int preroll;              /* How many times was this BB pre/unrolled */
134
        int unroll;
135 883 markom
        int nshared;
136 897 markom
        cuc_shared_item *shared;  /* List of shared resources */
137 879 markom
        int new_time;
138
        double size;
139
} cuc_timings;
140
 
141
/* Instructionn entity */
142
typedef struct {
143
        int type;           /* type of the instruction */
144
        int index;          /* Instruction index */
145
        int opt[MAX_OPERANDS];          /* operand types */
146
        unsigned long op[MAX_OPERANDS]; /* operand values */
147
        dep_list *dep;      /* instruction dependencies */
148
        unsigned long insn; /* Instruction opcode */
149
        char disasm[40];    /* disassembled string */
150
        int tmp;
151
} cuc_insn;
152
 
153
/* Basic block entity */
154
typedef struct {
155
        unsigned long type; /* Type of the bb */
156
        int first, last;    /* Where this block lies */
157
        int prev[2], next[2];
158
        int tmp;
159
        cuc_insn *insn;      /* Instructions lie here */
160
        int ninsn;          /* Number of instructions */
161
        int last_used_reg[MAX_REGS];
162
        dep_list *mdep;          /* Last memory access dependencies */
163
        int nmemory;
164
        int cnt;            /* how many times was this block executed */
165
        int unrolled;       /* how many times has been this block unrolled */
166 897 markom
 
167
        int ntim;           /* Basic block options */
168 879 markom
        cuc_timings *tim;
169 897 markom
        int selected_tim;   /* Selected option, -1 if none */
170 879 markom
} cuc_bb;
171
 
172
/* Function entity */
173 906 markom
typedef struct _cuc_func {
174 879 markom
        /* Basic blocks */
175
        int num_bb;
176
        cuc_bb bb[MAX_BB];
177 883 markom
        int saved_regs[MAX_REGS];/* Whether this register was saved */
178
        int lur[MAX_REGS];       /* Location of last use */
179
        int used_regs[MAX_REGS]; /* Nonzero if it was used */
180 879 markom
 
181
        /* Schedule of memory instructions */
182
        int nmsched;
183
        int msched[MAX_INSNS];
184
        int mtype[MAX_INSNS];
185
 
186
        /* initial bb and their relocations to new block numbers */
187
        int num_init_bb;
188
        int *init_bb_reloc;
189
        int orig_time;            /* time in cyc required for SW implementation */
190 883 markom
        int num_runs;             /* Number times this function was run */
191
        cuc_timings timings;      /* Base timings */
192 879 markom
        unsigned long start_addr; /* Address of first instruction inn function */
193
        unsigned long end_addr;   /* Address of last instruction inn function */
194 897 markom
        int memory_order;         /* Memory order */
195 906 markom
 
196
        int nfdeps;               /* Function dependencies */
197
        struct _cuc_func **fdeps;
198
 
199
        int tmp;
200 879 markom
} cuc_func;
201
 
202
/* Instructions from function */
203
extern cuc_insn insn[MAX_INSNS];
204
extern int num_insn;
205
extern int reloc[MAX_INSNS];
206
extern FILE *flog;
207
 
208
/* Loads from file into global array insn */
209 897 markom
int cuc_load (char *in_fn);
210 879 markom
 
211 905 markom
/* Negates conditional instruction */
212
void negate_conditional (cuc_insn *ii);
213
 
214 879 markom
/* Scans sequence of BBs and set bb[].cnt */
215
void generate_bb_seq (cuc_func *f, char *mp_filename, char *bb_filename);
216
 
217
/* Prints out instructions */
218
void print_insns (cuc_insn *insn, int size, int verbose);
219
 
220 925 markom
/* prints out bb string */
221
void print_bb_num (int num);
222
 
223 879 markom
/* Print out basic blocks */
224
void print_cuc_bb (cuc_func *func, char *s);
225
 
226
/* Duplicates function */
227
cuc_func *dup_func (cuc_func *f);
228
 
229
/* Releases memory allocated by function */
230
void free_func (cuc_func *f);
231
 
232 883 markom
/* Common subexpression elimination */
233
void cse (cuc_func *f);
234
 
235 897 markom
/* Common subexpression matching -- resource sharing, analysis pass */
236 883 markom
void csm (cuc_func *f);
237
 
238 897 markom
/* Common subexpression matching -- resource sharing, generation pass */
239
void csm_gen (cuc_func *f, cuc_func *rf, cuc_shared_item *shared, int nshared);
240
 
241 879 markom
/* Set the BB limits */
242
void detect_bb (cuc_func *func);
243
 
244
/* Optimize basic blocks */
245
void optimize_bb (cuc_func *func);
246
 
247
/* Removes BBs marked as dead */
248
void remove_dead_bb (cuc_func *func);
249
 
250
/* Detect register dependencies */
251
void reg_dep (cuc_func *func);
252
 
253
/* Cuts the tree and marks registers */
254
void mark_cut (cuc_func *f);
255
 
256
/* Unroll loop b times times and return new function. Original
257
   function is unmodified. */
258
cuc_func *preunroll_loop (cuc_func *func, int b, int preroll, int unroll, char *bb_filename);
259 883 markom
 
260 879 markom
/* Schedule memory accesses
261
 
262
void schedule_memory (cuc_func *func, int otype);
263
 
264
/* Generates verilog file out of insn dataflow */
265
void output_verilog (cuc_func *func, char *filename);
266
 
267
/* Recalculates bb[].cnt values, based on generated profile file */
268
void recalc_cnts (cuc_func *f, char *bb_filename);
269
 
270
/* Calculate timings */
271
void analyse_timings (cuc_func *func, cuc_timings *timings);
272
 
273
#endif /* __DATAF_H__ */

powered by: WebSVN 2.1.0

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