|
| 1 | +// Copyright 2016 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 mips |
| 6 | + |
| 7 | +import ( |
| 8 | + "cmd/compile/internal/gc" |
| 9 | + "cmd/internal/obj" |
| 10 | + "cmd/internal/obj/mips" |
| 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 = [mips.ALAST & obj.AMask]gc.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.AVARDEF: {Flags: gc.Pseudo | gc.RightWrite}, |
| 35 | + obj.AVARKILL: {Flags: gc.Pseudo | gc.RightWrite}, |
| 36 | + obj.AVARLIVE: {Flags: gc.Pseudo | gc.LeftRead}, |
| 37 | + |
| 38 | + // NOP is an internal no-op that also stands |
| 39 | + // for USED and SET annotations, not the MIPS opcode. |
| 40 | + obj.ANOP: {Flags: gc.LeftRead | gc.RightWrite}, |
| 41 | + |
| 42 | + // Integer |
| 43 | + mips.AADD & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 44 | + mips.AADDU & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 45 | + mips.ASUB & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 46 | + mips.ASUBU & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 47 | + mips.AAND & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 48 | + mips.AOR & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 49 | + mips.AXOR & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 50 | + mips.ANOR & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 51 | + mips.AMUL & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead}, |
| 52 | + mips.AMULU & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead}, |
| 53 | + mips.ADIV & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead}, |
| 54 | + mips.ADIVU & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead}, |
| 55 | + mips.ASLL & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 56 | + mips.ASRA & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 57 | + mips.ASRL & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 58 | + mips.ASGT & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 59 | + mips.ASGTU & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 60 | + |
| 61 | + mips.ACLZ & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightRead}, |
| 62 | + mips.ACLO & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightRead}, |
| 63 | + |
| 64 | + // Floating point. |
| 65 | + mips.AADDF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 66 | + mips.AADDD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 67 | + mips.ASUBF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 68 | + mips.ASUBD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 69 | + mips.AMULF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 70 | + mips.AMULD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 71 | + mips.ADIVF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 72 | + mips.ADIVD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead | gc.RightWrite}, |
| 73 | + mips.AABSF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite}, |
| 74 | + mips.AABSD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, |
| 75 | + mips.ANEGF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite}, |
| 76 | + mips.ANEGD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, |
| 77 | + mips.ACMPEQF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead}, |
| 78 | + mips.ACMPEQD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead}, |
| 79 | + mips.ACMPGTF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead}, |
| 80 | + mips.ACMPGTD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead}, |
| 81 | + mips.ACMPGEF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RegRead}, |
| 82 | + mips.ACMPGED & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RegRead}, |
| 83 | + mips.AMOVFD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 84 | + mips.AMOVDF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 85 | + mips.AMOVFW & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 86 | + mips.AMOVWF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 87 | + mips.AMOVDW & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 88 | + mips.AMOVWD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 89 | + mips.ATRUNCFW & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 90 | + mips.ATRUNCDW & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Conv}, |
| 91 | + |
| 92 | + mips.ASQRTF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite}, |
| 93 | + mips.ASQRTD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite}, |
| 94 | + |
| 95 | + // Moves |
| 96 | + mips.AMOVB & obj.AMask: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 97 | + mips.AMOVBU & obj.AMask: {Flags: gc.SizeB | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 98 | + mips.AMOVH & obj.AMask: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 99 | + mips.AMOVHU & obj.AMask: {Flags: gc.SizeW | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 100 | + mips.AMOVW & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 101 | + mips.AMOVF & obj.AMask: {Flags: gc.SizeF | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 102 | + mips.AMOVD & obj.AMask: {Flags: gc.SizeD | gc.LeftRead | gc.RightWrite | gc.Move | gc.Conv}, |
| 103 | + |
| 104 | + // Conditional moves |
| 105 | + mips.ACMOVN & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | RightRdwr}, |
| 106 | + mips.ACMOVZ & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RegRead | RightRdwr}, |
| 107 | + mips.ACMOVT & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | RightRdwr}, |
| 108 | + mips.ACMOVF & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | RightRdwr}, |
| 109 | + |
| 110 | + // Conditional trap |
| 111 | + mips.ATEQ & obj.AMask: {Flags: gc.SizeL | gc.RegRead | gc.RightRead}, |
| 112 | + mips.ATNE & obj.AMask: {Flags: gc.SizeL | gc.RegRead | gc.RightRead}, |
| 113 | + |
| 114 | + // Atomic |
| 115 | + mips.ASYNC & obj.AMask: {Flags: gc.OK}, |
| 116 | + mips.ALL & obj.AMask: {Flags: gc.SizeL | gc.LeftRead | gc.RightWrite}, |
| 117 | + mips.ASC & obj.AMask: {Flags: gc.SizeL | LeftRdwr | gc.RightRead}, |
| 118 | + |
| 119 | + // Jumps |
| 120 | + mips.AJMP & obj.AMask: {Flags: gc.Jump | gc.Break}, |
| 121 | + mips.AJAL & obj.AMask: {Flags: gc.Call}, |
| 122 | + mips.ABEQ & obj.AMask: {Flags: gc.Cjmp}, |
| 123 | + mips.ABNE & obj.AMask: {Flags: gc.Cjmp}, |
| 124 | + mips.ABGEZ & obj.AMask: {Flags: gc.Cjmp}, |
| 125 | + mips.ABLTZ & obj.AMask: {Flags: gc.Cjmp}, |
| 126 | + mips.ABGTZ & obj.AMask: {Flags: gc.Cjmp}, |
| 127 | + mips.ABLEZ & obj.AMask: {Flags: gc.Cjmp}, |
| 128 | + mips.ABFPF & obj.AMask: {Flags: gc.Cjmp}, |
| 129 | + mips.ABFPT & obj.AMask: {Flags: gc.Cjmp}, |
| 130 | + mips.ARET & obj.AMask: {Flags: gc.Break}, |
| 131 | + obj.ADUFFZERO: {Flags: gc.Call}, |
| 132 | + obj.ADUFFCOPY: {Flags: gc.Call}, |
| 133 | +} |
| 134 | + |
| 135 | +func proginfo(p *obj.Prog) gc.ProgInfo { |
| 136 | + info := progtable[p.As&obj.AMask] |
| 137 | + |
| 138 | + if info.Flags == 0 { |
| 139 | + gc.Fatalf("proginfo: unknown instruction %v", p) |
| 140 | + } |
| 141 | + |
| 142 | + if (info.Flags&gc.RegRead != 0) && p.Reg == 0 { |
| 143 | + info.Flags &^= gc.RegRead |
| 144 | + info.Flags |= gc.RightRead |
| 145 | + } |
| 146 | + |
| 147 | + if p.From.Type == obj.TYPE_ADDR && p.From.Sym != nil && (info.Flags&gc.LeftRead != 0) { |
| 148 | + info.Flags &^= gc.LeftRead |
| 149 | + info.Flags |= gc.LeftAddr |
| 150 | + } |
| 151 | + |
| 152 | + if p.As == mips.AMUL && p.To.Reg != 0 { |
| 153 | + info.Flags |= gc.RightWrite |
| 154 | + } |
| 155 | + |
| 156 | + return info |
| 157 | +} |
0 commit comments