Skip to content

Commit df67f2e

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-remove-loop-region-instead-of-using-branch-on-cond-true
2 parents 05b2e4e + e32afde commit df67f2e

File tree

128 files changed

+5805
-2629
lines changed

Some content is hidden

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

128 files changed

+5805
-2629
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3641,7 +3641,7 @@ program location should be executed. It is expected to be used to implement
36413641
<https://llvm.org/docs/LangRef.html#llvm-allow-runtime-check-intrinsic>`_
36423642
intrinsic.
36433643
3644-
The ``__builtin_allow_runtime_check()`` can be used within constrol structures
3644+
The ``__builtin_allow_runtime_check()`` can be used within control structures
36453645
like ``if`` to guard expensive runtime checks. The return value is determined
36463646
by the following compiler options and may differ per call site:
36473647

clang/test/Driver/spirv-openmp-toolchain.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// CHECK: "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}}"-emit-obj"
1010
// CHECK: clang-linker-wrapper{{.*}} "-o" "a.out"
1111

12-
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=spirv64-intel %s 2>&1 \
12+
// RUN: %clang -ccc-print-phases --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=spirv64-intel %s 2>&1 \
1313
// RUN: | FileCheck --check-prefix=CHECK-PHASES %s
1414

1515
// CHECK-PHASES: 0: input, "[[INPUT:.+]]", c, (host-openmp)
@@ -28,8 +28,8 @@
2828
// CHECK-PHASES: 13: assembler, {12}, object, (host-openmp)
2929
// CHECK-PHASES: 14: clang-linker-wrapper, {13}, image, (host-openmp)
3030

31-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
32-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
31+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
32+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS
3333

3434
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_BC:.+]]"
3535
// CHECK-BINDINGS: "spirv64-intel" - "clang", inputs: ["[[INPUT]]", "[[HOST_BC]]"], output: "[[DEVICE_TEMP_BC:.+]]"
@@ -38,8 +38,8 @@
3838
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_BC]]", "[[DEVICE_IMAGE]]"], output: "[[HOST_OBJ:.+]]"
3939
// CHECK-BINDINGS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out"
4040

41-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
42-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp -fopenmp-targets=spirv64-intel %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
41+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
42+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -ccc-print-bindings -save-temps -fopenmp=libomp -fopenmp-targets=spirv64-intel %s 2>&1 | FileCheck %s --check-prefix=CHECK-BINDINGS-TEMPS
4343
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[HOST_PP:.+]]"
4444
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang", inputs: ["[[HOST_PP]]"], output: "[[HOST_BC:.+]]"
4545
// CHECK-BINDINGS-TEMPS: "spirv64-intel" - "clang", inputs: ["[[INPUT]]"], output: "[[DEVICE_PP:.+]]"
@@ -51,14 +51,14 @@
5151
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "clang::as", inputs: ["[[HOST_ASM]]"], output: "[[HOST_OBJ:.+]]"
5252
// CHECK-BINDINGS-TEMPS: "x86_64-unknown-linux-gnu" - "Offload::Linker", inputs: ["[[HOST_OBJ]]"], output: "a.out"
5353

54-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
54+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -emit-llvm -S -fopenmp=libomp -fopenmp-targets=spirv64-intel -nogpulib %s 2>&1 | FileCheck %s --check-prefix=CHECK-EMIT-LLVM-IR
5555
// CHECK-EMIT-LLVM-IR: "-cc1" "-triple" "spirv64-intel"{{.*}}"-emit-llvm-bc"
5656

57-
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=spirv64-intel \
57+
// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp -fopenmp-targets=spirv64-intel \
5858
// RUN: --sysroot=%S/Inputs/spirv-openmp/ %s 2>&1 | FileCheck --check-prefix=CHECK-GPULIB %s
5959
// CHECK-GPULIB: "-cc1" "-triple" "spirv64-intel"{{.*}}"-mlink-builtin-bitcode" "{{.*}}libomptarget-spirv64.bc"
6060

61-
// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fopenmp --offload-arch=spirv64-intel \
61+
// RUN: not %clang -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=spirv64-intel \
6262
// RUN: --libomptarget-spirv-bc-path=%t/ -nogpulib %s 2>&1 \
6363
// RUN: | FileCheck %s --check-prefix=CHECK-OFFLOAD-ARCH-ERROR
6464
// CHECK-OFFLOAD-ARCH-ERROR: error: failed to deduce triple for target architecture 'spirv64-intel'; specify the triple using '-fopenmp-targets' and '-Xopenmp-target' instead

