diff options
author | Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> | 2022-06-30 19:53:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 01:53:02 +0200 |
commit | ed1a4e6b2794e096ecf049a64ed4944733f81b94 (patch) | |
tree | cc25548f69a2b00ed561ca61ba091ec299739b27 /lib/compilers | |
parent | d0a7a22bfa7503547c9d5c35c3d9e24e6dd311ad (diff) | |
download | compiler-explorer-ed1a4e6b2794e096ecf049a64ed4944733f81b94.tar.gz compiler-explorer-ed1a4e6b2794e096ecf049a64ed4944733f81b94.zip |
LLVM Optimization Pass Viewer (#3769)gh-3514
Diffstat (limited to 'lib/compilers')
-rw-r--r-- | lib/compilers/argument-parsers.js | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js index bec330b87..ce80e74b7 100644 --- a/lib/compilers/argument-parsers.js +++ b/lib/compilers/argument-parsers.js @@ -22,9 +22,13 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import path from 'path'; +import process from 'process'; + import _ from 'underscore'; import {logger} from '../logger'; +import * as props from '../properties'; import * as utils from '../utils'; export class BaseParser { @@ -143,15 +147,51 @@ export class ClangParser extends BaseParser { compiler.compiler.irArg = ['-Xclang', '-emit-llvm', '-fsyntax-only']; } + if ( + BaseParser.hasSupport(options, '-mllvm') && + this.mllvmOptions.has('--print-before-all') && + this.mllvmOptions.has('--print-after-all') + ) { + compiler.compiler.supportsLLVMOptPipelineView = true; + compiler.compiler.llvmOptArg = ['-mllvm', '--print-before-all', '-mllvm', '--print-after-all']; + compiler.compiler.llvmOptModuleScopeArg = []; + if (this.mllvmOptions.has('--print-module-scope')) { + compiler.compiler.llvmOptModuleScopeArg = ['-mllvm', '-print-module-scope']; + } + } + if (BaseParser.hasSupport(options, '-fcolor-diagnostics')) compiler.compiler.options += ' -fcolor-diagnostics'; if (BaseParser.hasSupport(options, '-fno-crash-diagnostics')) compiler.compiler.options += ' -fno-crash-diagnostics'; } static async parse(compiler) { - const options = await ClangParser.getOptions(compiler, '--help'); - this.setCompilerSettingsFromOptions(compiler, options); - return compiler; + try { + const options = await ClangParser.getOptions(compiler, '--help'); + + const EXAMPLES_PATH = props.get('builtin', 'sourcePath', './examples/'); + let filename = path.join(EXAMPLES_PATH, 'c++/default.cpp'); + if (!path.isAbsolute(filename)) filename = path.join(process.env.PWD, filename); + + this.mllvmOptions = new Set( + _.keys(await ClangParser.getOptions(compiler, `-mllvm --help-list-hidden ${filename} -c`, false)), + ); + this.setCompilerSettingsFromOptions(compiler, options); + return compiler; + } catch (error) { + logger.error('Error while trying to generate llvm backend arguments'); + logger.debug(error); + } + } + + static async getOptions(compiler, helpArg, populate = true) { + const optionFinder = /^\s*(--?[\d+,<=>[\]a-z|-]*)\s*(.*)/i; + const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' ')); + const options = result.code === 0 ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {}; + if (populate) { + compiler.possibleArguments.populateOptions(options); + } + return options; } } |