xref: /illumos-gate/usr/src/tools/smatch/src/storage.h (revision 1f5207b7)
1*1f5207b7SJohn Levon #ifndef STORAGE_H
2*1f5207b7SJohn Levon #define STORAGE_H
3*1f5207b7SJohn Levon 
4*1f5207b7SJohn Levon #include "allocate.h"
5*1f5207b7SJohn Levon #include "lib.h"
6*1f5207b7SJohn Levon 
7*1f5207b7SJohn Levon /*
8*1f5207b7SJohn Levon  * The "storage" that underlies an incoming/outgoing pseudo. It's
9*1f5207b7SJohn Levon  * basically the backing store for a pseudo, and may be a real hardware
10*1f5207b7SJohn Levon  * register, a stack slot or a static symbol. Or nothing at all,
11*1f5207b7SJohn Levon  * since some pseudos can just be recalculated on the fly.
12*1f5207b7SJohn Levon  */
13*1f5207b7SJohn Levon enum storage_type {
14*1f5207b7SJohn Levon 	REG_UDEF,
15*1f5207b7SJohn Levon 	REG_REG,
16*1f5207b7SJohn Levon 	REG_STACK,
17*1f5207b7SJohn Levon 	REG_FRAME,
18*1f5207b7SJohn Levon 	REG_SYM,
19*1f5207b7SJohn Levon 	REG_ARG,
20*1f5207b7SJohn Levon 	REG_BAD,
21*1f5207b7SJohn Levon };
22*1f5207b7SJohn Levon 
23*1f5207b7SJohn Levon enum inout_enum {
24*1f5207b7SJohn Levon 	STOR_IN,
25*1f5207b7SJohn Levon 	STOR_OUT
26*1f5207b7SJohn Levon };
27*1f5207b7SJohn Levon 
28*1f5207b7SJohn Levon struct storage;
29*1f5207b7SJohn Levon DECLARE_PTR_LIST(storage_ptr_list, struct storage *);
30*1f5207b7SJohn Levon 
31*1f5207b7SJohn Levon struct storage {
32*1f5207b7SJohn Levon 	enum storage_type type;
33*1f5207b7SJohn Levon 	int name;
34*1f5207b7SJohn Levon 	struct storage_ptr_list *users;
35*1f5207b7SJohn Levon 	union {
36*1f5207b7SJohn Levon 		int regno;
37*1f5207b7SJohn Levon 		int offset;
38*1f5207b7SJohn Levon 		struct symbol *sym;
39*1f5207b7SJohn Levon 	};
40*1f5207b7SJohn Levon };
41*1f5207b7SJohn Levon 
42*1f5207b7SJohn Levon DECLARE_PTR_LIST(storage_list, struct storage);
43*1f5207b7SJohn Levon 
44*1f5207b7SJohn Levon struct storage_hash {
45*1f5207b7SJohn Levon 	struct basic_block *bb;
46*1f5207b7SJohn Levon 	pseudo_t pseudo;
47*1f5207b7SJohn Levon 	enum inout_enum inout;
48*1f5207b7SJohn Levon 	struct storage *storage;
49*1f5207b7SJohn Levon 	unsigned long flags;
50*1f5207b7SJohn Levon };
51*1f5207b7SJohn Levon 
52*1f5207b7SJohn Levon DECLARE_PTR_LIST(storage_hash_list, struct storage_hash);
53*1f5207b7SJohn Levon 
54*1f5207b7SJohn Levon extern struct storage_hash_list *gather_storage(struct basic_block *, enum inout_enum);
55*1f5207b7SJohn Levon extern void free_storage(void);
56*1f5207b7SJohn Levon extern const char *show_storage(struct storage *);
57*1f5207b7SJohn Levon extern void set_up_storage(struct entrypoint *);
58*1f5207b7SJohn Levon struct storage *lookup_storage(struct basic_block *, pseudo_t, enum inout_enum);
59*1f5207b7SJohn Levon void add_storage(struct storage *, struct basic_block *, pseudo_t, enum inout_enum);
60*1f5207b7SJohn Levon 
61*1f5207b7SJohn Levon DECLARE_ALLOCATOR(storage);
62*1f5207b7SJohn Levon DECLARE_ALLOCATOR(storage_hash);
63*1f5207b7SJohn Levon 
alloc_storage(void)64*1f5207b7SJohn Levon static inline struct storage *alloc_storage(void)
65*1f5207b7SJohn Levon {
66*1f5207b7SJohn Levon 	return __alloc_storage(0);
67*1f5207b7SJohn Levon }
68*1f5207b7SJohn Levon 
alloc_storage_hash(struct storage * s)69*1f5207b7SJohn Levon static inline struct storage_hash *alloc_storage_hash(struct storage *s)
70*1f5207b7SJohn Levon {
71*1f5207b7SJohn Levon 	struct storage_hash *entry = __alloc_storage_hash(0);
72*1f5207b7SJohn Levon 	struct storage **usep = &entry->storage;
73*1f5207b7SJohn Levon 
74*1f5207b7SJohn Levon 	*usep = s;
75*1f5207b7SJohn Levon 	add_ptr_list(&s->users, usep);
76*1f5207b7SJohn Levon 	return entry;
77*1f5207b7SJohn Levon }
78*1f5207b7SJohn Levon 
79*1f5207b7SJohn Levon #endif /* STORAGE_H */
80