Home | History | Annotate | Download | only in gen
      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 // This file contains rules to decompose builtin compound types
      6 // (complex,string,slice,interface) into their constituent
      7 // types.  These rules work together with the decomposeBuiltIn
      8 // pass which handles phis of these types.
      9 
     10 // complex ops
     11 (ComplexReal (ComplexMake real _  )) -> real
     12 (ComplexImag (ComplexMake _ imag )) -> imag
     13 
     14 (Load <t> ptr mem) && t.IsComplex() && t.Size() == 8 ->
     15   (ComplexMake
     16     (Load <config.fe.TypeFloat32()> ptr mem)
     17     (Load <config.fe.TypeFloat32()>
     18       (OffPtr <config.fe.TypeFloat32().PtrTo()> [4] ptr)
     19       mem)
     20     )
     21 (Store [8] dst (ComplexMake real imag) mem) ->
     22   (Store [4]
     23     (OffPtr <config.fe.TypeFloat32().PtrTo()> [4] dst)
     24     imag
     25     (Store [4] dst real mem))
     26 (Load <t> ptr mem) && t.IsComplex() && t.Size() == 16 ->
     27   (ComplexMake
     28     (Load <config.fe.TypeFloat64()> ptr mem)
     29     (Load <config.fe.TypeFloat64()>
     30       (OffPtr <config.fe.TypeFloat64().PtrTo()> [8] ptr)
     31       mem)
     32     )
     33 (Store [16] dst (ComplexMake real imag) mem) ->
     34   (Store [8]
     35     (OffPtr <config.fe.TypeFloat64().PtrTo()> [8] dst)
     36     imag
     37     (Store [8] dst real mem))
     38 
     39 // string ops
     40 (StringPtr (StringMake ptr _)) -> ptr
     41 (StringLen (StringMake _ len)) -> len
     42 
     43 (Load <t> ptr mem) && t.IsString() ->
     44   (StringMake
     45     (Load <config.fe.TypeBytePtr()> ptr mem)
     46     (Load <config.fe.TypeInt()>
     47       (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr)
     48       mem))
     49 (Store [2*config.PtrSize] dst (StringMake ptr len) mem) ->
     50   (Store [config.PtrSize]
     51     (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst)
     52     len
     53     (Store [config.PtrSize] dst ptr mem))
     54 
     55 // slice ops
     56 (SlicePtr (SliceMake ptr _ _ )) -> ptr
     57 (SliceLen (SliceMake _ len _)) -> len
     58 (SliceCap (SliceMake _ _ cap)) -> cap
     59 
     60 (Load <t> ptr mem) && t.IsSlice() ->
     61   (SliceMake
     62     (Load <t.ElemType().PtrTo()> ptr mem)
     63     (Load <config.fe.TypeInt()>
     64       (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] ptr)
     65       mem)
     66     (Load <config.fe.TypeInt()>
     67       (OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] ptr)
     68       mem))
     69 (Store [3*config.PtrSize] dst (SliceMake ptr len cap) mem) ->
     70   (Store [config.PtrSize]
     71     (OffPtr <config.fe.TypeInt().PtrTo()> [2*config.PtrSize] dst)
     72     cap
     73     (Store [config.PtrSize]
     74       (OffPtr <config.fe.TypeInt().PtrTo()> [config.PtrSize] dst)
     75       len
     76       (Store [config.PtrSize] dst ptr mem)))
     77 
     78 // interface ops
     79 (ITab (IMake itab _)) -> itab
     80 (IData (IMake _ data)) -> data
     81 
     82 (Load <t> ptr mem) && t.IsInterface() ->
     83   (IMake
     84     (Load <config.fe.TypeBytePtr()> ptr mem)
     85     (Load <config.fe.TypeBytePtr()>
     86       (OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] ptr)
     87       mem))
     88 (Store [2*config.PtrSize] dst (IMake itab data) mem) ->
     89   (Store [config.PtrSize]
     90     (OffPtr <config.fe.TypeBytePtr().PtrTo()> [config.PtrSize] dst)
     91     data
     92     (Store [config.PtrSize] dst itab mem))
     93