Commit a1bdea56 authored by Danylo Boiko's avatar Danylo Boiko Committed by V8 LUCI CQ

[turbolizer] Schedule view/phase refactoring

Bug: v8:7327
Change-Id: I45085b4b2dcb76948e39e79fcf15711deb531541
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3764441
Commit-Queue: Danylo Boiko <danielboyko02@gmail.com>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81824}
parent 9230a278
......@@ -92,6 +92,20 @@ export class InstructionsPhase extends Phase {
return this.blockIdToInstructionRange[blockId] ?? [-1, -1];
}
public getInstructionMarker(start: number, end: number): [string, string] {
if (start != end) {
return ["&#8857;", `This node generated instructions in range [${start},${end}). ` +
`This is currently unreliable for constants.`];
}
if (start != -1) {
return ["&#183;", `The instruction selector did not generate instructions ` +
`for this node, but processed the node at instruction ${start}. ` +
`This usually means that this node was folded into another node; ` +
`the highlighted machine code is a guess.`];
}
return ["", `This not is not in the final schedule.`];
}
public getInstructionKindForPCOffset(offset: number): InstructionKind {
if (this.codeOffsetsInfo) {
if (offset >= this.codeOffsetsInfo.deoptimizationExits) {
......
......@@ -5,22 +5,16 @@
import { Phase, PhaseType } from "./phase";
export class SchedulePhase extends Phase {
data: string;
schedule: { currentBlock, blocks: Array<any>, nodes: Array<any> };
data: ScheduleData;
constructor(name: string, data: string) {
constructor(name: string, dataJson) {
super(name, PhaseType.Schedule);
this.data = data;
this.schedule = {
currentBlock: undefined,
blocks: new Array<any>(),
nodes: new Array<any>()
};
this.parseScheduleFromJSON(data);
this.data = new ScheduleData();
this.parseScheduleFromJSON(dataJson);
}
private parseScheduleFromJSON(scheduleDataJson): void {
const lines = scheduleDataJson.split(/[\n]/);
private parseScheduleFromJSON(dataJson): void {
const lines = dataJson.split(/[\n]/);
nextLine:
for (const line of lines) {
for (const rule of this.parsingRules) {
......@@ -37,46 +31,39 @@ export class SchedulePhase extends Phase {
}
private createNode = match => {
let inputs = [];
let inputs = new Array<number>();
if (match.groups.args) {
const nodeIdsString = match.groups.args.replace(/\s/g, '');
const nodeIdStrings = nodeIdsString.split(',');
const nodeIdsString = match.groups.args.replace(/\s/g, "");
const nodeIdStrings = nodeIdsString.split(",");
inputs = nodeIdStrings.map(n => Number.parseInt(n, 10));
}
const node = {
id: Number.parseInt(match.groups.id, 10),
label: match.groups.label,
inputs: inputs
};
const nodeId = Number.parseInt(match.groups.id, 10);
const node = new ScheduleNode(nodeId, match.groups.label, inputs);
if (match.groups.blocks) {
const nodeIdsString = match.groups.blocks.replace(/\s/g, '').replace(/B/g, '');
const nodeIdStrings = nodeIdsString.split(',');
this.schedule.currentBlock.succ = nodeIdStrings.map(n => Number.parseInt(n, 10));
const nodeIdsString = match.groups.blocks.replace(/\s/g, "").replace(/B/g, "");
const nodeIdStrings = nodeIdsString.split(",");
this.data.lastBlock().successors = nodeIdStrings.map(n => Number.parseInt(n, 10));
}
this.schedule.nodes[node.id] = node;
this.schedule.currentBlock.nodes.push(node);
this.data.nodes[node.id] = node;
this.data.lastBlock().nodes.push(node);
}
private createBlock = match => {
let predecessors = [];
let predecessors = new Array<number>();
if (match.groups.in) {
const blockIdsString = match.groups.in.replace(/\s/g, '').replace(/B/g, '');
const blockIdStrings = blockIdsString.split(',');
const blockIdsString = match.groups.in.replace(/\s/g, "").replace(/B/g, "");
const blockIdStrings = blockIdsString.split(",");
predecessors = blockIdStrings.map(n => Number.parseInt(n, 10));
}
const block = {
id: Number.parseInt(match.groups.id, 10),
isDeferred: match.groups.deferred != undefined,
pred: predecessors.sort(),
succ: [],
nodes: []
};
this.schedule.blocks[block.id] = block;
this.schedule.currentBlock = block;
const blockId = Number.parseInt(match.groups.id, 10);
const block = new ScheduleBlock(blockId, match.groups.deferred !== undefined,
predecessors.sort());
this.data.blocks[block.id] = block;
}
private setGotoSuccessor = match => {
this.schedule.currentBlock.succ = [Number.parseInt(match.groups.successor.replace(/\s/g, ''), 10)];
this.data.lastBlock().successors =
[Number.parseInt(match.groups.successor.replace(/\s/g, ""), 10)];
}
private parsingRules = [
......@@ -98,3 +85,50 @@ export class SchedulePhase extends Phase {
}
];
}
export class ScheduleNode {
id: number;
label: string;
inputs: Array<number>;
constructor(id: number, label: string, inputs: Array<number>) {
this.id = id;
this.label = label;
this.inputs = inputs;
}
public toString(): string {
return `${this.id}: ${this.label}(${this.inputs.join(", ")})`;
}
}
export class ScheduleBlock {
id: number;
deferred: boolean;
predecessors: Array<number>;
successors: Array<number>;
nodes: Array<ScheduleNode>;
constructor(id: number, deferred: boolean, predecessors: Array<number>) {
this.id = id;
this.deferred = deferred;
this.predecessors = predecessors;
this.successors = new Array<number>();
this.nodes = new Array<ScheduleNode>();
}
}
export class ScheduleData {
nodes: Array<ScheduleNode>;
blocks: Array<ScheduleBlock>;
constructor() {
this.nodes = new Array<ScheduleNode>();
this.blocks = new Array<ScheduleBlock>();
}
public lastBlock(): ScheduleBlock {
if (this.blocks.length == 0) return null;
return this.blocks[this.blocks.length - 1];
}
}
......@@ -12,13 +12,14 @@ export interface ClearableHandler {
}
export interface NodeSelectionHandler {
select(nodes: Iterable<TurboshaftGraphNode | GraphNode | string>, selected: boolean): void;
select(nodes: Iterable<TurboshaftGraphNode | GraphNode | string | number>, selected: boolean):
void;
clear(): void;
brokeredNodeSelect(nodeIds: Set<string>, selected: boolean): void;
}
export interface BlockSelectionHandler {
select(blocks: Iterable<TurboshaftGraphBlock | string>, selected: boolean): void;
select(blocks: Iterable<TurboshaftGraphBlock | string | number>, selected: boolean): void;
clear(): void;
brokeredBlockSelect(blockIds: Array<string>, selected: boolean): void;
}
......
This diff is collapsed.
......@@ -36,7 +36,7 @@ export abstract class TextView extends PhaseView {
nodeIdToBlockId: Array<string>;
patterns: Array<Array<any>>;
constructor(parent: HTMLDivElement, broker: SelectionBroker) {
constructor(parent: HTMLElement, broker: SelectionBroker) {
super(parent);
this.broker = broker;
this.sourceResolver = broker.sourceResolver;
......@@ -69,7 +69,7 @@ export abstract class TextView extends PhaseView {
public initializeContent(genericPhase: GenericTextPhase, _): void {
this.clearText();
if (!(genericPhase instanceof SequencePhase)) {
if (genericPhase instanceof DisassemblyPhase) {
this.processText(genericPhase.data);
}
this.show();
......@@ -207,7 +207,7 @@ export abstract class TextView extends PhaseView {
private initializeNodeSelectionHandler(): NodeSelectionHandler & ClearableHandler {
const view = this;
return {
select: function (nodeIds: Array<string>, selected: boolean) {
select: function (nodeIds: Array<string | number>, selected: boolean) {
view.nodeSelection.select(nodeIds, selected);
view.updateSelection();
view.broker.broadcastNodeSelect(this, view.nodeSelection.selectedKeys(), selected);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment