1. Aug 25, 2022
    • Ilia Diachkov's avatar
      [SPIRV] support builtin functions · f61eb416
      Ilia Diachkov authored
      The patch adds support for OpenCL and SPIR-V built-in functions.
      Their detection and properties are implemented using TableGen.
      Five tests are added to demonstrate the improvement.
      
      Differential Revision: https://reviews.llvm.org/D132024
      
      
      
      Co-authored-by: default avatarAleksandr Bezzubikov <zuban32s@gmail.com>
      Co-authored-by: default avatarMichal Paszkowski <michal.paszkowski@outlook.com>
      Co-authored-by: default avatarAndrey Tretyakov <andrey1.tretyakov@intel.com>
      Co-authored-by: default avatarKonrad Trifunovic <konrad.trifunovic@intel.com>
      f61eb416
    • Peter Cooper's avatar
    • Saleem Abdulrasool's avatar
      RISCV: permit unaligned nop-slide padding emission · 8f45b5a7
      Saleem Abdulrasool authored
      We may be requested to emit an unaligned nop sequence (e.g. 7-bytes or
      3-bytes).  These should be 0-filled even though that is not a valid
      instruction.  This matches the behaviour on other architectures like
      ARM, X86, and MIPS.  When a custom section is emitted, it may be
      classified as text even though it may be a data section or we may be
      emitting data into a text segment (e.g. a literal pool).  In such cases,
      we should be resilient to the emission request.
      
      This was originally identified by the Linux kernel build and reported on
      D131270 by Nathan Chancellor.
      
      Differential Revision: https://reviews.llvm.org/D132482
      Reviewed By: luismarques
      Tested By: Nathan Chancellor
      8f45b5a7
    • Cameron McInally's avatar
      [GlobalOpt] Bail out of GlobalOpt SROA if a Scalable Vector is seen · 38d58c1b
      Cameron McInally authored
      The SROA algorithm won't work for Scalable Vectors, since we don't
      know how many bytes are loaded/stored. Bail out if a Scalable
      Vector is seen.
      
      Differential Revision: https://reviews.llvm.org/D132417
      38d58c1b
    • Sanjay Patel's avatar
      [InstCombine] reduce disguised mul+add factorization · f7ab70cf
      Sanjay Patel authored
      ~(A * C1) + A --> (A * (1 - C1)) - 1
      
      This is a non-obvious mix of bitwise logic and math:
      https://alive2.llvm.org/ce/z/U7ACVT
      
      The pattern may be produced by Negator from the more typical
      code seen in issue #57255.
      f7ab70cf
    • Sanjay Patel's avatar
      [InstCombine] add tests for add with not-of-mul common operand; NFC · 24d52181
      Sanjay Patel authored
      Negator can create non-obvious math while trying hard to avoid subtraction.
      issue #57255
      24d52181
    • Eli Friedman's avatar
      Exclude check-polly-unittests and check-polly-isl from check-all · 2c29268b
      Eli Friedman authored
      The unittests are already included in check-polly, so check-all was
      running them twice.  Running them twice causes a race on the output
      files, which led to intermittent failures on the reverse-iteration
      buildbot.
      2c29268b
    • Chris Bieneman's avatar
      [HLSL] Entry functions require param annotation · bdf1327f
      Chris Bieneman authored
      HLSL entry function parameters must have parameter annotations. This
      allows appropriate intrinsic values to be populated into parameters
      during code generation.
      
      This does not handle entry function return values, which will be
      handled in a subsequent commit because we don't currently support any
      annotations that are valid for function returns.
      
      Reviewed By: aaron.ballman
      
      Differential Revision: https://reviews.llvm.org/D131625
      bdf1327f
    • Ye Luo's avatar
      [libomptarget][amdgpu] enable tests whenever possible. · 322ea531
      Ye Luo authored
      if(TARGET amdgpu-arch) doesn't work when ENABLE_LLVM_PROJECTS=openmp because openmp subdirectory is processed before clang subdirectory. Adopt the same logic of enabling tests like the CUDA plugin.
      
      Differential Revision: https://reviews.llvm.org/D132579
      322ea531
    • Sami Tolvanen's avatar
      Revert "KCFI sanitizer" · a79060e2
      Sami Tolvanen authored
      This reverts commit 67504c95 as using
      PointerEmbeddedInt to store 32 bits breaks 32-bit arm builds.
      a79060e2
    • Michael Liao's avatar
      [LoongArch] Fix build due to TLI interface changes. NFC. · dda38786
      Michael Liao authored
      - isCheapToSpeculateCttz/isCheapToSpeculateCtlz have one type operand
        after https://reviews.llvm.org/D132520
      dda38786
    • Prabhdeep Singh Soni's avatar
      [Flang][OpenMP] Add support for safelen clause · 457f1fe3
      Prabhdeep Singh Soni authored
      This supports lowering from parse-tree to MLIR for OpenMP safelen clause
      in SIMD construct.
      
      Reviewed By: kiranchandramohan
      
      Differential Revision: https://reviews.llvm.org/D132574
      457f1fe3
    • Sami Tolvanen's avatar
      KCFI sanitizer · 67504c95
      Sami Tolvanen authored
      The KCFI sanitizer, enabled with `-fsanitize=kcfi`, implements a
      forward-edge control flow integrity scheme for indirect calls. It
      uses a !kcfi_type metadata node to attach a type identifier for each
      function and injects verification code before indirect calls.
      
      Unlike the current CFI schemes implemented in LLVM, KCFI does not
      require LTO, does not alter function references to point to a jump
      table, and never breaks function address equality. KCFI is intended
      to be used in low-level code, such as operating system kernels,
      where the existing schemes can cause undue complications because
      of the aforementioned properties. However, unlike the existing
      schemes, KCFI is limited to validating only function pointers and is
      not compatible with executable-only memory.
      
      KCFI does not provide runtime support, but always traps when a
      type mismatch is encountered. Users of the scheme are expected
      to handle the trap. With `-fsanitize=kcfi`, Clang emits a `kcfi`
      operand bundle to indirect calls, and LLVM lowers this to a
      known architecture-specific sequence of instructions for each
      callsite to make runtime patching easier for users who require this
      functionality.
      
      A KCFI type identifier is a 32-bit constant produced by taking the
      lower half of xxHash64 from a C++ mangled typename. If a program
      contains indirect calls to assembly functions, they must be
      manually annotated with the expected type identifiers to prevent
      errors. To make this easier, Clang generates a weak SHN_ABS
      `__kcfi_typeid_<function>` symbol for each address-taken function
      declaration, which can be used to annotate functions in assembly
      as long as at least one C translation unit linked into the program
      takes the function address. For example on AArch64, we might have
      the following code:
      
      ```
      .c:
        int f(void);
        int (*p)(void) = f;
        p();
      
      .s:
        .4byte __kcfi_typeid_f
        .global f
        f:
          ...
      ```
      
      Note that X86 uses a different preamble format for compatibility
      with Linux kernel tooling. See the comments in
      `X86AsmPrinter::emitKCFITypeId` for details.
      
      As users of KCFI may need to locate trap locations for binary
      validation and error handling, LLVM can additionally emit the
      locations of traps to a `.kcfi_traps` section.
      
      Similarly to other sanitizers, KCFI checking can be disabled for a
      function with a `no_sanitize("kcfi")` function attribute.
      
      Reviewed By: nickdesaulniers, kees, joaomoreira, MaskRay
      
      Differential Revision: https://reviews.llvm.org/D119296
      67504c95
    • Siva Chandra Reddy's avatar
      [libc] Add linux implementation of POSIX fchmodat function. · 85dff764
      Siva Chandra Reddy authored
      Reviewed By: michaelrj
      
      Differential Revision: https://reviews.llvm.org/D132533
      85dff764
    • Philip Reames's avatar
    • Philip Reames's avatar
    • Valery N Dmitriev's avatar
    • Jan Svoboda's avatar
      [clang][modules] Track affecting modules · 002bfdd6
      Jan Svoboda authored
      When compiling a module, its semantics and Clang's behavior are affected by other modules. These modules are typically the **imported** ones. However, during implicit build, some modules end up being compiled and read without being actually imported. This patch starts tracking such modules and serializing them into `.pcm` files. This enables the dependency scanner to construct explicit compilations that mimic implicit build.
      
      Reviewed By: benlangmuir
      
      Differential Revision: https://reviews.llvm.org/D132430
      002bfdd6
    • Philip Reames's avatar
    • Fabian Parzefall's avatar
      Revert "[BOLT] Towards FunctionLayout const-correctness" · f24c299e
      Fabian Parzefall authored
      This reverts commit 587d2653.
      f24c299e
    • Fabian Parzefall's avatar
      Revert "[BOLT] Allocate FunctionFragment on heap" · 5065134a
      Fabian Parzefall authored
      This reverts commit 101344af.
      5065134a
    • Fabian Parzefall's avatar
      Revert "[BOLT] Track fragment info for all split fragments" · 6304e382
      Fabian Parzefall authored
      This reverts commit 7e254818.
      6304e382
    • Philip Reames's avatar
      [LV] Adjust code added in f79214d1 for 531dd363 [nfc] · 3ab00cfc
      Philip Reames authored
      When rebasing the review which became f79214d1, I forgot to adjust for the changed semantics introduced by 531dd363.  Functionally, this had no impact, but semantically it resulted in an incorrect result for isPredicatedInst.  I noticed this while doing a follow up change.
      3ab00cfc
    • Petr Hosek's avatar
      [Clang] Avoid using unwind library in the MSVC environment · 74af56c1
      Petr Hosek authored
      We're seeing the following warnings with --rtlib=compiler-rt:
      
        lld-link: warning: ignoring unknown argument '--as-needed'
        lld-link: warning: ignoring unknown argument '-lunwind'
        lld-link: warning: ignoring unknown argument '--no-as-needed'
      
      MSVC doesn't use the unwind library, so just omit it.
      
      Differential Revision: https://reviews.llvm.org/D132440
      74af56c1
    • Daniel Bertalan's avatar
      [llvm-objdump] Complete -chained_fixups support · 686d8ce1
      Daniel Bertalan authored
      This commit adds definitions for the `dyld_chained_import*` structs.
      The imports array is now printed with `llvm-otool -chained_fixups`. This
      completes this option's implementation.
      
      A slight difference from cctools otool is that we don't yet dump the
      raw bytes of the imports entries.
      
      When Apple's effort to upstream their chained fixups code continues,
      we'll replace this code with the then-upstreamed code. But we need
      something in the meantime for testing ld64.lld's chained fixups code.
      
      Differential Revision: https://reviews.llvm.org/D131982
      686d8ce1
    • Michael Jones's avatar
      [libc] move printf to use StringViews · 096463d0
      Michael Jones authored
      The FormatSection and the writer functions both previously took a char*
      and a length to represent a string. Now they use the StringView class to
      represent that more succinctly. This change also required fixing
      everywhere these were used, so it touches a lot of files.
      
      Reviewed By: sivachandra
      
      Differential Revision: https://reviews.llvm.org/D131994
      096463d0
    • Mark de Wever's avatar
      [libc++] Tests transitive includes for all C++ versions. · 3d68a67f
      Mark de Wever authored
      D132284 has an approach to reduce the number of transitive includes
      based on the language version used. This requires to be able to validate
      changes in transitive includes in all language versions.
      
      Due to issues in the experimental library c++03 will be done separately.
      
      Reviewed By: #libc, ldionne
      
      Differential Revision: https://reviews.llvm.org/D132534
      3d68a67f
    • Fabian Parzefall's avatar
      [BOLT] Track fragment info for all split fragments · 7e254818
      Fabian Parzefall authored
      To generate all symbols correctly, it is necessary to record the address
      of each fragment. This patch moves the address info for the main and
      cold fragments from BinaryFunction to FunctionFragment, where this data
      is recorded for all fragments.
      
      Reviewed By: rafauler
      
      Differential Revision: https://reviews.llvm.org/D132051
      7e254818
    • Fabian Parzefall's avatar
      [BOLT] Allocate FunctionFragment on heap · 101344af
      Fabian Parzefall authored
      This changes `FunctionFragment` from being used as a temporary proxy
      object to access basic block ranges to a heap-allocated object that can
      store fragment-specific information.
      
      Reviewed By: rafauler
      
      Differential Revision: https://reviews.llvm.org/D132050
      101344af
    • Fabian Parzefall's avatar
      [BOLT] Towards FunctionLayout const-correctness · 587d2653
      Fabian Parzefall authored
      A const-qualified reference to function layout allows accessing
      non-const qualified basic blocks on a const-qualified function. This
      patch adds or removes const-qualifiers where necessary to indicate where
      basic blocks are used in a non-const manner.
      
      Reviewed By: rafauler
      
      Differential Revision: https://reviews.llvm.org/D132049
      587d2653
    • Slava Zakharin's avatar
      [mlir] Support llvm.readnone attribute for all FunctionOpInterface ops. · 13cb085c
      Slava Zakharin authored
      The attribute is translated into LLVM's function attribute 'readnone'.
      There is no explicit verification regarding conflicting 'readnone'
      and function attributes from 'passthrough', though, LLVM would assert
      if they are incompatible during LLVM IR creation.
      
      Differential Revision: https://reviews.llvm.org/D131457
      13cb085c
    • Philip Reames's avatar
      [LV] Support predicated div/rem operations via safe-divisor select idiom · f79214d1
      Philip Reames authored
      This patch adds support for vectorizing conditionally executed div/rem operations via a variant of widening. The existing support for predicated divrem in the vectorizer requires scalarization which we can't do for scalable vectors.
      
      The basic idea is that we can always divide (take remainder) by 1 without executing UB. As such, we can use the active lane mask to conditional select either the actual divisor for active lanes, or a constant one for inactive lanes. We already account for the cost of the active lane mask, so the only additional cost is a splat of one and the vector select. This is one of several possible approaches to this problem; see the review thread for discussion on some of the others.  This one was chosen mostly because it was straight forward, and none of the others seemed oviously better.
      
      I enabled the new code only for scalable vectors. We could also legally enable it for fixed vectors as well, but I haven't thought through the cost tradeoffs between widening and scalarization enough to know if that's profitable. This will be explored in future patches.
      
      Differential Revision: https://reviews.llvm.org/D130164
      f79214d1
    • Florian Hahn's avatar
    • spupyrev's avatar
      extending code layout alg · 8d5b694d
      spupyrev authored
      The diff modifies ext-tsp code layout algorithm in the following ways:
      (i) fixes merging of cold block chains (this is a port of D129397);
      (ii) adjusts the cost model utilized for optimization;
      (iii) adjusts some APIs so that the implementation can be used in BOLT; this is
      a prerequisite for D129895.
      
      The only non-trivial change is (ii). Here we introduce different weights for
      conditional and unconditional branches in the cost model. Based on the new model
      it is slightly more important to increase the number of "fall-through
      unconditional" jumps, which makes sense, as placing two blocks with an
      unconditional jump next to each other reduces the number of jump instructions in
      the generated code. Experimentally, this makes a mild impact on the performance;
      I've seen up to 0.2%-0.3% perf win on some benchmarks.
      
      Reviewed By: hoy
      
      Differential Revision: https://reviews.llvm.org/D129893
      8d5b694d
    • Fangrui Song's avatar
      [ELF] Parallelize writes of different OutputSections · 3b4d8009
      Fangrui Song authored
      We currently process one OutputSection at a time and for each OutputSection
      write contained input sections in parallel. This strategy does not leverage
      multi-threading well. Instead, parallelize writes of different OutputSections.
      
      The default TaskSize for parallelFor often leads to inferior sharding. We
      prepare the task in the caller instead.
      
      * Move llvm::parallel::detail::TaskGroup to llvm::parallel::TaskGroup
      * Add llvm::parallel::TaskGroup::execute.
      * Change writeSections to declare TaskGroup and pass it to writeTo.
      
      Speed-up with --threads=8:
      
      * clang -DCMAKE_BUILD_TYPE=Release: 1.11x as fast
      * clang -DCMAKE_BUILD_TYPE=Debug: 1.10x as fast
      * chrome -DCMAKE_BUILD_TYPE=Release: 1.04x as fast
      * scylladb build/release: 1.09x as fast
      
      On M1, many benchmarks are a small fraction of a percentage faster. Mozilla showed the largest difference with the patch being about 1.03x as fast.
      
      Differential Revision: https://reviews.llvm.org/D131247
      3b4d8009
    • Jonas Devlieghere's avatar
      [llvm] Teach LLVM about filesets · e854c17b
      Jonas Devlieghere authored
      Teach LLVM about filesets. Filesets were added in macOS 11 (Big Sur) to
      combine multiple Mach-O files. They introduce a new load command
      (LC_FILESET_ENTRY) consisting of a fileset_entry_command.
      
        struct fileset_entry_command {
            uint32_t     cmd;        /* LC_FILESET_ENTRY */
            uint32_t     cmdsize;    /* includes entry_id string */
            uint64_t     vmaddr;     /* memory address of the entry */
            uint64_t     fileoff;    /* file offset of the entry */
            union lc_str entry_id;   /* contained entry id */
            uint32_t     reserved;   /* reserved */
        };
      
      This patch teaches LLVM about the new load command and the corresponding
      data.
      
      Differential revision: https://reviews.llvm.org/D132432
      e854c17b
    • Tyker's avatar
      [NFC][mlir] Add support for llvm style casting for mlir types · bb63d249
      Tyker authored
      Note:
      when operating on a Type hierarchy with LeafType inheriting from MiddleType which inherits from mlir::Type.
      calling LeafType::classof(MiddleType) will always return false.
      because classof call the static getTypeID from its parent instead of the dynamic Type::getTypeID
      so classof in this context will check if the TypeID of LeafType is the same as the TypeID of MiddleType which is always false.
      It is bypassed in this commit inside CastInfo<To, From>::isPossible by calling classof with an mlir::Type.
      but other unsuspecting users of LeafType::classof(MiddleType) would still get an incorrect result.
      bb63d249
    • Prabhdeep Singh Soni's avatar
      [MLIR][OpenMP] Add support for safelen clause · b8055c51
      Prabhdeep Singh Soni authored
      This supports translation from MLIR to LLVM IR using OMPIRBuilder for
      OpenMP safelen clause in SIMD construct.
      
      Reviewed By: ftynse
      
      Differential Revision: https://reviews.llvm.org/D132245
      b8055c51
    • Prabhdeep Singh Soni's avatar
      Revert "[MLIR][OpenMP] Add support for safelen clause" · 4fce38cd
      Prabhdeep Singh Soni authored
      This reverts commit 172fe170.
      4fce38cd
    • Simon Pilgrim's avatar
      [X86] Promote i8/i16 CTTZ (BSF) instructions and remove speculation branch · f9de1323
      Simon Pilgrim authored
      This patch adds a Type operand to the TLI isCheapToSpeculateCttz/isCheapToSpeculateCtlz callbacks, allowing targets to decide whether branches should occur on a type-by-type/legality basis.
      
      For X86, this patch proposes to allow CTTZ speculation for i8/i16 types that will lower to promoted i32 BSF instructions by masking the operand above the msb (we already do something similar for i8/i16 TZCNT). This required a minor tweak to CTTZ lowering - if the src operand is known never zero (i.e. due to the promotion masking) we can remove the CMOV zero src handling.
      
      Although BSF isn't very fast, most CPUs from the last 20 years don't do that bad a job with it, although there are some annoying passthrough EFLAGS dependencies. Additionally, now that we emit 'REP BSF' in most cases, we are tending towards assuming this will most likely be executed as a TZCNT instruction on any semi-modern CPU.
      
      Differential Revision: https://reviews.llvm.org/D132520
      f9de1323