1. Mar 11, 2024
    • lntue's avatar
      [libc] Fix flag parsing bugs. (#84706) · 6bec4fc7
      lntue authored
      6bec4fc7
    • fpasserby's avatar
      [coroutine] Implement llvm.coro.await.suspend intrinsic (#79712) · f7868813
      fpasserby authored
      Implement `llvm.coro.await.suspend` intrinsics, to deal with performance
      regression after prohibiting `.await_suspend` inlining, as suggested in
      #64945.
      Actually, there are three new intrinsics, which directly correspond to
      each of three forms of `await_suspend`:
      ```
      void llvm.coro.await.suspend.void(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      i1 llvm.coro.await.suspend.bool(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      ptr llvm.coro.await.suspend.handle(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      ```
      There are three different versions instead of one, because in `bool`
      case it's result is used for resuming via a branch, and in
      `coroutine_handle` case exceptions from `await_suspend` are handled in
      the coroutine, and exceptions from the subsequent `.resume()` are
      propagated to the caller.
      
      Await-suspend block is simplified down to intrinsic calls only, for
      example for symmetric transfer:
      ```
      %id = call token @llvm.coro.save(ptr null)
      %handle = call ptr @llvm.coro.await.suspend.handle(ptr %awaiter, ptr %frame, ptr @wrapperFunction)
      call void @llvm.coro.resume(%handle)
      %result = call i8 @llvm.coro.suspend(token %id, i1 false)
      switch i8 %result, ...
      ```
      All await-suspend logic is moved out into a wrapper function, generated
      for each suspension point.
      The signature of the function is `<type> wrapperFunction(ptr %awaiter,
      ptr %frame)` where `<type>` is one of `void` `i1` or `ptr`, depending on
      the return type of `await_suspend`.
      Intrinsic calls are lowered during `CoroSplit` pass, right after the
      split.
      
      Because I'm new to LLVM, I'm not sure if the helper function generation,
      calls to them and lowering are implemented in the right way, especially
      with regard to various metadata and attributes, i. e. for TBAA. All
      things that seemed questionable are marked with `FIXME` comments.
      
      There is another detail: in case of symmetric transfer raw pointer to
      the frame of coroutine, that should be resumed, is returned from the
      helper function and a direct call to `@llvm.coro.resume` is generated.
      C++ standard demands, that `.resume()` method is evaluated. Not sure how
      important is this, because code has been generated in the same way
      before, sans helper function.
      f7868813
    • wanglei's avatar
      [LoongArch] Make sure that the LoongArchISD::BSTRINS node uses the correct `MSB` value (#84454) · edd4c6c6
      wanglei authored
      The `MSB` must not be greater than `GRLen`. Without this patch, newly
      added test cases will crash with LoongArch32, resulting in a 'cannot
      select' error.
      edd4c6c6
    • Noah Goldstein's avatar
    • Noah Goldstein's avatar
      [InstCombine] Tests for `(icmp eq/ne (and (shl -1, X), Y), 0)` -> `(icmp eq/ne... · cef862e0
      Noah Goldstein authored
      [InstCombine] Tests for `(icmp eq/ne (and (shl -1, X), Y), 0)` -> `(icmp eq/ne (lshr Y, X), 0)`; NFC
      cef862e0
    • Jacek Caban's avatar
      [LLD][COFF] Add support for IMPORT_NAME_EXPORTAS import library names. (#83211) · 7b275aa2
      Jacek Caban authored
      This allows handling importlibs produced by llvm-dlltool in #78772.
      ARM64EC import libraries use it by default, but it's supported by MSVC
      link.exe on other platforms too.
      
      This also avoids assuming null-terminated input, like in #78769.
      7b275aa2
    • Schrodinger ZHU Yifan's avatar
    • Joseph Huber's avatar
      [libc][NFC] Move GPU allocator implementation to common header (#84690) · ea697dcc
      Joseph Huber authored
      Summary:
      This is a NFC move preceding more radical functional changes to the
      allocator implementation. We just move it to a common utility so it will
      be easier to write these in tandem.
      ea697dcc
    • alx32's avatar
      [lld-macho][NFC] Refactor ObjCSelRefsSection out of ObjCStubsSection (#83878) · a53401e9
      alx32 authored
      
      
      Currently ObjCStubsSection is handling both the logic for the
      "__objc_stubs" section, as well as the logic for the "__objc_selrefs"
      section.
      While this is OK for now, it will be an issue for other features that
      want to interact with the "__objc_selrefs" section, such as upcoming
      relative method lists feature - which will also want to create /
      reference entries in the "__objc_selrefs" section.
      In this PR we split the logic relating to handling the "__objc_selrefs"
      section into a new SyntheticSection (ObjCSelRefsSection). Non-functional
      change - neither the behavior nor implementation changes, the interface
      is just made more friendly to not have "__objc_selrefs" so bound to
      "__objc_stubs".
      
      ---------
      
      Co-authored-by: default avatarAlex B <alexborcan@meta.com>
      a53401e9
    • Noah Goldstein's avatar
      [InstCombine] Recognize `(icmp eq/ne (and X, ~Mask), 0)` pattern in `foldICmpWithLowBitMaskedVal` · 193b3d67
      Noah Goldstein authored
      `(icmp eq/ne (and X, ~Mask), 0)` is equivilent to `(icmp eq/ne (and X,
      Mask), X` and we sometimes generate the former pattern intentionally
      to reduce number of uses of `X`.
      Proof: https://alive2.llvm.org/ce/z/3u-usC
      
      Differential Revision: https://reviews.llvm.org/D159329
      
      Closes #81562
      193b3d67
    • Noah Goldstein's avatar
      [InstCombine] Improve mask detection in `foldICmpWithLowBitMaskedVal` · d77eb9ea
      Noah Goldstein authored
      Make recursive matcher that is able to detect a lot more patterns.
      Proofs for all supported patterns: https://alive2.llvm.org/ce/z/fSQ3nZ
      
      Differential Revision: https://reviews.llvm.org/D159058
      d77eb9ea
    • Noah Goldstein's avatar
    • Noah Goldstein's avatar
    • Joseph Huber's avatar
      [libc] Move RPC opcodes include out of the header · 8a790033
      Joseph Huber authored
      Summary:
      This header isn't strictly necessary, and is currently broken because we
      install these to separate locations.
      8a790033
    • Michael Flanders's avatar
      [libc][stdbit] Fix truncation err in CPP bit_ceil (#84683) · a066f71e
      Michael Flanders authored
      After #84657 was merged,
      [buildbot](https://lab.llvm.org/buildbot/#/builders/250/builds/19808) is
      reporting two errors for libc-x86_64-debian-gcc-fullbuild-dbg. This PR
      addresses the truncation error for `CPP::bit_ceil<unsigned char>` and
      `CPP::bit_ceil<unsigned short>`.
      
      The errors are:
      
      ```
      FAILED: projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o
      /usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-vir!
       tual-dtor
        -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -ffreestanding -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o -MF projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o.d -o projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_uc.dir/stdc_bit_ceil_uc.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_uc.cpp
      In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_uc.cpp:11:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h: In instantiation of ‘constexpr __llvm_libc_19_0_0_git::cpp::enable_if_t<is_unsigned_v<T>, T> __llvm_libc_19_0_0_git::cpp::bit_ceil(T) [with T = unsigned char; enable_if_t<is_unsigned_v<T>, T> = unsigned char]’:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_uc.cpp:17:23:   required from here
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h:196:57: error: conversion from ‘unsigned int’ to ‘unsigned char’ may change value [-Werror=conversion]
        196 |   return static_cast<T>(T(1) << cpp::bit_width<T>(value - 1u));
            |                                                   ~~~~~~^~~~
      cc1plus: all warnings being treated as errors
      [138/466] Building CXX object projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o
      FAILED: projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o
      /usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_19_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/projects/libc/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-vir!
       tual-dtor
        -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -fpie -ffreestanding -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=c++17 -MD -MT projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o -MF projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o.d -o projects/libc/src/stdbit/CMakeFiles/libc.src.stdbit.stdc_bit_ceil_us.dir/stdc_bit_ceil_us.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_us.cpp
      In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_us.cpp:11:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h: In instantiation of ‘constexpr __llvm_libc_19_0_0_git::cpp::enable_if_t<is_unsigned_v<T>, T> __llvm_libc_19_0_0_git::cpp::bit_ceil(T) [with T = short unsigned int; enable_if_t<is_unsigned_v<T>, T> = short unsigned int]’:
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/stdbit/stdc_bit_ceil_us.cpp:17:23:   required from here
      /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/__support/CPP/bit.h:196:57: error: conversion from ‘unsigned int’ to ‘short unsigned int’ may change value [-Werror=conversion]
        196 |   return static_cast<T>(T(1) << cpp::bit_width<T>(value - 1u));
            |                                                   ~~~~~~^~~~
      cc1plus: all warnings being treated as errors
      ```
      a066f71e
    • Michael Flanders's avatar
      [libc][stdbit][c23] adds implementation of `stdc_bit_ceil` functions (#84657) · 75b0d384
      Michael Flanders authored
      Closes #84652.
      
      Based on #84233.
      75b0d384
    • Simon Pilgrim's avatar
  2. Mar 10, 2024