Skip to content

Commit eb5f2e2

Browse files
authored
Merge branch 'main' into fix/111854
2 parents cd3d083 + d8b17f2 commit eb5f2e2

File tree

99 files changed

+3216
-976
lines changed

Some content is hidden

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

99 files changed

+3216
-976
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
635635
getNVPTXTargetFeatures(C.getDriver(), getToolChain().getTriple(), Args,
636636
Features);
637637
CmdArgs.push_back(
638-
Args.MakeArgString("--plugin-opt=mattr=" + llvm::join(Features, ",")));
638+
Args.MakeArgString("--plugin-opt=-mattr=" + llvm::join(Features, ",")));
639639

640640
// Add paths for the default clang library path.
641641
SmallString<256> DefaultLibPath =

clang/test/Driver/cuda-cross-compiling.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@
104104
// RUN: %clang -target nvptx64-nvidia-cuda --cuda-feature=+ptx63 -march=sm_52 -### %s 2>&1 \
105105
// RUN: | FileCheck -check-prefix=FEATURE %s
106106

107-
// FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=mattr=+ptx63"
107+
// FEATURE: clang-nvlink-wrapper{{.*}}"--plugin-opt=-mattr=+ptx63"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: echo '{' > %t.json
2+
// RUN: echo ' "married": true' >> %t.json
3+
// RUN: echo '}' >> %t.json
4+
5+
// RUN: clang-format -n -style=LLVM %t.json 2>&1 | FileCheck %s -allow-empty
6+
7+
// RUN: clang-format -n -style=LLVM < %t.json 2>&1 \
8+
// RUN: | FileCheck %s -check-prefix=CHECK2 -strict-whitespace
9+
10+
// RUN: echo '{' > %t.json
11+
// RUN: echo ' "married" : true' >> %t.json
12+
// RUN: echo '}' >> %t.json
13+
14+
// RUN: clang-format -n -style=LLVM < %t.json 2>&1 | FileCheck %s -allow-empty
15+
16+
// RUN: clang-format -n -style=LLVM %t.json 2>&1 \
17+
// RUN: | FileCheck %s -check-prefix=CHECK2 -strict-whitespace
18+
19+
// RUN: rm %t.json
20+
21+
// CHECK-NOT: warning
22+
// CHECK2: warning: code should be clang-formatted

