Commit Graph
125 Commits
Author SHA1 Message Date
narpfel 68db4ca482 Remove unused method AsmParser.labelFindFor (#8022)
`AsmParser.labelFindFor` was only called in tests.
2025-08-12 08:50:53 -05:00
narpfel f289b79f1d Don’t filter .set directives that declare merged functions (#8021)
Resolves #2409.
2025-08-11 14:31:44 -05:00
narpfel 82407976d1 Accept multiple dots in symbol names for jump to label (#8018)
Some compilers emit symbol names with multiple dots, e. g. Clang for
static data (like string literals) or GCC for function clones (e. g. due
to interprocedural constant propagation).

Test cases: https://godbolt.org/z/dGbGncnh8,
https://godbolt.org/z/dhrGGqrjo
2025-08-11 14:28:06 -05:00
Ofek a85260bc27 Fix #8009: Allow quotes as part of labels (#8015) 2025-08-09 20:21:31 +02:00
Shawn Zhong f92b6f388a Remove dangling empty braces in PTX (#7960)
After directive filtering, there will be dangling `{}` spanning two
lines. This PR attempts to remove them.

For example, 
```
.section    .debug_abbrev
{
.b8 1
}
.section    .debug_info
{
.b32 70
.b32 .debug_abbrev
}
```

The above assembly used to become the following text after filtering
directive

```
{
}
{
}
```
2025-07-30 10:40:00 -05:00
Shawn Zhong 227595d83e Fix PTX parsing with predicate (#7959)
Recogonize lines with predicate (e.g., `@%p1`, `@!%p1`) as instructions:
- `@%p1 ld.global.v4.b32 { %r9, %r10, %r11, %r12 }, [ %rd3 + 0 ];`
- `@%p2 bra $L__BB0_28;`
- `@!%p2 bra $L__BB0_28;`

| Before | After | 
| --- | --- |
| <img width="580" height="320" alt="image"
src="https://github.com/user-attachments/assets/c3913b09-ce04-44c5-a4c0-fa69805cf1d7"
/> | <img width="566" height="323" alt="image"
src="https://github.com/user-attachments/assets/08308b3d-df00-4cf1-8321-203c374c27c3"
/> |



From
https://docs.nvidia.com/cuda/parallel-thread-execution/#instruction-statements:

> Instructions have an optional guard predicate which controls
conditional execution. The guard predicate follows the optional label
and precedes the opcode, and is written as @p, where p is a predicate
register. The guard predicate may be optionally negated, written as @!p.

Implementation-wise, added `(@!?%\w+\s+)?` to existing default
`hasOpcodeRe` (`/^\s*(%[$.A-Z_a-z][\w$.]*\s*=\s*)?[A-Za-z]/`)
2025-07-30 10:34:59 -05:00
Shawn ZhongandMatt Godbolt 8befc91a79 Add Triton language and compiler (#7919)
Close #5530. Infra:
https://github.com/compiler-explorer/infra/pull/1711. Previous work by
@siboehm at #5531


## Summary

This pull request introduces support for the
[Triton](https://github.com/triton-lang/triton) language, a Python-based
DSL for writing highly efficient GPU kernels.


- [x] **New Language Support**: I've added comprehensive support for the
Triton programming language, allowing users to compile and inspect
Triton kernels within Compiler Explorer. (c.f.,
`lib/compilers/triton.ts`)
- [x] **Python Wrapper for Compilation**: A new Python wrapper script
(`triton_wrapper.py`) has been introduced to manage Triton compilation,
patching its behavior to dump compiled kernels and intermediate
representations without requiring actual execution, and consolidating
the output for Compiler Explorer.
- [x] **Device Assembly View**: Enables viewing of generated device
assembly code (e.g., PTX, AMDGCN) and various intermediate
representations (MLIR, LLVM IR) produced by the Triton compiler.
- [x] **MLIR Parsing**: New parsers (`asm-parser-mlir.ts` and
`mlir-pass-dump-parser.ts`) have been added to correctly interpret and
display MLIR assembly and optimization pass dumps, including source
location information.
- [x] **Multi-Version & Multi-Backend Support**: Painstakingly includes
all 8 versions (from 2.2.0 to 3.3.1) of Triton that supports Python
3.12. Supports both CUDA and HIP backend for Triton 3.

## Screenshots

Source and assembly:
<img width="1354" height="789" alt="image"
src="https://github.com/user-attachments/assets/c29650ff-2073-40e0-a9e6-ff8377094b5e"
/>



Device view for MLIR and LLVM IR: 
<img width="1402" height="670" alt="image"
src="https://github.com/user-attachments/assets/43dd5c68-ca78-41b1-9865-e97ffe3ef73c"
/>

Opt pipeline viewer:
<img width="1408" height="668" alt="image"
src="https://github.com/user-attachments/assets/429eef8c-aaac-4781-aafa-39ef0ffc7241"
/>

Diff of TTIR in Triton 3.3.1 vs 2.3.0:
<img width="1580" height="726" alt="image"
src="https://github.com/user-attachments/assets/a928c893-dd9a-4c3a-a048-14046e56a14c"
/>

CUDA & HIP:
<img width="1596" height="800" alt="image"
src="https://github.com/user-attachments/assets/c18800c3-cfad-4e5e-96de-ba92c9f236ea"
/>

## Implementation Details (and Notes for Reviewers)

- For Device Assembly View, I Implemented `MlirAsmParser` for parsing
MLIR assembly. Technically MLIR is not an assembly language, but there
is no better choice to make the source line map work w/ device view.
- I Implemented `MlirPassDumpParser` for processing MLIR optimization
pass dumps. I tried to subclass `LlvmPassDumpParser`, but they turn out
to be too different to worth doing it.
- `LlvmPassDumpParser` made some assumptions that do not hold true for
MLIR passed. Some effort is put to make sure that the passes are
properly diff-ed, since some passes can run multiple times and also
sometimes pass can be nested (i.e., some number of `before`s followed by
some number of `after`s)
- A lot of effort is put into `patch_triton` to make sure that the we
only compile the kernel without actually running it, and that needs to
work across all the versions we support.

## Steps to Run Locally

1. Clone https://github.com/ShawnZhong/compiler-explorer-infra.git
2. Install Triton to `/opt/compiler-explorer/triton`:
```sh
$ cd compiler-explorer-infra
$ ./bin/ce_install install triton
$ ls /opt/compiler-explorer/triton
# v2.2.0  v2.3.0  v2.3.1  v3.0.0  v3.1.0  v3.2.0  v3.3.0  v3.3.1
```
3. Clone https://github.com/ShawnZhong/compiler-explorer.git and
checkout branch `triton`
4. Run Compiler Explorer
```sh
make EXTRA_ARGS='--language triton' dev
```
5. Enjoy

---------

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2025-07-30 10:15:28 -05:00
Jacob Panov d9a124fe8d Fix to ensure labels are not mistaken for comments (#7926)
Ensured labels are not mistaken for comments by skipping comment
filtering when the line matches a label definition

Added a regression test verifying that labels starting with “@” remain
visible even when comment filtering is enabled

Fixes #7889 

Tested with 
npm run lint
npm run ts-check
npm run test-min
npm run check-frontend-imports
make check
2025-07-21 12:06:49 +03:00
Jeremy Rifkin e0958c8613 Add support for demangling quoted labels (#7846)
This PR updates a dozen regular expressions related to labels and
demangling to allow quoted names which gcc trunk is now emitting:


![image](https://github.com/user-attachments/assets/efc727d1-a056-4544-8196-4276bb14fc02)


Resolves #7729
2025-06-20 17:33:49 -05:00
Patrick Quist b5e7219baa Add dedicated PTX assembly parser to fix directive filtering (#7839) 2025-06-20 14:46:24 +02:00
Mats Jun Larsen b90ac4c382 Ban unused imports (#7827) 2025-06-18 14:21:25 +00:00
Matt GodboltandClaude 04972d6aaa Refactor AsmParser to extract testable components (#7777)
## Summary
- Extracted source line handling logic into a dedicated
`SourceLineHandler` class that consolidates .loc, .stabs, and .6502
directive parsing
- Extracted label processing logic into a `LabelProcessor` class with
methods for finding used labels and filtering
- Created a `ParsingState` class to manage parsing loop state variables
in a centralized way
- Fully integrated all components into the main `AsmParser` class,
replacing the original complex parsing loop

## Changes Made
- **SourceLineHandler**: Unifies `.loc`, `.d2line`, `.cv_loc`, `.dbg`,
`.stabn`, and 6502 debug directive parsing
- **LabelProcessor**: Handles complex label detection, filtering, and
cleanup logic with MIPS/non-MIPS support
- **ParsingState**: Encapsulates state management during parsing
(inNvccCode, inCustomAssembly, etc.)
- **Integration**: All components work together through well-defined
interfaces

## Verification
- ✅ All 1082+ tests pass, including new subclass compatibility tests
from PR #7779
- ✅ All 670+ filter tests pass, confirming exact behavior preservation
- ✅ Added comprehensive unit tests for all new components (32 tests
total)
- ✅ TypeScript compilation and linting pass
- ✅ No performance regression in core functionality

## Bug Fix Discovered
The refactoring inadvertently **fixes issue #7781** - EWAVR label
detection bug:
- **Before**: EWAVR couldn't find labels in usage contexts like `ldi
r16, HIGH(_data)` due to `labelFindFor()` returning definition regex
- **After**: Now correctly uses `identifierFindRe` to find labels in
usage contexts
- Updated tests to reflect the corrected behavior

## Benefits
- Reduced complexity in the main `processAsm` method (from 180+ lines to
more manageable chunks)
- Extracted highly testable, focused components with single
responsibilities
- Eliminated code duplication between source handling methods
- Centralized state management reduces scattered variable handling
- Maintained full backward compatibility and exact behavior
- Fixed EWAVR label detection bug as a side effect

🤖 Generated with [Claude Code](https://claude.ai/code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-06-11 18:22:44 -05:00
narpfelandMatt Godbolt 98c91227fa Fix go-to label with position-independent code (#7522)
Resolves #7521.

With this PR, `@...` suffixes are included in the clickable area for
go-to label.

This also affects PowerPC, where `@...` suffixes are a bit more common
(`@ha` and `@l` will also be marked as clickable).

---------

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2025-04-17 12:25:28 -05:00
Ofek e01aa3e691 Various type improvements 2025-02-26 02:07:09 +02:00
Stephen HeumannandMatt Godbolt 5a72fa0659 Add support for ORCA/C (#7368)
[ORCA/C](https://github.com/byteworksinc/ORCA-C) is a C compiler that
natively runs on and targets the Apple IIGS. ORCA/C and the programs it
generates can be run on modern Linux systems by using an emulation tool
called [Golden Gate](https://goldengate.gitlab.io).

This adds support for ORCA/C (run via Golden Gate) in Compiler Explorer.
It uses its own assembly format and objdumper (provided by Golden Gate),
so support for those is added. An extra configuration option was also
added to support execution via an emulator, bypassing the usual check
that executables can run natively. Asm docs for the WDC 65C816 processor
were also added.

ORCA/C and Golden Gate are not Free Software, but their rights holders
have given permission for them to be used on Compiler Explorer. Tarballs
for them can be supplied privately. See infra PR:
compiler-explorer/infra#1521

---------

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2025-02-18 10:28:10 -06:00
Mats Jun Larsen 5eea63328f Migrate to Biome for linting and formatting (#7033) 2025-02-02 17:54:31 +00:00
Marc Auberer 2d4a8d59fa Fix function define regex in pass dump parser (#7330)
Function in LLVM IR can also contain `-` characters without being
enquoted.
2025-01-29 11:30:16 -06:00
Matt Godbolt ed825b8aa2 Some tidying up of the asm parser code (#7329)
- use `Set` and `Map`
- reflow comments
- remove redundant `!!`
- rephrase iterative "follow the chain of weak symbols" to be recursive,
removing artificial limit.
2025-01-29 10:29:06 -06:00
Waqar Ahmed 650e706c4d Unset context.prevLabel when a label gets filtered (#7315)
Otherwise subsequent unused label's directives end up being included in
the processed asm even though the label itself got filtered
2025-01-29 08:40:07 -06:00
Matt Godbolt 3b507a6db3 Handle ARM's .set usage (#7322)
Treats `.set` as an "alias" for the set of labels referred to, and
doesn't filter alias-creating `.set` in used paths even if directive
filtering is on. Only works for `.set <something>, .` with an optional
`+ 0`.

Also changes a silly loop that was looping N times doing the same thing
if `inFunction && isDataDefinition`, though quite possibly that's broken
in a different way. No tests changed, anyway.

Adds a new test for the new behaviour.

Closes #1799
2025-01-29 10:07:43 +02:00
Matt Godbolt e452db56fc Special casing for msp430 (#7317)
- Make a special msp430 handler that breaks lines on `{` to fix the
weird inlining behaviour unique to msp430 output.

Closes #295
2025-01-28 10:00:04 -06:00
Matt Godbolt b6ead25038 Support .base64 as a data indicator. (#7281)
Fixes #7280

@partouf I expect this will need a fix in the C++ code too, right?
2025-01-16 15:58:05 -06:00
kevinjeon-g fd6a07d233 Add source<>disassembly highlighting for dex2oat (#7248)
oatdump, the dex2oat dump tool, doesn't output any information that can
be used to associate disassembly with source lines. However, dex2oat's
output optimization CFG (classes.cfg) does contain a final disassembly
stage that retains dex_pc.

Lines of disassembly from oatdump can be associated with lines of
disassembly in classes.cfg, and through the dex_pcs there, be mapped
back to the D8 .smali output, which does contain source line
information.
2025-01-08 11:17:17 -06:00
Waqar Ahmed e0e2420482 Improve odin codegen processing (#7228)
- Builtin runtime functions __$startup_runtime, __$cleanup_runtime, __$*
are now filtered out
- Label matching regex is fixed for odin, see OdinAsmParser class. This
ensures we filter out all labels that don't belong to the current file
- Slightly improved editor support, auto bracket closing and commenting
via keyboard shortcuts works now
- procedures within the file are automatically @require as requested by
GingerBill (odin lang creator).

There still are a lot of unused labels with data definitions that dont
get filtered out.

#7210
2025-01-06 15:49:15 -06:00
Spencer Fricke 05f86a38dd Add preliminary Slang support (#7151)
Part of
https://github.com/compiler-explorer/compiler-explorer/issues/2331 and
similar to [my GLSL
change](https://github.com/compiler-explorer/compiler-explorer/pull/6883)

[Slang](https://shader-slang.com/) is a GPU focused shading language
that has been worked on for years. Last week [The Khronos
Group](https://www.khronos.org/news/press/khronos-group-launches-slang-initiative-hosting-open-source-compiler-contributed-by-nvidia)
will now be running the project as open governance. The latest [Vulkan
SDK](https://www.lunarg.com/lunarg-releases-vulkan-sdk-1-3-296-0-for-windows-linux-macos/)
has also added a build of `Slangc` (slang compiler).

This change adds support for Slang (the language) as a front end with
`Slangc` (the compiler) as the only compiler. Slang can be used for
things like GLSL/HLSL, but that is for a future PR.

I am in contacts with people on the Slang development and plan to
support things for Slang as well as the other GPU related shading
languages

--- 

of course, screen shots as well


![image](https://github.com/user-attachments/assets/c9f6460b-b779-4ff5-b0bb-5a7eff543de1)


![image](https://github.com/user-attachments/assets/b2dbdd5a-c031-4110-ab9d-ed76b9881ad8)
2024-12-04 04:45:50 -06:00
Spencer Fricke 721b45b35b Add richer comments to SPIR-V assembly output (#7052) 2024-11-08 16:27:32 +01:00
Spencer Fricke 35527dd3b4 Fix OpLabel being in previous block (#7054)
SPIR-V is like LLVM in there are "Blocks" used for Control Flow,
`OpLabel` has a special text in the SPIR-V spec

> A block always starts with an
[OpLabel](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpLabel)
instruction. This may be immediately preceded by an
[OpLine](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpLine)
instruction, but the OpLabel is considered as the beginning of the
block.

But currently the coloring is off-by-1


![image](https://github.com/user-attachments/assets/4ec20d7d-0beb-49de-ba32-204f708a08c2)

This change now moves it up a line so it is the start of the block


![image](https://github.com/user-attachments/assets/3d6d1742-469f-4b29-a644-7677056bce9e)

This can be better seen why looking at the [SPIR-V
Visualizer](spirv-visualizer) tool output


![image](https://github.com/user-attachments/assets/10cbad0b-f093-4bd5-98dd-b38e78615218)
2024-11-03 19:37:45 +09:00
Ofek f6438f9c4d Store times in numbers only (#7023)
Also fixes #4655
2024-10-26 18:43:59 +03:00
Ofek c1985d64a1 Tsification binge #7 (#6974) 2024-10-25 12:19:04 +03:00
Ofek 2df8d32758 Tsify #6 (#6941)
Another tsification batch. 347 to go and I'm running out of easy fixes
:(
2024-10-22 21:41:44 +03:00
Ofek 7097a240a7 Introduce opt-pipeline for ClangIr (#6917)
Thank @Lancern for the CIR flags analogous to clang's
`--print-before|after-all.`


![cir](https://github.com/user-attachments/assets/78742d83-799d-40cd-bcef-7a2e69a83c54)
2024-09-30 22:11:30 -05:00
Steve ee2dc8ab00 Update asm parser and add support for IL and IL disassembler (#6856)
Supersedes #6842 

- We now have the upstream issue of `JitDisasmAssemblies` fixed. Enable
it for net9.0+.
- Update asm-parser to support CoreCLR and NativeAOT (Fixes #6833)
- Adding support for IL language
- Adding support for IL disassembler
- Fixes #6629
2024-09-29 13:15:47 -05:00
Ofek f715dc2932 More tsification (#6877)
About half way through. Only 708 tsification errors to go..
2024-09-28 10:32:36 +03:00
Ofek 9ef46fbafe Binge of (mostly) mindless tsification (#6838)
Turned on `noImplicitAny` in tsconfig, then went around fixing some
random easy stuff.
Hopefully tsification-PRs with more real content coming up.
2024-09-07 14:36:43 +03:00
Stephen Tozer be9c26b6de Add support for filtering debug records in LLVM IR (#6618)
In LLVM, debug records (`#dbg_value`) are now being printed by default
in LLVM IR instead of debug intrinsics (`call void @llvm.dbg.value`). As
the debug info filters don't recognize debug records, this means [IR
output from clang-19 (trunk)](https://godbolt.org/z/fPbdEhYsn) and
onwards will always show debug variable output.

This patch adds debug records to the filters to fix this.
2024-06-17 21:07:21 -05:00
Jason Francis 97a39232b2 Detect local label assignments as directives on MIPS (#6392) (#6467) 2024-05-29 18:13:16 +02:00
Ofek bcb397f56b Add noUnusedLocals to tsconfig + fix the new alerts (#6396)
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE
IT
Thanks for taking the time to improve CE. We really appreciate it.
Before opening the PR, please make sure that the tests & linter pass
their checks,
  by running `make check`.
In the best case scenario, you are also adding tests to back up your
changes,
  but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->
2024-05-14 18:46:22 +03:00
dzaima 3a6a7999b5 Hanfle filtering tail call void @llvm.dbg.* in LLVM IR (#6425)
Fixes #6416. Additionally escapes a dot in another copy of an
`@llvm.dbg` check.

Didn't find any existing tests for IR filtering to update where this
filter applies, but did make sure locally that it does start hiding the
instructions for clang-17 and clang-18.
2024-05-02 18:43:36 -05:00
Patrick Quist b8325cf0c6 eslint root setting and fixes (#6307) 2024-04-16 21:26:53 +02:00
Patrick Quist 43323b7b6c fix part of the windows tests (#6351) 2024-04-15 03:57:24 +02:00
Patrick Quist e96b125518 Add MadPascal (#6286) 2024-03-29 02:17:52 +01:00
standstaff 45ef23c940 chore: remove repetitive words (#6247)
<!-- THIS COMMENT IS INVISIBLE IN THE FINAL PR, BUT FEEL FREE TO REMOVE
IT
Thanks for taking the time to improve CE. We really appreciate it.
Before opening the PR, please make sure that the tests & linter pass
their checks,
  by running `make check`.
In the best case scenario, you are also adding tests to back up your
changes,
  but don't sweat it if you don't. We can discuss them at a later date.
Feel free to append your name to the CONTRIBUTORS.md file
Thanks again, we really appreciate this!
-->

Signed-off-by: standstaff <zhengxingru@yeah.net>
2024-03-16 09:22:15 +02:00
Ofek 8dd09d1c1f Replace the deprecated substr with substring (#6236)
Just some minor homekeeping.
2024-03-10 10:04:29 +02:00
Matt Godbolt fd3dd917f5 Vitest (#6219)
Port to vitest. Port everything to typescript. Remove chai, mocha and
chai-as-promised. Adds some docs.
2024-03-08 22:25:09 -06:00
Marc Auberer c8f0409c25 Accept tail calls for llvm.dbg filters (#6129)
This adds support for filtering tail calls to `llvm.dbg.*` intrinsics
using the regex-based filter mechanism.
Previously, normal calls were filtered out, but tail calls are not
caught by the regex so they remained in the output.
Example with the previous state: https://play.spicelang.com/z/MGGn98
2024-02-12 21:52:45 -06:00
Cassandra Beckley 4006b0a941 [SPIR-V parser] Filter OpMemberName as directive (#6106)
Filter `OpMemberName` as directive, to be consistent with `OpName`.
2024-02-09 18:45:33 +01:00
kevinjeon-g 2f6a7328b2 Add support for dex2oat (latest) (#5916)
Adds Dex2OatCompiler, which applies to the Android Java and Android
Kotlin languages. Dex2OatCompiler runs on .dex files output by
D8Compiler, which in turn runs on .class files output by JavaCompiler or
KotlinCompiler. A parser has been added for dex2oat optimization passes.
2024-01-15 15:15:05 -06:00
Anirudh Sundar Subramaniam c3f8f8665b Handle ir and machine functions separately in OptPipeline (#5902)
This patch makes a small change in how functions are handled while
parsing LLVM opt pipeline output. Specifically, it differentiates
between IR function and machine function, and while checking for the
close of function, it only checks if the corresponding function is open.

This was needed because in some targets like hexagon, the machine
functions could contain `BUNDLE`s as part of the dump and `BUNDLE`s are
also represented with opening and closing braces ({}). This was causing
assertion because the close brace for a BUNDLE was considered to be a IR
function close statement.
2024-01-08 15:32:45 -06:00
Matt Godbolt 1815ca1b99 Prettier the files, and ensure the checks check that next time 2023-12-11 22:07:10 -06:00
J. Ryan StinnettandMatt Godbolt f0e1d5d264 Add Racket optimisation pipeline (#5836)
This adds a Racket optimisation pipeline view by reusing the existing
LLVM-focused optimisation pipeline UI. A Racket-specific pass parser
translates its output into passes for the UI to present.

This new Racket optimisation pipeline view is currently only enabled for
Racket nightly, as it depends on [recent
changes](https://github.com/racket/racket/pull/4842) to Racket's
compiler output to function.

This also extends the opt pipeline view to allow customising the
function selector label as well as the options and filters for each
compiler where needed.


![image](https://github.com/compiler-explorer/compiler-explorer/assets/279572/f540b41e-fd55-4375-bb2d-a0bb977530b3)

---------

Co-authored-by: Matt Godbolt <matt@godbolt.org>
2023-12-11 19:35:45 -06:00