2024-08-14 09:41:43 +02:00
|
|
|
\begin{algorithmic}
|
|
|
|
\Function{staticdeps}{basic\_block}
|
|
|
|
\State{} deps $\gets{} \emptyset{}$
|
|
|
|
\State{} insn\_count, cur\_iter, cur\_instruction $\gets{} 0$
|
|
|
|
\State{} shadow\_memory, shadow\_registers, last\_wrote\_at $\gets{} \emptyset_\text{map}$
|
|
|
|
|
|
|
|
\medskip{}
|
|
|
|
|
|
|
|
\Function{fresh}{}
|
|
|
|
\State{} \textbf{return} random uint64\_t value
|
|
|
|
\EndFunction{}
|
|
|
|
|
|
|
|
\smallskip{}
|
|
|
|
|
|
|
|
\Function{read\_memory}{address}
|
2024-09-01 16:05:21 +02:00
|
|
|
\State{} \textbf{Assert} address \neq{} $\bot$
|
2024-08-14 09:41:43 +02:00
|
|
|
\If{address \not\in{} shadow\_memory}
|
|
|
|
\State{} shadow\_memory[address] $\gets$ \Call{fresh}{}
|
|
|
|
\EndIf{}
|
|
|
|
\State{} \Return{} shadow\_memory[address]
|
|
|
|
\EndFunction{}
|
|
|
|
|
|
|
|
\Function{read\_register}{register}
|
2024-09-01 16:05:21 +02:00
|
|
|
\State{} \ldots \Comment{Likewise, without dependency tracking}
|
2024-08-14 09:41:43 +02:00
|
|
|
\EndFunction{}
|
|
|
|
|
|
|
|
\smallskip{}
|
|
|
|
|
|
|
|
\Function{expr\_value}{expr}
|
|
|
|
\If{expr == Register(reg)}
|
|
|
|
\State{} \Return{} \Call{read\_register}{reg}
|
|
|
|
\ElsIf{expr == Memory(addr\_expr)}
|
|
|
|
\State{} addr $\gets{}$ \Call{expr\_value}{expr}
|
|
|
|
\If{addr \in{} last\_wrote\_at}
|
|
|
|
\State{} deps $\gets{}$ deps \cup{} (last\_wrote\_at[addr] \to{} (cur\_iter, cur\_instruction))
|
|
|
|
\EndIf{}
|
|
|
|
\State{} \Return{} \Call{read\_memory}{addr}
|
|
|
|
\ElsIf{expr == IntegerArithmeticOp(operator, op1, …, opN)}
|
2024-09-01 16:05:21 +02:00
|
|
|
\If{\Call{expr\_value}{op\_i} == $\bot$ for any i}
|
|
|
|
\State{} \Return{} $\bot$
|
2024-08-14 09:41:43 +02:00
|
|
|
\EndIf{}
|
2024-09-01 16:05:21 +02:00
|
|
|
\State\Return{} semantics(operator)(\Comment{Provided by Valgrind's Vex}
|
2024-08-14 09:41:43 +02:00
|
|
|
\State{} \quad \Call{expr\_value}{op1}, …, \Call{expr\_value}{opN})
|
|
|
|
\Else{}
|
2024-09-01 16:05:21 +02:00
|
|
|
\Return{} $\bot$
|
2024-08-14 09:41:43 +02:00
|
|
|
\EndIf{}
|
|
|
|
\EndFunction{}
|
|
|
|
|
|
|
|
\Function{iter\_statement}{statement}
|
|
|
|
\State{} lhs, rhs \gets{} statement
|
|
|
|
\If{lhs == Register(reg)}
|
|
|
|
\State{} shadow\_register[reg] \gets{} \Call{expr\_value}{rhs}
|
|
|
|
\ElsIf{lhs == Memory(addr\_expr)}
|
|
|
|
\State{} addr \gets{} \Call{expr\_value}{addr\_expr}
|
2024-09-01 16:05:21 +02:00
|
|
|
\State{} last\_wrote\_at[addr] \gets{} (cur\_iter, cur\_instruction)
|
|
|
|
\State{} shadow\_memory[addr] \gets{} \Call{expr\_value}{rhs}
|
2024-08-14 09:41:43 +02:00
|
|
|
\ElsIf{\ldots}
|
|
|
|
\Comment{Etc.}
|
|
|
|
\EndIf{}
|
|
|
|
\EndFunction{}
|
|
|
|
|
|
|
|
\medskip{}
|
|
|
|
|
|
|
|
\While{insn\_count <= |ROB| + |basic\_block|}
|
|
|
|
\State{} cur\_instruction \gets{} 0
|
|
|
|
\For{statement \in{} basic\_block}
|
|
|
|
\State{} \Call{iter\_statement}{statement}
|
|
|
|
\If{statement is last statement of an instruction}
|
|
|
|
\State{} \Comment{An instruction can be composed of multiple statements}
|
|
|
|
\State{} cur\_instruction \gets{} cur\_instruction + 1
|
|
|
|
\EndIf{}
|
|
|
|
\EndFor{}
|
|
|
|
\State{} cur\_iter \gets{} cur\_iter + 1
|
|
|
|
\EndWhile{}
|
|
|
|
\State{} \Return{} deps
|
|
|
|
\EndFunction{}
|
|
|
|
\end{algorithmic}
|