llir-opt  0.0.1
Low-Level Post-Link Optimiser for OCaml and C
nodes.h
1 // This file if part of the llir-opt project.
2 // Licensing information can be found in the LICENSE file.
3 // (C) 2018 Nandor Licker. All rights reserved.
4 
5 #pragma once
6 
7 #include <set>
8 
9 #include "core/adt/bitset.h"
10 #include "core/analysis/reference_graph.h"
11 #include "core/dag.h"
12 #include "core/ref.h"
13 #include "core/type.h"
14 
15 class Object;
16 class Inst;
17 class MemoryStoreInst;
18 
19 
20 
22 using ObjectOffsetMap = std::unordered_map<ID<Object>, OffsetSet>;
23 
25 struct ObjectClosure {
30 };
31 
33 struct FuncClosure {
35  std::unique_ptr<DAGFunc> DAG;
45  bool Raises;
47  bool Indirect;
48 };
49 
51 struct NodeState {
59  std::unordered_map
60  < ID<Object>
61  , std::map<uint64_t, std::pair<Type, Ref<Inst>>>
62  > Stores;
63 
64  void Merge(const NodeState &that);
65 
66  void Overwrite(ID<Object> changed)
67  {
68  BitSet<Object> imprecise;
69  imprecise.Insert(changed);
70  return Overwrite(imprecise);
71  }
72 
73  void Overwrite(const BitSet<Object> &changed);
74 
75  void dump(llvm::raw_ostream &os);
76 };
77 
78 
85  llvm::DenseSet<ReverseNodeState *> Succs;
86 
88  std::unordered_map
89  < ID<Object>
90  , std::map<uint64_t, std::pair<MemoryStoreInst *, uint64_t>>
91  > Stores;
94 
97 
99 
101  void Merge(const ReverseNodeState &that);
102 
104  void Store(ID<Object> id);
105  void Store(
106  ID<Object> id,
107  uint64_t start,
108  uint64_t end,
109  MemoryStoreInst *store = nullptr
110  );
111  void Store(const BitSet<Object> &changed);
112 
114  void Load(ID<Object> id);
115  void Load(ID<Object> id, uint64_t start, uint64_t end);
116  void Load(const BitSet<Object> &loaded);
117 
119  void dump(llvm::raw_ostream &os);
120 };
Inst
Definition: inst.h:53
FuncClosure::Indirect
bool Indirect
Flag to indicate whether any function has indirect calls.
Definition: nodes.h:47
ReverseNodeState::Loaded
BitSet< Object > Loaded
Set of inaccurate loads.
Definition: nodes.h:96
ReverseNodeState::dump
void dump(llvm::raw_ostream &os)
Print information about the node to a stream.
Definition: nodes.cpp:247
NodeState::Funcs
BitSet< Func > Funcs
IDs of referenced functions.
Definition: nodes.h:53
FuncClosure::Funcs
BitSet< Func > Funcs
Set of referenced functions.
Definition: nodes.h:37
ReverseNodeState::Node
DAGBlock & Node
Originating nodes.
Definition: nodes.h:83
ReverseNodeState::Store
void Store(ID< Object > id)
Definition: nodes.cpp:172
FuncClosure::Stored
BitSet< Object > Stored
Set of changed objects.
Definition: nodes.h:41
ObjectClosure::Funcs
BitSet< Func > Funcs
Set of referenced functions.
Definition: nodes.h:27
ReverseNodeState::Succs
llvm::DenseSet< ReverseNodeState * > Succs
Predecessor of the node.
Definition: nodes.h:85
ReverseNodeState::Stores
std::unordered_map< ID< Object >, std::map< uint64_t, std::pair< MemoryStoreInst *, uint64_t > > > Stores
Set of stores which can be forwarded here.
Definition: nodes.h:91
FuncClosure::Loaded
BitSet< Object > Loaded
Set of dereferenced objects.
Definition: nodes.h:43
ID
Definition: id.h:19
ReverseNodeState::Load
void Load(ID< Object > id)
Definition: nodes.cpp:216
Object
Definition: object.h:43
FuncClosure
Transitive closure of a function.
Definition: nodes.h:33
NodeState::Stores
std::unordered_map< ID< Object >, std::map< uint64_t, std::pair< Type, Ref< Inst > > > > Stores
Accurate stores.
Definition: nodes.h:62
FuncClosure::Escaped
BitSet< Object > Escaped
Set of escaped objects.
Definition: nodes.h:39
BitSet< Func >
ReverseNodeState::Merge
void Merge(const ReverseNodeState &that)
LUB operator of two nodes.
Definition: nodes.cpp:103
FuncClosure::DAG
std::unique_ptr< DAGFunc > DAG
DAG-based representation of the function.
Definition: nodes.h:35
ObjectClosure
Transitive closure of an object.
Definition: nodes.h:25
BitSet::Insert
bool Insert(const ID< T > &item)
Inserts an item into the bitset.
Definition: bitset.h:391
DAGBlock
Definition: dag.h:20
NodeState::Stored
BitSet< Object > Stored
Set of objects changed to unknown values.
Definition: nodes.h:57
ReverseNodeState
Definition: nodes.h:81
FuncClosure::Raises
bool Raises
Flag to indicate whether any function raises.
Definition: nodes.h:45
ReverseNodeState::Stored
BitSet< Object > Stored
Imprecise, tainted locations.
Definition: nodes.h:93
ObjectClosure::Objects
BitSet< Object > Objects
Set of referenced objects.
Definition: nodes.h:29
NodeState
Evaluation state of a node.
Definition: nodes.h:51
NodeState::Escaped
BitSet< Object > Escaped
ID of tainted objects.
Definition: nodes.h:55