Skip to content

Commit 33c24e3

Browse files
authored
Merge branch 'main' into fix/92847
2 parents e9fa671 + 3e62321 commit 33c24e3

File tree

70 files changed

+823
-398
lines changed

Some content is hidden

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

70 files changed

+823
-398
lines changed

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,10 +2457,86 @@ static void emitSimdlenSafelenClause(CodeGenFunction &CGF,
24572457
}
24582458
}
24592459

2460+
// Check for the presence of an `OMPOrderedDirective`,
2461+
// i.e., `ordered` in `#pragma omp ordered simd`.
2462+
//
2463+
// Consider the following source code:
2464+
// ```
2465+
// __attribute__((noinline)) void omp_simd_loop(float X[ARRAY_SIZE][ARRAY_SIZE])
2466+
// {
2467+
// for (int r = 1; r < ARRAY_SIZE; ++r) {
2468+
// for (int c = 1; c < ARRAY_SIZE; ++c) {
2469+
// #pragma omp simd
2470+
// for (int k = 2; k < ARRAY_SIZE; ++k) {
2471+
// #pragma omp ordered simd
2472+
// X[r][k] = X[r][k - 2] + sinf((float)(r / c));
2473+
// }
2474+
// }
2475+
// }
2476+
// }
2477+
// ```
2478+
//
2479+
// Suppose we are in `CodeGenFunction::EmitOMPSimdInit(const OMPLoopDirective
2480+
// &D)`. By examining `D.dump()` we have the following AST containing
2481+
// `OMPOrderedDirective`:
2482+
//
2483+
// ```
2484+
// OMPSimdDirective 0x1c32950
2485+
// `-CapturedStmt 0x1c32028
2486+
// |-CapturedDecl 0x1c310e8
2487+
// | |-ForStmt 0x1c31e30
2488+
// | | |-DeclStmt 0x1c31298
2489+
// | | | `-VarDecl 0x1c31208 used k 'int' cinit
2490+
// | | | `-IntegerLiteral 0x1c31278 'int' 2
2491+
// | | |-<<<NULL>>>
2492+
// | | |-BinaryOperator 0x1c31308 'int' '<'
2493+
// | | | |-ImplicitCastExpr 0x1c312f0 'int' <LValueToRValue>
2494+
// | | | | `-DeclRefExpr 0x1c312b0 'int' lvalue Var 0x1c31208 'k' 'int'
2495+
// | | | `-IntegerLiteral 0x1c312d0 'int' 256
2496+
// | | |-UnaryOperator 0x1c31348 'int' prefix '++'
2497+
// | | | `-DeclRefExpr 0x1c31328 'int' lvalue Var 0x1c31208 'k' 'int'
2498+
// | | `-CompoundStmt 0x1c31e18
2499+
// | | `-OMPOrderedDirective 0x1c31dd8
2500+
// | | |-OMPSimdClause 0x1c31380
2501+
// | | `-CapturedStmt 0x1c31cd0
2502+
// ```
2503+
//
2504+
// Note the presence of `OMPOrderedDirective` above:
2505+
// It's (transitively) nested in a `CapturedStmt` representing the pragma
2506+
// annotated compound statement. Thus, we need to consider this nesting and
2507+
// include checking the `getCapturedStmt` in this case.
2508+
static bool hasOrderedDirective(const Stmt *S) {
2509+
if (isa<OMPOrderedDirective>(S))
2510+
return true;
2511+
2512+
if (const auto *CS = dyn_cast<CapturedStmt>(S))
2513+
return hasOrderedDirective(CS->getCapturedStmt());
2514+
2515+
for (const Stmt *Child : S->children()) {
2516+
if (Child && hasOrderedDirective(Child))
2517+
return true;
2518+
}
2519+
2520+
return false;
2521+
}
2522+
2523+
static void applyConservativeSimdOrderedDirective(const Stmt &AssociatedStmt,
2524+
LoopInfoStack &LoopStack) {
2525+
// Check for the presence of an `OMPOrderedDirective`
2526+
// i.e., `ordered` in `#pragma omp ordered simd`
2527+
bool HasOrderedDirective = hasOrderedDirective(&AssociatedStmt);
2528+
// If present then conservatively disable loop vectorization
2529+
// analogously to how `emitSimdlenSafelenClause` does.
2530+
if (HasOrderedDirective)
2531+
LoopStack.setParallel(/*Enable=*/false);
2532+
}
2533+
24602534
void CodeGenFunction::EmitOMPSimdInit(const OMPLoopDirective &D) {
24612535
// Walk clauses and process safelen/lastprivate.
24622536
LoopStack.setParallel(/*Enable=*/true);
24632537
LoopStack.setVectorizeEnable();
2538+
const Stmt *AssociatedStmt = D.getAssociatedStmt();
2539+
applyConservativeSimdOrderedDirective(*AssociatedStmt, LoopStack);
24642540
emitSimdlenSafelenClause(*this, D);
24652541
if (const auto *C = D.getSingleClause<OMPOrderClause>())
24662542
if (C->getKind() == OMPC_ORDER_concurrent)

clang/test/OpenMP/ordered_codegen.cpp

Lines changed: 116 additions & 116 deletions
Large diffs are not rendered by default.

libcxx/include/__config

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,18 +1119,23 @@ typedef __char32_t char32_t;
11191119

11201120
// Optional attributes - these are useful for a better QoI, but not required to be available
11211121

1122+
# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1123+
# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1124+
# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1125+
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1126+
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1127+
__attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1128+
# define _LIBCPP_PACKED __attribute__((__packed__))
1129+
1130+
// Use a function like macro to imply that it must be followed by a semicolon
1131+
# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1132+
11221133
# if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
11231134
# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
11241135
# else
11251136
# define _LIBCPP_NO_CFI
11261137
# endif
11271138

1128-
# if __has_attribute(__malloc__)
1129-
# define _LIBCPP_NOALIAS __attribute__((__malloc__))
1130-
# else
1131-
# define _LIBCPP_NOALIAS
1132-
# endif
1133-
11341139
# if __has_attribute(__using_if_exists__)
11351140
# define _LIBCPP_USING_IF_EXISTS __attribute__((__using_if_exists__))
11361141
# else
@@ -1149,15 +1154,6 @@ typedef __char32_t char32_t;
11491154
# define _LIBCPP_DIAGNOSE_WARNING(...)
11501155
# endif
11511156

1152-
// Use a function like macro to imply that it must be followed by a semicolon
1153-
# if __has_cpp_attribute(fallthrough)
1154-
# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
1155-
# elif __has_attribute(__fallthrough__)
1156-
# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
1157-
# else
1158-
# define _LIBCPP_FALLTHROUGH() ((void)0)
1159-
# endif
1160-
11611157
# if __has_cpp_attribute(_Clang::__lifetimebound__)
11621158
# define _LIBCPP_LIFETIMEBOUND [[_Clang::__lifetimebound__]]
11631159
# else
@@ -1170,8 +1166,6 @@ typedef __char32_t char32_t;
11701166
# define _LIBCPP_NOESCAPE
11711167
# endif
11721168

1173-
# define _LIBCPP_NODEBUG [[__gnu__::__nodebug__]]
1174-
11751169
# if __has_cpp_attribute(_Clang::__no_specializations__)
11761170
# define _LIBCPP_NO_SPECIALIZATIONS \
11771171
[[_Clang::__no_specializations__("Users are not allowed to specialize this standard library entity")]]
@@ -1191,33 +1185,6 @@ typedef __char32_t char32_t;
11911185
# define _LIBCPP_PREFERRED_NAME(x)
11921186
# endif
11931187

1194-
# if __has_attribute(__no_sanitize__)
1195-
# define _LIBCPP_NO_SANITIZE(...) __attribute__((__no_sanitize__(__VA_ARGS__)))
1196-
# else
1197-
# define _LIBCPP_NO_SANITIZE(...)
1198-
# endif
1199-
1200-
# if __has_attribute(__init_priority__)
1201-
# define _LIBCPP_INIT_PRIORITY_MAX __attribute__((__init_priority__(100)))
1202-
# else
1203-
# define _LIBCPP_INIT_PRIORITY_MAX
1204-
# endif
1205-
1206-
# if __has_attribute(__format__)
1207-
// The attribute uses 1-based indices for ordinary and static member functions.
1208-
// The attribute uses 2-based indices for non-static member functions.
1209-
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) \
1210-
__attribute__((__format__(archetype, format_string_index, first_format_arg_index)))
1211-
# else
1212-
# define _LIBCPP_ATTRIBUTE_FORMAT(archetype, format_string_index, first_format_arg_index) /* nothing */
1213-
# endif
1214-
1215-
# if __has_attribute(__packed__)
1216-
# define _LIBCPP_PACKED __attribute__((__packed__))
1217-
# else
1218-
# define _LIBCPP_PACKED
1219-
# endif
1220-
12211188
# if defined(_LIBCPP_ABI_MICROSOFT) && __has_declspec_attribute(empty_bases)
12221189
# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
12231190
# else

