Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 132 lines (99 sloc) 3.293 kb
ca6b0f8 Add generic method inlining support! -Xjit.inline.generic
Evan Phoenix authored
1 #ifndef RBX_INSTRUCTIONS_UTIL_HPP
2 #define RBX_INSTRUCTIONS_UTIL_HPP
3
a352624 Start of new LLVM JIT
Evan Phoenix authored
4 #define SPECIFIC (static_cast<SubClass*>(this))
5
6 namespace rubinius {
7 template <class SubClass>
8 class VisitInstructions {
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
9 protected:
10 opcode* stream_;
11 int size_;
12 int next_ip_;
13
a352624 Start of new LLVM JIT
Evan Phoenix authored
14 public:
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
15
16 void set_stream(opcode* stream, int size) {
17 stream_ = stream;
18 size_ = size;
19 }
20
21 void set_stream(VMMethod* vmm) {
22 set_stream(vmm->opcodes, vmm->total);
23 }
24
a352624 Start of new LLVM JIT
Evan Phoenix authored
25 void visit(opcode code, opcode arg1, opcode arg2) { }
26
27 #define HANDLE_INST0(code, name) \
28 void visit_ ## name() { SPECIFIC->visit(code, -1, -1); }
29
30 #define HANDLE_INST1(code, name) \
31 void visit_ ## name(opcode arg1) { SPECIFIC->visit(code, arg1, -1); }
32
33 #define HANDLE_INST2(code, name) \
34 void visit_ ## name(opcode arg1, opcode arg2) { SPECIFIC->visit(code, arg1, arg2); }
35
2de92ea @brixen Standardize names of generated instruction files.
brixen authored
36 #include "vm/gen/instruction_visitors.hpp"
a352624 Start of new LLVM JIT
Evan Phoenix authored
37
38 #undef HANDLE_INST0
39 #undef HANDLE_INST1
40 #undef HANDLE_INST2
41
6a660c1 Add flow control instructions and a bunch more
Evan Phoenix authored
42 void at_ip(int ip) { }
d860556 Fix JIT by only driving generation of live instructions
Evan Phoenix authored
43 bool before(opcode op, opcode arg1 = 0, opcode arg2 = 0) { return true; }
6a660c1 Add flow control instructions and a bunch more
Evan Phoenix authored
44
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
45 int dispatch(int ip) {
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
46 SPECIFIC->at_ip(ip);
6a660c1 Add flow control instructions and a bunch more
Evan Phoenix authored
47
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
48 switch(stream_[ip]) {
a352624 Start of new LLVM JIT
Evan Phoenix authored
49 #define HANDLE_INST0(code, name) \
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
50 case code: \
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
51 next_ip_ = ip + 1; \
52 if(SPECIFIC->before(stream_[ip])) { \
53 SPECIFIC->visit_ ## name(); } return next_ip_;
a352624 Start of new LLVM JIT
Evan Phoenix authored
54
55 #define HANDLE_INST1(code, name) \
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
56 case code: \
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
57 next_ip_ = ip + 2; \
58 if(SPECIFIC->before(stream_[ip], stream_[ip + 1])) { \
59 SPECIFIC->visit_ ## name(stream_[ip + 1]); } return next_ip_;
a352624 Start of new LLVM JIT
Evan Phoenix authored
60
61 #define HANDLE_INST2(code, name) \
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
62 case code: \
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
63 next_ip_ = ip + 3; \
64 if(SPECIFIC->before(stream_[ip], stream_[ip + 1], stream_[ip + 2])) { \
65 SPECIFIC->visit_ ## name(stream_[ip + 1], stream_[ip + 2]); } return next_ip_;
a352624 Start of new LLVM JIT
Evan Phoenix authored
66
2de92ea @brixen Standardize names of generated instruction files.
brixen authored
67 #include "vm/gen/instruction_visitors.hpp"
a352624 Start of new LLVM JIT
Evan Phoenix authored
68
69 #undef HANDLE_INST0
70 #undef HANDLE_INST1
71 #undef HANDLE_INST2
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
72
73 default:
b3cf5f2 @evanphx Convert abort()s into bug()s
evanphx authored
74 rubinius::bug("Unknown instruction used");
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
75 return -1;
76 }
77 }
78
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
79 opcode next_op() {
80 if(next_ip_ >= size_) return 0;
81 return stream_[next_ip_];
82 }
83
84 opcode next_op_operand(size_t which) {
85 if(next_ip_ >= size_) return 0;
86 return stream_[next_ip_ + 1 + which];
87 }
88
89 static int opcode_size(opcode op) {
90 #undef HANDLE_INST0
91 #undef HANDLE_INST1
92 #undef HANDLE_INST2
93
94 switch(op) {
95 #define HANDLE_INST0(code, name) case code: return 1;
96 #define HANDLE_INST1(code, name) case code: return 2;
97 #define HANDLE_INST2(code, name) case code: return 3;
98
99 #include "vm/gen/instruction_visitors.hpp"
100
101 #undef HANDLE_INST0
102 #undef HANDLE_INST1
103 #undef HANDLE_INST2
104 }
105
106 return -1;
107 }
108
109 void skip_next_op() {
110 if(next_ip_ >= size_) return;
111 opcode op = stream_[next_ip_];
112
113 next_ip_ += opcode_size(op);
114 }
115
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
116 void drive(opcode* stream, int size, int start = 0) {
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
117 set_stream(stream, size);
118
d6b53ad Fix JIT codegen bug. Fixes #80.
Evan Phoenix authored
119 int ip = start;
120 while(ip < size) {
d65ad57 Inline policy work and block inlining optimizations
Evan Phoenix authored
121 ip = dispatch(ip);
a352624 Start of new LLVM JIT
Evan Phoenix authored
122 }
123 }
6a660c1 Add flow control instructions and a bunch more
Evan Phoenix authored
124
125 void drive(VMMethod* vmm) {
126 drive(vmm->opcodes, vmm->total);
127 }
a352624 Start of new LLVM JIT
Evan Phoenix authored
128 };
129 }
130
ca6b0f8 Add generic method inlining support! -Xjit.inline.generic
Evan Phoenix authored
131 #endif
Something went wrong with that request. Please try again.