docc 0.8.3 (0d44999b)
C++ API Reference
Loading...
Searching...
No Matches
lifting.h
Go to the documentation of this file.
1#pragma once
2
3#include <llvm/Analysis/TargetLibraryInfo.h>
4#include <llvm/IR/BasicBlock.h>
5#include <llvm/IR/Function.h>
6#include <llvm/IR/Instructions.h>
7
9
11#include "docc/lifting/utils.h"
12#include "docc/utils.h"
13
14namespace docc {
15namespace lifting {
16
20class Lifting {
21private:
22 llvm::TargetLibraryInfo& TLI_;
23 llvm::Function& function_;
24 const llvm::DataLayout& DL_;
25
26 sdfg::FunctionType target_type_;
28
29 std::map<const llvm::BasicBlock*, std::set<const sdfg::control_flow::State*>> state_mapping_;
30 std::map<const sdfg::control_flow::State*, std::set<const llvm::BasicBlock*>> pred_mapping_;
31
32 std::unordered_map<const llvm::Value*, std::string> constants_mapping_;
33 std::unordered_map<const llvm::Type*, std::string> anonymous_types_mapping_;
34
35 static void collect_globals(llvm::Function& function, llvm::Value* V, std::unordered_set<llvm::GlobalObject*>& visited);
36
37 void visit_globals();
38
39 void visit_arguments();
40
41 void visit_cfg();
42
43 void visit_block(const llvm::BasicBlock* block, sdfg::control_flow::State& state);
44
45 sdfg::control_flow::State& visit_instruction(
46 const llvm::BasicBlock* block, const llvm::Instruction* instruction, sdfg::control_flow::State& current_state
47 );
48
49 sdfg::control_flow::State& visit_AllocaInst(
50 const llvm::BasicBlock* block, const llvm::AllocaInst* instruction, sdfg::control_flow::State& current_state
51 );
52
53 sdfg::control_flow::State& visit_GetElementPtrInst(
54 const llvm::BasicBlock* block,
55 const llvm::GetElementPtrInst* instruction,
56 sdfg::control_flow::State& current_state
57 );
58
59 sdfg::control_flow::State& visit_LoadInst(
60 const llvm::BasicBlock* block, const llvm::LoadInst* instruction, sdfg::control_flow::State& current_state
61 );
62
63 sdfg::control_flow::State& visit_StoreInst(
64 const llvm::BasicBlock* block, const llvm::StoreInst* instruction, sdfg::control_flow::State& current_state
65 );
66
67 sdfg::control_flow::State& visit_PHINode(
68 const llvm::BasicBlock* block, const llvm::PHINode* instruction, sdfg::control_flow::State& current_state
69 );
70
71 sdfg::control_flow::State& visit_ICmpInst(
72 const llvm::BasicBlock* block, const llvm::ICmpInst* instruction, sdfg::control_flow::State& current_state
73 );
74
75 sdfg::control_flow::State& visit_ICmpInst_symbolic(
76 const llvm::BasicBlock* block, const llvm::ICmpInst* instruction, sdfg::control_flow::State& current_state
77 );
78
79 sdfg::control_flow::State& visit_ICmpInst_dataflow(
80 const llvm::BasicBlock* block, const llvm::ICmpInst* instruction, sdfg::control_flow::State& current_state
81 );
82
83 sdfg::control_flow::State& visit_FCmpInst(
84 const llvm::BasicBlock* block, const llvm::FCmpInst* instruction, sdfg::control_flow::State& current_state
85 );
86
87 sdfg::control_flow::State& visit_UnaryOperator(
88 const llvm::BasicBlock* block, const llvm::UnaryOperator* instruction, sdfg::control_flow::State& current_state
89 );
90
91 sdfg::control_flow::State& visit_BinaryOperator(
92 const llvm::BasicBlock* block, const llvm::BinaryOperator* instruction, sdfg::control_flow::State& current_state
93 );
94
95 sdfg::control_flow::State& visit_CastInst(
96 const llvm::BasicBlock* block, const llvm::CastInst* instruction, sdfg::control_flow::State& current_state
97 );
98
99 sdfg::control_flow::State& visit_ReturnInst(
100 const llvm::BasicBlock* block, const llvm::ReturnInst* instruction, sdfg::control_flow::State& current_state
101 );
102
103 sdfg::control_flow::State& visit_SelectInst(
104 const llvm::BasicBlock* block, const llvm::SelectInst* instruction, sdfg::control_flow::State& current_state
105 );
106
107 sdfg::control_flow::State& visit_UnreachableInst(
108 const llvm::BasicBlock* block,
109 const llvm::UnreachableInst* instruction,
110 sdfg::control_flow::State& current_state
111 );
112
113public:
115 llvm::TargetLibraryInfo& TLI,
116 llvm::Function& function,
117 sdfg::FunctionType target_type,
118 const std::string& sdfg_name
119 )
120 : TLI_(TLI), function_(function), DL_(function.getParent()->getDataLayout()), target_type_(target_type),
121 builder_(sdfg_name, target_type) {
122 if (this->function_.isVarArg()) {
123 throw NotImplementedException(
124 "FunctionLifting: Vararg functions are not supported",
125 docc::utils::get_debug_info(function),
126 function.getName().str()
127 );
128 }
129
130 auto return_type = lifting::utils::get_type(
131 this->builder_,
132 this->anonymous_types_mapping_,
133 this->DL_,
134 this->function_.getReturnType(),
135 lifting::utils::get_storage_type(this->target_type_, 0)
136 );
137 this->builder_.set_return_type(*return_type);
138 };
139
140 Lifting(llvm::TargetLibraryInfo& TLI, llvm::Function& function, sdfg::FunctionType target_type)
141 : Lifting(TLI, function, target_type, function.getName().str()) {
142
143 };
144
145 std::unique_ptr<sdfg::SDFG> run();
146
147 static void collect_globals(llvm::Function& function, std::unordered_set<llvm::GlobalObject*>& globals);
148};
149
150} // namespace lifting
151} // namespace docc
std::unique_ptr< sdfg::SDFG > run()
Lifting(llvm::TargetLibraryInfo &TLI, llvm::Function &function, sdfg::FunctionType target_type, const std::string &sdfg_name)
Definition lifting.h:114
Lifting(llvm::TargetLibraryInfo &TLI, llvm::Function &function, sdfg::FunctionType target_type)
Definition lifting.h:140
static void collect_globals(llvm::Function &function, std::unordered_set< llvm::GlobalObject * > &globals)
Definition sdfg_builder.h:13
A state in a Stateful DataFlow Graph (SDFG).
Definition state.h:38
std::unique_ptr< sdfg::types::IType > get_type(sdfg::builder::SDFGBuilder &builder, std::unordered_map< const llvm::Type *, std::string > &anonymous_types_mapping, const llvm::DataLayout &DL, llvm::Type *type, sdfg::types::StorageType storage_type, const std::string &initializer="")
sdfg::types::StorageType get_storage_type(sdfg::FunctionType target_type, size_t address_space)
Definition exceptions.h:9
Definition targets.h:8
StringEnum FunctionType
Definition function.h:37