diff options
Diffstat (limited to 'compiler/llvm.go')
-rw-r--r-- | compiler/llvm.go | 72 |
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 |