mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2025-12-27 10:33:59 -05:00
Adapt isOutputLikelyLlvmIr for Rust (#8253)
The existing heuristics don’t reliably recognise LLVM IR produced by `rustc` (e. g. when the generated code does not use any LLVM intrinsics), so this adds LLVM IR detection based on the `--emit=llvm-ir` and `--emit llvm-ir` command line flags.
This commit is contained in:
@@ -182,10 +182,6 @@ export interface SimpleOutputFilenameCompiler {
|
|||||||
getOutputFilename(dirPath: string): string;
|
getOutputFilename(dirPath: string): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isOutputLikelyLllvmIr(compilerOptions: string[]): boolean {
|
|
||||||
return compilerOptions && (compilerOptions.includes('-emit-llvm') || compilerOptions.includes('-mlir-to-llvmir'));
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BaseCompiler {
|
export class BaseCompiler {
|
||||||
public compiler: CompilerInfo;
|
public compiler: CompilerInfo;
|
||||||
public lang: Language;
|
public lang: Language;
|
||||||
@@ -3258,7 +3254,7 @@ export class BaseCompiler {
|
|||||||
if (this.compiler.supportsCfg && backendOptions.produceCfg && backendOptions.produceCfg.asm) {
|
if (this.compiler.supportsCfg && backendOptions.produceCfg && backendOptions.produceCfg.asm) {
|
||||||
const isLlvmIr =
|
const isLlvmIr =
|
||||||
this.compiler.instructionSet === 'llvm' ||
|
this.compiler.instructionSet === 'llvm' ||
|
||||||
(options && isOutputLikelyLllvmIr(options)) ||
|
(options && this.isOutputLikelyLlvmIr(options)) ||
|
||||||
this.llvmIr.isLlvmIr(result.asm);
|
this.llvmIr.isLlvmIr(result.asm);
|
||||||
result.cfg = await cfg.generateStructure(this.compiler, result.asm, isLlvmIr, result);
|
result.cfg = await cfg.generateStructure(this.compiler, result.asm, isLlvmIr, result);
|
||||||
}
|
}
|
||||||
@@ -3372,10 +3368,14 @@ export class BaseCompiler {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected isOutputLikelyLlvmIr(compilerOptions: string[]): boolean {
|
||||||
|
return compilerOptions.includes('-emit-llvm') || compilerOptions.includes('-mlir-to-llvmir');
|
||||||
|
}
|
||||||
|
|
||||||
async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) {
|
async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) {
|
||||||
if (
|
if (
|
||||||
result.languageId === 'llvm-ir' ||
|
result.languageId === 'llvm-ir' ||
|
||||||
(options && isOutputLikelyLllvmIr(options)) ||
|
(options && this.isOutputLikelyLlvmIr(options)) ||
|
||||||
this.llvmIr.isLlvmIr(result.asm)
|
this.llvmIr.isLlvmIr(result.asm)
|
||||||
) {
|
) {
|
||||||
return await this.llvmIr.processFromFilters(result.asm, filters);
|
return await this.llvmIr.processFromFilters(result.asm, filters);
|
||||||
|
|||||||
@@ -338,4 +338,9 @@ export class RustCompiler extends BaseCompiler {
|
|||||||
);
|
);
|
||||||
return super.runCompiler(compiler, newOptions, inputFilename, execOptions);
|
return super.runCompiler(compiler, newOptions, inputFilename, execOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override isOutputLikelyLlvmIr(options: string[]): boolean {
|
||||||
|
const emitIndex = options.indexOf('--emit');
|
||||||
|
return options.includes('--emit=llvm-ir') || (emitIndex >= 0 && options[emitIndex + 1] == 'llvm-ir');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user