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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_70/] [or1ksim/] [cuc/] [cuc.h] - Blame information for rev 907

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

powered by: WebSVN 2.1.0

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