Skip to content

Commit d223061

Browse files
authored
Merge branch 'main' into fix/111854
2 parents edb0a54 + 3fc0d94 commit d223061

File tree

55 files changed

+1324
-327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1324
-327
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: rm -f a.c b.c
2+
3+
// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
4+
// CHECK: a.c:
5+
// CHECK-NEXT: b.c:

clang/test/Modules/no-external-type-id.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export module b;
2323
import a;
2424
export int b();
2525

26-
// CHECK: <DECL_FUNCTION {{.*}} op8=4112
26+
// CHECK: <DECL_FUNCTION {{.*}} op8=4120
2727
// CHECK: <TYPE_FUNCTION_PROTO
2828

2929
//--- a.v1.cppm

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
410410
const bool IsSTDIN = FileName == "-";
411411
if (!OutputXML && Inplace && IsSTDIN) {
412412
errs() << "error: cannot use -i when reading from stdin.\n";
413-
return false;
413+
return true;
414414
}
415415
// On Windows, overwriting a file with an open file mapping doesn't work,
416416
// so read the whole file into memory when formatting in-place.
@@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
419419
? MemoryBuffer::getFileAsStream(FileName)
420420
: MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
421421
if (std::error_code EC = CodeOrErr.getError()) {
422-
errs() << EC.message() << "\n";
422+
errs() << FileName << ": " << EC.message() << "\n";
423423
return true;
424424
}
425425
std::unique_ptr<llvm::MemoryBuffer> Code = std::move(CodeOrErr.get());

