rm unused code (phi, abi.Name)

This commit is contained in:
xushiwei
2024-05-26 18:10:17 +08:00
parent c903785864
commit 12b0d81dda
3 changed files with 9 additions and 267 deletions

View File

@@ -456,157 +456,4 @@ func addChecked(p unsafe.Pointer, x uintptr, whySafe string) unsafe.Pointer {
return unsafe.Pointer(uintptr(p) + x) return unsafe.Pointer(uintptr(p) + x)
} }
/*
// Name is an encoded type Name with optional extra data.
//
// The first byte is a bit field containing:
//
// 1<<0 the name is exported
// 1<<1 tag data follows the name
// 1<<2 pkgPath nameOff follows the name and tag
// 1<<3 the name is of an embedded (a.k.a. anonymous) field
//
// Following that, there is a varint-encoded length of the name,
// followed by the name itself.
//
// If tag data is present, it also has a varint-encoded length
// followed by the tag itself.
//
// If the import path follows, then 4 bytes at the end of
// the data form a nameOff. The import path is only set for concrete
// methods that are defined in a different package than their type.
//
// If a name starts with "*", then the exported bit represents
// whether the pointed to type is exported.
//
// Note: this encoding must match here and in:
// cmd/compile/internal/reflectdata/reflect.go
// cmd/link/internal/ld/decodesym.go
type Name struct {
Bytes *byte
}
// DataChecked does pointer arithmetic on n's Bytes, and that arithmetic is asserted to
// be safe for the reason in whySafe (which can appear in a backtrace, etc.)
func (n Name) DataChecked(off int, whySafe string) *byte {
return (*byte)(addChecked(unsafe.Pointer(n.Bytes), uintptr(off), whySafe))
}
// Data does pointer arithmetic on n's Bytes, and that arithmetic is asserted to
// be safe because the runtime made the call (other packages use DataChecked)
func (n Name) Data(off int) *byte {
return (*byte)(addChecked(unsafe.Pointer(n.Bytes), uintptr(off), "the runtime doesn't need to give you a reason"))
}
// IsExported returns "is n exported?"
func (n Name) IsExported() bool {
return (*n.Bytes)&(1<<0) != 0
}
// HasTag returns true iff there is tag data following this name
func (n Name) HasTag() bool {
return (*n.Bytes)&(1<<1) != 0
}
// IsEmbedded returns true iff n is embedded (an anonymous field).
func (n Name) IsEmbedded() bool {
return (*n.Bytes)&(1<<3) != 0
}
// ReadVarint parses a varint as encoded by encoding/binary.
// It returns the number of encoded bytes and the encoded value.
func (n Name) ReadVarint(off int) (int, int) {
v := 0
for i := 0; ; i++ {
x := *n.DataChecked(off+i, "read varint")
v += int(x&0x7f) << (7 * i)
if x&0x80 == 0 {
return i + 1, v
}
}
}
// IsBlank indicates whether n is "_".
func (n Name) IsBlank() bool {
if n.Bytes == nil {
return false
}
_, l := n.ReadVarint(1)
return l == 1 && *n.Data(2) == '_'
}
// writeVarint writes n to buf in varint form. Returns the
// number of bytes written. n must be nonnegative.
// Writes at most 10 bytes.
func writeVarint(buf []byte, n int) int {
for i := 0; ; i++ {
b := byte(n & 0x7f)
n >>= 7
if n == 0 {
buf[i] = b
return i + 1
}
buf[i] = b | 0x80
}
}
// Name returns the tag string for n, or empty if there is none.
func (n Name) Name() string {
if n.Bytes == nil {
return ""
}
i, l := n.ReadVarint(1)
return unsafe.String(n.DataChecked(1+i, "non-empty string"), l)
}
// Tag returns the tag string for n, or empty if there is none.
func (n Name) Tag() string {
if !n.HasTag() {
return ""
}
i, l := n.ReadVarint(1)
i2, l2 := n.ReadVarint(1 + i + l)
return unsafe.String(n.DataChecked(1+i+l+i2, "non-empty string"), l2)
}
func NewName(n, tag string, exported, embedded bool) Name {
if len(n) >= 1<<29 {
panic("abi.NewName: name too long: " + n[:1024] + "...")
}
if len(tag) >= 1<<29 {
panic("abi.NewName: tag too long: " + tag[:1024] + "...")
}
var nameLen [10]byte
var tagLen [10]byte
nameLenLen := writeVarint(nameLen[:], len(n))
tagLenLen := writeVarint(tagLen[:], len(tag))
var bits byte
l := 1 + nameLenLen + len(n)
if exported {
bits |= 1 << 0
}
if len(tag) > 0 {
l += tagLenLen + len(tag)
bits |= 1 << 1
}
if embedded {
bits |= 1 << 3
}
b := make([]byte, l)
b[0] = bits
copy(b[1:], nameLen[:nameLenLen])
copy(b[1+nameLenLen:], n)
if len(tag) > 0 {
tb := b[1+nameLenLen+len(n):]
copy(tb, tagLen[:tagLenLen])
copy(tb[tagLenLen:], tag)
}
return Name{Bytes: &b[0]}
}
*/
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------

