2015-08-01 01:53:38 +08:00
|
|
|
//===- WebAssemblyInstrControl.td-WebAssembly control-flow ------*- tablegen -*-
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief WebAssembly control-flow code-gen constructs.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2015-11-26 03:36:19 +08:00
|
|
|
let Defs = [ARGUMENTS] in {
|
|
|
|
|
2015-09-17 00:51:30 +08:00
|
|
|
let isBranch = 1, isTerminator = 1, hasCtrlDep = 1 in {
|
2015-12-05 11:03:35 +08:00
|
|
|
// The condition operand is a boolean value which WebAssembly represents as i32.
|
2016-02-09 05:50:13 +08:00
|
|
|
def BR_IF : I<(outs), (ins bb_op:$dst, I32:$cond),
|
2015-12-05 11:03:35 +08:00
|
|
|
[(brcond I32:$cond, bb:$dst)],
|
2016-10-25 04:21:49 +08:00
|
|
|
"br_if \t$dst, $cond", 0x0d>;
|
2015-12-05 11:03:35 +08:00
|
|
|
let isCodeGenOnly = 1 in
|
2016-10-06 05:24:08 +08:00
|
|
|
def BR_UNLESS : I<(outs), (ins bb_op:$dst, I32:$cond), []>;
|
2015-09-17 00:51:30 +08:00
|
|
|
let isBarrier = 1 in {
|
|
|
|
def BR : I<(outs), (ins bb_op:$dst),
|
2015-11-06 04:42:30 +08:00
|
|
|
[(br bb:$dst)],
|
2016-10-25 04:21:49 +08:00
|
|
|
"br \t$dst", 0x0c>;
|
2015-09-17 00:51:30 +08:00
|
|
|
} // isBarrier = 1
|
|
|
|
} // isBranch = 1, isTerminator = 1, hasCtrlDep = 1
|
|
|
|
|
2015-12-05 11:03:35 +08:00
|
|
|
} // Defs = [ARGUMENTS]
|
|
|
|
|
|
|
|
def : Pat<(brcond (i32 (setne I32:$cond, 0)), bb:$dst),
|
2016-02-09 05:50:13 +08:00
|
|
|
(BR_IF bb_op:$dst, I32:$cond)>;
|
2015-12-05 11:03:35 +08:00
|
|
|
def : Pat<(brcond (i32 (seteq I32:$cond, 0)), bb:$dst),
|
2016-02-09 05:50:13 +08:00
|
|
|
(BR_UNLESS bb_op:$dst, I32:$cond)>;
|
2015-12-05 11:03:35 +08:00
|
|
|
|
|
|
|
let Defs = [ARGUMENTS] in {
|
|
|
|
|
2015-09-17 00:51:30 +08:00
|
|
|
// TODO: SelectionDAG's lowering insists on using a pointer as the index for
|
2016-03-08 11:18:12 +08:00
|
|
|
// jump tables, so in practice we don't ever use BR_TABLE_I64 in wasm32 mode
|
2015-09-17 00:51:30 +08:00
|
|
|
// currently.
|
2016-01-12 09:45:12 +08:00
|
|
|
// Set TSFlags{0} to 1 to indicate that the variable_ops are immediates.
|
2016-01-13 04:30:51 +08:00
|
|
|
// Set TSFlags{1} to 1 to indicate that the immediates represent labels.
|
2015-09-17 00:51:30 +08:00
|
|
|
let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
|
2016-03-08 11:18:12 +08:00
|
|
|
def BR_TABLE_I32 : I<(outs), (ins I32:$index, variable_ops),
|
|
|
|
[(WebAssemblybr_table I32:$index)],
|
2016-10-25 04:21:49 +08:00
|
|
|
"br_table \t$index", 0x0e> {
|
2016-01-12 09:45:12 +08:00
|
|
|
let TSFlags{0} = 1;
|
2016-01-13 04:30:51 +08:00
|
|
|
let TSFlags{1} = 1;
|
2016-01-12 09:45:12 +08:00
|
|
|
}
|
2016-03-08 11:18:12 +08:00
|
|
|
def BR_TABLE_I64 : I<(outs), (ins I64:$index, variable_ops),
|
|
|
|
[(WebAssemblybr_table I64:$index)],
|
|
|
|
"br_table \t$index"> {
|
2016-01-12 09:45:12 +08:00
|
|
|
let TSFlags{0} = 1;
|
2016-01-13 04:30:51 +08:00
|
|
|
let TSFlags{1} = 1;
|
2016-01-12 09:45:12 +08:00
|
|
|
}
|
2015-09-17 00:51:30 +08:00
|
|
|
} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
|
|
|
|
|
[WebAssembly] Make CFG stackification independent of basic-block labels.
This patch changes the way labels are referenced. Instead of referencing the
basic-block label name (eg. .LBB0_0), instructions now just have an immediate
which indicates the depth in the control-flow stack to find a label to jump to.
This makes them much closer to what we expect to have in the binary encoding,
and avoids the problem of basic-block label names not being explicit in the
binary encoding.
Also, it terminates blocks and loops with end_block and end_loop instructions,
rather than basic-block label names, for similar reasons.
This will also fix problems where two constructs appear to have the same label,
because we no longer explicitly use labels, so consumers that need labels will
presumably create their own labels, and presumably they won't reuse labels
when they do.
This patch does make the code a little more awkward to read; as a partial
mitigation, this patch also introduces comments showing where the labels are,
and comments on each branch showing where it's branching to.
llvm-svn: 257505
2016-01-13 03:14:46 +08:00
|
|
|
// Placemarkers to indicate the start or end of a block or loop scope. These
|
2016-10-04 06:43:53 +08:00
|
|
|
// use/clobber VALUE_STACK to prevent them from being moved into the middle of
|
2015-12-25 08:31:02 +08:00
|
|
|
// an expression tree.
|
2016-10-04 06:43:53 +08:00
|
|
|
let Uses = [VALUE_STACK], Defs = [VALUE_STACK] in {
|
2016-10-25 04:21:49 +08:00
|
|
|
def BLOCK : I<(outs), (ins Signature:$sig), [], "block \t$sig", 0x02>;
|
|
|
|
def LOOP : I<(outs), (ins Signature:$sig), [], "loop \t$sig", 0x03>;
|
2016-10-25 04:32:04 +08:00
|
|
|
|
|
|
|
// END_BLOCK and END_LOOP are represented with the same opcode in wasm.
|
2016-10-25 07:27:49 +08:00
|
|
|
def END_BLOCK : I<(outs), (ins), [], "end_block", 0x0b>;
|
|
|
|
def END_LOOP : I<(outs), (ins), [], "end_loop", 0x0b>;
|
2016-10-04 06:43:53 +08:00
|
|
|
} // Uses = [VALUE_STACK], Defs = [VALUE_STACK]
|
2015-09-17 00:51:30 +08:00
|
|
|
|
2015-08-01 12:48:44 +08:00
|
|
|
multiclass RETURN<WebAssemblyRegClass vt> {
|
2015-11-06 04:42:30 +08:00
|
|
|
def RETURN_#vt : I<(outs), (ins vt:$val), [(WebAssemblyreturn vt:$val)],
|
2016-10-25 07:27:49 +08:00
|
|
|
"return \t$val", 0x0f>;
|
2016-05-21 08:21:56 +08:00
|
|
|
// Equivalent to RETURN_#vt, for use at the end of a function when wasm
|
|
|
|
// semantics return by falling off the end of the block.
|
|
|
|
let isCodeGenOnly = 1 in
|
|
|
|
def FALLTHROUGH_RETURN_#vt : I<(outs), (ins vt:$val), []>;
|
2015-08-01 12:48:44 +08:00
|
|
|
}
|
2015-11-10 08:30:57 +08:00
|
|
|
|
2016-08-03 07:16:09 +08:00
|
|
|
multiclass SIMD_RETURN<ValueType vt> {
|
|
|
|
def RETURN_#vt : SIMD_I<(outs), (ins V128:$val),
|
|
|
|
[(WebAssemblyreturn (vt V128:$val))],
|
2016-10-25 07:27:49 +08:00
|
|
|
"return \t$val", 0x0f>;
|
2016-08-03 07:16:09 +08:00
|
|
|
// Equivalent to RETURN_#vt, for use at the end of a function when wasm
|
|
|
|
// semantics return by falling off the end of the block.
|
|
|
|
let isCodeGenOnly = 1 in
|
|
|
|
def FALLTHROUGH_RETURN_#vt : SIMD_I<(outs), (ins V128:$val), []>;
|
|
|
|
}
|
|
|
|
|
2015-11-10 08:30:57 +08:00
|
|
|
let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
|
2016-10-04 05:33:09 +08:00
|
|
|
|
2015-11-10 08:30:57 +08:00
|
|
|
let isReturn = 1 in {
|
2015-09-26 09:09:44 +08:00
|
|
|
defm : RETURN<I32>;
|
|
|
|
defm : RETURN<I64>;
|
|
|
|
defm : RETURN<F32>;
|
|
|
|
defm : RETURN<F64>;
|
2016-08-03 07:16:09 +08:00
|
|
|
defm : SIMD_RETURN<v16i8>;
|
|
|
|
defm : SIMD_RETURN<v8i16>;
|
|
|
|
defm : SIMD_RETURN<v4i32>;
|
|
|
|
defm : SIMD_RETURN<v4f32>;
|
|
|
|
|
2016-10-25 07:27:49 +08:00
|
|
|
def RETURN_VOID : I<(outs), (ins), [(WebAssemblyreturn)], "return", 0x0f>;
|
2016-05-21 08:21:56 +08:00
|
|
|
|
|
|
|
// This is to RETURN_VOID what FALLTHROUGH_RETURN_#vt is to RETURN_#vt.
|
|
|
|
let isCodeGenOnly = 1 in
|
|
|
|
def FALLTHROUGH_RETURN_VOID : I<(outs), (ins), []>;
|
2015-11-10 08:30:57 +08:00
|
|
|
} // isReturn = 1
|
2016-10-04 05:33:09 +08:00
|
|
|
|
2016-10-25 07:27:49 +08:00
|
|
|
def UNREACHABLE : I<(outs), (ins), [(trap)], "unreachable", 0x00>;
|
2016-10-04 05:33:09 +08:00
|
|
|
|
2015-11-10 08:30:57 +08:00
|
|
|
} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
|
2015-11-26 03:36:19 +08:00
|
|
|
|
|
|
|
} // Defs = [ARGUMENTS]
|