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 883

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

powered by: WebSVN 2.1.0

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