ssagen.Compile
Build SSA for the ir.Func (buildssa)
- Check
ssaDumpand set the dump flag. - Initialize
ssagen.state. - Push the line number or the parent’s line number (if it’s missing) to the stack.
- Set up
ssagen.stateflags fromir.Funcinformation. - Set up an empty
ssagen.ssafnwithir.Funcand ABI information. - Allocate the starting block for the current
ssa.Func. - Check open-coded defers. <- What’s this?
- Do
ABIAnalyze, get theabi.ABIParamResultInfoof function in/out parameters. - Generate the addresses of the local variables saved in
ir.Func.Dcl. - Generate the
AuxCallfor the current function. - Generate the addresses of the input parameters saved in
ir.Func.Dcl. - Generate the addresses of the closure variables saved in
ir.Func.Dcl. - Covert to SSA IR. I don’t have any experience with SSA, so it’s really difficult to understand this part of the code.
- Insert Phi values. <- What’s this?
- Call
ssa.Compile. It defines an array ofssa.pass, and run each of them against thessa.Func.
Generate SSA (genssa)
This step returns a objw.Progs to save the machine-level instructions of the function. objw saves platform-independent structures of the binary.
- Scan all blocks and generate the code, then call functions of
ArchInfoto generate the end of the block. - Check inline marks and mark the functions as inline.
- Resolve branches and jump table.
Assemble to machine code (pp.Flush)
What’s Next
- Read <<Compilers: Principles, Techniques, and Tools>>
- BuildID
- ABI architecture.
typessystem.irandssastructures.- escape analysis.
objwstructures.