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:
Richard Smith
2023-06-15 17:53:07 -07:00
committed by GitHub
co-authored by Jon Ross-Perkins
parent c27f41c94b
commit 0d4d392d12
44 changed files with 453 additions and 91 deletions
+13 -5
View File
@@ -103,16 +103,24 @@ auto LoweringContext::BuildFunctionDefinition(SemanticsFunctionId function_id)
function_lowering.SetLocal(param_storage, llvm_function->getArg(i));
}
CARBON_VLOG() << "Lowering " << function.body_id << "\n";
for (const auto& node_id : semantics_ir().GetNodeBlock(function.body_id)) {
auto node = semantics_ir().GetNode(node_id);
CARBON_VLOG() << "Lowering " << node_id << ": " << node << "\n";
switch (node.kind()) {
// Add the entry block to the worklist.
function_lowering.GetBlock(function.body_id);
while (!function_lowering.block_worklist().empty()) {
SemanticsNodeBlockId block = function_lowering.block_worklist().Pop();
CARBON_VLOG() << "Lowering " << block << "\n";
function_lowering.builder().SetInsertPoint(
function_lowering.GetBlock(block));
for (const auto& node_id : semantics_ir().GetNodeBlock(block)) {
auto node = semantics_ir().GetNode(node_id);
CARBON_VLOG() << "Lowering " << node_id << ": " << node << "\n";
switch (node.kind()) {
#define CARBON_SEMANTICS_NODE_KIND(Name) \
case SemanticsNodeKind::Name: \
LoweringHandle##Name(function_lowering, node_id, node); \
break;
#include "toolchain/semantics/semantics_node_kind.def"
}
}
}
}