handle.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #include "llvm/ADT/STLExtras.h"
  5. #include "llvm/ADT/Sequence.h"
  6. #include "toolchain/lower/function_context.h"
  7. #include "toolchain/sem_ir/node.h"
  8. #include "toolchain/sem_ir/node_kind.h"
  9. namespace Carbon::Lower {
  10. auto HandleCrossReference(FunctionContext& /*context*/,
  11. SemIR::NodeId /*node_id*/, SemIR::CrossReference node)
  12. -> void {
  13. CARBON_FATAL() << "TODO: Add support: " << node;
  14. }
  15. auto HandleAddressOf(FunctionContext& context, SemIR::NodeId node_id,
  16. SemIR::AddressOf node) -> void {
  17. context.SetLocal(node_id, context.GetLocal(node.lvalue_id));
  18. }
  19. auto HandleArrayIndex(FunctionContext& context, SemIR::NodeId node_id,
  20. SemIR::ArrayIndex node) -> void {
  21. auto* array_value = context.GetLocal(node.array_id);
  22. auto* llvm_type =
  23. context.GetType(context.semantics_ir().GetNode(node.array_id).type_id());
  24. llvm::Value* indexes[2] = {
  25. llvm::ConstantInt::get(llvm::Type::getInt32Ty(context.llvm_context()), 0),
  26. context.GetLocal(node.index_id)};
  27. context.SetLocal(node_id,
  28. context.builder().CreateInBoundsGEP(llvm_type, array_value,
  29. indexes, "array.index"));
  30. }
  31. auto HandleArrayInit(FunctionContext& context, SemIR::NodeId node_id,
  32. SemIR::ArrayInit node) -> void {
  33. // The result of initialization is the return slot of the initializer.
  34. context.SetLocal(
  35. node_id, context.GetLocal(context.semantics_ir()
  36. .GetNodeBlock(node.inits_and_return_slot_id)
  37. .back()));
  38. }
  39. auto HandleAssign(FunctionContext& context, SemIR::NodeId /*node_id*/,
  40. SemIR::Assign node) -> void {
  41. auto storage_type_id = context.semantics_ir().GetNode(node.lhs_id).type_id();
  42. context.FinishInitialization(storage_type_id, node.lhs_id, node.rhs_id);
  43. }
  44. auto HandleBinaryOperatorAdd(FunctionContext& /*context*/,
  45. SemIR::NodeId /*node_id*/,
  46. SemIR::BinaryOperatorAdd node) -> void {
  47. CARBON_FATAL() << "TODO: Add support: " << node;
  48. }
  49. auto HandleBindName(FunctionContext& context, SemIR::NodeId node_id,
  50. SemIR::BindName node) -> void {
  51. context.SetLocal(node_id, context.GetLocal(node.value_id));
  52. }
  53. auto HandleBlockArg(FunctionContext& context, SemIR::NodeId node_id,
  54. SemIR::BlockArg node) -> void {
  55. context.SetLocal(node_id, context.GetBlockArg(node.block_id, node.type_id));
  56. }
  57. auto HandleBoolLiteral(FunctionContext& context, SemIR::NodeId node_id,
  58. SemIR::BoolLiteral node) -> void {
  59. llvm::Value* v =
  60. llvm::ConstantInt::get(context.builder().getInt1Ty(), node.value.index);
  61. context.SetLocal(node_id, v);
  62. }
  63. auto HandleBranch(FunctionContext& context, SemIR::NodeId /*node_id*/,
  64. SemIR::Branch node) -> void {
  65. // Opportunistically avoid creating a BasicBlock that contains just a branch.
  66. // TODO: Don't do this if it would remove a loop preheader block.
  67. llvm::BasicBlock* block = context.builder().GetInsertBlock();
  68. if (block->empty() && context.TryToReuseBlock(node.target_id, block)) {
  69. // Reuse this block as the branch target.
  70. } else {
  71. context.builder().CreateBr(context.GetBlock(node.target_id));
  72. }
  73. context.builder().ClearInsertionPoint();
  74. }
  75. auto HandleBranchIf(FunctionContext& context, SemIR::NodeId /*node_id*/,
  76. SemIR::BranchIf node) -> void {
  77. llvm::Value* cond = context.GetLocal(node.cond_id);
  78. llvm::BasicBlock* then_block = context.GetBlock(node.target_id);
  79. llvm::BasicBlock* else_block = context.CreateSyntheticBlock();
  80. context.builder().CreateCondBr(cond, then_block, else_block);
  81. context.builder().SetInsertPoint(else_block);
  82. }
  83. auto HandleBranchWithArg(FunctionContext& context, SemIR::NodeId /*node_id*/,
  84. SemIR::BranchWithArg node) -> void {
  85. llvm::Value* arg = context.GetLocal(node.arg_id);
  86. SemIR::TypeId arg_type_id =
  87. context.semantics_ir().GetNode(node.arg_id).type_id();
  88. // Opportunistically avoid creating a BasicBlock that contains just a branch.
  89. // We only do this for a block that we know will only have a single
  90. // predecessor, so that we can correctly populate the predecessors of the
  91. // PHINode.
  92. llvm::BasicBlock* block = context.builder().GetInsertBlock();
  93. llvm::BasicBlock* phi_predecessor = block;
  94. if (block->empty() && context.IsCurrentSyntheticBlock(block) &&
  95. context.TryToReuseBlock(node.target_id, block)) {
  96. // Reuse this block as the branch target.
  97. phi_predecessor = block->getSinglePredecessor();
  98. CARBON_CHECK(phi_predecessor)
  99. << "Synthetic block did not have a single predecessor";
  100. } else {
  101. context.builder().CreateBr(context.GetBlock(node.target_id));
  102. }
  103. context.GetBlockArg(node.target_id, arg_type_id)
  104. ->addIncoming(arg, phi_predecessor);
  105. context.builder().ClearInsertionPoint();
  106. }
  107. auto HandleBuiltin(FunctionContext& /*context*/, SemIR::NodeId /*node_id*/,
  108. SemIR::Builtin node) -> void {
  109. CARBON_FATAL() << "TODO: Add support: " << node;
  110. }
  111. auto HandleCall(FunctionContext& context, SemIR::NodeId node_id,
  112. SemIR::Call node) -> void {
  113. auto* callee = llvm::cast<llvm::Function>(context.GetLocal(node.callee_id));
  114. std::vector<llvm::Value*> args;
  115. llvm::ArrayRef<SemIR::NodeId> arg_ids =
  116. context.semantics_ir().GetNodeBlock(node.args_id);
  117. if (SemIR::GetInitializingRepresentation(context.semantics_ir(), node.type_id)
  118. .has_return_slot()) {
  119. args.push_back(context.GetLocal(arg_ids.back()));
  120. arg_ids = arg_ids.drop_back();
  121. }
  122. for (auto arg_id : arg_ids) {
  123. auto arg_type_id = context.semantics_ir().GetNode(arg_id).type_id();
  124. if (SemIR::GetValueRepresentation(context.semantics_ir(), arg_type_id)
  125. .kind != SemIR::ValueRepresentation::None) {
  126. args.push_back(context.GetLocal(arg_id));
  127. }
  128. }
  129. auto* call = context.builder().CreateCall(callee, args);
  130. context.SetLocal(node_id, call);
  131. // Name the call's result the same as the callee.
  132. // TODO: Is this a helpful name?
  133. if (!call->getType()->isVoidTy()) {
  134. call->setName(callee->getName());
  135. }
  136. }
  137. auto HandleClassDeclaration(FunctionContext& /*context*/,
  138. SemIR::NodeId /*node_id*/,
  139. SemIR::ClassDeclaration /*node*/) -> void {
  140. // No action to perform.
  141. }
  142. auto HandleDereference(FunctionContext& context, SemIR::NodeId node_id,
  143. SemIR::Dereference node) -> void {
  144. context.SetLocal(node_id, context.GetLocal(node.pointer_id));
  145. }
  146. auto HandleFunctionDeclaration(FunctionContext& /*context*/,
  147. SemIR::NodeId /*node_id*/,
  148. SemIR::FunctionDeclaration node) -> void {
  149. CARBON_FATAL()
  150. << "Should not be encountered. If that changes, we may want to change "
  151. "higher-level logic to skip them rather than calling this. "
  152. << node;
  153. }
  154. auto HandleInitializeFrom(FunctionContext& context, SemIR::NodeId /*node_id*/,
  155. SemIR::InitializeFrom node) -> void {
  156. auto storage_type_id = context.semantics_ir().GetNode(node.dest_id).type_id();
  157. context.FinishInitialization(storage_type_id, node.dest_id, node.src_id);
  158. }
  159. auto HandleIntegerLiteral(FunctionContext& context, SemIR::NodeId node_id,
  160. SemIR::IntegerLiteral node) -> void {
  161. const llvm::APInt& i = context.semantics_ir().integers().Get(node.integer_id);
  162. // TODO: This won't offer correct semantics, but seems close enough for now.
  163. llvm::Value* v =
  164. llvm::ConstantInt::get(context.builder().getInt32Ty(), i.getZExtValue());
  165. context.SetLocal(node_id, v);
  166. }
  167. auto HandleNameReference(FunctionContext& context, SemIR::NodeId node_id,
  168. SemIR::NameReference node) -> void {
  169. auto type_node_id =
  170. context.semantics_ir().GetTypeAllowBuiltinTypes(node.type_id);
  171. if (type_node_id == SemIR::NodeId::BuiltinNamespaceType) {
  172. return;
  173. }
  174. auto target = context.semantics_ir().GetNode(node.value_id);
  175. if (auto function_decl = target.TryAs<SemIR::FunctionDeclaration>()) {
  176. context.SetLocal(node_id, context.GetFunction(function_decl->function_id));
  177. } else {
  178. // TODO: Handle other kinds of name references to globals.
  179. context.SetLocal(node_id, context.GetLocal(node.value_id));
  180. }
  181. }
  182. auto HandleNamespace(FunctionContext& /*context*/, SemIR::NodeId /*node_id*/,
  183. SemIR::Namespace node) -> void {
  184. CARBON_FATAL()
  185. << "Should not be encountered. If that changes, we may want to change "
  186. "higher-level logic to skip them rather than calling this. "
  187. << node;
  188. }
  189. auto HandleNoOp(FunctionContext& /*context*/, SemIR::NodeId /*node_id*/,
  190. SemIR::NoOp /*node*/) -> void {
  191. // No action to take.
  192. }
  193. auto HandleParameter(FunctionContext& /*context*/, SemIR::NodeId /*node_id*/,
  194. SemIR::Parameter /*node*/) -> void {
  195. CARBON_FATAL() << "Parameters should be lowered by `BuildFunctionDefinition`";
  196. }
  197. auto HandleRealLiteral(FunctionContext& context, SemIR::NodeId node_id,
  198. SemIR::RealLiteral node) -> void {
  199. const Real& real = context.semantics_ir().reals().Get(node.real_id);
  200. // TODO: This will probably have overflow issues, and should be fixed.
  201. double val =
  202. real.mantissa.getZExtValue() *
  203. std::pow((real.is_decimal ? 10 : 2), real.exponent.getSExtValue());
  204. llvm::APFloat llvm_val(val);
  205. context.SetLocal(node_id, llvm::ConstantFP::get(
  206. context.builder().getDoubleTy(), llvm_val));
  207. }
  208. auto HandleReturn(FunctionContext& context, SemIR::NodeId /*node_id*/,
  209. SemIR::Return /*node*/) -> void {
  210. context.builder().CreateRetVoid();
  211. }
  212. auto HandleReturnExpression(FunctionContext& context, SemIR::NodeId /*node_id*/,
  213. SemIR::ReturnExpression node) -> void {
  214. switch (SemIR::GetInitializingRepresentation(
  215. context.semantics_ir(),
  216. context.semantics_ir().GetNode(node.expr_id).type_id())
  217. .kind) {
  218. case SemIR::InitializingRepresentation::None:
  219. case SemIR::InitializingRepresentation::InPlace:
  220. // Nothing to return.
  221. context.builder().CreateRetVoid();
  222. return;
  223. case SemIR::InitializingRepresentation::ByCopy:
  224. // The expression produces the value representation for the type.
  225. context.builder().CreateRet(context.GetLocal(node.expr_id));
  226. return;
  227. }
  228. }
  229. auto HandleSpliceBlock(FunctionContext& context, SemIR::NodeId node_id,
  230. SemIR::SpliceBlock node) -> void {
  231. context.LowerBlock(node.block_id);
  232. context.SetLocal(node_id, context.GetLocal(node.result_id));
  233. }
  234. auto HandleStringLiteral(FunctionContext& /*context*/,
  235. SemIR::NodeId /*node_id*/, SemIR::StringLiteral node)
  236. -> void {
  237. CARBON_FATAL() << "TODO: Add support: " << node;
  238. }
  239. // Extracts an element of either a struct or a tuple by index. Depending on the
  240. // expression category of the aggregate input, this will either produce a value
  241. // or a reference.
  242. static auto GetStructOrTupleElement(FunctionContext& context,
  243. SemIR::NodeId aggr_node_id, unsigned idx,
  244. SemIR::TypeId result_type_id,
  245. llvm::Twine name) -> llvm::Value* {
  246. auto aggr_node = context.semantics_ir().GetNode(aggr_node_id);
  247. auto* aggr_value = context.GetLocal(aggr_node_id);
  248. switch (SemIR::GetExpressionCategory(context.semantics_ir(), aggr_node_id)) {
  249. case SemIR::ExpressionCategory::Error:
  250. case SemIR::ExpressionCategory::NotExpression:
  251. case SemIR::ExpressionCategory::Initializing:
  252. case SemIR::ExpressionCategory::Mixed:
  253. CARBON_FATAL() << "Unexpected expression category for aggregate access";
  254. case SemIR::ExpressionCategory::Value: {
  255. auto value_rep = SemIR::GetValueRepresentation(context.semantics_ir(),
  256. aggr_node.type_id());
  257. switch (value_rep.kind) {
  258. case SemIR::ValueRepresentation::Unknown:
  259. CARBON_FATAL() << "Lowering access to incomplete aggregate type";
  260. case SemIR::ValueRepresentation::None:
  261. return aggr_value;
  262. case SemIR::ValueRepresentation::Copy:
  263. // We are holding the values of the aggregate directly, elementwise.
  264. return context.builder().CreateExtractValue(aggr_value, idx, name);
  265. case SemIR::ValueRepresentation::Pointer: {
  266. // The value representation is a pointer to an aggregate that we want
  267. // to index into.
  268. auto pointee_type_id =
  269. context.semantics_ir().GetPointeeType(value_rep.type_id);
  270. auto* value_type = context.GetType(pointee_type_id);
  271. auto* elem_ptr = context.builder().CreateStructGEP(
  272. value_type, aggr_value, idx, name);
  273. auto result_value_type_id =
  274. SemIR::GetValueRepresentation(context.semantics_ir(),
  275. result_type_id)
  276. .type_id;
  277. return context.builder().CreateLoad(
  278. context.GetType(result_value_type_id), elem_ptr, name + ".load");
  279. }
  280. case SemIR::ValueRepresentation::Custom:
  281. CARBON_FATAL()
  282. << "Aggregate should never have custom value representation";
  283. }
  284. }
  285. case SemIR::ExpressionCategory::DurableReference:
  286. case SemIR::ExpressionCategory::EphemeralReference: {
  287. // Just locate the aggregate element.
  288. auto* aggr_type = context.GetType(aggr_node.type_id());
  289. return context.builder().CreateStructGEP(aggr_type, aggr_value, idx,
  290. name);
  291. }
  292. }
  293. }
  294. auto HandleStructAccess(FunctionContext& context, SemIR::NodeId node_id,
  295. SemIR::StructAccess node) -> void {
  296. auto struct_type_id =
  297. context.semantics_ir().GetNode(node.struct_id).type_id();
  298. // Get type information for member names.
  299. auto fields = context.semantics_ir().GetNodeBlock(
  300. context.semantics_ir()
  301. .GetNodeAs<SemIR::StructType>(
  302. context.semantics_ir().types().Get(struct_type_id).node_id)
  303. .fields_id);
  304. auto field = context.semantics_ir().GetNodeAs<SemIR::StructTypeField>(
  305. fields[node.index.index]);
  306. auto member_name = context.semantics_ir().strings().Get(field.name_id);
  307. context.SetLocal(node_id, GetStructOrTupleElement(context, node.struct_id,
  308. node.index.index,
  309. node.type_id, member_name));
  310. }
  311. auto HandleStructLiteral(FunctionContext& /*context*/,
  312. SemIR::NodeId /*node_id*/,
  313. SemIR::StructLiteral /*node*/) -> void {
  314. // A StructLiteral should always be converted to a StructInit or StructValue
  315. // if its value is needed.
  316. }
  317. // Emits the value representation for a struct or tuple whose elements are the
  318. // contents of `refs_id`.
  319. auto EmitStructOrTupleValueRepresentation(FunctionContext& context,
  320. SemIR::TypeId type_id,
  321. SemIR::NodeBlockId refs_id,
  322. llvm::Twine name) -> llvm::Value* {
  323. auto value_rep =
  324. SemIR::GetValueRepresentation(context.semantics_ir(), type_id);
  325. switch (value_rep.kind) {
  326. case SemIR::ValueRepresentation::Unknown:
  327. CARBON_FATAL() << "Incomplete aggregate type in lowering";
  328. case SemIR::ValueRepresentation::None:
  329. // TODO: Add a helper to get a "no value representation" value.
  330. return llvm::PoisonValue::get(context.GetType(value_rep.type_id));
  331. case SemIR::ValueRepresentation::Copy: {
  332. auto refs = context.semantics_ir().GetNodeBlock(refs_id);
  333. CARBON_CHECK(refs.size() == 1)
  334. << "Unexpected size for aggregate with by-copy value representation";
  335. // TODO: Remove the LLVM StructType wrapper in this case, so we don't
  336. // need this `insert_value` wrapping.
  337. return context.builder().CreateInsertValue(
  338. llvm::PoisonValue::get(context.GetType(value_rep.type_id)),
  339. context.GetLocal(refs[0]), {0});
  340. }
  341. case SemIR::ValueRepresentation::Pointer: {
  342. auto pointee_type_id =
  343. context.semantics_ir().GetPointeeType(value_rep.type_id);
  344. auto* llvm_value_rep_type = context.GetType(pointee_type_id);
  345. // Write the value representation to a local alloca so we can produce a
  346. // pointer to it as the value representation of the struct or tuple.
  347. auto* alloca =
  348. context.builder().CreateAlloca(llvm_value_rep_type,
  349. /*ArraySize=*/nullptr, name);
  350. for (auto [i, ref] :
  351. llvm::enumerate(context.semantics_ir().GetNodeBlock(refs_id))) {
  352. context.builder().CreateStore(
  353. context.GetLocal(ref),
  354. context.builder().CreateStructGEP(llvm_value_rep_type, alloca, i));
  355. }
  356. return alloca;
  357. }
  358. case SemIR::ValueRepresentation::Custom:
  359. CARBON_FATAL()
  360. << "Aggregate should never have custom value representation";
  361. }
  362. }
  363. auto HandleStructInit(FunctionContext& context, SemIR::NodeId node_id,
  364. SemIR::StructInit node) -> void {
  365. auto* llvm_type = context.GetType(node.type_id);
  366. switch (
  367. SemIR::GetInitializingRepresentation(context.semantics_ir(), node.type_id)
  368. .kind) {
  369. case SemIR::InitializingRepresentation::None:
  370. case SemIR::InitializingRepresentation::InPlace:
  371. // TODO: Add a helper to poison a value slot.
  372. context.SetLocal(node_id, llvm::PoisonValue::get(llvm_type));
  373. break;
  374. case SemIR::InitializingRepresentation::ByCopy: {
  375. context.SetLocal(
  376. node_id, EmitStructOrTupleValueRepresentation(
  377. context, node.type_id, node.elements_id, "struct.init"));
  378. break;
  379. }
  380. }
  381. }
  382. auto HandleStructValue(FunctionContext& context, SemIR::NodeId node_id,
  383. SemIR::StructValue node) -> void {
  384. context.SetLocal(node_id,
  385. EmitStructOrTupleValueRepresentation(
  386. context, node.type_id, node.elements_id, "struct"));
  387. }
  388. auto HandleStructTypeField(FunctionContext& /*context*/,
  389. SemIR::NodeId /*node_id*/,
  390. SemIR::StructTypeField /*node*/) -> void {
  391. // No action to take.
  392. }
  393. auto HandleTupleAccess(FunctionContext& context, SemIR::NodeId node_id,
  394. SemIR::TupleAccess node) -> void {
  395. context.SetLocal(
  396. node_id, GetStructOrTupleElement(context, node.tuple_id, node.index.index,
  397. node.type_id, "tuple.elem"));
  398. }
  399. auto HandleTupleIndex(FunctionContext& context, SemIR::NodeId node_id,
  400. SemIR::TupleIndex node) -> void {
  401. auto index_node =
  402. context.semantics_ir().GetNodeAs<SemIR::IntegerLiteral>(node.index_id);
  403. auto index = context.semantics_ir()
  404. .integers()
  405. .Get(index_node.integer_id)
  406. .getZExtValue();
  407. context.SetLocal(node_id,
  408. GetStructOrTupleElement(context, node.tuple_id, index,
  409. node.type_id, "tuple.index"));
  410. }
  411. auto HandleTupleLiteral(FunctionContext& /*context*/, SemIR::NodeId /*node_id*/,
  412. SemIR::TupleLiteral /*node*/) -> void {
  413. // A TupleLiteral should always be converted to a TupleInit or TupleValue if
  414. // its value is needed.
  415. }
  416. auto HandleTupleInit(FunctionContext& context, SemIR::NodeId node_id,
  417. SemIR::TupleInit node) -> void {
  418. auto* llvm_type = context.GetType(node.type_id);
  419. switch (
  420. SemIR::GetInitializingRepresentation(context.semantics_ir(), node.type_id)
  421. .kind) {
  422. case SemIR::InitializingRepresentation::None:
  423. case SemIR::InitializingRepresentation::InPlace:
  424. // TODO: Add a helper to poison a value slot.
  425. context.SetLocal(node_id, llvm::PoisonValue::get(llvm_type));
  426. break;
  427. case SemIR::InitializingRepresentation::ByCopy: {
  428. context.SetLocal(
  429. node_id, EmitStructOrTupleValueRepresentation(
  430. context, node.type_id, node.elements_id, "tuple.init"));
  431. break;
  432. }
  433. }
  434. }
  435. auto HandleTupleValue(FunctionContext& context, SemIR::NodeId node_id,
  436. SemIR::TupleValue node) -> void {
  437. context.SetLocal(
  438. node_id, EmitStructOrTupleValueRepresentation(context, node.type_id,
  439. node.elements_id, "tuple"));
  440. }
  441. auto HandleUnaryOperatorNot(FunctionContext& context, SemIR::NodeId node_id,
  442. SemIR::UnaryOperatorNot node) -> void {
  443. context.SetLocal(
  444. node_id, context.builder().CreateNot(context.GetLocal(node.operand_id)));
  445. }
  446. auto HandleVarStorage(FunctionContext& context, SemIR::NodeId node_id,
  447. SemIR::VarStorage node) -> void {
  448. // TODO: Eventually this name will be optional, and we'll want to provide
  449. // something like `var` as a default. However, that's not possible right now
  450. // so cannot be tested.
  451. auto name = context.semantics_ir().strings().Get(node.name_id);
  452. auto* alloca = context.builder().CreateAlloca(context.GetType(node.type_id),
  453. /*ArraySize=*/nullptr, name);
  454. context.SetLocal(node_id, alloca);
  455. }
  456. } // namespace Carbon::Lower