This is an archive of the discontinued LLVM Phabricator instance.

[Clang][LoongArch] Implement __builtin_loongarch_dbar builtin
ClosedPublic

Authored by gonglingqin on Oct 27 2022, 6:01 PM.

Diff Detail

Event Timeline

gonglingqin created this revision.Oct 27 2022, 6:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2022, 6:01 PM
gonglingqin requested review of this revision.Oct 27 2022, 6:01 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 27 2022, 6:01 PM
SixWeining added inline comments.Nov 6 2022, 7:59 PM
llvm/include/llvm/IR/IntrinsicsLoongArch.td
45

Seems this arg is unnecessary because the defalut value is [].

gonglingqin added inline comments.Nov 6 2022, 10:17 PM
llvm/include/llvm/IR/IntrinsicsLoongArch.td
45

Thanks, I will modify it.

Address @SixWeining's comments.

SixWeining accepted this revision.Nov 7 2022, 1:34 AM

LGTM but let's wait others.

This revision is now accepted and ready to land.Nov 7 2022, 1:34 AM
SixWeining added inline comments.Nov 7 2022, 10:31 PM
llvm/test/CodeGen/LoongArch/intrinsic-error.ll
11

It's better to add a test that immediate is out of range.

gonglingqin added inline comments.Nov 8 2022, 12:50 AM
llvm/test/CodeGen/LoongArch/intrinsic-error.ll
11

Thanks, I will add test cases.

Add test cases to detect whether the immediate is out of range.

This revision was landed with ongoing or failed builds.Nov 10 2022, 1:31 AM
This revision was automatically updated to reflect the committed changes.

Hi, this seems to be causing some problems when generating Xcode project.

When I try to generate the Xcode project with the following command:

cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_IDE=ON -DLLVM_CCACHE_BUILD=ON ../../llvm

I get the following error:

CMake Error in /path/to/llvm-project/clang/lib/Headers/CMakeLists.txt:

The custom command generating

  /path/to/llvm-project/build/Xcode-Debug/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/16/include/larchintrin.h

is attached to multiple targets:

  clang-resource-headers
  loongarch-resource-headers

but none of these is a common dependency of the other(s).  This is not
allowed by the Xcode "new build system".

CMake Error in /path/to/llvm-project/third-party/benchmark/CMakeLists.txt:

The custom command generating

  /path/to/llvm-project/build/Xcode-Debug/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/16/include/larchintrin.h

is attached to multiple targets:

  clang-resource-headers
  loongarch-resource-headers

but none of these is a common dependency of the other(s).  This is not
allowed by the Xcode "new build system".

Hi, this seems to be causing some problems when generating Xcode project.

When I try to generate the Xcode project with the following command:

cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_IDE=ON -DLLVM_CCACHE_BUILD=ON ../../llvm

I get the following error:

CMake Error in /path/to/llvm-project/clang/lib/Headers/CMakeLists.txt:

The custom command generating

  /path/to/llvm-project/build/Xcode-Debug/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/16/include/larchintrin.h

is attached to multiple targets:

  clang-resource-headers
  loongarch-resource-headers

but none of these is a common dependency of the other(s).  This is not
allowed by the Xcode "new build system".

CMake Error in /path/to/llvm-project/third-party/benchmark/CMakeLists.txt:

The custom command generating

  /path/to/llvm-project/build/Xcode-Debug/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/16/include/larchintrin.h

is attached to multiple targets:

  clang-resource-headers
  loongarch-resource-headers

but none of these is a common dependency of the other(s).  This is not
allowed by the Xcode "new build system".

Thank you for your input. Correct me if I'm wrong, when I create a new build directory and execute the following command:

cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_IDE=ON -DLLVM_CCACHE_BUILD=ON ../../llvm

I get the following error:

CMake Error: Could not create named generator Xcode

Generators
  Unix Makefiles               = Generates standard UNIX makefiles.
  Ninja                        = Generates build.ninja files.
  Watcom WMake                 = Generates Watcom WMake makefiles.
  CodeBlocks - Ninja           = Generates CodeBlocks project files.
  CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
  CodeLite - Ninja             = Generates CodeLite project files.
  CodeLite - Unix Makefiles    = Generates CodeLite project files.
  Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
  Sublime Text 2 - Unix Makefiles
                               = Generates Sublime Text 2 project files.
  Kate - Ninja                 = Generates Kate project files.
  Kate - Unix Makefiles        = Generates Kate project files.
  Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
  Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.

But when I change Xcode to Ninja, no error output is generated.
Do you have any suggestions for reproducing the bugs you mentioned?

Hi, this seems to be causing some problems when generating Xcode project.

When I try to generate the Xcode project with the following command:

cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_IDE=ON -DLLVM_CCACHE_BUILD=ON ../../llvm

I get the following error:

CMake Error in /path/to/llvm-project/clang/lib/Headers/CMakeLists.txt:

The custom command generating

  /path/to/llvm-project/build/Xcode-Debug/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/16/include/larchintrin.h

is attached to multiple targets:

  clang-resource-headers
  loongarch-resource-headers

but none of these is a common dependency of the other(s).  This is not
allowed by the Xcode "new build system".

CMake Error in /path/to/llvm-project/third-party/benchmark/CMakeLists.txt:

The custom command generating

  /path/to/llvm-project/build/Xcode-Debug/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)/lib/clang/16/include/larchintrin.h

is attached to multiple targets:

  clang-resource-headers
  loongarch-resource-headers

but none of these is a common dependency of the other(s).  This is not
allowed by the Xcode "new build system".

I realized that it might be my environment that prevented me from repeating this problem. Can you use https://reviews.llvm.org/D138403 to solve this problem?

I get the following error:

CMake Error: Could not create named generator Xcode

Sorry, I forgot to mention that Xcode is only available on macOS.

But when I change Xcode to Ninja, no error output is generated.

Indeed. Ninja works fine for me as well. The problem is I kind of need both Xcode and Ninja in my workflow (Xcode for editing, Ninja for building).

Do you have any suggestions for reproducing the bugs you mentioned?

I think the following steps should be able to reproduce the error messages I'm seeing (It's a bit long):

  1. Install macOS 12.6 or newer. (I'm currently on 12.6, but newer versions such as 12.6.1 and 13 (the latest) should produce the same error messages.)
  1. Install Xcode 14.1 and/or the Xcode command line tools
    • Xcode can be installed via this link (generally recommended), or from the Mac App Store via this link.
      • The first link downloads a .xip file which can take a long time to decompress. This step can be sped up significantly by decompressing the file using this tool.
    • The command line tools can be installed via this link, via the following commands, or by launching Xcode after it's installed. (I don't remember it clearly, but I think you probably can skip this step and have Homebrew install it for you in step 3)

      sudo rm -rf /Library/Developer/CommandLineTools

      sudo xcode-select --install
  1. Install LLVM's dependencies via Homebrew
    • First we need to install brew using the following command

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • Then install Cmake and Python with brew. (I'm not sure if Python is really needed)

      brew install cmake python
  1. Clone LLVM and create the build directory.
  2. Generate Xcode project using CMake.

    cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_IDE=ON -DLLVM_CCACHE_BUILD=ON path/to/llvm

    Flags other than -G "Xcode" probably are optional for the purpose of reproducing the error messages.

Can you use https://reviews.llvm.org/D138403 to solve this problem?

Thanks for letting me know. I'll give it a try.

I get the following error:

CMake Error: Could not create named generator Xcode

Sorry, I forgot to mention that Xcode is only available on macOS.

But when I change Xcode to Ninja, no error output is generated.

Indeed. Ninja works fine for me as well. The problem is I kind of need both Xcode and Ninja in my workflow (Xcode for editing, Ninja for building).

Do you have any suggestions for reproducing the bugs you mentioned?

I think the following steps should be able to reproduce the error messages I'm seeing (It's a bit long):

  1. Install macOS 12.6 or newer. (I'm currently on 12.6, but newer versions such as 12.6.1 and 13 (the latest) should produce the same error messages.)
  1. Install Xcode 14.1 and/or the Xcode command line tools
    • Xcode can be installed via this link (generally recommended), or from the Mac App Store via this link.
      • The first link downloads a .xip file which can take a long time to decompress. This step can be sped up significantly by decompressing the file using this tool.
    • The command line tools can be installed via this link, via the following commands, or by launching Xcode after it's installed. (I don't remember it clearly, but I think you probably can skip this step and have Homebrew install it for you in step 3)

      sudo rm -rf /Library/Developer/CommandLineTools

      sudo xcode-select --install
  1. Install LLVM's dependencies via Homebrew
    • First we need to install brew using the following command

      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    • Then install Cmake and Python with brew. (I'm not sure if Python is really needed)

      brew install cmake python
  1. Clone LLVM and create the build directory.
  2. Generate Xcode project using CMake.

    cmake -G "Xcode" -DCMAKE_BUILD_TYPE=Debug -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_OPTIMIZED_TABLEGEN=ON -DLLVM_ENABLE_IDE=ON -DLLVM_CCACHE_BUILD=ON path/to/llvm

    Flags other than -G "Xcode" probably are optional for the purpose of reproducing the error messages.

Thanks! Very nice to know.

Can you use https://reviews.llvm.org/D138403 to solve this problem?

Thanks for letting me know. I'll give it a try.

Thanks a lot!