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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_50/] [or1ksim/] [cuc/] [cuc.h] - Blame information for rev 905

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

powered by: WebSVN 2.1.0

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