compiler-rt/lib/builtins/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ set(GENERIC_SOURCES
104104
divti3.c
105105
extendsfdf2.c
106106
extendhfsf2.c
107+
extendhfxf2.c
107108
ffsdi2.c
108109
ffssi2.c
109110
ffsti2.c
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- lib/extendhfxf2.c - half -> long double conversion --------*- C -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#define SRC_HALF
10+
#define DST_DOUBLE
11+
#include "fp_extend_impl.inc"
12+
13+
// Use a forwarding definition and noinline to implement a poor man's alias,
14+
// as there isn't a good cross-platform way of defining one.
15+
// Long double are expected to be as precise as double.
16+
COMPILER_RT_ABI NOINLINE long double __extendhfxf2(src_t a) {
17+
return (long double)__extendXfYf2__(a);
18+
}

compiler-rt/lib/builtins/macho_embedded/common.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ divsf3
6060
divsi3
6161
extendsfdf2
6262
extendhfsf2
63+
extendhfxf2
6364
ffssi2
6465
fixdfsi
6566
fixsfsi
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// RUN: %clang_builtins %s %librt -o %t && %run %t
2+
// REQUIRES: librt_has_extendhfxf2
3+
4+
#include <limits.h>
5+
#include <math.h> // for isnan, isinf
6+
#include <stdio.h>
7+
8+
#if __LDBL_MANT_DIG__ >= 64 && defined(COMPILER_RT_HAS_FLOAT16)
9+
10+
long double __extendhfxf2(_Float16 f);
11+
12+
int test_extendhfxf2(_Float16 a, long double expected) {
13+
long double x = __extendhfxf2(a);
14+
__uint16_t *b = (void *)&a;
15+
int ret = !((isnan(x) && isnan(expected)) || x == expected);
16+
if (ret) {
17+
printf("error in test__extendhfxf2(%#.4x) = %.20Lf, "
18+
"expected %.20Lf\n",
19+
*b, x, expected);
20+
}
21+
return ret;
22+
}
23+
24+
char assumption_1[sizeof(_Float16) * CHAR_BIT == 16] = {0};
25+
26+
int main() {
27+
// Small positive value
28+
if (test_extendhfxf2(0.09997558593750000000f, 0.09997558593750000000L))
29+
return 1;
30+
31+
// Small negative value
32+
if (test_extendhfxf2(-0.09997558593750000000f, -0.09997558593750000000L))
33+
return 1;
34+
35+
// Zero
36+
if (test_extendhfxf2(0.0f, 0.0L))
37+
return 1;
38+
39+
// Smallest positive non-zero value
40+
if (test_extendhfxf2(0x1p-16f, 0x1p-16L))
41+
return 1;
42+
43+
// Smallest negative non-zero value
44+
if (test_extendhfxf2(-0x1p-16f, -0x1p-16L))
45+
return 1;
46+
47+
// Positive infinity
48+
if (test_extendhfxf2(__builtin_huge_valf16(), __builtin_huge_valf64x()))
49+
return 1;
50+
51+
// Negative infinity
52+
if (test_extendhfxf2(-__builtin_huge_valf16(),
53+
(long double)-__builtin_huge_valf64x()))
54+
return 1;
55+
56+
// NaN
57+
if (test_extendhfxf2(__builtin_nanf16(""),
58+
(long double)__builtin_nanf64x("")))
59+
return 1;
60+
61+
return 0;
62+
}
63+
64+
#else
65+
66+
int main() {
67+
printf("skipped\n");
68+
return 0;
69+
}
70+
71+
#endif
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//===-- CUFCommon.h -------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_
10+
#define FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_
11+
12+
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
13+
#include "mlir/IR/BuiltinOps.h"
14+
15+
static constexpr llvm::StringRef cudaDeviceModuleName = "cuda_device_mod";
16+
17+
namespace cuf {
18+
19+
/// Retrieve or create the CUDA Fortran GPU module in the given \p mod.
20+
mlir::gpu::GPUModuleOp getOrCreateGPUModule(mlir::ModuleOp mod,
21+
mlir::SymbolTable &symTab);
22+
23+
} // namespace cuf
24+
25+
#endif // FORTRAN_OPTIMIZER_TRANSFORMS_CUFCOMMON_H_

flang/lib/Optimizer/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_flang_library(FIRTransforms
99
CompilerGeneratedNames.cpp
1010
ConstantArgumentGlobalisation.cpp
1111
ControlFlowConverter.cpp
12+
CUFCommon.cpp
1213
CUFAddConstructor.cpp
1314
CUFDeviceGlobal.cpp
1415
CUFOpConversion.cpp

flang/lib/Optimizer/Transforms/CUFAddConstructor.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "flang/Optimizer/Dialect/FIRAttr.h"
1212
#include "flang/Optimizer/Dialect/FIRDialect.h"
1313
#include "flang/Optimizer/Dialect/FIROpsSupport.h"
14+
#include "flang/Optimizer/Transforms/CUFCommon.h"
1415
#include "flang/Runtime/entry-names.h"
1516
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1617
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
@@ -24,8 +25,6 @@ namespace fir {
2425

2526
namespace {
2627

27-
static constexpr llvm::StringRef cudaModName{"cuda_device_mod"};
28-
2928
static constexpr llvm::StringRef cudaFortranCtorName{
3029
"__cudaFortranConstructor"};
3130

@@ -60,15 +59,15 @@ struct CUFAddConstructor
6059
builder.create<mlir::LLVM::CallOp>(loc, funcTy, cufRegisterAllocatorRef);
6160

6261
// Register kernels
63-
auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(cudaModName);
62+
auto gpuMod = symTab.lookup<mlir::gpu::GPUModuleOp>(cudaDeviceModuleName);
6463
if (gpuMod) {
6564
auto llvmPtrTy = mlir::LLVM::LLVMPointerType::get(ctx);
6665
auto registeredMod = builder.create<cuf::RegisterModuleOp>(
6766
loc, llvmPtrTy, mlir::SymbolRefAttr::get(ctx, gpuMod.getName()));
6867
for (auto func : gpuMod.getOps<mlir::gpu::GPUFuncOp>()) {
6968
if (func.isKernel()) {
7069
auto kernelName = mlir::SymbolRefAttr::get(
71-
builder.getStringAttr(cudaModName),
70+
builder.getStringAttr(cudaDeviceModuleName),
7271
{mlir::SymbolRefAttr::get(builder.getContext(), func.getName())});
7372
builder.create<cuf::RegisterKernelOp>(loc, kernelName, registeredMod);
7473
}

0 commit comments

Comments
 (0)