Skip to content

Commit

Permalink
[mlir][sparse] Inline the definition of LLVM_ATTRIBUTE_WEAK
Browse files Browse the repository at this point in the history
This library is supposed not to have a dependency on LLVM, and linking
LLVMSupport into it breaks its shared library setup.
  • Loading branch information
d0k committed Jun 17, 2022
1 parent 9d5e6cc commit d5c29b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
15 changes: 12 additions & 3 deletions mlir/lib/ExecutionEngine/Float16bits.cpp
Expand Up @@ -12,7 +12,6 @@
//===----------------------------------------------------------------------===//

#include "mlir/ExecutionEngine/Float16bits.h"
#include "llvm/Support/Compiler.h"

namespace {

Expand Down Expand Up @@ -145,13 +144,23 @@ std::ostream &operator<<(std::ostream &os, const bf16 &d) {

// Provide a float->bfloat conversion routine in case the runtime doesn't have
// one.
extern "C" uint16_t LLVM_ATTRIBUTE_WEAK __truncsfbf2(float f) {
extern "C" uint16_t
#if defined(__has_attribute) && __has_attribute(weak) && \
!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)
__attribute__((__weak__))
#endif
__truncsfbf2(float f) {
return float2bfloat(f);
}

// Provide a double->bfloat conversion routine in case the runtime doesn't have
// one.
extern "C" uint16_t LLVM_ATTRIBUTE_WEAK __truncdfbf2(double d) {
extern "C" uint16_t
#if defined(__has_attribute) && __has_attribute(weak) && \
!defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(_WIN32)
__attribute__((__weak__))
#endif
__truncdfbf2(double d) {
// This does a double rounding step, but it's precise enough for our use
// cases.
return __truncsfbf2(static_cast<float>(d));
Expand Down
9 changes: 3 additions & 6 deletions utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Expand Up @@ -2226,14 +2226,14 @@ cc_library(
"lib/Dialect/NVGPU/Transforms/PassDetail.h",
],
hdrs = [
"include/mlir/Dialect/NVGPU/Transforms/Transforms.h",
"include/mlir/Dialect/NVGPU/Passes.h",
"include/mlir/Dialect/NVGPU/Transforms/Transforms.h",
],
includes = ["include"],
deps = [
":FuncDialect",
":AffineDialect",
":ArithmeticDialect",
":FuncDialect",
":GPUDialect",
":IR",
":MemRefDialect",
Expand Down Expand Up @@ -6264,8 +6264,8 @@ cc_library(
":MemRefTransforms",
":NVGPUDialect",
":NVGPUPassIncGen",
":NVGPUTransforms",
":NVGPUToNVVM",
":NVGPUTransforms",
":NVVMDialect",
":OpenACCDialect",
":OpenMPDialect",
Expand Down Expand Up @@ -6409,9 +6409,6 @@ cc_library(
"include/mlir/ExecutionEngine/SparseTensorUtils.h",
],
includes = ["include"],
deps = [
"//llvm:Support",
],
)

cc_library(
Expand Down

0 comments on commit d5c29b2

Please sign in to comment.