Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1760)

Side by Side Diff: ssa/builder.go

Issue 37270043: code review 37270043: go.tools/ssa: eliminate remaining uses of operands of "... (Closed)
Patch Set: diff -r a44dba07e828 https://code.google.com/p/go.tools Created 10 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ssa/const.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Go Authors. All rights reserved. 1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package ssa 5 package ssa
6 6
7 // This file implements the BUILD phase of SSA construction. 7 // This file implements the BUILD phase of SSA construction.
8 // 8 //
9 // SSA construction has two phases, CREATE and BUILD. In the CREATE phase 9 // SSA construction has two phases, CREATE and BUILD. In the CREATE phase
10 // (create.go), all packages are constructed and type-checked and 10 // (create.go), all packages are constructed and type-checked and
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 // Type constants. 55 // Type constants.
56 tBool = types.Typ[types.Bool] 56 tBool = types.Typ[types.Bool]
57 tByte = types.Typ[types.Byte] 57 tByte = types.Typ[types.Byte]
58 tInt = types.Typ[types.Int] 58 tInt = types.Typ[types.Int]
59 tInvalid = types.Typ[types.Invalid] 59 tInvalid = types.Typ[types.Invalid]
60 tUntypedNil = types.Typ[types.UntypedNil] 60 tUntypedNil = types.Typ[types.UntypedNil]
61 tRangeIter = &opaqueType{nil, "iter"} // the type of all "range" iterat ors 61 tRangeIter = &opaqueType{nil, "iter"} // the type of all "range" iterat ors
62 tEface = new(types.Interface) 62 tEface = new(types.Interface)
63 63
64 // SSA Value constants. 64 // SSA Value constants.
65 » vZero = intConst(0) 65 » vZero = intConst(0)
66 » vOne = intConst(1) 66 » vOne = intConst(1)
67 » vTrue = NewConst(exact.MakeBool(true), tBool) 67 » vTrue = NewConst(exact.MakeBool(true), tBool)
68 » vFalse = NewConst(exact.MakeBool(false), tBool)
69 ) 68 )
70 69
71 // builder holds state associated with the package currently being built. 70 // builder holds state associated with the package currently being built.
72 // Its methods contain all the logic for AST-to-SSA conversion. 71 // Its methods contain all the logic for AST-to-SSA conversion.
73 type builder struct{} 72 type builder struct{}
74 73
75 // cond emits to fn code to evaluate boolean condition e and jump 74 // cond emits to fn code to evaluate boolean condition e and jump
76 // to t or f depending on its value, performing various simplifications. 75 // to t or f depending on its value, performing various simplifications.
77 // 76 //
78 // Postcondition: fn.currentBlock is nil. 77 // Postcondition: fn.currentBlock is nil.
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return intConst(at.Len()) 306 return intConst(at.Len())
308 } 307 }
309 // Otherwise treat as normal. 308 // Otherwise treat as normal.
310 309
311 case "panic": 310 case "panic":
312 fn.emit(&Panic{ 311 fn.emit(&Panic{
313 X: emitConv(fn, b.expr(fn, args[0]), tEface), 312 X: emitConv(fn, b.expr(fn, args[0]), tEface),
314 pos: pos, 313 pos: pos,
315 }) 314 })
316 fn.currentBlock = fn.newBasicBlock("unreachable") 315 fn.currentBlock = fn.newBasicBlock("unreachable")
317 » » return vFalse // any non-nil Value will do 316 » » return vTrue // any non-nil Value will do
318 } 317 }
319 return nil // treat all others as a regular function call 318 return nil // treat all others as a regular function call
320 } 319 }
321 320
322 // addr lowers a single-result addressable expression e to SSA form, 321 // addr lowers a single-result addressable expression e to SSA form,
323 // emitting code to fn and returning the location (an lvalue) defined 322 // emitting code to fn and returning the location (an lvalue) defined
324 // by the expression. 323 // by the expression.
325 // 324 //
326 // If escaping is true, addr marks the base variable of the 325 // If escaping is true, addr marks the base variable of the
327 // addressable expression e as being a potentially escaping pointer 326 // addressable expression e as being a potentially escaping pointer
(...skipping 1555 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 X: emitConv(fn, b.expr(fn, s.Value), 1882 X: emitConv(fn, b.expr(fn, s.Value),
1884 fn.Pkg.typeOf(s.Chan).Underlying().(*types.Chan) .Elem()), 1883 fn.Pkg.typeOf(s.Chan).Underlying().(*types.Chan) .Elem()),
1885 pos: s.Arrow, 1884 pos: s.Arrow,
1886 }) 1885 })
1887 1886
1888 case *ast.IncDecStmt: 1887 case *ast.IncDecStmt:
1889 op := token.ADD 1888 op := token.ADD
1890 if s.Tok == token.DEC { 1889 if s.Tok == token.DEC {
1891 op = token.SUB 1890 op = token.SUB
1892 } 1891 }
1893 » » b.assignOp(fn, b.addr(fn, s.X, false), vOne, op) 1892 » » loc := b.addr(fn, s.X, false)
1893 » » b.assignOp(fn, loc, NewConst(exact.MakeInt64(1), loc.typ()), op)
1894 1894
1895 case *ast.AssignStmt: 1895 case *ast.AssignStmt:
1896 switch s.Tok { 1896 switch s.Tok {
1897 case token.ASSIGN, token.DEFINE: 1897 case token.ASSIGN, token.DEFINE:
1898 b.assignStmt(fn, s.Lhs, s.Rhs, s.Tok == token.DEFINE) 1898 b.assignStmt(fn, s.Lhs, s.Rhs, s.Tok == token.DEFINE)
1899 1899
1900 default: // +=, etc. 1900 default: // +=, etc.
1901 op := s.Tok + token.ADD - token.ADD_ASSIGN 1901 op := s.Tok + token.ADD - token.ADD_ASSIGN
1902 b.assignOp(fn, b.addr(fn, s.Lhs[0], false), b.expr(fn, s .Rhs[0]), op) 1902 b.assignOp(fn, b.addr(fn, s.Lhs[0], false), b.expr(fn, s .Rhs[0]), op)
1903 } 1903 }
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
2377 2377
2378 case *types.Tuple: 2378 case *types.Tuple:
2379 for i, n := 0, t.Len(); i < n; i++ { 2379 for i, n := 0, t.Len(); i < n; i++ {
2380 p.needMethodsOf(t.At(i).Type()) 2380 p.needMethodsOf(t.At(i).Type())
2381 } 2381 }
2382 2382
2383 default: 2383 default:
2384 panic(T) 2384 panic(T)
2385 } 2385 }
2386 } 2386 }
OLDNEW
« no previous file with comments | « no previous file | ssa/const.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b