跳转到内容

std.zig.llvm.Builder

标准库Zig 0.17.0官方原文
源码std/zig/llvm/Builder.zig

第 1 行

字段

gpa: Allocator
strip: bool
source_filename: String
data_layout: DataLayout
target_triple: String
module_asm: std.ArrayList(u8)
string_map: std.array_hash_map.Auto(void, void)
string_indices: std.ArrayList(u32)
string_bytes: std.ArrayList(u8)
types: std.array_hash_map.Auto(String, Type)
next_unnamed_type: String
next_unique_type_id: std.AutoHashMapUnmanaged(String, u32)
type_map: std.array_hash_map.Auto(void, void)
type_items: std.ArrayList(Type.Item)
type_extra: std.ArrayList(u32)
attributes: std.array_hash_map.Auto(Attribute.Storage, void)
attributes_map: std.array_hash_map.Auto(void, void)
attributes_indices: std.ArrayList(u32)
attributes_extra: std.ArrayList(u32)
function_attributes_set: std.array_hash_map.Auto(FunctionAttributes, void)
globals: std.array_hash_map.Auto(StrtabString, Global)
next_unnamed_global: StrtabString
next_replaced_global: StrtabString
next_unique_global_id: std.AutoHashMapUnmanaged(StrtabString, u32)
aliases: std.ArrayList(Alias)
variables: std.ArrayList(Variable)
functions: std.ArrayList(Function)
strtab_string_map: std.array_hash_map.Auto(void, void)
strtab_string_indices: std.ArrayList(u32)
strtab_string_bytes: std.ArrayList(u8)
constant_map: std.array_hash_map.Auto(void, void)
constant_items: std.MultiArrayList(Constant.Item)
constant_extra: std.ArrayList(u32)
constant_limbs: std.ArrayList(std.math.big.Limb)
alignment_forward_references: std.ArrayList(Alignment)
metadata_map: std.array_hash_map.Auto(void, void)
metadata_items: std.MultiArrayList(Metadata.Item)
metadata_extra: std.ArrayList(u32)
metadata_limbs: std.ArrayList(std.math.big.Limb)
metadata_forward_references: std.ArrayList(Metadata.Optional)
metadata_named: std.array_hash_map.Auto(String, struct {
    len: u32,
    index: Metadata.Item.ExtraIndex,
})
metadata_string_map: std.array_hash_map.Auto(void, void)
metadata_string_indices: std.ArrayList(u32)
metadata_string_bytes: std.ArrayList(u8)

std.zig.llvm.Builder.addAlias

函数

第 10261 行

pub fn addAlias( self: *Builder, name: StrtabString, ty: Type, addr_space: AddrSpace, aliasee: Constant, ) Allocator.Error!Alias.Index

参数

self: *Builder
name: StrtabString
ty: Type
addr_space: AddrSpace
aliasee: Constant

错误

OutOfMemory

std.zig.llvm.Builder.addAliasAssumeCapacity

函数

第 10275 行

pub fn addAliasAssumeCapacity( self: *Builder, name: StrtabString, ty: Type, addr_space: AddrSpace, aliasee: Constant, ) Alias.Index

参数

self: *Builder
name: StrtabString
ty: Type
addr_space: AddrSpace
aliasee: Constant

std.zig.llvm.Builder.addConstantExtraAssumeCapacity

函数

第 13141 行

fn addConstantExtraAssumeCapacity(self: *Builder, extra: anytype) Constant.Item.ExtraIndex

参数

self: *Builder

std.zig.llvm.Builder.addFunction

函数

第 10319 行

pub fn addFunction( self: *Builder, ty: Type, name: StrtabString, addr_space: AddrSpace, ) Allocator.Error!Function.Index

参数

self: *Builder
ty: Type
name: StrtabString
addr_space: AddrSpace

错误

OutOfMemory

std.zig.llvm.Builder.addFunctionAssumeCapacity

函数

第 10332 行

pub fn addFunctionAssumeCapacity( self: *Builder, ty: Type, name: StrtabString, addr_space: AddrSpace, ) Function.Index

参数

self: *Builder
ty: Type
name: StrtabString
addr_space: AddrSpace

std.zig.llvm.Builder.addGlobal

函数

第 10226 行

pub fn addGlobal(self: *Builder, name: StrtabString, global: Global) Allocator.Error!Global.Index

参数

self: *Builder
name: StrtabString
global: Global

错误

OutOfMemory

std.zig.llvm.Builder.addGlobalAssumeCapacity

函数

第 10233 行

pub fn addGlobalAssumeCapacity(self: *Builder, name: StrtabString, global: Global) Global.Index

参数

self: *Builder
name: StrtabString
global: Global

std.zig.llvm.Builder.addMetadataExtraAssumeCapacity

函数

第 13219 行

fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.ExtraIndex

参数

self: *Builder

std.zig.llvm.Builder.addNamedMetadata

函数

第 13351 行

pub fn addNamedMetadata(self: *Builder, name: String, operands: []const Metadata) Allocator.Error!void

参数

self: *Builder
name: String
operands: []const Metadata

错误

OutOfMemory

std.zig.llvm.Builder.addNamedMetadataAssumeCapacity

函数

第 13821 行

fn addNamedMetadataAssumeCapacity(self: *Builder, name: String, operands: []const Metadata) void

参数

self: *Builder
name: String
operands: []const Metadata

std.zig.llvm.Builder.AddrSpace

容器

第 2834 行

字段

default
_

std.zig.llvm.Builder.AddrSpace.amdgpu

命名空间

第 2872 行

std.zig.llvm.Builder.AddrSpace.amdgpu.buffer_fat_pointer

常量

第 2880 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.buffer_resource

常量

第 2881 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.buffer_strided_pointer

常量

第 2882 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant

常量

第 2877 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_32bit

常量

第 2879 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_0

常量

第 2885 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_1

常量

第 2886 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_10

常量

第 2895 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_11

常量

第 2896 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_12

常量

第 2897 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_13

常量

第 2898 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_14

常量

第 2899 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_15

常量

第 2900 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_2

常量

第 2887 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_3

常量

第 2888 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_4

常量

第 2889 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_5

常量

第 2890 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_6

常量

第 2891 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_7

常量

第 2892 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_8

常量

第 2893 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.constant_buffer_9

常量

第 2894 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.flat

常量

第 2873 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.global

常量

第 2874 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.local

常量

第 2876 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.param_d

常量

第 2883 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.param_i

常量

第 2884 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.private

常量

第 2878 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.region

常量

第 2875 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.amdgpu.streamout_register

常量

第 2901 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr

命名空间

第 2851 行

std.zig.llvm.Builder.AddrSpace.avr.data

常量

第 2852 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr.program

常量

第 2853 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr.program1

常量

第 2854 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr.program2

常量

第 2855 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr.program3

常量

第 2856 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr.program4

常量

第 2857 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.avr.program5

常量

第 2858 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.fmt

函数

第 2939 行

pub fn fmt(addr_space: AddrSpace, prefix: []const u8) Prefixed

参数

addr_space: AddrSpace
prefix: []const u8

std.zig.llvm.Builder.AddrSpace.format

函数

第 2923 行

pub fn format(addr_space: AddrSpace, w: *Writer) Writer.Error!void

参数

addr_space: AddrSpace
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.AddrSpace.nvptx

命名空间

第 2862 行

std.zig.llvm.Builder.AddrSpace.nvptx.constant

常量

第 2865 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.nvptx.generic

常量

第 2863 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.nvptx.global

常量

第 2864 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.nvptx.local

常量

第 2868 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.nvptx.param

常量

第 2867 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.nvptx.shared

常量

第 2866 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.Prefixed

容器

第 2927 行

字段

addr_space: AddrSpace
prefix: []const u8

std.zig.llvm.Builder.AddrSpace.Prefixed.format

函数

第 2931 行

pub fn format(p: Prefixed, w: *Writer) Writer.Error!void

参数

p: Prefixed
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.AddrSpace.spirv

命名空间

第 2904 行

std.zig.llvm.Builder.AddrSpace.spirv.cross_workgroup

常量

第 2906 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.device_only_intel

常量

第 2910 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.function

常量

第 2905 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.generic

常量

第 2909 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.host_only_intel

常量

第 2911 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.input

常量

第 2912 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.uniform_constant

常量

第 2907 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.spirv.workgroup

常量

第 2908 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.wasm

命名空间

第 2916 行

std.zig.llvm.Builder.AddrSpace.wasm.default

常量

第 2917 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.wasm.externref

常量

第 2919 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.wasm.funcref

常量

第 2920 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.wasm.variable

常量

第 2918 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.x86

命名空间

第 2839 行

std.zig.llvm.Builder.AddrSpace.x86_64

别名

第 2848 行

别名目标 std.zig.llvm.Builder.AddrSpace.x86

std.zig.llvm.Builder.AddrSpace.x86.fs

常量

第 2841 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.x86.gs

常量

第 2840 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.x86.ptr32_sptr

常量

第 2844 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.x86.ptr32_uptr

常量

第 2845 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.x86.ptr64

常量

第 2846 行

AddrSpace

std.zig.llvm.Builder.AddrSpace.x86.ss

常量

第 2842 行

AddrSpace

std.zig.llvm.Builder.addTypeExtraAssumeCapacity

函数

第 12204 行

fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraIndex

参数

self: *Builder

std.zig.llvm.Builder.addVariable

函数

第 10291 行

pub fn addVariable( self: *Builder, name: StrtabString, ty: Type, addr_space: AddrSpace, ) Allocator.Error!Variable.Index

参数

self: *Builder
name: StrtabString
ty: Type
addr_space: AddrSpace

错误

OutOfMemory

std.zig.llvm.Builder.addVariableAssumeCapacity

函数

第 10304 行

pub fn addVariableAssumeCapacity( self: *Builder, ty: Type, name: StrtabString, addr_space: AddrSpace, ) Variable.Index

参数

self: *Builder
ty: Type
name: StrtabString
addr_space: AddrSpace

std.zig.llvm.Builder.Alias

容器

第 3486 行

字段

global: Global.Index
thread_local: ThreadLocal = .default
aliasee: Constant = .no_init

std.zig.llvm.Builder.Alias.Index

容器

第 3491 行

字段

none = maxInt(u32)
_

std.zig.llvm.Builder.Alias.Index.getAliasee

函数

第 3523 行

pub fn getAliasee(self: Index, builder: *const Builder) Global.Index

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Alias.Index.name

函数

第 3503 行

pub fn name(self: Index, builder: *const Builder) StrtabString

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Alias.Index.ptr

函数

第 3495 行

pub fn ptr(self: Index, builder: *Builder) *Alias

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Alias.Index.ptrConst

函数

第 3499 行

pub fn ptrConst(self: Index, builder: *const Builder) *const Alias

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Alias.Index.rename

函数

第 3507 行

pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void

参数

self: Index
new_name: StrtabString
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Alias.Index.setAliasee

函数

第 3529 行

pub fn setAliasee(self: Index, aliasee: Constant, builder: *Builder) void

参数

self: Index
aliasee: Constant
builder: *Builder

std.zig.llvm.Builder.Alias.Index.toConst

函数

第 3515 行

pub fn toConst(self: Index, builder: *const Builder) Constant

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Alias.Index.toValue

函数

第 3519 行

pub fn toValue(self: Index, builder: *const Builder) Value

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Alias.Index.typeOf

函数

第 3511 行

pub fn typeOf(self: Index, builder: *const Builder) Type

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Alignment

容器

第 2953 行

字段

default = maxInt(u6)
_

std.zig.llvm.Builder.Alignment.fmt

函数

第 3025 行

pub fn fmt(alignment: Alignment, prefix: []const u8) Prefixed

参数

alignment: Alignment
prefix: []const u8

std.zig.llvm.Builder.Alignment.fromByteUnits

函数

第 2980 行

pub fn fromByteUnits(bytes: u64) Alignment

参数

bytes: u64

std.zig.llvm.Builder.Alignment.Lazy

容器

第 2957 行

字段

_

可放入 u6 的值已经是解析完成的 Alignment 值。 其他值是 Builder.alignment_forward_references 的索引,并以 maxInt(u6) 为偏移。

std.zig.llvm.Builder.Alignment.Lazy.fromFwdRefIndex

函数

第 2972 行

fn fromFwdRefIndex(index: usize) Lazy

参数

index: usize

std.zig.llvm.Builder.Alignment.Lazy.resolve

函数

第 2965 行

pub fn resolve(l: Lazy, b: *const Builder) Alignment

参数

l: Lazy
b: *const Builder

std.zig.llvm.Builder.Alignment.Lazy.toFwdRefIndex

函数

第 2975 行

fn toFwdRefIndex(l: Lazy) usize

参数

l: Lazy

std.zig.llvm.Builder.Alignment.Lazy.wrap

函数

第 2962 行

pub fn wrap(a: Alignment) Lazy

参数

std.zig.llvm.Builder.Alignment.max

函数

第 2995 行

断言 lhs 和 rhs 均不是 .default。

pub fn max(lhs: Alignment, rhs: Alignment) Alignment

参数

lhs: Alignment
rhs: Alignment

std.zig.llvm.Builder.Alignment.order

函数

第 3002 行

断言 lhs 和 rhs 均不是 .default。

pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order

参数

lhs: Alignment
rhs: Alignment

std.zig.llvm.Builder.Alignment.Prefixed

容器

第 3015 行

字段

alignment: Alignment
prefix: []const u8

std.zig.llvm.Builder.Alignment.Prefixed.format

函数

第 3019 行

pub fn format(p: Prefixed, w: *Writer) Writer.Error!void

参数

p: Prefixed
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Alignment.toByteUnits

函数

第 2987 行

pub fn toByteUnits(self: Alignment) ?u64

参数

self: Alignment

std.zig.llvm.Builder.Alignment.toLlvm

函数

第 3008 行

pub fn toLlvm(self: Alignment) u6

参数

self: Alignment

std.zig.llvm.Builder.alignmentForwardReference

函数

第 10790 行

前向引用的初始“已解析”值为 Alignment.default。

pub fn alignmentForwardReference(b: *Builder) Allocator.Error!Alignment.Lazy

参数

b: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Allocator

别名

第 6 行

别名目标 std.mem.Allocator

std.zig.llvm.Builder.arrayConst

函数

第 10601 行

pub fn arrayConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant

参数

self: *Builder
ty: Type
vals: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.arrayConstAssumeCapacity

函数

第 12560 行

fn arrayConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant

参数

self: *Builder
ty: Type
vals: []const Constant

std.zig.llvm.Builder.arrayType

函数

第 10153 行

pub fn arrayType(self: *Builder, len: u64, child: Type) Allocator.Error!Type

参数

self: *Builder
len: u64
child: Type

错误

OutOfMemory

std.zig.llvm.Builder.arrayTypeAssumeCapacity

函数

第 12019 行

fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type

参数

self: *Builder
len: u64
child: Type

std.zig.llvm.Builder.arrayTypeAssumeCapacity.eql

函数

第 12029 行

pub fn eql(ctx: @This(), lhs_key: Type.Vector, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Type.Vector
_: void
rhs_index: usize

std.zig.llvm.Builder.arrayTypeAssumeCapacity.eql

函数

第 12055 行

pub fn eql(ctx: @This(), lhs_key: Type.Array, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Type.Array
_: void
rhs_index: usize

std.zig.llvm.Builder.arrayTypeAssumeCapacity.hash

函数

第 12023 行

pub fn hash(_: @This(), key: Type.Vector) u32

参数

_: @This()
key: Type.Vector

std.zig.llvm.Builder.arrayTypeAssumeCapacity.hash

函数

第 12049 行

pub fn hash(_: @This(), key: Type.Array) u32

参数

_: @This()
key: Type.Array

std.zig.llvm.Builder.arrayValue

函数

第 10606 行

pub fn arrayValue(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Value

参数

self: *Builder
ty: Type
vals: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.asmConst

函数

第 10768 行

pub fn asmConst( self: *Builder, ty: Type, info: Constant.Assembly.Info, assembly: String, constraints: String, ) Allocator.Error!Constant

参数

self: *Builder
ty: Type
info: Constant.Assembly.Info
assembly: String
constraints: String

错误

OutOfMemory

std.zig.llvm.Builder.asmConstAssumeCapacity

函数

第 13016 行

fn asmConstAssumeCapacity( self: *Builder, ty: Type, info: Constant.Assembly.Info, assembly: String, constraints: String, ) Constant

参数

self: *Builder
ty: Type
info: Constant.Assembly.Info
assembly: String
constraints: String

std.zig.llvm.Builder.asmConstAssumeCapacity.eql

函数

第 13034 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.asmConstAssumeCapacity.hash

函数

第 13028 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.asmValue

函数

第 10779 行

pub fn asmValue( self: *Builder, ty: Type, info: Constant.Assembly.Info, assembly: String, constraints: String, ) Allocator.Error!Value

参数

self: *Builder
ty: Type
info: Constant.Assembly.Info
assembly: String
constraints: String

错误

OutOfMemory

std.zig.llvm.Builder.assert

别名

第 7 行

别名目标 std.debug.assert

std.zig.llvm.Builder.AtomicOrdering

容器

第 8280 行

字段

none = 0
unordered = 1
monotonic = 2
acquire = 3
release = 4
acq_rel = 5
seq_cst = 6

std.zig.llvm.Builder.AtomicOrdering.fmt

函数

第 8308 行

pub fn fmt(atomic_ordering: AtomicOrdering, prefix: []const u8) Prefixed

参数

atomic_ordering: AtomicOrdering
prefix: []const u8

std.zig.llvm.Builder.AtomicOrdering.format

函数

第 8289 行

pub fn format(atomic_ordering: AtomicOrdering, w: *Writer) Writer.Error!void

参数

atomic_ordering: AtomicOrdering
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.AtomicOrdering.Prefixed

容器

第 8293 行

字段

atomic_ordering: AtomicOrdering
prefix: []const u8

std.zig.llvm.Builder.AtomicOrdering.Prefixed.format

函数

第 8297 行

pub fn format(p: Prefixed, w: *Writer) Writer.Error!void

参数

p: Prefixed
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.attr

函数

第 10193 行

pub fn attr(self: *Builder, attribute: Attribute) Allocator.Error!Attribute.Index

参数

self: *Builder
attribute: Attribute

错误

OutOfMemory

std.zig.llvm.Builder.attrGeneric

函数

第 12266 行

fn attrGeneric(self: *Builder, data: []const u32) Allocator.Error!u32

参数

self: *Builder
data: []const u32

错误

OutOfMemory

std.zig.llvm.Builder.attrGeneric.eql

函数

第 12276 行

pub fn eql(ctx: @This(), lhs_key: []const u32, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: []const u32
_: void
rhs_index: usize

std.zig.llvm.Builder.attrGeneric.hash

函数

第 12273 行

pub fn hash(_: @This(), key: []const u32) u32

参数

_: @This()
key: []const u32

std.zig.llvm.Builder.Attribute

容器

第 1745 行

字段

zeroext
signext
noext
inreg
byval: Type
byref: Type
preallocated: Type
inalloca: Type
sret: Type
elementtype: Type
@"align": Alignment.Lazy
@"noalias"
nocapture
captures: Captures
nofree
nest
returned
nonnull
dereferenceable: u32
dereferenceable_or_null: u32
swiftself
swiftasync
swifterror
immarg
noundef
nofpclass: FpClass
alignstack: Alignment.Lazy
allocalign
allocptr
readnone
readonly
writeonly
writable
initializes: []const [2]u64
dead_on_unwind
dead_on_return: ?u32
range: [2]Constant
allockind: AllocKind
allocsize: AllocSize
alwaysinline
builtin
cold
convergent
disable_sanitizer_instrumentation
fn_ret_thunk_extern
hot
inlinehint
jumptable
memory: Memory
minsize
naked
nobuiltin
nocallback
nodivergencesource
noduplicate
noimplicitfloat
@"noinline"
nomerge
nonlazybind
noprofile
skipprofile
noredzone
noreturn
norecurse
willreturn
nosync
nounwind
nosanitize_bounds
nosanitize_coverage
null_pointer_is_valid
optdebug
optforfuzzing
optnone
optsize
returns_twice
safestack
sanitize_address
sanitize_memory
sanitize_thread
sanitize_hwaddress
sanitize_memtag
sanitize_realtime
sanitize_realtime_blocking
sanitize_alloc_token
speculative_load_hardening
speculatable
ssp
sspstrong
sspreq
strictfp
denormal_fpenv
uwtable: UwTable
nocf_check
shadowcallstack
mustprogress
vscale_range: VScaleRange
nooutline
nocreateundeforpoison
string: struct { kind: String, value: String }
none: noreturn

std.zig.llvm.Builder.Attribute.AllocKind

容器

第 2435 行

字段

alloc: bool
realloc: bool
free: bool
uninitialized: bool
zeroed: bool
aligned: bool
_: u26 = 0

std.zig.llvm.Builder.Attribute.AllocSize

容器

第 2445 行

字段

elem_size: u16
num_elems: u16

std.zig.llvm.Builder.Attribute.AllocSize.none

常量

第 2449 行

std.zig.llvm.Builder.Attribute.AllocSize.toLlvm

类型函数

第 2451 行

fn toLlvm(self: AllocSize) packed struct(u64) { num_elems: u32, elem_size: u32 }

参数

self: AllocSize

std.zig.llvm.Builder.Attribute.Captures

容器

第 2412 行

字段

other: Components = .none
ret: Components = .none
_: u24 = 0

std.zig.llvm.Builder.Attribute.Captures.Components

容器

第 2419 行

字段

address_is_null: bool = false
address: bool = false
read_provenance: bool = false
provenance: bool = false

std.zig.llvm.Builder.Attribute.Captures.Components.all

常量

第 2426 行

Components

std.zig.llvm.Builder.Attribute.Captures.Components.none

常量

第 2425 行

Components

std.zig.llvm.Builder.Attribute.Captures.none

常量

第 2417 行

Captures

std.zig.llvm.Builder.Attribute.FpClass

容器

第 2365 行

字段

signaling_nan: bool = false
quiet_nan: bool = false
negative_infinity: bool = false
negative_normal: bool = false
negative_subnormal: bool = false
negative_zero: bool = false
positive_zero: bool = false
positive_subnormal: bool = false
positive_normal: bool = false
positive_infinity: bool = false
_: u22 = 0

std.zig.llvm.Builder.Attribute.FpClass.all

常量

第 2378 行

std.zig.llvm.Builder.Attribute.FpClass.inf

常量

第 2395 行

std.zig.llvm.Builder.Attribute.FpClass.nan

常量

第 2391 行

std.zig.llvm.Builder.Attribute.FpClass.ninf

常量

第 2396 行

std.zig.llvm.Builder.Attribute.FpClass.nnorm

常量

第 2408 行

std.zig.llvm.Builder.Attribute.FpClass.norm

常量

第 2407 行

std.zig.llvm.Builder.Attribute.FpClass.nsub

常量

第 2404 行

std.zig.llvm.Builder.Attribute.FpClass.nzero

常量

第 2400 行

std.zig.llvm.Builder.Attribute.FpClass.pinf

常量

第 2397 行

std.zig.llvm.Builder.Attribute.FpClass.pnorm

常量

第 2409 行

std.zig.llvm.Builder.Attribute.FpClass.psub

常量

第 2405 行

std.zig.llvm.Builder.Attribute.FpClass.pzero

常量

第 2401 行

std.zig.llvm.Builder.Attribute.FpClass.qnan

常量

第 2393 行

std.zig.llvm.Builder.Attribute.FpClass.snan

常量

第 2392 行

std.zig.llvm.Builder.Attribute.FpClass.sub

常量

第 2403 行

std.zig.llvm.Builder.Attribute.FpClass.zero

常量

第 2399 行

std.zig.llvm.Builder.Attribute.getKind

函数

第 2493 行

pub fn getKind(self: Attribute) Kind

参数

self: Attribute

std.zig.llvm.Builder.Attribute.Index

容器

第 1854 行

字段

_

std.zig.llvm.Builder.Attribute.Index.fmt

函数

第 2118 行

pub fn fmt(self: Index, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format)

参数

self: Index
builder: *const Builder
flags: FormatData.Flags

std.zig.llvm.Builder.Attribute.Index.format

函数

第 1904 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Attribute.Index.FormatData

容器

第 1895 行

字段

attribute_index: Index
builder: *const Builder
flags: Flags = .{}

std.zig.llvm.Builder.Attribute.Index.FormatData.Flags

容器

第 1899 行

字段

pound: bool = false
quote: bool = false

std.zig.llvm.Builder.Attribute.Index.getKind

函数

第 1857 行

pub fn getKind(self: Index, builder: *const Builder) Kind

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Attribute.Index.toAttribute

函数

第 1861 行

pub fn toAttribute(self: Index, builder: *const Builder) Attribute

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Attribute.Index.toStorage

函数

第 2122 行

fn toStorage(self: Index, builder: *const Builder) Storage

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Attribute.Kind

容器

第 2127 行

字段

zeroext = @backingInt(ATTR_KIND.Z_EXT)
signext = @backingInt(ATTR_KIND.S_EXT)
noext = @backingInt(ATTR_KIND.NO_EXT)
inreg = @backingInt(ATTR_KIND.IN_REG)
byval = @backingInt(ATTR_KIND.BY_VAL)
byref = @backingInt(ATTR_KIND.BYREF)
preallocated = @backingInt(ATTR_KIND.PREALLOCATED)
inalloca = @backingInt(ATTR_KIND.IN_ALLOCA)
sret = @backingInt(ATTR_KIND.STRUCT_RET)
elementtype = @backingInt(ATTR_KIND.ELEMENTTYPE)
@"align" = @backingInt(ATTR_KIND.ALIGNMENT)
@"noalias" = @backingInt(ATTR_KIND.NO_ALIAS)
nocapture = @backingInt(ATTR_KIND.NO_CAPTURE)
captures = @backingInt(ATTR_KIND.CAPTURES)
nofree = @backingInt(ATTR_KIND.NOFREE)
nest = @backingInt(ATTR_KIND.NEST)
returned = @backingInt(ATTR_KIND.RETURNED)
nonnull = @backingInt(ATTR_KIND.NON_NULL)
dereferenceable = @backingInt(ATTR_KIND.DEREFERENCEABLE)
dereferenceable_or_null = @backingInt(ATTR_KIND.DEREFERENCEABLE_OR_NULL)
swiftself = @backingInt(ATTR_KIND.SWIFT_SELF)
swiftasync = @backingInt(ATTR_KIND.SWIFT_ASYNC)
swifterror = @backingInt(ATTR_KIND.SWIFT_ERROR)
immarg = @backingInt(ATTR_KIND.IMMARG)
noundef = @backingInt(ATTR_KIND.NOUNDEF)
nofpclass = @backingInt(ATTR_KIND.NOFPCLASS)
alignstack = @backingInt(ATTR_KIND.STACK_ALIGNMENT)
allocalign = @backingInt(ATTR_KIND.ALLOC_ALIGN)
allocptr = @backingInt(ATTR_KIND.ALLOCATED_POINTER)
readnone = @backingInt(ATTR_KIND.READ_NONE)
readonly = @backingInt(ATTR_KIND.READ_ONLY)
writeonly = @backingInt(ATTR_KIND.WRITEONLY)
writable = @backingInt(ATTR_KIND.WRITABLE)
initializes = @backingInt(ATTR_KIND.INITIALIZES)
dead_on_unwind = @backingInt(ATTR_KIND.DEAD_ON_UNWIND)
dead_on_return = @backingInt(ATTR_KIND.DEAD_ON_RETURN)
range = @backingInt(ATTR_KIND.RANGE)
allockind = @backingInt(ATTR_KIND.ALLOC_KIND)
allocsize = @backingInt(ATTR_KIND.ALLOC_SIZE)
alwaysinline = @backingInt(ATTR_KIND.ALWAYS_INLINE)
builtin = @backingInt(ATTR_KIND.BUILTIN)
cold = @backingInt(ATTR_KIND.COLD)
convergent = @backingInt(ATTR_KIND.CONVERGENT)
disable_sanitizer_instrumentation = @backingInt(ATTR_KIND.DISABLE_SANITIZER_INSTRUMENTATION)
fn_ret_thunk_extern = @backingInt(ATTR_KIND.FNRETTHUNK_EXTERN)
hot = @backingInt(ATTR_KIND.HOT)
inlinehint = @backingInt(ATTR_KIND.INLINE_HINT)
jumptable = @backingInt(ATTR_KIND.JUMP_TABLE)
memory = @backingInt(ATTR_KIND.MEMORY)
minsize = @backingInt(ATTR_KIND.MIN_SIZE)
naked = @backingInt(ATTR_KIND.NAKED)
nobuiltin = @backingInt(ATTR_KIND.NO_BUILTIN)
nocallback = @backingInt(ATTR_KIND.NO_CALLBACK)
nodivergencesource = @backingInt(ATTR_KIND.NO_DIVERGENCE_SOURCE)
noduplicate = @backingInt(ATTR_KIND.NO_DUPLICATE)
noimplicitfloat = @backingInt(ATTR_KIND.NO_IMPLICIT_FLOAT)
@"noinline" = @backingInt(ATTR_KIND.NO_INLINE)
nomerge = @backingInt(ATTR_KIND.NO_MERGE)
nonlazybind = @backingInt(ATTR_KIND.NON_LAZY_BIND)
noprofile = @backingInt(ATTR_KIND.NO_PROFILE)
skipprofile = @backingInt(ATTR_KIND.SKIP_PROFILE)
noredzone = @backingInt(ATTR_KIND.NO_RED_ZONE)
noreturn = @backingInt(ATTR_KIND.NO_RETURN)
norecurse = @backingInt(ATTR_KIND.NO_RECURSE)
willreturn = @backingInt(ATTR_KIND.WILLRETURN)
nosync = @backingInt(ATTR_KIND.NOSYNC)
nounwind = @backingInt(ATTR_KIND.NO_UNWIND)
nosanitize_bounds = @backingInt(ATTR_KIND.NO_SANITIZE_BOUNDS)
nosanitize_coverage = @backingInt(ATTR_KIND.NO_SANITIZE_COVERAGE)
null_pointer_is_valid = @backingInt(ATTR_KIND.NULL_POINTER_IS_VALID)
optdebug = @backingInt(ATTR_KIND.OPTIMIZE_FOR_DEBUGGING)
optforfuzzing = @backingInt(ATTR_KIND.OPT_FOR_FUZZING)
optnone = @backingInt(ATTR_KIND.OPTIMIZE_NONE)
optsize = @backingInt(ATTR_KIND.OPTIMIZE_FOR_SIZE)
returns_twice = @backingInt(ATTR_KIND.RETURNS_TWICE)
safestack = @backingInt(ATTR_KIND.SAFESTACK)
sanitize_address = @backingInt(ATTR_KIND.SANITIZE_ADDRESS)
sanitize_memory = @backingInt(ATTR_KIND.SANITIZE_MEMORY)
sanitize_thread = @backingInt(ATTR_KIND.SANITIZE_THREAD)
sanitize_hwaddress = @backingInt(ATTR_KIND.SANITIZE_HWADDRESS)
sanitize_memtag = @backingInt(ATTR_KIND.SANITIZE_MEMTAG)
sanitize_realtime = @backingInt(ATTR_KIND.SANITIZE_REALTIME)
sanitize_realtime_blocking = @backingInt(ATTR_KIND.SANITIZE_REALTIME_BLOCKING)
sanitize_alloc_token = @backingInt(ATTR_KIND.SANITIZE_ALLOC_TOKEN)
speculative_load_hardening = @backingInt(ATTR_KIND.SPECULATIVE_LOAD_HARDENING)
speculatable = @backingInt(ATTR_KIND.SPECULATABLE)
ssp = @backingInt(ATTR_KIND.STACK_PROTECT)
sspstrong = @backingInt(ATTR_KIND.STACK_PROTECT_STRONG)
sspreq = @backingInt(ATTR_KIND.STACK_PROTECT_REQ)
strictfp = @backingInt(ATTR_KIND.STRICT_FP)
denormal_fpenv = @backingInt(ATTR_KIND.DENORMAL_FPENV)
uwtable = @backingInt(ATTR_KIND.UW_TABLE)
nocf_check = @backingInt(ATTR_KIND.NOCF_CHECK)
shadowcallstack = @backingInt(ATTR_KIND.SHADOWCALLSTACK)
mustprogress = @backingInt(ATTR_KIND.MUSTPROGRESS)
vscale_range = @backingInt(ATTR_KIND.VSCALE_RANGE)
nooutline = @backingInt(ATTR_KIND.NOOUTLINE)
nocreateundeforpoison = @backingInt(ATTR_KIND.NO_CREATE_UNDEF_OR_POISON)
string = maxInt(u31)
none = maxInt(u32)
_

std.zig.llvm.Builder.Attribute.Kind.ATTR_KIND

容器

第 2253 行

enum AttributeKindCodes

字段

ALIGNMENT = 1
ALWAYS_INLINE = 2
BY_VAL = 3
INLINE_HINT = 4
IN_REG = 5
MIN_SIZE = 6
NAKED = 7
NEST = 8
NO_ALIAS = 9
NO_BUILTIN = 10
NO_CAPTURE = 11
NO_DUPLICATE = 12
NO_IMPLICIT_FLOAT = 13
NO_INLINE = 14
NON_LAZY_BIND = 15
NO_RED_ZONE = 16
NO_RETURN = 17
NO_UNWIND = 18
OPTIMIZE_FOR_SIZE = 19
READ_NONE = 20
READ_ONLY = 21
RETURNED = 22
RETURNS_TWICE = 23
S_EXT = 24
STACK_ALIGNMENT = 25
STACK_PROTECT = 26
STACK_PROTECT_REQ = 27
STACK_PROTECT_STRONG = 28
STRUCT_RET = 29
SANITIZE_ADDRESS = 30
SANITIZE_THREAD = 31
SANITIZE_MEMORY = 32
UW_TABLE = 33
Z_EXT = 34
BUILTIN = 35
COLD = 36
OPTIMIZE_NONE = 37
IN_ALLOCA = 38
NON_NULL = 39
JUMP_TABLE = 40
DEREFERENCEABLE = 41
DEREFERENCEABLE_OR_NULL = 42
CONVERGENT = 43
SAFESTACK = 44
ARGMEMONLY = 45
SWIFT_SELF = 46
SWIFT_ERROR = 47
NO_RECURSE = 48
INACCESSIBLEMEM_ONLY = 49
INACCESSIBLEMEM_OR_ARGMEMONLY = 50
ALLOC_SIZE = 51
WRITEONLY = 52
SPECULATABLE = 53
STRICT_FP = 54
SANITIZE_HWADDRESS = 55
NOCF_CHECK = 56
OPT_FOR_FUZZING = 57
SHADOWCALLSTACK = 58
SPECULATIVE_LOAD_HARDENING = 59
IMMARG = 60
WILLRETURN = 61
NOFREE = 62
NOSYNC = 63
SANITIZE_MEMTAG = 64
PREALLOCATED = 65
NO_MERGE = 66
NULL_POINTER_IS_VALID = 67
NOUNDEF = 68
BYREF = 69
MUSTPROGRESS = 70
NO_CALLBACK = 71
HOT = 72
NO_PROFILE = 73
VSCALE_RANGE = 74
SWIFT_ASYNC = 75
NO_SANITIZE_COVERAGE = 76
ELEMENTTYPE = 77
DISABLE_SANITIZER_INSTRUMENTATION = 78
NO_SANITIZE_BOUNDS = 79
ALLOC_ALIGN = 80
ALLOCATED_POINTER = 81
ALLOC_KIND = 82
PRESPLIT_COROUTINE = 83
FNRETTHUNK_EXTERN = 84
SKIP_PROFILE = 85
MEMORY = 86
NOFPCLASS = 87
OPTIMIZE_FOR_DEBUGGING = 88
WRITABLE = 89
CORO_ONLY_DESTROY_WHEN_COMPLETE = 90
DEAD_ON_UNWIND = 91
RANGE = 92
SANITIZE_NUMERICAL_STABILITY = 93
INITIALIZES = 94
HYBRID_PATCHABLE = 95
SANITIZE_REALTIME = 96
SANITIZE_REALTIME_BLOCKING = 97
CORO_ELIDE_SAFE = 98
NO_EXT = 99
NO_DIVERGENCE_SOURCE = 100
SANITIZE_TYPE = 101
CAPTURES = 102
DEAD_ON_RETURN = 103
SANITIZE_ALLOC_TOKEN = 104
NO_CREATE_UNDEF_OR_POISON = 105
DENORMAL_FPENV = 106
NOOUTLINE = 107
FLATTEN = 108

std.zig.llvm.Builder.Attribute.Kind.fromString

函数

第 2239 行

pub fn fromString(str: String) Kind

参数

str: String

std.zig.llvm.Builder.Attribute.Kind.len

常量

第 2237 行

std.zig.llvm.Builder.Attribute.Kind.toString

函数

第 2246 行

fn toString(self: Kind) ?String

参数

self: Kind

std.zig.llvm.Builder.Attribute.Memory

容器

第 2459 行

字段

argmem: Effect = .none
inaccessiblemem: Effect = .none
other: Effect = .none
_: u26 = 0

std.zig.llvm.Builder.Attribute.Memory.all

函数

第 2467 行

fn all(effect: Effect) Memory

参数

effect: Effect

std.zig.llvm.Builder.Attribute.Memory.Effect

容器

第 2465 行

字段

none
read
write
readwrite

std.zig.llvm.Builder.Attribute.Storage

容器

第 2500 行

字段

kind: Kind
value: u32

std.zig.llvm.Builder.Attribute.toStorage

函数

第 2505 行

fn toStorage(self: Attribute) Storage

参数

self: Attribute

std.zig.llvm.Builder.Attribute.UwTable

容器

第 2472 行

字段

none
sync
async

std.zig.llvm.Builder.Attribute.UwTable.default

常量

第 2477 行

std.zig.llvm.Builder.Attribute.VScaleRange

容器

第 2480 行

字段

min: Alignment
max: Alignment
_: u20 = 0

std.zig.llvm.Builder.Attribute.VScaleRange.toLlvm

类型函数

第 2485 行

fn toLlvm(self: VScaleRange) packed struct(u64) { max: u32, min: u32 }

参数

self: VScaleRange

std.zig.llvm.Builder.Attributes

容器

第 2527 行

字段

none
_

std.zig.llvm.Builder.Attributes.fmt

函数

第 2550 行

pub fn fmt(self: Attributes, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format)

参数

self: Attributes
builder: *const Builder
flags: FormatData.Flags

std.zig.llvm.Builder.Attributes.format

函数

第 2543 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Attributes.FormatData

容器

第 2537 行

字段

attributes: Attributes
builder: *const Builder
flags: Flags = .{}

std.zig.llvm.Builder.Attributes.FormatData.Flags

别名

第 2541 行

别名目标 std.zig.llvm.Builder.Attribute.Index.FormatData.Flags

std.zig.llvm.Builder.Attributes.slice

函数

第 2531 行

pub fn slice(self: Attributes, builder: *const Builder) []const Attribute.Index

参数

self: Attributes
builder: *const Builder

std.zig.llvm.Builder.attrs

函数

第 10201 行

pub fn attrs(self: *Builder, attributes: []Attribute.Index) Allocator.Error!Attributes

参数

self: *Builder
attributes: []Attribute.Index

错误

OutOfMemory

std.zig.llvm.Builder.attrs.lessThan

函数

第 10203 行

pub fn lessThan(builder: *const Builder, lhs: Attribute.Index, rhs: Attribute.Index) bool

参数

builder: *const Builder
lhs: Attribute.Index
rhs: Attribute.Index

std.zig.llvm.Builder.bfloatConst

函数

第 10520 行

pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant

参数

self: *Builder
val: f32

错误

OutOfMemory

std.zig.llvm.Builder.bfloatConstAssumeCapacity

函数

第 12367 行

fn bfloatConstAssumeCapacity(self: *Builder, val: f32) Constant

参数

self: *Builder
val: f32

std.zig.llvm.Builder.bfloatValue

函数

第 10525 行

pub fn bfloatValue(self: *Builder, value: f32) Allocator.Error!Value

参数

self: *Builder
value: f32

错误

OutOfMemory

std.zig.llvm.Builder.bigIntConst

函数

第 10466 行

pub fn bigIntConst(self: *Builder, ty: Type, value: std.math.big.int.Const) Allocator.Error!Constant

参数

self: *Builder
ty: Type
value: std.math.big.int.Const

错误

OutOfMemory

std.zig.llvm.Builder.bigIntConstAssumeCapacity

函数

第 12290 行

fn bigIntConstAssumeCapacity( self: *Builder, ty: Type, value: std.math.big.int.Const, ) Allocator.Error!Constant

参数

self: *Builder
ty: Type
value: std.math.big.int.Const

错误

OutOfMemory

std.zig.llvm.Builder.bigIntConstAssumeCapacity.eql

函数

第 12329 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.bigIntConstAssumeCapacity.hash

函数

第 12323 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.bigIntValue

函数

第 10473 行

pub fn bigIntValue(self: *Builder, ty: Type, value: std.math.big.int.Const) Allocator.Error!Value

参数

self: *Builder
ty: Type
value: std.math.big.int.Const

错误

OutOfMemory

std.zig.llvm.Builder.BinaryOpcode

容器

第 907 行

字段

add = 0
sub = 1
mul = 2
udiv = 3
sdiv = 4
urem = 5
srem = 6
shl = 7
lshr = 8
ashr = 9
@"and" = 10
@"or" = 11
xor = 12

std.zig.llvm.Builder.binConst

函数

第 10754 行

pub fn binConst( self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant, ) Allocator.Error!Constant

参数

self: *Builder
tag: Constant.Tag
lhs: Constant
rhs: Constant

错误

OutOfMemory

std.zig.llvm.Builder.binConstAssumeCapacity

函数

第 12969 行

fn binConstAssumeCapacity( self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant, ) Constant

参数

self: *Builder
tag: Constant.Tag
lhs: Constant
rhs: Constant

std.zig.llvm.Builder.binConstAssumeCapacity.eql

函数

第 12996 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.binConstAssumeCapacity.hash

函数

第 12990 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.binValue

函数

第 10764 行

pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant) Allocator.Error!Value

参数

self: *Builder
tag: Constant.Tag
lhs: Constant
rhs: Constant

错误

OutOfMemory

std.zig.llvm.Builder.bitcode_writer

别名

第 13 行

别名目标 std.zig.llvm.bitcode_writer

std.zig.llvm.Builder.blockAddrConst

函数

第 10669 行

pub fn blockAddrConst( self: *Builder, function: Function.Index, block: Function.Block.Index, ) Allocator.Error!Constant

参数

self: *Builder
function: Function.Index
block: Function.Block.Index

错误

OutOfMemory

std.zig.llvm.Builder.blockAddrConstAssumeCapacity

函数

第 12714 行

fn blockAddrConstAssumeCapacity( self: *Builder, function: Function.Index, block: Function.Block.Index, ) Constant

参数

self: *Builder
function: Function.Index
block: Function.Block.Index

std.zig.llvm.Builder.blockAddrConstAssumeCapacity.eql

函数

第 12727 行

pub fn eql(ctx: @This(), lhs_key: Constant.BlockAddress, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Constant.BlockAddress
_: void
rhs_index: usize

std.zig.llvm.Builder.blockAddrConstAssumeCapacity.hash

函数

第 12721 行

pub fn hash(_: @This(), key: Constant.BlockAddress) u32

参数

_: @This()
key: Constant.BlockAddress

std.zig.llvm.Builder.blockAddrValue

函数

第 10678 行

pub fn blockAddrValue( self: *Builder, function: Function.Index, block: Function.Block.Index, ) Allocator.Error!Value

参数

self: *Builder
function: Function.Index
block: Function.Block.Index

错误

OutOfMemory

std.zig.llvm.Builder.Builder

别名

第 2 行

别名目标 std.zig.llvm.Builder

std.zig.llvm.Builder.builtin

常量

第 1 行

std.zig.llvm.Builder.CallConv

容器

第 3030 行

字段

ccc
fastcc = 8
coldcc
ghccc
webkit_jscc = 12
anyregcc
preserve_mostcc
preserve_allcc
swiftcc
cxx_fast_tlscc
tailcc
cfguard_checkcc
swifttailcc
preserve_nonecc
x86_stdcallcc = 64
x86_fastcallcc
arm_apcscc
arm_aapcscc
arm_aapcs_vfpcc
msp430_intrcc
x86_thiscallcc
ptx_kernel
ptx_device
spir_func = 75
spir_kernel
intel_ocl_bicc
x86_64_sysvcc
win64cc
x86_vectorcallcc
hhvmcc
hhvm_ccc
x86_intrcc
avr_intrcc
avr_signalcc
avr_builtincc
amdgpu_vs = 87
amdgpu_gs
amdgpu_ps
amdgpu_cs
amdgpu_kernel
x86_regcallcc
amdgpu_hs
msp430_builtincc
amdgpu_ls = 95
amdgpu_es
aarch64_vector_pcs
aarch64_sve_vector_pcs
amdgpu_gfx = 100
m68k_intrcc
aarch64_sme_preservemost_from_x0 = 102
aarch64_sme_preservemost_from_x2
m68k_rtdcc = 106
riscv_vectorcallcc = 110
_

std.zig.llvm.Builder.CallConv.default

常量

第 3098 行

std.zig.llvm.Builder.CallConv.format

函数

第 3100 行

pub fn format(self: CallConv, w: *Writer) Writer.Error!void

参数

self: CallConv
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.castConst

函数

第 10721 行

pub fn castConst(self: *Builder, tag: Constant.Tag, val: Constant, ty: Type) Allocator.Error!Constant

参数

self: *Builder
tag: Constant.Tag
val: Constant
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.castConstAssumeCapacity

函数

第 12847 行

fn castConstAssumeCapacity(self: *Builder, tag: Constant.Tag, val: Constant, ty: Type) Constant

参数

self: *Builder
tag: Constant.Tag
val: Constant
ty: Type

std.zig.llvm.Builder.castConstAssumeCapacity.eql

函数

第 12857 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.castConstAssumeCapacity.hash

函数

第 12851 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.CastOpcode

容器

第 923 行

字段

trunc = 0
zext = 1
sext = 2
fptoui = 3
fptosi = 4
uitofp = 5
sitofp = 6
fptrunc = 7
fpext = 8
ptrtoint = 9
inttoptr = 10
bitcast = 11
addrspacecast = 12

std.zig.llvm.Builder.castValue

函数

第 10726 行

pub fn castValue(self: *Builder, tag: Constant.Tag, val: Constant, ty: Type) Allocator.Error!Value

参数

self: *Builder
tag: Constant.Tag
val: Constant
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.clearAndFree

函数

第 9956 行

pub fn clearAndFree(self: *Builder) void

参数

self: *Builder

std.zig.llvm.Builder.CmpPredicate

容器

第 939 行

字段

fcmp_false = 0
fcmp_oeq = 1
fcmp_ogt = 2
fcmp_oge = 3
fcmp_olt = 4
fcmp_ole = 5
fcmp_one = 6
fcmp_ord = 7
fcmp_uno = 8
fcmp_ueq = 9
fcmp_ugt = 10
fcmp_uge = 11
fcmp_ult = 12
fcmp_ule = 13
fcmp_une = 14
fcmp_true = 15
icmp_eq = 32
icmp_ne = 33
icmp_ugt = 34
icmp_uge = 35
icmp_ult = 36
icmp_ule = 37
icmp_sgt = 38
icmp_sge = 39
icmp_slt = 40
icmp_sle = 41

std.zig.llvm.Builder.Constant

容器

第 8356 行

字段

false
true
@"0"
@"1"
none
no_init = (1 << 30) - 1
_

std.zig.llvm.Builder.Constant.Aggregate

容器

第 8483 行

字段

type: Type

std.zig.llvm.Builder.Constant.Assembly

容器

第 8532 行

字段

type: Type
assembly: String
constraints: String

std.zig.llvm.Builder.Constant.Assembly.Info

容器

第 8537 行

字段

sideeffect: bool = false
alignstack: bool = false
inteldialect: bool = false
unwind: bool = false

std.zig.llvm.Builder.Constant.Binary

容器

第 8527 行

字段

lhs: Constant
rhs: Constant

std.zig.llvm.Builder.Constant.BlockAddress

容器

第 8493 行

字段

function: Function.Index
block: Function.Block.Index

std.zig.llvm.Builder.Constant.Cast

容器

第 8498 行

字段

val: Constant
type: Type

std.zig.llvm.Builder.Constant.Cast.Signedness

容器

第 8502 行

字段

unsigned
signed
unneeded

std.zig.llvm.Builder.Constant.Cast.Signedness.fromStdLang

函数

第 8507 行

pub fn fromStdLang(signedness: std.lang.Signedness) Signedness

参数

signedness: std.lang.Signedness

std.zig.llvm.Builder.Constant.Double

容器

第 8465 行

字段

lo: u32
hi: u32

std.zig.llvm.Builder.Constant.first_global

常量

第 8365 行

Constant

std.zig.llvm.Builder.Constant.fmt

函数

第 9002 行

pub fn fmt(self: Constant, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format)

参数

self: Constant
builder: *Builder
flags: FormatFlags

std.zig.llvm.Builder.Constant.format

函数

第 8736 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Constant.format.expected_limbs

常量

第 8769 行

std.zig.llvm.Builder.Constant.format.Repr

类型函数

第 8800 行

fn Repr(comptime T: type) type

参数

T: type

字段

mantissa: @Int(.unsigned, std.math.floatMantissaBits(T))
exponent: @Int(.unsigned, std.math.floatExponentBits(T))
sign: u1

std.zig.llvm.Builder.Constant.FormatData

容器

第 8731 行

字段

constant: Constant
builder: *Builder
flags: FormatFlags

std.zig.llvm.Builder.Constant.Fp128

容器

第 8476 行

字段

lo_lo: u32
lo_hi: u32
hi_lo: u32
hi_hi: u32

std.zig.llvm.Builder.Constant.Fp80

容器

第 8470 行

字段

lo_lo: u32
lo_hi: u32
hi: u32

std.zig.llvm.Builder.Constant.getBase

函数

第 8696 行

pub fn getBase(self: Constant, builder: *const Builder) Global.Index

参数

self: Constant
builder: *const Builder

std.zig.llvm.Builder.Constant.GetElementPtr

容器

第 8516 行

字段

type: Type
base: Constant
info: Info

std.zig.llvm.Builder.Constant.GetElementPtr.Info

容器

第 8524 行

字段

indices_len: u16
inrange: InRangeIndex

std.zig.llvm.Builder.Constant.GetElementPtr.InRangeIndex

容器

第 8523 行

字段

none = maxInt(u16)
_

std.zig.llvm.Builder.Constant.GetElementPtr.Kind

容器

第 8522 行

字段

normal
inbounds

std.zig.llvm.Builder.Constant.Integer

容器

第 8458 行

字段

type: Type
limbs_len: u32

std.zig.llvm.Builder.Constant.Integer.limbs

常量

第 8462 行

std.zig.llvm.Builder.Constant.isZeroInit

函数

第 8655 行

pub fn isZeroInit(self: Constant, builder: *const Builder) bool

参数

self: Constant
builder: *const Builder

std.zig.llvm.Builder.Constant.Item

容器

第 8451 行

字段

tag: Tag
data: ExtraIndex

std.zig.llvm.Builder.Constant.Item.ExtraIndex

类型

第 8455 行

std.zig.llvm.Builder.Constant.Splat

容器

第 8488 行

字段

type: Type
value: Constant

std.zig.llvm.Builder.Constant.Tag

容器

第 8367 行

字段

positive_integer
negative_integer
half
bfloat
float
double
fp128
x86_fp80
ppc_fp128
null
none
structure
packed_structure
array
string
vector
splat
zeroinitializer
undef
poison
blockaddress
dso_local_equivalent
no_cfi
trunc
ptrtoint
inttoptr
bitcast
addrspacecast
getelementptr
@"getelementptr inbounds"
add
@"add nsw"
@"add nuw"
sub
@"sub nsw"
@"sub nuw"
shl
xor
@"asm"
@"asm sideeffect"
@"asm alignstack"
@"asm sideeffect alignstack"
@"asm inteldialect"
@"asm sideeffect inteldialect"
@"asm alignstack inteldialect"
@"asm sideeffect alignstack inteldialect"
@"asm unwind"
@"asm sideeffect unwind"
@"asm alignstack unwind"
@"asm sideeffect alignstack unwind"
@"asm inteldialect unwind"
@"asm sideeffect inteldialect unwind"
@"asm alignstack inteldialect unwind"
@"asm sideeffect alignstack inteldialect unwind"

std.zig.llvm.Builder.Constant.Tag.toBinaryOpcode

函数

第 8423 行

pub fn toBinaryOpcode(self: Tag) BinaryOpcode

参数

self: Tag

std.zig.llvm.Builder.Constant.Tag.toCastOpcode

函数

第 8439 行

pub fn toCastOpcode(self: Tag) CastOpcode

参数

self: Tag

std.zig.llvm.Builder.Constant.toValue

函数

第 8555 行

pub fn toValue(self: Constant) Value

参数

self: Constant

std.zig.llvm.Builder.Constant.typeOf

函数

第 8559 行

pub fn typeOf(self: Constant, builder: *Builder) Type

参数

self: Constant
builder: *Builder

std.zig.llvm.Builder.Constant.unwrap

类型函数

第 8545 行

pub fn unwrap(self: Constant) union(enum) { constant: u30, global: Global.Index, }

参数

self: Constant

std.zig.llvm.Builder.constantExtraData

函数

第 13201 行

fn constantExtraData(self: *const Builder, comptime T: type, index: Constant.Item.ExtraIndex) T

参数

self: *const Builder
T: type
index: Constant.Item.ExtraIndex

std.zig.llvm.Builder.constantExtraDataTrail

类型函数

第 13177 行

fn constantExtraDataTrail( self: *const Builder, comptime T: type, index: Constant.Item.ExtraIndex, ) struct { data: T, trail: ConstantExtraDataTrail }

参数

self: *const Builder
T: type
index: Constant.Item.ExtraIndex

std.zig.llvm.Builder.ConstantExtraDataTrail

容器

第 13156 行

字段

std.zig.llvm.Builder.ConstantExtraDataTrail.next

函数

第 13165 行

fn next( self: *ConstantExtraDataTrail, len: u32, comptime Item: type, builder: *const Builder, ) []const Item

参数

self: *ConstantExtraDataTrail
len: u32
Item: type
builder: *const Builder

std.zig.llvm.Builder.ConstantExtraDataTrail.nextMut

函数

第 13159 行

fn nextMut(self: *ConstantExtraDataTrail, len: u32, comptime Item: type, builder: *Builder) []Item

参数

self: *ConstantExtraDataTrail
len: u32
Item: type
builder: *Builder

std.zig.llvm.Builder.convConst

函数

第 10704 行

pub fn convConst( self: *Builder, val: Constant, ty: Type, ) Allocator.Error!Constant

参数

self: *Builder
val: Constant
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.convConstAssumeCapacity

函数

第 12837 行

fn convConstAssumeCapacity( self: *Builder, val: Constant, ty: Type, ) Constant

参数

self: *Builder
val: Constant
ty: Type

std.zig.llvm.Builder.convConstTag

函数

第 12813 行

fn convConstTag( self: *Builder, val_ty: Type, ty: Type, ) Constant.Tag

参数

self: *Builder
val_ty: Type
ty: Type

std.zig.llvm.Builder.convTag

函数

第 12761 行

fn convTag( self: *Builder, signedness: Constant.Cast.Signedness, val_ty: Type, ty: Type, ) Function.Instruction.Tag

参数

self: *Builder
signedness: Constant.Cast.Signedness
val_ty: Type
ty: Type

std.zig.llvm.Builder.convValue

函数

第 10713 行

pub fn convValue( self: *Builder, val: Constant, ty: Type, ) Allocator.Error!Value

参数

self: *Builder
val: Constant
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.DataLayout

容器

第 383 行

字段

endian: ?std.lang.Endian
int_specs: PrimitiveSpec.Map
float_specs: PrimitiveSpec.Map
vector_specs: PrimitiveSpec.Map
pointer_specs: PointerSpec.Map
string_repr: String

std.zig.llvm.Builder.DataLayout.default_float_specs

常量

第 592 行

[]const PrimitiveSpec

std.zig.llvm.Builder.DataLayout.default_int_specs

常量

第 586 行

[]const PrimitiveSpec

std.zig.llvm.Builder.DataLayout.default_vector_specs

常量

第 598 行

[]const PrimitiveSpec

std.zig.llvm.Builder.DataLayout.deinit

函数

第 780 行

pub fn deinit(data_layout: *DataLayout, gpa: Allocator) void

参数

data_layout: *DataLayout
gpa: Allocator

std.zig.llvm.Builder.DataLayout.getFloatSpec

函数

第 798 行

pub fn getFloatSpec(data_layout: *const DataLayout, bit_width: PrimitiveSpec.BitWidth) PrimitiveSpec

参数

data_layout: *const DataLayout
bit_width: PrimitiveSpec.BitWidth

std.zig.llvm.Builder.DataLayout.getIntegerSpec

函数

第 787 行

pub fn getIntegerSpec(data_layout: *const DataLayout, bit_width: PrimitiveSpec.BitWidth) PrimitiveSpec

参数

data_layout: *const DataLayout
bit_width: PrimitiveSpec.BitWidth

std.zig.llvm.Builder.DataLayout.getIntegerSpec.order

函数

第 791 行

fn order(ctx: PrimitiveSpec.BitWidth, spec: PrimitiveSpec) std.math.Order

参数

std.zig.llvm.Builder.DataLayout.getPointerSpec

函数

第 828 行

pub fn getPointerSpec(data_layout: *const DataLayout, addr_space: AddrSpace) PointerSpec

参数

data_layout: *const DataLayout
addr_space: AddrSpace

std.zig.llvm.Builder.DataLayout.getVectorSpec

函数

第 810 行

pub fn getVectorSpec( data_layout: *const DataLayout, bit_width: PrimitiveSpec.BitWidth, store_size: Type.Size, ) PrimitiveSpec

参数

data_layout: *const DataLayout
bit_width: PrimitiveSpec.BitWidth
store_size: Type.Size

std.zig.llvm.Builder.DataLayout.parseString

函数

第 603 行

pub fn parseString(string_repr: String, builder: *Builder) Allocator.Error!DataLayout

参数

string_repr: String
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.DataLayout.parseString.lessThan

函数

第 751 行

pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool

参数

ctx: @This()
lhs_index: usize
rhs_index: usize

std.zig.llvm.Builder.DataLayout.parseString.lessThan

函数

第 762 行

pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool

参数

ctx: @This()
lhs_index: usize
rhs_index: usize

std.zig.llvm.Builder.DataLayout.PointerSpec

容器

第 411 行

字段

bit_width: BitWidth
index_bit_width: BitWidth
flags: packed struct(u32) {
    abi_align: Alignment,
    pref_align: Alignment,
    has_unstable_repr: bool,
    has_external_state: bool,
    null_ptr_repr: NullPtrRepr,
    unused: u17 = 0,
}
addr_space_name: String

std.zig.llvm.Builder.DataLayout.PointerSpec.BitWidth

类型

第 424 行

std.zig.llvm.Builder.DataLayout.PointerSpec.Map

类型

第 428 行

std.zig.llvm.Builder.DataLayout.PointerSpec.NullPtrRepr

容器

第 426 行

字段

all_zeros
all_ones

std.zig.llvm.Builder.DataLayout.PrimitiveSpec

容器

第 391 行

字段

bit_width: BitWidth
abi_align: Alignment
pref_align: Alignment

std.zig.llvm.Builder.DataLayout.PrimitiveSpec.BitWidth

类型

第 396 行

std.zig.llvm.Builder.DataLayout.PrimitiveSpec.Context

命名空间

第 400 行

std.zig.llvm.Builder.DataLayout.PrimitiveSpec.Context.eql

函数

第 405 行

pub fn eql(_: Context, lhs_spec: PrimitiveSpec, rhs_spec: PrimitiveSpec, _: usize) bool

参数

_: Context
lhs_spec: PrimitiveSpec
rhs_spec: PrimitiveSpec
_: usize

std.zig.llvm.Builder.DataLayout.PrimitiveSpec.Context.hash

函数

第 401 行

pub fn hash(_: Context, spec: PrimitiveSpec) u32

参数

std.zig.llvm.Builder.DataLayout.PrimitiveSpec.Map

类型

第 398 行

std.zig.llvm.Builder.DataLayout.stringForTarget

函数

第 431 行

pub fn stringForTarget(target: *const std.Target) []const u8

参数

target: *const std.Target

std.zig.llvm.Builder.debugArrayType

函数

第 13537 行

pub fn debugArrayType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugArrayTypeAssumeCapacity

函数

第 14041 行

fn debugArrayTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

std.zig.llvm.Builder.debugBoolType

函数

第 13424 行

pub fn debugBoolType( self: *Builder, name: ?Metadata.String, size_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugBoolTypeAssumeCapacity

函数

第 13923 行

fn debugBoolTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

std.zig.llvm.Builder.debugCompileUnit

函数

第 13366 行

pub fn debugCompileUnit( self: *Builder, file: ?Metadata, producer: ?Metadata.String, enums: ?Metadata, globals: ?Metadata, options: Metadata.CompileUnit.Options, ) Allocator.Error!Metadata

参数

self: *Builder
file: ?Metadata
producer: ?Metadata.String
enums: ?Metadata
globals: ?Metadata
options: Metadata.CompileUnit.Options

错误

OutOfMemory

std.zig.llvm.Builder.debugCompileUnitAssumeCapacity

函数

第 13845 行

pub fn debugCompileUnitAssumeCapacity( self: *Builder, file: ?Metadata, producer: ?Metadata.String, enums: ?Metadata, globals: ?Metadata, options: Metadata.CompileUnit.Options, ) Metadata

参数

self: *Builder
file: ?Metadata
producer: ?Metadata.String
enums: ?Metadata
globals: ?Metadata
options: Metadata.CompileUnit.Options

std.zig.llvm.Builder.debugCompositeTypeAssumeCapacity

函数

第 14091 行

fn debugCompositeTypeAssumeCapacity( self: *Builder, tag: Metadata.Tag, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Metadata

参数

self: *Builder
tag: Metadata.Tag
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

std.zig.llvm.Builder.debugEnumerationType

函数

第 13513 行

pub fn debugEnumerationType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugEnumerationTypeAssumeCapacity

函数

第 14016 行

fn debugEnumerationTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

std.zig.llvm.Builder.debugEnumerator

函数

第 13662 行

pub fn debugEnumerator( self: *Builder, name: ?Metadata.String, unsigned: bool, bit_width: u32, value: std.math.big.int.Const, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
unsigned: bool
bit_width: u32
value: std.math.big.int.Const

错误

OutOfMemory

std.zig.llvm.Builder.debugEnumeratorAssumeCapacity

函数

第 14206 行

fn debugEnumeratorAssumeCapacity( self: *Builder, name: ?Metadata.String, unsigned: bool, bit_width: u32, value: std.math.big.int.Const, ) Metadata

参数

self: *Builder
name: ?Metadata.String
unsigned: bool
bit_width: u32
value: std.math.big.int.Const

std.zig.llvm.Builder.debugEnumeratorAssumeCapacity.eql

函数

第 14230 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.debugEnumeratorAssumeCapacity.hash

函数

第 14222 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.debugExpression

函数

第 13684 行

pub fn debugExpression(self: *Builder, elements: []const u32) Allocator.Error!Metadata

参数

self: *Builder
elements: []const u32

错误

OutOfMemory

std.zig.llvm.Builder.debugExpressionAssumeCapacity

函数

第 14287 行

fn debugExpressionAssumeCapacity(self: *Builder, elements: []const u32) Metadata

参数

self: *Builder
elements: []const u32

std.zig.llvm.Builder.debugExpressionAssumeCapacity.eql

函数

第 14301 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.debugExpressionAssumeCapacity.hash

函数

第 14294 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.debugFile

函数

第 13357 行

pub fn debugFile( self: *Builder, filename: ?Metadata.String, directory: ?Metadata.String, ) Allocator.Error!Metadata

参数

self: *Builder
filename: ?Metadata.String
directory: ?Metadata.String

错误

OutOfMemory

std.zig.llvm.Builder.debugFileAssumeCapacity

函数

第 13833 行

fn debugFileAssumeCapacity( self: *Builder, filename: ?Metadata.String, directory: ?Metadata.String, ) Metadata

参数

self: *Builder
filename: ?Metadata.String
directory: ?Metadata.String

std.zig.llvm.Builder.debugFloatType

函数

第 13451 行

pub fn debugFloatType( self: *Builder, name: ?Metadata.String, size_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugFloatTypeAssumeCapacity

函数

第 13950 行

fn debugFloatTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

std.zig.llvm.Builder.debugForwardReference

函数

第 13460 行

pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata

参数

self: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.debugForwardReferenceAssumeCapacity

函数

第 13959 行

fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata

参数

self: *Builder

std.zig.llvm.Builder.debugGlobalVar

函数

第 13726 行

pub fn debugGlobalVar( self: *Builder, name: ?Metadata.String, linkage_name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, ty: ?Metadata, variable: Variable.Index, options: Metadata.GlobalVar.Options, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
linkage_name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
ty: ?Metadata
variable: Variable.Index
options: Metadata.GlobalVar.Options

错误

OutOfMemory

std.zig.llvm.Builder.debugGlobalVarAssumeCapacity

函数

第 14414 行

fn debugGlobalVarAssumeCapacity( self: *Builder, name: ?Metadata.String, linkage_name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, ty: ?Metadata, variable: Variable.Index, options: Metadata.GlobalVar.Options, ) Metadata

参数

self: *Builder
name: ?Metadata.String
linkage_name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
ty: ?Metadata
variable: Variable.Index
options: Metadata.GlobalVar.Options

std.zig.llvm.Builder.debugGlobalVarExpression

函数

第 13750 行

pub fn debugGlobalVarExpression( self: *Builder, variable: ?Metadata, expression: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
variable: ?Metadata
expression: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugGlobalVarExpressionAssumeCapacity

函数

第 14440 行

fn debugGlobalVarExpressionAssumeCapacity( self: *Builder, variable: ?Metadata, expression: ?Metadata, ) Metadata

参数

self: *Builder
variable: ?Metadata
expression: ?Metadata

std.zig.llvm.Builder.debugLexicalBlock

函数

第 13402 行

pub fn debugLexicalBlock( self: *Builder, scope: ?Metadata, file: ?Metadata, line: u32, column: u32, ) Allocator.Error!Metadata

参数

self: *Builder
scope: ?Metadata
file: ?Metadata
line: u32
column: u32

错误

OutOfMemory

std.zig.llvm.Builder.debugLexicalBlockAssumeCapacity

函数

第 13891 行

fn debugLexicalBlockAssumeCapacity( self: *Builder, scope: ?Metadata, file: ?Metadata, line: u32, column: u32, ) Metadata

参数

self: *Builder
scope: ?Metadata
file: ?Metadata
line: u32
column: u32

std.zig.llvm.Builder.debugLocalVar

函数

第 13701 行

pub fn debugLocalVar( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, ty: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
ty: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugLocalVarAssumeCapacity

函数

第 14376 行

fn debugLocalVarAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, ty: ?Metadata, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
ty: ?Metadata

std.zig.llvm.Builder.debugLocation

函数

第 13413 行

pub fn debugLocation( self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
line: u32
column: u32
scope: Metadata
inlined_at: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.DebugLocation

容器

第 6317 行

字段

no_location: void
location: Location

std.zig.llvm.Builder.DebugLocation.Location

容器

第 6321 行

字段

line: u32
column: u32
scope: Builder.Metadata.Optional
inlined_at: Builder.Metadata.Optional

std.zig.llvm.Builder.DebugLocation.toMetadata

函数

第 6328 行

pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata.Optional

参数

self: DebugLocation
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.debugLocationAssumeCapacity

函数

第 13907 行

fn debugLocationAssumeCapacity( self: *Builder, line: u32, column: u32, scope: Metadata, inlined_at: ?Metadata, ) Metadata

参数

self: *Builder
line: u32
column: u32
scope: Metadata
inlined_at: ?Metadata

std.zig.llvm.Builder.debugMemberType

函数

第 13609 行

pub fn debugMemberType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, offset_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
offset_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugMemberTypeAssumeCapacity

函数

第 14145 行

fn debugMemberTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, offset_in_bits: u64, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
offset_in_bits: u64

std.zig.llvm.Builder.debugParameter

函数

第 13713 行

pub fn debugParameter( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, ty: ?Metadata, arg_no: u32, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
ty: ?Metadata
arg_no: u32

错误

OutOfMemory

std.zig.llvm.Builder.debugParameterAssumeCapacity

函数

第 14394 行

fn debugParameterAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, ty: ?Metadata, arg_no: u32, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
ty: ?Metadata
arg_no: u32

std.zig.llvm.Builder.debugPointerType

函数

第 13585 行

pub fn debugPointerType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, offset_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
offset_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugPointerTypeAssumeCapacity

函数

第 14118 行

fn debugPointerTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, offset_in_bits: u64, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
offset_in_bits: u64

std.zig.llvm.Builder.debugSignedType

函数

第 13442 行

pub fn debugSignedType( self: *Builder, name: ?Metadata.String, size_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugSignedTypeAssumeCapacity

函数

第 13941 行

fn debugSignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

std.zig.llvm.Builder.debugStructType

函数

第 13465 行

pub fn debugStructType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugStructTypeAssumeCapacity

函数

第 13966 行

fn debugStructTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

std.zig.llvm.Builder.debugSubprogram

函数

第 13378 行

pub fn debugSubprogram( self: *Builder, file: ?Metadata, name: ?Metadata.String, linkage_name: ?Metadata.String, line: u32, scope_line: u32, ty: ?Metadata, options: Metadata.Subprogram.Options, compile_unit: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
file: ?Metadata
name: ?Metadata.String
linkage_name: ?Metadata.String
line: u32
scope_line: u32
ty: ?Metadata
options: Metadata.Subprogram.Options
compile_unit: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugSubprogramAssumeCapacity

函数

第 13865 行

fn debugSubprogramAssumeCapacity( self: *Builder, file: ?Metadata, name: ?Metadata.String, linkage_name: ?Metadata.String, line: u32, scope_line: u32, ty: ?Metadata, options: Metadata.Subprogram.Options, compile_unit: ?Metadata, ) Metadata

参数

self: *Builder
file: ?Metadata
name: ?Metadata.String
linkage_name: ?Metadata.String
line: u32
scope_line: u32
ty: ?Metadata
options: Metadata.Subprogram.Options
compile_unit: ?Metadata

std.zig.llvm.Builder.debugSubrange

函数

第 13675 行

pub fn debugSubrange( self: *Builder, lower_bound: ?Metadata, count: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
lower_bound: ?Metadata
count: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugSubrangeAssumeCapacity

函数

第 14279 行

fn debugSubrangeAssumeCapacity(self: *Builder, lower_bound: ?Metadata, count: ?Metadata) Metadata

参数

self: *Builder
lower_bound: ?Metadata
count: ?Metadata

std.zig.llvm.Builder.debugSubroutineType

函数

第 13657 行

pub fn debugSubroutineType(self: *Builder, types_tuple: ?Metadata) Allocator.Error!Metadata

参数

self: *Builder
types_tuple: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugSubroutineTypeAssumeCapacity

函数

第 14199 行

fn debugSubroutineTypeAssumeCapacity(self: *Builder, types_tuple: ?Metadata) Metadata

参数

self: *Builder
types_tuple: ?Metadata

std.zig.llvm.Builder.debugTypedefType

函数

第 13633 行

pub fn debugTypedefType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, offset_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
offset_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugTypedefTypeAssumeCapacity

函数

第 14172 行

fn debugTypedefTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, offset_in_bits: u64, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
offset_in_bits: u64

std.zig.llvm.Builder.debugUnionType

函数

第 13489 行

pub fn debugUnionType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugUnionTypeAssumeCapacity

函数

第 13991 行

fn debugUnionTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

std.zig.llvm.Builder.debugUnsignedType

函数

第 13433 行

pub fn debugUnsignedType( self: *Builder, name: ?Metadata.String, size_in_bits: u64, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

错误

OutOfMemory

std.zig.llvm.Builder.debugUnsignedTypeAssumeCapacity

函数

第 13932 行

fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata

参数

self: *Builder
name: ?Metadata.String
size_in_bits: u64

std.zig.llvm.Builder.debugVectorType

函数

第 13561 行

pub fn debugVectorType( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Allocator.Error!Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

错误

OutOfMemory

std.zig.llvm.Builder.debugVectorTypeAssumeCapacity

函数

第 14066 行

fn debugVectorTypeAssumeCapacity( self: *Builder, name: ?Metadata.String, file: ?Metadata, scope: ?Metadata, line: u32, underlying_type: ?Metadata, size_in_bits: u64, align_in_bits: u64, fields_tuple: ?Metadata, ) Metadata

参数

self: *Builder
name: ?Metadata.String
file: ?Metadata
scope: ?Metadata
line: u32
underlying_type: ?Metadata
size_in_bits: u64
align_in_bits: u64
fields_tuple: ?Metadata

std.zig.llvm.Builder.deinit

函数

第 10004 行

pub fn deinit(self: *Builder) void

参数

self: *Builder

std.zig.llvm.Builder.DllStorageClass

容器

第 2777 行

字段

default = 0
dllimport = 1
dllexport = 2

std.zig.llvm.Builder.DllStorageClass.format

函数

第 2782 行

pub fn format(self: DllStorageClass, w: *Writer) Writer.Error!void

参数

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.doubleConst

函数

第 10538 行

pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant

参数

self: *Builder
val: f64

错误

OutOfMemory

std.zig.llvm.Builder.doubleConstAssumeCapacity

函数

第 12382 行

fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant

参数

self: *Builder
val: f64

std.zig.llvm.Builder.doubleConstAssumeCapacity.eql

函数

第 12391 行

pub fn eql(ctx: @This(), lhs_key: f64, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: f64
_: void
rhs_index: usize

std.zig.llvm.Builder.doubleConstAssumeCapacity.hash

函数

第 12385 行

pub fn hash(_: @This(), key: f64) u32

参数

_: @This()
key: f64

std.zig.llvm.Builder.doubleValue

函数

第 10543 行

pub fn doubleValue(self: *Builder, value: f64) Allocator.Error!Value

参数

self: *Builder
value: f64

错误

OutOfMemory

std.zig.llvm.Builder.dsoLocalEquivalentConst

函数

第 10686 行

pub fn dsoLocalEquivalentConst(self: *Builder, function: Function.Index) Allocator.Error!Constant

参数

self: *Builder
function: Function.Index

错误

OutOfMemory

std.zig.llvm.Builder.dsoLocalEquivalentConstAssumeCapacity

函数

第 12747 行

fn dsoLocalEquivalentConstAssumeCapacity(self: *Builder, function: Function.Index) Constant

参数

self: *Builder
function: Function.Index

std.zig.llvm.Builder.dsoLocalEquivalentValue

函数

第 10691 行

pub fn dsoLocalEquivalentValue(self: *Builder, function: Function.Index) Allocator.Error!Value

参数

self: *Builder
function: Function.Index

错误

OutOfMemory

std.zig.llvm.Builder.dump

函数

第 10804 行

pub fn dump(b: *Builder, io: Io) void

参数

b: *Builder
io: Io

std.zig.llvm.Builder.DW

别名

第 8 行

别名目标 std.dwarf

std.zig.llvm.Builder.ensureUnusedConstantCapacity

函数

第 13058 行

fn ensureUnusedConstantCapacity( self: *Builder, count: usize, comptime Extra: type, trail_len: usize, ) Allocator.Error!void

参数

self: *Builder
count: usize
Extra: type
trail_len: usize

错误

OutOfMemory

std.zig.llvm.Builder.ensureUnusedGlobalCapacity

函数

第 11911 行

fn ensureUnusedGlobalCapacity(self: *Builder, name: StrtabString) Allocator.Error!void

参数

self: *Builder
name: StrtabString

错误

OutOfMemory

std.zig.llvm.Builder.ensureUnusedMetadataCapacity

函数

第 13205 行

fn ensureUnusedMetadataCapacity( self: *Builder, count: usize, comptime Extra: type, trail_len: usize, ) Allocator.Error!void

参数

self: *Builder
count: usize
Extra: type
trail_len: usize

错误

OutOfMemory

std.zig.llvm.Builder.ensureUnusedTypeCapacity

函数

第 12166 行

fn ensureUnusedTypeCapacity( self: *Builder, count: usize, comptime Extra: type, trail_len: usize, ) Allocator.Error!void

参数

self: *Builder
count: usize
Extra: type
trail_len: usize

错误

OutOfMemory

std.zig.llvm.Builder.expected_args_len

常量

第 75 行

std.zig.llvm.Builder.expected_attrs_len

常量

第 76 行

std.zig.llvm.Builder.expected_cases_len

常量

第 79 行

std.zig.llvm.Builder.expected_fields_len

常量

第 77 行

std.zig.llvm.Builder.expected_gep_indices_len

常量

第 78 行

std.zig.llvm.Builder.expected_incoming_len

常量

第 80 行

std.zig.llvm.Builder.ExternallyInitialized

容器

第 2944 行

字段

default
externally_initialized

std.zig.llvm.Builder.ExternallyInitialized.format

函数

第 2948 行

pub fn format(self: ExternallyInitialized, w: *Writer) Writer.Error!void

参数

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.FastMath

容器

第 8323 行

字段

unsafe_algebra: bool = false
nnan: bool = false
ninf: bool = false
nsz: bool = false
arcp: bool = false
contract: bool = false
afn: bool = false
reassoc: bool = false

std.zig.llvm.Builder.FastMath.fast

常量

第 8333 行

std.zig.llvm.Builder.FastMathKind

容器

第 8344 行

字段

normal
fast

std.zig.llvm.Builder.FastMathKind.toCallKind

函数

第 8348 行

pub fn toCallKind(self: FastMathKind) Function.Instruction.Call.Kind

参数

self: FastMathKind

std.zig.llvm.Builder.finishModuleAsm

函数

第 10060 行

pub fn finishModuleAsm(self: *Builder, aw: *Writer.Allocating) Allocator.Error!void

参数

self: *Builder
aw: *Writer.Allocating

错误

OutOfMemory

std.zig.llvm.Builder.FloatCondition

容器

第 8194 行

字段

oeq = 1
ogt = 2
oge = 3
olt = 4
ole = 5
one = 6
ord = 7
uno = 8
ueq = 9
ugt = 10
uge = 11
ult = 12
ule = 13
une = 14

std.zig.llvm.Builder.floatConst

函数

第 10529 行

pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant

参数

self: *Builder
val: f32

错误

OutOfMemory

std.zig.llvm.Builder.floatConstAssumeCapacity

函数

第 12375 行

fn floatConstAssumeCapacity(self: *Builder, val: f32) Constant

参数

self: *Builder
val: f32

std.zig.llvm.Builder.floatValue

函数

第 10534 行

pub fn floatValue(self: *Builder, value: f32) Allocator.Error!Value

参数

self: *Builder
value: f32

错误

OutOfMemory

std.zig.llvm.Builder.fmt

函数

第 10089 行

pub fn fmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!String

参数

self: *Builder
fmt_str: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.fmtAssumeCapacity

函数

第 10096 行

pub fn fmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) String

参数

self: *Builder
fmt_str: []const u8

std.zig.llvm.Builder.fnAttrs

函数

第 10213 行

pub fn fnAttrs(self: *Builder, fn_attributes: []const Attributes) Allocator.Error!FunctionAttributes

参数

self: *Builder
fn_attributes: []const Attributes

错误

OutOfMemory

std.zig.llvm.Builder.fnType

函数

第 10119 行

pub fn fnType( self: *Builder, ret: Type, params: []const Type, kind: Type.Function.Kind, ) Allocator.Error!Type

参数

self: *Builder
ret: Type
params: []const Type
kind: Type.Function.Kind

错误

OutOfMemory

std.zig.llvm.Builder.fnTypeAssumeCapacity

函数

第 11922 行

fn fnTypeAssumeCapacity( self: *Builder, ret: Type, params: []const Type, comptime kind: Type.Function.Kind, ) Type

参数

self: *Builder
ret: Type
params: []const Type
kind: Type.Function.Kind

std.zig.llvm.Builder.fnTypeAssumeCapacity.eql

函数

第 11941 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.fnTypeAssumeCapacity.hash

函数

第 11935 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.FormatFlags

容器

第 16556 行

字段

comma: bool = false
space: bool = false
percent: bool = false

std.zig.llvm.Builder.FormatFlags.onlyPercent

函数

第 16561 行

fn onlyPercent(f: FormatFlags) bool

参数

std.zig.llvm.Builder.fp128Const

函数

第 10547 行

pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant

参数

self: *Builder
val: f128

错误

OutOfMemory

std.zig.llvm.Builder.fp128ConstAssumeCapacity

函数

第 12413 行

fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant

参数

self: *Builder
val: f128

std.zig.llvm.Builder.fp128ConstAssumeCapacity.eql

函数

第 12422 行

pub fn eql(ctx: @This(), lhs_key: f128, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: f128
_: void
rhs_index: usize

std.zig.llvm.Builder.fp128ConstAssumeCapacity.hash

函数

第 12416 行

pub fn hash(_: @This(), key: f128) u32

参数

_: @This()
key: f128

std.zig.llvm.Builder.fp128Value

函数

第 10552 行

pub fn fp128Value(self: *Builder, value: f128) Allocator.Error!Value

参数

self: *Builder
value: f128

错误

OutOfMemory

std.zig.llvm.Builder.fpConst

函数

第 10477 行

pub fn fpConst(self: *Builder, ty: Type, comptime val: comptime_float) Allocator.Error!Constant

参数

self: *Builder
ty: Type
val: comptime_float

错误

OutOfMemory

std.zig.llvm.Builder.fpValue

函数

第 10490 行

pub fn fpValue(self: *Builder, ty: Type, comptime value: comptime_float) Allocator.Error!Value

参数

self: *Builder
ty: Type
value: comptime_float

错误

OutOfMemory

std.zig.llvm.Builder.Function

容器

第 5192 行

字段

global: Global.Index
call_conv: CallConv = CallConv.default
attributes: FunctionAttributes = .none
section: String = .none
alignment: Alignment = .default
blocks: []const Block = &.{}
instructions: std.MultiArrayList(Instruction) = .empty
names: [*]const String = &[0]String{}
value_indices: [*]const u32 = &[0]u32{}
strip: bool
debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .empty
debug_values: []const Instruction.Index = &.{}
extra: []const u32 = &.{}

std.zig.llvm.Builder.Function.arg

函数

第 6248 行

pub fn arg(self: *const Function, index: u32) Value

参数

self: *const Function
index: u32

std.zig.llvm.Builder.Function.Block

容器

第 5280 行

字段

instruction: Instruction.Index

std.zig.llvm.Builder.Function.Block.Index

别名

第 5283 行

别名目标 std.zig.llvm.Builder.WipFunction.Block.Index

std.zig.llvm.Builder.Function.deinit

函数

第 6237 行

pub fn deinit(self: *Function, gpa: Allocator) void

参数

self: *Function
gpa: Allocator

std.zig.llvm.Builder.Function.extraData

函数

第 6312 行

fn extraData(self: *const Function, comptime T: type, index: Instruction.ExtraIndex) T

参数

self: *const Function
T: type
index: Instruction.ExtraIndex

std.zig.llvm.Builder.Function.extraDataTrail

类型函数

第 6278 行

fn extraDataTrail( self: *const Function, comptime T: type, index: Instruction.ExtraIndex, ) struct { data: T, trail: ExtraDataTrail }

参数

self: *const Function
T: type
index: Instruction.ExtraIndex

std.zig.llvm.Builder.Function.ExtraDataTrail

容器

第 6257 行

字段

std.zig.llvm.Builder.Function.ExtraDataTrail.next

函数

第 6266 行

fn next( self: *ExtraDataTrail, len: u32, comptime Item: type, function: *const Function, ) []const Item

参数

self: *ExtraDataTrail
len: u32
Item: type
function: *const Function

std.zig.llvm.Builder.Function.ExtraDataTrail.nextMut

函数

第 6260 行

fn nextMut(self: *ExtraDataTrail, len: u32, comptime Item: type, function: *Function) []Item

参数

self: *ExtraDataTrail
len: u32
Item: type
function: *Function

std.zig.llvm.Builder.Function.Index

容器

第 5207 行

字段

none = maxInt(u32)
_

std.zig.llvm.Builder.Function.Index.getAttributes

函数

第 5259 行

pub fn getAttributes(self: Index, builder: *Builder) FunctionAttributes

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Function.Index.getSubprogram

函数

第 5275 行

pub fn getSubprogram(self: Index, builder: *const Builder) Metadata.Optional

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Function.Index.name

函数

第 5219 行

pub fn name(self: Index, builder: *const Builder) StrtabString

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Function.Index.ptr

函数

第 5211 行

pub fn ptr(self: Index, builder: *Builder) *Function

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Function.Index.ptrConst

函数

第 5215 行

pub fn ptrConst(self: Index, builder: *const Builder) *const Function

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Function.Index.rename

函数

第 5223 行

pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void

参数

self: Index
new_name: StrtabString
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Function.Index.setAlignment

函数

第 5267 行

pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void

参数

self: Index
alignment: Alignment
builder: *Builder

std.zig.llvm.Builder.Function.Index.setAttributes

函数

第 5251 行

pub fn setAttributes( self: Index, new_function_attributes: FunctionAttributes, builder: *Builder, ) void

参数

self: Index
new_function_attributes: FunctionAttributes
builder: *Builder

std.zig.llvm.Builder.Function.Index.setCallConv

函数

第 5247 行

pub fn setCallConv(self: Index, call_conv: CallConv, builder: *Builder) void

参数

self: Index
call_conv: CallConv
builder: *Builder

std.zig.llvm.Builder.Function.Index.setLinkage

函数

第 5239 行

pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void

参数

self: Index
linkage: Linkage
builder: *Builder

std.zig.llvm.Builder.Function.Index.setSection

函数

第 5263 行

pub fn setSection(self: Index, section: String, builder: *Builder) void

参数

self: Index
section: String
builder: *Builder

std.zig.llvm.Builder.Function.Index.setSubprogram

函数

第 5271 行

pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void

参数

self: Index
subprogram: Metadata
builder: *Builder

std.zig.llvm.Builder.Function.Index.setUnnamedAddr

函数

第 5243 行

pub fn setUnnamedAddr(self: Index, unnamed_addr: UnnamedAddr, builder: *Builder) void

参数

self: Index
unnamed_addr: UnnamedAddr
builder: *Builder

std.zig.llvm.Builder.Function.Index.toConst

函数

第 5231 行

pub fn toConst(self: Index, builder: *const Builder) Constant

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Function.Index.toValue

函数

第 5235 行

pub fn toValue(self: Index, builder: *const Builder) Value

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Function.Index.typeOf

函数

第 5227 行

pub fn typeOf(self: Index, builder: *const Builder) Type

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Function.Instruction

容器

第 5286 行

字段

tag: Tag
data: u32

std.zig.llvm.Builder.Function.Instruction.Alloca

容器

第 6119 行

字段

type: Type
len: Value
info: Info

std.zig.llvm.Builder.Function.Instruction.Alloca.Info

容器

第 6125 行

字段

alignment: Alignment
addr_space: AddrSpace
_: u2 = undefined

std.zig.llvm.Builder.Function.Instruction.Alloca.Kind

容器

第 6124 行

字段

normal
inalloca

std.zig.llvm.Builder.Function.Instruction.AtomicRmw

容器

第 6153 行

字段

info: MemoryAccessInfo
ptr: Value
val: Value

std.zig.llvm.Builder.Function.Instruction.AtomicRmw.Operation

容器

第 6158 行

字段

xchg = 0
add = 1
sub = 2
@"and" = 3
nand = 4
@"or" = 5
xor = 6
max = 7
min = 8
umax = 9
umin = 10
fadd = 11
fsub = 12
fmax = 13
fmin = 14
none = maxInt(u5)

std.zig.llvm.Builder.Function.Instruction.Binary

容器

第 6084 行

字段

lhs: Value
rhs: Value

std.zig.llvm.Builder.Function.Instruction.BrCond

容器

第 6047 行

字段

cond: Value
then: Block.Index
@"else": Block.Index
weights: Weights

std.zig.llvm.Builder.Function.Instruction.BrCond.Weights

容器

第 6053 行

字段

none = @bitCast(Metadata.Optional.none)
unpredictable
_

std.zig.llvm.Builder.Function.Instruction.BrCond.Weights.fromMetadata

函数

第 6058 行

pub fn fromMetadata(metadata: Metadata) Weights

参数

metadata: Metadata

std.zig.llvm.Builder.Function.Instruction.BrCond.Weights.toMetadata

函数

第 6063 行

pub fn toMetadata(weights: Weights) Metadata

参数

weights: Weights

std.zig.llvm.Builder.Function.Instruction.Call

容器

第 6206 行

字段

info: Info
attributes: FunctionAttributes
ty: Type
callee: Value
args_len: u32

std.zig.llvm.Builder.Function.Instruction.Call.Info

容器

第 6224 行

字段

call_conv: CallConv
has_op_bundle_cold: bool
_: u21 = undefined

std.zig.llvm.Builder.Function.Instruction.Call.Kind

容器

第 6214 行

字段

normal
fast
musttail
musttail_fast
notail
notail_fast
tail
tail_fast

std.zig.llvm.Builder.Function.Instruction.Cast

容器

第 6187 行

字段

val: Value
type: Type

std.zig.llvm.Builder.Function.Instruction.Cast.Signedness

别名

第 6191 行

别名目标 std.zig.llvm.Builder.Constant.Cast.Signedness

std.zig.llvm.Builder.Function.Instruction.CmpXchg

容器

第 6144 行

字段

info: MemoryAccessInfo
ptr: Value
cmp: Value
new: Value

std.zig.llvm.Builder.Function.Instruction.CmpXchg.Kind

容器

第 6150 行

字段

strong
weak

std.zig.llvm.Builder.Function.Instruction.ExtractElement

容器

第 6089 行

字段

val: Value
index: Value

std.zig.llvm.Builder.Function.Instruction.ExtractValue

容器

第 6106 行

字段

val: Value
indices_len: u32

std.zig.llvm.Builder.Function.Instruction.ExtraIndex

类型

第 6045 行

std.zig.llvm.Builder.Function.Instruction.GetElementPtr

容器

第 6178 行

字段

type: Type
base: Value
indices_len: u32

std.zig.llvm.Builder.Function.Instruction.GetElementPtr.Kind

别名

第 6184 行

别名目标 std.zig.llvm.Builder.Constant.GetElementPtr.Kind

std.zig.llvm.Builder.Function.Instruction.Index

容器

第 5571 行

字段

none = maxInt(u31)
_

std.zig.llvm.Builder.Function.Instruction.Index.fmt

函数

第 6030 行

pub fn fmt( self: Instruction.Index, function: Function.Index, builder: *Builder, flags: FormatFlags, ) std.fmt.Alt(FormatData, format)

参数

self: Instruction.Index
function: Function.Index
builder: *Builder
flags: FormatFlags

std.zig.llvm.Builder.Function.Instruction.Index.format

函数

第 6012 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Function.Instruction.Index.FormatData

容器

第 6006 行

字段

instruction: Instruction.Index
function: Function.Index
builder: *Builder
flags: FormatFlags

std.zig.llvm.Builder.Function.Instruction.Index.hasResultWip

函数

第 5601 行

pub fn hasResultWip(self: Instruction.Index, wip: *const WipFunction) bool

参数

self: Instruction.Index
wip: *const WipFunction

std.zig.llvm.Builder.Function.Instruction.Index.isTerminatorWip

函数

第 5587 行

pub fn isTerminatorWip(self: Instruction.Index, wip: *const WipFunction) bool

参数

self: Instruction.Index
wip: *const WipFunction

std.zig.llvm.Builder.Function.Instruction.Index.name

函数

第 5575 行

pub fn name(self: Instruction.Index, function: *const Function) String

参数

self: Instruction.Index
function: *const Function

std.zig.llvm.Builder.Function.Instruction.Index.toValue

函数

第 5583 行

pub fn toValue(self: Instruction.Index) Value

参数

std.zig.llvm.Builder.Function.Instruction.Index.typeOf

函数

第 5812 行

pub fn typeOf( self: Instruction.Index, function_index: Function.Index, builder: *Builder, ) Type

参数

self: Instruction.Index
function_index: Function.Index
builder: *Builder

std.zig.llvm.Builder.Function.Instruction.Index.typeOfWip

函数

第 5628 行

pub fn typeOfWip(self: Instruction.Index, wip: *const WipFunction) Type

参数

self: Instruction.Index
wip: *const WipFunction

std.zig.llvm.Builder.Function.Instruction.Index.valueIndex

函数

第 5579 行

pub fn valueIndex(self: Instruction.Index, function: *const Function) u32

参数

self: Instruction.Index
function: *const Function

std.zig.llvm.Builder.Function.Instruction.IndirectBr

容器

第 6078 行

字段

addr: Value
targets_len: u32

std.zig.llvm.Builder.Function.Instruction.InsertElement

容器

第 6094 行

字段

val: Value
elem: Value
index: Value

std.zig.llvm.Builder.Function.Instruction.InsertValue

容器

第 6112 行

字段

val: Value
elem: Value
indices_len: u32

std.zig.llvm.Builder.Function.Instruction.Load

容器

第 6132 行

字段

info: MemoryAccessInfo
type: Type
ptr: Value

std.zig.llvm.Builder.Function.Instruction.Phi

容器

第 6194 行

字段

type: Type

std.zig.llvm.Builder.Function.Instruction.Select

容器

第 6200 行

字段

cond: Value
lhs: Value
rhs: Value

std.zig.llvm.Builder.Function.Instruction.ShuffleVector

容器

第 6100 行

字段

lhs: Value
rhs: Value
mask: Value

std.zig.llvm.Builder.Function.Instruction.Store

容器

第 6138 行

字段

info: MemoryAccessInfo
val: Value
ptr: Value

std.zig.llvm.Builder.Function.Instruction.Switch

容器

第 6069 行

字段

val: Value
default: Block.Index
cases_len: u32
weights: BrCond.Weights

std.zig.llvm.Builder.Function.Instruction.Tag

容器

第 5290 行

字段

add
@"add nsw"
@"add nuw"
@"add nuw nsw"
addrspacecast
alloca
@"alloca inalloca"
@"and"
arg
ashr
@"ashr exact"
atomicrmw
bitcast
block
br
br_cond
call
@"call fast"
cmpxchg
@"cmpxchg weak"
extractelement
extractvalue
fadd
@"fadd fast"
@"fcmp false"
@"fcmp fast false"
@"fcmp fast oeq"
@"fcmp fast oge"
@"fcmp fast ogt"
@"fcmp fast ole"
@"fcmp fast olt"
@"fcmp fast one"
@"fcmp fast ord"
@"fcmp fast true"
@"fcmp fast ueq"
@"fcmp fast uge"
@"fcmp fast ugt"
@"fcmp fast ule"
@"fcmp fast ult"
@"fcmp fast une"
@"fcmp fast uno"
@"fcmp oeq"
@"fcmp oge"
@"fcmp ogt"
@"fcmp ole"
@"fcmp olt"
@"fcmp one"
@"fcmp ord"
@"fcmp true"
@"fcmp ueq"
@"fcmp uge"
@"fcmp ugt"
@"fcmp ule"
@"fcmp ult"
@"fcmp une"
@"fcmp uno"
fdiv
@"fdiv fast"
fence
fmul
@"fmul fast"
fneg
@"fneg fast"
fpext
fptosi
fptoui
fptrunc
frem
@"frem fast"
fsub
@"fsub fast"
getelementptr
@"getelementptr inbounds"
@"icmp eq"
@"icmp ne"
@"icmp sge"
@"icmp sgt"
@"icmp sle"
@"icmp slt"
@"icmp uge"
@"icmp ugt"
@"icmp ule"
@"icmp ult"
indirectbr
insertelement
insertvalue
inttoptr
load
@"load atomic"
lshr
@"lshr exact"
mul
@"mul nsw"
@"mul nuw"
@"mul nuw nsw"
@"musttail call"
@"musttail call fast"
@"notail call"
@"notail call fast"
@"or"
phi
@"phi fast"
ptrtoint
ret
@"ret void"
sdiv
@"sdiv exact"
select
@"select fast"
sext
shl
@"shl nsw"
@"shl nuw"
@"shl nuw nsw"
shufflevector
sitofp
srem
store
@"store atomic"
sub
@"sub nsw"
@"sub nuw"
@"sub nuw nsw"
@"switch"
@"tail call"
@"tail call fast"
trunc
@"trunc nuw"
@"trunc nsw"
@"trunc nuw nsw"
udiv
@"udiv exact"
urem
uitofp
@"unreachable"
va_arg
xor
zext

std.zig.llvm.Builder.Function.Instruction.Tag.toBinaryOpcode

函数

第 5430 行

pub fn toBinaryOpcode(self: Tag) BinaryOpcode

参数

self: Tag

std.zig.llvm.Builder.Function.Instruction.Tag.toCastOpcode

函数

第 5487 行

不接受 .@"trunc nuw"、.@"trunc nsw" 或 .@"trunc nuw nsw", 因为它们没有独立的 CastOpcode 值,而是在位码中 通过普通 trunc 操作上的标志进行编码。

fn toCastOpcode(self: Tag) CastOpcode

参数

self: Tag

std.zig.llvm.Builder.Function.Instruction.Tag.toCmpPredicate

函数

第 5506 行

pub fn toCmpPredicate(self: Tag) CmpPredicate

参数

self: Tag

std.zig.llvm.Builder.Function.Instruction.VaArg

容器

第 6231 行

字段

list: Value
type: Type

std.zig.llvm.Builder.FunctionAttributes

容器

第 2555 行

字段

none
_

std.zig.llvm.Builder.FunctionAttributes.func

函数

第 2684 行

pub fn func(self: FunctionAttributes, builder: *const Builder) Attributes

参数

self: FunctionAttributes
builder: *const Builder

std.zig.llvm.Builder.FunctionAttributes.function_index

常量

第 2559 行

std.zig.llvm.Builder.FunctionAttributes.get

函数

第 2712 行

fn get(self: FunctionAttributes, index: usize, builder: *const Builder) Attributes

参数

self: FunctionAttributes
index: usize
builder: *const Builder

std.zig.llvm.Builder.FunctionAttributes.param

函数

第 2692 行

pub fn param(self: FunctionAttributes, param_index: usize, builder: *const Builder) Attributes

参数

self: FunctionAttributes
param_index: usize
builder: *const Builder

std.zig.llvm.Builder.FunctionAttributes.params_index

常量

第 2561 行

std.zig.llvm.Builder.FunctionAttributes.ret

函数

第 2688 行

pub fn ret(self: FunctionAttributes, builder: *const Builder) Attributes

参数

self: FunctionAttributes
builder: *const Builder

std.zig.llvm.Builder.FunctionAttributes.return_index

常量

第 2560 行

std.zig.llvm.Builder.FunctionAttributes.slice

函数

第 2717 行

fn slice(self: FunctionAttributes, builder: *const Builder) []const Attributes

参数

self: FunctionAttributes
builder: *const Builder

std.zig.llvm.Builder.FunctionAttributes.toWip

函数

第 2696 行

pub fn toWip(self: FunctionAttributes, builder: *const Builder) Allocator.Error!Wip

参数

self: FunctionAttributes
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip

容器

第 2563 行

字段

maps: Maps = .empty

std.zig.llvm.Builder.FunctionAttributes.Wip.addAttr

函数

第 2641 行

fn addAttr( self: *Wip, index: usize, attribute: Attribute, builder: *Builder, ) Allocator.Error!void

参数

self: *Wip
index: usize
attribute: Attribute
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addAttrIndex

函数

第 2651 行

fn addAttrIndex( self: *Wip, index: usize, attribute_index: Attribute.Index, builder: *const Builder, ) Allocator.Error!void

参数

self: *Wip
index: usize
attribute_index: Attribute.Index
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addFnAttr

函数

第 2575 行

pub fn addFnAttr(self: *Wip, attribute: Attribute, builder: *Builder) Allocator.Error!void

参数

self: *Wip
attribute: Attribute
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addFnAttrIndex

函数

第 2579 行

pub fn addFnAttrIndex( self: *Wip, attribute_index: Attribute.Index, builder: *const Builder, ) Allocator.Error!void

参数

self: *Wip
attribute_index: Attribute.Index
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addParamAttr

函数

第 2607 行

pub fn addParamAttr( self: *Wip, param_index: usize, attribute: Attribute, builder: *Builder, ) Allocator.Error!void

参数

self: *Wip
param_index: usize
attribute: Attribute
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addParamAttrIndex

函数

第 2616 行

pub fn addParamAttrIndex( self: *Wip, param_index: usize, attribute_index: Attribute.Index, builder: *const Builder, ) Allocator.Error!void

参数

self: *Wip
param_index: usize
attribute_index: Attribute.Index
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addRetAttr

函数

第 2591 行

pub fn addRetAttr(self: *Wip, attribute: Attribute, builder: *Builder) Allocator.Error!void

参数

self: *Wip
attribute: Attribute
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.addRetAttrIndex

函数

第 2595 行

pub fn addRetAttrIndex( self: *Wip, attribute_index: Attribute.Index, builder: *const Builder, ) Allocator.Error!void

参数

self: *Wip
attribute_index: Attribute.Index
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.deinit

函数

第 2569 行

pub fn deinit(self: *Wip, builder: *const Builder) void

参数

self: *Wip
builder: *const Builder

std.zig.llvm.Builder.FunctionAttributes.Wip.ensureTotalLength

函数

第 2676 行

fn ensureTotalLength(self: *Wip, new_len: usize) Allocator.Error!void

参数

self: *Wip
new_len: usize

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.finish

函数

第 2633 行

pub fn finish(self: *const Wip, builder: *Builder) Allocator.Error!FunctionAttributes

参数

self: *const Wip
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.getMap

函数

第 2672 行

fn getMap(self: *Wip, index: usize) ?*Map

参数

self: *Wip
index: usize

std.zig.llvm.Builder.FunctionAttributes.Wip.getOrPutMap

函数

第 2666 行

fn getOrPutMap(self: *Wip, allocator: Allocator, index: usize) Allocator.Error!*Map

参数

self: *Wip
allocator: Allocator
index: usize

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.Map

类型

第 2566 行

std.zig.llvm.Builder.FunctionAttributes.Wip.Maps

类型

第 2567 行

std.zig.llvm.Builder.FunctionAttributes.Wip.removeAttr

函数

第 2661 行

fn removeAttr(self: *Wip, index: usize, attribute_kind: Attribute.Kind) Allocator.Error!bool

参数

self: *Wip
index: usize
attribute_kind: Attribute.Kind

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.removeFnAttr

函数

第 2587 行

pub fn removeFnAttr(self: *Wip, attribute_kind: Attribute.Kind) Allocator.Error!bool

参数

self: *Wip
attribute_kind: Attribute.Kind

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.removeParamAttr

函数

第 2625 行

pub fn removeParamAttr( self: *Wip, param_index: usize, attribute_kind: Attribute.Kind, ) Allocator.Error!bool

参数

self: *Wip
param_index: usize
attribute_kind: Attribute.Kind

错误

OutOfMemory

std.zig.llvm.Builder.FunctionAttributes.Wip.removeRetAttr

函数

第 2603 行

pub fn removeRetAttr(self: *Wip, attribute_kind: Attribute.Kind) Allocator.Error!bool

参数

self: *Wip
attribute_kind: Attribute.Kind

错误

OutOfMemory

std.zig.llvm.Builder.gepConst

函数

第 10730 行

pub fn gepConst( self: *Builder, comptime kind: Constant.GetElementPtr.Kind, ty: Type, base: Constant, inrange: ?u16, indices: []const Constant, ) Allocator.Error!Constant

参数

self: *Builder
kind: Constant.GetElementPtr.Kind
ty: Type
base: Constant
inrange: ?u16
indices: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.gepConstAssumeCapacity

函数

第 12877 行

fn gepConstAssumeCapacity( self: *Builder, comptime kind: Constant.GetElementPtr.Kind, ty: Type, base: Constant, inrange: ?u16, indices: []const Constant, ) Constant

参数

self: *Builder
kind: Constant.GetElementPtr.Kind
ty: Type
base: Constant
inrange: ?u16
indices: []const Constant

std.zig.llvm.Builder.gepConstAssumeCapacity.eql

函数

第 12935 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.gepConstAssumeCapacity.hash

函数

第 12927 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.gepConstAssumeCapacity.init

函数

第 12896 行

fn init(vector_ty: Type, builder: *const Builder) @This()

参数

vector_ty: Type
builder: *const Builder

std.zig.llvm.Builder.gepValue

函数

第 10743 行

pub fn gepValue( self: *Builder, comptime kind: Constant.GetElementPtr.Kind, ty: Type, base: Constant, inrange: ?u16, indices: []const Constant, ) Allocator.Error!Value

参数

self: *Builder
kind: Constant.GetElementPtr.Kind
ty: Type
base: Constant
inrange: ?u16
indices: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.getGlobal

函数

第 10257 行

pub fn getGlobal(self: *const Builder, name: StrtabString) ?Global.Index

参数

self: *const Builder
name: StrtabString

std.zig.llvm.Builder.getIntrinsic

函数

第 10351 行

pub fn getIntrinsic( self: *Builder, id: Intrinsic, overload: []const Type, ) Allocator.Error!Function.Index

参数

self: *Builder
id: Intrinsic
overload: []const Type

错误

OutOfMemory

std.zig.llvm.Builder.getIntrinsic.deinit

函数

第 10393 行

fn deinit(state: *@This()) void

参数

state: *@This()

std.zig.llvm.Builder.getIntrinsic.get

函数

第 10398 行

fn get(state: *@This(), attributes: []const Attribute) Allocator.Error!Attributes

参数

state: *@This()
attributes: []const Attribute

错误

OutOfMemory

std.zig.llvm.Builder.getOrPutConstantAggregateAssumeCapacity

类型函数

第 13097 行

fn getOrPutConstantAggregateAssumeCapacity( self: *Builder, tag: Constant.Tag, ty: Type, vals: []const Constant, ) struct { new: bool, constant: Constant }

参数

self: *Builder
tag: Constant.Tag
ty: Type
vals: []const Constant

std.zig.llvm.Builder.getOrPutConstantAggregateAssumeCapacity.eql

函数

第 13116 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.getOrPutConstantAggregateAssumeCapacity.hash

函数

第 13110 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.getOrPutConstantNoExtraAssumeCapacity

类型函数

第 13072 行

fn getOrPutConstantNoExtraAssumeCapacity( self: *Builder, item: Constant.Item, ) struct { new: bool, constant: Constant }

参数

self: *Builder
item: Constant.Item

std.zig.llvm.Builder.getOrPutConstantNoExtraAssumeCapacity.eql

函数

第 13084 行

pub fn eql(ctx: @This(), lhs_key: Constant.Item, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Constant.Item
_: void
rhs_index: usize

std.zig.llvm.Builder.getOrPutConstantNoExtraAssumeCapacity.hash

函数

第 13078 行

pub fn hash(_: @This(), key: Constant.Item) u32

参数

_: @This()
key: Constant.Item

std.zig.llvm.Builder.getOrPutTypeNoExtraAssumeCapacity

类型函数

第 12180 行

fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { new: bool, type: Type }

参数

self: *Builder
item: Type.Item

std.zig.llvm.Builder.getOrPutTypeNoExtraAssumeCapacity.eql

函数

第 12189 行

pub fn eql(ctx: @This(), lhs_key: Type.Item, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Type.Item
_: void
rhs_index: usize

std.zig.llvm.Builder.getOrPutTypeNoExtraAssumeCapacity.hash

函数

第 12183 行

pub fn hash(_: @This(), key: Type.Item) u32

参数

_: @This()
key: Type.Item

std.zig.llvm.Builder.Global

容器

第 3270 行

字段

linkage: Linkage = .external
preemption: Preemption = .dso_preemptable
visibility: Visibility = .default
dll_storage_class: DllStorageClass = .default
unnamed_addr: UnnamedAddr = .default
addr_space: AddrSpace = .default
externally_initialized: ExternallyInitialized = .default
type: Type
partition: String = .none
dbg: Metadata.Optional = .none
kind: union(enum) {
    alias: Alias.Index,
    variable: Variable.Index,
    function: Function.Index,
    replaced: Global.Index,
}

std.zig.llvm.Builder.Global.Index

容器

第 3288 行

字段

none = maxInt(u32)
_

std.zig.llvm.Builder.Global.Index.delete

函数

第 3400 行

pub fn delete(self: Index, builder: *Builder) void

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Global.Index.eql

函数

第 3302 行

pub fn eql(self: Index, other: Index, builder: *const Builder) bool

参数

self: Index
other: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.fmt

函数

第 3381 行

pub fn fmt(self: Index, builder: *const Builder) std.fmt.Alt(FormatData, format)

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.format

函数

第 3376 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Global.Index.FormatData

容器

第 3372 行

字段

global: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.getDebugMetadata

函数

第 3368 行

pub fn getDebugMetadata(self: Index, builder: *const Builder) Metadata.Optional

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.name

函数

第 3314 行

pub fn name(self: Index, builder: *const Builder) StrtabString

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.ptr

函数

第 3306 行

pub fn ptr(self: Index, builder: *Builder) *Global

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Global.Index.ptrConst

函数

第 3310 行

pub fn ptrConst(self: Index, builder: *const Builder) *const Global

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.rename

函数

第 3385 行

pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void

参数

self: Index
new_name: StrtabString
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Global.Index.renameAssumeCapacity

函数

第 3460 行

fn renameAssumeCapacity(self: Index, new_name: StrtabString, builder: *Builder) void

参数

self: Index
new_name: StrtabString
builder: *Builder

std.zig.llvm.Builder.Global.Index.replace

函数

第 3395 行

pub fn replace(self: Index, other: Index, builder: *Builder) Allocator.Error!void

参数

self: Index
other: Index
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Global.Index.replaceAssumeCapacity

函数

第 3477 行

fn replaceAssumeCapacity(self: Index, other: Index, builder: *Builder) void

参数

self: Index
other: Index
builder: *Builder

std.zig.llvm.Builder.Global.Index.setDebugMetadata

函数

第 3364 行

pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void

参数

self: Index
dbg: Metadata
builder: *Builder

std.zig.llvm.Builder.Global.Index.setDllStorageClass

函数

第 3356 行

pub fn setDllStorageClass(self: Index, class: DllStorageClass, builder: *Builder) void

参数

self: Index
class: DllStorageClass
builder: *Builder

std.zig.llvm.Builder.Global.Index.setLinkage

函数

第 3346 行

pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void

参数

self: Index
linkage: Linkage
builder: *Builder

std.zig.llvm.Builder.Global.Index.setUnnamedAddr

函数

第 3360 行

pub fn setUnnamedAddr(self: Index, unnamed_addr: UnnamedAddr, builder: *Builder) void

参数

self: Index
unnamed_addr: UnnamedAddr
builder: *Builder

std.zig.llvm.Builder.Global.Index.setVisibility

函数

第 3351 行

pub fn setVisibility(self: Index, visibility: Visibility, builder: *Builder) void

参数

self: Index
visibility: Visibility
builder: *Builder

std.zig.llvm.Builder.Global.Index.strtab

类型函数

第 3318 行

pub fn strtab(self: Index, builder: *const Builder) struct { offset: u32, size: u32, }

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.takeName

函数

第 3390 行

pub fn takeName(self: Index, other: Index, builder: *Builder) Allocator.Error!void

参数

self: Index
other: Index
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Global.Index.takeNameAssumeCapacity

函数

第 3471 行

fn takeNameAssumeCapacity(self: Index, other: Index, builder: *Builder) void

参数

self: Index
other: Index
builder: *Builder

std.zig.llvm.Builder.Global.Index.toConst

函数

第 3338 行

pub fn toConst(global: Index) Constant

参数

global: Index

std.zig.llvm.Builder.Global.Index.toNewAlias

函数

第 3431 行

用新的 Alias 替换此 Global 当前的内容。类似于 Builder.addAlias,但复用同一个 Global。

pub fn toNewAlias(global: Index, builder: *Builder) Allocator.Error!Alias.Index

参数

global: Index
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Global.Index.toNewFunction

函数

第 3406 行

用新的 Function 替换此 Global 当前的内容。类似于 Builder.addFunction,但复用同一个 Global。

pub fn toNewFunction(global: Index, builder: *Builder) Allocator.Error!Function.Index

参数

global: Index
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Global.Index.toNewVariable

函数

第 3420 行

使用新的 Variable 替换此 Global 当前包含的内容。 类似 Builder.addVariable,但复用同一个 Global。

pub fn toNewVariable(global: Index, builder: *Builder) Allocator.Error!Variable.Index

参数

global: Index
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Global.Index.toValue

函数

第 3342 行

pub fn toValue(global: Index) Value

参数

global: Index

std.zig.llvm.Builder.Global.Index.typeOf

函数

第 3334 行

pub fn typeOf(self: Index, builder: *const Builder) Type

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.unwrap

函数

第 3292 行

pub fn unwrap(orig_index: Index, builder: *const Builder) Index

参数

orig_index: Index
builder: *const Builder

std.zig.llvm.Builder.Global.Index.updateDsoLocal

函数

第 3440 行

fn updateDsoLocal(self: Index, builder: *Builder) void

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.halfConst

函数

第 10511 行

pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant

参数

self: *Builder
val: f16

错误

OutOfMemory

std.zig.llvm.Builder.halfConstAssumeCapacity

函数

第 12360 行

fn halfConstAssumeCapacity(self: *Builder, val: f16) Constant

参数

self: *Builder
val: f16

std.zig.llvm.Builder.halfValue

函数

第 10516 行

pub fn halfValue(self: *Builder, value: f16) Allocator.Error!Value

参数

self: *Builder
value: f16

错误

OutOfMemory

std.zig.llvm.Builder.init

函数

第 9837 行

pub fn init(options: Options) Allocator.Error!Builder

参数

options: Options

错误

OutOfMemory

std.zig.llvm.Builder.intConst

函数

第 10446 行

pub fn intConst(self: *Builder, ty: Type, value: anytype) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.IntegerCondition

容器

第 8211 行

字段

eq = 32
ne = 33
ugt = 34
uge = 35
ult = 36
ule = 37
sgt = 38
sge = 39
slt = 40
sle = 41

std.zig.llvm.Builder.Intrinsic

容器

第 3619 行

字段

va_start
va_end
va_copy
returnaddress
addressofreturnaddress
sponentry
frameaddress
prefetch
@"thread.pointer"
abs
smax
smin
umax
umin
scmp
ucmp
memcpy
@"memcpy.inline"
memmove
memset
@"memset.inline"
sqrt
powi
sin
cos
tan
asin
acos
atan
atan2
sinh
cosh
tanh
sincos
sincospi
modf
pow
exp
exp2
exp10
ldexp
frexp
log
log10
log2
fma
fabs
minnum
maxnum
minimum
maximum
minimumnum
maximumnum
copysign
floor
ceil
trunc
rint
nearbyint
round
roundeven
lround
llround
lrint
llrint
bitreverse
bswap
ctpop
ctlz
cttz
fshl
fshr
clmul
@"sadd.with.overflow"
@"uadd.with.overflow"
@"ssub.with.overflow"
@"usub.with.overflow"
@"smul.with.overflow"
@"umul.with.overflow"
@"sadd.sat"
@"uadd.sat"
@"ssub.sat"
@"usub.sat"
@"sshl.sat"
@"ushl.sat"
@"smul.fix"
@"umul.fix"
@"smul.fix.sat"
@"umul.fix.sat"
@"sdiv.fix"
@"udiv.fix"
@"sdiv.fix.sat"
@"udiv.fix.sat"
canonicalize
fmuladd
@"vector.reduce.add"
@"vector.reduce.fadd"
@"vector.reduce.mul"
@"vector.reduce.fmul"
@"vector.reduce.and"
@"vector.reduce.or"
@"vector.reduce.xor"
@"vector.reduce.smax"
@"vector.reduce.smin"
@"vector.reduce.umax"
@"vector.reduce.umin"
@"vector.reduce.fmax"
@"vector.reduce.fmin"
@"vector.reduce.fmaximum"
@"vector.reduce.fminimum"
@"vector.insert"
@"vector.extract"
@"is.fpclass"
@"var.annotation"
@"ptr.annotation"
annotation
@"codeview.annotation"
trap
debugtrap
ubsantrap
stackprotector
stackguard
objectsize
expect
@"expect.with.probability"
assume
@"ssa.copy"
@"type.test"
@"type.checked.load"
@"type.checked.load.relative"
@"arithmetic.fence"
donothing
@"load.relative"
sideeffect
@"is.constant"
ptrmask
@"threadlocal.address"
vscale
@"dbg.declare"
@"dbg.value"
@"amdgcn.workitem.id.x"
@"amdgcn.workitem.id.y"
@"amdgcn.workitem.id.z"
@"amdgcn.workgroup.id.x"
@"amdgcn.workgroup.id.y"
@"amdgcn.workgroup.id.z"
@"amdgcn.dispatch.ptr"
@"nvvm.read.ptx.sreg.tid.x"
@"nvvm.read.ptx.sreg.tid.y"
@"nvvm.read.ptx.sreg.tid.z"
@"nvvm.read.ptx.sreg.ntid.x"
@"nvvm.read.ptx.sreg.ntid.y"
@"nvvm.read.ptx.sreg.ntid.z"
@"nvvm.read.ptx.sreg.ctaid.x"
@"nvvm.read.ptx.sreg.ctaid.y"
@"nvvm.read.ptx.sreg.ctaid.z"
@"wasm.memory.size"
@"wasm.memory.grow"

std.zig.llvm.Builder.Intrinsic.Signature

容器

第 3808 行

字段

ret_len: u8
params: []const Parameter
attrs: []const Attribute = &.{}

std.zig.llvm.Builder.Intrinsic.Signature.Parameter

容器

第 3813 行

字段

kind: Kind
attrs: []const Attribute = &.{}

std.zig.llvm.Builder.Intrinsic.Signature.Parameter.Kind

容器

第 3817 行

字段

type: Type
overloaded
matches: u8
matches_scalar: u8
matches_changed_scalar: struct {
    index: u8,
    scalar: Type,
}

std.zig.llvm.Builder.Intrinsic.signatures

常量

第 3830 行

std.zig.llvm.Builder.intType

函数

第 10131 行

pub fn intType(self: *Builder, bits: u24) Allocator.Error!Type

参数

self: *Builder
bits: u24

错误

OutOfMemory

std.zig.llvm.Builder.intTypeAssumeCapacity

函数

第 11968 行

fn intTypeAssumeCapacity(self: *Builder, bits: u24) Type

参数

self: *Builder
bits: u24

std.zig.llvm.Builder.intValue

函数

第 10462 行

pub fn intValue(self: *Builder, ty: Type, value: anytype) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.Io

别名

第 5 行

别名目标 std.Io

std.zig.llvm.Builder.ir

别名

第 14 行

别名目标 std.zig.llvm.ir

std.zig.llvm.Builder.isValidIdentifier

函数

第 11887 行

fn isValidIdentifier(id: []const u8) bool

参数

id: []const u8

std.zig.llvm.Builder.Linkage

容器

第 2724 行

字段

private = 9
internal = 3
weak = 1
weak_odr = 10
linkonce = 4
linkonce_odr = 11
available_externally = 12
appending = 2
common = 8
extern_weak = 7
external = 0

std.zig.llvm.Builder.Linkage.fmtOptional

函数

第 2744 行

pub fn fmtOptional(self: ?Linkage) std.fmt.Alt(?Linkage, formatOptional)

参数

self: ?Linkage

std.zig.llvm.Builder.Linkage.format

函数

第 2737 行

pub fn format(self: Linkage, w: *Writer) Writer.Error!void

参数

self: Linkage
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Linkage.formatOptional

函数

第 2741 行

fn formatOptional(data: ?Linkage, w: *Writer) Writer.Error!void

参数

data: ?Linkage
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.log

类型

第 9 行

std.zig.llvm.Builder.maxInt

别名

第 10 行

别名目标 std.math.maxInt

std.zig.llvm.Builder.MemoryAccessInfo

容器

第 8313 行

字段

access_kind: MemoryAccessKind = .normal
atomic_rmw_operation: Function.Instruction.AtomicRmw.Operation = .none
sync_scope: SyncScope
success_ordering: AtomicOrdering
failure_ordering: AtomicOrdering = .none
alignment: Alignment = .default
_: u13 = undefined

std.zig.llvm.Builder.MemoryAccessKind

容器

第 8224 行

字段

normal
@"volatile"

std.zig.llvm.Builder.MemoryAccessKind.fmt

函数

第 8247 行

pub fn fmt(memory_access_kind: MemoryAccessKind, prefix: []const u8) Prefixed

参数

memory_access_kind: MemoryAccessKind
prefix: []const u8

std.zig.llvm.Builder.MemoryAccessKind.format

函数

第 8228 行

pub fn format(memory_access_kind: MemoryAccessKind, w: *Writer) Writer.Error!void

参数

memory_access_kind: MemoryAccessKind
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.MemoryAccessKind.Prefixed

容器

第 8232 行

字段

memory_access_kind: MemoryAccessKind
prefix: []const u8

std.zig.llvm.Builder.MemoryAccessKind.Prefixed.format

函数

第 8236 行

pub fn format(p: Prefixed, w: *Writer) Writer.Error!void

参数

p: Prefixed
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Metadata

容器

第 9085 行

字段

index: u29
kind: Kind
unused: enum(u1) { unused = 0 } = .unused

std.zig.llvm.Builder.Metadata.BasicType

容器

第 9463 行

字段

name: Metadata.String.Optional
size_in_bits_lo: u32
size_in_bits_hi: u32

std.zig.llvm.Builder.Metadata.BasicType.bitSize

函数

第 9468 行

pub fn bitSize(self: BasicType) u64

参数

self: BasicType

std.zig.llvm.Builder.Metadata.CompileUnit

容器

第 9371 行

字段

std.zig.llvm.Builder.Metadata.CompileUnit.Options

容器

第 9372 行

字段

optimized: bool

std.zig.llvm.Builder.Metadata.CompositeType

容器

第 9473 行

字段

name: Metadata.String.Optional
file: Metadata.Optional
scope: Metadata.Optional
line: u32
underlying_type: Metadata.Optional
size_in_bits_lo: u32
size_in_bits_hi: u32
align_in_bits_lo: u32
align_in_bits_hi: u32
fields_tuple: Metadata.Optional

std.zig.llvm.Builder.Metadata.CompositeType.bitAlign

函数

第 9488 行

pub fn bitAlign(self: CompositeType) u64

参数

std.zig.llvm.Builder.Metadata.CompositeType.bitSize

函数

第 9485 行

pub fn bitSize(self: CompositeType) u64

参数

std.zig.llvm.Builder.Metadata.DerivedType

容器

第 9493 行

字段

name: Metadata.String.Optional
file: Metadata.Optional
scope: Metadata.Optional
line: u32
underlying_type: Metadata.Optional
size_in_bits_lo: u32
size_in_bits_hi: u32
align_in_bits_lo: u32
align_in_bits_hi: u32
offset_in_bits_lo: u32
offset_in_bits_hi: u32

std.zig.llvm.Builder.Metadata.DerivedType.bitAlign

函数

第 9509 行

pub fn bitAlign(self: DerivedType) u64

参数

self: DerivedType

std.zig.llvm.Builder.Metadata.DerivedType.bitOffset

函数

第 9512 行

pub fn bitOffset(self: DerivedType) u64

参数

self: DerivedType

std.zig.llvm.Builder.Metadata.DerivedType.bitSize

函数

第 9506 行

pub fn bitSize(self: DerivedType) u64

参数

self: DerivedType

std.zig.llvm.Builder.Metadata.DIFlags

容器

第 9308 行

字段

Visibility: enum(u2) { Zero, Private, Protected, Public } = .Zero
FwdDecl: bool = false
AppleBlock: bool = false
ReservedBit4: u1 = 0
Virtual: bool = false
Artificial: bool = false
Explicit: bool = false
Prototyped: bool = false
ObjcClassComplete: bool = false
ObjectPointer: bool = false
Vector: bool = false
StaticMember: bool = false
LValueReference: bool = false
RValueReference: bool = false
ExportSymbols: bool = false
Inheritance: enum(u2) {
    Zero,
    SingleInheritance,
    MultipleInheritance,
    VirtualInheritance,
} = .Zero
IntroducedVirtual: bool = false
BitField: bool = false
NoReturn: bool = false
ReservedBit21: u1 = 0
TypePassbyValue: bool = false
TypePassbyReference: bool = false
EnumClass: bool = false
Thunk: bool = false
NonTrivial: bool = false
BigEndian: bool = false
LittleEndian: bool = false
AllCallsDescribed: bool = false
Unused: u2 = 0

std.zig.llvm.Builder.Metadata.DIFlags.format

函数

第 9344 行

pub fn format(self: DIFlags, w: *Writer) Writer.Error!void

参数

self: DIFlags
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Metadata.empty_tuple

常量

第 9097 行

Metadata

std.zig.llvm.Builder.Metadata.Enumerator

容器

第 9521 行

字段

name: Metadata.String.Optional
bit_width: u32
limbs_index: u32
limbs_len: u32

std.zig.llvm.Builder.Metadata.Expression

容器

第 9533 行

字段

elements_len: u32

std.zig.llvm.Builder.Metadata.File

容器

第 9366 行

字段

std.zig.llvm.Builder.Metadata.Formatter

容器

第 9581 行

字段

builder: *Builder
need_comma: bool
map: std.array_hash_map.Auto(union(enum) {
    metadata: Metadata,
    debug_location: DebugLocation.Location,
}, void) = .empty

std.zig.llvm.Builder.Metadata.Formatter.fmt

函数

第 9689 行

inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) { Metadata, Metadata.Optional, ?Metadata => Allocator.Error, else => error{}, }!std.fmt.Alt(FormatData, format)

参数

formatter: *Formatter
prefix: []const u8
special: ?FormatFlags

std.zig.llvm.Builder.Metadata.Formatter.fmtLocal

函数

第 9743 行

inline fn fmtLocal( formatter: *Formatter, prefix: []const u8, value: Value, function: Function.Index, ) Allocator.Error!std.fmt.Alt(FormatData, format)

参数

formatter: *Formatter
prefix: []const u8
value: Value
function: Function.Index

错误

OutOfMemory

std.zig.llvm.Builder.Metadata.Formatter.format

函数

第 9619 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Metadata.Formatter.FormatData

容器

第 9589 行

字段

formatter: *Formatter
prefix: []const u8 = ""
node: Node
specialized: ?FormatFlags

std.zig.llvm.Builder.Metadata.Formatter.FormatData.Node

容器

第 9595 行

字段

none
@"inline": Metadata
index: u32
local_value: ValueData
local_metadata: ValueData
local_inline: Metadata
local_index: u32
string: Metadata.String
bool: bool
u32: u32
u64: u64
di_flags: DIFlags
sp_flags: Subprogram.DISPFlags
raw: []const u8

std.zig.llvm.Builder.Metadata.Formatter.FormatData.Node.ValueData

容器

第 9613 行

字段

value: Value
function: Function.Index

std.zig.llvm.Builder.Metadata.Formatter.refUnwrapped

函数

第 9778 行

fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node

参数

formatter: *Formatter
node: Metadata

错误

OutOfMemory

std.zig.llvm.Builder.Metadata.Formatter.specialized

函数

第 9791 行

inline fn specialized( formatter: *Formatter, distinct: enum { @"!", @"distinct !" }, node: enum { DIFile, DICompileUnit, DISubprogram, DILexicalBlock, DILocation, DIBasicType, DICompositeType, DIDerivedType, DISubroutineType, DIEnumerator, DISubrange, DILocalVariable, DIGlobalVariable, DIGlobalVariableExpression, }, nodes: anytype, w: *Writer, ) !void

参数

formatter: *Formatter
distinct: enum { @"!", @"distinct !" }
node: enum {
    DIFile,
    DICompileUnit,
    DISubprogram,
    DILexicalBlock,
    DILocation,
    DIBasicType,
    DICompositeType,
    DIDerivedType,
    DISubroutineType,
    DIEnumerator,
    DISubrange,
    DILocalVariable,
    DIGlobalVariable,
    DIGlobalVariableExpression,
}
w: *Writer

std.zig.llvm.Builder.Metadata.getSubprogram

函数

第 9433 行

pub fn getSubprogram(metadata: Metadata, builder: *const Builder) Subprogram

参数

metadata: Metadata
builder: *const Builder

std.zig.llvm.Builder.Metadata.GlobalVar

容器

第 9562 行

字段

name: Metadata.String.Optional
linkage_name: Metadata.String.Optional
file: Metadata.Optional
scope: Metadata.Optional
line: u32
ty: Metadata.Optional
variable: Variable.Index

std.zig.llvm.Builder.Metadata.GlobalVar.Options

容器

第 9563 行

字段

local: bool

std.zig.llvm.Builder.Metadata.GlobalVarExpression

容器

第 9576 行

字段

variable: Metadata.Optional
expression: Metadata.Optional

std.zig.llvm.Builder.Metadata.isInline

函数

第 9284 行

pub fn isInline(metadata: Metadata, builder: *const Builder) bool

参数

metadata: Metadata
builder: *const Builder

std.zig.llvm.Builder.Metadata.item

函数

第 9279 行

pub fn item(metadata: Metadata, builder: *const Builder) Item

参数

metadata: Metadata
builder: *const Builder

std.zig.llvm.Builder.Metadata.Item

容器

第 9301 行

字段

tag: Tag
data: ExtraIndex

std.zig.llvm.Builder.Metadata.Item.ExtraIndex

类型

第 9305 行

std.zig.llvm.Builder.Metadata.Kind

容器

第 9090 行

字段

string
node
forward
local

std.zig.llvm.Builder.Metadata.LexicalBlock

容器

第 9449 行

字段

scope: Metadata.Optional
file: Metadata.Optional
line: u32
column: u32

std.zig.llvm.Builder.Metadata.LocalVar

容器

第 9545 行

字段

std.zig.llvm.Builder.Metadata.Location

容器

第 9456 行

字段

line: u32
column: u32
scope: Metadata
inlined_at: Metadata.Optional

std.zig.llvm.Builder.Metadata.Optional

容器

第 9099 行

字段

index: u29
kind: Metadata.Kind
is_none: bool

std.zig.llvm.Builder.Metadata.Optional.empty_tuple

常量

第 9105 行

Metadata.Optional

std.zig.llvm.Builder.Metadata.Optional.none

常量

第 9104 行

Metadata.Optional

std.zig.llvm.Builder.Metadata.Optional.toString

函数

第 9116 行

pub fn toString(metadata: Metadata.Optional) Metadata.String.Optional

参数

metadata: Metadata.Optional

std.zig.llvm.Builder.Metadata.Optional.toValue

函数

第 9113 行

pub fn toValue(metadata: Metadata.Optional) Value

参数

metadata: Metadata.Optional

std.zig.llvm.Builder.Metadata.Optional.unwrap

函数

第 9110 行

pub fn unwrap(metadata: Metadata.Optional) ?Metadata

参数

metadata: Metadata.Optional

std.zig.llvm.Builder.Metadata.Optional.wrap

函数

第 9107 行

pub fn wrap(metadata: ?Metadata) Metadata.Optional

参数

metadata: ?Metadata

std.zig.llvm.Builder.Metadata.Parameter

容器

第 9553 行

字段

name: Metadata.String.Optional
file: Metadata.Optional
scope: Metadata.Optional
line: u32
ty: Metadata.Optional
arg_no: u32

std.zig.llvm.Builder.Metadata.String

容器

第 9127 行

字段

_

std.zig.llvm.Builder.Metadata.String.Adapter

容器

第 9161 行

字段

builder: *const Builder

std.zig.llvm.Builder.Metadata.String.Adapter.eql

函数

第 9166 行

pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool

参数

ctx: Adapter
lhs_key: []const u8
_: void
rhs_index: usize

std.zig.llvm.Builder.Metadata.String.Adapter.hash

函数

第 9163 行

pub fn hash(_: Adapter, key: []const u8) u32

参数

_: Adapter
key: []const u8

std.zig.llvm.Builder.Metadata.String.fmt

函数

第 9179 行

fn fmt(self: Metadata.String, builder: *const Builder) std.fmt.Alt(FormatData, format)

参数

self: Metadata.String
builder: *const Builder

std.zig.llvm.Builder.Metadata.String.format

函数

第 9176 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Metadata.String.FormatData

容器

第 9172 行

字段

metadata: Metadata.String
builder: *const Builder

std.zig.llvm.Builder.Metadata.String.Optional

容器

第 9130 行

字段

none = @bitCast(Metadata.Optional.none)
_

std.zig.llvm.Builder.Metadata.String.Optional.toMetadata

函数

第 9143 行

pub fn toMetadata(metadata: Metadata.String.Optional) Metadata.Optional

参数

std.zig.llvm.Builder.Metadata.String.Optional.unwrap

函数

第 9137 行

pub fn unwrap(metadata: Metadata.String.Optional) ?Metadata.String

参数

std.zig.llvm.Builder.Metadata.String.Optional.wrap

函数

第 9134 行

pub fn wrap(metadata: ?Metadata.String) Metadata.String.Optional

参数

metadata: ?Metadata.String

std.zig.llvm.Builder.Metadata.String.slice

函数

第 9154 行

pub fn slice(metadata: Metadata.String, builder: *const Builder) []const u8

参数

metadata: Metadata.String
builder: *const Builder

std.zig.llvm.Builder.Metadata.String.toMetadata

函数

第 9150 行

pub fn toMetadata(metadata: Metadata.String) Metadata

参数

metadata: Metadata.String

std.zig.llvm.Builder.Metadata.String.toOptional

函数

第 9147 行

pub fn toOptional(metadata: Metadata.String) Metadata.String.Optional

参数

metadata: Metadata.String

std.zig.llvm.Builder.Metadata.Subprogram

容器

第 9382 行

字段

file: Metadata.Optional
name: Metadata.String.Optional
linkage_name: Metadata.String.Optional
line: u32
scope_line: u32
ty: Metadata.Optional
di_flags: DIFlags
compile_unit: Metadata.Optional

std.zig.llvm.Builder.Metadata.Subprogram.DISPFlags

容器

第 9388 行

字段

Virtuality: enum(u2) { Zero, Virtual, PureVirtual } = .Zero
LocalToUnit: bool = false
Definition: bool = false
Optimized: bool = false
Pure: bool = false
Elemental: bool = false
Recursive: bool = false
MainSubprogram: bool = false
Deleted: bool = false
ReservedBit10: u1 = 0
ObjCDirect: bool = false
Unused: u20 = 0

std.zig.llvm.Builder.Metadata.Subprogram.DISPFlags.format

函数

第 9402 行

pub fn format(self: DISPFlags, w: *Writer) Writer.Error!void

参数

self: DISPFlags
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Metadata.Subprogram.Options

容器

第 9383 行

字段

di_flags: DIFlags
sp_flags: DISPFlags

std.zig.llvm.Builder.Metadata.Subrange

容器

第 9528 行

字段

lower_bound: Metadata.Optional
count: Metadata.Optional

std.zig.llvm.Builder.Metadata.SubroutineType

容器

第 9517 行

字段

types_tuple: Metadata.Optional

std.zig.llvm.Builder.Metadata.tag

函数

第 9274 行

pub fn tag(metadata: Metadata, builder: *const Builder) Tag

参数

metadata: Metadata
builder: *const Builder

std.zig.llvm.Builder.Metadata.Tag

容器

第 9188 行

字段

file
compile_unit
@"compile_unit optimized"
subprogram
@"subprogram local"
@"subprogram definition"
@"subprogram local definition"
@"subprogram optimized"
@"subprogram optimized local"
@"subprogram optimized definition"
@"subprogram optimized local definition"
lexical_block
location
basic_bool_type
basic_unsigned_type
basic_signed_type
basic_float_type
composite_struct_type
composite_union_type
composite_enumeration_type
composite_array_type
composite_vector_type
derived_pointer_type
derived_member_type
derived_typedef_type
subroutine_type
enumerator_unsigned
enumerator_signed_positive
enumerator_signed_negative
subrange
tuple
expression
local_var
parameter
global_var
@"global_var local"
global_var_expression
constant

std.zig.llvm.Builder.Metadata.Tag.isInline

函数

第 9228 行

pub fn isInline(metadata_tag: Metadata.Tag) bool

参数

metadata_tag: Metadata.Tag

std.zig.llvm.Builder.Metadata.toOptional

函数

第 9120 行

pub fn toOptional(metadata: Metadata) Metadata.Optional

参数

metadata: Metadata

std.zig.llvm.Builder.Metadata.toString

函数

第 9183 行

pub fn toString(metadata: Metadata) Metadata.String

参数

metadata: Metadata

std.zig.llvm.Builder.Metadata.toValue

函数

第 9123 行

pub fn toValue(metadata: Metadata) Value

参数

metadata: Metadata

std.zig.llvm.Builder.Metadata.Tuple

容器

第 9539 行

字段

elements_len: u32

std.zig.llvm.Builder.Metadata.unwrap

函数

第 9288 行

pub fn unwrap(metadata: Metadata, builder: *const Builder) Metadata

参数

metadata: Metadata
builder: *const Builder

std.zig.llvm.Builder.metadataConstant

函数

第 13759 行

pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadata

参数

self: *Builder
value: Constant

错误

OutOfMemory

std.zig.llvm.Builder.metadataConstantAssumeCapacity

函数

第 14452 行

fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata

参数

self: *Builder
constant: Constant

std.zig.llvm.Builder.metadataConstantAssumeCapacity.eql

函数

第 14461 行

pub fn eql(ctx: @This(), lhs_key: Constant, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Constant
_: void
rhs_index: usize

std.zig.llvm.Builder.metadataConstantAssumeCapacity.hash

函数

第 14455 行

pub fn hash(_: @This(), key: Constant) u32

参数

_: @This()
key: Constant

std.zig.llvm.Builder.metadataDistinctAssumeCapacity

函数

第 13811 行

fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata

参数

self: *Builder
tag: Metadata.Tag

std.zig.llvm.Builder.metadataExtraData

函数

第 13279 行

fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Item.ExtraIndex) T

参数

self: *const Builder
T: type
index: Metadata.Item.ExtraIndex

std.zig.llvm.Builder.metadataExtraDataTrail

类型函数

第 13255 行

fn metadataExtraDataTrail( self: *const Builder, comptime T: type, index: Metadata.Item.ExtraIndex, ) struct { data: T, trail: MetadataExtraDataTrail }

参数

self: *const Builder
T: type
index: Metadata.Item.ExtraIndex

std.zig.llvm.Builder.MetadataExtraDataTrail

容器

第 13234 行

字段

std.zig.llvm.Builder.MetadataExtraDataTrail.next

函数

第 13243 行

fn next( self: *MetadataExtraDataTrail, len: u32, comptime Item: type, builder: *const Builder, ) []const Item

参数

self: *MetadataExtraDataTrail
len: u32
Item: type
builder: *const Builder

std.zig.llvm.Builder.MetadataExtraDataTrail.nextMut

函数

第 13237 行

fn nextMut(self: *MetadataExtraDataTrail, len: u32, comptime Item: type, builder: *Builder) []Item

参数

self: *MetadataExtraDataTrail
len: u32
Item: type
builder: *Builder

std.zig.llvm.Builder.metadataSimpleAssumeCapacity

函数

第 13772 行

fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata

参数

self: *Builder
tag: Metadata.Tag

std.zig.llvm.Builder.metadataSimpleAssumeCapacity.eql

函数

第 13787 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.metadataSimpleAssumeCapacity.hash

函数

第 13779 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.metadataString

函数

第 13283 行

pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!Metadata.String

参数

self: *Builder
bytes: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.metadataStringFmt

函数

第 13309 行

pub fn metadataStringFmt( self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype, ) Allocator.Error!Metadata.String

参数

self: *Builder
fmt_str: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.metadataStringFmtAssumeCapacity

函数

第 13323 行

pub fn metadataStringFmtAssumeCapacity( self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype, ) Metadata.String

参数

self: *Builder
fmt_str: []const u8

std.zig.llvm.Builder.metadataStringFromStrtabString

函数

第 13302 行

pub fn metadataStringFromStrtabString( self: *Builder, str: StrtabString, ) Allocator.Error!Metadata.String

参数

self: *Builder
str: StrtabString

错误

OutOfMemory

std.zig.llvm.Builder.metadataTuple

函数

第 13689 行

pub fn metadataTuple(self: *Builder, elements: []const Metadata) Allocator.Error!Metadata

参数

self: *Builder
elements: []const Metadata

错误

OutOfMemory

std.zig.llvm.Builder.metadataTupleOptionals

函数

第 13693 行

pub fn metadataTupleOptionals( self: *Builder, elements: []const Metadata.Optional, ) Allocator.Error!Metadata

参数

self: *Builder
elements: []const Metadata.Optional

错误

OutOfMemory

std.zig.llvm.Builder.metadataTupleOptionalsAssumeCapacity

函数

第 14333 行

fn metadataTupleOptionalsAssumeCapacity(self: *Builder, elements: []const Metadata.Optional) Metadata

参数

self: *Builder
elements: []const Metadata.Optional

std.zig.llvm.Builder.metadataTupleOptionalsAssumeCapacity.eql

函数

第 14345 行

pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Key
_: void
rhs_index: usize

std.zig.llvm.Builder.metadataTupleOptionalsAssumeCapacity.hash

函数

第 14339 行

pub fn hash(_: @This(), key: Key) u32

参数

_: @This()
key: Key

std.zig.llvm.Builder.Mutability

容器

第 2822 行

字段

global
constant

std.zig.llvm.Builder.namedTypeSetBody

函数

第 10183 行

pub fn namedTypeSetBody( self: *Builder, named_type: Type, body_type: Type, ) void

参数

self: *Builder
named_type: Type
body_type: Type

std.zig.llvm.Builder.nanConst

函数

第 10494 行

pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.nanValue

函数

第 10507 行

pub fn nanValue(self: *Builder, ty: Type) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.noCfiConst

函数

第 10695 行

pub fn noCfiConst(self: *Builder, function: Function.Index) Allocator.Error!Constant

参数

self: *Builder
function: Function.Index

错误

OutOfMemory

std.zig.llvm.Builder.noCfiConstAssumeCapacity

函数

第 12754 行

fn noCfiConstAssumeCapacity(self: *Builder, function: Function.Index) Constant

参数

self: *Builder
function: Function.Index

std.zig.llvm.Builder.noCfiValue

函数

第 10700 行

pub fn noCfiValue(self: *Builder, function: Function.Index) Allocator.Error!Value

参数

self: *Builder
function: Function.Index

错误

OutOfMemory

std.zig.llvm.Builder.NoExtra

命名空间

第 11885 行

std.zig.llvm.Builder.noneConst

函数

第 10583 行

pub fn noneConst(self: *Builder, ty: Type) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.noneConstAssumeCapacity

函数

第 12522 行

fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant

参数

self: *Builder
ty: Type

std.zig.llvm.Builder.noneValue

函数

第 10588 行

pub fn noneValue(self: *Builder, ty: Type) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.nullConst

函数

第 10574 行

pub fn nullConst(self: *Builder, ty: Type) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.nullConstAssumeCapacity

函数

第 12514 行

fn nullConstAssumeCapacity(self: *Builder, ty: Type) Constant

参数

self: *Builder
ty: Type

std.zig.llvm.Builder.nullValue

函数

第 10579 行

pub fn nullValue(self: *Builder, ty: Type) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.opaqueType

函数

第 10170 行

pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type

参数

self: *Builder
name: String

错误

OutOfMemory

std.zig.llvm.Builder.opaqueTypeAssumeCapacity

函数

第 12119 行

fn opaqueTypeAssumeCapacity(self: *Builder, name: String) Type

参数

self: *Builder
name: String

std.zig.llvm.Builder.opaqueTypeAssumeCapacity.eql

函数

第 12128 行

pub fn eql(ctx: @This(), lhs_key: String, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: String
_: void
rhs_index: usize

std.zig.llvm.Builder.opaqueTypeAssumeCapacity.hash

函数

第 12122 行

pub fn hash(_: @This(), key: String) u32

参数

_: @This()
key: String

std.zig.llvm.Builder.Options

容器

第 82 行

字段

allocator: Allocator
strip: bool = true
name: []const u8 = &.{}
target: *const std.Target = &builtin.target

std.zig.llvm.Builder.poisonConst

函数

第 10660 行

pub fn poisonConst(self: *Builder, ty: Type) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.poisonConstAssumeCapacity

函数

第 12699 行

fn poisonConstAssumeCapacity(self: *Builder, ty: Type) Constant

参数

self: *Builder
ty: Type

std.zig.llvm.Builder.poisonValue

函数

第 10665 行

pub fn poisonValue(self: *Builder, ty: Type) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.ppc_fp128Const

函数

第 10565 行

pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant

参数

self: *Builder
val: [2]f64

错误

OutOfMemory

std.zig.llvm.Builder.ppc_fp128ConstAssumeCapacity

函数

第 12480 行

fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant

参数

self: *Builder
val: [2]f64

std.zig.llvm.Builder.ppc_fp128ConstAssumeCapacity.eql

函数

第 12489 行

pub fn eql(ctx: @This(), lhs_key: [2]f64, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: [2]f64
_: void
rhs_index: usize

std.zig.llvm.Builder.ppc_fp128ConstAssumeCapacity.hash

函数

第 12483 行

pub fn hash(_: @This(), key: [2]f64) u32

参数

_: @This()
key: [2]f64

std.zig.llvm.Builder.ppc_fp128Value

函数

第 10570 行

pub fn ppc_fp128Value(self: *Builder, value: [2]f64) Allocator.Error!Value

参数

self: *Builder
value: [2]f64

错误

OutOfMemory

std.zig.llvm.Builder.Preemption

容器

第 2749 行

字段

dso_preemptable
dso_local
implicit_dso_local

std.zig.llvm.Builder.Preemption.format

函数

第 2754 行

pub fn format(self: Preemption, w: *Writer) Writer.Error!void

参数

self: Preemption
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.print

函数

第 10823 行

pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void

参数

self: *Builder
w: *Writer

std.zig.llvm.Builder.print.expected_limbs

常量

第 11762 行

std.zig.llvm.Builder.printEscapedString

函数

第 11897 行

fn printEscapedString(slice: []const u8, quotes: QuoteBehavior, w: *Writer) Writer.Error!void

参数

slice: []const u8
quotes: QuoteBehavior
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.printToFile

函数

第 10817 行

pub fn printToFile(b: *Builder, io: Io, file: Io.File, buffer: []u8) !void

参数

b: *Builder
io: Io
file: Io.File
buffer: []u8

std.zig.llvm.Builder.printToFilePath

函数

第 10810 行

pub fn printToFilePath(b: *Builder, io: Io, dir: Io.Dir, path: []const u8) !void

参数

b: *Builder
io: Io
dir: Io.Dir
path: []const u8

std.zig.llvm.Builder.Producer

容器

第 14484 行

字段

name: []const u8
version: std.SemanticVersion

std.zig.llvm.Builder.ptrType

函数

第 10136 行

pub fn ptrType(self: *Builder, addr_space: AddrSpace) Allocator.Error!Type

参数

self: *Builder
addr_space: AddrSpace

错误

OutOfMemory

std.zig.llvm.Builder.ptrTypeAssumeCapacity

函数

第 11974 行

fn ptrTypeAssumeCapacity(self: *Builder, addr_space: AddrSpace) Type

参数

self: *Builder
addr_space: AddrSpace

std.zig.llvm.Builder.QuoteBehavior

容器

第 11896 行

字段

always_quote
quote_unless_valid_identifier

std.zig.llvm.Builder.resolveAlignmentForwardReference

函数

第 10799 行

将对齐前向引用 fwd_ref 的“已解析”值更新为 value。

断言 fwd_ref 是前向引用,而非已经解析的对齐值。

pub fn resolveAlignmentForwardReference(b: *Builder, fwd_ref: Alignment.Lazy, value: Alignment) void

参数

b: *Builder
fwd_ref: Alignment.Lazy
value: Alignment

std.zig.llvm.Builder.resolveDebugForwardReference

函数

第 13766 行

将给定前向引用解析为给定值(该值本身不能是前向引用)。 若此前向引用已解析,则替换其目标。

pub fn resolveDebugForwardReference(self: *Builder, fwd_ref: Metadata, value: Metadata) void

参数

self: *Builder
fwd_ref: Metadata
value: Metadata

std.zig.llvm.Builder.splatConst

函数

第 10629 行

pub fn splatConst(self: *Builder, ty: Type, val: Constant) Allocator.Error!Constant

参数

self: *Builder
ty: Type
val: Constant

错误

OutOfMemory

std.zig.llvm.Builder.splatConstAssumeCapacity

函数

第 12610 行

fn splatConstAssumeCapacity(self: *Builder, ty: Type, val: Constant) Constant

参数

self: *Builder
ty: Type
val: Constant

std.zig.llvm.Builder.splatConstAssumeCapacity.eql

函数

第 12624 行

pub fn eql(ctx: @This(), lhs_key: Constant.Splat, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Constant.Splat
_: void
rhs_index: usize

std.zig.llvm.Builder.splatConstAssumeCapacity.hash

函数

第 12618 行

pub fn hash(_: @This(), key: Constant.Splat) u32

参数

_: @This()
key: Constant.Splat

std.zig.llvm.Builder.splatValue

函数

第 10634 行

pub fn splatValue(self: *Builder, ty: Type, val: Constant) Allocator.Error!Value

参数

self: *Builder
ty: Type
val: Constant

错误

OutOfMemory

std.zig.llvm.Builder.std

别名

第 4 行

别名目标 std

std.zig.llvm.Builder.string

函数

第 10066 行

pub fn string(self: *Builder, bytes: []const u8) Allocator.Error!String

参数

self: *Builder
bytes: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.String

容器

第 833 行

字段

none = maxInt(u31)
empty
_

std.zig.llvm.Builder.String.Adapter

容器

第 896 行

字段

builder: *const Builder

std.zig.llvm.Builder.String.Adapter.eql

函数

第 901 行

pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool

参数

ctx: Adapter
lhs_key: []const u8
_: void
rhs_index: usize

std.zig.llvm.Builder.String.Adapter.hash

函数

第 898 行

pub fn hash(_: Adapter, key: []const u8) u32

参数

_: Adapter
key: []const u8

std.zig.llvm.Builder.String.fmt

函数

第 863 行

pub fn fmt(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format)

参数

self: String
builder: *const Builder

std.zig.llvm.Builder.String.fmtQ

函数

第 871 行

pub fn fmtQ(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format)

参数

self: String
builder: *const Builder

std.zig.llvm.Builder.String.fmtRaw

函数

第 879 行

pub fn fmtRaw(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format)

参数

self: String
builder: *const Builder

std.zig.llvm.Builder.String.format

函数

第 855 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.String.FormatData

容器

第 850 行

字段

string: String
builder: *const Builder
quote_behavior: ?QuoteBehavior

std.zig.llvm.Builder.String.fromIndex

函数

第 887 行

fn fromIndex(index: ?usize) String

参数

index: ?usize

std.zig.llvm.Builder.String.isAnon

函数

第 838 行

pub fn isAnon(self: String) bool

参数

self: String

std.zig.llvm.Builder.String.slice

函数

第 843 行

pub fn slice(self: String, builder: *const Builder) ?[]const u8

参数

self: String
builder: *const Builder

std.zig.llvm.Builder.String.toIndex

函数

第 892 行

fn toIndex(self: String) ?usize

参数

self: String

std.zig.llvm.Builder.stringConst

函数

第 10610 行

pub fn stringConst(self: *Builder, val: String) Allocator.Error!Constant

参数

self: *Builder
val: String

错误

OutOfMemory

std.zig.llvm.Builder.stringConstAssumeCapacity

函数

第 12584 行

fn stringConstAssumeCapacity(self: *Builder, val: String) Constant

参数

self: *Builder
val: String

std.zig.llvm.Builder.stringIfExists

函数

第 10083 行

pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String

参数

self: *const Builder
bytes: []const u8

std.zig.llvm.Builder.stringNull

函数

第 10079 行

pub fn stringNull(self: *Builder, bytes: [:0]const u8) Allocator.Error!String

参数

self: *Builder
bytes: [:0]const u8

错误

OutOfMemory

std.zig.llvm.Builder.stringValue

函数

第 10616 行

pub fn stringValue(self: *Builder, val: String) Allocator.Error!Value

参数

self: *Builder
val: String

错误

OutOfMemory

std.zig.llvm.Builder.strtabString

函数

第 3221 行

pub fn strtabString(self: *Builder, bytes: []const u8) Allocator.Error!StrtabString

参数

self: *Builder
bytes: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.StrtabString

容器

第 3161 行

字段

none = maxInt(u31)
empty
_

std.zig.llvm.Builder.StrtabString.Adapter

容器

第 3210 行

字段

builder: *const Builder

std.zig.llvm.Builder.StrtabString.Adapter.eql

函数

第 3215 行

pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool

参数

ctx: Adapter
lhs_key: []const u8
_: void
rhs_index: usize

std.zig.llvm.Builder.StrtabString.Adapter.hash

函数

第 3212 行

pub fn hash(_: Adapter, key: []const u8) u32

参数

_: Adapter
key: []const u8

std.zig.llvm.Builder.StrtabString.fmt

函数

第 3190 行

pub fn fmt( self: StrtabString, builder: *const Builder, quote_behavior: ?QuoteBehavior, ) std.fmt.Alt(FormatData, format)

参数

self: StrtabString
builder: *const Builder
quote_behavior: ?QuoteBehavior

std.zig.llvm.Builder.StrtabString.format

函数

第 3183 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.StrtabString.FormatData

容器

第 3178 行

字段

string: StrtabString
builder: *const Builder
quote_behavior: ?QuoteBehavior

std.zig.llvm.Builder.StrtabString.fromIndex

函数

第 3202 行

fn fromIndex(index: ?usize) StrtabString

参数

index: ?usize

std.zig.llvm.Builder.StrtabString.isAnon

函数

第 3166 行

pub fn isAnon(self: StrtabString) bool

参数

self: StrtabString

std.zig.llvm.Builder.StrtabString.slice

函数

第 3171 行

pub fn slice(self: StrtabString, builder: *const Builder) ?[]const u8

参数

self: StrtabString
builder: *const Builder

std.zig.llvm.Builder.StrtabString.toIndex

函数

第 3206 行

fn toIndex(self: StrtabString) ?usize

参数

self: StrtabString

std.zig.llvm.Builder.strtabStringFmt

函数

第 3240 行

pub fn strtabStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!StrtabString

参数

self: *Builder
fmt_str: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.strtabStringFmtAssumeCapacity

函数

第 3247 行

pub fn strtabStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) StrtabString

参数

self: *Builder
fmt_str: []const u8

std.zig.llvm.Builder.strtabStringIfExists

函数

第 3234 行

pub fn strtabStringIfExists(self: *const Builder, bytes: []const u8) ?StrtabString

参数

self: *const Builder
bytes: []const u8

std.zig.llvm.Builder.structConst

函数

第 10592 行

pub fn structConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant

参数

self: *Builder
ty: Type
vals: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.structConstAssumeCapacity

函数

第 12530 行

fn structConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant

参数

self: *Builder
ty: Type
vals: []const Constant

std.zig.llvm.Builder.structType

函数

第 10159 行

pub fn structType( self: *Builder, kind: Type.Structure.Kind, fields: []const Type, ) Allocator.Error!Type

参数

self: *Builder
kind: Type.Structure.Kind
fields: []const Type

错误

OutOfMemory

std.zig.llvm.Builder.structTypeAssumeCapacity

函数

第 12079 行

fn structTypeAssumeCapacity( self: *Builder, comptime kind: Type.Structure.Kind, fields: []const Type, ) Type

参数

self: *Builder
kind: Type.Structure.Kind
fields: []const Type

std.zig.llvm.Builder.structTypeAssumeCapacity.eql

函数

第 12096 行

pub fn eql(ctx: @This(), lhs_key: []const Type, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: []const Type
_: void
rhs_index: usize

std.zig.llvm.Builder.structTypeAssumeCapacity.hash

函数

第 12090 行

pub fn hash(_: @This(), key: []const Type) u32

参数

_: @This()
key: []const Type

std.zig.llvm.Builder.structValue

函数

第 10597 行

pub fn structValue(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Value

参数

self: *Builder
ty: Type
vals: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.subArchName

函数

第 89 行

fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.Family, mappings: anytype) ?[]const u8

参数

target: *const std.Target
family: std.Target.Cpu.Arch.Family

std.zig.llvm.Builder.SyncScope

容器

第 8252 行

字段

singlethread
system

std.zig.llvm.Builder.SyncScope.fmt

函数

第 8275 行

pub fn fmt(sync_scope: SyncScope, prefix: []const u8) Prefixed

参数

sync_scope: SyncScope
prefix: []const u8

std.zig.llvm.Builder.SyncScope.format

函数

第 8256 行

pub fn format(sync_scope: SyncScope, w: *Writer) Writer.Error!void

参数

sync_scope: SyncScope
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.SyncScope.Prefixed

容器

第 8260 行

字段

sync_scope: SyncScope
prefix: []const u8

std.zig.llvm.Builder.SyncScope.Prefixed.format

函数

第 8264 行

pub fn format(p: Prefixed, w: *Writer) Writer.Error!void

参数

p: Prefixed
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.ThreadLocal

容器

第 2787 行

字段

default = 0
generaldynamic = 1
localdynamic = 2
initialexec = 3
localexec = 4

std.zig.llvm.Builder.ThreadLocal.fmt

函数

第 2817 行

pub fn fmt(tl: ThreadLocal, prefix: []const u8) Prefixed

参数

tl: ThreadLocal
prefix: []const u8

std.zig.llvm.Builder.ThreadLocal.format

函数

第 2794 行

pub fn format(tl: ThreadLocal, w: *Writer) Writer.Error!void

参数

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.ThreadLocal.Prefixed

容器

第 2798 行

字段

thread_local: ThreadLocal
prefix: []const u8

std.zig.llvm.Builder.ThreadLocal.Prefixed.format

函数

第 2802 行

pub fn format(p: Prefixed, w: *Writer) Writer.Error!void

参数

p: Prefixed
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.toBitcode

函数

第 14489 行

pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitcode_writer.Error![]const u32

参数

self: *Builder
allocator: Allocator
producer: Producer

错误

OutOfMemory

std.zig.llvm.Builder.toBitcode.firstInstr

函数

第 15890 行

fn firstInstr(adapter: @This()) u32

参数

adapter: @This()

std.zig.llvm.Builder.toBitcode.get

函数

第 14953 行

pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { Constant => u32, else => |Param| Param, }

参数

adapter: @This()

std.zig.llvm.Builder.toBitcode.get

函数

第 15401 行

pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { Metadata, Metadata.Optional, Metadata.String, Metadata.String.Optional, Constant => u32, else => |Result| Result, }

参数

adapter: @This()

std.zig.llvm.Builder.toBitcode.get

函数

第 15838 行

pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) { Value, Constant, FunctionAttributes => u32, else => |Result| Result, }

参数

adapter: @This()

std.zig.llvm.Builder.toBitcode.getConstantIndex

函数

第 14963 行

pub fn getConstantIndex(adapter: @This(), constant: Constant) u32

参数

adapter: @This()
constant: Constant

std.zig.llvm.Builder.toBitcode.getMetadataIndex

函数

第 15415 行

pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32

参数

adapter: @This()
metadata: Metadata

std.zig.llvm.Builder.toBitcode.getOffsetConstantIndex

函数

第 15882 行

pub fn getOffsetConstantIndex(adapter: @This(), constant: Constant) u32

参数

adapter: @This()
constant: Constant

std.zig.llvm.Builder.toBitcode.getOffsetValueIndex

函数

第 15872 行

pub fn getOffsetValueIndex(adapter: @This(), value: Value) u32

参数

adapter: @This()
value: Value

std.zig.llvm.Builder.toBitcode.getOffsetValueSignedIndex

函数

第 15876 行

pub fn getOffsetValueSignedIndex(adapter: @This(), value: Value) i32

参数

adapter: @This()
value: Value

std.zig.llvm.Builder.toBitcode.getOptionalMetadataIndex

函数

第 15425 行

pub fn getOptionalMetadataIndex(adapter: @This(), metadata: Metadata.Optional) u32

参数

adapter: @This()
metadata: Metadata.Optional

std.zig.llvm.Builder.toBitcode.getValueIndex

函数

第 15854 行

pub fn getValueIndex(adapter: @This(), value: Value) u32

参数

adapter: @This()
value: Value

std.zig.llvm.Builder.toBitcode.numConstants

函数

第 14970 行

pub fn numConstants(adapter: @This()) u32

参数

adapter: @This()

std.zig.llvm.Builder.toBitcode.numGlobals

函数

第 14974 行

pub fn numGlobals(adapter: @This()) u32

参数

adapter: @This()

std.zig.llvm.Builder.toBitcode.offset

函数

第 15886 行

pub fn offset(adapter: @This()) u32

参数

adapter: @This()

std.zig.llvm.Builder.trailingMetadataString

函数

第 13332 行

pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String

参数

self: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.trailingMetadataStringAssumeCapacity

函数

第 13338 行

pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String

参数

self: *Builder

std.zig.llvm.Builder.trailingString

函数

第 10101 行

pub fn trailingString(self: *Builder) Allocator.Error!String

参数

self: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.trailingStringAssumeCapacity

函数

第 10107 行

pub fn trailingStringAssumeCapacity(self: *Builder) String

参数

self: *Builder

std.zig.llvm.Builder.trailingStrtabString

函数

第 3252 行

pub fn trailingStrtabString(self: *Builder) Allocator.Error!StrtabString

参数

self: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.trailingStrtabStringAssumeCapacity

函数

第 3258 行

pub fn trailingStrtabStringAssumeCapacity(self: *Builder) StrtabString

参数

self: *Builder

std.zig.llvm.Builder.tripleForTarget

函数

第 97 行

pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const u8

参数

allocator: Allocator
target: *const std.Target

std.zig.llvm.Builder.Type

容器

第 968 行

字段

void
half
bfloat
float
double
fp128
x86_fp80
ppc_fp128
x86_amx
x86_mmx
label
token
metadata
i1
i8
i16
i29
i32
i64
i80
i128
ptr
@"ptr addrspace(4)"
none = maxInt(u32)
_

std.zig.llvm.Builder.Type.aggregateLen

函数

第 1360 行

pub fn aggregateLen(self: Type, builder: *const Builder) usize

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.alignment

函数

第 1705 行

pub fn alignment(ty: Type, kind: enum { abi, pref }, builder: *const Builder) Alignment

参数

ty: Type
kind: enum { abi, pref }
builder: *const Builder

std.zig.llvm.Builder.Type.Array

容器

第 1060 行

字段

len_lo: u32
len_hi: u32
child: Type

std.zig.llvm.Builder.Type.Array.length

函数

第 1065 行

fn length(self: Array) u64

参数

self: Array

std.zig.llvm.Builder.Type.bits

函数

第 1684 行

pub fn bits(ty: Type, builder: *const Builder) Size

参数

ty: Type
builder: *const Builder

std.zig.llvm.Builder.Type.changeLength

函数

第 1329 行

pub fn changeLength(self: Type, len: u32, builder: *Builder) Allocator.Error!Type

参数

self: Type
len: u32
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Type.changeLengthAssumeCapacity

函数

第 1334 行

pub fn changeLengthAssumeCapacity(self: Type, len: u32, builder: *Builder) Type

参数

self: Type
len: u32
builder: *Builder

std.zig.llvm.Builder.Type.changeScalar

函数

第 1292 行

pub fn changeScalar(self: Type, scalar: Type, builder: *Builder) Allocator.Error!Type

参数

self: Type
scalar: Type
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Type.changeScalarAssumeCapacity

函数

第 1297 行

pub fn changeScalarAssumeCapacity(self: Type, scalar: Type, builder: *Builder) Type

参数

self: Type
scalar: Type
builder: *Builder

std.zig.llvm.Builder.Type.childType

函数

第 1265 行

pub fn childType(self: Type, builder: *const Builder) Type

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.childTypeAt

函数

第 1392 行

pub fn childTypeAt(self: Type, indices: []const u32, builder: *const Builder) Type

参数

self: Type
indices: []const u32
builder: *const Builder

std.zig.llvm.Builder.Type.fmt

函数

第 1604 行

pub fn fmt(self: Type, builder: *const Builder, mode: FormatData.Mode) std.fmt.Alt(FormatData, format)

参数

self: Type
builder: *const Builder
mode: FormatData.Mode

std.zig.llvm.Builder.Type.format

函数

第 1433 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Type.FormatData

容器

第 1426 行

字段

type: Type
builder: *const Builder
mode: Mode

std.zig.llvm.Builder.Type.FormatData.Mode

容器

第 1431 行

字段

default
m
lt
gt
percent

std.zig.llvm.Builder.Type.Function

容器

第 1033 行

字段

ret: Type
params_len: u32

std.zig.llvm.Builder.Type.Function.Kind

容器

第 1038 行

字段

normal
vararg

std.zig.llvm.Builder.Type.functionKind

函数

第 1156 行

pub fn functionKind(self: Type, builder: *const Builder) Type.Function.Kind

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.functionParameters

函数

第 1164 行

pub fn functionParameters(self: Type, builder: *const Builder) []const Type

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.functionReturn

函数

第 1177 行

pub fn functionReturn(self: Type, builder: *const Builder) Type

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.isAggregate

函数

第 1217 行

pub fn isAggregate(self: Type, builder: *const Builder) bool

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.isFloatingPoint

函数

第 1111 行

pub fn isFloatingPoint(self: Type) bool

参数

self: Type

std.zig.llvm.Builder.Type.isFunction

函数

第 1149 行

pub fn isFunction(self: Type, builder: *const Builder) bool

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.isInteger

函数

第 1118 行

pub fn isInteger(self: Type, builder: *const Builder) bool

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.isPointer

函数

第 1128 行

pub fn isPointer(self: Type, builder: *const Builder) bool

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.isSized

函数

第 1419 行

pub fn isSized(self: Type, builder: *const Builder) Allocator.Error!bool

参数

self: Type
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.Type.isSizedVisited

函数

第 1609 行

fn isSizedVisited( self: Type, visited: *IsSizedVisited, builder: *const Builder, ) Allocator.Error!bool

参数

self: Type
visited: *IsSizedVisited
builder: *const Builder

错误

OutOfMemory

std.zig.llvm.Builder.Type.IsSizedVisited

类型

第 1608 行

std.zig.llvm.Builder.Type.isStruct

函数

第 1202 行

pub fn isStruct(self: Type, builder: *const Builder) bool

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.isVector

函数

第 1187 行

pub fn isVector(self: Type, builder: *const Builder) bool

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.Item

容器

第 1082 行

字段

tag: Tag
data: ExtraIndex

std.zig.llvm.Builder.Type.Item.ExtraIndex

类型

第 1086 行

std.zig.llvm.Builder.Type.NamedStructure

容器

第 1077 行

字段

id: String
body: Type

std.zig.llvm.Builder.Type.pointerAddrSpace

函数

第 1138 行

pub fn pointerAddrSpace(self: Type, builder: *const Builder) AddrSpace

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.ptr_amdgpu_constant

常量

第 997 行

std.zig.llvm.Builder.Type.scalarBits

函数

第 1224 行

pub fn scalarBits(self: Type, builder: *const Builder) u24

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.scalarTag

函数

第 1102 行

pub fn scalarTag(self: Type, builder: *const Builder) Tag

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.scalarType

函数

第 1278 行

pub fn scalarType(self: Type, builder: *const Builder) Type

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.Simple

容器

第 1016 行

字段

void = @backingInt(Code.VOID)
half = @backingInt(Code.HALF)
bfloat = @backingInt(Code.BFLOAT)
float = @backingInt(Code.FLOAT)
double = @backingInt(Code.DOUBLE)
fp128 = @backingInt(Code.FP128)
x86_fp80 = @backingInt(Code.X86_FP80)
ppc_fp128 = @backingInt(Code.PPC_FP128)
x86_amx = @backingInt(Code.X86_AMX)
x86_mmx = @backingInt(Code.X86_MMX)
label = @backingInt(Code.LABEL)
token = @backingInt(Code.TOKEN)
metadata = @backingInt(Code.METADATA)

std.zig.llvm.Builder.Type.Simple.Code

别名

第 1017 行

别名目标 std.zig.llvm.ir.ModuleBlock.TypeBlock.Code

std.zig.llvm.Builder.Type.Size

容器

第 1683 行

字段

fixed: u64
scalable: u64

std.zig.llvm.Builder.Type.structFields

函数

第 1377 行

pub fn structFields(self: Type, builder: *const Builder) []const Type

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.structKind

函数

第 1209 行

pub fn structKind(self: Type, builder: *const Builder) Type.Structure.Kind

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.Structure

容器

第 1070 行

字段

fields_len: u32

std.zig.llvm.Builder.Type.Structure.Kind

容器

第 1074 行

字段

normal
@"packed"

std.zig.llvm.Builder.Type.tag

函数

第 1089 行

pub fn tag(self: Type, builder: *const Builder) Tag

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.Tag

容器

第 1000 行

字段

simple
function
vararg_function
integer
pointer
target
vector
scalable_vector
small_array
array
structure
packed_structure
named_structure

std.zig.llvm.Builder.Type.Target

容器

第 1041 行

字段

name: String
types_len: u32
ints_len: u32

std.zig.llvm.Builder.Type.targetLayoutType

函数

第 1413 行

pub fn targetLayoutType(self: Type, builder: *const Builder) Type

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.unnamedTag

函数

第 1093 行

pub fn unnamedTag(self: Type, builder: *const Builder) Tag

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.Vector

容器

第 1049 行

字段

len: u32
child: Type

std.zig.llvm.Builder.Type.Vector.Kind

容器

第 1057 行

字段

normal
scalable

std.zig.llvm.Builder.Type.Vector.length

函数

第 1053 行

fn length(self: Vector) u32

参数

self: Vector

std.zig.llvm.Builder.Type.vectorKind

函数

第 1194 行

pub fn vectorKind(self: Type, builder: *const Builder) Type.Vector.Kind

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.Type.vectorLen

函数

第 1319 行

pub fn vectorLen(self: Type, builder: *const Builder) u32

参数

self: Type
builder: *const Builder

std.zig.llvm.Builder.typeExtraData

函数

第 12262 行

fn typeExtraData(self: *const Builder, comptime T: type, index: Type.Item.ExtraIndex) T

参数

self: *const Builder
T: type
index: Type.Item.ExtraIndex

std.zig.llvm.Builder.typeExtraDataTrail

类型函数

第 12239 行

fn typeExtraDataTrail( self: *const Builder, comptime T: type, index: Type.Item.ExtraIndex, ) struct { data: T, trail: TypeExtraDataTrail }

参数

self: *const Builder
T: type
index: Type.Item.ExtraIndex

std.zig.llvm.Builder.TypeExtraDataTrail

容器

第 12218 行

字段

std.zig.llvm.Builder.TypeExtraDataTrail.next

函数

第 12227 行

fn next( self: *TypeExtraDataTrail, len: u32, comptime Item: type, builder: *const Builder, ) []const Item

参数

self: *TypeExtraDataTrail
len: u32
Item: type
builder: *const Builder

std.zig.llvm.Builder.TypeExtraDataTrail.nextMut

函数

第 12221 行

fn nextMut(self: *TypeExtraDataTrail, len: u32, comptime Item: type, builder: *Builder) []Item

参数

self: *TypeExtraDataTrail
len: u32
Item: type
builder: *Builder

std.zig.llvm.Builder.undefConst

函数

第 10651 行

pub fn undefConst(self: *Builder, ty: Type) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.undefConstAssumeCapacity

函数

第 12684 行

fn undefConstAssumeCapacity(self: *Builder, ty: Type) Constant

参数

self: *Builder
ty: Type

std.zig.llvm.Builder.undefValue

函数

第 10656 行

pub fn undefValue(self: *Builder, ty: Type) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.UnnamedAddr

容器

第 2824 行

字段

default = 0
unnamed_addr = 1
local_unnamed_addr = 2

std.zig.llvm.Builder.UnnamedAddr.format

函数

第 2829 行

pub fn format(self: UnnamedAddr, w: *Writer) Writer.Error!void

参数

self: UnnamedAddr
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Value

容器

第 9011 行

字段

none = maxInt(u31)
false = first_constant + @backingInt(Constant.false)
true = first_constant + @backingInt(Constant.true)
@"0" = first_constant + @backingInt(Constant.@"0")
@"1" = first_constant + @backingInt(Constant.@"1")
_

std.zig.llvm.Builder.Value.first_constant

常量

第 9019 行

std.zig.llvm.Builder.Value.first_metadata

常量

第 9020 行

std.zig.llvm.Builder.Value.fmt

函数

第 9080 行

pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format)

参数

self: Value
function: Function.Index
builder: *Builder
flags: FormatFlags

std.zig.llvm.Builder.Value.format

函数

第 9064 行

fn format(data: FormatData, w: *Writer) Writer.Error!void

参数

data: FormatData
w: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Value.FormatData

容器

第 9058 行

字段

value: Value
function: Function.Index
builder: *Builder
flags: FormatFlags

std.zig.llvm.Builder.Value.toConst

函数

第 9051 行

pub fn toConst(self: Value) ?Constant

参数

self: Value

std.zig.llvm.Builder.Value.typeOf

函数

第 9043 行

pub fn typeOf(self: Value, function: Function.Index, builder: *Builder) Type

参数

self: Value
function: Function.Index
builder: *Builder

std.zig.llvm.Builder.Value.typeOfWip

函数

第 9035 行

pub fn typeOfWip(self: Value, wip: *const WipFunction) Type

参数

self: Value
wip: *const WipFunction

std.zig.llvm.Builder.Value.unwrap

类型函数

第 9022 行

pub fn unwrap(self: Value) union(enum) { instruction: Function.Instruction.Index, constant: Constant, metadata: Metadata, }

参数

self: Value

std.zig.llvm.Builder.Variable

容器

第 3535 行

字段

global: Global.Index
thread_local: ThreadLocal = .default
mutability: Mutability = .global
init: Constant = .no_init
section: String = .none
alignment: Alignment = .default

std.zig.llvm.Builder.Variable.Index

容器

第 3543 行

字段

none = maxInt(u32)
_

std.zig.llvm.Builder.Variable.Index.getAlignment

函数

第 3605 行

pub fn getAlignment(self: Index, builder: *Builder) Alignment

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Variable.Index.getGlobalVariableExpression

函数

第 3613 行

pub fn getGlobalVariableExpression(self: Index, builder: *Builder) Metadata.Optional

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Variable.Index.name

函数

第 3555 行

pub fn name(self: Index, builder: *const Builder) StrtabString

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Variable.Index.ptr

函数

第 3547 行

pub fn ptr(self: Index, builder: *Builder) *Variable

参数

self: Index
builder: *Builder

std.zig.llvm.Builder.Variable.Index.ptrConst

函数

第 3551 行

pub fn ptrConst(self: Index, builder: *const Builder) *const Variable

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Variable.Index.rename

函数

第 3559 行

pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void

参数

self: Index
new_name: StrtabString
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Variable.Index.setAlignment

函数

第 3601 行

pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void

参数

self: Index
alignment: Alignment
builder: *Builder

std.zig.llvm.Builder.Variable.Index.setGlobalVariableExpression

函数

第 3609 行

pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void

参数

self: Index
expression: Metadata
builder: *Builder

std.zig.llvm.Builder.Variable.Index.setInitializer

函数

第 3583 行

pub fn setInitializer( self: Index, initializer: Constant, builder: *Builder, ) Allocator.Error!void

参数

self: Index
initializer: Constant
builder: *Builder

错误

OutOfMemory

std.zig.llvm.Builder.Variable.Index.setMutability

函数

第 3579 行

pub fn setMutability(self: Index, mutability: Mutability, builder: *Builder) void

参数

self: Index
mutability: Mutability
builder: *Builder

std.zig.llvm.Builder.Variable.Index.setSection

函数

第 3597 行

pub fn setSection(self: Index, section: String, builder: *Builder) void

参数

self: Index
section: String
builder: *Builder

std.zig.llvm.Builder.Variable.Index.setThreadLocal

函数

第 3575 行

pub fn setThreadLocal(self: Index, thread_local: ThreadLocal, builder: *Builder) void

参数

self: Index
thread_local: ThreadLocal
builder: *Builder

std.zig.llvm.Builder.Variable.Index.toConst

函数

第 3567 行

pub fn toConst(self: Index, builder: *const Builder) Constant

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Variable.Index.toValue

函数

第 3571 行

pub fn toValue(self: Index, builder: *const Builder) Value

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.Variable.Index.typeOf

函数

第 3563 行

pub fn typeOf(self: Index, builder: *const Builder) Type

参数

self: Index
builder: *const Builder

std.zig.llvm.Builder.vectorConst

函数

第 10620 行

pub fn vectorConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant

参数

self: *Builder
ty: Type
vals: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.vectorConstAssumeCapacity

函数

第 12594 行

fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant

参数

self: *Builder
ty: Type
vals: []const Constant

std.zig.llvm.Builder.vectorType

函数

第 10141 行

pub fn vectorType( self: *Builder, kind: Type.Vector.Kind, len: u32, child: Type, ) Allocator.Error!Type

参数

self: *Builder
kind: Type.Vector.Kind
len: u32
child: Type

错误

OutOfMemory

std.zig.llvm.Builder.vectorTypeAssumeCapacity

函数

第 11981 行

fn vectorTypeAssumeCapacity( self: *Builder, comptime kind: Type.Vector.Kind, len: u32, child: Type, ) Type

参数

self: *Builder
kind: Type.Vector.Kind
len: u32
child: Type

std.zig.llvm.Builder.vectorTypeAssumeCapacity.eql

函数

第 12000 行

pub fn eql(ctx: @This(), lhs_key: Type.Vector, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: Type.Vector
_: void
rhs_index: usize

std.zig.llvm.Builder.vectorTypeAssumeCapacity.hash

函数

第 11994 行

pub fn hash(_: @This(), key: Type.Vector) u32

参数

_: @This()
key: Type.Vector

std.zig.llvm.Builder.vectorValue

函数

第 10625 行

pub fn vectorValue(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Value

参数

self: *Builder
ty: Type
vals: []const Constant

错误

OutOfMemory

std.zig.llvm.Builder.Visibility

容器

第 2759 行

字段

default = 0
hidden = 1
protected = 2

std.zig.llvm.Builder.Visibility.format

函数

第 2772 行

pub fn format(self: Visibility, writer: *Writer) Writer.Error!void

参数

self: Visibility
writer: *Writer

错误

WriteFailed

详细诊断信息见 Writer 实现。

std.zig.llvm.Builder.Visibility.fromSymbolVisibility

函数

第 2764 行

pub fn fromSymbolVisibility(sv: std.lang.SymbolVisibility) Visibility

参数

std.zig.llvm.Builder.WipFunction

容器

第 6341 行

字段

builder: *Builder
function: Function.Index
prev_debug_location: DebugLocation
debug_location: DebugLocation
cursor: Cursor
blocks: std.ArrayList(Block)
instructions: std.MultiArrayList(Instruction)
names: std.ArrayList(String)
strip: bool
debug_locations: std.array_hash_map.Auto(Instruction.Index, DebugLocation)
debug_values: std.array_hash_map.Auto(Instruction.Index, void)
extra: std.ArrayList(u32)

std.zig.llvm.Builder.WipFunction.@"switch"

函数

第 6522 行

pub fn @"switch"( self: *WipFunction, val: Value, default: Block.Index, cases_len: u32, weights: Instruction.BrCond.Weights, ) Allocator.Error!WipSwitch

参数

self: *WipFunction
val: Value
default: Block.Index
cases_len: u32
weights: Instruction.BrCond.Weights

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.@"unreachable"

函数

第 6562 行

pub fn @"unreachable"(self: *WipFunction) Allocator.Error!Instruction.Index

参数

self: *WipFunction

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.addExtraAssumeCapacity

函数

第 8109 行

fn addExtraAssumeCapacity(self: *WipFunction, extra: anytype) Instruction.ExtraIndex

参数

self: *WipFunction

std.zig.llvm.Builder.WipFunction.addInst

函数

第 8076 行

fn addInst( self: *WipFunction, name: ?[]const u8, instruction: Instruction, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
name: ?[]const u8
instruction: Instruction

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.alloca

函数

第 6782 行

pub fn alloca( self: *WipFunction, kind: Instruction.Alloca.Kind, ty: Type, len: Value, alignment: Alignment, addr_space: AddrSpace, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
kind: Instruction.Alloca.Kind
ty: Type
len: Value
alignment: Alignment
addr_space: AddrSpace
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.arg

函数

第 6419 行

pub fn arg(self: *const WipFunction, index: u32) Value

参数

self: *const WipFunction
index: u32

std.zig.llvm.Builder.WipFunction.atomicrmw

函数

第 6958 行

pub fn atomicrmw( self: *WipFunction, access_kind: MemoryAccessKind, operation: Instruction.AtomicRmw.Operation, ptr: Value, val: Value, sync_scope: SyncScope, ordering: AtomicOrdering, alignment: Alignment, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
access_kind: MemoryAccessKind
operation: Instruction.AtomicRmw.Operation
ptr: Value
val: Value
sync_scope: SyncScope
ordering: AtomicOrdering
alignment: Alignment
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.bin

函数

第 6597 行

pub fn bin( self: *WipFunction, tag: Instruction.Tag, lhs: Value, rhs: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
tag: Instruction.Tag
lhs: Value
rhs: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.block

函数

第 6428 行

pub fn block(self: *WipFunction, incoming: u32, name: []const u8) Allocator.Error!Block.Index

参数

self: *WipFunction
incoming: u32
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.Block

容器

第 6357 行

字段

name: String
incoming: u32
branches: u32 = 0
instructions: std.ArrayList(Instruction.Index)

std.zig.llvm.Builder.WipFunction.Block.Index

容器

第 6363 行

字段

entry
_

std.zig.llvm.Builder.WipFunction.Block.Index.ptr

函数

第 6367 行

pub fn ptr(self: Index, wip: *WipFunction) *Block

参数

self: Index
wip: *WipFunction

std.zig.llvm.Builder.WipFunction.Block.Index.ptrConst

函数

第 6371 行

pub fn ptrConst(self: Index, wip: *const WipFunction) *const Block

参数

self: Index
wip: *const WipFunction

std.zig.llvm.Builder.WipFunction.Block.Index.toInst

函数

第 6375 行

pub fn toInst(self: Index, function: *const Function) Instruction.Index

参数

self: Index
function: *const Function

std.zig.llvm.Builder.WipFunction.br

函数

第 6452 行

pub fn br(self: *WipFunction, dest: Block.Index) Allocator.Error!Instruction.Index

参数

self: *WipFunction
dest: Block.Index

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.brCond

函数

第 6459 行

pub fn brCond( self: *WipFunction, cond: Value, then: Block.Index, @"else": Block.Index, weights: enum { none, unpredictable, then_likely, else_likely }, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
cond: Value
then: Block.Index
@"else": Block.Index
weights: enum { none, unpredictable, then_likely, else_likely }

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.buildAggregate

函数

第 6769 行

pub fn buildAggregate( self: *WipFunction, ty: Type, elems: []const Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
ty: Type
elems: []const Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.call

函数

第 7187 行

pub fn call( self: *WipFunction, kind: Instruction.Call.Kind, call_conv: CallConv, function_attributes: FunctionAttributes, ty: Type, callee: Value, args: []const Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
kind: Instruction.Call.Kind
call_conv: CallConv
function_attributes: FunctionAttributes
ty: Type
callee: Value
args: []const Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callAsm

函数

第 7247 行

pub fn callAsm( self: *WipFunction, function_attributes: FunctionAttributes, ty: Type, kind: Constant.Assembly.Info, assembly: String, constraints: String, args: []const Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
function_attributes: FunctionAttributes
ty: Type
kind: Constant.Assembly.Info
assembly: String
constraints: String
args: []const Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callInner

函数

第 7200 行

fn callInner( self: *WipFunction, kind: Instruction.Call.Kind, call_conv: CallConv, function_attributes: FunctionAttributes, ty: Type, callee: Value, args: []const Value, name: []const u8, has_op_bundle_cold: bool, ) Allocator.Error!Value

参数

self: *WipFunction
kind: Instruction.Call.Kind
call_conv: CallConv
function_attributes: FunctionAttributes
ty: Type
callee: Value
args: []const Value
name: []const u8
has_op_bundle_cold: bool

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callIntrinsic

函数

第 7261 行

pub fn callIntrinsic( self: *WipFunction, fast: FastMathKind, function_attributes: FunctionAttributes, id: Intrinsic, overload: []const Type, args: []const Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
fast: FastMathKind
function_attributes: FunctionAttributes
id: Intrinsic
overload: []const Type
args: []const Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callIntrinsicAssumeCold

函数

第 7282 行

pub fn callIntrinsicAssumeCold(self: *WipFunction) Allocator.Error!Value

参数

self: *WipFunction

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callMemCpy

函数

第 7296 行

pub fn callMemCpy( self: *WipFunction, dst: Value, dst_align: Alignment, src: Value, src_align: Alignment, len: Value, kind: MemoryAccessKind, @"inline": bool, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
dst: Value
dst_align: Alignment
src: Value
src_align: Alignment
len: Value
kind: MemoryAccessKind
@"inline": bool

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callMemMove

函数

第 7327 行

pub fn callMemMove( self: *WipFunction, dst: Value, dst_align: Alignment, src: Value, src_align: Alignment, len: Value, kind: MemoryAccessKind, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
dst: Value
dst_align: Alignment
src: Value
src_align: Alignment
len: Value
kind: MemoryAccessKind

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.callMemSet

函数

第 7357 行

pub fn callMemSet( self: *WipFunction, dst: Value, dst_align: Alignment, val: Value, len: Value, kind: MemoryAccessKind, @"inline": bool, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
dst: Value
dst_align: Alignment
val: Value
len: Value
kind: MemoryAccessKind
@"inline": bool

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.cast

函数

第 7072 行

pub fn cast( self: *WipFunction, tag: Instruction.Tag, val: Value, ty: Type, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
tag: Instruction.Tag
val: Value
ty: Type
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.cmpTag

函数

第 7951 行

fn cmpTag( self: *WipFunction, tag: Instruction.Tag, lhs: Value, rhs: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
tag: Instruction.Tag
lhs: Value
rhs: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.cmpxchg

函数

第 6916 行

pub fn cmpxchg( self: *WipFunction, kind: Instruction.CmpXchg.Kind, access_kind: MemoryAccessKind, ptr: Value, cmp: Value, new: Value, sync_scope: SyncScope, success_ordering: AtomicOrdering, failure_ordering: AtomicOrdering, alignment: Alignment, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
kind: Instruction.CmpXchg.Kind
access_kind: MemoryAccessKind
ptr: Value
cmp: Value
new: Value
sync_scope: SyncScope
success_ordering: AtomicOrdering
failure_ordering: AtomicOrdering
alignment: Alignment
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.conv

函数

第 7060 行

pub fn conv( self: *WipFunction, signedness: Instruction.Cast.Signedness, val: Value, ty: Type, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
signedness: Instruction.Cast.Signedness
val: Value
ty: Type
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.Cursor

容器

第 6355 行

字段

block: Block.Index
instruction: u32 = 0

std.zig.llvm.Builder.WipFunction.debugValue

函数

第 7393 行

pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata.Optional

参数

self: *WipFunction
value: Value

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.deinit

函数

第 7940 行

pub fn deinit(self: *WipFunction) void

参数

self: *WipFunction

std.zig.llvm.Builder.WipFunction.ensureUnusedExtraCapacity

函数

第 8064 行

fn ensureUnusedExtraCapacity( self: *WipFunction, count: usize, comptime Extra: type, trail_len: usize, ) Allocator.Error!void

参数

self: *WipFunction
count: usize
Extra: type
trail_len: usize

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.extractElement

函数

第 6651 行

pub fn extractElement( self: *WipFunction, val: Value, index: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
val: Value
index: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.extractValue

函数

第 6727 行

pub fn extractValue( self: *WipFunction, val: Value, indices: []const u32, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
val: Value
indices: []const u32
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.extraData

函数

第 8189 行

fn extraData(self: *const WipFunction, comptime T: type, index: Instruction.ExtraIndex) T

参数

self: *const WipFunction
T: type
index: Instruction.ExtraIndex

std.zig.llvm.Builder.WipFunction.extraDataTrail

类型函数

第 8155 行

fn extraDataTrail( self: *const WipFunction, comptime T: type, index: Instruction.ExtraIndex, ) struct { data: T, trail: ExtraDataTrail }

参数

self: *const WipFunction
T: type
index: Instruction.ExtraIndex

std.zig.llvm.Builder.WipFunction.ExtraDataTrail

容器

第 8134 行

字段

std.zig.llvm.Builder.WipFunction.ExtraDataTrail.next

函数

第 8143 行

fn next( self: *ExtraDataTrail, len: u32, comptime Item: type, wip: *const WipFunction, ) []const Item

参数

self: *ExtraDataTrail
len: u32
Item: type
wip: *const WipFunction

std.zig.llvm.Builder.WipFunction.ExtraDataTrail.nextMut

函数

第 8137 行

fn nextMut(self: *ExtraDataTrail, len: u32, comptime Item: type, wip: *WipFunction) []Item

参数

self: *ExtraDataTrail
len: u32
Item: type
wip: *WipFunction

std.zig.llvm.Builder.WipFunction.fcmp

函数

第 7123 行

pub fn fcmp( self: *WipFunction, fast: FastMathKind, cond: FloatCondition, lhs: Value, rhs: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
fast: FastMathKind
cond: FloatCondition
lhs: Value
rhs: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.fence

函数

第 6899 行

pub fn fence( self: *WipFunction, sync_scope: SyncScope, ordering: AtomicOrdering, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
sync_scope: SyncScope
ordering: AtomicOrdering

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.finish

函数

第 7407 行

pub fn finish(self: *WipFunction) Allocator.Error!void

参数

self: *WipFunction

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.finish.addExtra

函数

第 7449 行

fn addExtra(wip_extra: *@This(), extra: anytype) Instruction.ExtraIndex

参数

wip_extra: *@This()

std.zig.llvm.Builder.WipFunction.finish.appendMappedValues

函数

第 7483 行

fn appendMappedValues(wip_extra: *@This(), vals: []const Value, ctx: anytype) void

参数

wip_extra: *@This()
vals: []const Value

std.zig.llvm.Builder.WipFunction.finish.appendSlice

函数

第 7475 行

fn appendSlice(wip_extra: *@This(), slice: anytype) void

参数

wip_extra: *@This()

std.zig.llvm.Builder.WipFunction.finish.finish

函数

第 7489 行

fn finish(wip_extra: *const @This()) []const u32

参数

wip_extra: *const @This()

std.zig.llvm.Builder.WipFunction.finish.map

函数

第 7419 行

fn map(instructions: @This(), val: Value) Value

参数

instructions: @This()
val: Value

std.zig.llvm.Builder.WipFunction.finish.map

函数

第 7532 行

fn map(wip_name: *@This(), name: String, sep: []const u8) Allocator.Error!String

参数

wip_name: *@This()
name: String
sep: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.gep

函数

第 6990 行

pub fn gep( self: *WipFunction, kind: Instruction.GetElementPtr.Kind, ty: Type, base: Value, indices: []const Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
kind: Instruction.GetElementPtr.Kind
ty: Type
base: Value
indices: []const Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.gep.init

函数

第 7005 行

fn init(vector_ty: Type, builder: *const Builder) @This()

参数

vector_ty: Type
builder: *const Builder

std.zig.llvm.Builder.WipFunction.gepStruct

函数

第 7049 行

pub fn gepStruct( self: *WipFunction, ty: Type, base: Value, index: usize, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
ty: Type
base: Value
index: usize
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.icmp

函数

第 7111 行

pub fn icmp( self: *WipFunction, cond: IntegerCondition, lhs: Value, rhs: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
cond: IntegerCondition
lhs: Value
rhs: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.indirectbr

函数

第 6544 行

pub fn indirectbr( self: *WipFunction, addr: Value, targets: []const Block.Index, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
addr: Value
targets: []const Block.Index

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.init

函数

第 6383 行

pub fn init(builder: *Builder, options: struct { function: Function.Index, strip: bool, }) Allocator.Error!WipFunction

参数

builder: *Builder
options: struct {
    function: Function.Index,
    strip: bool,
}

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.insertElement

函数

第 6670 行

pub fn insertElement( self: *WipFunction, val: Value, elem: Value, index: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
val: Value
elem: Value
index: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.insertValue

函数

第 6747 行

pub fn insertValue( self: *WipFunction, val: Value, elem: Value, indices: []const u32, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
val: Value
elem: Value
indices: []const u32
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.Instruction

别名

第 6381 行

别名目标 std.zig.llvm.Builder.Function.Instruction

std.zig.llvm.Builder.WipFunction.load

函数

第 6811 行

pub fn load( self: *WipFunction, access_kind: MemoryAccessKind, ty: Type, ptr: Value, alignment: Alignment, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
access_kind: MemoryAccessKind
ty: Type
ptr: Value
alignment: Alignment
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.loadAtomic

函数

第 6822 行

pub fn loadAtomic( self: *WipFunction, access_kind: MemoryAccessKind, ty: Type, ptr: Value, sync_scope: SyncScope, ordering: AtomicOrdering, alignment: Alignment, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
access_kind: MemoryAccessKind
ty: Type
ptr: Value
sync_scope: SyncScope
ordering: AtomicOrdering
alignment: Alignment
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.neg

函数

第 6593 行

pub fn neg(self: *WipFunction, val: Value, name: []const u8) Allocator.Error!Value

参数

self: *WipFunction
val: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.not

函数

第 6584 行

pub fn not(self: *WipFunction, val: Value, name: []const u8) Allocator.Error!Value

参数

self: *WipFunction
val: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.phi

函数

第 7165 行

pub fn phi(self: *WipFunction, ty: Type, name: []const u8) Allocator.Error!WipPhi

参数

self: *WipFunction
ty: Type
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.phiFast

函数

第 7169 行

pub fn phiFast(self: *WipFunction, ty: Type, name: []const u8) Allocator.Error!WipPhi

参数

self: *WipFunction
ty: Type
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.phiTag

函数

第 8016 行

fn phiTag( self: *WipFunction, tag: Instruction.Tag, ty: Type, name: []const u8, ) Allocator.Error!WipPhi

参数

self: *WipFunction
tag: Instruction.Tag
ty: Type
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.ret

函数

第 6441 行

pub fn ret(self: *WipFunction, val: Value) Allocator.Error!Instruction.Index

参数

self: *WipFunction
val: Value

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.retVoid

函数

第 6447 行

pub fn retVoid(self: *WipFunction) Allocator.Error!Instruction.Index

参数

self: *WipFunction

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.select

函数

第 7173 行

pub fn select( self: *WipFunction, fast: FastMathKind, cond: Value, lhs: Value, rhs: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
fast: FastMathKind
cond: Value
lhs: Value
rhs: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.selectTag

函数

第 8037 行

fn selectTag( self: *WipFunction, tag: Instruction.Tag, cond: Value, lhs: Value, rhs: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
tag: Instruction.Tag
cond: Value
lhs: Value
rhs: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.shuffleVector

函数

第 6691 行

pub fn shuffleVector( self: *WipFunction, lhs: Value, rhs: Value, mask: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
lhs: Value
rhs: Value
mask: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.splatVector

函数

第 6713 行

pub fn splatVector( self: *WipFunction, ty: Type, elem: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
ty: Type
elem: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.store

函数

第 6856 行

pub fn store( self: *WipFunction, kind: MemoryAccessKind, val: Value, ptr: Value, alignment: Alignment, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
kind: MemoryAccessKind
val: Value
ptr: Value
alignment: Alignment

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.storeAtomic

函数

第 6866 行

pub fn storeAtomic( self: *WipFunction, access_kind: MemoryAccessKind, val: Value, ptr: Value, sync_scope: SyncScope, ordering: AtomicOrdering, alignment: Alignment, ) Allocator.Error!Instruction.Index

参数

self: *WipFunction
access_kind: MemoryAccessKind
val: Value
ptr: Value
sync_scope: SyncScope
ordering: AtomicOrdering
alignment: Alignment

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.un

函数

第 6567 行

pub fn un( self: *WipFunction, tag: Instruction.Tag, val: Value, name: []const u8, ) Allocator.Error!Value

参数

self: *WipFunction
tag: Instruction.Tag
val: Value
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.vaArg

函数

第 7381 行

pub fn vaArg(self: *WipFunction, list: Value, ty: Type, name: []const u8) Allocator.Error!Value

参数

self: *WipFunction
list: Value
ty: Type
name: []const u8

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.WipPhi

容器

第 7141 行

字段

block: Block.Index
instruction: Instruction.Index

std.zig.llvm.Builder.WipFunction.WipPhi.finish

函数

第 7149 行

pub fn finish( self: WipPhi, vals: []const Value, blocks: []const Block.Index, wip: *WipFunction, ) void

参数

self: WipPhi
vals: []const Value
blocks: []const Block.Index
wip: *WipFunction

std.zig.llvm.Builder.WipFunction.WipPhi.toValue

函数

第 7145 行

pub fn toValue(self: WipPhi) Value

参数

self: WipPhi

std.zig.llvm.Builder.WipFunction.WipSwitch

容器

第 6496 行

字段

index: u32
instruction: Instruction.Index

std.zig.llvm.Builder.WipFunction.WipSwitch.addCase

函数

第 6500 行

pub fn addCase( self: *WipSwitch, val: Constant, dest: Block.Index, wip: *WipFunction, ) Allocator.Error!void

参数

self: *WipSwitch
val: Constant
dest: Block.Index
wip: *WipFunction

错误

OutOfMemory

std.zig.llvm.Builder.WipFunction.WipSwitch.finish

函数

第 6515 行

pub fn finish(self: WipSwitch, wip: *WipFunction) void

参数

self: WipSwitch
wip: *WipFunction

std.zig.llvm.Builder.Writer

别名

第 11 行

别名目标 std.Io.Writer

std.zig.llvm.Builder.x86_fp80Const

函数

第 10556 行

pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant

参数

self: *Builder
val: f80

错误

OutOfMemory

std.zig.llvm.Builder.x86_fp80ConstAssumeCapacity

函数

第 12447 行

fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant

参数

self: *Builder
val: f80

std.zig.llvm.Builder.x86_fp80ConstAssumeCapacity.eql

函数

第 12456 行

pub fn eql(ctx: @This(), lhs_key: f80, _: void, rhs_index: usize) bool

参数

ctx: @This()
lhs_key: f80
_: void
rhs_index: usize

std.zig.llvm.Builder.x86_fp80ConstAssumeCapacity.hash

函数

第 12450 行

pub fn hash(_: @This(), key: f80) u32

参数

_: @This()
key: f80

std.zig.llvm.Builder.x86_fp80Value

函数

第 10561 行

pub fn x86_fp80Value(self: *Builder, value: f80) Allocator.Error!Value

参数

self: *Builder
value: f80

错误

OutOfMemory

std.zig.llvm.Builder.zeroInitConst

函数

第 10638 行

pub fn zeroInitConst(self: *Builder, ty: Type) Allocator.Error!Constant

参数

self: *Builder
ty: Type

错误

OutOfMemory

std.zig.llvm.Builder.zeroInitConstAssumeCapacity

函数

第 12644 行

fn zeroInitConstAssumeCapacity(self: *Builder, ty: Type) Constant

参数

self: *Builder
ty: Type

std.zig.llvm.Builder.zeroInitValue

函数

第 10647 行

pub fn zeroInitValue(self: *Builder, ty: Type) Allocator.Error!Value

参数

self: *Builder
ty: Type

错误

OutOfMemory
源码

std/zig/llvm/Builder.zig

const builtin = @import("builtin");
const Builder = @This();

const std = @import("../../std.zig");
const Io = std.Io;
const Allocator = std.mem.Allocator;
const assert = std.debug.assert;
const DW = std.dwarf;
const log = std.log.scoped(.llvm);
const maxInt = std.math.maxInt;
const Writer = std.Io.Writer;

const bitcode_writer = @import("bitcode_writer.zig");
const ir = @import("ir.zig");

gpa: Allocator,
strip: bool,

source_filename: String,
data_layout: DataLayout,
target_triple: String,
module_asm: std.ArrayList(u8),

string_map: std.array_hash_map.Auto(void, void),
string_indices: std.ArrayList(u32),
string_bytes: std.ArrayList(u8),

types: std.array_hash_map.Auto(String, Type),
next_unnamed_type: String,
next_unique_type_id: std.AutoHashMapUnmanaged(String, u32),
type_map: std.array_hash_map.Auto(void, void),
type_items: std.ArrayList(Type.Item),
type_extra: std.ArrayList(u32),

attributes: std.array_hash_map.Auto(Attribute.Storage, void),
attributes_map: std.array_hash_map.Auto(void, void),
attributes_indices: std.ArrayList(u32),
attributes_extra: std.ArrayList(u32),

function_attributes_set: std.array_hash_map.Auto(FunctionAttributes, void),

globals: std.array_hash_map.Auto(StrtabString, Global),
next_unnamed_global: StrtabString,
next_replaced_global: StrtabString,
next_unique_global_id: std.AutoHashMapUnmanaged(StrtabString, u32),
aliases: std.ArrayList(Alias),
variables: std.ArrayList(Variable),
functions: std.ArrayList(Function),

strtab_string_map: std.array_hash_map.Auto(void, void),
strtab_string_indices: std.ArrayList(u32),
strtab_string_bytes: std.ArrayList(u8),

constant_map: std.array_hash_map.Auto(void, void),
constant_items: std.MultiArrayList(Constant.Item),
constant_extra: std.ArrayList(u32),
constant_limbs: std.ArrayList(std.math.big.Limb),

alignment_forward_references: std.ArrayList(Alignment),

metadata_map: std.array_hash_map.Auto(void, void),
metadata_items: std.MultiArrayList(Metadata.Item),
metadata_extra: std.ArrayList(u32),
metadata_limbs: std.ArrayList(std.math.big.Limb),
metadata_forward_references: std.ArrayList(Metadata.Optional),
metadata_named: std.array_hash_map.Auto(String, struct {
    len: u32,
    index: Metadata.Item.ExtraIndex,
}),

metadata_string_map: std.array_hash_map.Auto(void, void),
metadata_string_indices: std.ArrayList(u32),
metadata_string_bytes: std.ArrayList(u8),

pub const expected_args_len = 16;
pub const expected_attrs_len = 16;
pub const expected_fields_len = 32;
pub const expected_gep_indices_len = 8;
pub const expected_cases_len = 8;
pub const expected_incoming_len = 8;

pub const Options = struct {
    allocator: Allocator,
    strip: bool = true,
    name: []const u8 = &.{},
    target: *const std.Target = &builtin.target,
};

fn subArchName(target: *const std.Target, comptime family: std.Target.Cpu.Arch.Family, mappings: anytype) ?[]const u8 {
    inline for (mappings) |mapping| {
        if (target.cpu.has(family, mapping[0])) return mapping[1];
    }

    return null;
}

pub fn tripleForTarget(allocator: Allocator, target: *const std.Target) ![]const u8 {
    var llvm_triple = std.array_list.Managed(u8).init(allocator);
    defer llvm_triple.deinit();

    const llvm_arch = switch (target.cpu.arch) {
        .arm => "arm",
        .armeb => "armeb",
        .aarch64 => if (target.abi == .ilp32) "aarch64_32" else "aarch64",
        .aarch64_be => "aarch64_be",
        .arc => "arc",
        .avr => "avr",
        .bpfel => "bpfel",
        .bpfeb => "bpfeb",
        .csky => "csky",
        .hexagon => "hexagon",
        .loongarch32 => "loongarch32",
        .loongarch64 => "loongarch64",
        .m68k => "m68k",
        // MIPS 子架构略不规则,因此在此处手动处理。
        .mips => if (target.cpu.has(.mips, .mips32r6)) "mipsisa32r6" else "mips",
        .mipsel => if (target.cpu.has(.mips, .mips32r6)) "mipsisa32r6el" else "mipsel",
        .mips64 => if (target.cpu.has(.mips, .mips64r6)) "mipsisa64r6" else "mips64",
        .mips64el => if (target.cpu.has(.mips, .mips64r6)) "mipsisa64r6el" else "mips64el",
        .msp430 => "msp430",
        .powerpc => "powerpc",
        .powerpcle => "powerpcle",
        .powerpc64 => "powerpc64",
        .powerpc64le => "powerpc64le",
        .amdgcn => "amdgcn",
        .riscv32 => "riscv32",
        .riscv32be => "riscv32be",
        .riscv64 => "riscv64",
        .riscv64be => "riscv64be",
        .sparc => "sparc",
        .sparc64 => "sparc64",
        .s390x => "s390x",
        .thumb => "thumb",
        .thumbeb => "thumbeb",
        .x86 => "i386",
        .x86_64 => "x86_64",
        .xcore => "xcore",
        .xtensa => "xtensa",
        .nvptx => "nvptx",
        .nvptx64 => "nvptx64",
        .spirv32 => switch (target.os.tag) {
            .vulkan, .opengl => "spirv",
            else => "spirv32",
        },
        .spirv64 => "spirv64",
        .lanai => "lanai",
        .wasm32 => "wasm32",
        .wasm64 => "wasm64",
        .ve => "ve",

        .alpha,
        .arceb,
        .ez80,
        .hppa,
        .hppa64,
        .kalimba,
        .kvx,
        .m88k,
        .microblaze,
        .microblazeel,
        .or1k,
        .propeller,
        .sh,
        .sheb,
        .spork8,
        .x86_16,
        .xtensaeb,
        => unreachable, // 由 hasLlvmSupport() 控制启用。
    };

    try llvm_triple.appendSlice(llvm_arch);

    const llvm_sub_arch: ?[]const u8 = switch (target.cpu.arch) {
        .arm, .armeb, .thumb, .thumbeb => subArchName(target, .arm, .{
            .{ .v4t, "v4t" },
            .{ .v5t, "v5t" },
            .{ .v5te, "v5te" },
            .{ .v5tej, "v5tej" },
            .{ .v6, "v6" },
            .{ .v6k, "v6k" },
            .{ .v6kz, "v6kz" },
            .{ .v6m, "v6m" },
            .{ .v6t2, "v6t2" },
            .{ .v7a, "v7a" },
            .{ .v7em, "v7em" },
            .{ .v7m, "v7m" },
            .{ .v7r, "v7r" },
            .{ .v7ve, "v7ve" },
            .{ .v8a, "v8a" },
            .{ .v8_1a, "v8.1a" },
            .{ .v8_2a, "v8.2a" },
            .{ .v8_3a, "v8.3a" },
            .{ .v8_4a, "v8.4a" },
            .{ .v8_5a, "v8.5a" },
            .{ .v8_6a, "v8.6a" },
            .{ .v8_7a, "v8.7a" },
            .{ .v8_8a, "v8.8a" },
            .{ .v8_9a, "v8.9a" },
            .{ .v8m, "v8m.base" },
            .{ .v8m_main, "v8m.main" },
            .{ .v8_1m_main, "v8.1m.main" },
            .{ .v8r, "v8r" },
            .{ .v9a, "v9a" },
            .{ .v9_1a, "v9.1a" },
            .{ .v9_2a, "v9.2a" },
            .{ .v9_3a, "v9.3a" },
            .{ .v9_4a, "v9.4a" },
            .{ .v9_5a, "v9.5a" },
            .{ .v9_6a, "v9.6a" },
            .{ .v9_7a, "v9.7a" },
        }),
        .powerpc => subArchName(target, .powerpc, .{
            .{ .spe, "spe" },
        }),
        .spirv32, .spirv64 => subArchName(target, .spirv, .{
            .{ .v1_6, "1.6" },
            .{ .v1_5, "1.5" },
            .{ .v1_4, "1.4" },
            .{ .v1_3, "1.3" },
            .{ .v1_2, "1.2" },
            .{ .v1_1, "1.1" },
        }),
        else => null,
    };

    if (llvm_sub_arch) |sub| try llvm_triple.appendSlice(sub);
    try llvm_triple.append('-');

    try llvm_triple.appendSlice(switch (target.os.tag) {
        .driverkit,
        .ios,
        .maccatalyst,
        .macos,
        .tvos,
        .visionos,
        .watchos,
        => "apple",
        .ps4,
        .ps5,
        => "scei",
        .amdhsa,
        .amdpal,
        => "amd",
        .cuda,
        .nvcl,
        => "nvidia",
        .mesa3d,
        => "mesa",
        else => "unknown",
    });
    try llvm_triple.append('-');

    const llvm_os = switch (target.os.tag) {
        .dragonfly => "dragonfly",
        .freebsd => "freebsd",
        .fuchsia => "fuchsia",
        .linux => "linux",
        .netbsd => "netbsd",
        .openbsd => "openbsd",
        .illumos => "solaris",
        .windows, .uefi => "windows",
        .haiku => "haiku",
        .rtems => "rtems",
        .cuda => "cuda",
        .nvcl => "nvcl",
        .amdhsa => "amdhsa",
        .ps3 => "lv2",
        .ps4 => "ps4",
        .ps5 => "ps5",
        .mesa3d => "mesa3d",
        .amdpal => "amdpal",
        .hermit => "hermit",
        .hurd => "hurd",
        .wasi => "wasi",
        .emscripten => "emscripten",
        .macos => "macosx",
        .ios, .maccatalyst => "ios",
        .tvos => "tvos",
        .watchos => "watchos",
        .driverkit => "driverkit",
        .visionos => "xros",
        .serenity => "serenity",
        .vulkan => "vulkan",
        .managarm => "managarm",

        .contiki,
        .freestanding,
        .opencl, // https://llvm.org/docs/SPIRVUsage.html#target-triples
        .opengl,
        .other,
        .plan9,
        .psx,
        .psp,
        .vita,
        .tios,
        .@"3ds",
        .wiiu,
        .@"switch",
        .gba,
        .ashetos,
        => "unknown",
    };
    try llvm_triple.appendSlice(llvm_os);

    switch (target.os.versionRange()) {
        .none,
        .windows,
        => {},
        .semver => |ver| if (target.os.tag == .wasi and ver.min.major == 0) {
            try llvm_triple.print("p{d}", .{ver.min.minor});
        } else if (target.os.tag != .amdhsa) {
            try llvm_triple.print("{d}.{d}.{d}", .{
                ver.min.major,
                ver.min.minor,
                ver.min.patch,
            });
        },
        inline .linux, .hurd => |ver| try llvm_triple.print("{d}.{d}.{d}", .{
            ver.range.min.major,
            ver.range.min.minor,
            ver.range.min.patch,
        }),
    }
    try llvm_triple.append('-');

    const llvm_abi = switch (target.abi) {
        .none => if (target.os.tag == .maccatalyst) "macabi" else "unknown",
        .gnu => "gnu",
        .gnuabin32 => "gnuabin32",
        .gnuabi64 => "gnuabi64",
        .gnueabi => "gnueabi",
        .gnueabihf => "gnueabihf",
        .gnuf32 => "gnuf32",
        .gnusf => "gnusf",
        .gnux32 => "gnux32",
        .ilp32 => "unknown",
        .eabi => "eabi",
        .eabihf => "eabihf",
        .abin32 => "unknown",
        .x32 => "muslx32", // https://github.com/ziglang/zig/issues/25649
        .android => "android",
        .androideabi => "androideabi",
        .musl => switch (target.os.tag) {
            // 对于 WASI/Emscripten,“musl”指 libc,而非真正的 ABI。
            // “unknown”能为这些目标提供更好的 LLVM 工具兼容性。
            .wasi, .emscripten => "unknown",
            else => "musl",
        },
        .muslabin32 => "muslabin32",
        .muslabi64 => "muslabi64",
        .musleabi => "musleabi",
        .musleabihf => "musleabihf",
        .muslf32 => "muslf32",
        .muslsf => "muslsf",
        .muslx32 => "muslx32",
        .msvc => "msvc",
        .itanium => "itanium",
        .simulator => "simulator",
        .ohos, .ohoseabi => "ohos",
        .call0 => "unknown",
    };
    try llvm_triple.appendSlice(llvm_abi);

    switch (target.os.versionRange()) {
        .none,
        .semver,
        .windows,
        => {},
        inline .hurd, .linux => |ver| if (target.abi.isGnu()) {
            try llvm_triple.print("{d}.{d}.{d}", .{
                ver.glibc.major,
                ver.glibc.minor,
                ver.glibc.patch,
            });
        } else if (@TypeOf(ver) == std.Target.Os.LinuxVersionRange and target.abi.isAndroid()) {
            try llvm_triple.print("{d}", .{ver.android});
        },
    }

    return llvm_triple.toOwnedSlice();
}

pub const DataLayout = struct {
    endian: ?std.lang.Endian,
    int_specs: PrimitiveSpec.Map,
    float_specs: PrimitiveSpec.Map,
    vector_specs: PrimitiveSpec.Map,
    pointer_specs: PointerSpec.Map,
    string_repr: String,

    const PrimitiveSpec = packed struct(u32) {
        bit_width: BitWidth,
        abi_align: Alignment,
        pref_align: Alignment,

        const BitWidth = u20;

        const Map = std.array_hash_map.Custom(PrimitiveSpec, void, Context, false);

        const Context = struct {
            pub fn hash(_: Context, spec: PrimitiveSpec) u32 {
                return std.hash.int(spec.bit_width);
            }

            pub fn eql(_: Context, lhs_spec: PrimitiveSpec, rhs_spec: PrimitiveSpec, _: usize) bool {
                return lhs_spec.bit_width == rhs_spec.bit_width;
            }
        };
    };

    const PointerSpec = struct {
        bit_width: BitWidth,
        index_bit_width: BitWidth,
        flags: packed struct(u32) {
            abi_align: Alignment,
            pref_align: Alignment,
            has_unstable_repr: bool,
            has_external_state: bool,
            null_ptr_repr: NullPtrRepr,
            unused: u17 = 0,
        },
        addr_space_name: String,

        const BitWidth = u32;

        const NullPtrRepr = enum(u1) { all_zeros, all_ones };

        const Map = std.array_hash_map.Auto(AddrSpace, PointerSpec);
    };

    pub fn stringForTarget(target: *const std.Target) []const u8 {
        // 这些数据布局应与 Clang 匹配。
        return switch (target.cpu.arch) {
            .arc => "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-f32:32:32-i64:32-f64:32-a:0:32-n32",
            .xcore => "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i64:32-f64:32-a:0:32-n32",
            .hexagon => "e-m:e-p:32:32:32-a:0-n16:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048",
            .lanai => "E-m:e-p:32:32-i64:64-a:0:32-n32-S64",
            .aarch64 => if (target.ofmt == .macho)
                if (target.os.tag == .windows or target.os.tag == .uefi)
                    "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
                else if (target.abi == .ilp32)
                    "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
                else
                    "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-Fn32"
            else if (target.os.tag == .windows or target.os.tag == .uefi)
                "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-i64:64-i128:128-n32:64-S128-Fn32"
            else
                "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
            .aarch64_be => "E-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32",
            .arm => if (target.ofmt == .macho)
                "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
            else
                "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
            .armeb, .thumbeb => if (target.ofmt == .macho)
                "E-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
            else
                "E-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
            .thumb => if (target.ofmt == .macho)
                "e-m:o-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
            else if (target.os.tag == .windows or target.os.tag == .uefi)
                "e-m:w-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
            else
                "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
            .avr => "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8:16-a:8",
            .bpfeb => "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
            .bpfel => "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
            .msp430 => "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16",
            .mips => "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64",
            .mipsel => "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64",
            .mips64 => switch (target.abi) {
                .gnuabin32, .muslabin32, .abin32 => "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
                else => "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
            },
            .mips64el => switch (target.abi) {
                .gnuabin32, .muslabin32, .abin32 => "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
                else => "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
            },
            .m68k => "E-m:e-p:32:16:32-i8:8:8-i16:16:16-i32:16:32-n8:16:32-a:0:16-S16",
            .powerpc => "E-m:e-p:32:32-Fn32-i64:64-n32",
            .powerpcle => "e-m:e-p:32:32-Fn32-i64:64-n32",
            .powerpc64 => switch (target.os.tag) {
                .linux => "E-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512",
                .ps3 => "E-m:e-p:32:32-Fi64-i64:64-i128:128-n32:64",
                else => "E-m:e-Fn32-i64:64-i128:128-n32:64",
            },
            .powerpc64le => if (target.os.tag == .linux)
                "e-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512"
            else
                "e-m:e-Fn32-i64:64-i128:128-n32:64",
            .nvptx => "e-p:32:32-p6:32:32-p7:32:32-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64",
            .nvptx64 => "e-p6:32:32-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64",
            .amdgcn => "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9",
            .riscv32 => if (target.cpu.has(.riscv, .e))
                "e-m:e-p:32:32-i64:64-n32-S32"
            else
                "e-m:e-p:32:32-i64:64-n32-S128",
            .riscv32be => if (target.cpu.has(.riscv, .e))
                "E-m:e-p:32:32-i64:64-n32-S32"
            else
                "E-m:e-p:32:32-i64:64-n32-S128",
            .riscv64 => if (target.cpu.has(.riscv, .e))
                "e-m:e-p:64:64-i64:64-i128:128-n32:64-S64"
            else
                "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
            .riscv64be => if (target.cpu.has(.riscv, .e))
                "E-m:e-p:64:64-i64:64-i128:128-n32:64-S64"
            else
                "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
            .sparc => "E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64",
            .sparc64 => "E-m:e-i64:64-i128:128-n32:64-S128",
            .s390x => "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64",
            .x86 => if (target.os.tag == .windows or target.os.tag == .uefi) switch (target.abi) {
                .gnu => if (target.ofmt == .coff)
                    "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:32-n8:16:32-a:0:32-S32"
                else
                    "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:32-n8:16:32-a:0:32-S32",
                else => blk: {
                    const msvc = switch (target.abi) {
                        .none, .msvc => true,
                        else => false,
                    };

                    break :blk if (target.ofmt == .coff)
                        if (msvc)
                            "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32-a:0:32-S32"
                        else
                            "e-m:x-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:32-n8:16:32-a:0:32-S32"
                    else if (msvc)
                        "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32-a:0:32-S32"
                    else
                        "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:32-n8:16:32-a:0:32-S32";
                },
            } else if (target.ofmt == .macho)
                "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128"
            else
                "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128",
            .x86_64 => if (target.os.tag.isDarwin() or target.ofmt == .macho)
                "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
            else switch (target.abi) {
                .gnux32, .muslx32, .x32 => "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
                else => if ((target.os.tag == .windows or target.os.tag == .uefi) and target.ofmt == .coff)
                    "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
                else
                    "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
            },
            .spirv32 => switch (target.os.tag) {
                .vulkan, .opengl => "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
                else => "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
            },
            .spirv64 => "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-G1",
            .wasm32 => if (target.os.tag == .emscripten)
                "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-S128-ni:1:10:20"
            else
                "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20",
            .wasm64 => if (target.os.tag == .emscripten)
                "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-f128:64-n32:64-S128-ni:1:10:20"
            else
                "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-i128:128-n32:64-S128-ni:1:10:20",
            .ve => "e-m:e-i64:64-n32:64-S128-v64:64:64-v128:64:64-v256:64:64-v512:64:64-v1024:64:64-v2048:64:64-v4096:64:64-v8192:64:64-v16384:64:64",
            .csky => "e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32-v128:32:32-a:0:32-Fi32-n32",
            .loongarch32 => "e-m:e-p:32:32-i64:64-n32-S128",
            .loongarch64 => "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
            .xtensa => "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32",

            .alpha,
            .arceb,
            .ez80,
            .hppa,
            .hppa64,
            .kalimba,
            .kvx,
            .m88k,
            .microblaze,
            .microblazeel,
            .or1k,
            .propeller,
            .sh,
            .sheb,
            .x86_16,
            .xtensaeb,
            .spork8,
            => unreachable,
        };
    }

    const default_int_specs: []const PrimitiveSpec = &.{
        .{ .bit_width = 8, .abi_align = .fromByteUnits(1), .pref_align = .fromByteUnits(1) }, // i8:8:8
        .{ .bit_width = 16, .abi_align = .fromByteUnits(2), .pref_align = .fromByteUnits(2) }, // i16:16:16
        .{ .bit_width = 32, .abi_align = .fromByteUnits(4), .pref_align = .fromByteUnits(4) }, // i32:32:32
        .{ .bit_width = 64, .abi_align = .fromByteUnits(4), .pref_align = .fromByteUnits(8) }, // i64:32:64
    };
    const default_float_specs: []const PrimitiveSpec = &.{
        .{ .bit_width = 16, .abi_align = .fromByteUnits(2), .pref_align = .fromByteUnits(2) }, // f16:16:16
        .{ .bit_width = 32, .abi_align = .fromByteUnits(4), .pref_align = .fromByteUnits(4) }, // f32:32:32
        .{ .bit_width = 64, .abi_align = .fromByteUnits(8), .pref_align = .fromByteUnits(8) }, // f64:64:64
        .{ .bit_width = 128, .abi_align = .fromByteUnits(16), .pref_align = .fromByteUnits(16) }, // f128:128:128
    };
    const default_vector_specs: []const PrimitiveSpec = &.{
        .{ .bit_width = 64, .abi_align = .fromByteUnits(8), .pref_align = .fromByteUnits(8) }, // v64:64:64
        .{ .bit_width = 128, .abi_align = .fromByteUnits(16), .pref_align = .fromByteUnits(16) }, // v128:128:128
    };

    pub fn parseString(string_repr: String, builder: *Builder) Allocator.Error!DataLayout {
        const gpa = builder.gpa;

        var int_specs: PrimitiveSpec.Map = .empty;
        defer int_specs.deinit(gpa);
        var float_specs: PrimitiveSpec.Map = .empty;
        defer float_specs.deinit(gpa);
        var vector_specs: PrimitiveSpec.Map = .empty;
        defer vector_specs.deinit(gpa);
        var pointer_specs: PointerSpec.Map = .empty;
        defer pointer_specs.deinit(gpa);
        var non_integral_addr_spaces: std.ArrayList(AddrSpace) = .empty;
        defer non_integral_addr_spaces.deinit(gpa);

        try int_specs.ensureTotalCapacity(gpa, default_int_specs.len);
        for (default_int_specs) |int_spec| int_specs.putAssumeCapacityNoClobber(int_spec, {});
        try float_specs.ensureTotalCapacity(gpa, default_float_specs.len);
        for (default_float_specs) |float_spec| float_specs.putAssumeCapacityNoClobber(float_spec, {});
        try vector_specs.ensureTotalCapacity(gpa, default_vector_specs.len);
        for (default_vector_specs) |vector_spec| vector_specs.putAssumeCapacityNoClobber(vector_spec, {});
        try pointer_specs.putNoClobber(gpa, .default, comptime .{
            .bit_width = 64,
            .index_bit_width = 64,
            .flags = .{
                .abi_align = .fromByteUnits(8),
                .pref_align = .fromByteUnits(8),
                .has_unstable_repr = false,
                .has_external_state = false,
                .null_ptr_repr = .all_zeros,
            },
            .addr_space_name = .none,
        });

        var endian: ?std.lang.Endian = null;
        var spec_it = std.mem.splitScalar(u8, string_repr.slice(builder).?, '-');
        while (spec_it.next()) |spec| switch (spec[0]) {
            else => {},
            'E' => {
                assert(spec.len == 1);
                assert(endian == null);
                endian = .big;
            },
            'e' => {
                assert(spec.len == 1);
                assert(endian == null);
                endian = .little;
            },
            'p' => {
                var field_it = std.mem.splitScalar(u8, spec[1..], ':');

                const first = field_it.first();
                var has_unstable_repr = false;
                var has_external_state = false;
                var null_ptr_repr: ?PointerSpec.NullPtrRepr = null;
                var addr_space_name: String = .none;
                const addr_space = for (first, 0..) |flag, as_start| switch (flag) {
                    'u' => has_unstable_repr = true,
                    'e' => has_external_state = true,
                    'z' => {
                        assert(null_ptr_repr == null);
                        null_ptr_repr = .all_zeros;
                    },
                    'o' => {
                        assert(null_ptr_repr == null);
                        null_ptr_repr = .all_ones;
                    },
                    else => {
                        if (first[first.len - ")".len] != ')') break first[as_start..];
                        const name_start = std.mem.findScalarPos(u8, first, as_start, '(').?;
                        addr_space_name = try builder.string(first[name_start + "(".len .. first.len - ")".len]);
                        break first[as_start..name_start];
                    },
                } else first[first.len..];
                const bit_width = std.fmt.parseInt(PointerSpec.BitWidth, field_it.next().?, 10) catch unreachable;
                const abi_align: Alignment = .fromByteUnits(std.fmt.parseInt(u64, field_it.next().?, 10) catch unreachable);
                const pref_align: Alignment = if (field_it.next()) |pref_align|
                    .fromByteUnits(std.fmt.parseInt(u64, pref_align, 10) catch unreachable)
                else
                    abi_align;
                const index_bit_width = if (field_it.next()) |index_bit_width|
                    std.fmt.parseInt(PointerSpec.BitWidth, index_bit_width, 10) catch unreachable
                else
                    bit_width;
                assert(field_it.peek() == null);

                try pointer_specs.put(gpa, switch (addr_space.len) {
                    0 => .default,
                    else => @fromBackingInt(std.fmt.parseInt(u24, addr_space, 10) catch unreachable),
                }, .{
                    .bit_width = bit_width,
                    .index_bit_width = index_bit_width,
                    .flags = .{
                        .abi_align = abi_align,
                        .pref_align = pref_align,
                        .has_unstable_repr = has_unstable_repr,
                        .has_external_state = has_external_state,
                        .null_ptr_repr = null_ptr_repr orelse .all_zeros,
                    },
                    .addr_space_name = addr_space_name,
                });
            },
            'i', 'f', 'v' => |kind| {
                if (std.mem.eql(u8, spec, "ve")) {
                    vector_specs.clearRetainingCapacity();
                    continue;
                }
                var field_it = std.mem.splitScalar(u8, spec[1..], ':');
                const bit_width = std.fmt.parseInt(PrimitiveSpec.BitWidth, field_it.first(), 10) catch unreachable;
                const abi_align: Alignment = .fromByteUnits(std.fmt.parseInt(u64, field_it.next().?, 10) catch unreachable);
                const pref_align: Alignment = if (field_it.next()) |pref_align|
                    .fromByteUnits(std.fmt.parseInt(u64, pref_align, 10) catch unreachable)
                else
                    abi_align;
                assert(field_it.peek() == null);
                const specs = switch (kind) {
                    else => unreachable,
                    'i' => &int_specs,
                    'f' => &float_specs,
                    'v' => &vector_specs,
                };
                try specs.put(gpa, .{ .bit_width = bit_width, .abi_align = abi_align, .pref_align = pref_align }, {});
            },
            'n' => {
                var field_it = std.mem.splitScalar(u8, spec[1..], ':');
                if (std.mem.eql(u8, field_it.first(), "i")) {
                    while (field_it.next()) |non_integral_addr_space| try non_integral_addr_spaces.append(
                        gpa,
                        @fromBackingInt(std.fmt.parseInt(u24, non_integral_addr_space, 10) catch unreachable),
                    );
                } else {
                    field_it.reset();
                    while (field_it.next()) |native_bit_width| {
                        _ = std.fmt.parseInt(PrimitiveSpec.BitWidth, native_bit_width, 10) catch unreachable;
                    }
                }
            },
        };

        for (non_integral_addr_spaces.items) |non_integral_addr_space| {
            const pointer_spec_gop = try pointer_specs.getOrPut(gpa, non_integral_addr_space);
            if (!pointer_spec_gop.found_existing) pointer_spec_gop.value_ptr.* = pointer_specs.get(.default).?;
            pointer_spec_gop.value_ptr.flags.has_unstable_repr = true;
            pointer_spec_gop.value_ptr.flags.has_external_state = false;
        }

        {
            const SortContext = struct {
                specs: []const PrimitiveSpec,
                pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool {
                    return ctx.specs[lhs_index].bit_width < ctx.specs[rhs_index].bit_width;
                }
            };
            int_specs.sortUnstable(SortContext{ .specs = int_specs.keys() });
            float_specs.sortUnstable(SortContext{ .specs = float_specs.keys() });
            vector_specs.sortUnstable(SortContext{ .specs = vector_specs.keys() });
        }
        {
            const SortContext = struct {
                addr_spaces: []const AddrSpace,
                pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool {
                    return @backingInt(ctx.addr_spaces[lhs_index]) < @backingInt(ctx.addr_spaces[rhs_index]);
                }
            };
            pointer_specs.sortUnstable(SortContext{ .addr_spaces = pointer_specs.keys() });
            assert(pointer_specs.keys()[0] == .default);
        }

        return .{
            .endian = endian,
            .int_specs = int_specs.move(),
            .float_specs = float_specs.move(),
            .vector_specs = vector_specs.move(),
            .pointer_specs = pointer_specs.move(),
            .string_repr = string_repr,
        };
    }

    pub fn deinit(data_layout: *DataLayout, gpa: Allocator) void {
        data_layout.int_specs.deinit(gpa);
        data_layout.float_specs.deinit(gpa);
        data_layout.vector_specs.deinit(gpa);
        data_layout.pointer_specs.deinit(gpa);
    }

    pub fn getIntegerSpec(data_layout: *const DataLayout, bit_width: PrimitiveSpec.BitWidth) PrimitiveSpec {
        const specs = data_layout.int_specs.keys();
        return specs[
            @min(std.sort.lowerBound(PrimitiveSpec, specs, bit_width, struct {
                fn order(ctx: PrimitiveSpec.BitWidth, spec: PrimitiveSpec) std.math.Order {
                    return std.math.order(ctx, spec.bit_width);
                }
            }.order), specs.len - 1)
        ];
    }

    pub fn getFloatSpec(data_layout: *const DataLayout, bit_width: PrimitiveSpec.BitWidth) PrimitiveSpec {
        if (data_layout.float_specs.getEntry(.{
            .bit_width = bit_width,
            .abi_align = .default,
            .pref_align = .default,
        })) |entry| return entry.key_ptr.*;
        const default_align: Alignment = .fromByteUnits(
            std.math.ceilPowerOfTwoAssert(PrimitiveSpec.BitWidth, bit_width / 8),
        );
        return .{ .bit_width = bit_width, .abi_align = default_align, .pref_align = default_align };
    }

    pub fn getVectorSpec(
        data_layout: *const DataLayout,
        bit_width: PrimitiveSpec.BitWidth,
        store_size: Type.Size,
    ) PrimitiveSpec {
        if (data_layout.float_specs.getEntry(.{
            .bit_width = bit_width,
            .abi_align = .default,
            .pref_align = .default,
        })) |entry| return entry.key_ptr.*;
        const default_align: Alignment = .fromByteUnits(
            std.math.ceilPowerOfTwoAssert(PrimitiveSpec.BitWidth, switch (store_size) {
                .fixed, .scalable => |known_min| known_min,
            }),
        );
        return .{ .bit_width = bit_width, .abi_align = default_align, .pref_align = default_align };
    }

    pub fn getPointerSpec(data_layout: *const DataLayout, addr_space: AddrSpace) PointerSpec {
        return data_layout.pointer_specs.get(addr_space) orelse data_layout.pointer_specs.values()[0];
    }
};

pub const String = enum(u32) {
    none = maxInt(u31),
    empty,
    _,

    pub fn isAnon(self: String) bool {
        assert(self != .none);
        return self.toIndex() == null;
    }

    pub fn slice(self: String, builder: *const Builder) ?[]const u8 {
        const index = self.toIndex() orelse return null;
        const start = builder.string_indices.items[index];
        const end = builder.string_indices.items[index + 1];
        return builder.string_bytes.items[start..end];
    }

    const FormatData = struct {
        string: String,
        builder: *const Builder,
        quote_behavior: ?QuoteBehavior,
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        assert(data.string != .none);
        const string_slice = data.string.slice(data.builder) orelse
            return w.print("{d}", .{@backingInt(data.string)});
        const quote_behavior = data.quote_behavior orelse return w.writeAll(string_slice);
        return printEscapedString(string_slice, quote_behavior, w);
    }

    pub fn fmt(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{
            .string = self,
            .builder = builder,
            .quote_behavior = .quote_unless_valid_identifier,
        } };
    }

    pub fn fmtQ(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{
            .string = self,
            .builder = builder,
            .quote_behavior = .always_quote,
        } };
    }

    pub fn fmtRaw(self: String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{
            .string = self,
            .builder = builder,
            .quote_behavior = null,
        } };
    }

    fn fromIndex(index: ?usize) String {
        return @fromBackingInt(@as(u32, @intCast((index orelse return .none) +
            @backingInt(String.empty))));
    }

    fn toIndex(self: String) ?usize {
        return std.math.sub(u32, @backingInt(self), @backingInt(String.empty)) catch null;
    }

    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: Adapter, key: []const u8) u32 {
            return @truncate(std.hash.Wyhash.hash(0, key));
        }
        pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {
            return std.mem.eql(u8, lhs_key, String.fromIndex(rhs_index).slice(ctx.builder).?);
        }
    };
};

pub const BinaryOpcode = enum(u4) {
    add = 0,
    sub = 1,
    mul = 2,
    udiv = 3,
    sdiv = 4,
    urem = 5,
    srem = 6,
    shl = 7,
    lshr = 8,
    ashr = 9,
    @"and" = 10,
    @"or" = 11,
    xor = 12,
};

pub const CastOpcode = enum(u4) {
    trunc = 0,
    zext = 1,
    sext = 2,
    fptoui = 3,
    fptosi = 4,
    uitofp = 5,
    sitofp = 6,
    fptrunc = 7,
    fpext = 8,
    ptrtoint = 9,
    inttoptr = 10,
    bitcast = 11,
    addrspacecast = 12,
};

pub const CmpPredicate = enum(u6) {
    fcmp_false = 0,
    fcmp_oeq = 1,
    fcmp_ogt = 2,
    fcmp_oge = 3,
    fcmp_olt = 4,
    fcmp_ole = 5,
    fcmp_one = 6,
    fcmp_ord = 7,
    fcmp_uno = 8,
    fcmp_ueq = 9,
    fcmp_ugt = 10,
    fcmp_uge = 11,
    fcmp_ult = 12,
    fcmp_ule = 13,
    fcmp_une = 14,
    fcmp_true = 15,
    icmp_eq = 32,
    icmp_ne = 33,
    icmp_ugt = 34,
    icmp_uge = 35,
    icmp_ult = 36,
    icmp_ule = 37,
    icmp_sgt = 38,
    icmp_sge = 39,
    icmp_slt = 40,
    icmp_sle = 41,
};

pub const Type = enum(u32) {
    void,
    half,
    bfloat,
    float,
    double,
    fp128,
    x86_fp80,
    ppc_fp128,
    x86_amx,
    x86_mmx,
    label,
    token,
    metadata,

    i1,
    i8,
    i16,
    i29,
    i32,
    i64,
    i80,
    i128,
    ptr,
    @"ptr addrspace(4)",

    none = maxInt(u32),
    _,

    pub const ptr_amdgpu_constant =
        @field(Type, std.fmt.comptimePrint("ptr{f}", .{AddrSpace.amdgpu.constant.fmt(" ")}));

    pub const Tag = enum(u4) {
        simple,
        function,
        vararg_function,
        integer,
        pointer,
        target,
        vector,
        scalable_vector,
        small_array,
        array,
        structure,
        packed_structure,
        named_structure,
    };

    pub const Simple = enum(u5) {
        const Code = ir.ModuleBlock.TypeBlock.Code;
        void = @backingInt(Code.VOID),
        half = @backingInt(Code.HALF),
        bfloat = @backingInt(Code.BFLOAT),
        float = @backingInt(Code.FLOAT),
        double = @backingInt(Code.DOUBLE),
        fp128 = @backingInt(Code.FP128),
        x86_fp80 = @backingInt(Code.X86_FP80),
        ppc_fp128 = @backingInt(Code.PPC_FP128),
        x86_amx = @backingInt(Code.X86_AMX),
        x86_mmx = @backingInt(Code.X86_MMX),
        label = @backingInt(Code.LABEL),
        token = @backingInt(Code.TOKEN),
        metadata = @backingInt(Code.METADATA),
    };

    pub const Function = struct {
        ret: Type,
        params_len: u32,
        // params: [params_len]Value,

        pub const Kind = enum { normal, vararg };
    };

    pub const Target = extern struct {
        name: String,
        types_len: u32,
        ints_len: u32,
        // types: [types_len]Type,
        // ints: [ints_len]u32,
    };

    pub const Vector = extern struct {
        len: u32,
        child: Type,

        fn length(self: Vector) u32 {
            return self.len;
        }

        pub const Kind = enum { normal, scalable };
    };

    pub const Array = extern struct {
        len_lo: u32,
        len_hi: u32,
        child: Type,

        fn length(self: Array) u64 {
            return @as(u64, self.len_hi) << 32 | self.len_lo;
        }
    };

    pub const Structure = struct {
        fields_len: u32,
        // fields: [fields_len]Type,

        pub const Kind = enum { normal, @"packed" };
    };

    pub const NamedStructure = struct {
        id: String,
        body: Type,
    };

    pub const Item = packed struct(u32) {
        tag: Tag,
        data: ExtraIndex,

        pub const ExtraIndex = u28;
    };

    pub fn tag(self: Type, builder: *const Builder) Tag {
        return builder.type_items.items[@backingInt(self)].tag;
    }

    pub fn unnamedTag(self: Type, builder: *const Builder) Tag {
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .named_structure => builder.typeExtraData(Type.NamedStructure, item.data).body
                .unnamedTag(builder),
            else => item.tag,
        };
    }

    pub fn scalarTag(self: Type, builder: *const Builder) Tag {
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .vector, .scalable_vector => builder.typeExtraData(Type.Vector, item.data)
                .child.tag(builder),
            else => item.tag,
        };
    }

    pub fn isFloatingPoint(self: Type) bool {
        return switch (self) {
            .half, .bfloat, .float, .double, .fp128, .x86_fp80, .ppc_fp128 => true,
            else => false,
        };
    }

    pub fn isInteger(self: Type, builder: *const Builder) bool {
        return switch (self) {
            .i1, .i8, .i16, .i29, .i32, .i64, .i80, .i128 => true,
            else => switch (self.tag(builder)) {
                .integer => true,
                else => false,
            },
        };
    }

    pub fn isPointer(self: Type, builder: *const Builder) bool {
        return switch (self) {
            .ptr => true,
            else => switch (self.tag(builder)) {
                .pointer => true,
                else => false,
            },
        };
    }

    pub fn pointerAddrSpace(self: Type, builder: *const Builder) AddrSpace {
        switch (self) {
            .ptr => return .default,
            else => {
                const item = builder.type_items.items[@backingInt(self)];
                assert(item.tag == .pointer);
                return @fromBackingInt(@intCast(item.data));
            },
        }
    }

    pub fn isFunction(self: Type, builder: *const Builder) bool {
        return switch (self.tag(builder)) {
            .function, .vararg_function => true,
            else => false,
        };
    }

    pub fn functionKind(self: Type, builder: *const Builder) Type.Function.Kind {
        return switch (self.tag(builder)) {
            .function => .normal,
            .vararg_function => .vararg,
            else => unreachable,
        };
    }

    pub fn functionParameters(self: Type, builder: *const Builder) []const Type {
        const item = builder.type_items.items[@backingInt(self)];
        switch (item.tag) {
            .function,
            .vararg_function,
            => {
                var extra = builder.typeExtraDataTrail(Type.Function, item.data);
                return extra.trail.next(extra.data.params_len, Type, builder);
            },
            else => unreachable,
        }
    }

    pub fn functionReturn(self: Type, builder: *const Builder) Type {
        const item = builder.type_items.items[@backingInt(self)];
        switch (item.tag) {
            .function,
            .vararg_function,
            => return builder.typeExtraData(Type.Function, item.data).ret,
            else => unreachable,
        }
    }

    pub fn isVector(self: Type, builder: *const Builder) bool {
        return switch (self.tag(builder)) {
            .vector, .scalable_vector => true,
            else => false,
        };
    }

    pub fn vectorKind(self: Type, builder: *const Builder) Type.Vector.Kind {
        return switch (self.tag(builder)) {
            .vector => .normal,
            .scalable_vector => .scalable,
            else => unreachable,
        };
    }

    pub fn isStruct(self: Type, builder: *const Builder) bool {
        return switch (self.tag(builder)) {
            .structure, .packed_structure, .named_structure => true,
            else => false,
        };
    }

    pub fn structKind(self: Type, builder: *const Builder) Type.Structure.Kind {
        return switch (self.unnamedTag(builder)) {
            .structure => .normal,
            .packed_structure => .@"packed",
            else => unreachable,
        };
    }

    pub fn isAggregate(self: Type, builder: *const Builder) bool {
        return switch (self.tag(builder)) {
            .small_array, .array, .structure, .packed_structure, .named_structure => true,
            else => false,
        };
    }

    pub fn scalarBits(self: Type, builder: *const Builder) u24 {
        return switch (self) {
            .void, .label, .token, .metadata, .none, .x86_amx => unreachable,
            .i1 => 1,
            .i8 => 8,
            .half, .bfloat, .i16 => 16,
            .i29 => 29,
            .float, .i32 => 32,
            .double, .i64, .x86_mmx => 64,
            .x86_fp80, .i80 => 80,
            .fp128, .ppc_fp128, .i128 => 128,
            .ptr => @intCast(builder.data_layout.getPointerSpec(.default).bit_width),
            .@"ptr addrspace(4)" => @intCast(
                builder.data_layout.getPointerSpec(@fromBackingInt(@intCast(4))).bit_width,
            ),
            _ => {
                const item = builder.type_items.items[@backingInt(self)];
                return switch (item.tag) {
                    .simple,
                    .function,
                    .vararg_function,
                    => unreachable,
                    .integer => @intCast(item.data),
                    .pointer => @intCast(
                        builder.data_layout.getPointerSpec(@fromBackingInt(@intCast(item.data))).bit_width,
                    ),
                    .target => unreachable,
                    .vector,
                    .scalable_vector,
                    => builder.typeExtraData(Type.Vector, item.data).child.scalarBits(builder),
                    .small_array,
                    .array,
                    .structure,
                    .packed_structure,
                    .named_structure,
                    => unreachable,
                };
            },
        };
    }

    pub fn childType(self: Type, builder: *const Builder) Type {
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .vector,
            .scalable_vector,
            .small_array,
            => builder.typeExtraData(Type.Vector, item.data).child,
            .array => builder.typeExtraData(Type.Array, item.data).child,
            .named_structure => builder.typeExtraData(Type.NamedStructure, item.data).body,
            else => unreachable,
        };
    }

    pub fn scalarType(self: Type, builder: *const Builder) Type {
        if (self.isFloatingPoint()) return self;
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .integer,
            .pointer,
            => self,
            .vector,
            .scalable_vector,
            => builder.typeExtraData(Type.Vector, item.data).child,
            else => unreachable,
        };
    }

    pub fn changeScalar(self: Type, scalar: Type, builder: *Builder) Allocator.Error!Type {
        try builder.ensureUnusedTypeCapacity(1, Type.Vector, 0);
        return self.changeScalarAssumeCapacity(scalar, builder);
    }

    pub fn changeScalarAssumeCapacity(self: Type, scalar: Type, builder: *Builder) Type {
        if (self.isFloatingPoint()) return scalar;
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .integer,
            .pointer,
            => scalar,
            inline .vector,
            .scalable_vector,
            => |kind| builder.vectorTypeAssumeCapacity(
                switch (kind) {
                    .vector => .normal,
                    .scalable_vector => .scalable,
                    else => unreachable,
                },
                builder.typeExtraData(Type.Vector, item.data).len,
                scalar,
            ),
            else => unreachable,
        };
    }

    pub fn vectorLen(self: Type, builder: *const Builder) u32 {
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .vector,
            .scalable_vector,
            => builder.typeExtraData(Type.Vector, item.data).len,
            else => unreachable,
        };
    }

    pub fn changeLength(self: Type, len: u32, builder: *Builder) Allocator.Error!Type {
        try builder.ensureUnusedTypeCapacity(1, Type.Array, 0);
        return self.changeLengthAssumeCapacity(len, builder);
    }

    pub fn changeLengthAssumeCapacity(self: Type, len: u32, builder: *Builder) Type {
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            inline .vector,
            .scalable_vector,
            => |kind| builder.vectorTypeAssumeCapacity(
                switch (kind) {
                    .vector => .normal,
                    .scalable_vector => .scalable,
                    else => unreachable,
                },
                len,
                builder.typeExtraData(Type.Vector, item.data).child,
            ),
            .small_array => builder.arrayTypeAssumeCapacity(
                len,
                builder.typeExtraData(Type.Vector, item.data).child,
            ),
            .array => builder.arrayTypeAssumeCapacity(
                len,
                builder.typeExtraData(Type.Array, item.data).child,
            ),
            else => unreachable,
        };
    }

    pub fn aggregateLen(self: Type, builder: *const Builder) usize {
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .vector,
            .scalable_vector,
            .small_array,
            => builder.typeExtraData(Type.Vector, item.data).len,
            .array => @intCast(builder.typeExtraData(Type.Array, item.data).length()),
            .structure,
            .packed_structure,
            => builder.typeExtraData(Type.Structure, item.data).fields_len,
            .named_structure => builder.typeExtraData(Type.NamedStructure, item.data).body
                .aggregateLen(builder),
            else => unreachable,
        };
    }

    pub fn structFields(self: Type, builder: *const Builder) []const Type {
        const item = builder.type_items.items[@backingInt(self)];
        switch (item.tag) {
            .structure,
            .packed_structure,
            => {
                var extra = builder.typeExtraDataTrail(Type.Structure, item.data);
                return extra.trail.next(extra.data.fields_len, Type, builder);
            },
            .named_structure => return builder.typeExtraData(Type.NamedStructure, item.data).body
                .structFields(builder),
            else => unreachable,
        }
    }

    pub fn childTypeAt(self: Type, indices: []const u32, builder: *const Builder) Type {
        if (indices.len == 0) return self;
        const item = builder.type_items.items[@backingInt(self)];
        return switch (item.tag) {
            .small_array => builder.typeExtraData(Type.Vector, item.data).child
                .childTypeAt(indices[1..], builder),
            .array => builder.typeExtraData(Type.Array, item.data).child
                .childTypeAt(indices[1..], builder),
            .structure,
            .packed_structure,
            => {
                var extra = builder.typeExtraDataTrail(Type.Structure, item.data);
                const fields = extra.trail.next(extra.data.fields_len, Type, builder);
                return fields[indices[0]].childTypeAt(indices[1..], builder);
            },
            .named_structure => builder.typeExtraData(Type.NamedStructure, item.data).body
                .childTypeAt(indices, builder),
            else => unreachable,
        };
    }

    pub fn targetLayoutType(self: Type, builder: *const Builder) Type {
        _ = self;
        _ = builder;
        @panic("TODO: implement targetLayoutType");
    }

    pub fn isSized(self: Type, builder: *const Builder) Allocator.Error!bool {
        var visited: IsSizedVisited = .{};
        defer visited.deinit(builder.gpa);
        const result = try self.isSizedVisited(&visited, builder);
        return result;
    }

    const FormatData = struct {
        type: Type,
        builder: *const Builder,
        mode: Mode,

        const Mode = enum { default, m, lt, gt, percent };
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        assert(data.type != .none);
        if (data.mode == .m) {
            const item = data.builder.type_items.items[@backingInt(data.type)];
            switch (item.tag) {
                .simple => try w.writeAll(switch (@as(Simple, @fromBackingInt(@intCast(item.data)))) {
                    .void => "isVoid",
                    .half => "f16",
                    .bfloat => "bf16",
                    .float => "f32",
                    .double => "f64",
                    .fp128 => "f128",
                    .x86_fp80 => "f80",
                    .ppc_fp128 => "ppcf128",
                    .x86_amx => "x86amx",
                    .x86_mmx => "x86mmx",
                    .label, .token => unreachable,
                    .metadata => "Metadata",
                }),
                .function, .vararg_function => |kind| {
                    var extra = data.builder.typeExtraDataTrail(Type.Function, item.data);
                    const params = extra.trail.next(extra.data.params_len, Type, data.builder);
                    try w.print("f_{f}", .{extra.data.ret.fmt(data.builder, .m)});
                    for (params) |param| try w.print("{f}", .{param.fmt(data.builder, .m)});
                    switch (kind) {
                        .function => {},
                        .vararg_function => try w.writeAll("vararg"),
                        else => unreachable,
                    }
                    try w.writeByte('f');
                },
                .integer => try w.print("i{d}", .{item.data}),
                .pointer => try w.print("p{d}", .{item.data}),
                .target => {
                    var extra = data.builder.typeExtraDataTrail(Type.Target, item.data);
                    const types = extra.trail.next(extra.data.types_len, Type, data.builder);
                    const ints = extra.trail.next(extra.data.ints_len, u32, data.builder);
                    try w.print("t{s}", .{extra.data.name.slice(data.builder).?});
                    for (types) |ty| try w.print("_{f}", .{ty.fmt(data.builder, .m)});
                    for (ints) |int| try w.print("_{d}", .{int});
                    try w.writeByte('t');
                },
                .vector, .scalable_vector => |kind| {
                    const extra = data.builder.typeExtraData(Type.Vector, item.data);
                    try w.print("{s}v{d}{f}", .{
                        switch (kind) {
                            .vector => "",
                            .scalable_vector => "nx",
                            else => unreachable,
                        },
                        extra.len,
                        extra.child.fmt(data.builder, .m),
                    });
                },
                inline .small_array, .array => |kind| {
                    const extra = data.builder.typeExtraData(switch (kind) {
                        .small_array => Type.Vector,
                        .array => Type.Array,
                        else => unreachable,
                    }, item.data);
                    try w.print("a{d}{f}", .{ extra.length(), extra.child.fmt(data.builder, .m) });
                },
                .structure, .packed_structure => {
                    var extra = data.builder.typeExtraDataTrail(Type.Structure, item.data);
                    const fields = extra.trail.next(extra.data.fields_len, Type, data.builder);
                    try w.writeAll("sl_");
                    for (fields) |field| try w.print("{f}", .{field.fmt(data.builder, .m)});
                    try w.writeByte('s');
                },
                .named_structure => {
                    const extra = data.builder.typeExtraData(Type.NamedStructure, item.data);
                    try w.writeAll("s_");
                    if (extra.id.slice(data.builder)) |id| try w.writeAll(id);
                },
            }
            return;
        }
        if (std.enums.tagName(Type, data.type)) |name| return w.writeAll(name);
        const item = data.builder.type_items.items[@backingInt(data.type)];
        switch (item.tag) {
            .simple => unreachable,
            .function, .vararg_function => |kind| {
                var extra = data.builder.typeExtraDataTrail(Type.Function, item.data);
                const params = extra.trail.next(extra.data.params_len, Type, data.builder);
                if (data.mode != .gt)
                    try w.print("{f} ", .{extra.data.ret.fmt(data.builder, .percent)});
                if (data.mode != .lt) {
                    try w.writeByte('(');
                    for (params, 0..) |param, index| {
                        if (index > 0) try w.writeAll(", ");
                        try w.print("{f}", .{param.fmt(data.builder, .percent)});
                    }
                    switch (kind) {
                        .function => {},
                        .vararg_function => {
                            if (params.len > 0) try w.writeAll(", ");
                            try w.writeAll("...");
                        },
                        else => unreachable,
                    }
                    try w.writeByte(')');
                }
            },
            .integer => try w.print("i{d}", .{item.data}),
            .pointer => try w.print("ptr{f}", .{@as(AddrSpace, @fromBackingInt(@intCast(item.data))).fmt(" ")}),
            .target => {
                var extra = data.builder.typeExtraDataTrail(Type.Target, item.data);
                const types = extra.trail.next(extra.data.types_len, Type, data.builder);
                const ints = extra.trail.next(extra.data.ints_len, u32, data.builder);
                try w.print(
                    \\target({f}
                , .{extra.data.name.fmtQ(data.builder)});
                for (types) |ty| try w.print(", {f}", .{ty.fmt(data.builder, .percent)});
                for (ints) |int| try w.print(", {d}", .{int});
                try w.writeByte(')');
            },
            .vector, .scalable_vector => |kind| {
                const extra = data.builder.typeExtraData(Type.Vector, item.data);
                try w.print("<{s}{d} x {f}>", .{
                    switch (kind) {
                        .vector => "",
                        .scalable_vector => "vscale x ",
                        else => unreachable,
                    },
                    extra.len,
                    extra.child.fmt(data.builder, .percent),
                });
            },
            inline .small_array, .array => |kind| {
                const extra = data.builder.typeExtraData(switch (kind) {
                    .small_array => Type.Vector,
                    .array => Type.Array,
                    else => unreachable,
                }, item.data);
                try w.print("[{d} x {f}]", .{ extra.length(), extra.child.fmt(data.builder, .percent) });
            },
            .structure, .packed_structure => |kind| {
                var extra = data.builder.typeExtraDataTrail(Type.Structure, item.data);
                const fields = extra.trail.next(extra.data.fields_len, Type, data.builder);
                switch (kind) {
                    .structure => {},
                    .packed_structure => try w.writeByte('<'),
                    else => unreachable,
                }
                try w.writeAll("{ ");
                for (fields, 0..) |field, index| {
                    if (index > 0) try w.writeAll(", ");
                    try w.print("{f}", .{field.fmt(data.builder, .percent)});
                }
                try w.writeAll(" }");
                switch (kind) {
                    .structure => {},
                    .packed_structure => try w.writeByte('>'),
                    else => unreachable,
                }
            },
            .named_structure => {
                const extra = data.builder.typeExtraData(Type.NamedStructure, item.data);
                if (data.mode == .percent) try w.print("%{f}", .{
                    extra.id.fmt(data.builder),
                }) else switch (extra.body) {
                    .none => try w.writeAll("opaque"),
                    else => try format(.{
                        .type = extra.body,
                        .builder = data.builder,
                        .mode = data.mode,
                    }, w),
                }
            },
        }
    }
    pub fn fmt(self: Type, builder: *const Builder, mode: FormatData.Mode) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{ .type = self, .builder = builder, .mode = mode } };
    }

    const IsSizedVisited = std.AutoHashMapUnmanaged(Type, void);
    fn isSizedVisited(
        self: Type,
        visited: *IsSizedVisited,
        builder: *const Builder,
    ) Allocator.Error!bool {
        return switch (self) {
            .void,
            .label,
            .token,
            .metadata,
            => false,
            .half,
            .bfloat,
            .float,
            .double,
            .fp128,
            .x86_fp80,
            .ppc_fp128,
            .x86_amx,
            .x86_mmx,
            .i1,
            .i8,
            .i16,
            .i29,
            .i32,
            .i64,
            .i80,
            .i128,
            .ptr,
            .@"ptr addrspace(4)",
            => true,
            .none => unreachable,
            _ => {
                const item = builder.type_items.items[@backingInt(self)];
                return switch (item.tag) {
                    .simple => unreachable,
                    .function,
                    .vararg_function,
                    => false,
                    .integer,
                    .pointer,
                    => true,
                    .target => self.targetLayoutType(builder).isSizedVisited(visited, builder),
                    .vector,
                    .scalable_vector,
                    .small_array,
                    => builder.typeExtraData(Type.Vector, item.data)
                        .child.isSizedVisited(visited, builder),
                    .array => builder.typeExtraData(Type.Array, item.data)
                        .child.isSizedVisited(visited, builder),
                    .structure,
                    .packed_structure,
                    => {
                        if (try visited.fetchPut(builder.gpa, self, {})) |_| return false;

                        var extra = builder.typeExtraDataTrail(Type.Structure, item.data);
                        const fields = extra.trail.next(extra.data.fields_len, Type, builder);
                        for (fields) |field| {
                            if (field.isVector(builder) and field.vectorKind(builder) == .scalable)
                                return false;
                            if (!try field.isSizedVisited(visited, builder))
                                return false;
                        }
                        return true;
                    },
                    .named_structure => {
                        const body = builder.typeExtraData(Type.NamedStructure, item.data).body;
                        return body != .none and try body.isSizedVisited(visited, builder);
                    },
                };
            },
        };
    }

    const Size = union(enum) { fixed: u64, scalable: u64 };
    pub fn bits(ty: Type, builder: *const Builder) Size {
        const item = builder.type_items.items[@backingInt(ty)];
        return switch (item.tag) {
            else => unreachable,
            .simple => switch (@as(Simple, @fromBackingInt(@intCast(item.data)))) {
                else => unreachable,
                .label => .{ .fixed = builder.data_layout.getPointerSpec(.default).bit_width },
                .half, .bfloat => .{ .fixed = 16 },
                .float => .{ .fixed = 32 },
                .double => .{ .fixed = 64 },
                .ppc_fp128, .fp128 => .{ .fixed = 128 },
                .x86_amx => .{ .fixed = 8192 },
                .x86_fp80 => .{ .fixed = 80 },
            },
            .integer => .{ .fixed = item.data },
            .pointer => .{
                .fixed = builder.data_layout.getPointerSpec(@fromBackingInt(@intCast(item.data))).bit_width,
            },
        };
    }

    pub fn alignment(ty: Type, kind: enum { abi, pref }, builder: *const Builder) Alignment {
        const item = builder.type_items.items[@backingInt(ty)];
        switch (item.tag) {
            else => unreachable,
            .simple => switch (@as(Simple, @fromBackingInt(@intCast(item.data)))) {
                else => unreachable,
                .label => {
                    const spec = builder.data_layout.getPointerSpec(.default);
                    return switch (kind) {
                        .abi => spec.flags.abi_align,
                        .pref => spec.flags.pref_align,
                    };
                },
                .half, .bfloat, .float, .double, .ppc_fp128, .fp128, .x86_fp80 => {
                    const spec = builder.data_layout.getFloatSpec(@intCast(ty.bits(builder).fixed));
                    return switch (kind) {
                        .abi => spec.abi_align,
                        .pref => spec.pref_align,
                    };
                },
                .x86_amx => return comptime .fromByteUnits(64),
            },
            .integer => {
                const spec = builder.data_layout.getIntegerSpec(@intCast(item.data));
                return switch (kind) {
                    .abi => spec.abi_align,
                    .pref => spec.pref_align,
                };
            },
            .pointer => {
                const spec = builder.data_layout.getPointerSpec(@fromBackingInt(@intCast(item.data)));
                return switch (kind) {
                    .abi => spec.flags.abi_align,
                    .pref => spec.flags.pref_align,
                };
            },
        }
    }
};

pub const Attribute = union(Kind) {
    // 参数属性
    zeroext,
    signext,
    noext,
    inreg,
    byval: Type,
    byref: Type,
    preallocated: Type,
    inalloca: Type,
    sret: Type,
    elementtype: Type,
    @"align": Alignment.Lazy,
    @"noalias",
    nocapture,
    captures: Captures,
    nofree,
    nest,
    returned,
    nonnull,
    dereferenceable: u32,
    dereferenceable_or_null: u32,
    swiftself,
    swiftasync,
    swifterror,
    immarg,
    noundef,
    nofpclass: FpClass,
    alignstack: Alignment.Lazy,
    allocalign,
    allocptr,
    readnone,
    readonly,
    writeonly,
    writable,
    initializes: []const [2]u64,
    dead_on_unwind,
    dead_on_return: ?u32,
    range: [2]Constant,

    // 函数属性。
    // alignstack: Alignment.Lazy,
    allockind: AllocKind,
    allocsize: AllocSize,
    alwaysinline,
    builtin,
    cold,
    convergent,
    disable_sanitizer_instrumentation,
    fn_ret_thunk_extern,
    hot,
    inlinehint,
    jumptable,
    memory: Memory,
    minsize,
    naked,
    nobuiltin,
    nocallback,
    nodivergencesource,
    noduplicate,
    // nofree,
    noimplicitfloat,
    @"noinline",
    nomerge,
    nonlazybind,
    noprofile,
    skipprofile,
    noredzone,
    noreturn,
    norecurse,
    willreturn,
    nosync,
    nounwind,
    nosanitize_bounds,
    nosanitize_coverage,
    null_pointer_is_valid,
    optdebug,
    optforfuzzing,
    optnone,
    optsize,
    // preallocated: Type,
    returns_twice,
    safestack,
    sanitize_address,
    sanitize_memory,
    sanitize_thread,
    sanitize_hwaddress,
    sanitize_memtag,
    sanitize_realtime,
    sanitize_realtime_blocking,
    sanitize_alloc_token,
    speculative_load_hardening,
    speculatable,
    ssp,
    sspstrong,
    sspreq,
    strictfp,
    denormal_fpenv,
    uwtable: UwTable,
    nocf_check,
    shadowcallstack,
    mustprogress,
    vscale_range: VScaleRange,
    nooutline,
    nocreateundeforpoison,

    string: struct { kind: String, value: String },
    none: noreturn,

    pub const Index = enum(u32) {
        _,

        pub fn getKind(self: Index, builder: *const Builder) Kind {
            return self.toStorage(builder).kind;
        }

        pub fn toAttribute(self: Index, builder: *const Builder) Attribute {
            @setEvalBranchQuota(2_000);
            const storage = self.toStorage(builder);
            if (storage.kind.toString()) |kind| return .{ .string = .{
                .kind = kind,
                .value = @fromBackingInt(storage.value),
            } } else return switch (storage.kind) {
                inline else => |kind| {
                    const field_name, const field_type = comptime blk: {
                        @setEvalBranchQuota(12_000);
                        const info = @typeInfo(Attribute).@"union";
                        for (info.field_names, info.field_types) |field_name, field_type| {
                            if (std.mem.eql(u8, field_name, @tagName(kind))) break :blk .{ field_name, field_type };
                        }
                        unreachable;
                    };
                    comptime assert(std.mem.eql(u8, @tagName(kind), field_name));
                    return @unionInit(Attribute, field_name, switch (field_type) {
                        void => {},
                        u32 => storage.value,
                        Alignment.Lazy, String, Type, UwTable => @fromBackingInt(storage.value),
                        AllocKind, AllocSize, Captures, FpClass, Memory, VScaleRange => @bitCast(storage.value),
                        else => @compileError("bad payload type: " ++ field_name ++ ": " ++
                            @typeName(field_type)),
                    });
                },
                .initializes,
                .dead_on_return,
                .range,
                => @panic("TODO"),
                .string, .none, _ => unreachable,
            };
        }

        const FormatData = struct {
            attribute_index: Index,
            builder: *const Builder,
            flags: Flags = .{},
            const Flags = struct {
                pound: bool = false,
                quote: bool = false,
            };
        };
        fn format(data: FormatData, w: *Writer) Writer.Error!void {
            const attribute = data.attribute_index.toAttribute(data.builder);
            switch (attribute) {
                .zeroext,
                .signext,
                .noext,
                .inreg,
                .@"noalias",
                .nocapture,
                .nofree,
                .nest,
                .returned,
                .nonnull,
                .swiftself,
                .swiftasync,
                .swifterror,
                .immarg,
                .noundef,
                .allocalign,
                .allocptr,
                .readnone,
                .readonly,
                .writeonly,
                .writable,
                .dead_on_unwind,
                .alwaysinline,
                .builtin,
                .cold,
                .convergent,
                .disable_sanitizer_instrumentation,
                .fn_ret_thunk_extern,
                .hot,
                .inlinehint,
                .jumptable,
                .minsize,
                .naked,
                .nobuiltin,
                .nocallback,
                .nodivergencesource,
                .noduplicate,
                .noimplicitfloat,
                .@"noinline",
                .nomerge,
                .nonlazybind,
                .noprofile,
                .skipprofile,
                .noredzone,
                .noreturn,
                .norecurse,
                .willreturn,
                .nosync,
                .nounwind,
                .nosanitize_bounds,
                .nosanitize_coverage,
                .null_pointer_is_valid,
                .optdebug,
                .optforfuzzing,
                .optnone,
                .optsize,
                .returns_twice,
                .safestack,
                .sanitize_address,
                .sanitize_memory,
                .sanitize_thread,
                .sanitize_hwaddress,
                .sanitize_memtag,
                .sanitize_realtime,
                .sanitize_realtime_blocking,
                .sanitize_alloc_token,
                .speculative_load_hardening,
                .speculatable,
                .ssp,
                .sspstrong,
                .sspreq,
                .strictfp,
                .denormal_fpenv,
                .nocf_check,
                .shadowcallstack,
                .mustprogress,
                .nooutline,
                .nocreateundeforpoison,
                => try w.print(" {s}", .{@tagName(attribute)}),
                .byval,
                .byref,
                .preallocated,
                .inalloca,
                .sret,
                .elementtype,
                => |ty| try w.print(" {s}({f})", .{ @tagName(attribute), ty.fmt(data.builder, .percent) }),
                .@"align" => |alignment| try w.print("{f}", .{alignment.resolve(data.builder).fmt(" ")}),
                .dereferenceable,
                .dereferenceable_or_null,
                => |size| try w.print(" {s}({d})", .{ @tagName(attribute), size }),
                .captures => |captures| {
                    try w.print(" {s}(", .{@tagName(attribute)});
                    var need_comma = false;
                    if (captures == Captures.none) {
                        if (need_comma) try w.writeAll(", ");
                        try w.writeAll("none");
                        need_comma = true;
                    }
                    inline for (@typeInfo(Captures).@"struct".field_names) |field_name| {
                        if (comptime std.mem.eql(u8, field_name, "_")) continue;
                        const components = @field(captures, field_name);
                        if (components != Captures.Components.none) {
                            if (!comptime std.mem.eql(u8, field_name, "other")) {
                                if (need_comma) try w.writeAll(", ");
                                try w.writeAll(field_name ++ ": ");
                                need_comma = false;
                            }
                            if (components.address) {
                                if (need_comma) try w.writeAll(", ");
                                try w.writeAll("address");
                                need_comma = true;
                            } else if (components.address_is_null) {
                                if (need_comma) try w.writeAll(", ");
                                try w.writeAll("address_is_null");
                                need_comma = true;
                            }
                            if (components.provenance) {
                                if (need_comma) try w.writeAll(", ");
                                try w.writeAll("provenance");
                                need_comma = true;
                            } else if (components.read_provenance) {
                                if (need_comma) try w.writeAll(", ");
                                try w.writeAll("read_provenance");
                                need_comma = true;
                            }
                        }
                    }
                    try w.writeByte(')');
                },
                .nofpclass => |fpclass| {
                    const Int = @typeInfo(FpClass).@"struct".backing_integer.?;
                    try w.print(" {s}(", .{@tagName(attribute)});
                    var any = false;
                    var remaining: Int = @bitCast(fpclass);
                    inline for (@typeInfo(FpClass).@"struct".decl_names) |decl_name| {
                        const pattern: Int = @bitCast(@field(FpClass, decl_name));
                        if (remaining & pattern == pattern) {
                            if (!any) {
                                try w.writeByte(' ');
                                any = true;
                            }
                            try w.writeAll(decl_name);
                            remaining &= ~pattern;
                        }
                    }
                    try w.writeByte(')');
                },
                .alignstack => |alignment| {
                    try w.print(" {t}", .{attribute});
                    const alignment_bytes = alignment.resolve(data.builder).toByteUnits() orelse return;
                    if (data.flags.pound) {
                        try w.print("={d}", .{alignment_bytes});
                    } else {
                        try w.print("({d})", .{alignment_bytes});
                    }
                },
                .initializes => @panic("TODO"),
                .dead_on_return => @panic("TODO"),
                .range => @panic("TODO"),
                .allockind => |allockind| {
                    try w.print(" {t}(\"", .{attribute});
                    var any = false;
                    inline for (@typeInfo(AllocKind).@"struct".field_names) |field_name| {
                        if (comptime std.mem.eql(u8, field_name, "_")) continue;
                        if (@field(allockind, field_name)) {
                            if (!any) {
                                try w.writeByte(',');
                                any = true;
                            }
                            try w.writeAll(field_name);
                        }
                    }
                    try w.writeAll("\")");
                },
                .allocsize => |allocsize| {
                    try w.print(" {t}({d}", .{ attribute, allocsize.elem_size });
                    if (allocsize.num_elems != AllocSize.none)
                        try w.print(",{d}", .{allocsize.num_elems});
                    try w.writeByte(')');
                },
                .memory => |memory| {
                    try w.print(" {t}(", .{attribute});
                    var any = memory.other != .none or
                        (memory.argmem == .none and memory.inaccessiblemem == .none);
                    if (any) try w.writeAll(@tagName(memory.other));
                    inline for (.{ "argmem", "inaccessiblemem" }) |kind| {
                        if (@field(memory, kind) != memory.other) {
                            if (any) try w.writeAll(", ");
                            try w.print("{s}: {s}", .{ kind, @tagName(@field(memory, kind)) });
                            any = true;
                        }
                    }
                    try w.writeByte(')');
                },
                .uwtable => |uwtable| if (uwtable != .none) {
                    try w.print(" {s}", .{@tagName(attribute)});
                    if (uwtable != UwTable.default) try w.print("({s})", .{@tagName(uwtable)});
                },
                .vscale_range => |vscale_range| try w.print(" {s}({d},{d})", .{
                    @tagName(attribute),
                    vscale_range.min.toByteUnits().?,
                    vscale_range.max.toByteUnits() orelse 0,
                }),
                .string => |string_attr| if (data.flags.quote) {
                    try w.print(" {f}", .{string_attr.kind.fmtQ(data.builder)});
                    if (string_attr.value != .empty)
                        try w.print("={f}", .{string_attr.value.fmtQ(data.builder)});
                },
                .none => unreachable,
            }
        }
        pub fn fmt(self: Index, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) {
            return .{ .data = .{ .attribute_index = self, .builder = builder, .flags = flags } };
        }

        fn toStorage(self: Index, builder: *const Builder) Storage {
            return builder.attributes.keys()[@backingInt(self)];
        }
    };

    pub const Kind = enum(u32) {
        // 参数属性
        zeroext = @backingInt(ATTR_KIND.Z_EXT),
        signext = @backingInt(ATTR_KIND.S_EXT),
        noext = @backingInt(ATTR_KIND.NO_EXT),
        inreg = @backingInt(ATTR_KIND.IN_REG),
        byval = @backingInt(ATTR_KIND.BY_VAL),
        byref = @backingInt(ATTR_KIND.BYREF),
        preallocated = @backingInt(ATTR_KIND.PREALLOCATED),
        inalloca = @backingInt(ATTR_KIND.IN_ALLOCA),
        sret = @backingInt(ATTR_KIND.STRUCT_RET),
        elementtype = @backingInt(ATTR_KIND.ELEMENTTYPE),
        @"align" = @backingInt(ATTR_KIND.ALIGNMENT),
        @"noalias" = @backingInt(ATTR_KIND.NO_ALIAS),
        nocapture = @backingInt(ATTR_KIND.NO_CAPTURE),
        captures = @backingInt(ATTR_KIND.CAPTURES),
        nofree = @backingInt(ATTR_KIND.NOFREE),
        nest = @backingInt(ATTR_KIND.NEST),
        returned = @backingInt(ATTR_KIND.RETURNED),
        nonnull = @backingInt(ATTR_KIND.NON_NULL),
        dereferenceable = @backingInt(ATTR_KIND.DEREFERENCEABLE),
        dereferenceable_or_null = @backingInt(ATTR_KIND.DEREFERENCEABLE_OR_NULL),
        swiftself = @backingInt(ATTR_KIND.SWIFT_SELF),
        swiftasync = @backingInt(ATTR_KIND.SWIFT_ASYNC),
        swifterror = @backingInt(ATTR_KIND.SWIFT_ERROR),
        immarg = @backingInt(ATTR_KIND.IMMARG),
        noundef = @backingInt(ATTR_KIND.NOUNDEF),
        nofpclass = @backingInt(ATTR_KIND.NOFPCLASS),
        alignstack = @backingInt(ATTR_KIND.STACK_ALIGNMENT),
        allocalign = @backingInt(ATTR_KIND.ALLOC_ALIGN),
        allocptr = @backingInt(ATTR_KIND.ALLOCATED_POINTER),
        readnone = @backingInt(ATTR_KIND.READ_NONE),
        readonly = @backingInt(ATTR_KIND.READ_ONLY),
        writeonly = @backingInt(ATTR_KIND.WRITEONLY),
        writable = @backingInt(ATTR_KIND.WRITABLE),
        initializes = @backingInt(ATTR_KIND.INITIALIZES),
        dead_on_unwind = @backingInt(ATTR_KIND.DEAD_ON_UNWIND),
        dead_on_return = @backingInt(ATTR_KIND.DEAD_ON_RETURN),
        range = @backingInt(ATTR_KIND.RANGE),

        // 函数属性
        // alignstack = @intFromEnum(ATTR_KIND.STACK_ALIGNMENT),
        allockind = @backingInt(ATTR_KIND.ALLOC_KIND),
        allocsize = @backingInt(ATTR_KIND.ALLOC_SIZE),
        alwaysinline = @backingInt(ATTR_KIND.ALWAYS_INLINE),
        builtin = @backingInt(ATTR_KIND.BUILTIN),
        cold = @backingInt(ATTR_KIND.COLD),
        convergent = @backingInt(ATTR_KIND.CONVERGENT),
        disable_sanitizer_instrumentation = @backingInt(ATTR_KIND.DISABLE_SANITIZER_INSTRUMENTATION),
        fn_ret_thunk_extern = @backingInt(ATTR_KIND.FNRETTHUNK_EXTERN),
        hot = @backingInt(ATTR_KIND.HOT),
        inlinehint = @backingInt(ATTR_KIND.INLINE_HINT),
        jumptable = @backingInt(ATTR_KIND.JUMP_TABLE),
        memory = @backingInt(ATTR_KIND.MEMORY),
        minsize = @backingInt(ATTR_KIND.MIN_SIZE),
        naked = @backingInt(ATTR_KIND.NAKED),
        nobuiltin = @backingInt(ATTR_KIND.NO_BUILTIN),
        nocallback = @backingInt(ATTR_KIND.NO_CALLBACK),
        nodivergencesource = @backingInt(ATTR_KIND.NO_DIVERGENCE_SOURCE),
        noduplicate = @backingInt(ATTR_KIND.NO_DUPLICATE),
        // nofree = @intFromEnum(ATTR_KIND.NOFREE),
        noimplicitfloat = @backingInt(ATTR_KIND.NO_IMPLICIT_FLOAT),
        @"noinline" = @backingInt(ATTR_KIND.NO_INLINE),
        nomerge = @backingInt(ATTR_KIND.NO_MERGE),
        nonlazybind = @backingInt(ATTR_KIND.NON_LAZY_BIND),
        noprofile = @backingInt(ATTR_KIND.NO_PROFILE),
        skipprofile = @backingInt(ATTR_KIND.SKIP_PROFILE),
        noredzone = @backingInt(ATTR_KIND.NO_RED_ZONE),
        noreturn = @backingInt(ATTR_KIND.NO_RETURN),
        norecurse = @backingInt(ATTR_KIND.NO_RECURSE),
        willreturn = @backingInt(ATTR_KIND.WILLRETURN),
        nosync = @backingInt(ATTR_KIND.NOSYNC),
        nounwind = @backingInt(ATTR_KIND.NO_UNWIND),
        nosanitize_bounds = @backingInt(ATTR_KIND.NO_SANITIZE_BOUNDS),
        nosanitize_coverage = @backingInt(ATTR_KIND.NO_SANITIZE_COVERAGE),
        null_pointer_is_valid = @backingInt(ATTR_KIND.NULL_POINTER_IS_VALID),
        optdebug = @backingInt(ATTR_KIND.OPTIMIZE_FOR_DEBUGGING),
        optforfuzzing = @backingInt(ATTR_KIND.OPT_FOR_FUZZING),
        optnone = @backingInt(ATTR_KIND.OPTIMIZE_NONE),
        optsize = @backingInt(ATTR_KIND.OPTIMIZE_FOR_SIZE),
        // 预分配属性:preallocated = @intFromEnum(ATTR_KIND.PREALLOCATED),
        returns_twice = @backingInt(ATTR_KIND.RETURNS_TWICE),
        safestack = @backingInt(ATTR_KIND.SAFESTACK),
        sanitize_address = @backingInt(ATTR_KIND.SANITIZE_ADDRESS),
        sanitize_memory = @backingInt(ATTR_KIND.SANITIZE_MEMORY),
        sanitize_thread = @backingInt(ATTR_KIND.SANITIZE_THREAD),
        sanitize_hwaddress = @backingInt(ATTR_KIND.SANITIZE_HWADDRESS),
        sanitize_memtag = @backingInt(ATTR_KIND.SANITIZE_MEMTAG),
        sanitize_realtime = @backingInt(ATTR_KIND.SANITIZE_REALTIME),
        sanitize_realtime_blocking = @backingInt(ATTR_KIND.SANITIZE_REALTIME_BLOCKING),
        sanitize_alloc_token = @backingInt(ATTR_KIND.SANITIZE_ALLOC_TOKEN),
        speculative_load_hardening = @backingInt(ATTR_KIND.SPECULATIVE_LOAD_HARDENING),
        speculatable = @backingInt(ATTR_KIND.SPECULATABLE),
        ssp = @backingInt(ATTR_KIND.STACK_PROTECT),
        sspstrong = @backingInt(ATTR_KIND.STACK_PROTECT_STRONG),
        sspreq = @backingInt(ATTR_KIND.STACK_PROTECT_REQ),
        strictfp = @backingInt(ATTR_KIND.STRICT_FP),
        denormal_fpenv = @backingInt(ATTR_KIND.DENORMAL_FPENV),
        uwtable = @backingInt(ATTR_KIND.UW_TABLE),
        nocf_check = @backingInt(ATTR_KIND.NOCF_CHECK),
        shadowcallstack = @backingInt(ATTR_KIND.SHADOWCALLSTACK),
        mustprogress = @backingInt(ATTR_KIND.MUSTPROGRESS),
        vscale_range = @backingInt(ATTR_KIND.VSCALE_RANGE),
        nooutline = @backingInt(ATTR_KIND.NOOUTLINE),
        nocreateundeforpoison = @backingInt(ATTR_KIND.NO_CREATE_UNDEF_OR_POISON),

        string = maxInt(u31),
        none = maxInt(u32),
        _,

        pub const len = @typeInfo(Kind).@"enum".field_names.len - 2;

        pub fn fromString(str: String) Kind {
            assert(!str.isAnon());
            const kind: Kind = @fromBackingInt(@backingInt(str));
            assert(kind != .none);
            return kind;
        }

        fn toString(self: Kind) ?String {
            assert(self != .none);
            const str: String = @fromBackingInt(@backingInt(self));
            return if (str.isAnon()) null else str;
        }

        /// enum AttributeKindCodes
        const ATTR_KIND = enum(u32) {
            ALIGNMENT = 1,
            ALWAYS_INLINE = 2,
            BY_VAL = 3,
            INLINE_HINT = 4,
            IN_REG = 5,
            MIN_SIZE = 6,
            NAKED = 7,
            NEST = 8,
            NO_ALIAS = 9,
            NO_BUILTIN = 10,
            NO_CAPTURE = 11,
            NO_DUPLICATE = 12,
            NO_IMPLICIT_FLOAT = 13,
            NO_INLINE = 14,
            NON_LAZY_BIND = 15,
            NO_RED_ZONE = 16,
            NO_RETURN = 17,
            NO_UNWIND = 18,
            OPTIMIZE_FOR_SIZE = 19,
            READ_NONE = 20,
            READ_ONLY = 21,
            RETURNED = 22,
            RETURNS_TWICE = 23,
            S_EXT = 24,
            STACK_ALIGNMENT = 25,
            STACK_PROTECT = 26,
            STACK_PROTECT_REQ = 27,
            STACK_PROTECT_STRONG = 28,
            STRUCT_RET = 29,
            SANITIZE_ADDRESS = 30,
            SANITIZE_THREAD = 31,
            SANITIZE_MEMORY = 32,
            UW_TABLE = 33,
            Z_EXT = 34,
            BUILTIN = 35,
            COLD = 36,
            OPTIMIZE_NONE = 37,
            IN_ALLOCA = 38,
            NON_NULL = 39,
            JUMP_TABLE = 40,
            DEREFERENCEABLE = 41,
            DEREFERENCEABLE_OR_NULL = 42,
            CONVERGENT = 43,
            SAFESTACK = 44,
            ARGMEMONLY = 45,
            SWIFT_SELF = 46,
            SWIFT_ERROR = 47,
            NO_RECURSE = 48,
            INACCESSIBLEMEM_ONLY = 49,
            INACCESSIBLEMEM_OR_ARGMEMONLY = 50,
            ALLOC_SIZE = 51,
            WRITEONLY = 52,
            SPECULATABLE = 53,
            STRICT_FP = 54,
            SANITIZE_HWADDRESS = 55,
            NOCF_CHECK = 56,
            OPT_FOR_FUZZING = 57,
            SHADOWCALLSTACK = 58,
            SPECULATIVE_LOAD_HARDENING = 59,
            IMMARG = 60,
            WILLRETURN = 61,
            NOFREE = 62,
            NOSYNC = 63,
            SANITIZE_MEMTAG = 64,
            PREALLOCATED = 65,
            NO_MERGE = 66,
            NULL_POINTER_IS_VALID = 67,
            NOUNDEF = 68,
            BYREF = 69,
            MUSTPROGRESS = 70,
            NO_CALLBACK = 71,
            HOT = 72,
            NO_PROFILE = 73,
            VSCALE_RANGE = 74,
            SWIFT_ASYNC = 75,
            NO_SANITIZE_COVERAGE = 76,
            ELEMENTTYPE = 77,
            DISABLE_SANITIZER_INSTRUMENTATION = 78,
            NO_SANITIZE_BOUNDS = 79,
            ALLOC_ALIGN = 80,
            ALLOCATED_POINTER = 81,
            ALLOC_KIND = 82,
            PRESPLIT_COROUTINE = 83,
            FNRETTHUNK_EXTERN = 84,
            SKIP_PROFILE = 85,
            MEMORY = 86,
            NOFPCLASS = 87,
            OPTIMIZE_FOR_DEBUGGING = 88,
            WRITABLE = 89,
            CORO_ONLY_DESTROY_WHEN_COMPLETE = 90,
            DEAD_ON_UNWIND = 91,
            RANGE = 92,
            SANITIZE_NUMERICAL_STABILITY = 93,
            INITIALIZES = 94,
            HYBRID_PATCHABLE = 95,
            SANITIZE_REALTIME = 96,
            SANITIZE_REALTIME_BLOCKING = 97,
            CORO_ELIDE_SAFE = 98,
            NO_EXT = 99,
            NO_DIVERGENCE_SOURCE = 100,
            SANITIZE_TYPE = 101,
            CAPTURES = 102,
            DEAD_ON_RETURN = 103,
            SANITIZE_ALLOC_TOKEN = 104,
            NO_CREATE_UNDEF_OR_POISON = 105,
            DENORMAL_FPENV = 106,
            NOOUTLINE = 107,
            FLATTEN = 108,
        };
    };

    pub const FpClass = packed struct(u32) {
        signaling_nan: bool = false,
        quiet_nan: bool = false,
        negative_infinity: bool = false,
        negative_normal: bool = false,
        negative_subnormal: bool = false,
        negative_zero: bool = false,
        positive_zero: bool = false,
        positive_subnormal: bool = false,
        positive_normal: bool = false,
        positive_infinity: bool = false,
        _: u22 = 0,

        pub const all = FpClass{
            .signaling_nan = true,
            .quiet_nan = true,
            .negative_infinity = true,
            .negative_normal = true,
            .negative_subnormal = true,
            .negative_zero = true,
            .positive_zero = true,
            .positive_subnormal = true,
            .positive_normal = true,
            .positive_infinity = true,
        };

        pub const nan = FpClass{ .signaling_nan = true, .quiet_nan = true };
        pub const snan = FpClass{ .signaling_nan = true };
        pub const qnan = FpClass{ .quiet_nan = true };

        pub const inf = FpClass{ .negative_infinity = true, .positive_infinity = true };
        pub const ninf = FpClass{ .negative_infinity = true };
        pub const pinf = FpClass{ .positive_infinity = true };

        pub const zero = FpClass{ .positive_zero = true, .negative_zero = true };
        pub const nzero = FpClass{ .negative_zero = true };
        pub const pzero = FpClass{ .positive_zero = true };

        pub const sub = FpClass{ .positive_subnormal = true, .negative_subnormal = true };
        pub const nsub = FpClass{ .negative_subnormal = true };
        pub const psub = FpClass{ .positive_subnormal = true };

        pub const norm = FpClass{ .positive_normal = true, .negative_normal = true };
        pub const nnorm = FpClass{ .negative_normal = true };
        pub const pnorm = FpClass{ .positive_normal = true };
    };

    pub const Captures = packed struct(u32) {
        other: Components = .none,
        ret: Components = .none,
        _: u24 = 0,

        pub const none: Captures = .{};

        pub const Components = packed struct(u4) {
            address_is_null: bool = false,
            address: bool = false,
            read_provenance: bool = false,
            provenance: bool = false,

            pub const none: Components = .{};
            pub const all: Components = .{
                .address_is_null = true,
                .address = true,
                .read_provenance = true,
                .provenance = true,
            };
        };
    };

    pub const AllocKind = packed struct(u32) {
        alloc: bool,
        realloc: bool,
        free: bool,
        uninitialized: bool,
        zeroed: bool,
        aligned: bool,
        _: u26 = 0,
    };

    pub const AllocSize = packed struct(u32) {
        elem_size: u16,
        num_elems: u16,

        pub const none = maxInt(u16);

        fn toLlvm(self: AllocSize) packed struct(u64) { num_elems: u32, elem_size: u32 } {
            return .{ .num_elems = switch (self.num_elems) {
                else => self.num_elems,
                none => maxInt(u32),
            }, .elem_size = self.elem_size };
        }
    };

    pub const Memory = packed struct(u32) {
        argmem: Effect = .none,
        inaccessiblemem: Effect = .none,
        other: Effect = .none,
        _: u26 = 0,

        pub const Effect = enum(u2) { none, read, write, readwrite };

        fn all(effect: Effect) Memory {
            return .{ .argmem = effect, .inaccessiblemem = effect, .other = effect };
        }
    };

    pub const UwTable = enum(u32) {
        none,
        sync,
        async,

        pub const default = UwTable.async;
    };

    pub const VScaleRange = packed struct(u32) {
        min: Alignment,
        max: Alignment,
        _: u20 = 0,

        fn toLlvm(self: VScaleRange) packed struct(u64) { max: u32, min: u32 } {
            return .{
                .max = @intCast(self.max.toByteUnits() orelse 0),
                .min = @intCast(self.min.toByteUnits().?),
            };
        }
    };

    pub fn getKind(self: Attribute) Kind {
        return switch (self) {
            else => self,
            .string => |string_attr| Kind.fromString(string_attr.kind),
        };
    }

    const Storage = extern struct {
        kind: Kind,
        value: u32,
    };

    fn toStorage(self: Attribute) Storage {
        return switch (self) {
            inline else => |value, tag| .{ .kind = @as(Kind, self), .value = switch (@TypeOf(value)) {
                void => 0,
                u32 => value,
                Alignment.Lazy, String, Type, UwTable => @backingInt(value),
                AllocKind, AllocSize, Captures, FpClass, Memory, VScaleRange => @bitCast(value),
                else => @compileError("bad payload type: " ++ @tagName(tag) ++ ": " ++ @typeName(@TypeOf(value))),
            } },
            .initializes,
            .dead_on_return,
            .range,
            => @panic("TODO"),
            .string => |string_attr| .{
                .kind = Kind.fromString(string_attr.kind),
                .value = @backingInt(string_attr.value),
            },
            .none => unreachable,
        };
    }
};

pub const Attributes = enum(u32) {
    none,
    _,

    pub fn slice(self: Attributes, builder: *const Builder) []const Attribute.Index {
        const start = builder.attributes_indices.items[@backingInt(self)];
        const end = builder.attributes_indices.items[@backingInt(self) + 1];
        return @ptrCast(builder.attributes_extra.items[start..end]);
    }

    const FormatData = struct {
        attributes: Attributes,
        builder: *const Builder,
        flags: Flags = .{},
        const Flags = Attribute.Index.FormatData.Flags;
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        for (data.attributes.slice(data.builder)) |attribute_index| try Attribute.Index.format(.{
            .attribute_index = attribute_index,
            .builder = data.builder,
            .flags = data.flags,
        }, w);
    }
    pub fn fmt(self: Attributes, builder: *const Builder, flags: FormatData.Flags) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{ .attributes = self, .builder = builder, .flags = flags } };
    }
};

pub const FunctionAttributes = enum(u32) {
    none,
    _,

    const function_index = 0;
    const return_index = 1;
    const params_index = 2;

    pub const Wip = struct {
        maps: Maps = .empty,

        const Map = std.array_hash_map.Auto(Attribute.Kind, Attribute.Index);
        const Maps = std.ArrayList(Map);

        pub fn deinit(self: *Wip, builder: *const Builder) void {
            for (self.maps.items) |*map| map.deinit(builder.gpa);
            self.maps.deinit(builder.gpa);
            self.* = undefined;
        }

        pub fn addFnAttr(self: *Wip, attribute: Attribute, builder: *Builder) Allocator.Error!void {
            try self.addAttr(function_index, attribute, builder);
        }

        pub fn addFnAttrIndex(
            self: *Wip,
            attribute_index: Attribute.Index,
            builder: *const Builder,
        ) Allocator.Error!void {
            try self.addAttrIndex(function_index, attribute_index, builder);
        }

        pub fn removeFnAttr(self: *Wip, attribute_kind: Attribute.Kind) Allocator.Error!bool {
            return self.removeAttr(function_index, attribute_kind);
        }

        pub fn addRetAttr(self: *Wip, attribute: Attribute, builder: *Builder) Allocator.Error!void {
            try self.addAttr(return_index, attribute, builder);
        }

        pub fn addRetAttrIndex(
            self: *Wip,
            attribute_index: Attribute.Index,
            builder: *const Builder,
        ) Allocator.Error!void {
            try self.addAttrIndex(return_index, attribute_index, builder);
        }

        pub fn removeRetAttr(self: *Wip, attribute_kind: Attribute.Kind) Allocator.Error!bool {
            return self.removeAttr(return_index, attribute_kind);
        }

        pub fn addParamAttr(
            self: *Wip,
            param_index: usize,
            attribute: Attribute,
            builder: *Builder,
        ) Allocator.Error!void {
            try self.addAttr(params_index + param_index, attribute, builder);
        }

        pub fn addParamAttrIndex(
            self: *Wip,
            param_index: usize,
            attribute_index: Attribute.Index,
            builder: *const Builder,
        ) Allocator.Error!void {
            try self.addAttrIndex(params_index + param_index, attribute_index, builder);
        }

        pub fn removeParamAttr(
            self: *Wip,
            param_index: usize,
            attribute_kind: Attribute.Kind,
        ) Allocator.Error!bool {
            return self.removeAttr(params_index + param_index, attribute_kind);
        }

        pub fn finish(self: *const Wip, builder: *Builder) Allocator.Error!FunctionAttributes {
            const attributes = try builder.gpa.alloc(Attributes, self.maps.items.len);
            defer builder.gpa.free(attributes);
            for (attributes, self.maps.items) |*attribute, map|
                attribute.* = try builder.attrs(map.values());
            return builder.fnAttrs(attributes);
        }

        fn addAttr(
            self: *Wip,
            index: usize,
            attribute: Attribute,
            builder: *Builder,
        ) Allocator.Error!void {
            const map = try self.getOrPutMap(builder.gpa, index);
            try map.put(builder.gpa, attribute.getKind(), try builder.attr(attribute));
        }

        fn addAttrIndex(
            self: *Wip,
            index: usize,
            attribute_index: Attribute.Index,
            builder: *const Builder,
        ) Allocator.Error!void {
            const map = try self.getOrPutMap(builder.gpa, index);
            try map.put(builder.gpa, attribute_index.getKind(builder), attribute_index);
        }

        fn removeAttr(self: *Wip, index: usize, attribute_kind: Attribute.Kind) Allocator.Error!bool {
            const map = self.getMap(index) orelse return false;
            return map.swapRemove(attribute_kind);
        }

        fn getOrPutMap(self: *Wip, allocator: Allocator, index: usize) Allocator.Error!*Map {
            if (index >= self.maps.items.len)
                try self.maps.appendNTimes(allocator, .{}, index + 1 - self.maps.items.len);
            return &self.maps.items[index];
        }

        fn getMap(self: *Wip, index: usize) ?*Map {
            return if (index >= self.maps.items.len) null else &self.maps.items[index];
        }

        fn ensureTotalLength(self: *Wip, new_len: usize) Allocator.Error!void {
            try self.maps.appendNTimes(
                .{},
                std.math.sub(usize, new_len, self.maps.items.len) catch return,
            );
        }
    };

    pub fn func(self: FunctionAttributes, builder: *const Builder) Attributes {
        return self.get(function_index, builder);
    }

    pub fn ret(self: FunctionAttributes, builder: *const Builder) Attributes {
        return self.get(return_index, builder);
    }

    pub fn param(self: FunctionAttributes, param_index: usize, builder: *const Builder) Attributes {
        return self.get(params_index + param_index, builder);
    }

    pub fn toWip(self: FunctionAttributes, builder: *const Builder) Allocator.Error!Wip {
        var wip: Wip = .{};
        errdefer wip.deinit(builder);
        const attributes_slice = self.slice(builder);
        try wip.maps.ensureTotalCapacityPrecise(builder.gpa, attributes_slice.len);
        for (attributes_slice) |attributes| {
            const map = wip.maps.addOneAssumeCapacity();
            map.* = .{};
            const attribute_slice = attributes.slice(builder);
            try map.ensureTotalCapacity(builder.gpa, attribute_slice.len);
            for (attributes.slice(builder)) |attribute|
                map.putAssumeCapacityNoClobber(attribute.getKind(builder), attribute);
        }
        return wip;
    }

    fn get(self: FunctionAttributes, index: usize, builder: *const Builder) Attributes {
        const attribute_slice = self.slice(builder);
        return if (index < attribute_slice.len) attribute_slice[index] else .none;
    }

    fn slice(self: FunctionAttributes, builder: *const Builder) []const Attributes {
        const start = builder.attributes_indices.items[@backingInt(self)];
        const end = builder.attributes_indices.items[@backingInt(self) + 1];
        return @ptrCast(builder.attributes_extra.items[start..end]);
    }
};

pub const Linkage = enum(u4) {
    private = 9,
    internal = 3,
    weak = 1,
    weak_odr = 10,
    linkonce = 4,
    linkonce_odr = 11,
    available_externally = 12,
    appending = 2,
    common = 8,
    extern_weak = 7,
    external = 0,

    pub fn format(self: Linkage, w: *Writer) Writer.Error!void {
        if (self != .external) try w.print(" {s}", .{@tagName(self)});
    }

    fn formatOptional(data: ?Linkage, w: *Writer) Writer.Error!void {
        if (data) |linkage| try w.print(" {s}", .{@tagName(linkage)});
    }
    pub fn fmtOptional(self: ?Linkage) std.fmt.Alt(?Linkage, formatOptional) {
        return .{ .data = self };
    }
};

pub const Preemption = enum(u2) {
    dso_preemptable,
    dso_local,
    implicit_dso_local,

    pub fn format(self: Preemption, w: *Writer) Writer.Error!void {
        if (self == .dso_local) try w.print(" {s}", .{@tagName(self)});
    }
};

pub const Visibility = enum(u2) {
    default = 0,
    hidden = 1,
    protected = 2,

    pub fn fromSymbolVisibility(sv: std.lang.SymbolVisibility) Visibility {
        return switch (sv) {
            .default => .default,
            .hidden => .hidden,
            .protected => .protected,
        };
    }

    pub fn format(self: Visibility, writer: *Writer) Writer.Error!void {
        if (self != .default) try writer.print(" {s}", .{@tagName(self)});
    }
};

pub const DllStorageClass = enum(u2) {
    default = 0,
    dllimport = 1,
    dllexport = 2,

    pub fn format(self: DllStorageClass, w: *Writer) Writer.Error!void {
        if (self != .default) try w.print(" {s}", .{@tagName(self)});
    }
};

pub const ThreadLocal = enum(u3) {
    default = 0,
    generaldynamic = 1,
    localdynamic = 2,
    initialexec = 3,
    localexec = 4,

    pub fn format(tl: ThreadLocal, w: *Writer) Writer.Error!void {
        return Prefixed.format(.{ .thread_local = tl, .prefix = "" }, w);
    }

    pub const Prefixed = struct {
        thread_local: ThreadLocal,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            switch (p.thread_local) {
                .default => return,
                .generaldynamic => {
                    var vecs: [2][]const u8 = .{ p.prefix, "thread_local" };
                    return w.writeVecAll(&vecs);
                },
                else => {
                    var vecs: [4][]const u8 = .{ p.prefix, "thread_local(", @tagName(p.thread_local), ")" };
                    return w.writeVecAll(&vecs);
                },
            }
        }
    };

    pub fn fmt(tl: ThreadLocal, prefix: []const u8) Prefixed {
        return .{ .thread_local = tl, .prefix = prefix };
    }
};

pub const Mutability = enum { global, constant };

pub const UnnamedAddr = enum(u2) {
    default = 0,
    unnamed_addr = 1,
    local_unnamed_addr = 2,

    pub fn format(self: UnnamedAddr, w: *Writer) Writer.Error!void {
        if (self != .default) try w.print(" {s}", .{@tagName(self)});
    }
};

pub const AddrSpace = enum(u24) {
    default,
    _,

    // 参见 llvm/lib/Target/X86/X86.h
    pub const x86 = struct {
        pub const gs: AddrSpace = @fromBackingInt(256);
        pub const fs: AddrSpace = @fromBackingInt(257);
        pub const ss: AddrSpace = @fromBackingInt(258);

        pub const ptr32_sptr: AddrSpace = @fromBackingInt(270);
        pub const ptr32_uptr: AddrSpace = @fromBackingInt(271);
        pub const ptr64: AddrSpace = @fromBackingInt(272);
    };
    pub const x86_64 = x86;

    // 参见 llvm/lib/Target/AVR/AVR.h
    pub const avr = struct {
        pub const data: AddrSpace = @fromBackingInt(0);
        pub const program: AddrSpace = @fromBackingInt(1);
        pub const program1: AddrSpace = @fromBackingInt(2);
        pub const program2: AddrSpace = @fromBackingInt(3);
        pub const program3: AddrSpace = @fromBackingInt(4);
        pub const program4: AddrSpace = @fromBackingInt(5);
        pub const program5: AddrSpace = @fromBackingInt(6);
    };

    // 参见 llvm/lib/Target/NVPTX/NVPTX.h
    pub const nvptx = struct {
        pub const generic: AddrSpace = @fromBackingInt(0);
        pub const global: AddrSpace = @fromBackingInt(1);
        pub const constant: AddrSpace = @fromBackingInt(2);
        pub const shared: AddrSpace = @fromBackingInt(3);
        pub const param: AddrSpace = @fromBackingInt(4);
        pub const local: AddrSpace = @fromBackingInt(5);
    };

    // 参见 llvm/lib/Target/AMDGPU/AMDGPU.h
    pub const amdgpu = struct {
        pub const flat: AddrSpace = @fromBackingInt(0);
        pub const global: AddrSpace = @fromBackingInt(1);
        pub const region: AddrSpace = @fromBackingInt(2);
        pub const local: AddrSpace = @fromBackingInt(3);
        pub const constant: AddrSpace = @fromBackingInt(4);
        pub const private: AddrSpace = @fromBackingInt(5);
        pub const constant_32bit: AddrSpace = @fromBackingInt(6);
        pub const buffer_fat_pointer: AddrSpace = @fromBackingInt(7);
        pub const buffer_resource: AddrSpace = @fromBackingInt(8);
        pub const buffer_strided_pointer: AddrSpace = @fromBackingInt(9);
        pub const param_d: AddrSpace = @fromBackingInt(6);
        pub const param_i: AddrSpace = @fromBackingInt(7);
        pub const constant_buffer_0: AddrSpace = @fromBackingInt(8);
        pub const constant_buffer_1: AddrSpace = @fromBackingInt(9);
        pub const constant_buffer_2: AddrSpace = @fromBackingInt(10);
        pub const constant_buffer_3: AddrSpace = @fromBackingInt(11);
        pub const constant_buffer_4: AddrSpace = @fromBackingInt(12);
        pub const constant_buffer_5: AddrSpace = @fromBackingInt(13);
        pub const constant_buffer_6: AddrSpace = @fromBackingInt(14);
        pub const constant_buffer_7: AddrSpace = @fromBackingInt(15);
        pub const constant_buffer_8: AddrSpace = @fromBackingInt(16);
        pub const constant_buffer_9: AddrSpace = @fromBackingInt(17);
        pub const constant_buffer_10: AddrSpace = @fromBackingInt(18);
        pub const constant_buffer_11: AddrSpace = @fromBackingInt(19);
        pub const constant_buffer_12: AddrSpace = @fromBackingInt(20);
        pub const constant_buffer_13: AddrSpace = @fromBackingInt(21);
        pub const constant_buffer_14: AddrSpace = @fromBackingInt(22);
        pub const constant_buffer_15: AddrSpace = @fromBackingInt(23);
        pub const streamout_register: AddrSpace = @fromBackingInt(128);
    };

    pub const spirv = struct {
        pub const function: AddrSpace = @fromBackingInt(0);
        pub const cross_workgroup: AddrSpace = @fromBackingInt(1);
        pub const uniform_constant: AddrSpace = @fromBackingInt(2);
        pub const workgroup: AddrSpace = @fromBackingInt(3);
        pub const generic: AddrSpace = @fromBackingInt(4);
        pub const device_only_intel: AddrSpace = @fromBackingInt(5);
        pub const host_only_intel: AddrSpace = @fromBackingInt(6);
        pub const input: AddrSpace = @fromBackingInt(7);
    };

    // 参见 llvm/include/llvm/CodeGen/WasmAddressSpaces.h。
    pub const wasm = struct {
        pub const default: AddrSpace = @fromBackingInt(0);
        pub const variable: AddrSpace = @fromBackingInt(1);
        pub const externref: AddrSpace = @fromBackingInt(10);
        pub const funcref: AddrSpace = @fromBackingInt(20);
    };

    pub fn format(addr_space: AddrSpace, w: *Writer) Writer.Error!void {
        return Prefixed.format(.{ .addr_space = addr_space, .prefix = "" }, w);
    }

    pub const Prefixed = struct {
        addr_space: AddrSpace,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            switch (p.addr_space) {
                .default => return,
                else => return w.print("{s}addrspace({d})", .{ p.prefix, p.addr_space }),
            }
        }
    };

    pub fn fmt(addr_space: AddrSpace, prefix: []const u8) Prefixed {
        return .{ .addr_space = addr_space, .prefix = prefix };
    }
};

pub const ExternallyInitialized = enum(u1) {
    default,
    externally_initialized,

    pub fn format(self: ExternallyInitialized, w: *Writer) Writer.Error!void {
        if (self != .default) try w.print(" {s}", .{@tagName(self)});
    }
};

pub const Alignment = enum(u6) {
    default = maxInt(u6),
    _,

    pub const Lazy = enum(u32) {
        /// 可放入 `u6` 的值已经是解析完成的 `Alignment` 值。
        /// 其他值是 `Builder.alignment_forward_references` 的索引,并以 `maxInt(u6)` 为偏移。
        _,

        pub fn wrap(a: Alignment) Lazy {
            return @fromBackingInt(@backingInt(a));
        }
        pub fn resolve(l: Lazy, b: *const Builder) Alignment {
            return switch (@backingInt(l)) {
                0...maxInt(u6) => |raw| @fromBackingInt(@intCast(raw)),
                else => |offset_index| b.alignment_forward_references.items[offset_index - maxInt(u6)],
            };
        }

        fn fromFwdRefIndex(index: usize) Lazy {
            return @fromBackingInt(@intCast(index + maxInt(u6)));
        }
        fn toFwdRefIndex(l: Lazy) usize {
            return @backingInt(l) - maxInt(u6);
        }
    };

    pub fn fromByteUnits(bytes: u64) Alignment {
        if (bytes == 0) return .default;
        assert(std.math.isPowerOfTwo(bytes));
        assert(bytes <= 1 << 32);
        return @fromBackingInt(@intCast(@ctz(bytes)));
    }

    pub fn toByteUnits(self: Alignment) ?u64 {
        return switch (self) {
            .default => null,
            else => @as(u64, 1) << @backingInt(self),
        };
    }

    /// 断言 `lhs` 和 `rhs` 均不是 `.default`。
    pub fn max(lhs: Alignment, rhs: Alignment) Alignment {
        assert(lhs != .default);
        assert(rhs != .default);
        return @fromBackingInt(@max(@backingInt(lhs), @backingInt(rhs)));
    }

    /// 断言 `lhs` 和 `rhs` 均不是 `.default`。
    pub fn order(lhs: Alignment, rhs: Alignment) std.math.Order {
        assert(lhs != .default);
        assert(rhs != .default);
        return std.math.order(@backingInt(lhs), @backingInt(rhs));
    }

    pub fn toLlvm(self: Alignment) u6 {
        return switch (self) {
            .default => 0,
            else => @backingInt(self) + 1,
        };
    }

    pub const Prefixed = struct {
        alignment: Alignment,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            const byte_units = p.alignment.toByteUnits() orelse return;
            return w.print("{s}align {d}", .{ p.prefix, byte_units });
        }
    };

    pub fn fmt(alignment: Alignment, prefix: []const u8) Prefixed {
        return .{ .alignment = alignment, .prefix = prefix };
    }
};

pub const CallConv = enum(u10) {
    ccc,

    fastcc = 8,
    coldcc,
    ghccc,

    webkit_jscc = 12,
    anyregcc,
    preserve_mostcc,
    preserve_allcc,
    swiftcc,
    cxx_fast_tlscc,
    tailcc,
    cfguard_checkcc,
    swifttailcc,
    preserve_nonecc,

    x86_stdcallcc = 64,
    x86_fastcallcc,
    arm_apcscc,
    arm_aapcscc,
    arm_aapcs_vfpcc,
    msp430_intrcc,
    x86_thiscallcc,
    ptx_kernel,
    ptx_device,

    spir_func = 75,
    spir_kernel,
    intel_ocl_bicc,
    x86_64_sysvcc,
    win64cc,
    x86_vectorcallcc,
    hhvmcc,
    hhvm_ccc,
    x86_intrcc,
    avr_intrcc,
    avr_signalcc,
    avr_builtincc,

    amdgpu_vs = 87,
    amdgpu_gs,
    amdgpu_ps,
    amdgpu_cs,
    amdgpu_kernel,
    x86_regcallcc,
    amdgpu_hs,
    msp430_builtincc,

    amdgpu_ls = 95,
    amdgpu_es,
    aarch64_vector_pcs,
    aarch64_sve_vector_pcs,

    amdgpu_gfx = 100,

    m68k_intrcc,

    aarch64_sme_preservemost_from_x0 = 102,
    aarch64_sme_preservemost_from_x2,

    m68k_rtdcc = 106,

    riscv_vectorcallcc = 110,

    _,

    pub const default = CallConv.ccc;

    pub fn format(self: CallConv, w: *Writer) Writer.Error!void {
        switch (self) {
            default => {},
            .fastcc,
            .coldcc,
            .ghccc,
            .webkit_jscc,
            .anyregcc,
            .preserve_mostcc,
            .preserve_allcc,
            .swiftcc,
            .cxx_fast_tlscc,
            .tailcc,
            .cfguard_checkcc,
            .swifttailcc,
            .preserve_nonecc,
            .x86_stdcallcc,
            .x86_fastcallcc,
            .arm_apcscc,
            .arm_aapcscc,
            .arm_aapcs_vfpcc,
            .msp430_intrcc,
            .x86_thiscallcc,
            .ptx_kernel,
            .ptx_device,
            .spir_func,
            .spir_kernel,
            .intel_ocl_bicc,
            .x86_64_sysvcc,
            .win64cc,
            .x86_vectorcallcc,
            .hhvmcc,
            .hhvm_ccc,
            .x86_intrcc,
            .avr_intrcc,
            .avr_signalcc,
            .avr_builtincc,
            .amdgpu_vs,
            .amdgpu_gs,
            .amdgpu_ps,
            .amdgpu_cs,
            .amdgpu_kernel,
            .x86_regcallcc,
            .amdgpu_hs,
            .msp430_builtincc,
            .amdgpu_ls,
            .amdgpu_es,
            .aarch64_vector_pcs,
            .aarch64_sve_vector_pcs,
            .amdgpu_gfx,
            .m68k_intrcc,
            .aarch64_sme_preservemost_from_x0,
            .aarch64_sme_preservemost_from_x2,
            .m68k_rtdcc,
            .riscv_vectorcallcc,
            => try w.print(" {s}", .{@tagName(self)}),
            _ => try w.print(" cc{d}", .{@backingInt(self)}),
        }
    }
};

pub const StrtabString = enum(u32) {
    none = maxInt(u31),
    empty,
    _,

    pub fn isAnon(self: StrtabString) bool {
        assert(self != .none);
        return self.toIndex() == null;
    }

    pub fn slice(self: StrtabString, builder: *const Builder) ?[]const u8 {
        const index = self.toIndex() orelse return null;
        const start = builder.strtab_string_indices.items[index];
        const end = builder.strtab_string_indices.items[index + 1];
        return builder.strtab_string_bytes.items[start..end];
    }

    const FormatData = struct {
        string: StrtabString,
        builder: *const Builder,
        quote_behavior: ?QuoteBehavior,
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        assert(data.string != .none);
        const string_slice = data.string.slice(data.builder) orelse
            return w.print("{d}", .{@backingInt(data.string)});
        const quote_behavior = data.quote_behavior orelse return w.writeAll(string_slice);
        return printEscapedString(string_slice, quote_behavior, w);
    }
    pub fn fmt(
        self: StrtabString,
        builder: *const Builder,
        quote_behavior: ?QuoteBehavior,
    ) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{
            .string = self,
            .builder = builder,
            .quote_behavior = quote_behavior,
        } };
    }

    fn fromIndex(index: ?usize) StrtabString {
        return @fromBackingInt(@intCast((index orelse return .none) + @backingInt(StrtabString.empty)));
    }

    fn toIndex(self: StrtabString) ?usize {
        return std.math.sub(u32, @backingInt(self), @backingInt(StrtabString.empty)) catch null;
    }

    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: Adapter, key: []const u8) u32 {
            return @truncate(std.hash.Wyhash.hash(0, key));
        }
        pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {
            return std.mem.eql(u8, lhs_key, StrtabString.fromIndex(rhs_index).slice(ctx.builder).?);
        }
    };
};

pub fn strtabString(self: *Builder, bytes: []const u8) Allocator.Error!StrtabString {
    try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);
    try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1);

    const gop = self.strtab_string_map.getOrPutAssumeCapacityAdapted(bytes, StrtabString.Adapter{ .builder = self });
    if (!gop.found_existing) {
        self.strtab_string_bytes.appendSliceAssumeCapacity(bytes);
        self.strtab_string_indices.appendAssumeCapacity(@intCast(self.strtab_string_bytes.items.len));
    }
    return StrtabString.fromIndex(gop.index);
}

pub fn strtabStringIfExists(self: *const Builder, bytes: []const u8) ?StrtabString {
    return StrtabString.fromIndex(
        self.strtab_string_map.getIndexAdapted(bytes, StrtabString.Adapter{ .builder = self }) orelse return null,
    );
}

pub fn strtabStringFmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!StrtabString {
    try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1);
    try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args)));
    try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1);
    return self.strtabStringFmtAssumeCapacity(fmt_str, fmt_args);
}

pub fn strtabStringFmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) StrtabString {
    self.strtab_string_bytes.printAssumeCapacity(fmt_str, fmt_args);
    return self.trailingStrtabStringAssumeCapacity();
}

pub fn trailingStrtabString(self: *Builder) Allocator.Error!StrtabString {
    try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1);
    return self.trailingStrtabStringAssumeCapacity();
}

pub fn trailingStrtabStringAssumeCapacity(self: *Builder) StrtabString {
    const start = self.strtab_string_indices.last().?;
    const bytes: []const u8 = self.strtab_string_bytes.items[start..];
    const gop = self.strtab_string_map.getOrPutAssumeCapacityAdapted(bytes, StrtabString.Adapter{ .builder = self });
    if (gop.found_existing) {
        self.strtab_string_bytes.shrinkRetainingCapacity(start);
    } else {
        self.strtab_string_indices.appendAssumeCapacity(@intCast(self.strtab_string_bytes.items.len));
    }
    return StrtabString.fromIndex(gop.index);
}

pub const Global = struct {
    linkage: Linkage = .external,
    preemption: Preemption = .dso_preemptable,
    visibility: Visibility = .default,
    dll_storage_class: DllStorageClass = .default,
    unnamed_addr: UnnamedAddr = .default,
    addr_space: AddrSpace = .default,
    externally_initialized: ExternallyInitialized = .default,
    type: Type,
    partition: String = .none,
    dbg: Metadata.Optional = .none,
    kind: union(enum) {
        alias: Alias.Index,
        variable: Variable.Index,
        function: Function.Index,
        replaced: Global.Index,
    },

    pub const Index = enum(u32) {
        none = maxInt(u32),
        _,

        pub fn unwrap(orig_index: Index, builder: *const Builder) Index {
            var cur = orig_index;
            while (true) {
                switch (builder.globals.values()[@backingInt(cur)].kind) {
                    .replaced => |replacement| cur = replacement,
                    else => return cur,
                }
            }
        }

        pub fn eql(self: Index, other: Index, builder: *const Builder) bool {
            return self.unwrap(builder) == other.unwrap(builder);
        }

        pub fn ptr(self: Index, builder: *Builder) *Global {
            return &builder.globals.values()[@backingInt(self.unwrap(builder))];
        }

        pub fn ptrConst(self: Index, builder: *const Builder) *const Global {
            return &builder.globals.values()[@backingInt(self.unwrap(builder))];
        }

        pub fn name(self: Index, builder: *const Builder) StrtabString {
            return builder.globals.keys()[@backingInt(self.unwrap(builder))];
        }

        pub fn strtab(self: Index, builder: *const Builder) struct {
            offset: u32,
            size: u32,
        } {
            const name_index = self.name(builder).toIndex() orelse return .{
                .offset = 0,
                .size = 0,
            };

            return .{
                .offset = builder.strtab_string_indices.items[name_index],
                .size = builder.strtab_string_indices.items[name_index + 1] -
                    builder.strtab_string_indices.items[name_index],
            };
        }

        pub fn typeOf(self: Index, builder: *const Builder) Type {
            return self.ptrConst(builder).type;
        }

        pub fn toConst(global: Index) Constant {
            return @fromBackingInt(@backingInt(Constant.first_global) + @backingInt(global));
        }

        pub fn toValue(global: Index) Value {
            return global.toConst().toValue();
        }

        pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void {
            self.ptr(builder).linkage = linkage;
            self.updateDsoLocal(builder);
        }

        pub fn setVisibility(self: Index, visibility: Visibility, builder: *Builder) void {
            self.ptr(builder).visibility = visibility;
            self.updateDsoLocal(builder);
        }

        pub fn setDllStorageClass(self: Index, class: DllStorageClass, builder: *Builder) void {
            self.ptr(builder).dll_storage_class = class;
        }

        pub fn setUnnamedAddr(self: Index, unnamed_addr: UnnamedAddr, builder: *Builder) void {
            self.ptr(builder).unnamed_addr = unnamed_addr;
        }

        pub fn setDebugMetadata(self: Index, dbg: Metadata, builder: *Builder) void {
            self.ptr(builder).dbg = dbg.toOptional();
        }

        pub fn getDebugMetadata(self: Index, builder: *const Builder) Metadata.Optional {
            return self.ptrConst(builder).dbg;
        }

        const FormatData = struct {
            global: Index,
            builder: *const Builder,
        };
        fn format(data: FormatData, w: *Writer) Writer.Error!void {
            try w.print("@{f}", .{
                data.global.unwrap(data.builder).name(data.builder).fmt(data.builder, .quote_unless_valid_identifier),
            });
        }
        pub fn fmt(self: Index, builder: *const Builder) std.fmt.Alt(FormatData, format) {
            return .{ .data = .{ .global = self, .builder = builder } };
        }

        pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void {
            try builder.ensureUnusedGlobalCapacity(new_name);
            self.renameAssumeCapacity(new_name, builder);
        }

        pub fn takeName(self: Index, other: Index, builder: *Builder) Allocator.Error!void {
            try builder.ensureUnusedGlobalCapacity(.empty);
            self.takeNameAssumeCapacity(other, builder);
        }

        pub fn replace(self: Index, other: Index, builder: *Builder) Allocator.Error!void {
            try builder.ensureUnusedGlobalCapacity(.empty);
            self.replaceAssumeCapacity(other, builder);
        }

        pub fn delete(self: Index, builder: *Builder) void {
            self.ptr(builder).kind = .{ .replaced = .none };
        }

        /// 用新的 `Function` 替换此 `Global` 当前的内容。类似于 `Builder.addFunction`,但复用同一个 `Global`。
        ///
        pub fn toNewFunction(global: Index, builder: *Builder) Allocator.Error!Function.Index {
            try builder.functions.ensureUnusedCapacity(builder.gpa, 1);
            errdefer comptime unreachable;
            const function: Function.Index = @fromBackingInt(@intCast(builder.functions.items.len));
            builder.functions.appendAssumeCapacity(.{
                .global = global,
                .strip = undefined,
            });
            global.ptr(builder).kind = .{ .function = function };
            return function;
        }

        /// 使用新的 `Variable` 替换此 `Global` 当前包含的内容。
        /// 类似 `Builder.addVariable`,但复用同一个 `Global`。
        pub fn toNewVariable(global: Index, builder: *Builder) Allocator.Error!Variable.Index {
            try builder.variables.ensureUnusedCapacity(builder.gpa, 1);
            errdefer comptime unreachable;
            const variable: Variable.Index = @fromBackingInt(@intCast(builder.variables.items.len));
            builder.variables.appendAssumeCapacity(.{ .global = global });
            global.ptr(builder).kind = .{ .variable = variable };
            return variable;
        }

        /// 用新的 `Alias` 替换此 `Global` 当前的内容。类似于 `Builder.addAlias`,但复用同一个 `Global`。
        ///
        pub fn toNewAlias(global: Index, builder: *Builder) Allocator.Error!Alias.Index {
            try builder.aliases.ensureUnusedCapacity(builder.gpa, 1);
            errdefer comptime unreachable;
            const alias: Alias.Index = @fromBackingInt(@intCast(builder.aliases.items.len));
            builder.aliass.appendAssumeCapacity(.{ .global = global, .aliasee = .none });
            global.ptr(builder).kind = .{ .alias = alias };
            return alias;
        }

        fn updateDsoLocal(self: Index, builder: *Builder) void {
            const self_ptr = self.ptr(builder);
            switch (self_ptr.linkage) {
                .private, .internal => {
                    self_ptr.visibility = .default;
                    self_ptr.dll_storage_class = .default;
                    self_ptr.preemption = .implicit_dso_local;
                },
                .extern_weak => if (self_ptr.preemption == .implicit_dso_local) {
                    self_ptr.preemption = .dso_local;
                },
                else => switch (self_ptr.visibility) {
                    .default => if (self_ptr.preemption == .implicit_dso_local) {
                        self_ptr.preemption = .dso_local;
                    },
                    else => self_ptr.preemption = .implicit_dso_local,
                },
            }
        }

        fn renameAssumeCapacity(self: Index, new_name: StrtabString, builder: *Builder) void {
            const old_name = self.name(builder);
            if (new_name == old_name) return;
            const index = @backingInt(self.unwrap(builder));
            builder.globals.setKey(index, new_name);
            if (!old_name.isAnon()) return;
            builder.next_unnamed_global = @fromBackingInt(@backingInt(builder.next_unnamed_global) - 1);
            if (builder.next_unnamed_global == old_name) return;
            builder.getGlobal(builder.next_unnamed_global).?.renameAssumeCapacity(old_name, builder);
        }

        fn takeNameAssumeCapacity(self: Index, other: Index, builder: *Builder) void {
            const other_name = other.name(builder);
            other.renameAssumeCapacity(.empty, builder);
            self.renameAssumeCapacity(other_name, builder);
        }

        fn replaceAssumeCapacity(self: Index, other: Index, builder: *Builder) void {
            if (self.eql(other, builder)) return;
            builder.next_replaced_global = @fromBackingInt(@backingInt(builder.next_replaced_global) - 1);
            self.renameAssumeCapacity(builder.next_replaced_global, builder);
            self.ptr(builder).kind = .{ .replaced = other.unwrap(builder) };
        }
    };
};

pub const Alias = struct {
    global: Global.Index,
    thread_local: ThreadLocal = .default,
    aliasee: Constant = .no_init,

    pub const Index = enum(u32) {
        none = maxInt(u32),
        _,

        pub fn ptr(self: Index, builder: *Builder) *Alias {
            return &builder.aliases.items[@backingInt(self)];
        }

        pub fn ptrConst(self: Index, builder: *const Builder) *const Alias {
            return &builder.aliases.items[@backingInt(self)];
        }

        pub fn name(self: Index, builder: *const Builder) StrtabString {
            return self.ptrConst(builder).global.name(builder);
        }

        pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void {
            return self.ptrConst(builder).global.rename(new_name, builder);
        }

        pub fn typeOf(self: Index, builder: *const Builder) Type {
            return self.ptrConst(builder).global.typeOf(builder);
        }

        pub fn toConst(self: Index, builder: *const Builder) Constant {
            return self.ptrConst(builder).global.toConst();
        }

        pub fn toValue(self: Index, builder: *const Builder) Value {
            return self.toConst(builder).toValue();
        }

        pub fn getAliasee(self: Index, builder: *const Builder) Global.Index {
            const aliasee = self.ptrConst(builder).aliasee.getBase(builder);
            assert(aliasee != .none);
            return aliasee;
        }

        pub fn setAliasee(self: Index, aliasee: Constant, builder: *Builder) void {
            self.ptr(builder).aliasee = aliasee;
        }
    };
};

pub const Variable = struct {
    global: Global.Index,
    thread_local: ThreadLocal = .default,
    mutability: Mutability = .global,
    init: Constant = .no_init,
    section: String = .none,
    alignment: Alignment = .default,

    pub const Index = enum(u32) {
        none = maxInt(u32),
        _,

        pub fn ptr(self: Index, builder: *Builder) *Variable {
            return &builder.variables.items[@backingInt(self)];
        }

        pub fn ptrConst(self: Index, builder: *const Builder) *const Variable {
            return &builder.variables.items[@backingInt(self)];
        }

        pub fn name(self: Index, builder: *const Builder) StrtabString {
            return self.ptrConst(builder).global.name(builder);
        }

        pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void {
            return self.ptrConst(builder).global.rename(new_name, builder);
        }

        pub fn typeOf(self: Index, builder: *const Builder) Type {
            return self.ptrConst(builder).global.typeOf(builder);
        }

        pub fn toConst(self: Index, builder: *const Builder) Constant {
            return self.ptrConst(builder).global.toConst();
        }

        pub fn toValue(self: Index, builder: *const Builder) Value {
            return self.toConst(builder).toValue();
        }

        pub fn setThreadLocal(self: Index, thread_local: ThreadLocal, builder: *Builder) void {
            self.ptr(builder).thread_local = thread_local;
        }

        pub fn setMutability(self: Index, mutability: Mutability, builder: *Builder) void {
            self.ptr(builder).mutability = mutability;
        }

        pub fn setInitializer(
            self: Index,
            initializer: Constant,
            builder: *Builder,
        ) Allocator.Error!void {
            if (initializer != .no_init) {
                const variable = self.ptrConst(builder);
                const global = variable.global.ptr(builder);
                const initializer_type = initializer.typeOf(builder);
                global.type = initializer_type;
            }
            self.ptr(builder).init = initializer;
        }

        pub fn setSection(self: Index, section: String, builder: *Builder) void {
            self.ptr(builder).section = section;
        }

        pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void {
            self.ptr(builder).alignment = alignment;
        }

        pub fn getAlignment(self: Index, builder: *Builder) Alignment {
            return self.ptr(builder).alignment;
        }

        pub fn setGlobalVariableExpression(self: Index, expression: Metadata, builder: *Builder) void {
            self.ptrConst(builder).global.setDebugMetadata(expression, builder);
        }

        pub fn getGlobalVariableExpression(self: Index, builder: *Builder) Metadata.Optional {
            return self.ptrConst(builder).global.getDebugMetadata(builder);
        }
    };
};

pub const Intrinsic = enum {
    // 可变参数处理
    va_start,
    va_end,
    va_copy,

    // 代码生成器
    returnaddress,
    addressofreturnaddress,
    sponentry,
    frameaddress,
    prefetch,
    @"thread.pointer",

    // 标准 C/C++ 库
    abs,
    smax,
    smin,
    umax,
    umin,
    scmp,
    ucmp,
    memcpy,
    @"memcpy.inline",
    memmove,
    memset,
    @"memset.inline",
    sqrt,
    powi,
    sin,
    cos,
    tan,
    asin,
    acos,
    atan,
    atan2,
    sinh,
    cosh,
    tanh,
    sincos,
    sincospi,
    modf,
    pow,
    exp,
    exp2,
    exp10,
    ldexp,
    frexp,
    log,
    log10,
    log2,
    fma,
    fabs,
    minnum,
    maxnum,
    minimum,
    maximum,
    minimumnum,
    maximumnum,
    copysign,
    floor,
    ceil,
    trunc,
    rint,
    nearbyint,
    round,
    roundeven,
    lround,
    llround,
    lrint,
    llrint,

    // 位操作
    bitreverse,
    bswap,
    ctpop,
    ctlz,
    cttz,
    fshl,
    fshr,
    clmul,

    // 带溢出的算术运算
    @"sadd.with.overflow",
    @"uadd.with.overflow",
    @"ssub.with.overflow",
    @"usub.with.overflow",
    @"smul.with.overflow",
    @"umul.with.overflow",

    // 饱和算术
    @"sadd.sat",
    @"uadd.sat",
    @"ssub.sat",
    @"usub.sat",
    @"sshl.sat",
    @"ushl.sat",

    // 定点算术
    @"smul.fix",
    @"umul.fix",
    @"smul.fix.sat",
    @"umul.fix.sat",
    @"sdiv.fix",
    @"udiv.fix",
    @"sdiv.fix.sat",
    @"udiv.fix.sat",

    // 专用算术
    canonicalize,
    fmuladd,

    // 向量归约
    @"vector.reduce.add",
    @"vector.reduce.fadd",
    @"vector.reduce.mul",
    @"vector.reduce.fmul",
    @"vector.reduce.and",
    @"vector.reduce.or",
    @"vector.reduce.xor",
    @"vector.reduce.smax",
    @"vector.reduce.smin",
    @"vector.reduce.umax",
    @"vector.reduce.umin",
    @"vector.reduce.fmax",
    @"vector.reduce.fmin",
    @"vector.reduce.fmaximum",
    @"vector.reduce.fminimum",
    @"vector.insert",
    @"vector.extract",

    // 浮点测试
    @"is.fpclass",

    // 通用
    @"var.annotation",
    @"ptr.annotation",
    annotation,
    @"codeview.annotation",
    trap,
    debugtrap,
    ubsantrap,
    stackprotector,
    stackguard,
    objectsize,
    expect,
    @"expect.with.probability",
    assume,
    @"ssa.copy",
    @"type.test",
    @"type.checked.load",
    @"type.checked.load.relative",
    @"arithmetic.fence",
    donothing,
    @"load.relative",
    sideeffect,
    @"is.constant",
    ptrmask,
    @"threadlocal.address",
    vscale,

    // 调试
    @"dbg.declare",
    @"dbg.value",

    // AMDGPU
    @"amdgcn.workitem.id.x",
    @"amdgcn.workitem.id.y",
    @"amdgcn.workitem.id.z",
    @"amdgcn.workgroup.id.x",
    @"amdgcn.workgroup.id.y",
    @"amdgcn.workgroup.id.z",
    @"amdgcn.dispatch.ptr",

    // NVPTX
    @"nvvm.read.ptx.sreg.tid.x",
    @"nvvm.read.ptx.sreg.tid.y",
    @"nvvm.read.ptx.sreg.tid.z",
    @"nvvm.read.ptx.sreg.ntid.x",
    @"nvvm.read.ptx.sreg.ntid.y",
    @"nvvm.read.ptx.sreg.ntid.z",
    @"nvvm.read.ptx.sreg.ctaid.x",
    @"nvvm.read.ptx.sreg.ctaid.y",
    @"nvvm.read.ptx.sreg.ctaid.z",

    // WebAssembly
    @"wasm.memory.size",
    @"wasm.memory.grow",

    const Signature = struct {
        ret_len: u8,
        params: []const Parameter,
        attrs: []const Attribute = &.{},

        const Parameter = struct {
            kind: Kind,
            attrs: []const Attribute = &.{},

            const Kind = union(enum) {
                type: Type,
                overloaded,
                matches: u8,
                matches_scalar: u8,
                matches_changed_scalar: struct {
                    index: u8,
                    scalar: Type,
                },
            };
        };
    };

    const signatures = std.enums.EnumArray(Intrinsic, Signature).init(.{
        .va_start = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
        },
        .va_end = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
        },
        .va_copy = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
        },

        .returnaddress = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .addressofreturnaddress = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .sponentry = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .frameaddress = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .prefetch = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{ .nocapture, .readonly } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.readwrite) } },
        },
        .@"thread.pointer" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },

        .abs = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .smax = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .smin = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .umax = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .umin = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .scmp = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 1 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .ucmp = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 1 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .memcpy = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{ .@"noalias", .nocapture, .writeonly } },
                .{ .kind = .overloaded, .attrs = &.{ .@"noalias", .nocapture, .readonly } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nounwind, .willreturn, .{ .memory = .{ .argmem = .readwrite } } },
        },
        .@"memcpy.inline" = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{ .@"noalias", .nocapture, .writeonly } },
                .{ .kind = .overloaded, .attrs = &.{ .@"noalias", .nocapture, .readonly } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nounwind, .willreturn, .{ .memory = .{ .argmem = .readwrite } } },
        },
        .memmove = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{ .nocapture, .writeonly } },
                .{ .kind = .overloaded, .attrs = &.{ .nocapture, .readonly } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nounwind, .willreturn, .{ .memory = .{ .argmem = .readwrite } } },
        },
        .memset = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{ .nocapture, .writeonly } },
                .{ .kind = .{ .type = .i8 } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nounwind, .willreturn, .{ .memory = .{ .argmem = .write } } },
        },
        .@"memset.inline" = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{ .nocapture, .writeonly } },
                .{ .kind = .{ .type = .i8 } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nounwind, .willreturn, .{ .memory = .{ .argmem = .write } } },
        },
        .sqrt = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .powi = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .sin = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .cos = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .tan = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .asin = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .acos = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .atan = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .atan2 = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .sinh = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .cosh = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .tanh = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .sincos = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .sincospi = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .modf = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .pow = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .exp = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .exp2 = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .exp10 = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .ldexp = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .frexp = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .log = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .log10 = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .log2 = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .fma = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .fabs = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .minnum = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .maxnum = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .minimum = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .maximum = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .minimumnum = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .maximumnum = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .copysign = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .floor = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .ceil = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .trunc = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .rint = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .nearbyint = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .round = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .roundeven = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .lround = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .llround = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .lrint = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .llrint = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .bitreverse = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .bswap = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .ctpop = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .ctlz = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .cttz = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .fshl = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .fshr = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .clmul = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"sadd.with.overflow" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 0, .scalar = .i1 } } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"uadd.with.overflow" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 0, .scalar = .i1 } } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"ssub.with.overflow" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 0, .scalar = .i1 } } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"usub.with.overflow" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 0, .scalar = .i1 } } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"smul.with.overflow" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 0, .scalar = .i1 } } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"umul.with.overflow" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 0, .scalar = .i1 } } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"sadd.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"uadd.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"ssub.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"usub.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"sshl.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"ushl.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"smul.fix" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"umul.fix" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"smul.fix.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"umul.fix.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"sdiv.fix" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"udiv.fix" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"sdiv.fix.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"udiv.fix.sat" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },

        .canonicalize = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .fmuladd = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"vector.reduce.add" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.fadd" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 2 } },
                .{ .kind = .{ .matches_scalar = 2 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.mul" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.fmul" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 2 } },
                .{ .kind = .{ .matches_scalar = 2 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.and" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.or" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.xor" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.smax" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.smin" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.umax" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.umin" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.fmax" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.fmin" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.fmaximum" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.reduce.fminimum" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_scalar = 1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.insert" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i64 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"vector.extract" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i64 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"is.fpclass" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .matches_changed_scalar = .{ .index = 1, .scalar = .i1 } } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i32 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nocreateundeforpoison, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"var.annotation" = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 1 } },
                .{ .kind = .{ .type = .i32 } },
                .{ .kind = .{ .matches = 1 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .inaccessiblemem = .readwrite } } },
        },
        .@"ptr.annotation" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 2 } },
                .{ .kind = .{ .type = .i32 } },
                .{ .kind = .{ .matches = 2 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .inaccessiblemem = .readwrite } } },
        },
        .annotation = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 2 } },
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .inaccessiblemem = .readwrite } } },
        },
        .@"codeview.annotation" = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .{ .type = .metadata } },
            },
            .attrs = &.{ .nocallback, .noduplicate, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .inaccessiblemem = .readwrite } } },
        },
        .trap = .{
            .ret_len = 0,
            .params = &.{},
            .attrs = &.{ .cold, .noreturn, .nounwind, .{ .memory = .{ .inaccessiblemem = .write } } },
        },
        .debugtrap = .{
            .ret_len = 0,
            .params = &.{},
            .attrs = &.{.nounwind},
        },
        .ubsantrap = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .{ .type = .i8 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .cold, .noreturn, .nounwind },
        },
        .stackprotector = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .ptr } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
        },
        .stackguard = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
        },
        .objectsize = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .expect = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"expect.with.probability" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .{ .type = .double }, .attrs = &.{.immarg} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .assume = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .{ .type = .i1 }, .attrs = &.{.noundef} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .inaccessiblemem = .write } } },
        },
        .@"ssa.copy" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 }, .attrs = &.{.returned} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"type.test" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i1 } },
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .metadata } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"type.checked.load" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .i1 } },
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .i32 } },
                .{ .kind = .{ .type = .metadata } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"type.checked.load.relative" = .{
            .ret_len = 2,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .i1 } },
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .i32 } },
                .{ .kind = .{ .type = .metadata } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"arithmetic.fence" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .donothing = .{
            .ret_len = 0,
            .params = &.{},
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"load.relative" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .{ .type = .ptr } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .argmem = .read } } },
        },
        .sideeffect = .{
            .ret_len = 0,
            .params = &.{},
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .{ .inaccessiblemem = .readwrite } } },
        },
        .@"is.constant" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i1 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .convergent, .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .ptrmask = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .matches = 0 } },
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"threadlocal.address" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded, .attrs = &.{.nonnull} },
                .{ .kind = .{ .matches = 0 }, .attrs = &.{.nonnull} },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .vscale = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"dbg.declare" = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .{ .type = .metadata } },
                .{ .kind = .{ .type = .metadata } },
                .{ .kind = .{ .type = .metadata } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"dbg.value" = .{
            .ret_len = 0,
            .params = &.{
                .{ .kind = .{ .type = .metadata } },
                .{ .kind = .{ .type = .metadata } },
                .{ .kind = .{ .type = .metadata } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"amdgcn.workitem.id.x" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"amdgcn.workitem.id.y" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"amdgcn.workitem.id.z" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"amdgcn.workgroup.id.x" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"amdgcn.workgroup.id.y" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"amdgcn.workgroup.id.z" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"amdgcn.dispatch.ptr" = .{
            .ret_len = 1,
            .params = &.{
                .{
                    .kind = .{ .type = Type.ptr_amdgpu_constant },
                    .attrs = &.{.{ .@"align" = .wrap(.fromByteUnits(4)) }},
                },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .speculatable, .willreturn, .{ .memory = .all(.none) } },
        },

        .@"nvvm.read.ptx.sreg.tid.x" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },
        .@"nvvm.read.ptx.sreg.tid.y" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },
        .@"nvvm.read.ptx.sreg.tid.z" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },

        .@"nvvm.read.ptx.sreg.ntid.x" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },
        .@"nvvm.read.ptx.sreg.ntid.y" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },
        .@"nvvm.read.ptx.sreg.ntid.z" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },

        .@"nvvm.read.ptx.sreg.ctaid.x" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },
        .@"nvvm.read.ptx.sreg.ctaid.y" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },
        .@"nvvm.read.ptx.sreg.ctaid.z" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nounwind, .readnone },
        },

        .@"wasm.memory.size" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i32 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn, .{ .memory = .all(.none) } },
        },
        .@"wasm.memory.grow" = .{
            .ret_len = 1,
            .params = &.{
                .{ .kind = .overloaded },
                .{ .kind = .{ .type = .i32 } },
                .{ .kind = .{ .matches = 0 } },
            },
            .attrs = &.{ .nocallback, .nofree, .nosync, .nounwind, .willreturn },
        },
    });
};

pub const Function = struct {
    global: Global.Index,
    call_conv: CallConv = CallConv.default,
    attributes: FunctionAttributes = .none,
    section: String = .none,
    alignment: Alignment = .default,
    blocks: []const Block = &.{},
    instructions: std.MultiArrayList(Instruction) = .empty,
    names: [*]const String = &[0]String{},
    value_indices: [*]const u32 = &[0]u32{},
    strip: bool,
    debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .empty,
    debug_values: []const Instruction.Index = &.{},
    extra: []const u32 = &.{},

    pub const Index = enum(u32) {
        none = maxInt(u32),
        _,

        pub fn ptr(self: Index, builder: *Builder) *Function {
            return &builder.functions.items[@backingInt(self)];
        }

        pub fn ptrConst(self: Index, builder: *const Builder) *const Function {
            return &builder.functions.items[@backingInt(self)];
        }

        pub fn name(self: Index, builder: *const Builder) StrtabString {
            return self.ptrConst(builder).global.name(builder);
        }

        pub fn rename(self: Index, new_name: StrtabString, builder: *Builder) Allocator.Error!void {
            return self.ptrConst(builder).global.rename(new_name, builder);
        }

        pub fn typeOf(self: Index, builder: *const Builder) Type {
            return self.ptrConst(builder).global.typeOf(builder);
        }

        pub fn toConst(self: Index, builder: *const Builder) Constant {
            return self.ptrConst(builder).global.toConst();
        }

        pub fn toValue(self: Index, builder: *const Builder) Value {
            return self.toConst(builder).toValue();
        }

        pub fn setLinkage(self: Index, linkage: Linkage, builder: *Builder) void {
            return self.ptrConst(builder).global.setLinkage(linkage, builder);
        }

        pub fn setUnnamedAddr(self: Index, unnamed_addr: UnnamedAddr, builder: *Builder) void {
            return self.ptrConst(builder).global.setUnnamedAddr(unnamed_addr, builder);
        }

        pub fn setCallConv(self: Index, call_conv: CallConv, builder: *Builder) void {
            self.ptr(builder).call_conv = call_conv;
        }

        pub fn setAttributes(
            self: Index,
            new_function_attributes: FunctionAttributes,
            builder: *Builder,
        ) void {
            self.ptr(builder).attributes = new_function_attributes;
        }

        pub fn getAttributes(self: Index, builder: *Builder) FunctionAttributes {
            return self.ptr(builder).attributes;
        }

        pub fn setSection(self: Index, section: String, builder: *Builder) void {
            self.ptr(builder).section = section;
        }

        pub fn setAlignment(self: Index, alignment: Alignment, builder: *Builder) void {
            self.ptr(builder).alignment = alignment;
        }

        pub fn setSubprogram(self: Index, subprogram: Metadata, builder: *Builder) void {
            self.ptrConst(builder).global.setDebugMetadata(subprogram, builder);
        }

        pub fn getSubprogram(self: Index, builder: *const Builder) Metadata.Optional {
            return self.ptrConst(builder).global.getDebugMetadata(builder);
        }
    };

    pub const Block = struct {
        instruction: Instruction.Index,

        pub const Index = WipFunction.Block.Index;
    };

    pub const Instruction = struct {
        tag: Tag,
        data: u32,

        pub const Tag = enum(u8) {
            add,
            @"add nsw",
            @"add nuw",
            @"add nuw nsw",
            addrspacecast,
            alloca,
            @"alloca inalloca",
            @"and",
            arg,
            ashr,
            @"ashr exact",
            atomicrmw,
            bitcast,
            block,
            br,
            br_cond,
            call,
            @"call fast",
            cmpxchg,
            @"cmpxchg weak",
            extractelement,
            extractvalue,
            fadd,
            @"fadd fast",
            @"fcmp false",
            @"fcmp fast false",
            @"fcmp fast oeq",
            @"fcmp fast oge",
            @"fcmp fast ogt",
            @"fcmp fast ole",
            @"fcmp fast olt",
            @"fcmp fast one",
            @"fcmp fast ord",
            @"fcmp fast true",
            @"fcmp fast ueq",
            @"fcmp fast uge",
            @"fcmp fast ugt",
            @"fcmp fast ule",
            @"fcmp fast ult",
            @"fcmp fast une",
            @"fcmp fast uno",
            @"fcmp oeq",
            @"fcmp oge",
            @"fcmp ogt",
            @"fcmp ole",
            @"fcmp olt",
            @"fcmp one",
            @"fcmp ord",
            @"fcmp true",
            @"fcmp ueq",
            @"fcmp uge",
            @"fcmp ugt",
            @"fcmp ule",
            @"fcmp ult",
            @"fcmp une",
            @"fcmp uno",
            fdiv,
            @"fdiv fast",
            fence,
            fmul,
            @"fmul fast",
            fneg,
            @"fneg fast",
            fpext,
            fptosi,
            fptoui,
            fptrunc,
            frem,
            @"frem fast",
            fsub,
            @"fsub fast",
            getelementptr,
            @"getelementptr inbounds",
            @"icmp eq",
            @"icmp ne",
            @"icmp sge",
            @"icmp sgt",
            @"icmp sle",
            @"icmp slt",
            @"icmp uge",
            @"icmp ugt",
            @"icmp ule",
            @"icmp ult",
            indirectbr,
            insertelement,
            insertvalue,
            inttoptr,
            load,
            @"load atomic",
            lshr,
            @"lshr exact",
            mul,
            @"mul nsw",
            @"mul nuw",
            @"mul nuw nsw",
            @"musttail call",
            @"musttail call fast",
            @"notail call",
            @"notail call fast",
            @"or",
            phi,
            @"phi fast",
            ptrtoint,
            ret,
            @"ret void",
            sdiv,
            @"sdiv exact",
            select,
            @"select fast",
            sext,
            shl,
            @"shl nsw",
            @"shl nuw",
            @"shl nuw nsw",
            shufflevector,
            sitofp,
            srem,
            store,
            @"store atomic",
            sub,
            @"sub nsw",
            @"sub nuw",
            @"sub nuw nsw",
            @"switch",
            @"tail call",
            @"tail call fast",
            trunc,
            @"trunc nuw",
            @"trunc nsw",
            @"trunc nuw nsw",
            udiv,
            @"udiv exact",
            urem,
            uitofp,
            @"unreachable",
            va_arg,
            xor,
            zext,

            pub fn toBinaryOpcode(self: Tag) BinaryOpcode {
                return switch (self) {
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .@"add nuw nsw",
                    .fadd,
                    .@"fadd fast",
                    => .add,
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .@"sub nuw nsw",
                    .fsub,
                    .@"fsub fast",
                    => .sub,
                    .sdiv,
                    .@"sdiv exact",
                    .fdiv,
                    .@"fdiv fast",
                    => .sdiv,
                    .fmul,
                    .@"fmul fast",
                    .mul,
                    .@"mul nsw",
                    .@"mul nuw",
                    .@"mul nuw nsw",
                    => .mul,
                    .srem,
                    .frem,
                    .@"frem fast",
                    => .srem,
                    .udiv,
                    .@"udiv exact",
                    => .udiv,
                    .shl,
                    .@"shl nsw",
                    .@"shl nuw",
                    .@"shl nuw nsw",
                    => .shl,
                    .lshr,
                    .@"lshr exact",
                    => .lshr,
                    .ashr,
                    .@"ashr exact",
                    => .ashr,
                    .@"and" => .@"and",
                    .@"or" => .@"or",
                    .xor => .xor,
                    .urem => .urem,
                    else => unreachable,
                };
            }

            /// 不接受 `.@"trunc nuw"`、`.@"trunc nsw"` 或 `.@"trunc nuw nsw"`,
            /// 因为它们没有独立的 `CastOpcode` 值,而是在位码中
            /// 通过普通 `trunc` 操作上的标志进行编码。
            fn toCastOpcode(self: Tag) CastOpcode {
                return switch (self) {
                    .trunc => .trunc,
                    .zext => .zext,
                    .sext => .sext,
                    .fptoui => .fptoui,
                    .fptosi => .fptosi,
                    .uitofp => .uitofp,
                    .sitofp => .sitofp,
                    .fptrunc => .fptrunc,
                    .fpext => .fpext,
                    .ptrtoint => .ptrtoint,
                    .inttoptr => .inttoptr,
                    .bitcast => .bitcast,
                    .addrspacecast => .addrspacecast,
                    else => unreachable,
                };
            }

            pub fn toCmpPredicate(self: Tag) CmpPredicate {
                return switch (self) {
                    .@"fcmp false",
                    .@"fcmp fast false",
                    => .fcmp_false,
                    .@"fcmp oeq",
                    .@"fcmp fast oeq",
                    => .fcmp_oeq,
                    .@"fcmp oge",
                    .@"fcmp fast oge",
                    => .fcmp_oge,
                    .@"fcmp ogt",
                    .@"fcmp fast ogt",
                    => .fcmp_ogt,
                    .@"fcmp ole",
                    .@"fcmp fast ole",
                    => .fcmp_ole,
                    .@"fcmp olt",
                    .@"fcmp fast olt",
                    => .fcmp_olt,
                    .@"fcmp one",
                    .@"fcmp fast one",
                    => .fcmp_one,
                    .@"fcmp ord",
                    .@"fcmp fast ord",
                    => .fcmp_ord,
                    .@"fcmp true",
                    .@"fcmp fast true",
                    => .fcmp_true,
                    .@"fcmp ueq",
                    .@"fcmp fast ueq",
                    => .fcmp_ueq,
                    .@"fcmp uge",
                    .@"fcmp fast uge",
                    => .fcmp_uge,
                    .@"fcmp ugt",
                    .@"fcmp fast ugt",
                    => .fcmp_ugt,
                    .@"fcmp ule",
                    .@"fcmp fast ule",
                    => .fcmp_ule,
                    .@"fcmp ult",
                    .@"fcmp fast ult",
                    => .fcmp_ult,
                    .@"fcmp une",
                    .@"fcmp fast une",
                    => .fcmp_une,
                    .@"fcmp uno",
                    .@"fcmp fast uno",
                    => .fcmp_uno,
                    .@"icmp eq" => .icmp_eq,
                    .@"icmp ne" => .icmp_ne,
                    .@"icmp sge" => .icmp_sge,
                    .@"icmp sgt" => .icmp_sgt,
                    .@"icmp sle" => .icmp_sle,
                    .@"icmp slt" => .icmp_slt,
                    .@"icmp uge" => .icmp_uge,
                    .@"icmp ugt" => .icmp_ugt,
                    .@"icmp ule" => .icmp_ule,
                    .@"icmp ult" => .icmp_ult,
                    else => unreachable,
                };
            }
        };

        pub const Index = enum(u32) {
            none = maxInt(u31),
            _,

            pub fn name(self: Instruction.Index, function: *const Function) String {
                return function.names[@backingInt(self)];
            }

            pub fn valueIndex(self: Instruction.Index, function: *const Function) u32 {
                return function.value_indices[@backingInt(self)];
            }

            pub fn toValue(self: Instruction.Index) Value {
                return @fromBackingInt(@backingInt(self));
            }

            pub fn isTerminatorWip(self: Instruction.Index, wip: *const WipFunction) bool {
                return switch (wip.instructions.items(.tag)[@backingInt(self)]) {
                    .br,
                    .br_cond,
                    .indirectbr,
                    .ret,
                    .@"ret void",
                    .@"switch",
                    .@"unreachable",
                    => true,
                    else => false,
                };
            }

            pub fn hasResultWip(self: Instruction.Index, wip: *const WipFunction) bool {
                return switch (wip.instructions.items(.tag)[@backingInt(self)]) {
                    .br,
                    .br_cond,
                    .fence,
                    .indirectbr,
                    .ret,
                    .@"ret void",
                    .store,
                    .@"store atomic",
                    .@"switch",
                    .@"unreachable",
                    .block,
                    => false,
                    .call,
                    .@"call fast",
                    .@"musttail call",
                    .@"musttail call fast",
                    .@"notail call",
                    .@"notail call fast",
                    .@"tail call",
                    .@"tail call fast",
                    => self.typeOfWip(wip) != .void,
                    else => true,
                };
            }

            pub fn typeOfWip(self: Instruction.Index, wip: *const WipFunction) Type {
                const instruction = wip.instructions.get(@backingInt(self));
                return switch (instruction.tag) {
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .@"add nuw nsw",
                    .@"and",
                    .ashr,
                    .@"ashr exact",
                    .fadd,
                    .@"fadd fast",
                    .fdiv,
                    .@"fdiv fast",
                    .fmul,
                    .@"fmul fast",
                    .frem,
                    .@"frem fast",
                    .fsub,
                    .@"fsub fast",
                    .lshr,
                    .@"lshr exact",
                    .mul,
                    .@"mul nsw",
                    .@"mul nuw",
                    .@"mul nuw nsw",
                    .@"or",
                    .sdiv,
                    .@"sdiv exact",
                    .shl,
                    .@"shl nsw",
                    .@"shl nuw",
                    .@"shl nuw nsw",
                    .srem,
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .@"sub nuw nsw",
                    .udiv,
                    .@"udiv exact",
                    .urem,
                    .xor,
                    => wip.extraData(Binary, instruction.data).lhs.typeOfWip(wip),
                    .addrspacecast,
                    .bitcast,
                    .fpext,
                    .fptosi,
                    .fptoui,
                    .fptrunc,
                    .inttoptr,
                    .ptrtoint,
                    .sext,
                    .sitofp,
                    .trunc,
                    .@"trunc nuw",
                    .@"trunc nsw",
                    .@"trunc nuw nsw",
                    .uitofp,
                    .zext,
                    => wip.extraData(Cast, instruction.data).type,
                    .alloca,
                    .@"alloca inalloca",
                    => wip.builder.ptrTypeAssumeCapacity(
                        wip.extraData(Alloca, instruction.data).info.addr_space,
                    ),
                    .arg => wip.function.typeOf(wip.builder)
                        .functionParameters(wip.builder)[instruction.data],
                    .atomicrmw => wip.extraData(AtomicRmw, instruction.data).val.typeOfWip(wip),
                    .block => .label,
                    .br,
                    .br_cond,
                    .fence,
                    .indirectbr,
                    .ret,
                    .@"ret void",
                    .store,
                    .@"store atomic",
                    .@"switch",
                    .@"unreachable",
                    => .none,
                    .call,
                    .@"call fast",
                    .@"musttail call",
                    .@"musttail call fast",
                    .@"notail call",
                    .@"notail call fast",
                    .@"tail call",
                    .@"tail call fast",
                    => wip.extraData(Call, instruction.data).ty.functionReturn(wip.builder),
                    .cmpxchg,
                    .@"cmpxchg weak",
                    => wip.builder.structTypeAssumeCapacity(.normal, &.{
                        wip.extraData(CmpXchg, instruction.data).cmp.typeOfWip(wip),
                        .i1,
                    }),
                    .extractelement => wip.extraData(ExtractElement, instruction.data)
                        .val.typeOfWip(wip).childType(wip.builder),
                    .extractvalue => {
                        var extra = wip.extraDataTrail(ExtractValue, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, u32, wip);
                        return extra.data.val.typeOfWip(wip).childTypeAt(indices, wip.builder);
                    },
                    .@"fcmp false",
                    .@"fcmp fast false",
                    .@"fcmp fast oeq",
                    .@"fcmp fast oge",
                    .@"fcmp fast ogt",
                    .@"fcmp fast ole",
                    .@"fcmp fast olt",
                    .@"fcmp fast one",
                    .@"fcmp fast ord",
                    .@"fcmp fast true",
                    .@"fcmp fast ueq",
                    .@"fcmp fast uge",
                    .@"fcmp fast ugt",
                    .@"fcmp fast ule",
                    .@"fcmp fast ult",
                    .@"fcmp fast une",
                    .@"fcmp fast uno",
                    .@"fcmp oeq",
                    .@"fcmp oge",
                    .@"fcmp ogt",
                    .@"fcmp ole",
                    .@"fcmp olt",
                    .@"fcmp one",
                    .@"fcmp ord",
                    .@"fcmp true",
                    .@"fcmp ueq",
                    .@"fcmp uge",
                    .@"fcmp ugt",
                    .@"fcmp ule",
                    .@"fcmp ult",
                    .@"fcmp une",
                    .@"fcmp uno",
                    .@"icmp eq",
                    .@"icmp ne",
                    .@"icmp sge",
                    .@"icmp sgt",
                    .@"icmp sle",
                    .@"icmp slt",
                    .@"icmp uge",
                    .@"icmp ugt",
                    .@"icmp ule",
                    .@"icmp ult",
                    => wip.extraData(Binary, instruction.data).lhs.typeOfWip(wip)
                        .changeScalarAssumeCapacity(.i1, wip.builder),
                    .fneg,
                    .@"fneg fast",
                    => @as(Value, @fromBackingInt(instruction.data)).typeOfWip(wip),
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => {
                        var extra = wip.extraDataTrail(GetElementPtr, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, Value, wip);
                        const base_ty = extra.data.base.typeOfWip(wip);
                        if (!base_ty.isVector(wip.builder)) for (indices) |index| {
                            const index_ty = index.typeOfWip(wip);
                            if (!index_ty.isVector(wip.builder)) continue;
                            return index_ty.changeScalarAssumeCapacity(base_ty, wip.builder);
                        };
                        return base_ty;
                    },
                    .insertelement => wip.extraData(InsertElement, instruction.data).val.typeOfWip(wip),
                    .insertvalue => wip.extraData(InsertValue, instruction.data).val.typeOfWip(wip),
                    .load,
                    .@"load atomic",
                    => wip.extraData(Load, instruction.data).type,
                    .phi,
                    .@"phi fast",
                    => wip.extraData(Phi, instruction.data).type,
                    .select,
                    .@"select fast",
                    => wip.extraData(Select, instruction.data).lhs.typeOfWip(wip),
                    .shufflevector => {
                        const extra = wip.extraData(ShuffleVector, instruction.data);
                        return extra.lhs.typeOfWip(wip).changeLengthAssumeCapacity(
                            extra.mask.typeOfWip(wip).vectorLen(wip.builder),
                            wip.builder,
                        );
                    },
                    .va_arg => wip.extraData(VaArg, instruction.data).type,
                };
            }

            pub fn typeOf(
                self: Instruction.Index,
                function_index: Function.Index,
                builder: *Builder,
            ) Type {
                const function = function_index.ptrConst(builder);
                const instruction = function.instructions.get(@backingInt(self));
                return switch (instruction.tag) {
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .@"add nuw nsw",
                    .@"and",
                    .ashr,
                    .@"ashr exact",
                    .fadd,
                    .@"fadd fast",
                    .fdiv,
                    .@"fdiv fast",
                    .fmul,
                    .@"fmul fast",
                    .frem,
                    .@"frem fast",
                    .fsub,
                    .@"fsub fast",
                    .lshr,
                    .@"lshr exact",
                    .mul,
                    .@"mul nsw",
                    .@"mul nuw",
                    .@"mul nuw nsw",
                    .@"or",
                    .sdiv,
                    .@"sdiv exact",
                    .shl,
                    .@"shl nsw",
                    .@"shl nuw",
                    .@"shl nuw nsw",
                    .srem,
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .@"sub nuw nsw",
                    .udiv,
                    .@"udiv exact",
                    .urem,
                    .xor,
                    => function.extraData(Binary, instruction.data).lhs.typeOf(function_index, builder),
                    .addrspacecast,
                    .bitcast,
                    .fpext,
                    .fptosi,
                    .fptoui,
                    .fptrunc,
                    .inttoptr,
                    .ptrtoint,
                    .sext,
                    .sitofp,
                    .trunc,
                    .@"trunc nuw",
                    .@"trunc nsw",
                    .@"trunc nuw nsw",
                    .uitofp,
                    .zext,
                    => function.extraData(Cast, instruction.data).type,
                    .alloca,
                    .@"alloca inalloca",
                    => builder.ptrTypeAssumeCapacity(
                        function.extraData(Alloca, instruction.data).info.addr_space,
                    ),
                    .arg => function.global.typeOf(builder)
                        .functionParameters(builder)[instruction.data],
                    .atomicrmw => function.extraData(AtomicRmw, instruction.data)
                        .val.typeOf(function_index, builder),
                    .block => .label,
                    .br,
                    .br_cond,
                    .fence,
                    .indirectbr,
                    .ret,
                    .@"ret void",
                    .store,
                    .@"store atomic",
                    .@"switch",
                    .@"unreachable",
                    => .none,
                    .call,
                    .@"call fast",
                    .@"musttail call",
                    .@"musttail call fast",
                    .@"notail call",
                    .@"notail call fast",
                    .@"tail call",
                    .@"tail call fast",
                    => function.extraData(Call, instruction.data).ty.functionReturn(builder),
                    .cmpxchg,
                    .@"cmpxchg weak",
                    => builder.structTypeAssumeCapacity(.normal, &.{
                        function.extraData(CmpXchg, instruction.data)
                            .cmp.typeOf(function_index, builder),
                        .i1,
                    }),
                    .extractelement => function.extraData(ExtractElement, instruction.data)
                        .val.typeOf(function_index, builder).childType(builder),
                    .extractvalue => {
                        var extra = function.extraDataTrail(ExtractValue, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, u32, function);
                        return extra.data.val.typeOf(function_index, builder)
                            .childTypeAt(indices, builder);
                    },
                    .@"fcmp false",
                    .@"fcmp fast false",
                    .@"fcmp fast oeq",
                    .@"fcmp fast oge",
                    .@"fcmp fast ogt",
                    .@"fcmp fast ole",
                    .@"fcmp fast olt",
                    .@"fcmp fast one",
                    .@"fcmp fast ord",
                    .@"fcmp fast true",
                    .@"fcmp fast ueq",
                    .@"fcmp fast uge",
                    .@"fcmp fast ugt",
                    .@"fcmp fast ule",
                    .@"fcmp fast ult",
                    .@"fcmp fast une",
                    .@"fcmp fast uno",
                    .@"fcmp oeq",
                    .@"fcmp oge",
                    .@"fcmp ogt",
                    .@"fcmp ole",
                    .@"fcmp olt",
                    .@"fcmp one",
                    .@"fcmp ord",
                    .@"fcmp true",
                    .@"fcmp ueq",
                    .@"fcmp uge",
                    .@"fcmp ugt",
                    .@"fcmp ule",
                    .@"fcmp ult",
                    .@"fcmp une",
                    .@"fcmp uno",
                    .@"icmp eq",
                    .@"icmp ne",
                    .@"icmp sge",
                    .@"icmp sgt",
                    .@"icmp sle",
                    .@"icmp slt",
                    .@"icmp uge",
                    .@"icmp ugt",
                    .@"icmp ule",
                    .@"icmp ult",
                    => function.extraData(Binary, instruction.data).lhs.typeOf(function_index, builder)
                        .changeScalarAssumeCapacity(.i1, builder),
                    .fneg,
                    .@"fneg fast",
                    => @as(Value, @fromBackingInt(instruction.data)).typeOf(function_index, builder),
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => {
                        var extra = function.extraDataTrail(GetElementPtr, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, Value, function);
                        const base_ty = extra.data.base.typeOf(function_index, builder);
                        if (!base_ty.isVector(builder)) for (indices) |index| {
                            const index_ty = index.typeOf(function_index, builder);
                            if (!index_ty.isVector(builder)) continue;
                            return index_ty.changeScalarAssumeCapacity(base_ty, builder);
                        };
                        return base_ty;
                    },
                    .insertelement => function.extraData(InsertElement, instruction.data)
                        .val.typeOf(function_index, builder),
                    .insertvalue => function.extraData(InsertValue, instruction.data)
                        .val.typeOf(function_index, builder),
                    .load,
                    .@"load atomic",
                    => function.extraData(Load, instruction.data).type,
                    .phi,
                    .@"phi fast",
                    => function.extraData(Phi, instruction.data).type,
                    .select,
                    .@"select fast",
                    => function.extraData(Select, instruction.data).lhs.typeOf(function_index, builder),
                    .shufflevector => {
                        const extra = function.extraData(ShuffleVector, instruction.data);
                        return extra.lhs.typeOf(function_index, builder).changeLengthAssumeCapacity(
                            extra.mask.typeOf(function_index, builder).vectorLen(builder),
                            builder,
                        );
                    },
                    .va_arg => function.extraData(VaArg, instruction.data).type,
                };
            }

            const FormatData = struct {
                instruction: Instruction.Index,
                function: Function.Index,
                builder: *Builder,
                flags: FormatFlags,
            };
            fn format(data: FormatData, w: *Writer) Writer.Error!void {
                if (data.flags.comma) {
                    if (data.instruction == .none) return;
                    try w.writeByte(',');
                }
                if (data.flags.space) {
                    if (data.instruction == .none) return;
                    try w.writeByte(' ');
                }
                if (data.flags.percent) try w.print(
                    "{f} ",
                    .{data.instruction.typeOf(data.function, data.builder).fmt(data.builder, .percent)},
                );
                assert(data.instruction != .none);
                try w.print("%{f}", .{
                    data.instruction.name(data.function.ptrConst(data.builder)).fmt(data.builder),
                });
            }
            pub fn fmt(
                self: Instruction.Index,
                function: Function.Index,
                builder: *Builder,
                flags: FormatFlags,
            ) std.fmt.Alt(FormatData, format) {
                return .{ .data = .{
                    .instruction = self,
                    .function = function,
                    .builder = builder,
                    .flags = flags,
                } };
            }
        };

        pub const ExtraIndex = u32;

        pub const BrCond = struct {
            cond: Value,
            then: Block.Index,
            @"else": Block.Index,
            weights: Weights,

            pub const Weights = enum(u32) {
                none = @bitCast(Metadata.Optional.none),
                unpredictable,
                _,

                pub fn fromMetadata(metadata: Metadata) Weights {
                    assert(metadata.kind == .node);
                    return @fromBackingInt(metadata.index);
                }

                pub fn toMetadata(weights: Weights) Metadata {
                    return .{ .index = @intCast(@backingInt(weights)), .kind = .node };
                }
            };
        };

        pub const Switch = struct {
            val: Value,
            default: Block.Index,
            cases_len: u32,
            weights: BrCond.Weights,
            // case_vals: [cases_len]Constant,
            // case_blocks: [cases_len]Block.Index,
        };

        pub const IndirectBr = struct {
            addr: Value,
            targets_len: u32,
            // targets: [targets_len]Block.Index,
        };

        pub const Binary = struct {
            lhs: Value,
            rhs: Value,
        };

        pub const ExtractElement = struct {
            val: Value,
            index: Value,
        };

        pub const InsertElement = struct {
            val: Value,
            elem: Value,
            index: Value,
        };

        pub const ShuffleVector = struct {
            lhs: Value,
            rhs: Value,
            mask: Value,
        };

        pub const ExtractValue = struct {
            val: Value,
            indices_len: u32,
            // indices: [indices_len]u32,
        };

        pub const InsertValue = struct {
            val: Value,
            elem: Value,
            indices_len: u32,
            // indices: [indices_len]u32,
        };

        pub const Alloca = struct {
            type: Type,
            len: Value,
            info: Info,

            pub const Kind = enum { normal, inalloca };
            pub const Info = packed struct(u32) {
                alignment: Alignment,
                addr_space: AddrSpace,
                _: u2 = undefined,
            };
        };

        pub const Load = struct {
            info: MemoryAccessInfo,
            type: Type,
            ptr: Value,
        };

        pub const Store = struct {
            info: MemoryAccessInfo,
            val: Value,
            ptr: Value,
        };

        pub const CmpXchg = struct {
            info: MemoryAccessInfo,
            ptr: Value,
            cmp: Value,
            new: Value,

            pub const Kind = enum { strong, weak };
        };

        pub const AtomicRmw = struct {
            info: MemoryAccessInfo,
            ptr: Value,
            val: Value,

            pub const Operation = enum(u5) {
                xchg = 0,
                add = 1,
                sub = 2,
                @"and" = 3,
                nand = 4,
                @"or" = 5,
                xor = 6,
                max = 7,
                min = 8,
                umax = 9,
                umin = 10,
                fadd = 11,
                fsub = 12,
                fmax = 13,
                fmin = 14,
                none = maxInt(u5),
            };
        };

        pub const GetElementPtr = struct {
            type: Type,
            base: Value,
            indices_len: u32,
            // indices: [indices_len]Value,

            pub const Kind = Constant.GetElementPtr.Kind;
        };

        pub const Cast = struct {
            val: Value,
            type: Type,

            pub const Signedness = Constant.Cast.Signedness;
        };

        pub const Phi = struct {
            type: Type,
            // incoming_vals: [block.incoming]Value,
            // incoming_blocks: [block.incoming]Block.Index,
        };

        pub const Select = struct {
            cond: Value,
            lhs: Value,
            rhs: Value,
        };

        pub const Call = struct {
            info: Info,
            attributes: FunctionAttributes,
            ty: Type,
            callee: Value,
            args_len: u32,
            // args: [args_len]Value,

            pub const Kind = enum {
                normal,
                fast,
                musttail,
                musttail_fast,
                notail,
                notail_fast,
                tail,
                tail_fast,
            };
            pub const Info = packed struct(u32) {
                call_conv: CallConv,
                has_op_bundle_cold: bool,
                _: u21 = undefined,
            };
        };

        pub const VaArg = struct {
            list: Value,
            type: Type,
        };
    };

    pub fn deinit(self: *Function, gpa: Allocator) void {
        gpa.free(self.extra);
        gpa.free(self.debug_values);
        self.debug_locations.deinit(gpa);
        gpa.free(self.value_indices[0..self.instructions.len]);
        gpa.free(self.names[0..self.instructions.len]);
        self.instructions.deinit(gpa);
        gpa.free(self.blocks);
        self.* = undefined;
    }

    pub fn arg(self: *const Function, index: u32) Value {
        const argument = self.instructions.get(index);
        assert(argument.tag == .arg);
        assert(argument.data == index);

        const argument_index: Instruction.Index = @fromBackingInt(index);
        return argument_index.toValue();
    }

    const ExtraDataTrail = struct {
        index: Instruction.ExtraIndex,

        fn nextMut(self: *ExtraDataTrail, len: u32, comptime Item: type, function: *Function) []Item {
            const items: []Item = @ptrCast(function.extra[self.index..][0..len]);
            self.index += @intCast(len);
            return items;
        }

        fn next(
            self: *ExtraDataTrail,
            len: u32,
            comptime Item: type,
            function: *const Function,
        ) []const Item {
            const items: []const Item = @ptrCast(function.extra[self.index..][0..len]);
            self.index += @intCast(len);
            return items;
        }
    };

    fn extraDataTrail(
        self: *const Function,
        comptime T: type,
        index: Instruction.ExtraIndex,
    ) struct { data: T, trail: ExtraDataTrail } {
        var result: T = undefined;
        const info = @typeInfo(T).@"struct";
        inline for (
            info.field_names,
            info.field_types,
            self.extra[index..][0..info.field_names.len],
        ) |field_name, field_type, value|
            @field(result, field_name) = switch (field_type) {
                u32 => value,
                Alignment,
                AtomicOrdering,
                Block.Index,
                FunctionAttributes,
                Type,
                Value,
                Instruction.BrCond.Weights,
                => @fromBackingInt(value),
                MemoryAccessInfo,
                Instruction.Alloca.Info,
                Instruction.Call.Info,
                => @bitCast(value),
                else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
            };
        return .{
            .data = result,
            .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(info.field_names.len)) },
        };
    }

    fn extraData(self: *const Function, comptime T: type, index: Instruction.ExtraIndex) T {
        return self.extraDataTrail(T, index).data;
    }
};

pub const DebugLocation = union(enum) {
    no_location: void,
    location: Location,

    pub const Location = struct {
        line: u32,
        column: u32,
        scope: Builder.Metadata.Optional,
        inlined_at: Builder.Metadata.Optional,
    };

    pub fn toMetadata(self: DebugLocation, builder: *Builder) Allocator.Error!Metadata.Optional {
        return switch (self) {
            .no_location => .none,
            .location => |location| (try builder.debugLocation(
                location.line,
                location.column,
                location.scope.unwrap().?,
                location.inlined_at.unwrap(),
            )).toOptional(),
        };
    }
};

pub const WipFunction = struct {
    builder: *Builder,
    function: Function.Index,
    prev_debug_location: DebugLocation,
    debug_location: DebugLocation,
    cursor: Cursor,
    blocks: std.ArrayList(Block),
    instructions: std.MultiArrayList(Instruction),
    names: std.ArrayList(String),
    strip: bool,
    debug_locations: std.array_hash_map.Auto(Instruction.Index, DebugLocation),
    debug_values: std.array_hash_map.Auto(Instruction.Index, void),
    extra: std.ArrayList(u32),

    pub const Cursor = struct { block: Block.Index, instruction: u32 = 0 };

    pub const Block = struct {
        name: String,
        incoming: u32,
        branches: u32 = 0,
        instructions: std.ArrayList(Instruction.Index),

        const Index = enum(u32) {
            entry,
            _,

            pub fn ptr(self: Index, wip: *WipFunction) *Block {
                return &wip.blocks.items[@backingInt(self)];
            }

            pub fn ptrConst(self: Index, wip: *const WipFunction) *const Block {
                return &wip.blocks.items[@backingInt(self)];
            }

            pub fn toInst(self: Index, function: *const Function) Instruction.Index {
                return function.blocks[@backingInt(self)].instruction;
            }
        };
    };

    pub const Instruction = Function.Instruction;

    pub fn init(builder: *Builder, options: struct {
        function: Function.Index,
        strip: bool,
    }) Allocator.Error!WipFunction {
        var self: WipFunction = .{
            .builder = builder,
            .function = options.function,
            .prev_debug_location = .no_location,
            .debug_location = .no_location,
            .cursor = undefined,
            .blocks = .empty,
            .instructions = .empty,
            .names = .empty,
            .strip = options.strip,
            .debug_locations = .empty,
            .debug_values = .empty,
            .extra = .empty,
        };
        errdefer self.deinit();

        const params_len = options.function.typeOf(self.builder).functionParameters(self.builder).len;
        try self.ensureUnusedExtraCapacity(params_len, NoExtra, 0);
        try self.instructions.ensureUnusedCapacity(self.builder.gpa, params_len);
        if (!self.strip) {
            try self.names.ensureUnusedCapacity(self.builder.gpa, params_len);
        }
        for (0..params_len) |param_index| {
            self.instructions.appendAssumeCapacity(.{ .tag = .arg, .data = @intCast(param_index) });
            if (!self.strip) {
                self.names.appendAssumeCapacity(.empty); // TODO: 参数名
            }
        }

        return self;
    }

    pub fn arg(self: *const WipFunction, index: u32) Value {
        const argument = self.instructions.get(index);
        assert(argument.tag == .arg);
        assert(argument.data == index);

        const argument_index: Instruction.Index = @fromBackingInt(index);
        return argument_index.toValue();
    }

    pub fn block(self: *WipFunction, incoming: u32, name: []const u8) Allocator.Error!Block.Index {
        try self.blocks.ensureUnusedCapacity(self.builder.gpa, 1);

        const index: Block.Index = @fromBackingInt(@intCast(self.blocks.items.len));
        const final_name = if (self.strip) .empty else try self.builder.string(name);
        self.blocks.appendAssumeCapacity(.{
            .name = final_name,
            .incoming = incoming,
            .instructions = .empty,
        });
        return index;
    }

    pub fn ret(self: *WipFunction, val: Value) Allocator.Error!Instruction.Index {
        assert(val.typeOfWip(self) == self.function.typeOf(self.builder).functionReturn(self.builder));
        try self.ensureUnusedExtraCapacity(1, NoExtra, 0);
        return try self.addInst(null, .{ .tag = .ret, .data = @backingInt(val) });
    }

    pub fn retVoid(self: *WipFunction) Allocator.Error!Instruction.Index {
        try self.ensureUnusedExtraCapacity(1, NoExtra, 0);
        return try self.addInst(null, .{ .tag = .@"ret void", .data = undefined });
    }

    pub fn br(self: *WipFunction, dest: Block.Index) Allocator.Error!Instruction.Index {
        try self.ensureUnusedExtraCapacity(1, NoExtra, 0);
        const instruction = try self.addInst(null, .{ .tag = .br, .data = @backingInt(dest) });
        dest.ptr(self).branches += 1;
        return instruction;
    }

    pub fn brCond(
        self: *WipFunction,
        cond: Value,
        then: Block.Index,
        @"else": Block.Index,
        weights: enum { none, unpredictable, then_likely, else_likely },
    ) Allocator.Error!Instruction.Index {
        assert(cond.typeOfWip(self) == .i1);
        try self.ensureUnusedExtraCapacity(1, Instruction.BrCond, 0);
        const instruction = try self.addInst(null, .{
            .tag = .br_cond,
            .data = self.addExtraAssumeCapacity(Instruction.BrCond{
                .cond = cond,
                .then = then,
                .@"else" = @"else",
                .weights = weights: switch (weights) {
                    .none => .none,
                    .unpredictable => .unpredictable,
                    .then_likely, .else_likely => {
                        const branch_weights_str = try self.builder.metadataString("branch_weights");
                        const unlikely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 1));
                        const likely_const = try self.builder.metadataConstant(try self.builder.intConst(.i32, 2000));
                        const weight_vals: [3]Metadata = switch (weights) {
                            .none, .unpredictable => unreachable,
                            .then_likely => .{ branch_weights_str.toMetadata(), likely_const, unlikely_const },
                            .else_likely => .{ branch_weights_str.toMetadata(), unlikely_const, likely_const },
                        };
                        break :weights .fromMetadata(try self.builder.metadataTuple(&weight_vals));
                    },
                },
            }),
        });
        then.ptr(self).branches += 1;
        @"else".ptr(self).branches += 1;
        return instruction;
    }

    pub const WipSwitch = struct {
        index: u32,
        instruction: Instruction.Index,

        pub fn addCase(
            self: *WipSwitch,
            val: Constant,
            dest: Block.Index,
            wip: *WipFunction,
        ) Allocator.Error!void {
            const instruction = wip.instructions.get(@backingInt(self.instruction));
            var extra = wip.extraDataTrail(Instruction.Switch, instruction.data);
            assert(val.typeOf(wip.builder) == extra.data.val.typeOfWip(wip));
            extra.trail.nextMut(extra.data.cases_len, Constant, wip)[self.index] = val;
            extra.trail.nextMut(extra.data.cases_len, Block.Index, wip)[self.index] = dest;
            self.index += 1;
            dest.ptr(wip).branches += 1;
        }

        pub fn finish(self: WipSwitch, wip: *WipFunction) void {
            const instruction = wip.instructions.get(@backingInt(self.instruction));
            const extra = wip.extraData(Instruction.Switch, instruction.data);
            assert(self.index == extra.cases_len);
        }
    };

    pub fn @"switch"(
        self: *WipFunction,
        val: Value,
        default: Block.Index,
        cases_len: u32,
        weights: Instruction.BrCond.Weights,
    ) Allocator.Error!WipSwitch {
        try self.ensureUnusedExtraCapacity(1, Instruction.Switch, cases_len * 2);
        const instruction = try self.addInst(null, .{
            .tag = .@"switch",
            .data = self.addExtraAssumeCapacity(Instruction.Switch{
                .val = val,
                .default = default,
                .cases_len = cases_len,
                .weights = weights,
            }),
        });
        _ = self.extra.addManyAsSliceAssumeCapacity(cases_len * 2);
        default.ptr(self).branches += 1;
        return .{ .index = 0, .instruction = instruction };
    }

    pub fn indirectbr(
        self: *WipFunction,
        addr: Value,
        targets: []const Block.Index,
    ) Allocator.Error!Instruction.Index {
        try self.ensureUnusedExtraCapacity(1, Instruction.IndirectBr, targets.len);
        const instruction = try self.addInst(null, .{
            .tag = .indirectbr,
            .data = self.addExtraAssumeCapacity(Instruction.IndirectBr{
                .addr = addr,
                .targets_len = @intCast(targets.len),
            }),
        });
        _ = self.extra.appendSliceAssumeCapacity(@ptrCast(targets));
        for (targets) |target| target.ptr(self).branches += 1;
        return instruction;
    }

    pub fn @"unreachable"(self: *WipFunction) Allocator.Error!Instruction.Index {
        try self.ensureUnusedExtraCapacity(1, NoExtra, 0);
        return try self.addInst(null, .{ .tag = .@"unreachable", .data = undefined });
    }

    pub fn un(
        self: *WipFunction,
        tag: Instruction.Tag,
        val: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        switch (tag) {
            .fneg,
            .@"fneg fast",
            => assert(val.typeOfWip(self).scalarType(self.builder).isFloatingPoint()),
            else => unreachable,
        }
        try self.ensureUnusedExtraCapacity(1, NoExtra, 0);
        const instruction = try self.addInst(name, .{ .tag = tag, .data = @backingInt(val) });
        return instruction.toValue();
    }

    pub fn not(self: *WipFunction, val: Value, name: []const u8) Allocator.Error!Value {
        const ty = val.typeOfWip(self);
        const all_ones = try self.builder.splatValue(
            ty,
            try self.builder.intConst(ty.scalarType(self.builder), -1),
        );
        return self.bin(.xor, val, all_ones, name);
    }

    pub fn neg(self: *WipFunction, val: Value, name: []const u8) Allocator.Error!Value {
        return self.bin(.sub, try self.builder.zeroInitValue(val.typeOfWip(self)), val, name);
    }

    pub fn bin(
        self: *WipFunction,
        tag: Instruction.Tag,
        lhs: Value,
        rhs: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        switch (tag) {
            .add,
            .@"add nsw",
            .@"add nuw",
            .@"and",
            .ashr,
            .@"ashr exact",
            .fadd,
            .@"fadd fast",
            .fdiv,
            .@"fdiv fast",
            .fmul,
            .@"fmul fast",
            .frem,
            .@"frem fast",
            .fsub,
            .@"fsub fast",
            .lshr,
            .@"lshr exact",
            .mul,
            .@"mul nsw",
            .@"mul nuw",
            .@"or",
            .sdiv,
            .@"sdiv exact",
            .shl,
            .@"shl nsw",
            .@"shl nuw",
            .srem,
            .sub,
            .@"sub nsw",
            .@"sub nuw",
            .udiv,
            .@"udiv exact",
            .urem,
            .xor,
            => assert(lhs.typeOfWip(self) == rhs.typeOfWip(self)),
            else => unreachable,
        }
        try self.ensureUnusedExtraCapacity(1, Instruction.Binary, 0);
        const instruction = try self.addInst(name, .{
            .tag = tag,
            .data = self.addExtraAssumeCapacity(Instruction.Binary{ .lhs = lhs, .rhs = rhs }),
        });
        return instruction.toValue();
    }

    pub fn extractElement(
        self: *WipFunction,
        val: Value,
        index: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(val.typeOfWip(self).isVector(self.builder));
        assert(index.typeOfWip(self).isInteger(self.builder));
        try self.ensureUnusedExtraCapacity(1, Instruction.ExtractElement, 0);
        const instruction = try self.addInst(name, .{
            .tag = .extractelement,
            .data = self.addExtraAssumeCapacity(Instruction.ExtractElement{
                .val = val,
                .index = index,
            }),
        });
        return instruction.toValue();
    }

    pub fn insertElement(
        self: *WipFunction,
        val: Value,
        elem: Value,
        index: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(val.typeOfWip(self).scalarType(self.builder) == elem.typeOfWip(self));
        assert(index.typeOfWip(self).isInteger(self.builder));
        try self.ensureUnusedExtraCapacity(1, Instruction.InsertElement, 0);
        const instruction = try self.addInst(name, .{
            .tag = .insertelement,
            .data = self.addExtraAssumeCapacity(Instruction.InsertElement{
                .val = val,
                .elem = elem,
                .index = index,
            }),
        });
        return instruction.toValue();
    }

    pub fn shuffleVector(
        self: *WipFunction,
        lhs: Value,
        rhs: Value,
        mask: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(lhs.typeOfWip(self).isVector(self.builder));
        assert(lhs.typeOfWip(self) == rhs.typeOfWip(self));
        assert(mask.typeOfWip(self).scalarType(self.builder).isInteger(self.builder));
        _ = try self.ensureUnusedExtraCapacity(1, Instruction.ShuffleVector, 0);
        const instruction = try self.addInst(name, .{
            .tag = .shufflevector,
            .data = self.addExtraAssumeCapacity(Instruction.ShuffleVector{
                .lhs = lhs,
                .rhs = rhs,
                .mask = mask,
            }),
        });
        return instruction.toValue();
    }

    pub fn splatVector(
        self: *WipFunction,
        ty: Type,
        elem: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        const scalar_ty = try ty.changeLength(1, self.builder);
        const mask_ty = try ty.changeScalar(.i32, self.builder);
        const poison = try self.builder.poisonValue(scalar_ty);
        const mask = try self.builder.splatValue(mask_ty, .@"0");
        const scalar = try self.insertElement(poison, elem, .@"0", name);
        return self.shuffleVector(scalar, poison, mask, name);
    }

    pub fn extractValue(
        self: *WipFunction,
        val: Value,
        indices: []const u32,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(indices.len > 0);
        _ = val.typeOfWip(self).childTypeAt(indices, self.builder);
        try self.ensureUnusedExtraCapacity(1, Instruction.ExtractValue, indices.len);
        const instruction = try self.addInst(name, .{
            .tag = .extractvalue,
            .data = self.addExtraAssumeCapacity(Instruction.ExtractValue{
                .val = val,
                .indices_len = @intCast(indices.len),
            }),
        });
        self.extra.appendSliceAssumeCapacity(indices);
        return instruction.toValue();
    }

    pub fn insertValue(
        self: *WipFunction,
        val: Value,
        elem: Value,
        indices: []const u32,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(indices.len > 0);
        assert(val.typeOfWip(self).childTypeAt(indices, self.builder) == elem.typeOfWip(self));
        try self.ensureUnusedExtraCapacity(1, Instruction.InsertValue, indices.len);
        const instruction = try self.addInst(name, .{
            .tag = .insertvalue,
            .data = self.addExtraAssumeCapacity(Instruction.InsertValue{
                .val = val,
                .elem = elem,
                .indices_len = @intCast(indices.len),
            }),
        });
        self.extra.appendSliceAssumeCapacity(indices);
        return instruction.toValue();
    }

    pub fn buildAggregate(
        self: *WipFunction,
        ty: Type,
        elems: []const Value,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(ty.aggregateLen(self.builder) == elems.len);
        var cur = try self.builder.poisonValue(ty);
        for (elems, 0..) |elem, index|
            cur = try self.insertValue(cur, elem, &[_]u32{@intCast(index)}, name);
        return cur;
    }

    pub fn alloca(
        self: *WipFunction,
        kind: Instruction.Alloca.Kind,
        ty: Type,
        len: Value,
        alignment: Alignment,
        addr_space: AddrSpace,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(len == .none or len.typeOfWip(self).isInteger(self.builder));
        _ = try self.builder.ptrType(addr_space);
        try self.ensureUnusedExtraCapacity(1, Instruction.Alloca, 0);
        const instruction = try self.addInst(name, .{
            .tag = switch (kind) {
                .normal => .alloca,
                .inalloca => .@"alloca inalloca",
            },
            .data = self.addExtraAssumeCapacity(Instruction.Alloca{
                .type = ty,
                .len = switch (len) {
                    .none => .@"1",
                    else => len,
                },
                .info = .{ .alignment = alignment, .addr_space = addr_space },
            }),
        });
        return instruction.toValue();
    }

    pub fn load(
        self: *WipFunction,
        access_kind: MemoryAccessKind,
        ty: Type,
        ptr: Value,
        alignment: Alignment,
        name: []const u8,
    ) Allocator.Error!Value {
        return self.loadAtomic(access_kind, ty, ptr, undefined, .none, alignment, name);
    }

    pub fn loadAtomic(
        self: *WipFunction,
        access_kind: MemoryAccessKind,
        ty: Type,
        ptr: Value,
        sync_scope: SyncScope,
        ordering: AtomicOrdering,
        alignment: Alignment,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(ptr.typeOfWip(self).isPointer(self.builder));
        try self.ensureUnusedExtraCapacity(1, Instruction.Load, 0);
        const instruction = try self.addInst(name, .{
            .tag = switch (ordering) {
                .none => .load,
                else => .@"load atomic",
            },
            .data = self.addExtraAssumeCapacity(Instruction.Load{
                .info = .{
                    .access_kind = access_kind,
                    .sync_scope = switch (ordering) {
                        .none => .system,
                        else => sync_scope,
                    },
                    .success_ordering = ordering,
                    .alignment = alignment,
                },
                .type = ty,
                .ptr = ptr,
            }),
        });
        return instruction.toValue();
    }

    pub fn store(
        self: *WipFunction,
        kind: MemoryAccessKind,
        val: Value,
        ptr: Value,
        alignment: Alignment,
    ) Allocator.Error!Instruction.Index {
        return self.storeAtomic(kind, val, ptr, undefined, .none, alignment);
    }

    pub fn storeAtomic(
        self: *WipFunction,
        access_kind: MemoryAccessKind,
        val: Value,
        ptr: Value,
        sync_scope: SyncScope,
        ordering: AtomicOrdering,
        alignment: Alignment,
    ) Allocator.Error!Instruction.Index {
        assert(ptr.typeOfWip(self).isPointer(self.builder));
        try self.ensureUnusedExtraCapacity(1, Instruction.Store, 0);
        const instruction = try self.addInst(null, .{
            .tag = switch (ordering) {
                .none => .store,
                else => .@"store atomic",
            },
            .data = self.addExtraAssumeCapacity(Instruction.Store{
                .info = .{
                    .access_kind = access_kind,
                    .sync_scope = switch (ordering) {
                        .none => .system,
                        else => sync_scope,
                    },
                    .success_ordering = ordering,
                    .alignment = alignment,
                },
                .val = val,
                .ptr = ptr,
            }),
        });
        return instruction;
    }

    pub fn fence(
        self: *WipFunction,
        sync_scope: SyncScope,
        ordering: AtomicOrdering,
    ) Allocator.Error!Instruction.Index {
        assert(ordering != .none);
        try self.ensureUnusedExtraCapacity(1, NoExtra, 0);
        const instruction = try self.addInst(null, .{
            .tag = .fence,
            .data = @bitCast(MemoryAccessInfo{
                .sync_scope = sync_scope,
                .success_ordering = ordering,
            }),
        });
        return instruction;
    }

    pub fn cmpxchg(
        self: *WipFunction,
        kind: Instruction.CmpXchg.Kind,
        access_kind: MemoryAccessKind,
        ptr: Value,
        cmp: Value,
        new: Value,
        sync_scope: SyncScope,
        success_ordering: AtomicOrdering,
        failure_ordering: AtomicOrdering,
        alignment: Alignment,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(ptr.typeOfWip(self).isPointer(self.builder));
        const ty = cmp.typeOfWip(self);
        assert(ty == new.typeOfWip(self));
        assert(success_ordering != .none);
        assert(failure_ordering != .none);

        _ = try self.builder.structType(.normal, &.{ ty, .i1 });
        try self.ensureUnusedExtraCapacity(1, Instruction.CmpXchg, 0);
        const instruction = try self.addInst(name, .{
            .tag = switch (kind) {
                .strong => .cmpxchg,
                .weak => .@"cmpxchg weak",
            },
            .data = self.addExtraAssumeCapacity(Instruction.CmpXchg{
                .info = .{
                    .access_kind = access_kind,
                    .sync_scope = sync_scope,
                    .success_ordering = success_ordering,
                    .failure_ordering = failure_ordering,
                    .alignment = alignment,
                },
                .ptr = ptr,
                .cmp = cmp,
                .new = new,
            }),
        });
        return instruction.toValue();
    }

    pub fn atomicrmw(
        self: *WipFunction,
        access_kind: MemoryAccessKind,
        operation: Instruction.AtomicRmw.Operation,
        ptr: Value,
        val: Value,
        sync_scope: SyncScope,
        ordering: AtomicOrdering,
        alignment: Alignment,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(ptr.typeOfWip(self).isPointer(self.builder));
        assert(ordering != .none);

        try self.ensureUnusedExtraCapacity(1, Instruction.AtomicRmw, 0);
        const instruction = try self.addInst(name, .{
            .tag = .atomicrmw,
            .data = self.addExtraAssumeCapacity(Instruction.AtomicRmw{
                .info = .{
                    .access_kind = access_kind,
                    .atomic_rmw_operation = operation,
                    .sync_scope = sync_scope,
                    .success_ordering = ordering,
                    .alignment = alignment,
                },
                .ptr = ptr,
                .val = val,
            }),
        });
        return instruction.toValue();
    }

    pub fn gep(
        self: *WipFunction,
        kind: Instruction.GetElementPtr.Kind,
        ty: Type,
        base: Value,
        indices: []const Value,
        name: []const u8,
    ) Allocator.Error!Value {
        const base_ty = base.typeOfWip(self);
        const base_is_vector = base_ty.isVector(self.builder);

        const VectorInfo = struct {
            kind: Type.Vector.Kind,
            len: u32,

            fn init(vector_ty: Type, builder: *const Builder) @This() {
                return .{ .kind = vector_ty.vectorKind(builder), .len = vector_ty.vectorLen(builder) };
            }
        };
        var vector_info: ?VectorInfo =
            if (base_is_vector) VectorInfo.init(base_ty, self.builder) else null;
        for (indices) |index| {
            const index_ty = index.typeOfWip(self);
            switch (index_ty.tag(self.builder)) {
                .integer => {},
                .vector, .scalable_vector => {
                    const index_info = VectorInfo.init(index_ty, self.builder);
                    if (vector_info) |info|
                        assert(std.meta.eql(info, index_info))
                    else
                        vector_info = index_info;
                },
                else => unreachable,
            }
        }
        if (!base_is_vector) if (vector_info) |info| switch (info.kind) {
            inline else => |vector_kind| _ = try self.builder.vectorType(
                vector_kind,
                info.len,
                base_ty,
            ),
        };

        try self.ensureUnusedExtraCapacity(1, Instruction.GetElementPtr, indices.len);
        const instruction = try self.addInst(name, .{
            .tag = switch (kind) {
                .normal => .getelementptr,
                .inbounds => .@"getelementptr inbounds",
            },
            .data = self.addExtraAssumeCapacity(Instruction.GetElementPtr{
                .type = ty,
                .base = base,
                .indices_len = @intCast(indices.len),
            }),
        });
        self.extra.appendSliceAssumeCapacity(@ptrCast(indices));
        return instruction.toValue();
    }

    pub fn gepStruct(
        self: *WipFunction,
        ty: Type,
        base: Value,
        index: usize,
        name: []const u8,
    ) Allocator.Error!Value {
        assert(ty.isStruct(self.builder));
        return self.gep(.inbounds, ty, base, &.{ .@"0", try self.builder.intValue(.i32, index) }, name);
    }

    pub fn conv(
        self: *WipFunction,
        signedness: Instruction.Cast.Signedness,
        val: Value,
        ty: Type,
        name: []const u8,
    ) Allocator.Error!Value {
        const val_ty = val.typeOfWip(self);
        if (val_ty == ty) return val;
        return self.cast(self.builder.convTag(signedness, val_ty, ty), val, ty, name);
    }

    pub fn cast(
        self: *WipFunction,
        tag: Instruction.Tag,
        val: Value,
        ty: Type,
        name: []const u8,
    ) Allocator.Error!Value {
        switch (tag) {
            .addrspacecast,
            .bitcast,
            .fpext,
            .fptosi,
            .fptoui,
            .fptrunc,
            .inttoptr,
            .ptrtoint,
            .sext,
            .sitofp,
            .trunc,
            .@"trunc nuw",
            .@"trunc nsw",
            .@"trunc nuw nsw",
            .uitofp,
            .zext,
            => {},
            else => unreachable,
        }
        if (val.typeOfWip(self) == ty) return val;
        try self.ensureUnusedExtraCapacity(1, Instruction.Cast, 0);
        const instruction = try self.addInst(name, .{
            .tag = tag,
            .data = self.addExtraAssumeCapacity(Instruction.Cast{
                .val = val,
                .type = ty,
            }),
        });
        return instruction.toValue();
    }

    pub fn icmp(
        self: *WipFunction,
        cond: IntegerCondition,
        lhs: Value,
        rhs: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        return self.cmpTag(switch (cond) {
            inline else => |tag| @field(Instruction.Tag, "icmp " ++ @tagName(tag)),
        }, lhs, rhs, name);
    }

    pub fn fcmp(
        self: *WipFunction,
        fast: FastMathKind,
        cond: FloatCondition,
        lhs: Value,
        rhs: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        return self.cmpTag(switch (fast) {
            inline else => |fast_tag| switch (cond) {
                inline else => |cond_tag| @field(Instruction.Tag, "fcmp " ++ switch (fast_tag) {
                    .normal => "",
                    .fast => "fast ",
                } ++ @tagName(cond_tag)),
            },
        }, lhs, rhs, name);
    }

    pub const WipPhi = struct {
        block: Block.Index,
        instruction: Instruction.Index,

        pub fn toValue(self: WipPhi) Value {
            return self.instruction.toValue();
        }

        pub fn finish(
            self: WipPhi,
            vals: []const Value,
            blocks: []const Block.Index,
            wip: *WipFunction,
        ) void {
            const incoming_len = self.block.ptrConst(wip).incoming;
            assert(vals.len == incoming_len and blocks.len == incoming_len);
            const instruction = wip.instructions.get(@backingInt(self.instruction));
            var extra = wip.extraDataTrail(Instruction.Phi, instruction.data);
            for (vals) |val| assert(val.typeOfWip(wip) == extra.data.type);
            @memcpy(extra.trail.nextMut(incoming_len, Value, wip), vals);
            @memcpy(extra.trail.nextMut(incoming_len, Block.Index, wip), blocks);
        }
    };

    pub fn phi(self: *WipFunction, ty: Type, name: []const u8) Allocator.Error!WipPhi {
        return self.phiTag(.phi, ty, name);
    }

    pub fn phiFast(self: *WipFunction, ty: Type, name: []const u8) Allocator.Error!WipPhi {
        return self.phiTag(.@"phi fast", ty, name);
    }

    pub fn select(
        self: *WipFunction,
        fast: FastMathKind,
        cond: Value,
        lhs: Value,
        rhs: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        return self.selectTag(switch (fast) {
            .normal => .select,
            .fast => .@"select fast",
        }, cond, lhs, rhs, name);
    }

    pub fn call(
        self: *WipFunction,
        kind: Instruction.Call.Kind,
        call_conv: CallConv,
        function_attributes: FunctionAttributes,
        ty: Type,
        callee: Value,
        args: []const Value,
        name: []const u8,
    ) Allocator.Error!Value {
        return self.callInner(kind, call_conv, function_attributes, ty, callee, args, name, false);
    }

    fn callInner(
        self: *WipFunction,
        kind: Instruction.Call.Kind,
        call_conv: CallConv,
        function_attributes: FunctionAttributes,
        ty: Type,
        callee: Value,
        args: []const Value,
        name: []const u8,
        has_op_bundle_cold: bool,
    ) Allocator.Error!Value {
        const ret_ty = ty.functionReturn(self.builder);
        assert(ty.isFunction(self.builder));
        assert(callee.typeOfWip(self).isPointer(self.builder));
        const params = ty.functionParameters(self.builder);
        for (params, args[0..params.len]) |param, arg_val| assert(param == arg_val.typeOfWip(self));

        try self.ensureUnusedExtraCapacity(1, Instruction.Call, args.len);
        const instruction = try self.addInst(switch (ret_ty) {
            .void => null,
            else => name,
        }, .{
            .tag = switch (kind) {
                .normal => .call,
                .fast => .@"call fast",
                .musttail => .@"musttail call",
                .musttail_fast => .@"musttail call fast",
                .notail => .@"notail call",
                .notail_fast => .@"notail call fast",
                .tail => .@"tail call",
                .tail_fast => .@"tail call fast",
            },
            .data = self.addExtraAssumeCapacity(Instruction.Call{
                .info = .{
                    .call_conv = call_conv,
                    .has_op_bundle_cold = has_op_bundle_cold,
                },
                .attributes = function_attributes,
                .ty = ty,
                .callee = callee,
                .args_len = @intCast(args.len),
            }),
        });
        self.extra.appendSliceAssumeCapacity(@ptrCast(args));
        return instruction.toValue();
    }

    pub fn callAsm(
        self: *WipFunction,
        function_attributes: FunctionAttributes,
        ty: Type,
        kind: Constant.Assembly.Info,
        assembly: String,
        constraints: String,
        args: []const Value,
        name: []const u8,
    ) Allocator.Error!Value {
        const callee = try self.builder.asmValue(ty, kind, assembly, constraints);
        return self.call(.normal, CallConv.default, function_attributes, ty, callee, args, name);
    }

    pub fn callIntrinsic(
        self: *WipFunction,
        fast: FastMathKind,
        function_attributes: FunctionAttributes,
        id: Intrinsic,
        overload: []const Type,
        args: []const Value,
        name: []const u8,
    ) Allocator.Error!Value {
        const intrinsic = try self.builder.getIntrinsic(id, overload);
        return self.call(
            fast.toCallKind(),
            CallConv.default,
            function_attributes,
            intrinsic.typeOf(self.builder),
            intrinsic.toValue(self.builder),
            args,
            name,
        );
    }

    pub fn callIntrinsicAssumeCold(self: *WipFunction) Allocator.Error!Value {
        const intrinsic = try self.builder.getIntrinsic(.assume, &.{});
        return self.callInner(
            .normal,
            CallConv.default,
            .none,
            intrinsic.typeOf(self.builder),
            intrinsic.toValue(self.builder),
            &.{try self.builder.intValue(.i1, 1)},
            "",
            true,
        );
    }

    pub fn callMemCpy(
        self: *WipFunction,
        dst: Value,
        dst_align: Alignment,
        src: Value,
        src_align: Alignment,
        len: Value,
        kind: MemoryAccessKind,
        @"inline": bool,
    ) Allocator.Error!Instruction.Index {
        var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(dst_align) })};
        var src_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(src_align) })};
        const value = try self.callIntrinsic(
            .normal,
            try self.builder.fnAttrs(&.{
                .none,
                .none,
                try self.builder.attrs(&dst_attrs),
                try self.builder.attrs(&src_attrs),
            }),
            if (@"inline") .@"memcpy.inline" else .memcpy,
            &.{ dst.typeOfWip(self), src.typeOfWip(self), len.typeOfWip(self) },
            &.{ dst, src, len, switch (kind) {
                .normal => Value.false,
                .@"volatile" => Value.true,
            } },
            undefined,
        );
        return value.unwrap().instruction;
    }

    pub fn callMemMove(
        self: *WipFunction,
        dst: Value,
        dst_align: Alignment,
        src: Value,
        src_align: Alignment,
        len: Value,
        kind: MemoryAccessKind,
    ) Allocator.Error!Instruction.Index {
        var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(dst_align) })};
        var src_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(src_align) })};
        const value = try self.callIntrinsic(
            .normal,
            try self.builder.fnAttrs(&.{
                .none,
                .none,
                try self.builder.attrs(&dst_attrs),
                try self.builder.attrs(&src_attrs),
            }),
            .memmove,
            &.{ dst.typeOfWip(self), src.typeOfWip(self), len.typeOfWip(self) },
            &.{ dst, src, len, switch (kind) {
                .normal => Value.false,
                .@"volatile" => Value.true,
            } },
            undefined,
        );
        return value.unwrap().instruction;
    }

    pub fn callMemSet(
        self: *WipFunction,
        dst: Value,
        dst_align: Alignment,
        val: Value,
        len: Value,
        kind: MemoryAccessKind,
        @"inline": bool,
    ) Allocator.Error!Instruction.Index {
        var dst_attrs = [_]Attribute.Index{try self.builder.attr(.{ .@"align" = .wrap(dst_align) })};
        const value = try self.callIntrinsic(
            .normal,
            try self.builder.fnAttrs(&.{ .none, .none, try self.builder.attrs(&dst_attrs) }),
            if (@"inline") .@"memset.inline" else .memset,
            &.{ dst.typeOfWip(self), len.typeOfWip(self) },
            &.{ dst, val, len, switch (kind) {
                .normal => Value.false,
                .@"volatile" => Value.true,
            } },
            undefined,
        );
        return value.unwrap().instruction;
    }

    pub fn vaArg(self: *WipFunction, list: Value, ty: Type, name: []const u8) Allocator.Error!Value {
        try self.ensureUnusedExtraCapacity(1, Instruction.VaArg, 0);
        const instruction = try self.addInst(name, .{
            .tag = .va_arg,
            .data = self.addExtraAssumeCapacity(Instruction.VaArg{
                .list = list,
                .type = ty,
            }),
        });
        return instruction.toValue();
    }

    pub fn debugValue(self: *WipFunction, value: Value) Allocator.Error!Metadata.Optional {
        if (self.strip) return .none;
        const metadata: Metadata = metadata: switch (value.unwrap()) {
            .instruction => |instr_index| {
                const gop = try self.debug_values.getOrPut(self.builder.gpa, instr_index);
                if (!gop.found_existing) gop.key_ptr.* = instr_index;
                break :metadata .{ .index = @intCast(gop.index), .kind = .local };
            },
            .constant => |constant| try self.builder.metadataConstant(constant),
            .metadata => |metadata| metadata,
        };
        return metadata.toOptional();
    }

    pub fn finish(self: *WipFunction) Allocator.Error!void {
        const gpa = self.builder.gpa;
        const function = self.function.ptr(self.builder);
        const params_len = self.function.typeOf(self.builder).functionParameters(self.builder).len;
        const final_instructions_len = self.blocks.items.len + self.instructions.len;

        const blocks = try gpa.alloc(Function.Block, self.blocks.items.len);
        errdefer gpa.free(blocks);

        const instructions: struct {
            items: []Instruction.Index,

            fn map(instructions: @This(), val: Value) Value {
                if (val == .none) return .none;
                return switch (val.unwrap()) {
                    .instruction => |instruction| instructions.items[
                        @backingInt(instruction)
                    ].toValue(),
                    .constant => |constant| constant.toValue(),
                    .metadata => |metadata| metadata.toValue(),
                };
            }
        } = .{ .items = try gpa.alloc(Instruction.Index, self.instructions.len) };
        defer gpa.free(instructions.items);

        const names = try gpa.alloc(String, final_instructions_len);
        errdefer gpa.free(names);

        const value_indices = try gpa.alloc(u32, final_instructions_len);
        errdefer gpa.free(value_indices);

        var debug_locations: std.AutoHashMapUnmanaged(Instruction.Index, DebugLocation) = .empty;
        errdefer debug_locations.deinit(gpa);
        try debug_locations.ensureUnusedCapacity(gpa, @intCast(self.debug_locations.count()));

        const debug_values = try gpa.alloc(Instruction.Index, self.debug_values.count());
        errdefer gpa.free(debug_values);

        var wip_extra: struct {
            index: Instruction.ExtraIndex = 0,
            items: []u32,

            fn addExtra(wip_extra: *@This(), extra: anytype) Instruction.ExtraIndex {
                const result = wip_extra.index;
                const info = @typeInfo(@TypeOf(extra)).@"struct";
                inline for (info.field_names, info.field_types) |field_name, field_type| {
                    const value = @field(extra, field_name);
                    wip_extra.items[wip_extra.index] = switch (field_type) {
                        u32 => value,
                        Alignment,
                        AtomicOrdering,
                        Block.Index,
                        FunctionAttributes,
                        Type,
                        Value,
                        Instruction.BrCond.Weights,
                        => @backingInt(value),
                        MemoryAccessInfo,
                        Instruction.Alloca.Info,
                        Instruction.Call.Info,
                        => @bitCast(value),
                        else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
                    };
                    wip_extra.index += 1;
                }
                return result;
            }

            fn appendSlice(wip_extra: *@This(), slice: anytype) void {
                if (@typeInfo(@TypeOf(slice)).pointer.child == Value)
                    @compileError("use appendMappedValues");
                const data: []const u32 = @ptrCast(slice);
                @memcpy(wip_extra.items[wip_extra.index..][0..data.len], data);
                wip_extra.index += @intCast(data.len);
            }

            fn appendMappedValues(wip_extra: *@This(), vals: []const Value, ctx: anytype) void {
                for (wip_extra.items[wip_extra.index..][0..vals.len], vals) |*extra, val|
                    extra.* = @backingInt(ctx.map(val));
                wip_extra.index += @intCast(vals.len);
            }

            fn finish(wip_extra: *const @This()) []const u32 {
                assert(wip_extra.index == wip_extra.items.len);
                return wip_extra.items;
            }
        } = .{ .items = try gpa.alloc(u32, self.extra.items.len) };
        errdefer gpa.free(wip_extra.items);

        gpa.free(function.blocks);
        function.blocks = &.{};
        gpa.free(function.names[0..function.instructions.len]);
        function.debug_locations.deinit(gpa);
        function.debug_locations = .empty;
        gpa.free(function.debug_values);
        function.debug_values = &.{};
        gpa.free(function.extra);
        function.extra = &.{};

        function.instructions.shrinkRetainingCapacity(0);
        try function.instructions.setCapacity(gpa, final_instructions_len);
        errdefer function.instructions.shrinkRetainingCapacity(0);

        {
            var final_instruction_index: Instruction.Index = @fromBackingInt(0);
            for (0..params_len) |param_index| {
                instructions.items[param_index] = final_instruction_index;
                final_instruction_index = @fromBackingInt(@backingInt(final_instruction_index) + 1);
            }
            for (blocks, self.blocks.items) |*final_block, current_block| {
                assert(current_block.incoming == current_block.branches);
                final_block.instruction = final_instruction_index;
                final_instruction_index = @fromBackingInt(@backingInt(final_instruction_index) + 1);
                for (current_block.instructions.items) |instruction| {
                    instructions.items[@backingInt(instruction)] = final_instruction_index;
                    final_instruction_index = @fromBackingInt(@backingInt(final_instruction_index) + 1);
                }
            }
        }

        var wip_name: struct {
            next_name: String = @fromBackingInt(0),
            next_unique_name: std.AutoHashMap(String, String),
            builder: *Builder,

            fn map(wip_name: *@This(), name: String, sep: []const u8) Allocator.Error!String {
                switch (name) {
                    .none => return .none,
                    .empty => {
                        assert(wip_name.next_name != .none);
                        defer wip_name.next_name = @fromBackingInt(@backingInt(wip_name.next_name) + 1);
                        return wip_name.next_name;
                    },
                    _ => {
                        assert(!name.isAnon());
                        const gop = try wip_name.next_unique_name.getOrPut(name);
                        if (!gop.found_existing) {
                            gop.value_ptr.* = @fromBackingInt(0);
                            return name;
                        }

                        while (true) {
                            gop.value_ptr.* = @fromBackingInt(@backingInt(gop.value_ptr.*) + 1);
                            const unique_name = try wip_name.builder.fmt("{f}{s}{f}", .{
                                name.fmtRaw(wip_name.builder),
                                sep,
                                gop.value_ptr.fmtRaw(wip_name.builder),
                            });
                            const unique_gop = try wip_name.next_unique_name.getOrPut(unique_name);
                            if (!unique_gop.found_existing) {
                                unique_gop.value_ptr.* = @fromBackingInt(0);
                                return unique_name;
                            }
                        }
                    },
                }
            }
        } = .{
            .next_unique_name = std.AutoHashMap(String, String).init(gpa),
            .builder = self.builder,
        };
        defer wip_name.next_unique_name.deinit();

        var value_index: u32 = 0;
        for (0..params_len) |param_index| {
            const old_argument_index: Instruction.Index = @fromBackingInt(@intCast(param_index));
            const new_argument_index: Instruction.Index = @fromBackingInt(@intCast(function.instructions.len));
            const argument = self.instructions.get(@backingInt(old_argument_index));
            assert(argument.tag == .arg);
            assert(argument.data == param_index);
            value_indices[function.instructions.len] = value_index;
            value_index += 1;
            function.instructions.appendAssumeCapacity(argument);
            names[@backingInt(new_argument_index)] = try wip_name.map(
                if (self.strip) .empty else self.names.items[@backingInt(old_argument_index)],
                ".",
            );
            if (self.debug_locations.get(old_argument_index)) |location| {
                debug_locations.putAssumeCapacity(new_argument_index, location);
            }
            if (self.debug_values.getIndex(old_argument_index)) |index| {
                debug_values[index] = new_argument_index;
            }
        }
        for (self.blocks.items) |current_block| {
            const new_block_index: Instruction.Index = @fromBackingInt(@intCast(function.instructions.len));
            value_indices[function.instructions.len] = value_index;
            function.instructions.appendAssumeCapacity(.{
                .tag = .block,
                .data = current_block.incoming,
            });
            names[@backingInt(new_block_index)] = try wip_name.map(current_block.name, "");
            for (current_block.instructions.items) |old_instruction_index| {
                const new_instruction_index: Instruction.Index = @fromBackingInt(@intCast(function.instructions.len));
                var instruction = self.instructions.get(@backingInt(old_instruction_index));
                switch (instruction.tag) {
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .@"add nuw nsw",
                    .@"and",
                    .ashr,
                    .@"ashr exact",
                    .fadd,
                    .@"fadd fast",
                    .@"fcmp false",
                    .@"fcmp fast false",
                    .@"fcmp fast oeq",
                    .@"fcmp fast oge",
                    .@"fcmp fast ogt",
                    .@"fcmp fast ole",
                    .@"fcmp fast olt",
                    .@"fcmp fast one",
                    .@"fcmp fast ord",
                    .@"fcmp fast true",
                    .@"fcmp fast ueq",
                    .@"fcmp fast uge",
                    .@"fcmp fast ugt",
                    .@"fcmp fast ule",
                    .@"fcmp fast ult",
                    .@"fcmp fast une",
                    .@"fcmp fast uno",
                    .@"fcmp oeq",
                    .@"fcmp oge",
                    .@"fcmp ogt",
                    .@"fcmp ole",
                    .@"fcmp olt",
                    .@"fcmp one",
                    .@"fcmp ord",
                    .@"fcmp true",
                    .@"fcmp ueq",
                    .@"fcmp uge",
                    .@"fcmp ugt",
                    .@"fcmp ule",
                    .@"fcmp ult",
                    .@"fcmp une",
                    .@"fcmp uno",
                    .fdiv,
                    .@"fdiv fast",
                    .fmul,
                    .@"fmul fast",
                    .frem,
                    .@"frem fast",
                    .fsub,
                    .@"fsub fast",
                    .@"icmp eq",
                    .@"icmp ne",
                    .@"icmp sge",
                    .@"icmp sgt",
                    .@"icmp sle",
                    .@"icmp slt",
                    .@"icmp uge",
                    .@"icmp ugt",
                    .@"icmp ule",
                    .@"icmp ult",
                    .lshr,
                    .@"lshr exact",
                    .mul,
                    .@"mul nsw",
                    .@"mul nuw",
                    .@"mul nuw nsw",
                    .@"or",
                    .sdiv,
                    .@"sdiv exact",
                    .shl,
                    .@"shl nsw",
                    .@"shl nuw",
                    .@"shl nuw nsw",
                    .srem,
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .@"sub nuw nsw",
                    .udiv,
                    .@"udiv exact",
                    .urem,
                    .xor,
                    => {
                        const extra = self.extraData(Instruction.Binary, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.Binary{
                            .lhs = instructions.map(extra.lhs),
                            .rhs = instructions.map(extra.rhs),
                        });
                    },
                    .addrspacecast,
                    .bitcast,
                    .fpext,
                    .fptosi,
                    .fptoui,
                    .fptrunc,
                    .inttoptr,
                    .ptrtoint,
                    .sext,
                    .sitofp,
                    .trunc,
                    .@"trunc nuw",
                    .@"trunc nsw",
                    .@"trunc nuw nsw",
                    .uitofp,
                    .zext,
                    => {
                        const extra = self.extraData(Instruction.Cast, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.Cast{
                            .val = instructions.map(extra.val),
                            .type = extra.type,
                        });
                    },
                    .alloca,
                    .@"alloca inalloca",
                    => {
                        const extra = self.extraData(Instruction.Alloca, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.Alloca{
                            .type = extra.type,
                            .len = instructions.map(extra.len),
                            .info = extra.info,
                        });
                    },
                    .arg,
                    .block,
                    => unreachable,
                    .atomicrmw => {
                        const extra = self.extraData(Instruction.AtomicRmw, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.AtomicRmw{
                            .info = extra.info,
                            .ptr = instructions.map(extra.ptr),
                            .val = instructions.map(extra.val),
                        });
                    },
                    .br,
                    .fence,
                    .@"ret void",
                    .@"unreachable",
                    => {},
                    .br_cond => {
                        const extra = self.extraData(Instruction.BrCond, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.BrCond{
                            .cond = instructions.map(extra.cond),
                            .then = extra.then,
                            .@"else" = extra.@"else",
                            .weights = extra.weights,
                        });
                    },
                    .call,
                    .@"call fast",
                    .@"musttail call",
                    .@"musttail call fast",
                    .@"notail call",
                    .@"notail call fast",
                    .@"tail call",
                    .@"tail call fast",
                    => {
                        var extra = self.extraDataTrail(Instruction.Call, instruction.data);
                        const args = extra.trail.next(extra.data.args_len, Value, self);
                        instruction.data = wip_extra.addExtra(Instruction.Call{
                            .info = extra.data.info,
                            .attributes = extra.data.attributes,
                            .ty = extra.data.ty,
                            .callee = instructions.map(extra.data.callee),
                            .args_len = extra.data.args_len,
                        });
                        wip_extra.appendMappedValues(args, instructions);
                    },
                    .cmpxchg,
                    .@"cmpxchg weak",
                    => {
                        const extra = self.extraData(Instruction.CmpXchg, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.CmpXchg{
                            .info = extra.info,
                            .ptr = instructions.map(extra.ptr),
                            .cmp = instructions.map(extra.cmp),
                            .new = instructions.map(extra.new),
                        });
                    },
                    .extractelement => {
                        const extra = self.extraData(Instruction.ExtractElement, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.ExtractElement{
                            .val = instructions.map(extra.val),
                            .index = instructions.map(extra.index),
                        });
                    },
                    .extractvalue => {
                        var extra = self.extraDataTrail(Instruction.ExtractValue, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, u32, self);
                        instruction.data = wip_extra.addExtra(Instruction.ExtractValue{
                            .val = instructions.map(extra.data.val),
                            .indices_len = extra.data.indices_len,
                        });
                        wip_extra.appendSlice(indices);
                    },
                    .fneg,
                    .@"fneg fast",
                    .ret,
                    => instruction.data = @backingInt(instructions.map(@fromBackingInt(instruction.data))),
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => {
                        var extra = self.extraDataTrail(Instruction.GetElementPtr, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, Value, self);
                        instruction.data = wip_extra.addExtra(Instruction.GetElementPtr{
                            .type = extra.data.type,
                            .base = instructions.map(extra.data.base),
                            .indices_len = extra.data.indices_len,
                        });
                        wip_extra.appendMappedValues(indices, instructions);
                    },
                    .indirectbr => {
                        var extra = self.extraDataTrail(Instruction.IndirectBr, instruction.data);
                        const targets = extra.trail.next(extra.data.targets_len, Block.Index, self);
                        instruction.data = wip_extra.addExtra(Instruction.IndirectBr{
                            .addr = instructions.map(extra.data.addr),
                            .targets_len = extra.data.targets_len,
                        });
                        wip_extra.appendSlice(targets);
                    },
                    .insertelement => {
                        const extra = self.extraData(Instruction.InsertElement, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.InsertElement{
                            .val = instructions.map(extra.val),
                            .elem = instructions.map(extra.elem),
                            .index = instructions.map(extra.index),
                        });
                    },
                    .insertvalue => {
                        var extra = self.extraDataTrail(Instruction.InsertValue, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, u32, self);
                        instruction.data = wip_extra.addExtra(Instruction.InsertValue{
                            .val = instructions.map(extra.data.val),
                            .elem = instructions.map(extra.data.elem),
                            .indices_len = extra.data.indices_len,
                        });
                        wip_extra.appendSlice(indices);
                    },
                    .load,
                    .@"load atomic",
                    => {
                        const extra = self.extraData(Instruction.Load, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.Load{
                            .type = extra.type,
                            .ptr = instructions.map(extra.ptr),
                            .info = extra.info,
                        });
                    },
                    .phi,
                    .@"phi fast",
                    => {
                        const incoming_len = current_block.incoming;
                        var extra = self.extraDataTrail(Instruction.Phi, instruction.data);
                        const incoming_vals = extra.trail.next(incoming_len, Value, self);
                        const incoming_blocks = extra.trail.next(incoming_len, Block.Index, self);
                        instruction.data = wip_extra.addExtra(Instruction.Phi{
                            .type = extra.data.type,
                        });
                        wip_extra.appendMappedValues(incoming_vals, instructions);
                        wip_extra.appendSlice(incoming_blocks);
                    },
                    .select,
                    .@"select fast",
                    => {
                        const extra = self.extraData(Instruction.Select, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.Select{
                            .cond = instructions.map(extra.cond),
                            .lhs = instructions.map(extra.lhs),
                            .rhs = instructions.map(extra.rhs),
                        });
                    },
                    .shufflevector => {
                        const extra = self.extraData(Instruction.ShuffleVector, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.ShuffleVector{
                            .lhs = instructions.map(extra.lhs),
                            .rhs = instructions.map(extra.rhs),
                            .mask = instructions.map(extra.mask),
                        });
                    },
                    .store,
                    .@"store atomic",
                    => {
                        const extra = self.extraData(Instruction.Store, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.Store{
                            .val = instructions.map(extra.val),
                            .ptr = instructions.map(extra.ptr),
                            .info = extra.info,
                        });
                    },
                    .@"switch" => {
                        var extra = self.extraDataTrail(Instruction.Switch, instruction.data);
                        const case_vals = extra.trail.next(extra.data.cases_len, Constant, self);
                        const case_blocks = extra.trail.next(extra.data.cases_len, Block.Index, self);
                        instruction.data = wip_extra.addExtra(Instruction.Switch{
                            .val = instructions.map(extra.data.val),
                            .default = extra.data.default,
                            .cases_len = extra.data.cases_len,
                            .weights = extra.data.weights,
                        });
                        wip_extra.appendSlice(case_vals);
                        wip_extra.appendSlice(case_blocks);
                    },
                    .va_arg => {
                        const extra = self.extraData(Instruction.VaArg, instruction.data);
                        instruction.data = wip_extra.addExtra(Instruction.VaArg{
                            .list = instructions.map(extra.list),
                            .type = extra.type,
                        });
                    },
                }
                function.instructions.appendAssumeCapacity(instruction);
                names[@backingInt(new_instruction_index)] = try wip_name.map(if (self.strip)
                    if (old_instruction_index.hasResultWip(self)) .empty else .none
                else
                    self.names.items[@backingInt(old_instruction_index)], ".");

                if (self.debug_locations.get(old_instruction_index)) |location| {
                    debug_locations.putAssumeCapacity(new_instruction_index, location);
                }

                if (self.debug_values.getIndex(old_instruction_index)) |index| {
                    debug_values[index] = new_instruction_index;
                }

                value_indices[@backingInt(new_instruction_index)] = value_index;
                if (old_instruction_index.hasResultWip(self)) value_index += 1;
            }
        }

        assert(function.instructions.len == final_instructions_len);
        function.extra = wip_extra.finish();
        function.blocks = blocks;
        function.names = names.ptr;
        function.value_indices = value_indices.ptr;
        function.strip = self.strip;
        function.debug_locations = debug_locations;
        function.debug_values = debug_values;
    }

    pub fn deinit(self: *WipFunction) void {
        self.extra.deinit(self.builder.gpa);
        self.debug_values.deinit(self.builder.gpa);
        self.debug_locations.deinit(self.builder.gpa);
        self.names.deinit(self.builder.gpa);
        self.instructions.deinit(self.builder.gpa);
        for (self.blocks.items) |*b| b.instructions.deinit(self.builder.gpa);
        self.blocks.deinit(self.builder.gpa);
        self.* = undefined;
    }

    fn cmpTag(
        self: *WipFunction,
        tag: Instruction.Tag,
        lhs: Value,
        rhs: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        switch (tag) {
            .@"fcmp false",
            .@"fcmp fast false",
            .@"fcmp fast oeq",
            .@"fcmp fast oge",
            .@"fcmp fast ogt",
            .@"fcmp fast ole",
            .@"fcmp fast olt",
            .@"fcmp fast one",
            .@"fcmp fast ord",
            .@"fcmp fast true",
            .@"fcmp fast ueq",
            .@"fcmp fast uge",
            .@"fcmp fast ugt",
            .@"fcmp fast ule",
            .@"fcmp fast ult",
            .@"fcmp fast une",
            .@"fcmp fast uno",
            .@"fcmp oeq",
            .@"fcmp oge",
            .@"fcmp ogt",
            .@"fcmp ole",
            .@"fcmp olt",
            .@"fcmp one",
            .@"fcmp ord",
            .@"fcmp true",
            .@"fcmp ueq",
            .@"fcmp uge",
            .@"fcmp ugt",
            .@"fcmp ule",
            .@"fcmp ult",
            .@"fcmp une",
            .@"fcmp uno",
            .@"icmp eq",
            .@"icmp ne",
            .@"icmp sge",
            .@"icmp sgt",
            .@"icmp sle",
            .@"icmp slt",
            .@"icmp uge",
            .@"icmp ugt",
            .@"icmp ule",
            .@"icmp ult",
            => assert(lhs.typeOfWip(self) == rhs.typeOfWip(self)),
            else => unreachable,
        }
        _ = try lhs.typeOfWip(self).changeScalar(.i1, self.builder);
        try self.ensureUnusedExtraCapacity(1, Instruction.Binary, 0);
        const instruction = try self.addInst(name, .{
            .tag = tag,
            .data = self.addExtraAssumeCapacity(Instruction.Binary{
                .lhs = lhs,
                .rhs = rhs,
            }),
        });
        return instruction.toValue();
    }

    fn phiTag(
        self: *WipFunction,
        tag: Instruction.Tag,
        ty: Type,
        name: []const u8,
    ) Allocator.Error!WipPhi {
        switch (tag) {
            .phi, .@"phi fast" => assert(try ty.isSized(self.builder)),
            else => unreachable,
        }
        const incoming = self.cursor.block.ptrConst(self).incoming;
        assert(incoming > 0);
        try self.ensureUnusedExtraCapacity(1, Instruction.Phi, incoming * 2);
        const instruction = try self.addInst(name, .{
            .tag = tag,
            .data = self.addExtraAssumeCapacity(Instruction.Phi{ .type = ty }),
        });
        _ = self.extra.addManyAsSliceAssumeCapacity(incoming * 2);
        return .{ .block = self.cursor.block, .instruction = instruction };
    }

    fn selectTag(
        self: *WipFunction,
        tag: Instruction.Tag,
        cond: Value,
        lhs: Value,
        rhs: Value,
        name: []const u8,
    ) Allocator.Error!Value {
        switch (tag) {
            .select, .@"select fast" => {
                assert(cond.typeOfWip(self).scalarType(self.builder) == .i1);
                assert(lhs.typeOfWip(self) == rhs.typeOfWip(self));
            },
            else => unreachable,
        }
        try self.ensureUnusedExtraCapacity(1, Instruction.Select, 0);
        const instruction = try self.addInst(name, .{
            .tag = tag,
            .data = self.addExtraAssumeCapacity(Instruction.Select{
                .cond = cond,
                .lhs = lhs,
                .rhs = rhs,
            }),
        });
        return instruction.toValue();
    }

    fn ensureUnusedExtraCapacity(
        self: *WipFunction,
        count: usize,
        comptime Extra: type,
        trail_len: usize,
    ) Allocator.Error!void {
        try self.extra.ensureUnusedCapacity(
            self.builder.gpa,
            count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
        );
    }

    fn addInst(
        self: *WipFunction,
        name: ?[]const u8,
        instruction: Instruction,
    ) Allocator.Error!Instruction.Index {
        const block_instructions = &self.cursor.block.ptr(self).instructions;
        try self.instructions.ensureUnusedCapacity(self.builder.gpa, 1);
        if (!self.strip) {
            try self.names.ensureUnusedCapacity(self.builder.gpa, 1);
            try self.debug_locations.ensureUnusedCapacity(self.builder.gpa, 1);
        }
        try block_instructions.ensureUnusedCapacity(self.builder.gpa, 1);
        const final_name = if (name) |n|
            if (self.strip) .empty else try self.builder.string(n)
        else
            .none;

        const index: Instruction.Index = @fromBackingInt(@intCast(self.instructions.len));
        self.instructions.appendAssumeCapacity(instruction);
        if (!self.strip) {
            self.names.appendAssumeCapacity(final_name);
            if (block_instructions.items.len == 0 or
                !std.meta.eql(self.debug_location, self.prev_debug_location))
            {
                self.debug_locations.putAssumeCapacity(index, self.debug_location);
                self.prev_debug_location = self.debug_location;
            }
        }
        block_instructions.insertAssumeCapacity(self.cursor.instruction, index);
        self.cursor.instruction += 1;
        return index;
    }

    fn addExtraAssumeCapacity(self: *WipFunction, extra: anytype) Instruction.ExtraIndex {
        const result: Instruction.ExtraIndex = @intCast(self.extra.items.len);
        const info = @typeInfo(@TypeOf(extra)).@"struct";
        inline for (info.field_names, info.field_types) |field_name, field_type| {
            const value = @field(extra, field_name);
            self.extra.appendAssumeCapacity(switch (field_type) {
                u32 => value,
                Alignment,
                AtomicOrdering,
                Block.Index,
                FunctionAttributes,
                Type,
                Value,
                Instruction.BrCond.Weights,
                => @backingInt(value),
                MemoryAccessInfo,
                Instruction.Alloca.Info,
                Instruction.Call.Info,
                => @bitCast(value),
                else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
            });
        }
        return result;
    }

    const ExtraDataTrail = struct {
        index: Instruction.ExtraIndex,

        fn nextMut(self: *ExtraDataTrail, len: u32, comptime Item: type, wip: *WipFunction) []Item {
            const items: []Item = @ptrCast(wip.extra.items[self.index..][0..len]);
            self.index += @intCast(len);
            return items;
        }

        fn next(
            self: *ExtraDataTrail,
            len: u32,
            comptime Item: type,
            wip: *const WipFunction,
        ) []const Item {
            const items: []const Item = @ptrCast(wip.extra.items[self.index..][0..len]);
            self.index += @intCast(len);
            return items;
        }
    };

    fn extraDataTrail(
        self: *const WipFunction,
        comptime T: type,
        index: Instruction.ExtraIndex,
    ) struct { data: T, trail: ExtraDataTrail } {
        var result: T = undefined;
        const info = @typeInfo(T).@"struct";
        inline for (
            info.field_names,
            info.field_types,
            self.extra.items[index..][0..info.field_names.len],
        ) |field_name, field_type, value|
            @field(result, field_name) = switch (field_type) {
                u32 => value,
                Alignment,
                AtomicOrdering,
                Block.Index,
                FunctionAttributes,
                Type,
                Value,
                Instruction.BrCond.Weights,
                => @fromBackingInt(value),
                MemoryAccessInfo,
                Instruction.Alloca.Info,
                Instruction.Call.Info,
                => @bitCast(value),
                else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
            };
        return .{
            .data = result,
            .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(info.field_names.len)) },
        };
    }

    fn extraData(self: *const WipFunction, comptime T: type, index: Instruction.ExtraIndex) T {
        return self.extraDataTrail(T, index).data;
    }
};

pub const FloatCondition = enum(u4) {
    oeq = 1,
    ogt = 2,
    oge = 3,
    olt = 4,
    ole = 5,
    one = 6,
    ord = 7,
    uno = 8,
    ueq = 9,
    ugt = 10,
    uge = 11,
    ult = 12,
    ule = 13,
    une = 14,
};

pub const IntegerCondition = enum(u6) {
    eq = 32,
    ne = 33,
    ugt = 34,
    uge = 35,
    ult = 36,
    ule = 37,
    sgt = 38,
    sge = 39,
    slt = 40,
    sle = 41,
};

pub const MemoryAccessKind = enum(u1) {
    normal,
    @"volatile",

    pub fn format(memory_access_kind: MemoryAccessKind, w: *Writer) Writer.Error!void {
        return Prefixed.format(.{ .memory_access_kind = memory_access_kind, .prefix = "" }, w);
    }

    pub const Prefixed = struct {
        memory_access_kind: MemoryAccessKind,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            switch (p.memory_access_kind) {
                .normal => return,
                .@"volatile" => {
                    var vecs: [2][]const u8 = .{ p.prefix, "volatile" };
                    return w.writeVecAll(&vecs);
                },
            }
        }
    };

    pub fn fmt(memory_access_kind: MemoryAccessKind, prefix: []const u8) Prefixed {
        return .{ .memory_access_kind = memory_access_kind, .prefix = prefix };
    }
};

pub const SyncScope = enum(u1) {
    singlethread,
    system,

    pub fn format(sync_scope: SyncScope, w: *Writer) Writer.Error!void {
        return Prefixed.format(.{ .sync_scope = sync_scope, .prefix = "" }, w);
    }

    pub const Prefixed = struct {
        sync_scope: SyncScope,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            switch (p.sync_scope) {
                .system => return,
                .singlethread => {
                    var vecs: [2][]const u8 = .{ p.prefix, "syncscope(\"singlethread\")" };
                    return w.writeVecAll(&vecs);
                },
            }
        }
    };

    pub fn fmt(sync_scope: SyncScope, prefix: []const u8) Prefixed {
        return .{ .sync_scope = sync_scope, .prefix = prefix };
    }
};

pub const AtomicOrdering = enum(u3) {
    none = 0,
    unordered = 1,
    monotonic = 2,
    acquire = 3,
    release = 4,
    acq_rel = 5,
    seq_cst = 6,

    pub fn format(atomic_ordering: AtomicOrdering, w: *Writer) Writer.Error!void {
        return Prefixed.format(.{ .atomic_ordering = atomic_ordering, .prefix = "" }, w);
    }

    pub const Prefixed = struct {
        atomic_ordering: AtomicOrdering,
        prefix: []const u8,

        pub fn format(p: Prefixed, w: *Writer) Writer.Error!void {
            switch (p.atomic_ordering) {
                .none => return,
                else => {
                    var vecs: [2][]const u8 = .{ p.prefix, @tagName(p.atomic_ordering) };
                    return w.writeVecAll(&vecs);
                },
            }
        }
    };

    pub fn fmt(atomic_ordering: AtomicOrdering, prefix: []const u8) Prefixed {
        return .{ .atomic_ordering = atomic_ordering, .prefix = prefix };
    }
};

const MemoryAccessInfo = packed struct(u32) {
    access_kind: MemoryAccessKind = .normal,
    atomic_rmw_operation: Function.Instruction.AtomicRmw.Operation = .none,
    sync_scope: SyncScope,
    success_ordering: AtomicOrdering,
    failure_ordering: AtomicOrdering = .none,
    alignment: Alignment = .default,
    _: u13 = undefined,
};

pub const FastMath = packed struct(u8) {
    unsafe_algebra: bool = false, // 旧版
    nnan: bool = false,
    ninf: bool = false,
    nsz: bool = false,
    arcp: bool = false,
    contract: bool = false,
    afn: bool = false,
    reassoc: bool = false,

    pub const fast = FastMath{
        .nnan = true,
        .ninf = true,
        .nsz = true,
        .arcp = true,
        .contract = true,
        .afn = true,
        .reassoc = true,
    };
};

pub const FastMathKind = enum {
    normal,
    fast,

    pub fn toCallKind(self: FastMathKind) Function.Instruction.Call.Kind {
        return switch (self) {
            .normal => .normal,
            .fast => .fast,
        };
    }
};

pub const Constant = enum(u32) {
    false,
    true,
    @"0",
    @"1",
    none,
    no_init = (1 << 30) - 1,
    _,

    const first_global: Constant = @fromBackingInt(1 << 29);

    pub const Tag = enum(u7) {
        positive_integer,
        negative_integer,
        half,
        bfloat,
        float,
        double,
        fp128,
        x86_fp80,
        ppc_fp128,
        null,
        none,
        structure,
        packed_structure,
        array,
        string,
        vector,
        splat,
        zeroinitializer,
        undef,
        poison,
        blockaddress,
        dso_local_equivalent,
        no_cfi,
        trunc,
        ptrtoint,
        inttoptr,
        bitcast,
        addrspacecast,
        getelementptr,
        @"getelementptr inbounds",
        add,
        @"add nsw",
        @"add nuw",
        sub,
        @"sub nsw",
        @"sub nuw",
        shl,
        xor,
        @"asm",
        @"asm sideeffect",
        @"asm alignstack",
        @"asm sideeffect alignstack",
        @"asm inteldialect",
        @"asm sideeffect inteldialect",
        @"asm alignstack inteldialect",
        @"asm sideeffect alignstack inteldialect",
        @"asm unwind",
        @"asm sideeffect unwind",
        @"asm alignstack unwind",
        @"asm sideeffect alignstack unwind",
        @"asm inteldialect unwind",
        @"asm sideeffect inteldialect unwind",
        @"asm alignstack inteldialect unwind",
        @"asm sideeffect alignstack inteldialect unwind",

        pub fn toBinaryOpcode(self: Tag) BinaryOpcode {
            return switch (self) {
                .add,
                .@"add nsw",
                .@"add nuw",
                => .add,
                .sub,
                .@"sub nsw",
                .@"sub nuw",
                => .sub,
                .shl => .shl,
                .xor => .xor,
                else => unreachable,
            };
        }

        pub fn toCastOpcode(self: Tag) CastOpcode {
            return switch (self) {
                .trunc => .trunc,
                .ptrtoint => .ptrtoint,
                .inttoptr => .inttoptr,
                .bitcast => .bitcast,
                .addrspacecast => .addrspacecast,
                else => unreachable,
            };
        }
    };

    pub const Item = struct {
        tag: Tag,
        data: ExtraIndex,

        const ExtraIndex = u32;
    };

    pub const Integer = packed struct(u64) {
        type: Type,
        limbs_len: u32,

        pub const limbs = @divExact(@bitSizeOf(Integer), @bitSizeOf(std.math.big.Limb));
    };

    pub const Double = struct {
        lo: u32,
        hi: u32,
    };

    pub const Fp80 = struct {
        lo_lo: u32,
        lo_hi: u32,
        hi: u32,
    };

    pub const Fp128 = struct {
        lo_lo: u32,
        lo_hi: u32,
        hi_lo: u32,
        hi_hi: u32,
    };

    pub const Aggregate = struct {
        type: Type,
        // fields: [type.aggregateLen(builder)]Constant,
    };

    pub const Splat = extern struct {
        type: Type,
        value: Constant,
    };

    pub const BlockAddress = extern struct {
        function: Function.Index,
        block: Function.Block.Index,
    };

    pub const Cast = extern struct {
        val: Constant,
        type: Type,

        pub const Signedness = enum {
            unsigned,
            signed,
            unneeded,

            pub fn fromStdLang(signedness: std.lang.Signedness) Signedness {
                return switch (signedness) {
                    .unsigned => .unsigned,
                    .signed => .signed,
                };
            }
        };
    };

    pub const GetElementPtr = struct {
        type: Type,
        base: Constant,
        info: Info,
        // indices: [info.indices_len]Constant,

        pub const Kind = enum { normal, inbounds };
        pub const InRangeIndex = enum(u16) { none = maxInt(u16), _ };
        pub const Info = packed struct(u32) { indices_len: u16, inrange: InRangeIndex };
    };

    pub const Binary = extern struct {
        lhs: Constant,
        rhs: Constant,
    };

    pub const Assembly = extern struct {
        type: Type,
        assembly: String,
        constraints: String,

        pub const Info = packed struct {
            sideeffect: bool = false,
            alignstack: bool = false,
            inteldialect: bool = false,
            unwind: bool = false,
        };
    };

    pub fn unwrap(self: Constant) union(enum) {
        constant: u30,
        global: Global.Index,
    } {
        return if (@backingInt(self) < @backingInt(first_global))
            .{ .constant = @intCast(@backingInt(self)) }
        else
            .{ .global = @fromBackingInt(@backingInt(self) - @backingInt(first_global)) };
    }

    pub fn toValue(self: Constant) Value {
        return @fromBackingInt(Value.first_constant + @backingInt(self));
    }

    pub fn typeOf(self: Constant, builder: *Builder) Type {
        switch (self.unwrap()) {
            .constant => |constant| {
                const item = builder.constant_items.get(constant);
                return switch (item.tag) {
                    .positive_integer,
                    .negative_integer,
                    => @as(
                        *align(@alignOf(std.math.big.Limb)) Integer,
                        @ptrCast(builder.constant_limbs.items[item.data..][0..Integer.limbs]),
                    ).type,
                    .half => .half,
                    .bfloat => .bfloat,
                    .float => .float,
                    .double => .double,
                    .fp128 => .fp128,
                    .x86_fp80 => .x86_fp80,
                    .ppc_fp128 => .ppc_fp128,
                    .null,
                    .none,
                    .zeroinitializer,
                    .undef,
                    .poison,
                    => @fromBackingInt(item.data),
                    .structure,
                    .packed_structure,
                    .array,
                    .vector,
                    => builder.constantExtraData(Aggregate, item.data).type,
                    .splat => builder.constantExtraData(Splat, item.data).type,
                    .string => builder.arrayTypeAssumeCapacity(
                        @as(String, @fromBackingInt(item.data)).slice(builder).?.len,
                        .i8,
                    ),
                    .blockaddress => builder.ptrTypeAssumeCapacity(
                        builder.constantExtraData(BlockAddress, item.data)
                            .function.ptrConst(builder).global.ptrConst(builder).addr_space,
                    ),
                    .dso_local_equivalent,
                    .no_cfi,
                    => builder.ptrTypeAssumeCapacity(@as(Function.Index, @fromBackingInt(item.data))
                        .ptrConst(builder).global.ptrConst(builder).addr_space),
                    .trunc,
                    .ptrtoint,
                    .inttoptr,
                    .bitcast,
                    .addrspacecast,
                    => builder.constantExtraData(Cast, item.data).type,
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => {
                        var extra = builder.constantExtraDataTrail(GetElementPtr, item.data);
                        const indices =
                            extra.trail.next(extra.data.info.indices_len, Constant, builder);
                        const base_ty = extra.data.base.typeOf(builder);
                        if (!base_ty.isVector(builder)) for (indices) |index| {
                            const index_ty = index.typeOf(builder);
                            if (!index_ty.isVector(builder)) continue;
                            return index_ty.changeScalarAssumeCapacity(base_ty, builder);
                        };
                        return base_ty;
                    },
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .shl,
                    .xor,
                    => builder.constantExtraData(Binary, item.data).lhs.typeOf(builder),
                    .@"asm",
                    .@"asm sideeffect",
                    .@"asm alignstack",
                    .@"asm sideeffect alignstack",
                    .@"asm inteldialect",
                    .@"asm sideeffect inteldialect",
                    .@"asm alignstack inteldialect",
                    .@"asm sideeffect alignstack inteldialect",
                    .@"asm unwind",
                    .@"asm sideeffect unwind",
                    .@"asm alignstack unwind",
                    .@"asm sideeffect alignstack unwind",
                    .@"asm inteldialect unwind",
                    .@"asm sideeffect inteldialect unwind",
                    .@"asm alignstack inteldialect unwind",
                    .@"asm sideeffect alignstack inteldialect unwind",
                    => .ptr,
                };
            },
            .global => |global| return builder.ptrTypeAssumeCapacity(
                global.ptrConst(builder).addr_space,
            ),
        }
    }

    pub fn isZeroInit(self: Constant, builder: *const Builder) bool {
        switch (self.unwrap()) {
            .constant => |constant| {
                const item = builder.constant_items.get(constant);
                return switch (item.tag) {
                    .positive_integer => {
                        const extra: *align(@alignOf(std.math.big.Limb)) Integer =
                            @ptrCast(builder.constant_limbs.items[item.data..][0..Integer.limbs]);
                        const limbs = builder.constant_limbs
                            .items[item.data + Integer.limbs ..][0..extra.limbs_len];
                        return std.mem.eql(std.math.big.Limb, limbs, &.{0});
                    },
                    .half, .bfloat, .float => item.data == 0,
                    .double => {
                        const extra = builder.constantExtraData(Constant.Double, item.data);
                        return extra.lo == 0 and extra.hi == 0;
                    },
                    .fp128, .ppc_fp128 => {
                        const extra = builder.constantExtraData(Constant.Fp128, item.data);
                        return extra.lo_lo == 0 and extra.lo_hi == 0 and
                            extra.hi_lo == 0 and extra.hi_hi == 0;
                    },
                    .x86_fp80 => {
                        const extra = builder.constantExtraData(Constant.Fp80, item.data);
                        return extra.lo_lo == 0 and extra.lo_hi == 0 and extra.hi == 0;
                    },
                    .vector => {
                        var extra = builder.constantExtraDataTrail(Aggregate, item.data);
                        const len: u32 = @intCast(extra.data.type.aggregateLen(builder));
                        const vals = extra.trail.next(len, Constant, builder);
                        for (vals) |val| if (!val.isZeroInit(builder)) return false;
                        return true;
                    },
                    .null, .zeroinitializer => true,
                    else => false,
                };
            },
            .global => return false,
        }
    }

    pub fn getBase(self: Constant, builder: *const Builder) Global.Index {
        var cur = self;
        while (true) switch (cur.unwrap()) {
            .constant => |constant| {
                const item = builder.constant_items.get(constant);
                switch (item.tag) {
                    .ptrtoint,
                    .inttoptr,
                    .bitcast,
                    => cur = builder.constantExtraData(Cast, item.data).val,
                    .getelementptr => cur = builder.constantExtraData(GetElementPtr, item.data).base,
                    .add => {
                        const extra = builder.constantExtraData(Binary, item.data);
                        const lhs_base = extra.lhs.getBase(builder);
                        const rhs_base = extra.rhs.getBase(builder);
                        return if (lhs_base != .none and rhs_base != .none)
                            .none
                        else if (lhs_base != .none) lhs_base else rhs_base;
                    },
                    .sub => {
                        const extra = builder.constantExtraData(Binary, item.data);
                        if (extra.rhs.getBase(builder) != .none) return .none;
                        cur = extra.lhs;
                    },
                    else => return .none,
                }
            },
            .global => |global| switch (global.ptrConst(builder).kind) {
                .alias => |alias| cur = alias.ptrConst(builder).aliasee,
                .variable, .function => return global,
                .replaced => unreachable,
            },
        };
    }

    const FormatData = struct {
        constant: Constant,
        builder: *Builder,
        flags: FormatFlags,
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        if (data.flags.comma) {
            if (data.constant == .no_init) return;
            try w.writeByte(',');
        }
        if (data.flags.space) {
            if (data.constant == .no_init) return;
            try w.writeByte(' ');
        }
        if (data.flags.percent)
            try w.print("{f} ", .{data.constant.typeOf(data.builder).fmt(data.builder, .percent)});
        assert(data.constant != .no_init);
        if (std.enums.tagName(Constant, data.constant)) |name| return w.writeAll(name);
        switch (data.constant.unwrap()) {
            .constant => |constant| {
                const item = data.builder.constant_items.get(constant);
                switch (item.tag) {
                    .positive_integer,
                    .negative_integer,
                    => |tag| {
                        const extra: *align(@alignOf(std.math.big.Limb)) const Integer =
                            @ptrCast(data.builder.constant_limbs.items[item.data..][0..Integer.limbs]);
                        const limbs = data.builder.constant_limbs
                            .items[item.data + Integer.limbs ..][0..extra.limbs_len];
                        const bigint: std.math.big.int.Const = .{
                            .limbs = limbs,
                            .positive = switch (tag) {
                                .positive_integer => true,
                                .negative_integer => false,
                                else => unreachable,
                            },
                        };
                        const ExpectedContents = extern struct {
                            const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb));
                            string: [
                                (std.math.big.int.Const{
                                    .limbs = &@as([expected_limbs]std.math.big.Limb, @splat(maxInt(std.math.big.Limb))),
                                    .positive = false,
                                }).sizeInBaseUpperBound(10)
                            ]u8,
                            limbs: [
                                std.math.big.int.calcToStringLimbsBufferLen(expected_limbs, 10)
                            ]std.math.big.Limb,
                        };
                        var bfa_buf: ExpectedContents = undefined;
                        var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), data.builder.gpa);
                        const allocator = bfa.allocator();
                        const str = bigint.toStringAlloc(allocator, 10, undefined) catch return error.WriteFailed;
                        defer allocator.free(str);
                        try w.writeAll(str);
                    },
                    .half,
                    .bfloat,
                    => |tag| try w.print("0x{c}{X:0>4}", .{ @as(u8, switch (tag) {
                        .half => 'H',
                        .bfloat => 'R',
                        else => unreachable,
                    }), item.data >> switch (tag) {
                        .half => 0,
                        .bfloat => 16,
                        else => unreachable,
                    } }),
                    .float => {
                        const Float = struct {
                            fn Repr(comptime T: type) type {
                                return packed struct(@Int(.unsigned, @bitSizeOf(T))) {
                                    mantissa: @Int(.unsigned, std.math.floatMantissaBits(T)),
                                    exponent: @Int(.unsigned, std.math.floatExponentBits(T)),
                                    sign: u1,
                                };
                            }
                        };
                        const Mantissa64 = @FieldType(Float.Repr(f64), "mantissa");
                        const Exponent32 = @FieldType(Float.Repr(f32), "exponent");
                        const Exponent64 = @FieldType(Float.Repr(f64), "exponent");

                        const repr: Float.Repr(f32) = @bitCast(item.data);
                        const denormal_shift = switch (repr.exponent) {
                            std.math.minInt(Exponent32) => @as(
                                std.math.Log2Int(Mantissa64),
                                @clz(repr.mantissa),
                            ) + 1,
                            else => 0,
                        };
                        try w.print("0x{X:0>16}", .{@as(u64, @bitCast(Float.Repr(f64){
                            .mantissa = std.math.shl(
                                Mantissa64,
                                repr.mantissa,
                                std.math.floatMantissaBits(f64) - std.math.floatMantissaBits(f32) +
                                    denormal_shift,
                            ),
                            .exponent = switch (repr.exponent) {
                                std.math.minInt(Exponent32) => if (repr.mantissa > 0)
                                    @as(Exponent64, std.math.floatExponentMin(f32) +
                                        std.math.floatExponentMax(f64)) - denormal_shift
                                else
                                    std.math.minInt(Exponent64),
                                else => @as(Exponent64, repr.exponent) +
                                    (std.math.floatExponentMax(f64) - std.math.floatExponentMax(f32)),
                                maxInt(Exponent32) => maxInt(Exponent64),
                            },
                            .sign = repr.sign,
                        }))});
                    },
                    .double => {
                        const extra = data.builder.constantExtraData(Double, item.data);
                        try w.print("0x{X:0>8}{X:0>8}", .{ extra.hi, extra.lo });
                    },
                    .fp128,
                    .ppc_fp128,
                    => |tag| {
                        const extra = data.builder.constantExtraData(Fp128, item.data);
                        try w.print("0x{c}{X:0>8}{X:0>8}{X:0>8}{X:0>8}", .{
                            @as(u8, switch (tag) {
                                .fp128 => 'L',
                                .ppc_fp128 => 'M',
                                else => unreachable,
                            }),
                            extra.lo_hi,
                            extra.lo_lo,
                            extra.hi_hi,
                            extra.hi_lo,
                        });
                    },
                    .x86_fp80 => {
                        const extra = data.builder.constantExtraData(Fp80, item.data);
                        try w.print("0xK{X:0>4}{X:0>8}{X:0>8}", .{
                            extra.hi, extra.lo_hi, extra.lo_lo,
                        });
                    },
                    .null,
                    .none,
                    .zeroinitializer,
                    .undef,
                    .poison,
                    => |tag| try w.writeAll(@tagName(tag)),
                    .structure,
                    .packed_structure,
                    .array,
                    .vector,
                    => |tag| {
                        var extra = data.builder.constantExtraDataTrail(Aggregate, item.data);
                        const len: u32 = @intCast(extra.data.type.aggregateLen(data.builder));
                        const vals = extra.trail.next(len, Constant, data.builder);
                        try w.writeAll(switch (tag) {
                            .structure => "{ ",
                            .packed_structure => "<{ ",
                            .array => "[",
                            .vector => "<",
                            else => unreachable,
                        });
                        for (vals, 0..) |val, index| {
                            if (index > 0) try w.writeAll(", ");
                            try w.print("{f}", .{val.fmt(data.builder, .{ .percent = true })});
                        }
                        try w.writeAll(switch (tag) {
                            .structure => " }",
                            .packed_structure => " }>",
                            .array => "]",
                            .vector => ">",
                            else => unreachable,
                        });
                    },
                    .splat => {
                        const extra = data.builder.constantExtraData(Splat, item.data);
                        const len = extra.type.vectorLen(data.builder);
                        try w.writeByte('<');
                        for (0..len) |index| {
                            if (index > 0) try w.writeAll(", ");
                            try w.print("{f}", .{extra.value.fmt(data.builder, .{ .percent = true })});
                        }
                        try w.writeByte('>');
                    },
                    .string => try w.print("c{f}", .{
                        @as(String, @fromBackingInt(item.data)).fmtQ(data.builder),
                    }),
                    .blockaddress => |tag| {
                        const extra = data.builder.constantExtraData(BlockAddress, item.data);
                        const function = extra.function.ptrConst(data.builder);
                        try w.print("{s}({f}, {f})", .{
                            @tagName(tag),
                            function.global.fmt(data.builder),
                            extra.block.toInst(function).fmt(extra.function, data.builder, .{}),
                        });
                    },
                    .dso_local_equivalent,
                    .no_cfi,
                    => |tag| {
                        const function: Function.Index = @fromBackingInt(item.data);
                        try w.print("{s} {f}", .{
                            @tagName(tag),
                            function.ptrConst(data.builder).global.fmt(data.builder),
                        });
                    },
                    .trunc,
                    .ptrtoint,
                    .inttoptr,
                    .bitcast,
                    .addrspacecast,
                    => |tag| {
                        const extra = data.builder.constantExtraData(Cast, item.data);
                        try w.print("{s} ({f} to {f})", .{
                            @tagName(tag),
                            extra.val.fmt(data.builder, .{ .percent = true }),
                            extra.type.fmt(data.builder, .percent),
                        });
                    },
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => |tag| {
                        var extra = data.builder.constantExtraDataTrail(GetElementPtr, item.data);
                        const indices =
                            extra.trail.next(extra.data.info.indices_len, Constant, data.builder);
                        try w.print("{s} ({f}, {f}", .{
                            @tagName(tag),
                            extra.data.type.fmt(data.builder, .percent),
                            extra.data.base.fmt(data.builder, .{ .percent = true }),
                        });
                        for (indices) |index| try w.print(", {f}", .{index.fmt(data.builder, .{ .percent = true })});
                        try w.writeByte(')');
                    },
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .shl,
                    .xor,
                    => |tag| {
                        const extra = data.builder.constantExtraData(Binary, item.data);
                        try w.print("{s} ({f}, {f})", .{
                            @tagName(tag),
                            extra.lhs.fmt(data.builder, .{ .percent = true }),
                            extra.rhs.fmt(data.builder, .{ .percent = true }),
                        });
                    },
                    .@"asm",
                    .@"asm sideeffect",
                    .@"asm alignstack",
                    .@"asm sideeffect alignstack",
                    .@"asm inteldialect",
                    .@"asm sideeffect inteldialect",
                    .@"asm alignstack inteldialect",
                    .@"asm sideeffect alignstack inteldialect",
                    .@"asm unwind",
                    .@"asm sideeffect unwind",
                    .@"asm alignstack unwind",
                    .@"asm sideeffect alignstack unwind",
                    .@"asm inteldialect unwind",
                    .@"asm sideeffect inteldialect unwind",
                    .@"asm alignstack inteldialect unwind",
                    .@"asm sideeffect alignstack inteldialect unwind",
                    => |tag| {
                        const extra = data.builder.constantExtraData(Assembly, item.data);
                        try w.print("{s} {f}, {f}", .{
                            @tagName(tag),
                            extra.assembly.fmtQ(data.builder),
                            extra.constraints.fmtQ(data.builder),
                        });
                    },
                }
            },
            .global => |global| try w.print("{f}", .{global.fmt(data.builder)}),
        }
    }
    pub fn fmt(self: Constant, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{
            .constant = self,
            .builder = builder,
            .flags = flags,
        } };
    }
};

pub const Value = enum(u32) {
    none = maxInt(u31),
    false = first_constant + @backingInt(Constant.false),
    true = first_constant + @backingInt(Constant.true),
    @"0" = first_constant + @backingInt(Constant.@"0"),
    @"1" = first_constant + @backingInt(Constant.@"1"),
    _,

    const first_constant = 1 << 30;
    const first_metadata = 1 << 31;

    pub fn unwrap(self: Value) union(enum) {
        instruction: Function.Instruction.Index,
        constant: Constant,
        metadata: Metadata,
    } {
        return if (@backingInt(self) < first_constant)
            .{ .instruction = @fromBackingInt(@backingInt(self)) }
        else if (@backingInt(self) < first_metadata)
            .{ .constant = @fromBackingInt(@backingInt(self) - first_constant) }
        else
            .{ .metadata = @bitCast(@backingInt(self) - first_metadata) };
    }

    pub fn typeOfWip(self: Value, wip: *const WipFunction) Type {
        return switch (self.unwrap()) {
            .instruction => |instruction| instruction.typeOfWip(wip),
            .constant => |constant| constant.typeOf(wip.builder),
            .metadata => .metadata,
        };
    }

    pub fn typeOf(self: Value, function: Function.Index, builder: *Builder) Type {
        return switch (self.unwrap()) {
            .instruction => |instruction| instruction.typeOf(function, builder),
            .constant => |constant| constant.typeOf(builder),
            .metadata => .metadata,
        };
    }

    pub fn toConst(self: Value) ?Constant {
        return switch (self.unwrap()) {
            .instruction, .metadata => null,
            .constant => |constant| constant,
        };
    }

    const FormatData = struct {
        value: Value,
        function: Function.Index,
        builder: *Builder,
        flags: FormatFlags,
    };
    fn format(data: FormatData, w: *Writer) Writer.Error!void {
        switch (data.value.unwrap()) {
            .instruction => |instruction| try Function.Instruction.Index.format(.{
                .instruction = instruction,
                .function = data.function,
                .builder = data.builder,
                .flags = data.flags,
            }, w),
            .constant => |constant| try Constant.format(.{
                .constant = constant,
                .builder = data.builder,
                .flags = data.flags,
            }, w),
            .metadata => unreachable,
        }
    }
    pub fn fmt(self: Value, function: Function.Index, builder: *Builder, flags: FormatFlags) std.fmt.Alt(FormatData, format) {
        return .{ .data = .{ .value = self, .function = function, .builder = builder, .flags = flags } };
    }
};

pub const Metadata = packed struct(u32) {
    index: u29,
    kind: Kind,
    unused: enum(u1) { unused = 0 } = .unused,

    pub const Kind = enum(u2) {
        string,
        node,
        forward,
        local,
    };

    pub const empty_tuple: Metadata = .{ .kind = .node, .index = 0 };

    pub const Optional = packed struct(u32) {
        index: u29,
        kind: Metadata.Kind,
        is_none: bool,

        pub const none: Metadata.Optional = .{ .index = 0, .kind = .string, .is_none = true };
        pub const empty_tuple: Metadata.Optional = Metadata.empty_tuple.toOptional();

        pub fn wrap(metadata: ?Metadata) Metadata.Optional {
            return (metadata orelse return .none).toOptional();
        }
        pub fn unwrap(metadata: Metadata.Optional) ?Metadata {
            return if (metadata.is_none) null else .{ .index = metadata.index, .kind = metadata.kind };
        }
        pub fn toValue(metadata: Metadata.Optional) Value {
            return if (metadata.unwrap()) |m| m.toValue() else .none;
        }
        pub fn toString(metadata: Metadata.Optional) Metadata.String.Optional {
            return if (metadata.unwrap()) |m| m.toString().toOptional() else .none;
        }
    };
    pub fn toOptional(metadata: Metadata) Metadata.Optional {
        return .{ .index = metadata.index, .kind = metadata.kind, .is_none = false };
    }
    pub fn toValue(metadata: Metadata) Value {
        return @fromBackingInt(Value.first_metadata + @as(u32, @bitCast(metadata)));
    }

    pub const String = enum(u32) {
        _,

        pub const Optional = enum(u32) {
            none = @bitCast(Metadata.Optional.none),
            _,

            pub fn wrap(metadata: ?Metadata.String) Metadata.String.Optional {
                return (metadata orelse return .none).toOptional();
            }
            pub fn unwrap(metadata: Metadata.String.Optional) ?Metadata.String {
                return switch (metadata) {
                    .none => null,
                    else => @fromBackingInt(@backingInt(metadata)),
                };
            }
            pub fn toMetadata(metadata: Metadata.String.Optional) Metadata.Optional {
                return if (metadata.unwrap()) |m| m.toMetadata().toOptional() else .none;
            }
        };
        pub fn toOptional(metadata: Metadata.String) Metadata.String.Optional {
            return @fromBackingInt(@backingInt(metadata));
        }
        pub fn toMetadata(metadata: Metadata.String) Metadata {
            return .{ .index = @intCast(@backingInt(metadata)), .kind = .string };
        }

        pub fn slice(metadata: Metadata.String, builder: *const Builder) []const u8 {
            const index = @backingInt(metadata);
            const start = builder.metadata_string_indices.items[index];
            const end = builder.metadata_string_indices.items[index + 1];
            return builder.metadata_string_bytes.items[start..end];
        }

        const Adapter = struct {
            builder: *const Builder,
            pub fn hash(_: Adapter, key: []const u8) u32 {
                return @truncate(std.hash.Wyhash.hash(0, key));
            }
            pub fn eql(ctx: Adapter, lhs_key: []const u8, _: void, rhs_index: usize) bool {
                const rhs_metadata: Metadata.String = @fromBackingInt(@intCast(rhs_index));
                return std.mem.eql(u8, lhs_key, rhs_metadata.slice(ctx.builder));
            }
        };

        const FormatData = struct {
            metadata: Metadata.String,
            builder: *const Builder,
        };
        fn format(data: FormatData, w: *Writer) Writer.Error!void {
            try printEscapedString(data.metadata.slice(data.builder), .always_quote, w);
        }
        fn fmt(self: Metadata.String, builder: *const Builder) std.fmt.Alt(FormatData, format) {
            return .{ .data = .{ .metadata = self, .builder = builder } };
        }
    };
    pub fn toString(metadata: Metadata) Metadata.String {
        assert(metadata.kind == .string);
        return @fromBackingInt(metadata.index);
    }

    pub const Tag = enum(u6) {
        file,
        compile_unit,
        @"compile_unit optimized",
        subprogram,
        @"subprogram local",
        @"subprogram definition",
        @"subprogram local definition",
        @"subprogram optimized",
        @"subprogram optimized local",
        @"subprogram optimized definition",
        @"subprogram optimized local definition",
        lexical_block,
        location,
        basic_bool_type,
        basic_unsigned_type,
        basic_signed_type,
        basic_float_type,
        composite_struct_type,
        composite_union_type,
        composite_enumeration_type,
        composite_array_type,
        composite_vector_type,
        derived_pointer_type,
        derived_member_type,
        derived_typedef_type,
        subroutine_type,
        enumerator_unsigned,
        enumerator_signed_positive,
        enumerator_signed_negative,
        subrange,
        tuple,
        expression,
        local_var,
        parameter,
        global_var,
        @"global_var local",
        global_var_expression,
        constant,

        pub fn isInline(metadata_tag: Metadata.Tag) bool {
            return switch (metadata_tag) {
                .expression,
                .constant,
                => true,
                .file,
                .compile_unit,
                .@"compile_unit optimized",
                .subprogram,
                .@"subprogram local",
                .@"subprogram definition",
                .@"subprogram local definition",
                .@"subprogram optimized",
                .@"subprogram optimized local",
                .@"subprogram optimized definition",
                .@"subprogram optimized local definition",
                .lexical_block,
                .location,
                .basic_bool_type,
                .basic_unsigned_type,
                .basic_signed_type,
                .basic_float_type,
                .composite_struct_type,
                .composite_union_type,
                .composite_enumeration_type,
                .composite_array_type,
                .composite_vector_type,
                .derived_pointer_type,
                .derived_member_type,
                .derived_typedef_type,
                .subroutine_type,
                .enumerator_unsigned,
                .enumerator_signed_positive,
                .enumerator_signed_negative,
                .subrange,
                .tuple,
                .local_var,
                .parameter,
                .global_var,
                .@"global_var local",
                .global_var_expression,
                => false,
            };
        }
    };

    pub fn tag(metadata: Metadata, builder: *const Builder) Tag {
        assert(metadata.kind == .node);
        return builder.metadata_items.items(.tag)[metadata.index];
    }

    pub fn item(metadata: Metadata, builder: *const Builder) Item {
        assert(metadata.kind == .node);
        return builder.metadata_items.get(metadata.index);
    }

    pub fn isInline(metadata: Metadata, builder: *const Builder) bool {
        return metadata.tag(builder).isInline();
    }

    pub fn unwrap(metadata: Metadata, builder: *const Builder) Metadata {
        switch (metadata.kind) {
            .string, .node, .local => return metadata,
            .forward => {
                const referenced = builder.metadata_forward_references.items[metadata.index].unwrap().?;
                switch (referenced.kind) {
                    .string, .node => return referenced,
                    .forward, .local => unreachable,
                }
            },
        }
    }

    pub const Item = struct {
        tag: Tag,
        data: ExtraIndex,

        const ExtraIndex = u32;
    };

    pub const DIFlags = packed struct(u32) {
        Visibility: enum(u2) { Zero, Private, Protected, Public } = .Zero,
        FwdDecl: bool = false,
        AppleBlock: bool = false,
        ReservedBit4: u1 = 0,
        Virtual: bool = false,
        Artificial: bool = false,
        Explicit: bool = false,
        Prototyped: bool = false,
        ObjcClassComplete: bool = false,
        ObjectPointer: bool = false,
        Vector: bool = false,
        StaticMember: bool = false,
        LValueReference: bool = false,
        RValueReference: bool = false,
        ExportSymbols: bool = false,
        Inheritance: enum(u2) {
            Zero,
            SingleInheritance,
            MultipleInheritance,
            VirtualInheritance,
        } = .Zero,
        IntroducedVirtual: bool = false,
        BitField: bool = false,
        NoReturn: bool = false,
        ReservedBit21: u1 = 0,
        TypePassbyValue: bool = false,
        TypePassbyReference: bool = false,
        EnumClass: bool = false,
        Thunk: bool = false,
        NonTrivial: bool = false,
        BigEndian: bool = false,
        LittleEndian: bool = false,
        AllCallsDescribed: bool = false,
        Unused: u2 = 0,

        pub fn format(self: DIFlags, w: *Writer) Writer.Error!void {
            var need_pipe = false;
            const info = @typeInfo(DIFlags).@"struct";
            inline for (info.field_names, info.field_types) |field_name, field_type| {
                switch (@typeInfo(field_type)) {
                    .bool => if (@field(self, field_name)) {
                        if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
                        try w.print("DIFlag{s}", .{field_name});
                    },
                    .@"enum" => if (@field(self, field_name) != .Zero) {
                        if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
                        try w.print("DIFlag{s}", .{@tagName(@field(self, field_name))});
                    },
                    .int => assert(@field(self, field_name) == 0),
                    else => @compileError("bad field type: " ++ field_name ++ ": " ++
                        @typeName(field_type)),
                }
            }
            if (!need_pipe) try w.writeByte('0');
        }
    };

    pub const File = struct {
        filename: Metadata.String.Optional,
        directory: Metadata.String.Optional,
    };

    pub const CompileUnit = struct {
        pub const Options = struct {
            optimized: bool,
        };

        file: Metadata.Optional,
        producer: Metadata.String.Optional,
        enums: Metadata.Optional,
        globals: Metadata.Optional,
    };

    pub const Subprogram = struct {
        pub const Options = struct {
            di_flags: DIFlags,
            sp_flags: DISPFlags,
        };

        pub const DISPFlags = packed struct(u32) {
            Virtuality: enum(u2) { Zero, Virtual, PureVirtual } = .Zero,
            LocalToUnit: bool = false,
            Definition: bool = false,
            Optimized: bool = false,
            Pure: bool = false,
            Elemental: bool = false,
            Recursive: bool = false,
            MainSubprogram: bool = false,
            Deleted: bool = false,
            ReservedBit10: u1 = 0,
            ObjCDirect: bool = false,
            Unused: u20 = 0,

            pub fn format(self: DISPFlags, w: *Writer) Writer.Error!void {
                var need_pipe = false;
                const info = @typeInfo(DISPFlags).@"struct";
                inline for (info.field_names, info.field_types) |field_name, field_type| {
                    switch (@typeInfo(field_type)) {
                        .bool => if (@field(self, field_name)) {
                            if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
                            try w.print("DISPFlag{s}", .{field_name});
                        },
                        .@"enum" => if (@field(self, field_name) != .Zero) {
                            if (need_pipe) try w.writeAll(" | ") else need_pipe = true;
                            try w.print("DISPFlag{s}", .{@tagName(@field(self, field_name))});
                        },
                        .int => assert(@field(self, field_name) == 0),
                        else => @compileError("bad field type: " ++ field_name ++ ": " ++
                            @typeName(field_type)),
                    }
                }
                if (!need_pipe) try w.writeByte('0');
            }
        };

        file: Metadata.Optional,
        name: Metadata.String.Optional,
        linkage_name: Metadata.String.Optional,
        line: u32,
        scope_line: u32,
        ty: Metadata.Optional,
        di_flags: DIFlags,
        compile_unit: Metadata.Optional,
    };
    pub fn getSubprogram(metadata: Metadata, builder: *const Builder) Subprogram {
        const metadata_item = metadata.item(builder);
        switch (metadata_item.tag) {
            else => unreachable,
            .subprogram,
            .@"subprogram local",
            .@"subprogram definition",
            .@"subprogram local definition",
            .@"subprogram optimized",
            .@"subprogram optimized local",
            .@"subprogram optimized definition",
            .@"subprogram optimized local definition",
            => return builder.metadataExtraData(Metadata.Subprogram, metadata_item.data),
        }
    }

    pub const LexicalBlock = struct {
        scope: Metadata.Optional,
        file: Metadata.Optional,
        line: u32,
        column: u32,
    };

    pub const Location = struct {
        line: u32,
        column: u32,
        scope: Metadata,
        inlined_at: Metadata.Optional,
    };

    pub const BasicType = struct {
        name: Metadata.String.Optional,
        size_in_bits_lo: u32,
        size_in_bits_hi: u32,

        pub fn bitSize(self: BasicType) u64 {
            return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
        }
    };

    pub const CompositeType = struct {
        name: Metadata.String.Optional,
        file: Metadata.Optional,
        scope: Metadata.Optional,
        line: u32,
        underlying_type: Metadata.Optional,
        size_in_bits_lo: u32,
        size_in_bits_hi: u32,
        align_in_bits_lo: u32,
        align_in_bits_hi: u32,
        fields_tuple: Metadata.Optional,

        pub fn bitSize(self: CompositeType) u64 {
            return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
        }
        pub fn bitAlign(self: CompositeType) u64 {
            return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
        }
    };

    pub const DerivedType = struct {
        name: Metadata.String.Optional,
        file: Metadata.Optional,
        scope: Metadata.Optional,
        line: u32,
        underlying_type: Metadata.Optional,
        size_in_bits_lo: u32,
        size_in_bits_hi: u32,
        align_in_bits_lo: u32,
        align_in_bits_hi: u32,
        offset_in_bits_lo: u32,
        offset_in_bits_hi: u32,

        pub fn bitSize(self: DerivedType) u64 {
            return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;
        }
        pub fn bitAlign(self: DerivedType) u64 {
            return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;
        }
        pub fn bitOffset(self: DerivedType) u64 {
            return @as(u64, self.offset_in_bits_hi) << 32 | self.offset_in_bits_lo;
        }
    };

    pub const SubroutineType = struct {
        types_tuple: Metadata.Optional,
    };

    pub const Enumerator = struct {
        name: Metadata.String.Optional,
        bit_width: u32,
        limbs_index: u32,
        limbs_len: u32,
    };

    pub const Subrange = struct {
        lower_bound: Metadata.Optional,
        count: Metadata.Optional,
    };

    pub const Expression = struct {
        elements_len: u32,

        // elements: [elements_len]u32
    };

    pub const Tuple = struct {
        elements_len: u32,

        // elements: [elements_len]Metadata
    };

    pub const LocalVar = struct {
        name: Metadata.String.Optional,
        file: Metadata.Optional,
        scope: Metadata.Optional,
        line: u32,
        ty: Metadata.Optional,
    };

    pub const Parameter = struct {
        name: Metadata.String.Optional,
        file: Metadata.Optional,
        scope: Metadata.Optional,
        line: u32,
        ty: Metadata.Optional,
        arg_no: u32,
    };

    pub const GlobalVar = struct {
        pub const Options = struct {
            local: bool,
        };

        name: Metadata.String.Optional,
        linkage_name: Metadata.String.Optional,
        file: Metadata.Optional,
        scope: Metadata.Optional,
        line: u32,
        ty: Metadata.Optional,
        variable: Variable.Index,
    };

    pub const GlobalVarExpression = struct {
        variable: Metadata.Optional,
        expression: Metadata.Optional,
    };

    const Formatter = struct {
        builder: *Builder,
        need_comma: bool,
        map: std.array_hash_map.Auto(union(enum) {
            metadata: Metadata,
            debug_location: DebugLocation.Location,
        }, void) = .empty,

        const FormatData = struct {
            formatter: *Formatter,
            prefix: []const u8 = "",
            node: Node,
            specialized: ?FormatFlags,

            const Node = union(enum) {
                none,
                @"inline": Metadata,
                index: u32,

                local_value: ValueData,
                local_metadata: ValueData,
                local_inline: Metadata,
                local_index: u32,

                string: Metadata.String,
                bool: bool,
                u32: u32,
                u64: u64,
                di_flags: DIFlags,
                sp_flags: Subprogram.DISPFlags,
                raw: []const u8,

                const ValueData = struct {
                    value: Value,
                    function: Function.Index,
                };
            };
        };
        fn format(data: FormatData, w: *Writer) Writer.Error!void {
            if (data.node == .none) return;

            const is_specialized = data.specialized != null;

            if (data.formatter.need_comma) try w.writeAll(", ");
            defer data.formatter.need_comma = true;
            try w.writeAll(data.prefix);

            const builder = data.formatter.builder;
            switch (data.node) {
                .none => unreachable,
                .@"inline" => |node| {
                    const needed_comma = data.formatter.need_comma;
                    defer data.formatter.need_comma = needed_comma;
                    data.formatter.need_comma = false;

                    const node_item = node.item(builder);
                    switch (node_item.tag) {
                        .expression => {
                            var extra = builder.metadataExtraDataTrail(Expression, node_item.data);
                            const elements = extra.trail.next(extra.data.elements_len, u32, builder);
                            try w.writeAll("!DIExpression(");
                            for (elements) |element| try format(.{
                                .formatter = data.formatter,
                                .node = .{ .u64 = element },
                                .specialized = .{ .percent = true },
                            }, w);
                            try w.writeByte(')');
                        },
                        .constant => try Constant.format(.{
                            .constant = @fromBackingInt(node_item.data),
                            .builder = builder,
                            .flags = data.specialized orelse .{},
                        }, w),
                        else => unreachable,
                    }
                },
                .index => |node| try w.print("!{d}", .{node}),
                inline .local_value, .local_metadata => |node, node_tag| try Value.format(.{
                    .value = node.value,
                    .function = node.function,
                    .builder = builder,
                    .flags = switch (node_tag) {
                        .local_value => data.specialized orelse .{},
                        .local_metadata => .{ .percent = true },
                        else => unreachable,
                    },
                }, w),
                inline .local_inline, .local_index => |node, node_tag| {
                    if (data.specialized) |flags| {
                        if (flags.onlyPercent()) {
                            try w.print("{f} ", .{Type.metadata.fmt(builder, .percent)});
                        }
                    }
                    try format(.{
                        .formatter = data.formatter,
                        .node = @unionInit(FormatData.Node, @tagName(node_tag)["local_".len..], node),
                        .specialized = .{ .percent = true },
                    }, w);
                },
                .string => |s| {
                    if (is_specialized) try w.writeByte('!');
                    try w.print("{f}", .{s.fmt(builder)});
                },
                inline .bool, .u32, .u64 => |node| try w.print("{}", .{node}),
                inline .di_flags, .sp_flags => |node| try w.print("{f}", .{node}),
                .raw => |node| try w.writeAll(node),
            }
        }
        inline fn fmt(formatter: *Formatter, prefix: []const u8, node: anytype, special: ?FormatFlags) switch (@TypeOf(node)) {
            Metadata, Metadata.Optional, ?Metadata => Allocator.Error,
            else => error{},
        }!std.fmt.Alt(FormatData, format) {
            const Node = @TypeOf(node);
            const MaybeNode = switch (Node) {
                Metadata.Optional => ?Metadata,
                Metadata.String.Optional => ?Metadata.String,
                else => switch (@typeInfo(Node)) {
                    .optional => Node,
                    .null => ?noreturn,
                    else => ?Node,
                },
            };
            const Some = @typeInfo(MaybeNode).optional.child;
            return .{ .data = .{
                .formatter = formatter,
                .prefix = prefix,
                .node = if (@as(MaybeNode, switch (Node) {
                    Metadata.Optional, Metadata.String.Optional => node.unwrap(),
                    else => node,
                })) |some| switch (@typeInfo(Some)) {
                    .@"enum" => |enum_info| switch (Some) {
                        Metadata.String => .{ .string = some },
                        else => if (enum_info.mode == .exhaustive)
                            .{ .raw = @tagName(some) }
                        else
                            @compileError("unknown type to format: " ++ @typeName(Node)),
                    },
                    .enum_literal => .{ .raw = @tagName(some) },
                    .bool => .{ .bool = some },
                    .@"struct" => switch (Some) {
                        DIFlags => .{ .di_flags = some },
                        Metadata => switch (some.kind) {
                            .string => .{ .string = some.toString() },
                            .node, .forward => try formatter.refUnwrapped(some.unwrap(formatter.builder)),
                            .local => unreachable,
                        },
                        Subprogram.DISPFlags => .{ .sp_flags = some },
                        else => @compileError("unknown type to format: " ++ @typeName(Node)),
                    },
                    .int, .comptime_int => .{ .u64 = some },
                    .pointer => .{ .raw = some },
                    else => @compileError("unknown type to format: " ++ @typeName(Node)),
                } else switch (Node) {
                    Metadata.Optional, Metadata.String.Optional => .none,
                    else => switch (@typeInfo(Node)) {
                        .optional, .null => .none,
                        else => unreachable,
                    },
                },
                .specialized = special,
            } };
        }
        inline fn fmtLocal(
            formatter: *Formatter,
            prefix: []const u8,
            value: Value,
            function: Function.Index,
        ) Allocator.Error!std.fmt.Alt(FormatData, format) {
            return .{ .data = .{
                .formatter = formatter,
                .prefix = prefix,
                .node = node: switch (value.unwrap()) {
                    .instruction, .constant => .{ .local_value = .{
                        .value = value,
                        .function = function,
                    } },
                    .metadata => |metadata| if (value == .none) .none else {
                        const unwrapped = metadata.unwrap(formatter.builder);
                        break :node switch (unwrapped.kind) {
                            .string, .node => switch (try formatter.refUnwrapped(unwrapped)) {
                                .@"inline" => |node| .{ .local_inline = node },
                                .index => |node| .{ .local_index = node },
                                else => unreachable,
                            },
                            .forward => unreachable,
                            .local => .{ .local_metadata = .{
                                .value = function.ptrConst(formatter.builder).debug_values[
                                    unwrapped.index
                                ].toValue(),
                                .function = function,
                            } },
                        };
                    },
                },
                .specialized = null,
            } };
        }
        fn refUnwrapped(formatter: *Formatter, node: Metadata) Allocator.Error!FormatData.Node {
            const builder = formatter.builder;
            const unwrapped_metadata = node.unwrap(builder);
            switch (unwrapped_metadata.tag(builder)) {
                .expression, .constant => return .{ .@"inline" = unwrapped_metadata },
                else => |metadata_tag| {
                    assert(!metadata_tag.isInline());
                    const gop = try formatter.map.getOrPut(builder.gpa, .{ .metadata = unwrapped_metadata });
                    return .{ .index = @intCast(gop.index) };
                },
            }
        }

        inline fn specialized(
            formatter: *Formatter,
            distinct: enum { @"!", @"distinct !" },
            node: enum {
                DIFile,
                DICompileUnit,
                DISubprogram,
                DILexicalBlock,
                DILocation,
                DIBasicType,
                DICompositeType,
                DIDerivedType,
                DISubroutineType,
                DIEnumerator,
                DISubrange,
                DILocalVariable,
                DIGlobalVariable,
                DIGlobalVariableExpression,
            },
            nodes: anytype,
            w: *Writer,
        ) !void {
            const names = @typeInfo(@TypeOf(nodes)).@"struct".field_names;

            comptime var fmt_str: []const u8 = "{[distinct]s}{[node]s}(";
            inline for (names) |name| fmt_str = fmt_str ++ "{[" ++ name ++ "]f}";
            fmt_str = fmt_str ++ ")\n";

            const field_names = @as([]const []const u8, &.{ "distinct", "node" }) ++ names;
            comptime var field_types: [2 + names.len]type = undefined;
            @memset(field_types[0..2], []const u8);
            @memset(field_types[2..], std.fmt.Alt(FormatData, format));

            var fmt_args: @Struct(.auto, null, field_names, &field_types, &@splat(.{})) = undefined;
            fmt_args.distinct = @tagName(distinct);
            fmt_args.node = @tagName(node);
            inline for (names) |name| @field(fmt_args, name) = try formatter.fmt(
                name ++ ": ",
                @field(nodes, name),
                null,
            );
            try w.print(fmt_str, fmt_args);
        }
    };
};

pub fn init(options: Options) Allocator.Error!Builder {
    var self: Builder = .{
        .gpa = options.allocator,
        .strip = options.strip,

        .source_filename = .none,
        .data_layout = .{
            .endian = null,
            .int_specs = .empty,
            .float_specs = .empty,
            .vector_specs = .empty,
            .pointer_specs = .empty,
            .string_repr = .none,
        },
        .target_triple = .none,
        .module_asm = .empty,

        .string_map = .empty,
        .string_indices = .empty,
        .string_bytes = .empty,

        .types = .empty,
        .next_unnamed_type = @fromBackingInt(0),
        .next_unique_type_id = .empty,
        .type_map = .empty,
        .type_items = .empty,
        .type_extra = .empty,

        .attributes = .empty,
        .attributes_map = .empty,
        .attributes_indices = .empty,
        .attributes_extra = .empty,

        .function_attributes_set = .empty,

        .globals = .empty,
        .next_unnamed_global = @fromBackingInt(0),
        .next_replaced_global = .none,
        .next_unique_global_id = .empty,
        .aliases = .empty,
        .variables = .empty,
        .functions = .empty,

        .strtab_string_map = .empty,
        .strtab_string_indices = .empty,
        .strtab_string_bytes = .empty,

        .constant_map = .empty,
        .constant_items = .empty,
        .constant_extra = .empty,
        .constant_limbs = .empty,

        .alignment_forward_references = .empty,

        .metadata_map = .empty,
        .metadata_items = .empty,
        .metadata_extra = .empty,
        .metadata_limbs = .empty,
        .metadata_forward_references = .empty,
        .metadata_named = .empty,
        .metadata_string_map = .empty,
        .metadata_string_indices = .empty,
        .metadata_string_bytes = .empty,
    };
    errdefer self.deinit();

    try self.string_indices.append(self.gpa, 0);
    assert(try self.string("") == .empty);

    const llvm_triple = try tripleForTarget(self.gpa, options.target);
    defer self.gpa.free(llvm_triple);
    self.target_triple = try self.string(llvm_triple);
    self.data_layout = try .parseString(try self.string(DataLayout.stringForTarget(options.target)), &self);

    try self.strtab_string_indices.append(self.gpa, 0);
    assert(try self.strtabString("") == .empty);

    if (options.name.len > 0) self.source_filename = try self.string(options.name);

    {
        const static_len = @typeInfo(Type).@"enum".field_names.len - 1;
        try self.type_map.ensureTotalCapacity(self.gpa, static_len);
        try self.type_items.ensureTotalCapacity(self.gpa, static_len);
        const info = @typeInfo(Type.Simple).@"enum";
        inline for (info.field_names, info.field_values) |simple_field_name, simple_field_value| {
            const result = self.getOrPutTypeNoExtraAssumeCapacity(
                .{ .tag = .simple, .data = simple_field_value },
            );
            assert(result.new and result.type == @field(Type, simple_field_name));
        }
        inline for (.{ 1, 8, 16, 29, 32, 64, 80, 128 }) |bits|
            assert(self.intTypeAssumeCapacity(bits) ==
                @field(Type, std.fmt.comptimePrint("i{d}", .{bits})));
        inline for (.{ 0, 4 }) |addr_space_index| {
            const addr_space: AddrSpace = @fromBackingInt(addr_space_index);
            assert(self.ptrTypeAssumeCapacity(addr_space) ==
                @field(Type, std.fmt.comptimePrint("ptr{f}", .{addr_space.fmt(" ")})));
        }
    }

    {
        try self.attributes_indices.append(self.gpa, 0);
        assert(try self.attrs(&.{}) == .none);
        assert(try self.fnAttrs(&.{}) == .none);
    }

    assert(try self.intConst(.i1, 0) == .false);
    assert(try self.intConst(.i1, 1) == .true);
    assert(try self.intConst(.i32, 0) == .@"0");
    assert(try self.intConst(.i32, 1) == .@"1");
    assert(try self.noneConst(.token) == .none);

    assert(try self.metadataTuple(&.{}) == Metadata.empty_tuple);

    try self.metadata_string_indices.append(self.gpa, 0);

    return self;
}

pub fn clearAndFree(self: *Builder) void {
    self.module_asm.clearAndFree(self.gpa);

    self.string_map.clearAndFree(self.gpa);
    self.string_indices.clearAndFree(self.gpa);
    self.string_bytes.clearAndFree(self.gpa);

    self.types.clearAndFree(self.gpa);
    self.next_unique_type_id.clearAndFree(self.gpa);
    self.type_map.clearAndFree(self.gpa);
    self.type_items.clearAndFree(self.gpa);
    self.type_extra.clearAndFree(self.gpa);

    self.attributes.clearAndFree(self.gpa);
    self.attributes_map.clearAndFree(self.gpa);
    self.attributes_indices.clearAndFree(self.gpa);
    self.attributes_extra.clearAndFree(self.gpa);

    self.function_attributes_set.clearAndFree(self.gpa);

    self.globals.clearAndFree(self.gpa);
    self.next_unique_global_id.clearAndFree(self.gpa);
    self.aliases.clearAndFree(self.gpa);
    self.variables.clearAndFree(self.gpa);
    for (self.functions.items) |*function| function.deinit(self.gpa);
    self.functions.clearAndFree(self.gpa);

    self.strtab_string_map.clearAndFree(self.gpa);
    self.strtab_string_indices.clearAndFree(self.gpa);
    self.strtab_string_bytes.clearAndFree(self.gpa);

    self.constant_map.clearAndFree(self.gpa);
    self.constant_items.shrinkAndFree(self.gpa, 0);
    self.constant_extra.clearAndFree(self.gpa);
    self.constant_limbs.clearAndFree(self.gpa);

    self.metadata_map.clearAndFree(self.gpa);
    self.metadata_items.shrinkAndFree(self.gpa, 0);
    self.metadata_extra.clearAndFree(self.gpa);
    self.metadata_limbs.clearAndFree(self.gpa);
    self.metadata_forward_references.clearAndFree(self.gpa);
    self.metadata_named.clearAndFree(self.gpa);

    self.metadata_string_map.clearAndFree(self.gpa);
    self.metadata_string_indices.clearAndFree(self.gpa);
    self.metadata_string_bytes.clearAndFree(self.gpa);
}

pub fn deinit(self: *Builder) void {
    const gpa = self.gpa;

    self.data_layout.deinit(gpa);

    self.module_asm.deinit(gpa);

    self.string_map.deinit(gpa);
    self.string_indices.deinit(gpa);
    self.string_bytes.deinit(gpa);

    self.types.deinit(gpa);
    self.next_unique_type_id.deinit(gpa);
    self.type_map.deinit(gpa);
    self.type_items.deinit(gpa);
    self.type_extra.deinit(gpa);

    self.attributes.deinit(gpa);
    self.attributes_map.deinit(gpa);
    self.attributes_indices.deinit(gpa);
    self.attributes_extra.deinit(gpa);

    self.function_attributes_set.deinit(gpa);

    self.globals.deinit(gpa);
    self.next_unique_global_id.deinit(gpa);
    self.aliases.deinit(gpa);
    self.variables.deinit(gpa);
    for (self.functions.items) |*function| function.deinit(gpa);
    self.functions.deinit(gpa);

    self.strtab_string_map.deinit(gpa);
    self.strtab_string_indices.deinit(gpa);
    self.strtab_string_bytes.deinit(gpa);

    self.constant_map.deinit(gpa);
    self.constant_items.deinit(gpa);
    self.constant_extra.deinit(gpa);
    self.constant_limbs.deinit(gpa);

    self.alignment_forward_references.deinit(gpa);

    self.metadata_map.deinit(gpa);
    self.metadata_items.deinit(gpa);
    self.metadata_extra.deinit(gpa);
    self.metadata_limbs.deinit(gpa);
    self.metadata_forward_references.deinit(gpa);
    self.metadata_named.deinit(gpa);

    self.metadata_string_map.deinit(gpa);
    self.metadata_string_indices.deinit(gpa);
    self.metadata_string_bytes.deinit(gpa);

    self.* = undefined;
}

pub fn finishModuleAsm(self: *Builder, aw: *Writer.Allocating) Allocator.Error!void {
    self.module_asm = aw.toArrayList();
    if (self.module_asm.last()) |last| if (last != '\n')
        try self.module_asm.append(self.gpa, '\n');
}

pub fn string(self: *Builder, bytes: []const u8) Allocator.Error!String {
    try self.string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);
    try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.string_map.ensureUnusedCapacity(self.gpa, 1);

    const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
    if (!gop.found_existing) {
        self.string_bytes.appendSliceAssumeCapacity(bytes);
        self.string_indices.appendAssumeCapacity(@intCast(self.string_bytes.items.len));
    }
    return String.fromIndex(gop.index);
}

pub fn stringNull(self: *Builder, bytes: [:0]const u8) Allocator.Error!String {
    return self.string(bytes[0 .. bytes.len + 1]);
}

pub fn stringIfExists(self: *const Builder, bytes: []const u8) ?String {
    return String.fromIndex(
        self.string_map.getIndexAdapted(bytes, String.Adapter{ .builder = self }) orelse return null,
    );
}

pub fn fmt(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) Allocator.Error!String {
    try self.string_map.ensureUnusedCapacity(self.gpa, 1);
    try self.string_bytes.ensureUnusedCapacity(self.gpa, @intCast(std.fmt.count(fmt_str, fmt_args)));
    try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
    return self.fmtAssumeCapacity(fmt_str, fmt_args);
}

pub fn fmtAssumeCapacity(self: *Builder, comptime fmt_str: []const u8, fmt_args: anytype) String {
    self.string_bytes.printAssumeCapacity(fmt_str, fmt_args);
    return self.trailingStringAssumeCapacity();
}

pub fn trailingString(self: *Builder) Allocator.Error!String {
    try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.string_map.ensureUnusedCapacity(self.gpa, 1);
    return self.trailingStringAssumeCapacity();
}

pub fn trailingStringAssumeCapacity(self: *Builder) String {
    const start = self.string_indices.last().?;
    const bytes: []const u8 = self.string_bytes.items[start..];
    const gop = self.string_map.getOrPutAssumeCapacityAdapted(bytes, String.Adapter{ .builder = self });
    if (gop.found_existing) {
        self.string_bytes.shrinkRetainingCapacity(start);
    } else {
        self.string_indices.appendAssumeCapacity(@intCast(self.string_bytes.items.len));
    }
    return String.fromIndex(gop.index);
}

pub fn fnType(
    self: *Builder,
    ret: Type,
    params: []const Type,
    kind: Type.Function.Kind,
) Allocator.Error!Type {
    try self.ensureUnusedTypeCapacity(1, Type.Function, params.len);
    switch (kind) {
        inline else => |comptime_kind| return self.fnTypeAssumeCapacity(ret, params, comptime_kind),
    }
}

pub fn intType(self: *Builder, bits: u24) Allocator.Error!Type {
    try self.ensureUnusedTypeCapacity(1, NoExtra, 0);
    return self.intTypeAssumeCapacity(bits);
}

pub fn ptrType(self: *Builder, addr_space: AddrSpace) Allocator.Error!Type {
    try self.ensureUnusedTypeCapacity(1, NoExtra, 0);
    return self.ptrTypeAssumeCapacity(addr_space);
}

pub fn vectorType(
    self: *Builder,
    kind: Type.Vector.Kind,
    len: u32,
    child: Type,
) Allocator.Error!Type {
    try self.ensureUnusedTypeCapacity(1, Type.Vector, 0);
    switch (kind) {
        inline else => |comptime_kind| return self.vectorTypeAssumeCapacity(comptime_kind, len, child),
    }
}

pub fn arrayType(self: *Builder, len: u64, child: Type) Allocator.Error!Type {
    comptime assert(@sizeOf(Type.Array) >= @sizeOf(Type.Vector));
    try self.ensureUnusedTypeCapacity(1, Type.Array, 0);
    return self.arrayTypeAssumeCapacity(len, child);
}

pub fn structType(
    self: *Builder,
    kind: Type.Structure.Kind,
    fields: []const Type,
) Allocator.Error!Type {
    try self.ensureUnusedTypeCapacity(1, Type.Structure, fields.len);
    switch (kind) {
        inline else => |comptime_kind| return self.structTypeAssumeCapacity(comptime_kind, fields),
    }
}

pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type {
    try self.string_map.ensureUnusedCapacity(self.gpa, 1);
    if (name.slice(self)) |id| {
        const count: usize = comptime std.fmt.count("{d}", .{maxInt(u32)});
        try self.string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);
    }
    try self.string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.types.ensureUnusedCapacity(self.gpa, 1);
    try self.next_unique_type_id.ensureUnusedCapacity(self.gpa, 1);
    try self.ensureUnusedTypeCapacity(1, Type.NamedStructure, 0);
    return self.opaqueTypeAssumeCapacity(name);
}

pub fn namedTypeSetBody(
    self: *Builder,
    named_type: Type,
    body_type: Type,
) void {
    const named_item = self.type_items.items[@backingInt(named_type)];
    self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] =
        @backingInt(body_type);
}

pub fn attr(self: *Builder, attribute: Attribute) Allocator.Error!Attribute.Index {
    try self.attributes.ensureUnusedCapacity(self.gpa, 1);

    const gop = self.attributes.getOrPutAssumeCapacity(attribute.toStorage());
    if (!gop.found_existing) gop.value_ptr.* = {};
    return @fromBackingInt(@intCast(gop.index));
}

pub fn attrs(self: *Builder, attributes: []Attribute.Index) Allocator.Error!Attributes {
    std.sort.heap(Attribute.Index, attributes, self, struct {
        pub fn lessThan(builder: *const Builder, lhs: Attribute.Index, rhs: Attribute.Index) bool {
            const lhs_kind = lhs.getKind(builder);
            const rhs_kind = rhs.getKind(builder);
            assert(lhs_kind != rhs_kind);
            return @backingInt(lhs_kind) < @backingInt(rhs_kind);
        }
    }.lessThan);
    return @fromBackingInt(try self.attrGeneric(@ptrCast(attributes)));
}

pub fn fnAttrs(self: *Builder, fn_attributes: []const Attributes) Allocator.Error!FunctionAttributes {
    try self.function_attributes_set.ensureUnusedCapacity(self.gpa, 1);
    const function_attributes: FunctionAttributes = @fromBackingInt(try self.attrGeneric(@ptrCast(
        fn_attributes[0..if (std.mem.findLastNone(Attributes, fn_attributes, &.{.none})) |last|
            last + 1
        else
            0],
    )));

    _ = self.function_attributes_set.getOrPutAssumeCapacity(function_attributes);
    return function_attributes;
}

pub fn addGlobal(self: *Builder, name: StrtabString, global: Global) Allocator.Error!Global.Index {
    assert(!name.isAnon());
    try self.ensureUnusedTypeCapacity(1, NoExtra, 0);
    try self.ensureUnusedGlobalCapacity(name);
    return self.addGlobalAssumeCapacity(name, global);
}

pub fn addGlobalAssumeCapacity(self: *Builder, name: StrtabString, global: Global) Global.Index {
    _ = self.ptrTypeAssumeCapacity(global.addr_space);
    var id = name;
    if (name == .empty) {
        id = self.next_unnamed_global;
        assert(id != self.next_replaced_global);
        self.next_unnamed_global = @fromBackingInt(@backingInt(id) + 1);
    }
    while (true) {
        const global_gop = self.globals.getOrPutAssumeCapacity(id);
        if (!global_gop.found_existing) {
            global_gop.value_ptr.* = global;
            const global_index: Global.Index = @fromBackingInt(@intCast(global_gop.index));
            global_index.updateDsoLocal(self);
            return global_index;
        }

        const unique_gop = self.next_unique_global_id.getOrPutAssumeCapacity(name);
        if (!unique_gop.found_existing) unique_gop.value_ptr.* = 2;
        id = self.strtabStringFmtAssumeCapacity("{s}.{d}", .{ name.slice(self).?, unique_gop.value_ptr.* });
        unique_gop.value_ptr.* += 1;
    }
}

pub fn getGlobal(self: *const Builder, name: StrtabString) ?Global.Index {
    return @fromBackingInt(@intCast(self.globals.getIndex(name) orelse return null));
}

pub fn addAlias(
    self: *Builder,
    name: StrtabString,
    ty: Type,
    addr_space: AddrSpace,
    aliasee: Constant,
) Allocator.Error!Alias.Index {
    assert(!name.isAnon());
    try self.ensureUnusedTypeCapacity(1, NoExtra, 0);
    try self.ensureUnusedGlobalCapacity(name);
    try self.aliases.ensureUnusedCapacity(self.gpa, 1);
    return self.addAliasAssumeCapacity(name, ty, addr_space, aliasee);
}

pub fn addAliasAssumeCapacity(
    self: *Builder,
    name: StrtabString,
    ty: Type,
    addr_space: AddrSpace,
    aliasee: Constant,
) Alias.Index {
    const alias_index: Alias.Index = @fromBackingInt(@intCast(self.aliases.items.len));
    self.aliases.appendAssumeCapacity(.{ .global = self.addGlobalAssumeCapacity(name, .{
        .addr_space = addr_space,
        .type = ty,
        .kind = .{ .alias = alias_index },
    }), .aliasee = aliasee });
    return alias_index;
}

pub fn addVariable(
    self: *Builder,
    name: StrtabString,
    ty: Type,
    addr_space: AddrSpace,
) Allocator.Error!Variable.Index {
    assert(!name.isAnon());
    try self.ensureUnusedTypeCapacity(1, NoExtra, 0);
    try self.ensureUnusedGlobalCapacity(name);
    try self.variables.ensureUnusedCapacity(self.gpa, 1);
    return self.addVariableAssumeCapacity(ty, name, addr_space);
}

pub fn addVariableAssumeCapacity(
    self: *Builder,
    ty: Type,
    name: StrtabString,
    addr_space: AddrSpace,
) Variable.Index {
    const variable_index: Variable.Index = @fromBackingInt(@intCast(self.variables.items.len));
    self.variables.appendAssumeCapacity(.{ .global = self.addGlobalAssumeCapacity(name, .{
        .addr_space = addr_space,
        .type = ty,
        .kind = .{ .variable = variable_index },
    }) });
    return variable_index;
}

pub fn addFunction(
    self: *Builder,
    ty: Type,
    name: StrtabString,
    addr_space: AddrSpace,
) Allocator.Error!Function.Index {
    assert(!name.isAnon());
    try self.ensureUnusedTypeCapacity(1, NoExtra, 0);
    try self.ensureUnusedGlobalCapacity(name);
    try self.functions.ensureUnusedCapacity(self.gpa, 1);
    return self.addFunctionAssumeCapacity(ty, name, addr_space);
}

pub fn addFunctionAssumeCapacity(
    self: *Builder,
    ty: Type,
    name: StrtabString,
    addr_space: AddrSpace,
) Function.Index {
    assert(ty.isFunction(self));
    const function_index: Function.Index = @fromBackingInt(@intCast(self.functions.items.len));
    self.functions.appendAssumeCapacity(.{
        .global = self.addGlobalAssumeCapacity(name, .{
            .addr_space = addr_space,
            .type = ty,
            .kind = .{ .function = function_index },
        }),
        .strip = undefined,
    });
    return function_index;
}

pub fn getIntrinsic(
    self: *Builder,
    id: Intrinsic,
    overload: []const Type,
) Allocator.Error!Function.Index {
    const ExpectedContents = extern union {
        attrs: extern struct {
            params: [expected_args_len]Type,
            fn_attrs: [FunctionAttributes.params_index + expected_args_len]Attributes,
            attrs: [expected_attrs_len]Attribute.Index,
            fields: [expected_fields_len]Type,
        },
    };
    var bfa_buf: ExpectedContents = undefined;
    var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), self.gpa);
    const allocator = bfa.allocator();

    const name = name: {
        {
            var aw: Writer.Allocating = .fromArrayList(self.gpa, &self.strtab_string_bytes);
            const w = &aw.writer;
            defer self.strtab_string_bytes = aw.toArrayList();
            w.print("llvm.{s}", .{@tagName(id)}) catch return error.OutOfMemory;
            for (overload) |ty| w.print(".{f}", .{ty.fmt(self, .m)}) catch return error.OutOfMemory;
        }
        break :name try self.trailingStrtabString();
    };
    if (self.getGlobal(name)) |global| return global.ptrConst(self).kind.function;

    const signature = Intrinsic.signatures.get(id);
    const param_types = try allocator.alloc(Type, signature.params.len);
    defer allocator.free(param_types);
    const function_attributes = try allocator.alloc(
        Attributes,
        FunctionAttributes.params_index + (signature.params.len - signature.ret_len),
    );
    defer allocator.free(function_attributes);

    var attributes: struct {
        builder: *Builder,
        list: std.array_list.Managed(Attribute.Index),

        fn deinit(state: *@This()) void {
            state.list.deinit();
            state.* = undefined;
        }

        fn get(state: *@This(), attributes: []const Attribute) Allocator.Error!Attributes {
            try state.list.resize(attributes.len);
            for (state.list.items, attributes) |*item, attribute|
                item.* = try state.builder.attr(attribute);
            return state.builder.attrs(state.list.items);
        }
    } = .{ .builder = self, .list = std.array_list.Managed(Attribute.Index).init(allocator) };
    defer attributes.deinit();

    var overload_index: usize = 0;
    function_attributes[FunctionAttributes.function_index] = try attributes.get(signature.attrs);
    function_attributes[FunctionAttributes.return_index] = .none; // void 返回所需
    for (0.., param_types, signature.params) |param_index, *param_type, signature_param| {
        switch (signature_param.kind) {
            .type => |ty| param_type.* = ty,
            .overloaded => {
                param_type.* = overload[overload_index];
                overload_index += 1;
            },
            .matches, .matches_scalar, .matches_changed_scalar => {},
        }
        function_attributes[
            if (param_index < signature.ret_len)
                FunctionAttributes.return_index
            else
                FunctionAttributes.params_index + (param_index - signature.ret_len)
        ] = try attributes.get(signature_param.attrs);
    }
    assert(overload_index == overload.len);
    for (param_types, signature.params) |*param_type, signature_param| {
        param_type.* = switch (signature_param.kind) {
            .type, .overloaded => continue,
            .matches => |param_index| param_types[param_index],
            .matches_scalar => |param_index| param_types[param_index].scalarType(self),
            .matches_changed_scalar => |info| try param_types[info.index]
                .changeScalar(info.scalar, self),
        };
    }

    const function_index = try self.addFunction(try self.fnType(switch (signature.ret_len) {
        0 => .void,
        1 => param_types[0],
        else => try self.structType(.normal, param_types[0..signature.ret_len]),
    }, param_types[signature.ret_len..], .normal), name, .default);
    function_index.ptr(self).attributes = try self.fnAttrs(function_attributes);
    return function_index;
}

pub fn intConst(self: *Builder, ty: Type, value: anytype) Allocator.Error!Constant {
    const int_value = switch (@typeInfo(@TypeOf(value))) {
        .int, .comptime_int => value,
        .@"enum" => @backingInt(value),
        else => @compileError("intConst expected an integral value, got " ++ @typeName(@TypeOf(value))),
    };
    var limbs: [
        switch (@typeInfo(@TypeOf(int_value))) {
            .int => |info| std.math.big.int.calcTwosCompLimbCount(info.bits),
            .comptime_int => std.math.big.int.calcLimbLen(int_value),
            else => unreachable,
        }
    ]std.math.big.Limb = undefined;
    return self.bigIntConst(ty, std.math.big.int.Mutable.init(&limbs, int_value).toConst());
}

pub fn intValue(self: *Builder, ty: Type, value: anytype) Allocator.Error!Value {
    return (try self.intConst(ty, value)).toValue();
}

pub fn bigIntConst(self: *Builder, ty: Type, value: std.math.big.int.Const) Allocator.Error!Constant {
    try self.constant_map.ensureUnusedCapacity(self.gpa, 1);
    try self.constant_items.ensureUnusedCapacity(self.gpa, 1);
    try self.constant_limbs.ensureUnusedCapacity(self.gpa, Constant.Integer.limbs + value.limbs.len);
    return self.bigIntConstAssumeCapacity(ty, value);
}

pub fn bigIntValue(self: *Builder, ty: Type, value: std.math.big.int.Const) Allocator.Error!Value {
    return (try self.bigIntConst(ty, value)).toValue();
}

pub fn fpConst(self: *Builder, ty: Type, comptime val: comptime_float) Allocator.Error!Constant {
    return switch (ty) {
        .half => try self.halfConst(val),
        .bfloat => try self.bfloatConst(val),
        .float => try self.floatConst(val),
        .double => try self.doubleConst(val),
        .fp128 => try self.fp128Const(val),
        .x86_fp80 => try self.x86_fp80Const(val),
        .ppc_fp128 => try self.ppc_fp128Const(.{ val, -0.0 }),
        else => unreachable,
    };
}

pub fn fpValue(self: *Builder, ty: Type, comptime value: comptime_float) Allocator.Error!Value {
    return (try self.fpConst(ty, value)).toValue();
}

pub fn nanConst(self: *Builder, ty: Type) Allocator.Error!Constant {
    return switch (ty) {
        .half => try self.halfConst(std.math.nan(f16)),
        .bfloat => try self.bfloatConst(std.math.nan(f32)),
        .float => try self.floatConst(std.math.nan(f32)),
        .double => try self.doubleConst(std.math.nan(f64)),
        .fp128 => try self.fp128Const(std.math.nan(f128)),
        .x86_fp80 => try self.x86_fp80Const(std.math.nan(f80)),
        .ppc_fp128 => try self.ppc_fp128Const(@splat(.{std.math.nan(f64)})),
        else => unreachable,
    };
}

pub fn nanValue(self: *Builder, ty: Type) Allocator.Error!Value {
    return (try self.nanConst(ty)).toValue();
}

pub fn halfConst(self: *Builder, val: f16) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.halfConstAssumeCapacity(val);
}

pub fn halfValue(self: *Builder, value: f16) Allocator.Error!Value {
    return (try self.halfConst(value)).toValue();
}

pub fn bfloatConst(self: *Builder, val: f32) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.bfloatConstAssumeCapacity(val);
}

pub fn bfloatValue(self: *Builder, value: f32) Allocator.Error!Value {
    return (try self.bfloatConst(value)).toValue();
}

pub fn floatConst(self: *Builder, val: f32) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.floatConstAssumeCapacity(val);
}

pub fn floatValue(self: *Builder, value: f32) Allocator.Error!Value {
    return (try self.floatConst(value)).toValue();
}

pub fn doubleConst(self: *Builder, val: f64) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Double, 0);
    return self.doubleConstAssumeCapacity(val);
}

pub fn doubleValue(self: *Builder, value: f64) Allocator.Error!Value {
    return (try self.doubleConst(value)).toValue();
}

pub fn fp128Const(self: *Builder, val: f128) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Fp128, 0);
    return self.fp128ConstAssumeCapacity(val);
}

pub fn fp128Value(self: *Builder, value: f128) Allocator.Error!Value {
    return (try self.fp128Const(value)).toValue();
}

pub fn x86_fp80Const(self: *Builder, val: f80) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Fp80, 0);
    return self.x86_fp80ConstAssumeCapacity(val);
}

pub fn x86_fp80Value(self: *Builder, value: f80) Allocator.Error!Value {
    return (try self.x86_fp80Const(value)).toValue();
}

pub fn ppc_fp128Const(self: *Builder, val: [2]f64) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Fp128, 0);
    return self.ppc_fp128ConstAssumeCapacity(val);
}

pub fn ppc_fp128Value(self: *Builder, value: [2]f64) Allocator.Error!Value {
    return (try self.ppc_fp128Const(value)).toValue();
}

pub fn nullConst(self: *Builder, ty: Type) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.nullConstAssumeCapacity(ty);
}

pub fn nullValue(self: *Builder, ty: Type) Allocator.Error!Value {
    return (try self.nullConst(ty)).toValue();
}

pub fn noneConst(self: *Builder, ty: Type) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.noneConstAssumeCapacity(ty);
}

pub fn noneValue(self: *Builder, ty: Type) Allocator.Error!Value {
    return (try self.noneConst(ty)).toValue();
}

pub fn structConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Aggregate, vals.len);
    return self.structConstAssumeCapacity(ty, vals);
}

pub fn structValue(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Value {
    return (try self.structConst(ty, vals)).toValue();
}

pub fn arrayConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Aggregate, vals.len);
    return self.arrayConstAssumeCapacity(ty, vals);
}

pub fn arrayValue(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Value {
    return (try self.arrayConst(ty, vals)).toValue();
}

pub fn stringConst(self: *Builder, val: String) Allocator.Error!Constant {
    try self.ensureUnusedTypeCapacity(1, Type.Array, 0);
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.stringConstAssumeCapacity(val);
}

pub fn stringValue(self: *Builder, val: String) Allocator.Error!Value {
    return (try self.stringConst(val)).toValue();
}

pub fn vectorConst(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Aggregate, vals.len);
    return self.vectorConstAssumeCapacity(ty, vals);
}

pub fn vectorValue(self: *Builder, ty: Type, vals: []const Constant) Allocator.Error!Value {
    return (try self.vectorConst(ty, vals)).toValue();
}

pub fn splatConst(self: *Builder, ty: Type, val: Constant) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Splat, 0);
    return self.splatConstAssumeCapacity(ty, val);
}

pub fn splatValue(self: *Builder, ty: Type, val: Constant) Allocator.Error!Value {
    return (try self.splatConst(ty, val)).toValue();
}

pub fn zeroInitConst(self: *Builder, ty: Type) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Fp128, 0);
    try self.constant_limbs.ensureUnusedCapacity(
        self.gpa,
        Constant.Integer.limbs + comptime std.math.big.int.calcLimbLen(0),
    );
    return self.zeroInitConstAssumeCapacity(ty);
}

pub fn zeroInitValue(self: *Builder, ty: Type) Allocator.Error!Value {
    return (try self.zeroInitConst(ty)).toValue();
}

pub fn undefConst(self: *Builder, ty: Type) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.undefConstAssumeCapacity(ty);
}

pub fn undefValue(self: *Builder, ty: Type) Allocator.Error!Value {
    return (try self.undefConst(ty)).toValue();
}

pub fn poisonConst(self: *Builder, ty: Type) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.poisonConstAssumeCapacity(ty);
}

pub fn poisonValue(self: *Builder, ty: Type) Allocator.Error!Value {
    return (try self.poisonConst(ty)).toValue();
}

pub fn blockAddrConst(
    self: *Builder,
    function: Function.Index,
    block: Function.Block.Index,
) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.BlockAddress, 0);
    return self.blockAddrConstAssumeCapacity(function, block);
}

pub fn blockAddrValue(
    self: *Builder,
    function: Function.Index,
    block: Function.Block.Index,
) Allocator.Error!Value {
    return (try self.blockAddrConst(function, block)).toValue();
}

pub fn dsoLocalEquivalentConst(self: *Builder, function: Function.Index) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.dsoLocalEquivalentConstAssumeCapacity(function);
}

pub fn dsoLocalEquivalentValue(self: *Builder, function: Function.Index) Allocator.Error!Value {
    return (try self.dsoLocalEquivalentConst(function)).toValue();
}

pub fn noCfiConst(self: *Builder, function: Function.Index) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, NoExtra, 0);
    return self.noCfiConstAssumeCapacity(function);
}

pub fn noCfiValue(self: *Builder, function: Function.Index) Allocator.Error!Value {
    return (try self.noCfiConst(function)).toValue();
}

pub fn convConst(
    self: *Builder,
    val: Constant,
    ty: Type,
) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Cast, 0);
    return self.convConstAssumeCapacity(val, ty);
}

pub fn convValue(
    self: *Builder,
    val: Constant,
    ty: Type,
) Allocator.Error!Value {
    return (try self.convConst(val, ty)).toValue();
}

pub fn castConst(self: *Builder, tag: Constant.Tag, val: Constant, ty: Type) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Cast, 0);
    return self.castConstAssumeCapacity(tag, val, ty);
}

pub fn castValue(self: *Builder, tag: Constant.Tag, val: Constant, ty: Type) Allocator.Error!Value {
    return (try self.castConst(tag, val, ty)).toValue();
}

pub fn gepConst(
    self: *Builder,
    comptime kind: Constant.GetElementPtr.Kind,
    ty: Type,
    base: Constant,
    inrange: ?u16,
    indices: []const Constant,
) Allocator.Error!Constant {
    try self.ensureUnusedTypeCapacity(1, Type.Vector, 0);
    try self.ensureUnusedConstantCapacity(1, Constant.GetElementPtr, indices.len);
    return self.gepConstAssumeCapacity(kind, ty, base, inrange, indices);
}

pub fn gepValue(
    self: *Builder,
    comptime kind: Constant.GetElementPtr.Kind,
    ty: Type,
    base: Constant,
    inrange: ?u16,
    indices: []const Constant,
) Allocator.Error!Value {
    return (try self.gepConst(kind, ty, base, inrange, indices)).toValue();
}

pub fn binConst(
    self: *Builder,
    tag: Constant.Tag,
    lhs: Constant,
    rhs: Constant,
) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Binary, 0);
    return self.binConstAssumeCapacity(tag, lhs, rhs);
}

pub fn binValue(self: *Builder, tag: Constant.Tag, lhs: Constant, rhs: Constant) Allocator.Error!Value {
    return (try self.binConst(tag, lhs, rhs)).toValue();
}

pub fn asmConst(
    self: *Builder,
    ty: Type,
    info: Constant.Assembly.Info,
    assembly: String,
    constraints: String,
) Allocator.Error!Constant {
    try self.ensureUnusedConstantCapacity(1, Constant.Assembly, 0);
    return self.asmConstAssumeCapacity(ty, info, assembly, constraints);
}

pub fn asmValue(
    self: *Builder,
    ty: Type,
    info: Constant.Assembly.Info,
    assembly: String,
    constraints: String,
) Allocator.Error!Value {
    return (try self.asmConst(ty, info, assembly, constraints)).toValue();
}

/// 前向引用的初始“已解析”值为 `Alignment.default`。
pub fn alignmentForwardReference(b: *Builder) Allocator.Error!Alignment.Lazy {
    const index = b.alignment_forward_references.items.len;
    try b.alignment_forward_references.append(b.gpa, .default);
    return .fromFwdRefIndex(index);
}

/// 将对齐前向引用 `fwd_ref` 的“已解析”值更新为 `value`。
///
/// 断言 `fwd_ref` 是前向引用,而非已经解析的对齐值。
pub fn resolveAlignmentForwardReference(b: *Builder, fwd_ref: Alignment.Lazy, value: Alignment) void {
    const index = fwd_ref.toFwdRefIndex();
    b.alignment_forward_references.items[index] = value;
}

pub fn dump(b: *Builder, io: Io) void {
    var buffer: [4000]u8 = undefined;
    const stderr: Io.File = .stderr();
    b.printToFile(io, stderr, &buffer) catch {};
}

pub fn printToFilePath(b: *Builder, io: Io, dir: Io.Dir, path: []const u8) !void {
    var buffer: [4000]u8 = undefined;
    const file = try dir.createFile(io, path, .{});
    defer file.close(io);
    try b.printToFile(io, file, &buffer);
}

pub fn printToFile(b: *Builder, io: Io, file: Io.File, buffer: []u8) !void {
    var fw = file.writer(io, buffer);
    try print(b, &fw.interface);
    try fw.interface.flush();
}

pub fn print(self: *Builder, w: *Writer) (Writer.Error || Allocator.Error)!void {
    var need_newline = false;
    var metadata_formatter: Metadata.Formatter = .{ .builder = self, .need_comma = undefined };
    defer metadata_formatter.map.deinit(self.gpa);

    if (self.source_filename != .none or self.data_layout.string_repr != .none or self.target_triple != .none) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        if (self.source_filename != .none) try w.print(
            \\; ModuleID = '{s}'
            \\source_filename = {f}
            \\
        , .{ self.source_filename.slice(self).?, self.source_filename.fmtQ(self) });
        if (self.data_layout.string_repr != .none) try w.print(
            \\target datalayout = {f}
            \\
        , .{self.data_layout.string_repr.fmtQ(self)});
        if (self.target_triple != .none) try w.print(
            \\target triple = {f}
            \\
        , .{self.target_triple.fmtQ(self)});
    }

    if (self.module_asm.items.len > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        var line_it = std.mem.tokenizeScalar(u8, self.module_asm.items, '\n');
        while (line_it.next()) |line| {
            try w.writeAll("module asm ");
            try printEscapedString(line, .always_quote, w);
            try w.writeByte('\n');
        }
    }

    if (self.types.count() > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        for (self.types.keys(), self.types.values()) |id, ty| try w.print(
            \\%{f} = type {f}
            \\
        , .{ id.fmt(self), ty.fmt(self, .default) });
    }

    if (self.variables.items.len > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        for (self.variables.items, 0..) |variable, variable_i| {
            // 若变量的全局符号已另作他用,则跳过该变量。
            switch (variable.global.ptrConst(self).kind) {
                .variable => |v| if (@backingInt(v) != variable_i) continue,
                else => continue,
            }
            const global = variable.global.ptrConst(self);
            metadata_formatter.need_comma = true;
            defer metadata_formatter.need_comma = undefined;
            try w.print(
                \\{f} ={f}{f}{f}{f}{f}{f}{f}{f} {s} {f}{f}
            , .{
                variable.global.fmt(self),
                Linkage.fmtOptional(
                    if (global.linkage == .external and variable.init != .no_init) null else global.linkage,
                ),
                global.preemption,
                global.visibility,
                global.dll_storage_class,
                variable.thread_local.fmt(" "),
                global.unnamed_addr,
                global.addr_space.fmt(" "),
                global.externally_initialized,
                @tagName(variable.mutability),
                global.type.fmt(self, .percent),
                variable.init.fmt(self, .{ .space = true }),
            });
            if (variable.section != .none) {
                try w.print(", section {f}", .{variable.section.fmtQ(self)});
            }
            try w.print(
                \\{f}{f}
                \\
            , .{
                variable.alignment.fmt(", "),
                try metadata_formatter.fmt("!dbg ", global.dbg, null),
            });
        }
    }

    if (self.aliases.items.len > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        for (self.aliases.items, 0..) |alias, alias_i| {
            // 若别名对应的全局对象已被改作其他用途,则跳过该别名。
            switch (alias.global.ptrConst(self).kind) {
                .alias => |a| if (@backingInt(a) != alias_i) continue,
                else => continue,
            }
            const global = alias.global.ptrConst(self);
            metadata_formatter.need_comma = true;
            defer metadata_formatter.need_comma = undefined;
            try w.print(
                \\{f} ={f}{f}{f}{f}{f}{f} alias {f}, {f}{f}
                \\
            , .{
                alias.global.fmt(self),
                global.linkage,
                global.preemption,
                global.visibility,
                global.dll_storage_class,
                alias.thread_local.fmt(" "),
                global.unnamed_addr,
                global.type.fmt(self, .percent),
                alias.aliasee.fmt(self, .{ .percent = true }),
                try metadata_formatter.fmt("!dbg ", global.dbg, null),
            });
        }
    }

    var attribute_groups: std.array_hash_map.Auto(Attributes, void) = .empty;
    defer attribute_groups.deinit(self.gpa);

    for (0.., self.functions.items) |function_i, function| {
        // 如果函数的全局项已改作其他用途,则跳过该函数。
        switch (function.global.ptrConst(self).kind) {
            .function => |f| if (@backingInt(f) != function_i) continue,
            else => continue,
        }
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        const function_index: Function.Index = @fromBackingInt(@intCast(function_i));
        const global = function.global.ptrConst(self);
        const params_len = global.type.functionParameters(self).len;
        const function_attributes = function.attributes.func(self);
        if (function_attributes != .none) try w.print(
            \\; Function Attrs:{f}
            \\
        , .{function_attributes.fmt(self, .{})});
        try w.print(
            \\{s}{f}{f}{f}{f}{f}{f} {f} {f}(
        , .{
            if (function.instructions.len > 0) "define" else "declare",
            global.linkage,
            global.preemption,
            global.visibility,
            global.dll_storage_class,
            function.call_conv,
            function.attributes.ret(self).fmt(self, .{}),
            global.type.functionReturn(self).fmt(self, .percent),
            function.global.fmt(self),
        });
        for (0..params_len) |arg| {
            if (arg > 0) try w.writeAll(", ");
            try w.print(
                \\{f}{f}
            , .{
                global.type.functionParameters(self)[arg].fmt(self, .percent),
                function.attributes.param(arg, self).fmt(self, .{}),
            });
            if (function.instructions.len > 0)
                try w.print(" {f}", .{function.arg(@intCast(arg)).fmt(function_index, self, .{})})
            else
                try w.print(" %{d}", .{arg});
        }
        switch (global.type.functionKind(self)) {
            .normal => {},
            .vararg => {
                if (params_len > 0) try w.writeAll(", ");
                try w.writeAll("...");
            },
        }
        try w.print("){f}{f}", .{ global.unnamed_addr, global.addr_space.fmt(" ") });
        if (function_attributes != .none) try w.print(" #{d}", .{
            (try attribute_groups.getOrPutValue(self.gpa, function_attributes, {})).index,
        });
        {
            metadata_formatter.need_comma = false;
            defer metadata_formatter.need_comma = undefined;
            if (function.section != .none) {
                try w.print(" section {f}", .{function.section.fmtQ(self)});
            }
            try w.print("{f}{f}", .{
                function.alignment.fmt(" "),
                try metadata_formatter.fmt(" !dbg ", global.dbg, null),
            });
        }
        if (function.instructions.len > 0) {
            var block_incoming_len: u32 = undefined;
            try w.writeAll(" {\n");
            var maybe_dbg_index: ?u32 = null;
            for (params_len..function.instructions.len) |instruction_i| {
                const instruction_index: Function.Instruction.Index = @fromBackingInt(@intCast(instruction_i));
                const instruction = function.instructions.get(@backingInt(instruction_index));
                if (function.debug_locations.get(instruction_index)) |debug_location| switch (debug_location) {
                    .no_location => maybe_dbg_index = null,
                    .location => |location| {
                        const gop = try metadata_formatter.map.getOrPut(self.gpa, .{
                            .debug_location = location,
                        });
                        maybe_dbg_index = @intCast(gop.index);
                    },
                };
                switch (instruction.tag) {
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .@"add nuw nsw",
                    .@"and",
                    .ashr,
                    .@"ashr exact",
                    .fadd,
                    .@"fadd fast",
                    .@"fcmp false",
                    .@"fcmp fast false",
                    .@"fcmp fast oeq",
                    .@"fcmp fast oge",
                    .@"fcmp fast ogt",
                    .@"fcmp fast ole",
                    .@"fcmp fast olt",
                    .@"fcmp fast one",
                    .@"fcmp fast ord",
                    .@"fcmp fast true",
                    .@"fcmp fast ueq",
                    .@"fcmp fast uge",
                    .@"fcmp fast ugt",
                    .@"fcmp fast ule",
                    .@"fcmp fast ult",
                    .@"fcmp fast une",
                    .@"fcmp fast uno",
                    .@"fcmp oeq",
                    .@"fcmp oge",
                    .@"fcmp ogt",
                    .@"fcmp ole",
                    .@"fcmp olt",
                    .@"fcmp one",
                    .@"fcmp ord",
                    .@"fcmp true",
                    .@"fcmp ueq",
                    .@"fcmp uge",
                    .@"fcmp ugt",
                    .@"fcmp ule",
                    .@"fcmp ult",
                    .@"fcmp une",
                    .@"fcmp uno",
                    .fdiv,
                    .@"fdiv fast",
                    .fmul,
                    .@"fmul fast",
                    .frem,
                    .@"frem fast",
                    .fsub,
                    .@"fsub fast",
                    .@"icmp eq",
                    .@"icmp ne",
                    .@"icmp sge",
                    .@"icmp sgt",
                    .@"icmp sle",
                    .@"icmp slt",
                    .@"icmp uge",
                    .@"icmp ugt",
                    .@"icmp ule",
                    .@"icmp ult",
                    .lshr,
                    .@"lshr exact",
                    .mul,
                    .@"mul nsw",
                    .@"mul nuw",
                    .@"mul nuw nsw",
                    .@"or",
                    .sdiv,
                    .@"sdiv exact",
                    .srem,
                    .shl,
                    .@"shl nsw",
                    .@"shl nuw",
                    .@"shl nuw nsw",
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .@"sub nuw nsw",
                    .udiv,
                    .@"udiv exact",
                    .urem,
                    .xor,
                    => |tag| {
                        const extra = function.extraData(Function.Instruction.Binary, instruction.data);
                        try w.print("  %{f} = {s} {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.lhs.fmt(function_index, self, .{ .percent = true }),
                            extra.rhs.fmt(function_index, self, .{}),
                        });
                    },
                    .addrspacecast,
                    .bitcast,
                    .fpext,
                    .fptosi,
                    .fptoui,
                    .fptrunc,
                    .inttoptr,
                    .ptrtoint,
                    .sext,
                    .sitofp,
                    .trunc,
                    .@"trunc nuw",
                    .@"trunc nsw",
                    .@"trunc nuw nsw",
                    .uitofp,
                    .zext,
                    => |tag| {
                        const extra = function.extraData(Function.Instruction.Cast, instruction.data);
                        try w.print("  %{f} = {s} {f} to {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.val.fmt(function_index, self, .{ .percent = true }),
                            extra.type.fmt(self, .percent),
                        });
                    },
                    .alloca,
                    .@"alloca inalloca",
                    => |tag| {
                        const extra = function.extraData(Function.Instruction.Alloca, instruction.data);
                        try w.print("  %{f} = {s} {f}{f}{f}{f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.type.fmt(self, .percent),
                            Value.fmt(switch (extra.len) {
                                .@"1" => .none,
                                else => extra.len,
                            }, function_index, self, .{
                                .comma = true,
                                .percent = true,
                            }),
                            extra.info.alignment.fmt(", "),
                            extra.info.addr_space.fmt(", "),
                        });
                    },
                    .arg => unreachable,
                    .atomicrmw => |tag| {
                        const extra =
                            function.extraData(Function.Instruction.AtomicRmw, instruction.data);
                        try w.print("  %{f} = {t}{f} {t} {f}, {f}{f}{f}{f}", .{
                            instruction_index.name(&function).fmt(self),
                            tag,
                            extra.info.access_kind.fmt(" "),
                            extra.info.atomic_rmw_operation,
                            extra.ptr.fmt(function_index, self, .{ .percent = true }),
                            extra.val.fmt(function_index, self, .{ .percent = true }),
                            extra.info.sync_scope.fmt(" "),
                            extra.info.success_ordering.fmt(" "),
                            extra.info.alignment.fmt(", "),
                        });
                    },
                    .block => {
                        block_incoming_len = instruction.data;
                        const name = instruction_index.name(&function);
                        if (@backingInt(instruction_index) > params_len)
                            try w.writeByte('\n');
                        try w.print("{f}:\n", .{name.fmt(self)});
                        continue;
                    },
                    .br => |tag| {
                        const target: Function.Block.Index = @fromBackingInt(instruction.data);
                        try w.print("  {s} {f}", .{
                            @tagName(tag), target.toInst(&function).fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .br_cond => {
                        const extra = function.extraData(Function.Instruction.BrCond, instruction.data);
                        try w.print("  br {f}, {f}, {f}", .{
                            extra.cond.fmt(function_index, self, .{ .percent = true }),
                            extra.then.toInst(&function).fmt(function_index, self, .{ .percent = true }),
                            extra.@"else".toInst(&function).fmt(function_index, self, .{ .percent = true }),
                        });
                        metadata_formatter.need_comma = true;
                        defer metadata_formatter.need_comma = undefined;
                        switch (extra.weights) {
                            .none => {},
                            .unpredictable => try w.writeAll(", !unpredictable !{}"),
                            _ => try w.print("{f}", .{
                                try metadata_formatter.fmt(", !prof ", extra.weights.toMetadata(), null),
                            }),
                        }
                    },
                    .call,
                    .@"call fast",
                    .@"musttail call",
                    .@"musttail call fast",
                    .@"notail call",
                    .@"notail call fast",
                    .@"tail call",
                    .@"tail call fast",
                    => |tag| {
                        var extra =
                            function.extraDataTrail(Function.Instruction.Call, instruction.data);
                        const args = extra.trail.next(extra.data.args_len, Value, &function);
                        try w.writeAll("  ");
                        const ret_ty = extra.data.ty.functionReturn(self);
                        switch (ret_ty) {
                            .void => {},
                            else => try w.print("%{f} = ", .{
                                instruction_index.name(&function).fmt(self),
                            }),
                            .none => unreachable,
                        }
                        try w.print("{t}{f}{f}{f} {f} {f}(", .{
                            tag,
                            extra.data.info.call_conv,
                            extra.data.attributes.ret(self).fmt(self, .{}),
                            extra.data.callee.typeOf(function_index, self).pointerAddrSpace(self),
                            switch (extra.data.ty.functionKind(self)) {
                                .normal => ret_ty,
                                .vararg => extra.data.ty,
                            }.fmt(self, .percent),
                            extra.data.callee.fmt(function_index, self, .{}),
                        });
                        for (0.., args) |arg_index, arg| {
                            if (arg_index > 0) try w.writeAll(", ");
                            metadata_formatter.need_comma = false;
                            defer metadata_formatter.need_comma = undefined;
                            try w.print("{f}{f}{f}", .{
                                arg.typeOf(function_index, self).fmt(self, .percent),
                                extra.data.attributes.param(arg_index, self).fmt(self, .{}),
                                try metadata_formatter.fmtLocal(" ", arg, function_index),
                            });
                        }
                        try w.writeByte(')');
                        if (extra.data.info.has_op_bundle_cold) {
                            try w.writeAll(" [ \"cold\"() ]");
                        }
                        const call_function_attributes = extra.data.attributes.func(self);
                        if (call_function_attributes != .none) try w.print(" #{d}", .{
                            (try attribute_groups.getOrPutValue(
                                self.gpa,
                                call_function_attributes,
                                {},
                            )).index,
                        });
                    },
                    .cmpxchg,
                    .@"cmpxchg weak",
                    => |tag| {
                        const extra =
                            function.extraData(Function.Instruction.CmpXchg, instruction.data);
                        try w.print("  %{f} = {t}{f} {f}, {f}, {f}{f}{f}{f}{f}", .{
                            instruction_index.name(&function).fmt(self),
                            tag,
                            extra.info.access_kind.fmt(" "),
                            extra.ptr.fmt(function_index, self, .{ .percent = true }),
                            extra.cmp.fmt(function_index, self, .{ .percent = true }),
                            extra.new.fmt(function_index, self, .{ .percent = true }),
                            extra.info.sync_scope.fmt(" "),
                            extra.info.success_ordering.fmt(" "),
                            extra.info.failure_ordering.fmt(" "),
                            extra.info.alignment.fmt(", "),
                        });
                    },
                    .extractelement => |tag| {
                        const extra =
                            function.extraData(Function.Instruction.ExtractElement, instruction.data);
                        try w.print("  %{f} = {s} {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.val.fmt(function_index, self, .{ .percent = true }),
                            extra.index.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .extractvalue => |tag| {
                        var extra = function.extraDataTrail(
                            Function.Instruction.ExtractValue,
                            instruction.data,
                        );
                        const indices = extra.trail.next(extra.data.indices_len, u32, &function);
                        try w.print("  %{f} = {s} {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.data.val.fmt(function_index, self, .{ .percent = true }),
                        });
                        for (indices) |index| try w.print(", {d}", .{index});
                    },
                    .fence => |tag| {
                        const info: MemoryAccessInfo = @bitCast(instruction.data);
                        try w.print("  {t}{f}{f}", .{
                            tag,
                            info.sync_scope.fmt(" "),
                            info.success_ordering.fmt(" "),
                        });
                    },
                    .fneg,
                    .@"fneg fast",
                    => |tag| {
                        const val: Value = @fromBackingInt(instruction.data);
                        try w.print("  %{f} = {s} {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            val.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => |tag| {
                        var extra = function.extraDataTrail(
                            Function.Instruction.GetElementPtr,
                            instruction.data,
                        );
                        const indices = extra.trail.next(extra.data.indices_len, Value, &function);
                        try w.print("  %{f} = {s} {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.data.type.fmt(self, .percent),
                            extra.data.base.fmt(function_index, self, .{ .percent = true }),
                        });
                        for (indices) |index| try w.print(", {f}", .{
                            index.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .indirectbr => |tag| {
                        var extra =
                            function.extraDataTrail(Function.Instruction.IndirectBr, instruction.data);
                        const targets =
                            extra.trail.next(extra.data.targets_len, Function.Block.Index, &function);
                        try w.print("  {s} {f}, [", .{
                            @tagName(tag),
                            extra.data.addr.fmt(function_index, self, .{ .percent = true }),
                        });
                        for (0.., targets) |target_index, target| {
                            if (target_index > 0) try w.writeAll(", ");
                            try w.print("{f}", .{
                                target.toInst(&function).fmt(function_index, self, .{ .percent = true }),
                            });
                        }
                        try w.writeByte(']');
                    },
                    .insertelement => |tag| {
                        const extra =
                            function.extraData(Function.Instruction.InsertElement, instruction.data);
                        try w.print("  %{f} = {s} {f}, {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.val.fmt(function_index, self, .{ .percent = true }),
                            extra.elem.fmt(function_index, self, .{ .percent = true }),
                            extra.index.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .insertvalue => |tag| {
                        var extra =
                            function.extraDataTrail(Function.Instruction.InsertValue, instruction.data);
                        const indices = extra.trail.next(extra.data.indices_len, u32, &function);
                        try w.print("  %{f} = {s} {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.data.val.fmt(function_index, self, .{ .percent = true }),
                            extra.data.elem.fmt(function_index, self, .{ .percent = true }),
                        });
                        for (indices) |index| try w.print(", {d}", .{index});
                    },
                    .load,
                    .@"load atomic",
                    => |tag| {
                        const extra = function.extraData(Function.Instruction.Load, instruction.data);
                        try w.print("  %{f} = {t}{f} {f}, {f}{f}{f}{f}", .{
                            instruction_index.name(&function).fmt(self),
                            tag,
                            extra.info.access_kind.fmt(" "),
                            extra.type.fmt(self, .percent),
                            extra.ptr.fmt(function_index, self, .{ .percent = true }),
                            extra.info.sync_scope.fmt(" "),
                            extra.info.success_ordering.fmt(" "),
                            extra.info.alignment.fmt(", "),
                        });
                    },
                    .phi,
                    .@"phi fast",
                    => |tag| {
                        var extra = function.extraDataTrail(Function.Instruction.Phi, instruction.data);
                        const vals = extra.trail.next(block_incoming_len, Value, &function);
                        const blocks =
                            extra.trail.next(block_incoming_len, Function.Block.Index, &function);
                        try w.print("  %{f} = {s} {f} ", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            vals[0].typeOf(function_index, self).fmt(self, .percent),
                        });
                        for (0.., vals, blocks) |incoming_index, incoming_val, incoming_block| {
                            if (incoming_index > 0) try w.writeAll(", ");
                            try w.print("[ {f}, {f} ]", .{
                                incoming_val.fmt(function_index, self, .{}),
                                incoming_block.toInst(&function).fmt(function_index, self, .{}),
                            });
                        }
                    },
                    .ret => |tag| {
                        const val: Value = @fromBackingInt(instruction.data);
                        try w.print("  {s} {f}", .{
                            @tagName(tag),
                            val.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .@"ret void",
                    .@"unreachable",
                    => |tag| try w.print("  {s}", .{@tagName(tag)}),
                    .select,
                    .@"select fast",
                    => |tag| {
                        const extra = function.extraData(Function.Instruction.Select, instruction.data);
                        try w.print("  %{f} = {s} {f}, {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.cond.fmt(function_index, self, .{ .percent = true }),
                            extra.lhs.fmt(function_index, self, .{ .percent = true }),
                            extra.rhs.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .shufflevector => |tag| {
                        const extra =
                            function.extraData(Function.Instruction.ShuffleVector, instruction.data);
                        try w.print("  %{f} = {s} {f}, {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.lhs.fmt(function_index, self, .{ .percent = true }),
                            extra.rhs.fmt(function_index, self, .{ .percent = true }),
                            extra.mask.fmt(function_index, self, .{ .percent = true }),
                        });
                    },
                    .store,
                    .@"store atomic",
                    => |tag| {
                        const extra = function.extraData(Function.Instruction.Store, instruction.data);
                        try w.print("  {t}{f} {f}, {f}{f}{f}{f}", .{
                            tag,
                            extra.info.access_kind.fmt(" "),
                            extra.val.fmt(function_index, self, .{ .percent = true }),
                            extra.ptr.fmt(function_index, self, .{ .percent = true }),
                            extra.info.sync_scope.fmt(" "),
                            extra.info.success_ordering.fmt(" "),
                            extra.info.alignment.fmt(", "),
                        });
                    },
                    .@"switch" => |tag| {
                        var extra =
                            function.extraDataTrail(Function.Instruction.Switch, instruction.data);
                        const vals = extra.trail.next(extra.data.cases_len, Constant, &function);
                        const blocks =
                            extra.trail.next(extra.data.cases_len, Function.Block.Index, &function);
                        try w.print("  {s} {f}, {f} [\n", .{
                            @tagName(tag),
                            extra.data.val.fmt(function_index, self, .{ .percent = true }),
                            extra.data.default.toInst(&function).fmt(function_index, self, .{ .percent = true }),
                        });
                        for (vals, blocks) |case_val, case_block| try w.print(
                            "    {f}, {f}\n",
                            .{
                                case_val.fmt(self, .{ .percent = true }),
                                case_block.toInst(&function).fmt(function_index, self, .{ .percent = true }),
                            },
                        );
                        try w.writeAll("  ]");
                        metadata_formatter.need_comma = true;
                        defer metadata_formatter.need_comma = undefined;
                        switch (extra.data.weights) {
                            .none => {},
                            .unpredictable => try w.writeAll("!unpredictable !{}"),
                            _ => try w.print("{f}", .{
                                try metadata_formatter.fmt("!prof ", extra.data.weights.toMetadata(), null),
                            }),
                        }
                    },
                    .va_arg => |tag| {
                        const extra = function.extraData(Function.Instruction.VaArg, instruction.data);
                        try w.print("  %{f} = {s} {f}, {f}", .{
                            instruction_index.name(&function).fmt(self),
                            @tagName(tag),
                            extra.list.fmt(function_index, self, .{ .percent = true }),
                            extra.type.fmt(self, .percent),
                        });
                    },
                }

                if (maybe_dbg_index) |dbg_index| {
                    try w.print(", !dbg !{d}", .{dbg_index});
                }
                try w.writeByte('\n');
            }
            try w.writeByte('}');
        }
        try w.writeByte('\n');
    }

    if (attribute_groups.count() > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        for (0.., attribute_groups.keys()) |attribute_group_index, attribute_group|
            try w.print(
                \\attributes #{d} = {{{f} }}
                \\
            , .{ attribute_group_index, attribute_group.fmt(self, .{ .pound = true, .quote = true }) });
    }

    if (self.metadata_named.count() > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        for (self.metadata_named.keys(), self.metadata_named.values()) |name, data| {
            const elements: []const Metadata =
                @ptrCast(self.metadata_extra.items[data.index..][0..data.len]);
            try w.writeByte('!');
            try printEscapedString(name.slice(self).?, .quote_unless_valid_identifier, w);
            try w.writeAll(" = !{");
            metadata_formatter.need_comma = false;
            defer metadata_formatter.need_comma = undefined;
            for (elements) |element| try w.print("{f}", .{try metadata_formatter.fmt("", element, null)});
            try w.writeAll("}\n");
        }
    }

    if (metadata_formatter.map.count() > 0) {
        if (need_newline) try w.writeByte('\n') else need_newline = true;
        var metadata_index: usize = 0;
        while (metadata_index < metadata_formatter.map.count()) : (metadata_index += 1) {
            @setEvalBranchQuota(10_000);
            try w.print("!{d} = ", .{metadata_index});
            metadata_formatter.need_comma = false;
            defer metadata_formatter.need_comma = undefined;

            const key = metadata_formatter.map.keys()[metadata_index];
            const metadata_item = switch (key) {
                .debug_location => |location| {
                    try metadata_formatter.specialized(.@"!", .DILocation, .{
                        .line = location.line,
                        .column = location.column,
                        .scope = location.scope,
                        .inlinedAt = location.inlined_at,
                        .isImplicitCode = false,
                    }, w);
                    continue;
                },
                .metadata => |metadata| metadata.item(self),
            };

            switch (metadata_item.tag) {
                .expression, .constant => unreachable,
                .file => {
                    const extra = self.metadataExtraData(Metadata.File, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DIFile, .{
                        .filename = extra.filename,
                        .directory = extra.directory,
                        .checksumkind = null,
                        .checksum = null,
                        .source = null,
                    }, w);
                },
                .compile_unit,
                .@"compile_unit optimized",
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.CompileUnit, metadata_item.data);
                    try metadata_formatter.specialized(.@"distinct !", .DICompileUnit, .{
                        .language = .DW_LANG_C99,
                        .file = extra.file,
                        .producer = extra.producer,
                        .isOptimized = switch (kind) {
                            .compile_unit => false,
                            .@"compile_unit optimized" => true,
                            else => unreachable,
                        },
                        .flags = null,
                        .runtimeVersion = 0,
                        .splitDebugFilename = null,
                        .emissionKind = .FullDebug,
                        .enums = extra.enums,
                        .retainedTypes = null,
                        .globals = extra.globals,
                        .imports = null,
                        .macros = null,
                        .dwoId = null,
                        .splitDebugInlining = false,
                        .debugInfoForProfiling = null,
                        .nameTableKind = null,
                        .rangesBaseAddress = null,
                        .sysroot = null,
                        .sdk = null,
                    }, w);
                },
                .subprogram,
                .@"subprogram local",
                .@"subprogram definition",
                .@"subprogram local definition",
                .@"subprogram optimized",
                .@"subprogram optimized local",
                .@"subprogram optimized definition",
                .@"subprogram optimized local definition",
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.Subprogram, metadata_item.data);
                    try metadata_formatter.specialized(.@"distinct !", .DISubprogram, .{
                        .name = extra.name,
                        .linkageName = extra.linkage_name,
                        .scope = extra.file,
                        .file = extra.file,
                        .line = extra.line,
                        .type = extra.ty,
                        .scopeLine = extra.scope_line,
                        .containingType = null,
                        .virtualIndex = null,
                        .thisAdjustment = null,
                        .flags = extra.di_flags,
                        .spFlags = @as(Metadata.Subprogram.DISPFlags, @bitCast(@as(u32, @as(u3, @intCast(
                            @backingInt(kind) - @backingInt(Metadata.Tag.subprogram),
                        ))) << 2)),
                        .unit = extra.compile_unit,
                        .templateParams = null,
                        .declaration = null,
                        .retainedNodes = null,
                        .thrownTypes = null,
                        .annotations = null,
                        .targetFuncName = null,
                    }, w);
                },
                .lexical_block => {
                    const extra = self.metadataExtraData(Metadata.LexicalBlock, metadata_item.data);
                    try metadata_formatter.specialized(.@"distinct !", .DILexicalBlock, .{
                        .scope = extra.scope,
                        .file = extra.file,
                        .line = extra.line,
                        .column = extra.column,
                    }, w);
                },
                .location => {
                    const extra = self.metadataExtraData(Metadata.Location, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DILocation, .{
                        .line = extra.line,
                        .column = extra.column,
                        .scope = extra.scope,
                        .inlinedAt = extra.inlined_at,
                        .isImplicitCode = false,
                    }, w);
                },
                .basic_bool_type,
                .basic_unsigned_type,
                .basic_signed_type,
                .basic_float_type,
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.BasicType, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DIBasicType, .{
                        .tag = null,
                        .name = extra.name,
                        .size = extra.bitSize(),
                        .@"align" = null,
                        .encoding = @as(enum {
                            DW_ATE_boolean,
                            DW_ATE_unsigned,
                            DW_ATE_signed,
                            DW_ATE_float,
                        }, switch (kind) {
                            .basic_bool_type => .DW_ATE_boolean,
                            .basic_unsigned_type => .DW_ATE_unsigned,
                            .basic_signed_type => .DW_ATE_signed,
                            .basic_float_type => .DW_ATE_float,
                            else => unreachable,
                        }),
                        .flags = null,
                    }, w);
                },
                .composite_struct_type,
                .composite_union_type,
                .composite_enumeration_type,
                .composite_array_type,
                .composite_vector_type,
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.CompositeType, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DICompositeType, .{
                        .tag = @as(enum {
                            DW_TAG_structure_type,
                            DW_TAG_union_type,
                            DW_TAG_enumeration_type,
                            DW_TAG_array_type,
                        }, switch (kind) {
                            .composite_struct_type => .DW_TAG_structure_type,
                            .composite_union_type => .DW_TAG_union_type,
                            .composite_enumeration_type => .DW_TAG_enumeration_type,
                            .composite_array_type, .composite_vector_type => .DW_TAG_array_type,
                            else => unreachable,
                        }),
                        .name = extra.name,
                        .scope = extra.scope,
                        .file = null,
                        .line = null,
                        .baseType = extra.underlying_type,
                        .size = extra.bitSize(),
                        .@"align" = extra.bitAlign(),
                        .offset = null,
                        .flags = null,
                        .elements = extra.fields_tuple,
                        .runtimeLang = null,
                        .vtableHolder = null,
                        .templateParams = null,
                        .identifier = null,
                        .discriminator = null,
                        .dataLocation = null,
                        .associated = null,
                        .allocated = null,
                        .rank = null,
                        .annotations = null,
                    }, w);
                },
                .derived_pointer_type,
                .derived_member_type,
                .derived_typedef_type,
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.DerivedType, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DIDerivedType, .{
                        .tag = @as(enum {
                            DW_TAG_pointer_type,
                            DW_TAG_member,
                            DW_TAG_typedef,
                        }, switch (kind) {
                            .derived_pointer_type => .DW_TAG_pointer_type,
                            .derived_member_type => .DW_TAG_member,
                            .derived_typedef_type => .DW_TAG_typedef,
                            else => unreachable,
                        }),
                        .name = extra.name,
                        .scope = extra.scope,
                        .file = null,
                        .line = null,
                        .baseType = extra.underlying_type,
                        .size = extra.bitSize(),
                        .@"align" = extra.bitAlign(),
                        .offset = switch (extra.bitOffset()) {
                            0 => null,
                            else => |bit_offset| bit_offset,
                        },
                        .flags = null,
                        .extraData = null,
                        .dwarfAddressSpace = null,
                        .annotations = null,
                    }, w);
                },
                .subroutine_type => {
                    const extra = self.metadataExtraData(Metadata.SubroutineType, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DISubroutineType, .{
                        .flags = null,
                        .cc = null,
                        .types = extra.types_tuple,
                    }, w);
                },
                .enumerator_unsigned,
                .enumerator_signed_positive,
                .enumerator_signed_negative,
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.Enumerator, metadata_item.data);

                    const ExpectedContents = extern struct {
                        const expected_limbs = @divExact(512, @bitSizeOf(std.math.big.Limb));
                        string: [
                            (std.math.big.int.Const{
                                .limbs = &@as([expected_limbs]std.math.big.Limb, @splat(maxInt(std.math.big.Limb))),
                                .positive = false,
                            }).sizeInBaseUpperBound(10)
                        ]u8,
                        limbs: [
                            std.math.big.int.calcToStringLimbsBufferLen(expected_limbs, 10)
                        ]std.math.big.Limb,
                    };
                    var bfa_buf: ExpectedContents = undefined;
                    var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), self.gpa);
                    const allocator = bfa.allocator();

                    const limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len];
                    const bigint: std.math.big.int.Const = .{
                        .limbs = limbs,
                        .positive = switch (kind) {
                            .enumerator_unsigned,
                            .enumerator_signed_positive,
                            => true,
                            .enumerator_signed_negative => false,
                            else => unreachable,
                        },
                    };
                    const str = try bigint.toStringAlloc(allocator, 10, undefined);
                    defer allocator.free(str);

                    try metadata_formatter.specialized(.@"!", .DIEnumerator, .{
                        .name = extra.name,
                        .value = str,
                        .isUnsigned = switch (kind) {
                            .enumerator_unsigned => true,
                            .enumerator_signed_positive,
                            .enumerator_signed_negative,
                            => false,
                            else => unreachable,
                        },
                    }, w);
                },
                .subrange => {
                    const extra = self.metadataExtraData(Metadata.Subrange, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DISubrange, .{
                        .count = extra.count,
                        .lowerBound = extra.lower_bound,
                        .upperBound = null,
                        .stride = null,
                    }, w);
                },
                .tuple => {
                    var extra = self.metadataExtraDataTrail(Metadata.Tuple, metadata_item.data);
                    const elements = extra.trail.next(extra.data.elements_len, Metadata, self);
                    try w.writeAll("!{");
                    for (elements) |element| try w.print("{[element]f}", .{
                        .element = try metadata_formatter.fmt("", element, .{ .percent = true }),
                    });
                    try w.writeAll("}\n");
                },
                .local_var => {
                    const extra = self.metadataExtraData(Metadata.LocalVar, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DILocalVariable, .{
                        .name = extra.name,
                        .arg = null,
                        .scope = extra.scope,
                        .file = extra.file,
                        .line = extra.line,
                        .type = extra.ty,
                        .flags = null,
                        .@"align" = null,
                        .annotations = null,
                    }, w);
                },
                .parameter => {
                    const extra = self.metadataExtraData(Metadata.Parameter, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DILocalVariable, .{
                        .name = extra.name,
                        .arg = extra.arg_no,
                        .scope = extra.scope,
                        .file = extra.file,
                        .line = extra.line,
                        .type = extra.ty,
                        .flags = null,
                        .@"align" = null,
                        .annotations = null,
                    }, w);
                },
                .global_var,
                .@"global_var local",
                => |kind| {
                    const extra = self.metadataExtraData(Metadata.GlobalVar, metadata_item.data);
                    try metadata_formatter.specialized(.@"distinct !", .DIGlobalVariable, .{
                        .name = extra.name,
                        .linkageName = extra.linkage_name,
                        .scope = extra.scope,
                        .file = extra.file,
                        .line = extra.line,
                        .type = extra.ty,
                        .isLocal = switch (kind) {
                            .global_var => false,
                            .@"global_var local" => true,
                            else => unreachable,
                        },
                        .isDefinition = true,
                        .declaration = null,
                        .templateParams = null,
                        .@"align" = null,
                        .annotations = null,
                    }, w);
                },
                .global_var_expression => {
                    const extra =
                        self.metadataExtraData(Metadata.GlobalVarExpression, metadata_item.data);
                    try metadata_formatter.specialized(.@"!", .DIGlobalVariableExpression, .{
                        .@"var" = extra.variable,
                        .expr = extra.expression,
                    }, w);
                },
            }
        }
    }
}

const NoExtra = struct {};

fn isValidIdentifier(id: []const u8) bool {
    for (id, 0..) |byte, index| switch (byte) {
        '$', '-', '.', 'A'...'Z', '_', 'a'...'z' => {},
        '0'...'9' => if (index == 0) return false,
        else => return false,
    };
    return true;
}

const QuoteBehavior = enum { always_quote, quote_unless_valid_identifier };
fn printEscapedString(slice: []const u8, quotes: QuoteBehavior, w: *Writer) Writer.Error!void {
    const need_quotes = switch (quotes) {
        .always_quote => true,
        .quote_unless_valid_identifier => !isValidIdentifier(slice),
    };
    if (need_quotes) try w.writeByte('"');
    for (slice) |byte| switch (byte) {
        '\\' => try w.writeAll("\\\\"),
        ' '...'"' - 1, '"' + 1...'\\' - 1, '\\' + 1...'~' => try w.writeByte(byte),
        else => try w.print("\\{X:0>2}", .{byte}),
    };
    if (need_quotes) try w.writeByte('"');
}

fn ensureUnusedGlobalCapacity(self: *Builder, name: StrtabString) Allocator.Error!void {
    try self.strtab_string_map.ensureUnusedCapacity(self.gpa, 1);
    if (name.slice(self)) |id| {
        const count: usize = comptime std.fmt.count("{d}", .{maxInt(u32)});
        try self.strtab_string_bytes.ensureUnusedCapacity(self.gpa, id.len + count);
    }
    try self.strtab_string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.globals.ensureUnusedCapacity(self.gpa, 1);
    try self.next_unique_global_id.ensureUnusedCapacity(self.gpa, 1);
}

fn fnTypeAssumeCapacity(
    self: *Builder,
    ret: Type,
    params: []const Type,
    comptime kind: Type.Function.Kind,
) Type {
    const tag: Type.Tag = switch (kind) {
        .normal => .function,
        .vararg => .vararg_function,
    };
    const Key = struct { ret: Type, params: []const Type };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = std.hash.Wyhash.init(comptime std.hash.int(@backingInt(tag)));
            hasher.update(std.mem.asBytes(&key.ret));
            hasher.update(std.mem.sliceAsBytes(key.params));
            return @truncate(hasher.final());
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            const rhs_data = ctx.builder.type_items.items[rhs_index];
            if (rhs_data.tag != tag) return false;
            var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Function, rhs_data.data);
            const rhs_params = rhs_extra.trail.next(rhs_extra.data.params_len, Type, ctx.builder);
            return lhs_key.ret == rhs_extra.data.ret and std.mem.eql(Type, lhs_key.params, rhs_params);
        }
    };
    const gop = self.type_map.getOrPutAssumeCapacityAdapted(
        Key{ .ret = ret, .params = params },
        Adapter{ .builder = self },
    );
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.type_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addTypeExtraAssumeCapacity(Type.Function{
                .ret = ret,
                .params_len = @intCast(params.len),
            }),
        });
        self.type_extra.appendSliceAssumeCapacity(@ptrCast(params));
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn intTypeAssumeCapacity(self: *Builder, bits: u24) Type {
    assert(bits > 0);
    const result = self.getOrPutTypeNoExtraAssumeCapacity(.{ .tag = .integer, .data = bits });
    return result.type;
}

fn ptrTypeAssumeCapacity(self: *Builder, addr_space: AddrSpace) Type {
    const result = self.getOrPutTypeNoExtraAssumeCapacity(
        .{ .tag = .pointer, .data = @backingInt(addr_space) },
    );
    return result.type;
}

fn vectorTypeAssumeCapacity(
    self: *Builder,
    comptime kind: Type.Vector.Kind,
    len: u32,
    child: Type,
) Type {
    assert(child.isFloatingPoint() or child.isInteger(self) or child.isPointer(self));
    const tag: Type.Tag = switch (kind) {
        .normal => .vector,
        .scalable => .scalable_vector,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Type.Vector) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(tag)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Type.Vector, _: void, rhs_index: usize) bool {
            const rhs_data = ctx.builder.type_items.items[rhs_index];
            return rhs_data.tag == tag and
                std.meta.eql(lhs_key, ctx.builder.typeExtraData(Type.Vector, rhs_data.data));
        }
    };
    const data = Type.Vector{ .len = len, .child = child };
    const gop = self.type_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.type_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addTypeExtraAssumeCapacity(data),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn arrayTypeAssumeCapacity(self: *Builder, len: u64, child: Type) Type {
    if (std.math.cast(u32, len)) |small_len| {
        const Adapter = struct {
            builder: *const Builder,
            pub fn hash(_: @This(), key: Type.Vector) u32 {
                return @truncate(std.hash.Wyhash.hash(
                    comptime std.hash.int(@backingInt(Type.Tag.small_array)),
                    std.mem.asBytes(&key),
                ));
            }
            pub fn eql(ctx: @This(), lhs_key: Type.Vector, _: void, rhs_index: usize) bool {
                const rhs_data = ctx.builder.type_items.items[rhs_index];
                return rhs_data.tag == .small_array and
                    std.meta.eql(lhs_key, ctx.builder.typeExtraData(Type.Vector, rhs_data.data));
            }
        };
        const data = Type.Vector{ .len = small_len, .child = child };
        const gop = self.type_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
        if (!gop.found_existing) {
            gop.key_ptr.* = {};
            gop.value_ptr.* = {};
            self.type_items.appendAssumeCapacity(.{
                .tag = .small_array,
                .data = self.addTypeExtraAssumeCapacity(data),
            });
        }
        return @fromBackingInt(@intCast(gop.index));
    } else {
        const Adapter = struct {
            builder: *const Builder,
            pub fn hash(_: @This(), key: Type.Array) u32 {
                return @truncate(std.hash.Wyhash.hash(
                    comptime std.hash.int(@backingInt(Type.Tag.array)),
                    std.mem.asBytes(&key),
                ));
            }
            pub fn eql(ctx: @This(), lhs_key: Type.Array, _: void, rhs_index: usize) bool {
                const rhs_data = ctx.builder.type_items.items[rhs_index];
                return rhs_data.tag == .array and
                    std.meta.eql(lhs_key, ctx.builder.typeExtraData(Type.Array, rhs_data.data));
            }
        };
        const data = Type.Array{
            .len_lo = @truncate(len),
            .len_hi = @intCast(len >> 32),
            .child = child,
        };
        const gop = self.type_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
        if (!gop.found_existing) {
            gop.key_ptr.* = {};
            gop.value_ptr.* = {};
            self.type_items.appendAssumeCapacity(.{
                .tag = .array,
                .data = self.addTypeExtraAssumeCapacity(data),
            });
        }
        return @fromBackingInt(@intCast(gop.index));
    }
}

fn structTypeAssumeCapacity(
    self: *Builder,
    comptime kind: Type.Structure.Kind,
    fields: []const Type,
) Type {
    const tag: Type.Tag = switch (kind) {
        .normal => .structure,
        .@"packed" => .packed_structure,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: []const Type) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(tag)),
                std.mem.sliceAsBytes(key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: []const Type, _: void, rhs_index: usize) bool {
            const rhs_data = ctx.builder.type_items.items[rhs_index];
            if (rhs_data.tag != tag) return false;
            var rhs_extra = ctx.builder.typeExtraDataTrail(Type.Structure, rhs_data.data);
            const rhs_fields = rhs_extra.trail.next(rhs_extra.data.fields_len, Type, ctx.builder);
            return std.mem.eql(Type, lhs_key, rhs_fields);
        }
    };
    const gop = self.type_map.getOrPutAssumeCapacityAdapted(fields, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.type_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addTypeExtraAssumeCapacity(Type.Structure{
                .fields_len = @intCast(fields.len),
            }),
        });
        self.type_extra.appendSliceAssumeCapacity(@ptrCast(fields));
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn opaqueTypeAssumeCapacity(self: *Builder, name: String) Type {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: String) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Type.Tag.named_structure)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: String, _: void, rhs_index: usize) bool {
            const rhs_data = ctx.builder.type_items.items[rhs_index];
            return rhs_data.tag == .named_structure and
                lhs_key == ctx.builder.typeExtraData(Type.NamedStructure, rhs_data.data).id;
        }
    };
    var id = name;
    if (name == .empty) {
        id = self.next_unnamed_type;
        assert(id != .none);
        self.next_unnamed_type = @fromBackingInt(@backingInt(id) + 1);
    } else assert(!name.isAnon());
    while (true) {
        const type_gop = self.types.getOrPutAssumeCapacity(id);
        if (!type_gop.found_existing) {
            const gop = self.type_map.getOrPutAssumeCapacityAdapted(id, Adapter{ .builder = self });
            assert(!gop.found_existing);
            gop.key_ptr.* = {};
            gop.value_ptr.* = {};
            self.type_items.appendAssumeCapacity(.{
                .tag = .named_structure,
                .data = self.addTypeExtraAssumeCapacity(Type.NamedStructure{
                    .id = id,
                    .body = .none,
                }),
            });
            const result: Type = @fromBackingInt(@intCast(gop.index));
            type_gop.value_ptr.* = result;
            return result;
        }

        const unique_gop = self.next_unique_type_id.getOrPutAssumeCapacity(name);
        if (!unique_gop.found_existing) unique_gop.value_ptr.* = 2;
        id = self.fmtAssumeCapacity("{s}.{d}", .{ name.slice(self).?, unique_gop.value_ptr.* });
        unique_gop.value_ptr.* += 1;
    }
}

fn ensureUnusedTypeCapacity(
    self: *Builder,
    count: usize,
    comptime Extra: type,
    trail_len: usize,
) Allocator.Error!void {
    try self.type_map.ensureUnusedCapacity(self.gpa, count);
    try self.type_items.ensureUnusedCapacity(self.gpa, count);
    try self.type_extra.ensureUnusedCapacity(
        self.gpa,
        count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
    );
}

fn getOrPutTypeNoExtraAssumeCapacity(self: *Builder, item: Type.Item) struct { new: bool, type: Type } {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Type.Item) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Type.Tag.simple)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Type.Item, _: void, rhs_index: usize) bool {
            const lhs_bits: u32 = @bitCast(lhs_key);
            const rhs_bits: u32 = @bitCast(ctx.builder.type_items.items[rhs_index]);
            return lhs_bits == rhs_bits;
        }
    };
    const gop = self.type_map.getOrPutAssumeCapacityAdapted(item, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.type_items.appendAssumeCapacity(item);
    }
    return .{ .new = !gop.found_existing, .type = @fromBackingInt(@intCast(gop.index)) };
}

fn addTypeExtraAssumeCapacity(self: *Builder, extra: anytype) Type.Item.ExtraIndex {
    const result: Type.Item.ExtraIndex = @intCast(self.type_extra.items.len);
    const info = @typeInfo(@TypeOf(extra)).@"struct";
    inline for (info.field_names, info.field_types) |field_name, field_type| {
        const value = @field(extra, field_name);
        self.type_extra.appendAssumeCapacity(switch (field_type) {
            u32 => value,
            String, Type => @backingInt(value),
            else => @compileError("bad field type: " ++ field_name ++ ": " ++ @typeName(field_type)),
        });
    }
    return result;
}

const TypeExtraDataTrail = struct {
    index: Type.Item.ExtraIndex,

    fn nextMut(self: *TypeExtraDataTrail, len: u32, comptime Item: type, builder: *Builder) []Item {
        const items: []Item = @ptrCast(builder.type_extra.items[self.index..][0..len]);
        self.index += @intCast(len);
        return items;
    }

    fn next(
        self: *TypeExtraDataTrail,
        len: u32,
        comptime Item: type,
        builder: *const Builder,
    ) []const Item {
        const items: []const Item = @ptrCast(builder.type_extra.items[self.index..][0..len]);
        self.index += @intCast(len);
        return items;
    }
};

fn typeExtraDataTrail(
    self: *const Builder,
    comptime T: type,
    index: Type.Item.ExtraIndex,
) struct { data: T, trail: TypeExtraDataTrail } {
    var result: T = undefined;
    const info = @typeInfo(T).@"struct";
    inline for (
        info.field_names,
        info.field_types,
        self.type_extra.items[index..][0..info.field_names.len],
    ) |field_name, field_type, value|
        @field(result, field_name) = switch (field_type) {
            u32 => value,
            String, Type => @fromBackingInt(value),
            else => @compileError("bad field type: " ++ @typeName(field_type)),
        };
    return .{
        .data = result,
        .trail = .{ .index = index + @as(Type.Item.ExtraIndex, @intCast(info.field_names.len)) },
    };
}

fn typeExtraData(self: *const Builder, comptime T: type, index: Type.Item.ExtraIndex) T {
    return self.typeExtraDataTrail(T, index).data;
}

fn attrGeneric(self: *Builder, data: []const u32) Allocator.Error!u32 {
    try self.attributes_map.ensureUnusedCapacity(self.gpa, 1);
    try self.attributes_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.attributes_extra.ensureUnusedCapacity(self.gpa, data.len);

    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: []const u32) u32 {
            return @truncate(std.hash.Wyhash.hash(1, std.mem.sliceAsBytes(key)));
        }
        pub fn eql(ctx: @This(), lhs_key: []const u32, _: void, rhs_index: usize) bool {
            const start = ctx.builder.attributes_indices.items[rhs_index];
            const end = ctx.builder.attributes_indices.items[rhs_index + 1];
            return std.mem.eql(u32, lhs_key, ctx.builder.attributes_extra.items[start..end]);
        }
    };
    const gop = self.attributes_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        self.attributes_extra.appendSliceAssumeCapacity(data);
        self.attributes_indices.appendAssumeCapacity(@intCast(self.attributes_extra.items.len));
    }
    return @intCast(gop.index);
}

fn bigIntConstAssumeCapacity(
    self: *Builder,
    ty: Type,
    value: std.math.big.int.Const,
) Allocator.Error!Constant {
    const type_item = self.type_items.items[@backingInt(ty)];
    assert(type_item.tag == .integer);
    const bits = type_item.data;

    const ExpectedContents = [64 / @sizeOf(std.math.big.Limb)]std.math.big.Limb;
    var bfa_buf: ExpectedContents = undefined;
    var bfa: std.heap.BufferFirstAllocator = .init(@ptrCast(&bfa_buf), self.gpa);
    const allocator = bfa.allocator();

    var limbs: []std.math.big.Limb = &.{};
    defer allocator.free(limbs);
    const canonical_value = if (value.fitsInTwosComp(.signed, bits)) value else canon: {
        assert(value.fitsInTwosComp(.unsigned, bits));
        limbs = try allocator.alloc(std.math.big.Limb, std.math.big.int.calcTwosCompLimbCount(bits));
        var temp_value = std.math.big.int.Mutable.init(limbs, 0);
        temp_value.truncate(value, .signed, bits);
        break :canon temp_value.toConst();
    };
    assert(canonical_value.fitsInTwosComp(.signed, bits));

    const ExtraPtr = *align(@alignOf(std.math.big.Limb)) Constant.Integer;
    const Key = struct { tag: Constant.Tag, type: Type, limbs: []const std.math.big.Limb };
    const tag: Constant.Tag = switch (canonical_value.positive) {
        true => .positive_integer,
        false => .negative_integer,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = std.hash.Wyhash.init(std.hash.int(@backingInt(key.tag)));
            hasher.update(std.mem.asBytes(&key.type));
            hasher.update(std.mem.sliceAsBytes(key.limbs));
            return @truncate(hasher.final());
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.constant_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra: ExtraPtr =
                @ptrCast(ctx.builder.constant_limbs.items[rhs_data..][0..Constant.Integer.limbs]);
            const rhs_limbs = ctx.builder.constant_limbs
                .items[rhs_data + Constant.Integer.limbs ..][0..rhs_extra.limbs_len];
            return lhs_key.type == rhs_extra.type and
                std.mem.eql(std.math.big.Limb, lhs_key.limbs, rhs_limbs);
        }
    };

    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(
        Key{ .tag = tag, .type = ty, .limbs = canonical_value.limbs },
        Adapter{ .builder = self },
    );
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = @intCast(self.constant_limbs.items.len),
        });
        const extra: ExtraPtr =
            @ptrCast(self.constant_limbs.addManyAsArrayAssumeCapacity(Constant.Integer.limbs));
        extra.* = .{ .type = ty, .limbs_len = @intCast(canonical_value.limbs.len) };
        self.constant_limbs.appendSliceAssumeCapacity(canonical_value.limbs);
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn halfConstAssumeCapacity(self: *Builder, val: f16) Constant {
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .half, .data = @as(u16, @bitCast(val)) },
    );
    return result.constant;
}

fn bfloatConstAssumeCapacity(self: *Builder, val: f32) Constant {
    assert(@as(u16, @truncate(@as(u32, @bitCast(val)))) == 0);
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .bfloat, .data = @bitCast(val) },
    );
    return result.constant;
}

fn floatConstAssumeCapacity(self: *Builder, val: f32) Constant {
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .float, .data = @bitCast(val) },
    );
    return result.constant;
}

fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: f64) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Constant.Tag.double)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: f64, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .double) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Double, rhs_data);
            return @as(u64, @bitCast(lhs_key)) == @as(u64, rhs_extra.hi) << 32 | rhs_extra.lo;
        }
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = .double,
            .data = self.addConstantExtraAssumeCapacity(Constant.Double{
                .lo = @truncate(@as(u64, @bitCast(val))),
                .hi = @intCast(@as(u64, @bitCast(val)) >> 32),
            }),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: f128) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Constant.Tag.fp128)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: f128, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .fp128) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
            return @as(u128, @bitCast(lhs_key)) == @as(u128, rhs_extra.hi_hi) << 96 |
                @as(u128, rhs_extra.hi_lo) << 64 | @as(u128, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
        }
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = .fp128,
            .data = self.addConstantExtraAssumeCapacity(Constant.Fp128{
                .lo_lo = @truncate(@as(u128, @bitCast(val))),
                .lo_hi = @truncate(@as(u128, @bitCast(val)) >> 32),
                .hi_lo = @truncate(@as(u128, @bitCast(val)) >> 64),
                .hi_hi = @intCast(@as(u128, @bitCast(val)) >> 96),
            }),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: f80) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Constant.Tag.x86_fp80)),
                std.mem.asBytes(&key)[0..10],
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: f80, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .x86_fp80) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Fp80, rhs_data);
            return @as(u80, @bitCast(lhs_key)) == @as(u80, rhs_extra.hi) << 64 |
                @as(u80, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;
        }
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = .x86_fp80,
            .data = self.addConstantExtraAssumeCapacity(Constant.Fp80{
                .lo_lo = @truncate(@as(u80, @bitCast(val))),
                .lo_hi = @truncate(@as(u80, @bitCast(val)) >> 32),
                .hi = @intCast(@as(u80, @bitCast(val)) >> 64),
            }),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: [2]f64) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Constant.Tag.ppc_fp128)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: [2]f64, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .ppc_fp128) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
            return @as(u64, @bitCast(lhs_key[0])) == @as(u64, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo and
                @as(u64, @bitCast(lhs_key[1])) == @as(u64, rhs_extra.hi_hi) << 32 | rhs_extra.hi_lo;
        }
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = .ppc_fp128,
            .data = self.addConstantExtraAssumeCapacity(Constant.Fp128{
                .lo_lo = @truncate(@as(u64, @bitCast(val[0]))),
                .lo_hi = @intCast(@as(u64, @bitCast(val[0])) >> 32),
                .hi_lo = @truncate(@as(u64, @bitCast(val[1]))),
                .hi_hi = @intCast(@as(u64, @bitCast(val[1])) >> 32),
            }),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn nullConstAssumeCapacity(self: *Builder, ty: Type) Constant {
    assert(self.type_items.items[@backingInt(ty)].tag == .pointer);
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .null, .data = @backingInt(ty) },
    );
    return result.constant;
}

fn noneConstAssumeCapacity(self: *Builder, ty: Type) Constant {
    assert(ty == .token);
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .none, .data = @backingInt(ty) },
    );
    return result.constant;
}

fn structConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
    const type_item = self.type_items.items[@backingInt(ty)];
    var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) {
        .structure, .packed_structure => type_item.data,
        .named_structure => data: {
            const body_ty = self.typeExtraData(Type.NamedStructure, type_item.data).body;
            const body_item = self.type_items.items[@backingInt(body_ty)];
            switch (body_item.tag) {
                .structure, .packed_structure => break :data body_item.data,
                else => unreachable,
            }
        },
        else => unreachable,
    });
    const fields = extra.trail.next(extra.data.fields_len, Type, self);
    for (fields, vals) |field, val| assert(field == val.typeOf(self));

    for (vals) |val| {
        if (!val.isZeroInit(self)) break;
    } else return self.zeroInitConstAssumeCapacity(ty);

    const tag: Constant.Tag = switch (ty.unnamedTag(self)) {
        .structure => .structure,
        .packed_structure => .packed_structure,
        else => unreachable,
    };
    const result = self.getOrPutConstantAggregateAssumeCapacity(tag, ty, vals);
    return result.constant;
}

fn arrayConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
    const type_item = self.type_items.items[@backingInt(ty)];
    const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) {
        inline .small_array, .array => |kind| extra: {
            const extra = self.typeExtraData(switch (kind) {
                .small_array => Type.Vector,
                .array => Type.Array,
                else => unreachable,
            }, type_item.data);
            break :extra .{ .len = extra.length(), .child = extra.child };
        },
        else => unreachable,
    };
    assert(type_extra.len == vals.len);
    for (vals) |val| assert(type_extra.child == val.typeOf(self));

    for (vals) |val| {
        if (!val.isZeroInit(self)) break;
    } else return self.zeroInitConstAssumeCapacity(ty);

    const result = self.getOrPutConstantAggregateAssumeCapacity(.array, ty, vals);
    return result.constant;
}

fn stringConstAssumeCapacity(self: *Builder, val: String) Constant {
    const slice = val.slice(self).?;
    const ty = self.arrayTypeAssumeCapacity(slice.len, .i8);
    if (std.mem.allEqual(u8, slice, 0)) return self.zeroInitConstAssumeCapacity(ty);
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .string, .data = @backingInt(val) },
    );
    return result.constant;
}

fn vectorConstAssumeCapacity(self: *Builder, ty: Type, vals: []const Constant) Constant {
    assert(ty.isVector(self));
    assert(ty.vectorLen(self) == vals.len);
    for (vals) |val| assert(ty.childType(self) == val.typeOf(self));

    for (vals[1..]) |val| {
        if (vals[0] != val) break;
    } else return self.splatConstAssumeCapacity(ty, vals[0]);
    for (vals) |val| {
        if (!val.isZeroInit(self)) break;
    } else return self.zeroInitConstAssumeCapacity(ty);

    const result = self.getOrPutConstantAggregateAssumeCapacity(.vector, ty, vals);
    return result.constant;
}

fn splatConstAssumeCapacity(self: *Builder, ty: Type, val: Constant) Constant {
    assert(ty.scalarType(self) == val.typeOf(self));

    if (!ty.isVector(self)) return val;
    if (val.isZeroInit(self)) return self.zeroInitConstAssumeCapacity(ty);

    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Constant.Splat) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Constant.Tag.splat)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Constant.Splat, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .splat) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Splat, rhs_data);
            return std.meta.eql(lhs_key, rhs_extra);
        }
    };
    const data = Constant.Splat{ .type = ty, .value = val };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = .splat,
            .data = self.addConstantExtraAssumeCapacity(data),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn zeroInitConstAssumeCapacity(self: *Builder, ty: Type) Constant {
    switch (ty) {
        inline .half,
        .bfloat,
        .float,
        .double,
        .fp128,
        .x86_fp80,
        => |tag| return @field(Builder, @tagName(tag) ++ "ConstAssumeCapacity")(self, 0.0),
        .ppc_fp128 => return self.ppc_fp128ConstAssumeCapacity(.{ 0.0, 0.0 }),
        .token => return .none,
        .i1 => return .false,
        else => switch (self.type_items.items[@backingInt(ty)].tag) {
            .simple,
            .function,
            .vararg_function,
            => unreachable,
            .integer => {
                var limbs: [std.math.big.int.calcLimbLen(0)]std.math.big.Limb = undefined;
                const bigint = std.math.big.int.Mutable.init(&limbs, 0);
                return self.bigIntConstAssumeCapacity(ty, bigint.toConst()) catch unreachable;
            },
            .pointer => return self.nullConstAssumeCapacity(ty),
            .target,
            .vector,
            .scalable_vector,
            .small_array,
            .array,
            .structure,
            .packed_structure,
            .named_structure,
            => {},
        },
    }
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .zeroinitializer, .data = @backingInt(ty) },
    );
    return result.constant;
}

fn undefConstAssumeCapacity(self: *Builder, ty: Type) Constant {
    switch (self.type_items.items[@backingInt(ty)].tag) {
        .simple => switch (ty) {
            .void, .label => unreachable,
            else => {},
        },
        .function, .vararg_function => unreachable,
        else => {},
    }
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .undef, .data = @backingInt(ty) },
    );
    return result.constant;
}

fn poisonConstAssumeCapacity(self: *Builder, ty: Type) Constant {
    switch (self.type_items.items[@backingInt(ty)].tag) {
        .simple => switch (ty) {
            .void, .label => unreachable,
            else => {},
        },
        .function, .vararg_function => unreachable,
        else => {},
    }
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .poison, .data = @backingInt(ty) },
    );
    return result.constant;
}

fn blockAddrConstAssumeCapacity(
    self: *Builder,
    function: Function.Index,
    block: Function.Block.Index,
) Constant {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Constant.BlockAddress) u32 {
            return @truncate(std.hash.Wyhash.hash(
                comptime std.hash.int(@backingInt(Constant.Tag.blockaddress)),
                std.mem.asBytes(&key),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Constant.BlockAddress, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != .blockaddress) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.BlockAddress, rhs_data);
            return std.meta.eql(lhs_key, rhs_extra);
        }
    };
    const data = Constant.BlockAddress{ .function = function, .block = block };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = .blockaddress,
            .data = self.addConstantExtraAssumeCapacity(data),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn dsoLocalEquivalentConstAssumeCapacity(self: *Builder, function: Function.Index) Constant {
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .dso_local_equivalent, .data = @backingInt(function) },
    );
    return result.constant;
}

fn noCfiConstAssumeCapacity(self: *Builder, function: Function.Index) Constant {
    const result = self.getOrPutConstantNoExtraAssumeCapacity(
        .{ .tag = .no_cfi, .data = @backingInt(function) },
    );
    return result.constant;
}

fn convTag(
    self: *Builder,
    signedness: Constant.Cast.Signedness,
    val_ty: Type,
    ty: Type,
) Function.Instruction.Tag {
    assert(val_ty != ty);
    return switch (val_ty.scalarTag(self)) {
        .simple => switch (ty.scalarTag(self)) {
            .simple => switch (std.math.order(val_ty.scalarBits(self), ty.scalarBits(self))) {
                .lt => .fpext,
                .eq => unreachable,
                .gt => .fptrunc,
            },
            .integer => switch (signedness) {
                .unsigned => .fptoui,
                .signed => .fptosi,
                .unneeded => unreachable,
            },
            else => unreachable,
        },
        .integer => switch (ty.scalarTag(self)) {
            .simple => switch (signedness) {
                .unsigned => .uitofp,
                .signed => .sitofp,
                .unneeded => unreachable,
            },
            .integer => switch (std.math.order(val_ty.scalarBits(self), ty.scalarBits(self))) {
                .lt => switch (signedness) {
                    .unsigned => .zext,
                    .signed => .sext,
                    .unneeded => unreachable,
                },
                .eq => unreachable,
                .gt => switch (signedness) {
                    .unsigned => .@"trunc nuw",
                    .signed => .@"trunc nsw",
                    .unneeded => .trunc,
                },
            },
            .pointer => .inttoptr,
            else => unreachable,
        },
        .pointer => switch (ty.scalarTag(self)) {
            .integer => .ptrtoint,
            .pointer => .addrspacecast,
            else => unreachable,
        },
        else => unreachable,
    };
}

fn convConstTag(
    self: *Builder,
    val_ty: Type,
    ty: Type,
) Constant.Tag {
    assert(val_ty != ty);
    return switch (val_ty.scalarTag(self)) {
        .integer => switch (ty.scalarTag(self)) {
            .integer => switch (std.math.order(val_ty.scalarBits(self), ty.scalarBits(self))) {
                .gt => .trunc,
                else => unreachable,
            },
            .pointer => .inttoptr,
            else => unreachable,
        },
        .pointer => switch (ty.scalarTag(self)) {
            .integer => .ptrtoint,
            .pointer => .addrspacecast,
            else => unreachable,
        },
        else => unreachable,
    };
}

fn convConstAssumeCapacity(
    self: *Builder,
    val: Constant,
    ty: Type,
) Constant {
    const val_ty = val.typeOf(self);
    if (val_ty == ty) return val;
    return self.castConstAssumeCapacity(self.convConstTag(val_ty, ty), val, ty);
}

fn castConstAssumeCapacity(self: *Builder, tag: Constant.Tag, val: Constant, ty: Type) Constant {
    const Key = struct { tag: Constant.Tag, cast: Constant.Cast };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            return @truncate(std.hash.Wyhash.hash(
                std.hash.int(@backingInt(key.tag)),
                std.mem.asBytes(&key.cast),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.constant_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Cast, rhs_data);
            return std.meta.eql(lhs_key.cast, rhs_extra);
        }
    };
    const data: Key = .{ .tag = tag, .cast = .{ .val = val, .type = ty } };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addConstantExtraAssumeCapacity(data.cast),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn gepConstAssumeCapacity(
    self: *Builder,
    comptime kind: Constant.GetElementPtr.Kind,
    ty: Type,
    base: Constant,
    inrange: ?u16,
    indices: []const Constant,
) Constant {
    const tag: Constant.Tag = switch (kind) {
        .normal => .getelementptr,
        .inbounds => .@"getelementptr inbounds",
    };
    const base_ty = base.typeOf(self);
    const base_is_vector = base_ty.isVector(self);

    const VectorInfo = struct {
        kind: Type.Vector.Kind,
        len: u32,

        fn init(vector_ty: Type, builder: *const Builder) @This() {
            return .{ .kind = vector_ty.vectorKind(builder), .len = vector_ty.vectorLen(builder) };
        }
    };
    var vector_info: ?VectorInfo = if (base_is_vector) VectorInfo.init(base_ty, self) else null;
    for (indices) |index| {
        const index_ty = index.typeOf(self);
        switch (index_ty.tag(self)) {
            .integer => {},
            .vector, .scalable_vector => {
                const index_info = VectorInfo.init(index_ty, self);
                if (vector_info) |info|
                    assert(std.meta.eql(info, index_info))
                else
                    vector_info = index_info;
            },
            else => unreachable,
        }
    }
    if (!base_is_vector) if (vector_info) |info| switch (info.kind) {
        inline else => |vector_kind| _ = self.vectorTypeAssumeCapacity(vector_kind, info.len, base_ty),
    };

    const Key = struct {
        type: Type,
        base: Constant,
        inrange: Constant.GetElementPtr.InRangeIndex,
        indices: []const Constant,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = std.hash.Wyhash.init(comptime std.hash.int(@backingInt(tag)));
            hasher.update(std.mem.asBytes(&key.type));
            hasher.update(std.mem.asBytes(&key.base));
            hasher.update(std.mem.asBytes(&key.inrange));
            hasher.update(std.mem.sliceAsBytes(key.indices));
            return @truncate(hasher.final());
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (ctx.builder.constant_items.items(.tag)[rhs_index] != tag) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            var rhs_extra = ctx.builder.constantExtraDataTrail(Constant.GetElementPtr, rhs_data);
            const rhs_indices =
                rhs_extra.trail.next(rhs_extra.data.info.indices_len, Constant, ctx.builder);
            return lhs_key.type == rhs_extra.data.type and lhs_key.base == rhs_extra.data.base and
                lhs_key.inrange == rhs_extra.data.info.inrange and
                std.mem.eql(Constant, lhs_key.indices, rhs_indices);
        }
    };
    const data: Key = .{
        .type = ty,
        .base = base,
        .inrange = if (inrange) |index| @fromBackingInt(index) else .none,
        .indices = indices,
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addConstantExtraAssumeCapacity(Constant.GetElementPtr{
                .type = ty,
                .base = base,
                .info = .{ .indices_len = @intCast(indices.len), .inrange = data.inrange },
            }),
        });
        self.constant_extra.appendSliceAssumeCapacity(@ptrCast(indices));
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn binConstAssumeCapacity(
    self: *Builder,
    tag: Constant.Tag,
    lhs: Constant,
    rhs: Constant,
) Constant {
    switch (tag) {
        .add,
        .@"add nsw",
        .@"add nuw",
        .sub,
        .@"sub nsw",
        .@"sub nuw",
        .shl,
        .xor,
        => {},
        else => unreachable,
    }
    const Key = struct { tag: Constant.Tag, extra: Constant.Binary };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            return @truncate(std.hash.Wyhash.hash(
                std.hash.int(@backingInt(key.tag)),
                std.mem.asBytes(&key.extra),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.constant_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Binary, rhs_data);
            return std.meta.eql(lhs_key.extra, rhs_extra);
        }
    };
    const data: Key = .{ .tag = tag, .extra = .{ .lhs = lhs, .rhs = rhs } };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addConstantExtraAssumeCapacity(data.extra),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn asmConstAssumeCapacity(
    self: *Builder,
    ty: Type,
    info: Constant.Assembly.Info,
    assembly: String,
    constraints: String,
) Constant {
    assert(ty.functionKind(self) == .normal);

    const Key = struct { tag: Constant.Tag, extra: Constant.Assembly };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            return @truncate(std.hash.Wyhash.hash(
                std.hash.int(@backingInt(key.tag)),
                std.mem.asBytes(&key.extra),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.constant_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.constantExtraData(Constant.Assembly, rhs_data);
            return std.meta.eql(lhs_key.extra, rhs_extra);
        }
    };

    const data: Key = .{
        .tag = @fromBackingInt(@backingInt(Constant.Tag.@"asm") + @as(u4, @bitCast(info))),
        .extra = .{ .type = ty, .assembly = assembly, .constraints = constraints },
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(data, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = data.tag,
            .data = self.addConstantExtraAssumeCapacity(data.extra),
        });
    }
    return @fromBackingInt(@intCast(gop.index));
}

fn ensureUnusedConstantCapacity(
    self: *Builder,
    count: usize,
    comptime Extra: type,
    trail_len: usize,
) Allocator.Error!void {
    try self.constant_map.ensureUnusedCapacity(self.gpa, count);
    try self.constant_items.ensureUnusedCapacity(self.gpa, count);
    try self.constant_extra.ensureUnusedCapacity(
        self.gpa,
        count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
    );
}

fn getOrPutConstantNoExtraAssumeCapacity(
    self: *Builder,
    item: Constant.Item,
) struct { new: bool, constant: Constant } {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Constant.Item) u32 {
            return @truncate(std.hash.Wyhash.hash(
                std.hash.int(@backingInt(key.tag)),
                std.mem.asBytes(&key.data),
            ));
        }
        pub fn eql(ctx: @This(), lhs_key: Constant.Item, _: void, rhs_index: usize) bool {
            return std.meta.eql(lhs_key, ctx.builder.constant_items.get(rhs_index));
        }
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(item, Adapter{ .builder = self });
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(item);
    }
    return .{ .new = !gop.found_existing, .constant = @fromBackingInt(@intCast(gop.index)) };
}

fn getOrPutConstantAggregateAssumeCapacity(
    self: *Builder,
    tag: Constant.Tag,
    ty: Type,
    vals: []const Constant,
) struct { new: bool, constant: Constant } {
    switch (tag) {
        .structure, .packed_structure, .array, .vector => {},
        else => unreachable,
    }
    const Key = struct { tag: Constant.Tag, type: Type, vals: []const Constant };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = std.hash.Wyhash.init(std.hash.int(@backingInt(key.tag)));
            hasher.update(std.mem.asBytes(&key.type));
            hasher.update(std.mem.sliceAsBytes(key.vals));
            return @truncate(hasher.final());
        }
        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.constant_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
            var rhs_extra = ctx.builder.constantExtraDataTrail(Constant.Aggregate, rhs_data);
            if (lhs_key.type != rhs_extra.data.type) return false;
            const rhs_vals = rhs_extra.trail.next(@intCast(lhs_key.vals.len), Constant, ctx.builder);
            return std.mem.eql(Constant, lhs_key.vals, rhs_vals);
        }
    };
    const gop = self.constant_map.getOrPutAssumeCapacityAdapted(
        Key{ .tag = tag, .type = ty, .vals = vals },
        Adapter{ .builder = self },
    );
    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.constant_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addConstantExtraAssumeCapacity(Constant.Aggregate{ .type = ty }),
        });
        self.constant_extra.appendSliceAssumeCapacity(@ptrCast(vals));
    }
    return .{ .new = !gop.found_existing, .constant = @fromBackingInt(@intCast(gop.index)) };
}

fn addConstantExtraAssumeCapacity(self: *Builder, extra: anytype) Constant.Item.ExtraIndex {
    const result: Constant.Item.ExtraIndex = @intCast(self.constant_extra.items.len);
    const info = @typeInfo(@TypeOf(extra)).@"struct";
    inline for (info.field_names, info.field_types) |field_name, field_type| {
        const value = @field(extra, field_name);
        self.constant_extra.appendAssumeCapacity(switch (field_type) {
            u32 => value,
            String, Type, Constant, Function.Index, Function.Block.Index => @backingInt(value),
            Constant.GetElementPtr.Info => @bitCast(value),
            else => @compileError("bad field type: " ++ @typeName(field_type)),
        });
    }
    return result;
}

const ConstantExtraDataTrail = struct {
    index: Constant.Item.ExtraIndex,

    fn nextMut(self: *ConstantExtraDataTrail, len: u32, comptime Item: type, builder: *Builder) []Item {
        const items: []Item = @ptrCast(builder.constant_extra.items[self.index..][0..len]);
        self.index += @intCast(len);
        return items;
    }

    fn next(
        self: *ConstantExtraDataTrail,
        len: u32,
        comptime Item: type,
        builder: *const Builder,
    ) []const Item {
        const items: []const Item = @ptrCast(builder.constant_extra.items[self.index..][0..len]);
        self.index += @intCast(len);
        return items;
    }
};

fn constantExtraDataTrail(
    self: *const Builder,
    comptime T: type,
    index: Constant.Item.ExtraIndex,
) struct { data: T, trail: ConstantExtraDataTrail } {
    var result: T = undefined;
    const info = @typeInfo(T).@"struct";
    inline for (
        info.field_names,
        info.field_types,
        self.constant_extra.items[index..][0..info.field_names.len],
    ) |field_name, field_type, value|
        @field(result, field_name) = switch (field_type) {
            u32 => value,
            String, Type, Constant, Function.Index, Function.Block.Index => @fromBackingInt(value),
            Constant.GetElementPtr.Info => @bitCast(value),
            else => @compileError("bad field type: " ++ @typeName(field_type)),
        };
    return .{
        .data = result,
        .trail = .{ .index = index + @as(Constant.Item.ExtraIndex, @intCast(info.field_names.len)) },
    };
}

fn constantExtraData(self: *const Builder, comptime T: type, index: Constant.Item.ExtraIndex) T {
    return self.constantExtraDataTrail(T, index).data;
}

fn ensureUnusedMetadataCapacity(
    self: *Builder,
    count: usize,
    comptime Extra: type,
    trail_len: usize,
) Allocator.Error!void {
    try self.metadata_map.ensureUnusedCapacity(self.gpa, count);
    try self.metadata_items.ensureUnusedCapacity(self.gpa, count);
    try self.metadata_extra.ensureUnusedCapacity(
        self.gpa,
        count * (@typeInfo(Extra).@"struct".field_names.len + trail_len),
    );
}

fn addMetadataExtraAssumeCapacity(self: *Builder, extra: anytype) Metadata.Item.ExtraIndex {
    const result: Metadata.Item.ExtraIndex = @intCast(self.metadata_extra.items.len);
    const info = @typeInfo(@TypeOf(extra)).@"struct";
    inline for (info.field_names, info.field_types) |field_name, field_type| {
        const value = @field(extra, field_name);
        self.metadata_extra.appendAssumeCapacity(switch (field_type) {
            u32 => value,
            Metadata.String, Metadata.String.Optional, Variable.Index, Value => @backingInt(value),
            Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
            else => @compileError("bad field type: " ++ @typeName(field_type)),
        });
    }
    return result;
}

const MetadataExtraDataTrail = struct {
    index: Metadata.Item.ExtraIndex,

    fn nextMut(self: *MetadataExtraDataTrail, len: u32, comptime Item: type, builder: *Builder) []Item {
        const items: []Item = @ptrCast(builder.metadata_extra.items[self.index..][0..len]);
        self.index += @intCast(len);
        return items;
    }

    fn next(
        self: *MetadataExtraDataTrail,
        len: u32,
        comptime Item: type,
        builder: *const Builder,
    ) []const Item {
        const items: []const Item = @ptrCast(builder.metadata_extra.items[self.index..][0..len]);
        self.index += @intCast(len);
        return items;
    }
};

fn metadataExtraDataTrail(
    self: *const Builder,
    comptime T: type,
    index: Metadata.Item.ExtraIndex,
) struct { data: T, trail: MetadataExtraDataTrail } {
    var result: T = undefined;
    const info = @typeInfo(T).@"struct";
    inline for (
        info.field_names,
        info.field_types,
        self.metadata_extra.items[index..][0..info.field_names.len],
    ) |field_name, field_type, value|
        @field(result, field_name) = switch (field_type) {
            u32 => value,
            Metadata.String, Metadata.String.Optional, Variable.Index, Value => @fromBackingInt(value),
            Metadata, Metadata.Optional, Metadata.DIFlags => @bitCast(value),
            else => @compileError("bad field type: " ++ @typeName(field_type)),
        };
    return .{
        .data = result,
        .trail = .{ .index = index + @as(Metadata.Item.ExtraIndex, @intCast(info.field_names.len)) },
    };
}

fn metadataExtraData(self: *const Builder, comptime T: type, index: Metadata.Item.ExtraIndex) T {
    return self.metadataExtraDataTrail(T, index).data;
}

pub fn metadataString(self: *Builder, bytes: []const u8) Allocator.Error!Metadata.String {
    assert(bytes.len > 0);
    try self.metadata_string_bytes.ensureUnusedCapacity(self.gpa, bytes.len);
    try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);

    const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(
        bytes,
        Metadata.String.Adapter{ .builder = self },
    );
    if (!gop.found_existing) {
        self.metadata_string_bytes.appendSliceAssumeCapacity(bytes);
        self.metadata_string_indices.appendAssumeCapacity(
            @intCast(self.metadata_string_bytes.items.len),
        );
    }
    return @fromBackingInt(@intCast(gop.index));
}

pub fn metadataStringFromStrtabString(
    self: *Builder,
    str: StrtabString,
) Allocator.Error!Metadata.String {
    return try self.metadataString(str.slice(self).?);
}

pub fn metadataStringFmt(
    self: *Builder,
    comptime fmt_str: []const u8,
    fmt_args: anytype,
) Allocator.Error!Metadata.String {
    try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
    try self.metadata_string_bytes.ensureUnusedCapacity(
        self.gpa,
        @intCast(std.fmt.count(fmt_str, fmt_args)),
    );
    try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
    return self.metadataStringFmtAssumeCapacity(fmt_str, fmt_args);
}

pub fn metadataStringFmtAssumeCapacity(
    self: *Builder,
    comptime fmt_str: []const u8,
    fmt_args: anytype,
) Metadata.String {
    self.metadata_string_bytes.printAssumeCapacity(fmt_str, fmt_args);
    return self.trailingMetadataStringAssumeCapacity();
}

pub fn trailingMetadataString(self: *Builder) Allocator.Error!Metadata.String {
    try self.metadata_string_indices.ensureUnusedCapacity(self.gpa, 1);
    try self.metadata_string_map.ensureUnusedCapacity(self.gpa, 1);
    return self.trailingMetadataStringAssumeCapacity();
}

pub fn trailingMetadataStringAssumeCapacity(self: *Builder) Metadata.String {
    const start = self.metadata_string_indices.last().?;
    const bytes: []const u8 = self.metadata_string_bytes.items[start..];
    assert(bytes.len > 0);
    const gop = self.metadata_string_map.getOrPutAssumeCapacityAdapted(bytes, Metadata.String.Adapter{ .builder = self });
    if (gop.found_existing) {
        self.metadata_string_bytes.shrinkRetainingCapacity(start);
    } else {
        self.metadata_string_indices.appendAssumeCapacity(@intCast(self.metadata_string_bytes.items.len));
    }
    return @fromBackingInt(@intCast(gop.index));
}

pub fn addNamedMetadata(self: *Builder, name: String, operands: []const Metadata) Allocator.Error!void {
    try self.metadata_extra.ensureUnusedCapacity(self.gpa, operands.len);
    try self.metadata_named.ensureUnusedCapacity(self.gpa, 1);
    self.addNamedMetadataAssumeCapacity(name, operands);
}

pub fn debugFile(
    self: *Builder,
    filename: ?Metadata.String,
    directory: ?Metadata.String,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.File, 0);
    return self.debugFileAssumeCapacity(filename, directory);
}

pub fn debugCompileUnit(
    self: *Builder,
    file: ?Metadata,
    producer: ?Metadata.String,
    enums: ?Metadata,
    globals: ?Metadata,
    options: Metadata.CompileUnit.Options,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.CompileUnit, 0);
    return self.debugCompileUnitAssumeCapacity(file, producer, enums, globals, options);
}

pub fn debugSubprogram(
    self: *Builder,
    file: ?Metadata,
    name: ?Metadata.String,
    linkage_name: ?Metadata.String,
    line: u32,
    scope_line: u32,
    ty: ?Metadata,
    options: Metadata.Subprogram.Options,
    compile_unit: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.Subprogram, 0);
    return self.debugSubprogramAssumeCapacity(
        file,
        name,
        linkage_name,
        line,
        scope_line,
        ty,
        options,
        compile_unit,
    );
}

pub fn debugLexicalBlock(
    self: *Builder,
    scope: ?Metadata,
    file: ?Metadata,
    line: u32,
    column: u32,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.LexicalBlock, 0);
    return self.debugLexicalBlockAssumeCapacity(scope, file, line, column);
}

pub fn debugLocation(
    self: *Builder,
    line: u32,
    column: u32,
    scope: Metadata,
    inlined_at: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.Location, 0);
    return self.debugLocationAssumeCapacity(line, column, scope, inlined_at);
}

pub fn debugBoolType(
    self: *Builder,
    name: ?Metadata.String,
    size_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
    return self.debugBoolTypeAssumeCapacity(name, size_in_bits);
}

pub fn debugUnsignedType(
    self: *Builder,
    name: ?Metadata.String,
    size_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
    return self.debugUnsignedTypeAssumeCapacity(name, size_in_bits);
}

pub fn debugSignedType(
    self: *Builder,
    name: ?Metadata.String,
    size_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
    return self.debugSignedTypeAssumeCapacity(name, size_in_bits);
}

pub fn debugFloatType(
    self: *Builder,
    name: ?Metadata.String,
    size_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.BasicType, 0);
    return self.debugFloatTypeAssumeCapacity(name, size_in_bits);
}

pub fn debugForwardReference(self: *Builder) Allocator.Error!Metadata {
    try self.metadata_forward_references.ensureUnusedCapacity(self.gpa, 1);
    return self.debugForwardReferenceAssumeCapacity();
}

pub fn debugStructType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
    return self.debugStructTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

pub fn debugUnionType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
    return self.debugUnionTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

pub fn debugEnumerationType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
    return self.debugEnumerationTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

pub fn debugArrayType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
    return self.debugArrayTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

pub fn debugVectorType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.CompositeType, 0);
    return self.debugVectorTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

pub fn debugPointerType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    offset_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
    return self.debugPointerTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        offset_in_bits,
    );
}

pub fn debugMemberType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    offset_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
    return self.debugMemberTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        offset_in_bits,
    );
}

pub fn debugTypedefType(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    offset_in_bits: u64,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.DerivedType, 0);
    return self.debugTypedefTypeAssumeCapacity(
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        offset_in_bits,
    );
}

pub fn debugSubroutineType(self: *Builder, types_tuple: ?Metadata) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.SubroutineType, 0);
    return self.debugSubroutineTypeAssumeCapacity(types_tuple);
}

pub fn debugEnumerator(
    self: *Builder,
    name: ?Metadata.String,
    unsigned: bool,
    bit_width: u32,
    value: std.math.big.int.Const,
) Allocator.Error!Metadata {
    assert(!(unsigned and !value.positive));
    try self.ensureUnusedMetadataCapacity(1, Metadata.Enumerator, 0);
    try self.metadata_limbs.ensureUnusedCapacity(self.gpa, value.limbs.len);
    return self.debugEnumeratorAssumeCapacity(name, unsigned, bit_width, value);
}

pub fn debugSubrange(
    self: *Builder,
    lower_bound: ?Metadata,
    count: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.Subrange, 0);
    return self.debugSubrangeAssumeCapacity(lower_bound, count);
}

pub fn debugExpression(self: *Builder, elements: []const u32) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.Expression, elements.len);
    return self.debugExpressionAssumeCapacity(elements);
}

pub fn metadataTuple(self: *Builder, elements: []const Metadata) Allocator.Error!Metadata {
    return self.metadataTupleOptionals(@ptrCast(elements));
}

pub fn metadataTupleOptionals(
    self: *Builder,
    elements: []const Metadata.Optional,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.Tuple, elements.len);
    return self.metadataTupleOptionalsAssumeCapacity(elements);
}

pub fn debugLocalVar(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    ty: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.LocalVar, 0);
    return self.debugLocalVarAssumeCapacity(name, file, scope, line, ty);
}

pub fn debugParameter(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    ty: ?Metadata,
    arg_no: u32,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.Parameter, 0);
    return self.debugParameterAssumeCapacity(name, file, scope, line, ty, arg_no);
}

pub fn debugGlobalVar(
    self: *Builder,
    name: ?Metadata.String,
    linkage_name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    ty: ?Metadata,
    variable: Variable.Index,
    options: Metadata.GlobalVar.Options,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVar, 0);
    return self.debugGlobalVarAssumeCapacity(
        name,
        linkage_name,
        file,
        scope,
        line,
        ty,
        variable,
        options,
    );
}

pub fn debugGlobalVarExpression(
    self: *Builder,
    variable: ?Metadata,
    expression: ?Metadata,
) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, Metadata.GlobalVarExpression, 0);
    return self.debugGlobalVarExpressionAssumeCapacity(variable, expression);
}

pub fn metadataConstant(self: *Builder, value: Constant) Allocator.Error!Metadata {
    try self.ensureUnusedMetadataCapacity(1, NoExtra, 0);
    return self.metadataConstantAssumeCapacity(value);
}

/// 将给定前向引用解析为给定值(该值本身不能是前向引用)。
/// 若此前向引用已解析,则替换其目标。
pub fn resolveDebugForwardReference(self: *Builder, fwd_ref: Metadata, value: Metadata) void {
    assert(fwd_ref.kind == .forward);
    assert(value.kind != .forward);
    self.metadata_forward_references.items[fwd_ref.index] = value.toOptional();
}

fn metadataSimpleAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
    const Key = struct {
        tag: Metadata.Tag,
        value: @TypeOf(value),
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = std.hash.Wyhash.init(std.hash.int(@backingInt(key.tag)));
            inline for (@typeInfo(@TypeOf(value)).@"struct".field_names) |field_name| {
                hasher.update(std.mem.asBytes(&@field(key.value, field_name)));
            }
            return @truncate(hasher.final());
        }

        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.metadataExtraData(@TypeOf(value), rhs_data);
            return std.meta.eql(lhs_key.value, rhs_extra);
        }
    };

    const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
        Key{ .tag = tag, .value = value },
        Adapter{ .builder = self },
    );

    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.metadata_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addMetadataExtraAssumeCapacity(value),
        });
    }
    return .{ .index = @intCast(gop.index), .kind = .node };
}

fn metadataDistinctAssumeCapacity(self: *Builder, tag: Metadata.Tag, value: anytype) Metadata {
    const index = self.metadata_items.len;
    _ = self.metadata_map.entries.addOneAssumeCapacity();
    self.metadata_items.appendAssumeCapacity(.{
        .tag = tag,
        .data = self.addMetadataExtraAssumeCapacity(value),
    });
    return .{ .index = @intCast(index), .kind = .node };
}

fn addNamedMetadataAssumeCapacity(self: *Builder, name: String, operands: []const Metadata) void {
    assert(name != .none);
    const extra_index: u32 = @intCast(self.metadata_extra.items.len);
    self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(operands));

    const gop = self.metadata_named.getOrPutAssumeCapacity(name);
    gop.value_ptr.* = .{
        .index = extra_index,
        .len = @intCast(operands.len),
    };
}

fn debugFileAssumeCapacity(
    self: *Builder,
    filename: ?Metadata.String,
    directory: ?Metadata.String,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.file, Metadata.File{
        .filename = .wrap(filename),
        .directory = .wrap(directory),
    });
}

pub fn debugCompileUnitAssumeCapacity(
    self: *Builder,
    file: ?Metadata,
    producer: ?Metadata.String,
    enums: ?Metadata,
    globals: ?Metadata,
    options: Metadata.CompileUnit.Options,
) Metadata {
    assert(!self.strip);
    return self.metadataDistinctAssumeCapacity(
        if (options.optimized) .@"compile_unit optimized" else .compile_unit,
        Metadata.CompileUnit{
            .file = .wrap(file),
            .producer = .wrap(producer),
            .enums = .wrap(enums),
            .globals = .wrap(globals),
        },
    );
}

fn debugSubprogramAssumeCapacity(
    self: *Builder,
    file: ?Metadata,
    name: ?Metadata.String,
    linkage_name: ?Metadata.String,
    line: u32,
    scope_line: u32,
    ty: ?Metadata,
    options: Metadata.Subprogram.Options,
    compile_unit: ?Metadata,
) Metadata {
    assert(!self.strip);
    const tag: Metadata.Tag = @fromBackingInt(@backingInt(Metadata.Tag.subprogram) +
        @as(u3, @truncate(@as(u32, @bitCast(options.sp_flags)) >> 2)));
    return self.metadataDistinctAssumeCapacity(tag, Metadata.Subprogram{
        .file = .wrap(file),
        .name = .wrap(name),
        .linkage_name = .wrap(linkage_name),
        .line = line,
        .scope_line = scope_line,
        .ty = .wrap(ty),
        .di_flags = options.di_flags,
        .compile_unit = .wrap(compile_unit),
    });
}

fn debugLexicalBlockAssumeCapacity(
    self: *Builder,
    scope: ?Metadata,
    file: ?Metadata,
    line: u32,
    column: u32,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.lexical_block, Metadata.LexicalBlock{
        .scope = .wrap(scope),
        .file = .wrap(file),
        .line = line,
        .column = column,
    });
}

fn debugLocationAssumeCapacity(
    self: *Builder,
    line: u32,
    column: u32,
    scope: Metadata,
    inlined_at: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.location, Metadata.Location{
        .line = line,
        .column = column,
        .scope = scope,
        .inlined_at = .wrap(inlined_at),
    });
}

fn debugBoolTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.basic_bool_type, Metadata.BasicType{
        .name = .wrap(name),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
    });
}

fn debugUnsignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.basic_unsigned_type, Metadata.BasicType{
        .name = .wrap(name),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
    });
}

fn debugSignedTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.basic_signed_type, Metadata.BasicType{
        .name = .wrap(name),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
    });
}

fn debugFloatTypeAssumeCapacity(self: *Builder, name: ?Metadata.String, size_in_bits: u64) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.basic_float_type, Metadata.BasicType{
        .name = .wrap(name),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
    });
}

fn debugForwardReferenceAssumeCapacity(self: *Builder) Metadata {
    assert(!self.strip);
    const index = self.metadata_forward_references.items.len;
    self.metadata_forward_references.appendAssumeCapacity(.none);
    return .{ .index = @intCast(index), .kind = .forward };
}

fn debugStructTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.debugCompositeTypeAssumeCapacity(
        .composite_struct_type,
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

fn debugUnionTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.debugCompositeTypeAssumeCapacity(
        .composite_union_type,
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

fn debugEnumerationTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.debugCompositeTypeAssumeCapacity(
        .composite_enumeration_type,
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

fn debugArrayTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.debugCompositeTypeAssumeCapacity(
        .composite_array_type,
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

fn debugVectorTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.debugCompositeTypeAssumeCapacity(
        .composite_vector_type,
        name,
        file,
        scope,
        line,
        underlying_type,
        size_in_bits,
        align_in_bits,
        fields_tuple,
    );
}

fn debugCompositeTypeAssumeCapacity(
    self: *Builder,
    tag: Metadata.Tag,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    fields_tuple: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(tag, Metadata.CompositeType{
        .name = .wrap(name),
        .file = .wrap(file),
        .scope = .wrap(scope),
        .line = line,
        .underlying_type = .wrap(underlying_type),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
        .align_in_bits_lo = @truncate(align_in_bits),
        .align_in_bits_hi = @truncate(align_in_bits >> 32),
        .fields_tuple = .wrap(fields_tuple),
    });
}

fn debugPointerTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    offset_in_bits: u64,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.derived_pointer_type, Metadata.DerivedType{
        .name = .wrap(name),
        .file = .wrap(file),
        .scope = .wrap(scope),
        .line = line,
        .underlying_type = .wrap(underlying_type),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
        .align_in_bits_lo = @truncate(align_in_bits),
        .align_in_bits_hi = @truncate(align_in_bits >> 32),
        .offset_in_bits_lo = @truncate(offset_in_bits),
        .offset_in_bits_hi = @truncate(offset_in_bits >> 32),
    });
}

fn debugMemberTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    offset_in_bits: u64,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.derived_member_type, Metadata.DerivedType{
        .name = .wrap(name),
        .file = .wrap(file),
        .scope = .wrap(scope),
        .line = line,
        .underlying_type = .wrap(underlying_type),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
        .align_in_bits_lo = @truncate(align_in_bits),
        .align_in_bits_hi = @truncate(align_in_bits >> 32),
        .offset_in_bits_lo = @truncate(offset_in_bits),
        .offset_in_bits_hi = @truncate(offset_in_bits >> 32),
    });
}

fn debugTypedefTypeAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    underlying_type: ?Metadata,
    size_in_bits: u64,
    align_in_bits: u64,
    offset_in_bits: u64,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.derived_typedef_type, Metadata.DerivedType{
        .name = .wrap(name),
        .file = .wrap(file),
        .scope = .wrap(scope),
        .line = line,
        .underlying_type = .wrap(underlying_type),
        .size_in_bits_lo = @truncate(size_in_bits),
        .size_in_bits_hi = @truncate(size_in_bits >> 32),
        .align_in_bits_lo = @truncate(align_in_bits),
        .align_in_bits_hi = @truncate(align_in_bits >> 32),
        .offset_in_bits_lo = @truncate(offset_in_bits),
        .offset_in_bits_hi = @truncate(offset_in_bits >> 32),
    });
}

fn debugSubroutineTypeAssumeCapacity(self: *Builder, types_tuple: ?Metadata) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.subroutine_type, Metadata.SubroutineType{
        .types_tuple = .wrap(types_tuple),
    });
}

fn debugEnumeratorAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    unsigned: bool,
    bit_width: u32,
    value: std.math.big.int.Const,
) Metadata {
    assert(!self.strip);
    const Key = struct {
        tag: Metadata.Tag,
        name: Metadata.String.Optional,
        bit_width: u32,
        value: std.math.big.int.Const,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = std.hash.Wyhash.init(std.hash.int(@backingInt(key.tag)));
            hasher.update(std.mem.asBytes(&key.name));
            hasher.update(std.mem.asBytes(&key.bit_width));
            hasher.update(std.mem.sliceAsBytes(key.value.limbs));
            return @truncate(hasher.final());
        }

        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (lhs_key.tag != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
            const rhs_extra = ctx.builder.metadataExtraData(Metadata.Enumerator, rhs_data);
            const limbs = ctx.builder.metadata_limbs
                .items[rhs_extra.limbs_index..][0..rhs_extra.limbs_len];
            const rhs_value = std.math.big.int.Const{
                .limbs = limbs,
                .positive = lhs_key.value.positive,
            };
            return lhs_key.name == rhs_extra.name and
                lhs_key.bit_width == rhs_extra.bit_width and
                lhs_key.value.eql(rhs_value);
        }
    };

    const tag: Metadata.Tag = if (unsigned)
        .enumerator_unsigned
    else if (value.positive)
        .enumerator_signed_positive
    else
        .enumerator_signed_negative;

    assert(!(tag == .enumerator_unsigned and !value.positive));

    const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(Key{
        .tag = tag,
        .name = .wrap(name),
        .bit_width = bit_width,
        .value = value,
    }, Adapter{ .builder = self });

    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.metadata_items.appendAssumeCapacity(.{
            .tag = tag,
            .data = self.addMetadataExtraAssumeCapacity(Metadata.Enumerator{
                .name = .wrap(name),
                .bit_width = bit_width,
                .limbs_index = @intCast(self.metadata_limbs.items.len),
                .limbs_len = @intCast(value.limbs.len),
            }),
        });
        self.metadata_limbs.appendSliceAssumeCapacity(value.limbs);
    }
    return .{ .index = @intCast(gop.index), .kind = .node };
}

fn debugSubrangeAssumeCapacity(self: *Builder, lower_bound: ?Metadata, count: ?Metadata) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.subrange, Metadata.Subrange{
        .lower_bound = .wrap(lower_bound),
        .count = .wrap(count),
    });
}

fn debugExpressionAssumeCapacity(self: *Builder, elements: []const u32) Metadata {
    assert(!self.strip);
    const Key = struct {
        elements: []const u32,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher =
                comptime std.hash.Wyhash.init(std.hash.int(@backingInt(Metadata.Tag.expression)));
            hasher.update(std.mem.sliceAsBytes(key.elements));
            return @truncate(hasher.final());
        }

        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (Metadata.Tag.expression != ctx.builder.metadata_items.items(.tag)[rhs_index])
                return false;
            const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
            var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Expression, rhs_data);
            return std.mem.eql(
                u32,
                lhs_key.elements,
                rhs_extra.trail.next(rhs_extra.data.elements_len, u32, ctx.builder),
            );
        }
    };

    const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
        Key{ .elements = elements },
        Adapter{ .builder = self },
    );

    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.metadata_items.appendAssumeCapacity(.{
            .tag = .expression,
            .data = self.addMetadataExtraAssumeCapacity(Metadata.Expression{
                .elements_len = @intCast(elements.len),
            }),
        });
        self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
    }
    return .{ .index = @intCast(gop.index), .kind = .node };
}

fn metadataTupleOptionalsAssumeCapacity(self: *Builder, elements: []const Metadata.Optional) Metadata {
    const Key = struct {
        elements: []const Metadata.Optional,
    };
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Key) u32 {
            var hasher = comptime std.hash.Wyhash.init(std.hash.int(@backingInt(Metadata.Tag.tuple)));
            hasher.update(std.mem.sliceAsBytes(key.elements));
            return @truncate(hasher.final());
        }

        pub fn eql(ctx: @This(), lhs_key: Key, _: void, rhs_index: usize) bool {
            if (Metadata.Tag.tuple != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
            const rhs_data = ctx.builder.metadata_items.items(.data)[rhs_index];
            var rhs_extra = ctx.builder.metadataExtraDataTrail(Metadata.Tuple, rhs_data);
            return std.mem.eql(
                Metadata.Optional,
                lhs_key.elements,
                rhs_extra.trail.next(rhs_extra.data.elements_len, Metadata.Optional, ctx.builder),
            );
        }
    };

    const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
        Key{ .elements = elements },
        Adapter{ .builder = self },
    );

    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.metadata_items.appendAssumeCapacity(.{
            .tag = .tuple,
            .data = self.addMetadataExtraAssumeCapacity(Metadata.Tuple{
                .elements_len = @intCast(elements.len),
            }),
        });
        self.metadata_extra.appendSliceAssumeCapacity(@ptrCast(elements));
    }
    return .{ .index = @intCast(gop.index), .kind = .node };
}

fn debugLocalVarAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    ty: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.local_var, Metadata.LocalVar{
        .name = .wrap(name),
        .file = .wrap(file),
        .scope = .wrap(scope),
        .line = line,
        .ty = .wrap(ty),
    });
}

fn debugParameterAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    ty: ?Metadata,
    arg_no: u32,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.parameter, Metadata.Parameter{
        .name = .wrap(name),
        .file = .wrap(file),
        .scope = .wrap(scope),
        .line = line,
        .ty = .wrap(ty),
        .arg_no = arg_no,
    });
}

fn debugGlobalVarAssumeCapacity(
    self: *Builder,
    name: ?Metadata.String,
    linkage_name: ?Metadata.String,
    file: ?Metadata,
    scope: ?Metadata,
    line: u32,
    ty: ?Metadata,
    variable: Variable.Index,
    options: Metadata.GlobalVar.Options,
) Metadata {
    assert(!self.strip);
    return self.metadataDistinctAssumeCapacity(
        if (options.local) .@"global_var local" else .global_var,
        Metadata.GlobalVar{
            .name = .wrap(name),
            .linkage_name = .wrap(linkage_name),
            .file = .wrap(file),
            .scope = .wrap(scope),
            .line = line,
            .ty = .wrap(ty),
            .variable = variable,
        },
    );
}

fn debugGlobalVarExpressionAssumeCapacity(
    self: *Builder,
    variable: ?Metadata,
    expression: ?Metadata,
) Metadata {
    assert(!self.strip);
    return self.metadataSimpleAssumeCapacity(.global_var_expression, Metadata.GlobalVarExpression{
        .variable = .wrap(variable),
        .expression = .wrap(expression),
    });
}

fn metadataConstantAssumeCapacity(self: *Builder, constant: Constant) Metadata {
    const Adapter = struct {
        builder: *const Builder,
        pub fn hash(_: @This(), key: Constant) u32 {
            var hasher = comptime std.hash.Wyhash.init(std.hash.int(@backingInt(Metadata.Tag.constant)));
            hasher.update(std.mem.asBytes(&key));
            return @truncate(hasher.final());
        }

        pub fn eql(ctx: @This(), lhs_key: Constant, _: void, rhs_index: usize) bool {
            if (Metadata.Tag.constant != ctx.builder.metadata_items.items(.tag)[rhs_index]) return false;
            const rhs_data: Constant = @fromBackingInt(ctx.builder.metadata_items.items(.data)[rhs_index]);
            return rhs_data == lhs_key;
        }
    };

    const gop = self.metadata_map.getOrPutAssumeCapacityAdapted(
        constant,
        Adapter{ .builder = self },
    );

    if (!gop.found_existing) {
        gop.key_ptr.* = {};
        gop.value_ptr.* = {};
        self.metadata_items.appendAssumeCapacity(.{
            .tag = .constant,
            .data = @backingInt(constant),
        });
    }
    return .{ .index = @intCast(gop.index), .kind = .node };
}

pub const Producer = struct {
    name: []const u8,
    version: std.SemanticVersion,
};

pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitcode_writer.Error![]const u32 {
    const BitcodeWriter = bitcode_writer.BitcodeWriter(&.{ Type, FunctionAttributes });
    var bitcode = BitcodeWriter.init(allocator, .{
        std.math.log2_int_ceil(usize, self.type_items.items.len),
        std.math.log2_int_ceil(usize, 1 + self.function_attributes_set.count()),
    });
    errdefer bitcode.deinit();

    // 写入 LLVM IR 魔数
    try bitcode.writeBits(ir.MAGIC, 32);

    var record: std.ArrayList(u64) = .empty;
    defer record.deinit(self.gpa);

    // IDENTIFICATION_BLOCK
    {
        const IdentificationBlock = ir.IdentificationBlock;
        var identification_block = try bitcode.enterTopBlock(IdentificationBlock);

        const producer_str = try std.fmt.allocPrint(self.gpa, "{s} {d}.{d}.{d}", .{
            producer.name,
            producer.version.major,
            producer.version.minor,
            producer.version.patch,
        });
        defer self.gpa.free(producer_str);

        try identification_block.writeAbbrev(IdentificationBlock.Version{ .string = producer_str });
        try identification_block.writeAbbrev(IdentificationBlock.Epoch{ .epoch = 0 });

        try identification_block.end();
    }

    // MODULE_BLOCK
    {
        const ModuleBlock = ir.ModuleBlock;
        var module_block = try bitcode.enterTopBlock(ModuleBlock);

        try module_block.writeAbbrev(ModuleBlock.Version{});

        if (self.target_triple.slice(self)) |triple| {
            try module_block.writeAbbrev(ModuleBlock.String{
                .code = 2,
                .string = triple,
            });
        }

        if (self.data_layout.string_repr.slice(self)) |data_layout| {
            try module_block.writeAbbrev(ModuleBlock.String{
                .code = 3,
                .string = data_layout,
            });
        }

        if (self.source_filename.slice(self)) |source_filename| {
            try module_block.writeAbbrev(ModuleBlock.String{
                .code = 16,
                .string = source_filename,
            });
        }

        if (self.module_asm.items.len != 0) {
            try module_block.writeAbbrev(ModuleBlock.String{
                .code = 4,
                .string = self.module_asm.items,
            });
        }

        // TYPE_BLOCK
        {
            const TypeBlock = ir.ModuleBlock.TypeBlock;
            var type_block = try module_block.enterSubBlock(TypeBlock, true);

            try type_block.writeAbbrev(TypeBlock.NumEntry{ .num = @intCast(self.type_items.items.len) });

            for (self.type_items.items, 0..) |item, i| {
                const ty: Type = @fromBackingInt(@intCast(i));

                switch (item.tag) {
                    .simple => try type_block.writeAbbrev(TypeBlock.Simple{ .code = @fromBackingInt(@intCast(item.data)) }),
                    .integer => try type_block.writeAbbrev(TypeBlock.Integer{ .width = item.data }),
                    .structure,
                    .packed_structure,
                    => |kind| {
                        const is_packed = switch (kind) {
                            .structure => false,
                            .packed_structure => true,
                            else => unreachable,
                        };
                        var extra = self.typeExtraDataTrail(Type.Structure, item.data);
                        try type_block.writeAbbrev(TypeBlock.StructAnon{
                            .is_packed = is_packed,
                            .types = extra.trail.next(extra.data.fields_len, Type, self),
                        });
                    },
                    .named_structure => {
                        const extra = self.typeExtraData(Type.NamedStructure, item.data);
                        try type_block.writeAbbrev(TypeBlock.StructName{
                            .string = extra.id.slice(self).?,
                        });

                        switch (extra.body) {
                            .none => try type_block.writeAbbrev(TypeBlock.Opaque{}),
                            else => {
                                const real_struct = self.type_items.items[@backingInt(extra.body)];
                                const is_packed: bool = switch (real_struct.tag) {
                                    .structure => false,
                                    .packed_structure => true,
                                    else => unreachable,
                                };

                                var real_extra = self.typeExtraDataTrail(Type.Structure, real_struct.data);
                                try type_block.writeAbbrev(TypeBlock.StructNamed{
                                    .is_packed = is_packed,
                                    .types = real_extra.trail.next(real_extra.data.fields_len, Type, self),
                                });
                            },
                        }
                    },
                    .array,
                    .small_array,
                    => try type_block.writeAbbrev(TypeBlock.Array{
                        .len = ty.aggregateLen(self),
                        .child = ty.childType(self),
                    }),
                    .vector,
                    .scalable_vector,
                    => try type_block.writeAbbrev(TypeBlock.Vector{
                        .len = ty.aggregateLen(self),
                        .child = ty.childType(self),
                    }),
                    .pointer => try type_block.writeAbbrev(TypeBlock.Pointer{
                        .addr_space = ty.pointerAddrSpace(self),
                    }),
                    .target => {
                        var extra = self.typeExtraDataTrail(Type.Target, item.data);
                        try type_block.writeAbbrev(TypeBlock.StructName{
                            .string = extra.data.name.slice(self).?,
                        });

                        const types = extra.trail.next(extra.data.types_len, Type, self);
                        const ints = extra.trail.next(extra.data.ints_len, u32, self);

                        try type_block.writeAbbrev(TypeBlock.Target{
                            .num_types = extra.data.types_len,
                            .types = types,
                            .ints = ints,
                        });
                    },
                    .function, .vararg_function => |kind| {
                        const is_vararg = switch (kind) {
                            .function => false,
                            .vararg_function => true,
                            else => unreachable,
                        };
                        var extra = self.typeExtraDataTrail(Type.Function, item.data);
                        try type_block.writeAbbrev(TypeBlock.Function{
                            .is_vararg = is_vararg,
                            .return_type = extra.data.ret,
                            .param_types = extra.trail.next(extra.data.params_len, Type, self),
                        });
                    },
                }
            }

            try type_block.end();
        }

        var attributes_set: std.array_hash_map.Auto(struct {
            attributes: Attributes,
            index: u32,
        }, void) = .{};
        defer attributes_set.deinit(self.gpa);

        // PARAMATTR_GROUP_BLOCK
        {
            const ParamattrGroupBlock = ir.ModuleBlock.ParamattrGroupBlock;

            var paramattr_group_block = try module_block.enterSubBlock(ParamattrGroupBlock, true);

            for (self.function_attributes_set.keys()) |func_attributes| {
                for (func_attributes.slice(self), 0..) |attributes, i| {
                    const attributes_slice = attributes.slice(self);
                    if (attributes_slice.len == 0) continue;

                    const attr_gop = try attributes_set.getOrPut(self.gpa, .{
                        .attributes = attributes,
                        .index = @intCast(i),
                    });

                    if (attr_gop.found_existing) continue;

                    record.clearRetainingCapacity();
                    try record.ensureUnusedCapacity(self.gpa, 2);

                    record.appendAssumeCapacity(attr_gop.index);
                    record.appendAssumeCapacity(switch (i) {
                        0 => 0xffffffff,
                        else => i - 1,
                    });

                    for (attributes_slice) |attr_index| {
                        const kind = attr_index.getKind(self);
                        switch (attr_index.toAttribute(self)) {
                            .zeroext,
                            .signext,
                            .noext,
                            .inreg,
                            .@"noalias",
                            .nocapture,
                            .nofree,
                            .nest,
                            .returned,
                            .nonnull,
                            .swiftself,
                            .swiftasync,
                            .swifterror,
                            .immarg,
                            .noundef,
                            .allocalign,
                            .allocptr,
                            .readnone,
                            .readonly,
                            .writeonly,
                            .writable,
                            .dead_on_unwind,
                            .alwaysinline,
                            .builtin,
                            .cold,
                            .convergent,
                            .disable_sanitizer_instrumentation,
                            .fn_ret_thunk_extern,
                            .hot,
                            .inlinehint,
                            .jumptable,
                            .minsize,
                            .naked,
                            .nobuiltin,
                            .nocallback,
                            .nodivergencesource,
                            .noduplicate,
                            .noimplicitfloat,
                            .@"noinline",
                            .nomerge,
                            .nonlazybind,
                            .noprofile,
                            .skipprofile,
                            .noredzone,
                            .noreturn,
                            .norecurse,
                            .willreturn,
                            .nosync,
                            .nounwind,
                            .nosanitize_bounds,
                            .nosanitize_coverage,
                            .null_pointer_is_valid,
                            .optdebug,
                            .optforfuzzing,
                            .optnone,
                            .optsize,
                            .returns_twice,
                            .safestack,
                            .sanitize_address,
                            .sanitize_memory,
                            .sanitize_thread,
                            .sanitize_hwaddress,
                            .sanitize_memtag,
                            .sanitize_realtime,
                            .sanitize_realtime_blocking,
                            .sanitize_alloc_token,
                            .speculative_load_hardening,
                            .speculatable,
                            .ssp,
                            .sspstrong,
                            .sspreq,
                            .strictfp,
                            .denormal_fpenv,
                            .nocf_check,
                            .shadowcallstack,
                            .mustprogress,
                            .nooutline,
                            .nocreateundeforpoison,
                            => {
                                try record.ensureUnusedCapacity(self.gpa, 2);
                                record.appendAssumeCapacity(0);
                                record.appendAssumeCapacity(@backingInt(kind));
                            },
                            .byval,
                            .byref,
                            .preallocated,
                            .inalloca,
                            .sret,
                            .elementtype,
                            => |ty| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(6);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@backingInt(ty));
                            },
                            .@"align",
                            .alignstack,
                            => |alignment| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(alignment.resolve(self).toByteUnits() orelse 0);
                            },
                            .captures => |captures| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@as(u32, @bitCast(captures)));
                            },
                            .dereferenceable,
                            .dereferenceable_or_null,
                            => |size| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(size);
                            },
                            .nofpclass => |fpclass| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@as(u32, @bitCast(fpclass)));
                            },
                            .initializes => @panic("TODO"),
                            .dead_on_return => @panic("TODO"),
                            .range => @panic("TODO"),
                            .allockind => |allockind| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@as(u32, @bitCast(allockind)));
                            },

                            .allocsize => |allocsize| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@bitCast(allocsize.toLlvm()));
                            },
                            .memory => |memory| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@as(u32, @bitCast(memory)));
                            },
                            .uwtable => |uwtable| if (uwtable != .none) {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@backingInt(uwtable));
                            },
                            .vscale_range => |vscale_range| {
                                try record.ensureUnusedCapacity(self.gpa, 3);
                                record.appendAssumeCapacity(1);
                                record.appendAssumeCapacity(@backingInt(kind));
                                record.appendAssumeCapacity(@bitCast(vscale_range.toLlvm()));
                            },
                            .string => |string_attr| {
                                const string_attr_kind_slice = string_attr.kind.slice(self).?;
                                const string_attr_value_slice = if (string_attr.value != .none)
                                    string_attr.value.slice(self).?
                                else
                                    null;

                                try record.ensureUnusedCapacity(
                                    self.gpa,
                                    2 + string_attr_kind_slice.len + if (string_attr_value_slice) |slice| slice.len + 1 else 0,
                                );
                                record.appendAssumeCapacity(if (string_attr.value == .none) 3 else 4);
                                for (string_attr.kind.slice(self).?) |c| {
                                    record.appendAssumeCapacity(c);
                                }
                                record.appendAssumeCapacity(0);
                                if (string_attr_value_slice) |slice| {
                                    for (slice) |c| {
                                        record.appendAssumeCapacity(c);
                                    }
                                    record.appendAssumeCapacity(0);
                                }
                            },
                            .none => unreachable,
                        }
                    }

                    try paramattr_group_block.writeUnabbrev(3, record.items);
                }
            }

            try paramattr_group_block.end();
        }

        // PARAMATTR_BLOCK
        {
            const ParamattrBlock = ir.ModuleBlock.ParamattrBlock;
            var paramattr_block = try module_block.enterSubBlock(ParamattrBlock, true);

            for (self.function_attributes_set.keys()) |func_attributes| {
                const func_attributes_slice = func_attributes.slice(self);
                record.clearRetainingCapacity();
                try record.ensureUnusedCapacity(self.gpa, func_attributes_slice.len);
                for (func_attributes_slice, 0..) |attributes, i| {
                    const attributes_slice = attributes.slice(self);
                    if (attributes_slice.len == 0) continue;

                    const group_index = attributes_set.getIndex(.{
                        .attributes = attributes,
                        .index = @intCast(i),
                    }).?;
                    record.appendAssumeCapacity(@intCast(group_index));
                }

                try paramattr_block.writeAbbrev(ParamattrBlock.Entry{ .group_indices = record.items });
            }

            try paramattr_block.end();
        }

        var globals: std.array_hash_map.Auto(Global.Index, void) = .empty;
        defer globals.deinit(self.gpa);
        try globals.ensureUnusedCapacity(
            self.gpa,
            self.variables.items.len +
                self.functions.items.len +
                self.aliases.items.len,
        );

        for (self.variables.items, 0..) |variable, variable_i| {
            // 若变量的全局符号已另作他用,则跳过该变量。
            switch (variable.global.ptrConst(self).kind) {
                .variable => |v| if (@backingInt(v) != variable_i) continue,
                else => continue,
            }

            globals.putAssumeCapacity(variable.global, {});
        }

        for (self.functions.items, 0..) |function, function_i| {
            // 如果函数的全局项已改作其他用途,则跳过该函数。
            switch (function.global.ptrConst(self).kind) {
                .function => |f| if (@backingInt(f) != function_i) continue,
                else => continue,
            }

            globals.putAssumeCapacity(function.global, {});
        }

        for (self.aliases.items, 0..) |alias, alias_i| {
            // 若别名对应的全局对象已被改作其他用途,则跳过该别名。
            switch (alias.global.ptrConst(self).kind) {
                .alias => |a| if (@backingInt(a) != alias_i) continue,
                else => continue,
            }

            globals.putAssumeCapacity(alias.global, {});
        }

        const ConstantAdapter = struct {
            builder: *const Builder,
            globals: *const std.array_hash_map.Auto(Global.Index, void),

            pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
                Constant => u32,
                else => |Param| Param,
            } {
                return switch (@TypeOf(param)) {
                    Constant => adapter.getConstantIndex(param),
                    else => param,
                };
            }

            pub fn getConstantIndex(adapter: @This(), constant: Constant) u32 {
                return switch (constant.unwrap()) {
                    .constant => |c| c + adapter.numGlobals(),
                    .global => |global| @intCast(adapter.globals.getIndex(global.unwrap(adapter.builder)).?),
                };
            }

            pub fn numConstants(adapter: @This()) u32 {
                return @intCast(adapter.globals.count() + adapter.builder.constant_items.len);
            }

            pub fn numGlobals(adapter: @This()) u32 {
                return @intCast(adapter.globals.count());
            }
        };
        const constant_adapter: ConstantAdapter = .{ .builder = self, .globals = &globals };

        // 全局项
        {
            var section_map: std.array_hash_map.Auto(String, void) = .empty;
            defer section_map.deinit(self.gpa);
            try section_map.ensureUnusedCapacity(self.gpa, globals.count());

            for (self.variables.items, 0..) |variable, variable_i| {
                // 若变量的全局符号已另作他用,则跳过该变量。
                switch (variable.global.ptrConst(self).kind) {
                    .variable => |v| if (@backingInt(v) != variable_i) continue,
                    else => continue,
                }

                const section = blk: {
                    if (variable.section == .none) break :blk 0;
                    const gop = section_map.getOrPutAssumeCapacity(variable.section);
                    if (!gop.found_existing) {
                        try module_block.writeAbbrev(ModuleBlock.String{
                            .code = 5,
                            .string = variable.section.slice(self).?,
                        });
                    }
                    break :blk gop.index + 1;
                };

                const initid = if (variable.init == .no_init)
                    0
                else
                    (constant_adapter.getConstantIndex(variable.init) + 1);

                const strtab = variable.global.strtab(self);

                const global = variable.global.ptrConst(self);
                try module_block.writeAbbrev(ModuleBlock.Variable{
                    .strtab_offset = strtab.offset,
                    .strtab_size = strtab.size,
                    .type_index = global.type,
                    .is_const = .{
                        .is_const = switch (variable.mutability) {
                            .global => false,
                            .constant => true,
                        },
                        .addr_space = global.addr_space,
                    },
                    .initid = initid,
                    .linkage = global.linkage,
                    .alignment = variable.alignment.toLlvm(),
                    .section = section,
                    .visibility = global.visibility,
                    .thread_local = variable.thread_local,
                    .unnamed_addr = global.unnamed_addr,
                    .externally_initialized = global.externally_initialized,
                    .dllstorageclass = global.dll_storage_class,
                    .preemption = global.preemption,
                });
            }

            for (self.functions.items, 0..) |func, func_i| {
                // 如果函数的全局项已改作其他用途,则跳过该函数。
                switch (func.global.ptrConst(self).kind) {
                    .function => |f| if (@backingInt(f) != func_i) continue,
                    else => continue,
                }

                const section = blk: {
                    if (func.section == .none) break :blk 0;
                    const gop = section_map.getOrPutAssumeCapacity(func.section);
                    if (!gop.found_existing) {
                        try module_block.writeAbbrev(ModuleBlock.String{
                            .code = 5,
                            .string = func.section.slice(self).?,
                        });
                    }
                    break :blk gop.index + 1;
                };

                const paramattr_index = if (self.function_attributes_set.getIndex(func.attributes)) |index|
                    index + 1
                else
                    0;

                const strtab = func.global.strtab(self);

                const global = func.global.ptrConst(self);
                try module_block.writeAbbrev(ModuleBlock.Function{
                    .strtab_offset = strtab.offset,
                    .strtab_size = strtab.size,
                    .type_index = global.type,
                    .call_conv = func.call_conv,
                    .is_proto = func.instructions.len == 0,
                    .linkage = global.linkage,
                    .paramattr = paramattr_index,
                    .alignment = func.alignment.toLlvm(),
                    .section = section,
                    .visibility = global.visibility,
                    .unnamed_addr = global.unnamed_addr,
                    .dllstorageclass = global.dll_storage_class,
                    .preemption = global.preemption,
                    .addr_space = global.addr_space,
                });
            }

            for (self.aliases.items, 0..) |alias, alias_i| {
                // 若别名对应的全局对象已被改作其他用途,则跳过该别名。
                switch (alias.global.ptrConst(self).kind) {
                    .alias => |a| if (@backingInt(a) != alias_i) continue,
                    else => continue,
                }

                const strtab = alias.global.strtab(self);
                const global = alias.global.ptrConst(self);

                // LLVM 要求类型匹配
                assert(global.addr_space == alias.aliasee.typeOf(self).pointerAddrSpace(self));

                try module_block.writeAbbrev(ModuleBlock.Alias{
                    .strtab_offset = strtab.offset,
                    .strtab_size = strtab.size,
                    .type_index = global.type,
                    .addr_space = global.addr_space,
                    .aliasee = constant_adapter.getConstantIndex(alias.aliasee),
                    .linkage = global.linkage,
                    .visibility = global.visibility,
                    .thread_local = alias.thread_local,
                    .unnamed_addr = global.unnamed_addr,
                    .dllstorageclass = global.dll_storage_class,
                    .preemption = global.preemption,
                });
            }
        }

        // CONSTANTS_BLOCK
        {
            const ConstantsBlock = ir.ModuleBlock.ConstantsBlock;
            var constants_block = try module_block.enterSubBlock(ConstantsBlock, true);

            var current_type: Type = .none;
            const tags = self.constant_items.items(.tag);
            const datas = self.constant_items.items(.data);
            for (0..self.constant_items.len) |index| {
                record.clearRetainingCapacity();
                const constant: Constant = @fromBackingInt(@intCast(index));
                const constant_type = constant.typeOf(self);
                if (constant_type != current_type) {
                    try constants_block.writeAbbrev(ConstantsBlock.SetType{ .type_id = constant_type });
                    current_type = constant_type;
                }
                const data = datas[index];
                switch (tags[index]) {
                    .null,
                    .zeroinitializer,
                    .none,
                    => try constants_block.writeAbbrev(ConstantsBlock.Null{}),
                    .undef => try constants_block.writeAbbrev(ConstantsBlock.Undef{}),
                    .poison => try constants_block.writeAbbrev(ConstantsBlock.Poison{}),
                    .positive_integer,
                    .negative_integer,
                    => |tag| {
                        const extra: *align(@alignOf(std.math.big.Limb)) Constant.Integer =
                            @ptrCast(self.constant_limbs.items[data..][0..Constant.Integer.limbs]);
                        const bigint: std.math.big.int.Const = .{
                            .limbs = self.constant_limbs
                                .items[data + Constant.Integer.limbs ..][0..extra.limbs_len],
                            .positive = switch (tag) {
                                .positive_integer => true,
                                .negative_integer => false,
                                else => unreachable,
                            },
                        };
                        const bit_count = extra.type.scalarBits(self);
                        const val: i64 = if (bit_count <= 64)
                            bigint.toInt(i64) catch unreachable
                        else if (bigint.toInt(u63)) |val|
                            @bitCast(@as(u64, val))
                        else |_| {
                            const limbs = try record.addManyAsSlice(
                                self.gpa,
                                std.math.divCeil(u24, bit_count, 64) catch unreachable,
                            );
                            bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little);
                            for (limbs) |*limb| {
                                const val = std.mem.littleToNative(i64, @bitCast(limb.*));
                                limb.* = @bitCast(if (val >= 0)
                                    val << 1 | 0
                                else
                                    -%val << 1 | 1);
                            }
                            try constants_block.writeUnabbrev(5, record.items);
                            continue;
                        };
                        try constants_block.writeAbbrev(ConstantsBlock.Integer{
                            .value = @bitCast(if (val >= 0)
                                val << 1 | 0
                            else
                                -%val << 1 | 1),
                        });
                    },
                    .half,
                    .bfloat,
                    => try constants_block.writeAbbrev(ConstantsBlock.Half{ .value = @truncate(data) }),
                    .float => try constants_block.writeAbbrev(ConstantsBlock.Float{ .value = data }),
                    .double => {
                        const extra = self.constantExtraData(Constant.Double, data);
                        try constants_block.writeAbbrev(ConstantsBlock.Double{
                            .value = (@as(u64, extra.hi) << 32) | extra.lo,
                        });
                    },
                    .x86_fp80 => {
                        const extra = self.constantExtraData(Constant.Fp80, data);
                        try constants_block.writeAbbrev(ConstantsBlock.Fp80{
                            .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |
                                extra.lo_lo >> 16,
                            .lo = @truncate(extra.lo_lo),
                        });
                    },
                    .fp128,
                    .ppc_fp128,
                    => {
                        const extra = self.constantExtraData(Constant.Fp128, data);
                        try constants_block.writeAbbrev(ConstantsBlock.Fp128{
                            .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),
                            .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),
                        });
                    },
                    .array,
                    .vector,
                    .structure,
                    .packed_structure,
                    => {
                        var extra = self.constantExtraDataTrail(Constant.Aggregate, data);
                        const len: u32 = @intCast(extra.data.type.aggregateLen(self));
                        const values = extra.trail.next(len, Constant, self);

                        try constants_block.writeAbbrevAdapted(
                            ConstantsBlock.Aggregate{ .values = values },
                            constant_adapter,
                        );
                    },
                    .splat => {
                        const ConstantsBlockWriter = @TypeOf(constants_block);
                        const extra = self.constantExtraData(Constant.Splat, data);
                        const vector_len = extra.type.vectorLen(self);
                        const c = constant_adapter.getConstantIndex(extra.value);

                        try bitcode.writeBits(
                            ConstantsBlockWriter.abbrevId(ConstantsBlock.Aggregate),
                            ConstantsBlockWriter.abbrev_len,
                        );
                        try bitcode.writeVbr(vector_len, 6);
                        for (0..vector_len) |_| {
                            try bitcode.writeBits(c, ConstantsBlock.Aggregate.ops[1].array_fixed);
                        }
                    },
                    .string => {
                        const str: String = @fromBackingInt(data);
                        if (str == .none) {
                            try constants_block.writeAbbrev(ConstantsBlock.Null{});
                        } else {
                            const slice = str.slice(self).?;
                            if (slice.len > 0 and slice[slice.len - 1] == 0)
                                try constants_block.writeAbbrev(ConstantsBlock.CString{ .string = slice[0 .. slice.len - 1] })
                            else
                                try constants_block.writeAbbrev(ConstantsBlock.String{ .string = slice });
                        }
                    },
                    .bitcast,
                    .inttoptr,
                    .ptrtoint,
                    .addrspacecast,
                    .trunc,
                    => |tag| {
                        const extra = self.constantExtraData(Constant.Cast, data);
                        try constants_block.writeAbbrevAdapted(ConstantsBlock.Cast{
                            .type_index = extra.type,
                            .val = extra.val,
                            .opcode = tag.toCastOpcode(),
                        }, constant_adapter);
                    },
                    .add,
                    .@"add nsw",
                    .@"add nuw",
                    .sub,
                    .@"sub nsw",
                    .@"sub nuw",
                    .shl,
                    .xor,
                    => |tag| {
                        const extra = self.constantExtraData(Constant.Binary, data);
                        try constants_block.writeAbbrevAdapted(ConstantsBlock.Binary{
                            .opcode = tag.toBinaryOpcode(),
                            .lhs = extra.lhs,
                            .rhs = extra.rhs,
                        }, constant_adapter);
                    },
                    .getelementptr,
                    .@"getelementptr inbounds",
                    => |tag| {
                        var extra = self.constantExtraDataTrail(Constant.GetElementPtr, data);
                        const indices = extra.trail.next(extra.data.info.indices_len, Constant, self);
                        try record.ensureUnusedCapacity(self.gpa, 1 + 2 + 2 * indices.len);

                        record.appendAssumeCapacity(@backingInt(extra.data.type));

                        record.appendAssumeCapacity(@backingInt(extra.data.base.typeOf(self)));
                        record.appendAssumeCapacity(constant_adapter.getConstantIndex(extra.data.base));

                        for (indices) |i| {
                            record.appendAssumeCapacity(@backingInt(i.typeOf(self)));
                            record.appendAssumeCapacity(constant_adapter.getConstantIndex(i));
                        }

                        try constants_block.writeUnabbrev(switch (tag) {
                            .getelementptr => 12,
                            .@"getelementptr inbounds" => 20,
                            else => unreachable,
                        }, record.items);
                    },
                    .@"asm",
                    .@"asm sideeffect",
                    .@"asm alignstack",
                    .@"asm sideeffect alignstack",
                    .@"asm inteldialect",
                    .@"asm sideeffect inteldialect",
                    .@"asm alignstack inteldialect",
                    .@"asm sideeffect alignstack inteldialect",
                    .@"asm unwind",
                    .@"asm sideeffect unwind",
                    .@"asm alignstack unwind",
                    .@"asm sideeffect alignstack unwind",
                    .@"asm inteldialect unwind",
                    .@"asm sideeffect inteldialect unwind",
                    .@"asm alignstack inteldialect unwind",
                    .@"asm sideeffect alignstack inteldialect unwind",
                    => |tag| {
                        const extra = self.constantExtraData(Constant.Assembly, data);

                        const assembly_slice = extra.assembly.slice(self).?;
                        const constraints_slice = extra.constraints.slice(self).?;

                        try record.ensureUnusedCapacity(self.gpa, 4 + assembly_slice.len + constraints_slice.len);

                        record.appendAssumeCapacity(@backingInt(extra.type));
                        record.appendAssumeCapacity(switch (tag) {
                            .@"asm" => 0,
                            .@"asm sideeffect" => 0b0001,
                            .@"asm sideeffect alignstack" => 0b0011,
                            .@"asm sideeffect inteldialect" => 0b0101,
                            .@"asm sideeffect alignstack inteldialect" => 0b0111,
                            .@"asm sideeffect unwind" => 0b1001,
                            .@"asm sideeffect alignstack unwind" => 0b1011,
                            .@"asm sideeffect inteldialect unwind" => 0b1101,
                            .@"asm sideeffect alignstack inteldialect unwind" => 0b1111,
                            .@"asm alignstack" => 0b0010,
                            .@"asm inteldialect" => 0b0100,
                            .@"asm alignstack inteldialect" => 0b0110,
                            .@"asm unwind" => 0b1000,
                            .@"asm alignstack unwind" => 0b1010,
                            .@"asm inteldialect unwind" => 0b1100,
                            .@"asm alignstack inteldialect unwind" => 0b1110,
                            else => unreachable,
                        });

                        record.appendAssumeCapacity(assembly_slice.len);
                        for (assembly_slice) |c| record.appendAssumeCapacity(c);

                        record.appendAssumeCapacity(constraints_slice.len);
                        for (constraints_slice) |c| record.appendAssumeCapacity(c);

                        try constants_block.writeUnabbrev(30, record.items);
                    },
                    .blockaddress => {
                        const extra = self.constantExtraData(Constant.BlockAddress, data);
                        try constants_block.writeAbbrev(ConstantsBlock.BlockAddress{
                            .type_id = extra.function.typeOf(self),
                            .function = constant_adapter.getConstantIndex(extra.function.toConst(self)),
                            .block = @backingInt(extra.block),
                        });
                    },
                    .dso_local_equivalent,
                    .no_cfi,
                    => |tag| {
                        const function: Function.Index = @fromBackingInt(data);
                        try constants_block.writeAbbrev(ConstantsBlock.DsoLocalEquivalentOrNoCfi{
                            .code = switch (tag) {
                                .dso_local_equivalent => .DSO_LOCAL_EQUIVALENT,
                                .no_cfi => .NO_CFI_VALUE,
                                else => unreachable,
                            },
                            .type_id = function.typeOf(self),
                            .function = constant_adapter.getConstantIndex(function.toConst(self)),
                        });
                    },
                }
            }

            try constants_block.end();
        }

        // METADATA_KIND_BLOCK
        {
            const MetadataKindBlock = ir.ModuleBlock.MetadataKindBlock;
            var metadata_kind_block = try module_block.enterSubBlock(MetadataKindBlock, true);

            const info = @typeInfo(ir.FixedMetadataKind).@"enum";

            inline for (info.field_names, info.field_values) |field_name, field_value| {
                // 已剥离的函数中不包含 `dbg`
                if (!(self.strip and std.mem.eql(u8, field_name, "dbg"))) {
                    try metadata_kind_block.writeAbbrev(MetadataKindBlock.Kind{
                        .id = field_value,
                        .name = field_name,
                    });
                }
            }

            try metadata_kind_block.end();
        }

        const MetadataAdapter = struct {
            constant_adapter: ConstantAdapter,

            pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
                Metadata, Metadata.Optional, Metadata.String, Metadata.String.Optional, Constant => u32,
                else => |Result| Result,
            } {
                return switch (@TypeOf(param)) {
                    Metadata => adapter.getMetadataIndex(param),
                    Metadata.Optional => adapter.getOptionalMetadataIndex(param),
                    Metadata.String => adapter.getMetadataIndex(param.toMetadata()),
                    Metadata.String.Optional => adapter.getOptionalMetadataIndex(param.toMetadata()),
                    Constant => adapter.constant_adapter.getConstantIndex(param),
                    else => param,
                };
            }

            pub fn getMetadataIndex(adapter: @This(), metadata: Metadata) u32 {
                const builder = adapter.constant_adapter.builder;
                const unwrapped_metadata = metadata.unwrap(builder);
                return switch (unwrapped_metadata.kind) {
                    .string => unwrapped_metadata.index,
                    .node => @intCast(builder.metadata_string_map.count() + unwrapped_metadata.index),
                    .forward, .local => unreachable,
                };
            }

            pub fn getOptionalMetadataIndex(adapter: @This(), metadata: Metadata.Optional) u32 {
                return if (metadata.unwrap()) |m| 1 + adapter.getMetadataIndex(m) else 0;
            }
        };
        const metadata_adapter: MetadataAdapter = .{ .constant_adapter = constant_adapter };

        // METADATA_BLOCK
        {
            const MetadataBlock = ir.ModuleBlock.MetadataBlock;
            var metadata_block = try module_block.enterSubBlock(MetadataBlock, true);

            const MetadataBlockWriter = @TypeOf(metadata_block);

            // 发出所有 Metadata.Strings
            const strings_len: u32 = @intCast(self.metadata_string_map.count());
            if (strings_len > 0) {
                const string_bytes_offset = string_bytes_offset: {
                    var string_bytes_bit_offset: u32 = 0;
                    for (
                        self.metadata_string_indices.items[0..strings_len],
                        self.metadata_string_indices.items[1..],
                    ) |start, end| string_bytes_bit_offset += BitcodeWriter.bitsVbr(end - start, 6);
                    break :string_bytes_offset @divExact(
                        std.mem.alignForward(u32, string_bytes_bit_offset, 32),
                        8,
                    );
                };
                const string_bytes_len =
                    std.mem.alignForward(u32, @intCast(self.metadata_string_bytes.items.len), 4);

                try bitcode.writeBits(
                    comptime MetadataBlockWriter.abbrevId(MetadataBlock.Strings),
                    MetadataBlockWriter.abbrev_len,
                );

                try bitcode.writeVbr(strings_len, 6);
                try bitcode.writeVbr(string_bytes_offset, 6);

                try bitcode.writeVbr(string_bytes_offset + string_bytes_len, 6);

                try bitcode.alignTo32();

                for (
                    self.metadata_string_indices.items[0..strings_len],
                    self.metadata_string_indices.items[1..],
                ) |start, end| try bitcode.writeVbr(end - start, 6);

                try bitcode.writeBlob(self.metadata_string_bytes.items);
            }

            for (self.metadata_items.items(.tag), self.metadata_items.items(.data)) |tag, data| {
                record.clearRetainingCapacity();
                switch (tag) {
                    .file => {
                        const extra = self.metadataExtraData(Metadata.File, data);

                        try metadata_block.writeAbbrevAdapted(MetadataBlock.File{
                            .filename = extra.filename,
                            .directory = extra.directory,
                        }, metadata_adapter);
                    },
                    .compile_unit,
                    .@"compile_unit optimized",
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.CompileUnit, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.CompileUnit{
                            .file = extra.file,
                            .producer = extra.producer,
                            .is_optimized = switch (kind) {
                                .compile_unit => false,
                                .@"compile_unit optimized" => true,
                                else => unreachable,
                            },
                            .enums = extra.enums,
                            .globals = extra.globals,
                        }, metadata_adapter);
                    },
                    .subprogram,
                    .@"subprogram local",
                    .@"subprogram definition",
                    .@"subprogram local definition",
                    .@"subprogram optimized",
                    .@"subprogram optimized local",
                    .@"subprogram optimized definition",
                    .@"subprogram optimized local definition",
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.Subprogram, data);

                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Subprogram{
                            .scope = extra.file,
                            .name = extra.name,
                            .linkage_name = extra.linkage_name,
                            .file = extra.file,
                            .line = extra.line,
                            .ty = extra.ty,
                            .scope_line = extra.scope_line,
                            .sp_flags = @bitCast(@as(u32, @as(u3, @intCast(
                                @backingInt(kind) - @backingInt(Metadata.Tag.subprogram),
                            ))) << 2),
                            .flags = extra.di_flags,
                            .compile_unit = extra.compile_unit,
                        }, metadata_adapter);
                    },
                    .lexical_block => {
                        const extra = self.metadataExtraData(Metadata.LexicalBlock, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.LexicalBlock{
                            .scope = extra.scope,
                            .file = extra.file,
                            .line = extra.line,
                            .column = extra.column,
                        }, metadata_adapter);
                    },
                    .location => {
                        const extra = self.metadataExtraData(Metadata.Location, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Location{
                            .line = extra.line,
                            .column = extra.column,
                            .scope = extra.scope,
                            .inlined_at = extra.inlined_at,
                        }, metadata_adapter);
                    },
                    .basic_bool_type,
                    .basic_unsigned_type,
                    .basic_signed_type,
                    .basic_float_type,
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.BasicType, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.BasicType{
                            .name = extra.name,
                            .size_in_bits = extra.bitSize(),
                            .encoding = switch (kind) {
                                .basic_bool_type => DW.ATE.boolean,
                                .basic_unsigned_type => DW.ATE.unsigned,
                                .basic_signed_type => DW.ATE.signed,
                                .basic_float_type => DW.ATE.float,
                                else => unreachable,
                            },
                        }, metadata_adapter);
                    },
                    .composite_struct_type,
                    .composite_union_type,
                    .composite_enumeration_type,
                    .composite_array_type,
                    .composite_vector_type,
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.CompositeType, data);

                        try metadata_block.writeAbbrevAdapted(MetadataBlock.CompositeType{
                            .tag = switch (kind) {
                                .composite_struct_type => DW.TAG.structure_type,
                                .composite_union_type => DW.TAG.union_type,
                                .composite_enumeration_type => DW.TAG.enumeration_type,
                                .composite_array_type, .composite_vector_type => DW.TAG.array_type,
                                else => unreachable,
                            },
                            .name = extra.name,
                            .file = extra.file,
                            .line = extra.line,
                            .scope = extra.scope,
                            .underlying_type = extra.underlying_type,
                            .size_in_bits = extra.bitSize(),
                            .align_in_bits = extra.bitAlign(),
                            .flags = if (kind == .composite_vector_type) .{ .Vector = true } else .{},
                            .elements = extra.fields_tuple,
                        }, metadata_adapter);
                    },
                    .derived_pointer_type,
                    .derived_member_type,
                    .derived_typedef_type,
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.DerivedType, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.DerivedType{
                            .tag = switch (kind) {
                                .derived_pointer_type => DW.TAG.pointer_type,
                                .derived_member_type => DW.TAG.member,
                                .derived_typedef_type => DW.TAG.typedef,
                                else => unreachable,
                            },
                            .name = extra.name,
                            .file = extra.file,
                            .line = extra.line,
                            .scope = extra.scope,
                            .underlying_type = extra.underlying_type,
                            .size_in_bits = extra.bitSize(),
                            .align_in_bits = extra.bitAlign(),
                            .offset_in_bits = extra.bitOffset(),
                        }, metadata_adapter);
                    },
                    .subroutine_type => {
                        const extra = self.metadataExtraData(Metadata.SubroutineType, data);

                        try metadata_block.writeAbbrevAdapted(MetadataBlock.SubroutineType{
                            .types = extra.types_tuple,
                        }, metadata_adapter);
                    },
                    .enumerator_unsigned,
                    .enumerator_signed_positive,
                    .enumerator_signed_negative,
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.Enumerator, data);
                        const bigint: std.math.big.int.Const = .{
                            .limbs = self.metadata_limbs.items[extra.limbs_index..][0..extra.limbs_len],
                            .positive = switch (kind) {
                                .enumerator_unsigned,
                                .enumerator_signed_positive,
                                => true,
                                .enumerator_signed_negative => false,
                                else => unreachable,
                            },
                        };
                        const flags: MetadataBlock.Enumerator.Flags = .{
                            .unsigned = switch (kind) {
                                .enumerator_unsigned => true,
                                .enumerator_signed_positive,
                                .enumerator_signed_negative,
                                => false,
                                else => unreachable,
                            },
                        };
                        const val: i64 = if (bigint.toInt(i64)) |val|
                            val
                        else |_| if (bigint.toInt(u64)) |val|
                            @bitCast(val)
                        else |_| {
                            const limbs_len = std.math.divCeil(u32, extra.bit_width, 64) catch unreachable;
                            try record.ensureTotalCapacity(self.gpa, 3 + limbs_len);
                            record.appendAssumeCapacity(@as(
                                @typeInfo(MetadataBlock.Enumerator.Flags).@"struct".backing_integer.?,
                                @bitCast(flags),
                            ));
                            record.appendAssumeCapacity(extra.bit_width);
                            record.appendAssumeCapacity(metadata_adapter.getOptionalMetadataIndex(extra.name.toMetadata()));
                            const limbs = record.addManyAsSliceAssumeCapacity(limbs_len);
                            bigint.writeTwosComplement(std.mem.sliceAsBytes(limbs), .little);
                            for (limbs) |*limb| {
                                const val = std.mem.littleToNative(i64, @bitCast(limb.*));
                                limb.* = @bitCast(if (val >= 0)
                                    val << 1 | 0
                                else
                                    -%val << 1 | 1);
                            }
                            try metadata_block.writeUnabbrev(@backingInt(MetadataBlock.Code.ENUMERATOR), record.items);
                            continue;
                        };
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Enumerator{
                            .flags = flags,
                            .bit_width = extra.bit_width,
                            .name = extra.name,
                            .value = @bitCast(if (val >= 0)
                                val << 1 | 0
                            else
                                -%val << 1 | 1),
                        }, metadata_adapter);
                    },
                    .subrange => {
                        const extra = self.metadataExtraData(Metadata.Subrange, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Subrange{
                            .count = extra.count,
                            .lower_bound = extra.lower_bound,
                        }, metadata_adapter);
                    },
                    .expression => {
                        var extra = self.metadataExtraDataTrail(Metadata.Expression, data);
                        const elements = extra.trail.next(extra.data.elements_len, u32, self);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Expression{
                            .elements = elements,
                        }, metadata_adapter);
                    },
                    .tuple => {
                        var extra = self.metadataExtraDataTrail(Metadata.Tuple, data);
                        const elements =
                            extra.trail.next(extra.data.elements_len, Metadata.Optional, self);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Node{
                            .elements = elements,
                        }, metadata_adapter);
                    },
                    .local_var => {
                        const extra = self.metadataExtraData(Metadata.LocalVar, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.LocalVar{
                            .scope = extra.scope,
                            .name = extra.name,
                            .file = extra.file,
                            .line = extra.line,
                            .ty = extra.ty,
                        }, metadata_adapter);
                    },
                    .parameter => {
                        const extra = self.metadataExtraData(Metadata.Parameter, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Parameter{
                            .scope = extra.scope,
                            .name = extra.name,
                            .file = extra.file,
                            .line = extra.line,
                            .ty = extra.ty,
                            .arg = extra.arg_no,
                        }, metadata_adapter);
                    },
                    .global_var,
                    .@"global_var local",
                    => |kind| {
                        const extra = self.metadataExtraData(Metadata.GlobalVar, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalVar{
                            .scope = extra.scope,
                            .name = extra.name,
                            .linkage_name = extra.linkage_name,
                            .file = extra.file,
                            .line = extra.line,
                            .ty = extra.ty,
                            .local = kind == .@"global_var local",
                        }, metadata_adapter);
                    },
                    .global_var_expression => {
                        const extra = self.metadataExtraData(Metadata.GlobalVarExpression, data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalVarExpression{
                            .variable = extra.variable,
                            .expression = extra.expression,
                        }, metadata_adapter);
                    },
                    .constant => {
                        const constant: Constant = @fromBackingInt(data);
                        try metadata_block.writeAbbrevAdapted(MetadataBlock.Constant{
                            .ty = constant.typeOf(self),
                            .constant = constant,
                        }, metadata_adapter);
                    },
                }
            }

            // 写入具名元数据
            for (self.metadata_named.keys(), self.metadata_named.values()) |name, operands| {
                try metadata_block.writeAbbrev(MetadataBlock.Name{ .name = name.slice(self).? });
                try metadata_block.writeAbbrevAdapted(MetadataBlock.NamedNode{
                    .elements = @ptrCast(self.metadata_extra.items[operands.index..][0..operands.len]),
                }, metadata_adapter);
            }

            // 写入全局附加元数据
            {
                for (globals.keys()) |global_index| {
                    const global = global_index.ptrConst(self);
                    if (global.dbg.unwrap()) |dbg| {
                        switch (global.kind) {
                            .function => |f| if (f.ptrConst(self).instructions.len != 0) continue,
                            else => {},
                        }

                        try metadata_block.writeAbbrevAdapted(MetadataBlock.GlobalDeclAttachment{
                            .value = global_index.toConst(),
                            .kind = .dbg,
                            .metadata = dbg,
                        }, metadata_adapter);
                    }
                }
            }

            try metadata_block.end();
        }

        // OPERAND_BUNDLE_TAGS_BLOCK
        {
            const OperandBundleTagsBlock = ir.ModuleBlock.OperandBundleTagsBlock;
            var operand_bundle_tags_block = try module_block.enterSubBlock(OperandBundleTagsBlock, true);

            try operand_bundle_tags_block.writeAbbrev(OperandBundleTagsBlock.OperandBundleTag{
                .tag = "cold",
            });

            try operand_bundle_tags_block.end();
        }

        // 块信息
        {
            const BlockInfoBlock = ir.BlockInfoBlock;
            var block_info_block = try module_block.enterSubBlock(BlockInfoBlock, true);

            try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
                @backingInt(ir.ModuleBlock.FunctionBlock.id),
            });
            inline for (ir.ModuleBlock.FunctionBlock.abbrevs) |abbrev| {
                try block_info_block.defineAbbrev(&abbrev.ops);
            }

            try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
                @backingInt(ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.id),
            });
            inline for (ir.ModuleBlock.FunctionBlock.ValueSymtabBlock.abbrevs) |abbrev| {
                try block_info_block.defineAbbrev(&abbrev.ops);
            }

            try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
                @backingInt(ir.ModuleBlock.FunctionBlock.MetadataBlock.id),
            });
            inline for (ir.ModuleBlock.FunctionBlock.MetadataBlock.abbrevs) |abbrev| {
                try block_info_block.defineAbbrev(&abbrev.ops);
            }

            try block_info_block.writeUnabbrev(BlockInfoBlock.set_block_id, &.{
                @backingInt(ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.id),
            });
            inline for (ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock.abbrevs) |abbrev| {
                try block_info_block.defineAbbrev(&abbrev.ops);
            }

            try block_info_block.end();
        }

        // FUNCTION_BLOCKS
        {
            const FunctionAdapter = struct {
                metadata_adapter: MetadataAdapter,
                func: *const Function,
                instruction_index: Function.Instruction.Index,

                pub fn get(adapter: @This(), param: anytype) switch (@TypeOf(param)) {
                    Value, Constant, FunctionAttributes => u32,
                    else => |Result| Result,
                } {
                    return switch (@TypeOf(param)) {
                        Value => adapter.getOffsetValueIndex(param),
                        Constant => adapter.getOffsetConstantIndex(param),
                        FunctionAttributes => switch (param) {
                            .none => 0,
                            else => @intCast(1 + adapter.metadata_adapter.constant_adapter.builder
                                .function_attributes_set.getIndex(param).?),
                        },
                        else => param,
                    };
                }

                pub fn getValueIndex(adapter: @This(), value: Value) u32 {
                    return @intCast(switch (value.unwrap()) {
                        .instruction => |instruction| instruction.valueIndex(adapter.func) + adapter.firstInstr(),
                        .constant => |constant| adapter.metadata_adapter.constant_adapter.getConstantIndex(constant),
                        .metadata => |metadata| {
                            const builder = adapter.metadata_adapter.constant_adapter.builder;
                            const unwrapped_metadata = metadata.unwrap(builder);
                            return switch (unwrapped_metadata.kind) {
                                .string, .node => adapter.metadata_adapter.getMetadataIndex(unwrapped_metadata),
                                .forward => unreachable,
                                .local => @intCast(builder.metadata_string_map.count() +
                                    builder.metadata_map.count() +
                                    unwrapped_metadata.index),
                            };
                        },
                    });
                }

                pub fn getOffsetValueIndex(adapter: @This(), value: Value) u32 {
                    return adapter.offset() -% adapter.getValueIndex(value);
                }

                pub fn getOffsetValueSignedIndex(adapter: @This(), value: Value) i32 {
                    const signed_offset: i32 = @intCast(adapter.offset());
                    const signed_value: i32 = @intCast(adapter.getValueIndex(value));
                    return signed_offset - signed_value;
                }

                pub fn getOffsetConstantIndex(adapter: @This(), constant: Constant) u32 {
                    return adapter.offset() - adapter.constant_adapter.getConstantIndex(constant);
                }

                pub fn offset(adapter: @This()) u32 {
                    return adapter.instruction_index.valueIndex(adapter.func) + adapter.firstInstr();
                }

                fn firstInstr(adapter: @This()) u32 {
                    return adapter.metadata_adapter.constant_adapter.numConstants();
                }
            };

            for (self.functions.items, 0..) |func, func_index| {
                // 如果函数的全局项已改作其他用途,则跳过该函数。
                switch (func.global.ptrConst(self).kind) {
                    .function => |f| if (@backingInt(f) != func_index) continue,
                    else => continue,
                }

                const FunctionBlock = ir.ModuleBlock.FunctionBlock;

                if (func.instructions.len == 0) continue;

                var function_block = try module_block.enterSubBlock(FunctionBlock, false);

                try function_block.writeAbbrev(FunctionBlock.DeclareBlocks{ .num_blocks = func.blocks.len });

                var adapter: FunctionAdapter = .{
                    .metadata_adapter = metadata_adapter,
                    .func = &func,
                    .instruction_index = @fromBackingInt(0),
                };

                // 发出函数级元数据块
                if (!func.strip and func.debug_values.len > 0) {
                    const MetadataBlock = ir.ModuleBlock.FunctionBlock.MetadataBlock;
                    var metadata_block = try function_block.enterSubBlock(MetadataBlock, false);

                    for (func.debug_values) |value| {
                        try metadata_block.writeAbbrev(MetadataBlock.Value{
                            .ty = value.typeOf(@fromBackingInt(@intCast(func_index)), self),
                            .value = @fromBackingInt(adapter.getValueIndex(value.toValue())),
                        });
                    }

                    try metadata_block.end();
                }

                const tags = func.instructions.items(.tag);
                const datas = func.instructions.items(.data);

                var has_location = false;

                var block_incoming_len: u32 = undefined;
                for (tags, datas, 0..) |tag, data, instr_index| {
                    adapter.instruction_index = @fromBackingInt(@intCast(instr_index));
                    record.clearRetainingCapacity();

                    switch (tag) {
                        .arg => continue,
                        .block => {
                            block_incoming_len = data;
                            continue;
                        },
                        .@"unreachable" => try function_block.writeAbbrev(FunctionBlock.Unreachable{}),
                        .call,
                        .@"musttail call",
                        .@"notail call",
                        .@"tail call",
                        => |kind| {
                            var extra = func.extraDataTrail(Function.Instruction.Call, data);

                            if (extra.data.info.has_op_bundle_cold) {
                                try function_block.writeAbbrev(FunctionBlock.ColdOperandBundle{});
                            }

                            const call_conv = extra.data.info.call_conv;
                            const args = extra.trail.next(extra.data.args_len, Value, &func);
                            try function_block.writeAbbrevAdapted(FunctionBlock.Call{
                                .attributes = extra.data.attributes,
                                .call_type = switch (kind) {
                                    .call => .{ .call_conv = call_conv },
                                    .@"tail call" => .{ .tail = true, .call_conv = call_conv },
                                    .@"musttail call" => .{ .must_tail = true, .call_conv = call_conv },
                                    .@"notail call" => .{ .no_tail = true, .call_conv = call_conv },
                                    else => unreachable,
                                },
                                .type_id = extra.data.ty,
                                .callee = extra.data.callee,
                                .args = args,
                            }, adapter);
                        },
                        .@"call fast",
                        .@"musttail call fast",
                        .@"notail call fast",
                        .@"tail call fast",
                        => |kind| {
                            var extra = func.extraDataTrail(Function.Instruction.Call, data);

                            if (extra.data.info.has_op_bundle_cold) {
                                try function_block.writeAbbrev(FunctionBlock.ColdOperandBundle{});
                            }

                            const call_conv = extra.data.info.call_conv;
                            const args = extra.trail.next(extra.data.args_len, Value, &func);
                            try function_block.writeAbbrevAdapted(FunctionBlock.CallFast{
                                .attributes = extra.data.attributes,
                                .call_type = switch (kind) {
                                    .@"call fast" => .{ .call_conv = call_conv },
                                    .@"tail call fast" => .{ .tail = true, .call_conv = call_conv },
                                    .@"musttail call fast" => .{ .must_tail = true, .call_conv = call_conv },
                                    .@"notail call fast" => .{ .no_tail = true, .call_conv = call_conv },
                                    else => unreachable,
                                },
                                .fast_math = FastMath.fast,
                                .type_id = extra.data.ty,
                                .callee = extra.data.callee,
                                .args = args,
                            }, adapter);
                        },
                        .add,
                        .@"and",
                        .fadd,
                        .fdiv,
                        .fmul,
                        .mul,
                        .frem,
                        .fsub,
                        .sdiv,
                        .sub,
                        .udiv,
                        .xor,
                        .shl,
                        .lshr,
                        .@"or",
                        .urem,
                        .srem,
                        .ashr,
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Binary, data);
                            try function_block.writeAbbrev(FunctionBlock.Binary{
                                .opcode = kind.toBinaryOpcode(),
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                            });
                        },
                        .@"sdiv exact",
                        .@"udiv exact",
                        .@"lshr exact",
                        .@"ashr exact",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Binary, data);
                            try function_block.writeAbbrev(FunctionBlock.BinaryExact{
                                .opcode = kind.toBinaryOpcode(),
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                            });
                        },
                        .@"add nsw",
                        .@"add nuw",
                        .@"add nuw nsw",
                        .@"mul nsw",
                        .@"mul nuw",
                        .@"mul nuw nsw",
                        .@"sub nsw",
                        .@"sub nuw",
                        .@"sub nuw nsw",
                        .@"shl nsw",
                        .@"shl nuw",
                        .@"shl nuw nsw",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Binary, data);
                            try function_block.writeAbbrev(FunctionBlock.BinaryNoWrap{
                                .opcode = kind.toBinaryOpcode(),
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .flags = switch (kind) {
                                    .@"add nsw",
                                    .@"mul nsw",
                                    .@"sub nsw",
                                    .@"shl nsw",
                                    => .{ .no_unsigned_wrap = false, .no_signed_wrap = true },
                                    .@"add nuw",
                                    .@"mul nuw",
                                    .@"sub nuw",
                                    .@"shl nuw",
                                    => .{ .no_unsigned_wrap = true, .no_signed_wrap = false },
                                    .@"add nuw nsw",
                                    .@"mul nuw nsw",
                                    .@"sub nuw nsw",
                                    .@"shl nuw nsw",
                                    => .{ .no_unsigned_wrap = true, .no_signed_wrap = true },
                                    else => unreachable,
                                },
                            });
                        },
                        .@"fadd fast",
                        .@"fdiv fast",
                        .@"fmul fast",
                        .@"frem fast",
                        .@"fsub fast",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Binary, data);
                            try function_block.writeAbbrev(FunctionBlock.BinaryFast{
                                .opcode = kind.toBinaryOpcode(),
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .fast_math = FastMath.fast,
                            });
                        },
                        .alloca,
                        .@"alloca inalloca",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Alloca, data);
                            const alignment = extra.info.alignment.toLlvm();
                            try function_block.writeAbbrev(FunctionBlock.Alloca{
                                .inst_type = extra.type,
                                .len_type = extra.len.typeOf(@fromBackingInt(@intCast(func_index)), self),
                                .len_value = adapter.getValueIndex(extra.len),
                                .flags = .{
                                    .align_lower = @truncate(alignment),
                                    .inalloca = kind == .@"alloca inalloca",
                                    .explicit_type = true,
                                    .swift_error = false,
                                    .align_upper = @truncate(alignment << 5),
                                },
                            });
                        },
                        .bitcast,
                        .inttoptr,
                        .ptrtoint,
                        .fptosi,
                        .fptoui,
                        .sitofp,
                        .uitofp,
                        .addrspacecast,
                        .fptrunc,
                        .trunc,
                        .fpext,
                        .sext,
                        .zext,
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Cast, data);
                            try function_block.writeAbbrev(FunctionBlock.Cast{
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .type_index = extra.type,
                                .opcode = kind.toCastOpcode(),
                            });
                        },
                        .@"trunc nuw",
                        .@"trunc nsw",
                        .@"trunc nuw nsw",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Cast, data);
                            try function_block.writeAbbrev(FunctionBlock.TruncNoWrap{
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .type_index = extra.type,
                                .flags = .{
                                    .no_unsigned_wrap = kind == .@"trunc nuw" or kind == .@"trunc nuw nsw",
                                    .no_signed_wrap = kind == .@"trunc nsw" or kind == .@"trunc nuw nsw",
                                },
                            });
                        },
                        .@"fcmp false",
                        .@"fcmp oeq",
                        .@"fcmp oge",
                        .@"fcmp ogt",
                        .@"fcmp ole",
                        .@"fcmp olt",
                        .@"fcmp one",
                        .@"fcmp ord",
                        .@"fcmp true",
                        .@"fcmp ueq",
                        .@"fcmp uge",
                        .@"fcmp ugt",
                        .@"fcmp ule",
                        .@"fcmp ult",
                        .@"fcmp une",
                        .@"fcmp uno",
                        .@"icmp eq",
                        .@"icmp ne",
                        .@"icmp sge",
                        .@"icmp sgt",
                        .@"icmp sle",
                        .@"icmp slt",
                        .@"icmp uge",
                        .@"icmp ugt",
                        .@"icmp ule",
                        .@"icmp ult",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Binary, data);
                            try function_block.writeAbbrev(FunctionBlock.Cmp{
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .pred = kind.toCmpPredicate(),
                            });
                        },
                        .@"fcmp fast false",
                        .@"fcmp fast oeq",
                        .@"fcmp fast oge",
                        .@"fcmp fast ogt",
                        .@"fcmp fast ole",
                        .@"fcmp fast olt",
                        .@"fcmp fast one",
                        .@"fcmp fast ord",
                        .@"fcmp fast true",
                        .@"fcmp fast ueq",
                        .@"fcmp fast uge",
                        .@"fcmp fast ugt",
                        .@"fcmp fast ule",
                        .@"fcmp fast ult",
                        .@"fcmp fast une",
                        .@"fcmp fast uno",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.Binary, data);
                            try function_block.writeAbbrev(FunctionBlock.CmpFast{
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .pred = kind.toCmpPredicate(),
                                .fast_math = FastMath.fast,
                            });
                        },
                        .fneg => try function_block.writeAbbrev(FunctionBlock.FNeg{
                            .val = adapter.getOffsetValueIndex(@fromBackingInt(data)),
                        }),
                        .@"fneg fast" => try function_block.writeAbbrev(FunctionBlock.FNegFast{
                            .val = adapter.getOffsetValueIndex(@fromBackingInt(data)),
                            .fast_math = FastMath.fast,
                        }),
                        .extractvalue => {
                            var extra = func.extraDataTrail(Function.Instruction.ExtractValue, data);
                            const indices = extra.trail.next(extra.data.indices_len, u32, &func);
                            try function_block.writeAbbrev(FunctionBlock.ExtractValue{
                                .val = adapter.getOffsetValueIndex(extra.data.val),
                                .indices = indices,
                            });
                        },
                        .extractelement => {
                            const extra = func.extraData(Function.Instruction.ExtractElement, data);
                            try function_block.writeAbbrev(FunctionBlock.ExtractElement{
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .index = adapter.getOffsetValueIndex(extra.index),
                            });
                        },
                        .indirectbr => {
                            var extra =
                                func.extraDataTrail(Function.Instruction.IndirectBr, datas[instr_index]);
                            const targets =
                                extra.trail.next(extra.data.targets_len, Function.Block.Index, &func);
                            try function_block.writeAbbrevAdapted(
                                FunctionBlock.IndirectBr{
                                    .ty = extra.data.addr.typeOf(@fromBackingInt(@intCast(func_index)), self),
                                    .addr = extra.data.addr,
                                    .targets = targets,
                                },
                                adapter,
                            );
                        },
                        .insertelement => {
                            const extra = func.extraData(Function.Instruction.InsertElement, data);
                            try function_block.writeAbbrev(FunctionBlock.InsertElement{
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .elem = adapter.getOffsetValueIndex(extra.elem),
                                .index = adapter.getOffsetValueIndex(extra.index),
                            });
                        },
                        .insertvalue => {
                            var extra = func.extraDataTrail(Function.Instruction.InsertValue, datas[instr_index]);
                            const indices = extra.trail.next(extra.data.indices_len, u32, &func);
                            try function_block.writeAbbrev(FunctionBlock.InsertValue{
                                .val = adapter.getOffsetValueIndex(extra.data.val),
                                .elem = adapter.getOffsetValueIndex(extra.data.elem),
                                .indices = indices,
                            });
                        },
                        .select => {
                            const extra = func.extraData(Function.Instruction.Select, data);
                            try function_block.writeAbbrev(FunctionBlock.Select{
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .cond = adapter.getOffsetValueIndex(extra.cond),
                            });
                        },
                        .@"select fast" => {
                            const extra = func.extraData(Function.Instruction.Select, data);
                            try function_block.writeAbbrev(FunctionBlock.SelectFast{
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .cond = adapter.getOffsetValueIndex(extra.cond),
                                .fast_math = FastMath.fast,
                            });
                        },
                        .shufflevector => {
                            const extra = func.extraData(Function.Instruction.ShuffleVector, data);
                            try function_block.writeAbbrev(FunctionBlock.ShuffleVector{
                                .lhs = adapter.getOffsetValueIndex(extra.lhs),
                                .rhs = adapter.getOffsetValueIndex(extra.rhs),
                                .mask = adapter.getOffsetValueIndex(extra.mask),
                            });
                        },
                        .getelementptr,
                        .@"getelementptr inbounds",
                        => |kind| {
                            var extra = func.extraDataTrail(Function.Instruction.GetElementPtr, data);
                            const indices = extra.trail.next(extra.data.indices_len, Value, &func);
                            try function_block.writeAbbrevAdapted(
                                FunctionBlock.GetElementPtr{
                                    .is_inbounds = kind == .@"getelementptr inbounds",
                                    .type_index = extra.data.type,
                                    .base = extra.data.base,
                                    .indices = indices,
                                },
                                adapter,
                            );
                        },
                        .load => {
                            const extra = func.extraData(Function.Instruction.Load, data);
                            try function_block.writeAbbrev(FunctionBlock.Load{
                                .ptr = adapter.getOffsetValueIndex(extra.ptr),
                                .ty = extra.type,
                                .alignment = extra.info.alignment.toLlvm(),
                                .is_volatile = extra.info.access_kind == .@"volatile",
                            });
                        },
                        .@"load atomic" => {
                            const extra = func.extraData(Function.Instruction.Load, data);
                            try function_block.writeAbbrev(FunctionBlock.LoadAtomic{
                                .ptr = adapter.getOffsetValueIndex(extra.ptr),
                                .ty = extra.type,
                                .alignment = extra.info.alignment.toLlvm(),
                                .is_volatile = extra.info.access_kind == .@"volatile",
                                .success_ordering = extra.info.success_ordering,
                                .sync_scope = extra.info.sync_scope,
                            });
                        },
                        .store => {
                            const extra = func.extraData(Function.Instruction.Store, data);
                            try function_block.writeAbbrev(FunctionBlock.Store{
                                .ptr = adapter.getOffsetValueIndex(extra.ptr),
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .alignment = extra.info.alignment.toLlvm(),
                                .is_volatile = extra.info.access_kind == .@"volatile",
                            });
                        },
                        .@"store atomic" => {
                            const extra = func.extraData(Function.Instruction.Store, data);
                            try function_block.writeAbbrev(FunctionBlock.StoreAtomic{
                                .ptr = adapter.getOffsetValueIndex(extra.ptr),
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .alignment = extra.info.alignment.toLlvm(),
                                .is_volatile = extra.info.access_kind == .@"volatile",
                                .success_ordering = extra.info.success_ordering,
                                .sync_scope = extra.info.sync_scope,
                            });
                        },
                        .br => {
                            try function_block.writeAbbrev(FunctionBlock.BrUnconditional{
                                .block = data,
                            });
                        },
                        .br_cond => {
                            const extra = func.extraData(Function.Instruction.BrCond, data);
                            try function_block.writeAbbrev(FunctionBlock.BrConditional{
                                .then_block = @backingInt(extra.then),
                                .else_block = @backingInt(extra.@"else"),
                                .condition = adapter.getOffsetValueIndex(extra.cond),
                            });
                        },
                        .@"switch" => {
                            var extra = func.extraDataTrail(Function.Instruction.Switch, data);

                            try record.ensureUnusedCapacity(self.gpa, 3 + extra.data.cases_len * 2);

                            // 条件类型
                            record.appendAssumeCapacity(@backingInt(extra.data.val.typeOf(@fromBackingInt(@intCast(func_index)), self)));

                            // 条件式
                            record.appendAssumeCapacity(adapter.getOffsetValueIndex(extra.data.val));

                            // 默认块
                            record.appendAssumeCapacity(@backingInt(extra.data.default));

                            const vals = extra.trail.next(extra.data.cases_len, Constant, &func);
                            const blocks = extra.trail.next(extra.data.cases_len, Function.Block.Index, &func);
                            for (vals, blocks) |val, block| {
                                record.appendAssumeCapacity(adapter.metadata_adapter.constant_adapter.getConstantIndex(val));
                                record.appendAssumeCapacity(@backingInt(block));
                            }

                            try function_block.writeUnabbrev(12, record.items);
                        },
                        .va_arg => {
                            const extra = func.extraData(Function.Instruction.VaArg, data);
                            try function_block.writeAbbrev(FunctionBlock.VaArg{
                                .list_type = extra.list.typeOf(@fromBackingInt(@intCast(func_index)), self),
                                .list = adapter.getOffsetValueIndex(extra.list),
                                .type = extra.type,
                            });
                        },
                        .phi,
                        .@"phi fast",
                        => |kind| {
                            var extra = func.extraDataTrail(Function.Instruction.Phi, data);
                            const vals = extra.trail.next(block_incoming_len, Value, &func);
                            const blocks = extra.trail.next(block_incoming_len, Function.Block.Index, &func);

                            try record.ensureUnusedCapacity(
                                self.gpa,
                                1 + block_incoming_len * 2 + @intFromBool(kind == .@"phi fast"),
                            );

                            record.appendAssumeCapacity(@backingInt(extra.data.type));

                            for (vals, blocks) |val, block| {
                                const offset_value = adapter.getOffsetValueSignedIndex(val);
                                const abs_value: u32 = @intCast(@abs(offset_value));
                                const signed_vbr = if (offset_value > 0) abs_value << 1 else ((abs_value << 1) | 1);
                                record.appendAssumeCapacity(signed_vbr);
                                record.appendAssumeCapacity(@backingInt(block));
                            }

                            if (kind == .@"phi fast") record.appendAssumeCapacity(@as(u8, @bitCast(FastMath{})));

                            try function_block.writeUnabbrev(16, record.items);
                        },
                        .ret => try function_block.writeAbbrev(FunctionBlock.Ret{
                            .val = adapter.getOffsetValueIndex(@fromBackingInt(data)),
                        }),
                        .@"ret void" => try function_block.writeAbbrev(FunctionBlock.RetVoid{}),
                        .atomicrmw => {
                            const extra = func.extraData(Function.Instruction.AtomicRmw, data);
                            try function_block.writeAbbrev(FunctionBlock.AtomicRmw{
                                .ptr = adapter.getOffsetValueIndex(extra.ptr),
                                .val = adapter.getOffsetValueIndex(extra.val),
                                .operation = extra.info.atomic_rmw_operation,
                                .is_volatile = extra.info.access_kind == .@"volatile",
                                .success_ordering = extra.info.success_ordering,
                                .sync_scope = extra.info.sync_scope,
                                .alignment = extra.info.alignment.toLlvm(),
                            });
                        },
                        .cmpxchg,
                        .@"cmpxchg weak",
                        => |kind| {
                            const extra = func.extraData(Function.Instruction.CmpXchg, data);

                            try function_block.writeAbbrev(FunctionBlock.CmpXchg{
                                .ptr = adapter.getOffsetValueIndex(extra.ptr),
                                .cmp = adapter.getOffsetValueIndex(extra.cmp),
                                .new = adapter.getOffsetValueIndex(extra.new),
                                .is_volatile = extra.info.access_kind == .@"volatile",
                                .success_ordering = extra.info.success_ordering,
                                .sync_scope = extra.info.sync_scope,
                                .failure_ordering = extra.info.failure_ordering,
                                .is_weak = kind == .@"cmpxchg weak",
                                .alignment = extra.info.alignment.toLlvm(),
                            });
                        },
                        .fence => {
                            const info: MemoryAccessInfo = @bitCast(data);
                            try function_block.writeAbbrev(FunctionBlock.Fence{
                                .ordering = info.success_ordering,
                                .sync_scope = info.sync_scope,
                            });
                        },
                    }

                    if (!func.strip) {
                        if (func.debug_locations.get(adapter.instruction_index)) |debug_location| {
                            switch (debug_location) {
                                .no_location => has_location = false,
                                .location => |location| {
                                    try function_block.writeAbbrevAdapted(FunctionBlock.DebugLoc{
                                        .line = location.line,
                                        .column = location.column,
                                        .scope = location.scope,
                                        .inlined_at = location.inlined_at,
                                    }, metadata_adapter);
                                    has_location = true;
                                },
                            }
                        } else if (has_location) {
                            try function_block.writeAbbrev(FunctionBlock.DebugLocAgain{});
                        }
                    }
                }

                // VALUE_SYMTAB
                if (!func.strip) {
                    const ValueSymtabBlock = ir.ModuleBlock.FunctionBlock.ValueSymtabBlock;

                    var value_symtab_block = try function_block.enterSubBlock(ValueSymtabBlock, false);

                    for (func.blocks, 0..) |block, block_index| {
                        const name = block.instruction.name(&func);

                        if (name == .none or name == .empty) continue;

                        try value_symtab_block.writeAbbrev(ValueSymtabBlock.BlockEntry{
                            .value_id = @intCast(block_index),
                            .string = name.slice(self).?,
                        });
                    }

                    // TODO: 若构造器开始为非块对象分配名称,则生成非块条目

                    try value_symtab_block.end();
                }

                // METADATA_ATTACHMENT_BLOCK
                {
                    const MetadataAttachmentBlock = ir.ModuleBlock.FunctionBlock.MetadataAttachmentBlock;
                    var metadata_attach_block = try function_block.enterSubBlock(MetadataAttachmentBlock, false);

                    if (func.global.ptrConst(self).dbg.unwrap()) |dbg| {
                        try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentGlobalSingle{
                            .kind = .dbg,
                            .metadata = dbg,
                        }, metadata_adapter);
                    }

                    var instr_index: u32 = 0;
                    for (func.instructions.items(.tag), func.instructions.items(.data)) |instr_tag, data| switch (instr_tag) {
                        .arg, .block => {}, // 不是实际指令
                        else => {
                            instr_index += 1;
                        },
                        .br_cond, .@"switch" => {
                            const weights = switch (instr_tag) {
                                .br_cond => func.extraData(Function.Instruction.BrCond, data).weights,
                                .@"switch" => func.extraData(Function.Instruction.Switch, data).weights,
                                else => unreachable,
                            };
                            switch (weights) {
                                .none => {},
                                .unpredictable => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{
                                    .inst = instr_index,
                                    .kind = .unpredictable,
                                    .metadata = .empty_tuple,
                                }, metadata_adapter),
                                _ => try metadata_attach_block.writeAbbrevAdapted(MetadataAttachmentBlock.AttachmentInstructionSingle{
                                    .inst = instr_index,
                                    .kind = .prof,
                                    .metadata = weights.toMetadata(),
                                }, metadata_adapter),
                            }
                            instr_index += 1;
                        },
                    };

                    try metadata_attach_block.end();
                }

                try function_block.end();
            }
        }

        try module_block.end();
    }

    // STRTAB_BLOCK
    {
        const Strtab = ir.StrtabBlock;
        var strtab_block = try bitcode.enterTopBlock(Strtab);

        try strtab_block.writeAbbrev(Strtab.Blob{ .blob = self.strtab_string_bytes.items });

        try strtab_block.end();
    }

    return bitcode.toOwnedSlice();
}

const FormatFlags = struct {
    comma: bool = false,
    space: bool = false,
    percent: bool = false,

    fn onlyPercent(f: FormatFlags) bool {
        return !f.comma and !f.space and f.percent;
    }
};