libcxxabi/src/cxa_default_handlers.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// new_handler.
1010
//===----------------------------------------------------------------------===//
1111

12+
#include <cstdlib> // std::abort
1213
#include <exception>
1314
#include <new>
1415
#include "abort_message.h"
@@ -94,7 +95,7 @@ static void demangling_unexpected_handler()
9495
static constexpr std::terminate_handler default_terminate_handler = demangling_terminate_handler;
9596
static constexpr std::terminate_handler default_unexpected_handler = demangling_unexpected_handler;
9697
#else // !LIBCXXABI_SILENT_TERMINATE
97-
static constexpr std::terminate_handler default_terminate_handler = ::abort;
98+
static constexpr std::terminate_handler default_terminate_handler = std::abort;
9899
static constexpr std::terminate_handler default_unexpected_handler = std::terminate;
99100
#endif // !LIBCXXABI_SILENT_TERMINATE
100101

llvm/include/llvm/CodeGen/MachineScheduler.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
#include <vector>
9999

100100
namespace llvm {
101+
namespace impl_detail {
102+
// FIXME: Remove these declarations once RegisterClassInfo is queryable as an
103+
// analysis.
104+
class MachineSchedulerImpl;
105+
class PostMachineSchedulerImpl;
106+
} // namespace impl_detail
101107

102108
namespace MISched {
103109
enum Direction {
@@ -1385,6 +1391,34 @@ std::unique_ptr<ScheduleDAGMutation>
13851391
createCopyConstrainDAGMutation(const TargetInstrInfo *TII,
13861392
const TargetRegisterInfo *TRI);
13871393

1394+
class MachineSchedulerPass : public PassInfoMixin<MachineSchedulerPass> {
1395+
// FIXME: Remove this member once RegisterClassInfo is queryable as an
1396+
// analysis.
1397+
std::unique_ptr<impl_detail::MachineSchedulerImpl> Impl;
1398+
const TargetMachine *TM;
1399+
1400+
public:
1401+
MachineSchedulerPass(const TargetMachine *TM);
1402+
MachineSchedulerPass(MachineSchedulerPass &&Other);
1403+
~MachineSchedulerPass();
1404+
PreservedAnalyses run(MachineFunction &MF,
1405+
MachineFunctionAnalysisManager &MFAM);
1406+
};
1407+
1408+
class PostMachineSchedulerPass
1409+
: public PassInfoMixin<PostMachineSchedulerPass> {
1410+
// FIXME: Remove this member once RegisterClassInfo is queryable as an
1411+
// analysis.
1412+
std::unique_ptr<impl_detail::PostMachineSchedulerImpl> Impl;
1413+
const TargetMachine *TM;
1414+
1415+
public:
1416+
PostMachineSchedulerPass(const TargetMachine *TM);
1417+
PostMachineSchedulerPass(PostMachineSchedulerPass &&Other);
1418+
~PostMachineSchedulerPass();
1419+
PreservedAnalyses run(MachineFunction &MF,
1420+
MachineFunctionAnalysisManager &MFAM);
1421+
};
13881422
} // end namespace llvm
13891423

13901424
#endif // LLVM_CODEGEN_MACHINESCHEDULER_H

llvm/include/llvm/InitializePasses.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void initializeMachinePipelinerPass(PassRegistry &);
209209
void initializeMachinePostDominatorTreeWrapperPassPass(PassRegistry &);
210210
void initializeMachineRegionInfoPassPass(PassRegistry &);
211211
void initializeMachineSanitizerBinaryMetadataPass(PassRegistry &);
212-
void initializeMachineSchedulerPass(PassRegistry &);
212+
void initializeMachineSchedulerLegacyPass(PassRegistry &);
213213
void initializeMachineSinkingPass(PassRegistry &);
214214
void initializeMachineTraceMetricsWrapperPassPass(PassRegistry &);
215215
void initializeMachineUniformityInfoPrinterPassPass(PassRegistry &);
@@ -238,7 +238,7 @@ void initializePostDomPrinterWrapperPassPass(PassRegistry &);
238238
void initializePostDomViewerWrapperPassPass(PassRegistry &);
239239
void initializePostDominatorTreeWrapperPassPass(PassRegistry &);
240240
void initializePostInlineEntryExitInstrumenterPass(PassRegistry &);
241-
void initializePostMachineSchedulerPass(PassRegistry &);
241+
void initializePostMachineSchedulerLegacyPass(PassRegistry &);
242242
void initializePostRAHazardRecognizerPass(PassRegistry &);
243243
void initializePostRAMachineSinkingPass(PassRegistry &);
244244
void initializePostRASchedulerLegacyPass(PassRegistry &);

llvm/include/llvm/Passes/CodeGenPassBuilder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "llvm/CodeGen/MachineLICM.h"
5151
#include "llvm/CodeGen/MachineModuleInfo.h"
5252
#include "llvm/CodeGen/MachinePassManager.h"
53+
#include "llvm/CodeGen/MachineScheduler.h"
5354
#include "llvm/CodeGen/MachineVerifier.h"
5455
#include "llvm/CodeGen/OptimizePHIs.h"
5556
#include "llvm/CodeGen/PHIElimination.h"
@@ -960,7 +961,7 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::addMachinePasses(
960961
if (getOptLevel() != CodeGenOptLevel::None &&
961962
!TM.targetSchedulesPostRAScheduling()) {
962963
if (Opt.MISchedPostRA)
963-
addPass(PostMachineSchedulerPass());
964+
addPass(PostMachineSchedulerPass(&TM));
964965
else
965966
addPass(PostRASchedulerPass(&TM));
966967
}
@@ -1144,7 +1145,7 @@ void CodeGenPassBuilder<Derived, TargetMachineT>::addOptimizedRegAlloc(
11441145
addPass(RenameIndependentSubregsPass());
11451146

11461147
// PreRA instruction scheduling.
1147-
addPass(MachineSchedulerPass());
1148+
addPass(MachineSchedulerPass(&TM));
11481149

11491150
if (derived().addRegAssignmentOptimized(addPass)) {
11501151
// Allow targets to expand pseudo instructions depending on the choice of

llvm/include/llvm/Passes/MachinePassRegistry.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ MACHINE_FUNCTION_PASS("finalize-isel", FinalizeISelPass())
142142
MACHINE_FUNCTION_PASS("localstackalloc", LocalStackSlotAllocationPass())
143143
MACHINE_FUNCTION_PASS("machine-cp", MachineCopyPropagationPass())
144144
MACHINE_FUNCTION_PASS("machine-cse", MachineCSEPass())
145+
MACHINE_FUNCTION_PASS("machine-scheduler", MachineSchedulerPass(TM))
145146
MACHINE_FUNCTION_PASS("machinelicm", MachineLICMPass())
146147
MACHINE_FUNCTION_PASS("no-op-machine-function", NoOpMachineFunctionPass())
147148
MACHINE_FUNCTION_PASS("opt-phis", OptimizePHIsPass())
148149
MACHINE_FUNCTION_PASS("peephole-opt", PeepholeOptimizerPass())
149150
MACHINE_FUNCTION_PASS("phi-node-elimination", PHIEliminationPass())
150151
MACHINE_FUNCTION_PASS("post-RA-sched", PostRASchedulerPass(TM))
152+
MACHINE_FUNCTION_PASS("postmisched", PostMachineSchedulerPass(TM))
151153
MACHINE_FUNCTION_PASS("print", PrintMIRPass())
152154
MACHINE_FUNCTION_PASS("print<livedebugvars>", LiveDebugVariablesPrinterPass(errs()))
153155
MACHINE_FUNCTION_PASS("print<live-intervals>", LiveIntervalsPrinterPass(errs()))
@@ -243,13 +245,11 @@ DUMMY_MACHINE_FUNCTION_PASS("static-data-splitter", StaticDataSplitter)
243245
DUMMY_MACHINE_FUNCTION_PASS("machine-function-splitter", MachineFunctionSplitterPass)
244246
DUMMY_MACHINE_FUNCTION_PASS("machine-latecleanup", MachineLateInstrsCleanupPass)
245247
DUMMY_MACHINE_FUNCTION_PASS("machine-sanmd", MachineSanitizerBinaryMetadata)
246-
DUMMY_MACHINE_FUNCTION_PASS("machine-scheduler", MachineSchedulerPass)
247248
DUMMY_MACHINE_FUNCTION_PASS("machine-sink", MachineSinkingPass)
248249
DUMMY_MACHINE_FUNCTION_PASS("machine-uniformity", MachineUniformityInfoWrapperPass)
249250
DUMMY_MACHINE_FUNCTION_PASS("machineinstr-printer", MachineFunctionPrinterPass)
250251
DUMMY_MACHINE_FUNCTION_PASS("mirfs-discriminators", MIRAddFSDiscriminatorsPass)
251252
DUMMY_MACHINE_FUNCTION_PASS("patchable-function", PatchableFunctionPass)
252-
DUMMY_MACHINE_FUNCTION_PASS("postmisched", PostMachineSchedulerPass)
253253
DUMMY_MACHINE_FUNCTION_PASS("postra-machine-sink", PostRAMachineSinkingPass)
254254
DUMMY_MACHINE_FUNCTION_PASS("postrapseudos", ExpandPostRAPseudosPass)
255255
DUMMY_MACHINE_FUNCTION_PASS("print-machine-cycles", MachineCycleInfoPrinterPass)

llvm/lib/CodeGen/CodeGen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
9494
initializeModuloScheduleTestPass(Registry);
9595
initializeMachinePostDominatorTreeWrapperPassPass(Registry);
9696
initializeMachineRegionInfoPassPass(Registry);
97-
initializeMachineSchedulerPass(Registry);
97+
initializeMachineSchedulerLegacyPass(Registry);
9898
initializeMachineSinkingPass(Registry);
9999
initializeMachineUniformityAnalysisPassPass(Registry);
100100
initializeMachineUniformityInfoPrinterPassPass(Registry);
@@ -105,7 +105,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
105105
initializePHIEliminationPass(Registry);
106106
initializePatchableFunctionPass(Registry);
107107
initializePeepholeOptimizerLegacyPass(Registry);
108-
initializePostMachineSchedulerPass(Registry);
108+
initializePostMachineSchedulerLegacyPass(Registry);
109109
initializePostRAHazardRecognizerPass(Registry);
110110
initializePostRAMachineSinkingPass(Registry);
111111
initializePostRASchedulerLegacyPass(Registry);

0 commit comments

Comments
 (0)