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] Cleanup cir.scopes with a single cir.yield operation #482

Closed
wants to merge 1,410 commits into from
This pull request is big! We’re only showing the most recent 250 commits.

Commits on Jan 29, 2024

  1. [CIR][CIRGen][Bugfix] Update unions to track all members

    This diverges from the original codegen by tracking all members of a
    union, instead of just the largest one. This is necessary to support
    type-checking at the MLIR level when accessing union members. It also
    preserves more information about the source code, which might be useful.
    
    Fixes llvm#224
    
    ghstack-source-id: 8a975426d077a66c49f050741d7362da3c102fed
    Pull Request resolved: llvm#229
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    05a94f6 View commit details
    Browse the repository at this point in the history
  2. [CIR][Lowering] Lower unions

    Converts a union to a struct containing only its largest element.
    GetMemberOp for unions is lowered as bitcasts instead of GEPs, since
    union members share the same address space.
    
    ghstack-source-id: 744ac312675b8f3225ccc459fcd09474bcfcfe81
    Pull Request resolved: llvm#230
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    97db1ae View commit details
    Browse the repository at this point in the history
  3. [CIR][Codegen] Destructor support for global variable initialization (l…

    …lvm#241)
    
    Similar with the previous ctor support, I'm bringing up the dtor support
    for global var initialization.
    
    This change only contains the CIR early codegen work. The upcoming
    lowering prepare work will be in a separate change.
    htyu authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    afa51d4 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    624223a View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    8fe9081 View commit details
    Browse the repository at this point in the history
  6. [CIR][Lowering] Global destructor support (llvm#249)

    This change adds lowering support for global variable definition with
    destructor.
    
    For example:
    
    ```
       cir.global "private" internal @_ZL8__ioinit = ctor : !ty_22Init22 {
         %0 = cir.get_global @_ZL8__ioinit : cir.ptr <!ty_22Init22>
         %1 = cir.const(#true) : !cir.bool
         cir.call @_ZN4InitC1Eb(%0, %1) : (!cir.ptr<!ty_22Init22>, !cir.bool) -> ()
       } dtor {
          %0 = cir.get_global @_ZL8__ioinit : cir.ptr <!ty_22Init22>
          cir.call @_ZN4InitD1Ev(%0) : (!cir.ptr<!ty_22Init22>) -> ()
       }
    
    ```
    is now lowered to 
    
    ```
       cir.func internal private @__cxx_global_var_init() {
        %0 = cir.get_global @_ZL8__ioinit : cir.ptr <!ty_22Init22>
        %1 = cir.const(#true) : !cir.bool
        cir.call @_ZN4InitC1Eb(%0, %1) : (!cir.ptr<!ty_22Init22>, !cir.bool) -> ()
        %2 = cir.get_global @_ZL8__ioinit : cir.ptr <!ty_22Init22>
        %3 = cir.get_global @_ZN4InitD1Ev : cir.ptr <!cir.func<!void (!cir.ptr<!ty_22Init22>)>>
        %4 = cir.cast(bitcast, %3 : !cir.ptr<!cir.func<!void (!cir.ptr<!ty_22Init22>)>>), !cir.ptr<!cir.func<!void (!cir.ptr<!void>)>>
        %5 = cir.cast(bitcast, %2 : !cir.ptr<!ty_22Init22>), !cir.ptr<!void>
        %6 = cir.get_global @__dso_handle : cir.ptr <i8>
        cir.call @__cxa_atexit(%4, %5, %6) : (!cir.ptr<!cir.func<!void (!cir.ptr<!void>)>>, !cir.ptr<!void>, !cir.ptr<i8>) -> ()
        cir.return
      } 
    ```
    
    Note that instead calling the destructor in the global initializer
    function, a registration with `__cxa_atexit` is done instead so that the
    destructor will be called right before the program is shut down.
    htyu authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    7b3f877 View commit details
    Browse the repository at this point in the history
  7. [CIR][CIRGen] Add initial support for throw expression

    Add two new CIR ops: cir.alloc_exception and cir.throw, they are higher
    level representations for their __cxa_* counterparts.
    
    Add CIRGen for a simple `throw <expr>` example, which requires using the above added
    operations. Rethrow mechanism (plain `throw`) is still NYI.
    
    For LLVM lowering: LoweringPrepare work needs to be done next, breaking these ops
    back to functions calls.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    920dcd6 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    140b35c View commit details
    Browse the repository at this point in the history
  9. [CIR][CIRGen][NFC] Add more checks for detecting proper vtable linkage

    Add an assert while we don't handle the available externally.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    b859a24 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    ac82b5d View commit details
    Browse the repository at this point in the history
  11. [CIR][CIRGen][NFC] Try-catch support: skeleton

    Add lots of necessary boilerplate for personality functions, catch
    block tracking and building catch scope stack. We enter the try but
    no catching handling yet.
    
    New paths all guarded with asserts, therefore NFC.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    5bfecc1 View commit details
    Browse the repository at this point in the history
  12. [CIR][CIRGen][NFC] Cleanup buildCall a bit and pave for CannotThrow

    In order to support exceptions, skeleton for unwind detection.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bac5b1b View commit details
    Browse the repository at this point in the history
  13. [CIR][CIRGen][NFC] Introduce ConstructAttributeList, to populate cir.…

    …call attributes soon
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bf89b5b View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    5f349e7 View commit details
    Browse the repository at this point in the history
  15. [CIR][NFC] Add sketch for TryOp

    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    7d4320b View commit details
    Browse the repository at this point in the history
  16. [CIR][NFC] Add sketch for CatchOp

    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d46979c View commit details
    Browse the repository at this point in the history
  17. [CIR][CIRGen] Create catch op and track entry blocks for each clause

    Populate regions and basic blocks for handling try-catch!
    
    No testcases just yet, new path guarded with unreachable, so effectively this
    is NFC.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    ae18581 View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    1a0f501 View commit details
    Browse the repository at this point in the history
  19. [CIR][CIRGen] Removes hasBooleanRepresentation (llvm#251)

    This PR removes the method `hasBooleanRepresentation` as was discussed
    in [PR#233](llvm#233)
    Briefly, the `cir.bool` has the same representation in memory and after
    load. The LLVM IR differs, that's why the check is there, in the origin
    `CodeGen`.
    
    Also, in order to trigger the path and make the implementation to be
    conform with the original `CodeGen`, there are changes in the
    `CIRGenExprScalar`: call the common `buildFromLValue` instead of manaul
    `load` creation.
    
    Also, a couple of tests for the bool load/store added
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bc8c25d View commit details
    Browse the repository at this point in the history
  20. [CIR] Introduce ConstPtrAttr for absolute pointer value initializatio…

    …n. (llvm#253)
    
    Introducing `cir.ConstPtrAttr` to represent arbitrary absolute pointer
    value initializations. Also incorporating previous `cir.nullptr` effort
    into this work.
    htyu authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    c5bb2e8 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    4c10875 View commit details
    Browse the repository at this point in the history
  22. [CIR] Implement fabs operation. (llvm#254)

    Following discussion in llvm#237 this adds support for `fabs` builtins which
    are used extensively in llvm-test-suite.
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f37da01 View commit details
    Browse the repository at this point in the history
  23. [CIR][IR] Bypass get_member verifier for incomplete types

    Temporary workaround until we patch the codegen for record types.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    76f1fa4 View commit details
    Browse the repository at this point in the history
  24. [CIR][Codegen] VTT support for virtual class inheritance (llvm#252)

    This patch brings up the basic support for C++ virtual inheritance. VTT
    (virtual table table) now can be laid out as expected for simple program
    with single virtual inheritance. RTTI support is on the way.
    
    This patch does not include LLVM lowering support.
    htyu authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bea9906 View commit details
    Browse the repository at this point in the history
  25. [CIR][CIRGen] CIR generation for bitfields. Fixes llvm#13 (llvm#233)

    This PR introduces bitfelds support.  This now works:
    
    ```
    #include <stdio.h>
    
    typedef struct {
        int a1 : 4;
        int a2 : 28;
        int a3 : 16;
        int a4 : 3;
        int a5 : 17;
        int a6 : 25;
    } A;
    
    void init(A* a) {
        a->a1 = 1;
        a->a2 = 321;
        a->a3 = 15;
        a->a4 = -2;
        a->a5 = -123;
        a->a6 = 1234;
    }
    
    void print(A* a) {
        printf("%d %d %d %d %d %d\n",
            a->a1,
            a->a2,
            a->a3,
            a->a4,
            a->a5,
            a->a6
        );
    }
    
    int main() {
        A a;
        init(&a);
        print(&a);
        return 0;
    }
    
    ```
    the output is:
    `1 321 15 -2 -123 1234`
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    01b9dc6 View commit details
    Browse the repository at this point in the history
  26. Revert "[CIR][CIRGen] CIR generation for bitfields. Fixes llvm#13 (ll…

    …vm#233)"
    
    Breaks ninja check-clang-cir
    
    This reverts commit 471e568.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    7e54191 View commit details
    Browse the repository at this point in the history
  27. [CIR] Make AST attributes accessible via interfaces. (llvm#250)

    - Introduces `CIR/Interfaces/ASTAttrInterfaces` which model API of clang
    AST nodes, but allows to plugin custom attribute, making `CIR` dialect
    AST independent.
    
    - Extends hierarchy of `DeclAttr`s to model `Decl` attributes more
    faithfully.
    - Notably all `CIRASTAttr`s are now created uniformly using
    `makeAstDeclAttr` which builds corresponding Attribute based on
    `clang::Decl`.
    xlauko authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    cd67650 View commit details
    Browse the repository at this point in the history
  28. [CIR][CodeGen][Bugfix] Generate field index with respect to layout (l…

    …lvm#263)
    
    There is a bug in the code generation: the field index for the
    `GetMemberOp` is taken from the `FieldDecl`, with no respect to the
    record layout. One of the manifestation of the bug is the wrong index
    generated for a field in a derived class that does not take into the
    account the instance of the base class (that has index 0).
    
    You can take a look at the example in
    `test/CIR/CodeGen/derived-to-base.cpp`, i.e. the current test is not the
    correct one
    ```
    // CHECK-DAG: !ty_22C23A3ALayer22 = !cir.struct<class "C2::Layer" {!ty_22C13A3ALayer22, !cir.ptr<!ty_22C222>
    // CHECK-DAG: !ty_22C33A3ALayer22 = !cir.struct<struct "C3::Layer" {!ty_22C23A3ALayer22
    
    // CHECK: cir.func @_ZN2C35Layer10InitializeEv
    
    // CHECK:  cir.scope {
    // CHECK:    %2 = cir.base_class_addr(%1 : cir.ptr <!ty_22C33A3ALayer22>) -> cir.ptr <!ty_22C23A3ALayer22>
    // CHECK:    %3 = cir.get_member %2[0] {name = "m_C1"} : !cir.ptr<!ty_22C23A3ALayer22> -> !cir.ptr<!cir.ptr<!ty_22C222>>
    ```
    As one can see, the result (of ptr type to `!ty_22C222` ) must have the
    index `1` in the corresponded struct `ty_22C23A3ALayer22`.
    
    Basically the same is done in the `clang/CodeGen/CGExpr.cpp`, so we
    don't invent something new here.
    
    Note, this fix doesn't affect anything related to the usage of
    `buildPreserveStructAccess` where the `field->getFieldIndex()` is used.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f5d0a0f View commit details
    Browse the repository at this point in the history
  29. [CIR][Lowering] Add scf.scope lowering to standard dialects (llvm#262)

    This PR adds MLIR lowering of `cir.scope`.
    
    I also notice that the MLIR unit tests still uses old integer types. I
    will fix those in a separate PR.
    Kuree authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    cef3df8 View commit details
    Browse the repository at this point in the history
  30. [CIR][CIRGen][Exception] Workaround internal testcase break

    Recent work on exceptions broke an internal testcase, free the path
    back while I work on a holistic solution.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    4ea8de4 View commit details
    Browse the repository at this point in the history
  31. [CIR][Bugfix] adds clangAST dependency

    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    3109e04 View commit details
    Browse the repository at this point in the history
  32. [CIR] Remove cir-tidy

    We've integrated this functionality into the main clang-tidy and clangd
    tools and no longer have a purpose for it. We only kept around to
    maintain support for internal tooling built upon it. So remove it here.
    lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    a0aed8c View commit details
    Browse the repository at this point in the history
  33. [CIR][Lowering] use cir.int type in LIT tests (llvm#266)

    Here is the promised patch that adds proper type conversion to CIR ->
    MLIR conversion. I tried to keep the changes minimum but the existing
    implementation doesn't use `TypeConverter`.
    
    This should not have any functional changes except for one tiny fix that
    registers the `cf` dialect, which should allow `goto.mlir` to pass.
    Happy to break the PR into two if requested.
    Kuree authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    5d69cff View commit details
    Browse the repository at this point in the history
  34. [CIR][CIRGen] Revisiting CIR generation for bitfields. Fixes llvm#13 (l…

    …lvm#268)
    
    This is an updated PR for [PR
    llvm#233](llvm#233) with some fixes
    explained in [PR llvm#261](llvm#261) which
    now can be safely closed.
    
    First of all, let me introduce how do the bitfields looks like in CIR.
    For the struct `S` defined as following:
    ```
    typedef struct {
      int a : 4;
      int b : 27;
      int c : 17;
      int d : 2;
      int e : 15;
      unsigned f;
    } S;
    ```
    the CIR type is `!ty_22S22 = !cir.struct<struct "S" {!u32i, !u32i,
    !u16i, !u32i} #cir.record.decl.ast>` where all the bitfields are packed
    in the first three storages.
    
    Also, the next bugs was fixed:
    - type mismatch
    - index out of bounds
    - single bitfield of size < 8
    
    The cases covered with tests.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    212d51c View commit details
    Browse the repository at this point in the history
  35. [CIR][Codegen][Bugfix] use record layout to generate index for a field (

    llvm#270)
    
    This is a minor fix similar to the one introduced in llvm#263.
    Basically, all calls to the `buildLValueForFieldInitialization` are even
    with the origin codegen `emitLValueForFieldInitialization` calls, i.e.
    the field index is calculated from the record layout, but not from the
    decl `field->getFieldIndex()`.
    
    Added just one test, because looks like we need to implement some `NYI`
    features first to test another places e.g. in `CIRGenExprAgg.cpp`,
    though I could miss something.
    
    Anyway, given the original codegen doesn't use `getFieldIndex` in these
    places, we also should not.
    
    All the remaining usages of `getFieldIndex` are ok.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    569d88b View commit details
    Browse the repository at this point in the history
  36. [CIR][Lowering] Deprecate typed LLVM dialect pointers (llvm#271)

    Updates the lowering pass to use only opaque pointers. This essentially
    involves updating the type converter to drop pointee types and
    explicitly defining the types loaded/stored/GEPed by LLVM operations.
    
    The reasons for this are twofold:
    
    - LLVM dialect is currently transitioning to deprecate typed pointers,
    allowing only opaque pointers. The sooner we transition the fewer
    changes we will have to make.
    - Opaque pointers greatly simplify lowering self-references, since all
    self-references in records are wrapped in a pointer.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f3d2033 View commit details
    Browse the repository at this point in the history
  37. [CIR][Lowering][Bugfix] Fix GetMemberOp lowering (llvm#273)

    The wrong element type was being passed to LLVM's GEP op, generating an
    invalid IR. Tests were also updated to properly validate the
    `llvm.getelementptr` element type.
    
    Fixes llvm#272
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    90ad669 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    3f4338a View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    c7e3740 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    e429fd5 View commit details
    Browse the repository at this point in the history
  41. Configuration menu
    Copy the full SHA
    9c427bf View commit details
    Browse the repository at this point in the history
  42. [CIR][Lowering] Add cir.brcond lowering (llvm#278)

    This PR adds `cir.brcond` lowering, which more or less follows the one
    in LLVM dialect lowering.
    Kuree authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    52ab8d0 View commit details
    Browse the repository at this point in the history
  43. [CIR][IR] Relax get_member verifier for incomplete types (llvm#269)

    This is a suggestion to relax the existing verification even more than
    we did it in PR llvm#257.
    Here we also skip verification if a field on the given index is also of
    incomplete type - and we can not compare it with the result type of the
    operation.
    
    Now the next code fails with type mismatch error:
    ```
    typedef struct Node {    
        struct Node* next;
    } NodeStru;
    
    void foo(NodeStru* a) {        
        a->next = 0;
    }
    ```
    because the result type is kind of full and the type of field is not
    (for the reasons discussed in llvm#256).
    Basically, the problem is in the `GetMemberOp` result type generated as
    following (via `CIRGenTypes::convertType`)
    `!cir.ptr<!cir.struct<struct "Node" {!cir.ptr<!cir.struct<struct "Node"
    incomplete #cir.record.decl.ast>>} #cir.record.decl.ast>>`
    
    where the field type at index differs from the record type - compare
    with
     `!cir.ptr<!cir.struct<struct "Node" incomplete #cir.record.decl.ast>>`
    
    We just slightly relax the previous solution in llvm#257 - and the
    compilation won't fail in the case of recursive types.
    
    Well, if there are some other thoughts?
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2e08b4e View commit details
    Browse the repository at this point in the history
  44. [CIR][CodeGen][Bugfix] supports local structs decl (llvm#280)

    Just a trivial fix that enables declaration of local structs. 
    Basically, there it's a copy-pasta from the original `CodeGen`, without
    debug info handling.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    126ef4f View commit details
    Browse the repository at this point in the history
  45. [CIR][CodeGen][Bugfix] fixes global vars initialization (llvm#281)

    This PR handles globals initializations for c++ code for the case when a
    global is inited from a function call or another global.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    54a62ef View commit details
    Browse the repository at this point in the history
  46. [CIR][CIRGen] Ensure unique IDs for anonymous records (llvm#274)

    Traditional Clang's codegen generates IDs for anonymous records (e.g.
    "struct.anon.1") and ensures that they are unique. This patch does the
    same for CIRGen, which, until now, would just identify any anonymous
    record as "anon".
    
    This will be required to support mutable structs uniquely identified by
    their names.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2ff3de7 View commit details
    Browse the repository at this point in the history
  47. [CIR] Rename StructType "typeName" attribute to "name" (llvm#275)

    Rename `typeName` to just `name`, also use `StringAttr`'s nullability to
    identify if the record is identified or anonymous. Unnamed structs are
    also no longer aliased, as they have no unique name to be used in the
    alias.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    a751dff View commit details
    Browse the repository at this point in the history
  48. [CIR][Codegen] RTTI support for virtual class inheritence (llvm#259)

    This patch adds RTTI support for C++ virtual inheritance. 
    
    This patch does not include LLVM lowering support.
    htyu authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    53ee1f3 View commit details
    Browse the repository at this point in the history
  49. [CIR][Lowering] Lower vtable and type info (llvm#264)

    Lowering Vtable and RTTI globals. Also lowering AddressPoint.
    
    based on llvm#259
    htyu authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d4a20d8 View commit details
    Browse the repository at this point in the history
  50. Configuration menu
    Copy the full SHA
    a450eed View commit details
    Browse the repository at this point in the history
  51. [CIR][NFC] Refactor StructType body attribute

    The `body` attribute is used to identify if a struct type has a body
    or not. In other words, it separates complete from incomplete structs.
    For this reason, the `body` attribute was renamed to `incomplete`,
    matching its keyword in the CIR language.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    454cdc7 View commit details
    Browse the repository at this point in the history
  52. [CIR][NFC] Remove std::optional from StructType ast attribute

    MLIR's attributes are inherently nullable, so there is no need to use
    std::optional to represent a nullable attribute. This patch removes
    std::optional from StructType's ast attribute to simplify its usage.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    3be05c3 View commit details
    Browse the repository at this point in the history
  53. [CIR][CIRGen][NFC] Fix redudancy while casting integers and remove wr…

    …ong and untested CastKind::floating path
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    be846dd View commit details
    Browse the repository at this point in the history
  54. [CIR] Implement bool->int conversion (llvm#292)

    In the CIR CodeGen function `ScalarExprEmitter::buildScalarCast`,
    implement conversions from bool to an integral type. This was
    inadvertently left out in earlier changes.
    
    Reorganize the code in the function to be more clear, with better
    assertion failure messages when encountering an unimplemented construct.
    
    This is a partial fix for issue llvm#290
    dkolsen-pgi authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    fa015ea View commit details
    Browse the repository at this point in the history
  55. Configuration menu
    Copy the full SHA
    68ff280 View commit details
    Browse the repository at this point in the history
  56. [CIR][CodeGen] Introduce CIRBaseBuilder (llvm#297)

    As discussed in llvm#279, we split `CIRGenBuilder` in two parts, which make
    some of the helpers usable outside of the `CodeGen` part.
    Basically, I placed casts and binary operations into a separate class,
    `CIRBaseBuilder`. Later, it can be extended with another helpers. But
    right now an idea to have a state less builder as a base one.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    b4cb6ac View commit details
    Browse the repository at this point in the history
  57. [CIR][CodeGen] Support integer-to-pointer casts. (llvm#298)

    A silly fix for code like
    ```
    *(char *)0 = 0;
    ```
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    51644be View commit details
    Browse the repository at this point in the history
  58. [CIR][CIRGen] Ensure unique names for template specializations (llvm#295

    )
    
    Currently, different specializations of a template will generate
    distinct types with the same name. To properly differentiate each
    specialization, this patch includes the template arguments in the name
    of the type.
    
    This will be required to support mutable structs uniquely identified by
    their names.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    9385689 View commit details
    Browse the repository at this point in the history
  59. [CIR][CIRGen] Refactor StructType builders (llvm#294)

    Instead of using a single builder for every possible StructType, we now
    have three builders: identified complete, identified incomplete, and
    anonymous struct types. This allows us to enforce correctness and to
    explicitly show the intent when creating a StructType.
    
    This patch also adds support for anonymous structs type aliases. When a
    StructType has no name, it will generate a `ty_anon_<kind>` alias.
    Conflicts are automatically resolved by MLIR.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    907af96 View commit details
    Browse the repository at this point in the history
  60. [CIR] Forbid identified structs with empty names (llvm#301)

    There are instances of CIR where anonymous structs are generated as
    identified structs with an empty name. This patch Adds a verifier for
    StructType, which ensures structs have a non-empty name.
    
    This will be required for properly uniqueing mutable CIR structs.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2c12f80 View commit details
    Browse the repository at this point in the history
  61. Configuration menu
    Copy the full SHA
    8ba9e09 View commit details
    Browse the repository at this point in the history
  62. [CIR][IR][NFC] Redefine tablegen CIR StructType with C++

    Essentially, this patch redefines the CIR StructType manually instead
    of using the autogenerated definition from tablegen. This is the first
    step to make StructType mutable, as this feature is not yet supported
    by tablegen.
    
    It's mostly a copy of the tablegen definition, with a few notable
    differences:
    
     - A few embellishments are added to make the code more dev-friendly
     - Addition of a CIRTypesDetails.h file to keep custom storage definitions
     - The CIR_AnyCIRType constraint is removed, as it is not used and must
       be defined in C++ to ensure StructType is a part of it.
    
    ghstack-source-id: 5f706dc0a61a4a2ed6e2f20ab0937b1a42bfa9cc
    Pull Request resolved: llvm#302
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    adfef40 View commit details
    Browse the repository at this point in the history
  63. [CIR][CIRGen] Support mutable and recursive named records

    This allows a named StructType to be mutated after it has been created,
    if it is identified and incomplete.
    
    The motivation for this is to improve the codegen of CIR in certain
    scenarios where an incomplete type is used and later completed. These
    usually leave the IR in an inconsistent state, where there are two
    records types with the same identifier but different definitions (one
    complete the other incomplete).
    
    For example:
    
    ```c++
    struct Node {
      Node *next;
    };
    void test(struct Node n) {}
    ```
    
    Generates:
    
    ```mlir
    !temp_struct = !cir.struct<struct "Node" incomplete>
    !full_struct = !cir.struct<struct "Node" {!cir.ptr<!temp_struct>}>
    ```
    
    To generate the `Node` struct type, its members must be created first.
    However, the `next` member is a recursive reference, so it can only be
    completed after its parent. This generates a temporary incomplete
    definition of the `Node` type that remains in the code even after the
    type to which it refers is completed. As a consequence, accessing the
    `next` member of a `Node` value fetches the old incomplete version of
    the type which affects CIR's type-checking capabilities.
    
    This patch ensures that, once the parent is fully visited, the `next`
    member can be completed in place, automatically updating any references
    to it at a low cost. To represent recursive types, the StructType now
    is equipped with self-references. These are represented by a
    `cir.struct` type with just the name of the parent struct that it
    refers to. The same snippet of code will not generate the following
    CIR IR:
    
    ```mlir
    !full_struct = !cir.struct<struct "Node" {!cir.ptr<!cir.struct<struct "Node">>}>
    ```
    
    Summary of the changes made:
     - Named records are now uniquely identified by their name. An attempt
       to create a new record with the same will fail.
     - Anonymous records are uniquely identified by members and other
       relevant attributes.
     - StructType has a new `mutate` method that allows it to be mutated
       after it has been created. Each type can only be mutated if it is
       identified and incomplete, rendering further changes impossible.
     - When building a new name StructType, the builder will try to first
       create, then complete the type, ensuring that:
    
        - Inexistent types are created
        - Existing incomplete types are completed
        - Existing complete types with matching attributes are reused
        - Existing complete types with different attributes raise errors
    
     - StructType now uses the CyclicParser/Printer guard to avoid infinite
       recursion and identify when it should print/parse a self-reference.
    
    ghstack-source-id: a6d4f650515cbf2d7f6e27d45aae6f768ba44f92
    Pull Request resolved: llvm#303
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    32aff4d View commit details
    Browse the repository at this point in the history
  64. [CIR][NFC] Refactor ScalarExprEmitter::buildScalarCast (llvm#306)

    Matrix types are already checked for in `buildScalarConversion`, so they
    don't need to be checked for again in `buildScalarCast`. Not having to
    worry about matrix types means the `Element` local variables are no
    longer necessary.
    
    Remove duplicate code by having a variable to store the `CastKind`, and
    have only one call to `Builder.create<CastOp>`.
    
    There are no test changes, because this is refactoring only. There
    should be no functional changes.
    dkolsen-pgi authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    776519a View commit details
    Browse the repository at this point in the history
  65. [CIR][CodeGen][Bugfix] fixes explicit cast in initialization (llvm#309)

    The PR fixes a var initialization with explicit cast.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    048199a View commit details
    Browse the repository at this point in the history
  66. [CIR] Support bool-to-float conversions (llvm#307)

    Add a new entry to enum `CastKind`, `bool_to_float`, since none of the
    existing enum values adequately covered that conversion. Add code to
    code gen, CIR validation, LLVM lowering, and the cast test to cover this
    conversion.
    
    Fix ClangIR issue llvm#290
    dkolsen-pgi authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    21da5e1 View commit details
    Browse the repository at this point in the history
  67. [CIR] Add validation tests for scalar casts (llvm#317)

    Fix a couple typos in the validation failure messages for scalar casts
    dkolsen-pgi authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    7f73051 View commit details
    Browse the repository at this point in the history
  68. [CIR] Fix bool-to-pointer conversions (llvm#319)

    Conversions from an integer to a pointer are implemented in CIR code gen
    as an integral conversion to uintptr_t followed by the
    integral-to-pointer conversion. Conversions from bool to pointer were
    following the same code path. But bool-to-int is a different CastKind
    than int-to-int in CIR, and CIR was failing validation. Fix the integer
    to pointer conversion code to correctly handle a source type of bool.
    
    (A conversion from bool to pointer makes no sense and should never
    happen in the real world. But it is legal due to bool being sort of an
    integral type. So we need to support it.)
    
    Also, in `ScalarExprEmitter::buildScalarConversion` change a couple
    not-yet-implemented messages about pointer types into assertion
    failures. Conversions involving pointer types should never go through
    `ScalarExprEmitter::buildScalarConversion`.
    dkolsen-pgi authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    35e9da0 View commit details
    Browse the repository at this point in the history
  69. [CIR][CIRGen] Ensure proper tmp location for agg exprs (llvm#320)

    This PR fixes a bug with wrong arguments passed into the call to
    `buildAnyExpr`. This function has args with default values, hence the
    bug occurred.
    All the changes are even with the clang's original codegen.
    
    For the reference, the LLVM IR code for `agg-init.cpp::usev()` function
    looks like the following:
    ```
    define dso_local void @_Z3usev() #0 {
    entry:
      %agg.tmp.ensured = alloca %struct.yep_, align 4
      %Status = getelementptr inbounds %struct.yep_, ptr %agg.tmp.ensured, i32 0, i32 0
      store i32 0, ptr %Status, align 4
      %HC = getelementptr inbounds %struct.yep_, ptr %agg.tmp.ensured, i32 0, i32 1
      store i32 0, ptr %HC, align 4
      ret void
    }
    ```
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    ffa498e View commit details
    Browse the repository at this point in the history
  70. [CIR][CodeGen] Support global variable offsets in initializers (llvmg…

    …h-299). (llvm#305)
    
    This PR adds proper handling for address offsets in global initializers
    as e.g. in
    ```
    int val[10];                                                                     
    int *addr = &val[1];                                                               
    ```
    (such offsets are ignored on current trunk).
    
    I'm not proud of this patch because it performs an ugly conversion from
    byte offset, produced by `APValue::getLValueOffset`, to a sequence of
    CIR indices. Alternative suggestions are welcomed.
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    03df997 View commit details
    Browse the repository at this point in the history
  71. [CIR][CIRGen][Lowering] supports functions pointers (llvm#316)

    This PR adds a support of the function pointers in CIR.
    
    From the implementation point of view, we emit an address of a function
    as a `GlobalViewAttr`.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    9eb6612 View commit details
    Browse the repository at this point in the history
  72. [CIR][Lowering] fix lowering for the structs inited with zeros (llvm#315

    )
    
    Basically that is, the  next code should work now
    ```
    typedef struct {
        int a;
        int b;
    } A;
    ...
    A a = {0, 0};
    ```
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    611bc4c View commit details
    Browse the repository at this point in the history
  73. [CIR][Codegen] Fixes function ptrs in recursive types (llvm#328)

    Since recursive types were perfectly fixed, we can safely remove the
    assert that prevented functons types generation for the case of
    incomplete types. The test is added - just to show that everything is ok
    for such kind of functions.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    3628228 View commit details
    Browse the repository at this point in the history
  74. [CIR][IR] Harden get_member verifier (llvm#330)

    I think it's time to claim that CIR supports recursive types (many
    thanks to llvm#303 and to @sitio-couto :) )
    And we can bring back the `get_member` verification back, with no checks
    for incomplete types. What do you think?
    
    And we can close llvm#256 as well
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    39694bf View commit details
    Browse the repository at this point in the history
  75. [CIR][CodeGen] Support incomplete arrays (llvm#333)

    Just a minor fix with for incomplete arrays + minor refactoring
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f8c1d43 View commit details
    Browse the repository at this point in the history
  76. Configuration menu
    Copy the full SHA
    d675625 View commit details
    Browse the repository at this point in the history
  77. [CIR][NFC] Move LexicalScope after RunCleanupsScope

    While here toggle LexicalScopeGuard's visibility, to be consistent..
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d382404 View commit details
    Browse the repository at this point in the history
  78. [CIR][CIRGen] Generalize and run cleanups on lexical scopes

    This adds more support for automatic variable destruction, which is long due.
    There are more bits to come in following patches but this enables the bulk
    mechanism.
    
    - Bake running cleanup functionality from scopes into LexicalScopeContext
    - This is closer to traditional LLVM codegen, LexicalScopeContext now inherits from RunCleanupsScope.
    - Merge LexicalScopeContext and LexicalScopeGuard into one LexicalScope
    - Proper implement dtor for lexicalScope and fwd ForceCleanup
    - Add testcase
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    458dec8 View commit details
    Browse the repository at this point in the history
  79. [CIR][NFC] Make test more portable on windows

    Fixes llvm#337
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    935aca0 View commit details
    Browse the repository at this point in the history
  80. [CIR] Change GlobalViewAttr indices to use MLIR integers. (llvm#327)

    This is a followup PR to comment
    llvm#305 (comment) by
    @bcardosolopes
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2ef8776 View commit details
    Browse the repository at this point in the history
  81. [CIR][IR] Fix ConstPtrAttr parsing (llvm#341)

    ConstPtrAttrs with numbers instead of the `null` keyword were not parsed
    correctly.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    a9a7c26 View commit details
    Browse the repository at this point in the history
  82. [CIR][Lowering] Fix vbase.cpp test (llvm#342)

    Two fixes were applied:
    
    - A couple of `lowerCirAttrAsValue` visitors were fixed as one of the
    arguments was missing the const qualifier on the type converter. To
    avoid this problem, the const qualifier was moved to before the type.
    - In the type converter, `cir.struct`s were wrongly identified by their
    name's length, now, they are identified by their name's existence.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    0aadb74 View commit details
    Browse the repository at this point in the history
  83. [CIR][CIRGen] Fix agg-init2.cpp test (llvm#343)

    This patch fixes the agg-init2.cpp test by doing two things:
    
    - Updating the `VisitCXXConstructExpr` to return a zero attribute
    initializer for trivial zero-initialized objects.
    - Forcing the `buildAutoVarInit` method to use ctor calls on temporary
    object expressions even if the object can be constant-initialized.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    6554863 View commit details
    Browse the repository at this point in the history
  84. [CIR][NFC] Remove XFAIL from ThroughMLIR tests (llvm#344)

    Replaces the usage of builtin integers in the CIR code and removes the
    dynamic dimension from `memref`s lowered from `!cir.ptr` types.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    c74aed1 View commit details
    Browse the repository at this point in the history
  85. [CIR][CogeGen] Support aggregate copy via assignment (llvm#325)

    This PR adds a support of copies of aggregated data types via
    assignment.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    48572c3 View commit details
    Browse the repository at this point in the history
  86. [CIR][CodeGen] Bitfield operations (llvm#279)

    As we discussed in llvm#233, there is a desire to have CIR operations for
    bit fields set/get access and do all the stuff in the `LoweringPrepare`.
    
    There is one thing I want to discuss, that's why the PR is marked as a
    draft now.
    Looks like I have to introduce some redundant helpers for all these `or`
    and `shift` operations: while we were in the `CodeGen` area, we used
    `CIRGenBuilder` and we could easily extend it. I bet we don't want to
    depend from `CodeGen` in the `LoweringPrepare`. Once it's true. what is
    a good place for all this common things? As an idea, we could introduce
    one more layer for builder, with no state involved - just helpers and
    nothing else. But again, what is a good place for it from your point of
    view?
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    3cd2c56 View commit details
    Browse the repository at this point in the history
  87. [CIR][CIRGen] Fix zero-offset global view access

    Instead of ignoring global view access with zero offset, we should
    properly dereference the global type to prevent type-matching errors.
    
    This patch also fixes other two issues:
    
     - An extra index was wrongly added to the global view access. E.g.
       for an access like `a[0]` would generate a GV with 2 zero indexes.
       The indexes, however, do not take the pointer wrapping the global
       type into account.
     - When assigning the address of a complete type to an incomplete one
       the complete type would override the incomplete destination type,
       causing inconsistencies during CodeGen. For example, given `int a[3];`
       and `int (*ptr_a)[] = &a;`, despite `ptr_a`, in CIR it would be
       considered complete.
    
    Fixes llvm#329
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d40e85d View commit details
    Browse the repository at this point in the history
  88. [CIR][github] Setup github test CIR workflow. (llvm#332)

    Closes llvm#288 
    
    The action mirrors
    https://github.com/llvm/llvm-project/blob/main/.github/workflows/clang-tests.yml
    with a few minor differences:
     - it is not restricted to: `github.repository_owner == 'llvm'`
    - it triggers on pull requests and pushes to `main` instead of `release`
    branches
    
    I suggest adding branch protection rule to require tests to pass for
    each pull request:
    `Settings -> Branches -> Add branch protection rule -> Require status
    checks to pass before merging`
    xlauko authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d1c6a4d View commit details
    Browse the repository at this point in the history
  89. Configuration menu
    Copy the full SHA
    540517d View commit details
    Browse the repository at this point in the history
  90. [CIR][CIRGen] Enable more cases for dtor generation

    This allows some dtors code (like in dtors-scopes.cpp) to work and run on macOS
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    463c780 View commit details
    Browse the repository at this point in the history
  91. Configuration menu
    Copy the full SHA
    cd6e2de View commit details
    Browse the repository at this point in the history
  92. [CIR][IR] Refactor parsing/printing of implicitly terminated regions

    The `shouldPrintTerm` and `checkBlockTerminator` were replaced in favor
    of `omitRegionTerm` and `ensureRegionTerm` respectively. The first is
    essentially the same method but simplified. The latter was refactored to
    do only two things: check if the terminator omission of a region is
    valid and, if so, insert the omitted terminator into the region.
    
    The simplifications mostly leverage the fact that we only omit empty
    yield values in a single-block region.
    
    ghstack-source-id: 7b943719ca0fb4ac2d1d29775d7545787c23bcbf
    Pull Request resolved: llvm#321
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bd97626 View commit details
    Browse the repository at this point in the history
  93. [CIR][IR] Refactor ScopeOp assembly format

    This simplifies and modularizes the assembly format for ScopeOp by
    using the Tablegen assembly description and a new custom printer/parser
    that handles regions with omitted terminators.
    
    It also fixes an issue where the parser would not correctly handle
    `cir.scopes` with a return value.
    
    ghstack-source-id: c5b9be705113c21117363cb3bd78e19d133c3fc5
    Pull Request resolved: llvm#311
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f94deb1 View commit details
    Browse the repository at this point in the history
  94. [CIR][NFC] Remove comment breadcrumb

    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    a6c54fe View commit details
    Browse the repository at this point in the history
  95. Configuration menu
    Copy the full SHA
    176e9a3 View commit details
    Browse the repository at this point in the history
  96. Configuration menu
    Copy the full SHA
    478802d View commit details
    Browse the repository at this point in the history
  97. Configuration menu
    Copy the full SHA
    e9d6705 View commit details
    Browse the repository at this point in the history
  98. [CIR] Add cir.libc.memchr operation

    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bd87e2d View commit details
    Browse the repository at this point in the history
  99. Configuration menu
    Copy the full SHA
    7af1085 View commit details
    Browse the repository at this point in the history
  100. Configuration menu
    Copy the full SHA
    0fffb27 View commit details
    Browse the repository at this point in the history
  101. [CIR][CodeGen] Inline asm: CIR operation (llvm#326)

    I will break the PR llvm#308 into pieces and submit them one-by-one.
    
    The first PR introduce CIR operation and the `buildAsmStmt` function.
    The latter is the main place for the future changesm and the former was
    taken directly from MLIR LLVM IR dialect.
    As a result, there is nothing really interesting happen here, but now we
    can at least emit cir for an empty inline assembler. And as a first step
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    035dded View commit details
    Browse the repository at this point in the history
  102. [CIR][CodeGen] Add dynamic AllocaOp support (llvm#340)

    This PR adds dynamic stack allocation into `AllocaOp` that will be useful in future -
    currently I work on variable length array support. So I start to make
    tiny PRs in advance)
    No changes in tests needed, I tried to make the changes as smooth as
    possible, so no existing `AllocaOp` usages need to be changed.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2e8461d View commit details
    Browse the repository at this point in the history
  103. [CIR][Lowering] Fix loop lowering for top-level break/continue (llvm#349

    )
    
    This PR fixes a couple of corner cases connected with the `YieldOp`
    lowering in loops.
    Previously, in llvm#211 we introduced `lowerNestedBreakContinue` but we
    didn't check that `YieldOp` may belong to the same region, i.e. it is
    not nested, e.g.
    ```
    while(1) {
       break;
    }
    ```
    Hence the error `op already replaced`. 
    
    Next, we fix `yield` lowering for `ifOp` and `switchOp` but didn't cover
    `scopeOp`, and the same error occurred. This PR fixes this as well.
    
    I added two tests - with no checks actually, just to make sure no more
    crashes happen.
    
    fixes llvm#324
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    b89132d View commit details
    Browse the repository at this point in the history
  104. Configuration menu
    Copy the full SHA
    85f6393 View commit details
    Browse the repository at this point in the history
  105. [CIR] Add skeleton for Idiom Recognizer pass

    Among other long term things, in the short term this will be used to map some
    higher level library calls into CIR operations.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    1caf67d View commit details
    Browse the repository at this point in the history
  106. Configuration menu
    Copy the full SHA
    8096e30 View commit details
    Browse the repository at this point in the history
  107. Configuration menu
    Copy the full SHA
    bc47fa9 View commit details
    Browse the repository at this point in the history
  108. Configuration menu
    Copy the full SHA
    7a46b55 View commit details
    Browse the repository at this point in the history
  109. [CIR][CIRGen] Add CallExpr nodes to cir.call when possible

    It's not used just yet, and the ast was removed from printing given
    we don't have a serialization story anyways, so it's less aggressive
    with existing tests.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    8b60b9a View commit details
    Browse the repository at this point in the history
  110. [CIR][NFC] Add a isStdFunctionCall method to ASTCallExprInterface

    This will be tested soon by some idiom recognition code.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    e4ca377 View commit details
    Browse the repository at this point in the history
  111. [CIR][NFC] Isolate ClangIR-specific options in Options.td

    Organize things a bit while here.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    b3c3e8e View commit details
    Browse the repository at this point in the history
  112. [CIR] Add initial support for idiom recognizing std::find

    - Identify such calls and produce a remark. Next step is to map
    this to a CIR operation representing std::find, which should
    come next.
    - Add new `-fclangir-idiom-recognizer=` option, used to control
    remark options for now.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    ff44f50 View commit details
    Browse the repository at this point in the history
  113. [CIR] Add cir.std.find operation

    This is going to be used to raise `cir.call`s to `std::find(...)` into
    `cir.std.find`.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    8bf7a43 View commit details
    Browse the repository at this point in the history
  114. [CIR] Raise std::find call to cir.std.find

    Also implement lowering back to `std::call` before lowering to LLVM.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    6a819c3 View commit details
    Browse the repository at this point in the history
  115. [CIR][Lowering] Fix function ptr field lowering in a global struct (l…

    …lvm#353)
    
    This PR fixes a global vars lowering with a funciton ptr field.
    Previously, the next code caused fail in the `foo` lowering:
    ```
    static void myfun(int a) {}
    
    static struct {
        void (*func)(int flag);
    } const Handlers[] = {
        {myfun}, {myfun}, {myfun}
    };
    
    void foo(int i, int flag) {
        Handlers[i].func(flag);
    }
    ```
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    031bf70 View commit details
    Browse the repository at this point in the history
  116. [CIR][NFC] Formatting

    lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    15e0ad9 View commit details
    Browse the repository at this point in the history
  117. [CIR] Vector types - part 1 (llvm#347)

    This is the first part of implementing vector types and vector
    operations in ClangIR, issue llvm#284. This is enough to compile this test
    program. I haven't tried to do anything beyond that yet.
    ```
    typedef int int4 __attribute__((vector_size(16)));
    int main(int argc, char** argv) {
      int4 a = { 1, argc, argc + 1, 4 };
      int4 b = { 5, argc + 2, argc + 3, 8 };
      int4 c = a + b;
      return c[1];
    }
    ```
    
    This change includes:
    
    * Fixed-sized vector types which are parameterized on the element type
    and the number of elements. For example, `!cir.vector<s32i x 4>`. (No
    scalable vector types yet; those will come later.)
    
    * New operation `cir.vec` which creates an object of a vector type with
    the given operands.
    
    * New operation `cir.vec_elem` which extracts an element from a vector.
    (The array subscript operation doesn't work here because the result is
    an rvalue, not an lvalue.)
    
    * Basic binary arithmetic operations on vector types, though only
    addition has been tested.
    
    There are no unary operators, comparison operators, casts, or shuffle
    operations yet. Those will all come later.
    dkolsen-pgi authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f7d1590 View commit details
    Browse the repository at this point in the history
  118. [CIR][CodeGen][Lowering] Support multi-block case/default clauses (ll…

    …vm#356)
    
    This PR adds a support for the multi-block case statements.
    Previously, the code example below caused crash in cir verification 
    
    Lowering to the `llvm` dialect is pretty straightforward: the same logic
    as before is applied to all the region's blocks with no successors, i.e.
    we no longer think a case/default region contains only one block.
    
    The `CodeGen` part is a little bit tricky. Previously, any sub-statement
    of `case` or`default`, that was not any of them (i.e. neither `case` nor
    `default`) was processed with an insertion guard, meaning that the next
    sub-statement in the same clause was inserted again in the same block as
    the first one. It would be fine, once sub-statement didn't generate any
    blocks as well.
    
    For instance, 
    ```
    void foo(int a) {
      switch (a)
      {
      case 3:
        return;
        break;
      }
    }
    ```
    The `return` statement actually emit a new block after, where the
    unreachable code with `break` should be inserted in. That's why we also
    need to update `lastCaseBlock` while generating `cir.switch`
    
    This is quite frequent bug in `llvm-test-suite`
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    bfae692 View commit details
    Browse the repository at this point in the history
  119. Configuration menu
    Copy the full SHA
    325c8b6 View commit details
    Browse the repository at this point in the history
  120. [CIR][Passes] Introduce cir-lib-opt pass

    This contains just the skeleton, but the idea is that this pass is
    going to contain transformations done on top CIR generated by the
    C/C++ idiom recognizer.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    ec80621 View commit details
    Browse the repository at this point in the history
  121. [CIR] Fix issues pointed by github CI

    Specify proper target triples to prevent issues on both Windows and MacOS
    regarding non-implemented ABI bits.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    4e263f5 View commit details
    Browse the repository at this point in the history
  122. [CIR] Add iterator_{begin,end} ops

    Only a skeleton for incremental work.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    3a81895 View commit details
    Browse the repository at this point in the history
  123. [CIR][IdiomRecognizer] Recognize few variations for begin/end iterators

    Initial step into modeling iterators in CIR.
    
    Right now it only looks at the member functions with .begin/.end function
    calls, it does not look at the iterator type, has no notion of forward/reverse
    iterators, nor filters based on the container types - those improvements will
    come next.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    76aeb7b View commit details
    Browse the repository at this point in the history
  124. [CIR][CodeGen] Use signed type for result of ptrdiff operation. (llvm…

    …#355)
    
    Before this fix attached test case has been failing due to type mismatch
    (signed vs unsigned).
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f8ff91a View commit details
    Browse the repository at this point in the history
  125. [CIR] support -std=gnu89 (llvm#358)

    Tiny PR, support `-std=gnu89` option
    This is quite frequent bug in `llvm-test-suite`
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    58a6262 View commit details
    Browse the repository at this point in the history
  126. [CIR][CodeGen] support extern var in function (llvm#359)

    This PR "adds" the support of extern vars in function body. Actually, I
    just erased an assert. Any reason it was there?
    ```
    int foo() {
        extern int optind;
        return optind;
    }
    ```
    
    This is quite frequent bug in `llvm-test-suite`
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    8034b97 View commit details
    Browse the repository at this point in the history
  127. [CIR][Codegen] Adds Stack save-restore ops (llvm#346)

    This PR adds `cir.stack_save` and `cir.stack_restore` operations.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    81be6d5 View commit details
    Browse the repository at this point in the history
  128. [CIR][Lowering][Bugfix] Lower nested breaks in switch statements (llv…

    …m#357)
    
    This PR fixes lowering of the next code: 
    ```
    void foo(int x, int y) {
        switch (x) {
            case 0: 
                if (y) 
                    break;
                break;
        }
    }
    ```
    i.e. when some sub statement contains `break` as well. Previously, we
    did this trick for `loop`: process nested `break`/`continue` statements
    while `LoopOp` lowering if they don't belong to another `LoopOp` or
    `SwitchOp`. This is why there is some refactoring here as well, but the
    idea is stiil the same: we need to process nested operations and emit
    branches to the proper blocks.
    
    This is quite frequent bug in `llvm-test-suite`
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    dbdd28b View commit details
    Browse the repository at this point in the history
  129. [CIR] Change mock std::array iterator definitions

    This is how both libc++ and libstdc++ implement iterator in std::array, stick
    to those use cases for now. We could add other variations in the future if there
    are others around.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d0dd042 View commit details
    Browse the repository at this point in the history
  130. [CIR][IdiomRecognizer] Make iterator recognition more strict

    - Check whether container is part of std, add a fixed list of
    available containers (for now only std::array)
    - Add a getRawDecl method to ASTRecordDeclInterface
    - Testcases
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    3c94e31 View commit details
    Browse the repository at this point in the history
  131. [CIR] Cleanup idiom-recognizer and lib-opt options

    This was a bit half backed, give it some love.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    5ecc5b4 View commit details
    Browse the repository at this point in the history
  132. [CIR][LibOpt] Add a first transformation: std::find to memchr

    Inspired by similar work in libc++, pointed to me by Louis Dionne
    and Nikolas Klauser.
    
    This is initial, very conservative and not generalized yet: works
    for `char`s within a specific version of `std::find`.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    c1fe1f2 View commit details
    Browse the repository at this point in the history
  133. Configuration menu
    Copy the full SHA
    66f7a40 View commit details
    Browse the repository at this point in the history
  134. Configuration menu
    Copy the full SHA
    e53b5c9 View commit details
    Browse the repository at this point in the history
  135. Configuration menu
    Copy the full SHA
    e8cf076 View commit details
    Browse the repository at this point in the history
  136. [CIR][CodeGen] Fix flat offset lowering code to consider field alignm…

    …ents.
    
    Before this fix conversion of flat offset to GlobalView indices could
    crash or compute invalid result.
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    7b1fd66 View commit details
    Browse the repository at this point in the history
  137. [CIR][Lowering][Bugfix] Lower ScopeOp with return op (llvm#364)

    `ScopeOp` may end with `ReturnOp` instead of `YieldOp`, that is not
    expected now. This PR fix this.
    The reduced example is:
    ```
    int foo() {
        {
            return 0;
        }
    }
    ```
    This is quite frequent bug in `llvm-test-suite`
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    f8c6adb View commit details
    Browse the repository at this point in the history
  138. Configuration menu
    Copy the full SHA
    ccf9c9b View commit details
    Browse the repository at this point in the history
  139. Configuration menu
    Copy the full SHA
    f51cdec View commit details
    Browse the repository at this point in the history
  140. Revert "[mlir][llvm] Fixes CallOp builder for the case of indirect call"

    This reverts commit bbaa147.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    043aa75 View commit details
    Browse the repository at this point in the history
  141. [CIR][CIRGen][NFC] Enhance alloca helpers (llvm#367)

    One more step towards variable length array support. 
    This PR adds one more helper for the `alloca` instruction and re-use the
    existing ones.
    
    The reason is the following: right now there are two possible ways to
    insert alloca: either to a function entry block or to the given block
    after all the existing alloca instructions. But for VLA support we need
    to insert alloca anywhere, right after an array's size becomes known.
    Thus, we add one more parameter with the default value - insertion
    point.
    
    Also, we don't want copy-paste the code, and reuse the existing helpers,
    but it may be a little bit confusing to read.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    9bcfc1a View commit details
    Browse the repository at this point in the history
  142. [CIR][Lowering] add cir.ternary to scf.if lowering (llvm#368)

    This PR adds `cir.ternary` lowering. There are two approaches to lower
    `cir.ternary` imo:
    1. Use `scf.if` op.
    2. Use `cf.cond_br` op. 
    
    I choose `scf.if` because `scf.if` + canonicalization produces
    `arith.select` whereas `cf.cond_br` requires scf lifting. In many ways
    `scf.if` is more high-level and closer to `cir.ternary`.
    
    A separate `cir.yield` lowering is required since we cannot directly
    replace `cir.yield` in the ternary op lowering -- the yield operands may
    still be illegal and doing so produces `builtin.unrealized_cast` ops. I
    couldn't figured out a way to solve this issue without adding a separate
    lowering pattern. Please let me know if you know a way to solve this
    issue.
    Kuree authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    dd1123f View commit details
    Browse the repository at this point in the history
  143. [CIR][CIRGen] supports struct copy from function call result (llvm#369)

    This PR fixes the next case 
    ```
    typedef struct { } A;
    
    A create() { A a; return a; }
    
    void foo() {
        A a;
        a = create();
    }
    ```
    i.e. when a struct  is assigned to a function call result
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    5262dda View commit details
    Browse the repository at this point in the history
  144. Configuration menu
    Copy the full SHA
    fcd7462 View commit details
    Browse the repository at this point in the history
  145. [CIR][Lowering] Support lowering of cir.const with GlobalViewAttr (ll…

    …vmgh-352) (llvm#363)
    
    The error manifested in code like
    ```
    int a[16];
    int *const p = a;
    
    void foo() {
      p[0];
    }
    ```
    It's one the most frequent errors in current llvm-test-suite.
    
    I've added the test to globals.cir which is currently XFAILed, I think
    @gitoleg will fix it soon.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    4e8f97d View commit details
    Browse the repository at this point in the history
  146. [CIR][CIRGen] emit cir.zero for constant string literals (llvm#373)

    This PR addresses llvm#248 .
    
    Currently string literals are always lowered to a `cir.const_array`
    attribute even if the string literal only contains null bytes. This
    patch make the CodeGen emits `cir.zero` for these string literals.
    Lancern authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    be1a251 View commit details
    Browse the repository at this point in the history
  147. [CIR][CIRGen] Lvalues and comma expression (llvm#376)

    Currently, codegen of lvalue comma expression would crash:
    
    ```cpp
    int &foo1();
    int &foo2();
    
    void c1() {
        int &x = (foo1(), foo2());  // CRASH
    }
    ```
    
    This simple patch fixes this issue.
    Lancern authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    37732f8 View commit details
    Browse the repository at this point in the history
  148. [CIR] Replace AnyType with CIR_AnyType (llvm#371)

    This PR addresses llvm#90. It introduces a new type constraint `CIR_AnyType`
    which allows CIR types and MLIR floating-point types. Present `AnyType`
    constraints are replaced with the new `CIR_AnyType` constraint.
    Lancern authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    96bb98f View commit details
    Browse the repository at this point in the history
  149. [CIR][CIRGen] Support array def after decl with unknown bound (llvm#375)

    Arrays can be first declared without a known bound, and then defined
    with a known bound. For example:
    
    ```cpp
    extern int data[];
    
    int test() { return data[1]; }
    
    int data[3] {1, 2, 3};
    ```
    
    Currently `clangir` crashes on generating CIR for this case. This is due
    to the type of the `data` definition being different from its
    declaration. This patch adds support for such a case.
    Lancern authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    b9e19a2 View commit details
    Browse the repository at this point in the history
  150. Configuration menu
    Copy the full SHA
    8f21b49 View commit details
    Browse the repository at this point in the history
  151. [CIR][Transforms][NFC] Refactor MergeCleanups pass (llvm#384)

    Breaks the pass into smaller more manageable rewrites.
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    373c887 View commit details
    Browse the repository at this point in the history
  152. Configuration menu
    Copy the full SHA
    7274cc5 View commit details
    Browse the repository at this point in the history
  153. [CIR][Transforms][Bugfix] Do not use-after-free in MergeCleanups and …

    …IdiomRecognizer. (llvm#389)
    
    Some tests started failing under `-DLLVM_USE_SANITIZER=Address` due to
    trivial use-after-free errors.
    yugr authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    6d7ab16 View commit details
    Browse the repository at this point in the history
  154. [CIR][IR] Implement loop's conditional operation (llvm#391)

    Like SCF's `scf.condition`, the `cir.condition` simplifies codegen of
    loop conditions by removing the need of a contitional branch. It takes a
    single boolean operand which, if true, executes the body region,
    otherwise exits the loop. This also simplifies lowering and the dialect
    it self.
    
    A new constraint is now enforced on `cir.loops`: the condition region
    must terminate with a `cir.condition` operation.
    
    A few tests were removed as they became redundant, and others where
    simplified.
    
    The merge-cleanups pass no longer simplifies compile-time constant
    conditions, as the condition body terminator is no longer allowed to be
    terminated with a `cir.yield`. To circumvent this, a proper folder
    should be implemented to fold constant conditions, but this was left as
    future work.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    a37d71e View commit details
    Browse the repository at this point in the history
  155. Configuration menu
    Copy the full SHA
    ece0e11 View commit details
    Browse the repository at this point in the history
  156. [CIR][CIRGen][NFC] Support yielding values in LexicalScope

    Once the LexicalScope goes out of scope, its cleanup process will also
    check if a return was set to be yielded, and, if so, generate the yield
    with the respective value.
    
    ghstack-source-id: 9305d2ba5631840937721755358a774dc9e08b90
    Pull Request resolved: llvm#312
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    dced002 View commit details
    Browse the repository at this point in the history
  157. [CIR][CIRGen][NFC] Return scope result in compound stmt builders

    Instead of returning a boolean indicating whether the statement was
    handled, returns the ReturnExpr of the statement if there is one. It
    also adds some extra bookkeeping to ensure that the result is returned
    when needed. This allows for better support of GCC's `ExprStmt`
    extension.
    
    The logical result was not used: it was handled but it would never fail.
    Any errors within builders should likely be handled with asserts and
    unreachables since they imply a programmer's error in the code.
    
    ghstack-source-id: 2319cf3f12e56374a52aaafa4304e74de3ee6453
    Pull Request resolved: llvm#313
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    01bdc1d View commit details
    Browse the repository at this point in the history
  158. [CIR][CIRGen] Partially support statement expressions return values

    Adds support for GCC statement expressions return values as well as
    StmtExpr LValue emissions.
    
    To simplify the lowering process, the scope return value is not used.
    Instead, a temporary allocation is created on the parent scope where the
    return value is stored. For classes, a second scope is created around
    this temporary allocation to ensure any destructors are called.
    
    This does not implement the full semantics of statement expressions.
    
    ghstack-source-id: 64e03fc3df45975590ddbcab44959c2b49601101
    Pull Request resolved: llvm#314
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    5240538 View commit details
    Browse the repository at this point in the history
  159. [CIR] Introduce exception info type

    Incrementally design out support for try/catch and relationship
    with calls. This introduces an exception information type, which
    is will be returned somehow by throwing calls.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    65ac181 View commit details
    Browse the repository at this point in the history
  160. Configuration menu
    Copy the full SHA
    d30f499 View commit details
    Browse the repository at this point in the history
  161. [CIR][CIRGen][Exceptions] More on try statemet codegen: wrap with cir…

    ….scope
    
    Incremental work, test coming soon. This code path isn't exercised just yet.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    57f5daa View commit details
    Browse the repository at this point in the history
  162. Configuration menu
    Copy the full SHA
    62fa7e6 View commit details
    Browse the repository at this point in the history
  163. [CIR][CIRGen] Fix wrong assert

    Silly mistake introduced in previous commit.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    126c22c View commit details
    Browse the repository at this point in the history
  164. Configuration menu
    Copy the full SHA
    4807a28 View commit details
    Browse the repository at this point in the history
  165. Configuration menu
    Copy the full SHA
    a53f205 View commit details
    Browse the repository at this point in the history
  166. [CIR] Introduce cir.try_call operation

    This will be used for any calls happening inside try regions.
    
    More refactoring. For now it's incremental work, still some mileage to cover
    before I can introduce a testcase. The current implementation mimics cir.call,
    pieces are going to change in following commits.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    8306747 View commit details
    Browse the repository at this point in the history
  167. [CIR][CIRGen] Add constraints to inline assembly (llvm#351)

    The next step for inline assembly. Sorry, maybe it looks too big on the
    first glance. And it's kind of hard to extract something well-grained
    from the code and introduce it as a separate PR, but I try.
    
    Actually there is nothing really interesting done here, and the next
    will (I hope :) ) simplify your review process.
    
    1) In this PR we introduce operand's constraints and the task is to
    collect them (and maybe transform a little)
    2) There are two big functions copy-pasted from the traditional
    `Codegen` and I doubt they need to be reviewed.
    3) We still don't do anything CIR-specific. Basically, we just work with
    strings in the same way like traditional `Codegen` does.
    4) We just iterate over the input and output operands and collect the
    constraints
    5) We still follow to the traditional `CodeGen` and don't do anything
    new, except a separate function that collects constraints infos in the
    very beginning of the `buildStmt`.
    
    
    Also, I renamed `AsmDialect` to `AsmFlavor` as you asked in llvm#326
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    807899f View commit details
    Browse the repository at this point in the history
  168. [CIR][Lowering] Support lowering of const arrays of structs (llvm#370)

    This PR fixes CIR lowering for the next case.
    
    ```
    void foo() {
        struct {
            int a;
            int b;
        } a[1] = {{0,1}}; 
    }
    ```
    Note, we don't create attribute here and lower such const arrays as
    values.
    gitoleg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    dd7bc5c View commit details
    Browse the repository at this point in the history
  169. Configuration menu
    Copy the full SHA
    bf610f8 View commit details
    Browse the repository at this point in the history
  170. [CIR] Fix int constant type verification (llvm#386)

    When introducing attribute `#cir.int`, the constant type verification is
    not updated. If a `cir.const` operation produces an integral constant
    from a `#cir.int` attribute, the integer's type is not verified:
    
    ```mlir
    %1 = cir.const(#cir.int<0> : !cir.int<s, 8>) : !cir.int<u, 8>
    // Not verified: !cir.int<s, 8> differs from !cir.int<u, 8>
    ```
    
    The corresponding test is also wrong but fail to be detected.
    
    This patch fixes this issue.
    Lancern authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    905a45a View commit details
    Browse the repository at this point in the history
  171. [CIR] Vector types, part 2 (llvm#387)

    This is part 2 of implementing vector types and vector operations in
    ClangIR, issue llvm#284.
    
    Create new operation `cir.vec.insert`, which changes one element of an
    existing vector object and returns the modified vector object. The input
    and output vectors are prvalues; this operation does not touch memory.
    The assembly format and the order of the arguments match that of
    llvm.insertelement in the LLVM dialect, since the operations have
    identical semantics.
    
    Implement vector element lvalues in class `LValue`, adding member
    functions `getVectorAddress()`, `getVectorPointer()`, `getVectorIdx()`,
    and `MakeVectorElt(...)`.
    
    The assembly format for operation `cir.vec.extract` was changed to match
    that of llvm.extractelement in the LLVM dialect, since the operations
    have identical semantics.
    
    These two features, `cir.vec.insert` and vector element lvalues, are
    used to implement `v[n] = e`, where `v` is a vector. This is a little
    tricky, because `v[n]` isn't really an lvalue, as its address cannot be
    taken. The only place it can be used as an lvalue is on the left-hand
    side of an assignment.
    
    Implement unary operators on vector objects (except for logical not on a
    vector mask, which will be covered in a future commit for boolean
    vectors). The code for lowering cir.unary for all types, in
    `CIRUnaryOpLowering::matchAndRewrite`, was largely rewritten. Support
    for unary `+` on non-vector pointer types was added. (It was already
    supported and tested in AST->ClangIR CodeGen, but was missing from
    ClangIR->LLVM Dialect lowering.)
    
    Add tests for all binary vector arithmetic operations other than
    relational operators and shift operators. There were all working after
    the previous vector types commit, but only addition had beet tested at
    the time.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    1497843 View commit details
    Browse the repository at this point in the history
  172. [CIR][IR] Implement cir.continue operation

    Detaches the representation of the C/C++ `continue` statement into a
    separate operation. This simplifies mostly lowering and verifications
    related to `continue` statements, as well as the definition and lowering
    of the `cir.yield` operation.
    
    A few checks regarding region terminators were also removed from the
    lowering stage, since they are already enforced by MLIR.
    
    ghstack-source-id: 1810a48ada88fe7ef5638b0758a2298d9cfbdb8b
    Pull Request resolved: llvm#394
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    76c9f1a View commit details
    Browse the repository at this point in the history
  173. [CIR][IR] Implement cir.break operation

    Same rationale as `cir.continue`, it detaches the representation of the
    C/C++ `break` statement into a separate operation. This simplifies
    lowering and verifications related to `break` statements, as well as the
    definition and lowering of the `cir.yield` operation.
    
    ghstack-source-id: 929cf96c3abe51d717c2fa6ca9e0073e42e770c6
    Pull Request resolved: llvm#395
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    def74b9 View commit details
    Browse the repository at this point in the history
  174. [CIR][IR] Deprecate cir.yield nosuspend

    This changes the `cir.await` operation to expect a `cir.condition` as
    the terminator for the ready region. This simplifies the `cir.await`
    while also simplifying the `cir.yield`. If `cir.condition` holds a
    true value, then the `cir.await` will continue the coroutine, otherwise,
    it will suspend its execution.
    
    The `cir.condition` op was also updated to allow `cir.await` as its
    parent operation.
    
    ghstack-source-id: 1ebeb2cfbdeff6f289936d16354cba534e093ea7
    Pull Request resolved: llvm#396
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    596559f View commit details
    Browse the repository at this point in the history
  175. [CIR][IR] Deprecate cir.yield fallthrough

    Instead of having a `cir.yield fallthrough` operation, the default
    branching behavior of the parent operation is denoted by `cir.yield`.
    In other words, a `cir.yield` operation in a switch case region
    represents the default branching behavior of the switch operation, which
    is a fallthrough.
    
    The `cir.yield` operation now represents the default branching behavior
    of the parent operation's region. For example, in a if-else region, a
    `cir.yield` operation represents a branch to the exit block.
    
    ghstack-source-id: 713c457dfb2228fbdf63ba72dd6396665512bb9d
    Pull Request resolved: llvm#397
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2e01ec4 View commit details
    Browse the repository at this point in the history
  176. [CIR] TryCallOp: add blocks, arguments, proper interface impl and tes…

    …tcase
    
    - Add cir.try_call parsing.
    - Add block destinations and hookup exception info type.
    - Properly implement interface methods.
    
    Printer is still missing, but coming next.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    9a82c8a View commit details
    Browse the repository at this point in the history
  177. [CIR][Exceptions] Simplify cir.try_call

    After some discussions with @sitio-couto, it might be better if we use a
    simplified version that doesn't take the labels into account just yet.
    `cir.try_call` should have the same semantics as `cir.break`, in the sense that
    it needs further expansion when getting rid of structured control flow. Early
    lowering here would complicate CIR generated code and make it harder to
    analyse. Further CIR to CIR passes will properly expand this at some point
    prior to LLVM lowering.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2b5cd69 View commit details
    Browse the repository at this point in the history
  178. [CIR] TryCallOp: improve printing

    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    dbccdb1 View commit details
    Browse the repository at this point in the history
  179. [CIR][CIRGen][Exceptions] More prep work on landing-pad like logic

    We can now handle more of EHScope::Catch and lay out the skeleton for CIR's
    version of that, adding tons of asserts for cases not currently handled. As
    part of this we're able to build the clause list as part of CatchOp based on
    the handlers, and create allocation for the exception_info type.
    
    In the next part (where we currently hit an assert) of this work, the CatchOp
    will then get its regions populated.
    
    Incremental steps into getting basic exceptions to work, not enough for a
    testcase just yet.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    14747d7 View commit details
    Browse the repository at this point in the history
  180. [CIR][CIRGen][Exceptions] Complete buildCatchDispatchBlock

    Doesn't do a lot of things compared to LLVM traditional codegen, one
    more step towards basic exception support. No testcase possible just yet.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    6d1d001 View commit details
    Browse the repository at this point in the history
  181. [CIR] Add cir.resume op and use it in cir.catch

    - Add an extra CatchOp region to hold fallback (where EH usually resumes or
      rethrows as part of try/catch).
    - Emit `cir.resume` on the fallback region.
    
    Incremental step into the next assertion, still missing pieces before adding
    the first testcase.
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    2af33f4 View commit details
    Browse the repository at this point in the history
  182. [CIR][CIRGen] Support wide string literals (llvm#399)

    This commit supports the codegen of wide string literals, including
    `wchar_t` string literals, `char16_t` string literals, and `char32_t`
    string literals.
    
    I'm not following the proposal in llvm#374. The clang frontend doesn't
    record the literal string. It only records the encoded code units for
    wide string literals. So I believe that a dedicated string attribute
    with an encoding tag as described in llvm#374 may not be that helpful as I
    thought.
    Lancern authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    64efeb2 View commit details
    Browse the repository at this point in the history
  183. [CIR][OpenMP] Initial commit for OpenMP support in CIR (llvm#382)

    This patch introduces initial support for:
    ```
    pragma omp parallel
    ```
    
    This patch doesn't add support for any of the `parallel` clauses,
    including variable privatization; thus, all variables are handled as
    shared.
    
    This PR fixes issue llvm#285.
    fabianmcg authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d129b76 View commit details
    Browse the repository at this point in the history
  184. [CIR][Interfaces] Implement LoopOpInterface

    Adds an interface to generically handle lowering and analysis of loop
    operations in CIR. It can also perform verification of invariants common
    to all loop operations.
    
    ghstack-source-id: 0e413b14ea063a2b0d75aeaca0af88e547c15277
    Pull Request resolved: llvm#405
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    97c0a0b View commit details
    Browse the repository at this point in the history
  185. [CIR][Lowering][NFC] Refactor LoopOp lowering

    Leverages the new LoopOpInterface for lowering instead of the LoopOp
    operation. This is a step towards removing the LoopOp operation.
    
    ghstack-source-id: 28c1294833a12669d222a293de76609d2cf19148
    Pull Request resolved: llvm#406
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    382c3fc View commit details
    Browse the repository at this point in the history
  186. [CIR][IR] Refactor do-while loops

    Creates a separate C/C++ operation for do-while loops, while keeping the
    LoopOpInterface to generically handle loops. This simplifies the IR
    generation and printing/parsing of do-while loops. It also allows us to
    define it regions in the order that they are executed, which is useful
    for the lifetime analysis.
    
    ghstack-source-id: b4d9517197b8f82ae677dc2684101fe5762b21b7
    Pull Request resolved: llvm#407
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    25d62f0 View commit details
    Browse the repository at this point in the history
  187. [CIR][IR] Refactor while loops

    Creates a separate C/C++ operation for while loops, while keeping the
    LoopOpInterface to generically handle loops. This simplifies the IR
    generation and printing/parsing of while loops.
    
    ghstack-source-id: 29a6d7530263a4f96dbe6ce3052875831126005d
    Pull Request resolved: llvm#408
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    82bd985 View commit details
    Browse the repository at this point in the history
  188. [CIR][IR] Refactor for loops

    This patch completes the deprecation of the generic `cir.loop` operation
    by adding a new `cir.for` operation and removing the `cir.loop` op. The
    new representation removes some bloat and places the regions in order of
    execution.
    
    ghstack-source-id: 886e0dacc632e5809015e2212810d690ef3ec294
    Pull Request resolved: llvm#409
    sitio-couto authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    ca93268 View commit details
    Browse the repository at this point in the history
  189. [CIR][CIRGen][Exceptions] Populate catch clauses and fix order of ope…

    …rations
    
    More machinery for exceptions.
    
    This time around we finally emit a cir.catch and fix the order of emitting
    operations. This allows a testcase to be added. I also added `CatchParamOp`,
    which fetches the arguments for the clauses from the !cir.eh_info object.
    
    Work coming next:
    - Dtors.
    - Use cir.try instead of cir.scope.
    - Eesume.
    - Documentation.`
    bcardosolopes authored and lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    1d3572b View commit details
    Browse the repository at this point in the history
  190. Configuration menu
    Copy the full SHA
    27e7d22 View commit details
    Browse the repository at this point in the history
  191. [CIR] Make MLIRCIR depend on MLIRCIRInterfaces

    This is currently missing and Debug builds are failing without it.
    lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    e9c1dc6 View commit details
    Browse the repository at this point in the history
  192. [CIR] Remove LLVM_ENABLE_PROJECTS support

    ghstack-source-id: 855519648a4bf2dced501f96e6de1b9b164d85ad
    Pull Request resolved: llvm#424
    lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    d348a30 View commit details
    Browse the repository at this point in the history
  193. Configuration menu
    Copy the full SHA
    3a2e923 View commit details
    Browse the repository at this point in the history
  194. [CIR] Move CI to CLANG_ENABLE_CIR

    ghstack-source-id: 0706d6bb81b5b8eefb04146719b4443aedb29ab1
    Pull Request resolved: llvm#427
    lanza committed Jan 29, 2024
    Configuration menu
    Copy the full SHA
    79d4dc7 View commit details
    Browse the repository at this point in the history

Commits on Jan 30, 2024

  1. Configuration menu
    Copy the full SHA
    38bc6fd View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen][Exceptions] Use cir.try instead of cir.scope

    One more step towards completing try/catch.
    bcardosolopes committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    9bc8b47 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen][NFC] Make buildCall more generic by using CIRCallOpInte…

    …rface
    
    This is prep work for introducing cir.try_call inside cir.try scopes.
    bcardosolopes committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    095d1c5 View commit details
    Browse the repository at this point in the history
  4. [CIR][CIRGen][Exceptions] Use cir.try_call within cir.try regions

    One more incremental step towards try/catch: properly use cir.try_call instead
    of regular cir.call when within a cir.try region.
    bcardosolopes committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    aa157fe View commit details
    Browse the repository at this point in the history

Commits on Jan 31, 2024

  1. [CIR] Add a new volatile flag to distinguish volatile accesses (llvm#402

    )
    
    This patch adds a new `volatile` tag to the following operations to
    distinguish volatile loads and stores from normal loads and stores:
    
    - `cir.load`
    - `cir.store`
    - `cir.get_bitfield`
    - `cir.set_bitfield`
    
    Besides, this patch also updates the CodeGen and LLVMIR lowering code to
    start emitting CIR and LLVMIR operations with volatile flag.
    Lancern committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    afb7c68 View commit details
    Browse the repository at this point in the history
  2. [CIR] Vector types, comparison operators (llvm#432)

    This is part 3 of implementing vector types and vector operations in
    ClangIR, issue llvm#284.
    
    Create new operation `cir.vec.cmp` which implements the relational
    comparison operators (`== != < > <= >=`) on vector types. A new
    operation was created rather than reusing `cir.cmp` because the result
    is a vector of a signed intergral type, not a `bool`.
    
    Add CodeGen and Lowering tests for vector comparisons.
    
    Fix the floating-point comparison predicate when lowering to LLVM. To
    handle NaN values correctly, the comparisons need to be ordered rather
    than unordered. (Except for `!=`, which needs to be unordered.) For
    example, "ueq" was changed to "oeq".
    dkolsen-pgi committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    f2ac9f5 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Add missing visitor for ParenExpr (llvm#428)

    Compilation of the following test
    ```
    void foo6(A* a1) {
      A a2 = (*a1);
    }
    ```
    fails with.
    ```
    NYI
    UNREACHABLE executed at /home/huawei/cir/repo/llvm-project/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp:175!
    ```
    Commit adds required visitor and fixes the issue.
    YazZz1k committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    e7a6bba View commit details
    Browse the repository at this point in the history
  4. [CIR][CodeGen][BugFix] use proper base type for derived class (llvm#404)

    In the original codegen a new type is created for the base class, while
    in CIR we were rewriting the type being processed (due tp misused
    pointers). This PR fix this, and also makes CIR codegen even with the
    original one.
    gitoleg committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    0cef361 View commit details
    Browse the repository at this point in the history
  5. [CIR][CodeGen] Initial variable length array support (llvm#398)

    This is a first PR for variable length array support. There are one (or
    more :) ) ahead.
    
    Basically, we already did lot's of preliminary job in order to land VLA
    in CIR in llvm#367 llvm#346 llvm#340. So now we add initial VLA support itself.
    
    Most of the changes are taken from the original codegen, so there is
    nothing to be scary of)
    
    I added just one test, and basically that's all we can test right now.
    Later, I will add more, from the original codegen tests.
    gitoleg committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    61fab7a View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    57cc970 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    5fa4171 View commit details
    Browse the repository at this point in the history
  8. [CIR][CIRGen] Handle __extension__ keyword (llvm#421)

    Support \_\_extension\_\_ keyword in CIRGen
    YazZz1k committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    f308835 View commit details
    Browse the repository at this point in the history
  9. [CIR][CIRGen] Add missing case to 'isNullValue' (llvm#433)

    Support for BoolAttr in isNullValue
    YazZz1k committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    257a5b0 View commit details
    Browse the repository at this point in the history

Commits on Feb 2, 2024

  1. [CIR][CIRGen] Support for section atttribute (llvm#422)

    This PR adds support for section("$name") attribute
    YazZz1k committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    d601e55 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen][Bugfix] Fix bool zero initialization (llvm#411)

    Support missing zero initialization of Bools
    YazZz1k committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    749af65 View commit details
    Browse the repository at this point in the history
  3. [CIR][Lowering] Support conversion of cir.zero to dense consts (llvm#413

    )
    
    Compiling the given c-code
    
    ```
    void foo() { 
      int      i [2][1] = { { 1 }, { 0 } };
      long int li[2][1] = { { 1 }, { 0 } };
      float    fl[2][1] = { { 1 }, { 0 } };
      double   d [2][1] = { { 1 }, { 0 } };
    }
    ```
    
    leads to compilation error
    
    ```
    unknown element in ConstArrayAttr
    UNREACHABLE executed at /home/huawei/cir/repo/van/llvm-project/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp:951!
    ```
    
    PR implements conversion the cir.zero attr to dense constant and fixed
    this error.
    YazZz1k committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    7bc8339 View commit details
    Browse the repository at this point in the history
  4. [CIR][CodeGen] Initial support for dynamic_cast (llvm#426)

    This PR introduces CIR CodeGen support for `dynamic_cast`.
    
    The full feature set of `dynamic_cast` is not fully implemented in this
    PR as it's already pretty large. This PR only include support for
    downcasting and sidecasting a pointer or reference. `dynamic_cast<void
    *>` is not yet implemented.
    Lancern committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    00b21e0 View commit details
    Browse the repository at this point in the history
  5. [CIR][CIRGen] Add codegen for branch prediction info builtins (llvm#439)

    Initial support for the following builtins:
    ```
    __builtin_expect
    __builtin_expect_with_probability
    __builtin_unpredictable
    ```
    This PR supports codegen for this builtins on "-O0" compilation
    pipeline.
    YazZz1k committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    c17e4e0 View commit details
    Browse the repository at this point in the history
  6. [CIR][CIRGen] Handle ternary op inside if cond (llvm#440)

    Support for ConditionalOperator inside the if condition stmt
    YazZz1k committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    18b757d View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    ba1f118 View commit details
    Browse the repository at this point in the history
  8. [CIR][CIRGen] Support dynamic_cast to void ptr (llvm#442)

    This patch adds CIRGen for downcasting a pointer to the complete object
    through `dynamic_cast<void *>`.
    
    Together with llvm#426 , the full functionality of `dynamic_cast` should be
    supported in CIRGen after this PR merges.
    Lancern committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    4b46643 View commit details
    Browse the repository at this point in the history
  9. [CIR][CodeGen][Lowering] Supports arrays with trailing zeros (llvm#393)

    This PR adds support for constant arrays with trailing zeros.
    
    The original `CodeGen` does the following: once a constant array contain
    trailing zeros, a struct with two members is generated: initialized
    elements and `zeroinitializer` for the remaining part. And depending on
    some conditions, `memset` or `memcpy` are emitted. In the latter case a
    global const array is created.
    Well, we may go this way, but it requires us to implement
    [features](https://github.com/llvm/clangir/blob/main/clang/lib/CIR/CodeGen/CIRGenDecl.cpp#L182)
    that are not implemented yet.
    
    Another option is to add one more parameter to the `constArrayAttr` and
    utilize it during the lowering. So far I chose this way, but if you have
    any doubts, we can discuss here. So we just emit constant array as
    usually and once there are trailing zeros, lower this arrray (i.e. an
    attribute) as a value.
    
    I added a couple of tests and will add more, once we agree on the
    approach. So far I marked the PR as a draft one.
    gitoleg committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    5dcfa7c View commit details
    Browse the repository at this point in the history
  10. [CIR][LibOpt] Extend std::find optimization to all calls with raw poi…

    …nters (llvm#400)
    
    This also adds a missing check whether the pointer returned from
    `memchr` is null and changes the result to `last` in that case.
    philnik777 committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    4449a78 View commit details
    Browse the repository at this point in the history

Commits on Feb 3, 2024

  1. Configuration menu
    Copy the full SHA
    15d3254 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Implement "if consteval" code generation (llvm#446)

    Emit the false-branch of the consteval if statement, if any.
    keryell committed Feb 3, 2024
    Configuration menu
    Copy the full SHA
    6a12086 View commit details
    Browse the repository at this point in the history

Commits on Feb 4, 2024

  1. [CIR] Allow mlir::UnknownLoc in function op (llvm#448)

    Originally, the location associated with a function is checked to be an
    `mlir::FileLineColLoc` before the function is lowered to an LLVMIR
    FuncOp. However, runtime function declarations do not have such
    locations. This patch further allows `mlir::UnknownLoc` to be associated
    with a function.
    Lancern committed Feb 4, 2024
    Configuration menu
    Copy the full SHA
    332095f View commit details
    Browse the repository at this point in the history

Commits on Feb 5, 2024

  1. [CIR][CodeGen] Const structs with bitfields (llvm#412)

    This PR adds a support for const structs with bitfields. 
    Now only global structs are supported, the support of the local ones can
    be added more or less easily - there is one ugly thing need to be done
    though)
    
    So .. what is all about.  
    First of all - as usually, I'm sorry for the big PR. But it's hard to
    break it down to peaces. The good news is that in the same time it's a
    copy-pasta from the original codegen, no surprises here. Basically, the
    most hard place to read is `ConstantAggregateBuilder::addBits` copied
    with minimum of changes.
    
    The main problem - and frankly speaking I have no idea why it's done
    this way in the original codegen - is that the data layout is different
    for such structures, I mean literally another type is used. For
    instance, the code:
    ```
    struct T {
      int X : 15;
      int Y : 6;
      unsigned Z : 9;
      int W;
    };
    
    struct T GV = { 1, 5, 256, -1};
    ```
    is represented in LLVM IR (with no CIR enabled) as:
    
    ```
    %struct.T = type { i32, i32 }
    %struct.Inner = type { i8, i32 }
    
    @gv = dso_local global { i8, i8, i8, i8, i32 } ...
    ```
    i.e. the global var `GV` is looks like a struct of single bytes (up to
    the last field, which is not a btfield).
    And my guess is that we want to have the same behavior in CIR. So we do.
    
    The main problem is that we have to treat the same data differently -
    and this is why one additional `bitcast` is needed when we create a
    global var. Actually, there was a comment there - and I really wonder
    where it came from. But anyways, I don't really like this and don't see
    any good workaround here. Well, maybe we may add a kind of map in order
    to store the correspondence between types and do a bitcast more wisely.
    The same is true for the const structs with bitfields defined locally.
    gitoleg committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    fdf178a View commit details
    Browse the repository at this point in the history
  2. [CIR][Lowering][Bugfix] Fix lowering of bool_to_int cast (llvm#450)

    The minimal bug repro:
    ```
    #include <stdbool.h>
    #include <stdint.h>
    void bar() {
      bool x = true;
      uint8_t y = (uint8_t)x;
    }
    ```
    Fails on verification stage:
    ```
    loc("repro.c":5:24): error: integer width of the output type is smaller or equal to the integer width of the input type
    fatal error: error in backend: The pass manager failed to lower CIR to LLVMIR dialect!
    ```
    The problem is that in some cases lowering from CIR emits the invalid
    zext operation. PR fixes this issue by emitting the llvm.bitcast instead
    of llvm.zext in such cases.
    YazZz1k committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    7808d59 View commit details
    Browse the repository at this point in the history

Commits on Feb 6, 2024

  1. Configuration menu
    Copy the full SHA
    9bc6b59 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    0fdd775 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Add suppport for local typedefs (llvm#451)

    The change is taken from original codegen.
    YazZz1k committed Feb 6, 2024
    Configuration menu
    Copy the full SHA
    cf22b71 View commit details
    Browse the repository at this point in the history
  4. [CIR][CIRGen][BugFix] Fix building of calls (llvm#452)

    The issue is that the CIR codegen assumes that function pointer is
    always result of cir.load op.
    But it isn't true because the funcion pointer may be result of other
    operations (f.e cir.call).
    YazZz1k committed Feb 6, 2024
    Configuration menu
    Copy the full SHA
    f17b5c5 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    dcaecc1 View commit details
    Browse the repository at this point in the history

Commits on Feb 7, 2024

  1. Configuration menu
    Copy the full SHA
    b3c1026 View commit details
    Browse the repository at this point in the history

Commits on Feb 8, 2024

  1. [CIR][CIRGen] Add codegen for global compound literals (llvm#454)

    This PR adds support for global compound literals. 
    The implementation is almost the same as in original codegen. But the
    original codegen can reuse the value of emitted compound literal global
    variable in case then the init expression of new variable and this
    variable are the same.
    It's easy to implement this feature. But I can't find any test-case then
    this feature will be applied. So I decided to ignore this optimization
    opportunity to avoid mistakes.
    YazZz1k committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    db2e245 View commit details
    Browse the repository at this point in the history
  2. [CIR][CodeGen] VLA support next step (llvm#453)

    Here is the next step in VLA support.
    Basically, these changes handle different expressions, like `int
    (*a[5])[n]` or `sizeof(a[n])`.
    
    I took tests from the original `codegen` - they don't check anything,
    just verify we don't fail.
    
    There is still an issue with a proper cleanup - there are cases when
    `stack_save` doesn't dominate a corresponded `stack_restore`. For
    example in the next example:
    
    ```
    void test(unsigned x) {
      while (1) {
        char a[x];
        if (x > 5) 
          break;
        ++x;
      }
    }
    ```
    Look like `break` here doesn't lead to `stack_restore`. But I would say
    this is less related to VLA, though probably I need to fix this as well.
    gitoleg committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    ed08d6f View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen][Bugfix] Emit valid type for evaluated const (llvm#456)

    This PR fixes the issue connected with folding a simple boolean
    expresion pattern (f.e. `0 && RHS = 0`).
    The problem is that the scalar expression emitter always creates a
    `cir.bool` attribute as a result of expression. But in some cases the
    result expression should be a `cir.int` attr.
    YazZz1k committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    5c2afc3 View commit details
    Browse the repository at this point in the history

Commits on Feb 9, 2024

  1. Configuration menu
    Copy the full SHA
    eaf965e View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Support for local const arrays (llvm#458)

    The change is taken from the original llvm codegen.
    YazZz1k committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    af78f2e View commit details
    Browse the repository at this point in the history

Commits on Feb 10, 2024

  1. [CIR][CIRGen][NFC] Relax asserts for using decls and namespace alias

    Originally those are only used for debug info generation, so get a bit more
    specific on what's missing here.
    bcardosolopes committed Feb 10, 2024
    Configuration menu
    Copy the full SHA
    9d245ac View commit details
    Browse the repository at this point in the history

Commits on Feb 12, 2024

  1. [CIR][CIRGen] Fix in replacing of no_proto func (llvm#460)

    When replacing the no-proto functions with it's real definition, codegen
    assumes that only `cir.call` operation may use the replaced function.
    Such behaviour leads to compilation error because of the
    `cir.get_global` op can also use the function to get pointer to
    function.
    This PR adds handle the case with `cir.get_global` operation and fixes
    the issue.
    YazZz1k committed Feb 12, 2024
    Configuration menu
    Copy the full SHA
    72beb2c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    db95ea7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    89c4579 View commit details
    Browse the repository at this point in the history

Commits on Feb 13, 2024

  1. [CIR][Lowering] add lowering of bool attribute (llvm#461)

    This PR adds missing case to lowerCirAttrAsValue.
    YazZz1k committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    d39eb48 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen][Exceptions] Prep work for using cir.try_call outside ci…

    …r.try
    
    The final destination here is to support cir.try_calls that are not within a
    `try {}` statement in C++.  This only affect untested paths that will
    assert a bit later than before, testcase coming soon.
    bcardosolopes committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    a2b7b65 View commit details
    Browse the repository at this point in the history

Commits on Feb 14, 2024

  1. [CIR][CodeGen] Locally inited structures with bitfields (llvm#463)

    The second part of the job started in llvm#412 , now about local structures.
    
    As it was mentioned previously, sometimes the layout for structures with
    bit fields inited with constants differ from the originally created in
    `CIRRecordLayoutBuilder` and it cause `storeOp` verification fail due to
    different structure type was used to allocation.
    This PR fix it.
    An example:
    ```
    typedef struct {
      int a : 4;
      int b : 5;
      int c;
    } D;
    
    void bar () {
      D d = {1,2,3};  
    }
    ```
    
    Well, I can't say I'm proud of these changes - it seems like a type
    safety violation, but looks like it's the best we can do here.
    
    The original codegen doesn't have this problem at all, there is just a
    `memcpy` there, I provide LLVM IR just for reference:
    
    ```
    %struct.D = type { i16, i32 }
    
    @__const.bar.d = private unnamed_addr constant { i8, i8, i32 } { i8 33, i8 0, i32 3 }, align 4
    
    ; Function Attrs: noinline nounwind optnone uwtable
    define dso_local void @bar() #0 {
    entry:
      %d = alloca %struct.D, align 4
      call void @llvm.memcpy.p0.p0.i64(ptr align 4 %d, ptr align 4 @__const.bar.d, i64 8, i1 false)
      ret void
    }
    ```
    gitoleg committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    52cdf6c View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Introduce cir.unreachable operation (llvm#447)

    In llvm#426 we confirmed that CIR needs a `cir.unreachable` operation to
    mark unreachable program points
    [(discussion)](llvm#426 (comment)).
    This PR adds it.
    Lancern committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    76bb766 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Add missing case to VisitMemberExpr (llvm#464)

    This PR adds support for evaluating constants in member exprs.
    The change is taken from original codegen.
    YazZz1k committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    6697d0f View commit details
    Browse the repository at this point in the history

Commits on Feb 15, 2024

  1. [CIR][CIRGen][Exceptions] Add unwind attribute

    - Add it to functions but not yet on calls.
    - Add more skeleton for tagging function attributes.
    - Testcases
    
    One more incremental step towards cir.try_call outside cir.try scopes.
    bcardosolopes committed Feb 15, 2024
    Configuration menu
    Copy the full SHA
    3d83982 View commit details
    Browse the repository at this point in the history
  2. [CIR][CodeGen] Inline assembly: adds operands (llvm#465)

    The next step in inline-assembly support: we add instruction operands!
    Nothing interesting, just some copy-pasta from the `codegen` with some
    sort of simplifications for now.
    
    Well, I'm not sure `functional-type` is the best way to print operands
    though it's used in mlir's `InlineAsmOp`. But anyways, maybe you have a
    better idea.
    
    There are two or three steps ahead, so we are not that far from being
    able to run something!
    gitoleg committed Feb 15, 2024
    Configuration menu
    Copy the full SHA
    824c5ab View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b27ad0f View commit details
    Browse the repository at this point in the history

Commits on Feb 16, 2024

  1. [CIR][CodeGen] Adds clobbers to inline assembly (llvm#469)

    One more tiny step!
    This a tiny PR that adds clobbers to constraint string. 
    Note, that `~{dirflag},~{fpsr},~{flags}` is a
    [X86](https://github.com/llvm/clangir/blob/main/clang/lib/Basic/Targets/X86.h#L281)
    dependent clobbers.
    
    Basically, the next things remain:
    - lowering
    - store the results of the `cir.asm`
    gitoleg committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    b9cd201 View commit details
    Browse the repository at this point in the history

Commits on Feb 24, 2024

  1. Configuration menu
    Copy the full SHA
    4b8f11f View commit details
    Browse the repository at this point in the history

Commits on Mar 13, 2024

  1. suggestions from review

    hardshah committed Mar 13, 2024
    Configuration menu
    Copy the full SHA
    7e93cd3 View commit details
    Browse the repository at this point in the history
  2. [CIR] Added testcase for empty scopes with single yield operation

    Expected behavior is that scope blocks with only a single yield op are cleaned up.
    hardshah committed Mar 13, 2024
    Configuration menu
    Copy the full SHA
    6693cc4 View commit details
    Browse the repository at this point in the history
  3. [CIR] Formatting

    hardshah committed Mar 13, 2024
    Configuration menu
    Copy the full SHA
    a984329 View commit details
    Browse the repository at this point in the history