mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-06 08:34:43 +01:00
Lowering of Branch / BranchIf / BranchWithArg / BlockArg. (#2904)
This gives us complete lowering of `if` expressions plus `and` and `or`. Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
This commit is contained in:
co-authored by
Jon Ross-Perkins
parent
c27f41c94b
commit
0d4d392d12
@@ -228,7 +228,8 @@ auto SemanticsHandleInfixOperator(SemanticsContext& context,
|
||||
context.AddNodeAndPush(
|
||||
parse_node,
|
||||
SemanticsNode::BlockArg::Make(
|
||||
parse_node, context.semantics_ir().GetNode(rhs_id).type_id()));
|
||||
parse_node, context.semantics_ir().GetNode(rhs_id).type_id(),
|
||||
resume_block_id));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -68,7 +68,8 @@ auto SemanticsHandleIfExpressionElse(SemanticsContext& context,
|
||||
|
||||
// Obtain the value in the resumption block and push it.
|
||||
context.AddNodeAndPush(
|
||||
if_node, SemanticsNode::BlockArg::Make(if_node, result_type_id));
|
||||
if_node,
|
||||
SemanticsNode::BlockArg::Make(if_node, result_type_id, resume_block_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,8 @@ class SemanticsNode {
|
||||
SemanticsStringId /*name_id*/,
|
||||
SemanticsNodeId /*node_id*/>;
|
||||
|
||||
using BlockArg = Factory<SemanticsNodeKind::BlockArg>;
|
||||
using BlockArg =
|
||||
Factory<SemanticsNodeKind::BlockArg, SemanticsNodeBlockId /*block_id*/>;
|
||||
|
||||
using BoolLiteral =
|
||||
Factory<SemanticsNodeKind::BoolLiteral, SemanticsBoolValue /*value*/>;
|
||||
@@ -450,6 +451,9 @@ struct SemanticsIdMapInfo {
|
||||
|
||||
// Support use of Id types as DenseMap/DenseSet keys.
|
||||
template <>
|
||||
struct llvm::DenseMapInfo<Carbon::SemanticsNodeBlockId>
|
||||
: public Carbon::SemanticsIdMapInfo<Carbon::SemanticsNodeBlockId> {};
|
||||
template <>
|
||||
struct llvm::DenseMapInfo<Carbon::SemanticsNodeId>
|
||||
: public Carbon::SemanticsIdMapInfo<Carbon::SemanticsNodeId> {};
|
||||
template <>
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: node+4, arg1: node+2, type: type1},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block7, arg1: node+9},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block7, arg1: node+10},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type1},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block7, type: type1},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+13, type: type1},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: node_blocks: [
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
// CHECK:STDOUT: {kind: Call, arg0: block0, arg1: function1, type: type0},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block7, arg1: node+10},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block7, arg1: node+11},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type0},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block7, type: type0},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+14, type: type0},
|
||||
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function3},
|
||||
// CHECK:STDOUT: {kind: BoolLiteral, arg0: false, type: type1},
|
||||
@@ -51,7 +51,7 @@
|
||||
// CHECK:STDOUT: {kind: Call, arg0: block0, arg1: function1, type: type0},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block11, arg1: node+20},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block11, arg1: node+21},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type0},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block11, type: type0},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+24, type: type0},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: node_blocks: [
|
||||
|
||||
@@ -41,7 +41,7 @@
|
||||
// CHECK:STDOUT: {kind: Call, arg0: block0, arg1: function1, type: type0},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block9, arg1: node+11},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block9, arg1: node+12},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type0},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block9, type: type0},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+15, type: type0},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: node_blocks: [
|
||||
|
||||
@@ -41,17 +41,17 @@
|
||||
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type1},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block9, arg1: node+11},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block9, arg1: node+12},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type1},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block9, type: type1},
|
||||
// CHECK:STDOUT: {kind: BranchIf, arg0: block11, arg1: node+4},
|
||||
// CHECK:STDOUT: {kind: Branch, arg0: block10},
|
||||
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int2, type: type1},
|
||||
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int3, type: type1},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block12, arg1: node+18},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block12, arg1: node+19},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type1},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block12, type: type1},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block13, arg1: node+15},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block13, arg1: node+22},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type1},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block13, type: type1},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+25, type: type1},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: node_blocks: [
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block5, arg1: node+8},
|
||||
// CHECK:STDOUT: {kind: Call, arg0: block0, arg1: function1, type: type0},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block5, arg1: node+11},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type0},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block5, type: type0},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+13, type: type0},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: node_blocks: [
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block5, arg1: node+9},
|
||||
// CHECK:STDOUT: {kind: Call, arg0: block0, arg1: function1, type: type0},
|
||||
// CHECK:STDOUT: {kind: BranchWithArg, arg0: block5, arg1: node+12},
|
||||
// CHECK:STDOUT: {kind: BlockArg, type: type0},
|
||||
// CHECK:STDOUT: {kind: BlockArg, arg0: block5, type: type0},
|
||||
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+14, type: type0},
|
||||
// CHECK:STDOUT: ]
|
||||
// CHECK:STDOUT: node_blocks: [
|
||||
|
||||
Reference in New Issue
Block a user