Skip to content

Commit eb67eab

Browse files
committed
cmd/compile: late call expansion for rtcall
Change-Id: I0708c9d649d8a579857330b68d9fbcbbeced29e5 Reviewed-on: https://go-review.googlesource.com/c/go/+/248189 Trust: David Chase <[email protected]> Run-TryBot: David Chase <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent bb46b60 commit eb67eab

File tree

1 file changed

+38
-10
lines changed
  • src/cmd/compile/internal/gc

1 file changed

+38
-10
lines changed

src/cmd/compile/internal/gc/ssa.go

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4353,7 +4353,6 @@ func (s *state) openDeferExit() {
43534353
} else {
43544354
s.vars[&memVar] = call
43554355
}
4356-
43574356
// Make sure that the stack slots with pointers are kept live
43584357
// through the call (which is a pre-emption point). Also, we will
43594358
// use the first call of the last defer exit to compute liveness
@@ -5076,15 +5075,22 @@ func (s *state) rtcall(fn *obj.LSym, returns bool, results []*types.Type, args .
50765075
s.prevCall = nil
50775076
// Write args to the stack
50785077
off := Ctxt.FixedFrameSize()
5078+
testLateExpansion := ssa.LateCallExpansionEnabledWithin(s.f)
50795079
var ACArgs []ssa.Param
50805080
var ACResults []ssa.Param
5081+
var callArgs []*ssa.Value
5082+
50815083
for _, arg := range args {
50825084
t := arg.Type
50835085
off = Rnd(off, t.Alignment())
5084-
ptr := s.constOffPtrSP(t.PtrTo(), off)
50855086
size := t.Size()
50865087
ACArgs = append(ACArgs, ssa.Param{Type: t, Offset: int32(off)})
5087-
s.store(t, ptr, arg)
5088+
if testLateExpansion {
5089+
callArgs = append(callArgs, arg)
5090+
} else {
5091+
ptr := s.constOffPtrSP(t.PtrTo(), off)
5092+
s.store(t, ptr, arg)
5093+
}
50885094
off += size
50895095
}
50905096
off = Rnd(off, int64(Widthreg))
@@ -5098,8 +5104,17 @@ func (s *state) rtcall(fn *obj.LSym, returns bool, results []*types.Type, args .
50985104
}
50995105

51005106
// Issue call
5101-
call := s.newValue1A(ssa.OpStaticCall, types.TypeMem, ssa.StaticAuxCall(fn, ACArgs, ACResults), s.mem())
5102-
s.vars[&memVar] = call
5107+
var call *ssa.Value
5108+
aux := ssa.StaticAuxCall(fn, ACArgs, ACResults)
5109+
if testLateExpansion {
5110+
callArgs = append(callArgs, s.mem())
5111+
call = s.newValue0A(ssa.OpStaticLECall, aux.LateExpansionResultType(), aux)
5112+
call.AddArgs(callArgs...)
5113+
s.vars[&memVar] = s.newValue1I(ssa.OpSelectN, types.TypeMem, int64(len(ACResults)), call)
5114+
} else {
5115+
call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, aux, s.mem())
5116+
s.vars[&memVar] = call
5117+
}
51035118

51045119
if !returns {
51055120
// Finish block
@@ -5115,11 +5130,24 @@ func (s *state) rtcall(fn *obj.LSym, returns bool, results []*types.Type, args .
51155130

51165131
// Load results
51175132
res := make([]*ssa.Value, len(results))
5118-
for i, t := range results {
5119-
off = Rnd(off, t.Alignment())
5120-
ptr := s.constOffPtrSP(types.NewPtr(t), off)
5121-
res[i] = s.load(t, ptr)
5122-
off += t.Size()
5133+
if testLateExpansion {
5134+
for i, t := range results {
5135+
off = Rnd(off, t.Alignment())
5136+
if canSSAType(t) {
5137+
res[i] = s.newValue1I(ssa.OpSelectN, t, int64(i), call)
5138+
} else {
5139+
addr := s.newValue1I(ssa.OpSelectNAddr, types.NewPtr(t), int64(i), call)
5140+
res[i] = s.rawLoad(t, addr)
5141+
}
5142+
off += t.Size()
5143+
}
5144+
} else {
5145+
for i, t := range results {
5146+
off = Rnd(off, t.Alignment())
5147+
ptr := s.constOffPtrSP(types.NewPtr(t), off)
5148+
res[i] = s.load(t, ptr)
5149+
off += t.Size()
5150+
}
51235151
}
51245152
off = Rnd(off, int64(Widthptr))
51255153

0 commit comments

Comments
 (0)