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 |
|
|
#define DEBUG 0
|
24 |
|
|
|
25 |
|
|
/* Maximum number of instructions per function */
|
26 |
|
|
#define MAX_INSNS 0x10000
|
27 |
|
|
#define MAX_OPERANDS 4
|
28 |
|
|
#define MAX_BB 0x100
|
29 |
|
|
#define MAX_REGS 34
|
30 |
|
|
#define FLAG_REG (MAX_REGS - 2)
|
31 |
|
|
#define LRBB_REG (MAX_REGS - 1)
|
32 |
|
|
#define MAX_STACK 0x1000 /* if more, not converted */
|
33 |
|
|
#define MAX_PREROLL 32
|
34 |
|
|
#define MAX_UNROLL 32
|
35 |
|
|
|
36 |
|
|
#define IT_BRANCH 0x0001 /* Branch instruction */
|
37 |
|
|
#define IT_INDELAY 0x0002 /* Instruction is in delay slot */
|
38 |
|
|
#define IT_BBSTART 0x0004 /* BB start marker */
|
39 |
|
|
#define IT_BBEND 0x0008 /* BB end marker */
|
40 |
|
|
#define IT_OUTPUT 0x0010 /* this instruction holds final value of the register */
|
41 |
|
|
#define IT_SIGNED 0x0020 /* Instruction is signed */
|
42 |
|
|
#define IT_MEMORY 0x0040 /* Instruction does memory access */
|
43 |
|
|
#define IT_UNUSED 0x0080 /* dead instruction marker */
|
44 |
|
|
#define IT_FLAG1 0x0100 /* misc flags */
|
45 |
|
|
#define IT_FLAG2 0x0200
|
46 |
|
|
#define IT_VOLATILE 0x0400 /* Should not be moved/removed */
|
47 |
|
|
#define IT_MEMADD 0x0800 /* add before the load -- should not be removed */
|
48 |
|
|
#define IT_COND 0x1000 /* Conditional */
|
49 |
|
|
#define IT_LATCHED 0x2000 /* Output of this instruction is latched/registered */
|
50 |
|
|
#define IT_CUT 0x4000 /* After this instruction register is placed */
|
51 |
|
|
|
52 |
|
|
#define OPT_NONE 0x00
|
53 |
|
|
#define OPT_CONST 0x01
|
54 |
|
|
#define OPT_REGISTER 0x02
|
55 |
|
|
#define OPT_REF 0x04
|
56 |
|
|
#define OPT_JUMP 0x08 /* Jump to an instruction index */
|
57 |
|
|
#define OPT_DEST 0x10 /* This operand is dest */
|
58 |
|
|
#define OPT_BB 0x20 /* Jumpt to BB */
|
59 |
|
|
#define OPT_LRBB 0x40 /* 0 if we came in from left BB, or 1 otherwise */
|
60 |
|
|
|
61 |
|
|
#define MT_WIDTH 0x07 /* These bits hold memory access width in bytes 1 << x */
|
62 |
|
|
#define MT_BURST 0x08 /* burst start & end markers */
|
63 |
|
|
#define MT_BURSTE 0x10
|
64 |
|
|
#define MT_WRITE 0x20 /* This memory access does a write */
|
65 |
|
|
#define MT_SIGNED 0x40 /* Signed memory access */
|
66 |
|
|
|
67 |
|
|
#define BB_INLOOP 0x01 /* This block is inside a loop */
|
68 |
|
|
#define BB_OPTIONAL 0x02
|
69 |
|
|
#define BB_END 0x04 /* Last block in a function */
|
70 |
|
|
#define BB_DEAD 0x08 /* This block is unaccessible -> to be removed */
|
71 |
|
|
|
72 |
|
|
/* Various macros to minimize code size */
|
73 |
|
|
#define REF(bb,i) (((bb) * MAX_INSNS) + (i))
|
74 |
|
|
#define REF_BB(r) ((r) / MAX_INSNS)
|
75 |
|
|
#define REF_I(r) ((r) % MAX_INSNS)
|
76 |
|
|
#define INSN(ref) bb[REF_BB(ref)].insn[REF_I(ref)]
|
77 |
|
|
|
78 |
|
|
#define log(x...) fprintf (flog, x)
|
79 |
|
|
|
80 |
|
|
/* Options */
|
81 |
|
|
static const int calling_convention = 1;
|
82 |
|
|
static const int memory_order = 2;
|
83 |
|
|
static const int enable_bursts = 1;
|
84 |
|
|
static const int no_multicycle = 1;
|
85 |
|
|
|
86 |
|
|
/* Temporary registers by software convention */
|
87 |
|
|
extern const int call_saved[MAX_REGS];
|
88 |
|
|
|
89 |
|
|
typedef struct _dep_list_t {
|
90 |
|
|
unsigned long ref;
|
91 |
|
|
struct _dep_list_t *next;
|
92 |
|
|
} dep_list;
|
93 |
|
|
|
94 |
|
|
/* Implementation specific timings */
|
95 |
|
|
typedef struct {
|
96 |
|
|
int b; /* Basic block # this timing is referring to */
|
97 |
|
|
int preroll; /* How many times was this BB pre/unrolled */
|
98 |
|
|
int unroll;
|
99 |
|
|
int new_time;
|
100 |
|
|
int old_time;
|
101 |
|
|
double size;
|
102 |
|
|
} cuc_timings;
|
103 |
|
|
|
104 |
|
|
/* Instructionn entity */
|
105 |
|
|
typedef struct {
|
106 |
|
|
int type; /* type of the instruction */
|
107 |
|
|
int index; /* Instruction index */
|
108 |
|
|
int opt[MAX_OPERANDS]; /* operand types */
|
109 |
|
|
unsigned long op[MAX_OPERANDS]; /* operand values */
|
110 |
|
|
dep_list *dep; /* instruction dependencies */
|
111 |
|
|
unsigned long insn; /* Instruction opcode */
|
112 |
|
|
char disasm[40]; /* disassembled string */
|
113 |
|
|
int tmp;
|
114 |
|
|
} cuc_insn;
|
115 |
|
|
|
116 |
|
|
/* Basic block entity */
|
117 |
|
|
typedef struct {
|
118 |
|
|
unsigned long type; /* Type of the bb */
|
119 |
|
|
int first, last; /* Where this block lies */
|
120 |
|
|
int prev[2], next[2];
|
121 |
|
|
int tmp;
|
122 |
|
|
cuc_insn *insn; /* Instructions lie here */
|
123 |
|
|
int ninsn; /* Number of instructions */
|
124 |
|
|
int last_used_reg[MAX_REGS];
|
125 |
|
|
dep_list *mdep; /* Last memory access dependencies */
|
126 |
|
|
int nmemory;
|
127 |
|
|
int cnt; /* how many times was this block executed */
|
128 |
|
|
int unrolled; /* how many times has been this block unrolled */
|
129 |
|
|
int ntim; /* Basic block options */
|
130 |
|
|
cuc_timings *tim;
|
131 |
|
|
} cuc_bb;
|
132 |
|
|
|
133 |
|
|
/* Function entity */
|
134 |
|
|
typedef struct {
|
135 |
|
|
/* Basic blocks */
|
136 |
|
|
int num_bb;
|
137 |
|
|
cuc_bb bb[MAX_BB];
|
138 |
|
|
int saved_regs[MAX_REGS];
|
139 |
|
|
|
140 |
|
|
/* Schedule of memory instructions */
|
141 |
|
|
int nmsched;
|
142 |
|
|
int msched[MAX_INSNS];
|
143 |
|
|
int mtype[MAX_INSNS];
|
144 |
|
|
|
145 |
|
|
/* initial bb and their relocations to new block numbers */
|
146 |
|
|
int num_init_bb;
|
147 |
|
|
int *init_bb_reloc;
|
148 |
|
|
int orig_time; /* time in cyc required for SW implementation */
|
149 |
|
|
unsigned long start_addr; /* Address of first instruction inn function */
|
150 |
|
|
unsigned long end_addr; /* Address of last instruction inn function */
|
151 |
|
|
} cuc_func;
|
152 |
|
|
|
153 |
|
|
/* Instructions from function */
|
154 |
|
|
extern cuc_insn insn[MAX_INSNS];
|
155 |
|
|
extern int num_insn;
|
156 |
|
|
extern int reloc[MAX_INSNS];
|
157 |
|
|
extern FILE *flog;
|
158 |
|
|
|
159 |
|
|
/* Loads from file into global array insn */
|
160 |
|
|
void cuc_load (char *in_fn);
|
161 |
|
|
|
162 |
|
|
/* Scans sequence of BBs and set bb[].cnt */
|
163 |
|
|
void generate_bb_seq (cuc_func *f, char *mp_filename, char *bb_filename);
|
164 |
|
|
|
165 |
|
|
/* Prints out instructions */
|
166 |
|
|
void print_insns (cuc_insn *insn, int size, int verbose);
|
167 |
|
|
|
168 |
|
|
/* Print out basic blocks */
|
169 |
|
|
void print_cuc_bb (cuc_func *func, char *s);
|
170 |
|
|
|
171 |
|
|
/* Duplicates function */
|
172 |
|
|
cuc_func *dup_func (cuc_func *f);
|
173 |
|
|
|
174 |
|
|
/* Releases memory allocated by function */
|
175 |
|
|
void free_func (cuc_func *f);
|
176 |
|
|
|
177 |
|
|
/* Set the BB limits */
|
178 |
|
|
void detect_bb (cuc_func *func);
|
179 |
|
|
|
180 |
|
|
/* Optimize basic blocks */
|
181 |
|
|
void optimize_bb (cuc_func *func);
|
182 |
|
|
|
183 |
|
|
/* Removes BBs marked as dead */
|
184 |
|
|
void remove_dead_bb (cuc_func *func);
|
185 |
|
|
|
186 |
|
|
/* Detect register dependencies */
|
187 |
|
|
void reg_dep (cuc_func *func);
|
188 |
|
|
|
189 |
|
|
/* Cuts the tree and marks registers */
|
190 |
|
|
void mark_cut (cuc_func *f);
|
191 |
|
|
|
192 |
|
|
/* Unroll loop b times times and return new function. Original
|
193 |
|
|
function is unmodified. */
|
194 |
|
|
cuc_func *preunroll_loop (cuc_func *func, int b, int preroll, int unroll, char *bb_filename);
|
195 |
|
|
|
196 |
|
|
/* Schedule memory accesses
|
197 |
|
|
|
198 |
|
|
void schedule_memory (cuc_func *func, int otype);
|
199 |
|
|
|
200 |
|
|
/* Generates verilog file out of insn dataflow */
|
201 |
|
|
void output_verilog (cuc_func *func, char *filename);
|
202 |
|
|
|
203 |
|
|
/* Recalculates bb[].cnt values, based on generated profile file */
|
204 |
|
|
void recalc_cnts (cuc_func *f, char *bb_filename);
|
205 |
|
|
|
206 |
|
|
/* Calculate timings */
|
207 |
|
|
void analyse_timings (cuc_func *func, cuc_timings *timings);
|
208 |
|
|
|
209 |
|
|
#endif /* __DATAF_H__ */
|