mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add loads for data. (#2860)
Start inserting loads when getting a value. This is done conditionally, but in theory we could start tracking nodes which need loading differently if the `isa` is considered cumbersome.
This commit is contained in:
@@ -46,10 +46,10 @@ auto LoweringContext::Run() -> std::unique_ptr<llvm::Module> {
|
||||
}
|
||||
|
||||
auto LoweringContext::LowerBlock(SemanticsNodeBlockId block_id) -> void {
|
||||
CARBON_VLOG() << "Lowering block " << block_id << "\n";
|
||||
CARBON_VLOG() << "Lowering " << block_id << "\n";
|
||||
for (const auto& node_id : semantics_ir_->GetNodeBlock(block_id)) {
|
||||
auto node = semantics_ir_->GetNode(node_id);
|
||||
CARBON_VLOG() << "Lowering node" << node_id << ": " << node << "\n";
|
||||
CARBON_VLOG() << "Lowering " << node_id << ": " << node << "\n";
|
||||
switch (node.kind()) {
|
||||
#define CARBON_SEMANTICS_NODE_KIND(Name) \
|
||||
case SemanticsNodeKind::Name: \
|
||||
@@ -102,4 +102,15 @@ auto LoweringContext::BuildType(SemanticsNodeId node_id) -> llvm::Type* {
|
||||
}
|
||||
}
|
||||
|
||||
auto LoweringContext::GetNodeLoaded(SemanticsNodeId node_id) -> llvm::Value* {
|
||||
auto* value = GetNode(node_id);
|
||||
if (llvm::isa<llvm::AllocaInst, llvm::GetElementPtrInst>(value)) {
|
||||
auto* load_type = GetType(semantics_ir().GetNode(node_id).type_id());
|
||||
return builder().CreateLoad(load_type, value);
|
||||
} else {
|
||||
// No load is needed.
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
|
||||
Reference in New Issue
Block a user