[llvm-branch-commits] [llvm] [Coro] Use DebugInfoCache to speed up cloning in CoroSplitPass (PR #118630)
https://github.com/artempyanykh edited https://github.com/llvm/llvm-project/pull/118630 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [Coro] Prebuild a module-level debug info set and share it between all coroutine clones (PR #118628)
https://github.com/artempyanykh edited https://github.com/llvm/llvm-project/pull/118628 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [JITLink][LoongArch] Add label addition and subtraction relocations (PR #122262)
https://github.com/zhaoqi5 updated https://github.com/llvm/llvm-project/pull/122262 >From 4398bd99d87c58307e55798a3f6dde372b4d0cb6 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Fri, 27 Dec 2024 15:39:57 +0800 Subject: [PATCH] [JITLink][LoongArch] Add label addition and subtraction relocations --- .../llvm/ExecutionEngine/JITLink/loongarch.h | 180 ++ .../ExecutionEngine/JITLink/ELF_loongarch.cpp | 24 +++ .../lib/ExecutionEngine/JITLink/loongarch.cpp | 12 ++ .../JITLink/LoongArch/ELF_reloc_addsub.s | 53 ++ 4 files changed, 269 insertions(+) create mode 100644 llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_reloc_addsub.s diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h index d6025edf7d110d..1d763e1255fc21 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h @@ -14,8 +14,10 @@ #define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H #include "TableManager.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/Support/LEB128.h" namespace llvm { namespace jitlink { @@ -226,6 +228,90 @@ enum EdgeKind_loongarch : Edge::Kind { /// Call36PCRel, + /// low 6 bits label addition + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup + (Target + Addend) & 0x3f) : int8 + /// + Add6, + + /// 8 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{1}Fixup + Addend) : int8 + /// + Add8, + + /// 16 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{2}Fixup + Addend) : int16 + /// + Add16, + + /// 32 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{4}Fixup + Addend) : int32 + /// + Add32, + + /// 64 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{8}Fixup + Addend) : int64 + /// + Add64, + + /// ULEB128 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{16}Fixup + Addend) : uleb128 + /// + AddUleb128, + + /// low 6 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - (Target + Addend) & 0x3f) : int8 + /// + Sub6, + + /// 8 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - Target - Addend) : int8 + /// + Sub8, + + /// 16 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{2}Fixup - Target - Addend) : int16 + /// + Sub16, + + /// 32 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{4}Fixup - Target - Addend) : int32 + /// + Sub32, + + /// 64 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{8}Fixup - Target - Addend) : int64 + /// + Sub64, + + /// ULEB128 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{16}Fixup - Target - Addend) : uleb128 + /// + SubUleb128, + /// Alignment requirement used by linker relaxation. /// /// Linker relaxation will use this to ensure all code sequences are properly @@ -369,6 +455,100 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E) { *(little32_t *)(FixupPtr + 4) = Jirl | Lo16; break; } + case Add6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value += ((TargetAddress + Addend) & 0x3f); +*FixupPtr = (*FixupPtr & 0xc0) | (static_cast(Value) & 0x3f); +break; + } + case Add8: { +int64_t Value = +TargetAddress + *(reinterpret_cast(FixupPtr)) + Addend; +*FixupPtr = static_cast(Value); +break; + } + case Add16: { +int64_t Value = +TargetAddress + support::endian::read16le(FixupPtr) + Addend; +*(little16_t *)FixupPtr = static_cast(Value); +break; + } + case Add32: { +int64_t Value = +TargetAddress + support::endian::read32le(FixupPtr) + Addend; +*(little32_t *)FixupPtr = static_cast(Value); +break; + } + case Add64: { +int64_t Value = +TargetAddress + support::endian::read64le(FixupPtr) + Addend; +*(little64_t *)FixupPtr = static_cast(Value); +break; + } + case AddUleb128: { +const uint32_t Maxcount = 1 + 64 / 7; +uint32_t Count; +const char *Error = nullptr; +uint64_t Orig = decodeULEB128((reinterpret_cast(FixupPtr)), + &Count, nullptr, &Error); + +if (Count > Maxcount || (Count == Maxcount && Error)) + return make_error( + "0x" + llvm::utohexstr(orc::ExecutorAddr(FixupAddress).getValue()) + + ": extra space for uleb128"); + +uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL; +encodeULEB128((Orig + TargetAddress + Addend) & Mask, + (reinterpret_cast(FixupPtr)), Count); +break; + } + case Sub6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value -= ((Targ
[llvm-branch-commits] [NFCI][BoundsChecking] Apply nosanitize on local-bounds instrumentation (PR #122416)
https://github.com/thurstond approved this pull request. https://github.com/llvm/llvm-project/pull/122416 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [nfc][ubsan] Add local-bounds test (PR #122415)
https://github.com/thurstond commented: Would it be useful to keep -fsanitize=...null and add local-bounds instead of replacing null with local-bounds? It would make the test more rigorous and also make the diff smaller. https://github.com/llvm/llvm-project/pull/122415 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)
topperc wrote: Description needs to be updated if MachineLICM, MachineSink, MachinePipeliner have been migrated to RegisterClassInfo. https://github.com/llvm/llvm-project/pull/118787 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)
spavloff wrote: Sorry, I didn't provide enough documentation. Now the attribute is documented in LangRef and the motivation for this change is presented in the PR description. > I think this is aiming too low. I think this should be a general floating > point environment access that is specific about what aspects of the floating > point environment may be used. This includes read or write of the rounding > mode, other FP env fields, and errno It would be profitable to extend the set of FP parameters beyond FP environment. For example, static rounding mode, strictly speaking, is not a part of FP environment, it is just a parameter. But passing it in FP operand bundles allows us to obtain a more consistent representation, because in many cases it does not matter if rounding mode comes from a register or encoded as a part of instruction. https://github.com/llvm/llvm-project/pull/122313 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)
arsenm wrote: I think this is aiming too low. I think this should be a general floating point environment access that is specific about what aspects of the floating point environment may be used https://github.com/llvm/llvm-project/pull/122313 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] f11be66 - Revert "Spiller: Detach legacy pass and supply analyses instead (#119181)"
Author: Akshat Oke Date: 2025-01-10T12:22:48+05:30 New Revision: f11be66dcc53b1908f4520772e55d5506253ae27 URL: https://github.com/llvm/llvm-project/commit/f11be66dcc53b1908f4520772e55d5506253ae27 DIFF: https://github.com/llvm/llvm-project/commit/f11be66dcc53b1908f4520772e55d5506253ae27.diff LOG: Revert "Spiller: Detach legacy pass and supply analyses instead (#119181)" This reverts commit a531800344dc54e9c197a13b22e013f919f3f5e1. Added: Modified: llvm/include/llvm/CodeGen/Spiller.h llvm/lib/CodeGen/InlineSpiller.cpp llvm/lib/CodeGen/RegAllocBasic.cpp llvm/lib/CodeGen/RegAllocGreedy.cpp llvm/lib/CodeGen/RegAllocPBQP.cpp Removed: diff --git a/llvm/include/llvm/CodeGen/Spiller.h b/llvm/include/llvm/CodeGen/Spiller.h index 3132cefeb6c68a..51ad36bc6b1f8b 100644 --- a/llvm/include/llvm/CodeGen/Spiller.h +++ b/llvm/include/llvm/CodeGen/Spiller.h @@ -19,10 +19,6 @@ class MachineFunction; class MachineFunctionPass; class VirtRegMap; class VirtRegAuxInfo; -class LiveIntervals; -class LiveStacks; -class MachineDominatorTree; -class MachineBlockFrequencyInfo; /// Spiller interface. /// @@ -45,20 +41,12 @@ class Spiller { virtual ArrayRef getReplacedRegs() = 0; virtual void postOptimization() {} - - struct RequiredAnalyses { -LiveIntervals &LIS; -LiveStacks &LSS; -MachineDominatorTree &MDT; -const MachineBlockFrequencyInfo &MBFI; - }; }; /// Create and return a spiller that will insert spill code directly instead /// of deferring though VirtRegMap. -Spiller *createInlineSpiller(const Spiller::RequiredAnalyses &Analyses, - MachineFunction &MF, VirtRegMap &VRM, - VirtRegAuxInfo &VRAI); +Spiller *createInlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, + VirtRegMap &VRM, VirtRegAuxInfo &VRAI); } // end namespace llvm diff --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp index b9768d5c63a5d1..64f290f5930a1b 100644 --- a/llvm/lib/CodeGen/InlineSpiller.cpp +++ b/llvm/lib/CodeGen/InlineSpiller.cpp @@ -75,6 +75,7 @@ RestrictStatepointRemat("restrict-statepoint-remat", cl::desc("Restrict remat for statepoint operands")); namespace { + class HoistSpillHelper : private LiveRangeEdit::Delegate { MachineFunction &MF; LiveIntervals &LIS; @@ -127,11 +128,15 @@ class HoistSpillHelper : private LiveRangeEdit::Delegate { DenseMap &SpillsToIns); public: - HoistSpillHelper(const Spiller::RequiredAnalyses &Analyses, - MachineFunction &mf, VirtRegMap &vrm) - : MF(mf), LIS(Analyses.LIS), LSS(Analyses.LSS), MDT(Analyses.MDT), + HoistSpillHelper(MachineFunctionPass &pass, MachineFunction &mf, + VirtRegMap &vrm) + : MF(mf), LIS(pass.getAnalysis().getLIS()), +LSS(pass.getAnalysis().getLS()), +MDT(pass.getAnalysis().getDomTree()), VRM(vrm), MRI(mf.getRegInfo()), TII(*mf.getSubtarget().getInstrInfo()), -TRI(*mf.getSubtarget().getRegisterInfo()), MBFI(Analyses.MBFI), +TRI(*mf.getSubtarget().getRegisterInfo()), +MBFI( + pass.getAnalysis().getMBFI()), IPA(LIS, mf.getNumBlockIDs()) {} void addToMergeableSpills(MachineInstr &Spill, int StackSlot, @@ -185,12 +190,16 @@ class InlineSpiller : public Spiller { ~InlineSpiller() override = default; public: - InlineSpiller(const Spiller::RequiredAnalyses &Analyses, MachineFunction &MF, -VirtRegMap &VRM, VirtRegAuxInfo &VRAI) - : MF(MF), LIS(Analyses.LIS), LSS(Analyses.LSS), MDT(Analyses.MDT), + InlineSpiller(MachineFunctionPass &Pass, MachineFunction &MF, VirtRegMap &VRM, +VirtRegAuxInfo &VRAI) + : MF(MF), LIS(Pass.getAnalysis().getLIS()), +LSS(Pass.getAnalysis().getLS()), +MDT(Pass.getAnalysis().getDomTree()), VRM(VRM), MRI(MF.getRegInfo()), TII(*MF.getSubtarget().getInstrInfo()), -TRI(*MF.getSubtarget().getRegisterInfo()), MBFI(Analyses.MBFI), -HSpiller(Analyses, MF, VRM), VRAI(VRAI) {} +TRI(*MF.getSubtarget().getRegisterInfo()), +MBFI( + Pass.getAnalysis().getMBFI()), +HSpiller(Pass, MF, VRM), VRAI(VRAI) {} void spill(LiveRangeEdit &) override; ArrayRef getSpilledRegs() override { return RegsToSpill; } @@ -228,11 +237,10 @@ Spiller::~Spiller() = default; void Spiller::anchor() {} -Spiller * -llvm::createInlineSpiller(const InlineSpiller::RequiredAnalyses &Analyses, - MachineFunction &MF, VirtRegMap &VRM, - VirtRegAuxInfo &VRAI) { - return new InlineSpiller(Analyses, MF, VRM, VRAI); +Spiller *llvm::createInlineSpiller(MachineFunctionPass &Pass, + MachineFunction &MF, VirtRegMap &VRM, +
[llvm-branch-commits] [flang] [Flang] Optionally do not compile the runtime in-tree (PR #122336)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/122336 >From dd3ac2e6d8d8d57cd639c25bea3b8d5c99a2f81e Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 9 Jan 2025 15:58:48 +0100 Subject: [PATCH 1/4] Introduce FLANG_INCLUDE_RUNTIME --- flang/CMakeLists.txt| 7 +++- flang/test/CMakeLists.txt | 6 +++- flang/test/Driver/ctofortran.f90| 1 + flang/test/Driver/exec.f90 | 1 + flang/test/Runtime/no-cpp-dep.c | 2 +- flang/test/lit.cfg.py | 5 ++- flang/test/lit.site.cfg.py.in | 1 + flang/tools/f18/CMakeLists.txt | 4 +-- flang/unittests/CMakeLists.txt | 6 ++-- flang/unittests/Evaluate/CMakeLists.txt | 46 ++--- 10 files changed, 50 insertions(+), 29 deletions(-) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 68947eaa9c9bd7..69e963a43d0b97 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -233,6 +233,9 @@ else() include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR}) endif() +option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON) +pythonize_bool(FLANG_INCLUDE_RUNTIME) + set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") mark_as_advanced(FLANG_TOOLS_INSTALL_DIR) @@ -473,7 +476,9 @@ if (FLANG_CUF_RUNTIME) find_package(CUDAToolkit REQUIRED) endif() -add_subdirectory(runtime) +if (FLANG_INCLUDE_RUNTIME) + add_subdirectory(runtime) +endif () if (LLVM_INCLUDE_EXAMPLES) add_subdirectory(examples) diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt index cab214c2ef4c8c..e398e0786147aa 100644 --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS llvm-objdump llvm-readobj split-file - FortranRuntime FortranDecimal ) + +if (FLANG_INCLUDE_RUNTIME) + list(APPEND FLANG_TEST_DEPENDS FortranRuntime) +endif () + if (LLVM_ENABLE_PLUGINS AND NOT WIN32) list(APPEND FLANG_TEST_DEPENDS Bye) endif() diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90 index 78eac32133b18e..10c7adaccc9588 100644 --- a/flang/test/Driver/ctofortran.f90 +++ b/flang/test/Driver/ctofortran.f90 @@ -1,4 +1,5 @@ ! UNSUPPORTED: system-windows +! REQUIRES: flang-rt ! RUN: split-file %s %t ! RUN: chmod +x %t/runtest.sh ! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s diff --git a/flang/test/Driver/exec.f90 b/flang/test/Driver/exec.f90 index fd174005ddf62a..9ca91ee24011c9 100644 --- a/flang/test/Driver/exec.f90 +++ b/flang/test/Driver/exec.f90 @@ -1,4 +1,5 @@ ! UNSUPPORTED: system-windows +! REQUIRES: flang-rt ! Verify that flang can correctly build executables. ! RUN: %flang %s -o %t diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c index b1a5fa004014cc..7303ce63fdec41 100644 --- a/flang/test/Runtime/no-cpp-dep.c +++ b/flang/test/Runtime/no-cpp-dep.c @@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on the C++ runtime library. It tries to link this simple file against libFortranRuntime.a with a C compiler. -REQUIRES: c-compiler +REQUIRES: c-compiler, flang-rt RUN: %if system-aix %{ export OBJECT_MODE=64 %} RUN: %cc -std=c99 %s -I%include %libruntime -lm \ diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index c452b6d231c89f..78378bf5f413e8 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -163,10 +163,13 @@ ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal") ) +if config.flang_include_runtime: + config.available_features.add("flang-rt") + # Define some variables to help us test that the flang runtime doesn't depend on # the C++ runtime libraries. For this we need a C compiler. If for some reason # we don't have one, we can just disable the test. -if config.cc: +if config.flang_include_runtime and config.cc: libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a") include = os.path.join(config.flang_src_dir, "include") diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index d1a0ac763cf8a0..19f9330f93ae14 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -32,6 +32,7 @@ else: config.openmp_module_dir = None config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@" config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@" +config.flang_include_runtime = @FLANG_INCLUDE_RUNTIME@ import lit.llvm lit.llvm.initialize(lit_config, config) diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index 4362fcf0537616..022c346aabdbde 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -72,7 +72,7 @@ if (NOT CMAKE_CROSSCOMPILING) set(depends ${FLANG_
[llvm-branch-commits] [llvm] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)
@@ -925,9 +925,16 @@ class TargetRegisterInfo : public MCRegisterInfo { virtual const char *getRegPressureSetName(unsigned Idx) const = 0; /// Get the register unit pressure limit for this dimension. - /// This limit must be adjusted dynamically for reserved registers. + /// TargetRegisterInfo adjusts this limit for reserved registers. + /// Avoid using this method directly as it is costly to compute. Use the + /// cached version `RegisterClassInfo::getRegPressureSetLimit` instead. virtual unsigned getRegPressureSetLimit(const MachineFunction &MF, wangpc-pp wrote: If moving to `MachineRegisterInfo`, then AMDGPU target will not be able to override it and that will cause regressions. https://github.com/llvm/llvm-project/pull/118787 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [Analysis] Add DebugInfoCache analysis (PR #118629)
https://github.com/artempyanykh edited https://github.com/llvm/llvm-project/pull/118629 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [nfc][BoundsChecking] Rename BoundsCheckingOptions into Options (PR #122359)
https://github.com/thurstond approved this pull request. https://github.com/llvm/llvm-project/pull/122359 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] 20d254d - Revert "[SLP] NFC. Replace MainOp and AltOp in TreeEntry with InstructionsSta…"
Author: Han-Kuan Chen Date: 2025-01-10T10:38:21+08:00 New Revision: 20d254d9728fd1dff9a98bc2f82431dd990307a7 URL: https://github.com/llvm/llvm-project/commit/20d254d9728fd1dff9a98bc2f82431dd990307a7 DIFF: https://github.com/llvm/llvm-project/commit/20d254d9728fd1dff9a98bc2f82431dd990307a7.diff LOG: Revert "[SLP] NFC. Replace MainOp and AltOp in TreeEntry with InstructionsSta…" This reverts commit 760f550de25792db83cd39c88ef57ab6d80a41a0. Added: Modified: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp Removed: diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 8ff70fdb1180b0..fd897b3f720be3 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -2414,16 +2414,15 @@ class BoUpSLP { } /// Go through the instructions in VL and append their operands. -void appendOperandsOfVL(ArrayRef VL, const InstructionsState &S) { +void appendOperandsOfVL(ArrayRef VL, Instruction *VL0) { assert(!VL.empty() && "Bad VL"); assert((empty() || VL.size() == getNumLanes()) && "Expected same number of lanes"); // IntrinsicInst::isCommutative returns true if swapping the first "two" // arguments to the intrinsic produces the same result. constexpr unsigned IntrinsicNumOperands = 2; - unsigned NumOperands = S.getMainOp()->getNumOperands(); - ArgSize = isa(S.getMainOp()) ? IntrinsicNumOperands - : NumOperands; + unsigned NumOperands = VL0->getNumOperands(); + ArgSize = isa(VL0) ? IntrinsicNumOperands : NumOperands; OpsVec.resize(NumOperands); unsigned NumLanes = VL.size(); for (unsigned OpIdx = 0; OpIdx != NumOperands; ++OpIdx) { @@ -2443,8 +2442,8 @@ class BoUpSLP { // tell the inverse operations by checking commutativity. if (isa(VL[Lane])) { OpsVec[OpIdx][Lane] = { -PoisonValue::get(S.getMainOp()->getOperand(OpIdx)->getType()), -true, false}; +PoisonValue::get(VL0->getOperand(OpIdx)->getType()), true, +false}; continue; } bool IsInverseOperation = !isCommutative(cast(VL[Lane])); @@ -2556,12 +2555,11 @@ class BoUpSLP { public: /// Initialize with all the operands of the instruction vector \p RootVL. -VLOperands(ArrayRef RootVL, const InstructionsState &S, - const BoUpSLP &R) +VLOperands(ArrayRef RootVL, Instruction *VL0, const BoUpSLP &R) : TLI(*R.TLI), DL(*R.DL), SE(*R.SE), R(R), - L(R.LI->getLoopFor(S.getMainOp()->getParent())) { + L(R.LI->getLoopFor((VL0->getParent( { // Append all the operands of RootVL. - appendOperandsOfVL(RootVL, S); + appendOperandsOfVL(RootVL, VL0); } /// \Returns a value vector with the operands across all lanes for the @@ -3034,7 +3032,7 @@ class BoUpSLP { /// non-identity permutation that allows to reuse extract instructions. /// \param ResizeAllowed indicates whether it is allowed to handle subvector /// extract order. - bool canReuseExtract(ArrayRef VL, + bool canReuseExtract(ArrayRef VL, Value *OpValue, SmallVectorImpl &CurrentOrder, bool ResizeAllowed = false) const; @@ -3261,7 +3259,7 @@ class BoUpSLP { }; /// Checks if the current node is a gather node. -bool isGather() const { return State == NeedToGather; } +bool isGather() const {return State == NeedToGather; } /// A vector of scalars. ValueList Scalars; @@ -3325,9 +3323,9 @@ class BoUpSLP { /// reordering of operands during buildTree_rec() and vectorizeTree(). SmallVector Operands; -/// MainOp and AltOp are recorded inside. S should be obtained from -/// newTreeEntry. -InstructionsState S = InstructionsState::invalid(); +/// The main/alternate instruction. +Instruction *MainOp = nullptr; +Instruction *AltOp = nullptr; /// Interleaving factor for interleaved loads Vectorize nodes. unsigned InterleaveFactor = 0; @@ -3351,10 +3349,10 @@ class BoUpSLP { /// Set this bundle's operand from Scalars. void setOperand(const BoUpSLP &R, bool RequireReorder = false) { - VLOperands Ops(Scalars, S, R); + VLOperands Ops(Scalars, MainOp, R); if (RequireReorder) Ops.reorder(); - for (unsigned I : seq(S.getMainOp()->getNumOperands())) + for (unsigned I : seq(MainOp->getNumOperands())) setOperand(I, Ops.getVL(I)); } @@ -3387,9 +3385,13 @@ class BoUpSLP { } /// Some of the instructions in the list have alternate opcodes. -bool isAltShuffle() const { return S.isAltShuffle(); } +bool isAltShuffle() const { return MainOp != AltOp;
[llvm-branch-commits] [llvm] bb82cf6 - Revert "[SLP] NFC. Refactor getSameOpcode and reduce for loop iterations. (#1…"
Author: Vitaly Buka Date: 2025-01-09T18:09:16-08:00 New Revision: bb82cf61a7a0b7c74dee596f85243cdcbe59e695 URL: https://github.com/llvm/llvm-project/commit/bb82cf61a7a0b7c74dee596f85243cdcbe59e695 DIFF: https://github.com/llvm/llvm-project/commit/bb82cf61a7a0b7c74dee596f85243cdcbe59e695.diff LOG: Revert "[SLP] NFC. Refactor getSameOpcode and reduce for loop iterations. (#1…" This reverts commit 36b423e0f85cb35eb8b211662a0fab70d476f501. Added: Modified: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp Removed: diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index 8ff70fdb1180b0..6360ddb57007d6 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -916,22 +916,24 @@ static InstructionsState getSameOpcode(ArrayRef VL, if (It == VL.end()) return InstructionsState::invalid(); - Instruction *MainOp = cast(*It); + Value *V = *It; unsigned InstCnt = std::count_if(It, VL.end(), IsaPred); - if ((VL.size() > 2 && !isa(MainOp) && InstCnt < VL.size() / 2) || + if ((VL.size() > 2 && !isa(V) && InstCnt < VL.size() / 2) || (VL.size() == 2 && InstCnt < 2)) return InstructionsState::invalid(); - bool IsCastOp = isa(MainOp); - bool IsBinOp = isa(MainOp); - bool IsCmpOp = isa(MainOp); - CmpInst::Predicate BasePred = IsCmpOp ? cast(MainOp)->getPredicate() -: CmpInst::BAD_ICMP_PREDICATE; - Instruction *AltOp = MainOp; - unsigned Opcode = MainOp->getOpcode(); + bool IsCastOp = isa(V); + bool IsBinOp = isa(V); + bool IsCmpOp = isa(V); + CmpInst::Predicate BasePred = + IsCmpOp ? cast(V)->getPredicate() : CmpInst::BAD_ICMP_PREDICATE; + unsigned Opcode = cast(V)->getOpcode(); unsigned AltOpcode = Opcode; + unsigned AltIndex = std::distance(VL.begin(), It); - bool SwappedPredsCompatible = IsCmpOp && [&]() { + bool SwappedPredsCompatible = [&]() { +if (!IsCmpOp) + return false; SetVector UniquePreds, UniqueNonSwappedPreds; UniquePreds.insert(BasePred); UniqueNonSwappedPreds.insert(BasePred); @@ -954,18 +956,18 @@ static InstructionsState getSameOpcode(ArrayRef VL, }(); // Check for one alternate opcode from another BinaryOperator. // TODO - generalize to support all operators (types, calls etc.). + auto *IBase = cast(V); Intrinsic::ID BaseID = 0; SmallVector BaseMappings; - if (auto *CallBase = dyn_cast(MainOp)) { + if (auto *CallBase = dyn_cast(IBase)) { BaseID = getVectorIntrinsicIDForCall(CallBase, &TLI); BaseMappings = VFDatabase(*CallBase).getMappings(*CallBase); if (!isTriviallyVectorizable(BaseID) && BaseMappings.empty()) return InstructionsState::invalid(); } bool AnyPoison = InstCnt != VL.size(); - // Skip MainOp. - for (Value *V : iterator_range(It + 1, VL.end())) { -auto *I = dyn_cast(V); + for (int Cnt = 0, E = VL.size(); Cnt < E; Cnt++) { +auto *I = dyn_cast(VL[Cnt]); if (!I) continue; @@ -981,11 +983,11 @@ static InstructionsState getSameOpcode(ArrayRef VL, if (Opcode == AltOpcode && isValidForAlternation(InstOpcode) && isValidForAlternation(Opcode)) { AltOpcode = InstOpcode; -AltOp = I; +AltIndex = Cnt; continue; } } else if (IsCastOp && isa(I)) { - Value *Op0 = MainOp->getOperand(0); + Value *Op0 = IBase->getOperand(0); Type *Ty0 = Op0->getType(); Value *Op1 = I->getOperand(0); Type *Ty1 = Op1->getType(); @@ -997,12 +999,12 @@ static InstructionsState getSameOpcode(ArrayRef VL, isValidForAlternation(InstOpcode) && "Cast isn't safe for alternation, logic needs to be updated!"); AltOpcode = InstOpcode; - AltOp = I; + AltIndex = Cnt; continue; } } -} else if (auto *Inst = dyn_cast(I); Inst && IsCmpOp) { - auto *BaseInst = cast(MainOp); +} else if (auto *Inst = dyn_cast(VL[Cnt]); Inst && IsCmpOp) { + auto *BaseInst = cast(V); Type *Ty0 = BaseInst->getOperand(0)->getType(); Type *Ty1 = Inst->getOperand(0)->getType(); if (Ty0 == Ty1) { @@ -1016,21 +1018,21 @@ static InstructionsState getSameOpcode(ArrayRef VL, CmpInst::Predicate SwappedCurrentPred = CmpInst::getSwappedPredicate(CurrentPred); -if ((VL.size() == 2 || SwappedPredsCompatible) && +if ((E == 2 || SwappedPredsCompatible) && (BasePred == CurrentPred || BasePred == SwappedCurrentPred)) continue; if (isCmpSameOrSwapped(BaseInst, Inst, TLI)) continue; -auto *AltInst = cast(AltOp); -if (MainOp != AltOp) { +auto *AltInst = cast(VL[AltIndex]); +if (AltIndex) { if (isCmpSameOrSwapped(AltInst, Inst, T
[llvm-branch-commits] [llvm] [JITLink][LoongArch] Add label addition and subtraction relocations (PR #122262)
https://github.com/zhaoqi5 updated https://github.com/llvm/llvm-project/pull/122262 >From 4398bd99d87c58307e55798a3f6dde372b4d0cb6 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Fri, 27 Dec 2024 15:39:57 +0800 Subject: [PATCH 1/2] [JITLink][LoongArch] Add label addition and subtraction relocations --- .../llvm/ExecutionEngine/JITLink/loongarch.h | 180 ++ .../ExecutionEngine/JITLink/ELF_loongarch.cpp | 24 +++ .../lib/ExecutionEngine/JITLink/loongarch.cpp | 12 ++ .../JITLink/LoongArch/ELF_reloc_addsub.s | 53 ++ 4 files changed, 269 insertions(+) create mode 100644 llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_reloc_addsub.s diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h index d6025edf7d110d..1d763e1255fc21 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h @@ -14,8 +14,10 @@ #define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H #include "TableManager.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/Support/LEB128.h" namespace llvm { namespace jitlink { @@ -226,6 +228,90 @@ enum EdgeKind_loongarch : Edge::Kind { /// Call36PCRel, + /// low 6 bits label addition + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup + (Target + Addend) & 0x3f) : int8 + /// + Add6, + + /// 8 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{1}Fixup + Addend) : int8 + /// + Add8, + + /// 16 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{2}Fixup + Addend) : int16 + /// + Add16, + + /// 32 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{4}Fixup + Addend) : int32 + /// + Add32, + + /// 64 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{8}Fixup + Addend) : int64 + /// + Add64, + + /// ULEB128 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{16}Fixup + Addend) : uleb128 + /// + AddUleb128, + + /// low 6 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - (Target + Addend) & 0x3f) : int8 + /// + Sub6, + + /// 8 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - Target - Addend) : int8 + /// + Sub8, + + /// 16 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{2}Fixup - Target - Addend) : int16 + /// + Sub16, + + /// 32 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{4}Fixup - Target - Addend) : int32 + /// + Sub32, + + /// 64 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{8}Fixup - Target - Addend) : int64 + /// + Sub64, + + /// ULEB128 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{16}Fixup - Target - Addend) : uleb128 + /// + SubUleb128, + /// Alignment requirement used by linker relaxation. /// /// Linker relaxation will use this to ensure all code sequences are properly @@ -369,6 +455,100 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E) { *(little32_t *)(FixupPtr + 4) = Jirl | Lo16; break; } + case Add6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value += ((TargetAddress + Addend) & 0x3f); +*FixupPtr = (*FixupPtr & 0xc0) | (static_cast(Value) & 0x3f); +break; + } + case Add8: { +int64_t Value = +TargetAddress + *(reinterpret_cast(FixupPtr)) + Addend; +*FixupPtr = static_cast(Value); +break; + } + case Add16: { +int64_t Value = +TargetAddress + support::endian::read16le(FixupPtr) + Addend; +*(little16_t *)FixupPtr = static_cast(Value); +break; + } + case Add32: { +int64_t Value = +TargetAddress + support::endian::read32le(FixupPtr) + Addend; +*(little32_t *)FixupPtr = static_cast(Value); +break; + } + case Add64: { +int64_t Value = +TargetAddress + support::endian::read64le(FixupPtr) + Addend; +*(little64_t *)FixupPtr = static_cast(Value); +break; + } + case AddUleb128: { +const uint32_t Maxcount = 1 + 64 / 7; +uint32_t Count; +const char *Error = nullptr; +uint64_t Orig = decodeULEB128((reinterpret_cast(FixupPtr)), + &Count, nullptr, &Error); + +if (Count > Maxcount || (Count == Maxcount && Error)) + return make_error( + "0x" + llvm::utohexstr(orc::ExecutorAddr(FixupAddress).getValue()) + + ": extra space for uleb128"); + +uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL; +encodeULEB128((Orig + TargetAddress + Addend) & Mask, + (reinterpret_cast(FixupPtr)), Count); +break; + } + case Sub6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value -= ((
[llvm-branch-commits] [llvm] [JITLink][LoongArch] Add label addition and subtraction relocations (PR #122262)
https://github.com/zhaoqi5 updated https://github.com/llvm/llvm-project/pull/122262 >From 4398bd99d87c58307e55798a3f6dde372b4d0cb6 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Fri, 27 Dec 2024 15:39:57 +0800 Subject: [PATCH 1/3] [JITLink][LoongArch] Add label addition and subtraction relocations --- .../llvm/ExecutionEngine/JITLink/loongarch.h | 180 ++ .../ExecutionEngine/JITLink/ELF_loongarch.cpp | 24 +++ .../lib/ExecutionEngine/JITLink/loongarch.cpp | 12 ++ .../JITLink/LoongArch/ELF_reloc_addsub.s | 53 ++ 4 files changed, 269 insertions(+) create mode 100644 llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_reloc_addsub.s diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h index d6025edf7d110d..1d763e1255fc21 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h @@ -14,8 +14,10 @@ #define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H #include "TableManager.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/Support/LEB128.h" namespace llvm { namespace jitlink { @@ -226,6 +228,90 @@ enum EdgeKind_loongarch : Edge::Kind { /// Call36PCRel, + /// low 6 bits label addition + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup + (Target + Addend) & 0x3f) : int8 + /// + Add6, + + /// 8 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{1}Fixup + Addend) : int8 + /// + Add8, + + /// 16 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{2}Fixup + Addend) : int16 + /// + Add16, + + /// 32 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{4}Fixup + Addend) : int32 + /// + Add32, + + /// 64 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{8}Fixup + Addend) : int64 + /// + Add64, + + /// ULEB128 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{16}Fixup + Addend) : uleb128 + /// + AddUleb128, + + /// low 6 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - (Target + Addend) & 0x3f) : int8 + /// + Sub6, + + /// 8 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - Target - Addend) : int8 + /// + Sub8, + + /// 16 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{2}Fixup - Target - Addend) : int16 + /// + Sub16, + + /// 32 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{4}Fixup - Target - Addend) : int32 + /// + Sub32, + + /// 64 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{8}Fixup - Target - Addend) : int64 + /// + Sub64, + + /// ULEB128 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{16}Fixup - Target - Addend) : uleb128 + /// + SubUleb128, + /// Alignment requirement used by linker relaxation. /// /// Linker relaxation will use this to ensure all code sequences are properly @@ -369,6 +455,100 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E) { *(little32_t *)(FixupPtr + 4) = Jirl | Lo16; break; } + case Add6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value += ((TargetAddress + Addend) & 0x3f); +*FixupPtr = (*FixupPtr & 0xc0) | (static_cast(Value) & 0x3f); +break; + } + case Add8: { +int64_t Value = +TargetAddress + *(reinterpret_cast(FixupPtr)) + Addend; +*FixupPtr = static_cast(Value); +break; + } + case Add16: { +int64_t Value = +TargetAddress + support::endian::read16le(FixupPtr) + Addend; +*(little16_t *)FixupPtr = static_cast(Value); +break; + } + case Add32: { +int64_t Value = +TargetAddress + support::endian::read32le(FixupPtr) + Addend; +*(little32_t *)FixupPtr = static_cast(Value); +break; + } + case Add64: { +int64_t Value = +TargetAddress + support::endian::read64le(FixupPtr) + Addend; +*(little64_t *)FixupPtr = static_cast(Value); +break; + } + case AddUleb128: { +const uint32_t Maxcount = 1 + 64 / 7; +uint32_t Count; +const char *Error = nullptr; +uint64_t Orig = decodeULEB128((reinterpret_cast(FixupPtr)), + &Count, nullptr, &Error); + +if (Count > Maxcount || (Count == Maxcount && Error)) + return make_error( + "0x" + llvm::utohexstr(orc::ExecutorAddr(FixupAddress).getValue()) + + ": extra space for uleb128"); + +uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL; +encodeULEB128((Orig + TargetAddress + Addend) & Mask, + (reinterpret_cast(FixupPtr)), Count); +break; + } + case Sub6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value -= ((
[llvm-branch-commits] [flang] [Flang] Optionally do not compile the runtime in-tree (PR #122336)
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/122336 >From dd3ac2e6d8d8d57cd639c25bea3b8d5c99a2f81e Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 9 Jan 2025 15:58:48 +0100 Subject: [PATCH 1/5] Introduce FLANG_INCLUDE_RUNTIME --- flang/CMakeLists.txt| 7 +++- flang/test/CMakeLists.txt | 6 +++- flang/test/Driver/ctofortran.f90| 1 + flang/test/Driver/exec.f90 | 1 + flang/test/Runtime/no-cpp-dep.c | 2 +- flang/test/lit.cfg.py | 5 ++- flang/test/lit.site.cfg.py.in | 1 + flang/tools/f18/CMakeLists.txt | 4 +-- flang/unittests/CMakeLists.txt | 6 ++-- flang/unittests/Evaluate/CMakeLists.txt | 46 ++--- 10 files changed, 50 insertions(+), 29 deletions(-) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 68947eaa9c9bd7..69e963a43d0b97 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -233,6 +233,9 @@ else() include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR}) endif() +option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON) +pythonize_bool(FLANG_INCLUDE_RUNTIME) + set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") mark_as_advanced(FLANG_TOOLS_INSTALL_DIR) @@ -473,7 +476,9 @@ if (FLANG_CUF_RUNTIME) find_package(CUDAToolkit REQUIRED) endif() -add_subdirectory(runtime) +if (FLANG_INCLUDE_RUNTIME) + add_subdirectory(runtime) +endif () if (LLVM_INCLUDE_EXAMPLES) add_subdirectory(examples) diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt index cab214c2ef4c8c..e398e0786147aa 100644 --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS llvm-objdump llvm-readobj split-file - FortranRuntime FortranDecimal ) + +if (FLANG_INCLUDE_RUNTIME) + list(APPEND FLANG_TEST_DEPENDS FortranRuntime) +endif () + if (LLVM_ENABLE_PLUGINS AND NOT WIN32) list(APPEND FLANG_TEST_DEPENDS Bye) endif() diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90 index 78eac32133b18e..10c7adaccc9588 100644 --- a/flang/test/Driver/ctofortran.f90 +++ b/flang/test/Driver/ctofortran.f90 @@ -1,4 +1,5 @@ ! UNSUPPORTED: system-windows +! REQUIRES: flang-rt ! RUN: split-file %s %t ! RUN: chmod +x %t/runtest.sh ! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s diff --git a/flang/test/Driver/exec.f90 b/flang/test/Driver/exec.f90 index fd174005ddf62a..9ca91ee24011c9 100644 --- a/flang/test/Driver/exec.f90 +++ b/flang/test/Driver/exec.f90 @@ -1,4 +1,5 @@ ! UNSUPPORTED: system-windows +! REQUIRES: flang-rt ! Verify that flang can correctly build executables. ! RUN: %flang %s -o %t diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c index b1a5fa004014cc..7303ce63fdec41 100644 --- a/flang/test/Runtime/no-cpp-dep.c +++ b/flang/test/Runtime/no-cpp-dep.c @@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on the C++ runtime library. It tries to link this simple file against libFortranRuntime.a with a C compiler. -REQUIRES: c-compiler +REQUIRES: c-compiler, flang-rt RUN: %if system-aix %{ export OBJECT_MODE=64 %} RUN: %cc -std=c99 %s -I%include %libruntime -lm \ diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index c452b6d231c89f..78378bf5f413e8 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -163,10 +163,13 @@ ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal") ) +if config.flang_include_runtime: + config.available_features.add("flang-rt") + # Define some variables to help us test that the flang runtime doesn't depend on # the C++ runtime libraries. For this we need a C compiler. If for some reason # we don't have one, we can just disable the test. -if config.cc: +if config.flang_include_runtime and config.cc: libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a") include = os.path.join(config.flang_src_dir, "include") diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index d1a0ac763cf8a0..19f9330f93ae14 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -32,6 +32,7 @@ else: config.openmp_module_dir = None config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@" config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@" +config.flang_include_runtime = @FLANG_INCLUDE_RUNTIME@ import lit.llvm lit.llvm.initialize(lit_config, config) diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index 4362fcf0537616..022c346aabdbde 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -72,7 +72,7 @@ if (NOT CMAKE_CROSSCOMPILING) set(depends ${FLANG_
[llvm-branch-commits] [nfc][ubsan] Add local-bounds test (PR #122415)
https://github.com/thurstond edited https://github.com/llvm/llvm-project/pull/122415 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)
topperc wrote: Do you know what caused the X86 changes? I don't see any uses of getRegPressureSetLimit in the X86 directory. https://github.com/llvm/llvm-project/pull/118787 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [nfc][ubsan] Add local-bounds test (PR #122415)
https://github.com/thurstond approved this pull request. https://github.com/llvm/llvm-project/pull/122415 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)
@@ -1198,6 +1198,14 @@ define <32 x i8> @out_v32i8(ptr%px, ptr%py, ptr%pmask) nounwind { ; CHECK-BASELINE-NEXT:movq %rdx, %r8 ; CHECK-BASELINE-NEXT:movq %rsi, %r9 ; CHECK-BASELINE-NEXT:movq %rdi, %r11 +; CHECK-BASELINE-NEXT:movzbl 19(%rdx), %eax topperc wrote: Is this a regression? https://github.com/llvm/llvm-project/pull/118787 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)
https://github.com/spavloff updated https://github.com/llvm/llvm-project/pull/122313 >From b6b73416ef8bdb10113c1311bfa88ea16847b365 Mon Sep 17 00:00:00 2001 From: Serge Pavlov Date: Mon, 16 Dec 2024 19:21:33 +0700 Subject: [PATCH] [IR] Add FPOperation intrinsic property The previous implementation of constrained functions passed floating-point parameters as metadata function arguments. They represented a part of the function signature and were mandatory. Passing such parameters to irrelevant functions were not possible. The new implementation passes the floating-point parameters in operand bundles. This is an optional call component and technically such bundles can be attached to any call. To keep IR cleaner, some mechanism is required to avoid setting FP bundles on irrelevant functions. This change implements such mechanism by introducing a new function attribute, "fpoperation". It should be set for built-in functions that operate floating-point values in some way and thus the parameters, represented by FP bundles, make sense for them. Verifier can check if FP bundles are attached to call to such functions only. --- clang/test/CodeGen/builtin-sqrt.c | 2 +- clang/test/CodeGen/libcalls.c | 2 +- .../cl20-device-side-enqueue-attributes.cl | 2 +- llvm/docs/LangRef.rst | 3 +++ llvm/include/llvm/Bitcode/LLVMBitCodes.h | 1 + llvm/include/llvm/IR/Attributes.td | 3 +++ llvm/include/llvm/IR/Intrinsics.td | 18 +++--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 2 ++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 2 ++ llvm/lib/IR/Verifier.cpp | 8 llvm/lib/Transforms/Utils/CodeExtractor.cpp| 1 + .../AArch64/replace-with-veclib-armpl.ll | 2 +- .../replace-with-veclib-sleef-scalable.ll | 2 +- .../AArch64/replace-with-veclib-sleef.ll | 2 +- .../AMDGPU/amdgpu-simplify-libcall-rootn.ll| 2 +- .../replace-with-veclib-sleef-scalable.ll | 2 +- llvm/test/Feature/intrinsics.ll| 5 +++-- llvm/test/Linker/drop-attribute.ll | 2 +- llvm/test/Transforms/Attributor/nofree.ll | 6 +++--- llvm/test/Transforms/Attributor/nosync.ll | 2 +- llvm/test/Transforms/Attributor/willreturn.ll | 6 +++--- llvm/test/Verifier/fp-intrinsics.ll| 18 ++ .../utils/TableGen/Basic/CodeGenIntrinsics.cpp | 2 ++ llvm/utils/TableGen/Basic/CodeGenIntrinsics.h | 3 +++ llvm/utils/TableGen/IntrinsicEmitter.cpp | 7 +-- 25 files changed, 78 insertions(+), 27 deletions(-) diff --git a/clang/test/CodeGen/builtin-sqrt.c b/clang/test/CodeGen/builtin-sqrt.c index 2313a68d2d0e20..c2056556f61566 100644 --- a/clang/test/CodeGen/builtin-sqrt.c +++ b/clang/test/CodeGen/builtin-sqrt.c @@ -11,5 +11,5 @@ float foo(float X) { // HAS_ERRNO-NOT: attributes [[ATTR]] = {{{.*}} memory(none) // NO_ERRNO: declare float @llvm.sqrt.f32(float) [[ATTR:#[0-9]+]] -// NO_ERRNO: attributes [[ATTR]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } +// NO_ERRNO: attributes [[ATTR]] = { fpoperation nocallback nofree nosync nounwind speculatable willreturn memory(none) } diff --git a/clang/test/CodeGen/libcalls.c b/clang/test/CodeGen/libcalls.c index 1e4b06e34aaf92..49a80f2d6ee051 100644 --- a/clang/test/CodeGen/libcalls.c +++ b/clang/test/CodeGen/libcalls.c @@ -124,4 +124,4 @@ void test_builtins(double d, float f, long double ld) { } // CHECK-YES: attributes [[NUW]] = { nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+cx8,+x87" } -// CHECK-NO-DAG: attributes [[NUW_RNI]] = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } +// CHECK-NO-DAG: attributes [[NUW_RNI]] = { fpoperation nocallback nofree nosync nounwind speculatable willreturn memory(none) } diff --git a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl index 31f1aa60780b9e..233acd3f0bd729 100644 --- a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl +++ b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue-attributes.cl @@ -165,7 +165,7 @@ kernel void device_side_enqueue(global float *a, global float *b, int i) { // SPIR32: attributes #[[ATTR0]] = { convergent noinline norecurse nounwind optnone "denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" } // SPIR32: attributes #[[ATTR1:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } // SPIR32: attributes #[[ATTR2]] = { convergent noinline nounwind optnone "denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" "stack-protector-buffer-size"="8" } -// SPIR32: attributes #[[ATTR3:[0-9]+]] = { nocallback nofree nosync nounwind speculatable willreturn me
[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)
https://github.com/spavloff edited https://github.com/llvm/llvm-project/pull/122313 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for IfStmt (PR #113111)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113111 >From 3ea6383e2142889550f37389dfaaee81e5ae7d9c Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 15:15:03 +0900 Subject: [PATCH 1/4] [Coverage][Single] Enable Branch coverage for IfStmt --- clang/lib/CodeGen/CGStmt.cpp | 31 +++- clang/lib/CodeGen/CodeGenPGO.cpp | 12 --- clang/lib/CodeGen/CoverageMappingGen.cpp | 21 +++ .../CoverageMapping/single-byte-counters.cpp | 36 ++- 4 files changed, 38 insertions(+), 62 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index dbc1ce9bf993cd..c511e5f4f4213a 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -840,8 +840,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // If the skipped block has no labels in it, just emit the executed block. // This avoids emitting dead code and simplifies the CFG substantially. if (S.isConstexpr() || !ContainsLabel(Skipped)) { - if (CondConstant) -incrementProfileCounter(&S); + incrementProfileCounter(!CondConstant, &S, true); if (Executed) { RunCleanupsScope ExecutedScope(*this); EmitStmt(Executed); @@ -851,14 +850,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { } } + auto HasSkip = getIsCounterPair(&S); + // Otherwise, the condition did not fold, or we couldn't elide it. Just emit // the conditional branch. llvm::BasicBlock *ThenBlock = createBasicBlock("if.then"); llvm::BasicBlock *ContBlock = createBasicBlock("if.end"); - llvm::BasicBlock *ElseBlock = ContBlock; - if (Else) -ElseBlock = createBasicBlock("if.else"); - + llvm::BasicBlock *ElseBlock = + (Else || HasSkip.second ? createBasicBlock("if.else") : ContBlock); // Prefer the PGO based weights over the likelihood attribute. // When the build isn't optimized the metadata isn't used, so don't generate // it. @@ -891,10 +890,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // Emit the 'then' code. EmitBlock(ThenBlock); - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(S.getThen()); - else -incrementProfileCounter(&S); + incrementProfileCounter(false, &S); { RunCleanupsScope ThenScope(*this); EmitStmt(S.getThen()); @@ -908,9 +904,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { auto NL = ApplyDebugLocation::CreateEmpty(*this); EmitBlock(ElseBlock); } -// When single byte coverage mode is enabled, add a counter to else block. -if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(Else); +// Add a counter to else block unless it has CounterExpr. +if (HasSkip.second) + incrementProfileCounter(true, &S); { RunCleanupsScope ElseScope(*this); EmitStmt(Else); @@ -920,15 +916,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { auto NL = ApplyDebugLocation::CreateEmpty(*this); EmitBranch(ContBlock); } + } else if (HasSkip.second) { +EmitBlock(ElseBlock); +incrementProfileCounter(true, &S); +EmitBranch(ContBlock); } // Emit the continuation block for code after the if. EmitBlock(ContBlock, true); - - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(&S); } bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression, diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 0f2090da47a374..f6b9b5c82952c4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -366,18 +366,6 @@ struct MapRegionCounters : public RecursiveASTVisitor { if (Hash.getHashVersion() == PGO_HASH_V1) return Base::TraverseIfStmt(If); -// When single byte coverage mode is enabled, add a counter to then and -// else. -bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; -for (Stmt *CS : If->children()) { - if (!CS || NoSingleByteCoverage) -continue; - if (CS == If->getThen()) -CounterMap[If->getThen()] = NextCounter++; - else if (CS == If->getElse()) -CounterMap[If->getElse()] = NextCounter++; -} - // Otherwise, keep track of which branch we're in while traversing. VisitStmt(If); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a331d5bc68286b..6c6aecb9994c6b 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -2050,12 +2050,7 @@ struct CounterCoverageMappingBuilder extendRegion(S->getCond()); Counter ParentCount = getRegion().getCounter(); -auto [ThenCount, ElseCount] = -(llvm::EnableSingleByteCoverage - ? std::make_pair(getRegionCounter(S->getThen())
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for CondOp (PR #113110)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113110 >From 744c5b634de08f9214c82d6fcfde7179bc4edfb0 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 14:46:07 +0900 Subject: [PATCH 1/5] [Coverage][Single] Enable Branch coverage for CondOp --- clang/lib/CodeGen/CGExpr.cpp | 6 +-- clang/lib/CodeGen/CGExprAgg.cpp | 14 +-- clang/lib/CodeGen/CGExprComplex.cpp | 15 +--- clang/lib/CodeGen/CGExprScalar.cpp| 37 +++ clang/lib/CodeGen/CodeGenFunction.cpp | 3 +- clang/lib/CodeGen/CodeGenPGO.cpp | 8 clang/lib/CodeGen/CoverageMappingGen.cpp | 16 ++-- .../CoverageMapping/single-byte-counters.cpp | 11 +++--- 8 files changed, 25 insertions(+), 85 deletions(-) diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index cc85f05ad9f70c..67e3a1de17e679 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -5137,8 +5137,7 @@ std::optional HandleConditionalOperatorLValueSimpleCase( if (!CGF.ContainsLabel(Dead)) { // If the true case is live, we need to track its region. - if (CondExprBool) -CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(!CondExprBool, E, true); CGF.markStmtMaybeUsed(Dead); // If a throw expression we emit it and return an undefined lvalue // because it can't be used. @@ -5177,7 +5176,7 @@ ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF, // Any temporaries created here are conditional. CGF.EmitBlock(Info.lhsBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); eval.begin(CGF); Info.LHS = BranchGenFunc(CGF, E->getTrueExpr()); eval.end(CGF); @@ -5188,6 +5187,7 @@ ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF, // Any temporaries created here are conditional. CGF.EmitBlock(Info.rhsBlock); + CGF.incrementProfileCounter(true, E); eval.begin(CGF); Info.RHS = BranchGenFunc(CGF, E->getFalseExpr()); eval.end(CGF); diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 2ad6587089f101..0c778ef185532f 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -36,10 +36,6 @@ using namespace CodeGen; //Aggregate Expression Emitter //===--===// -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - namespace { class AggExprEmitter : public StmtVisitor { CodeGenFunction &CGF; @@ -1293,10 +1289,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(LHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getTrueExpr()); - else -CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); Visit(E->getTrueExpr()); eval.end(CGF); @@ -1311,8 +1304,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getFalseExpr()); + CGF.incrementProfileCounter(true, E); Visit(E->getFalseExpr()); eval.end(CGF); @@ -1321,8 +1313,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { E->getType()); CGF.EmitBlock(ContBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E); } void AggExprEmitter::VisitChooseExpr(const ChooseExpr *CE) { diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index fef26e7b4ccdbd..bcece9431de764 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -28,10 +28,6 @@ using namespace CodeGen; //Complex Expression Emitter //===--===// -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - typedef CodeGenFunction::ComplexPairTy ComplexPairTy; /// Return the complex type that we are meant to emit. @@ -1381,11 +1377,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(LHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getTrueExpr()); - else -CGF.incrementProfileCounter(E); - + CGF.incrementProfileCounter(false, E); ComplexPairTy LHS = Visit(E->getTrueExpr()); LHSBlock = Builder.GetInsertBlock(); CGF.EmitBranch(ContBlock); @@ -1393,13 +1385,10 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - if (llvm::EnableSingleByteCoverage) -CGF.incrementProfileCounter(E->getFalseExpr()); + CGF.incrementProfileCounter(true, E); Com
[llvm-branch-commits] [clang] [compiler-rt] [llvm] [Coverage][Single] Enable Branch coverage for IfStmt (PR #113111)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/113111 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/116052 >From 9cf700147b302de9bb9fc5ec1453aa660ecb8411 Mon Sep 17 00:00:00 2001 From: Sergio Afonso Date: Tue, 12 Nov 2024 10:49:28 + Subject: [PATCH] [MLIR][OpenMP] LLVM IR translation of host_eval This patch adds support for processing the `host_eval` clause of `omp.target` to populate default and runtime kernel launch attributes. Specifically, these related to the `num_teams`, `thread_limit` and `num_threads` clauses attached to operations nested inside of `omp.target`. As a result, the `thread_limit` clause of `omp.target` is also supported. The implementation of `initTargetDefaultAttrs()` is intended to reflect clang's own processing of multiple constructs and clauses in order to define a default number of teams and threads to be used as kernel attributes and to populate global variables in the target device module. One side effect of this change is that it is no longer possible to translate to LLVM IR target device MLIR modules unless they have a supported target triple. This is because the local `getGridValue()` function in the `OpenMPIRBuilder` only works for certain architectures, and it is called whenever the maximum number of threads has not been explicitly defined. This limitation also matches clang. Evaluating the collapsed loop trip count of target SPMD kernels remains unsupported. --- .../Integration/OpenMP/target-filtering.f90 | 2 +- .../Lower/OpenMP/function-filtering-2.f90 | 6 +- .../Lower/OpenMP/function-filtering-3.f90 | 6 +- .../test/Lower/OpenMP/function-filtering.f90 | 6 +- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 262 -- ...target-byref-bycopy-generation-device.mlir | 4 +- .../omptarget-constant-alloca-raise.mlir | 4 +- ...arget-constant-indexing-device-region.mlir | 4 +- mlir/test/Target/LLVMIR/omptarget-debug.mlir | 2 +- .../omptarget-declare-target-llvm-device.mlir | 2 +- .../LLVMIR/omptarget-parallel-llvm.mlir | 4 +- .../LLVMIR/omptarget-region-device-llvm.mlir | 6 +- .../LLVMIR/omptarget-target-inside-task.mlir | 4 +- ...ptarget-threadprivate-device-lowering.mlir | 4 +- .../LLVMIR/openmp-target-launch-device.mlir | 45 +++ .../LLVMIR/openmp-target-launch-host.mlir | 31 +++ .../openmp-target-use-device-nested.mlir | 4 +- .../LLVMIR/openmp-task-target-device.mlir | 2 +- mlir/test/Target/LLVMIR/openmp-todo.mlir | 27 +- 19 files changed, 362 insertions(+), 63 deletions(-) create mode 100644 mlir/test/Target/LLVMIR/openmp-target-launch-device.mlir create mode 100644 mlir/test/Target/LLVMIR/openmp-target-launch-host.mlir diff --git a/flang/test/Integration/OpenMP/target-filtering.f90 b/flang/test/Integration/OpenMP/target-filtering.f90 index d1ab1b47e580d4..699c1040d91f9c 100644 --- a/flang/test/Integration/OpenMP/target-filtering.f90 +++ b/flang/test/Integration/OpenMP/target-filtering.f90 @@ -7,7 +7,7 @@ !===--===! !RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefixes HOST,ALL -!RUN: %flang_fc1 -emit-llvm -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefixes DEVICE,ALL +!RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-llvm -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefixes DEVICE,ALL !HOST: define {{.*}}@{{.*}}before{{.*}}( !DEVICE-NOT: define {{.*}}@before{{.*}}( diff --git a/flang/test/Lower/OpenMP/function-filtering-2.f90 b/flang/test/Lower/OpenMP/function-filtering-2.f90 index 0c02aa223820e7..a2c5e29cfdcbf6 100644 --- a/flang/test/Lower/OpenMP/function-filtering-2.f90 +++ b/flang/test/Lower/OpenMP/function-filtering-2.f90 @@ -1,9 +1,9 @@ ! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-HOST %s ! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s -! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-DEVICE %s -! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s +! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-DEVICE %s +! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s ! RUN: bbc -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s -! RUN: bbc -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s +! RUN: bbc -target amdgcn-amd-amdhsa -fopenmp -fopenmp-vers
[llvm-branch-commits] [flang] [mlir] [Flang][OpenMP] Lowering of host-evaluated clauses (PR #116219)
@@ -55,6 +55,149 @@ static void genOMPDispatch(lower::AbstractConverter &converter, const ConstructQueue &queue, ConstructQueue::const_iterator item); +static void processHostEvalClauses(lower::AbstractConverter &converter, + semantics::SemanticsContext &semaCtx, + lower::StatementContext &stmtCtx, + lower::pft::Evaluation &eval, + mlir::Location loc); + +namespace { +/// Structure holding information that is needed to pass host-evaluated +/// information to later lowering stages. +class HostEvalInfo { +public: + // Allow this function access to private members in order to initialize them. + friend void ::processHostEvalClauses(lower::AbstractConverter &, + semantics::SemanticsContext &, + lower::StatementContext &, + lower::pft::Evaluation &, + mlir::Location); + + /// Fill \c vars with values stored in \c ops. + /// + /// The order in which values are stored matches the one expected by \see + /// bindOperands(). + void collectValues(llvm::SmallVectorImpl &vars) const { +vars.append(ops.loopLowerBounds); +vars.append(ops.loopUpperBounds); +vars.append(ops.loopSteps); + +if (ops.numTeamsLower) + vars.push_back(ops.numTeamsLower); + +if (ops.numTeamsUpper) + vars.push_back(ops.numTeamsUpper); + +if (ops.numThreads) + vars.push_back(ops.numThreads); + +if (ops.threadLimit) + vars.push_back(ops.threadLimit); + } + + /// Update \c ops, replacing all values with the corresponding block argument + /// in \c args. + /// + /// The order in which values are stored in \c args is the same as the one + /// used by \see collectValues(). + void bindOperands(llvm::ArrayRef args) { +assert(args.size() == + ops.loopLowerBounds.size() + ops.loopUpperBounds.size() + + ops.loopSteps.size() + (ops.numTeamsLower ? 1 : 0) + + (ops.numTeamsUpper ? 1 : 0) + (ops.numThreads ? 1 : 0) + + (ops.threadLimit ? 1 : 0) && + "invalid block argument list"); +int argIndex = 0; +for (size_t i = 0; i < ops.loopLowerBounds.size(); ++i) + ops.loopLowerBounds[i] = args[argIndex++]; + +for (size_t i = 0; i < ops.loopUpperBounds.size(); ++i) + ops.loopUpperBounds[i] = args[argIndex++]; + +for (size_t i = 0; i < ops.loopSteps.size(); ++i) + ops.loopSteps[i] = args[argIndex++]; + +if (ops.numTeamsLower) + ops.numTeamsLower = args[argIndex++]; + +if (ops.numTeamsUpper) + ops.numTeamsUpper = args[argIndex++]; + +if (ops.numThreads) + ops.numThreads = args[argIndex++]; + +if (ops.threadLimit) + ops.threadLimit = args[argIndex++]; + } + + /// Update \p clauseOps and \p ivOut with the corresponding host-evaluated + /// values and Fortran symbols, respectively, if they have already been + /// initialized but not yet applied. + /// + /// \returns whether an update was performed. If not, these clauses were not + /// evaluated in the host device. + bool apply(mlir::omp::LoopNestOperands &clauseOps, + llvm::SmallVectorImpl &ivOut) { +if (iv.empty() || loopNestApplied) { + loopNestApplied = true; + return false; +} + +loopNestApplied = true; +clauseOps.loopLowerBounds = ops.loopLowerBounds; +clauseOps.loopUpperBounds = ops.loopUpperBounds; +clauseOps.loopSteps = ops.loopSteps; +ivOut.append(iv); +return true; + } + + /// Update \p clauseOps with the corresponding host-evaluated values if they + /// have already been initialized but not yet applied. + /// + /// \returns whether an update was performed. If not, these clauses were not + /// evaluated in the host device. + bool apply(mlir::omp::ParallelOperands &clauseOps) { +if (!ops.numThreads || parallelApplied) { + parallelApplied = true; + return false; +} + +parallelApplied = true; +clauseOps.numThreads = ops.numThreads; +return true; + } + + /// Update \p clauseOps with the corresponding host-evaluated values if they + /// have already been initialized. + /// + /// \returns whether an update was performed. If not, these clauses were not + /// evaluated in the host device. + bool apply(mlir::omp::TeamsOperands &clauseOps) { agozillon wrote: Likely a dumb question, but is there a reason why we don't check this function has already "applied"? https://github.com/llvm/llvm-project/pull/116219 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [AsmPrinter][TargetLowering]Place a hot jump table into a hot-suffixed section (PR #122215)
https://github.com/mingmingl-llvm updated https://github.com/llvm/llvm-project/pull/122215 >From a2a6f9f5a6f7647f85a230241bf3aa39c4bd65d9 Mon Sep 17 00:00:00 2001 From: mingmingl Date: Wed, 8 Jan 2025 16:53:45 -0800 Subject: [PATCH 1/2] [AsmPrinter][TargetLowering]Place a hot jump table into a hot-suffixed section --- llvm/include/llvm/CodeGen/AsmPrinter.h| 8 +- .../CodeGen/TargetLoweringObjectFileImpl.h| 3 + .../llvm/Target/TargetLoweringObjectFile.h| 5 + llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp| 102 +- .../CodeGen/TargetLoweringObjectFileImpl.cpp | 28 +++-- llvm/lib/CodeGen/TargetPassConfig.cpp | 8 +- llvm/lib/Target/TargetLoweringObjectFile.cpp | 6 ++ llvm/test/CodeGen/X86/jump-table-partition.ll | 8 +- 8 files changed, 130 insertions(+), 38 deletions(-) diff --git a/llvm/include/llvm/CodeGen/AsmPrinter.h b/llvm/include/llvm/CodeGen/AsmPrinter.h index c9a88d7b1c015c..9249d5adf3f6f7 100644 --- a/llvm/include/llvm/CodeGen/AsmPrinter.h +++ b/llvm/include/llvm/CodeGen/AsmPrinter.h @@ -453,6 +453,10 @@ class AsmPrinter : public MachineFunctionPass { /// function to the current output stream. virtual void emitJumpTableInfo(); + virtual void emitJumpTables(const std::vector &JumpTableIndices, + MCSection *JumpTableSection, bool JTInDiffSection, + const MachineJumpTableInfo &MJTI); + /// Emit the specified global variable to the .s file. virtual void emitGlobalVariable(const GlobalVariable *GV); @@ -892,10 +896,10 @@ class AsmPrinter : public MachineFunctionPass { // Internal Implementation Details //===--===// - void emitJumpTableEntry(const MachineJumpTableInfo *MJTI, + void emitJumpTableEntry(const MachineJumpTableInfo &MJTI, const MachineBasicBlock *MBB, unsigned uid) const; - void emitJumpTableSizesSection(const MachineJumpTableInfo *MJTI, + void emitJumpTableSizesSection(const MachineJumpTableInfo &MJTI, const Function &F) const; void emitLLVMUsedList(const ConstantArray *InitList); diff --git a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index a2a9e5d499e527..3d48d380fcb245 100644 --- a/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -74,6 +74,9 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile { MCSection *getSectionForJumpTable(const Function &F, const TargetMachine &TM) const override; + MCSection * + getSectionForJumpTable(const Function &F, const TargetMachine &TM, + const MachineJumpTableEntry *JTE) const override; MCSection *getSectionForLSDA(const Function &F, const MCSymbol &FnSym, const TargetMachine &TM) const override; diff --git a/llvm/include/llvm/Target/TargetLoweringObjectFile.h b/llvm/include/llvm/Target/TargetLoweringObjectFile.h index 4864ba843f4886..577adc458fcbf1 100644 --- a/llvm/include/llvm/Target/TargetLoweringObjectFile.h +++ b/llvm/include/llvm/Target/TargetLoweringObjectFile.h @@ -27,6 +27,7 @@ class Function; class GlobalObject; class GlobalValue; class MachineBasicBlock; +class MachineJumpTableEntry; class MachineModuleInfo; class Mangler; class MCContext; @@ -132,6 +133,10 @@ class TargetLoweringObjectFile : public MCObjectFileInfo { virtual MCSection *getSectionForJumpTable(const Function &F, const TargetMachine &TM) const; + virtual MCSection * + getSectionForJumpTable(const Function &F, const TargetMachine &TM, + const MachineJumpTableEntry *JTE) const; + virtual MCSection *getSectionForLSDA(const Function &, const MCSymbol &, const TargetMachine &) const { return LSDASection; diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index d34fe0e86c7495..b575cd7d993c39 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -168,6 +168,11 @@ static cl::opt BBAddrMapSkipEmitBBEntries( "unnecessary for some PGOAnalysisMap features."), cl::Hidden, cl::init(false)); +static cl::opt +EmitStaticDataHotnessSuffix("emit-static-data-hotness-suffix", cl::Hidden, +cl::init(false), cl::ZeroOrMore, +cl::desc("Emit static data hotness suffix")); + static cl::opt EmitJumpTableSizesSection( "emit-jump-table-sizes-section", cl::desc("Emit a section containing jump table addresses and sizes"), @@ -2861,7 +2866,6 @@ void AsmPrinter::emitConstantPool() { // Print assembly representations of the jump tables
[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode (PR #116051)
https://github.com/skatrak edited https://github.com/llvm/llvm-project/pull/116051 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [OMPIRBuilder] Propagate attributes to outlined target regions (PR #117875)
https://github.com/abidh approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/117875 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [Flang][OpenMP] Lowering of host-evaluated clauses (PR #116219)
https://github.com/agozillon approved this pull request. LGTM, thank you for the patch @skatrak :-) https://github.com/llvm/llvm-project/pull/116219 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)
@@ -3453,6 +3453,17 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions +struct OmpClause; +struct OmpClauseList; + +struct OmpDirectiveSpecification { + TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification); + std::tuple>> + t; + CharBlock source; +}; kiranchandramohan wrote: This needs a comment. Is this strictly part of context-selectors? https://github.com/llvm/llvm-project/pull/121815 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)
@@ -3453,6 +3453,17 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions +struct OmpClause; +struct OmpClauseList; + +struct OmpDirectiveSpecification { + TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification); + std::tuple>> + t; + CharBlock source; +}; kparzysz wrote: No, this is the type of the argument to `when` and `otherwise` directives. I can move this to PR121817 (the PR with the actual clauses). https://github.com/llvm/llvm-project/pull/121815 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)
https://github.com/kparzysz edited https://github.com/llvm/llvm-project/pull/121815 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage] Make additional counters available for BranchRegion. NFC. (PR #120930)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/120930 >From 5e460594c8a2550c38c759b2e6f1c5dc4152f820 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Thu, 17 Oct 2024 22:15:12 +0900 Subject: [PATCH 01/10] [Coverage] Make additional counters available for BranchRegion. NFC. `getBranchCounterPair()` allocates an additional Counter to SkipPath in `SingleByteCoverage`. `IsCounterEqual()` calculates the comparison with rewinding counter replacements. `NumRegionCounters` is updated to take additional counters in account. `incrementProfileCounter()` has a few additiona arguments. - `UseSkipPath=true`, to specify setting counters for SkipPath. It assumes `UseSkipPath=false` is used together. - `UseBoth` may be specified for marking another path. It introduces the same effect as issueing `markStmtAsUsed(!SkipPath, S)`. `llvm-cov` discovers counters in `FalseCount` to allocate `MaxCounterID` for empty profile data. --- clang/lib/CodeGen/CodeGenFunction.h | 8 - clang/lib/CodeGen/CodeGenPGO.cpp | 31 +-- clang/lib/CodeGen/CodeGenPGO.h| 1 + clang/lib/CodeGen/CoverageMappingGen.cpp | 31 ++- .../ProfileData/Coverage/CoverageMapping.cpp | 4 +++ 5 files changed, 65 insertions(+), 10 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 89ac3b342d0a7c..cb1192bf6e11fe 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1629,11 +1629,17 @@ class CodeGenFunction : public CodeGenTypeCache { /// Increment the profiler's counter for the given statement by \p StepV. /// If \p StepV is null, the default increment is 1. void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { +incrementProfileCounter(false, S, false, StepV); + } + + void incrementProfileCounter(bool UseSkipPath, const Stmt *S, + bool UseBoth = false, + llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr() && !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) && !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) { auto AL = ApplyDebugLocation::CreateArtificial(*this); - PGO.emitCounterSetOrIncrement(Builder, S, StepV); + PGO.emitCounterSetOrIncrement(Builder, S, UseSkipPath, UseBoth, StepV); } PGO.setCurrentStmt(S); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 069469e3de856b..aefd53e12088b4 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -1138,6 +1138,19 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { if (CoverageMapping.empty()) return; + // Scan max(FalseCnt) and update NumRegionCounters. + unsigned MaxNumCounters = NumRegionCounters; + for (const auto [_, V] : *RegionCounterMap) { +auto HasCounters = V.getIsCounterPair(); +assert((!HasCounters.first || +MaxNumCounters > (V.first & CounterPair::Mask)) && + "TrueCnt should not be reassigned"); +if (HasCounters.second) + MaxNumCounters = + std::max(MaxNumCounters, (V.second & CounterPair::Mask) + 1); + } + NumRegionCounters = MaxNumCounters; + CGM.getCoverageMapping()->addFunctionMappingRecord( FuncNameVar, FuncName, FunctionHash, CoverageMapping); } @@ -1193,11 +1206,25 @@ std::pair CodeGenPGO::getIsCounterPair(const Stmt *S) const { } void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseSkipPath, bool UseBoth, llvm::Value *StepV) { - if (!RegionCounterMap || !Builder.GetInsertBlock()) + if (!RegionCounterMap) return; - unsigned Counter = (*RegionCounterMap)[S].first; + unsigned Counter; + auto &TheMap = (*RegionCounterMap)[S]; + auto IsCounter = TheMap.getIsCounterPair(); + if (!UseSkipPath) { +assert(IsCounter.first); +Counter = (TheMap.first & CounterPair::Mask); + } else { +if (!IsCounter.second) + return; +Counter = (TheMap.second & CounterPair::Mask); + } + + if (!Builder.GetInsertBlock()) +return; // Make sure that pointer to global is passed in with zero addrspace // This is relevant during GPU profiling diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h index 83f35785e5327d..8b769dd88d7f1e 100644 --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/lib/CodeGen/CodeGenPGO.h @@ -112,6 +112,7 @@ class CodeGenPGO { public: std::pair getIsCounterPair(const Stmt *S) const; void emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseFalsePath, bool UseBoth, llvm::Value *StepV); void emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder, const Expr *S,
[llvm-branch-commits] [clang] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=flang-rt (PR #110217)
https://github.com/h-vetinari edited https://github.com/llvm/llvm-project/pull/110217 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for SwitchStmt (PR #113112)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113112 >From ec05cc37e1177f06c9a44a1e39dadc9306cc5c68 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Mon, 21 Oct 2024 08:09:31 +0900 Subject: [PATCH 1/4] [Coverage][Single] Enable Branch coverage for SwitchStmt --- clang/lib/CodeGen/CGStmt.cpp | 12 ++ clang/lib/CodeGen/CoverageMappingGen.cpp | 22 ++- .../CoverageMapping/single-byte-counters.cpp | 13 ++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index dbc1ce9bf993cd..80fe5cf183de16 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -2259,6 +2259,18 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) { ConditionScope.ForceCleanup(); + // Close the last case (or DefaultBlock). + EmitBranch(SwitchExit.getBlock()); + + // Insert a False Counter if SwitchStmt doesn't have DefaultStmt. + if (getIsCounterPair(S.getCond()).second) { +auto *ImplicitDefaultBlock = createBasicBlock("sw.false"); +EmitBlock(ImplicitDefaultBlock); +incrementProfileCounter(true, S.getCond()); +Builder.CreateBr(SwitchInsn->getDefaultDest()); +SwitchInsn->setDefaultDest(ImplicitDefaultBlock); + } + // Emit continuation. EmitBlock(SwitchExit.getBlock(), true); incrementProfileCounter(&S); diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index a331d5bc68286b..c5fdf23299e4e9 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -958,6 +958,14 @@ struct CounterCoverageMappingBuilder return {ExecCnt, SkipCnt}; } + Counter getSwitchImplicitDefaultCounter(const Stmt *Cond, Counter ParentCount, + Counter CaseCountSum) { +return ( +llvm::EnableSingleByteCoverage +? Counter::getCounter(CounterMap[Cond].second = NextCounterNum++) +: subtractCounters(ParentCount, CaseCountSum)); + } + bool IsCounterEqual(Counter OutCount, Counter ParentCount) { if (OutCount == ParentCount) return true; @@ -1885,7 +1893,7 @@ struct CounterCoverageMappingBuilder propagateCounts(Counter::getZero(), Body); BreakContinue BC = BreakContinueStack.pop_back_val(); -if (!BreakContinueStack.empty() && !llvm::EnableSingleByteCoverage) +if (!BreakContinueStack.empty()) BreakContinueStack.back().ContinueCount = addCounters( BreakContinueStack.back().ContinueCount, BC.ContinueCount); @@ -1900,11 +1908,6 @@ struct CounterCoverageMappingBuilder MostRecentLocation = getStart(S); handleFileExit(ExitLoc); -// When single byte coverage mode is enabled, do not create branch region by -// early returning. -if (llvm::EnableSingleByteCoverage) - return; - // Create a Branch Region around each Case. Subtract the case's // counter from the Parent counter to track the "False" branch count. Counter CaseCountSum; @@ -1920,7 +1923,8 @@ struct CounterCoverageMappingBuilder // the hidden branch, which will be added later by the CodeGen. This region // will be associated with the switch statement's condition. if (!HasDefaultCase) { - Counter DefaultCount = subtractCounters(ParentCount, CaseCountSum); + Counter DefaultCount = getSwitchImplicitDefaultCounter( + S->getCond(), ParentCount, CaseCountSum); createBranchRegion(S->getCond(), Counter::getZero(), DefaultCount); } } @@ -1929,9 +1933,7 @@ struct CounterCoverageMappingBuilder extendRegion(S); SourceMappingRegion &Parent = getRegion(); -Counter Count = llvm::EnableSingleByteCoverage -? getRegionCounter(S) -: addCounters(Parent.getCounter(), getRegionCounter(S)); +Counter Count = addCounters(Parent.getCounter(), getRegionCounter(S)); // Reuse the existing region if it starts at our label. This is typical of // the first case in a switch. diff --git a/clang/test/CoverageMapping/single-byte-counters.cpp b/clang/test/CoverageMapping/single-byte-counters.cpp index d20b695bc2636a..464fa370d86f09 100644 --- a/clang/test/CoverageMapping/single-byte-counters.cpp +++ b/clang/test/CoverageMapping/single-byte-counters.cpp @@ -34,19 +34,22 @@ int testIfElseReturn(int x) { // CHECK-NEXT: File 0, [[@LINE]]:29 -> [[@LINE+9]] } // CHECK-NEXT: testSwitch -int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+17]]:2 = [[C30:#0]] +int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+20]]:2 = [[C30:#0]] int result; switch (x) { -// CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+10]]:15 = 0 - case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:10 = [[C31:#2]] +// CHECK-NEXT: Gap,File
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/116052 >From 9035b53e097a46642c7d10df543d93c5a818dead Mon Sep 17 00:00:00 2001 From: Sergio Afonso Date: Tue, 12 Nov 2024 10:49:28 + Subject: [PATCH] [MLIR][OpenMP] LLVM IR translation of host_eval This patch adds support for processing the `host_eval` clause of `omp.target` to populate default and runtime kernel launch attributes. Specifically, these related to the `num_teams`, `thread_limit` and `num_threads` clauses attached to operations nested inside of `omp.target`. As a result, the `thread_limit` clause of `omp.target` is also supported. The implementation of `initTargetDefaultAttrs()` is intended to reflect clang's own processing of multiple constructs and clauses in order to define a default number of teams and threads to be used as kernel attributes and to populate global variables in the target device module. One side effect of this change is that it is no longer possible to translate to LLVM IR target device MLIR modules unless they have a supported target triple. This is because the local `getGridValue()` function in the `OpenMPIRBuilder` only works for certain architectures, and it is called whenever the maximum number of threads has not been explicitly defined. This limitation also matches clang. Evaluating the collapsed loop trip count of target SPMD kernels remains unsupported. --- .../Integration/OpenMP/target-filtering.f90 | 2 +- .../Lower/OpenMP/function-filtering-2.f90 | 6 +- .../Lower/OpenMP/function-filtering-3.f90 | 6 +- .../test/Lower/OpenMP/function-filtering.f90 | 6 +- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 262 -- ...target-byref-bycopy-generation-device.mlir | 4 +- .../omptarget-constant-alloca-raise.mlir | 4 +- ...arget-constant-indexing-device-region.mlir | 4 +- mlir/test/Target/LLVMIR/omptarget-debug.mlir | 2 +- .../omptarget-declare-target-llvm-device.mlir | 2 +- .../LLVMIR/omptarget-parallel-llvm.mlir | 4 +- .../LLVMIR/omptarget-region-device-llvm.mlir | 6 +- .../LLVMIR/omptarget-target-inside-task.mlir | 4 +- .../LLVMIR/openmp-target-launch-device.mlir | 45 +++ .../LLVMIR/openmp-target-launch-host.mlir | 31 +++ .../openmp-target-use-device-nested.mlir | 4 +- .../LLVMIR/openmp-task-target-device.mlir | 2 +- mlir/test/Target/LLVMIR/openmp-todo.mlir | 27 +- 18 files changed, 360 insertions(+), 61 deletions(-) create mode 100644 mlir/test/Target/LLVMIR/openmp-target-launch-device.mlir create mode 100644 mlir/test/Target/LLVMIR/openmp-target-launch-host.mlir diff --git a/flang/test/Integration/OpenMP/target-filtering.f90 b/flang/test/Integration/OpenMP/target-filtering.f90 index d1ab1b47e580d4..699c1040d91f9c 100644 --- a/flang/test/Integration/OpenMP/target-filtering.f90 +++ b/flang/test/Integration/OpenMP/target-filtering.f90 @@ -7,7 +7,7 @@ !===--===! !RUN: %flang_fc1 -emit-llvm -fopenmp %s -o - | FileCheck %s --check-prefixes HOST,ALL -!RUN: %flang_fc1 -emit-llvm -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefixes DEVICE,ALL +!RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -emit-llvm -fopenmp -fopenmp-is-target-device %s -o - | FileCheck %s --check-prefixes DEVICE,ALL !HOST: define {{.*}}@{{.*}}before{{.*}}( !DEVICE-NOT: define {{.*}}@before{{.*}}( diff --git a/flang/test/Lower/OpenMP/function-filtering-2.f90 b/flang/test/Lower/OpenMP/function-filtering-2.f90 index 0c02aa223820e7..a2c5e29cfdcbf6 100644 --- a/flang/test/Lower/OpenMP/function-filtering-2.f90 +++ b/flang/test/Lower/OpenMP/function-filtering-2.f90 @@ -1,9 +1,9 @@ ! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-HOST %s ! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s -! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-DEVICE %s -! RUN: %flang_fc1 -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s +! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -flang-experimental-hlfir -emit-llvm %s -o - | FileCheck --check-prefixes=LLVM,LLVM-DEVICE %s +! RUN: %flang_fc1 -triple amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefix=MLIR %s ! RUN: bbc -fopenmp -fopenmp-version=52 -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-HOST,MLIR-ALL %s -! RUN: bbc -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - | FileCheck --check-prefixes=MLIR-DEVICE,MLIR-ALL %s +! RUN: bbc -target amdgcn-amd-amdhsa -fopenmp -fopenmp-version=52 -fopenmp-is-target-device -emit-hlfir %s -o - |
[llvm-branch-commits] [clang] [compiler-rt] [llvm] [Coverage][Single] Enable Branch coverage for SwitchStmt (PR #113112)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/113112 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [compiler-rt] [llvm] [Coverage][Single] Enable Branch coverage for CondOp (PR #113110)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/113110 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)
https://github.com/HerrCai0907 created https://github.com/llvm/llvm-project/pull/122296 None >From 7958e403f1a7bbba383f8a4ed5c1dbdbadba18d4 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Thu, 9 Jan 2025 23:15:18 +0800 Subject: [PATCH] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max --- .../readability/UseStdMinMaxCheck.cpp | 35 --- clang-tools-extra/docs/ReleaseNotes.rst | 4 +++ .../checkers/readability/use-std-min-max.cpp | 21 +++ 3 files changed, 48 insertions(+), 12 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp index 179173502a8d01..6f6b8a853a91e0 100644 --- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp @@ -79,6 +79,27 @@ static QualType getNonTemplateAlias(QualType QT) { return QT; } +static QualType getReplacementCastType(const Expr *CondLhs, const Expr *CondRhs, + QualType ComparedType) { + QualType LhsType = CondLhs->getType(); + QualType RhsType = CondRhs->getType(); + QualType LhsCanonicalType = + LhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType(); + QualType RhsCanonicalType = + RhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType(); + QualType GlobalImplicitCastType; + if (LhsCanonicalType != RhsCanonicalType) { +if (llvm::isa(CondRhs)) { + GlobalImplicitCastType = getNonTemplateAlias(LhsType); +} else if (llvm::isa(CondLhs)) { + GlobalImplicitCastType = getNonTemplateAlias(RhsType); +} else { + GlobalImplicitCastType = getNonTemplateAlias(ComparedType); +} + } + return GlobalImplicitCastType; +} + static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs, const Expr *AssignLhs, const SourceManager &Source, @@ -92,18 +113,8 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs, const llvm::StringRef AssignLhsStr = Lexer::getSourceText( Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO); - QualType GlobalImplicitCastType; - QualType LhsType = CondLhs->getType() - .getCanonicalType() - .getNonReferenceType() - .getUnqualifiedType(); - QualType RhsType = CondRhs->getType() - .getCanonicalType() - .getNonReferenceType() - .getUnqualifiedType(); - if (LhsType != RhsType) { -GlobalImplicitCastType = getNonTemplateAlias(BO->getLHS()->getType()); - } + QualType GlobalImplicitCastType = + getReplacementCastType(CondLhs, CondRhs, BO->getLHS()->getType()); return (AssignLhsStr + " = " + FunctionName + (!GlobalImplicitCastType.isNull() diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 94e15639c4a92e..fd523da8dc5a1b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -364,6 +364,10 @@ Changes in existing checks ` check to validate ``namespace`` aliases. +- Improved :doc:`readability-use-std-min-max + ` check to use correct template + type in ``std::min`` and ``std::max`` when operand is integer literal. + Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp index 9c0e2eabda348d..35ade8a7c6d37e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp @@ -252,3 +252,24 @@ void testVectorSizeType() { if (value < v.size()) value = v.size(); } + +namespace gh121676 { + +void useLeft() { + using U16 = unsigned short; + U16 I = 0; + // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::max` instead of `<` [readability-use-std-min-max] + // CHECK-FIXES: I = std::max(I, 16U); + if (I < 16U) +I = 16U; +} +void useRight() { + using U16 = unsigned short; + U16 I = 0; + // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `<` [readability-use-std-min-max] + // CHECK-FIXES: I = std::min(16U, I); + if (16U < I) +I = 16U; +} + +} // namespace gh121676 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)
HerrCai0907 wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/122296?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#122296** https://app.graphite.dev/github/pr/llvm/llvm-project/122296?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/122296?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#122288** https://app.graphite.dev/github/pr/llvm/llvm-project/122288?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/122296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)
https://github.com/HerrCai0907 edited https://github.com/llvm/llvm-project/pull/122296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)
https://github.com/HerrCai0907 edited https://github.com/llvm/llvm-project/pull/122296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Congcong Cai (HerrCai0907) Changes When comparing with integer literal, integer promote will happen to promote type which has less bit width than int to int or unsigned int. It will let auto-fix provide correct but out of expected fix. e.g. ```c++ short a; if ( a > 10 ) a = 10; ``` will be ```c++ short a; if ( (int)a > 10 ) a = (short)10; ``` which will be fixed as ```c++ short a; a = std::max(a, 10); ``` but actually it can be ```c++ short a; a = std::max (a, 10); ``` --- Full diff: https://github.com/llvm/llvm-project/pull/122296.diff 3 Files Affected: - (modified) clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp (+23-12) - (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) - (modified) clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp (+21) ``diff diff --git a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp index 179173502a8d01..6f6b8a853a91e0 100644 --- a/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/UseStdMinMaxCheck.cpp @@ -79,6 +79,27 @@ static QualType getNonTemplateAlias(QualType QT) { return QT; } +static QualType getReplacementCastType(const Expr *CondLhs, const Expr *CondRhs, + QualType ComparedType) { + QualType LhsType = CondLhs->getType(); + QualType RhsType = CondRhs->getType(); + QualType LhsCanonicalType = + LhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType(); + QualType RhsCanonicalType = + RhsType.getCanonicalType().getNonReferenceType().getUnqualifiedType(); + QualType GlobalImplicitCastType; + if (LhsCanonicalType != RhsCanonicalType) { +if (llvm::isa(CondRhs)) { + GlobalImplicitCastType = getNonTemplateAlias(LhsType); +} else if (llvm::isa(CondLhs)) { + GlobalImplicitCastType = getNonTemplateAlias(RhsType); +} else { + GlobalImplicitCastType = getNonTemplateAlias(ComparedType); +} + } + return GlobalImplicitCastType; +} + static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs, const Expr *AssignLhs, const SourceManager &Source, @@ -92,18 +113,8 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs, const llvm::StringRef AssignLhsStr = Lexer::getSourceText( Source.getExpansionRange(AssignLhs->getSourceRange()), Source, LO); - QualType GlobalImplicitCastType; - QualType LhsType = CondLhs->getType() - .getCanonicalType() - .getNonReferenceType() - .getUnqualifiedType(); - QualType RhsType = CondRhs->getType() - .getCanonicalType() - .getNonReferenceType() - .getUnqualifiedType(); - if (LhsType != RhsType) { -GlobalImplicitCastType = getNonTemplateAlias(BO->getLHS()->getType()); - } + QualType GlobalImplicitCastType = + getReplacementCastType(CondLhs, CondRhs, BO->getLHS()->getType()); return (AssignLhsStr + " = " + FunctionName + (!GlobalImplicitCastType.isNull() diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 94e15639c4a92e..fd523da8dc5a1b 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -364,6 +364,10 @@ Changes in existing checks ` check to validate ``namespace`` aliases. +- Improved :doc:`readability-use-std-min-max + ` check to use correct template + type in ``std::min`` and ``std::max`` when operand is integer literal. + Removed checks ^^ diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp index 9c0e2eabda348d..35ade8a7c6d37e 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/readability/use-std-min-max.cpp @@ -252,3 +252,24 @@ void testVectorSizeType() { if (value < v.size()) value = v.size(); } + +namespace gh121676 { + +void useLeft() { + using U16 = unsigned short; + U16 I = 0; + // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::max` instead of `<` [readability-use-std-min-max] + // CHECK-FIXES: I = std::max(I, 16U); + if (I < 16U) +I = 16U; +} +void useRight() { + using U16 = unsigned short; + U16 I = 0; + // CHECK-MESSAGES: :[[@LINE+2]]:3: warning: use `std::min` instead of `<` [readability-use-std-min-max] + // CHECK-FIXES: I = std::min(16U, I); + if (16U < I) +I = 16U; +} + +} // namespace gh121676 `` https://github.com/llvm/llvm-project/pull/122296 __
[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/121815 >From 215c7e6133bf07d005ac7483b8faf797e319a1fa Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 12 Dec 2024 15:26:26 -0600 Subject: [PATCH 1/2] [flang][OpenMP] Parsing context selectors for METADIRECTIVE This is just adding parsers for context selectors. There are no tests because there is no way to execute these parsers yet. --- flang/include/flang/Parser/characters.h | 2 + flang/include/flang/Parser/dump-parse-tree.h | 14 ++ flang/include/flang/Parser/parse-tree.h | 136 +++ flang/lib/Parser/openmp-parsers.cpp | 78 +++ flang/lib/Parser/token-parsers.h | 4 + flang/lib/Parser/unparse.cpp | 38 ++ flang/lib/Semantics/check-omp-structure.cpp | 8 ++ flang/lib/Semantics/check-omp-structure.h| 3 + flang/lib/Semantics/resolve-directives.cpp | 6 + 9 files changed, 289 insertions(+) diff --git a/flang/include/flang/Parser/characters.h b/flang/include/flang/Parser/characters.h index df188d674b9eeb..dbdc058c44995a 100644 --- a/flang/include/flang/Parser/characters.h +++ b/flang/include/flang/Parser/characters.h @@ -180,6 +180,8 @@ inline constexpr bool IsValidFortranTokenCharacter(char ch) { case '>': case '[': case ']': + case '{': // Used in OpenMP context selector specification + case '}': // return true; default: return IsLegalIdentifierStart(ch) || IsDecimalDigit(ch); diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index 3331520922bc63..a61d7973dd5c36 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -476,6 +476,20 @@ class ParseTreeDumper { NODE(parser, NullInit) NODE(parser, ObjectDecl) NODE(parser, OldParameterStmt) + NODE(parser, OmpDirectiveSpecification) + NODE(parser, OmpTraitPropertyName) + NODE(parser, OmpTraitScore) + NODE(parser, OmpTraitPropertyExtension) + NODE(OmpTraitPropertyExtension, ExtensionValue) + NODE(parser, OmpTraitProperty) + NODE(parser, OmpTraitSelectorName) + NODE_ENUM(OmpTraitSelectorName, Value) + NODE(parser, OmpTraitSelector) + NODE(OmpTraitSelector, Properties) + NODE(parser, OmpTraitSetSelectorName) + NODE_ENUM(OmpTraitSetSelectorName, Value) + NODE(parser, OmpTraitSetSelector) + NODE(parser, OmpContextSelectorSpecification) NODE(parser, OmpMapper) NODE(parser, OmpMapType) NODE_ENUM(OmpMapType, Value) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 941d70d3876291..697bddfaf16150 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3453,6 +3453,17 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions +struct OmpClause; +struct OmpClauseList; + +struct OmpDirectiveSpecification { + TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification); + std::tuple>> + t; + CharBlock source; +}; + // 2.1 Directives or clauses may accept a list or extended-list. // A list item is a variable, array section or common block name (enclosed // in slashes). An extended list item is a list item or a procedure Name. @@ -3474,6 +3485,128 @@ WRAPPER_CLASS(OmpObjectList, std::list); #define MODIFIERS() std::optional> +inline namespace traits { +// trait-property-name -> +//identifier | string-literal +struct OmpTraitPropertyName { + WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string); +}; + +// trait-score -> +//SCORE(non-negative-const-integer-expression) +struct OmpTraitScore { + WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr); +}; + +// trait-property-extension -> +//trait-property-name (trait-property-value, ...) +// trait-property-value -> +//trait-property-name | +//scalar-integer-expression | +//trait-property-extension +// +// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different +// version (but equivalent) that doesn't have ambiguities. +// The ambiguity is in +// trait-property: +// trait-property-name <- (a) +// trait-property-clause +// trait-property-expression<- (b) +// trait-property-extension <- this conflicts with (a) and (b) +// trait-property-extension: +// trait-property-name <- conflict with (a) +// identifier(trait-property-extension[, trait-property-extension[, ...]]) +// constant integer expression <- conflict with (b) +// +struct OmpTraitPropertyExtension { + TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension); + struct ExtensionValue { +UNION_CLASS_BOILERPLATE(ExtensionValue); +std::variant> +u; + }; + using ExtensionList = std::list; + std::tuple t; +}; + +// trait-property -> +//trait-property-name | OmpClause | +//trait-property-expression | trait-property-extension +// trait-property-expression -> +//
[llvm-branch-commits] [clang-tools-extra] [clang-tidy] use correct template type in ``std::min`` and ``std::max`` when operand is integer literal for readability-use-std-min-max (PR #122296)
https://github.com/HerrCai0907 ready_for_review https://github.com/llvm/llvm-project/pull/122296 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [flang] [lld] [llvm] [Flang] LLVM_ENABLE_RUNTIMES=flang-rt (PR #110217)
h-vetinari wrote: This file has spurious line-ending changes (though the culprit is in https://github.com/llvm/llvm-project/pull/110298 AFAICT https://github.com/llvm/llvm-project/pull/110217 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` (PR #113113)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113113 >From 16e2bb8b73bcde1c2618bb358a905a9f463c1217 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 16:24:26 +0900 Subject: [PATCH 1/3] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` --- clang/lib/CodeGen/CGExprScalar.cpp | 83 +++- clang/lib/CodeGen/CGStmt.cpp | 4 -- clang/lib/CodeGen/CodeGenFunction.cpp| 43 ++-- clang/lib/CodeGen/CoverageMappingGen.cpp | 6 -- 4 files changed, 104 insertions(+), 32 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 11d4ec8a267605..83962ba96aa484 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -4918,6 +4918,9 @@ Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) { } Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { + auto HasLHSSkip = CGF.getIsCounterPair(E); + auto HasRHSSkip = CGF.getIsCounterPair(E->getRHS()); + // Perform vector logical and on comparisons with zero vectors. if (E->getType()->isVectorType()) { CGF.incrementProfileCounter(E); @@ -4964,11 +4967,17 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CodeGenFunction::isInstrumentedCondition(E->getRHS())) { CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond); llvm::BasicBlock *FBlock = CGF.createBasicBlock("land.end"); +llvm::BasicBlock *RHSSkip = +(HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : FBlock); llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); -Builder.CreateCondBr(RHSCond, RHSBlockCnt, FBlock); +Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSSkip); CGF.EmitBlock(RHSBlockCnt); -CGF.incrementProfileCounter(E->getRHS()); +CGF.incrementProfileCounter(false, E->getRHS()); CGF.EmitBranch(FBlock); +if (HasRHSSkip.second) { + CGF.EmitBlock(RHSSkip); + CGF.incrementProfileCounter(true, E->getRHS()); +} CGF.EmitBlock(FBlock); } @@ -4997,12 +5006,21 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { llvm::BasicBlock *ContBlock = CGF.createBasicBlock("land.end"); llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("land.rhs"); + llvm::BasicBlock *LHSFalseBlock = + (HasLHSSkip.second ? CGF.createBasicBlock("land.lhsskip") : ContBlock); + CodeGenFunction::ConditionalEvaluation eval(CGF); // Branch on the LHS first. If it is false, go to the failure (cont) block. - CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, ContBlock, + CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, LHSFalseBlock, CGF.getProfileCount(E->getRHS())); + if (HasLHSSkip.second) { +CGF.EmitBlock(LHSFalseBlock); +CGF.incrementProfileCounter(true, E); +CGF.EmitBranch(ContBlock); + } + // Any edges into the ContBlock are now from an (indeterminate number of) // edges from this first condition. All of these values will be false. Start // setting up the PHI node in the Cont Block for this. @@ -5014,7 +5032,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); eval.end(CGF); @@ -5024,15 +5042,24 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { // If we're generating for profiling or coverage, generate a branch on the // RHS to a block that increments the RHS true counter needed to track branch // condition coverage. + llvm::BasicBlock *ContIncoming = RHSBlock; if (InstrumentRegions && CodeGenFunction::isInstrumentedCondition(E->getRHS())) { CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond); llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); -Builder.CreateCondBr(RHSCond, RHSBlockCnt, ContBlock); +llvm::BasicBlock *RHSBlockSkip = +(HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : ContBlock); +Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSBlockSkip); CGF.EmitBlock(RHSBlockCnt); -CGF.incrementProfileCounter(E->getRHS()); +CGF.incrementProfileCounter(false, E->getRHS()); CGF.EmitBranch(ContBlock); PN->addIncoming(RHSCond, RHSBlockCnt); +if (HasRHSSkip.second) { + CGF.EmitBlock(RHSBlockSkip); + CGF.incrementProfileCounter(true, E->getRHS()); + CGF.EmitBranch(ContBlock); + ContIncoming = RHSBlockSkip; +} } // Emit an unconditional branch from this block to ContBlock. @@ -5042,7 +5069,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CGF.EmitBlock(ContBlock); } // Insert an entry into the phi node for the edge with the value of RHSCond.
[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode (PR #116051)
https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/116051 >From 47a64959c79fbdec4e6108ddad8f2b2317ce0b76 Mon Sep 17 00:00:00 2001 From: Sergio Afonso Date: Wed, 27 Nov 2024 11:33:01 + Subject: [PATCH] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode This patch introduces a `TargetKernelRuntimeAttrs` structure to hold host-evaluated `num_teams`, `thread_limit`, `num_threads` and trip count values passed to the runtime kernel offloading call. Additionally, kernel type information is used to influence target device code generation and the `IsSPMD` flag is replaced by `ExecFlags`, which provide more granularity. --- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 5 +- .../llvm/Frontend/OpenMP/OMPIRBuilder.h | 38 ++- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 129 ++--- .../Frontend/OpenMPIRBuilderTest.cpp | 263 +- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 12 +- 5 files changed, 386 insertions(+), 61 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp index 654a13d75ec810..1e2e693d91de72 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -20,6 +20,7 @@ #include "clang/AST/StmtVisitor.h" #include "clang/Basic/Cuda.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h" #include "llvm/Frontend/OpenMP/OMPGridValues.h" using namespace clang; @@ -745,7 +746,9 @@ void CGOpenMPRuntimeGPU::emitKernelInit(const OMPExecutableDirective &D, CodeGenFunction &CGF, EntryFunctionState &EST, bool IsSPMD) { llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs Attrs; - Attrs.IsSPMD = IsSPMD; + Attrs.ExecFlags = + IsSPMD ? llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD + : llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC; computeMinAndMaxThreadsAndTeams(D, CGF, Attrs); CGBuilderTy &Bld = CGF.Builder; diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index 8ca3bc08b5ad49..7eceec3d8cf8f5 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -1389,9 +1389,6 @@ class OpenMPIRBuilder { /// Supporting functions for Reductions CodeGen. private: - /// Emit the llvm.used metadata. - void emitUsed(StringRef Name, std::vector &List); - /// Get the id of the current thread on the GPU. Value *getGPUThreadID(); @@ -2013,6 +2010,13 @@ class OpenMPIRBuilder { /// Value. GlobalValue *createGlobalFlag(unsigned Value, StringRef Name); + /// Emit the llvm.used metadata. + void emitUsed(StringRef Name, ArrayRef List); + + /// Emit the kernel execution mode. + GlobalVariable *emitKernelExecutionMode(StringRef KernelName, + omp::OMPTgtExecModeFlags Mode); + /// Generate control flow and cleanup for cancellation. /// /// \param CancelFlag Flag indicating if the cancellation is performed. @@ -2233,13 +2237,34 @@ class OpenMPIRBuilder { /// time. The number of max values will be 1 except for the case where /// ompx_bare is set. struct TargetKernelDefaultAttrs { -bool IsSPMD = false; +omp::OMPTgtExecModeFlags ExecFlags = +omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC; SmallVector MaxTeams = {-1}; int32_t MinTeams = 1; SmallVector MaxThreads = {-1}; int32_t MinThreads = 1; }; + /// Container to pass LLVM IR runtime values or constants related to the + /// number of teams and threads with which the kernel must be launched, as + /// well as the trip count of the loop, if it is an SPMD or Generic-SPMD + /// kernel. These must be defined in the host prior to the call to the kernel + /// launch OpenMP RTL function. + struct TargetKernelRuntimeAttrs { +SmallVector MaxTeams = {nullptr}; +Value *MinTeams = nullptr; +SmallVector TargetThreadLimit = {nullptr}; +SmallVector TeamsThreadLimit = {nullptr}; + +/// 'parallel' construct 'num_threads' clause value, if present and it is an +/// SPMD kernel. +Value *MaxThreads = nullptr; + +/// Total number of iterations of the SPMD or Generic-SPMD kernel or null if +/// it is a generic kernel. +Value *LoopTripCount = nullptr; + }; + /// Data structure that contains the needed information to construct the /// kernel args vector. struct TargetKernelArgs { @@ -2971,7 +2996,9 @@ class OpenMPIRBuilder { /// \param CodeGenIP The insertion point where the call to the outlined /// function should be emitted. /// \param EntryInfo The entry information about the function. - /// \param DefaultAttrs Structure containing the default numbers of threads + /// \param DefaultAttrs Structure containing the default attributes, i
[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode (PR #116051)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 45c6667a70aa16409d0cc24df8f88168c883c51d 76b2b9f55e73a533e2a6aa0c98ebb1509e2d7dbd --extensions h,cpp -- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp `` View the diff from clang-format here. ``diff diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index 25c5dee037..7eceec3d8c 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -2237,7 +2237,8 @@ public: /// time. The number of max values will be 1 except for the case where /// ompx_bare is set. struct TargetKernelDefaultAttrs { -omp::OMPTgtExecModeFlags ExecFlags = omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC; +omp::OMPTgtExecModeFlags ExecFlags = +omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC; SmallVector MaxTeams = {-1}; int32_t MinTeams = 1; SmallVector MaxThreads = {-1}; `` https://github.com/llvm/llvm-project/pull/116051 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [Multilib] Custom flags processing for library selection (PR #110659)
https://github.com/vhscampos updated https://github.com/llvm/llvm-project/pull/110659 >From 2fe418964fff9e03861650afb89a81ac80f1413d Mon Sep 17 00:00:00 2001 From: Victor Campos Date: Thu, 26 Sep 2024 14:44:33 +0100 Subject: [PATCH 1/6] [Multilib] Custom flags processing for library selection Select library variants in the multilib system using the flags passed following the '-fmultilib-flag=' format. Multilib flags that were not passed in the command-line have their default value fed into the library selection mechanism. A warning is shown if the flag's value name is invalid. If the wrong name is close enough to any valid one, according to edit distance, the closest valid value name is suggested. Details about this change can be found in this thread: https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058 --- clang/include/clang/Driver/Driver.h | 2 +- clang/include/clang/Driver/Multilib.h | 11 +- clang/include/clang/Driver/ToolChain.h| 7 + clang/lib/Driver/Driver.cpp | 141 ++ clang/lib/Driver/Multilib.cpp | 136 - clang/lib/Driver/ToolChains/BareMetal.cpp | 22 ++- clang/lib/Driver/ToolChains/BareMetal.h | 5 + .../baremetal-multilib-custom-flags.yaml | 79 ++ 8 files changed, 328 insertions(+), 75 deletions(-) create mode 100644 clang/test/Driver/baremetal-multilib-custom-flags.yaml diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index c23d037e725bb9..80be9261ec40f7 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -466,7 +466,7 @@ class Driver { /// ArgList. llvm::opt::InputArgList ParseArgStrings(ArrayRef Args, bool UseDriverMode, - bool &ContainsError); + bool &ContainsError) const; /// BuildInputs - Construct the list of inputs and their types from /// the given arguments. diff --git a/clang/include/clang/Driver/Multilib.h b/clang/include/clang/Driver/Multilib.h index 1dab45c062aeec..36bdfdb6157b0b 100644 --- a/clang/include/clang/Driver/Multilib.h +++ b/clang/include/clang/Driver/Multilib.h @@ -163,9 +163,18 @@ class MultilibSet { const_iterator begin() const { return Multilibs.begin(); } const_iterator end() const { return Multilibs.end(); } + /// Process custom flags from \p Flags and returns an expanded flags list and + /// a list of extra compilation arguments. + /// Returns a pair where: + /// - first: the new flags list including custom flags after processing. + /// - second: the extra compilation arguments to be fed to the driver. + std::pair> + processCustomFlags(const Driver &D, const Multilib::flags_list &Flags) const; + /// Select compatible variants, \returns false if none are compatible bool select(const Driver &D, const Multilib::flags_list &Flags, - llvm::SmallVectorImpl &) const; + llvm::SmallVectorImpl &, + llvm::SmallVector * = nullptr) const; unsigned size() const { return Multilibs.size(); } diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 5347e29be91439..25f51b7de3e9f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -686,6 +686,13 @@ class ToolChain { /// Add warning options that need to be passed to cc1 for this target. virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const; + // Get the list of extra driver arguments strings requested by the multilib + // configuration. + virtual SmallVector + getMultilibDriverArgsStr(llvm::opt::ArgList &Args) const { +return {}; + }; + // GetRuntimeLibType - Determine the runtime library type to use with the // given compilation arguments. virtual RuntimeLibType diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index fb73b62cf2daed..761876b9fcc53b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -262,7 +262,7 @@ void Driver::setDriverMode(StringRef Value) { } InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings, - bool UseDriverMode, bool &ContainsError) { + bool UseDriverMode, bool &ContainsError) const { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); ContainsError = false; @@ -1272,8 +1272,8 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { bool HasConfigFileTail = !ContainsError && CfgOptionsTail; // All arguments, from both config file and command line. - InputArgList Args = - HasConfigFileHead ? std::move(*CfgOptionsHead) : std::move(*CLOptions); + auto UArgs = std::make_unique(HasConfigFileHead ? std::move(*CfgOptionsHead) : std::move(*CLOptions)); + InputArgList &Args =
[llvm-branch-commits] [llvm] [JITLink][LoongArch] Add label addition and subtraction relocations (PR #122262)
https://github.com/zhaoqi5 created https://github.com/llvm/llvm-project/pull/122262 None >From 92a79bed9a8404b57630cac07713166f179eb686 Mon Sep 17 00:00:00 2001 From: Qi Zhao Date: Fri, 27 Dec 2024 15:39:57 +0800 Subject: [PATCH] [JITLink][LoongArch] Add label addition and subtraction relocations --- .../llvm/ExecutionEngine/JITLink/loongarch.h | 180 ++ .../ExecutionEngine/JITLink/ELF_loongarch.cpp | 24 +++ .../lib/ExecutionEngine/JITLink/loongarch.cpp | 12 ++ .../JITLink/LoongArch/ELF_reloc_addsub.s | 53 ++ 4 files changed, 269 insertions(+) create mode 100644 llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_reloc_addsub.s diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h index d6025edf7d110d..1d763e1255fc21 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h @@ -14,8 +14,10 @@ #define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H #include "TableManager.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/Support/LEB128.h" namespace llvm { namespace jitlink { @@ -226,6 +228,90 @@ enum EdgeKind_loongarch : Edge::Kind { /// Call36PCRel, + /// low 6 bits label addition + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup + (Target + Addend) & 0x3f) : int8 + /// + Add6, + + /// 8 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{1}Fixup + Addend) : int8 + /// + Add8, + + /// 16 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{2}Fixup + Addend) : int16 + /// + Add16, + + /// 32 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{4}Fixup + Addend) : int32 + /// + Add32, + + /// 64 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{8}Fixup + Addend) : int64 + /// + Add64, + + /// ULEB128 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{16}Fixup + Addend) : uleb128 + /// + AddUleb128, + + /// low 6 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - (Target + Addend) & 0x3f) : int8 + /// + Sub6, + + /// 8 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - Target - Addend) : int8 + /// + Sub8, + + /// 16 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{2}Fixup - Target - Addend) : int16 + /// + Sub16, + + /// 32 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{4}Fixup - Target - Addend) : int32 + /// + Sub32, + + /// 64 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{8}Fixup - Target - Addend) : int64 + /// + Sub64, + + /// ULEB128 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{16}Fixup - Target - Addend) : uleb128 + /// + SubUleb128, + /// Alignment requirement used by linker relaxation. /// /// Linker relaxation will use this to ensure all code sequences are properly @@ -369,6 +455,100 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E) { *(little32_t *)(FixupPtr + 4) = Jirl | Lo16; break; } + case Add6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value += ((TargetAddress + Addend) & 0x3f); +*FixupPtr = (*FixupPtr & 0xc0) | (static_cast(Value) & 0x3f); +break; + } + case Add8: { +int64_t Value = +TargetAddress + *(reinterpret_cast(FixupPtr)) + Addend; +*FixupPtr = static_cast(Value); +break; + } + case Add16: { +int64_t Value = +TargetAddress + support::endian::read16le(FixupPtr) + Addend; +*(little16_t *)FixupPtr = static_cast(Value); +break; + } + case Add32: { +int64_t Value = +TargetAddress + support::endian::read32le(FixupPtr) + Addend; +*(little32_t *)FixupPtr = static_cast(Value); +break; + } + case Add64: { +int64_t Value = +TargetAddress + support::endian::read64le(FixupPtr) + Addend; +*(little64_t *)FixupPtr = static_cast(Value); +break; + } + case AddUleb128: { +const uint32_t Maxcount = 1 + 64 / 7; +uint32_t Count; +const char *Error = nullptr; +uint64_t Orig = decodeULEB128((reinterpret_cast(FixupPtr)), + &Count, nullptr, &Error); + +if (Count > Maxcount || (Count == Maxcount && Error)) + return make_error( + "0x" + llvm::utohexstr(orc::ExecutorAddr(FixupAddress).getValue()) + + ": extra space for uleb128"); + +uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL; +encodeULEB128((Orig + TargetAddress + Addend) & Mask, + (reinterpret_cast(FixupPtr)), Count); +break; + } + case Sub6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value -=
[llvm-branch-commits] [llvm] [JITLink][LoongArch] Add label addition and subtraction relocations (PR #122262)
llvmbot wrote: @llvm/pr-subscribers-backend-loongarch Author: ZhaoQi (zhaoqi5) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/122262.diff 4 Files Affected: - (modified) llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h (+180) - (modified) llvm/lib/ExecutionEngine/JITLink/ELF_loongarch.cpp (+24) - (modified) llvm/lib/ExecutionEngine/JITLink/loongarch.cpp (+12) - (added) llvm/test/ExecutionEngine/JITLink/LoongArch/ELF_reloc_addsub.s (+53) ``diff diff --git a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h index d6025edf7d110d..1d763e1255fc21 100644 --- a/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h +++ b/llvm/include/llvm/ExecutionEngine/JITLink/loongarch.h @@ -14,8 +14,10 @@ #define LLVM_EXECUTIONENGINE_JITLINK_LOONGARCH_H #include "TableManager.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ExecutionEngine/JITLink/JITLink.h" #include "llvm/ExecutionEngine/Orc/Shared/MemoryFlags.h" +#include "llvm/Support/LEB128.h" namespace llvm { namespace jitlink { @@ -226,6 +228,90 @@ enum EdgeKind_loongarch : Edge::Kind { /// Call36PCRel, + /// low 6 bits label addition + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup + (Target + Addend) & 0x3f) : int8 + /// + Add6, + + /// 8 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{1}Fixup + Addend) : int8 + /// + Add8, + + /// 16 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{2}Fixup + Addend) : int16 + /// + Add16, + + /// 32 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{4}Fixup + Addend) : int32 + /// + Add32, + + /// 64 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{8}Fixup + Addend) : int64 + /// + Add64, + + /// ULEB128 bits label addition + /// + /// Fixup expression: + /// Fixup <- (Target + *{16}Fixup + Addend) : uleb128 + /// + AddUleb128, + + /// low 6 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - (Target + Addend) & 0x3f) : int8 + /// + Sub6, + + /// 8 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{1}Fixup - Target - Addend) : int8 + /// + Sub8, + + /// 16 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{2}Fixup - Target - Addend) : int16 + /// + Sub16, + + /// 32 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{4}Fixup - Target - Addend) : int32 + /// + Sub32, + + /// 64 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{8}Fixup - Target - Addend) : int64 + /// + Sub64, + + /// ULEB128 bits label subtraction + /// + /// Fixup expression: + /// Fixup <- (*{16}Fixup - Target - Addend) : uleb128 + /// + SubUleb128, + /// Alignment requirement used by linker relaxation. /// /// Linker relaxation will use this to ensure all code sequences are properly @@ -369,6 +455,100 @@ inline Error applyFixup(LinkGraph &G, Block &B, const Edge &E) { *(little32_t *)(FixupPtr + 4) = Jirl | Lo16; break; } + case Add6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value += ((TargetAddress + Addend) & 0x3f); +*FixupPtr = (*FixupPtr & 0xc0) | (static_cast(Value) & 0x3f); +break; + } + case Add8: { +int64_t Value = +TargetAddress + *(reinterpret_cast(FixupPtr)) + Addend; +*FixupPtr = static_cast(Value); +break; + } + case Add16: { +int64_t Value = +TargetAddress + support::endian::read16le(FixupPtr) + Addend; +*(little16_t *)FixupPtr = static_cast(Value); +break; + } + case Add32: { +int64_t Value = +TargetAddress + support::endian::read32le(FixupPtr) + Addend; +*(little32_t *)FixupPtr = static_cast(Value); +break; + } + case Add64: { +int64_t Value = +TargetAddress + support::endian::read64le(FixupPtr) + Addend; +*(little64_t *)FixupPtr = static_cast(Value); +break; + } + case AddUleb128: { +const uint32_t Maxcount = 1 + 64 / 7; +uint32_t Count; +const char *Error = nullptr; +uint64_t Orig = decodeULEB128((reinterpret_cast(FixupPtr)), + &Count, nullptr, &Error); + +if (Count > Maxcount || (Count == Maxcount && Error)) + return make_error( + "0x" + llvm::utohexstr(orc::ExecutorAddr(FixupAddress).getValue()) + + ": extra space for uleb128"); + +uint64_t Mask = Count < Maxcount ? (1ULL << 7 * Count) - 1 : -1ULL; +encodeULEB128((Orig + TargetAddress + Addend) & Mask, + (reinterpret_cast(FixupPtr)), Count); +break; + } + case Sub6: { +int64_t Value = *(reinterpret_cast(FixupPtr)); +Value -= ((TargetAddress + Addend) & 0x3f); +*FixupPtr = (*FixupPtr & 0xc0) | (static_cast(Value) & 0x3f); +break; + } + case Sub8: { +int64_t Value = +*(reinterpre
[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Introduce struct to hold default kernel teams/threads (PR #116050)
@@ -6182,9 +6182,12 @@ TEST_F(OpenMPIRBuilderTest, TargetRegion) { TargetRegionEntryInfo EntryInfo("func", 42, 4711, 17); OpenMPIRBuilder::LocationDescription OmpLoc({Builder.saveIP(), DL}); - OpenMPIRBuilder::InsertPointOrErrorTy AfterIP = OMPBuilder.createTarget( - OmpLoc, /*IsOffloadEntry=*/true, Builder.saveIP(), Builder.saveIP(), - EntryInfo, -1, 0, Inputs, GenMapInfoCB, BodyGenCB, SimpleArgAccessorCB); + OpenMPIRBuilder::TargetKernelDefaultAttrs DefaultAttrs = { + /*MaxTeams=*/{-1}, /*MinTeams=*/0, /*MaxThreads=*/{0}, /*MinThreads=*/0}; ergawy wrote: Thanks for the clarification. https://github.com/llvm/llvm-project/pull/116050 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Introduce struct to hold default kernel teams/threads (PR #116050)
https://github.com/ergawy approved this pull request. https://github.com/llvm/llvm-project/pull/116050 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)
@@ -925,9 +925,16 @@ class TargetRegisterInfo : public MCRegisterInfo { virtual const char *getRegPressureSetName(unsigned Idx) const = 0; /// Get the register unit pressure limit for this dimension. - /// This limit must be adjusted dynamically for reserved registers. + /// TargetRegisterInfo adjusts this limit for reserved registers. + /// Avoid using this method directly as it is costly to compute. Use the + /// cached version `RegisterClassInfo::getRegPressureSetLimit` instead. virtual unsigned getRegPressureSetLimit(const MachineFunction &MF, arsenm wrote: If this version depends on dynamic function state, it would be more consistent to move it to MachineRegisterInfo https://github.com/llvm/llvm-project/pull/118787 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocEvictionAdvisor analysis to NPM (PR #117309)
@@ -59,59 +62,112 @@ cl::opt EvictInterferenceCutoff( #define LLVM_HAVE_TF_AOT #endif -char RegAllocEvictionAdvisorAnalysis::ID = 0; -INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysis, "regalloc-evict", +char RegAllocEvictionAdvisorAnalysisLegacy::ID = 0; +INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysisLegacy, "regalloc-evict", "Regalloc eviction policy", false, true) namespace { -class DefaultEvictionAdvisorAnalysis final -: public RegAllocEvictionAdvisorAnalysis { +class DefaultEvictionAdvisorProvider final +: public RegAllocEvictionAdvisorProvider { public: - DefaultEvictionAdvisorAnalysis(bool NotAsRequested) - : RegAllocEvictionAdvisorAnalysis(AdvisorMode::Default), -NotAsRequested(NotAsRequested) {} + DefaultEvictionAdvisorProvider(bool NotAsRequested, LLVMContext &Ctx) + : RegAllocEvictionAdvisorProvider(AdvisorMode::Default, Ctx) { +if (NotAsRequested) + Ctx.emitError("Requested regalloc eviction advisor analysis " +"could not be created. Using default"); + } // support for isa<> and dyn_cast. - static bool classof(const RegAllocEvictionAdvisorAnalysis *R) { + static bool classof(const RegAllocEvictionAdvisorProvider *R) { return R->getAdvisorMode() == AdvisorMode::Default; } -private: std::unique_ptr - getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override { + getAdvisor(const MachineFunction &MF, const RAGreedy &RA, + MachineBlockFrequencyInfo *, MachineLoopInfo *) override { return std::make_unique(MF, RA); } +}; + +class DefaultEvictionAdvisorAnalysisLegacy final +: public RegAllocEvictionAdvisorAnalysisLegacy { +public: + DefaultEvictionAdvisorAnalysisLegacy(bool NotAsRequested) + : RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Default), +NotAsRequested(NotAsRequested) {} + bool doInitialization(Module &M) override { -if (NotAsRequested) - M.getContext().emitError("Requested regalloc eviction advisor analysis " - "could not be created. Using default"); -return RegAllocEvictionAdvisorAnalysis::doInitialization(M); +Provider.reset( +new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext())); +return false; + } + + // support for isa<> and dyn_cast. + static bool classof(const RegAllocEvictionAdvisorAnalysisLegacy *R) { +return R->getAdvisorMode() == AdvisorMode::Default; } + +private: const bool NotAsRequested; }; } // namespace -template <> Pass *llvm::callDefaultCtor() { +AnalysisKey RegAllocEvictionAdvisorAnalysis::Key; + +void RegAllocEvictionAdvisorAnalysis::initializeProvider( +RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) { + if (Provider) +return; + switch (Mode) { + case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default: +Provider.reset( +new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/false, Ctx)); +break; + case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development: +#if defined(LLVM_HAVE_TFLITE) +Provider.reset(createDevelopmentModeAdvisorProvider(Ctx)); +#endif +break; + case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release: +Provider.reset(createReleaseModeAdvisorProvider(Ctx)); +break; + } + + if (!Provider) arsenm wrote: Move to switch default https://github.com/llvm/llvm-project/pull/117309 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [flang][OpenMP] Parsing context selectors for METADIRECTIVE (PR #121815)
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/121815 >From 215c7e6133bf07d005ac7483b8faf797e319a1fa Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 12 Dec 2024 15:26:26 -0600 Subject: [PATCH 1/5] [flang][OpenMP] Parsing context selectors for METADIRECTIVE This is just adding parsers for context selectors. There are no tests because there is no way to execute these parsers yet. --- flang/include/flang/Parser/characters.h | 2 + flang/include/flang/Parser/dump-parse-tree.h | 14 ++ flang/include/flang/Parser/parse-tree.h | 136 +++ flang/lib/Parser/openmp-parsers.cpp | 78 +++ flang/lib/Parser/token-parsers.h | 4 + flang/lib/Parser/unparse.cpp | 38 ++ flang/lib/Semantics/check-omp-structure.cpp | 8 ++ flang/lib/Semantics/check-omp-structure.h| 3 + flang/lib/Semantics/resolve-directives.cpp | 6 + 9 files changed, 289 insertions(+) diff --git a/flang/include/flang/Parser/characters.h b/flang/include/flang/Parser/characters.h index df188d674b9eeb..dbdc058c44995a 100644 --- a/flang/include/flang/Parser/characters.h +++ b/flang/include/flang/Parser/characters.h @@ -180,6 +180,8 @@ inline constexpr bool IsValidFortranTokenCharacter(char ch) { case '>': case '[': case ']': + case '{': // Used in OpenMP context selector specification + case '}': // return true; default: return IsLegalIdentifierStart(ch) || IsDecimalDigit(ch); diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index 3331520922bc63..a61d7973dd5c36 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -476,6 +476,20 @@ class ParseTreeDumper { NODE(parser, NullInit) NODE(parser, ObjectDecl) NODE(parser, OldParameterStmt) + NODE(parser, OmpDirectiveSpecification) + NODE(parser, OmpTraitPropertyName) + NODE(parser, OmpTraitScore) + NODE(parser, OmpTraitPropertyExtension) + NODE(OmpTraitPropertyExtension, ExtensionValue) + NODE(parser, OmpTraitProperty) + NODE(parser, OmpTraitSelectorName) + NODE_ENUM(OmpTraitSelectorName, Value) + NODE(parser, OmpTraitSelector) + NODE(OmpTraitSelector, Properties) + NODE(parser, OmpTraitSetSelectorName) + NODE_ENUM(OmpTraitSetSelectorName, Value) + NODE(parser, OmpTraitSetSelector) + NODE(parser, OmpContextSelectorSpecification) NODE(parser, OmpMapper) NODE(parser, OmpMapType) NODE_ENUM(OmpMapType, Value) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 941d70d3876291..697bddfaf16150 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3453,6 +3453,17 @@ WRAPPER_CLASS(PauseStmt, std::optional); // --- Common definitions +struct OmpClause; +struct OmpClauseList; + +struct OmpDirectiveSpecification { + TUPLE_CLASS_BOILERPLATE(OmpDirectiveSpecification); + std::tuple>> + t; + CharBlock source; +}; + // 2.1 Directives or clauses may accept a list or extended-list. // A list item is a variable, array section or common block name (enclosed // in slashes). An extended list item is a list item or a procedure Name. @@ -3474,6 +3485,128 @@ WRAPPER_CLASS(OmpObjectList, std::list); #define MODIFIERS() std::optional> +inline namespace traits { +// trait-property-name -> +//identifier | string-literal +struct OmpTraitPropertyName { + WRAPPER_CLASS_BOILERPLATE(OmpTraitPropertyName, std::string); +}; + +// trait-score -> +//SCORE(non-negative-const-integer-expression) +struct OmpTraitScore { + WRAPPER_CLASS_BOILERPLATE(OmpTraitScore, ScalarIntExpr); +}; + +// trait-property-extension -> +//trait-property-name (trait-property-value, ...) +// trait-property-value -> +//trait-property-name | +//scalar-integer-expression | +//trait-property-extension +// +// The grammar in OpenMP 5.2+ spec is ambiguous, the above is a different +// version (but equivalent) that doesn't have ambiguities. +// The ambiguity is in +// trait-property: +// trait-property-name <- (a) +// trait-property-clause +// trait-property-expression<- (b) +// trait-property-extension <- this conflicts with (a) and (b) +// trait-property-extension: +// trait-property-name <- conflict with (a) +// identifier(trait-property-extension[, trait-property-extension[, ...]]) +// constant integer expression <- conflict with (b) +// +struct OmpTraitPropertyExtension { + TUPLE_CLASS_BOILERPLATE(OmpTraitPropertyExtension); + struct ExtensionValue { +UNION_CLASS_BOILERPLATE(ExtensionValue); +std::variant> +u; + }; + using ExtensionList = std::list; + std::tuple t; +}; + +// trait-property -> +//trait-property-name | OmpClause | +//trait-property-expression | trait-property-extension +// trait-property-expression -> +//
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Parse WHEN, OTHERWISE, MATCH clauses plus METADIRECTIVE (PR #121817)
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/121817 >From 5f534c559ca1bb7911b484264582d1a5078bdcb8 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 12 Dec 2024 15:26:26 -0600 Subject: [PATCH 1/9] [flang][OpenMP] Parse WHEN, OTHERWISE, MATCH clauses plus METADIRECTIVE Parse METADIRECTIVE as a standalone executable directive at the moment. This will allow testing the parser code. There is no lowering, not even clause conversion yet. There is also no verification of the allowed values for trait sets, trait properties. --- flang/include/flang/Parser/dump-parse-tree.h | 5 + flang/include/flang/Parser/parse-tree.h | 41 - flang/lib/Lower/OpenMP/Clauses.cpp | 21 ++- flang/lib/Lower/OpenMP/Clauses.h | 1 + flang/lib/Lower/OpenMP/OpenMP.cpp| 6 + flang/lib/Parser/openmp-parsers.cpp | 26 ++- flang/lib/Parser/unparse.cpp | 12 ++ flang/lib/Semantics/check-omp-structure.cpp | 9 + flang/lib/Semantics/check-omp-structure.h| 3 + flang/lib/Semantics/resolve-directives.cpp | 5 + flang/test/Parser/OpenMP/metadirective.f90 | 165 +++ llvm/include/llvm/Frontend/OpenMP/OMP.td | 9 +- 12 files changed, 296 insertions(+), 7 deletions(-) create mode 100644 flang/test/Parser/OpenMP/metadirective.f90 diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index a61d7973dd5c36..94ca7c67cbd52e 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -476,6 +476,11 @@ class ParseTreeDumper { NODE(parser, NullInit) NODE(parser, ObjectDecl) NODE(parser, OldParameterStmt) + NODE(parser, OmpMetadirectiveDirective) + NODE(parser, OmpMatchClause) + NODE(parser, OmpOtherwiseClause) + NODE(parser, OmpWhenClause) + NODE(OmpWhenClause, Modifier) NODE(parser, OmpDirectiveSpecification) NODE(parser, OmpTraitPropertyName) NODE(parser, OmpTraitScore) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 697bddfaf16150..113ff3380ba22c 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3964,6 +3964,7 @@ struct OmpBindClause { // data-sharing-attribute -> //SHARED | NONE | // since 4.5 //PRIVATE | FIRSTPRIVATE// since 5.0 +// See also otherwise-clause. struct OmpDefaultClause { ENUM_CLASS(DataSharingAttribute, Private, Firstprivate, Shared, None) WRAPPER_CLASS_BOILERPLATE(OmpDefaultClause, DataSharingAttribute); @@ -4184,6 +4185,16 @@ struct OmpMapClause { std::tuple t; }; +// Ref: [5.0:58-60], [5.1:63-68], [5.2:194-195] +// +// match-clause -> +//MATCH (context-selector-specification)// since 5.0 +struct OmpMatchClause { + // The context-selector is an argument. + WRAPPER_CLASS_BOILERPLATE( + OmpMatchClause, traits::OmpContextSelectorSpecification); +}; + // Ref: [5.2:217-218] // message-clause -> //MESSAGE("message-text") @@ -4214,6 +4225,17 @@ struct OmpOrderClause { std::tuple t; }; +// Ref: [5.0:56-57], [5.1:60-62], [5.2:191] +// +// otherwise-clause -> +//DEFAULT ([directive-specification]) // since 5.0, until 5.1 +// otherwise-clause -> +//OTHERWISE ([directive-specification])]// since 5.2 +struct OmpOtherwiseClause { + WRAPPER_CLASS_BOILERPLATE( + OmpOtherwiseClause, std::optional); +}; + // Ref: [4.5:46-50], [5.0:74-78], [5.1:92-96], [5.2:229-230] // // proc-bind-clause -> @@ -4299,6 +4321,17 @@ struct OmpUpdateClause { std::variant u; }; +// Ref: [5.0:56-57], [5.1:60-62], [5.2:190-191] +// +// when-clause -> +//WHEN (context-selector : +//[directive-specification])// since 5.0 +struct OmpWhenClause { + TUPLE_CLASS_BOILERPLATE(OmpWhenClause); + MODIFIER_BOILERPLATE(OmpContextSelector); + std::tuple> t; +}; + // OpenMP Clauses struct OmpClause { UNION_CLASS_BOILERPLATE(OmpClause); @@ -4323,6 +4356,12 @@ struct OmpClauseList { // --- Directives and constructs +struct OmpMetadirectiveDirective { + TUPLE_CLASS_BOILERPLATE(OmpMetadirectiveDirective); + std::tuple t; + CharBlock source; +}; + // Ref: [5.1:89-90], [5.2:216] // // nothing-directive -> @@ -4696,7 +4735,7 @@ struct OpenMPStandaloneConstruct { CharBlock source; std::variant + OpenMPDepobjConstruct, OmpMetadirectiveDirective> u; }; diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index b424e209d56da9..d60171552087fa 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -230,9 +230,9 @@ MAKE_EMPTY_CLASS(Threadprivate, Threadprivate); MAKE_INCOMPLETE_CLASS(AdjustArgs, AdjustArgs); MAKE_INCOMPLETE_CLASS(AppendArgs, AppendArgs); -MAKE_INCOMPLETE_CLASS(Match, Match); +// MAKE_INCOMPLETE_CLASS(Match, Mat
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
@@ -289,7 +281,16 @@ static LogicalResult checkImplementationStatus(Operation &op) { checkBare(op, result); checkDevice(op, result); checkHasDeviceAddr(op, result); -checkHostEval(op, result); + +// Host evaluated clauses are supported, except for target SPMD loop agozillon wrote: Nit: Would it make sense to keep this segment inside of the checkHostEval function just to keep things "tidy"? I'll leave it up to you, not overly fussed personally! https://github.com/llvm/llvm-project/pull/116052 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
https://github.com/agozillon approved this pull request. Thank you for the patch @skatrak LGTM, left a few nits but feel free to ignore any you think make no sense! https://github.com/llvm/llvm-project/pull/116052 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg, return builder.saveIP(); } +/// Follow uses of `host_eval`-defined block arguments of the given `omp.target` +/// operation and populate output variables with their corresponding host value +/// (i.e. operand evaluated outside of the target region), based on their uses +/// inside of the target region. +/// +/// Loop bounds and steps are only optionally populated, if output vectors are +/// provided. +static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads, + Value &numTeamsLower, Value &numTeamsUpper, + Value &threadLimit) { + auto blockArgIface = llvm::cast(*targetOp); + for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(), + blockArgIface.getHostEvalBlockArgs())) { +Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item); + +for (Operation *user : blockArg.getUsers()) { + llvm::TypeSwitch(user) + .Case([&](omp::TeamsOp teamsOp) { +if (teamsOp.getNumTeamsLower() == blockArg) + numTeamsLower = hostEvalVar; +else if (teamsOp.getNumTeamsUpper() == blockArg) + numTeamsUpper = hostEvalVar; +else if (teamsOp.getThreadLimit() == blockArg) + threadLimit = hostEvalVar; +else + llvm_unreachable("unsupported host_eval use"); + }) + .Case([&](omp::ParallelOp parallelOp) { +if (parallelOp.getNumThreads() == blockArg) + numThreads = hostEvalVar; +else + llvm_unreachable("unsupported host_eval use"); + }) + .Case([&](omp::LoopNestOp loopOp) { +// TODO: Extract bounds and step values. + }) + .Default([](Operation *) { +llvm_unreachable("unsupported host_eval use"); + }); +} + } +} + +/// If \p op is of the given type parameter, return it casted to that type. +/// Otherwise, if its immediate parent operation (or some other higher-level +/// parent, if \p immediateParent is false) is of that type, return that parent +/// casted to the given type. +/// +/// If \p op is \c null or neither it or its parent(s) are of the specified +/// type, return a \c null operation. +template +static OpTy castOrGetParentOfType(Operation *op, bool immediateParent = false) { + if (!op) +return OpTy(); + + if (OpTy casted = dyn_cast(op)) +return casted; + + if (immediateParent) +return dyn_cast_if_present(op->getParentOp()); + + return op->getParentOfType(); +} + +/// Populate default `MinTeams`, `MaxTeams` and `MaxThreads` to their default +/// values as stated by the corresponding clauses, if constant. +/// +/// These default values must be set before the creation of the outlined LLVM +/// function for the target region, so that they can be used to initialize the +/// corresponding global `ConfigurationEnvironmentTy` structure. +static void +initTargetDefaultAttrs(omp::TargetOp targetOp, + llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &attrs, + bool isTargetDevice) { + // TODO: Handle constant 'if' clauses. + Operation *capturedOp = targetOp.getInnermostCapturedOmpOp(); + + Value numThreads, numTeamsLower, numTeamsUpper, threadLimit; + if (!isTargetDevice) { +extractHostEvalClauses(targetOp, numThreads, numTeamsLower, numTeamsUpper, + threadLimit); + } else { +// In the target device, values for these clauses are not passed as +// host_eval, but instead evaluated prior to entry to the region. This +// ensures values are mapped and available inside of the target region. +if (auto teamsOp = castOrGetParentOfType(capturedOp)) { + numTeamsLower = teamsOp.getNumTeamsLower(); + numTeamsUpper = teamsOp.getNumTeamsUpper(); + threadLimit = teamsOp.getThreadLimit(); +} + +if (auto parallelOp = castOrGetParentOfType(capturedOp)) + numThreads = parallelOp.getNumThreads(); + } + + auto extractConstInteger = [](Value value) -> std::optional { +if (auto constOp = +dyn_cast_if_present(value.getDefiningOp())) + if (auto constAttr = dyn_cast(constOp.getValue())) +return constAttr.getInt(); + +return std::nullopt; + }; + + // Handle clauses impacting the number of teams. + + int32_t minTeamsVal = 1, maxTeamsVal = -1; + if (castOrGetParentOfType(capturedOp)) { +// TODO: Use `hostNumTeamsLower` to initialize `minTeamsVal`. For now, match +// clang and set min and max to the same value. +if (numTeamsUpper) { + if (auto val = extractConstInteger(numTeamsUpper)) +minTeamsVal = maxTeamsVal = *val; agozillon wrote: likely a dumb question, would it make sense to have an else here, to set minTeamsVal/maxTeamsVal to 0 as is do
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg, return builder.saveIP(); } +/// Follow uses of `host_eval`-defined block arguments of the given `omp.target` +/// operation and populate output variables with their corresponding host value +/// (i.e. operand evaluated outside of the target region), based on their uses +/// inside of the target region. +/// +/// Loop bounds and steps are only optionally populated, if output vectors are +/// provided. +static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads, + Value &numTeamsLower, Value &numTeamsUpper, + Value &threadLimit) { + auto blockArgIface = llvm::cast(*targetOp); + for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(), + blockArgIface.getHostEvalBlockArgs())) { +Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item); + +for (Operation *user : blockArg.getUsers()) { + llvm::TypeSwitch(user) + .Case([&](omp::TeamsOp teamsOp) { +if (teamsOp.getNumTeamsLower() == blockArg) + numTeamsLower = hostEvalVar; +else if (teamsOp.getNumTeamsUpper() == blockArg) + numTeamsUpper = hostEvalVar; +else if (teamsOp.getThreadLimit() == blockArg) + threadLimit = hostEvalVar; +else + llvm_unreachable("unsupported host_eval use"); + }) + .Case([&](omp::ParallelOp parallelOp) { +if (parallelOp.getNumThreads() == blockArg) + numThreads = hostEvalVar; +else + llvm_unreachable("unsupported host_eval use"); + }) + .Case([&](omp::LoopNestOp loopOp) { +// TODO: Extract bounds and step values. + }) + .Default([](Operation *) { +llvm_unreachable("unsupported host_eval use"); + }); +} + } +} + +/// If \p op is of the given type parameter, return it casted to that type. +/// Otherwise, if its immediate parent operation (or some other higher-level +/// parent, if \p immediateParent is false) is of that type, return that parent +/// casted to the given type. +/// +/// If \p op is \c null or neither it or its parent(s) are of the specified +/// type, return a \c null operation. +template +static OpTy castOrGetParentOfType(Operation *op, bool immediateParent = false) { + if (!op) +return OpTy(); + + if (OpTy casted = dyn_cast(op)) +return casted; + + if (immediateParent) +return dyn_cast_if_present(op->getParentOp()); + + return op->getParentOfType(); +} + +/// Populate default `MinTeams`, `MaxTeams` and `MaxThreads` to their default +/// values as stated by the corresponding clauses, if constant. +/// +/// These default values must be set before the creation of the outlined LLVM +/// function for the target region, so that they can be used to initialize the +/// corresponding global `ConfigurationEnvironmentTy` structure. +static void +initTargetDefaultAttrs(omp::TargetOp targetOp, + llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs &attrs, + bool isTargetDevice) { + // TODO: Handle constant 'if' clauses. + Operation *capturedOp = targetOp.getInnermostCapturedOmpOp(); + + Value numThreads, numTeamsLower, numTeamsUpper, threadLimit; + if (!isTargetDevice) { +extractHostEvalClauses(targetOp, numThreads, numTeamsLower, numTeamsUpper, + threadLimit); + } else { +// In the target device, values for these clauses are not passed as +// host_eval, but instead evaluated prior to entry to the region. This +// ensures values are mapped and available inside of the target region. +if (auto teamsOp = castOrGetParentOfType(capturedOp)) { + numTeamsLower = teamsOp.getNumTeamsLower(); + numTeamsUpper = teamsOp.getNumTeamsUpper(); + threadLimit = teamsOp.getThreadLimit(); +} + +if (auto parallelOp = castOrGetParentOfType(capturedOp)) + numThreads = parallelOp.getNumThreads(); + } + + auto extractConstInteger = [](Value value) -> std::optional { agozillon wrote: might honestly be worth just making this a function as it's possibly useful elsewhere in the file, but I'll leave that up to you as usual! :-) https://github.com/llvm/llvm-project/pull/116052 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg, return builder.saveIP(); } +/// Follow uses of `host_eval`-defined block arguments of the given `omp.target` +/// operation and populate output variables with their corresponding host value +/// (i.e. operand evaluated outside of the target region), based on their uses +/// inside of the target region. +/// +/// Loop bounds and steps are only optionally populated, if output vectors are +/// provided. +static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads, + Value &numTeamsLower, Value &numTeamsUpper, + Value &threadLimit) { + auto blockArgIface = llvm::cast(*targetOp); + for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(), + blockArgIface.getHostEvalBlockArgs())) { +Value hostEvalVar = std::get<0>(item), blockArg = std::get<1>(item); + +for (Operation *user : blockArg.getUsers()) { + llvm::TypeSwitch(user) + .Case([&](omp::TeamsOp teamsOp) { +if (teamsOp.getNumTeamsLower() == blockArg) + numTeamsLower = hostEvalVar; +else if (teamsOp.getNumTeamsUpper() == blockArg) + numTeamsUpper = hostEvalVar; +else if (teamsOp.getThreadLimit() == blockArg) + threadLimit = hostEvalVar; +else + llvm_unreachable("unsupported host_eval use"); + }) + .Case([&](omp::ParallelOp parallelOp) { +if (parallelOp.getNumThreads() == blockArg) + numThreads = hostEvalVar; +else + llvm_unreachable("unsupported host_eval use"); + }) + .Case([&](omp::LoopNestOp loopOp) { +// TODO: Extract bounds and step values. agozillon wrote: probably not worth the effort and maybe it doesn't make sense, but I suppose we could do a TODO/llvm_unreachable here when we check (excuse the pseudo code) if (loopOp.step() == blockArg), just so that if we ever happen to apply this in lowering we'll emit a TODO reminder effectively reminding people it has no effect, but might be more trouble than it's worth and silently failing is more ideal, I'll leave the decision to you! Shame there isn't a TODO warning as opposed to hard failure for cases where it won't generate wrong code, but unoptimized/ignored requests. https://github.com/llvm/llvm-project/pull/116052 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
https://github.com/agozillon edited https://github.com/llvm/llvm-project/pull/116052 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [MLIR][OpenMP] LLVM IR translation of host_eval (PR #116052)
@@ -3889,6 +3889,215 @@ createDeviceArgumentAccessor(MapInfoData &mapData, llvm::Argument &arg, return builder.saveIP(); } +/// Follow uses of `host_eval`-defined block arguments of the given `omp.target` +/// operation and populate output variables with their corresponding host value +/// (i.e. operand evaluated outside of the target region), based on their uses +/// inside of the target region. +/// +/// Loop bounds and steps are only optionally populated, if output vectors are +/// provided. +static void extractHostEvalClauses(omp::TargetOp targetOp, Value &numThreads, + Value &numTeamsLower, Value &numTeamsUpper, + Value &threadLimit) { + auto blockArgIface = llvm::cast(*targetOp); + for (auto item : llvm::zip_equal(targetOp.getHostEvalVars(), agozillon wrote: Small nit: Not sure if it makes sense to do something like: `Value [hostEvalVar, blockArg] = llvm::zip_equal` here but might save you the std::get's below https://github.com/llvm/llvm-project/pull/116052 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocEvictionAdvisor analysis to NPM (PR #117309)
@@ -541,25 +531,83 @@ class DevelopmentModeEvictionAdvisorAnalysis final Log = std::make_unique(std::move(OS), LFS, Reward, /*IncludeReward*/ true); -return false; +return; + } + + // support for isa<> and dyn_cast. + static bool classof(const RegAllocEvictionAdvisorProvider *R) { +return R->getAdvisorMode() == AdvisorMode::Development; + } + + void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) override { +if (!Log || !Log->hasAnyObservationForContext(MF.getName())) + return; +// The function pass manager would run all the function passes for a +// function, so we assume the last context belongs to this function. If +// this invariant ever changes, we can implement at that time switching +// contexts. At this point, it'd be an error +if (Log->currentContext() != MF.getName()) { + MF.getFunction().getContext().emitError( + "The training log context shouldn't have had changed."); +} +if (Log->hasObservationInProgress()) + Log->logReward(GetReward()); } std::unique_ptr - getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override { + getAdvisor(const MachineFunction &MF, const RAGreedy &RA, + MachineBlockFrequencyInfo *MBFI, MachineLoopInfo *Loops) override { if (!Runner) return nullptr; if (Log) Log->switchContext(MF.getName()); +assert(MBFI && Loops && + "Invalid provider state: must have analysis available"); return std::make_unique( -MF, RA, Runner.get(), -getAnalysis().getMBFI(), -getAnalysis().getLI(), Log.get()); +MF, RA, Runner.get(), *MBFI, *Loops, Log.get()); } +private: + std::vector InputFeatures; + std::vector TrainingInputFeatures; + std::unique_ptr Runner; std::unique_ptr Log; }; +class DevelopmentModeEvictionAdvisorAnalysisLegacy final +: public RegAllocEvictionAdvisorAnalysisLegacy { +public: + DevelopmentModeEvictionAdvisorAnalysisLegacy() + : RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Development) {} + + bool doInitialization(Module &M) override { +Provider = std::make_unique( +M.getContext()); +return false; + } + + void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) override { +Provider->logRewardIfNeeded(MF, GetReward); + } + + // support for isa<> and dyn_cast. + static bool classof(const RegAllocEvictionAdvisorAnalysisLegacy *R) { +return R->getAdvisorMode() == AdvisorMode::Development; + } + + void getAnalysisUsage(AnalysisUsage &AU) const override { +AU.addRequired(); +AU.addRequired(); +RegAllocEvictionAdvisorAnalysisLegacy::getAnalysisUsage(AU); + } + +private: + // std::unique_ptr Provider; arsenm wrote: ```suggestion ``` Commented out code https://github.com/llvm/llvm-project/pull/117309 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocEvictionAdvisor analysis to NPM (PR #117309)
@@ -59,59 +62,112 @@ cl::opt EvictInterferenceCutoff( #define LLVM_HAVE_TF_AOT #endif -char RegAllocEvictionAdvisorAnalysis::ID = 0; -INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysis, "regalloc-evict", +char RegAllocEvictionAdvisorAnalysisLegacy::ID = 0; +INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysisLegacy, "regalloc-evict", "Regalloc eviction policy", false, true) namespace { -class DefaultEvictionAdvisorAnalysis final -: public RegAllocEvictionAdvisorAnalysis { +class DefaultEvictionAdvisorProvider final +: public RegAllocEvictionAdvisorProvider { public: - DefaultEvictionAdvisorAnalysis(bool NotAsRequested) - : RegAllocEvictionAdvisorAnalysis(AdvisorMode::Default), -NotAsRequested(NotAsRequested) {} + DefaultEvictionAdvisorProvider(bool NotAsRequested, LLVMContext &Ctx) + : RegAllocEvictionAdvisorProvider(AdvisorMode::Default, Ctx) { +if (NotAsRequested) + Ctx.emitError("Requested regalloc eviction advisor analysis " +"could not be created. Using default"); + } // support for isa<> and dyn_cast. - static bool classof(const RegAllocEvictionAdvisorAnalysis *R) { + static bool classof(const RegAllocEvictionAdvisorProvider *R) { return R->getAdvisorMode() == AdvisorMode::Default; } -private: std::unique_ptr - getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override { + getAdvisor(const MachineFunction &MF, const RAGreedy &RA, + MachineBlockFrequencyInfo *, MachineLoopInfo *) override { return std::make_unique(MF, RA); } +}; + +class DefaultEvictionAdvisorAnalysisLegacy final +: public RegAllocEvictionAdvisorAnalysisLegacy { +public: + DefaultEvictionAdvisorAnalysisLegacy(bool NotAsRequested) + : RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Default), +NotAsRequested(NotAsRequested) {} + bool doInitialization(Module &M) override { -if (NotAsRequested) - M.getContext().emitError("Requested regalloc eviction advisor analysis " - "could not be created. Using default"); -return RegAllocEvictionAdvisorAnalysis::doInitialization(M); +Provider.reset( +new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext())); +return false; + } + + // support for isa<> and dyn_cast. + static bool classof(const RegAllocEvictionAdvisorAnalysisLegacy *R) { +return R->getAdvisorMode() == AdvisorMode::Default; } + +private: const bool NotAsRequested; }; } // namespace -template <> Pass *llvm::callDefaultCtor() { +AnalysisKey RegAllocEvictionAdvisorAnalysis::Key; + +void RegAllocEvictionAdvisorAnalysis::initializeProvider( +RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) { + if (Provider) +return; + switch (Mode) { + case RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default: +Provider.reset( +new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/false, Ctx)); +break; arsenm wrote: return https://github.com/llvm/llvm-project/pull/117309 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [llvm] [flang][OpenMP] Parse WHEN, OTHERWISE, MATCH clauses plus METADIRECTIVE (PR #121817)
https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/121817 >From 5f534c559ca1bb7911b484264582d1a5078bdcb8 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek Date: Thu, 12 Dec 2024 15:26:26 -0600 Subject: [PATCH 1/8] [flang][OpenMP] Parse WHEN, OTHERWISE, MATCH clauses plus METADIRECTIVE Parse METADIRECTIVE as a standalone executable directive at the moment. This will allow testing the parser code. There is no lowering, not even clause conversion yet. There is also no verification of the allowed values for trait sets, trait properties. --- flang/include/flang/Parser/dump-parse-tree.h | 5 + flang/include/flang/Parser/parse-tree.h | 41 - flang/lib/Lower/OpenMP/Clauses.cpp | 21 ++- flang/lib/Lower/OpenMP/Clauses.h | 1 + flang/lib/Lower/OpenMP/OpenMP.cpp| 6 + flang/lib/Parser/openmp-parsers.cpp | 26 ++- flang/lib/Parser/unparse.cpp | 12 ++ flang/lib/Semantics/check-omp-structure.cpp | 9 + flang/lib/Semantics/check-omp-structure.h| 3 + flang/lib/Semantics/resolve-directives.cpp | 5 + flang/test/Parser/OpenMP/metadirective.f90 | 165 +++ llvm/include/llvm/Frontend/OpenMP/OMP.td | 9 +- 12 files changed, 296 insertions(+), 7 deletions(-) create mode 100644 flang/test/Parser/OpenMP/metadirective.f90 diff --git a/flang/include/flang/Parser/dump-parse-tree.h b/flang/include/flang/Parser/dump-parse-tree.h index a61d7973dd5c36..94ca7c67cbd52e 100644 --- a/flang/include/flang/Parser/dump-parse-tree.h +++ b/flang/include/flang/Parser/dump-parse-tree.h @@ -476,6 +476,11 @@ class ParseTreeDumper { NODE(parser, NullInit) NODE(parser, ObjectDecl) NODE(parser, OldParameterStmt) + NODE(parser, OmpMetadirectiveDirective) + NODE(parser, OmpMatchClause) + NODE(parser, OmpOtherwiseClause) + NODE(parser, OmpWhenClause) + NODE(OmpWhenClause, Modifier) NODE(parser, OmpDirectiveSpecification) NODE(parser, OmpTraitPropertyName) NODE(parser, OmpTraitScore) diff --git a/flang/include/flang/Parser/parse-tree.h b/flang/include/flang/Parser/parse-tree.h index 697bddfaf16150..113ff3380ba22c 100644 --- a/flang/include/flang/Parser/parse-tree.h +++ b/flang/include/flang/Parser/parse-tree.h @@ -3964,6 +3964,7 @@ struct OmpBindClause { // data-sharing-attribute -> //SHARED | NONE | // since 4.5 //PRIVATE | FIRSTPRIVATE// since 5.0 +// See also otherwise-clause. struct OmpDefaultClause { ENUM_CLASS(DataSharingAttribute, Private, Firstprivate, Shared, None) WRAPPER_CLASS_BOILERPLATE(OmpDefaultClause, DataSharingAttribute); @@ -4184,6 +4185,16 @@ struct OmpMapClause { std::tuple t; }; +// Ref: [5.0:58-60], [5.1:63-68], [5.2:194-195] +// +// match-clause -> +//MATCH (context-selector-specification)// since 5.0 +struct OmpMatchClause { + // The context-selector is an argument. + WRAPPER_CLASS_BOILERPLATE( + OmpMatchClause, traits::OmpContextSelectorSpecification); +}; + // Ref: [5.2:217-218] // message-clause -> //MESSAGE("message-text") @@ -4214,6 +4225,17 @@ struct OmpOrderClause { std::tuple t; }; +// Ref: [5.0:56-57], [5.1:60-62], [5.2:191] +// +// otherwise-clause -> +//DEFAULT ([directive-specification]) // since 5.0, until 5.1 +// otherwise-clause -> +//OTHERWISE ([directive-specification])]// since 5.2 +struct OmpOtherwiseClause { + WRAPPER_CLASS_BOILERPLATE( + OmpOtherwiseClause, std::optional); +}; + // Ref: [4.5:46-50], [5.0:74-78], [5.1:92-96], [5.2:229-230] // // proc-bind-clause -> @@ -4299,6 +4321,17 @@ struct OmpUpdateClause { std::variant u; }; +// Ref: [5.0:56-57], [5.1:60-62], [5.2:190-191] +// +// when-clause -> +//WHEN (context-selector : +//[directive-specification])// since 5.0 +struct OmpWhenClause { + TUPLE_CLASS_BOILERPLATE(OmpWhenClause); + MODIFIER_BOILERPLATE(OmpContextSelector); + std::tuple> t; +}; + // OpenMP Clauses struct OmpClause { UNION_CLASS_BOILERPLATE(OmpClause); @@ -4323,6 +4356,12 @@ struct OmpClauseList { // --- Directives and constructs +struct OmpMetadirectiveDirective { + TUPLE_CLASS_BOILERPLATE(OmpMetadirectiveDirective); + std::tuple t; + CharBlock source; +}; + // Ref: [5.1:89-90], [5.2:216] // // nothing-directive -> @@ -4696,7 +4735,7 @@ struct OpenMPStandaloneConstruct { CharBlock source; std::variant + OpenMPDepobjConstruct, OmpMetadirectiveDirective> u; }; diff --git a/flang/lib/Lower/OpenMP/Clauses.cpp b/flang/lib/Lower/OpenMP/Clauses.cpp index b424e209d56da9..d60171552087fa 100644 --- a/flang/lib/Lower/OpenMP/Clauses.cpp +++ b/flang/lib/Lower/OpenMP/Clauses.cpp @@ -230,9 +230,9 @@ MAKE_EMPTY_CLASS(Threadprivate, Threadprivate); MAKE_INCOMPLETE_CLASS(AdjustArgs, AdjustArgs); MAKE_INCOMPLETE_CLASS(AppendArgs, AppendArgs); -MAKE_INCOMPLETE_CLASS(Match, Match); +// MAKE_INCOMPLETE_CLASS(Match, Mat
[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)
@@ -308,6 +308,9 @@ def StackProtectStrong : EnumAttr<"sspstrong", IntersectPreserve, [FnAttr]>; /// Function was called in a scope requiring strict floating point semantics. def StrictFP : EnumAttr<"strictfp", IntersectPreserve, [FnAttr]>; +/// Function is a floating point operation. +def FPOperation : EnumAttr<"fpoperation", IntersectPreserve, [FnAttr]>; jayfoad wrote: Function attributes need documenting in LangRef https://github.com/llvm/llvm-project/pull/122313 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [IR] Add FPOperation intrinsic property (PR #122313)
https://github.com/nikic commented: At least based on your description, I don't think this intrinsic property should be implemented using an attribute. https://github.com/llvm/llvm-project/pull/122313 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` (PR #113113)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113113 >From 16e2bb8b73bcde1c2618bb358a905a9f463c1217 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 20 Oct 2024 16:24:26 +0900 Subject: [PATCH 1/3] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` --- clang/lib/CodeGen/CGExprScalar.cpp | 83 +++- clang/lib/CodeGen/CGStmt.cpp | 4 -- clang/lib/CodeGen/CodeGenFunction.cpp| 43 ++-- clang/lib/CodeGen/CoverageMappingGen.cpp | 6 -- 4 files changed, 104 insertions(+), 32 deletions(-) diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 11d4ec8a267605..83962ba96aa484 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -4918,6 +4918,9 @@ Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) { } Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { + auto HasLHSSkip = CGF.getIsCounterPair(E); + auto HasRHSSkip = CGF.getIsCounterPair(E->getRHS()); + // Perform vector logical and on comparisons with zero vectors. if (E->getType()->isVectorType()) { CGF.incrementProfileCounter(E); @@ -4964,11 +4967,17 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CodeGenFunction::isInstrumentedCondition(E->getRHS())) { CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond); llvm::BasicBlock *FBlock = CGF.createBasicBlock("land.end"); +llvm::BasicBlock *RHSSkip = +(HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : FBlock); llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); -Builder.CreateCondBr(RHSCond, RHSBlockCnt, FBlock); +Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSSkip); CGF.EmitBlock(RHSBlockCnt); -CGF.incrementProfileCounter(E->getRHS()); +CGF.incrementProfileCounter(false, E->getRHS()); CGF.EmitBranch(FBlock); +if (HasRHSSkip.second) { + CGF.EmitBlock(RHSSkip); + CGF.incrementProfileCounter(true, E->getRHS()); +} CGF.EmitBlock(FBlock); } @@ -4997,12 +5006,21 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { llvm::BasicBlock *ContBlock = CGF.createBasicBlock("land.end"); llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("land.rhs"); + llvm::BasicBlock *LHSFalseBlock = + (HasLHSSkip.second ? CGF.createBasicBlock("land.lhsskip") : ContBlock); + CodeGenFunction::ConditionalEvaluation eval(CGF); // Branch on the LHS first. If it is false, go to the failure (cont) block. - CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, ContBlock, + CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, LHSFalseBlock, CGF.getProfileCount(E->getRHS())); + if (HasLHSSkip.second) { +CGF.EmitBlock(LHSFalseBlock); +CGF.incrementProfileCounter(true, E); +CGF.EmitBranch(ContBlock); + } + // Any edges into the ContBlock are now from an (indeterminate number of) // edges from this first condition. All of these values will be false. Start // setting up the PHI node in the Cont Block for this. @@ -5014,7 +5032,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(false, E); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); eval.end(CGF); @@ -5024,15 +5042,24 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { // If we're generating for profiling or coverage, generate a branch on the // RHS to a block that increments the RHS true counter needed to track branch // condition coverage. + llvm::BasicBlock *ContIncoming = RHSBlock; if (InstrumentRegions && CodeGenFunction::isInstrumentedCondition(E->getRHS())) { CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond); llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt"); -Builder.CreateCondBr(RHSCond, RHSBlockCnt, ContBlock); +llvm::BasicBlock *RHSBlockSkip = +(HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : ContBlock); +Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSBlockSkip); CGF.EmitBlock(RHSBlockCnt); -CGF.incrementProfileCounter(E->getRHS()); +CGF.incrementProfileCounter(false, E->getRHS()); CGF.EmitBranch(ContBlock); PN->addIncoming(RHSCond, RHSBlockCnt); +if (HasRHSSkip.second) { + CGF.EmitBlock(RHSBlockSkip); + CGF.incrementProfileCounter(true, E->getRHS()); + CGF.EmitBranch(ContBlock); + ContIncoming = RHSBlockSkip; +} } // Emit an unconditional branch from this block to ContBlock. @@ -5042,7 +5069,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { CGF.EmitBlock(ContBlock); } // Insert an entry into the phi node for the edge with the value of RHSCond.
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocEvictionAdvisor analysis to NPM (PR #117309)
https://github.com/optimisan edited https://github.com/llvm/llvm-project/pull/117309 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM (PR #118462)
https://github.com/optimisan updated https://github.com/llvm/llvm-project/pull/118462 >From ad905a2ce757ad8d82218c4f670af9f03abfdceb Mon Sep 17 00:00:00 2001 From: Akshat Oke Date: Tue, 3 Dec 2024 10:12:36 + Subject: [PATCH 1/5] [CodeGen][NewPM] Port RegAllocPriorityAdvisor analysis to NPM --- .../llvm}/CodeGen/RegAllocPriorityAdvisor.h | 78 +++- llvm/include/llvm/InitializePasses.h | 2 +- .../llvm/Passes/MachinePassRegistry.def | 1 + llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp | 6 +- .../lib/CodeGen/MLRegAllocPriorityAdvisor.cpp | 184 +++--- llvm/lib/CodeGen/RegAllocEvictionAdvisor.cpp | 2 +- llvm/lib/CodeGen/RegAllocGreedy.cpp | 9 +- llvm/lib/CodeGen/RegAllocGreedy.h | 2 +- llvm/lib/CodeGen/RegAllocPriorityAdvisor.cpp | 155 +++ llvm/lib/Passes/PassBuilder.cpp | 1 + 10 files changed, 320 insertions(+), 120 deletions(-) rename llvm/{lib => include/llvm}/CodeGen/RegAllocPriorityAdvisor.h (57%) diff --git a/llvm/lib/CodeGen/RegAllocPriorityAdvisor.h b/llvm/include/llvm/CodeGen/RegAllocPriorityAdvisor.h similarity index 57% rename from llvm/lib/CodeGen/RegAllocPriorityAdvisor.h rename to llvm/include/llvm/CodeGen/RegAllocPriorityAdvisor.h index 0758743c2b1403..a53739fdc3fc40 100644 --- a/llvm/lib/CodeGen/RegAllocPriorityAdvisor.h +++ b/llvm/include/llvm/CodeGen/RegAllocPriorityAdvisor.h @@ -9,8 +9,10 @@ #ifndef LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H #define LLVM_CODEGEN_REGALLOCPRIORITYADVISOR_H +#include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/RegAllocEvictionAdvisor.h" #include "llvm/CodeGen/SlotIndexes.h" +#include "llvm/IR/PassManager.h" #include "llvm/Pass.h" namespace llvm { @@ -68,12 +70,72 @@ class DummyPriorityAdvisor : public RegAllocPriorityAdvisor { unsigned getPriority(const LiveInterval &LI) const override; }; -class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { +/// Common provider for getting the priority advisor and logging rewards. +/// Legacy analysis forwards all calls to this provider. +/// New analysis serves the provider as the analysis result. +/// Expensive setup is done in the constructor, so that the advisor can be +/// created quickly for every machine function. +/// TODO: Remove once legacy PM support is dropped. +class RegAllocPriorityAdvisorProvider { public: enum class AdvisorMode : int { Default, Release, Development, Dummy }; - RegAllocPriorityAdvisorAnalysis(AdvisorMode Mode) - : ImmutablePass(ID), Mode(Mode){}; + RegAllocPriorityAdvisorProvider(AdvisorMode Mode) : Mode(Mode) {} + + virtual ~RegAllocPriorityAdvisorProvider() = default; + + virtual void logRewardIfNeeded(const MachineFunction &MF, + llvm::function_ref GetReward) {}; + + virtual std::unique_ptr + getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0; + + void setAnalyses(SlotIndexes *SI) { this->SI = SI; } + + AdvisorMode getAdvisorMode() const { return Mode; } + +protected: + SlotIndexes *SI; + +private: + const AdvisorMode Mode; +}; + +RegAllocPriorityAdvisorProvider *createReleaseModePriorityAdvisorProvider(); + +RegAllocPriorityAdvisorProvider * +createDevelopmentModePriorityAdvisorProvider(LLVMContext &Ctx); + +class RegAllocPriorityAdvisorAnalysis +: public AnalysisInfoMixin { + static AnalysisKey Key; + friend AnalysisInfoMixin; + +public: + struct Result { +// Owned by this analysis. +RegAllocPriorityAdvisorProvider *Provider; + +bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, +MachineFunctionAnalysisManager::Invalidator &Inv) { + auto PAC = PA.getChecker(); + return !PAC.preservedWhenStateless() || + Inv.invalidate(MF, PA); +} + }; + + Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); + +private: + void initializeProvider(LLVMContext &Ctx); + std::unique_ptr Provider; +}; + +class RegAllocPriorityAdvisorAnalysisLegacy : public ImmutablePass { +public: + using AdvisorMode = RegAllocPriorityAdvisorProvider::AdvisorMode; + RegAllocPriorityAdvisorAnalysisLegacy(AdvisorMode Mode) + : ImmutablePass(ID), Mode(Mode) {}; static char ID; /// Get an advisor for the given context (i.e. machine function, etc) @@ -81,7 +143,7 @@ class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { getAdvisor(const MachineFunction &MF, const RAGreedy &RA) = 0; AdvisorMode getAdvisorMode() const { return Mode; } virtual void logRewardIfNeeded(const MachineFunction &MF, - llvm::function_ref GetReward){}; + llvm::function_ref GetReward) {}; protected: // This analysis preserves everything, and subclasses may have additional @@ -97,11 +159,13 @@ class RegAllocPriorityAdvisorAnalysis : public ImmutablePass { /// Specialization for the API used by the analysis infrastructure to create /// an instan
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocGreedy to NPM (PR #119540)
https://github.com/optimisan edited https://github.com/llvm/llvm-project/pull/119540 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [RegAlloc][NewPM] Plug Greedy RA in codegen pipeline (PR #120557)
https://github.com/optimisan updated https://github.com/llvm/llvm-project/pull/120557 >From 7325b329a27eacbca5d45f7245ce12120745627e Mon Sep 17 00:00:00 2001 From: Akshat Oke Date: Wed, 11 Dec 2024 10:57:21 + Subject: [PATCH 1/4] [RegAlloc][NewPM] Plug Greedy RA in codegen pipeline --- llvm/include/llvm/Passes/CodeGenPassBuilder.h | 18 +++- .../llvm/Passes/MachinePassRegistry.def | 4 ++-- .../include/llvm/Target/CGPassBuilderOption.h | 2 +- llvm/lib/Passes/PassBuilder.cpp | 13 ...plicit-def-remat-requires-impdef-check.mir | 1 + ...implicit-def-with-impdef-greedy-assert.mir | 1 + llvm/test/CodeGen/AArch64/pr51516.mir | 1 + llvm/test/CodeGen/AArch64/spill-fold.mir | 2 ++ .../extend-phi-subrange-not-in-parent.mir | 1 + llvm/test/CodeGen/MIR/Generic/runPass.mir | 1 + .../SystemZ/clear-liverange-spillreg.mir | 1 + llvm/test/CodeGen/Thumb/high-reg-clobber.mir | 1 + llvm/test/CodeGen/X86/limit-split-cost.mir| 1 + .../test/tools/llc/new-pm/regalloc-amdgpu.mir | 17 +-- llvm/tools/llc/NewPMDriver.cpp| 21 +++ 15 files changed, 71 insertions(+), 14 deletions(-) diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h index aca9b3b888acc3..971217923f7ef1 100644 --- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h +++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h @@ -1056,7 +1056,7 @@ void CodeGenPassBuilder::addMachineSSAOptimization( /// /// A target that uses the standard regalloc pass order for fast or optimized /// allocation may still override this for per-target regalloc -/// selection. But -regalloc=... always takes precedence. +/// selection. But -regalloc-npm=... always takes precedence. template void CodeGenPassBuilder::addTargetRegisterAllocator( AddMachinePass &addPass, bool Optimized) const { @@ -1073,6 +1073,22 @@ template void CodeGenPassBuilder::addRegAllocPass( AddMachinePass &addPass, bool Optimized) const { // TODO: Parse Opt.RegAlloc to add register allocator. + // Use the specified -regalloc-npm={basic|greedy|fast|pbqp} + if (Opt.RegAlloc > RegAllocType::Default) { +switch (Opt.RegAlloc) { + case RegAllocType::Fast: +addPass(RegAllocFastPass()); +break; + case RegAllocType::Greedy: +addPass(RAGreedyPass()); +break; + default: +llvm_unreachable("Register allocator not supported yet."); +} +return; + } + // -regalloc=default or unspecified, so pick based on the optimization level. + derived().addTargetRegisterAllocator(addPass, Optimized); } template diff --git a/llvm/include/llvm/Passes/MachinePassRegistry.def b/llvm/include/llvm/Passes/MachinePassRegistry.def index fa7f769f31fdde..1c89fb0eb8dbb1 100644 --- a/llvm/include/llvm/Passes/MachinePassRegistry.def +++ b/llvm/include/llvm/Passes/MachinePassRegistry.def @@ -188,12 +188,12 @@ MACHINE_FUNCTION_PASS_WITH_PARAMS( }, "filter=reg-filter;no-clear-vregs") +// 'all' is the default filter MACHINE_FUNCTION_PASS_WITH_PARAMS( "greedy", "RAGreedyPass", [](RAGreedyPass::Options Opts) { return RAGreedyPass(Opts); }, [PB = this](StringRef Params) { - // TODO: parseRegAllocGreedyFilterFunc(*PB, Params); - return Expected(RAGreedyPass::Options{}); + return parseRegAllocGreedyFilterFunc(*PB, Params); }, "reg-filter" ) #undef MACHINE_FUNCTION_PASS_WITH_PARAMS diff --git a/llvm/include/llvm/Target/CGPassBuilderOption.h b/llvm/include/llvm/Target/CGPassBuilderOption.h index d3d19c8a7dc9f2..c7c1572bcde603 100644 --- a/llvm/include/llvm/Target/CGPassBuilderOption.h +++ b/llvm/include/llvm/Target/CGPassBuilderOption.h @@ -52,7 +52,7 @@ struct CGPassBuilderOption { bool RequiresCodeGenSCCOrder = false; RunOutliner EnableMachineOutliner = RunOutliner::TargetDefault; - StringRef RegAlloc = "default"; + RegAllocType RegAlloc = RegAllocType::Default; std::optional EnableGlobalISelAbort; std::string FSProfileFile; std::string FSRemappingFile; diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 3a9db2dbd59226..769d3b0a20f964 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1316,6 +1316,19 @@ parseBoundsCheckingOptions(StringRef Params) { return Options; } +Expected parseRegAllocGreedyFilterFunc(PassBuilder &PB, StringRef Params) { + if (Params.empty() || Params == "all") { +return RAGreedyPass::Options(); + } + std::optional Filter = PB.parseRegAllocFilter(Params); + if (!Filter) { +return make_error( +formatv("invalid regallocgreedy register filter '{0}' ", Params).str(), +inconvertibleErrorCode()); + } + return RAGreedyPass::Options{*Filter, Params}; +} + } // namespace /// Tests whether a pass name starts with a valid prefix for a default pipeline diff --git a/llvm/test/CodeGen/AArch64/imp
[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for loop statements (PR #113109)
https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113109 >From 5d19c77551c6fc585d1b15c4c2a71c3c3f99ef8a Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Fri, 18 Oct 2024 09:33:51 +0900 Subject: [PATCH 1/4] [Coverage][Single] Enable Branch coverage for loop statements --- clang/lib/CodeGen/CGStmt.cpp | 82 --- clang/lib/CodeGen/CodeGenFunction.cpp | 11 +- clang/lib/CodeGen/CodeGenPGO.cpp | 79 +-- clang/lib/CodeGen/CoverageMappingGen.cpp | 130 +- .../CoverageMapping/single-byte-counters.cpp | 53 +++ 5 files changed, 97 insertions(+), 258 deletions(-) diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index dbc1ce9bf993cd..7d778ce58a1487 100644 --- a/clang/lib/CodeGen/CGStmt.cpp +++ b/clang/lib/CodeGen/CGStmt.cpp @@ -1039,15 +1039,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, SourceLocToDebugLoc(R.getEnd()), checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S))); - // When single byte coverage mode is enabled, add a counter to loop condition. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(S.getCond()); - // As long as the condition is true, go to the loop body. llvm::BasicBlock *LoopBody = createBasicBlock("while.body"); if (EmitBoolCondBranch) { llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); -if (ConditionScope.requiresCleanups()) +if (getIsCounterPair(&S).second || ConditionScope.requiresCleanups()) ExitBlock = createBasicBlock("while.exit"); llvm::MDNode *Weights = createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody())); @@ -1058,6 +1054,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); + incrementProfileCounter(true, &S); EmitBranchThroughCleanup(LoopExit); } } else if (const Attr *A = Stmt::getLikelihoodAttr(S.getBody())) { @@ -1075,11 +1072,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, { RunCleanupsScope BodyScope(*this); EmitBlock(LoopBody); -// When single byte coverage mode is enabled, add a counter to the body. -if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getBody()); -else - incrementProfileCounter(&S); +incrementProfileCounter(false, &S); EmitStmt(S.getBody()); } @@ -1099,13 +1092,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, // The LoopHeader typically is just a branch if we skipped emitting // a branch, try to erase it. - if (!EmitBoolCondBranch) + if (!EmitBoolCondBranch) { SimplifyForwardingBlocks(LoopHeader.getBlock()); - - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(&S); +PGO.markStmtAsUsed(true, &S); + } if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); @@ -1124,10 +1114,7 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, // Emit the body of the loop. llvm::BasicBlock *LoopBody = createBasicBlock("do.body"); - if (llvm::EnableSingleByteCoverage) -EmitBlockWithFallThrough(LoopBody, S.getBody()); - else -EmitBlockWithFallThrough(LoopBody, &S); + EmitBlockWithFallThrough(LoopBody, &S); if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.push_back( @@ -1139,9 +1126,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, } EmitBlock(LoopCond.getBlock()); - // When single byte coverage mode is enabled, add a counter to loop condition. - if (llvm::EnableSingleByteCoverage) -incrementProfileCounter(S.getCond()); // C99 6.8.5.2: "The evaluation of the controlling expression takes place // after each execution of the loop body." @@ -1164,16 +1148,25 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, SourceLocToDebugLoc(R.getEnd()), checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S))); + auto *LoopFalse = + (getIsCounterPair(&S).second ? createBasicBlock("do.loopfalse") + : LoopExit.getBlock()); + // As long as the condition is true, iterate the loop. if (EmitBoolCondBranch) { uint64_t BackedgeCount = getProfileCount(S.getBody()) - ParentCount; Builder.CreateCondBr( -BoolCondVal, LoopBody, LoopExit.getBlock(), +BoolCondVal, LoopBody, LoopFalse, createProfileWeightsForLoop(S.getCond(), BackedgeCount)); } LoopStack.pop(); + if (LoopFalse != LoopExit.getBlock()) { +EmitBlock(LoopFalse); +incrementProfileCounter(true, &S, true); + } + // Emit the exit block. EmitBlock(LoopExit.getBlock()); @@ -1182,11 +1175,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, if (!EmitBoolCondBranch) SimplifyForwardingBlocks(LoopCond.getBlock());
[llvm-branch-commits] [clang] [compiler-rt] [llvm] [Coverage][Single] Enable Branch coverage for loop statements (PR #113109)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/113109 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [CodeGen][NewPM] Port RegAllocEvictionAdvisor analysis to NPM (PR #117309)
@@ -59,59 +62,102 @@ cl::opt EvictInterferenceCutoff( #define LLVM_HAVE_TF_AOT #endif -char RegAllocEvictionAdvisorAnalysis::ID = 0; -INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysis, "regalloc-evict", +char RegAllocEvictionAdvisorAnalysisLegacy::ID = 0; +INITIALIZE_PASS(RegAllocEvictionAdvisorAnalysisLegacy, "regalloc-evict", "Regalloc eviction policy", false, true) namespace { -class DefaultEvictionAdvisorAnalysis final -: public RegAllocEvictionAdvisorAnalysis { +class DefaultEvictionAdvisorProvider final +: public RegAllocEvictionAdvisorProvider { public: - DefaultEvictionAdvisorAnalysis(bool NotAsRequested) - : RegAllocEvictionAdvisorAnalysis(AdvisorMode::Default), -NotAsRequested(NotAsRequested) {} + DefaultEvictionAdvisorProvider(bool NotAsRequested, LLVMContext &Ctx) + : RegAllocEvictionAdvisorProvider(AdvisorMode::Default, Ctx) { +if (NotAsRequested) + Ctx.emitError("Requested regalloc eviction advisor analysis " +"could not be created. Using default"); + } // support for isa<> and dyn_cast. - static bool classof(const RegAllocEvictionAdvisorAnalysis *R) { + static bool classof(const RegAllocEvictionAdvisorProvider *R) { return R->getAdvisorMode() == AdvisorMode::Default; } -private: std::unique_ptr - getAdvisor(const MachineFunction &MF, const RAGreedy &RA) override { + getAdvisor(const MachineFunction &MF, const RAGreedy &RA, + MachineBlockFrequencyInfo *, MachineLoopInfo *) override { return std::make_unique(MF, RA); } +}; + +class DefaultEvictionAdvisorAnalysisLegacy final +: public RegAllocEvictionAdvisorAnalysisLegacy { +public: + DefaultEvictionAdvisorAnalysisLegacy(bool NotAsRequested) + : RegAllocEvictionAdvisorAnalysisLegacy(AdvisorMode::Default), +NotAsRequested(NotAsRequested) {} + bool doInitialization(Module &M) override { -if (NotAsRequested) - M.getContext().emitError("Requested regalloc eviction advisor analysis " - "could not be created. Using default"); -return RegAllocEvictionAdvisorAnalysis::doInitialization(M); +Provider.reset( +new DefaultEvictionAdvisorProvider(NotAsRequested, M.getContext())); +return false; } + + // support for isa<> and dyn_cast. + static bool classof(const RegAllocEvictionAdvisorAnalysisLegacy *R) { +return R->getAdvisorMode() == AdvisorMode::Default; + } + +private: const bool NotAsRequested; }; } // namespace -template <> Pass *llvm::callDefaultCtor() { +AnalysisKey RegAllocEvictionAdvisorAnalysis::Key; + +void RegAllocEvictionAdvisorAnalysis::initializeProvider( +RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode Mode, LLVMContext &Ctx) { + if (Provider) +return; + if (Mode == RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default) +Provider.reset( +new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/false, Ctx)); + else +initializeMLProvider(Mode, Ctx); + if (!Provider) +Provider.reset( +new DefaultEvictionAdvisorProvider(/*NotAsRequested=*/true, Ctx)); optimisan wrote: Reverting to one switch case https://github.com/llvm/llvm-project/pull/117309 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [Multilib] Custom flags processing for library selection (PR #110659)
https://github.com/vhscampos updated https://github.com/llvm/llvm-project/pull/110659 >From 2fe418964fff9e03861650afb89a81ac80f1413d Mon Sep 17 00:00:00 2001 From: Victor Campos Date: Thu, 26 Sep 2024 14:44:33 +0100 Subject: [PATCH 1/5] [Multilib] Custom flags processing for library selection Select library variants in the multilib system using the flags passed following the '-fmultilib-flag=' format. Multilib flags that were not passed in the command-line have their default value fed into the library selection mechanism. A warning is shown if the flag's value name is invalid. If the wrong name is close enough to any valid one, according to edit distance, the closest valid value name is suggested. Details about this change can be found in this thread: https://discourse.llvm.org/t/rfc-multilib-custom-flags/81058 --- clang/include/clang/Driver/Driver.h | 2 +- clang/include/clang/Driver/Multilib.h | 11 +- clang/include/clang/Driver/ToolChain.h| 7 + clang/lib/Driver/Driver.cpp | 141 ++ clang/lib/Driver/Multilib.cpp | 136 - clang/lib/Driver/ToolChains/BareMetal.cpp | 22 ++- clang/lib/Driver/ToolChains/BareMetal.h | 5 + .../baremetal-multilib-custom-flags.yaml | 79 ++ 8 files changed, 328 insertions(+), 75 deletions(-) create mode 100644 clang/test/Driver/baremetal-multilib-custom-flags.yaml diff --git a/clang/include/clang/Driver/Driver.h b/clang/include/clang/Driver/Driver.h index c23d037e725bb9..80be9261ec40f7 100644 --- a/clang/include/clang/Driver/Driver.h +++ b/clang/include/clang/Driver/Driver.h @@ -466,7 +466,7 @@ class Driver { /// ArgList. llvm::opt::InputArgList ParseArgStrings(ArrayRef Args, bool UseDriverMode, - bool &ContainsError); + bool &ContainsError) const; /// BuildInputs - Construct the list of inputs and their types from /// the given arguments. diff --git a/clang/include/clang/Driver/Multilib.h b/clang/include/clang/Driver/Multilib.h index 1dab45c062aeec..36bdfdb6157b0b 100644 --- a/clang/include/clang/Driver/Multilib.h +++ b/clang/include/clang/Driver/Multilib.h @@ -163,9 +163,18 @@ class MultilibSet { const_iterator begin() const { return Multilibs.begin(); } const_iterator end() const { return Multilibs.end(); } + /// Process custom flags from \p Flags and returns an expanded flags list and + /// a list of extra compilation arguments. + /// Returns a pair where: + /// - first: the new flags list including custom flags after processing. + /// - second: the extra compilation arguments to be fed to the driver. + std::pair> + processCustomFlags(const Driver &D, const Multilib::flags_list &Flags) const; + /// Select compatible variants, \returns false if none are compatible bool select(const Driver &D, const Multilib::flags_list &Flags, - llvm::SmallVectorImpl &) const; + llvm::SmallVectorImpl &, + llvm::SmallVector * = nullptr) const; unsigned size() const { return Multilibs.size(); } diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index 5347e29be91439..25f51b7de3e9f5 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -686,6 +686,13 @@ class ToolChain { /// Add warning options that need to be passed to cc1 for this target. virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const; + // Get the list of extra driver arguments strings requested by the multilib + // configuration. + virtual SmallVector + getMultilibDriverArgsStr(llvm::opt::ArgList &Args) const { +return {}; + }; + // GetRuntimeLibType - Determine the runtime library type to use with the // given compilation arguments. virtual RuntimeLibType diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index fb73b62cf2daed..761876b9fcc53b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -262,7 +262,7 @@ void Driver::setDriverMode(StringRef Value) { } InputArgList Driver::ParseArgStrings(ArrayRef ArgStrings, - bool UseDriverMode, bool &ContainsError) { + bool UseDriverMode, bool &ContainsError) const { llvm::PrettyStackTraceString CrashInfo("Command line argument parsing"); ContainsError = false; @@ -1272,8 +1272,8 @@ Compilation *Driver::BuildCompilation(ArrayRef ArgList) { bool HasConfigFileTail = !ContainsError && CfgOptionsTail; // All arguments, from both config file and command line. - InputArgList Args = - HasConfigFileHead ? std::move(*CfgOptionsHead) : std::move(*CLOptions); + auto UArgs = std::make_unique(HasConfigFileHead ? std::move(*CfgOptionsHead) : std::move(*CLOptions)); + InputArgList &Args =
[llvm-branch-commits] [clang] [Multilib] Custom flags processing for library selection (PR #110659)
@@ -92,12 +93,141 @@ MultilibSet &MultilibSet::FilterOut(FilterCallback F) { void MultilibSet::push_back(const Multilib &M) { Multilibs.push_back(M); } -bool MultilibSet::select(const Driver &D, const Multilib::flags_list &Flags, - llvm::SmallVectorImpl &Selected) const { - llvm::StringSet<> FlagSet(expandFlags(Flags)); +static void DiagnoseUnclaimedMultilibCustomFlags( +const Driver &D, const SmallVector &UnclaimedCustomFlagValues, +const SmallVector &CustomFlagDecls) { + struct EditDistanceInfo { +StringRef FlagValue; +unsigned EditDistance; + }; + const unsigned MaxEditDistance = 5; + + for (StringRef Unclaimed : UnclaimedCustomFlagValues) { +std::optional BestCandidate; +for (const auto &Decl : CustomFlagDecls) { + for (const auto &Value : Decl->ValueList) { +const std::string &FlagValueName = Value.Name; +unsigned EditDistance = +Unclaimed.edit_distance(FlagValueName, /*AllowReplacements=*/true, +/*MaxEditDistance=*/MaxEditDistance); +if (!BestCandidate || (EditDistance <= MaxEditDistance && + EditDistance < BestCandidate->EditDistance)) { + BestCandidate = {FlagValueName, EditDistance}; +} + } +} +if (!BestCandidate) + D.Diag(clang::diag::err_drv_unsupported_opt) + << (custom_flag::Prefix + Unclaimed).str(); +else + D.Diag(clang::diag::err_drv_unsupported_opt_with_suggestion) + << (custom_flag::Prefix + Unclaimed).str() + << (custom_flag::Prefix + BestCandidate->FlagValue).str(); + } +} + +namespace clang::driver::custom_flag { +// Map implemented using linear searches as the expected size is too small for +// the overhead of a search tree or a hash table. +class ValueNameToDetailMap { + SmallVector> Mapping; + +public: + template + ValueNameToDetailMap(It FlagDeclsBegin, It FlagDeclsEnd) { +for (auto DeclIt = FlagDeclsBegin; DeclIt != FlagDeclsEnd; ++DeclIt) { + const DeclarationPtr &Decl = *DeclIt; + for (const auto &Value : Decl->ValueList) +Mapping.emplace_back(Value.Name, &Value); +} + } + + const ValueDetail *get(StringRef Key) const { +auto Iter = llvm::find_if( +Mapping, [&](const auto &Pair) { return Pair.first == Key; }); +return Iter != Mapping.end() ? Iter->second : nullptr; + } +}; +} // namespace clang::driver::custom_flag + +std::pair> +MultilibSet::processCustomFlags(const Driver &D, +const Multilib::flags_list &Flags) const { + Multilib::flags_list Result; + SmallVector MacroDefines; + + // Custom flag values detected in the flags list + SmallVector ClaimedCustomFlagValues; + + // Arguments to -fmultilib-flag= that don't correspond to any valid + // custom flag value. An error will be printed out for each of these. + SmallVector UnclaimedCustomFlagValueStrs; + + const auto ValueNameToValueDetail = custom_flag::ValueNameToDetailMap( + CustomFlagDecls.begin(), CustomFlagDecls.end()); + + for (StringRef Flag : Flags) { +if (!Flag.starts_with(custom_flag::Prefix)) { + Result.push_back(Flag.str()); + continue; +} + +StringRef CustomFlagValueStr = Flag.substr(custom_flag::Prefix.size()); +const custom_flag::ValueDetail *Detail = +ValueNameToValueDetail.get(CustomFlagValueStr); +if (Detail) + ClaimedCustomFlagValues.push_back(Detail); +else + UnclaimedCustomFlagValueStrs.push_back(CustomFlagValueStr); + } + + // Set of custom flag declarations for which a value was passed in the flags + // list. This is used to, firstly, detect multiple values for the same flag + // declaration (in this case, the last one wins), and secondly, to detect + // which declarations had no value passed in (in this case, the default value + // is selected). + llvm::SmallSet TriggeredCustomFlagDecls; + + // Detect multiple values for the same flag declaration. Last one wins. + for (auto *CustomFlagValue : llvm::reverse(ClaimedCustomFlagValues)) { +if (!TriggeredCustomFlagDecls.insert(CustomFlagValue->Decl).second) + continue; +Result.push_back(std::string(custom_flag::Prefix) + CustomFlagValue->Name); +if (CustomFlagValue->MacroDefines) + MacroDefines.append(CustomFlagValue->MacroDefines->begin(), + CustomFlagValue->MacroDefines->end()); + } + + // Detect flag declarations with no value passed in. Select default value. + for (const auto &Decl : CustomFlagDecls) { +if (TriggeredCustomFlagDecls.contains(Decl)) + continue; +custom_flag::ValueDetail &CustomFlagValue = +Decl->ValueList[*Decl->DefaultValueIdx]; +Result.push_back(std::string(custom_flag::Prefix) + CustomFlagValue.Name); +if (CustomFlagValue.MacroDefines) + MacroDefines.append(CustomFlagValue.MacroDefines->begin(), + CustomFlagValue.MacroDefines->
[llvm-branch-commits] [clang] [llvm] [mlir] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode (PR #116051)
https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/116051 >From 76b2b9f55e73a533e2a6aa0c98ebb1509e2d7dbd Mon Sep 17 00:00:00 2001 From: Sergio Afonso Date: Wed, 27 Nov 2024 11:33:01 + Subject: [PATCH] [OMPIRBuilder] Support runtime number of teams and threads, and SPMD mode This patch introduces a `TargetKernelRuntimeAttrs` structure to hold host-evaluated `num_teams`, `thread_limit`, `num_threads` and trip count values passed to the runtime kernel offloading call. Additionally, kernel type information is used to influence target device code generation and the `IsSPMD` flag is replaced by `ExecFlags`, which provide more granularity. --- clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp | 5 +- .../llvm/Frontend/OpenMP/OMPIRBuilder.h | 37 ++- llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 129 ++--- .../Frontend/OpenMPIRBuilderTest.cpp | 263 +- .../OpenMP/OpenMPToLLVMIRTranslation.cpp | 12 +- 5 files changed, 385 insertions(+), 61 deletions(-) diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp index 654a13d75ec810..1e2e693d91de72 100644 --- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp +++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp @@ -20,6 +20,7 @@ #include "clang/AST/StmtVisitor.h" #include "clang/Basic/Cuda.h" #include "llvm/ADT/SmallPtrSet.h" +#include "llvm/Frontend/OpenMP/OMPDeviceConstants.h" #include "llvm/Frontend/OpenMP/OMPGridValues.h" using namespace clang; @@ -745,7 +746,9 @@ void CGOpenMPRuntimeGPU::emitKernelInit(const OMPExecutableDirective &D, CodeGenFunction &CGF, EntryFunctionState &EST, bool IsSPMD) { llvm::OpenMPIRBuilder::TargetKernelDefaultAttrs Attrs; - Attrs.IsSPMD = IsSPMD; + Attrs.ExecFlags = + IsSPMD ? llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_SPMD + : llvm::omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC; computeMinAndMaxThreadsAndTeams(D, CGF, Attrs); CGBuilderTy &Bld = CGF.Builder; diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h index 8ca3bc08b5ad49..25c5dee0376027 100644 --- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h +++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h @@ -1389,9 +1389,6 @@ class OpenMPIRBuilder { /// Supporting functions for Reductions CodeGen. private: - /// Emit the llvm.used metadata. - void emitUsed(StringRef Name, std::vector &List); - /// Get the id of the current thread on the GPU. Value *getGPUThreadID(); @@ -2013,6 +2010,13 @@ class OpenMPIRBuilder { /// Value. GlobalValue *createGlobalFlag(unsigned Value, StringRef Name); + /// Emit the llvm.used metadata. + void emitUsed(StringRef Name, ArrayRef List); + + /// Emit the kernel execution mode. + GlobalVariable *emitKernelExecutionMode(StringRef KernelName, + omp::OMPTgtExecModeFlags Mode); + /// Generate control flow and cleanup for cancellation. /// /// \param CancelFlag Flag indicating if the cancellation is performed. @@ -2233,13 +2237,33 @@ class OpenMPIRBuilder { /// time. The number of max values will be 1 except for the case where /// ompx_bare is set. struct TargetKernelDefaultAttrs { -bool IsSPMD = false; +omp::OMPTgtExecModeFlags ExecFlags = omp::OMPTgtExecModeFlags::OMP_TGT_EXEC_MODE_GENERIC; SmallVector MaxTeams = {-1}; int32_t MinTeams = 1; SmallVector MaxThreads = {-1}; int32_t MinThreads = 1; }; + /// Container to pass LLVM IR runtime values or constants related to the + /// number of teams and threads with which the kernel must be launched, as + /// well as the trip count of the loop, if it is an SPMD or Generic-SPMD + /// kernel. These must be defined in the host prior to the call to the kernel + /// launch OpenMP RTL function. + struct TargetKernelRuntimeAttrs { +SmallVector MaxTeams = {nullptr}; +Value *MinTeams = nullptr; +SmallVector TargetThreadLimit = {nullptr}; +SmallVector TeamsThreadLimit = {nullptr}; + +/// 'parallel' construct 'num_threads' clause value, if present and it is an +/// SPMD kernel. +Value *MaxThreads = nullptr; + +/// Total number of iterations of the SPMD or Generic-SPMD kernel or null if +/// it is a generic kernel. +Value *LoopTripCount = nullptr; + }; + /// Data structure that contains the needed information to construct the /// kernel args vector. struct TargetKernelArgs { @@ -2971,7 +2995,9 @@ class OpenMPIRBuilder { /// \param CodeGenIP The insertion point where the call to the outlined /// function should be emitted. /// \param EntryInfo The entry information about the function. - /// \param DefaultAttrs Structure containing the default numbers of threads + /// \param DefaultAttrs Structure containing the default attributes, including
[llvm-branch-commits] [llvm] [TRI] Remove reserved registers in getRegPressureSetLimit (PR #118787)
wangpc-pp wrote: Ping. https://github.com/llvm/llvm-project/pull/118787 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [mlir] [Flang][OpenMP] Lowering of host-evaluated clauses (PR #116219)
https://github.com/skatrak updated https://github.com/llvm/llvm-project/pull/116219 >From 65d6b2f57327adbc0ecd5600f633f557bcce313d Mon Sep 17 00:00:00 2001 From: Sergio Afonso Date: Thu, 14 Nov 2024 12:24:15 + Subject: [PATCH] [Flang][OpenMP] Lowering of host-evaluated clauses This patch adds support for lowering OpenMP clauses and expressions attached to constructs nested inside of a target region that need to be evaluated in the host device. This is done through the use of the `OpenMP_HostEvalClause` `omp.target` set of operands and entry block arguments. When lowering clauses for a target construct, a more involved `processHostEvalClauses()` function is called, which looks at the current and potentially other nested constructs in order to find and lower clauses that need to be processed outside of the `omp.target` operation under construction. This populates an instance of a global structure with the resulting MLIR values. The resulting list of host-evaluated values is used to initialize the `host_eval` operands when constructing the `omp.target` operation, and then replaced with the corresponding block arguments after creating that operation's region. Afterwards, while lowering nested operations, those that might potentially be evaluated in the host (e.g. `num_teams`, `thread_limit`, `num_threads` and `collapse`) check first whether there is an active global host-evaluated information structure and whether it holds values referring to these clauses. If that is the case, the stored values (referring to `omp.target` entry block arguments at that stage) are used instead of lowering clauses again. --- flang/include/flang/Common/OpenMP-utils.h | 20 +- flang/lib/Common/OpenMP-utils.cpp | 9 +- flang/lib/Lower/OpenMP/OpenMP.cpp | 449 +- flang/test/Lower/OpenMP/host-eval.f90 | 157 ++ flang/test/Lower/OpenMP/target-spmd.f90 | 191 .../Dialect/OpenMP/OpenMPClauseOperands.h | 6 + 6 files changed, 805 insertions(+), 27 deletions(-) create mode 100644 flang/test/Lower/OpenMP/host-eval.f90 create mode 100644 flang/test/Lower/OpenMP/target-spmd.f90 diff --git a/flang/include/flang/Common/OpenMP-utils.h b/flang/include/flang/Common/OpenMP-utils.h index e6a3f1bac1c605..a65629834c6ff9 100644 --- a/flang/include/flang/Common/OpenMP-utils.h +++ b/flang/include/flang/Common/OpenMP-utils.h @@ -34,6 +34,7 @@ struct EntryBlockArgsEntry { /// Structure holding the information needed to create and bind entry block /// arguments associated to all clauses that can define them. struct EntryBlockArgs { + llvm::ArrayRef hostEvalVars; EntryBlockArgsEntry inReduction; EntryBlockArgsEntry map; EntryBlockArgsEntry priv; @@ -49,18 +50,25 @@ struct EntryBlockArgs { } auto getSyms() const { -return llvm::concat( -inReduction.syms, map.syms, priv.syms, reduction.syms, -taskReduction.syms, useDeviceAddr.syms, useDevicePtr.syms); +return llvm::concat(inReduction.syms, +map.syms, priv.syms, reduction.syms, taskReduction.syms, +useDeviceAddr.syms, useDevicePtr.syms); } auto getVars() const { -return llvm::concat(inReduction.vars, map.vars, -priv.vars, reduction.vars, taskReduction.vars, useDeviceAddr.vars, -useDevicePtr.vars); +return llvm::concat(hostEvalVars, inReduction.vars, +map.vars, priv.vars, reduction.vars, taskReduction.vars, +useDeviceAddr.vars, useDevicePtr.vars); } }; +/// Create an entry block for the given region, including the clause-defined +/// arguments specified. +/// +/// \param [in] builder - MLIR operation builder. +/// \param [in] rgs - entry block arguments information for the given +/// operation. +/// \param [in] region - Empty region in which to create the entry block. mlir::Block *genEntryBlock( mlir::OpBuilder &builder, const EntryBlockArgs &args, mlir::Region ®ion); } // namespace Fortran::common::openmp diff --git a/flang/lib/Common/OpenMP-utils.cpp b/flang/lib/Common/OpenMP-utils.cpp index f5115f475d6a19..47e89fe6dd1ee9 100644 --- a/flang/lib/Common/OpenMP-utils.cpp +++ b/flang/lib/Common/OpenMP-utils.cpp @@ -18,10 +18,10 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args, llvm::SmallVector types; llvm::SmallVector locs; - unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() + - args.priv.vars.size() + args.reduction.vars.size() + - args.taskReduction.vars.size() + args.useDeviceAddr.vars.size() + - args.useDevicePtr.vars.size(); + unsigned numVars = args.hostEvalVars.size() + args.inReduction.vars.size() + + args.map.vars.size() + args.priv.vars.size() + + args.reduction.vars.size() + args.taskReduction.vars.size() + + args.useDeviceAddr.vars.size() + args.useDevicePtr.vars.size(); types.reserve(numVars); locs.reserve(numVars); @@ -34,6 +34,7 @@ mlir::Block *genEnt
[llvm-branch-commits] [flang] [llvm] [Flang][NFC] Move runtime library files to flang-rt. (PR #110298)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/110298 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [Flang] Optionally do not compile the runtime in-tree (PR #122336)
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/122336 Introduce the CMake switch FLANG_INCLUDE_RUNTIME. When set to off, do not add build instructions for the runtime. This is required for Flang-RT (#110217) and the current runtime CMake code to exist at the same time. When using `LLVM_ENABLE_RUNTIME=flang-rt`, the in-tree build instructions are in conflict and must be disabled. Extracted out of #110217 >From dd3ac2e6d8d8d57cd639c25bea3b8d5c99a2f81e Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 9 Jan 2025 15:58:48 +0100 Subject: [PATCH 1/3] Introduce FLANG_INCLUDE_RUNTIME --- flang/CMakeLists.txt| 7 +++- flang/test/CMakeLists.txt | 6 +++- flang/test/Driver/ctofortran.f90| 1 + flang/test/Driver/exec.f90 | 1 + flang/test/Runtime/no-cpp-dep.c | 2 +- flang/test/lit.cfg.py | 5 ++- flang/test/lit.site.cfg.py.in | 1 + flang/tools/f18/CMakeLists.txt | 4 +-- flang/unittests/CMakeLists.txt | 6 ++-- flang/unittests/Evaluate/CMakeLists.txt | 46 ++--- 10 files changed, 50 insertions(+), 29 deletions(-) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index 68947eaa9c9bd7..69e963a43d0b97 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -233,6 +233,9 @@ else() include_directories(SYSTEM ${MLIR_TABLEGEN_OUTPUT_DIR}) endif() +option(FLANG_INCLUDE_RUNTIME "Build the runtime in-tree (deprecated; to be replaced with LLVM_ENABLE_RUNTIMES=flang-rt)" ON) +pythonize_bool(FLANG_INCLUDE_RUNTIME) + set(FLANG_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH "Path for binary subdirectory (defaults to '${CMAKE_INSTALL_BINDIR}')") mark_as_advanced(FLANG_TOOLS_INSTALL_DIR) @@ -473,7 +476,9 @@ if (FLANG_CUF_RUNTIME) find_package(CUDAToolkit REQUIRED) endif() -add_subdirectory(runtime) +if (FLANG_INCLUDE_RUNTIME) + add_subdirectory(runtime) +endif () if (LLVM_INCLUDE_EXAMPLES) add_subdirectory(examples) diff --git a/flang/test/CMakeLists.txt b/flang/test/CMakeLists.txt index cab214c2ef4c8c..e398e0786147aa 100644 --- a/flang/test/CMakeLists.txt +++ b/flang/test/CMakeLists.txt @@ -71,9 +71,13 @@ set(FLANG_TEST_DEPENDS llvm-objdump llvm-readobj split-file - FortranRuntime FortranDecimal ) + +if (FLANG_INCLUDE_RUNTIME) + list(APPEND FLANG_TEST_DEPENDS FortranRuntime) +endif () + if (LLVM_ENABLE_PLUGINS AND NOT WIN32) list(APPEND FLANG_TEST_DEPENDS Bye) endif() diff --git a/flang/test/Driver/ctofortran.f90 b/flang/test/Driver/ctofortran.f90 index 78eac32133b18e..10c7adaccc9588 100644 --- a/flang/test/Driver/ctofortran.f90 +++ b/flang/test/Driver/ctofortran.f90 @@ -1,4 +1,5 @@ ! UNSUPPORTED: system-windows +! REQUIRES: flang-rt ! RUN: split-file %s %t ! RUN: chmod +x %t/runtest.sh ! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang | FileCheck %s diff --git a/flang/test/Driver/exec.f90 b/flang/test/Driver/exec.f90 index fd174005ddf62a..9ca91ee24011c9 100644 --- a/flang/test/Driver/exec.f90 +++ b/flang/test/Driver/exec.f90 @@ -1,4 +1,5 @@ ! UNSUPPORTED: system-windows +! REQUIRES: flang-rt ! Verify that flang can correctly build executables. ! RUN: %flang %s -o %t diff --git a/flang/test/Runtime/no-cpp-dep.c b/flang/test/Runtime/no-cpp-dep.c index b1a5fa004014cc..7303ce63fdec41 100644 --- a/flang/test/Runtime/no-cpp-dep.c +++ b/flang/test/Runtime/no-cpp-dep.c @@ -3,7 +3,7 @@ This test makes sure that flang's runtime does not depend on the C++ runtime library. It tries to link this simple file against libFortranRuntime.a with a C compiler. -REQUIRES: c-compiler +REQUIRES: c-compiler, flang-rt RUN: %if system-aix %{ export OBJECT_MODE=64 %} RUN: %cc -std=c99 %s -I%include %libruntime -lm \ diff --git a/flang/test/lit.cfg.py b/flang/test/lit.cfg.py index c452b6d231c89f..78378bf5f413e8 100644 --- a/flang/test/lit.cfg.py +++ b/flang/test/lit.cfg.py @@ -163,10 +163,13 @@ ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal") ) +if config.flang_include_runtime: + config.available_features.add("flang-rt") + # Define some variables to help us test that the flang runtime doesn't depend on # the C++ runtime libraries. For this we need a C compiler. If for some reason # we don't have one, we can just disable the test. -if config.cc: +if config.flang_include_runtime and config.cc: libruntime = os.path.join(config.flang_lib_dir, "libFortranRuntime.a") include = os.path.join(config.flang_src_dir, "include") diff --git a/flang/test/lit.site.cfg.py.in b/flang/test/lit.site.cfg.py.in index d1a0ac763cf8a0..19f9330f93ae14 100644 --- a/flang/test/lit.site.cfg.py.in +++ b/flang/test/lit.site.cfg.py.in @@ -32,6 +32,7 @@ else: config.openmp_module_dir = None config.flang_runtime_f128_math_lib = "@FLANG_RUNTIME_F128_MATH_LIB@" config.have_ldbl_mant_dig_113 = "@HAVE_LDBL_MANT_DIG_113@" +config.flang_include_runti
[llvm-branch-commits] [nfc][BoundsChecking] Rename BoundsCheckingOptions into Options (PR #122359)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/122359 None ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [nfc][BoundsChecking] Rename BoundsCheckingOptions into Options (PR #122359)
llvmbot wrote: @llvm/pr-subscribers-llvm-transforms Author: Vitaly Buka (vitalybuka) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/122359.diff 5 Files Affected: - (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h (+3-3) - (modified) llvm/lib/Passes/PassBuilder.cpp (+2-2) - (modified) llvm/lib/Passes/PassRegistry.def (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp (+10-10) ``diff diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index f350accfc530bf..37ef2bd203fdfd 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1027,7 +1027,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback([this](FunctionPassManager &FPM, OptimizationLevel Level) { -BoundsCheckingPass::BoundsCheckingOptions Options; +BoundsCheckingPass::Options Options; Options.Merge = CodeGenOpts.SanitizeMergeHandlers.has(SanitizerKind::LocalBounds); if (!CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) { diff --git a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h index 9c0506428bd625..836fc907375d30 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h +++ b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h @@ -20,7 +20,7 @@ class Function; class BoundsCheckingPass : public PassInfoMixin { public: - struct BoundsCheckingOptions { + struct Options { struct Runtime { Runtime(bool MinRuntime, bool MayReturn) : MinRuntime(MinRuntime), MayReturn(MayReturn) {} @@ -31,14 +31,14 @@ class BoundsCheckingPass : public PassInfoMixin { bool Merge = false; }; - BoundsCheckingPass(BoundsCheckingOptions Options) : Options(Options) {} + BoundsCheckingPass(Options Opts) : Opts(Opts) {} PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); static bool isRequired() { return true; } void printPipeline(raw_ostream &OS, function_ref MapClassName2PassName); private: - BoundsCheckingOptions Options; + Options Opts; }; } // end namespace llvm diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index b75387ac556e39..aac44077400550 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1284,9 +1284,9 @@ parseRegAllocFastPassOptions(PassBuilder &PB, StringRef Params) { return Opts; } -Expected +Expected parseBoundsCheckingOptions(StringRef Params) { - BoundsCheckingPass::BoundsCheckingOptions Options; + BoundsCheckingPass::Options Options; while (!Params.empty()) { StringRef ParamName; std::tie(ParamName, Params) = Params.split(';'); diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 13e192fffbdd95..1021d7fcd92474 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -623,7 +623,7 @@ FUNCTION_PASS_WITH_PARAMS( parseWinEHPrepareOptions, "demote-catchswitch-only") FUNCTION_PASS_WITH_PARAMS( "bounds-checking", "BoundsCheckingPass", -[](BoundsCheckingPass::BoundsCheckingOptions Options) { +[](BoundsCheckingPass::Options Options) { return BoundsCheckingPass(Options); }, parseBoundsCheckingOptions, "trap") diff --git a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp index 3d2a2663230c06..10596f87fbcaba 100644 --- a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp +++ b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp @@ -162,8 +162,8 @@ static void insertBoundsCheck(Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB) { BranchInst::Create(TrapBB, Cont, Or, OldBB); } -static std::string getRuntimeCallName( -const BoundsCheckingPass::BoundsCheckingOptions::Runtime &Opts) { +static std::string +getRuntimeCallName(const BoundsCheckingPass::Options::Runtime &Opts) { std::string Name = "__ubsan_handle_local_out_of_bounds"; if (Opts.MinRuntime) Name += "_minimal"; @@ -172,9 +172,9 @@ static std::string getRuntimeCallName( return Name; } -static bool -addBoundsChecking(Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE, - const BoundsCheckingPass::BoundsCheckingOptions &Opts) { +static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI, + ScalarEvolution &SE, + const BoundsCheckingPass::Options &Opts) { if (F.hasFnAttribute(Attribute::NoSanitizeBounds)) return false; @@ -271,7 +271,7 @@ PreservedAnalyses BoundsCheckingPass::run(Function &F, FunctionAnalysisManager &
[llvm-branch-commits] [nfc][BoundsChecking] Rename BoundsCheckingOptions into Options (PR #122359)
llvmbot wrote: @llvm/pr-subscribers-clang-codegen Author: Vitaly Buka (vitalybuka) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/122359.diff 5 Files Affected: - (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h (+3-3) - (modified) llvm/lib/Passes/PassBuilder.cpp (+2-2) - (modified) llvm/lib/Passes/PassRegistry.def (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp (+10-10) ``diff diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index f350accfc530bf..37ef2bd203fdfd 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1027,7 +1027,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback([this](FunctionPassManager &FPM, OptimizationLevel Level) { -BoundsCheckingPass::BoundsCheckingOptions Options; +BoundsCheckingPass::Options Options; Options.Merge = CodeGenOpts.SanitizeMergeHandlers.has(SanitizerKind::LocalBounds); if (!CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) { diff --git a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h index 9c0506428bd625..836fc907375d30 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h +++ b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h @@ -20,7 +20,7 @@ class Function; class BoundsCheckingPass : public PassInfoMixin { public: - struct BoundsCheckingOptions { + struct Options { struct Runtime { Runtime(bool MinRuntime, bool MayReturn) : MinRuntime(MinRuntime), MayReturn(MayReturn) {} @@ -31,14 +31,14 @@ class BoundsCheckingPass : public PassInfoMixin { bool Merge = false; }; - BoundsCheckingPass(BoundsCheckingOptions Options) : Options(Options) {} + BoundsCheckingPass(Options Opts) : Opts(Opts) {} PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); static bool isRequired() { return true; } void printPipeline(raw_ostream &OS, function_ref MapClassName2PassName); private: - BoundsCheckingOptions Options; + Options Opts; }; } // end namespace llvm diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index b75387ac556e39..aac44077400550 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1284,9 +1284,9 @@ parseRegAllocFastPassOptions(PassBuilder &PB, StringRef Params) { return Opts; } -Expected +Expected parseBoundsCheckingOptions(StringRef Params) { - BoundsCheckingPass::BoundsCheckingOptions Options; + BoundsCheckingPass::Options Options; while (!Params.empty()) { StringRef ParamName; std::tie(ParamName, Params) = Params.split(';'); diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 13e192fffbdd95..1021d7fcd92474 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -623,7 +623,7 @@ FUNCTION_PASS_WITH_PARAMS( parseWinEHPrepareOptions, "demote-catchswitch-only") FUNCTION_PASS_WITH_PARAMS( "bounds-checking", "BoundsCheckingPass", -[](BoundsCheckingPass::BoundsCheckingOptions Options) { +[](BoundsCheckingPass::Options Options) { return BoundsCheckingPass(Options); }, parseBoundsCheckingOptions, "trap") diff --git a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp index 3d2a2663230c06..10596f87fbcaba 100644 --- a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp +++ b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp @@ -162,8 +162,8 @@ static void insertBoundsCheck(Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB) { BranchInst::Create(TrapBB, Cont, Or, OldBB); } -static std::string getRuntimeCallName( -const BoundsCheckingPass::BoundsCheckingOptions::Runtime &Opts) { +static std::string +getRuntimeCallName(const BoundsCheckingPass::Options::Runtime &Opts) { std::string Name = "__ubsan_handle_local_out_of_bounds"; if (Opts.MinRuntime) Name += "_minimal"; @@ -172,9 +172,9 @@ static std::string getRuntimeCallName( return Name; } -static bool -addBoundsChecking(Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE, - const BoundsCheckingPass::BoundsCheckingOptions &Opts) { +static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI, + ScalarEvolution &SE, + const BoundsCheckingPass::Options &Opts) { if (F.hasFnAttribute(Attribute::NoSanitizeBounds)) return false; @@ -271,7 +271,7 @@ PreservedAnalyses BoundsCheckingPass::run(Function &F, FunctionAnalysisManager &
[llvm-branch-commits] [nfc][BoundsChecking] Rename BoundsCheckingOptions into Options (PR #122359)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) Changes --- Full diff: https://github.com/llvm/llvm-project/pull/122359.diff 5 Files Affected: - (modified) clang/lib/CodeGen/BackendUtil.cpp (+1-1) - (modified) llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h (+3-3) - (modified) llvm/lib/Passes/PassBuilder.cpp (+2-2) - (modified) llvm/lib/Passes/PassRegistry.def (+1-1) - (modified) llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp (+10-10) ``diff diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index f350accfc530bf..37ef2bd203fdfd 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1027,7 +1027,7 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback([this](FunctionPassManager &FPM, OptimizationLevel Level) { -BoundsCheckingPass::BoundsCheckingOptions Options; +BoundsCheckingPass::Options Options; Options.Merge = CodeGenOpts.SanitizeMergeHandlers.has(SanitizerKind::LocalBounds); if (!CodeGenOpts.SanitizeTrap.has(SanitizerKind::LocalBounds)) { diff --git a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h index 9c0506428bd625..836fc907375d30 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h +++ b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h @@ -20,7 +20,7 @@ class Function; class BoundsCheckingPass : public PassInfoMixin { public: - struct BoundsCheckingOptions { + struct Options { struct Runtime { Runtime(bool MinRuntime, bool MayReturn) : MinRuntime(MinRuntime), MayReturn(MayReturn) {} @@ -31,14 +31,14 @@ class BoundsCheckingPass : public PassInfoMixin { bool Merge = false; }; - BoundsCheckingPass(BoundsCheckingOptions Options) : Options(Options) {} + BoundsCheckingPass(Options Opts) : Opts(Opts) {} PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); static bool isRequired() { return true; } void printPipeline(raw_ostream &OS, function_ref MapClassName2PassName); private: - BoundsCheckingOptions Options; + Options Opts; }; } // end namespace llvm diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index b75387ac556e39..aac44077400550 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1284,9 +1284,9 @@ parseRegAllocFastPassOptions(PassBuilder &PB, StringRef Params) { return Opts; } -Expected +Expected parseBoundsCheckingOptions(StringRef Params) { - BoundsCheckingPass::BoundsCheckingOptions Options; + BoundsCheckingPass::Options Options; while (!Params.empty()) { StringRef ParamName; std::tie(ParamName, Params) = Params.split(';'); diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 13e192fffbdd95..1021d7fcd92474 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -623,7 +623,7 @@ FUNCTION_PASS_WITH_PARAMS( parseWinEHPrepareOptions, "demote-catchswitch-only") FUNCTION_PASS_WITH_PARAMS( "bounds-checking", "BoundsCheckingPass", -[](BoundsCheckingPass::BoundsCheckingOptions Options) { +[](BoundsCheckingPass::Options Options) { return BoundsCheckingPass(Options); }, parseBoundsCheckingOptions, "trap") diff --git a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp index 3d2a2663230c06..10596f87fbcaba 100644 --- a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp +++ b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp @@ -162,8 +162,8 @@ static void insertBoundsCheck(Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB) { BranchInst::Create(TrapBB, Cont, Or, OldBB); } -static std::string getRuntimeCallName( -const BoundsCheckingPass::BoundsCheckingOptions::Runtime &Opts) { +static std::string +getRuntimeCallName(const BoundsCheckingPass::Options::Runtime &Opts) { std::string Name = "__ubsan_handle_local_out_of_bounds"; if (Opts.MinRuntime) Name += "_minimal"; @@ -172,9 +172,9 @@ static std::string getRuntimeCallName( return Name; } -static bool -addBoundsChecking(Function &F, TargetLibraryInfo &TLI, ScalarEvolution &SE, - const BoundsCheckingPass::BoundsCheckingOptions &Opts) { +static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI, + ScalarEvolution &SE, + const BoundsCheckingPass::Options &Opts) { if (F.hasFnAttribute(Attribute::NoSanitizeBounds)) return false; @@ -271,7 +271,7 @@ PreservedAnalyses BoundsCheckingPass::run(Function &F, FunctionAnalysisManager & auto &T
[llvm-branch-commits] [clang] [flang] [lld] [llvm] [Flang][NFC] Move runtime library files to flang-rt. (PR #110298)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r baa7cb19d7f77c4be9c283d1662ec6b5d4d0646f...b58bd1ffc06f04755e7611f1f160bcf4d1d21bce flang/test/lit.cfg.py `` View the diff from darker here. ``diff --- lit.cfg.py 2025-01-09 15:03:02.00 + +++ lit.cfg.py 2025-01-09 18:47:17.360215 + @@ -162,11 +162,11 @@ tools.append( ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal") ) if config.flang_include_runtime: - config.available_features.add("flang-rt") +config.available_features.add("flang-rt") # Define some variables to help us test that the flang runtime doesn't depend on # the C++ runtime libraries. For this we need a C compiler. If for some reason # we don't have one, we can just disable the test. if config.flang_include_runtime and config.cc: `` https://github.com/llvm/llvm-project/pull/110298 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [Flang] Promote FortranEvaluateTesting library (PR #122334)
https://github.com/Meinersbur edited https://github.com/llvm/llvm-project/pull/122334 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [flang] [Flang] Promote FortranEvaluateTesting library (PR #122334)
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/122334 The non-GTest library will be shared by unittests of Flang and Flang-RT. Promote it as a regular library for use by both projects. In the long term, we may want to convert these to regular GTest checks to avoid having multiple testing frameworks. >From 74432e2d5d4916f09ee6f60a4d80f3f5a96f1b12 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 9 Jan 2025 11:31:23 +0100 Subject: [PATCH 1/3] Promote Testing lib --- .../flang/Testing}/fp-testing.h| 14 +++--- .../Evaluate => include/flang/Testing}/testing.h | 14 +++--- .../Evaluate => lib/Testing}/fp-testing.cpp| 10 +- .../Evaluate => lib/Testing}/testing.cpp | 10 +- flang/unittests/Evaluate/CMakeLists.txt| 4 ++-- flang/unittests/Evaluate/ISO-Fortran-binding.cpp | 2 +- flang/unittests/Evaluate/bit-population-count.cpp | 2 +- flang/unittests/Evaluate/expression.cpp| 2 +- flang/unittests/Evaluate/folding.cpp | 2 +- flang/unittests/Evaluate/integer.cpp | 2 +- flang/unittests/Evaluate/intrinsics.cpp| 2 +- .../unittests/Evaluate/leading-zero-bit-count.cpp | 2 +- flang/unittests/Evaluate/logical.cpp | 2 +- flang/unittests/Evaluate/real.cpp | 4 ++-- flang/unittests/Evaluate/reshape.cpp | 2 +- flang/unittests/Evaluate/uint128.cpp | 2 +- 16 files changed, 54 insertions(+), 22 deletions(-) rename flang/{unittests/Evaluate => include/flang/Testing}/fp-testing.h (54%) rename flang/{unittests/Evaluate => include/flang/Testing}/testing.h (74%) rename flang/{unittests/Evaluate => lib/Testing}/fp-testing.cpp (87%) rename flang/{unittests/Evaluate => lib/Testing}/testing.cpp (88%) diff --git a/flang/unittests/Evaluate/fp-testing.h b/flang/include/flang/Testing/fp-testing.h similarity index 54% rename from flang/unittests/Evaluate/fp-testing.h rename to flang/include/flang/Testing/fp-testing.h index 9091963a99b32d..e223d2ef7d1b8b 100644 --- a/flang/unittests/Evaluate/fp-testing.h +++ b/flang/include/flang/Testing/fp-testing.h @@ -1,5 +1,13 @@ -#ifndef FORTRAN_TEST_EVALUATE_FP_TESTING_H_ -#define FORTRAN_TEST_EVALUATE_FP_TESTING_H_ +//===-- include/flang/Testing/fp-testing.h --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef FORTRAN_TESTING_FP_TESTING_H_ +#define FORTRAN_TESTING_FP_TESTING_H_ #include "flang/Common/target-rounding.h" #include @@ -24,4 +32,4 @@ class ScopedHostFloatingPointEnvironment { #endif }; -#endif // FORTRAN_TEST_EVALUATE_FP_TESTING_H_ +#endif /* FORTRAN_TESTING_FP_TESTING_H_ */ diff --git a/flang/unittests/Evaluate/testing.h b/flang/include/flang/Testing/testing.h similarity index 74% rename from flang/unittests/Evaluate/testing.h rename to flang/include/flang/Testing/testing.h index 422e2853c05bc6..404650c9a89f2c 100644 --- a/flang/unittests/Evaluate/testing.h +++ b/flang/include/flang/Testing/testing.h @@ -1,5 +1,13 @@ -#ifndef FORTRAN_EVALUATE_TESTING_H_ -#define FORTRAN_EVALUATE_TESTING_H_ +//===-- include/flang/Testing/testing.h -*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +#ifndef FORTRAN_TESTING_TESTING_H_ +#define FORTRAN_TESTING_TESTING_H_ #include #include @@ -33,4 +41,4 @@ FailureDetailPrinter Match(const char *file, int line, const std::string &want, FailureDetailPrinter Compare(const char *file, int line, const char *xs, const char *rel, const char *ys, std::uint64_t x, std::uint64_t y); } // namespace testing -#endif // FORTRAN_EVALUATE_TESTING_H_ +#endif /* FORTRAN_TESTING_TESTING_H_ */ diff --git a/flang/unittests/Evaluate/fp-testing.cpp b/flang/lib/Testing/fp-testing.cpp similarity index 87% rename from flang/unittests/Evaluate/fp-testing.cpp rename to flang/lib/Testing/fp-testing.cpp index 1a1d7425d58249..5e1728e8df5e4b 100644 --- a/flang/unittests/Evaluate/fp-testing.cpp +++ b/flang/lib/Testing/fp-testing.cpp @@ -1,4 +1,12 @@ -#include "fp-testing.h" +//===-- lib/Testing/fp-testing.cpp --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--
[llvm-branch-commits] [flang] [Flang] Optionally do not compile the runtime in-tree (PR #122336)
github-actions[bot] wrote: :warning: Python code formatter, darker found issues in your code. :warning: You can test this locally with the following command: ``bash darker --check --diff -r 11a9773de93c31abf74d5b7c24142c9e25d4515b...582045951e7edaba35e8c6966fa40101f8d54ad9 flang/test/lit.cfg.py `` View the diff from darker here. ``diff --- lit.cfg.py 2025-01-09 14:58:48.00 + +++ lit.cfg.py 2025-01-09 19:00:23.138152 + @@ -162,11 +162,11 @@ tools.append( ToolSubst("%not_todo_abort_cmd", command=FindTool("not"), unresolved="fatal") ) if config.flang_include_runtime: - config.available_features.add("flang-rt") +config.available_features.add("flang-rt") # Define some variables to help us test that the flang runtime doesn't depend on # the C++ runtime libraries. For this we need a C compiler. If for some reason # we don't have one, we can just disable the test. if config.flang_include_runtime and config.cc: `` https://github.com/llvm/llvm-project/pull/122336 ___ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] [flang] [lld] [llvm] [Flang] Rename libFortranRuntime.a to libflang_rt.a (PR #122341)
https://github.com/Meinersbur created https://github.com/llvm/llvm-project/pull/122341 The future name of Flang's runtime component is `flang_rt`, as already used in PR #110217 (Flang-RT). Since the flang driver has to select the runtime to link, both build instructions must agree on the name. Extracted out of #110217 >From c77098f90a5c20bdbce078a0ee3aec1fe53772e3 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Wed, 8 Jan 2025 11:23:02 +0100 Subject: [PATCH 1/4] clang-format to sort headers --- flang/tools/f18-parse-demo/f18-parse-demo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/tools/f18-parse-demo/f18-parse-demo.cpp b/flang/tools/f18-parse-demo/f18-parse-demo.cpp index 90bbce246e3f16..a50c88dc840643 100644 --- a/flang/tools/f18-parse-demo/f18-parse-demo.cpp +++ b/flang/tools/f18-parse-demo/f18-parse-demo.cpp @@ -21,7 +21,6 @@ // scaffolding compiler driver that can test some semantic passes of the // F18 compiler under development. -#include "flang/Support/Fortran-features.h" #include "flang/Parser/characters.h" #include "flang/Parser/dump-parse-tree.h" #include "flang/Parser/message.h" @@ -30,6 +29,7 @@ #include "flang/Parser/parsing.h" #include "flang/Parser/provenance.h" #include "flang/Parser/unparse.h" +#include "flang/Support/Fortran-features.h" #include "flang/Support/default-kinds.h" #include "llvm/Support/Errno.h" #include "llvm/Support/FileSystem.h" >From 22ed7ebde19d4003fa3036039f75977b1e6b9f60 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Wed, 8 Jan 2025 14:15:45 +0100 Subject: [PATCH 2/4] FortranRuntime -> flang_rt --- clang/lib/Driver/ToolChains/CommonArgs.cpp| 4 +- clang/lib/Driver/ToolChains/Flang.cpp | 8 ++-- flang-rt/unittests/Evaluate/CMakeLists.txt| 21 ++ flang/CMakeLists.txt | 2 +- flang/docs/FlangDriver.md | 8 ++-- flang/docs/GettingStarted.md | 6 +-- flang/docs/OpenACC-descriptor-management.md | 2 +- flang/docs/ReleaseNotes.md| 2 + .../ExternalHelloWorld/CMakeLists.txt | 2 +- flang/runtime/CMakeLists.txt | 40 +++ flang/runtime/CUDA/CMakeLists.txt | 2 +- flang/runtime/Float128Math/CMakeLists.txt | 2 +- flang/runtime/time-intrinsic.cpp | 2 +- flang/test/CMakeLists.txt | 6 ++- .../test/Driver/gcc-toolchain-install-dir.f90 | 2 +- flang/test/Driver/linker-flags.f90| 8 ++-- .../test/Driver/msvc-dependent-lib-flags.f90 | 8 ++-- flang/test/Driver/nostdlib.f90| 2 +- flang/test/Runtime/no-cpp-dep.c | 2 +- flang/test/lit.cfg.py | 2 +- flang/tools/f18/CMakeLists.txt| 8 ++-- flang/unittests/CMakeLists.txt| 2 +- flang/unittests/Evaluate/CMakeLists.txt | 9 +++-- flang/unittests/Frontend/CMakeLists.txt | 1 + flang/unittests/Runtime/CMakeLists.txt| 2 +- flang/unittests/Runtime/CUDA/CMakeLists.txt | 2 +- lld/COFF/MinGW.cpp| 2 +- 27 files changed, 97 insertions(+), 60 deletions(-) create mode 100644 flang-rt/unittests/Evaluate/CMakeLists.txt diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp index 9e9872975de9c2..4c6b9f29f362ca 100644 --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -1317,7 +1317,7 @@ void tools::addOpenMPHostOffloadingArgs(const Compilation &C, /// Add Fortran runtime libs void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, llvm::opt::ArgStringList &CmdArgs) { - // Link FortranRuntime + // Link flang_rt // These are handled earlier on Windows by telling the frontend driver to // add the correct libraries to link against as dependents in the object // file. @@ -1333,7 +1333,7 @@ void tools::addFortranRuntimeLibs(const ToolChain &TC, const ArgList &Args, if (AsNeeded) addAsNeededOption(TC, Args, CmdArgs, /*as_needed=*/false); } -CmdArgs.push_back("-lFortranRuntime"); +CmdArgs.push_back("-lflang_rt"); addArchSpecificRPath(TC, Args, CmdArgs); } diff --git a/clang/lib/Driver/ToolChains/Flang.cpp b/clang/lib/Driver/ToolChains/Flang.cpp index 749af4ada9a696..2cf1108b28dab3 100644 --- a/clang/lib/Driver/ToolChains/Flang.cpp +++ b/clang/lib/Driver/ToolChains/Flang.cpp @@ -356,26 +356,26 @@ static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, case options::OPT__SLASH_MT: CmdArgs.push_back("-D_MT"); CmdArgs.push_back("--dependent-lib=libcmt"); -CmdArgs.push_back("--dependent-lib=FortranRuntime.static.lib"); +CmdArgs.push_back("--dependent-lib=flang_rt.static.lib"); break; case options::OPT__SLASH_MTd: CmdArgs.push_back("-D_MT"); CmdArgs.push_back("-D_DEBU