Re: [PATCH] D24119: [libc++] add linker option "-Wl, -z, defs" in standalone build

2016-09-27 Thread Lei Zhang via cfe-commits
zlei added inline comments.


Comment at: libcxx/trunk/CMakeLists.txt:329
@@ +328,3 @@
+  ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND
+ NOT LLVM_USE_SANITIZER)
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")

rmaprath wrote:
> Perhaps we should exclude `LIBCXX_HAS_EXTERNAL_THREAD_API` as well? Because 
> there we explicitly strip off these flags.
I agree. Could you prepare a patch for it?

BTW, I really don't like duplicating code snippet from llvm. Is there any 
better solution for that?


Repository:
  rL LLVM

https://reviews.llvm.org/D24119



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] [Request, 2 lines] D25071: [openmp] fix a compile error on musl-libc

2016-09-29 Thread Lei Zhang via cfe-commits
zlei created this revision.
zlei added a reviewer: jcownie.
zlei added a subscriber: cfe-commits.

Function `strerror_r()` has different signatures in different implementations 
of libc: glibc's version returns a `char*`, while BSDs and musl return a `int`. 
libomp unconditionally assumes glibc on Linux and thus fails to compile against 
musl-libc. This patch addresses this issue.


https://reviews.llvm.org/D25071

Files:
  runtime/src/kmp_i18n.c


Index: runtime/src/kmp_i18n.c
===
--- runtime/src/kmp_i18n.c
+++ runtime/src/kmp_i18n.c
@@ -809,7 +809,7 @@
 intstrerror_r( int, char *, size_t );  // XSI version
 */
 
-#if KMP_OS_LINUX
+#if KMP_OS_LINUX && __GLIBC__
 
 // GNU version of strerror_r.
 


Index: runtime/src/kmp_i18n.c
===
--- runtime/src/kmp_i18n.c
+++ runtime/src/kmp_i18n.c
@@ -809,7 +809,7 @@
 intstrerror_r( int, char *, size_t );  // XSI version
 */
 
-#if KMP_OS_LINUX
+#if KMP_OS_LINUX && __GLIBC__
 
 // GNU version of strerror_r.
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-27 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for the contribution and sorry about the delay! I'm getting around to 
review this pull request (already done a few others). Please wait a bit. 

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-27 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for the contribution and sorry about the delay! I'm getting around to 
review this pull request (already done a few others). Please wait a bit. 

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-28 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst requested changes to this pull request.

Nice. Just one final request.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-28 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst edited 
https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-28 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst requested changes to this pull request.

