Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
77 lines (63 loc) · 2.66 KB
/
Copy pathmain.cpp
File metadata and controls
77 lines (63 loc) · 2.66 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
76
77
#include <iostream>
#include <tuple>
#include <vector>
#include "evolutionary.hpp"
#include "flagsgenerator.hpp"
#include "plotting.hpp"
void genOptimizationsLists(std::string file_name) {
std::string o1 = "opt --passes='default<O1>' --print-pipeline-passes bc/";
o1 += file_name + ".bc > o1/" + file_name + ".txt";
system(o1.c_str());
std::string o2 = "opt --passes='default<O2>' --print-pipeline-passes bc/";
o2 += file_name + ".bc > o2/" + file_name + ".txt";
system(o2.c_str());
std::string o3 = "opt --passes='default<O3>' --print-pipeline-passes bc/";
o3 += file_name + ".bc > o3/" + file_name + ".txt";
system(o3.c_str());
}
void genBC(std::string file_name) {
std::string cmd =
"clang -O0 -emit-llvm -c "
"-I/usr/include/apr-1.0 "
"-L/usr/lib/x86_64-linux-gnu "
"input/" + file_name + ".c "
"-o bc/" + file_name + ".bc "
"-lapr-1";
system(cmd.c_str());
}
int main() {
std::vector<std::tuple<std::vector<Item>, double>> list_results;
// std::string file_name = "t57";
std::string file_name = "0002";
int exec_times = 1;
try {
genBC(file_name);
genOptimizationsLists(file_name);
std::cout << "Rodando instancia 1:" << std::endl;
load_flags();
std::tuple<std::vector<Item>, double> result = runEvolutionaryProgramming("bc/" + file_name);
std::tuple<std::vector<Item>, double> best_result = result;
double count_time = std::get<1>(result);
for(int i = 0; i < exec_times - 1; i++) {
std::cout << "Rodando instancia " << i << ":" << std::endl;
result = runEvolutionaryProgramming("bc/" + file_name);
list_results.push_back(result);
count_time += std::get<1>(result);
if(std::get<1>(result) < std::get<1>(best_result))
best_result = result;
}
auto [o1, o2, o3] = testOptimizations("bc/" + file_name);
std::cout << "Resultados:" << std::endl;
std::cout << "-O1: " << o1 << " segundos" << std::endl;
std::cout << "-O2: " << o2 << " segundos" << std::endl;
std::cout << "-O3: " << o3 << " segundos" << std::endl;
std::cout << "\nMédia: " << count_time/exec_times << " segundos" << std::endl;
std::cout << "\nMelhor: " << std::get<1>(best_result) << " segundos" << std::endl;
std::cout << "Flags: " << itemsToFlagString(std::get<0>(best_result)) << std::endl;
plotting(o1, o2, o3, count_time/exec_times, std::get<1>(best_result), file_name);
} catch (const std::exception& e) {
std::cerr << "Erro fatal: " << e.what() << std::endl;
return 1;
}
return 0;
}