aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/clang.ts
diff options
context:
space:
mode:
authornickpdemarco <nickpdemarco@gmail.com>2023-10-11 14:43:05 -0400
committernickpdemarco <nickpdemarco@gmail.com>2023-10-11 14:43:05 -0400
commit9cda199e40c920fcc9c53082b0dabb17d31a8b7f (patch)
treea4e9a03a9feea17376f5990e19c12818d32ec95e /lib/compilers/clang.ts
parent55a2b1455f823026c78b9219f93799af00ef60ae (diff)
parent10796b3696cf1eef928de8c750b4d3350ee0c2db (diff)
downloadcompiler-explorer-9cda199e40c920fcc9c53082b0dabb17d31a8b7f.tar.gz
compiler-explorer-9cda199e40c920fcc9c53082b0dabb17d31a8b7f.zip
Merge main, resolve conflicts with vala
Diffstat (limited to 'lib/compilers/clang.ts')
-rw-r--r--lib/compilers/clang.ts119
1 files changed, 113 insertions, 6 deletions
diff --git a/lib/compilers/clang.ts b/lib/compilers/clang.ts
index d161e0f98..a5534aa36 100644
--- a/lib/compilers/clang.ts
+++ b/lib/compilers/clang.ts
@@ -27,13 +27,16 @@ import path from 'path';
import _ from 'underscore';
-import type {ExecutionOptions} from '../../types/compilation/compilation.interfaces.js';
+import type {BypassCache, CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ExecutableExecutionOptions, UnprocessedExecResult} from '../../types/execution/execution.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {AmdgpuAsmParser} from '../parsers/asm-parser-amdgpu.js';
import {SassAsmParser} from '../parsers/asm-parser-sass.js';
+import {HexagonAsmParser} from '../parsers/asm-parser-hexagon.js';
+import * as utils from '../utils.js';
+import {ArtifactType} from '../../types/tool.interfaces.js';
const offloadRegexp = /^#\s+__CLANG_OFFLOAD_BUNDLE__(__START__|__END__)\s+(.*)$/gm;
@@ -68,10 +71,37 @@ export class ClangCompiler extends BaseCompiler {
}
}
+ override isCfgCompiler() {
+ return true;
+ }
+
+ async addTimeTraceToResult(result: CompilationResult, dirPath: string, outputFilename: string) {
+ let timeTraceJson = '';
+ const outputExt = path.extname(outputFilename);
+ if (outputExt) {
+ timeTraceJson = outputFilename.replace(outputExt, '.json');
+ } else {
+ timeTraceJson += '.json';
+ }
+ const jsonFilepath = path.join(dirPath, timeTraceJson);
+ if (await utils.fileExists(jsonFilepath)) {
+ this.addArtifactToResult(
+ result,
+ jsonFilepath,
+ ArtifactType.timetrace,
+ 'Trace events JSON',
+ (buffer: Buffer) => {
+ return buffer.toString('utf-8').startsWith('{"traceEvents":[');
+ },
+ );
+ }
+ }
+
override runExecutable(executable, executeParameters: ExecutableExecutionOptions, homeDir) {
if (this.asanSymbolizerPath) {
executeParameters.env = {
ASAN_SYMBOLIZER_PATH: this.asanSymbolizerPath,
+ MSAN_SYMBOLIZER_PATH: this.asanSymbolizerPath,
...executeParameters.env,
};
}
@@ -88,20 +118,61 @@ export class ClangCompiler extends BaseCompiler {
return options;
}
- override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string) {
+ override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string, userOptions?: string[]) {
const options = super.optionsForFilter(filters, outputFilename);
return this.forceDwarf4UnlessOverridden(options);
}
- override runCompiler(compiler: string, options: string[], inputFilename: string, execOptions: ExecutionOptions) {
+ override async afterCompilation(
+ result,
+ doExecute,
+ key,
+ executeParameters,
+ tools,
+ backendOptions,
+ filters,
+ options,
+ optOutput,
+ stackUsageOutput,
+ bypassCache: BypassCache,
+ customBuildPath?,
+ ) {
+ const compilationInfo = this.getCompilationInfo(key, result, customBuildPath);
+
+ const dirPath = path.dirname(compilationInfo.outputFilename);
+ const filename = path.basename(compilationInfo.outputFilename);
+ await this.addTimeTraceToResult(result, dirPath, filename);
+
+ return super.afterCompilation(
+ result,
+ doExecute,
+ key,
+ executeParameters,
+ tools,
+ backendOptions,
+ filters,
+ options,
+ optOutput,
+ stackUsageOutput,
+ bypassCache,
+ customBuildPath,
+ );
+ }
+
+ override async runCompiler(
+ compiler: string,
+ options: string[],
+ inputFilename: string,
+ execOptions: ExecutionOptions & {env: Record<string, string>},
+ ) {
if (!execOptions) {
execOptions = this.getDefaultExecOptions();
}
execOptions.customCwd = path.dirname(inputFilename);
- return super.runCompiler(compiler, options, inputFilename, execOptions);
+ return await super.runCompiler(compiler, options, inputFilename, execOptions);
}
async splitDeviceCode(assembly) {
@@ -200,7 +271,7 @@ export class ClangCudaCompiler extends ClangCompiler {
override async objdump(outputFilename, result, maxSize) {
// For nvdisasm.
- const args = [outputFilename, '-c', '-g', '-hex'];
+ const args = [...this.compiler.objdumperArgs, outputFilename, '-c', '-g', '-hex'];
const execOptions = {maxOutput: maxSize, customCwd: path.dirname(outputFilename)};
const objResult = await this.exec(this.compiler.objdumper, args, execOptions);
@@ -246,7 +317,7 @@ export class ClangIntelCompiler extends ClangCompiler {
}
}
- override getDefaultExecOptions(): ExecutionOptions {
+ override getDefaultExecOptions(): ExecutionOptions & {env: Record<string, string>} {
const opts = super.getDefaultExecOptions();
opts.env.PATH = process.env.PATH + path.delimiter + path.dirname(this.compiler.exe);
@@ -261,3 +332,39 @@ export class ClangIntelCompiler extends ClangCompiler {
return super.runExecutable(executable, executeParameters, homeDir);
}
}
+
+export class ClangHexagonCompiler extends ClangCompiler {
+ static override get key() {
+ return 'clang-hexagon';
+ }
+
+ constructor(info: PreliminaryCompilerInfo, env) {
+ super(info, env);
+
+ this.asm = new HexagonAsmParser();
+ }
+}
+
+export class ClangDxcCompiler extends ClangCompiler {
+ static override get key() {
+ return 'clang-dxc';
+ }
+
+ constructor(info: PreliminaryCompilerInfo, env) {
+ super(info, env);
+
+ this.compiler.supportsIntel = false;
+ this.compiler.irArg = ['-Xclang', '-emit-llvm'];
+ // dxc mode doesn't have -fsave-optimization-record or -fstack-usage
+ this.compiler.supportsOptOutput = false;
+ this.compiler.supportsStackUsageOutput = false;
+ }
+
+ override optionsForFilter(
+ filters: ParseFiltersAndOutputOptions,
+ outputFilename: string,
+ userOptions?: string[],
+ ): string[] {
+ return ['--driver-mode=dxc', '-Zi', '-Qembed_debug', '-Fc', this.filename(outputFilename)];
+ }
+}