Good working version of the pane

This commit is contained in:
Jeremy Rifkin
2022-06-25 20:05:52 -04:00
parent 8b8a7d6030
commit 3e664fd83d
9 changed files with 305 additions and 22 deletions
+8 -11
View File
@@ -1,4 +1,4 @@
// Copyright (c) 2018, Compiler Explorer Authors
// Copyright (c) 2022, Compiler Explorer Authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
@@ -24,6 +24,7 @@
import _ from 'underscore';
import {LLVMOptPipelineOutput, OutputLine, Pass} from '../../types/compilation/llvm-opt-pipeline-output.interfaces';
import {ParseFilters} from '../../types/features/filters.interfaces';
import * as utils from '../utils';
@@ -45,7 +46,6 @@ function assert(condition: boolean, message?: string, ...args: any[]): asserts c
}
}
type OutputLine = {text: string};
// Ir Dump for a pass with raw lines
type PassDump = {
header: string;
@@ -56,12 +56,6 @@ type SplitPassDump = {
header: string;
functions: Record<string, OutputLine[]>;
};
// Pass name with before / after dump
type Pass = {
name: string;
after: OutputLine[];
before: OutputLine[];
};
export class LlvmPrintAfterAllParser {
filters: RegExp[];
@@ -229,7 +223,7 @@ export class LlvmPrintAfterAllParser {
lines,
});
}
if (functionEntries.length > 0) {
if (functionEntries.length === 0) {
throw 'Internal error during breakdownOutput (2)';
} else if (functionEntries.length === 1) {
const name = functionEntries[0][0];
@@ -245,7 +239,7 @@ export class LlvmPrintAfterAllParser {
//});
// We have all the passes for each function, now we will go through each function and match the before/after
// dumps
const final_output: Record<string, Pass[]> = {};
const final_output: LLVMOptPipelineOutput = {};
for (const [function_name, passDumps] of Object.entries(passDumpsByFunction)) {
// I had a fantastic chunk2 method to iterate the passes in chunks of 2 but I've been foiled by an edge
// case: At least the "Delete dead loops" may only print a before dump and no after dump
@@ -256,6 +250,7 @@ export class LlvmPrintAfterAllParser {
name: '',
after: [],
before: [],
irChanged: true,
};
assert(i < passDumps.length - 1); // make sure there's another item
const current_dump = passDumps[i];
@@ -286,6 +281,8 @@ export class LlvmPrintAfterAllParser {
} else {
assert(false, 'Unexpected pass header', current_dump.header);
}
// check for equality
pass.irChanged = pass.before.map(x => x.text).join('\n') !== pass.after.map(x => x.text).join('\n');
passes.push(pass);
}
assert(!(function_name in final_output), 'xxx');
@@ -297,7 +294,7 @@ export class LlvmPrintAfterAllParser {
return final_output;
}
process(ir: {text: string}[], _: ParseFilters) {
process(ir: OutputLine[], _: ParseFilters) {
// Filter a lot of junk before processing
const preprocessed_lines = ir
.filter(line => this.filters.every(re => line.text.match(re) === null)) // apply filters
+27
View File
@@ -54,6 +54,7 @@
"request": "^2.88.2",
"response-time": "^2.3.2",
"sanitize-filename": "^1.6.3",
"scroll-into-view-if-needed": "^2.2.29",
"semver": "^7.3.5",
"serve-favicon": "^2.4.5",
"shell-quote": "^1.7.3",
@@ -3857,6 +3858,11 @@
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"node_modules/compute-scroll-into-view": {
"version": "1.0.17",
"resolved": "https://registry.npmjs.org/compute-scroll-into-view/-/compute-scroll-into-view-1.0.17.tgz",
"integrity": "sha512-j4dx+Fb0URmzbwwMUrhqWM2BEWHdFGx+qZ9qqASHRPqvTYdqvWnHg0H1hIbcyLnvgnoNAVMlwkepyqM3DaIFUg=="
},
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -12111,6 +12117,14 @@
"resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
"integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg=="
},
"node_modules/scroll-into-view-if-needed": {
"version": "2.2.29",
"resolved": "https://registry.npmjs.org/scroll-into-view-if-needed/-/scroll-into-view-if-needed-2.2.29.tgz",
"integrity": "sha512-hxpAR6AN+Gh53AdAimHM6C8oTN1ppwVZITihix+WqalywBeFcQ6LdQP5ABNl26nX8GTEL7VT+b8lKpdqq65wXg==",
"dependencies": {
"compute-scroll-into-view": "^1.0.17"
}
},
"node_modules/select": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz",
@@ -17817,6 +17831,11 @@
}
}
},
"compute-scroll-into-view": {
"version": "1.0.17",
"resolved": "https://registry.npmjs.org/compute-scroll-into-view/-/compute-scroll-into-view-1.0.17.tgz",
"integrity": "sha512-j4dx+Fb0URmzbwwMUrhqWM2BEWHdFGx+qZ9qqASHRPqvTYdqvWnHg0H1hIbcyLnvgnoNAVMlwkepyqM3DaIFUg=="
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -23866,6 +23885,14 @@
}
}
},
"scroll-into-view-if-needed": {
"version": "2.2.29",
"resolved": "https://registry.npmjs.org/scroll-into-view-if-needed/-/scroll-into-view-if-needed-2.2.29.tgz",
"integrity": "sha512-hxpAR6AN+Gh53AdAimHM6C8oTN1ppwVZITihix+WqalywBeFcQ6LdQP5ABNl26nX8GTEL7VT+b8lKpdqq65wXg==",
"requires": {
"compute-scroll-into-view": "^1.0.17"
}
},
"select": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/select/-/select-1.1.2.tgz",
+1
View File
@@ -65,6 +65,7 @@
"request": "^2.88.2",
"response-time": "^2.3.2",
"sanitize-filename": "^1.6.3",
"scroll-into-view-if-needed": "^2.2.29",
"semver": "^7.3.5",
"serve-favicon": "^2.4.5",
"shell-quote": "^1.7.3",
+31
View File
@@ -134,6 +134,10 @@ li.tweet {
margin: 0 10px 0 0;
}
.llvm-opt-function-picker {
min-width: 10em;
}
#root {
width: 100%;
margin: 0;
@@ -952,3 +956,30 @@ html[data-theme='dark'] {
}
}
}
.llvm-opt-pipeline-body {
display: flex;
overflow: hidden;
align-items: stretch;
height: 100%;
.passes-column {
color: white;
min-width: 200px;
max-width: 30%;
overflow-y: scroll;
overflow-x: hidden;
height: 100%;
.passes-list div {
background: rgba(255, 255, 255, 0.1);
padding: 2px 3px;
border: 1px solid black;
cursor: pointer;
&:hover, &.active {
background: rgba(255, 255, 255, 0.2);
}
&.changed {
color: #36ac46;
}
}
}
}
+181 -9
View File
@@ -38,21 +38,100 @@ import {Hub} from '../hub';
import * as utils from '../utils';
export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneCodeEditor, IrState> {
import {LLVMOptPipelineOutput, OutputLine, Pass} from '../../types/compilation/llvm-opt-pipeline-output.interfaces';
import TomSelect from 'tom-select';
import scrollIntoView from 'scroll-into-view-if-needed';
export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneDiffEditor, IrState> {
results: LLVMOptPipelineOutput = {};
irCode: any[] = [];
passesColumn: JQuery;
passesList: JQuery;
body: JQuery;
clickCallback: (e: JQuery.ClickEvent) => void;
keydownCallback: (e: JQuery.KeyDownEvent) => void;
isPassListSelected = false;
functionSelector: TomSelect;
selectedFunction = '';
originalModel: any;
modifiedModel: any;
constructor(hub: Hub, container: Container, state: IrState & MonacoPaneState) {
super(hub, container, state);
this.passesColumn = this.domRoot.find('.passes-column');
this.passesList = this.domRoot.find('.passes-list');
this.body = this.domRoot.find('.llvm-opt-pipeline-body');
const selector = this.domRoot.get()[0].getElementsByClassName('function-selector')[0];
if (!(selector instanceof HTMLSelectElement)) {
throw new Error('.function-selector is not an HTMLSelectElement');
}
/*const instance = new TomSelect(selector, {
sortField: 'name',
valueField: 'id',
labelField: 'name',
searchField: ['name'],
options: [
{id: 1, name: 'Assembly'},
{id: 2, name: 'Compiler stdout'},
{id: 3, name: 'Compiler stderr'},
{id: 4, name: 'Execution stdout'},
{id: 5, name: 'Execution stderr'},
{id: 6, name: 'GNAT Expanded Code'},
{id: 7, name: 'GNAT Tree Code'},
],
items: [],
render: {
option: (item, escape) => {
return `<div>${escape(item.name)}</div>`;
},
},
dropdownParent: 'body',
plugins: ['input_autogrow'],
onChange: value => {
//if (picker.classList.contains('lhsdifftype')) {
// this.lhs.difftype = parseInt(value as any as string);
// this.lhs.refresh();
//} else {
// this.rhs.difftype = parseInt(value as any as string);
// this.rhs.refresh();
//}
//this.updateState();
},
});*/
this.functionSelector = new TomSelect(selector, {
valueField: 'value',
labelField: 'title',
searchField: ['title'],
dropdownParent: 'body',
plugins: ['input_autogrow'],
sortField: 'title',
onChange: e => this.onFnChange(e as any as string),
});
//this.functionSelector.addOption({
// title: "Test",
// value: "x"
//});
//this.functionSelector.addOption({
// title: "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest",
// value: "y"
//});
//this.functionSelector.addOption({
// title: "alpha",
// value: "a"
//});
this.clickCallback = this.onClickCallback.bind(this);
this.keydownCallback = this.onKeydownCallback.bind(this);
$(document).on('click', this.clickCallback);
$(document).on('keydown', this.keydownCallback);
}
override getInitialHTML(): string {
return $('#llvm-opt-pipeline').html();
}
override createEditor(editorRoot: HTMLElement): monaco.editor.IStandaloneCodeEditor {
return monaco.editor.create(
override createEditor(editorRoot: HTMLElement): monaco.editor.IStandaloneDiffEditor {
const editor = monaco.editor.createDiffEditor(
editorRoot,
extendConfig({
language: 'llvm-ir',
@@ -62,6 +141,10 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneCodeEdi
automaticLayout: true,
})
);
this.originalModel = monaco.editor.createModel('', 'llvm-ir');
this.modifiedModel = monaco.editor.createModel('', 'llvm-ir');
editor.setModel({original: this.originalModel, modified: this.modifiedModel});
return editor;
}
override registerOpeningAnalyticsEvent(): void {
@@ -115,9 +198,9 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneCodeEdi
//console.log(compilerId, compiler, result);
if (this.compilerInfo.compilerId !== compilerId) return;
if (result.hasLLVMOptPipelineOutput) {
this.showIrResults(result.llvmOptPipelineOutput);
this.updateResults(result.llvmOptPipelineOutput as LLVMOptPipelineOutput);
} else if (compiler.supportsLLVMOptPipelineView) {
this.showIrResults([{text: '<No output>'}]);
//this.showIrResults([{text: '<No output>'}]); // TODO
}
}
@@ -128,13 +211,31 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneCodeEdi
this.compilerInfo.treeId = treeId;
this.updateTitle();
if (compiler && !compiler.supportsLLVMOptPipelineView) {
this.editor.setValue('<LLVM IR output is not supported for this compiler>');
//this.editor.setValue('<LLVM IR output is not supported for this compiler>');
}
}
showIrResults(result: any[]): void {
this.irCode = result;
this.editor.getModel()?.setValue(result.length ? _.pluck(result, 'text').join('\n') : '<No LLVM IR generated>');
updateResults(results: LLVMOptPipelineOutput): void {
this.results = results;
//const functions = Object.keys(result);
this.functionSelector.clearOptions();
this.functionSelector.clearActiveOption();
const keys = Object.keys(results);
if (keys.length === 0) {
this.functionSelector.addOption({
title: '<No functions available>',
value: '<No functions available>',
});
}
for (const fn of keys) {
this.functionSelector.addOption({
title: fn,
value: fn,
});
}
//this.irCode = result;
/*this.editor.getModel()?.setValue(result.length ? _.pluck(result, 'text').join('\n') : '<No LLVM IR generated>');
if (!this.isAwaitingInitialResults) {
if (this.selection) {
@@ -142,6 +243,74 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneCodeEdi
this.editor.revealLinesInCenter(this.selection.startLineNumber, this.selection.endLineNumber);
}
this.isAwaitingInitialResults = true;
}*/
//const x = result[Object.keys(result)[0]][0];
//this.editor.getModel()?.setValue(x.before.map(y => y.text).join("\n") + x.after.map(y => y.text).join("\n"));
}
onFnChange(name: string) {
this.selectedFunction = name;
const passes = this.results[name];
this.passesList.empty();
for (const [i, pass] of passes.entries()) {
const changedClass = pass.irChanged ? 'changed' : '';
this.passesList.append(`<div data-i="${i}" class="pass ${changedClass}">${_.escape(pass.name)}</div>`);
}
const passDivs = this.passesList.find('.pass');
passDivs.on('click', e => {
const target = e.target;
this.passesList.find('.active').removeClass('active');
$(target).addClass('active');
this.displayPass(parseInt(target.getAttribute('data-i') as string));
});
this.resize(); // pass list width may change
}
displayPass(i: number) {
const pass = this.results[this.selectedFunction][i];
console.log(pass);
const before = pass.before.map(x => x.text).join('\n');
const after = pass.after.map(x => x.text).join('\n');
console.log(this.editor.getModel());
console.log(this.editor.getModel()?.original);
this.editor.getModel()?.original.setValue(before);
this.editor.getModel()?.modified.setValue(after);
}
onClickCallback(e: JQuery.ClickEvent) {
this.isPassListSelected = (this.passesList.get(0) as HTMLElement).contains(e.target);
}
onKeydownCallback(e: JQuery.KeyDownEvent) {
if (this.isPassListSelected) {
if (e.key === 'ArrowUp') {
e.preventDefault();
const active = this.passesList.find('.active');
const prev = active.prev().get(0);
if (prev) {
active.removeClass('active');
$(prev).addClass('active');
scrollIntoView(prev, {
scrollMode: 'if-needed',
block: 'nearest',
});
this.displayPass(parseInt(prev.getAttribute('data-i') as string));
}
}
if (e.key === 'ArrowDown') {
e.preventDefault();
const active = this.passesList.find('.active');
const next = active.next().get(0);
if (next) {
active.removeClass('active');
$(next).addClass('active');
scrollIntoView(next, {
scrollMode: 'if-needed',
block: 'nearest',
});
this.displayPass(parseInt(next.getAttribute('data-i') as string));
}
}
}
}
@@ -152,10 +321,13 @@ export class LLVMOptPipeline extends MonacoPane<monaco.editor.IStandaloneCodeEdi
width: (this.domRoot.width() as number) - (this.passesColumn.width() as number),
height: (this.domRoot.height() as number) - topBarHeight,
});
(this.body.get(0) as HTMLElement).style.height = (this.domRoot.height() as number) - topBarHeight + 'px';
});
}
override close(): void {
$(document).off('click', this.clickCallback);
$(document).off('keydown', this.keydownCallback);
this.eventHub.unsubscribe();
this.eventHub.emit('llvmOptPipelineViewClosed', this.compilerInfo.compilerId);
this.editor.dispose();
+7
View File
@@ -554,3 +554,10 @@ a {
color: #17a2b8;
background-color: rgba(49, 54, 60, 0.85);
}
.llvm-opt-pipeline-body .passes-column .passes-list div {
background: rgba(255, 255, 255, 0.1);
&:hover, &.active {
background: rgba(255, 255, 255, 0.2);
}
}
+7
View File
@@ -351,3 +351,10 @@ div.argmenuitem span.argdescription {
background-color: darken(rgba(248, 249, 250, 0.85), 3%);
border: 1px solid #d2d3d4;
}
.llvm-opt-pipeline-body .passes-column .passes-list div {
background: rgba(0, 0, 0, 0.1);
&:hover, &.active {
background: rgba(0, 0, 0, 0.2);
}
}
@@ -0,0 +1,35 @@
// Copyright (c) 2022, Compiler Explorer Authors
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
export type OutputLine = {text: string};
// Pass name with before / after dump
export type Pass = {
name: string;
after: OutputLine[];
before: OutputLine[];
irChanged: boolean;
};
export type LLVMOptPipelineOutput = Record<string, Pass[]>;
+8 -2
View File
@@ -329,8 +329,14 @@
#llvm-opt-pipeline
.top-bar.btn-toolbar.bg-light(role="toolbar")
include font-size.pug
div(style="display: flex; overflow: hidden;")
.passes-column(style="color: white; min-width: 100px; max-width: 20%;") Passes:
.btn-group.btn-group-sm
.input-group.input-group-sm.mb-auto
.input-group-prepend
label.input-group-text
| Function:&nbsp;
select.llvm-opt-function-picker.function-selector(placeholder="Select function")
div.llvm-opt-pipeline-body
.passes-column Passes:
.passes-list
.monaco-placeholder