[all-commits] [llvm/llvm-project] 2f9ace: [OpenMP] Introduce new flag to change offloading d...

Joseph Huber via All-commits all-commits at lists.llvm.org
Mon Jan 31 12:56:21 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 2f9ace9e9a5816684b3c19528bd4a3908b2b8ac0
      https://github.com/llvm/llvm-project/commit/2f9ace9e9a5816684b3c19528bd4a3908b2b8ac0
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2022-01-31 (Mon, 31 Jan 2022)

  Changed paths:
    M clang/include/clang/Driver/Driver.h
    M clang/include/clang/Driver/Options.td
    M clang/lib/Driver/Driver.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/test/Driver/openmp-offload-gpu.c

  Log Message:
  -----------
  [OpenMP] Introduce new flag to change offloading driver pipeline

This patch introduces the `-fopenmp-new-driver` option which instructs
the compiler to use a new driver scheme for producing offloading code.
In this scheme we create a complete offloading object file and then pass
it as input to the host compilation phase. This will allow us to embed
the object code in the backend phase.

This is the start of a series of commits to rework the OpenMP offloading driver
pipeline. The goal of this is to simplify the steps required for creating an
offloading program. This patch changes the driver's configuration to simply pass
the device file back to the host as an input so it can be embedded as an LLVM IR
global during the backend, then simply passes that object file to the linker.

This driver implementation will currently create the following phases,
```
$ clang input.c -fopenmp -fopenmp-targets=nvptx64 -fopenmp-new-driver -ccc-print-phases
               +- 0: input, "input.c", c, (host-openmp)
            +- 1: preprocessor, {0}, cpp-output, (host-openmp)
         +- 2: compiler, {1}, ir, (host-openmp)
         |        |     +- 3: input, "input.c", c, (device-openmp)
         |        |  +- 4: preprocessor, {3}, cpp-output, (device-openmp)
         |        |- 5: compiler, {4}, ir, (device-openmp)
         |     +- 6: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (nvptx64)" {5}, ir
         |  +- 7: backend, {6}, assembler, (device-openmp)
         |- 8: assembler, {7}, object, (device-openmp)
      +- 9: offload, "host-openmp (x86_64-unknown-linux-gnu)" {2}, "device-openmp (nvptx64)" {8}, ir
   +- 10: backend, {9}, assembler, (host-openmp)
+- 11: assembler, {10}, object, (host-openmp)
12: clang-linker-wrapper, {11}, image, (host-openmp)
```

Which will map to the following bindings

```
# "x86_64-unknown-linux-gnu" - "clang", inputs: ["input.c"], output: "/tmp/input-bae62e.bc"
# "nvptx64" - "clang", inputs: ["input.c", "/tmp/input-bae62e.bc"], output: "/tmp/input-76784e.s"
# "nvptx64" - "NVPTX::Assembler", inputs: ["/tmp/input-76784e.s"], output: "/tmp/input-8f29db.o"
# "x86_64-unknown-linux-gnu" - "clang", inputs: ["/tmp/input-bae62e.bc", "/tmp/input-8f29db.o"], output: "/tmp/input-545450.o"
# "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["/tmp/input-545450.o"], output: "a.out"
```

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D116541


  Commit: 551b1774524428aae5692ed3d41f969288ecd5a2
      https://github.com/llvm/llvm-project/commit/551b1774524428aae5692ed3d41f969288ecd5a2
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2022-01-31 (Mon, 31 Jan 2022)

  Changed paths:
    M clang/include/clang/Basic/CodeGenOptions.h
    M clang/include/clang/CodeGen/BackendUtil.h
    M clang/include/clang/Driver/Options.td
    M clang/lib/CodeGen/BackendUtil.cpp
    M clang/lib/CodeGen/CodeGenAction.cpp
    A clang/test/Frontend/embed-object.ll
    M llvm/include/llvm/Bitcode/BitcodeWriter.h
    M llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
    M llvm/lib/Bitcode/Writer/CMakeLists.txt

  Log Message:
  -----------
  [OpenMP] Add a flag for embedding a file into the module

This patch adds support for a flag `-fembed-offload-binary` to embed a
file as an ELF section in the output by placing it in a global variable.
This can be used to bundle offloading files with the host binary so it
can be accessed by the linker. The section is named using the
`-fembed-offload-section` option.

Depends on D116541

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D116542


  Commit: 12ae095bbb639c3dda9607a57487b83ccec9d246
      https://github.com/llvm/llvm-project/commit/12ae095bbb639c3dda9607a57487b83ccec9d246
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2022-01-31 (Mon, 31 Jan 2022)

  Changed paths:
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/test/Driver/openmp-offload-gpu.c

  Log Message:
  -----------
  [OpenMP] Embed device files into the host IR

This patch adds support for embedding the device object files into the
host IR to create a fat binary. Each offloading file will be inserted
into a section with the following naming format
`.llvm.offloading.<triple>.<arch>.<filename>`.

Depends on D116542

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D116543


  Commit: 95c8f7464092e2ccd45c3ae6dc42da6bd9a037b5
      https://github.com/llvm/llvm-project/commit/95c8f7464092e2ccd45c3ae6dc42da6bd9a037b5
  Author: Joseph Huber <jhuber6 at vols.utk.edu>
  Date:   2022-01-31 (Mon, 31 Jan 2022)

  Changed paths:
    A clang/docs/ClangLinkerWrapper.rst
    M clang/docs/ReleaseNotes.rst
    M clang/include/clang/Driver/Action.h
    M clang/include/clang/Driver/Job.h
    M clang/include/clang/Driver/ToolChain.h
    M clang/lib/Driver/Action.cpp
    M clang/lib/Driver/Driver.cpp
    M clang/lib/Driver/ToolChain.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Driver/ToolChains/Clang.h
    M clang/tools/CMakeLists.txt
    A clang/tools/clang-linker-wrapper/CMakeLists.txt
    A clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

  Log Message:
  -----------
  [Clang] Introduce Clang Linker Wrapper Tool

This patch introduces a linker wrapper tool that allows us to preprocess
files before they are sent to the linker. This adds a dummy action and
job to the driver stage that builds the linker command as usual and then
replaces the command line with the wrapper tool.

Depends on D116543

Reviewed By: JonChesterfield

Differential Revision: https://reviews.llvm.org/D116544


Compare: https://github.com/llvm/llvm-project/compare/78fd413cf736...95c8f7464092


More information about the All-commits mailing list