From fadb992aeaff1a98864f37bc72ab94e5e54684c0 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 26 Nov 2024 11:43:09 -0800 Subject: [PATCH 1/3] Add documentation for the three most common kinds of instruction operand --- toolchain/docs/check.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/toolchain/docs/check.md b/toolchain/docs/check.md index 0ed49596bbf4a..5e6f57c215129 100644 --- a/toolchain/docs/check.md +++ b/toolchain/docs/check.md @@ -13,6 +13,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - [Overview](#overview) - [Postorder processing](#postorder-processing) - [Key IR concepts](#key-ir-concepts) + - [Instruction operands](#instruction-operands) - [Parameters and arguments](#parameters-and-arguments) - [SemIR textual format](#semir-textual-format) - [Raw form](#raw-form) @@ -74,7 +75,7 @@ interprets to build the `SemIR`. A `SemIR::Inst` is the basic building block that represents a simple instruction, such as an operator or declaring a literal. For each kind of -instruction, a typedef for that specific kind of instruction is provided in the +instruction, a struct for that specific kind of instruction is provided in the `SemIR` namespace. For example, `SemIR::Assign` represents an assignment instruction, and `SemIR::PointerType` represents a pointer type instruction. @@ -108,6 +109,27 @@ facet type `type`. We will also have built-in functions which would need to form the implementation of some library types, such as `i32`. Built-ins are in a stable index across `SemIR` instances. +### Instruction operands + +The kind-specific members on a typed instruction struct can be of any type +listed in the `SemIR::IdKind` enumeration defined in +[sem_ir/id_kinds.h](/toolchain/sem_ir/id_kinds.h). The most commonly used kinds +refer to other instructions: + +- `SemIR::InstId`: Refers to a specific instance of an instruction. For + example, this should be used if the operand may have side-effects or a + meaningful location. +- `SemIR::ConstantId`: An abstract reference to a known constant value. + This should be used instead of `InstId` if you care only about the identity + of the value and not how it was formed. +- `SemIR::TypeId`: An abstract reference to a known constant value of type + `type`. This should be used instead of `ConstantId` if you know that the + type of the constant value is always `type` (or the value is the "error" + constant, whose type is also the "error" constant). + +Other ID types are used for more specialized purposes. Refer to the class +documentation for the ID type for more details. + ### Parameters and arguments Parameters and arguments will be stored as two `SemIR::InstBlock`s each. The From 84da8b91174c25c8d850ce7fc67fff1e448a1cab Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 26 Nov 2024 11:47:41 -0800 Subject: [PATCH 2/3] Reflow. Co-authored-by: Carbon Infra Bot --- toolchain/docs/check.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/toolchain/docs/check.md b/toolchain/docs/check.md index 5e6f57c215129..7954cadfe003c 100644 --- a/toolchain/docs/check.md +++ b/toolchain/docs/check.md @@ -119,9 +119,9 @@ refer to other instructions: - `SemIR::InstId`: Refers to a specific instance of an instruction. For example, this should be used if the operand may have side-effects or a meaningful location. -- `SemIR::ConstantId`: An abstract reference to a known constant value. - This should be used instead of `InstId` if you care only about the identity - of the value and not how it was formed. +- `SemIR::ConstantId`: An abstract reference to a known constant value. This + should be used instead of `InstId` if you care only about the identity of + the value and not how it was formed. - `SemIR::TypeId`: An abstract reference to a known constant value of type `type`. This should be used instead of `ConstantId` if you know that the type of the constant value is always `type` (or the value is the "error" From 3c21e488e7226b013bde26e391ad73474c4b50f7 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 26 Nov 2024 12:07:26 -0800 Subject: [PATCH 3/3] Fix file name. Co-authored-by: Dana Jansens --- toolchain/docs/check.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchain/docs/check.md b/toolchain/docs/check.md index 7954cadfe003c..826a886aa173c 100644 --- a/toolchain/docs/check.md +++ b/toolchain/docs/check.md @@ -113,7 +113,7 @@ stable index across `SemIR` instances. The kind-specific members on a typed instruction struct can be of any type listed in the `SemIR::IdKind` enumeration defined in -[sem_ir/id_kinds.h](/toolchain/sem_ir/id_kinds.h). The most commonly used kinds +[sem_ir/id_kind.h](/toolchain/sem_ir/id_kind.h). The most commonly used kinds refer to other instructions: - `SemIR::InstId`: Refers to a specific instance of an instruction. For