Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR][ThroughMLIR] Support lowering SwitchOp without fallthrough to scf #986

Open
wants to merge 1,956 commits into
base: main
Choose a base branch
from
This pull request is big! We’re only showing the most recent 250 commits.

Commits on Oct 12, 2024

  1. [CIR][LowerToLLVM] Exceptions: lower cir.try_call to llvm's invoke

    Incremental step: we need the full try/catch to test `cir.try_call`, so testing
    coming next with the other necessary operations.
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    43f84bd View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    92f4df7 View commit details
    Browse the repository at this point in the history
  3. [CIR][LowerToLLVM] Exceptions: more lowering work for cir.try_call

    …and `cir.eh.inflight_exception`
    
    - Fix parser problems that were preventing testing and fix additional lowering missing for `cir.try_call`.
    - Add lowering from scratch for `cir.eh.inflight_exception`.
    
    End-to-end requires full exception support (still more lowering TBD to get
    there).
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    582f06e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    c28af61 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    ae91222 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    ffe43e7 View commit details
    Browse the repository at this point in the history
  7. [CIR][CodeGen][Lowering] Better handling of alloca address space with…

    … unified AS (llvm#682)
    
    `TargetCodeGenInfo::getASTAllocaAddressSpace` is a bad design because it
    requires the targets return `LangAS`, which enforce the targets to
    consider which languages could be their upstream and unnecessarily
    complicate the target info. Unified AS in CIR is a better abstraction
    level for this kind of target info.
    
    Apart from that, the languages also has some requirements on the result
    address space of alloca.
    
    ```cpp
    void func() {
      int x;
      // Here, the AS of pointer `&x` is the alloca AS defined by the language.
    }
    ```
    
    When we have inconsistency between the alloca AS defined by the language
    and the one from target info, we have to perform `addrspacecast` from
    the target one to the language one.
    
    This PR includes
    * New method `CGM.getLangTempAllocaAddressSpace` which explicitly
    specifies the alloca address space defined by languages. It replaces the
    vague `LangAS::Default` in the AS comparisons from OG CodeGen.
    * Replace `getASTAllocaAddressSpace` with `getCIRAllocaAddressSpace`,
    which returns CIR unified AS.
    * Also use `getCIRAllocaAddressSpace` as the result address space of
    `buildAlloca`.
    * Fix the lowering of `cir.alloca` operation to be address-space-aware.
    
    We don't perform any `addrspacecast` in this PR, i.e. all the related
    code paths still remain NYI and it's fine. That's because we don't even
    have a `(language, target)` pair holding the inconsistency.
    
    After these changes, in the previous OpenCL testcases we will see all
    the alloca pointers turning into private AS, without any
    `addrspacecast`.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    256a8bb View commit details
    Browse the repository at this point in the history
  8. [CIR][ThroughMLIR] Lowering cir.do to scf.while,and fix cir.while low…

    …ering bugs. (llvm#756)
    
    In this pr, I lowering cir.do to scf.while, fix cir.while nested loop
    bugs and add test cases.
    GaoXiangYa authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    c8fc5d5 View commit details
    Browse the repository at this point in the history
  9. [CIR][CIRGen] Add CIRGen for scalar co_yield expression (llvm#761)

    This PR adds CIRGen for scalar `co_yield` expressions.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    f25c23e View commit details
    Browse the repository at this point in the history
  10. [CIR] CIRGen for bit cast builtin (llvm#762)

    This PR adds CIRGen support for the `__builtin_bit_cast` builtin. No new
    operations are added so the LLVM IR lowering is also added
    automatically.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    30bc050 View commit details
    Browse the repository at this point in the history
  11. [CIR][ABI][NFCI] Enable SPIR-V return value and argument ABI to use D…

    …irect and Extend (llvm#763)
    
    This NFCI PR enhances the SPIR-V *CIRGen* ABI with Direct and Extend in
    both argument and return value, because some future test cases requires
    it.
    
    * kernel argument metadata needs arguments of promotable integer types
    * builtin functions like `get_global_id` returns `si64`, rather than
    void for all OpenCL kernels
    
    Given that CallConvLowering will replace these bits and other targets is
    already doing the same, I think it's safe to enable it now.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    9fe2333 View commit details
    Browse the repository at this point in the history
  12. [CIR][LowerToLLVM][NFC] Refactor amendOperation to dispatch differe…

    …nt ops (llvm#768)
    
    Soon I would like to submit a patch emitting OpenCL module metadata in
    LowerToLLVM path, which requires to attach the metadata to LLVM module
    when `amendOperaion` is called for MLIR module op. This PR refactors the
    method to a dispatcher to make the future changes cleaner.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    cdea7af View commit details
    Browse the repository at this point in the history
  13. [CIR][Dialect] Emit OpenCL kernel argument metadata (llvm#767)

    Similar to llvm#705, this PR implements the remaining
    `genKernelArgMetadata()` logic.
    
    The attribute `cir.cl.kernel_arg_metadata` is also intentionally placed
    in the `cir.func`'s `extra_attrs` rather than `cir.func`'s standard
    `arg_attrs` list. Also, the metadata is stored by `Array` with proper
    verification on it. See the tablegen doc string for details.
    
    This is in order to
    * keep it side-by-side with `cl.kernel_metadata`.
    * still emit metadata when kernel has an *empty* arg list (see the test
    `kernel-arg-meatadata.cl`).
    * avoid horrors of repeating the long name `cir.cl.kernel_arg_metadata`
    for `numArgs` times.
    
    Because clangir doesn't support OpenCL built-in types and the `half`
    floating point type yet, their changes and test cases are not included.
    Corresponding missing feature flag is added.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    aa85d46 View commit details
    Browse the repository at this point in the history
  14. [CIR][Dialect][Lowering] Add calling convention attribute to FuncOp (l…

    …lvm#760)
    
    This PR simply adds the calling convention attribute to FuncOp with LLVM
    Lowering support.
    
    The overall approach follows `GlobalLinkageKind`: Extend the ODS,
    parser, printer and lowering pass. When the call conv is C call conv,
    it's omitted in the output assembly.
    
    ---------
    
    Co-authored-by: Bruno Cardoso Lopes <[email protected]>
    2 people authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    e2c3b82 View commit details
    Browse the repository at this point in the history
  15. [CIR][ThroughMLIR] Support array type GlobalOp lowering with initial …

    …values (llvm#753)
    
    This commit makes the changes as following.
    
    1. Enable array type GlobalOp lowering with initial values
    
    2. Add error message when array size is not equal to initial string
    value size
           E.g. char big_string[10] = "abc";
    ShivaChen authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    a8c8d47 View commit details
    Browse the repository at this point in the history
  16. [CIR][LowerToLLVM][NFC] Add data layout verification of alloca as (ll…

    …vm#769)
    
    There are two sources for the target allocation address space: one from
    `TargetCIRGenInfo::getCIRAllocaAddressSpace()` and another from
    `targetDataLayout.getAllocaMemorySpace()`. Since both are provided by
    the specific target, they should be consistent. This PR adds a check to
    ensure this consistency and avoid potential errors.
    
    The ctor of `CIRAllocaLowering` pattern is updated to pass the data
    layout in.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    515a6bb View commit details
    Browse the repository at this point in the history
  17. [CIR][CodeGen][NFC] Replace the calling convention in CodeGen with th…

    …e one in dialect (llvm#772)
    
    This PR remove the header `CIR/CodeGen/CallingConv.h` and migrates all
    `::cir::CallingConv` stuff to `::mlir::cir::CallingConv` in
    `CIRGenTypes` and `CIRGenFunctionInfo`.
    
    In TargetLowering library, LowerTypes and LowerFunctionInfo basically
    have the same clangCallConvToLLVMCallConv stuff. The CC there is the
    LLVM one. But those changes are not included because of the potential
    conflicts. We can still easily switch to the dialect when it's needed.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    8f08c82 View commit details
    Browse the repository at this point in the history
  18. [CIR][Dialect] Add OpenCL C language in cir.lang (llvm#774)

    This PR adds OpenCL C language case to the enum
    `mlir::cir::SourceLanguage`, and maps `opts.OpenCL &&
    !opts.OpenCLCPlusPlus` to it.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    7f6a112 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    8fe0460 View commit details
    Browse the repository at this point in the history
  20. [CIR] Introduce CIR simplification (llvm#696)

    This PR introduce cir simplification pass. The idea is to have a pass
    for the redundant operations removal/update.
    
    Right now two pattern implemented, both related to the redundant `bool`
    operations.
    First pattern removes redundant casts from `bool` to `int` and back that
    for some reasons appear in the code.
    Second pattern removes sequential unary not operations (`!!`) .
    
    For example, the code from the test is expanded from the simple check
    that is common for C code:
    
    ```
    #define CHECK_PTR(ptr)  \
      do {                   \
        if (__builtin_expect((!!((ptr) == 0)), 0))\
          return -42; \
      } while(0)
    ```
    
    I mark this PR as a draft for the following reasons:
    1) I have no idea if it's useful for the community
    2) There is a test fail - unfortunately current pattern rewriter run DCE
    underneath the hood and looks like we can't workaround it.
    It's enough just to add an operation to the list - in this case
    `UnaryOp` - and call `applyOpPatternsAndFold`. I could rewrite a test a
    little in order to make everything non dead or implement a simple fix
    point algorithm for the particular task (I would do the former).
    gitoleg authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    d196a1c View commit details
    Browse the repository at this point in the history
  21. [CIR][NFC] Cleanup whitespaces

    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    4e0f6a3 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    beb5cdf View commit details
    Browse the repository at this point in the history
  23. [CIR] Add support for complex cast operations (llvm#758)

    This PR adds support for complex cast operations. It adds the following
    new cast kind variants to the `cir.cast` operation:
    
      - `float_to_complex`,
      - `int_to_complex`,
      - `float_complex_to_real`,
      - `int_complex_to_real`,
      - `float_complex_to_bool`,
      - `int_complex_to_bool`,
      - `float_complex`,
      - `float_complex_to_int_complex`,
      - `int_complex`, and
      - `int_complex_to_float_complex`.
    
    CIRGen and LLVM IR support for these new cast variants are also
    included.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    5ee7f9f View commit details
    Browse the repository at this point in the history
  24. [CIR][CodeGen][LowerToLLVM] Emit OpenCL version metadata for SPIR-V t…

    …arget (llvm#773)
    
    Similar to llvm#767, this PR emit the module level OpenCL version metadata
    following the OG CodeGen skeleton.
    
    We use a full qualified `cir.cl.version` attribute on the module op to
    store the info in CIR.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    fc230fb View commit details
    Browse the repository at this point in the history
  25. [CIR][Transforms] Add folders for complex operations (llvm#775)

    This PR adds folders for `cir.complex.create`, `cir.complex.real`, and
    `cir.complex.imag`.
    
    This PR adds a new attribute `#cir.complex` that represents a constant
    complex value. Besides, the CIR dialect does not have a constant
    materializer yet; this PR adds it.
    
    Address llvm#726 .
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    8ffb552 View commit details
    Browse the repository at this point in the history
  26. [CIR][CodeGen][NFCI] Target-independent ABI handling for SpirKernel c…

    …all conv (llvm#778)
    
    This PR follows OG CodeGen to use SPIR ABI info whatever the target is
    when analysing the function info of SPIR-V kernels (identified by its
    calling convention).
    
    For example, when compiling OpenCL kernels to x86-64 target, the kernel
    should still use SPIR-V's ABIInfo.
    
    As we haven't implemented SPIR-V ABI handling for complex constructs,
    there should be no functional changes. There is a test for this logic in
    OG CodeGen:
    `clang/test/CodeGenOpenCL/kernels-have-spir-cc-by-default.cl`. It mainly
    involves structs, which is beyond the progress of CIR ABI stuff.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    fdb48cb View commit details
    Browse the repository at this point in the history
  27. [CIR][Dialect] Add address space attribute to global op (llvm#779)

    This PR adds the CIR address space attribute to GlobalOp and starts to
    resolve the missing feature flag `addressSpaceInGlobalVar`.
    
    The same asm format in pointer type is used:
    
    ```
    cir.global external addrspace(offload_global) @addrspace1 = #cir.int<1> : !s32i
    ```
    
    The parsing and printing helper is extracted into a common function to
    be reused by both `GlobalOp` and `PointerType` with two custom format
    proxy to it. That's because the signature of ODS generated method
    differs from the one for PointerType.
    
    Lowering to LLVM IR and CIRGen will come sequentially.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    5e8b4a1 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    b4bc921 View commit details
    Browse the repository at this point in the history
  29. [CIR][LowerToLLVM] Exceptions: lower cir.alloc.exception

    Incremental work: test is available in the followup commit.
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    f7b6a49 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    fc2ea65 View commit details
    Browse the repository at this point in the history
  31. [CIR][CodeGen] Set CIR function calling conventions (llvm#780)

    This PR adds the counterparts of methods `SetFunctionAttributes`
    `SetLLVMFunctionAttributes` from OG CodeGen, in order to set proper
    calling conv for `cir.func` ops.
    
    `spir-calling-conv.cl` is the dedicated test, while other OpenCL-related
    tests are also updated. It removes previous workaround of incorrect
    calling conv and better synchronizes with the original tests. (These
    changes are not musts).
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    65817d7 View commit details
    Browse the repository at this point in the history
  32. [CIR][CodeGen][Dialect][NFC] Refactor OpenCL stuff to separate impl f…

    …iles (llvm#781)
    
    This PR refactors OpenCL-specific logic that is rather independent from
    CIRGen and dialect definition into two new implementation files:
    `CIRGenOpenCL.cpp` and `CIROpenCLAttrs.cpp`.
    
    There will also be a `CIRGenOpenCLRuntime.cpp` in the future as the
    counterpart of `CGOpenCLRuntime.cpp` from OG CodeGen. But that's
    basically a dedicated implementation file of a class `CGOpenCLRuntime`,
    we should not bother it.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    5743391 View commit details
    Browse the repository at this point in the history
  33. [CIR][ClangTidy][Lifetime] Update to newer dyn_cast usage and update …

    …pass pipeline
    
    Unbreaks `ninja check-clang-extra-clang-tidy`
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    054485c View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    1ef4b45 View commit details
    Browse the repository at this point in the history
  35. [CIR][FrontendAction] Use ClangIR pipeline to emit LLVM bitcode (llvm…

    …#782)
    
    This PR enables ClangIR pipeline for LLVM bitcode output when it's
    specified properly, aligned with the behavior of text-form LLVM IR.
    
    Some refactors about switch cases are also included to avoid too many
    dups.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    6912d20 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    ae5a97e View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    48a3782 View commit details
    Browse the repository at this point in the history
  38. [CIR][CIRGen] Builtins: focus on non fast math path

    The LLVM lowering actually maps to the version without fast math, to add
    support for fast math we need to set the proper LLVM attribute on each of those
    operations.
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    4bda394 View commit details
    Browse the repository at this point in the history
  39. [CIR][LowerToLLVM] Support address space lowering for global ops (llv…

    …m#783)
    
    This PR set a proper addrspace attribute for LLVM globals. For
    simplicity, a temporary pointer type is created and consumed by our LLVM
    type converter. The correct address space is then extracted from the
    converted pointer type of LLVM.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    04287e2 View commit details
    Browse the repository at this point in the history
  40. [CIR][ABI] Implement basic struct CC lowering for x86_64 (llvm#784)

    This patch adds the necessary bits for unraveling struct arguments and
    return values for the x86_64 calling convention.
    sitio-couto authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    84a486a View commit details
    Browse the repository at this point in the history
  41. [CIR][CIRGen] Implement VisitCXXStdInitializerListExpr to support use…

    … of std::initializer_list (llvm#764)
    
    implement VisitCXXStdInitializerListExpr as similar as to
    [OG](https://github.com/llvm/clangir/blob/7150a050c12119c27e9eb1547aa65f535e4bfbe9/clang/lib/CodeGen/CGExprAgg.cpp#L417):
    In order to support this implementation, made some changes to get more
    helper functions.
    Also added some tests.
    
    The generated LLVM code is most similar to OG's llvm code, 3 interesting
    differences:
    1.  CIR introduced scope, thus extra branch
    2. OG' has comdat for _ZSt1fIiEvSt16initializer_listIT_E function, but
    we haven't implemented FuncOP's comdat yet. I'll probably try to add it
    in another PR, but it's not in the scope of this PR.
    3. When defining initialized_list type, OG prefers generic type like
    %"class.std::initializer_list" = type { ptr, ptr }, but CIR prefers
    instantiated like "%"class.std::initializer_list<const char *>" = type {
    ptr, ptr }"
    ghehg authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    9c33243 View commit details
    Browse the repository at this point in the history
  42. [CIR][CIRGen] Support more complex value casts (llvm#786)

    This PR adds CIRGen and LLVMIR codegen for those not-yet-covered complex
    casts, including explicit type cast expressions of complex types and
    complex value promotion.
    
    All type conversion expressions involving complex types should now
    codegen.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    6949a3a View commit details
    Browse the repository at this point in the history
  43. [CIR][Dialect] Add verification of address space to get_global (llv…

    …m#787)
    
    This PR verifies `cir.get_global` has its result type correctly
    annotated with address space of the referenced symbol. The documentation
    is also updated to clarify this constraint.
    
    `GlobalOp` is the main consideration. It's worth noting that if the
    `cir.get_global` op references a function, we also (implicitly) checks
    that its result pointer type has no address space attribute.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    a0239aa View commit details
    Browse the repository at this point in the history
  44. [CIR][CodeGen] Set address space for OpenCL globals (llvm#788)

    This PR sets proper address space when creating `cir.global` and
    `cir.get_global`.
    
    Different languages use different ways to encode the address space in
    AST constructs (i.e. VarDecl *). OpenCL and SYCL use an address space
    qualifier on the type of `VarDecl`, while CUDA uses separate AST
    attributes like `CUDASharedAttr`. Similarily, some targets may want to
    use special address space for global variables. So a per-language +
    per-target hook is needed to provide this customization point. In the
    LLVM CodeGen, it's the helper method `getGlobalVarAddressSpace` that
    takes on the role.
    
    For OpenCL C + SPIR-V combination, OpenCL C converts the address space
    qualifier to corresponding LangAS, but SPIR-V does not require any
    action.
    
    This PR implements `global` qualifier in OpenCL C, but does not include
    `constant` qualifier. Although the modified part works for `constant`,
    CIRGen is not yet able to set constant attribute for global ops (there
    is a TODO line).
    
    Static variable decl and `local` qualifier work in a similar way and
    come in later patches.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    0fb41a1 View commit details
    Browse the repository at this point in the history
  45. [CIR] Fix wrong LLVMIR lowering of fp decrement (llvm#789)

    Unary decrement expression on floating point operands was lowered to
    `fsub -1.0` by a typo. This PR fixes this bug.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    1e9382e View commit details
    Browse the repository at this point in the history
  46. [CIR][CIRGen] Add new CIR visibility to represent Default, Hidden, Pr…

    …otected (llvm#776)
    
    This PR add a new CIR attribute `mlir::cir::VisibilityAttr` to represent
    CIR visibility. It will represent C/C++ visibility type `Default`,
    `Hidden`, `Protected`.
    
    The PR handles the parsing, printing of CIR visibility and also lower to
    LLVM.
    
    After this PR, there will be more PR's to migrate CIRGen properties that
    are currently querying MLIR visibility(e.g. `sym_visibility`), to
    instead query CIR visibility, and remove MLIR's visibility from printing
    and parsing.
    roro47 authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    354e876 View commit details
    Browse the repository at this point in the history
  47. [CIR][CIRGen] Complex unary increment and decrement operator (llvm#790)

    This PR adds CIRGen and LLVMIR lowering for unary increment and
    decrement expressions of complex types.
    
    Currently blocked by llvm#789 .
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    4eb034b View commit details
    Browse the repository at this point in the history
  48. [CIR][CodeGen] Set address space for OpenCL static and local-qualifie…

    …d variables (llvm#792)
    
    In OpenCL, `local`-qualified variables are implicitly considered as
    static. In order to support it, this PR unblocks code paths related to
    OpenCL static declarations in `CIRGenDecl.cpp`.
    
    Following the approach of LLVM CodeGen, a new class
    `CIRGenOpenCLRuntime` is added to handle the language hook of creating
    `local`-qualified variables. The default behavior of this hook is quite
    simple. It forwards the call to `CGF.buildStaticVarDecl`.
    
    So in CIR, the OpenCL local memory representation is equivalent to the
    one defined by SPIR-LLVM convention: a `cir.global` with
    `addrspace(local)` and *without initializer*, which corresponds to LLVM
    `undef` initializer. See check lines in test for more details.
    
    A `static global`-qualified variable is also added in the test to
    exercise the static code path itself.
    seven-mile authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    34bc341 View commit details
    Browse the repository at this point in the history
  49. [CIR][ABI][NFC] Follow-up to struct unpacking (llvm#791)

    This patch fixes a bunch of pending review comments in llvm#784:
    
     - Remove data layout attribute from address space testing
     - Remove incoherent comment
     - Rename abi_or_pref to abiOrPref
     - Make comments impersonal
     - Implement feature guard for ARM's CMSE secure call feature
     - Track volatile return times feature in CC lowering
     - Track missing features in the Itanium record builder
     - Remove incoherent fix me
     - Clarify comment regarding CIR record layout getter
     - Track missing cache for record layout getter
     - Remove unnecessary todo's
    sitio-couto authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    e487b83 View commit details
    Browse the repository at this point in the history
  50. [CIR][CIRGen] Add CIRGen support for pointer-to-member-functions (llv…

    …m#722)
    
    This PR adds the initial CIRGen support for pointer-to-member-functions.
    It contains the following new types, attributes, and operations:
    
      - `!cir.method`, which represents the pointer-to-member-function type.
    - `#cir.method`, which represents a literal pointer-to-member-function
    value that points to ~~non-virtual~~ member functions.
    - ~~`#cir.virtual_method`, which represents a literal
    pointer-to-member-function value that points to virtual member
    functions.~~
    - ~~`cir.get_method_callee`~~ `cir.get_method`, which resolves a
    pointer-to-member-function to a function pointer as the callee.
    
    See the new test at `clang/test/CIR/CIRGen/pointer-to-member-func.cpp`
    for how these new CIR stuff works to support
    pointer-to-member-functions.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    63c6bdf View commit details
    Browse the repository at this point in the history
  51. [CIR][CIRGen] Achieve union's bitfields additionally. (llvm#742)

    Achieve union's bitfields additionally.
    566hub authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    970efe9 View commit details
    Browse the repository at this point in the history
  52. [CIR] Cleanup most recent warnings

    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    2f82a2a View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    e6ac8e5 View commit details
    Browse the repository at this point in the history
  54. [CIR] Add select operation (llvm#796)

    This PR adds a new `cir.select` operation. This operation won't be
    generated directly by CIRGen but it is useful during further CIR to CIR
    transformations.
    
    This PR addresses llvm#785 .
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    253d1e3 View commit details
    Browse the repository at this point in the history
  55. [CIR][CIRGen] Inline variables processing (llvm#794)

    There is an implementation for inline variables processing at CIR. The
    LIT test was taken from clang's cxx1z-inline-variables.cpp where the
    same functionality is tested for Clang Code generation. The test can be
    run as follows
    ```
    bin/llvm-lit -v ../clang/test/CIR/CodeGen/cxx1z-inline-variables.cpp
    ```
    
    Note: the pull request also contains a formatting change for two files:
    - `clang/lib/CIR/Dialect/IR/CIRDataLayout.cpp`
    - `clang/lib/CIR/Dialect/Transforms/TargetLowering/Targets/X86.cpp`
    ivanmurashko authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    cb40fcc View commit details
    Browse the repository at this point in the history
  56. [CIR] Incorrect global view index and offset when neg index (llvm#795)

    mixed signed and unsigned integer operator cause difference result when
    index of array is negative
    HerrCai0907 authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    8dc84ff View commit details
    Browse the repository at this point in the history
  57. [CIR][NFC] Replace ternary ops after lowering prepare to select ops (l…

    …lvm#800)
    
    This PR refactors the LoweringPrepare pass and replaces various ternary
    ops generated by LoweringPrepare with semantically equivalent select
    ops.
    Lancern authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    2f86e11 View commit details
    Browse the repository at this point in the history
  58. [CIR][CirGen][Bugfix] Fixes __sync_fetch_and_add for unsigned integers (

    llvm#799)
    
    `__sync_fetch_and_add` currently doesn't support unsigned integers. 
    
    The following code snippet, for example, raises an error:  
    ```
    #include <stdint.h>
    
    void foo(uint64_t x) {
      __sync_fetch_and_add(&x, 1);
    }
    ```
    The error can be traced down to this line `auto intType =
    builder.getSIntNTy(cgf.getContext().getTypeSize(typ));` from
    `clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp`.
    bruteforceboy authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    403f4dc View commit details
    Browse the repository at this point in the history
  59. Configuration menu
    Copy the full SHA
    d784759 View commit details
    Browse the repository at this point in the history
  60. [CIR][NFC] Fix sign-compare warning

    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    f13d2ec View commit details
    Browse the repository at this point in the history
  61. Configuration menu
    Copy the full SHA
    49ceda3 View commit details
    Browse the repository at this point in the history
  62. Configuration menu
    Copy the full SHA
    307fd34 View commit details
    Browse the repository at this point in the history
  63. [CIR][Lowering] Add the concept of simple lowering and use it for una…

    …ry fp2fp operations (llvm#806)
    
    This PR is the continuation and refinement of PR llvm#434 which is
    originally authored by @philnik777 . Does not update it in-place since I
    don't have commit access to Nikolas' repo.
    
    This PR basically just rebases llvm#434 onto the latest `main`. I also
    updated some naming used in the original PR to keep naming styles
    consistent.
    
    Co-authored-by: Nikolas Klauser <[email protected]>
    2 people authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    ddf7003 View commit details
    Browse the repository at this point in the history
  64. [CIR][CIRGen] Exceptions: Use the surrounding scope (if available) fo…

    …r try local allocas
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    ec31a4a View commit details
    Browse the repository at this point in the history
  65. Configuration menu
    Copy the full SHA
    e9527a6 View commit details
    Browse the repository at this point in the history
  66. [CIR][CIRGen] Exceptions: handle cleanups and global initializers

    Still missing CFG flattening and lowering, coming next.
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    806b457 View commit details
    Browse the repository at this point in the history
  67. Configuration menu
    Copy the full SHA
    14dd633 View commit details
    Browse the repository at this point in the history
  68. Configuration menu
    Copy the full SHA
    c0c66d7 View commit details
    Browse the repository at this point in the history
  69. Configuration menu
    Copy the full SHA
    1529f0e View commit details
    Browse the repository at this point in the history
  70. [CIR][CIRGen][NFC] Add more skeleton to make crashes fine grained on …

    …pushTemporaryCleanup
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    8ef6fce View commit details
    Browse the repository at this point in the history
  71. Configuration menu
    Copy the full SHA
    672ade9 View commit details
    Browse the repository at this point in the history
  72. Configuration menu
    Copy the full SHA
    eefe053 View commit details
    Browse the repository at this point in the history
  73. [CIR][CIRGen] Handle more cleanup situations and fix bug

    - Tackle a FIXME left in previous commit.
    - Start turning missing cleanup features into actual NYI asserts.
    - Make sure we run CleanupDeactivationScope properly and deactivate necessary cleanups.
    - Add more verifications/asserts for overall state.
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    91720d6 View commit details
    Browse the repository at this point in the history
  74. Configuration menu
    Copy the full SHA
    9682945 View commit details
    Browse the repository at this point in the history
  75. Configuration menu
    Copy the full SHA
    b6685a2 View commit details
    Browse the repository at this point in the history
  76. [CIR] Disable test temporatily

    This is currently crashing on Linux only internally, but not on GitHub's CI,
    disable it temporarily while we investigate.
    bcardosolopes authored and lanza committed Oct 12, 2024
    Configuration menu
    Copy the full SHA
    5956abb View commit details
    Browse the repository at this point in the history

Commits on Oct 14, 2024

  1. Configuration menu
    Copy the full SHA
    f494178 View commit details
    Browse the repository at this point in the history
  2. [CIR] Reland failing tests (llvm#811)

    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ef771a4 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Support pure and deleted virtual functions (llvm#823)

    This is a straightforward adaption of existing CodeGen logic. While I'm
    here, move block comments inside their blocks, so that they look nicer.
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ecae00b View commit details
    Browse the repository at this point in the history
  4. [CIR][CIRGen][Lowering] Get alignment from frontend and pass it to LL…

    …VM (llvm#810)
    
    As title.
    Add setAlignmentAttr for GlobalOps created from AST.
    LLVM Lowering should have LLVM GlobalOp's alignment attribute inherited
    from CIR::GlobalOp.
    
    This PR is definitely needed to fix issue
    llvm#801 (comment), but
    the issue doesn't have alignment and comdat attribute for CIR Ops to
    begin with, so I'll keep investigating and fix CIR problem in another
    PR.
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    cd0ca4c View commit details
    Browse the repository at this point in the history
  5. [CIR][CodeGen] Fix address space of result pointer type of array deca…

    …y cast op (llvm#812)
    
    There are two occurrences of `cir.cast(array_to_ptrdecay, ...)` that
    drop address spaces unexpectedly for its result pointer type. This PR
    fixes them with the source address space.
    
    ```mlir
    // Before
    %1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i>
    // After
    %1 = cir.cast(array_to_ptrdecay, %0 : !cir.ptr<!cir.array<!s32i x 32>, addrspace(offload_local)>), !cir.ptr<!s32i, addrspace(offload_local)>
    ```
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    99aef47 View commit details
    Browse the repository at this point in the history
  6. [CIR][Transform] Add simplify transformation for select op (llvm#816)

    As mentioned at
    llvm#809 (comment) , this
    PR adds more simplify transformations for select op:
    
    - `cir.select if %0 then x else x` -> `x`
    - `cir.select if %0 then #true else #false` -> `%0`
    - `cir.select if %0 then #false else #true` -> `cir.unary not %0`
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    410d638 View commit details
    Browse the repository at this point in the history
  7. [CIR][NFC] Extend simple lowering to unary fp2int ops and binary fp2f…

    …p ops (llvm#818)
    
    This PR makes simple lowering generate the result type lowering logic
    and make it suitable for unary fp2int operations and binary fp2fp
    operations.
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    f32fe84 View commit details
    Browse the repository at this point in the history
  8. [CIR][CIRGen] Add initial CIRGen support for local temporary material…

    …ization (llvm#820)
    
    This PR adds initial support for temporary materialization of local
    temporaries with trivial cleanups.
    
    Materialization of global temporaries and local temporaries with
    non-trivial cleanups is far more trickier that I initially thought and I
    decide to submit this easy part first.
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    7f528a8 View commit details
    Browse the repository at this point in the history
  9. [CIR][CIRGen] Implement delegating constructors (llvm#821)

    This is a straightforward adaption from CodeGen. I checked the uses of
    the Delegating arg that's passed in various places, and it only appears
    to be used by virtual inheritance, which should be handled by
    llvm#624.
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    d6c0ec3 View commit details
    Browse the repository at this point in the history
  10. [CIR][Dialect] Verify bitcast does not contain address space conversi…

    …on (llvm#813)
    
    Currently some bitcasts would silently change the address space of
    source pointer type, which hides some miscompilations of pointer type in
    CIR.
    
    llvm#812 is an example. The address space in result pointer type is dropped,
    but the bitcast later keep the type consistency no matter what the
    result type is. Such bitcast is commonly emitted in CodeGen.
    
    CIR bitcasts are lowered to LLVM bitcasts, which also don't allow
    mismatch between address spaces. This PR adds this verification.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    8dc4fb4 View commit details
    Browse the repository at this point in the history
  11. [CIR][Dialect] Remove 22 prefix and suffix from type aliases (llvm#826)

    We were previously printing the type alias for `struct S` as `!ty_22S22`
    instead of just `!ty_S`. This was because our alias computation for a
    StructType did the following:
    
        os << "ty_" << structType.getName()
    
    `structType.getName()` is a `StringAttr`, and writing a `StringAttr` to
    an output stream adds double quotes around the actual string [1][2].
    These double quotes then get hex-encoded as 22 [3].
    
    We can fix this by writing the actual string value instead. Aliases that
    would end in a number will now receive a trailing underscore because of
    MLIR's alias sanitization not allowing a trailing digit [4] (which
    ironically didn't kick in even though our aliases were always previously
    ending with a number, which might be a bug in the sanitization logic).
    Aliases containing other special characters (e.g. `::`) will still be
    escaped as before. In other words:
    
    ```
    struct S {};
    // before: !ty_22S22 = ...
    // after:  !ty_S = ...
    
    struct S1 {};
    // before: !ty_22S122 = ...
    // after:  !ty_S1_ = ...
    
    struct std::string {};
    // before: !ty_22std3A3Astring22
    // after:  !ty_std3A3Astring
    ```
    
    I'm not a big fan of the trailing underscore special-case, but I also
    don't want to touch core MLIR logic, and I think the end result is still
    nicer than before.
    
    The tests were mechanically updated with the following command run
    inside `clang/test/CIR`, and the same commands can be run to update the
    tests for any in-flight patches. (These are for GNU sed; for macOS
    change the `-i` to `-i ''`.)
    
    find . -type f | xargs sed -i -E -e
    's/ty_22([A-Za-z0-9_$]+[0-9])22/ty_\1_/g' -e
    's/ty_22([A-Za-z0-9_$]+)22/ty_\1/g'
    
    clang/test/CIR/CodeGen/stmtexpr-init.c needed an additional minor fix to
    swap the expected order of two type aliases in the CIR output.
    clang/test/CIR/CodeGen/coro-task.cpp needed some surgery because it was
    searching for `22` to find the end of a type alias; I changed it to
    search for the actual alias instead.
    
    If you run into merge conflicts after this change, you can auto-resolve
    them via
    
    smeenai@715f061
    
    [1]
    https://github.com/llvm/llvm-project/blob/b3d2d5039b9b8aa10a86c593387f200b15c02aef/mlir/lib/IR/AsmPrinter.cpp#L2295
    [2]
    https://github.com/llvm/llvm-project/blob/b3d2d5039b9b8aa10a86c593387f200b15c02aef/mlir/lib/IR/AsmPrinter.cpp#L2763
    [3]
    https://github.com/llvm/llvm-project/blob/b3d2d5039b9b8aa10a86c593387f200b15c02aef/mlir/lib/IR/AsmPrinter.cpp#L1014
    [4]
    https://github.com/llvm/llvm-project/blob/b3d2d5039b9b8aa10a86c593387f200b15c02aef/mlir/lib/IR/AsmPrinter.cpp#L1154
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    f8d1d9c View commit details
    Browse the repository at this point in the history
  12. [CIR][Lowering] Fix BrCond Lowering (llvm#819)

    This PR fixes the lowering for BrCond. 
    
    Consider the following code snippet: 
    ```
    #include <stdbool.h>
    
    bool test() {
      bool x = false;
      if (x) 
        return x;
      return x;
    } 
    ```
    Emitting the CIR to `tmp.cir` using `-fclangir-mem2reg` produces the
    following CIR (truncated):
    ```
    !s32i = !cir.int<s, 32>
    #fn_attr = #cir<extra({inline = #cir.inline<no>, nothrow = #cir.nothrow, optnone = #cir.optnone})>
    module { cir.func no_proto  @test() -> !cir.bool extra(#fn_attr) {
        %0 = cir.const #cir.int<0> : !s32i 
        %1 = cir.cast(int_to_bool, %0 : !s32i), !cir.bool 
        cir.br ^bb1 
      ^bb1:  // pred: ^bb0
        cir.brcond %1 ^bb2, ^bb3 
      ^bb2:  // pred: ^bb1
        cir.return %1 : !cir.bool 
      ^bb3:  // pred: ^bb1
        cir.br ^bb4 
      ^bb4:  // pred: ^bb3
        cir.return %1 : !cir.bool 
      } 
    }
    ```
    Lowering the CIR to LLVM using `cir-opt tmp.cir -cir-to-llvm` fails
    with:
    ```
    tmp.cir:5:10: error: failed to legalize operation 'llvm.zext' marked as erased
    ```
    
    The CIR cast `%1 = cir.cast(int_to_bool, %0 : !s32i)` is lowered to a
    CIR comparison with zero, which is then lowered to an `LLVM::ICmpOp` and
    `LLVM::ZExtOp`.
    
    In the BrCond lowering, the zext is deleted when `zext->use_empty()`,
    but during this phase the lowering for the CIR above is not complete
    yet, because the zext will still have usage(s) later.
    
    The current check for when the zext is deleted is error-prone and can be
    improved.
    
    To fix this, in addition to checking that the use of the zext is empty,
    an additional check that the defining operation for the BrCond in the
    CIR (the cast operation in this case) is used exactly once is added.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    a4fa59b View commit details
    Browse the repository at this point in the history
  13. [CIR] Add some extra dumping to help with intermitent bug

    We haven't been able to find the root cause of
    llvm#829 just yet, the problem does also not
    show up under a ASANified build.
    
    Add some extra information before we crash, hopefully that might shed some
    light.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    dd9e883 View commit details
    Browse the repository at this point in the history
  14. [CIR][driver] Forward -fno-clangir-direct-lowering option to cc1 (llv…

    …m#822)
    
    Allow from the clang driver the use of lowering from CIR to MLIR
    standard dialect.
    Update the test to match the real output when
    `-fno-clangir-direct-lowering` is used, or with a combination of both
    `-fclangir-direct-lowering` and `-fno-clangir-direct-lowering`.
    
    ---------
    
    Co-authored-by: Bruno Cardoso Lopes <[email protected]>
    Co-authored-by: Shoaib Meenai <[email protected]>
    3 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ed1f9fd View commit details
    Browse the repository at this point in the history
  15. [CIR][CIRGen] Exceptions: handle synthetic cir.try within functions

    We can now get the cleanup right for other potential throwing ctors,
    still missing LLVM lowering support.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    f2349c4 View commit details
    Browse the repository at this point in the history
  16. [CIR][Transform] Add ternary simplification (llvm#809)

    This PR adds a new transformation that transform suitable ternary
    operations into select operations.
    
    Currently the "suitable" ternary operations are those ternary operations
    whose both branches satisfy either one of the following criteria:
    
    - The branch only contain a single `cir.yield` operation;
    - The branch contains a `cir.const` followed by a `cir.yield` that
    yields the constant value produced by the `cir.const`.
    - ~~The branch contains a `cir.load` followed by a `cir.yield` that
    yields the value loaded by the `cir.load`. The load operation cannot be
    volatile and must load from an alloca.~~
    
    These criteria are hardcoded now so that simple C/C++ ternary
    expressions could be eventually lowered to a `cir.select` operation
    instead.
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    c1e80e1 View commit details
    Browse the repository at this point in the history
  17. [CIR][CIRGen] Support a defined pure virtual destructor (llvm#825)

    This is permitted by the language, and IRGen emits traps for destructors
    other than the base object destructor. Make CIRGen follow suit.
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    127fb54 View commit details
    Browse the repository at this point in the history
  18. [CIR][Dialect] Add calling convention attribute to cir.call op (llvm#828

    )
    
    The first patch to fix llvm#803 . This PR adds the calling convention
    attribute to CallOp directly, which is similar to LLVM, rather than
    adding the information to function type, which mimics Clang AST function
    type.
    
    The syntax of it in CIR assembly is between the function type and extra
    attributes, as follows:
    
    ```mlir
    %1 = cir.call %fnptr(%a) : (!fnptr, !s32i) -> !s32i cc(spir_kernel) extra(#fn_attr)
    ```
    
    The verification of direct calls is not included. It will be included in
    the next patch extending CIRGen & Lowering.
    
    ---
    
    For every builder method of Call Op, an optional parameter `callingConv`
    is inserted right before the parameter of extra attribute. However,
    apart from the parser / printer, this PR does not introduce any
    functional changes.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    a0ea3fb View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    548a503 View commit details
    Browse the repository at this point in the history
  20. [CIR][LowerToLLVM] Exceptions: llvm.zero needed for landingpad should…

    … go into entry block
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    9f26e4e View commit details
    Browse the repository at this point in the history
  21. [CIR][CIRGen] Exceptions: support nested scope cleanup

    FlattenCFG will soon get the necessary support for lowering to LLVM,
    this is CIRGen only for now.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    972ca21 View commit details
    Browse the repository at this point in the history
  22. [CIR][CodeGen][NFCI] Unify attribute list handling of func / call by …

    …`constructAttributeList` (llvm#831)
    
    Similar to llvm#830 , this PR completes the `setCIRFunctionAttributes` part
    with the call to `constructAttributeList` method, so that func op and
    call op share the logic of handling these kinds of attributes, which is
    the design of OG CodeGen.
    
    It also includes other refactors. The function `constructAttributeList`
    now use `mlir::NamedAttrList &` rather than immutable attribute
    `mlir::DictionaryAttr &` as the inout result parameter, which benefits
    the additive merging of attributes.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    5214678 View commit details
    Browse the repository at this point in the history
  23. [CIR][CodeGen] Refactor setExtraAttributesForFunc to better align w…

    …ith OG (llvm#830)
    
    Previously the body of `setExtraAttributesForFunc` corresponds to
    `SetLLVMFunctionAttributesForDefinition`, but the callsite of it does
    not reside at the right position. This PR rename it and adjust the calls
    to it following OG CodeGen.
    
    To be specific, `setExtraAttributesForFunc` is called right after the
    initialization of `FuncOp`. But in OG CodeGen, the list of attributes is
    constructed by several more functions: `SetLLVMFunctionAttributes` and
    `SetLLVMFunctionAttributesForDefinition`.
    
    This results in diff in attributes of function declarations, which is
    reflected by the changes of test files. Apart from them, there is no
    functional change. In other words, the two code path calling
    `setCIRFunctionAttributesForDefinition` are tested by existing tests:
    
    * Caller `buildGlobalFunctionDefinition`: tested by
    `CIR/CodeGen/function-attrs.cpp`, ...
    * Caller `codegenCXXStructor`: tested by
    `CIR/CodeGen/delegating-ctor.cpp`, `defined-pure-virtual-func.cpp`, ...
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    dfc1677 View commit details
    Browse the repository at this point in the history
  24. [CIR][Asm] Fix parsing of extra(...) attributes in cir.call (llvm#835)

    The parser was looking for extra(...) before the return type while the
    pretty-printer put it after the return type.
    This was breaking the LSP-server for example.
    Change the parser behavior accordingly.
    keryell authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    e6fffd6 View commit details
    Browse the repository at this point in the history
  25. [CIR][CodeGen][LowerToLLVM] Set calling convention for call ops (llvm…

    …#836)
    
    This PR implements the CIRGen and Lowering part of calling convention
    attribute of `cir.call`-like operations. Here we have **4 kinds of
    operations**: (direct or indirect) x (`call` or `try_call`).
    
    According to our need and feasibility of constructing a test case, this
    PR includes:
    
    * For CIRGen, only direct `call`. Until now, the only extra calling
    conventions are SPIR ones, which cannot be set from source code manually
    using attributes. Meanwhile, OpenCL C *does not allow* function pointers
    or exceptions, therefore the only case remaining is direct call.
    * For Lowering, direct and indirect `call`, but not any `try_call`.
    Although it's possible to write all 4 kinds of calls with calling
    convention in ClangIR assembly, exceptions is quite hard to write and
    read. I prefer source-code-level test for it when it's available in the
    future. For example, possibly C++ `thiscall` with exceptions.
    * Extra: the verification of calling convention consistency for direct
    `call` and direct `try_call`.
    
    All unsupported cases are guarded by assertions or MLIR diags.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    6d07605 View commit details
    Browse the repository at this point in the history
  26. [CIR][Lowering] Fix static array lowering (llvm#838)

    Consider the following code snippet `test.c`: 
    
    ```
    int test(int x) {
      static int arr[10] = {0, 1, 0, 0};
      return arr[x];
    }
    ```
    
    When lowering from CIR to LLVM using `bin/clang test.c -Xclang -fclangir
    -Xclang -emit-llvm -S -o -` It produces:
    ```
    clangir/mlir/lib/IR/BuiltinAttributes.cpp:1015: static mlir::DenseElementsAttr mlir::DenseElementsAttr::get(mlir::ShapedType, llvm::ArrayRef<llvm::APInt>): Assertion `hasSameElementsOrSplat(type, values)' failed.
    ```
    
    I traced the bug back to `Lowering/LoweringHelpers.cpp` where we fill
    trailing zeros, and I believe this PR does it the right way. I have also
    added a very simple test for verification.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    bc457d4 View commit details
    Browse the repository at this point in the history
  27. [CIR][CIRGen][Lowering] Add support for attribute annotate (llvm#804)

    The main purpose of this PR is to add support for C/C++ attribute
    annotate. The PR involves both CIR generation and Lowering Prepare. In
    the rest of this description, we first introduce the concept of
    attribute annotate, then talk about expectations of LLVM regarding
    annotation, after it, we describe how ClangIR handles it in this PR.
    Finally, we list trivial differences between LLVM code generated by
    clang codegen and ClangIR codegen.
    **The concept of attribute annotate. and expected LLVM IR**
    the following is C code example of annotation.
    say in example.c
    `int *b __attribute__((annotate("withargs", "21", 12 )));
    int *a __attribute__((annotate("oneargs", "21", )));
    int *c __attribute__((annotate("noargs")));
    `
    here "withargs" is the annotation string, "21" and 12 are arguments for
    this annotation named "withargs". LLVM-based compiler is expected keep
    these information and build a global variable capturing all annotations
    used in the translation unit when emitting into LLVM IR. This global
    variable itself is **not** constant, but will be initialized with
    constants that are related to annotation representation, e.g. "withargs"
    should be literal string variable in IR.
    
    This global variable has a fixed name "llvm.global.annotations", and its
    of array of struct type, and should be initialized with a const array of
    const structs, each const struct is a representation of an annotation
    site, which has 5-field.
    [ptr to global var/func annotated, ptr to translation unit string const,
    line_no, annotation_name, ptr to arguments const]
    annotation name string and args constants, as well as this global var
    should be in section "llvm.metadata".
    e.g. In the above example, 
    We shall have following in the generated LLVM IR like the following 
    ```
    @b = global ptr null, align 8
    @.str = private unnamed_addr constant [9 x i8] c"withargs\00", section "llvm.metadata"
    @.str.1 = private unnamed_addr constant [10 x i8] c"example.c\00", section "llvm.metadata"
    @.str.2 = private unnamed_addr constant [3 x i8] c"21\00", align 1
    @.args = private unnamed_addr constant { ptr, i32 } { ptr @.str.2, i32 12 }, section "llvm.metadata"
    @A = global ptr null, align 8
    @.str.3 = private unnamed_addr constant [8 x i8] c"oneargs\00", section "llvm.metadata"
    @.args.4 = private unnamed_addr constant { ptr } { ptr @.str.2 }, section "llvm.metadata"
    @c = global ptr null, align 8
    @.str.5 = private unnamed_addr constant [7 x i8] c"noargs\00", section "llvm.metadata"
    @llvm.global.annotations = appending global [3 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @b, ptr @.str, ptr @.str.1, i32 1, ptr @.args }, { ptr, ptr, ptr, i32, ptr } { ptr @A, ptr @.str.3, ptr @.str.1, i32 2, ptr @.args.4 }, { ptr, ptr, ptr, i32, ptr } { ptr @c, ptr @.str.5, ptr @.str.1, i32 3, ptr null }], section "llvm.metadata"
    ```
    notice that since variable c's annotation has no arg, the last field of
    its corresponding annotation entry is a nullptr.
    
    **ClangIR's handling of annotations**
    In CIR, we introduce AnnotationAttr to GlobalOp and FuncOp to record its
    annotations. That way, we are able to make fast query about annotation
    if in future a CIR pass is interested in them.
    We leave the work of generating const variables as well as global
    annotations' var to LLVM lowering. But at LoweringPrepare we collect all
    annotations and create a module attribute "cir.global_annotations" so to
    facilitate LLVM lowering.
    
    **Some implementation details and trivial differences between clangir
    generated LLVM code and vanilla LLVM code**
    1. I suffix names of constants generated for annotation purpose with
    ".annotation" to avoid redefinition, but clang codegen doesn't do it.
    3. clang codegen seems to visit FuncDecls in slightly different orders
    than CIR, thus, sometimes the order of elements of the initial value
    const array for llvm.global.annotations var is different from clang
    generated LLVMIR, it should be trivial, as I don't expect consumer of
    this var is assuming a fixed order of collecting annotations.
    
    Otherwise, clang codegen and clangir pretty much generate same LLVM IR
    for annotations!
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    967ae69 View commit details
    Browse the repository at this point in the history
  28. [CIR][CIRGen][NFC] Exceptions: add cleanups to cir.call

    Now that the basic is working, start adding cleanups to be attached to
    cir.call's instead. This is necessary in order to tie the pieces
    (landing pads and cleanups) more properly, allowing multiple calls
    inside cir.try op to be connected with the right cleanup.
    
    This is the first piece of a series, tests coming next.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    bae79ba View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    9e13781 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    8f820ed View commit details
    Browse the repository at this point in the history
  31. [CIR][CIRGen][NFC] Exceptions: Move the logic to create surrounding t…

    …ry to be close to call generation
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    06f96ca View commit details
    Browse the repository at this point in the history
  32. [CIR][CIRGen][NFCI] Exceptions: change getEHDispatchBlock to create b…

    …locks inside calls
    
    getEHDispatchBlock result isn't really used to track anything just yet, so this change
    isn't supposed to affect anything. This is building block for having a cleanup per call.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    665798d View commit details
    Browse the repository at this point in the history
  33. [CIR][NFC] Fix mismatch of argument type in IR tests (llvm#837)

    There is a typo in `call.cir` that uses a wrong function argument type,
    leading to failure in the final LLVM IR translation.
    
    CIR verification does not reject it, because it skips indirect calls at
    the beginning. It's `verifySymbolUses` after all.
    
    
    https://github.com/llvm/clangir/blob/bde154cf1243cc4f938339c4dc15b1576d3025ab/clang/lib/CIR/Dialect/IR/CIRDialect.cpp#L2672-L2679
    
    The typo was copied to another IR test. Here we fix them all.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    143e2a5 View commit details
    Browse the repository at this point in the history
  34. [CIR][Dialect] Add convergent attribute to functions for SIMT langu…

    …ages (llvm#840)
    
    Fix llvm#805. This PR includes end-to-end implementation.
    
    The `convergent` attribute is set depending on languages, which is
    wrapped as `langOpts.assumeFunctionsAreConvergent()`.
    
    Therefore, in ClangIR, every `cir.func` under `#cir.lang<opencl_c>` is
    set to be convergent.
    
    After lowering to LLVM IR, `PostOrderFunctionAttrs` pass will remove
    unnecessary `convergent` then. In other words, we will still see
    `convergent` on every function with `-O0`, but not with default
    optimization level.
    
    The test taken from `CodeGenOpenCL/convergent.cl` is a bit complicated.
    However, the core of it is that `convergent` is set properly for
    `convfun()` `non_convfun()` `f()` and `g()`. Merge of two `if` is more
    or less a result of generating the same LLVM IR as OG.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    bff487f View commit details
    Browse the repository at this point in the history
  35. [CIR][FlattenCFG] Fix use after free when flattening terminator (llvm…

    …#843)
    
    Per the operation walking documentation [1]:
    
    > A callback on a block or operation is allowed to erase that block or
    > operation if either:
    >   * the walk is in post-order, or
    > * the walk is in pre-order and the walk is skipped after the erasure.
    
    We were doing neither when erasing terminator operations and replacing
    them with a branch, leading to a use after free and ASAN errors. This
    fixes the following tests with ASAN:
    
    ```
      Clang :: CIR/CodeGen/switch-gnurange.cpp
      Clang :: CIR/Lowering/atomic-runtime.cpp
      Clang :: CIR/Lowering/loop.cir
      Clang :: CIR/Lowering/loops-with-break.cir
      Clang :: CIR/Lowering/loops-with-continue.cir
      Clang :: CIR/Lowering/switch.cir
      Clang :: CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp
      Clang :: CIR/Transforms/loop.cir
      Clang :: CIR/Transforms/switch.cir
    ```
    
    These two tests still fail with ASAN after this, which I'm looking into:
    ```
      Clang :: CIR/CodeGen/pointer-arith-ext.c
      Clang :: CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp
    ```
    
    `CIR/CodeGen/global-new.cpp` is failing even on a non-ASAN Release build
    for me on the parent commit, so it's unrelated.
    
    [1]
    https://github.com/llvm/llvm-project/blob/0c55ad11ab3857056bb3917fdf087c4aa811b790/mlir/include/mlir/IR/Operation.h#L767-L770
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    7b4e3c7 View commit details
    Browse the repository at this point in the history
  36. [CIR][CodeGen][BugFix] Fixes structures name collisions (llvm#844)

    CIR Codegen fails to generate functions with local types with the same
    names. For instance, the next code :
    ```
    void foo(int a, float b) {
      struct A { int x; };
      struct A loc = {a};
      {
        struct A { float y; };
        struct A loc = {b};
      }
    }
    ```
    fails with on the next assertion: `Unable to find record layout
    information for type`. The problem is that we don't create record layout
    for the structures with equal names and
    `CIRGenTypes::convertRecordDeclType` returns the wrong type for the
    second struct type in the example above. This PR fixes this problem.
    
    In the original codegen the call to `Ty->setName(name)` resolves name
    collisions and assign a proper name for the type. In our case looks like
    we need to use the same approach as we did for the anonymous structures,
    i.e. to track the used names in the builder.
    
    Also, I fixed the struct type creation. Previously, the type was created
    several times - first in the `CIRGenTypes::convertRecordDeclType` and
    then in the `CIRGenTypes::computeRecordLayout`. This is why the indexes
    used by the anonymous structures naming had relatively big values and
    this is where the most changes on the tests come from.
    gitoleg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    c01b543 View commit details
    Browse the repository at this point in the history
  37. [CIR][Bugfix] renames minor/major parameters of the OpenCLVersionAttr (

    …llvm#845)
    
    Looks like certain names should not be used - I even could not build CIR
    on the Ubuntu with a relatively old glibc version.
    In this case `minor` and `major` are macroses and can not be used in
    this context.
    
    You can take a look at the comments in the
    [mlir/test/lib/Dialect/Test/TestDialect.h](https://github.com/llvm/clangir/blob/main/mlir/test/lib/Dialect/Test/TestDialect.h#L70)
    reference as well
    gitoleg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    229ebc1 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    3a95d58 View commit details
    Browse the repository at this point in the history
  39. [CIR][CIRGen] Properly link multiple level of cleanups

    Generalize approach and be able to tie together cleanups with their
    matching throwing calls. Before this the dtors were not really emitted
    in the proper order.
    
    LLVM support for this still hits a NYI,
    so nothing special here on the LLVM lowering side.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    12f12bf View commit details
    Browse the repository at this point in the history
  40. [CIR][CodeGen] Fix packed structures (llvm#839)

    Consider the following code snippet `test.c`:
    ```
    
    typedef struct {
        char b;
        int c;
    } D;
    
    typedef struct {
        D e;
        int f;
    } E;
    
    void f1() {
        E a = {};
    }
    ```
    When emitting the CIR using `bin/clang test.c -Xclang -fclangir -Xclang
    -emit-cir -S -o -` the current implementation gets:
    ```
    NYI
    UNREACHABLE executed at ~/clangir/clang/lib/CIR/CodeGen/CIRGenExprConst.cpp:338!
     ```
    This is only one of the many tests where this happens.
    
    Comparing the implementations of `CIR/CodeGen/CIRRecordLayoutBuilder.cpp` and clang's codegen `lib/CodeGen/CGRecordLayoutBuilder.cpp`, there is some padding missing for packed structures, and some alignments that need to be corrected.
    
    This PR also updates 2 existing tests. In the first test, `structural-binding.cpp`, I updated some `cir.get_member` indexes. In the second test, `packed-structs.c`, I updated the `cir` layout for the structure, and added more tests. I have compared the changes I made in the tests to the original clang codegen and everything seems fine.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    25bf750 View commit details
    Browse the repository at this point in the history
  41. [CIR][CIRGen] add CIRGen support for assume builtins (llvm#841)

    This PR adds CIRGen support for the following 3 builtins related to
    compile- time assumptions:
      - `__builtin_assume`
      - `__builtin_assume_aligned`
      - `__builtin_assume_separate_storage`
    
    3 new operations are invented to represent the three builtins.
    
    _LLVMIR lowering for these builtins cannot be implemented at this
    moment_ due to the lack of operand bundle support in LLVMIR dialect.
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    6eee944 View commit details
    Browse the repository at this point in the history
  42. [CIR][NFC] Change default LLVM output file extension (llvm#849)

    When the output file name is not specified via `-o`, the upstream clang
    uses `.ll` as the extension of the default output file name. This PR
    makes ClangIR follow this behavior.
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    a64c961 View commit details
    Browse the repository at this point in the history
  43. [CIR][Asm] Parse extra attributes after calling convention (llvm#847)

    Align parsing of cir.call with its pretty-printing.
    keryell authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    08b2e1e View commit details
    Browse the repository at this point in the history
  44. [CIR][CIRGen][Lowering] Lower AArch64::BI__builtin_arm_ldrex to llvm …

    …intrinsic (llvm#833)
    
    As title. And this PR introduces IntrinsicCallOp which will be used to
    lower intrinsics to llvm intrinsics.
    This PR handles clang::AArch64::BI__builtin_arm_ldrex.
    For this particular one, we only have test .cir, because a MLIR issue
    mentioned
    llvm#833 (comment)
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    efee5c0 View commit details
    Browse the repository at this point in the history
  45. [CIR][FlattenCFG][NFC] Exceptions: refactor landing pad code and catches

    This is in prep for creating more accurate landing pads w.r.t to their
    functions call and associated cleanup, so far we only support one.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    07315cb View commit details
    Browse the repository at this point in the history
  46. [CIR][CIRGen][NFC] Exceptions: refactor more infra for handling multi…

    …ple landing pads
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    2950f36 View commit details
    Browse the repository at this point in the history
  47. [CIR][CIRGen][NFCI] Exceptions: generalize landing pad insertion

    More refactoring, now the infra to generate one landing pad per call
    is up, but we still have an assert for more than one call, next commit
    will actually introduce new functionality.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    4038dff View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    39a2c08 View commit details
    Browse the repository at this point in the history
  49. Configuration menu
    Copy the full SHA
    86d5ca4 View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    3729f9f View commit details
    Browse the repository at this point in the history
  51. Configuration menu
    Copy the full SHA
    e4eecd2 View commit details
    Browse the repository at this point in the history
  52. [CIR][LowerToLLVM][NFC] Exceptions: use getOrCreateLLVMFuncOp to crea…

    …te personality functions
    
    While here, cleanup getOrCreateLLVMFuncOp usaga a bit.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ae75127 View commit details
    Browse the repository at this point in the history
  53. [CIR][Lowering] Erase op through rewriter instead of directly (llvm#853)

    Directly erasing the op causes a use after free later on, presumably
    because the lowering framework isn't aware of the op being deleted. This
    fixes `clang/test/CIR/CodeGen/pointer-arith-ext.c` with ASAN.
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    74066a1 View commit details
    Browse the repository at this point in the history
  54. Configuration menu
    Copy the full SHA
    e95f39b View commit details
    Browse the repository at this point in the history
  55. [CIR][ABI] Fix use after free from erasing while iterating (llvm#854)

    The loop was erasing the user of a value while iterating on the value's
    users, which results in a use after free. We're already assuming (and
    asserting) that there's only one user, so we can just access it directly
    instead. CIR/Transforms/Target/x86_64/x86_64-call-conv-lowering-pass.cpp
    was failing with ASAN before this change. We're now ASAN-clean except
    for llvm#829 (which is also in
    progress).
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    b981867 View commit details
    Browse the repository at this point in the history
  56. Recommit [CIR][Pipeline] Support -fclangir-analysis-only (llvm#832)

    Reland llvm#638
    
    This was reverted due to llvm#655. I
    tried to address the problem in the newest commit.
    
    The changes of the PR since the last landed one includes:
    - Move the definition of `cir::CIRGenConsumer` to
    `clang/include/clang/CIRFrontendAction/CIRGenConsumer.h`, and leave its
    `HandleTranslationUnit` interface is left empty. So that
    `cir::CIRGenConsumer` won't need to depend on CodeGen any more.
    - Change the old definition of `cir::CIRGenConsumer` in
    `clang/lib/CIR/FrontendAction/CIRGenAction.cpp` and to
    `CIRLoweringConsumer`, inherited from `cir::CIRGenConsumer`, which
    implements the original `HandleTranslationUnit` interface.
    
    I feel this may improve the readability more even without my original
    patch.
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    22bd691 View commit details
    Browse the repository at this point in the history
  57. [CIR][Lowering] Fix lowering for multi dimensional array (llvm#851)

    This PR fixes the lowering for multi dimensional arrays.
    
    Consider the following code snippet `test.c`: 
    ```
    void foo() {
      char arr[4][1] = {"a", "b", "c", "d"};
    }
    ```
    
    When ran with `bin/clang test.c -Xclang -fclangir -Xclang -emit-llvm -S
    -o -`, It produces the following error:
    ```
    ~/clangir/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = mlir::ArrayAttr; From = mlir::Attribute]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
    ```
    
    The bug can be traced back to `LoweringHelpers.cpp`. It considers the
    values in the array as integer types, and this causes an error in this
    case.
    
    This PR updates `convertToDenseElementsAttrImpl` when the array contains
    string attributes. I have also added one more similar test. Note that in
    the tests I used a **literal match** to avoid matching as regex, so
    `!dbg` is useful.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    9980dbb View commit details
    Browse the repository at this point in the history
  58. [CIR][CodeGen] Support global temporaries

    Support expressions at the top level such as
    
    const unsigned int n = 1234;
    const int &r = (const int&)n;
    
    Reviewers: bcardosolopes
    
    Pull Request: llvm#857
    lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    d88868e View commit details
    Browse the repository at this point in the history
  59. [CIR][CodeGen][NFC] Move GetUndefRValue to the right file

    This is to match clang CodeGen
    lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    92f3e1e View commit details
    Browse the repository at this point in the history
  60. [CIR][CIRGen] Exceptions: lexical scope issue with global initializers

    Fix llvm#829
    
    Thanks @smeenai for pointing out the root cause and UBSan failure!
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    789fb87 View commit details
    Browse the repository at this point in the history
  61. [CIR][CIRGen][Builtin][Neon] Lower __builtin_neon_vrndns_f32 (llvm#858)

    As title.
    Also introduced buildAArch64NeonCall skeleton, which is partially the
    counterpart of OG's EmitNeonCall. And this could be use for many other
    neon intrinsics.
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    9ec43b0 View commit details
    Browse the repository at this point in the history
  62. Configuration menu
    Copy the full SHA
    bdfa942 View commit details
    Browse the repository at this point in the history
  63. Configuration menu
    Copy the full SHA
    191ea78 View commit details
    Browse the repository at this point in the history
  64. [CIR][CIRGen] Initialize more CGF member variables to nullptr (llvm#863)

    These were uninitialized, which led to intermittent test failures from
    the use of uninitialized variables. Initialize them to `nullptr` as is
    done with other member variables that are pointers to fix this.
    
    I did a quick spot-check and didn't find other uninitialized variables
    in the main CGF class itself. Lots of subclasses have uninitialized
    member variables, but those are presumably expected to be initialized at
    all points of construction, so we can leave them alone until they cause
    any issues.
    
    `ninja check-clang-cir` now passes with ASan+UBSan and MSan.
    
    Fixes llvm#829
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    3bf78fe View commit details
    Browse the repository at this point in the history
  65. [CIR][CIRGen] Implement Nullpointer arithmatic extension (llvm#861)

    See the test for example.
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    5c3e67b View commit details
    Browse the repository at this point in the history
  66. [CIR][Codegen] supports aarch64_be (llvm#864)

    This PR adds aarch64 big endian support.
    
    Basically the support for aarch64_be itself is expressed only in two
    extra cases for the switch statement and changes in the `CIRDataLayout`
    are needed to prove that we really support big endian. Hence the idea
    for the test - I think the best way for proof is something connected
    with bit-fields, so we compare the results of the original codegen and
    ours.
    gitoleg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    48cab65 View commit details
    Browse the repository at this point in the history
  67. [CIR] Split cir-simplify into two passes (llvm#868)

    This PR splits the old `cir-simplify` pass into two new passes, namely
    `cir-canonicalize` and `cir-simplify` (the new `cir-simplify`). The
    `cir-canonicalize` pass runs transformations that do not affect
    CIR-to-source fidelity much, such as operation folding and redundant
    operation elimination. On the other hand, the new `cir-simplify` pass
    runs transformations that may significantly change the code and break
    high-level code analysis passes, such as more aggresive code
    optimizations.
    
    This PR also updates the CIR-to-CIR pipeline to fit these two new
    passes. The `cir-canonicalize` pass is moved to the very front of the
    pipeline, while the new `cir-simplify` pass is moved to the back of the
    pipeline (but still before lowering prepare of course). Additionally,
    the new `cir-simplify` now only runs when the user specifies a non-zero
    optimization level on the frontend.
    
    Also fixed some typos and resolved some `clang-tidy` complaints along
    the way.
    
    Resolves llvm#827 .
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    7cf7961 View commit details
    Browse the repository at this point in the history
  68. [CIR][CodeGen] Implement union cast (llvm#867)

    Currently the C style cast is not implemented/supported for unions.
    
    This PR adds support for union casts as done in `CGExprAgg.cpp`. I have
    also added an extra test in `union-init.c`.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    689a762 View commit details
    Browse the repository at this point in the history
  69. Configuration menu
    Copy the full SHA
    b924002 View commit details
    Browse the repository at this point in the history
  70. [CIR][CodeGen] Fix array initialization in CIRGenExprAgg (llvm#852)

    Mistakenly closed llvm#850
    
    llvm#850 (review)
     
    This PR fixes array initialization for expression arguments. 
    
    Consider the following code snippet `test.c`: 
    ```
    typedef struct {
      int a;
      int b[2];
    } A;
    
    int bar() {
      return 42;
    }
    
    void foo() {
      A a = {bar(), {}};
    }
    ```
    When ran with `bin/clang test.c -Xclang -fclangir -Xclang -emit-cir -S
    -o -`, It produces the following error:
    ```
    ~/clangir/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp:483: void {anonymous}::AggExprEmitter::buildArrayInit(cir::Address, mlir::cir::ArrayType, clang::QualType, clang::Expr*, llvm::ArrayRef<clang::Expr*>, clang::Expr*): Assertion `NumInitElements != 0' failed.
    ```
    The error can be traced back to `CIRGenExprAgg.cpp`, and the fix is
    simple. It is possible to have an empty array initialization as an
    expression argument!
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    16991e3 View commit details
    Browse the repository at this point in the history
  71. [CIR][CIRGen] Correct isSized predicate for vector type (llvm#869)

    As title, if element type of vector type is sized, then the vector type
    should be deemed sized.
    This would enable us generate code for neon without triggering assertion
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ab37943 View commit details
    Browse the repository at this point in the history
  72. [CIR][CIRGen][Builtin][Neon] Lower builtin_neon_vrnda_v and builtin_n…

    …eon_vrndaq_v (llvm#871)
    
    as title. 
    This also added NeonType support for Float32
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    2e1febe View commit details
    Browse the repository at this point in the history
  73. Configuration menu
    Copy the full SHA
    8412ead View commit details
    Browse the repository at this point in the history
  74. [CIR][CIRGen][NFC] Cleanups: add skeleton for DominatingValue<RValue>…

    …::saved_type::save
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    5a290b6 View commit details
    Browse the repository at this point in the history
  75. Configuration menu
    Copy the full SHA
    6ca5f24 View commit details
    Browse the repository at this point in the history
  76. [CIR][CIRGen][NFC] Cleanups: add more skeleton to pushFullExprCleanup

    It will hit another assert when calling initFullExprCleanup.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    c99f210 View commit details
    Browse the repository at this point in the history
  77. [CIR][CodeGen][BugFix] don't place alloca before the label (llvm#875)

    This PR fixes the case, when a temporary var is used, and `alloca`
    operation is inserted in the block start before the `label` operation.
    Implementation: when we search for the `alloca` place in a block, we
    take label operations into account as well.
    
    Fix llvm#870
    
    ---------
    
    Co-authored-by: Bruno Cardoso Lopes <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    73aebf4 View commit details
    Browse the repository at this point in the history
  78. [CIR][CIRGen] Allow constant evaluation of int annotation (llvm#874)

    __attribute__((annotate()) was only accepting integer literals,
    preventing some meta-programming usage for example.
    This should be extended to some other kinds of types.
    
    ---------
    
    Co-authored-by: Bruno Cardoso Lopes <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    5334d5a View commit details
    Browse the repository at this point in the history
  79. [CIR][CIRGen] Cleanups: handle conditional cleanups

    Just as the title says, but only covers non-exception path, that's
    coming next.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    831c229 View commit details
    Browse the repository at this point in the history
  80. [CIR][CIRGen][NFC] Cleanups: Prepare for conditional cleanup

    Nothing unblocked yet, just hit next assert in the same path.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ba03052 View commit details
    Browse the repository at this point in the history
  81. [CIR][CIRGen][NFC] Cleanups: more boilerplate work for conditional on…

    … exceptions
    
    Code path still hits an assert sooner, incremental NFC step.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    2b97f7a View commit details
    Browse the repository at this point in the history
  82. [CIR][CodeGen] Handling multiple stmt followed after a switch case (l…

    …lvm#878)
    
    Close llvm#876
    
    We've already considered the case that there are random stmt after a
    switch case:
    
    ```
    for (auto *c : compoundStmt->body()) {
          if (auto *switchCase = dyn_cast<SwitchCase>(c)) {
            res = buildSwitchCase(*switchCase, condType, caseAttrs);
          } else if (lastCaseBlock) {
            // This means it's a random stmt following up a case, just
            // emit it as part of previous known case.
            mlir::OpBuilder::InsertionGuard guardCase(builder);
            builder.setInsertionPointToEnd(lastCaseBlock);
            res = buildStmt(c, /*useCurrentScope=*/!isa<CompoundStmt>(c));
          } else {
            llvm_unreachable("statement doesn't belong to any case region, NYI");
          }
    
          lastCaseBlock = builder.getBlock();
    
          if (res.failed())
            break;
    }
    ```
    
    However, maybe this is an oversight, in the branch of ` if
    (lastCaseBlock)`, the insertion point will be updated automatically when
    the RAII object `guardCase` destroys, then we can assign the correct
    value for `lastCaseBlock` later. So we will see the weird code pattern
    in the issue side.
    
    BTW, I found the codes in CIRGenStmt.cpp are far more less similar with
    the ones other code gen places. Is this intentional? And what is the
    motivation and guide lines here?
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    933f775 View commit details
    Browse the repository at this point in the history
  83. [CIR][CIRGen] Generate CIR for empty compound literal (llvm#880)

    as title.
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    8f96cfa View commit details
    Browse the repository at this point in the history
  84. [CIR][CIRGen] Generate CIR for vset_lane and vsetq_lane intrinsics (l…

    …lvm#882)
    
    As title. 
    Notice that for those intrinsics, just like OG, we do not lower to llvm
    intrinsics, instead, do vector insert.
    The test case is partially from OG
    [aarch64-neon-vget.c](https://github.com/llvm/clangir/blob/85bc6407f559221afebe08a60ed2b50bf1edf7fa/clang/test/CodeGen/aarch64-neon-vget.c)
    But, I did not do all signed and unsigned int tests because unsigned and
    signed of the same width essentially just use the same intrinsic ID thus
    exactly same code path as far as this PR concerns.
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    669eaa9 View commit details
    Browse the repository at this point in the history
  85. [CIR][CI] Remove libcxx tests

    Reviewers: bcardosolopes
    
    Reviewed By: bcardosolopes
    
    Pull Request: llvm#881
    lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    348f18f View commit details
    Browse the repository at this point in the history
  86. [CIR][Dialect][CodeGen] Add a unit attribute for OpenCL kernels (llvm…

    …#877)
    
    We need a target-independent way to distinguish OpenCL kernels in
    ClangIR. This PR adds a unit attribute `OpenCLKernelAttr` similar to the
    one in Clang AST.
    
    This attribute is attached to the extra attribute dictionary of
    `cir.func` operations only. (Not for `cir.call`.)
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    5649a45 View commit details
    Browse the repository at this point in the history
  87. [CIR][CodeGen] Handle the case of 'case' after label statement after …

    …'case' (llvm#879)
    
    Motivation example:
    
    ```
    extern "C" void action1();
    extern "C" void action2();
    
    extern "C" void case_follow_label(int v) {
      switch (v) {
        case 1:
        label:
        case 2:
          action1();
          break;
        default:
          action2();
          goto label;
      }
    }
    ```
    
    When we compile it, we will meet:
    
    ```
      case Stmt::CaseStmtClass:
      case Stmt::DefaultStmtClass:
        assert(0 &&
               "Should not get here, currently handled directly from SwitchStmt");
        break;
    ```
    
    in `buildStmt`. The cause is clear. We call `buildStmt` when we build
    the label stmt.
    
    To solve this, I think we should be able to build case stmt in
    buildStmt. But the new problem is, we need to pass the information like
    caseAttr and condType. So I tried to add such informations in
    CIRGenFunction as data member.
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    d0fad9f View commit details
    Browse the repository at this point in the history
  88. [CIR][CIRGen] Generate CIR for neon_vget and neon_vdup lane intrinsics (

    llvm#884)
    
    as title. 
    This PR has simliar test case organization as to
    [PR882](llvm#882)
    Notice that comparing to OG, this PR combines cases for some pairs of
    intrinsics such as
    BI__builtin_neon_vget_lane_f32 and BI__builtin_neon_vdups_lane_f32. 
    They have the same code generated in OG and CIRGen
    OG separate them into different case handling because it passes
    mnemonics which are different. CIRGen doesn't pass that so why not
    combine them.
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    98586db View commit details
    Browse the repository at this point in the history
  89. [CIR][CIRGen] Allow maybeSetTrivialComdat for GlobalOp (llvm#885)

    as title, this would complete solution to fix issue [LLVM lowering
    missing comdat and constant
    attributes](llvm#801)
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    64ae660 View commit details
    Browse the repository at this point in the history
  90. [CIR][CIRGen][Builtin][Neon] Lower neon vqadd_v (llvm#890)

    as title. 
    Also add function buildCommonNeonBuiltinExpr just like OG's
    emitCommonNeonBuiltinExpr. This might help consolidate neon cases and
    share common code.
    Notice:
    
    - I pretty much keep the skeleton of OG's emitCommonNeonBuiltinExpr at
    the cost of that we didn't use a few variables they calculate. They
    might help in the future.
    - The purpose of having CommonNeonBuiltinExpr is to reduce
    implementation code duplication. So far, we only have one type
    implemented, and it's hard for CIR to be more generic. But we should see
    if in future we can have different types of intrinsics share more
    generic code path.
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    6fd7507 View commit details
    Browse the repository at this point in the history
  91. Configuration menu
    Copy the full SHA
    0a33748 View commit details
    Browse the repository at this point in the history
  92. Configuration menu
    Copy the full SHA
    7e3d6e6 View commit details
    Browse the repository at this point in the history
  93. [CIR][CIRGen][Builtin] Allow CIRGen for builtin calls with math error…

    …no override (llvm#893)
    
    As title. 
    The test case used is abort(), but it is from the real code. 
    Notice: Since CIR implementation for NoReturn Call is pending to
    implement, the generated llvm code is like:
    `define dso_local void @test() llvm#1  {
      call void @abort(), !dbg !8
      ret void
    }`
    which is not right, right code should be like, 
    `
    `define dso_local void @test() llvm#1  {
      call void @abort(), !dbg !8
      unreachable
    }`
    `
    Still send this PR as Noreturn implementation is a separate issue.
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    166af47 View commit details
    Browse the repository at this point in the history
  94. Configuration menu
    Copy the full SHA
    ce7ccce View commit details
    Browse the repository at this point in the history
  95. [CIR][NFC] Rename test

    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    737e91b View commit details
    Browse the repository at this point in the history
  96. [CIR][ABI] Apply CC lowering pass by default (llvm#842)

    Before this patch, the CC lowering pass was applied only when explicitly
    requested by the user. This update changes the default behavior to
    always apply the CC lowering pass, with an option to disable it using
    the `-fno-clangir-call-conv-lowering` flag if necessary.
    
    The primary objective is to make this pass a mandatory step in the
    compilation pipeline. This ensures that future contributions correctly
    implement the CC lowering for both existing and new targets, resulting
    in more consistent and accurate code generation.
    
    From an implementation perspective, several `llvm_unreachable`
    statements have been substituted with a new `assert_or_abort` macro.
    This macro can be configured to either trigger a non-blocking assertion
    or a blocking unreachable statement. This facilitates a test-by-testa
    incremental development as it does not required you to know which code
    path a test will trigger an just cause a crash if it does.
    
    A few notable changes:
    
     - Support multi-block function in CC lowering
     - Ignore pointer-related CC lowering
     - Ignore no-proto functions CC lowering
     - Handle missing type evaluation kinds
     - Fix CC lowering for function declarations
     - Unblock indirect function calls
     - Disable CC lowering pass on several tests
    sitio-couto authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    80814d6 View commit details
    Browse the repository at this point in the history
  97. [CIR][CIRGen][Builtin][Neon] Lower vqrshrun_n and add getAArch64SIMDI…

    …ntrinsicString (llvm#899)
    
    as title.
    In addition, this PR has 2 extra changes.
    
    1. change return type of GetNeonType into mlir::cir::VectorType so we
    don't have to do cast all the time, this is consistent with
    [OG](https://github.com/llvm/clangir/blob/db6b7c07c076cb738d0acae248d7c3c199b2b952/clang/lib/CodeGen/CGBuiltin.cpp#L6234)
    as well.
    2. add getAArch64SIMDIntrinsicString helper function so we have better
    debug info when hitting NYI in buildCommonNeonBuiltinExpr
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    d246854 View commit details
    Browse the repository at this point in the history
  98. [CIR][NFC] Silence unused warning

    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    881c18a View commit details
    Browse the repository at this point in the history
  99. Revert "[CIR][ABI] Apply CC lowering pass by default (llvm#842)"

    Fix llvm#895 and it's also missing some more
    throughout behavior for the pass, it also needs to be enabled by default when
    emitting object files.
    
    This reverts commit db6b7c0.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    41891e8 View commit details
    Browse the repository at this point in the history
  100. [CIR][CIRGen] Add time trace to several CIRGen pieces (llvm#898)

    Then we can observe the time consumed in different part of CIR. This
    patch is not complete. But I think it is fine given we can always add
    them easily.
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    b59a2e7 View commit details
    Browse the repository at this point in the history
  101. [CIR][Dialect] Support OpenCL work group uniformity attribute (llvm#896)

    > To keep information about whether an OpenCL kernel has uniform work
    > group size or not, clang generates 'uniform-work-group-size' function
    > attribute for every kernel:
    > 
    > "uniform-work-group-size"="true" for OpenCL 1.2 and lower,
    > "uniform-work-group-size"="true" for OpenCL 2.0 and higher if
    '-cl-uniform-work-group-size' option was specified,
    > "uniform-work-group-size"="false" for OpenCL 2.0 and higher if no
    '-cl-uniform-work-group-size' options was specified.
    > If the function is not an OpenCL kernel, 'uniform-work-group-size'
    > attribute isn't generated.
    > 
    > *From [Differential 43570](https://reviews.llvm.org/D43570)*
    
    This PR introduces the `OpenCLKernelUniformWorkGroupSizeAttr` attribute
    to the ClangIR pipeline, towards the completeness in attributes for
    OpenCL. While this attribute is represented as a unit attribute in MLIR,
    its absence signifies either non-kernel functions or a `false` value for
    kernel functions. To match the original LLVM IR behavior, we also
    consider whether a function is an OpenCL kernel during lowering:
    
    * If the function is not a kernel, the attribute is ignored. No LLVM
    function attribute is set.
    * If the function is a kernel:
    * and the `OpenCLKernelUniformWorkGroupSizeAttr` is present, we generate
    the LLVM function attribute `"uniform-work-group-size"="true"`.
        * If absent, we generate `"uniform-work-group-size"="false"`.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    14970ad View commit details
    Browse the repository at this point in the history
  102. [CIR][CodeGen][NFC] Rename the confusing buildGlobal overload (llvm…

    …#897)
    
    `CIRGenModule::buildGlobal` --[rename]-->
    `CIRGenModule::getOrCreateCIRGlobal`
    
    We already have `CIRGenModule::buildGlobal` that corresponds to
    `CodeGenModule::EmitGlobal`. But there is an overload of `buildGlobal`
    used by `getAddrOfGlobalVar`. Since this name is confusing, this PR
    rename it to `getOrCreateCIRGlobal`.
    
    Note that `getOrCreateCIRGlobal` already exists. It is intentional to
    make the renamed function an overload to it. The reason here is that the
    renamed function is basically a wrapper of the original
    `getOrCreateCIRGlobal` with more specific parameters:
    
    `getOrCreateCIRGlobal(decl, type, isDef)` --[call]-->
    `getOrCreateCIRGlobal(getMangledName(decl), type,
    decl->getType()->getAS(), decl, isDef)`
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ae40465 View commit details
    Browse the repository at this point in the history
  103. [CIR][CIRGen][Builtin][Neon] Lower neon vld1_lane and vld1q_lane (llv…

    …m#901)
    
    just as title.
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ce0aa5c View commit details
    Browse the repository at this point in the history
  104. [CIR][CodeGen][NFC] Break the missing feature flag for OpenCL into sm…

    …aller pieces (llvm#902)
    
    The missing feature flag for OpenCL has very few occurrences now. This
    PR rearranges them into proper pieces to better track them.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    3e13daf View commit details
    Browse the repository at this point in the history
  105. [CIR][CodeGen] Add nothrow for functions in OpenCL languages (llvm#903

    )
    
    Heterogeneous languages do not support exceptions, which corresponds to
    `nothrow` in ClangIR and `nounwind` in LLVM IR.
    
    This PR adds nothrow attributes for all functions for OpenCL languages
    in CIRGen. The Lowering for it is already supported previously.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    2322e2a View commit details
    Browse the repository at this point in the history
  106. [CIR][CodeGen] Set constant properly for global variables (llvm#904)

    Fix llvm#801 (the remaining `constant` part). Actually the missing stage is
    CIRGen.
    
    There are two places where `GV.setConstant` is called:
    
    * `buildGlobalVarDefinition`
    * `getOrCreateCIRGlobal`
    
    Therefore, the primary test `global-constant.c` contains a global
    definition and a global declaration with use, which should be enough to
    cover the two paths.
    
    A test for OpenCL `constant` qualified global is also added. Some
    existing testcases need tweaking to avoid failure of missing constant.
    seven-mile authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    31cc156 View commit details
    Browse the repository at this point in the history
  107. [CIR][Test][NFC] Organize CIR CodeGen AArch64 neon tests (llvm#910)

    as title.
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    f9a83c8 View commit details
    Browse the repository at this point in the history
  108. [CIR][Lowering] Fix Global Attr Lowering (llvm#906)

    Consider the following code snippet `tmp.c`: 
    ```
    #define N 3200
    
    struct S {
      double a[N];
      double b[N];
    } s;
    
    double *b = s.b;
    
    void foo() {
      double x = 0;
      for (int i = 0; i < N; i++)
        x += b[i];
    }
    
    int main() {
      foo();
      return 0;
    }
    ```
    Running `bin/clang tmp.c -fclangir -o tmp && ./tmp` causes a
    segmentation fault.
    
    I compared the LLVM IR with and without CIR and noticed a difference
    which causes this:
    `@b = global ptr getelementptr inbounds (%struct.S, ptr @s, i32 0, i32
    1)` // no CIR
    `@b = global ptr getelementptr inbounds (%struct.S, ptr @s, i32 1)` //
    with CIR
    
    It seems there is a missing index when creating global pointers from
    structs. I have updated `Lowering/DirectToLLVM/LowerToLLVM.cpp`, and
    added a few tests.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    3966c67 View commit details
    Browse the repository at this point in the history
  109. [CIR][CIRGen][Builtin] Implement builtin __sync_fetch_and_sub (llvm#932)

    as title.
    Notice this is not target specific nor neon intrinsics.
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    088accd View commit details
    Browse the repository at this point in the history
  110. [CIR][CIRGen] Cleanup: enable conditional cleanup with exceptions

    Entails several minor changes:
    - Duplicate resume blocks around.
    - Disable LP caching, we repeat them as often as necessary.
    - Update maps accordingly for tracking places to patch up.
    - Make changes to clean up block handling.
    - Fix an issue in flatten cfg.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    ef57d5f View commit details
    Browse the repository at this point in the history
  111. [CIR][CIRGen][Builtin][Neon] Lower BI__builtin_neon_vmovn_v (llvm#909)

    as title. 
    The current implementation of this PR is use cir::CastOP integral
    casting to implement vector type truncation. Thus, LLVM lowering code
    has been change to accommodate it.
    In addition.
    Added code into
    [CIRGenBuiltinAArch64.cpp](https://github.com/llvm/clangir/pull/909/files#diff-6f7700013aa60ed524eb6ddcbab90c4dd288c384f9434547b038357868334932)
    to make it more similar to OG.
    ```
     mlir::Type ty = vTy;
      if (!ty)
    ```
    Added test case into neon.c as the file already contains similar vector
    move test cases such as vmovl
    
    ---------
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    6885dd0 View commit details
    Browse the repository at this point in the history
  112. [CIR][CIRGen][Builtin][Neon] Lower neon vst1q_lane and vst1_lane (llv…

    …m#935)
    
    as title. 
    Also changed
    [neon-ldst.c](https://github.com/llvm/clangir/compare/main...ghehg:clangir-llvm-ghehg:macM3?expand=1#diff-ea4814b6503bff2b7bc4afc6400565e6e89e5785bfcda587dc8401d8de5d3a22)
    to make it have the same RUN options as OG
    [clang/test/CodeGen/aarch64-neon-intrinsics.c](https://github.com/llvm/clangir/blob/main/clang/test/CodeGen/aarch64-neon-intrinsics.c)
    Those options help us to avoid checking load/store pairs thus make the
    test less verbose and easier to compare against OG.
    
    Co-authored-by: Guojin He <[email protected]>
    2 people authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    c9e5a9c View commit details
    Browse the repository at this point in the history
  113. [CIR] Derived-to-base conversions (llvm#937)

    Implement derived-to-base address conversions for non-virtual base
    classes. The code gen for this situation was only implemented when the
    offset was zero, and it simply created a `cir.base_class_addr` op for
    which no lowering or other transformation existed.
    
    Conversion to a virtual base class is not yet implemented.
    
    Two new fields are added to the `cir.base_class_addr` operation: the
    byte offset of the necessary adjustment, and a boolean flag indicating
    whether the source operand may be null. The offset is easy to compute in
    the front end while the entire path of intermediate classes is still
    available. It would be difficult for the back end to recompute the
    offset. So it is best to store it in the operation. The null-pointer
    check is best done late in the lowering process. But whether or not the
    null-pointer check is needed is only known by the front end; the back
    end can't figure that out. So that flag needs to be stored in the
    operation.
    
    `CIRGenFunction::getAddressOfBaseClass` was largely rewritten. The code
    path no longer matches the equivalent function in the LLVM IR code gen,
    because the generated ClangIR is quite different from the generated LLVM
    IR.
    
    `cir.base_class_addr` is lowered to LLVM IR as a `getelementptr`
    operation. If a null-pointer check is needed, then that is wrapped in a
    `select` operation.
    
    When generating code for a constructor or destructor, an incorrect
    `cir.ptr_stride` op was used to convert the pointer to a base class. The
    code was assuming that the operand of `cir.ptr_stride` was measured in
    bytes; the operand is the number elements, not the number of bytes. So
    the base class constructor was being called on the wrong chunk of
    memory. Fix this by using a `cir.base_class_addr` op instead of
    `cir.ptr_stride` in this scenario.
    
    The use of `cir.ptr_stride` in `ApplyNonVirtualAndVirtualOffset` had the
    same problem. Continue using `cir.ptr_stride` here, but temporarily
    convert the pointer to type `char*` so the pointer is adjusted
    correctly.
    
    Adjust the expected results of three existing tests in response to these
    changes.
    
    Add two new tests, one code gen and one lowering, to cover the case
    where a base class is at a non-zero offset.
    dkolsen-pgi authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    74d032f View commit details
    Browse the repository at this point in the history
  114. Configuration menu
    Copy the full SHA
    2ec2277 View commit details
    Browse the repository at this point in the history
  115. [CIR][CIRGen] Exceptions: fix agg store for temporaries

    Fix llvm#934
    
    While here move scope op codegen outside the builder, so it's easier
    to dump blocks and operations while debugging.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    366b4a3 View commit details
    Browse the repository at this point in the history
  116. Configuration menu
    Copy the full SHA
    9cc1faf View commit details
    Browse the repository at this point in the history
  117. Configuration menu
    Copy the full SHA
    eaacaf1 View commit details
    Browse the repository at this point in the history
  118. Configuration menu
    Copy the full SHA
    cea946a View commit details
    Browse the repository at this point in the history
  119. [Lowering][DirectToLLVM] Fix calling variadic functions (llvm#945)

    After 5da4310, the LLVM dialect
    requires the variadic callee type to be present for variadic calls. The
    op builders take care of this automatically if you pass the function
    type, so change our lowering logic to do so. Add tests for this as well
    as a missing test for indirect function call lowering.
    
    Fixes llvm#913
    Fixes llvm#933
    smeenai authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    4d2c56f View commit details
    Browse the repository at this point in the history
  120. [CIR] [CodeGen] Remove NYI in buildPointerWithAlignment (llvm#949)

    See the test for the reproducer. It would crash due the NYI.
    
    See
    https://github.com/llvm/llvm-project/blob/327124ece7d59de56ca0f9faa2cd82af68c011b9/clang/lib/CodeGen/CGExpr.cpp#L1295-L1373,
    I found we've implemented all the cases in CGExpr.cpp. IIUC, I think we
    can remove the NYI.
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    99a4590 View commit details
    Browse the repository at this point in the history
  121. [CIR][Lowering] Introduce HoistAllocasPass (llvm#887)

    Close llvm#883. See the above issue
    for details
    ChuanqiXu9 authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    45fe4fd View commit details
    Browse the repository at this point in the history
  122. [CIR][CodeGen] Enable -fno-PIE (llvm#940)

    The title describes the purpose of the PR. 
    
    The logic was gotten from the original CodeGen, and I added a test to
    check that `-fno-PIE` is indeed enabled.
    bruteforceboy authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    f9ef59a View commit details
    Browse the repository at this point in the history
  123. [CIR][CIRGen] Add support for __fp16 type (llvm#950)

    This PR adds support for the `__fp16` type. CIRGen and LLVM lowering is
    included.
    
    Resolve llvm#900 .
    Lancern authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    04087b5 View commit details
    Browse the repository at this point in the history
  124. [CIR][CIRGen][Builtin] Support unsigned type for _sync_(bool/val)_com…

    …pare_and_swap (llvm#955)
    
    as title. 
    Actually just follow the way in `makeBinaryAtomicValue` in the same file
    which did the right thing by creating SInt or UInt based on first
    argument's signess.
    ghehg authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    0bc6286 View commit details
    Browse the repository at this point in the history
  125. [CIR][CIRGen][NFC] Improve buildAutoVarAlloca skeleton and add hooks …

    …for buildVarAnnotations
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    42f05b5 View commit details
    Browse the repository at this point in the history
  126. [CIR][CIRGen] Support annotations on local var decl

    LLVM lowering support coming next.
    bcardosolopes authored and lanza committed Oct 14, 2024
    Configuration menu
    Copy the full SHA
    19c9099 View commit details
    Browse the repository at this point in the history

Commits on Oct 19, 2024

  1. Configuration menu
    Copy the full SHA
    8f61a4c View commit details
    Browse the repository at this point in the history
  2. [CIR][NFC] Fix post-rebase warning

    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    7dd34cd View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d1b1222 View commit details
    Browse the repository at this point in the history
  4. Reapply and patch "[CIR][ABI] Apply CC lowering pass by default (llvm…

    …#842)" (llvm#944)
    
    This reverts commit 8f699fd and fixes some issues, namely:
     
    - CC lowering pass will no longer fail if the function has no AST
    information that won't be used.
    - Fixed CC lowering not disabling when running certain `cc1` compilation
    commands.
    - CC lowering can now be disabled when calling `cir-opt` and
    `cir-translate`.
    - Compilation commands that generate Object files should now invoke CC
    lowering by default.
    sitio-couto authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    6d49e8b View commit details
    Browse the repository at this point in the history
  5. [CIR][CodeGen] kr-style for function arguments (llvm#938)

    I tried to run llvm-test-suite and turned out that there are many tests
    fail with segfault due to old C style (let's remember Kernighan and
    Ritchie) . This PR fix it by the usual copy-pasta from the original
    codegen :)
    
    So let's take a look at the code:
    ```
    void foo(x) short x; {}
    int main() {
      foo(4); 
      return 0;
    }
    ```
    and CIR for `foo` function is:
    ```
    cir.func  @foo(%arg0: !s32i) {
        %0 = cir.alloca !s16i, !cir.ptr<!s16i>, ["x", init] 
        %1 = cir.cast(bitcast, %0 : !cir.ptr<!s16i>), !cir.ptr<!s32i>
        cir.store %arg0, %1 : !s32i, !cir.ptr<!s32i>
        cir.return
    }
    ```
    We bitcast the **address** (!!!) and store a value of a bigger size
    there.
    
    And now everything looks fine:
    ```
    cir.func no_proto  @foo(%arg0: !s32i) {
        %0 = cir.alloca !s16i, !cir.ptr<!s16i>, ["x", init] 
        %1 = cir.cast(integral, %arg0 : !s32i), !s16i
        cir.store %1, %0 : !s16i, !cir.ptr<!s16i> 
        cir.return 
    } 
    ```
    We truncate an argument and store it. 
    
    P.S.
    The `bitcast` that was there before looks a little bit suspicious and
    dangerous. Are we sure we can do this unconditional cast while we create
    `StoreOp` ?
    gitoleg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    a34d6e6 View commit details
    Browse the repository at this point in the history
  6. [CIR][CIRGen] Add const attribute to alloca operations (llvm#892)

    This PR tries to give a simple initial implementation for eliminating
    redundant loads of constant objects, an idea originally posted by
    OfekShilon.
    
    Specifically, this PR adds a new unit attribute `const` to the
    `cir.alloca` operation. Presence of this attribute indicates that the
    alloca-ed object is declared `const` in the input source program. CIRGen
    is updated accordingly to start emitting this new attribute.
    Lancern authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    b2ad574 View commit details
    Browse the repository at this point in the history
  7. [CIR][Lowering] VecCreateOp and VecSplatOp lowering choose LLVM:Poiso…

    …nOp (llvm#959)
    
    They should use PoisonOp (which becomes PoisonValue in LLVMIR) as it is
    the OG's choice.
    Proof:
    We generate VecCreateOp [here
    ](https://github.com/llvm/clangir/blob/2ca12fe5ec3a1e7279256f069010be2d68200585/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp#L1975)
    And it's OG counterpart is
    [here](https://github.com/llvm/clangir/blob/2ca12fe5ec3a1e7279256f069010be2d68200585/clang/lib/CodeGen/CGExprScalar.cpp#L2096)
    OG uses PoisonValue. 
    As to VecSplatOp, OG unconditionally [chooses PoisonValue
    ](https://github.com/llvm/clangir/blob/2ca12fe5ec3a1e7279256f069010be2d68200585/llvm/lib/IR/IRBuilder.cpp#L1204)
    
    A even more solid proof for this case is that 
    when we use OG to generate code for our test case I changed in this PR ,
    its always using poison instead of undef as far as VecSplat and
    VecCreate is concerned. The [OG generated code for vectype-ext.cpp
    ](https://godbolt.org/z/eqx1rns86) here.
    The [OG generated code for vectype.cpp
    ](https://godbolt.org/z/frMjbKGeT) here.
    
    For reference, generated CIR for the test case vectype-ext.cpp is
    [here](https://godbolt.org/z/frMjbKGeT)
    
    This is to unblock llvm#936 to help it
    set on the right path.
    
    Note: There might be other CIR vec ops that need to choose Poison to be
    consistent with OG, but I'd limit the scope of this PR, and wait to see
    issue pop up in the future.
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    a6fd0d7 View commit details
    Browse the repository at this point in the history
  8. [CIR][NFC][Testing] Fix test failure (llvm#963)

    as title.
    Base on my experience of [this type of test(https://github.com/llvm/clangir/blob/a7ac2b4e2055e169d9f556abf5821a1ccab666cd/clang/test/CIR/CodeGen/attribute-annotate-multiple.cpp#L51),
    The number of characters varies in this line as it's about full file
    path which changes during environment.
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    6976c41 View commit details
    Browse the repository at this point in the history
  9. fixup! [CIR][LowerToLLVM] Fix crash in PtrStrideOp lowering

    After recent rebases (likely as a result of [1]), the LLVMIR stride
    operand can be generated by an unrealized_conversion_cast whereas the
    CIR operand is coming directly from a block argument (and thus has no
    defining op), so we need to separately check the CIR operand for the
    existence of a defining op.
    
    [1] llvm/llvm-project@2d50029
    smeenai authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    43f5b48 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    d8d2464 View commit details
    Browse the repository at this point in the history
  11. [CIR][CIRGen] Support CodeGen for vbase constructors

    1. Add new `cir.vtt.address_point` op for visiting the element of VTT to
    initialize the virtual pointer.
    2. Implement `getVirtualBaseClassOffset` method which provides a virtual offset
    to adjust to actual virtual pointers in virtual base.
    3. Follows the original clang CodeGen scheme for the implementation of most
    other parts.
    
    @bcardosolopes's note: this is cherry-picked from an older PR from Jing Zhang and
    slightly modified for updates: applied review, test, doc and operation syntax.
    It does not yet has LLVM lowering support, I'm going to make incremental
    changes on top of this.  Any necessary CIR modifications to this design should
    follow up shortly too. Also, to make this work I also added more logic to
    `addImplicitStructorParam`s` and `buildThisParam`.
    Laity000 authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    077ebe9 View commit details
    Browse the repository at this point in the history
  12. [CIR][CIRGen][Builtin][Neon] Lower neon_vtrn and neon_vtrnq (llvm#942)

    as title. 
    The generated code is the same as Clang codeden except in a small
    discrepancy when GEP:
    OG generates code like this: 
    `%6 = getelementptr inbounds <4 x i16>, ptr %retval.i, i32 1`
    CIR generates a bit differently:
    `%6 = getelementptr <4 x i16>, ptr %retval.i, i64 1`
    Ptr offest might be trivial because choosing i64 over i32 as index type
    seems to be LLVM Dialect's choice.
    
    The lack of `inbounds` keyword might be an issue as
    `mlir::cir::PtrStrideOp` is currently not lowering to LLVM:GEPOp with
    `inbounds` attribute as `mlir::cir::PtrStrideOp` itself has no
    `inbounds`. It's probably because there was no need for it though we do
    have an implementation of [`CIRGenFunction::buildCheckedInBoundsGEP`
    ](https://github.com/llvm/clangir/blob/10d6f4b94da7e0181a070f0265d079419d96cf78/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp#L2762).
    
    Anyway, the issue is not in the scope of this PR and should be addressed
    in a separate PR. If we think this is an issue, I can create another PR
    and probably add optional attribute to `mlir::cir::PtrStrideOp` to
    achieve it.
    
    In addition to lowering work, a couple of more works:
    
    1. Did a little refactoring on variable name changing into desired
    CamelBack case.
    2. Changed neon-misc RUN Options to be consistent with other neon test
    files and make test case more concise.
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    c693c34 View commit details
    Browse the repository at this point in the history
  13. [CIR][CIRGen][Builtin][Neon] Lower neon_vext_v and neon_vextq_v (llvm…

    …#951)
    
    as title. 
    There are two highlights of the PR
    
    1. The PR introduced a new test file to cover neon intrinsics that move
    data, which is a big category. This would the 5th neon test file. And
    we're committed to keep total number of neon test files within 6. This
    file uses another opt option instcombine, which makes test LLVM code
    more concise, and our -fclangir generated LLVM code would be identical
    to OG with this. It looks like OG did some instcombine optimization.
    
    2. `getIntFromMLIRValue` helper function could be substituted by
    [`mlir::cir::IntAttr getConstOpIntAttr` in
    CIRGenAtomic.cpp](https://github.com/llvm/clangir/blob/24b24557c98d1c031572a567b658cfb6254f8a89/clang/lib/CIR/CodeGen/CIRGenAtomic.cpp#L337).
    The function `mlir::cir::IntAttr getConstOpIntAttr` is doing more than
    `getIntFromMLIRValue`, and there is FIXME in the comment, so not sure if
    we should just use `mlir::cir::IntAttr getConstOpIntAttr`, either is
    fine with me.
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    ffdbdc3 View commit details
    Browse the repository at this point in the history
  14. [CIR][Lowering] Handling Lowering of multiple dimension array correct…

    …ly (llvm#961)
    
    Close llvm#957
    
    the previous algorithm to convert a multiple dimension array to a tensor
    is: fill the value one by one and fill the zero values in conditions.
    And it has some problems handling the multiple dimension array as above
    issue shows so that the generated values are not in the same shape with
    the original array.
    
    the new algorithm here is, full fill the values ahead of time with the
    correct element size and full fill the values to different slots and we
    only need to maintain the index to write.
    
    I feel the new version has better performance (avoid allocation) and
    better readability slightly.
    ChuanqiXu9 authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    666dbcf View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    90a9be6 View commit details
    Browse the repository at this point in the history
  16. [CIR][CIRGen][Builtin][Neon] Lower neon_vpadd_v and neon_vpaddq_v int…

    …o llvm intrinsic (llvm#960)
    
    This PR refactored Neon Built in code in clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp a bit to make it cleaner.
    
    Also changed RUNOption of test file clang/test/CIR/CodeGen/AArch64/neon-arith.c to make test more concise, and easy to compare against OG (to compare, just remove -fclangir from llvm gen part of RUN, and the test should still pass)
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    244734d View commit details
    Browse the repository at this point in the history
  17. [CIR] [Lowering] Fix handling of multiple array for ZeroAttr (llvm#970)

    This is the following up fix for the previous fix
    llvm#961
    
    See the attached new test for the reproducer.
    
    Sorry for the initial overlook.
    ChuanqiXu9 authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    4a8a588 View commit details
    Browse the repository at this point in the history
  18. [CIR][Driver] Fix -fclangir-call-conv-lowering behavior

    - The flag is the default even for cc1, so make it disable two level deep.
    - While here, remove the unnecessary flag disable for pure `-emit-cir`.
    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    a43cad3 View commit details
    Browse the repository at this point in the history
  19. Configuration menu
    Copy the full SHA
    2b5947a View commit details
    Browse the repository at this point in the history
  20. [CIR] Make the asserts to display suggestion for -fno-clangir-call-co…

    …nv-lowering
    
    While here, add more unrecheables to cover some of the current errors, so that
    our users can see a clear message instead of a random cast assert of sorts.
    This covers at least all crashes seen when removing
    -fno-clangir-call-conv-lowering from all tests, there are probably other things
    we'll find as we exercise this path.
    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    5f4a2ae View commit details
    Browse the repository at this point in the history
  21. [CIR][NFC] Massively rename workarounds for callconv lowering

    These are not meant to be used by any other component, make sure it's very
    specific.
    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    b4b6fbe View commit details
    Browse the repository at this point in the history
  22. [CIR][CIRGen] Implement CIRGenModule::shouldEmitFunction (llvm#984)

    This is the usual copy-paste-modify from CodeGen, though I changed all
    the variable names to conform to our new style. All these functions
    should be pulled out as common helpers when we're upstream.
    smeenai authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    3ef5e65 View commit details
    Browse the repository at this point in the history
  23. [CIR][CIRGen] Port 1d0bd8e (llvm#983)

    llvm/llvm-project@1d0bd8e
    moves a conditional from CodeGen to AST, and this follows suit for
    consistency. (Our support for the Microsoft ABI is NYI anyway; this is
    just to make things simpler to follow when matching up logic between
    CodeGen and CIRGen.)
    smeenai authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    0c6d78b View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    679b8ea View commit details
    Browse the repository at this point in the history
  25. [CIR][NFC] Rename function in a test

    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    7f1a689 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    4f3b99e View commit details
    Browse the repository at this point in the history
  27. [CIR][CIRGen][NFC] Consolidate RUN lines for builtin tests (llvm#968)

    There is no change to testing functionality. This refacot let those
    files have the same Run options that is easier to maintain and extend.
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    ffd2935 View commit details
    Browse the repository at this point in the history
  28. [CIR] [Lowering] care trailing zero for lowering constant array (llvm…

    …#976)
    
    Close llvm#975
    
    See the attached test case for example
    ChuanqiXu9 authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    478deb6 View commit details
    Browse the repository at this point in the history
  29. [CIR] Add support for __int128 type (llvm#980)

    This PR adds initial support for the `__int128` type. The `!cir.int`
    type is extended to support 128-bit integer types.
    
    This PR comes with a simple test that verifies the CIRGen and LLVM
    lowering of `!s128i` and `!u128i` work.
    
    Resolve llvm#953 .
    Lancern authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    31fd4b7 View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    e865152 View commit details
    Browse the repository at this point in the history
  31. [CIR][CIRGen][Builtin][Neon] Lower vqdmulhq_lane, vqdmulh_lane, vqrdm…

    …ulhq_lane and vqrdmulh_lane (llvm#985)
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    35ec8a6 View commit details
    Browse the repository at this point in the history
  32. [CIR][CIRGen][Builtin][Type] Support for IEEE Quad (long double) adde…

    …d (in CIR + Direct to LLVM) (llvm#966)
    
    Fixes llvm#931
    Added type definition in CIRTypes.td, created appropriate functions for
    the same in CIRTypes.cpp like getPreferredAlignment,
    getPreferredAlignment, etc. Optionally added lowering in LowerToLLVM.cpp
    mvvsmk authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    0d894e1 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    f0c1120 View commit details
    Browse the repository at this point in the history
  34. [CIR] Disable -fclangir-call-conv-lowering from default in the LLVM…

    … pipeline
    
    This is causing lots of churn. `-fclangir-call-conv-lowering` is not mature
    enough, assumptions are leading to crashes we cannot track with special
    messages, leading to not great user experience. Turn this off until we have
    someone dedicated to roll this out.
    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    ce33590 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    ae4a7df View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    6e7779a View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    da816c5 View commit details
    Browse the repository at this point in the history
  38. [CIR][CIRGen][NFC] Add more skeleton for handling inheritance ctors

    While here add some bits for ptr auth and match OG.
    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    2c3c8ef View commit details
    Browse the repository at this point in the history
  39. [CIR][CIRGen] Ensure default visibility for local linkage functions (l…

    …lvm#990)
    
    LLVM's verifier enforces this, which was previously causing us to fail
    verification. This is a bit of a band-aid; the overall linkage and
    visibility setting flow needs some work to match the original.
    smeenai authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    e3ad862 View commit details
    Browse the repository at this point in the history
  40. [CIR][CIRGen][Builtin][Neon] Lower neon_vshl_n_v and neon_vshlq_n_v (l…

    …lvm#965)
    
    As title, but important step in this PR is to allow CIR ShiftOp to take
    vector of int type as input type. As result, I added a verifier to
    ShiftOp with 2 constraints
    
    1. Input type either all vector or int type. This is consistent with
    LLVM::ShlOp, vector shift amount is expected.
    2. In the spirit of C99 6.5.7.3, shift amount type must be the same as
    result type, the if vector type is used. (This is enforced in LLVM
    lowering for scalar int type).
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    bb3b839 View commit details
    Browse the repository at this point in the history
  41. [CIR][CIRGen] Use Clang Codegen's skeleton in CIRGenFunction::buildBu…

    …iltinExpr (llvm#967)
    
    This PR helps us to triage unimplemented builtins (that are target
    independent).
    There are unhandled builtins in CIR Codegen
    `[CIRGenFunction::buildBuiltinExpr](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp#L305)`.
    And those builtins have implementation in
    [OG](https://github.com/llvm/clangir/blob/4c446b3287895879da598e23164d338d04bced3e/clang/lib/CodeGen/CGBuiltin.cpp#L2573).
    Currently, those builtins just are treated as LibraryCall or some other
    ways which eventually get failure, and failure messages are confusing.
    This PR address this problem by refactoring
    `CIRGenFunction::buildBuiltinExpr` to keep the same skeleton as OG
    counterpart `CodeGenFunction::EmitBuiltinExpr`, and add builtin name to
    NYI message
    ghehg authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    b24f6f6 View commit details
    Browse the repository at this point in the history
  42. Configuration menu
    Copy the full SHA
    5b81555 View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    e198f7e View commit details
    Browse the repository at this point in the history
  44. [CIR][CIRGen] Support initial cases of inheritance ctor/dtor

    Add more NFC skeleton while here.
    bcardosolopes authored and lanza committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    92c7d8f View commit details
    Browse the repository at this point in the history
  45. Configuration menu
    Copy the full SHA
    cb0cb34 View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    c1731b1 View commit details
    Browse the repository at this point in the history
  47. [CIR][CIRGen] Add missing testcase for null base class

    Forgot to git add in cb0cb34
    bcardosolopes committed Oct 19, 2024
    Configuration menu
    Copy the full SHA
    e744086 View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    7f0c7f4 View commit details
    Browse the repository at this point in the history