Jlm
LlvmConversionContext.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_LLVM_FRONTEND_LLVMCONVERSIONCONTEXT_HPP
7 #define JLM_LLVM_FRONTEND_LLVMCONVERSIONCONTEXT_HPP
8 
11 #include <jlm/llvm/ir/tac.hpp>
13 
14 #include <llvm/IR/DerivedTypes.h>
15 
16 #include <unordered_map>
17 
18 namespace llvm
19 {
20 class BasicBlock;
21 class Function;
22 class Value;
23 }
24 
25 namespace jlm::llvm
26 {
27 
28 class ControlFlowGraph;
29 class ControlFlowGraphNode;
30 class InterProceduralGraphModule;
31 class Variable;
32 
34 
35 class Context final
36 {
37 public:
39  : module_(im),
40  node_(nullptr),
41  iostate_(nullptr),
42  memory_state_(nullptr)
43  {}
44 
45  const llvm::Variable *
46  result() const noexcept
47  {
48  return result_;
49  }
50 
51  inline void
53  {
54  result_ = result;
55  }
56 
58  iostate() const noexcept
59  {
60  return iostate_;
61  }
62 
63  void
65  {
66  iostate_ = state;
67  }
68 
69  inline llvm::Variable *
70  memory_state() const noexcept
71  {
72  return memory_state_;
73  }
74 
75  inline void
77  {
78  memory_state_ = state;
79  }
80 
81  inline bool
82  has(const ::llvm::BasicBlock * bb) const noexcept
83  {
84  return bbmap_.HasKey(bb);
85  }
86 
87  inline bool
88  has(BasicBlock * bb) const noexcept
89  {
90  return bbmap_.HasValue(bb);
91  }
92 
93  inline BasicBlock *
94  get(const ::llvm::BasicBlock * bb) const noexcept
95  {
96  return bbmap_.LookupKey(bb);
97  }
98 
99  inline const ::llvm::BasicBlock *
100  get(BasicBlock * bb) const noexcept
101  {
102  return bbmap_.LookupValue(bb);
103  }
104 
105  inline void
107  {
108  bbmap_ = std::move(bbmap);
109  }
110 
111  inline bool
112  has_value(const ::llvm::Value * value) const noexcept
113  {
114  return vmap_.find(value) != vmap_.end();
115  }
116 
117  inline const llvm::Variable *
118  lookup_value(const ::llvm::Value * value) const noexcept
119  {
120  JLM_ASSERT(has_value(value));
121  return vmap_.find(value)->second;
122  }
123 
124  inline void
125  insert_value(const ::llvm::Value * value, const llvm::Variable * variable)
126  {
127  JLM_ASSERT(!has_value(value));
128  vmap_[value] = variable;
129  }
130 
131  [[nodiscard]] InterProceduralGraphModule &
132  module() const noexcept
133  {
134  return module_;
135  }
136 
137  inline void
139  {
140  node_ = node;
141  }
142 
143  inline InterProceduralGraphNode *
144  node() const noexcept
145  {
146  return node_;
147  }
148 
149  TypeConverter &
150  GetTypeConverter() noexcept
151  {
152  return TypeConverter_;
153  }
154 
155 private:
162  std::unordered_map<const ::llvm::Value *, const llvm::Variable *> vmap_;
164 };
165 
166 }
167 
168 #endif
const ::llvm::BasicBlock * get(BasicBlock *bb) const noexcept
Context(InterProceduralGraphModule &im)
const llvm::Variable * lookup_value(const ::llvm::Value *value) const noexcept
llvm::Variable * memory_state() const noexcept
const llvm::Variable * result() const noexcept
bool has_value(const ::llvm::Value *value) const noexcept
llvm::Variable * iostate() const noexcept
const llvm::Variable * result_
void set_memory_state(llvm::Variable *state)
InterProceduralGraphModule & module() const noexcept
void set_iostate(llvm::Variable *state)
void set_result(const llvm::Variable *result)
void set_basic_block_map(BasicBlockMap bbmap)
BasicBlock * get(const ::llvm::BasicBlock *bb) const noexcept
InterProceduralGraphNode * node() const noexcept
void set_node(InterProceduralGraphNode *node) noexcept
llvm::Variable * memory_state_
bool has(BasicBlock *bb) const noexcept
std::unordered_map< const ::llvm::Value *, const llvm::Variable * > vmap_
void insert_value(const ::llvm::Value *value, const llvm::Variable *variable)
TypeConverter & GetTypeConverter() noexcept
bool has(const ::llvm::BasicBlock *bb) const noexcept
InterProceduralGraphNode * node_
InterProceduralGraphModule & module_
const V & LookupKey(const K &key) const
const K & LookupValue(const V &value) const
bool HasKey(const K &key) const noexcept
bool HasValue(const V &value) const noexcept
#define JLM_ASSERT(x)
Definition: common.hpp:16
Global memory state passed between functions.
@ Value
Designate a value type.