[all-commits] [llvm/llvm-project] 9ca1a1: [flang][Driver] Add -masm option to flang (#81490)

David Spickett via All-commits all-commits at lists.llvm.org
Tue Feb 13 02:38:51 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 9ca1a1575a337931d0e49859f83a0d5b70916abd
      https://github.com/llvm/llvm-project/commit/9ca1a1575a337931d0e49859f83a0d5b70916abd
  Author: David Spickett <david.spickett at linaro.org>
  Date:   2024-02-13 (Tue, 13 Feb 2024)

  Changed paths:
    M clang/include/clang/Driver/Options.td
    M clang/lib/Driver/ToolChains/Flang.cpp
    M clang/lib/Driver/ToolChains/Flang.h
    A flang/test/Driver/masm.f90

  Log Message:
  -----------
  [flang][Driver] Add -masm option to flang (#81490)

The motivation here was a suggestion over in Compiler Explorer. You can
use `-mllvm` already to do this but since gfortran supports `-masm`, I
figured I'd try to add it.

This is done by flang expanding `-masm` into `-mllvm x86-asm-syntax=`,
then passing that to fc1. Which then collects all the `-mllvm` options
and forwards them on.

The code to expand it comes from clang `Clang::AddX86TargetArgs` (there
are some other places doing the same thing too). However I've removed
the `-inline-asm` that clang adds, as fortran doesn't have inline
assembly.

So `-masm` for flang purely changes the style of assembly output.

```
$ ./bin/flang-new /tmp/test.f90 -o - -S -target x86_64-linux-gnu
<...>
        pushq   %rbp
$ ./bin/flang-new /tmp/test.f90 -o - -S -target x86_64-linux-gnu -masm=att
<...>
        pushq   %rbp
$ ./bin/flang-new /tmp/test.f90 -o - -S -target x86_64-linux-gnu -masm=intel
<...>
        push    rbp
```

The test is adapted from `clang/test/Driver/masm.c` by removing the
clang-cl related lines and changing the 32 bit triples to 64 bit triples
since flang doesn't support 32 bit targets.




More information about the All-commits mailing list