forked from sampsyo/llvm-pass-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
67 lines (59 loc) · 2.11 KB
/
run.py
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
import os
import subprocess
program = lambda num_runs, threshold: f'''
#include <vector>
#include "llvm/Analysis/InlineCost.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/Transforms/Utils/Cloning.h"
using namespace llvm;
namespace {{
const int INLINE_THRESHOLD = {threshold};
const int NUM_RUNS = {num_runs};
struct FunctionInliningPass : public FunctionPass {{
static char ID;
FunctionInliningPass() : FunctionPass(ID) {{}}
virtual bool runOnFunction(Function &F) {{
bool modified = false;
for (int i = 0; i < NUM_RUNS; ++i) {{
std::vector<Instruction *> worklist;
for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {{
worklist.push_back(&*I);
}}
for (Instruction *I : worklist) {{
CallInst *call = dyn_cast<CallInst>(I);
if (call != nullptr) {{
Function *fun = call->getCalledFunction();
if (fun != nullptr && isInlineViable(*fun) &&
fun->getInstructionCount() <= INLINE_THRESHOLD) {{
InlineFunctionInfo info;
InlineFunction(call, info);
modified = true;
}}
}}
}}
}}
return modified;
}}
}};
}} // namespace
char FunctionInliningPass::ID = 0;
// Register the pass so `opt -function-inlining` runs it.
static RegisterPass<FunctionInliningPass> X("function-inlining",
"a useful pass");
'''
if __name__ == '__main__':
for threshold in (10, 100, 1000):
for num_runs in (1, 2, 3):
prog = program(num_runs, threshold)
with open('function-inlining/FunctionInlining.cpp', 'w') as f:
f.write(prog)
result = subprocess.run(['./build.sh'])
assert result.returncode == 0, "benis"
result = subprocess.run(['python3', 'benchmark.py', f'out-{num_runs}-{threshold}.csv'])
assert result.returncode == 0, "big ol begnis"