llvm-project/clang/lib/CodeGen
Johannes Doerfert 1228d42dda [OpenMP][Part 2] Use reusable OpenMP context/traits handling
This patch implements an almost complete handling of OpenMP
contexts/traits such that we can reuse most of the logic in Flang
through the OMPContext.{h,cpp} in llvm/Frontend/OpenMP.

All but construct SIMD specifiers, e.g., inbranch, and the device ISA
selector are define in `llvm/lib/Frontend/OpenMP/OMPKinds.def`. From
these definitions we generate the enum classes `TraitSet`,
`TraitSelector`, and `TraitProperty` as well as conversion and helper
functions in `llvm/lib/Frontend/OpenMP/OMPContext.{h,cpp}`.

The above enum classes are used in the parser, sema, and the AST
attribute. The latter is not a collection of multiple primitive variant
arguments that contain encodings via numbers and strings but instead a
tree that mirrors the `match` clause (see `struct OpenMPTraitInfo`).

The changes to the parser make it more forgiving when wrong syntax is
read and they also resulted in more specialized diagnostics. The tests
are updated and the core issues are detected as before. Here and
elsewhere this patch tries to be generic, thus we do not distinguish
what selector set, selector, or property is parsed except if they do
behave exceptionally, as for example `user={condition(EXPR)}` does.

The sema logic changed in two ways: First, the OMPDeclareVariantAttr
representation changed, as mentioned above, and the sema was adjusted to
work with the new `OpenMPTraitInfo`. Second, the matching and scoring
logic moved into `OMPContext.{h,cpp}`. It is implemented on a flat
representation of the `match` clause that is not tied to clang.
`OpenMPTraitInfo` provides a method to generate this flat structure (see
`struct VariantMatchInfo`) by computing integer score values and boolean
user conditions from the `clang::Expr` we keep for them.

The OpenMP context is now an explicit object (see `struct OMPContext`).
This is in anticipation of construct traits that need to be tracked. The
OpenMP context, as well as the `VariantMatchInfo`, are basically made up
of a set of active or respectively required traits, e.g., 'host', and an
ordered container of constructs which allows duplication. Matching and
scoring is kept as generic as possible to allow easy extension in the
future.

---

Test changes:

The messages checked in `OpenMP/declare_variant_messages.{c,cpp}` have
been auto generated to match the new warnings and notes of the parser.
The "subset" checks were reversed causing the wrong version to be
picked. The tests have been adjusted to correct this.
We do not print scores if the user did not provide one.
We print spaces to make lists in the `match` clause more legible.

Reviewers: kiranchandramohan, ABataev, RaviNarayanaswamy, gtbercea, grokos, sdmitriev, JonChesterfield, hfinkel, fghanim

