pub struct Function {
pub name: String,
pub ty: TypeId,
pub args: Vec<Argument>,
pub blocks: Vec<BasicBlock>,
pub instructions: Vec<Instruction>,
pub instr_dbg_locs: HashMap<InstrId, u32>,
pub instr_metadata: HashMap<InstrId, Vec<(String, String)>>,
pub value_names: HashMap<String, InstrId>,
pub arg_names: HashMap<String, ArgId>,
pub is_declaration: bool,
pub linkage: Linkage,
/* private fields */
}Expand description
A function definition or declaration.
Fields§
§name: StringPublic API for name.
ty: TypeIdFunction type (FunctionType TypeId).
args: Vec<Argument>Formal arguments.
blocks: Vec<BasicBlock>Basic blocks in program order.
instructions: Vec<Instruction>Flat instruction pool; InstrId(i) indexes instructions[i].
instr_dbg_locs: HashMap<InstrId, u32>Optional !dbg !N attachment for each instruction id.
instr_metadata: HashMap<InstrId, Vec<(String, String)>>Arbitrary metadata attachments per instruction, e.g. !dbg !12, !tbaa !7.
value_names: HashMap<String, InstrId>Maps result name → InstrId.
arg_names: HashMap<String, ArgId>Maps argument name → ArgId.
is_declaration: boolTrue if this is a declaration (no body).
linkage: LinkagePublic API for linkage.
Implementations§
Source§impl Function
impl Function
Sourcepub fn new(
name: impl Into<String>,
ty: TypeId,
args: Vec<Argument>,
linkage: Linkage,
) -> Self
pub fn new( name: impl Into<String>, ty: TypeId, args: Vec<Argument>, linkage: Linkage, ) -> Self
Public API for new.
Sourcepub fn new_declaration(
name: impl Into<String>,
ty: TypeId,
args: Vec<Argument>,
linkage: Linkage,
) -> Self
pub fn new_declaration( name: impl Into<String>, ty: TypeId, args: Vec<Argument>, linkage: Linkage, ) -> Self
Public API for new_declaration.
Sourcepub fn add_block(&mut self, bb: BasicBlock) -> BlockId
pub fn add_block(&mut self, bb: BasicBlock) -> BlockId
Add a new basic block and return its BlockId.
Sourcepub fn block(&self, id: BlockId) -> &BasicBlock
pub fn block(&self, id: BlockId) -> &BasicBlock
Public API for block.
Sourcepub fn block_mut(&mut self, id: BlockId) -> &mut BasicBlock
pub fn block_mut(&mut self, id: BlockId) -> &mut BasicBlock
Public API for block_mut.
Sourcepub fn num_blocks(&self) -> usize
pub fn num_blocks(&self) -> usize
Public API for num_blocks.
Sourcepub fn alloc_instr(&mut self, instr: Instruction) -> InstrId
pub fn alloc_instr(&mut self, instr: Instruction) -> InstrId
Allocate an instruction in the flat pool, register its name if any,
and return the InstrId.
Sourcepub fn instr(&self, id: InstrId) -> &Instruction
pub fn instr(&self, id: InstrId) -> &Instruction
Public API for instr.
Sourcepub fn instr_mut(&mut self, id: InstrId) -> &mut Instruction
pub fn instr_mut(&mut self, id: InstrId) -> &mut Instruction
Public API for instr_mut.
Sourcepub fn num_instrs(&self) -> usize
pub fn num_instrs(&self) -> usize
Public API for num_instrs.
Sourcepub fn set_instr_dbg_loc(&mut self, id: InstrId, loc_id: u32)
pub fn set_instr_dbg_loc(&mut self, id: InstrId, loc_id: u32)
Public API for set_instr_dbg_loc.
Sourcepub fn instr_dbg_loc(&self, id: InstrId) -> Option<u32>
pub fn instr_dbg_loc(&self, id: InstrId) -> Option<u32>
Public API for instr_dbg_loc.
Sourcepub fn add_instr_metadata(
&mut self,
id: InstrId,
key: impl Into<String>,
value: impl Into<String>,
)
pub fn add_instr_metadata( &mut self, id: InstrId, key: impl Into<String>, value: impl Into<String>, )
Public API for add_instr_metadata.
Sourcepub fn instr_metadata(&self, id: InstrId) -> Option<&[(String, String)]>
pub fn instr_metadata(&self, id: InstrId) -> Option<&[(String, String)]>
Public API for instr_metadata.
Sourcepub fn lookup_value(&self, name: &str) -> Option<ValueRef>
pub fn lookup_value(&self, name: &str) -> Option<ValueRef>
Public API for lookup_value.
Sourcepub fn lookup_block(&self, name: &str) -> Option<BlockId>
pub fn lookup_block(&self, name: &str) -> Option<BlockId>
Public API for lookup_block.
Sourcepub fn type_of_value(&self, vref: ValueRef) -> Option<TypeId>
pub fn type_of_value(&self, vref: ValueRef) -> Option<TypeId>
Public API for type_of_value.
Sourcepub fn fresh_name(&mut self) -> String
pub fn fresh_name(&mut self) -> String
Produce a unique name like "1", "2", … for unnamed SSA values.