Skip to content

Commit a61524d

Browse files
committed
cmd/internal/obj: add Prog.SetFrom3{Reg,Const}
These are the the most common uses, and they reduce line noise. I don't love adding new deprecated APIs, but since they're trivial wrappers, it'll be very easy to update them along with the rest. No functional changes; passes toolstash-check. Change-Id: I691a8175cfef9081180e463c63f326376af3f3a6 Reviewed-on: https://go-review.googlesource.com/c/go/+/296009 Trust: Josh Bleecher Snyder <[email protected]> Run-TryBot: Josh Bleecher Snyder <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 5f15af1 commit a61524d

File tree

8 files changed

+41
-30
lines changed

8 files changed

+41
-30
lines changed

src/cmd/asm/internal/asm/asm.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,7 @@ func (p *Parser) asmInstruction(op obj.As, cond string, a []obj.Addr) {
811811
} else {
812812
mask = (^uint32(0) >> uint(mask2+1)) & (^uint32(0) << uint(31-(mask1-1)))
813813
}
814-
prog.SetFrom3(obj.Addr{
815-
Type: obj.TYPE_CONST,
816-
Offset: int64(mask),
817-
})
814+
prog.SetFrom3Const(int64(mask))
818815
prog.To = a[4]
819816
break
820817
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
201201
p := s.Prog(v.Op.Asm())
202202
p.From = obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[2].Reg()}
203203
p.To = obj.Addr{Type: obj.TYPE_REG, Reg: v.Reg()}
204-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[1].Reg()})
204+
p.SetFrom3Reg(v.Args[1].Reg())
205205
case ssa.OpAMD64ADDQ, ssa.OpAMD64ADDL:
206206
r := v.Reg()
207207
r1 := v.Args[0].Reg()
@@ -588,7 +588,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
588588
p.From.Offset = v.AuxInt
589589
p.To.Type = obj.TYPE_REG
590590
p.To.Reg = r
591-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[0].Reg()})
591+
p.SetFrom3Reg(v.Args[0].Reg())
592592

593593
case ssa.OpAMD64SUBQconst, ssa.OpAMD64SUBLconst,
594594
ssa.OpAMD64ANDQconst, ssa.OpAMD64ANDLconst,
@@ -1073,7 +1073,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
10731073
}
10741074
p.From.Offset = val
10751075
p.From.Type = obj.TYPE_CONST
1076-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[0].Reg()})
1076+
p.SetFrom3Reg(v.Args[0].Reg())
10771077
p.To.Type = obj.TYPE_REG
10781078
p.To.Reg = v.Reg()
10791079
case ssa.OpAMD64POPCNTQ, ssa.OpAMD64POPCNTL:

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
279279
p := s.Prog(v.Op.Asm())
280280
p.From.Type = obj.TYPE_CONST
281281
p.From.Offset = v.AuxInt >> 8
282-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: v.AuxInt & 0xff})
282+
p.SetFrom3Const(v.AuxInt & 0xff)
283283
p.Reg = v.Args[0].Reg()
284284
p.To.Type = obj.TYPE_REG
285285
p.To.Reg = v.Reg()
@@ -299,7 +299,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
299299
p := s.Prog(arm.ABFC)
300300
p.From.Type = obj.TYPE_CONST
301301
p.From.Offset = int64(width)
302-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: int64(lsb)})
302+
p.SetFrom3Const(int64(lsb))
303303
p.To.Type = obj.TYPE_REG
304304
p.To.Reg = v.Reg()
305305
break

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
229229
p.Reg = ra
230230
p.From.Type = obj.TYPE_REG
231231
p.From.Reg = rm
232-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: rn})
232+
p.SetFrom3Reg(rn)
233233
p.To.Type = obj.TYPE_REG
234234
p.To.Reg = rt
235235
case ssa.OpARM64ADDconst,
@@ -292,7 +292,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
292292
p := s.Prog(v.Op.Asm())
293293
p.From.Type = obj.TYPE_CONST
294294
p.From.Offset = v.AuxInt
295-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[0].Reg()})
295+
p.SetFrom3Reg(v.Args[0].Reg())
296296
p.Reg = v.Args[1].Reg()
297297
p.To.Type = obj.TYPE_REG
298298
p.To.Reg = v.Reg()
@@ -522,7 +522,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
522522
p := s.Prog(v.Op.Asm())
523523
p.From.Type = obj.TYPE_CONST
524524
p.From.Offset = v.AuxInt >> 8
525-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: v.AuxInt & 0xff})
525+
p.SetFrom3Const(v.AuxInt & 0xff)
526526
p.Reg = v.Args[1].Reg()
527527
p.To.Type = obj.TYPE_REG
528528
p.To.Reg = v.Reg()
@@ -533,7 +533,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
533533
p := s.Prog(v.Op.Asm())
534534
p.From.Type = obj.TYPE_CONST
535535
p.From.Offset = v.AuxInt >> 8
536-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: v.AuxInt & 0xff})
536+
p.SetFrom3Const(v.AuxInt & 0xff)
537537
p.Reg = v.Args[0].Reg()
538538
p.To.Type = obj.TYPE_REG
539539
p.To.Reg = v.Reg()
@@ -952,7 +952,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
952952
p.From.Type = obj.TYPE_REG // assembler encodes conditional bits in Reg
953953
p.From.Reg = condBits[ssa.Op(v.AuxInt)]
954954
p.Reg = v.Args[0].Reg()
955-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: r1})
955+
p.SetFrom3Reg(r1)
956956
p.To.Type = obj.TYPE_REG
957957
p.To.Reg = v.Reg()
958958
case ssa.OpARM64DUFFZERO:

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

