Files
carbon-lang/toolchain/lower/handle_expression_category.cpp
T
Jon Ross-Perkins ec307b18d8 Rename the lowering dir to lower (#3172)
This is continuing with #3070, starting dir renaming with lowering
because it's at the tip. AFAICT git is catching all the file moves.
2023-08-31 15:59:49 +00:00

48 lines
1.9 KiB
C++

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "toolchain/lower/function_context.h"
namespace Carbon::Lower {
auto HandleBindValue(FunctionContext& context, SemIR::NodeId node_id,
SemIR::Node node) -> void {
switch (auto rep = SemIR::GetValueRepresentation(context.semantics_ir(),
node.type_id());
rep.kind) {
case SemIR::ValueRepresentation::None:
// Nothing should use this value, but StubReference needs a value to
// propagate.
context.SetLocal(node_id,
llvm::PoisonValue::get(context.GetType(node.type_id())));
break;
case SemIR::ValueRepresentation::Copy:
context.SetLocal(node_id, context.builder().CreateLoad(
context.GetType(node.type_id()),
context.GetLocal(node.GetAsBindValue())));
break;
case SemIR::ValueRepresentation::Pointer:
context.SetLocal(node_id, context.GetLocal(node.GetAsBindValue()));
break;
case SemIR::ValueRepresentation::Custom:
CARBON_FATAL() << "TODO: Add support for BindValue with custom value rep";
}
}
auto HandleTemporary(FunctionContext& context, SemIR::NodeId node_id,
SemIR::Node node) -> void {
auto [temporary_id, init_id] = node.GetAsTemporary();
context.FinishInitialization(node.type_id(), temporary_id, init_id);
context.SetLocal(node_id, context.GetLocal(temporary_id));
}
auto HandleTemporaryStorage(FunctionContext& context, SemIR::NodeId node_id,
SemIR::Node node) -> void {
context.SetLocal(
node_id, context.builder().CreateAlloca(context.GetType(node.type_id()),
nullptr, "temp"));
}
} // namespace Carbon::Lower