flang/examples/FlangOmpReport/FlangOmpReportVisitor.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ SourcePosition OpenMPCounterVisitor::getLocation(const OpenMPConstruct &c) {
9090
const CharBlock &source{c.source};
9191
return (parsing->allCooked().GetSourcePositionRange(source))->first;
9292
},
93+
[&](const OpenMPUtilityConstruct &c) -> SourcePosition {
94+
const CharBlock &source{c.source};
95+
return (parsing->allCooked().GetSourcePositionRange(source))->first;
96+
},
9397
},
9498
c.u);
9599
}
@@ -102,10 +106,16 @@ std::string OpenMPCounterVisitor::getName(const OmpWrapperType &w) {
102106
return getName(*std::get<const OpenMPDeclarativeConstruct *>(w));
103107
}
104108
std::string OpenMPCounterVisitor::getName(const OpenMPDeclarativeConstruct &c) {
105-
return std::visit(
106-
[&](const auto &o) -> std::string {
107-
const CharBlock &source{std::get<Verbatim>(o.t).source};
108-
return normalize_construct_name(source.ToString());
109+
return std::visit( //
110+
Fortran::common::visitors{
111+
[&](const OpenMPUtilityConstruct &o) -> std::string {
112+
const CharBlock &source{o.source};
113+
return normalize_construct_name(source.ToString());
114+
},
115+
[&](const auto &o) -> std::string {
116+
const CharBlock &source{std::get<Verbatim>(o.t).source};
117+
return normalize_construct_name(source.ToString());
118+
},
109119
},
110120
c.u);
111121
}
@@ -143,8 +153,8 @@ std::string OpenMPCounterVisitor::getName(const OpenMPConstruct &c) {
143153
},
144154
c.u);
145155
},
146-
[&](const OpenMPErrorConstruct &c) -> std::string {
147-
const CharBlock &source{std::get<0>(c.t).source};
156+
[&](const OpenMPUtilityConstruct &c) -> std::string {
157+
const CharBlock &source{c.source};
148158
return normalize_construct_name(source.ToString());
149159
},
150160
[&](const OpenMPSectionConstruct &c) -> std::string {

flang/include/flang/Optimizer/HLFIR/Passes.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,8 @@ def InlineElementals : Pass<"inline-elementals"> {
4949
let summary = "Inline chained hlfir.elemental operations";
5050
}
5151

52+
def InlineHLFIRAssign : Pass<"inline-hlfir-assign"> {
53+
let summary = "Inline hlfir.assign operations";
54+
}
55+
5256
#endif //FORTRAN_DIALECT_HLFIR_PASSES

flang/include/flang/Parser/dump-parse-tree.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,8 @@ class ParseTreeDumper {
516516
#include "llvm/Frontend/OpenMP/OMP.inc"
517517
NODE(parser, OmpClauseList)
518518
NODE(parser, OmpCriticalDirective)
519+
NODE(parser, OmpErrorDirective)
520+
NODE(parser, OmpNothingDirective)
519521
NODE(parser, OmpDeclareTargetSpecifier)
520522
NODE(parser, OmpDeclareTargetWithClause)
521523
NODE(parser, OmpDeclareTargetWithList)
@@ -662,7 +664,7 @@ class ParseTreeDumper {
662664
NODE(parser, OmpAtomicDefaultMemOrderClause)
663665
NODE_ENUM(common, OmpAtomicDefaultMemOrderType)
664666
NODE(parser, OpenMPDepobjConstruct)
665-
NODE(parser, OpenMPErrorConstruct)
667+
NODE(parser, OpenMPUtilityConstruct)
666668
NODE(parser, OpenMPFlushConstruct)
667669
NODE(parser, OpenMPLoopConstruct)
668670
NODE(parser, OpenMPExecutableAllocate)

flang/include/flang/Parser/parse-tree.h

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4182,6 +4182,30 @@ struct OmpClauseList {
41824182

41834183
// --- Directives and constructs
41844184

4185+
// Ref: [5.1:89-90], [5.2:216]
4186+
//
4187+
// nothing-directive ->
4188+
// NOTHING // since 5.1
4189+
struct OmpNothingDirective {
4190+
using EmptyTrait = std::true_type;
4191+
COPY_AND_ASSIGN_BOILERPLATE(OmpNothingDirective);
4192+
CharBlock source;
4193+
};
4194+
4195+
// Ref: OpenMP [5.2:216-218]
4196+
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
4197+
struct OmpErrorDirective {
4198+
TUPLE_CLASS_BOILERPLATE(OmpErrorDirective);
4199+
CharBlock source;
4200+
std::tuple<Verbatim, OmpClauseList> t;
4201+
};
4202+
4203+
struct OpenMPUtilityConstruct {
4204+
UNION_CLASS_BOILERPLATE(OpenMPUtilityConstruct);
4205+
CharBlock source;
4206+
std::variant<OmpErrorDirective, OmpNothingDirective> u;
4207+
};
4208+
41854209
// 2.7.2 SECTIONS
41864210
// 2.11.2 PARALLEL SECTIONS
41874211
struct OmpSectionsDirective {
@@ -4318,7 +4342,7 @@ struct OpenMPDeclarativeConstruct {
43184342
std::variant<OpenMPDeclarativeAllocate, OpenMPDeclareMapperConstruct,
43194343
OpenMPDeclareReductionConstruct, OpenMPDeclareSimdConstruct,
43204344
OpenMPDeclareTargetConstruct, OpenMPThreadprivate,
4321-
OpenMPRequiresConstruct>
4345+
OpenMPRequiresConstruct, OpenMPUtilityConstruct>
43224346
u;
43234347
};
43244348

@@ -4506,14 +4530,6 @@ struct OpenMPDepobjConstruct {
45064530
std::tuple<Verbatim, OmpObject, OmpClause> t;
45074531
};
45084532

4509-
// Ref: OpenMP [5.2:216-218]
4510-
// ERROR AT(compilation|execution) SEVERITY(fatal|warning) MESSAGE("msg-str)
4511-
struct OpenMPErrorConstruct {
4512-
TUPLE_CLASS_BOILERPLATE(OpenMPErrorConstruct);
4513-
CharBlock source;
4514-
std::tuple<Verbatim, OmpClauseList> t;
4515-
};
4516-
45174533
// 2.17.8 flush -> FLUSH [memory-order-clause] [(variable-name-list)]
45184534
struct OpenMPFlushConstruct {
45194535
TUPLE_CLASS_BOILERPLATE(OpenMPFlushConstruct);
@@ -4586,7 +4602,7 @@ struct OpenMPConstruct {
45864602
UNION_CLASS_BOILERPLATE(OpenMPConstruct);
45874603
std::variant<OpenMPStandaloneConstruct, OpenMPSectionsConstruct,
45884604
OpenMPSectionConstruct, OpenMPLoopConstruct, OpenMPBlockConstruct,
4589-
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPErrorConstruct,
4605+
OpenMPAtomicConstruct, OpenMPDeclarativeAllocate, OpenMPUtilityConstruct,
45904606
OpenMPExecutableAllocate, OpenMPAllocatorsConstruct,
45914607
OpenMPCriticalConstruct>
45924608
u;

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -923,32 +923,70 @@ static void genBodyOfTargetOp(
923923
while (!valuesDefinedAbove.empty()) {
924924
for (mlir::Value val : valuesDefinedAbove) {
925925
mlir::Operation *valOp = val.getDefiningOp();
926-
if (mlir::isMemoryEffectFree(valOp)) {
926+
assert(valOp != nullptr);
927+
928+
// NOTE: We skip BoxDimsOp's as the lesser of two evils is to map the
929+
// indices separately, as the alternative is to eventually map the Box,
930+
// which comes with a fairly large overhead comparatively. We could be
931+
// more robust about this and check using a BackwardsSlice to see if we
932+
// run the risk of mapping a box.
933+
if (mlir::isMemoryEffectFree(valOp) &&
934+
!mlir::isa<fir::BoxDimsOp>(valOp)) {
927935
mlir::Operation *clonedOp = valOp->clone();
928936
entryBlock->push_front(clonedOp);
929-
val.replaceUsesWithIf(clonedOp->getResult(0),
930-
[entryBlock](mlir::OpOperand &use) {
931-
return use.getOwner()->getBlock() == entryBlock;
932-
});
937+
938+
auto replace = [entryBlock](mlir::OpOperand &use) {
939+
return use.getOwner()->getBlock() == entryBlock;
940+
};
941+
942+
valOp->getResults().replaceUsesWithIf(clonedOp->getResults(), replace);
943+
valOp->replaceUsesWithIf(clonedOp, replace);
933944
} else {
934945
auto savedIP = firOpBuilder.getInsertionPoint();
935946
firOpBuilder.setInsertionPointAfter(valOp);
936947
auto copyVal =
937948
firOpBuilder.createTemporary(val.getLoc(), val.getType());
938949
firOpBuilder.createStoreWithConvert(copyVal.getLoc(), val, copyVal);
939950

940-
llvm::SmallVector<mlir::Value> bounds;
951+
lower::AddrAndBoundsInfo info = lower::getDataOperandBaseAddr(
952+
firOpBuilder, val, /*isOptional=*/false, val.getLoc());
953+
llvm::SmallVector<mlir::Value> bounds =
954+
Fortran::lower::genImplicitBoundsOps<mlir::omp::MapBoundsOp,
955+
mlir::omp::MapBoundsType>(
956+
firOpBuilder, info,
957+
hlfir::translateToExtendedValue(val.getLoc(), firOpBuilder,
958+
hlfir::Entity{val})
959+
.first,
960+
/*dataExvIsAssumedSize=*/false, val.getLoc());
961+
941962
std::stringstream name;
942963
firOpBuilder.setInsertionPoint(targetOp);
964+
965+
llvm::omp::OpenMPOffloadMappingFlags mapFlag =
966+
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
967+
mlir::omp::VariableCaptureKind captureKind =
968+
mlir::omp::VariableCaptureKind::ByRef;
969+
970+
mlir::Type eleType = copyVal.getType();
971+
if (auto refType =
972+
mlir::dyn_cast<fir::ReferenceType>(copyVal.getType()))
973+
eleType = refType.getElementType();
974+
975+
if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
976+
captureKind = mlir::omp::VariableCaptureKind::ByCopy;
977+
} else if (!fir::isa_builtin_cptr_type(eleType)) {
978+
mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
979+
}
980+
943981
mlir::Value mapOp = createMapInfoOp(
944982
firOpBuilder, copyVal.getLoc(), copyVal,
945983
/*varPtrPtr=*/mlir::Value{}, name.str(), bounds,
946984
/*members=*/llvm::SmallVector<mlir::Value>{},
947985
/*membersIndex=*/mlir::ArrayAttr{},
948986
static_cast<
949987
std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
950-
llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT),
951-
mlir::omp::VariableCaptureKind::ByCopy, copyVal.getType());
988+
mapFlag),
989+
captureKind, copyVal.getType());
952990

953991
// Get the index of the first non-map argument before modifying mapVars,
954992
// then append an element to mapVars and an associated entry block
@@ -2586,6 +2624,10 @@ static void genOMPDispatch(lower::AbstractConverter &converter,
25862624
//===----------------------------------------------------------------------===//
25872625
// OpenMPDeclarativeConstruct visitors
25882626
//===----------------------------------------------------------------------===//
2627+
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
2628+
semantics::SemanticsContext &semaCtx,
2629+
lower::pft::Evaluation &eval,
2630+
const parser::OpenMPUtilityConstruct &);
25892631

25902632
static void
25912633
genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
@@ -2907,8 +2949,8 @@ static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
29072949
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,
29082950
semantics::SemanticsContext &semaCtx,
29092951
lower::pft::Evaluation &eval,
2910-
const parser::OpenMPErrorConstruct &) {
2911-
TODO(converter.getCurrentLocation(), "OpenMPErrorConstruct");
2952+
const parser::OpenMPUtilityConstruct &) {
2953+
TODO(converter.getCurrentLocation(), "OpenMPUtilityConstruct");
29122954
}
29132955

29142956
static void genOMP(lower::AbstractConverter &converter, lower::SymMap &symTable,

flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ class BoxprocTypeRewriter : public mlir::TypeConverter {
172172
addConversion([&](TypeDescType ty) {
173173
return TypeDescType::get(convertType(ty.getOfTy()));
174174
});
175-
addArgumentMaterialization(materializeProcedure);
176175
addSourceMaterialization(materializeProcedure);
177176
addTargetMaterialization(materializeProcedure);
178177
}

flang/lib/Optimizer/HLFIR/Transforms/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ add_flang_library(HLFIRTransforms
44
BufferizeHLFIR.cpp
55
ConvertToFIR.cpp
66
InlineElementals.cpp
7+
InlineHLFIRAssign.cpp
78
LowerHLFIRIntrinsics.cpp
89
LowerHLFIROrderedAssignments.cpp
910
ScheduleOrderedAssignments.cpp

0 commit comments

Comments
 (0)