+11-11
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
419419
// If it is a Compare-and-Swap-Release operation, set the EH field with
420420
// the release hint.
421421
if v.AuxInt == 0 {
422-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: 0})
422+
p.SetFrom3Const(0)
423423
}
424424
// CMP reg1,reg2
425425
p1 := s.Prog(cmp)
@@ -586,7 +586,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
586586
p := s.Prog(v.Op.Asm())
587587
// clrlslwi ra,rs,mb,sh will become rlwinm ra,rs,sh,mb-sh,31-sh as described in ISA
588588
p.From = obj.Addr{Type: obj.TYPE_CONST, Offset: ssa.GetPPC64Shiftmb(shifts)}
589-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: ssa.GetPPC64Shiftsh(shifts)})
589+
p.SetFrom3Const(ssa.GetPPC64Shiftsh(shifts))
590590
p.Reg = r1
591591
p.To.Type = obj.TYPE_REG
592592
p.To.Reg = r
@@ -598,7 +598,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
598598
p := s.Prog(v.Op.Asm())
599599
// clrlsldi ra,rs,mb,sh will become rldic ra,rs,sh,mb-sh
600600
p.From = obj.Addr{Type: obj.TYPE_CONST, Offset: ssa.GetPPC64Shiftmb(shifts)}
601-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: ssa.GetPPC64Shiftsh(shifts)})
601+
p.SetFrom3Const(ssa.GetPPC64Shiftsh(shifts))
602602
p.Reg = r1
603603
p.To.Type = obj.TYPE_REG
604604
p.To.Reg = r
@@ -610,7 +610,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
610610
shifts := v.AuxInt
611611
p := s.Prog(v.Op.Asm())
612612
p.From = obj.Addr{Type: obj.TYPE_CONST, Offset: ssa.GetPPC64Shiftsh(shifts)}
613-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: ssa.GetPPC64Shiftmb(shifts)})
613+
p.SetFrom3Const(ssa.GetPPC64Shiftmb(shifts))
614614
p.Reg = r1
615615
p.To.Type = obj.TYPE_REG
616616
p.To.Reg = r
@@ -658,7 +658,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
658658
p.To = obj.Addr{Type: obj.TYPE_REG, Reg: v.Reg()}
659659
p.Reg = v.Args[0].Reg()
660660
p.From = obj.Addr{Type: obj.TYPE_CONST, Offset: int64(rot)}
661-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: int64(mask)})
661+
p.SetFrom3Const(int64(mask))
662662

663663
// Auxint holds mask
664664
case ssa.OpPPC64RLWNM:
@@ -667,7 +667,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
667667
p.To = obj.Addr{Type: obj.TYPE_REG, Reg: v.Reg()}
668668
p.Reg = v.Args[0].Reg()
669669
p.From = obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[1].Reg()}
670-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: int64(mask)})
670+
p.SetFrom3Const(int64(mask))
671671

672672
case ssa.OpPPC64MADDLD:
673673
r := v.Reg()
@@ -679,7 +679,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
679679
p.From.Type = obj.TYPE_REG
680680
p.From.Reg = r1
681681
p.Reg = r2
682-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: r3})
682+
p.SetFrom3Reg(r3)
683683
p.To.Type = obj.TYPE_REG
684684
p.To.Reg = r
685685

@@ -693,7 +693,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
693693
p.From.Type = obj.TYPE_REG
694694
p.From.Reg = r1
695695
p.Reg = r3
696-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: r2})
696+
p.SetFrom3Reg(r2)
697697
p.To.Type = obj.TYPE_REG
698698
p.To.Reg = r
699699