Nice. Just one final request.

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] Update convert-gpu-to-spirv pass to prepare using GPU compilat… (PR #69941)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -54,22 +55,52 @@ void GPUToSPIRVPass::runOnOperation() {
 
   SmallVector gpuModules;
   OpBuilder builder(context);
+
+  auto targetEnvSupportsKernelCapability = [](gpu::GPUModuleOp moduleOp) {
+Operation *gpuModule = moduleOp.getOperation();
+auto targetAttr = spirv::lookupTargetEnvOrDefault(gpuModule);
+spirv::TargetEnv targetEnv(targetAttr);
+return targetEnv.allows(spirv::Capability::Kernel);
+  };
+
   module.walk([&](gpu::GPUModuleOp moduleOp) {
 // Clone each GPU kernel module for conversion, given that the GPU
 // launch op still needs the original GPU kernel module.
-builder.setInsertionPoint(moduleOp.getOperation());
+// For Vulkan Shader capabilities, we insert the newly converted SPIR-V
+// module right after the original GPU module, as that's the expectation of
+// the in-tree Vulkan runner.
+// For OpenCL Kernel capabilities, we insert the newly converted SPIR-V
+// module inside the original GPU module, as that's the expectaion of the
+// normal GPU compilation pipeline.
+if (targetEnvSupportsKernelCapability(moduleOp)) {
+  builder.setInsertionPoint(moduleOp.getBody(),
+moduleOp.getBody()->begin());
+} else {
+  builder.setInsertionPoint(moduleOp.getOperation());
+}
 gpuModules.push_back(builder.clone(*moduleOp.getOperation()));
   });
 
   // Run conversion for each module independently as they can have different
   // TargetEnv attributes.
   for (Operation *gpuModule : gpuModules) {
+spirv::TargetEnvAttr targetAttr =
+spirv::lookupTargetEnvOrDefault(gpuModule);
+
 // Map MemRef memory space to SPIR-V storage class first if requested.
 if (mapMemorySpace) {
+  spirv::TargetEnv targetEnv(targetAttr);
+  FailureOr memoryModel =
+  spirv::getMemoryModel(targetEnv);
+  if (failed(memoryModel))
+return signalPassFailure();
+
   std::unique_ptr target =
   spirv::getMemorySpaceToStorageClassTarget(*context);
   spirv::MemorySpaceToStorageClassMap memorySpaceMap =
-  spirv::mapMemorySpaceToVulkanStorageClass;
+  (memoryModel == spirv::MemoryModel::OpenCL)

antiagainst wrote:

Here we can also use the above `targetEnvSupportsKernelCapability` no? 
Something like:

```c++
spirv::MemorySpaceToStorageClassMap memorySpaceMap =
  targetEnvSupportsKernelCapability(gpuModule) ? ...
```

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This files defines SPIRV target related functions including registration
+// calls for the `#spirv.target` compilation attribute.
+//
+//===--===//
+
+#include "mlir/Target/SPIRV/Target.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
+#include "mlir/Target/SPIRV/Serialization.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+// Implementation of the `TargetAttrInterface` model.
+class SPIRVTargetAttrImpl
+: public gpu::TargetAttrInterface::FallbackModel {
+public:
+  std::optional>
+  serializeToObject(Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const;
+
+  Attribute createObject(Attribute attribute,
+ const SmallVector &object,
+ const gpu::TargetOptions &options) const;
+};
+} // namespace
+
+// Register the SPIRV dialect, the SPIRV translation & the target interface.
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+DialectRegistry ®istry) {
+  registry.addExtension(+[](MLIRContext *ctx, spirv::SPIRVDialect *dialect) {
+spirv::SPIRVTargetAttr::attachInterface(*ctx);
+  });
+}
+
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+MLIRContext &context) {
+  DialectRegistry registry;
+  registerSPIRVTargetInterfaceExternalModels(registry);
+  context.appendDialectRegistry(registry);
+}
+
+// Reuse from existing serializer
+std::optional> SPIRVTargetAttrImpl::serializeToObject(
+Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const {
+  assert(module && "The module must be non null.");
+  if (!module)
+return std::nullopt;
+  if (!mlir::isa(module)) {
+module->emitError("Module must be a GPU module.");
+return std::nullopt;
+  }
+  auto gpuMod = dyn_cast(module);
+  auto spvMods = gpuMod.getOps();
+  // Empty spirv::ModuleOp

antiagainst wrote:

The comment here does not provide additional value; we should remove it or 
expand it to be more clear.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst edited 
https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.
+//===--===//
+
+def SPIRV_TargetAttr : SPIRV_Attr<"SPIRVTarget", "target"> {

antiagainst wrote:

This attribute is pretty much a duplication of `spirv::TargetEnvAttr` defined 
in `SPIRVAttributes.h`? We should avoid introducing such duplications and 
causing confusion. Any reaons we cannot use `spirv::TargetEnvAttr` directly? 

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//

antiagainst wrote:

Nit: again, please use SPIR-V in docs and comments. Please make sure everywhere 
follows the convention. :)

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,7 @@
+// RUN: mlir-opt %s --spirv-attach-target='module=spirv.* ver=v1.0 
caps=Kernel' | FileCheck %s
+
+module attributes {gpu.container_module} {
+// CHECK: @spirv_module_1 [#spirv.target, 
resource_limits = <>>]
+gpu.module @spirv_module_1 {

antiagainst wrote:

Can we add tests to show like

1) multiple GPU modules in the same container module?
2) different match regex with hits and misses?

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This files defines SPIRV target related functions including registration
+// calls for the `#spirv.target` compilation attribute.
+//
+//===--===//
+
+#include "mlir/Target/SPIRV/Target.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
+#include "mlir/Target/SPIRV/Serialization.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+// Implementation of the `TargetAttrInterface` model.

antiagainst wrote:

SPIR-V implementation of the `gpu:TargetAttrInterface`.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,
+ListOption<"spirvCapabilities", "caps", "std::string",
+   "List of required SPIRV Capabilities">,

antiagainst wrote:

s/required/supported/

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This files defines SPIRV target related functions including registration
+// calls for the `#spirv.target` compilation attribute.
+//
+//===--===//
+
+#include "mlir/Target/SPIRV/Target.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
+#include "mlir/Target/SPIRV/Serialization.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+// Implementation of the `TargetAttrInterface` model.
+class SPIRVTargetAttrImpl
+: public gpu::TargetAttrInterface::FallbackModel {
+public:
+  std::optional>
+  serializeToObject(Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const;
+
+  Attribute createObject(Attribute attribute,
+ const SmallVector &object,
+ const gpu::TargetOptions &options) const;
+};
+} // namespace
+
+// Register the SPIRV dialect, the SPIRV translation & the target interface.
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+DialectRegistry ®istry) {
+  registry.addExtension(+[](MLIRContext *ctx, spirv::SPIRVDialect *dialect) {
+spirv::SPIRVTargetAttr::attachInterface(*ctx);
+  });
+}
+
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+MLIRContext &context) {
+  DialectRegistry registry;
+  registerSPIRVTargetInterfaceExternalModels(registry);
+  context.appendDialectRegistry(registry);
+}
+
+// Reuse from existing serializer
+std::optional> SPIRVTargetAttrImpl::serializeToObject(
+Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const {
+  assert(module && "The module must be non null.");
+  if (!module)
+return std::nullopt;
+  if (!mlir::isa(module)) {
+module->emitError("Module must be a GPU module.");
+return std::nullopt;
+  }
+  auto gpuMod = dyn_cast(module);
+  auto spvMods = gpuMod.getOps();
+  // Empty spirv::ModuleOp
+  if (spvMods.empty()) {
+return std::nullopt;
+  }
+  auto spvMod = *spvMods.begin();
+  llvm::SmallVector spvBinary;
+
+  spvBinary.clear();
+  // serialize the spv module to spv binary
+  if (mlir::failed(spirv::serialize(spvMod, spvBinary))) {
+spvMod.emitError() << "Failed to serialize SPIR-V module";

antiagainst wrote:

Nit: "failed to .."

no capitalization to compose better with previous / following messages. 

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This files defines SPIRV target related functions including registration
+// calls for the `#spirv.target` compilation attribute.
+//
+//===--===//
+
+#include "mlir/Target/SPIRV/Target.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
+#include "mlir/Target/SPIRV/Serialization.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+// Implementation of the `TargetAttrInterface` model.
+class SPIRVTargetAttrImpl
+: public gpu::TargetAttrInterface::FallbackModel {
+public:
+  std::optional>
+  serializeToObject(Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const;
+
+  Attribute createObject(Attribute attribute,
+ const SmallVector &object,
+ const gpu::TargetOptions &options) const;
+};
+} // namespace
+
+// Register the SPIRV dialect, the SPIRV translation & the target interface.
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+DialectRegistry ®istry) {
+  registry.addExtension(+[](MLIRContext *ctx, spirv::SPIRVDialect *dialect) {
+spirv::SPIRVTargetAttr::attachInterface(*ctx);
+  });
+}
+
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+MLIRContext &context) {
+  DialectRegistry registry;
+  registerSPIRVTargetInterfaceExternalModels(registry);
+  context.appendDialectRegistry(registry);
+}
+
+// Reuse from existing serializer
+std::optional> SPIRVTargetAttrImpl::serializeToObject(
+Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const {
+  assert(module && "The module must be non null.");

antiagainst wrote:

We don't need this assert here?

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching
+// `#spirv.target` attributes to GPU modules.
+//
+//===--===//
+
+#include "mlir/Dialect/GPU/Transforms/Passes.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/TargetAndABI.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Target/SPIRV/Target.h"
+#include "llvm/Support/Regex.h"
+
+namespace mlir {
+#define GEN_PASS_DEF_GPUSPIRVATTACHTARGET
+#include "mlir/Dialect/GPU/Transforms/Passes.h.inc"
+} // namespace mlir
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+struct SPIRVAttachTarget
+: public impl::GpuSPIRVAttachTargetBase {
+  using Base::Base;
+
+  void runOnOperation() override;
+
+  void getDependentDialects(DialectRegistry ®istry) const override {
+registry.insert();
+  }
+};
+} // namespace
+
+void SPIRVAttachTarget::runOnOperation() {
+  OpBuilder builder(&getContext());
+  if (!symbolizeVersion(spirvVersion))
+return signalPassFailure();
+  if (!symbolizeClientAPI(clientApi))
+return signalPassFailure();
+  if (!symbolizeVendor(deviceVendor))
+return signalPassFailure();
+  if (!symbolizeDeviceType(deviceType))
+return signalPassFailure();
+
+  Version version = symbolizeVersion(spirvVersion).value();

antiagainst wrote:

We should avoid calling `symbolizeVersion` twice. We can save the result in a 
local variable in the above call and use it here.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.

antiagainst wrote:

Nit: SPIR-V

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,94 @@
+//===- SPIRVAttachTarget.cpp - Attach an SPIRV target 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file implements the `GpuSPIRVAttachTarget` pass, attaching

antiagainst wrote:

Nit: GPUSPIRVAttachTarget

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
+```
+  }];
+  let options = [
+Option<"moduleMatcher", "module", "std::string",
+   /*default=*/ [{""}],
+   "Regex used to identify the modules to attach the target to.">,
+Option<"spirvVersion", "ver", "std::string",
+   /*default=*/ "\"v1.0\"",
+   "SPIRV Addressing Model.">,
+ListOption<"spirvCapabilities", "caps", "std::string",
+   "List of required SPIRV Capabilities">,

antiagainst wrote:

s/required/supported/

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This files defines SPIRV target related functions including registration
+// calls for the `#spirv.target` compilation attribute.
+//
+//===--===//
+
+#include "mlir/Target/SPIRV/Target.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
+#include "mlir/Target/SPIRV/Serialization.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+// Implementation of the `TargetAttrInterface` model.
+class SPIRVTargetAttrImpl
+: public gpu::TargetAttrInterface::FallbackModel {
+public:
+  std::optional>
+  serializeToObject(Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const;
+
+  Attribute createObject(Attribute attribute,
+ const SmallVector &object,
+ const gpu::TargetOptions &options) const;
+};
+} // namespace
+
+// Register the SPIRV dialect, the SPIRV translation & the target interface.
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+DialectRegistry ®istry) {
+  registry.addExtension(+[](MLIRContext *ctx, spirv::SPIRVDialect *dialect) {
+spirv::SPIRVTargetAttr::attachInterface(*ctx);
+  });
+}
+
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+MLIRContext &context) {
+  DialectRegistry registry;
+  registerSPIRVTargetInterfaceExternalModels(registry);
+  context.appendDialectRegistry(registry);
+}
+
+// Reuse from existing serializer
+std::optional> SPIRVTargetAttrImpl::serializeToObject(
+Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const {
+  assert(module && "The module must be non null.");
+  if (!module)
+return std::nullopt;
+  if (!mlir::isa(module)) {
+module->emitError("Module must be a GPU module.");
+return std::nullopt;
+  }
+  auto gpuMod = dyn_cast(module);
+  auto spvMods = gpuMod.getOps();
+  // Empty spirv::ModuleOp
+  if (spvMods.empty()) {
+return std::nullopt;
+  }
+  auto spvMod = *spvMods.begin();
+  llvm::SmallVector spvBinary;
+
+  spvBinary.clear();
+  // serialize the spv module to spv binary
+  if (mlir::failed(spirv::serialize(spvMod, spvBinary))) {
+spvMod.emitError() << "Failed to serialize SPIR-V module";

antiagainst wrote:

Nit: "failed to .."

no capitalization to compose better with previous / following messages. 

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";

antiagainst wrote:

Nit: s/SPIRV/SPIR-V/.

SPIR-V is the formal spelling. We should use that when in docs and comments.

Also for all the following docs and comments.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -166,4 +166,35 @@ def SPIRV_ResourceLimitsAttr : 
SPIRV_Attr<"ResourceLimits", "resource_limits"> {
   let assemblyFormat = "`<` struct(params) `>`";
 }
 
+//===--===//
+// SPIRV target attribute.
+//===--===//
+
+def SPIRV_TargetAttr : SPIRV_Attr<"SPIRVTarget", "target"> {

antiagainst wrote:

This attribute is pretty much a duplication of `spirv::TargetEnvAttr` defined 
in `SPIRVAttributes.h`? We should avoid introducing such duplications and 
causing confusion. Any reaons we cannot use `spirv::TargetEnvAttr` directly? 

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,30 @@
+//===- Target.h - MLIR SPIRV target registration *- C++ 
-*-===//

antiagainst wrote:

Nit: again, please use SPIR-V in docs and comments.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst requested changes to this pull request.

Thanks again for the contribution! A couple of comments inlined. My main 
concern is the duplication of `spirv.target` attribute. We should avoid the 
duplication and confusion there.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,117 @@
+//===- Target.cpp - MLIR SPIRV target compilation ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This files defines SPIRV target related functions including registration
+// calls for the `#spirv.target` compilation attribute.
+//
+//===--===//
+
+#include "mlir/Target/SPIRV/Target.h"
+
+#include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVOps.h"
+#include "mlir/Target/LLVMIR/Dialect/GPU/GPUToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
+#include "mlir/Target/LLVMIR/Export.h"
+#include "mlir/Target/SPIRV/Serialization.h"
+
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
+#include "llvm/Support/Program.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include 
+#include 
+
+using namespace mlir;
+using namespace mlir::spirv;
+
+namespace {
+// Implementation of the `TargetAttrInterface` model.
+class SPIRVTargetAttrImpl
+: public gpu::TargetAttrInterface::FallbackModel {
+public:
+  std::optional>
+  serializeToObject(Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const;
+
+  Attribute createObject(Attribute attribute,
+ const SmallVector &object,
+ const gpu::TargetOptions &options) const;
+};
+} // namespace
+
+// Register the SPIRV dialect, the SPIRV translation & the target interface.
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+DialectRegistry ®istry) {
+  registry.addExtension(+[](MLIRContext *ctx, spirv::SPIRVDialect *dialect) {
+spirv::SPIRVTargetAttr::attachInterface(*ctx);
+  });
+}
+
+void mlir::spirv::registerSPIRVTargetInterfaceExternalModels(
+MLIRContext &context) {
+  DialectRegistry registry;
+  registerSPIRVTargetInterfaceExternalModels(registry);
+  context.appendDialectRegistry(registry);
+}
+
+// Reuse from existing serializer
+std::optional> SPIRVTargetAttrImpl::serializeToObject(
+Attribute attribute, Operation *module,
+const gpu::TargetOptions &options) const {
+  assert(module && "The module must be non null.");
+  if (!module)
+return std::nullopt;
+  if (!mlir::isa(module)) {
+module->emitError("Module must be a GPU module.");
+return std::nullopt;
+  }
+  auto gpuMod = dyn_cast(module);
+  auto spvMods = gpuMod.getOps();
+  // Empty spirv::ModuleOp
+  if (spvMods.empty()) {

antiagainst wrote:

Nit: drop `{..}` for trivial if statements per LLVM coding sytle.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";
+  let description = [{
+This pass searches for all GPU Modules in the immediate regions and 
attaches
+an SPIRV target if the module matches the name specified by the `module` 
argument.
+
+Example:
+```
+// File: in1.mlir:
+gpu.module @nvvm_module_1 {...}
+gpu.module @spirv_module_1 {...}
+// mlir-opt --spirv-attach-target="module=spirv.* ver=v1.0 caps=Kernel" 
in1.mlir

antiagainst wrote:

Given the following file

```
Please don't call the symbolize* functions twice everywhere--those functions 
are expensive. We can save the result in a locla variable and use it later.
```
With `mlir-opt ...`, it will generate:

```
gpu.module @nvvm_module_1 {...}
gpu.module @spirv_module_1 [#spirv.target, resource_limits = <>>] {...}
```

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -188,4 +188,46 @@ def GpuROCDLAttachTarget: Pass<"rocdl-attach-target", ""> {
   ];
 }
 
+def GpuSPIRVAttachTarget: Pass<"spirv-attach-target", ""> {
+  let summary = "Attaches an SPIRV target attribute to a GPU Module.";

antiagainst wrote:

Nit: s/SPIRV/SPIR-V/.

SPIR-V is the formal spelling. We should use that when in docs and comments.

Also for all the following docs and comments.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-10-28 Thread Lei Zhang via cfe-commits


@@ -0,0 +1,30 @@
+//===- Target.h - MLIR SPIRV target registration *- C++ 
-*-===//

antiagainst wrote:

Nit: again, please use SPIR-V in docs and comments.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [MLIR] SPIRV Target Attribute (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst approved this pull request.

LGTM. Thanks for addressing the comments!

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst edited 
https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst closed 
https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [libcxx] [libc] [llvm] [mlir] [compiler-rt] [flang] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

I revised the commit message a bit and landed it. Thanks for the waiting!

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [compiler-rt] [libcxx] [llvm] [libc] [mlir] [clang-tools-extra] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Sorry about that! I uploaded 
https://github.com/llvm/llvm-project/commit/4a4b8570f7c16346094c59fab1bd8debf9b177e1
 to fix this. Verified that it fixes the break for me locally.

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [libc] [mlir] [libcxx] [mlir][spirv] Implement gpu::TargetAttrInterface (PR #69949)

2023-11-05 Thread Lei Zhang via cfe-commits


@@ -15,6 +15,7 @@
 
 #include "Utils.h"
 #include "mlir/Dialect/GPU/IR/GPUDialect.h"
+#include "mlir/Dialect/SPIRV/IR/SPIRVAttributes.h"

antiagainst wrote:

SG. Thanks @jpienaar & @fabianmcg!

https://github.com/llvm/llvm-project/pull/69949
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [lldb] [mlir] [libcxx] [mlir] Prepare convert-gpu-to-spirv for OpenCL support (PR #69941)

2023-11-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst closed 
https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[compiler-rt] [llvm] [clang-tools-extra] [clang] [flang] [lldb] [mlir] [libcxx] [mlir] Prepare convert-gpu-to-spirv for OpenCL support (PR #69941)

2023-11-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

> @antiagainst @joker-eph Can someone merge this PR? Thanks in advance.

Done. Thanks for the contribution again!

https://github.com/llvm/llvm-project/pull/69941
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [flang] [clang-tools-extra] [lldb] [llvm] [libc] [lld] [compiler-rt] [libcxx] [clang] [MLIR] Enable GPU Dialect to SYCL runtime integration (PR #71430)

2023-11-26 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst approved this pull request.

LGTM regarding SPIR-V. But please address comments from others. :)

https://github.com/llvm/llvm-project/pull/71430
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [compiler-rt] [llvm] [lldb] [lld] [clang-tools-extra] [mlir] [clang] [openmp] [libcxx] [flang] [MLIR] Enabling Intel GPU Integration. (PR #65539)

2023-11-26 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for breaking down this pull request into various smaller pieces to make 
it easier for review. I looked at various pieces; LGTM. Looking forward to see 
this being supported! :)

from @joker-eph:
> Vulkan and Spirv still have dedicated runners on the model of the original 
> cuda-runner, but I suspect this is just legacy?

from @Jianhui-Li:
> The current way of mlir-cpu-runner using the share library name to indicate 
> target-platform looks good to me: Cuda, Rocm, and SYCL with this PR. Vulkan 
> could be added same way. mlir-cpu-spirv-runner could be refactored to be 
> mlir-opt passes generating spirv binary and feed to mlir-cpu-runner.

Yup; it's legacy. +1 to the idea of unifying! I've created 
https://github.com/llvm/llvm-project/issues/73457 to track this issue to make 
it more visible. I might not have the bandwidth to work on this; if somebody 
else is interested that'd be nice! So maked it as "good first issue" (not sure 
whether I'm pushing the limit of "good first issue" but hoping to get traction 
there).


https://github.com/llvm/llvm-project/pull/65539
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [mlir] [llvm] [clang-tools-extra] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst updated 
https://github.com/llvm/llvm-project/pull/75660

>From fd8c637f2b146ffce657307841f84a4123e351af Mon Sep 17 00:00:00 2001
From: Dimple Prajapati 
Date: Wed, 13 Dec 2023 22:33:23 +
Subject: [PATCH 1/6] [mlir][spirv] Fix spirv dialect to support Specialization
 constants in GlobalVar initializer

Changes include:
- spirv serialization and deserialization needs handling in cases when 
GlobalVariableOp
  initializer is defined using spirv SpecConstant or 
SpecConstantComposite op, currently
  even though it allows SpecConst, it only looked up in for 
GlobalVariable Map to find
  initializer symbol reference, change is fixing this and extending the 
support to
  SpecConstantComposite as an initializer.
- Adds tests to make sure GlobalVariable can be initialzed using 
specialized constants.
---
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp|  5 ++--
 .../SPIRV/Deserialization/Deserializer.cpp| 19 ++-
 .../SPIRV/Serialization/SerializeOps.cpp  | 22 -
 mlir/test/Dialect/SPIRV/IR/structure-ops.mlir | 15 +++-
 mlir/test/Target/SPIRV/global-variable.mlir   | 24 +++
 5 files changed, 70 insertions(+), 15 deletions(-)

diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 2a1d083308282a..66f1d6b2e12206 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -1163,9 +1163,10 @@ LogicalResult spirv::GlobalVariableOp::verify() {
 // constants and other variables is supported. They could be normal
 // constants in the module scope as well.
 if (!initOp ||
-!isa(initOp)) {
+!isa(initOp)) {
   return emitOpError("initializer must be result of a "
- "spirv.SpecConstant or spirv.GlobalVariable op");
+ "spirv.SpecConstant or spirv.GlobalVariable or "
+ "spirv.SpecConstantCompositeOp op");
 }
   }
 
diff --git a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp 
b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
index 89e2e7ad52fa7d..ccea690a7c3ded 100644
--- a/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
+++ b/mlir/lib/Target/SPIRV/Deserialization/Deserializer.cpp
@@ -637,14 +637,21 @@ 
spirv::Deserializer::processGlobalVariable(ArrayRef operands) {
 
   // Initializer.
   FlatSymbolRefAttr initializer = nullptr;
+  
   if (wordIndex < operands.size()) {
-auto initializerOp = getGlobalVariable(operands[wordIndex]);
-if (!initializerOp) {
-  return emitError(unknownLoc, "unknown  ")
- << operands[wordIndex] << "used as initializer";
-}
+Operation *op = nullptr;
+
+if((op = getGlobalVariable(operands[wordIndex])))
+  initializer = 
SymbolRefAttr::get((dyn_cast(op)).getOperation());
+else if ((op  = getSpecConstant(operands[wordIndex])))
+  initializer = 
SymbolRefAttr::get((dyn_cast(op)).getOperation());
+else if((op = getSpecConstantComposite(operands[wordIndex])))
+  initializer = 
SymbolRefAttr::get((dyn_cast(op)).getOperation());
+else
+  return emitError(unknownLoc,
+"Unknown op used as initializer");
+
 wordIndex++;
-initializer = SymbolRefAttr::get(initializerOp.getOperation());
   }
   if (wordIndex != operands.size()) {
 return emitError(unknownLoc,
diff --git a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp 
b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
index 44538c38a41b83..bd1fc7a84fbd6a 100644
--- a/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
+++ b/mlir/lib/Target/SPIRV/Serialization/SerializeOps.cpp
@@ -383,12 +383,22 @@ 
Serializer::processGlobalVariableOp(spirv::GlobalVariableOp varOp) {
   operands.push_back(static_cast(varOp.storageClass()));
 
   // Encode initialization.
-  if (auto initializer = varOp.getInitializer()) {
-auto initializerID = getVariableID(*initializer);
-if (!initializerID) {
-  return emitError(varOp.getLoc(),
-   "invalid usage of undefined variable as initializer");
-}
+  if (auto initializerName = varOp.getInitializer()) {
+
+uint32_t initializerID = 0;
+auto init = varOp->getAttrOfType("initializer");
+Operation *initOp = 
SymbolTable::lookupNearestSymbolFrom(varOp->getParentOp(), init.getAttr());
+
+// Check if initializer is GlobalVariable or 
SpecConstant/SpecConstantComposite
+if(isa(initOp))
+  initializerID = getVariableID(*initializerName);
+else
+  initializerID = getSpecConstID(*initializerName);
+
+if (!initializerID)
+return emitError(varOp.getLoc(),
+  "invalid usage of undefined variable as initializer");
+   
 operands.push_back(initializerID);
 elidedAttrs.push_back("initializer");
   }
diff --git a/mlir/test/Dialect/SPIRV/IR/structure-ops.mlir 
b/mlir/test/Dialect/SPIRV/IR/struc

[clang] [mlir] [llvm] [clang-tools-extra] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst approved this pull request.


https://github.com/llvm/llvm-project/pull/75660
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [clang] [clang-tools-extra] [llvm] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks for the contribution! Sorry about the delay in reviews. I do have some 
style-ish comments but given this has been a while I just went ahead fixed them 
and will land this path directly. Thanks again! 

https://github.com/llvm/llvm-project/pull/75660
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [mlir] [clang-tools-extra] [llvm] [mlir][spirv] Fix spirv dialect to support Specialization constants as GlobalVar initializer (PR #75660)

2024-01-05 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst closed 
https://github.com/llvm/llvm-project/pull/75660
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst updated 
https://github.com/llvm/llvm-project/pull/76353

>From ebd9634057e9417905d7fcd27bac829c5d0889e0 Mon Sep 17 00:00:00 2001
From: Kohei Yamaguchi 
Date: Fri, 22 Dec 2023 17:22:25 +
Subject: [PATCH 01/10] [mlir][spirv] Support function argument decorations for
 ptr in the PhysicalStorageBuffer

---
 .../Dialect/SPIRV/IR/SPIRVStructureOps.td |  8 +++
 mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp| 37 ++
 mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp| 69 ++-
 .../spirv-storage-class-mapping.mlir  |  2 +-
 mlir/test/Dialect/SPIRV/IR/cast-ops.mlir  |  2 +-
 mlir/test/Dialect/SPIRV/IR/structure-ops.mlir | 42 +++
 .../SPIRV/Transforms/vce-deduction.mlir   |  2 +-
 mlir/test/Target/SPIRV/cast-ops.mlir  |  2 +-
 8 files changed, 145 insertions(+), 19 deletions(-)

diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td 
b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
index 5fd25e3b576f2a..0afe508b4db013 100644
--- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
+++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
@@ -267,6 +267,11 @@ def SPIRV_FuncOp : SPIRV_Op<"func", [
 This op itself takes no operands and generates no results. Its region
 can take zero or more arguments and return zero or one values.
 
+From `SPV_KHR_physical_storage_buffer`:
+If a parameter of function is
+- a pointer (or contains a pointer) in the PhysicalStorageBuffer storage 
class, the function parameter must be decorated with exactly one of `Aliased` 
or `Restrict`.
+- a pointer (or contains a pointer) and the type it points to is a pointer 
in the PhysicalStorageBuffer storage class, the function parameter must be 
decorated with exactly one of `AliasedPointer` or `RestrictPointer`.
+
 
 
 ```
@@ -280,6 +285,9 @@ def SPIRV_FuncOp : SPIRV_Op<"func", [
 ```mlir
 spirv.func @foo() -> () "None" { ... }
 spirv.func @bar() -> () "Inline|Pure" { ... }
+
+spirv.func @baz(%arg0: !spirv.ptr { 
spirv.decoration = #spirv.decoration}) -> () "None" { ... }
+spirv.func @qux(%arg0: !spirv.ptr, 
Generic> { spirv.decoration = 
#spirv.decoration}) "None)
 ```
   }];
 
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
index 8a68decc5878c8..66ec520cfeca31 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVDialect.cpp
@@ -992,19 +992,25 @@ static LogicalResult verifyRegionAttribute(Location loc, 
Type valueType,
   StringRef symbol = attribute.getName().strref();
   Attribute attr = attribute.getValue();
 
-  if (symbol != spirv::getInterfaceVarABIAttrName())
+  if (symbol == spirv::getInterfaceVarABIAttrName()) {
+auto varABIAttr = llvm::dyn_cast(attr);
+if (!varABIAttr)
+  return emitError(loc, "'")
+ << symbol << "' must be a spirv::InterfaceVarABIAttr";
+
+if (varABIAttr.getStorageClass() && !valueType.isIntOrIndexOrFloat())
+  return emitError(loc, "'") << symbol
+ << "' attribute cannot specify storage class "
+"when attaching to a non-scalar value";
+  } else if (symbol == spirv::DecorationAttr::name) {
+auto decAttr = llvm::dyn_cast(attr);
+if (!decAttr)
+  return emitError(loc, "'")
+ << symbol << "' must be a spirv::DecorationAttr";
+  } else {
 return emitError(loc, "found unsupported '")
<< symbol << "' attribute on region argument";
-
-  auto varABIAttr = llvm::dyn_cast(attr);
-  if (!varABIAttr)
-return emitError(loc, "'")
-   << symbol << "' must be a spirv::InterfaceVarABIAttr";
-
-  if (varABIAttr.getStorageClass() && !valueType.isIntOrIndexOrFloat())
-return emitError(loc, "'") << symbol
-   << "' attribute cannot specify storage class "
-  "when attaching to a non-scalar value";
+  }
 
   return success();
 }
@@ -1013,9 +1019,12 @@ LogicalResult 
SPIRVDialect::verifyRegionArgAttribute(Operation *op,
  unsigned regionIndex,
  unsigned argIndex,
  NamedAttribute attribute) 
{
-  return verifyRegionAttribute(
-  op->getLoc(), op->getRegion(regionIndex).getArgument(argIndex).getType(),
-  attribute);
+  auto funcOp = dyn_cast(op);
+  if (!funcOp)
+return success();
+  Type argType = funcOp.getArgumentTypes()[argIndex];
+
+  return verifyRegionAttribute(op->getLoc(), argType, attribute);
 }
 
 LogicalResult SPIRVDialect::verifyRegionResultAttribute(
diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp 
b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
index 2a1d083308282a..d6064f446b4454 100644
--- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
+++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
@@ -97

[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support function argument decorations for ptr in the PhysicalStorageBuffer (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

antiagainst wrote:

Thanks a lot for the contribution and bearing with me for the nitpicking. :) To 
avoid burden you further, I rebased and revised some comment/error message 
slightly. :) I'll land once bots are happy.

https://github.com/llvm/llvm-project/pull/76353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst edited 
https://github.com/llvm/llvm-project/pull/76353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [clang-tools-extra] [clang] [llvm] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

https://github.com/antiagainst closed 
https://github.com/llvm/llvm-project/pull/76353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[mlir] [llvm] [clang-tools-extra] [clang] [mlir][spirv] Support alias/restrict function argument decorations (PR #76353)

2024-01-06 Thread Lei Zhang via cfe-commits

antiagainst wrote:

> @kuhar @antiagainst Thanks for your comment and support to land this PR! If 
> you have any issues or TODO tasks in SPIR-V dialect, I would be happy if you 
> could share it with me. :)

Thanks for your further interest! Please feel free to take a look at issues 
with the `mlir:spirv` label to see if any one of them is interesting to you, 
especially those with the `good first issue` label at the same time!

https://github.com/llvm/llvm-project/pull/76353
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24069: Document option '-rtlib' in clang's man page and help info

2016-08-31 Thread Lei Zhang via cfe-commits
zlei created this revision.
zlei added reviewers: cfe-commits, Hahnfeld.

This patch adds an entry for "-rtlib" in the output of `man clang` and `clang 
-help`.

https://reviews.llvm.org/D24069

Files:
  docs/CommandGuide/clang.rst
  include/clang/Driver/Options.td

Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1860,7 +1860,8 @@
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[DriverOption]>,
   Alias;
 def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>;
-def rtlib_EQ : Joined<["-", "--"], "rtlib=">;
+def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
+  HelpText<"Compiler runtime library to use">;
 def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[DriverOption]>,
   HelpText<"Save intermediate compilation results.">;
Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -107,6 +107,11 @@
  Specify the C++ standard library to use; supported options are libstdc++ and
  libc++.
 
+.. option:: -rtlib=
+
+ Specify the compiler runtime library to use; supported options are libgcc and
+ compiler-rt.
+
 .. option:: -ansi
 
  Same as -std=c89.


Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1860,7 +1860,8 @@
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[DriverOption]>,
   Alias;
 def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>;
-def rtlib_EQ : Joined<["-", "--"], "rtlib=">;
+def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
+  HelpText<"Compiler runtime library to use">;
 def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[DriverOption]>,
   HelpText<"Save intermediate compilation results.">;
Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -107,6 +107,11 @@
  Specify the C++ standard library to use; supported options are libstdc++ and
  libc++.
 
+.. option:: -rtlib=
+
+ Specify the compiler runtime library to use; supported options are libgcc and
+ compiler-rt.
+
 .. option:: -ansi
 
  Same as -std=c89.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24069: Document option '-rtlib' in clang's man page and help info

2016-08-31 Thread Lei Zhang via cfe-commits
zlei added inline comments.


Comment at: docs/CommandGuide/clang.rst:114
@@ -110,1 +113,3 @@
+ compiler-rt.
+
 .. option:: -ansi

bruno wrote:
> It might be worth mentioning what's the default behaviour in case the flag 
> isn't specified?
This option behaves a lot like `-stdlib`, so I want their doc entries to look 
alike too. Perhaps I should update them both to state the default behavior?


https://reviews.llvm.org/D24069



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24119: [libc++] add linker option "-Wl, -z, defs" in standalone build

2016-08-31 Thread Lei Zhang via cfe-commits
zlei created this revision.
zlei added a reviewer: cfe-commits.

This option is used to avoid underlinking. It's available in LLVM's main tree, 
but not in a standalone build of libc++. This patch ensures the option is 
passed in whether libc++ is built in-tree or out-of-tree.

https://reviews.llvm.org/D24119

Files:
  CMakeLists.txt

Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -305,6 +305,18 @@
 # so they don't get transformed into -Wno and -errors respectivly.
 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 
+# FIXME: this is cribbed from HandleLLVMOptions.cmake.
+if(LIBCXX_STANDALONE_BUILD)
+  # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
+  # build might work on ELF but fail on MachO/COFF.
+  if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR
+  ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR
+  ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND
+ NOT LLVM_USE_SANITIZER)
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
+  endif()
+endif()
+
 # Required flags ==
 set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build 
dialect")
 add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER})


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -305,6 +305,18 @@
 # so they don't get transformed into -Wno and -errors respectivly.
 remove_flags(-Wno-pedantic -pedantic-errors -pedantic)
 
+# FIXME: this is cribbed from HandleLLVMOptions.cmake.
+if(LIBCXX_STANDALONE_BUILD)
+  # Pass -Wl,-z,defs. This makes sure all symbols are defined. Otherwise a DSO
+  # build might work on ELF but fail on MachO/COFF.
+  if(NOT (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR WIN32 OR CYGWIN OR
+  ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR
+  ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") AND
+ NOT LLVM_USE_SANITIZER)
+set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
+  endif()
+endif()
+
 # Required flags ==
 set(LIBCXX_STANDARD_VER c++11 CACHE INTERNAL "internal option to change build dialect")
 add_compile_flags_if_supported(-std=${LIBCXX_STANDARD_VER})
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24069: Document option '-rtlib' in clang's man page and help info

2016-08-31 Thread Lei Zhang via cfe-commits
zlei edited reviewers, added: bruno; removed: cfe-commits.
zlei edited subscribers, added: cfe-commits; removed: bruno.
zlei updated this revision to Diff 69947.
zlei added a comment.

Update the man page entry to state default behavior of this option.


https://reviews.llvm.org/D24069

Files:
  docs/CommandGuide/clang.rst
  include/clang/Driver/Options.td

Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1860,7 +1860,8 @@
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[DriverOption]>,
   Alias;
 def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>;
-def rtlib_EQ : Joined<["-", "--"], "rtlib=">;
+def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
+  HelpText<"Compiler runtime library to use">;
 def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[DriverOption]>,
   HelpText<"Save intermediate compilation results.">;
Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -105,7 +105,12 @@
 .. option:: -stdlib=
 
  Specify the C++ standard library to use; supported options are libstdc++ and
- libc++.
+ libc++. If not specified, platform default will be used.
+
+.. option:: -rtlib=
+
+ Specify the compiler runtime library to use; supported options are libgcc and
+ compiler-rt. If not specified, platform default will be used.
 
 .. option:: -ansi
 


Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1860,7 +1860,8 @@
 def resource_dir_EQ : Joined<["-"], "resource-dir=">, Flags<[DriverOption]>,
   Alias;
 def rpath : Separate<["-"], "rpath">, Flags<[LinkerInput]>;
-def rtlib_EQ : Joined<["-", "--"], "rtlib=">;
+def rtlib_EQ : Joined<["-", "--"], "rtlib=">,
+  HelpText<"Compiler runtime library to use">;
 def r : Flag<["-"], "r">, Flags<[LinkerInput,NoArgumentUnused]>;
 def save_temps_EQ : Joined<["-", "--"], "save-temps=">, Flags<[DriverOption]>,
   HelpText<"Save intermediate compilation results.">;
Index: docs/CommandGuide/clang.rst
===
--- docs/CommandGuide/clang.rst
+++ docs/CommandGuide/clang.rst
@@ -105,7 +105,12 @@
 .. option:: -stdlib=
 
  Specify the C++ standard library to use; supported options are libstdc++ and
- libc++.
+ libc++. If not specified, platform default will be used.
+
+.. option:: -rtlib=
+
+ Specify the compiler runtime library to use; supported options are libgcc and
+ compiler-rt. If not specified, platform default will be used.
 
 .. option:: -ansi
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D24069: Document option '-rtlib' in clang's man page and help info

2016-09-13 Thread Lei Zhang via cfe-commits
zlei added a comment.

In https://reviews.llvm.org/D24069#540804, @Hahnfeld wrote:

> @zlei will you commit the patch or do you want me to do that on your behalf?


I don't have commit access, so please do me a favor :)


https://reviews.llvm.org/D24069



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-21 Thread Lei Zhang via cfe-commits
zlei created this revision.
zlei added reviewers: cfe-commits, ddunbar, Hahnfeld.

This patch introduces a new cmake variable: CLANG_DEFAULT_RTLIB, thru
which we can specify a default value for -rtlib (libgcc or
compiler-rt) at build time, just like how we set the default C++
stdlib thru CLANG_DEFAULT_CXX_STDLIB.

With these two options, we can configure clang to build binaries on
Linux that have no runtime dependence on any gcc libs (libstdc++ or
libgcc_s).

https://reviews.llvm.org/D22663

Files:
  CMakeLists.txt
  include/clang/Config/config.h.cmake
  lib/Driver/ToolChain.cpp

Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -526,16 +526,16 @@
 
 ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
 const ArgList &Args) const {
-  if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
-StringRef Value = A->getValue();
-if (Value == "compiler-rt")
-  return ToolChain::RLT_CompilerRT;
-if (Value == "libgcc")
-  return ToolChain::RLT_Libgcc;
-getDriver().Diag(diag::err_drv_invalid_rtlib_name)
-  << A->getAsString(Args);
-  }
+  const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
+  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
 
+  if (LibName == "compiler-rt")
+return ToolChain::RLT_CompilerRT;
+  if (LibName == "libgcc")
+return ToolChain::RLT_Libgcc;
+  if (A)
+getDriver().Diag(diag::err_drv_invalid_rtlib_name) << A->getAsString(Args);
+
   return GetDefaultRuntimeLibType();
 }
 
Index: include/clang/Config/config.h.cmake
===
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -11,6 +11,9 @@
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 
+/* Default runtime library to use. */
+#define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}"
+
 /* Default OpenMP runtime used by -fopenmp. */
 #define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
 
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -201,6 +201,15 @@
   set(CLANG_DEFAULT_CXX_STDLIB "")
 endif()
 
+set(CLANG_DEFAULT_RTLIB "" CACHE STRING
+  "Default runtime library to use (libgcc or compiler-rt)")
+if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
+CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
+CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
+  message(WARNING "Resetting default rtlib to use platform default")
+  set(CLANG_DEFAULT_RTLIB "")
+endif()
+
 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
   "Default OpenMP runtime used by -fopenmp.")
 


Index: lib/Driver/ToolChain.cpp
===
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -526,16 +526,16 @@
 
 ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
 const ArgList &Args) const {
-  if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
-StringRef Value = A->getValue();
-if (Value == "compiler-rt")
-  return ToolChain::RLT_CompilerRT;
-if (Value == "libgcc")
-  return ToolChain::RLT_Libgcc;
-getDriver().Diag(diag::err_drv_invalid_rtlib_name)
-  << A->getAsString(Args);
-  }
+  const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
+  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
 
+  if (LibName == "compiler-rt")
+return ToolChain::RLT_CompilerRT;
+  if (LibName == "libgcc")
+return ToolChain::RLT_Libgcc;
+  if (A)
+getDriver().Diag(diag::err_drv_invalid_rtlib_name) << A->getAsString(Args);
+
   return GetDefaultRuntimeLibType();
 }
 
Index: include/clang/Config/config.h.cmake
===
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -11,6 +11,9 @@
 /* Default C++ stdlib to use. */
 #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
 
+/* Default runtime library to use. */
+#define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}"
+
 /* Default OpenMP runtime used by -fopenmp. */
 #define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
 
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -201,6 +201,15 @@
   set(CLANG_DEFAULT_CXX_STDLIB "")
 endif()
 
+set(CLANG_DEFAULT_RTLIB "" CACHE STRING
+  "Default runtime library to use (libgcc or compiler-rt)")
+if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
+CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
+CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
+  message(WARNING "Resetting default rtlib to use platform default")
+  set(CLANG_DEFAULT_RTLIB "")
+endif()
+
 set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
   "Default OpenMP runtime used by -fopenmp.")
 

[PATCH] D22716: [libunwind] support building shared lib and static lib simultaneously

2016-07-22 Thread Lei Zhang via cfe-commits
zlei created this revision.
zlei added reviewers: rmaprath, EricWF, cfe-commits.

Currently libunwind can be configured to build either shared lib or static lib, 
but not both. Downstream package maintainers may want to build/install shared 
lib and static lib simultaneously, without configuring twice.

This patch enables building static lib along with shared lib.

https://reviews.llvm.org/D22716

Files:
  CMakeLists.txt
  src/CMakeLists.txt

Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -49,20 +49,12 @@
 ${LIBUNWIND_C_SOURCES}
 ${LIBUNWIND_ASM_SOURCES})
 
