This repository was archived by the owner on Apr 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCudaCFGFactory.cpp
More file actions
75 lines (68 loc) · 2.47 KB
/
CudaCFGFactory.cpp
File metadata and controls
75 lines (68 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "CudaCFGFactory.hpp"
#include "CudaFunction.hpp"
#include <iostream>
namespace Dyninst {
namespace ParseAPI {
Function *CudaCFGFactory::mkfunc(Address addr, FuncSource src,
std::string name, CodeObject * obj, CodeRegion * region,
Dyninst::InstructionSource * isrc) {
// find function by name
for (auto *function : _functions) {
if (function->name == name) {
CudaFunction *ret_func = new CudaFunction(addr, name, obj, region, isrc);
bool first_entry = true;
for (auto *block : function->blocks) {
CudaBlock *ret_block = NULL;
if (_block_filter.find(block->id) == _block_filter.end()) {
std::vector<Offset> inst_offsets;
for (auto *inst : block->insts) {
inst_offsets.push_back(inst->offset);
}
ret_block = new CudaBlock(obj, region, block->insts[0]->offset, inst_offsets);
_block_filter[block->id] = ret_block;
blocks_.add(*ret_block);
ret_func->add_block(ret_block);
} else {
ret_block = _block_filter[block->id];
}
if (first_entry) {
ret_func->setEntry(ret_block);
first_entry = false;
}
for (auto *target : block->targets) {
CudaBlock *ret_target_block = NULL;
if (_block_filter.find(target->block->id) == _block_filter.end()) {
std::vector<Offset> inst_offsets;
for (auto *inst : target->block->insts) {
inst_offsets.push_back(inst->offset);
}
ret_target_block = new CudaBlock(obj, region, target->block->insts[0]->offset, inst_offsets);
_block_filter[target->block->id] = ret_target_block;
blocks_.add(*ret_target_block);
ret_func->add_block(ret_target_block);
} else {
ret_target_block = _block_filter[target->block->id];
}
Edge *ret_edge = NULL;
if (target->type == CudaParse::CALL) {
ret_edge = new Edge(ret_block, ret_target_block, CALL);
} else if (target->type = CudaParse::FALLTHROUGH) {
ret_edge = new Edge(ret_block, ret_target_block, FALLTHROUGH);
} else { // TODO(Keren): Add more edge types
ret_edge = new Edge(ret_block, ret_target_block, DIRECT);
}
ret_edge->install();
edges_.add(*ret_edge);
}
}
return ret_func;
}
}
return NULL;
// iterate blocks
// add blocks
// iterate targets
// add edges
}
}
}