@@ -720,7 +720,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
720720

721721
case ssa.OpPPC64SUBFCconst:
722722
p := s.Prog(v.Op.Asm())
723-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: v.AuxInt})
723+
p.SetFrom3Const(v.AuxInt)
724724
p.From.Type = obj.TYPE_REG
725725
p.From.Reg = v.Args[0].Reg()
726726
p.To.Type = obj.TYPE_REG
@@ -910,7 +910,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
910910
// AuxInt values 4,5,6 implemented with reverse operand order from 0,1,2
911911
if v.AuxInt > 3 {
912912
p.Reg = r.Reg
913-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[0].Reg()})
913+
p.SetFrom3Reg(v.Args[0].Reg())
914914
} else {
915915
p.Reg = v.Args[0].Reg()
916916
p.SetFrom3(r)
@@ -1784,7 +1784,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
17841784
pp.To.Reg = ppc64.REG_LR
17851785

17861786
// Insert a hint this is not a subroutine return.
1787-
pp.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: 1})
1787+
pp.SetFrom3Const(1)
17881788

17891789
if base.Ctxt.Flag_shared {
17901790
// When compiling Go into PIC, the function we just

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
894894
p.From.Type = obj.TYPE_CONST
895895
p.From.Offset = int64(s390x.NotEqual & s390x.NotUnordered) // unordered is not possible
896896
p.Reg = s390x.REG_R3
897-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: 0})
897+
p.SetFrom3Const(0)
898898
if b.Succs[0].Block() != next {
899899
s.Br(s390x.ABR, b.Succs[0].Block())
900900
}
@@ -937,17 +937,17 @@ func ssaGenBlock(s *ssagen.State, b, next *ssa.Block) {
937937
p.From.Type = obj.TYPE_CONST
938938
p.From.Offset = int64(mask & s390x.NotUnordered) // unordered is not possible
939939
p.Reg = b.Controls[0].Reg()
940-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: b.Controls[1].Reg()})
940+
p.SetFrom3Reg(b.Controls[1].Reg())
941941
case ssa.BlockS390XCGIJ, ssa.BlockS390XCIJ:
942942
p.From.Type = obj.TYPE_CONST
943943
p.From.Offset = int64(mask & s390x.NotUnordered) // unordered is not possible
944944
p.Reg = b.Controls[0].Reg()
945-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: int64(int8(b.AuxInt))})
945+
p.SetFrom3Const(int64(int8(b.AuxInt)))
946946
case ssa.BlockS390XCLGIJ, ssa.BlockS390XCLIJ:
947947
p.From.Type = obj.TYPE_CONST
948948
p.From.Offset = int64(mask & s390x.NotUnordered) // unordered is not possible
949949
p.Reg = b.Controls[0].Reg()
950-
p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: int64(uint8(b.AuxInt))})
950+
p.SetFrom3Const(int64(uint8(b.AuxInt)))
951951
default:
952952
b.Fatalf("branch not implemented: %s", b.LongString())
953953
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
342342
p.From.Offset = v.AuxInt
343343
p.To.Type = obj.TYPE_REG
344344
p.To.Reg = r
345-
p.SetFrom3(obj.Addr{Type: obj.TYPE_REG, Reg: v.Args[0].Reg()})
345+
p.SetFrom3Reg(v.Args[0].Reg())
346346

347347
case ssa.Op386SUBLconst,
348348
ssa.Op386ADCLconst,

src/cmd/internal/obj/link.go

+14
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,20 @@ func (p *Prog) SetFrom3(a Addr) {
360360
p.RestArgs = []AddrPos{{a, Source}}
361361
}
362362

363+
// SetFrom3Reg calls p.SetFrom3 with a register Addr containing reg.
364+
//
365+
// Deprecated: for the same reasons as Prog.GetFrom3.
366+
func (p *Prog) SetFrom3Reg(reg int16) {
367+
p.SetFrom3(Addr{Type: TYPE_REG, Reg: reg})
368+
}
369+
370+
// SetFrom3Const calls p.SetFrom3 with a const Addr containing x.
371+
//
372+
// Deprecated: for the same reasons as Prog.GetFrom3.
373+
func (p *Prog) SetFrom3Const(off int64) {
374+
p.SetFrom3(Addr{Type: TYPE_CONST, Offset: off})
375+
}
376+
363377
// SetTo2 assigns []Args{{a, 1}} to p.RestArgs when the second destination
364378
// operand does not fit into prog.RegTo2.
365379
func (p *Prog) SetTo2(a Addr) {

0 commit comments

Comments
 (0)