blob: c410cc4f027d63004fa23b17e27cc3505a406592 [file] [log] [blame]
Keith Randall0dca7352015-06-06 16:03:33 -07001// 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
5package main
6
7var genericOps = []opData{
8 // 2-input arithmetic
9 // Types must be consistent with Go typing. Add, for example, must take two values
10 // of the same type and produces that same type.
11 {name: "Add"}, // arg0 + arg1
12 {name: "Sub"}, // arg0 - arg1
13 {name: "Mul"}, // arg0 * arg1
14 {name: "Lsh"}, // arg0 << arg1
15 {name: "Rsh"}, // arg0 >> arg1 (signed/unsigned depending on signedness of type)
16
17 // 2-input comparisons
Josh Bleecher Snyder46815b92015-06-24 17:48:22 -070018 {name: "Eq"}, // arg0 == arg1
19 {name: "Neq"}, // arg0 != arg1
20 {name: "Less"}, // arg0 < arg1
21 {name: "Leq"}, // arg0 <= arg1
22 {name: "Greater"}, // arg0 > arg1
23 {name: "Geq"}, // arg0 <= arg1
Keith Randall0dca7352015-06-06 16:03:33 -070024
25 // Data movement
26 {name: "Phi"}, // select an argument based on which predecessor block we came from
27 {name: "Copy"}, // output = arg0
28
29 // constants. Constant values are stored in the aux field.
30 // booleans have a bool aux field, strings have a string aux
31 // field, and so on. All integer types store their value
32 // in the aux field as an int64 (including int, uint64, etc.).
33 // We could store int8 as an int8, but that won't work for int,
34 // as it may be different widths on the host and target.
35 {name: "Const"},
36
37 // Constant-like things
Keith Randall8c46aa52015-06-19 21:02:28 -070038 {name: "Arg"}, // memory input to the function.
39
40 // The address of a variable. arg0 is the base pointer (SB or SP, depending
41 // on whether it is a global or stack variable). The Aux field identifies the
42 // variable. It will be either an *ExternSymbol (with arg0=SB), *ArgSymbol (arg0=SP),
43 // or *AutoSymbol (arg0=SP).
44 {name: "Addr"}, // Address of a variable. Arg0=SP or SB. Aux identifies the variable.
45
46 {name: "SP"}, // stack pointer
47 {name: "SB"}, // static base pointer (a.k.a. globals pointer)
48 {name: "Func"}, // entry address of a function
Keith Randall0dca7352015-06-06 16:03:33 -070049
50 // Memory operations
Keith Randall8f22b522015-06-11 21:29:25 -070051 {name: "Load"}, // Load from arg0. arg1=memory
52 {name: "Store"}, // Store arg1 to arg0. arg2=memory. Returns memory.
53 {name: "Move"}, // arg0=destptr, arg1=srcptr, arg2=mem, auxint=size. Returns memory.
Daniel Morsing66b47812015-06-27 15:45:20 +010054 {name: "Zero"}, // arg0=destptr, arg1=mem, auxint=size. Returns memory.
Keith Randall0dca7352015-06-06 16:03:33 -070055
56 // Function calls. Arguments to the call have already been written to the stack.
57 // Return values appear on the stack. The method receiver, if any, is treated
58 // as a phantom first argument.
Keith Randall290d8fc2015-06-10 15:03:06 -070059 {name: "ClosureCall"}, // arg0=code pointer, arg1=context ptr, arg2=memory. Returns memory.
60 {name: "StaticCall"}, // call function aux.(*gc.Sym), arg0=memory. Returns memory.
Keith Randall0dca7352015-06-06 16:03:33 -070061
62 // Conversions
63 {name: "Convert"}, // convert arg0 to another type
64 {name: "ConvNop"}, // interpret arg0 as another type
65
66 // Safety checks
67 {name: "IsNonNil"}, // arg0 != nil
68 {name: "IsInBounds"}, // 0 <= arg0 < arg1
69
70 // Indexing operations
71 {name: "ArrayIndex"}, // arg0=array, arg1=index. Returns a[i]
72 {name: "PtrIndex"}, // arg0=ptr, arg1=index. Computes ptr+sizeof(*v.type)*index, where index is extended to ptrwidth type
Keith Randall8f22b522015-06-11 21:29:25 -070073 {name: "OffPtr"}, // arg0 + auxint (arg0 and result are pointers)
Keith Randall0dca7352015-06-06 16:03:33 -070074
75 // Slices
76 {name: "SliceMake"}, // arg0=ptr, arg1=len, arg2=cap
77 {name: "SlicePtr"}, // ptr(arg0)
78 {name: "SliceLen"}, // len(arg0)
79 {name: "SliceCap"}, // cap(arg0)
80
81 // Strings
82 {name: "StringMake"}, // arg0=ptr, arg1=len
83 {name: "StringPtr"}, // ptr(arg0)
84 {name: "StringLen"}, // len(arg0)
85
86 // Spill&restore ops for the register allocator. These are
87 // semantically identical to OpCopy; they do not take/return
88 // stores like regular memory ops do. We can get away without memory
89 // args because we know there is no aliasing of spill slots on the stack.
90 // TODO: remove these, make them arch-specific ops stored
91 // in the fields of Config instead.
92 {name: "StoreReg8"},
93 {name: "LoadReg8"},
94
95 // Used during ssa construction. Like Copy, but the arg has not been specified yet.
96 {name: "FwdRef"},
97}
98
99// kind control successors
100// ------------------------------------------
101// Exit return mem []
102// Plain nil [next]
103// If a boolean Value [then, else]
104// Call mem [nopanic, panic] (control opcode should be OpCall or OpStaticCall)
105
106var genericBlocks = []blockData{
107 {name: "Exit"}, // no successors. There should only be 1 of these.
Josh Bleecher Snyder9b048522015-07-09 21:24:12 -0600108 {name: "Dead"}, // no successors; determined to be dead but not yet removed
Keith Randall0dca7352015-06-06 16:03:33 -0700109 {name: "Plain"}, // a single successor
110 {name: "If"}, // 2 successors, if control goto Succs[0] else goto Succs[1]
111 {name: "Call"}, // 2 successors, normal return and panic
112 // TODO(khr): BlockPanic for the built-in panic call, has 1 edge to the exit block
113}
114
115func init() {
Josh Bleecher Snyderba8a1462015-06-11 15:52:08 -0700116 archs = append(archs, arch{"generic", genericOps, genericBlocks, nil})
Keith Randall0dca7352015-06-06 16:03:33 -0700117}