Skip to content

Commit

Permalink
wazevo(amd64): support for perfmap (tetratelabs#2087)
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake authored and evacchi committed Feb 28, 2024
1 parent a581892 commit 3a6874f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion internal/engine/wazevo/backend/isa/amd64/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1797,10 +1797,22 @@ func (m *machine) encodeWithoutSSA(root *instruction) {
}

// Encode implements backend.Machine Encode.
func (m *machine) Encode(context.Context) {
func (m *machine) Encode(ctx context.Context) {
ectx := m.ectx
bufPtr := m.c.BufPtr()

var fn string
var fnIndex int
var labelToSSABlockID map[backend.Label]ssa.BasicBlockID
if wazevoapi.PerfMapEnabled {
fn = wazevoapi.GetCurrentFunctionName(ctx)
labelToSSABlockID = make(map[backend.Label]ssa.BasicBlockID)
for i, l := range ectx.SsaBlockIDToLabels {
labelToSSABlockID[l] = ssa.BasicBlockID(i)
}
fnIndex = wazevoapi.GetCurrentFunctionIndex(ctx)
}

m.labelResolutionPends = m.labelResolutionPends[:0]
for _, pos := range ectx.OrderedBlockLabels {
offset := int64(len(*bufPtr))
Expand All @@ -1825,6 +1837,18 @@ func (m *machine) Encode(context.Context) {
)
}
}

if wazevoapi.PerfMapEnabled {
l := pos.L
var labelStr string
if blkID, ok := labelToSSABlockID[l]; ok {
labelStr = fmt.Sprintf("%s::SSA_Block[%s]", l, blkID)
} else {
labelStr = l.String()
}
size := int64(len(*bufPtr)) - offset
wazevoapi.PerfMap.AddModuleEntry(fnIndex, offset, uint64(size), fmt.Sprintf("%s:::::%s", fn, labelStr))
}
}

for i := range m.consts {
Expand Down

0 comments on commit 3a6874f

Please sign in to comment.