clang/tools/clang-format/ClangFormat.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,6 @@ static void outputReplacementsXML(const Replacements &Replaces) {
351351
static bool
352352
emitReplacementWarnings(const Replacements &Replaces, StringRef AssumedFileName,
353353
const std::unique_ptr<llvm::MemoryBuffer> &Code) {
354-
if (Replaces.empty())
355-
return false;
356-
357354
unsigned Errors = 0;
358355
if (WarnFormat && !NoWarnFormat) {
359356
SourceMgr Mgr;
@@ -490,9 +487,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
490487
Replacements Replaces = sortIncludes(*FormatStyle, Code->getBuffer(), Ranges,
491488
AssumedFileName, &CursorPosition);
492489

490+
const bool IsJson = FormatStyle->isJson();
491+
493492
// To format JSON insert a variable to trick the code into thinking its
494493
// JavaScript.
495-
if (FormatStyle->isJson() && !FormatStyle->DisableFormat) {
494+
if (IsJson && !FormatStyle->DisableFormat) {
496495
auto Err = Replaces.add(tooling::Replacement(
497496
tooling::Replacement(AssumedFileName, 0, 0, "x = ")));
498497
if (Err)
@@ -510,9 +509,11 @@ static bool format(StringRef FileName, bool ErrorOnIncompleteFormat = false) {
510509
Replacements FormatChanges =
511510
reformat(*FormatStyle, *ChangedCode, Ranges, AssumedFileName, &Status);
512511
Replaces = Replaces.merge(FormatChanges);
513-
if (OutputXML || DryRun) {
514-
if (DryRun)
515-
return emitReplacementWarnings(Replaces, AssumedFileName, Code);
512+
if (DryRun) {
513+
return Replaces.size() > (IsJson ? 1 : 0) &&
514+
emitReplacementWarnings(Replaces, AssumedFileName, Code);
515+
}
516+
if (OutputXML) {
516517
outputXML(Replaces, FormatChanges, Status, Cursor, CursorPosition);
517518
} else {
518519
IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(

compiler-rt/lib/lsan/lsan_common.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -394,18 +394,18 @@ void ScanGlobalRange(uptr begin, uptr end, Frontier *frontier) {
394394
}
395395

396396
template <class Accessor>
397-
void ScanExtraStack(const InternalMmapVector<Range> &ranges, Frontier *frontier,
398-
Accessor &accessor) {
397+
void ScanRanges(const InternalMmapVector<Range> &ranges, Frontier *frontier,
398+
const char *region_type, Accessor &accessor) {
399399
for (uptr i = 0; i < ranges.size(); i++) {
400-
ScanForPointers(ranges[i].begin, ranges[i].end, frontier, "FAKE STACK",
400+
ScanForPointers(ranges[i].begin, ranges[i].end, frontier, region_type,
401401
kReachable, accessor);
402402
}
403403
}
404404

405405
void ScanExtraStackRanges(const InternalMmapVector<Range> &ranges,
406406
Frontier *frontier) {
407407
DirectMemoryAccessor accessor;
408-
ScanExtraStack(ranges, frontier, accessor);
408+
ScanRanges(ranges, frontier, "FAKE STACK", accessor);
409409
}
410410

411411
# if SANITIZER_FUCHSIA
@@ -499,7 +499,7 @@ static void ProcessThread(tid_t os_id, uptr sp,
499499
ScanForPointers(stack_begin, stack_end, frontier, "STACK", kReachable,
500500
accessor);
501501
GetThreadExtraStackRangesLocked(os_id, &extra_ranges);
502-
ScanExtraStack(extra_ranges, frontier, accessor);
502+
ScanRanges(extra_ranges, frontier, "FAKE STACK", accessor);
503503
}
504504

505505
if (flags()->use_tls) {
@@ -521,13 +521,14 @@ static void ProcessThread(tid_t os_id, uptr sp,
521521
}
522522
}
523523
# if SANITIZER_ANDROID
524+
extra_ranges.clear();
524525
auto *cb = +[](void *dtls_begin, void *dtls_end, uptr /*dso_idd*/,
525526
void *arg) -> void {
526-
ScanForPointers(
527-
reinterpret_cast<uptr>(dtls_begin), reinterpret_cast<uptr>(dtls_end),
528-
reinterpret_cast<Frontier *>(arg), "DTLS", kReachable, accessor);
527+
reinterpret_cast<InternalMmapVector<Range> *>(arg)->push_back(
528+
{reinterpret_cast<uptr>(dtls_begin),
529+
reinterpret_cast<uptr>(dtls_end)});
529530
};
530-
531+
ScanRanges(extra_ranges, frontier, "DTLS", accessor);
531532
// FIXME: There might be a race-condition here (and in Bionic) if the
532533
// thread is suspended in the middle of updating its DTLS. IOWs, we
533534
// could scan already freed memory. (probably fine for now)

flang/include/flang/Optimizer/Dialect/CUF/CUFOps.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.h"
1313
#include "flang/Optimizer/Dialect/CUF/CUFDialect.h"
1414
#include "flang/Optimizer/Dialect/FIRType.h"
15+
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1516
#include "mlir/IR/OpDefinition.h"
1617

1718
#define GET_OP_CLASSES

flang/include/flang/Optimizer/Dialect/CUF/CUFOps.td

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ include "flang/Optimizer/Dialect/CUF/CUFDialect.td"
1818
include "flang/Optimizer/Dialect/CUF/Attributes/CUFAttr.td"
1919
include "flang/Optimizer/Dialect/FIRTypes.td"
2020
include "flang/Optimizer/Dialect/FIRAttr.td"
21+
include "mlir/Dialect/LLVMIR/LLVMOpBase.td"
2122
include "mlir/Interfaces/LoopLikeInterface.td"
2223
include "mlir/IR/BuiltinAttributes.td"
2324

@@ -288,15 +289,30 @@ def cuf_KernelOp : cuf_Op<"kernel", [AttrSizedOperandSegments,
288289
let hasVerifier = 1;
289290
}
290291

292+
def cuf_RegisterModuleOp : cuf_Op<"register_module", []> {
293+
let summary = "Register a CUDA module";
294+
295+
let arguments = (ins
296+
SymbolRefAttr:$name
297+
);
298+
299+
let assemblyFormat = [{
300+
$name attr-dict `->` type($modulePtr)
301+
}];
302+
303+
let results = (outs LLVM_AnyPointer:$modulePtr);
304+
}
305+
291306
def cuf_RegisterKernelOp : cuf_Op<"register_kernel", []> {
292307
let summary = "Register a CUDA kernel";
293308

294309
let arguments = (ins
295-
SymbolRefAttr:$name
310+
SymbolRefAttr:$name,
311+
LLVM_AnyPointer:$modulePtr
296312
);
297313

298314
let assemblyFormat = [{
299-
$name attr-dict
315+
$name `(` $modulePtr `:` type($modulePtr) `)`attr-dict
300316
}];
301317

302318
let hasVerifier = 1;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===- CUFToLLVMIRTranslation.h - CUF Dialect to LLVM IR --------*- 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+
// This provides registration calls for GPU dialect to LLVM IR translation.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef FLANG_OPTIMIZER_DIALECT_CUF_GPUTOLLVMIRTRANSLATION_H_
14+
#define FLANG_OPTIMIZER_DIALECT_CUF_GPUTOLLVMIRTRANSLATION_H_
15+
16+
namespace mlir {
17+
class DialectRegistry;
18+
class MLIRContext;
19+
} // namespace mlir
20+
21+
namespace cuf {
22+
23+
/// Register the CUF dialect and the translation from it to the LLVM IR in
24+
/// the given registry.
25+
void registerCUFDialectTranslation(mlir::DialectRegistry &registry);
26+
27+
} // namespace cuf
28+
29+
#endif // FLANG_OPTIMIZER_DIALECT_CUF_GPUTOLLVMIRTRANSLATION_H_

flang/include/flang/Optimizer/Support/InitFIR.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define FORTRAN_OPTIMIZER_SUPPORT_INITFIR_H
1515

1616
#include "flang/Optimizer/Dialect/CUF/CUFDialect.h"
17+
#include "flang/Optimizer/Dialect/CUF/CUFToLLVMIRTranslation.h"
1718
#include "flang/Optimizer/Dialect/FIRDialect.h"
1819
#include "flang/Optimizer/HLFIR/HLFIRDialect.h"
1920
#include "mlir/Conversion/Passes.h"
@@ -61,6 +62,7 @@ inline void addFIRExtensions(mlir::DialectRegistry &registry,
6162
if (addFIRInlinerInterface)
6263
addFIRInlinerExtension(registry);
6364
addFIRToLLVMIRExtension(registry);
65+
cuf::registerCUFDialectTranslation(registry);
6466
}
6567

6668
inline void loadNonCodegenDialects(mlir::MLIRContext &context) {

flang/include/flang/Optimizer/Transforms/CufOpConversion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ class LLVMTypeConverter;
1818

1919
namespace mlir {
2020
class DataLayout;
21+
class SymbolTable;
2122
}
2223

2324
namespace cuf {
2425

2526
void populateCUFToFIRConversionPatterns(const fir::LLVMTypeConverter &converter,
2627
mlir::DataLayout &dl,
28+
const mlir::SymbolTable &symtab,
2729
mlir::RewritePatternSet &patterns);
2830

2931
} // namespace cuf

0 commit comments

Comments
 (0)