ACT Library
Loading...
Searching...
No Matches
statepass.h
Go to the documentation of this file.
1/*************************************************************************
2 *
3 * This file is part of the ACT library
4 *
5 * Copyright (c) 2020 Rajit Manohar
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 **************************************************************************
23 */
24#ifndef __ACT_PASS_STATE_H__
25#define __ACT_PASS_STATE_H__
26
27#include <map>
28#include <act/act.h>
29#include <act/iter.h>
30#include <act/passes/booleanize.h>
31#include <common/hash.h>
32#include <common/array.h>
33
34
35/*
36 * State information: assumed that ports are allocated in the parent
37 * process, so no booleans associated with ports are included in the
38 * local/all bools count.
39 */
40
42 int bools; // HSE/PRS bools
43
44 int xbools; // extra bools for chp, if any
45 int chans;
46 int ints;
47
48public:
49 void addInt (int v = 1) { ints += v; }
50 int numInts () { return ints; }
51
52 void addBool (int v = 1) { bools += v; }
53 int numBools () { return bools; }
54
55 void addChan (int v = 1) { chans += v; }
56 int numChans() { return chans; }
57
58 void addCHPBool (int v = 1) { xbools += v; }
59 int numCHPBools () { return xbools; }
60 int numAllBools() { return bools + xbools; }
61
62 int numCHPVars() { return xbools + ints + chans; }
63 int numAllVars() { return bools + xbools + ints + chans; }
64
65 void addVar (state_counts &s, int sz = 1) {
66 bools += sz*s.bools;
67 xbools += sz*s.xbools;
68 chans += sz*s.chans;
69 ints += sz*s.ints;
70 }
71
72 state_counts() { bools = 0; xbools = 0; chans = 0; ints = 0; }
73};
74
75typedef struct {
76 act_boolean_netlist_t *bnl; // the basis for this calculation
77
78 /*
79 * Usage of state for:
80 * 1. Just the used ports
81 * 2. Just the local state (not including sub-processes)
82 * 3. Local state plus sub-process state
83 */
84 state_counts ports, local, all;
85
86 /*--
87 Boolean variables are numbered
88 0 ... nportbools-1 ... (nportbools + localbools - 1)
89 --*/
90
91 bitset_t *multi; // bitset of local bools that are
92 // locally multi-driver. The size of
93 // this bitset is # of local.bools + #
94 // of port.bools. 0..ports.bools-1 are
95 // the ports, and the rest are
96 // numbered as per local.bool numbering
97 // with nportbools as the offset.
98
99 int ismulti; // 1 if this process contributes to a
100 // multi-driver scenario
101
102 struct pHashtable *map; // map from connection pointer to
103 // unique integer from 0 .. localbools-1
104 // for local booleans.
105 // For port bools, negative numbers
106 // numbered from -nportbools to -1.
107 //
108 // Similar for port integers, and port
109 // channels.
110 // for chp extra booleans, the port
111 // numbers are more negative, and the
112 // local state is more positive.
113
114 /* The port numbering is pos - total #ports.
115
116 But using the offset methods below reverses the port
117 numbering. This is so that the functions don't need to know the
118 number of ports.
119
120 It is this reversed numbering that is used in all the tools when
121 converting negative idx to their actual location in an array.
122 */
123
124
125 int chp_ismulti; // multidriver through CHP
126
127 struct pHashtable *inst; // used for instance offsets
128
130
131class ActStatePass : public ActPass {
132public:
133 ActStatePass (Act *a, int inst_offset = 0);
135
136 int run (Process *p = NULL);
137
138 void Print (FILE *fp, Process *p = NULL);
139
142
143 /* type: 0 = bool, 1 = int, 2 = chan-in, 3 = chan-not-in */
144
145 /* return 0 on error, 1 on success */
147 int *offset, int *type, int *width);
148
150 int *offset_i, int *offset_b);
151
153
155 int *offset, int *type, int *width) {
156 return getTypeOffset (getStateInfo (p), c, offset, type, width);
157 }
158
159 act_connection *getConnFromOffset (stateinfo_t *si, int offset, int type,
160 int *dy);
161 act_connection *getConnFromOffset (Process *p, int offset, int type, int *dy) {
162 return getConnFromOffset (getStateInfo (p), offset, type, dy);
163 }
164
166
168
169 int isGlobalOffset (int off) {
170 if (off >= 0) { return 0; }
171 off = -off;
172 if (off & 1) { return 0; }
173 return 1;
174 }
175
176 int isPortOffset (int off) {
177 if (off >= 0) { return 0; }
178 off = -off;
179 if (off & 1) { return 1; }
180 return 0;
181 }
182
183 int portIdx (int off) {
184 Assert (isPortOffset (off), "What?");
185 off = -off;
186 return (off + 1)/2 - 1;
187 }
188
189 int globalIdx (int off) {
190 Assert (isGlobalOffset (off), "What?");
191 off = -off;
192 return off/2 - 1;
193 }
194
195 int instOffsets () { return _inst_offsets; }
196
197 int checkIdExists (ActId *id); /*< checks if the full ID path is
198 valid */
200
201 static void getStructCount (Data *d, state_counts *sc);
202
203private:
204 void *local_op (Process *p, int mode = 0);
205 void free_local (void *);
206
208 void printLocal (FILE *fp, Process *p);
211
212 stateinfo_t *_root_si; // top-level state info
214
216 FILE *_fp;
217};
218
219
220
221
222
223#endif /* __ACT_PASS_STATE_H__ */
This pass is used to pre-process information about languages and variables within the design....
Definition: booleanize.h:271
act_boolean_netlist_t * getBNL(Process *p)
The main Act class used to read in an ACT file and create basic data structures. All design informati...
Definition: act.h:334
This class is used to store Act identifiers that correspond to instances. Identifiers have an optiona...
Definition: act_id.h:56
The main ActPass class used to implement an ACT analysis/synthesis pass. All the core tools use this ...
Definition: act.h:791
Act * a
Definition: act.h:810
Definition: statepass.h:131
state_counts _globals
Definition: statepass.h:213
void printLocal(FILE *fp, Process *p)
int checkIdExists(ActId *id)
int _inst_offsets
Definition: statepass.h:210
act_boolean_netlist_t * getBNL(Process *p)
Definition: statepass.h:141
int instOffsets()
Definition: statepass.h:195
int _black_box_mode
Definition: statepass.h:209
int portIdx(int off)
Definition: statepass.h:183
ActBooleanizePass * bp
Definition: statepass.h:215
void * local_op(Process *p, int mode=0)
stateinfo_t * rootStateInfo()
Definition: statepass.h:167
act_connection * getConnFromOffset(stateinfo_t *si, int offset, int type, int *dy)
bool connExists(stateinfo_t *si, act_connection *c)
FILE * _fp
Definition: statepass.h:216
state_counts getGlobals()
Definition: statepass.h:165
int getTypeDynamicStructOffset(stateinfo_t *si, act_connection *c, int *offset_i, int *offset_b)
stateinfo_t * _root_si
Definition: statepass.h:212
int isPortOffset(int off)
Definition: statepass.h:176
int getTypeOffset(stateinfo_t *si, act_connection *c, int *offset, int *type, int *width)
void Print(FILE *fp, Process *p=NULL)
stateinfo_t * getStateInfo(Process *p)
void free_local(void *)
ActStatePass(Act *a, int inst_offset=0)
int isGlobalOffset(int off)
Definition: statepass.h:169
int run(Process *p=NULL)
stateinfo_t * countLocalState(Process *p)
static void getStructCount(Data *d, state_counts *sc)
int globalIdx(int off)
Definition: statepass.h:189
int globalBoolOffset(ActId *id)
int getTypeOffset(Process *p, act_connection *c, int *offset, int *type, int *width)
Definition: statepass.h:154
act_connection * getConnFromOffset(Process *p, int offset, int type, int *dy)
Definition: statepass.h:161
A user-defined data types.
Definition: types.h:1062
User-defined processes.
Definition: types.h:750
Connections.
Definition: value.h:113
Definition: statepass.h:41
int chans
Definition: statepass.h:45
void addBool(int v=1)
Definition: statepass.h:52
state_counts()
Definition: statepass.h:72
int numCHPVars()
Definition: statepass.h:62
void addInt(int v=1)
Definition: statepass.h:49
void addVar(state_counts &s, int sz=1)
Definition: statepass.h:65
int bools
Definition: statepass.h:42
int numBools()
Definition: statepass.h:53
void addCHPBool(int v=1)
Definition: statepass.h:58
int numAllBools()
Definition: statepass.h:60
int numInts()
Definition: statepass.h:50
int numCHPBools()
Definition: statepass.h:59
int ints
Definition: statepass.h:46
void addChan(int v=1)
Definition: statepass.h:55
int numChans()
Definition: statepass.h:56
int xbools
Definition: statepass.h:44
int numAllVars()
Definition: statepass.h:63
This contains the implementation of a number of C++ iterators to make it easier to walk through an AC...
This structure is computed for each process by the Booleanize pass. It summarizes the information abo...
Definition: booleanize.h:187
Definition: statepass.h:75
int ismulti
Definition: statepass.h:99
state_counts all
Definition: statepass.h:84
struct pHashtable * map
Definition: statepass.h:102
bitset_t * multi
Definition: statepass.h:91
int chp_ismulti
Definition: statepass.h:125
struct pHashtable * inst
Definition: statepass.h:127
act_boolean_netlist_t * bnl
Definition: statepass.h:76