aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers
diff options
context:
space:
mode:
authorMosè Giordano <giordano@users.noreply.github.com>2024-04-02 05:08:35 +0200
committerGitHub <noreply@github.com>2024-04-01 22:08:35 -0500
commit8ad14193681dd29b6c02e920ed8bd58d6f866988 (patch)
tree2a36ae93f67244dcd376d3884083c3141c65fe01 /lib/compilers
parentf5efd390fa7aeb8c1ab2a47de20350734fbfb597 (diff)
downloadcompiler-explorer-8ad14193681dd29b6c02e920ed8bd58d6f866988.tar.gz
compiler-explorer-8ad14193681dd29b6c02e920ed8bd58d6f866988.zip
[julia] Add LLVM IrView (#6285)gh-11202
Julia is based on LLVM like other toolchains supported by Compiler Explorer, and it can emit LLVM IR, but at the moment we only expose it via the flag `--format=llvm` to the compiler wrapper. With this PR we add a proper LLVM IR viewer, like the other LLVM-based toolchains. We add a new option for the wrapper to emit the entire LLVM module, which has the benefit of being parsable by Compiler Explorer, so that we can automatically filter out debug information and metadata annotations. Preview (from https://github.com/compiler-explorer/compiler-explorer/issues/4597#issuecomment-2018956112): ![image](https://github.com/compiler-explorer/compiler-explorer/assets/765740/7c2f80b4-9c92-4761-9f6e-393d0ad26935) We removed the custom `<[source code line] [number of output lines] [function name] [method types]>` line in the output of the `code_*` functions, together with the custom ASM parsing, because they invalidate the output (it isn't valid ASM nor LLVM), and create more problems than they solve. This PR was prepared in collaboration with @vchuravy. This should eventually address #4597, once inlined LLVM functions are handled by the IR parser in Compiler Explorer, I think @vchuravy can comment more on that issue. --------- Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
Diffstat (limited to 'lib/compilers')
-rw-r--r--lib/compilers/julia.ts45
1 files changed, 10 insertions, 35 deletions
diff --git a/lib/compilers/julia.ts b/lib/compilers/julia.ts
index 5402dd08b..a4f6493c0 100644
--- a/lib/compilers/julia.ts
+++ b/lib/compilers/julia.ts
@@ -24,7 +24,6 @@
import path from 'path';
-import type {ParsedAsmResultLine} from '../../types/asmresult/asmresult.interfaces.js';
import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
@@ -42,6 +41,9 @@ export class JuliaCompiler extends BaseCompiler {
constructor(info: PreliminaryCompilerInfo, env) {
super(info, env);
+ this.compiler.supportsIrView = true;
+ this.compiler.irArg = ['--format=llvm-module'];
+ this.compiler.minIrArgs = ['--format=llvm-module'];
this.compiler.demangler = '';
this.demanglerClass = null;
this.compilerWrapperPath =
@@ -58,39 +60,6 @@ export class JuliaCompiler extends BaseCompiler {
return [];
}
- override async processAsm(result, filters, options) {
- const lineRe = /^<(\d+) (\d+) ([^ ]+) ([^>]*)>$/;
- const bytecodeLines = result.asm.split('\n');
- const bytecodeResult: ParsedAsmResultLine[] = [];
- // Every method block starts with a introductory line
- // <[source code line] [output line number] [function name] [method types]>
- // Check for the starting line, add the method block, skip other lines
- let i = 0;
- while (i < bytecodeLines.length) {
- const line = bytecodeLines[i];
- const match = line.match(lineRe);
-
- if (match) {
- const source = parseInt(match[1]);
- let linenum = parseInt(match[2]);
- linenum = Math.min(linenum, bytecodeLines.length);
- const funname = match[3];
- const types = match[4];
- let j = 0;
- bytecodeResult.push({text: '<' + funname + ' ' + types + '>', source: {line: source, file: null}});
- while (j < linenum) {
- bytecodeResult.push({text: bytecodeLines[i + 1 + j], source: {line: source, file: null}});
- j++;
- }
- bytecodeResult.push({text: '', source: {file: null}});
- i += linenum + 1;
- continue;
- }
- i++;
- }
- return {asm: bytecodeResult};
- }
-
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string) {
return [];
}
@@ -109,6 +78,7 @@ export class JuliaCompiler extends BaseCompiler {
options: string[],
inputFilename: string,
execOptions: ExecutionOptions & {env: Record<string, string>},
+ filters?: ParseFiltersAndOutputOptions,
): Promise<CompilationResult> {
if (!execOptions) {
execOptions = this.getDefaultExecOptions();
@@ -122,12 +92,17 @@ export class JuliaCompiler extends BaseCompiler {
const juliaOptions = [this.compilerWrapperPath, '--'];
juliaOptions.push(...options);
- juliaOptions.push(this.getOutputFilename(dirPath, this.outputFilebase));
+ juliaOptions.push(
+ options.includes('--format=llvm-module')
+ ? this.getIrOutputFilename(inputFilename, filters)
+ : this.getOutputFilename(dirPath, this.outputFilebase),
+ );
const execResult = await this.exec(compiler, juliaOptions, execOptions);
return {
compilationOptions: juliaOptions,
...this.transformToCompilationResult(execResult, inputFilename),
+ languageId: this.getCompilerResultLanguageId(filters),
};
}
}