@@ -10,6 +10,27 @@ ExecutionTrace::ExecutionTrace() : currentBlockIndex(0), currentOperationIndex(0
10
10
createBlock ();
11
11
}
12
12
13
+ Block& ExecutionTrace::getBlock (uint16_t blockIndex) {
14
+ return blocks[blockIndex];
15
+ }
16
+
17
+ uint16_t ExecutionTrace::getCurrentBlockIndex () const {
18
+ return currentBlockIndex;
19
+ }
20
+
21
+ Block& ExecutionTrace::getCurrentBlock () {
22
+ return blocks[currentBlockIndex];
23
+ }
24
+
25
+ void ExecutionTrace::setCurrentBlock (uint16_t index) {
26
+ currentOperationIndex = 0 ;
27
+ currentBlockIndex = index;
28
+ }
29
+
30
+ std::vector<Block>& ExecutionTrace::getBlocks () {
31
+ return blocks;
32
+ }
33
+
13
34
bool ExecutionTrace::checkTag (Snapshot& snapshot) {
14
35
// check if operation is in global map -> we have a repeating operation ->
15
36
// this is a control-flow merge
@@ -20,11 +41,10 @@ bool ExecutionTrace::checkTag(Snapshot& snapshot) {
20
41
return false ;
21
42
}
22
43
44
+ // check if we visited the same operation in this execution -> loop
23
45
auto localTagIter = localTagMap.find (snapshot);
24
46
if (localTagIter != localTagMap.end ()) {
25
- // TODO #3500 Fix handling of repeated operations
26
47
auto & ref = localTagIter->second ;
27
- // add loop iteration to tag
28
48
processControlFlowMerge (ref);
29
49
return false ;
30
50
}
@@ -41,7 +61,6 @@ void ExecutionTrace::addReturn(Snapshot& snapshot, Type type, value_ref ref) {
41
61
auto operationIdentifier = getNextOperationIdentifier ();
42
62
addTag (snapshot, operationIdentifier);
43
63
44
- // returnRefs
45
64
returnRefs.emplace_back (operationIdentifier);
46
65
}
47
66
@@ -88,11 +107,8 @@ void ExecutionTrace::addCmpOperation(Snapshot& snapshot, value_ref inputs) {
88
107
getBlock (trueBlock).predecessors .emplace_back (getCurrentBlockIndex ());
89
108
auto falseBlock = createBlock ();
90
109
getBlock (falseBlock).predecessors .emplace_back (getCurrentBlockIndex ());
91
-
92
- auto operationInputs = std::vector<InputVariant> {inputs, BlockRef (trueBlock), BlockRef (falseBlock)};
93
-
94
110
auto & operations = blocks[currentBlockIndex].operations ;
95
- operations.emplace_back (snapshot, CMP, Type::v, value_ref (getNextValueRef (), Type::v), std::forward<std:: vector<InputVariant>>(operationInputs) );
111
+ operations.emplace_back (snapshot, CMP, Type::v, value_ref (getNextValueRef (), Type::v), std::vector<InputVariant> {inputs, BlockRef (trueBlock), BlockRef (falseBlock)} );
96
112
auto operationIdentifier = getNextOperationIdentifier ();
97
113
addTag (snapshot, operationIdentifier);
98
114
}
@@ -107,25 +123,18 @@ void ExecutionTrace::nextOperation() {
107
123
}
108
124
109
125
TraceOperation& ExecutionTrace::getCurrentOperation () {
110
- auto currentOp = getCurrentBlock ().operations [currentOperationIndex];
126
+ auto & currentOp = getCurrentBlock ().operations [currentOperationIndex];
111
127
while (currentOp.op == JMP) {
112
128
auto & nextBlock = std::get<BlockRef>(currentOp.input [0 ]);
113
129
setCurrentBlock (nextBlock.block );
114
130
currentOp = getCurrentBlock ().operations [currentOperationIndex];
115
131
}
116
- return getCurrentBlock (). operations [currentOperationIndex] ;
132
+ return currentOp ;
117
133
}
118
134
119
135
uint16_t ExecutionTrace::createBlock () {
120
- // add first block
121
- if (blocks.empty ()) {
122
- // add arguments to first block
123
- blocks.emplace_back (blocks.size ());
124
- // blocks[0].arguments = arguments;
125
- return blocks.size () - 1 ;
126
- }
127
- blocks.emplace_back (blocks.size ());
128
- return blocks.size () - 1 ;
136
+ auto & block = blocks.emplace_back (blocks.size ());
137
+ return block.blockId ;
129
138
}
130
139
131
140
Block& ExecutionTrace::processControlFlowMerge (operation_identifier oi) {
@@ -168,10 +177,10 @@ Block& ExecutionTrace::processControlFlowMerge(operation_identifier oi) {
168
177
169
178
// add jump from referenced block to merge block
170
179
auto mergeBlockRef = BlockRef (mergedBlockId);
171
- referenceBlock.addOperation ({Op::JMP, std::vector<InputVariant> {mergeBlockRef}});
180
+ referenceBlock.addOperation ({Op::JMP, {mergeBlockRef}});
172
181
173
182
// add jump from current block to merge block
174
- currentBlock.addOperation ({Op::JMP, std::vector<InputVariant> {mergeBlockRef}});
183
+ currentBlock.addOperation ({Op::JMP, {mergeBlockRef}});
175
184
176
185
mergeBlock.predecessors .emplace_back (oi.blockIndex );
177
186
mergeBlock.predecessors .emplace_back (currentBlockIndex);
@@ -203,17 +212,12 @@ value_ref ExecutionTrace::setArgument(Type type, size_t index) {
203
212
return arguments[index];
204
213
}
205
214
206
- void ExecutionTrace::destruct (nautilus::tracing::value_ref) {
207
- // variableBitset[inputs] = false;
208
- }
209
-
210
215
std::vector<operation_identifier> ExecutionTrace::getReturn () {
211
216
return returnRefs;
212
217
}
213
218
214
219
uint16_t ExecutionTrace::getNextValueRef () {
215
- auto ref = ++lastValueRef;
216
- return ref;
220
+ return ++lastValueRef;
217
221
}
218
222
219
223
operation_identifier ExecutionTrace::getNextOperationIdentifier () {
@@ -222,7 +226,6 @@ operation_identifier ExecutionTrace::getNextOperationIdentifier() {
222
226
}
223
227
224
228
void ExecutionTrace::resetExecution () {
225
- // variableBitset.reset();
226
229
currentBlockIndex = 0 ;
227
230
currentOperationIndex = 0 ;
228
231
globalTagMap.merge (localTagMap);
0 commit comments