github.com/q45/go@v0.0.0-20151101211701-a4fb8c13db3f/src/cmd/compile/internal/arm64/prog.go (about)

     1  // Copyright 2014 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 arm64
     6  
     7  import (
     8  	"cmd/compile/internal/gc"
     9  	"cmd/internal/obj"
    10  	"cmd/internal/obj/arm64"
    11  )
    12  
    13  const (
    14  	LeftRdwr  uint32 = gc.LeftRead | gc.LeftWrite
    15  	RightRdwr uint32 = gc.RightRead | gc.RightWrite
    16  )
    17  
    18  // This table gives the basic information about instruction
    19  // generated by the compiler and processed in the optimizer.
    20  // See opt.h for bit definitions.
    21  //
    22  // Instructions not generated need not be listed.
    23  // As an exception to that rule, we typically write down all the
    24  // size variants of an operation even if we just use a subset.
    25  //
    26  // The table is formatted for 8-space tabs.
    27  var progtable = [arm64.ALAST]obj.ProgInfo{
    28  	obj.ATYPE:     {Flags: gc.Pseudo | gc.Skip},
    29  	obj.ATEXT:     {Flags: gc.Pseudo},
    30  	obj.AFUNCDATA: {Flags: gc.Pseudo},
    31  	obj.APCDATA:   {Flags: gc.Pseudo},
    32  	obj.AUNDEF:    {Flags: gc.Break},
    33  	obj.AUSEFIELD: {Flags: gc.OK},
    34  	obj.ACHECKNIL: {Flags: gc.LeftRead},
    35  	obj.AVARDEF:   {Flags: gc.Pseudo | gc.RightWrite},
    36  	obj.AVARKILL:  {Flags: gc.Pseudo | gc.RightWrite},
    37  
    38  	// NOP is an internal no-op that also stands
    39  	// for USED and SET annotations, not the Power opcode.
    40  	obj.ANOP:    {Flags: gc.LeftRead | gc.RightWrite},
    41  	arm64.AHINT: {Flags: gc.OK},
    42  
    43  	// Integer
    44  	arm64.AADD:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    45  	arm64.ASUB:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    46  	arm64.ANEG:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    47  	arm64.AAND:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    48  	arm64.AORR:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    49  	arm64.AEOR:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    50  	arm64.AMUL:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    51  	arm64.ASMULL: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    52  	arm64.AUMULL: {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    53  	arm64.ASMULH: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite},
    54  	arm64.AUMULH: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite},
    55  	arm64.ASDIV:  {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    56  	arm64.AUDIV:  {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    57  	arm64.ALSL:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    58  	arm64.ALSR:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    59  	arm64.AASR:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead | gc.RightWrite},
    60  	arm64.ACMP:   {Flags: gc.SizeQ | gc.LeftRead | gc.RegRead},
    61  
    62  	// Floating point.
    63  	arm64.AFADDD:  {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite},
    64  	arm64.AFADDS:  {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite},
    65  	arm64.AFSUBD:  {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite},
    66  	arm64.AFSUBS:  {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite},
    67  	arm64.AFNEGD:  {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite},
    68  	arm64.AFNEGS:  {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite},
    69  	arm64.AFSQRTD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite},
    70  	arm64.AFMULD:  {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite},
    71  	arm64.AFMULS:  {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite},
    72  	arm64.AFDIVD:  {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite},
    73  	arm64.AFDIVS:  {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite},
    74  	arm64.AFCMPD:  {Flags: gc.SizeD | gc.LeftRead | gc.RegRead},
    75  	arm64.AFCMPS:  {Flags: gc.SizeF | gc.LeftRead | gc.RegRead},
    76  
    77  	// float -> integer
    78  	arm64.AFCVTZSD:  {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
    79  	arm64.AFCVTZSS:  {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv},
    80  	arm64.AFCVTZSDW: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
    81  	arm64.AFCVTZSSW: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv},
    82  	arm64.AFCVTZUD:  {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
    83  	arm64.AFCVTZUS:  {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv},
    84  	arm64.AFCVTZUDW: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
    85  	arm64.AFCVTZUSW: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv},
    86  
    87  	// float -> float
    88  	arm64.AFCVTSD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
    89  	arm64.AFCVTDS: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv},
    90  
    91  	// integer -> float
    92  	arm64.ASCVTFD:  {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv},
    93  	arm64.ASCVTFS:  {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv},
    94  	arm64.ASCVTFWD: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv},
    95  	arm64.ASCVTFWS: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv},
    96  	arm64.AUCVTFD:  {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv},
    97  	arm64.AUCVTFS:  {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Conv},
    98  	arm64.AUCVTFWD: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv},
    99  	arm64.AUCVTFWS: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv},
   100  
   101  	// Moves
   102  	arm64.AMOVB:  {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   103  	arm64.AMOVBU: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   104  	arm64.AMOVH:  {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   105  	arm64.AMOVHU: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   106  	arm64.AMOVW:  {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   107  	arm64.AMOVWU: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   108  	arm64.AMOVD:  {Flags: gc.SizeQ | gc.LeftRead | gc.RightWrite | gc.Move},
   109  	arm64.AFMOVS: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv},
   110  	arm64.AFMOVD: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Move},
   111  
   112  	// Jumps
   113  	arm64.AB:      {Flags: gc.Jump | gc.Break},
   114  	arm64.ABL:     {Flags: gc.Call},
   115  	arm64.ABEQ:    {Flags: gc.Cjmp},
   116  	arm64.ABNE:    {Flags: gc.Cjmp},
   117  	arm64.ABGE:    {Flags: gc.Cjmp},
   118  	arm64.ABLT:    {Flags: gc.Cjmp},
   119  	arm64.ABGT:    {Flags: gc.Cjmp},
   120  	arm64.ABLE:    {Flags: gc.Cjmp},
   121  	arm64.ABLO:    {Flags: gc.Cjmp},
   122  	arm64.ABLS:    {Flags: gc.Cjmp},
   123  	arm64.ABHI:    {Flags: gc.Cjmp},
   124  	arm64.ABHS:    {Flags: gc.Cjmp},
   125  	arm64.ACBZ:    {Flags: gc.Cjmp},
   126  	arm64.ACBNZ:   {Flags: gc.Cjmp},
   127  	obj.ARET:      {Flags: gc.Break},
   128  	obj.ADUFFZERO: {Flags: gc.Call},
   129  	obj.ADUFFCOPY: {Flags: gc.Call},
   130  }
   131  
   132  func proginfo(p *obj.Prog) {
   133  	info := &p.Info
   134  	*info = progtable[p.As]
   135  	if info.Flags == 0 {
   136  		gc.Fatalf("proginfo: unknown instruction %v", p)
   137  	}
   138  
   139  	if (info.Flags&gc.RegRead != 0) && p.Reg == 0 {
   140  		info.Flags &^= gc.RegRead
   141  		info.Flags |= gc.RightRead /*CanRegRead |*/
   142  	}
   143  
   144  	if (p.From.Type == obj.TYPE_MEM || p.From.Type == obj.TYPE_ADDR) && p.From.Reg != 0 {
   145  		info.Regindex |= RtoB(int(p.From.Reg))
   146  		if p.Scond != 0 {
   147  			info.Regset |= RtoB(int(p.From.Reg))
   148  		}
   149  	}
   150  
   151  	if (p.To.Type == obj.TYPE_MEM || p.To.Type == obj.TYPE_ADDR) && p.To.Reg != 0 {
   152  		info.Regindex |= RtoB(int(p.To.Reg))
   153  		if p.Scond != 0 {
   154  			info.Regset |= RtoB(int(p.To.Reg))
   155  		}
   156  	}
   157  
   158  	if p.From.Type == obj.TYPE_ADDR && p.From.Sym != nil && (info.Flags&gc.LeftRead != 0) {
   159  		info.Flags &^= gc.LeftRead
   160  		info.Flags |= gc.LeftAddr
   161  	}
   162  
   163  	if p.As == obj.ADUFFZERO {
   164  		info.Reguse |= RtoB(arm64.REGRT1)
   165  		info.Regset |= RtoB(arm64.REGRT1)
   166  	}
   167  
   168  	if p.As == obj.ADUFFCOPY {
   169  		// TODO(austin) Revisit when duffcopy is implemented
   170  		info.Reguse |= RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2) | RtoB(arm64.REG_R5)
   171  
   172  		info.Regset |= RtoB(arm64.REGRT1) | RtoB(arm64.REGRT2)
   173  	}
   174  }