Pablo IR
Pablo IR consists of basic blocks, instructions, labels, variables and constants. Basic blocks are sequences of instructions, with a label identifying the entry point of the basic block. Instructions operate on integer values specified as fixed constants or the values of variables.
Values
- The values of PabloIR are integers of type
iN
for someN
. - All variables in PabloIR represent a value of type
iN
. - The value of
N
is fixed for any given program. - Positive and negative integer constants may be specified.
Variables
- The variables of PabloIR must match the regular expression
%[a-zA-Z_0-9]+
.
Constant and Variable Assignments
Pablo IR also allows the values of variables to be set using constants or other variables. Examples:
%r = 0
%s = %t
Bitwise Binary Operations
Pablo IR defines the following bitwise binary operations.
Op | Syntax | Meaning | LLVM Equivalent |
---|---|---|---|
add | %r = add %a, %b | \(r = a + b\,\) | %r = add iN %a, %b> |
and | %r = and %a, %b | \(r = a \wedge b\,\) (bitwise-and) | %r = and iN %a, %b |
or | %r = or %a, %b | \(r =a \vee b\,\) (bitwise-or) | %r = or iN %a, %b |
xor | %r = xor %a, %b | \(r = a \oplus b\,\) (bitwise-xor) | %r = xor iN %a, %b |
shl | %r = shl %a, %b | \(r = a \times 2^b\,\) (shift left) | %r = shl iN %a, %b |
Control Instructions
Pablo IR defines the following control instructions.
Syntax | Meaning | LLVM Equivalent |
---|---|---|
br %target | Unconditional transfer to the basic block labelled target: | br label %target |
cb %a, %nz, %zero | Branch to the basic block nz: or zero: depending on whether %a is nonzero | %t = icmp neq iN %a, 0 br i1 %t, label %nz, label %z |
ret | Terminates Pablo processing, returning control to the calling context. | ret void |
Phi Nodes
Phi nodes are special instruction nodes at the beginning of basic blocks that create a static single assignment to a variable depending on two possible incoming control transfers, with the following syntax.
%r = phi [%a, %block1], [%b, %block2]
Here, the variable %r
will hold the value of %a
if control was transferred from the basic block labelled %block1
or the value of %b
if control was transferred from the basic block labelled %block2
.
Basic Blocks
In Pablo IR, a basic block has the following syntax:
<basic-block> ::= <label> ":" {<phi-instruction>} {<binary-instruction>} {<control-instruction>}
Any phi
instructions must be first within the basic block,
and any control transfer functions must be last.
Newlines terminates each instruction.