aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler/llvm.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2019-11-27 00:23:03 +0100
committerRon Evans <[email protected]>2019-12-04 22:19:49 +0100
commit374349cfa5cca4796b037c3d8c08614aaaf0ded6 (patch)
treeb1dab8bdf9057c2ab4726e6079d099ae22326c67 /compiler/llvm.go
parent024a0827eade975f82128d8a03216f3c1e7cff66 (diff)
downloadtinygo-374349cfa5cca4796b037c3d8c08614aaaf0ded6.tar.gz
tinygo-374349cfa5cca4796b037c3d8c08614aaaf0ded6.zip
compiler: refactor func lowering to the transform package
This commit makes a number of changes: * It avoids a dependency on Compiler.emitStartGoroutine. * It moves the func-lowering pass to the transform package. * It adds testing to func lowering. No functionality should have changed with this commit.
Diffstat (limited to 'compiler/llvm.go')
-rw-r--r--compiler/llvm.go72
1 files changed, 0 insertions, 72 deletions
diff --git a/compiler/llvm.go b/compiler/llvm.go
index 078956657..53d52bbae 100644
--- a/compiler/llvm.go
+++ b/compiler/llvm.go
@@ -52,78 +52,6 @@ func (c *Compiler) emitPointerUnpack(ptr llvm.Value, valueTypes []llvm.Type) []l
return llvmutil.EmitPointerUnpack(c.builder, c.mod, ptr, valueTypes)
}
-// splitBasicBlock splits a LLVM basic block into two parts. All instructions
-// after afterInst are moved into a new basic block (created right after the
-// current one) with the given name.
-func (c *Compiler) splitBasicBlock(afterInst llvm.Value, insertAfter llvm.BasicBlock, name string) llvm.BasicBlock {
- oldBlock := afterInst.InstructionParent()
- newBlock := c.ctx.InsertBasicBlock(insertAfter, name)
- var nextInstructions []llvm.Value // values to move
-
- // Collect to-be-moved instructions.
- inst := afterInst
- for {
- inst = llvm.NextInstruction(inst)
- if inst.IsNil() {
- break
- }
- nextInstructions = append(nextInstructions, inst)
- }
-
- // Move instructions.
- c.builder.SetInsertPointAtEnd(newBlock)
- for _, inst := range nextInstructions {
- inst.RemoveFromParentAsInstruction()
- c.builder.Insert(inst)
- }
-
- // Find PHI nodes to update.
- var phiNodes []llvm.Value // PHI nodes to update
- for bb := insertAfter.Parent().FirstBasicBlock(); !bb.IsNil(); bb = llvm.NextBasicBlock(bb) {
- for inst := bb.FirstInstruction(); !inst.IsNil(); inst = llvm.NextInstruction(inst) {
- if inst.IsAPHINode().IsNil() {
- continue
- }
- needsUpdate := false
- incomingCount := inst.IncomingCount()
- for i := 0; i < incomingCount; i++ {
- if inst.IncomingBlock(i) == oldBlock {
- needsUpdate = true
- break
- }
- }
- if !needsUpdate {
- // PHI node has no incoming edge from the old block.
- continue
- }
- phiNodes = append(phiNodes, inst)
- }
- }
-
- // Update PHI nodes.
- for _, phi := range phiNodes {
- c.builder.SetInsertPointBefore(phi)
- newPhi := c.builder.CreatePHI(phi.Type(), "")
- incomingCount := phi.IncomingCount()
- incomingVals := make([]llvm.Value, incomingCount)
- incomingBlocks := make([]llvm.BasicBlock, incomingCount)
- for i := 0; i < incomingCount; i++ {
- value := phi.IncomingValue(i)
- block := phi.IncomingBlock(i)
- if block == oldBlock {
- block = newBlock
- }
- incomingVals[i] = value
- incomingBlocks[i] = block
- }
- newPhi.AddIncoming(incomingVals, incomingBlocks)
- phi.ReplaceAllUsesWith(newPhi)
- phi.EraseFromParentAsInstruction()
- }
-
- return newBlock
-}
-
// makeGlobalArray creates a new LLVM global with the given name and integers as
// contents, and returns the global.
// Note that it is left with the default linkage etc., you should set