-if (LIBUNWIND_ENABLE_SHARED)
-  add_library(unwind SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
-else()
-  add_library(unwind STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
-endif ()
-
 # Generate library list.
 set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
 append_if(libraries LIBUNWIND_HAS_C_LIB c)
 append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
 append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
 
-target_link_libraries(unwind ${libraries})
-
 # Setup flags.
 append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_FPIC_FLAG -fPIC)
 append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti)
@@ -97,19 +89,40 @@
 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
 
-set_target_properties(unwind
-  PROPERTIES
-COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
-LINK_FLAGS"${LIBUNWIND_LINK_FLAGS}"
-OUTPUT_NAME   "unwind"
-VERSION   "1.0"
-SOVERSION "1")
 set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
  APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_CXX_FLAGS} 
${LIBUNWIND_CXX_FLAGS}")
 set_property(SOURCE ${LIBUNWIND_C_SOURCES}
  APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_C_FLAGS} 
${LIBUNWIND_C_FLAGS}")
 
-install(TARGETS unwind
+set(LIBUNWIND_TARGETS)
+
+if (LIBUNWIND_ENABLE_SHARED)
+  add_library(unwind_shared SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
+  target_link_libraries(unwind_shared ${libraries})
+  set_target_properties(unwind_shared
+PROPERTIES
+  COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
+  LINK_FLAGS"${LIBUNWIND_LINK_FLAGS}"
+  OUTPUT_NAME   "unwind"
+  VERSION   "1.0"
+  SOVERSION "1")
+  list(APPEND LIBUNWIND_TARGETS "unwind_shared")
+endif ()
+
+if (LIBUNWIND_ENABLE_STATIC)
+  add_library(unwind_static STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
+  target_link_libraries(unwind_static ${libraries})
+  set_target_properties(unwind_static
+PROPERTIES
+  COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
+  LINK_FLAGS"${LIBUNWIND_LINK_FLAGS}"
+  OUTPUT_NAME   "unwind")
+  list(APPEND LIBUNWIND_TARGETS "unwind_static")
+endif ()
+
+add_custom_target(unwind DEPENDS ${LIBUNWIND_TARGETS})
+
+install(TARGETS ${LIBUNWIND_TARGETS}
 LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
 ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX})
 
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -104,6 +104,7 @@
 option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
 option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
 option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
+option(LIBUNWIND_ENABLE_STATIC "Build libunwind as a static library." OFF)
 option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding 
support." OFF)
 option(LIBUNWIND_ENABLE_ARM_WMMX "Enable unwinding support for ARM WMMX 
registers." OFF)
 


Index: src/CMakeLists.txt
===
--- src/CMakeLists.txt
+++ src/CMakeLists.txt
@@ -49,20 +49,12 @@
 ${LIBUNWIND_C_SOURCES}
 ${LIBUNWIND_ASM_SOURCES})
 
-if (LIBUNWIND_ENABLE_SHARED)
-  add_library(unwind SHARED ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
-else()
-  add_library(unwind STATIC ${LIBUNWIND_SOURCES} ${LIBUNWIND_HEADERS})
-endif ()
-
 # Generate library list.
 set(libraries ${LIBUNWINDCXX_ABI_LIBRARIES})
 append_if(libraries LIBUNWIND_HAS_C_LIB c)
 append_if(libraries LIBUNWIND_HAS_DL_LIB dl)
 append_if(libraries LIBUNWIND_HAS_PTHREAD_LIB pthread)
 
-target_link_libraries(unwind ${libraries})
-
 # Setup flags.
 append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_FPIC_FLAG -fPIC)
 append_if(LIBUNWIND_CXX_FLAGS LIBUNWIND_HAS_NO_RTTI_FLAG -fno-rtti)
@@ -97,19 +89,40 @@
 string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
 string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLA

Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-25 Thread Lei Zhang via cfe-commits
zlei added a comment.

In https://reviews.llvm.org/D22663#494460, @Hahnfeld wrote:

> With the changes applied and configured with 
> `CLANG_DEFAULT_RTLIB=compiler-rt` some tests fail so you may have to adapt 
> the idea of `-rtlib=platform` for the tests.


Got it. And I also need to fix those failing tests by adding `-rtlib=platform` 
to them, right?



Comment at: CMakeLists.txt:210
@@ +209,3 @@
+  message(WARNING "Resetting default rtlib to use platform default")
+  set(CLANG_DEFAULT_RTLIB "")
+endif()

beanz wrote:
> You'll want this to be:
> 
> 
> ```
> set(CLANG_DEFAULT_RTLIB "" CACHE STRING "Default runtime library to use 
> (libgcc or compiler-rt)" FORCE)
> ```
> 
> Cached variables can only be overwritten by a `FORCE`.
Sorry, I'm not very familiar with cmake. But why isn't 
`CLANG_DEFAULT_CXX_STDLIB` declared with `FORCE`? Should I fix it as well?


Comment at: lib/Driver/ToolChain.cpp:530
@@ -538,1 +529,3 @@
+  const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
+  StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
 

Hahnfeld wrote:
> What I dislike here is that it falls back to the platform default if the 
> specified argument value is invalid regardless of what was configured. This 
> may be surprising for the user as he gets a different behaviour when 
> specifiying `-rtlib=bla` than completely omitting.
> 
> I just added a comment explaining how this works in `GetCXXStdlibType`. Maybe 
> you can adapt its idea?
If you give an invalid value to `-rtlib`, clang should just abort and give you 
an error message, instead of falling back to the platform default. I see that's 
also how `-stdlib` behaves.

Or maybe I misunderstood your point?


https://reviews.llvm.org/D22663



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-26 Thread Lei Zhang via cfe-commits
zlei updated this revision to Diff 65497.
zlei added a comment.
Herald added subscribers: srhines, danalbert, tberghammer.

Support a new option `-rtlib=platform` for internal use, and fix tests that 
previously failed when configured with `CLANG_DEFAULT_RTLIB=compiler-rt`.


https://reviews.llvm.org/D22663

Files:
  CMakeLists.txt
  include/clang/Config/config.h.cmake
  lib/Driver/ToolChain.cpp
  test/Driver/linux-ld.c
  test/Driver/miamcu-opt.c
  test/Driver/miamcu-opt.cpp
  test/Driver/mingw-libgcc.c
  test/Driver/mingw.cpp
  test/Driver/sanitizer-ld.c
  test/Driver/windows-cross.c
  test/OpenMP/linking.c

Index: test/OpenMP/linking.c
===
--- test/OpenMP/linking.c
+++ test/OpenMP/linking.c
@@ -4,42 +4,42 @@
 // FIXME: Replace DEFAULT_OPENMP_LIB below with the value chosen at configure time.
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target i386-unknown-linux \
+// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-32 %s
 // CHECK-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
 // CHECK-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target x86_64-unknown-linux \
+// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-64 %s
 // CHECK-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
 // CHECK-LD-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libgomp -target i386-unknown-linux \
+// RUN: -fopenmp=libgomp -target i386-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-GOMP-LD-32 %s
 // CHECK-GOMP-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-GOMP-LD-32: "-lgomp" "-lrt" "-lgcc"
 // CHECK-GOMP-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libgomp -target x86_64-unknown-linux \
+// RUN: -fopenmp=libgomp -target x86_64-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-GOMP-LD-64 %s
 // CHECK-GOMP-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-GOMP-LD-64: "-lgomp" "-lrt" "-lgcc"
 // CHECK-GOMP-LD-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target i386-unknown-linux \
+// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-IOMP5-LD-32 %s
 // CHECK-IOMP5-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-IOMP5-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
 // CHECK-IOMP5-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target x86_64-unknown-linux \
+// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-IOMP5-LD-64 %s
 // CHECK-IOMP5-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-IOMP5-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
@@ -57,29 +57,31 @@
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -fopenmp -fopenmp=libgomp -target i386-unknown-linux \
+// RUN: -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-OVERRIDE-32 %s
 // CHECK-LD-OVERRIDE-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-OVERRIDE-32: "-lgomp" "-lrt" "-lgcc"
 // CHECK-LD-OVERRIDE-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -fopenmp -fopenmp=libgomp -target x86_64-unknown-linux \
+// RUN: -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-OVERRIDE-64 %s
 // CHECK-LD-OVERRIDE-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt" "-lgcc"
 // CHECK-LD-OVERRIDE-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libomp -target x86_64-msvc-win32 \
+// RUN: -fopenmp=libomp -target x86_64-msvc-win32 -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-MSVC-LINK-64 %s
 // CHECK-MSVC-LINK-64: link.exe
 // CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcomp.lib
 // CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcompd.lib
 // CHECK-MSVC-LINK-64-SAME: -libpath:{{.+}}/../lib
 // CHECK-MSVC-LINK-64-SAME: -defaultlib:libomp.lib
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 \
+// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-MSVC-ILINK-64 %s
 // CHECK-MSVC-ILINK-64: link.exe
 // CHECK-MSVC-ILINK-64-SAME: -nodefaultlib:vcomp.lib
Index: test/Driver/windows-cross.c
===
--- test/Driver/windows-cross.c
+++ test/Driver/windows-cross.c
@@ -1,4 +1,4 @@
-// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inp

Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-26 Thread Lei Zhang via cfe-commits
zlei added inline comments.


Comment at: CMakeLists.txt:210
@@ -202,3 +209,3 @@
 
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")

I think the original code for resetting `CLANG_DEFAULT_CXX_STDLIB` doesn't work 
as expected, as beanz pointed out.

In this revision, I just disable invalid values for both 
`CLANG_DEFAULT_CXX_STDLIB` and `CLANG_DEFAULT_RTLIB`. Users will get a error 
message when assigning unsupported values to them.


https://reviews.llvm.org/D22663



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-26 Thread Lei Zhang via cfe-commits
zlei added inline comments.


Comment at: CMakeLists.txt:210
@@ -202,3 +209,3 @@
 
 set(CLANG_VENDOR ${PACKAGE_VENDOR} CACHE STRING
   "Vendor-specific text for showing with version information.")

Hahnfeld wrote:
> zlei wrote:
> > I think the original code for resetting `CLANG_DEFAULT_CXX_STDLIB` doesn't 
> > work as expected, as beanz pointed out.
> > 
> > In this revision, I just disable invalid values for both 
> > `CLANG_DEFAULT_CXX_STDLIB` and `CLANG_DEFAULT_RTLIB`. Users will get a 
> > error message when assigning unsupported values to them.
> I tested it this morning and it works as (at least I) expected: It will 
> temporarily reset the value and warn the user that the parameter is not valid.
> 
> I'm against erroring out here because there actually is a sane default 
> value...
I don't have a strong opinion on this, but the problem is the original line 
`set(CLANG_DEFAULT_CXX_STDLIB "")` doesn't have actual effect (it seems to me).

I'm not sure what you mean by "temporarily reset the value". Last time I tested 
it, `-DCLANG_DEFAULT_CXX_STDLIB=blah` doesn't reset the value to an empty 
string (as expected?)

Anyway, I'm fine with either warning or erroring :)


https://reviews.llvm.org/D22663



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-26 Thread Lei Zhang via cfe-commits
zlei updated this revision to Diff 65643.
zlei added a comment.

Fix a bug on Darwin that crashes clang when `CLANG_DEFAULT_RTLIB=libgcc`


https://reviews.llvm.org/D22663

Files:
  CMakeLists.txt
  include/clang/Config/config.h.cmake
  lib/Driver/ToolChain.cpp
  lib/Driver/ToolChains.cpp
  lib/Driver/ToolChains.h
  test/Driver/linux-ld.c
  test/Driver/miamcu-opt.c
  test/Driver/miamcu-opt.cpp
  test/Driver/mingw-libgcc.c
  test/Driver/mingw.cpp
  test/Driver/mips-mti-linux.c
  test/Driver/sanitizer-ld.c
  test/Driver/windows-cross.c
  test/OpenMP/linking.c

Index: test/OpenMP/linking.c
===
--- test/OpenMP/linking.c
+++ test/OpenMP/linking.c
@@ -4,42 +4,42 @@
 // FIXME: Replace DEFAULT_OPENMP_LIB below with the value chosen at configure time.
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target i386-unknown-linux \
+// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-32 %s
 // CHECK-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
 // CHECK-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target x86_64-unknown-linux \
+// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-64 %s
 // CHECK-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
 // CHECK-LD-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libgomp -target i386-unknown-linux \
+// RUN: -fopenmp=libgomp -target i386-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-GOMP-LD-32 %s
 // CHECK-GOMP-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-GOMP-LD-32: "-lgomp" "-lrt" "-lgcc"
 // CHECK-GOMP-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libgomp -target x86_64-unknown-linux \
+// RUN: -fopenmp=libgomp -target x86_64-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-GOMP-LD-64 %s
 // CHECK-GOMP-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-GOMP-LD-64: "-lgomp" "-lrt" "-lgcc"
 // CHECK-GOMP-LD-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target i386-unknown-linux \
+// RUN: -fopenmp -target i386-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-IOMP5-LD-32 %s
 // CHECK-IOMP5-LD-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-IOMP5-LD-32: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
 // CHECK-IOMP5-LD-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp -target x86_64-unknown-linux \
+// RUN: -fopenmp -target x86_64-unknown-linux -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-IOMP5-LD-64 %s
 // CHECK-IOMP5-LD-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-IOMP5-LD-64: "-l[[DEFAULT_OPENMP_LIB:[^"]*]]" "-lgcc"
@@ -57,29 +57,31 @@
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -fopenmp -fopenmp=libgomp -target i386-unknown-linux \
+// RUN: -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-OVERRIDE-32 %s
 // CHECK-LD-OVERRIDE-32: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-OVERRIDE-32: "-lgomp" "-lrt" "-lgcc"
 // CHECK-LD-OVERRIDE-32: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
 // RUN: -fopenmp -fopenmp=libgomp -target x86_64-unknown-linux \
+// RUN: -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-OVERRIDE-64 %s
 // CHECK-LD-OVERRIDE-64: "{{.*}}ld{{(.exe)?}}"
 // CHECK-LD-OVERRIDE-64: "-lgomp" "-lrt" "-lgcc"
 // CHECK-LD-OVERRIDE-64: "-lpthread" "-lc"
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libomp -target x86_64-msvc-win32 \
+// RUN: -fopenmp=libomp -target x86_64-msvc-win32 -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-MSVC-LINK-64 %s
 // CHECK-MSVC-LINK-64: link.exe
 // CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcomp.lib
 // CHECK-MSVC-LINK-64-SAME: -nodefaultlib:vcompd.lib
 // CHECK-MSVC-LINK-64-SAME: -libpath:{{.+}}/../lib
 // CHECK-MSVC-LINK-64-SAME: -defaultlib:libomp.lib
 //
 // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
-// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 \
+// RUN: -fopenmp=libiomp5 -target x86_64-msvc-win32 -rtlib=platform \
 // RUN:   | FileCheck --check-prefix=CHECK-MSVC-ILINK-64 %s
 // CHECK-MSVC-ILINK-64: link.exe
 // CHECK-MSVC-ILINK-64-SAME: -nodefaultlib:vcomp.lib
Index: test/Driver/windows-cross.c
===
--- test/Driver/windows-cross.c
+++ test/Driver/windows-cross.c
@@ -1,4 +1,4 @@
-// RUN: %clang -### -target armv7-windows-itanium --sysroot %S/Inputs/Windows/ARM/8.1 -B %S/Inputs/Windows/ARM/8.1/usr

Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-26 Thread Lei Zhang via cfe-commits
zlei added a comment.

@Hahnfeld Your patch applied. Thanks.


https://reviews.llvm.org/D22663



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22663: Support setting default value for -rtlib at build time

2016-07-27 Thread Lei Zhang via cfe-commits
zlei added a comment.

@Hahnfeld Could you please commit it? I don't have the access.

Thanks :)


https://reviews.llvm.org/D22663



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D22904: Fix two bugs for musl-libc on ARM

2016-07-28 Thread Lei Zhang via cfe-commits
zlei created this revision.
zlei added reviewers: cfe-commits, rafael.
Herald added subscribers: samparker, srhines, danalbert, tberghammer, rengolin, 
aemerson.

Bug #1: triples like `armv7-pc-linux-musl` uses wrong linker name 
`ld-musl-armv7.so.1`; the right name should be `ld-musl-arm.so.1`, disregarding 
the subarch field.

Bug #2: when compiler option `-mhard-float` is used, we should use the 
"hardfloat" linker, no matter whether the triple itself mentions "hardfloat".

https://reviews.llvm.org/D22904

Files:
  lib/Driver/ToolChains.cpp

Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4262,21 +4262,29 @@
 
   const enum Distro Distro = DetectDistro(getDriver(), Arch);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
 return Triple.isArch64Bit() ? "/system/bin/linker64" : 
"/system/bin/linker";
-  else if (Triple.isMusl()) {
+  } else if (Triple.isMusl()) {
 std::string ArchName;
+bool IsArm = false;
+
 switch (Arch) {
+case llvm::Triple::arm:
 case llvm::Triple::thumb:
   ArchName = "arm";
+  IsArm = true;
   break;
+case llvm::Triple::armeb:
 case llvm::Triple::thumbeb:
   ArchName = "armeb";
+  IsArm = true;
   break;
 default:
   ArchName = Triple.getArchName().str();
 }
-if (Triple.getEnvironment() == llvm::Triple::MuslEABIHF)
+if (IsArm &&
+(Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
+ tools::arm::getARMFloatABI(*this, Args) == 
tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
 return "/lib/ld-musl-" + ArchName + ".so.1";


Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4262,21 +4262,29 @@
 
   const enum Distro Distro = DetectDistro(getDriver(), Arch);
 
-  if (Triple.isAndroid())
+  if (Triple.isAndroid()) {
 return Triple.isArch64Bit() ? "/system/bin/linker64" : "/system/bin/linker";
-  else if (Triple.isMusl()) {
+  } else if (Triple.isMusl()) {
 std::string ArchName;
+bool IsArm = false;
+
 switch (Arch) {
+case llvm::Triple::arm:
 case llvm::Triple::thumb:
   ArchName = "arm";
+  IsArm = true;
   break;
+case llvm::Triple::armeb:
 case llvm::Triple::thumbeb:
   ArchName = "armeb";
+  IsArm = true;
   break;
 default:
   ArchName = Triple.getArchName().str();
 }
-if (Triple.getEnvironment() == llvm::Triple::MuslEABIHF)
+if (IsArm &&
+(Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
+ tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
 return "/lib/ld-musl-" + ArchName + ".so.1";
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22904: Fix two bugs for musl-libc on ARM

2016-07-28 Thread Lei Zhang via cfe-commits
zlei updated this revision to Diff 66074.
zlei added a comment.

Restructure the code and add a few tests.


https://reviews.llvm.org/D22904

Files:
  lib/Driver/ToolChains.cpp
  test/Driver/linux-ld.c

Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -1613,24 +1613,36 @@
 // RUN: --target=thumb-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=thumbv7-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=thumbeb-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=thumbeb-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=thumbv7eb-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARM %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=armeb-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=armeb-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7eb-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=aarch64-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-AARCH64 %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
Index: lib/Driver/ToolChains.cpp
===
--- lib/Driver/ToolChains.cpp
+++ lib/Driver/ToolChains.cpp
@@ -4264,19 +4264,28 @@
 
   if (Triple.isAndroid())
 return Triple.isArch64Bit() ? "/system/bin/linker64" : 
"/system/bin/linker";
-  else if (Triple.isMusl()) {
+
+  if (Triple.isMusl()) {
 std::string ArchName;
+bool IsArm = false;
+
 switch (Arch) {
+case llvm::Triple::arm:
 case llvm::Triple::thumb:
   ArchName = "arm";
+  IsArm = true;
   break;
+case llvm::Triple::armeb:
 case llvm::Triple::thumbeb:
   ArchName = "armeb";
+  IsArm = true;
   break;
 default:
   ArchName = Triple.getArchName().str();
 }
-if (Triple.getEnvironment() == llvm::Triple::MuslEABIHF)
+if (IsArm &&
+(Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
+ tools::arm::getARMFloatABI(*this, Args) == 
tools::arm::FloatABI::Hard))
   ArchName += "hf";
 
 return "/lib/ld-musl-" + ArchName + ".so.1";


Index: test/Driver/linux-ld.c
===
--- test/Driver/linux-ld.c
+++ test/Driver/linux-ld.c
@@ -1613,24 +1613,36 @@
 // RUN: --target=thumb-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=thumbv7-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=thumbeb-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=thumbeb-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=thumbv7eb-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARM %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=arm-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7-pc-linux-musleabi -mhard-float \
+// RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMHF %s
+// RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=armeb-pc-linux-musleabi \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEB %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
 // RUN: --target=armeb-pc-linux-musleabihf \
 // RUN:   | FileCheck --check-prefix=CHECK-MUSL-ARMEBHF %s
 // RUN: %clang %s -### -o %t.o 2>&1 \
+// RUN: --target=armv7eb-pc-linux-musleabi -mhard-float \
+// R

Re: [PATCH] D22904: Fix two bugs for musl-libc on ARM

2016-07-28 Thread Lei Zhang via cfe-commits
zlei added a comment.

@rengolin Thanks for your comments. Patch updated.


https://reviews.llvm.org/D22904



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22904: Fix two bugs for musl-libc on ARM

2016-08-07 Thread Lei Zhang via cfe-commits
zlei added a comment.

@rengolin Could you please apply this patch? I don't have the permission.

Thanks.


https://reviews.llvm.org/D22904



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D22904: Fix two bugs for musl-libc on ARM

2016-08-08 Thread Lei Zhang via cfe-commits
zlei added a comment.

@rovka Thanks a lot :)


Repository:
  rL LLVM

https://reviews.llvm.org/D22904



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Add support for musl-libc on Linux

2016-06-11 Thread Lei Zhang via cfe-commits
Hi,

The first patch introduces musl as a new environment type in LLVM; the
second helps clang to find musl's dynamic linker, which has a
different naming scheme from glibc's.

The two patches together enable clang to support targets like
"x86_64-pc-linux-musl" and build binaries against musl-libc instead of
glibc. This make it easy for clang to work on some musl-based systems
like Alpine Linux and certain flavors of Gentoo.


Regards,
Lei


llvm-musl.patch
Description: Binary data


clang-musl.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Add support for musl-libc on Linux

2016-06-11 Thread Lei Zhang via cfe-commits
Hi,

I'm replying to this thread; sorry I wasn't subscribed to the list,
thus cannot reply to it directly.

http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160606/161733.html

Joerg, thanks for your reply. Could you please tell me what kind of
test cases I should prepare?


Thanks,
Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Add support for musl-libc on Linux

2016-06-13 Thread Lei Zhang via cfe-commits
2016-06-13 3:07 GMT+08:00 Joerg Sonnenberger :
> On Sun, Jun 12, 2016 at 10:51:11AM +0800, Lei Zhang via llvm-commits wrote:
>> Hi,
>>
>> I'm replying to this thread; sorry I wasn't subscribed to the list,
>> thus cannot reply to it directly.
>>
>> http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160606/161733.html
>>
>> Joerg, thanks for your reply. Could you please tell me what kind of
>> test cases I should prepare?
>
> The target/triple parser has a unit test in
> unittests/ADT/TripleTest.cpp. The rest should get output validation in
> clang's test/Driver directory. Not sure which one is the primary
> GNU/Linux test.

Thanks for the pointer :)

The patches are re-attached with test cases included. Do they look sane enough?


Lei


llvm-musl.patch
Description: Binary data


clang-musl.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Add support for musl-libc on Linux

2016-06-13 Thread Lei Zhang via cfe-commits
2016-06-13 21:02 GMT+08:00 Rafael Espíndola :
> Should musl really be an environment? What happens when targeting ARM,
> do we get a gnueabi+musl? Is it used as an environment when
> configuring gcc?

Honestly I couldn't judge if musl *should* be an environment. But it
*is* used as an environment when configuring gcc, and
"x86_64-pc-linux-musl" could be parsed by config.sub as a valid
triplet.

As for ARM, I guess something like arm-linux-musleabi would do.


Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-13 Thread Lei Zhang via cfe-commits
2016-06-13 21:21 GMT+08:00 Felix Janda :
> [Added CC to the musl list]
>
> Lei Zhang wrote:
>> 2016-06-13 3:07 GMT+08:00 Joerg Sonnenberger :
>> > On Sun, Jun 12, 2016 at 10:51:11AM +0800, Lei Zhang via llvm-commits wrote:
>> >> Hi,
>> >>
>> >> I'm replying to this thread; sorry I wasn't subscribed to the list,
>> >> thus cannot reply to it directly.
>> >>
>> >> http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20160606/161733.html
>> >>
>> >> Joerg, thanks for your reply. Could you please tell me what kind of
>> >> test cases I should prepare?
>> >
>> > The target/triple parser has a unit test in
>> > unittests/ADT/TripleTest.cpp. The rest should get output validation in
>> > clang's test/Driver directory. Not sure which one is the primary
>> > GNU/Linux test.
>>
>> Thanks for the pointer :)
>>
>> The patches are re-attached with test cases included. Do they look sane 
>> enough?
>
>> --- lib/Driver/ToolChains.cpp   (revision 272546)
>> +++ lib/Driver/ToolChains.cpp   (working copy)
>> @@ -4152,6 +4152,8 @@
>>
>>if (Triple.isAndroid())
>>  return Triple.isArch64Bit() ? "/system/bin/linker64" : 
>> "/system/bin/linker";
>> +  else if (Triple.getEnvironment() == llvm::Triple::Musl)
>> +return "/lib/ld-musl-" + Triple.getArchName().str() + ".so.1";
>
> It does not seem to me that the dynamic linker name detection will work
> on most archs not in the test cases. For example, the arm gentoo musl
> stage3's have the target triple

You're right. Frankly I've only had x86 platforms on my mind so far;
but I agree with Rafael that we could extend this to other archs in
the future.

> It seems difficult to get all cases right and some of them might not be
> very interesting, but it would be nice to have a more intelligent patch.
> See for example
>
> http://git.alpinelinux.org/cgit/aports/plain/main/clang/clang-0004-Add-musl-targets-and-dynamic-linker.patch

This looks neat :)


Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-13 Thread Lei Zhang via cfe-commits
2016-06-14 5:00 GMT+08:00 Rafael Espíndola :
> Do you need someone to commit it for you?

Yes, please :)


Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-15 Thread Lei Zhang via cfe-commits
2016-06-14 20:55 GMT+08:00 Rafael Espíndola :
> On 13 June 2016 at 21:07, Lei Zhang  wrote:
>> 2016-06-14 5:00 GMT+08:00 Rafael Espíndola :
>>> Do you need someone to commit it for you?
>>
>> Yes, please :)
>
> Committed.

Thanks!

Here's another patch including test cases for various non-x86 archs,
which should just work with my previous patches. ARM is left out
purposely since it involves extra complexity. I'll work on it later.


Lei


musl-test.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-17 Thread Lei Zhang via cfe-commits
2016-06-15 16:28 GMT+08:00 Lei Zhang :
> Here's another patch including test cases for various non-x86 archs,
> which should just work with my previous patches. ARM is left out
> purposely since it involves extra complexity. I'll work on it later.

Hi,

Here are another two patches which add support for ARM, with some test
cases included.

They're a lot bigger than previous patches, and I'm not 100% sure if I
missed anything. Any comments are utterly welcome :)


Lei


llvm-musl-arm.patch
Description: Binary data


clang-musl-arm.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-20 Thread Lei Zhang via cfe-commits
2016-06-20 17:37 GMT+08:00 Peter Smith :
> Hello Lei,

Hi, thanks for your reply!

> I agree with Rafael that this is currently missing a few critical
> things right now, especially in the llvm patch.
>
> My (limited) understanding of musl is that it intends to support the
> same interface as GNUEABI and GNUEABIHF, but it is obviously a
> different implementation.
>
> This is what I could find with a basic grep for GNUAEABI and working
> out from there.
>
> Clang patch
> I'm assuming you are only intending to support Musl on linux, and not BSD.

Yes.

> ToolChains.cpp
> - getDynamicLinker()
> There is a Triple.getEnvironment() == llvm::triple::GNUEABIHF which
> selects between ld-linux-armhf.so.3 or ld-linux.so.3. I think you'll
> need ld-linux-armhf.so.3 for MUSLHF here as well.

Actually musl's dynamic linker has a different naming scheme from
glibc's, which is handled by an extra chunk of code in the patch. The
code you mentioned won't be reached when musl is present, and thus
need no change.

> LLVM patch
> ARMSubtarget.h
> - isTargetGNUAEABI()
> I think you'll need to check all the callsites of this function, and
> check what you want isTargetMusl() to do. At present I think you'll
> want them to do the same thing in all cases except finding the
> implementation. There looks to be a trade off between adding MUSCL and
> MUSCLHF to isTargetGNUAEABI(), adding something like
> isTargetGNUAEABIInterface() and adding isTargetMusl() to all the
> callsites.
>
> - isTargetEHABICompatible()
> I'm making the assumption that musl supports the ARM exceptions EHABI,
> if so you'll want to add MUSL and MUSLHF here.

I'm not 100% sure about this. Could some insider from musl confirm this?

> - isTargetHardFloat()
> You'll want to add MUSLHF here.
>
> ARMTargetMachine.cpp
> - computeTargetABI()
> You'll want to add MUSL and MUSLHF alongside GNUEABI and GNUEABIHF in
> the switch.
>
> Hope this helps

In addition to what you mentioned, perhaps I should also add "Musl" as
a new EABI type in TargetOptions.h (in LLVM), just side by side with
"GNU", and change relevant bits in LLVM and clang accordingly.


Thanks again,
Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-20 Thread Lei Zhang via cfe-commits
2016-06-18 8:52 GMT+08:00 Rafael Espíndola :
> There are probably a few more places that need to be patched.
>
> In particular, take a look at lib/Target/ARM. There are things like
> computeTargetABI and isTargetHardFloat that probably need to be
> updated (and tested).

Any hints how to test the new changes? I guess merely checking clang's
output like the previous test cases won't suffice this time.


Thanks,
Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-20 Thread Lei Zhang via cfe-commits
2016-06-20 19:44 GMT+08:00 Peter Smith :
> From what I can see, the EABI type is used to decide if certain
> __aeabi_ prefixed functions such as __aeabi_idiv are available. If
> Musl differs in function availability from the GNU library here I
> think you'll need a Musl EABI type. However if there is no difference
> you should be able to use the EABI::GNU type for Musl.

I think musl and glibc is compatible on this; I'm just a little
concerned that using EABI::GNU for both GNUEABI* and MuslEABI* might
cause some confusion.

> You might find http://reviews.llvm.org/D12413 helpful here
> (introduction of -meabi option).

It seems clang's -meabi option is incompatible with gcc's.


Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-21 Thread Lei Zhang via cfe-commits
2016-06-20 19:05 GMT+08:00 Lei Zhang :
> 2016-06-18 8:52 GMT+08:00 Rafael Espíndola :
>> There are probably a few more places that need to be patched.
>>
>> In particular, take a look at lib/Target/ARM. There are things like
>> computeTargetABI and isTargetHardFloat that probably need to be
>> updated (and tested).
>
> Any hints how to test the new changes? I guess merely checking clang's
> output like the previous test cases won't suffice this time.

Here're the refined patches. Please let me know if the test cases
aren't complete.

Thanks,
Lei


clang-musl-arm-v2.patch
Description: Binary data


llvm-musl-arm-v2.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-22 Thread Lei Zhang via cfe-commits
2016-06-21 23:07 GMT+08:00 Peter Smith :
> Hello Lei,
>
> The changes to llvm and clang look ok to me. I've got some suggestions
> for testing.
>
> For the clang patch, it looks like there isn't a test to check that
> musleabihf implies hard floating point. It looks like
> Driver/arm-mfpu.c CHECK-HF might be a good candidate to add a test.
>
> For the llvm patch
>
> I think you should be able to find a test that checks the behaviour of
> GNUEABI and GNUEABIHF for each of the properties that you've added
> Subtarget->isTargetMuslAEABI() to or equivalent. It would be useful to
> add a test case for MUSLEABI and/or MUSLEABIHF. For example in the
> RTLIB case there are a large number of tests that check whether the
> correct __aeabi_ function is called.
>
> Some files I came across (there are many more) that might be a good
> place to check that musleabi and musleabihf behaves like gnueabi and
> gnueabihf:
> CodeGen/ARM/memfunc.ll
> CodeGen/Thumb2/float-ops.ll
> CodeGen/ARM/divmod-eabi.ll
> CodeGen/ARM/fp16.ll (hard-float for HF)
> MC/ARM/eh-directives-personalityindex.s

Thanks for the pointers! Please see the refined (again) patches.

As a side note, there's no "gnueabi" in float-ops.ll or
eh-directive-personalityindex.s, so I skipped them. In addition, I
found a few other relevant test files to patch thanks to your advice.


Lei


llvm-musl-arm-v3.patch
Description: Binary data


clang-musl-arm-v3.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-23 Thread Lei Zhang via cfe-commits
2016-06-22 16:55 GMT+08:00 Peter Smith :
> Hello Lei,
>
> Thanks for all the updates. That looks good to me from an ARM perspective.

Ping.

Are the patches good enough to be committed?


Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [gentoo-musl] Re: Add support for musl-libc on Linux

2016-06-24 Thread Lei Zhang via cfe-commits
2016-06-24 16:02 GMT+08:00 Peter Smith :
> Hello Lei,
>
> They look good enough for me. Unless anyone else has any objections I
> think you are good to go.

I just see them committed by r273735 in clang and r273726 in LLVM.

Peter, thank you for the comments; and Rafael, thank you for
committing the patches :)


Lei
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Support setting default value for -rtlib at build time

2016-07-17 Thread Lei Zhang via cfe-commits
Hi,

This patch introduces a new cmake variable: CLANG_DEFAULT_RTLIB, thru
which we can specify a default value for -rtlib (libgcc or
compiler-rt) at build time, just like how we set the default C++
stdlib thru CLANG_DEFAULT_CXX_STDLIB.

With these two options, we can configure clang to build binaries on
Linux that have no runtime dependence on any gcc libs (libstdc++ or
libgcc_s).


Regards,
Lei


clang-default-rtlib.patch
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits