Source file src/cmd/compile/internal/ssacompile/lower.go

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package ssacompile
     6  
     7  import (
     8  	"cmd/compile/internal/ssa"
     9  	"cmd/compile/internal/ssa/ssaop"
    10  )
    11  
    12  // convert to machine-dependent ops.
    13  func lower(f *ssa.Func) {
    14  	// repeat rewrites until we find no more rewrites
    15  	applyRewrite(f, f.Config.LowerBlock, f.Config.LowerValue, ssa.RemoveDeadValues)
    16  }
    17  
    18  // lateLower applies those rules that need to be run after the general lower rules.
    19  func lateLower(f *ssa.Func) {
    20  	// repeat rewrites until we find no more rewrites
    21  	if f.Config.LateLowerValue != nil {
    22  		applyRewrite(f, f.Config.LateLowerBlock, f.Config.LateLowerValue, ssa.RemoveDeadValues)
    23  	}
    24  }
    25  
    26  // checkLower checks for unlowered opcodes and fails if we find one.
    27  func checkLower(f *ssa.Func) {
    28  	// Needs to be a separate phase because it must run after both
    29  	// lowering and a subsequent dead code elimination (because lowering
    30  	// rules may leave dead generic ops behind).
    31  	for _, b := range f.Blocks {
    32  		for _, v := range b.Values {
    33  			if !ssaop.OpcodeTable[v.Op].Generic {
    34  				continue // lowered
    35  			}
    36  			switch v.Op {
    37  			case ssaop.OpSP, ssaop.OpSPanchored, ssaop.OpSB, ssaop.OpInitMem, ssaop.OpArg, ssaop.OpArgIntReg, ssaop.OpArgFloatReg, ssaop.OpPhi, ssaop.OpVarDef, ssaop.OpVarLive, ssaop.OpKeepAlive, ssaop.OpSelect0, ssaop.OpSelect1, ssaop.OpSelectN, ssaop.OpConvert, ssaop.OpInlMark, ssaop.OpWBend:
    38  				continue // ok not to lower
    39  			case ssaop.OpMakeResult:
    40  				if b.Controls[0] == v {
    41  					continue
    42  				}
    43  			case ssaop.OpGetG:
    44  				if f.Config.HasGReg {
    45  					// has hardware g register, regalloc takes care of it
    46  					continue // ok not to lower
    47  				}
    48  			}
    49  			s := "not lowered: " + v.String() + ", " + v.Op.String() + " " + v.Type.SimpleString()
    50  
    51  			for _, a := range v.Args {
    52  				s += " " + a.Type.SimpleString()
    53  			}
    54  			f.Fatalf("%s", s)
    55  		}
    56  	}
    57  }
    58  

View as plain text