View File

@@ -27,25 +27,6 @@ type Type = abi.Type
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
/*
type Name = abi.Name
// NewName creates a new name.
func NewName(name string, exported bool) Name {
return abi.NewName(name, "", exported, false)
}
// NewPkgName creates a package name.
func NewPkgName(pkgPath string) (ret Name) {
if len(pkgPath) > 0 {
ret = abi.NewName(pkgPath, "", false, false)
}
return
}
*/
// -----------------------------------------------------------------------------
func Basic(kind Kind) *Type { func Basic(kind Kind) *Type {
return basicTypes[kind] return basicTypes[kind]
} }

View File

@@ -514,115 +514,29 @@ func llvmPredBlocks(preds []BasicBlock) []llvm.BasicBlock {
return ret return ret
} }
type aPhi struct { // -----------------------------------------------------------------------------
Expr
// phis []llvm.Value
}
// Phi represents a phi node. // Phi represents a phi node.
type Phi = *aPhi type Phi struct {
Expr
/*
func (b Builder) newPhi(t Type, phis []llvm.Value) Phi {
ret := b.aggregateValue(t, phis...)
return &aPhi{ret, phis}
} }
*/
// AddIncoming adds incoming values to a phi node. // AddIncoming adds incoming values to a phi node.
func (p Phi) AddIncoming(b Builder, preds []BasicBlock, f func(i int, blk BasicBlock) Expr) { func (p Phi) AddIncoming(b Builder, preds []BasicBlock, f func(i int, blk BasicBlock) Expr) {
bs := llvmPredBlocks(preds) bs := llvmPredBlocks(preds)
/* vals := make([]llvm.Value, len(preds))
phis := p.phis for iblk, blk := range preds {
if phis != nil { vals[iblk] = f(iblk, blk).impl
vals := make([][]llvm.Value, len(phis))
for iblk, blk := range preds {
val := f(iblk, blk).impl
impl := b.impl
b.SetBlockEx(blk, BeforeLast, false)
for i := range phis {
if iblk == 0 {
vals[i] = make([]llvm.Value, len(preds))
}
vals[i][iblk] = llvm.CreateExtractValue(impl, val, i)
}
}
for i, phi := range phis {
phi.AddIncoming(vals[i], bs)
}
} else */
{
vals := make([]llvm.Value, len(preds))
for iblk, blk := range preds {
vals[iblk] = f(iblk, blk).impl
}
p.impl.AddIncoming(vals, bs)
} }
p.impl.AddIncoming(vals, bs)
} }
// Phi returns a phi node. // Phi returns a phi node.
func (b Builder) Phi(t Type) Phi { func (b Builder) Phi(t Type) Phi {
impl := b.impl phi := llvm.CreatePHI(b.impl, t.ll)
/* return Phi{Expr{phi, t}}
switch tund := t.raw.Type.Underlying().(type) {
case *types.Basic:
kind := tund.Kind()
switch kind {
case types.String:
phis := createStringPhis(impl, make([]llvm.Value, 0, 2), b.Prog)
return b.newPhi(t, phis)
}
case *types.Struct:
phis := createStrucPhis(impl, nil, tund, b.Prog)
return b.newPhi(t, phis)
default:
log.Panicf("todo: %T\n", tund)
}
*/
phi := llvm.CreatePHI(impl, t.ll)
return &aPhi{Expr{phi, t}} //, nil}
} }
/*
func createStringPhis(b llvm.Builder, phis []llvm.Value, prog Program) []llvm.Value {
phis = append(phis, llvm.CreatePHI(b, prog.tyVoidPtr()))
return append(phis, llvm.CreatePHI(b, prog.tyInt()))
}
func createStrucPhis(b llvm.Builder, phis []llvm.Value, t *types.Struct, prog Program) []llvm.Value {
n := t.NumFields()
if phis == nil {
phis = make([]llvm.Value, 0, n)
}
for i := 0; i < n; i++ {
fld := t.Field(i)
switch tfld := fld.Type().Underlying().(type) {
case *types.Basic:
kind := tfld.Kind()
switch kind {
case types.String:
phis = createStringPhis(b, phis, prog)
default:
phis = createBasicPhi(b, phis, tfld, prog)
}
case *types.Pointer:
phis = createBasicPhi(b, phis, tfld, prog)
case *types.Struct:
phis = createStrucPhis(b, phis, tfld, prog)
default:
panic("todo")
}
}
return phis
}
func createBasicPhi(b llvm.Builder, phis []llvm.Value, t types.Type, prog Program) []llvm.Value {
tll := prog.rawType(t).ll
phi := llvm.CreatePHI(b, tll)
return append(phis, phi)
}
*/
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Advance returns the pointer ptr advanced by offset. // Advance returns the pointer ptr advanced by offset.