Subscribers: merge_guards_bot, rampitec, mgorny, hiraditya, aheejin, fedor.sergeev, simoncook, bollu, guansong, dexonsmith, jfb, s.egerton, llvm-commits, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D71830
2020-02-14 16:37:42 -06:00
..
ABIInfo.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
Address.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BackendUtil.cpp Revert "[DebugInfo] Enable the debug entry values feature by default" 2020-02-12 11:59:04 +01:00
CGAtomic.cpp [OPENMP50]Add codegen for acq_rel clause in atomic|flush directives. 2020-02-07 15:05:09 -05:00
CGBlocks.cpp [Alignment][NFC] Use Align with CreateAlignedStore 2020-01-23 17:34:32 +01:00
CGBlocks.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGBuilder.h [clang] Add support for __builtin_memcpy_inline 2020-02-07 23:55:26 +01:00
CGBuiltin.cpp [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
CGCUDANV.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
CGCUDARuntime.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCUDARuntime.h [HIP] Add the interface deriving the stub name of device kernels. 2019-06-17 12:51:36 +00:00
CGCXX.cpp [Alignment][NFC] Use Align with CreateAlignedLoad 2020-01-27 10:58:36 +01:00
CGCXXABI.cpp Avoid Attr.h includes, CodeGen edition 2019-12-09 16:17:18 -08:00
CGCXXABI.h Improve code generation for thread_local variables: 2019-09-12 20:00:24 +00:00
CGCall.cpp [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
CGCall.h Revert "[IRGen] Emit lifetime intrinsics around temporary aggregate argument allocas" 2020-02-12 12:26:46 -08:00
CGClass.cpp Don't assume a reference refers to at least sizeof(T) bytes. 2020-01-31 19:08:17 -08:00
CGCleanup.cpp [Alignment][Clang][NFC] Add CharUnits::getAsAlign 2019-10-03 13:00:29 +00:00
CGCleanup.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGCoroutine.cpp Fix parameter name comments using clang-tidy. NFC. 2019-07-16 04:46:31 +00:00
CGDebugInfo.cpp Revert "[DebugInfo] Enable the debug entry values feature by default" 2020-02-12 11:59:04 +01:00
CGDebugInfo.h Recommit "[DWARF5][clang]: Added support for DebugInfo generation for auto return type for C++ member functions." 2020-01-24 14:50:17 +05:30
CGDecl.cpp [OPENMP50]Full handling of atomic_default_mem_order in requires 2020-02-11 15:42:34 -05:00
CGDeclCXX.cpp Avoid Attr.h includes, CodeGen edition 2019-12-09 16:17:18 -08:00
CGException.cpp [clang] Add -fignore-exceptions 2020-02-12 09:56:18 +00:00
CGExpr.cpp [ARM] Follow AACPS for preserving number of loads/stores of volatile bit-fields 2020-02-07 10:11:54 +00:00
CGExprAgg.cpp [c++20] P1959R0: Remove support for std::*_equality. 2019-12-16 17:49:45 -08:00
CGExprCXX.cpp Fix "pointer is null" static analyzer warnings. NFCI. 2020-01-11 16:02:23 +00:00
CGExprComplex.cpp Fix a crash when casting _Complex and ignoring the results. 2020-01-28 13:05:56 -05:00
CGExprConstant.cpp C++ DR2026: static storage duration variables are not zeroed before 2020-02-06 16:37:22 -08:00
CGExprScalar.cpp [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
CGGPUBuiltin.cpp [Alignment][NFC] Use Align with CreateAlignedStore 2020-01-23 17:34:32 +01:00
CGLoopInfo.cpp [Clang] Pragma vectorize_width() implies vectorize(enable) 2019-12-11 10:37:40 +00:00
CGLoopInfo.h Don't keep stale pointers to LoopInfos. 2019-08-19 13:37:41 +00:00
CGNonTrivialStruct.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
CGObjC.cpp Relax the rules around objc_alloc and objc_alloc_init optimizations. 2020-01-14 19:48:33 -08:00
CGObjCGNU.cpp Fix more implicit conversions. Getting closer to having clang working with gcc 5 again 2020-01-29 02:57:59 +01:00
CGObjCMac.cpp [objc_direct] fix codegen for mismatched Decl/Impl return types 2020-01-30 18:17:45 -08:00
CGObjCRuntime.cpp [opaque pointer types] Pass function types for runtime function calls. 2019-02-05 16:42:33 +00:00
CGObjCRuntime.h Implement __attribute__((objc_direct)), __attribute__((objc_direct_members)) 2019-11-18 11:48:40 -08:00
CGOpenCLRuntime.cpp Fix "pointer is null" static analyzer warning. NFCI. 2020-01-08 17:19:08 +00:00
CGOpenCLRuntime.h [OpenCL] Simplify LLVM IR generated for OpenCL blocks 2019-02-21 11:02:10 +00:00
CGOpenMPRuntime.cpp [OpenMP][Part 2] Use reusable OpenMP context/traits handling 2020-02-14 16:37:42 -06:00
CGOpenMPRuntime.h [OPENMP50]Full handling of atomic_default_mem_order in requires 2020-02-11 15:42:34 -05:00
CGOpenMPRuntimeNVPTX.cpp [OPENMP50]Full handling of atomic_default_mem_order in requires 2020-02-11 15:42:34 -05:00
CGOpenMPRuntimeNVPTX.h [OPENMP50]Full handling of atomic_default_mem_order in requires 2020-02-11 15:42:34 -05:00
CGRecordLayout.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGRecordLayoutBuilder.cpp P0840R2: support for [[no_unique_address]] attribute 2019-06-20 20:44:45 +00:00
CGStmt.cpp Support -fstack-clash-protection for x86 2020-02-09 10:42:45 +01:00
CGStmtOpenMP.cpp [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
CGVTT.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGVTables.cpp Restore "[LTO/WPD] Enable aggressive WPD under LTO option" 2020-01-27 07:55:05 -08:00
CGVTables.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CGValue.h Move verification of Sema::MaximumAlignment to a .cpp file 2020-01-30 13:37:52 -08:00
CMakeLists.txt Generalize the pass registration mechanism used by Polly to any third-party tool 2020-01-02 16:45:31 +01:00
CodeGenABITypes.cpp Fix parameter name comments using clang-tidy. NFC. 2019-07-16 04:46:31 +00:00
CodeGenAction.cpp [Remarks] Extend the RemarkStreamer to support other emitters 2020-02-04 17:16:02 -08:00
CodeGenFunction.cpp [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
CodeGenFunction.h [AsmPrinter] De-capitalize all AsmPrinter::Emit* but EmitInstruction 2020-02-13 17:06:24 -08:00
CodeGenModule.cpp Support -fstack-clash-protection for x86 2020-02-09 10:42:45 +01:00
CodeGenModule.h Don't assume a reference refers to at least sizeof(T) bytes. 2020-01-31 19:08:17 -08:00
CodeGenPGO.cpp [NFC] Fixes -Wrange-loop-analysis warnings 2020-01-01 20:01:37 +01:00
CodeGenPGO.h Fix uninitialized variable warning in CodeGenPGO constructor. NFCI. 2019-10-02 21:05:21 +00:00
CodeGenTBAA.cpp Fix detection of __attribute__((may_alias)) to properly look through 2019-12-11 14:04:37 -08:00
CodeGenTBAA.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTypeCache.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CodeGenTypes.cpp Silence static analyzer getAs<RecordType> null dereference warnings. NFCI. 2019-10-03 11:22:48 +00:00
CodeGenTypes.h IRGen: Remove StructorType; thread GlobalDecl through more code. NFCI. 2019-03-22 23:05:10 +00:00
ConstantEmitter.h [CodeGen] Fix clang crash on aggregate initialization of array of labels 2019-11-28 00:59:25 +01:00
ConstantInitBuilder.cpp [Alignment][Clang][NFC] Add CharUnits::getAsAlign 2019-10-03 13:00:29 +00:00
CoverageMappingGen.cpp [clang] Replace SmallStr.str().str() with std::string conversion operator. 2020-01-29 21:27:46 -08:00
CoverageMappingGen.h Revert "[Coverage] Revise format to reduce binary size" 2019-12-04 10:35:14 -08:00
EHScopeStack.h Replace llvm::integer_sequence and friends with the C++14 standard version 2019-08-15 10:56:05 +00:00
ItaniumCXXABI.cpp Restore "[LTO/WPD] Enable aggressive WPD under LTO option" 2020-01-27 07:55:05 -08:00
MacroPPCallbacks.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MacroPPCallbacks.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MicrosoftCXXABI.cpp [WPD] Emit vcall_visibility metadata for MicrosoftCXXABI 2020-01-27 06:22:24 -08:00
ModuleBuilder.cpp reland "[DebugInfo] Support to emit debugInfo for extern variables" 2019-12-22 18:28:50 -08:00
ObjectFilePCHContainerOperations.cpp [Alignment][Clang][NFC] Add CharUnits::getAsAlign 2019-10-03 13:00:29 +00:00
PatternInit.cpp CodeGet: Init 32bit pointers with 0xFFFFFFFF 2019-07-12 17:21:55 +00:00
PatternInit.h Variable auto-init: also auto-init alloca 2019-04-12 00:11:27 +00:00
README.txt
SanitizerMetadata.cpp Avoid Attr.h includes, CodeGen edition 2019-12-09 16:17:18 -08:00
SanitizerMetadata.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SwiftCallingConv.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
TargetInfo.cpp Fix `-Wunused-variable` warning. NFC. 2020-02-12 12:45:14 -05:00
TargetInfo.h [OpenCL][PR41727] Prevent ICE on global dtors 2019-07-15 11:58:10 +00:00
VarBypassDetector.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
VarBypassDetector.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00

README.txt

IRgen optimization opportunities.

//===---------------------------------------------------------------------===//

The common pattern of
--
short x; // or char, etc
(x == 10)
--
generates an zext/sext of x which can easily be avoided.

//===---------------------------------------------------------------------===//

Bitfields accesses can be shifted to simplify masking and sign
extension. For example, if the bitfield width is 8 and it is
appropriately aligned then is is a lot shorter to just load the char
directly.

//===---------------------------------------------------------------------===//

It may be worth avoiding creation of alloca's for formal arguments
for the common situation where the argument is never written to or has
its address taken. The idea would be to begin generating code by using
the argument directly and if its address is taken or it is stored to
then generate the alloca and patch up the existing code.

In theory, the same optimization could be a win for block local
variables as long as the declaration dominates all statements in the
block.

NOTE: The main case we care about this for is for -O0 -g compile time
performance, and in that scenario we will need to emit the alloca
anyway currently to emit proper debug info. So this is blocked by
being able to emit debug information which refers to an LLVM
temporary, not an alloca.

//===---------------------------------------------------------------------===//

We should try and avoid generating basic blocks which only contain
jumps. At -O0, this penalizes us all the way from IRgen (malloc &
instruction overhead), all the way down through code generation and
assembly time.

On 176.gcc:expr.ll, it looks like over 12% of basic blocks are just
direct branches!

//===---------------------------------------------------------------------===//