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] Extend support for floating point attributes #572

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

Commits on Nov 3, 2023

  1. Configuration menu
    Copy the full SHA
    94d428b View commit details
    Browse the repository at this point in the history
  2. [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 Nov 3, 2023
    Configuration menu
    Copy the full SHA
    9cbc015 View commit details
    Browse the repository at this point in the history

Commits on Nov 13, 2023

  1. [CIR][CIRGen] Fix wrong assert

    Silly mistake introduced in previous commit.
    bcardosolopes authored and lanza committed Nov 13, 2023
    Configuration menu
    Copy the full SHA
    21718ce View commit details
    Browse the repository at this point in the history

Commits on Dec 12, 2023

  1. [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 Dec 12, 2023
    Configuration menu
    Copy the full SHA
    099f575 View commit details
    Browse the repository at this point in the history
  2. [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 Dec 12, 2023
    Configuration menu
    Copy the full SHA
    1e0e169 View commit details
    Browse the repository at this point in the history

Commits on Dec 13, 2023

  1. [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 Dec 13, 2023
    Configuration menu
    Copy the full SHA
    dba066d View commit details
    Browse the repository at this point in the history
  2. [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 Dec 13, 2023
    Configuration menu
    Copy the full SHA
    cb09502 View commit details
    Browse the repository at this point in the history

Commits on Dec 14, 2023

  1. [CIR][NFC] Formatting

    lanza committed Dec 14, 2023
    Configuration menu
    Copy the full SHA
    59d6eb9 View commit details
    Browse the repository at this point in the history
  2. [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 Dec 14, 2023
    Configuration menu
    Copy the full SHA
    a8e47cf View commit details
    Browse the repository at this point in the history

Commits on Dec 19, 2023

  1. [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 Dec 19, 2023
    Configuration menu
    Copy the full SHA
    bc1a644 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    5fed9bd View commit details
    Browse the repository at this point in the history
  3. [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 Dec 19, 2023
    Configuration menu
    Copy the full SHA
    d58857d View commit details
    Browse the repository at this point in the history

Commits on Dec 20, 2023

  1. [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 Dec 20, 2023
    Configuration menu
    Copy the full SHA
    15f763b View commit details
    Browse the repository at this point in the history
  2. [CIR] Add iterator_{begin,end} ops

    Only a skeleton for incremental work.
    bcardosolopes authored and lanza committed Dec 20, 2023
    Configuration menu
    Copy the full SHA
    abcf931 View commit details
    Browse the repository at this point in the history
  3. [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 Dec 20, 2023
    Configuration menu
    Copy the full SHA
    ee41cbd View commit details
    Browse the repository at this point in the history

Commits on Dec 21, 2023

  1. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    073a014 View commit details
    Browse the repository at this point in the history
  2. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    be3f6f7 View commit details
    Browse the repository at this point in the history
  3. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    ffd5ae3 View commit details
    Browse the repository at this point in the history
  4. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    6c4bf4c View commit details
    Browse the repository at this point in the history
  5. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    1ef7eab View commit details
    Browse the repository at this point in the history
  6. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    d5b3cc1 View commit details
    Browse the repository at this point in the history
  7. [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 Dec 21, 2023
    Configuration menu
    Copy the full SHA
    8fb3356 View commit details
    Browse the repository at this point in the history

Commits on Dec 22, 2023

  1. [CIR] Cleanup idiom-recognizer and lib-opt options

    This was a bit half backed, give it some love.
    bcardosolopes authored and lanza committed Dec 22, 2023
    Configuration menu
    Copy the full SHA
    28bf4ec View commit details
    Browse the repository at this point in the history
  2. [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 Dec 22, 2023
    Configuration menu
    Copy the full SHA
    2fdc25b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    1139cfe View commit details
    Browse the repository at this point in the history

Commits on Dec 26, 2023

  1. Revert "[mlir][llvm] Fixes CallOp builder for the case of indirect call"

    This reverts commit bbaa147.
    gitoleg authored and lanza committed Dec 26, 2023
    Configuration menu
    Copy the full SHA
    8d37db3 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    67da9e6 View commit details
    Browse the repository at this point in the history

Commits on Jan 4, 2024

  1. [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 4, 2024
    Configuration menu
    Copy the full SHA
    cb185ad View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7d4101a View commit details
    Browse the repository at this point in the history
  3. [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 4, 2024
    Configuration menu
    Copy the full SHA
    f88ee31 View commit details
    Browse the repository at this point in the history
  4. [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 4, 2024
    Configuration menu
    Copy the full SHA
    403ae40 View commit details
    Browse the repository at this point in the history
  5. [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 4, 2024
    Configuration menu
    Copy the full SHA
    b21e81e View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    ead25fe View commit details
    Browse the repository at this point in the history
  7. [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 4, 2024
    Configuration menu
    Copy the full SHA
    be13b81 View commit details
    Browse the repository at this point in the history
  8. [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 4, 2024
    Configuration menu
    Copy the full SHA
    f387e1a View commit details
    Browse the repository at this point in the history
  9. [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 4, 2024
    Configuration menu
    Copy the full SHA
    2bde4fe View commit details
    Browse the repository at this point in the history

Commits on Jan 9, 2024

  1. [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 9, 2024
    Configuration menu
    Copy the full SHA
    6a0e742 View commit details
    Browse the repository at this point in the history
  2. [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 9, 2024
    Configuration menu
    Copy the full SHA
    1d442f6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0affd8d View commit details
    Browse the repository at this point in the history
  4. [CIR][Transforms][NFC] Refactor MergeCleanups pass (llvm#384)

    Breaks the pass into smaller more manageable rewrites.
    sitio-couto authored and lanza committed Jan 9, 2024
    Configuration menu
    Copy the full SHA
    3aeb3e0 View commit details
    Browse the repository at this point in the history

Commits on Jan 10, 2024

  1. Configuration menu
    Copy the full SHA
    006dfd0 View commit details
    Browse the repository at this point in the history
  2. [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 10, 2024
    Configuration menu
    Copy the full SHA
    67859c4 View commit details
    Browse the repository at this point in the history
  3. [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 10, 2024
    Configuration menu
    Copy the full SHA
    58ccd20 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    8fa0bbb View commit details
    Browse the repository at this point in the history
  5. [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 10, 2024
    Configuration menu
    Copy the full SHA
    ada6175 View commit details
    Browse the repository at this point in the history
  6. [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 10, 2024
    Configuration menu
    Copy the full SHA
    d744421 View commit details
    Browse the repository at this point in the history
  7. [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 10, 2024
    Configuration menu
    Copy the full SHA
    50d414a View commit details
    Browse the repository at this point in the history

Commits on Jan 11, 2024

  1. [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 11, 2024
    Configuration menu
    Copy the full SHA
    fbb25ae View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b0dd640 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    439217e View commit details
    Browse the repository at this point in the history

Commits on Jan 12, 2024

  1. Configuration menu
    Copy the full SHA
    7463d87 View commit details
    Browse the repository at this point in the history
  2. [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 12, 2024
    Configuration menu
    Copy the full SHA
    d3e07d2 View commit details
    Browse the repository at this point in the history

Commits on Jan 16, 2024

  1. [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 16, 2024
    Configuration menu
    Copy the full SHA
    2d58e58 View commit details
    Browse the repository at this point in the history
  2. [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 16, 2024
    Configuration menu
    Copy the full SHA
    b91b91c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    11024a5 View commit details
    Browse the repository at this point in the history
  4. [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 16, 2024
    Configuration menu
    Copy the full SHA
    e881544 View commit details
    Browse the repository at this point in the history
  5. [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 16, 2024
    Configuration menu
    Copy the full SHA
    5a6fe55 View commit details
    Browse the repository at this point in the history
  6. [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 16, 2024
    Configuration menu
    Copy the full SHA
    9989230 View commit details
    Browse the repository at this point in the history
  7. [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 16, 2024
    Configuration menu
    Copy the full SHA
    65880d7 View commit details
    Browse the repository at this point in the history
  8. [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 16, 2024
    Configuration menu
    Copy the full SHA
    2f48e4a View commit details
    Browse the repository at this point in the history
  9. [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 16, 2024
    Configuration menu
    Copy the full SHA
    1ee5f18 View commit details
    Browse the repository at this point in the history
  10. [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 16, 2024
    Configuration menu
    Copy the full SHA
    92cceb7 View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2024

  1. [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 17, 2024
    Configuration menu
    Copy the full SHA
    1273f07 View commit details
    Browse the repository at this point in the history
  2. [CIR] TryCallOp: improve printing

    bcardosolopes authored and lanza committed Jan 17, 2024
    Configuration menu
    Copy the full SHA
    d98b9f0 View commit details
    Browse the repository at this point in the history

Commits on Jan 18, 2024

  1. [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 18, 2024
    Configuration menu
    Copy the full SHA
    0d91f68 View commit details
    Browse the repository at this point in the history
  2. [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 18, 2024
    Configuration menu
    Copy the full SHA
    bcfacd1 View commit details
    Browse the repository at this point in the history
  3. [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 18, 2024
    Configuration menu
    Copy the full SHA
    4aa8ff9 View commit details
    Browse the repository at this point in the history

Commits on Jan 19, 2024

  1. [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 19, 2024
    Configuration menu
    Copy the full SHA
    7a4e5c3 View commit details
    Browse the repository at this point in the history

Commits on Jan 22, 2024

  1. [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 22, 2024
    Configuration menu
    Copy the full SHA
    c003cb3 View commit details
    Browse the repository at this point in the history
  2. [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 22, 2024
    Configuration menu
    Copy the full SHA
    8e6cad9 View commit details
    Browse the repository at this point in the history
  3. [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 22, 2024
    Configuration menu
    Copy the full SHA
    b41ff5f View commit details
    Browse the repository at this point in the history
  4. [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 22, 2024
    Configuration menu
    Copy the full SHA
    979ea99 View commit details
    Browse the repository at this point in the history
  5. [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 22, 2024
    Configuration menu
    Copy the full SHA
    4541cfa View commit details
    Browse the repository at this point in the history
  6. [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 22, 2024
    Configuration menu
    Copy the full SHA
    7bd9fe3 View commit details
    Browse the repository at this point in the history

Commits on Jan 23, 2024

  1. [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 23, 2024
    Configuration menu
    Copy the full SHA
    bc1b7c9 View commit details
    Browse the repository at this point in the history

Commits on Jan 25, 2024

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

Commits on Jan 26, 2024

  1. [CIR] Remove LLVM_ENABLE_PROJECTS support

    ghstack-source-id: 855519648a4bf2dced501f96e6de1b9b164d85ad
    Pull Request resolved: llvm#424
    lanza committed Jan 26, 2024
    Configuration menu
    Copy the full SHA
    3cf377a View commit details
    Browse the repository at this point in the history

Commits on Jan 27, 2024

  1. [CIR] Make MLIRCIR depend on MLIRCIRInterfaces

    This is currently missing and Debug builds are failing without it.
    lanza committed Jan 27, 2024
    Configuration menu
    Copy the full SHA
    e4f7839 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1de9a22 View commit details
    Browse the repository at this point in the history

Commits on Jan 29, 2024

  1. [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
    8d26c92 View commit details
    Browse the repository at this point in the history

Commits on Jan 30, 2024

  1. [CIR][CIRGen][Exceptions] Use cir.try instead of cir.scope

    One more step towards completing try/catch.
    bcardosolopes authored and lanza committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    1cd5a4b View commit details
    Browse the repository at this point in the history
  2. [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 authored and lanza committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    d1d7b19 View commit details
    Browse the repository at this point in the history
  3. [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 authored and lanza committed Jan 30, 2024
    Configuration menu
    Copy the full SHA
    1390496 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    fae636d 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    1da7e33 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    000f9f7 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    e1ad7ee 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    3f9153d View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    a602024 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    c5e3476 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    eced6fa 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 authored and lanza committed Jan 31, 2024
    Configuration menu
    Copy the full SHA
    efb9922 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    87c4338 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    765e5dc 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    58b5474 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    7b4745e 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    323e0c1 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    615a367 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    a010209 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    c35b579 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    d54e041 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 authored and lanza committed Feb 2, 2024
    Configuration menu
    Copy the full SHA
    e7e05a8 View commit details
    Browse the repository at this point in the history

Commits on Feb 3, 2024

  1. [CIR][CIRGen] Implement "if consteval" code generation (llvm#446)

    Emit the false-branch of the consteval if statement, if any.
    keryell authored and lanza committed Feb 3, 2024
    Configuration menu
    Copy the full SHA
    6094902 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 authored and lanza committed Feb 4, 2024
    Configuration menu
    Copy the full SHA
    da3343a 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 authored and lanza committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    38bd933 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 authored and lanza committed Feb 5, 2024
    Configuration menu
    Copy the full SHA
    113b787 View commit details
    Browse the repository at this point in the history

Commits on Feb 6, 2024

  1. Configuration menu
    Copy the full SHA
    cb53cf8 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    671ffc7 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 authored and lanza committed Feb 6, 2024
    Configuration menu
    Copy the full SHA
    72e9f23 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 authored and lanza committed Feb 6, 2024
    Configuration menu
    Copy the full SHA
    013a653 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    e95a5c4 View commit details
    Browse the repository at this point in the history

Commits on Feb 7, 2024

  1. Configuration menu
    Copy the full SHA
    c3e6388 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 authored and lanza committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    4f89aa7 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 authored and lanza committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    6c29cd4 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 authored and lanza committed Feb 8, 2024
    Configuration menu
    Copy the full SHA
    06da08a View commit details
    Browse the repository at this point in the history

Commits on Feb 9, 2024

  1. [CIR][CIRGen][Exceptions][NFC] Add skeleton for some missing function…

    … start/end functionality
    bcardosolopes authored and lanza committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    101c4c0 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 authored and lanza committed Feb 9, 2024
    Configuration menu
    Copy the full SHA
    b63a943 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 authored and lanza committed Feb 10, 2024
    Configuration menu
    Copy the full SHA
    ad2de47 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 authored and lanza committed Feb 12, 2024
    Configuration menu
    Copy the full SHA
    877a15e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c976e4b View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d7f09ca 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 authored and lanza committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    a1d0b22 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 authored and lanza committed Feb 13, 2024
    Configuration menu
    Copy the full SHA
    49bcdd2 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 authored and lanza committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    6d83a86 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 authored and lanza committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    d3b91b5 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 authored and lanza committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    19350cf View commit details
    Browse the repository at this point in the history
  4. [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 authored and lanza committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    e3d14fd View commit details
    Browse the repository at this point in the history

Commits on Feb 15, 2024

  1. [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 authored and lanza committed Feb 15, 2024
    Configuration menu
    Copy the full SHA
    e0dc80f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b5e684e 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 authored and lanza committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    da2e461 View commit details
    Browse the repository at this point in the history

Commits on Feb 17, 2024

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

Commits on Feb 20, 2024

  1. [CIR][Lowering] Handle unsupported types for CIR-MLIR type conversion (

    …llvm#471)
    
    * Pointers to CIR types that do not have converters (e.g. cir.struct)
    cause crashes due to passing null types to construct mlir::MemRefType.
    
    * This commit adds checks for pointers and alloca lowering to fail
    gracefully if the underlying type can not be converted.
    mrsoliman authored and lanza committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    321ca2b View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Support for zero initialization of arrays (llvm#468)

    As in original codegen this PR uses the do-while loop to initialize the
    array elements with the filler expression.
    But unlike the original codegen we allocates the temporary variable on
    stack. Allocation is necessary to store the pointer to the first
    uniinitialized element.
    YazZz1k authored and lanza committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    e846fd2 View commit details
    Browse the repository at this point in the history
  3. [CIR][CodeGen][Bugfix] Fix storage size for bitfields (llvm#462)

    This PR fixes a bug caused by `IntType` size limitations in CIR (and by
    some magic of numbers as well).
    
    As you know, we need to create a storage for bit fields that usually
    contain several of them. There next code fails with `IntType` size check
    which exceeds 64 bits.
    ```
    typedef struct {
        uint8_t a;
        uint8_t b;
        uint8_t c;
    
        int d: 2;
        int e: 2;
        int f: 4;
        int g: 25;
        int h: 3;
        int i: 4;
        int j: 3;
        int k: 8;
        int l: 14;
    } D;
    
    void foo() {
        D d;
    }
    ```
    Note, if we remove first three fields (or even one) everything will be
    fine even without this fix, because
    [this](https://github.com/llvm/clangir/blob/main/clang/lib/CIR/CodeGen/CIRRecordLayoutBuilder.cpp#L553)
    check won't pass. The bug is kind of hard to reproduce and I would say
    it's a rare case. I mean the problem is not only in the number of bit
    fields that form together something bigger than 64 bits.
    
    ### Several details
    
    Well, while iterating over the bit fields in some struct type, we need
    to stop accumulating bit fields in one storage and start to do the same
    in another one. Basically, we operate with `Tail` and `StartBitOffset`
    where the former is an offset of the next field. And once `Tail -
    StartBitOffset >= 64` we say that it's not possible to create a storage
    of such size due to `IntType` size limitation. Sounds reasonable.
    
    But it can be a case when we can not afford to take the next field
    because its `Tail` in turn leads to a storage of the size bigger then
    64. Thus, we want to check it as well. From the implementation point of
    view I added one more check to the `IsBetterAsSingleFieldRun` in order
    to have all these checks for size in a single place. And the check I
    mentioned before were saving us from hitting this issue.
    gitoleg authored and lanza committed Feb 20, 2024
    Configuration menu
    Copy the full SHA
    72eccae View commit details
    Browse the repository at this point in the history

Commits on Feb 21, 2024

  1. [CIR] introduce CIR floating-point types (llvm#385)

    This PR adds a dedicated `cir.float` type for representing
    floating-point types. There are several issues linked to this PR: llvm#5,
    llvm#78, and llvm#90.
    Lancern authored and lanza committed Feb 21, 2024
    Configuration menu
    Copy the full SHA
    b82fdb0 View commit details
    Browse the repository at this point in the history

Commits on Feb 22, 2024

  1. [CIR][Codegen] Fix bitfields unary and binary ops (llvm#477)

    This PR fixes a couple of  NIY features for bit fields.
    
    Basically, such expressions with bit fields `x->a++` and `x->a |= 42`
    are supported now.
    
    The main problem is `UnOp` verification - now it can be defined both by
    `loadOp` and by `GetBitfieldOp` or even by `CastOp`. So shame on me, I
    removed a test from `invalid.cir`
    gitoleg authored and lanza committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    624f2be View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Fix calling a function through a function pointer (llvm…

    …#467)
    
    CIR codegen always casts the no-proto function pointer to `FuncOp`. But
    the function pointer may be result of cir operations (f.e. `cir.load`).
    As a result in such cases the function pointer sets to `nullptr`. That
    leads to compilation error.
    So this PR removes the unecessary cast to 'FuncOp' and resolves the
    issue.
    YazZz1k authored and lanza committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    876101b View commit details
    Browse the repository at this point in the history
  3. [CIR] initial support for pointer-to-data-member type (llvm#401)

    This patch adds initial support for the pointer-to-data-member type.
    Specifically, this commit includes:
    
    - New ops, types, and attributes:
    - CodeGen for pointer-to-data-member types and values
      - Lower C++ pointer-to-member type
      - Lower C++ expression `&C::D`
      - Lower C++ expression `c.*p` and `c->*p`
    
    This patch only includes an initial support. The following stuff related
    to pointer-to-member types are not supported yet:
    
    - Pointer to member function;
    - Conversion from `T Base::*` to `T Derived::*`;
    - LLVMIR lowering.
    Lancern authored and lanza committed Feb 22, 2024
    Configuration menu
    Copy the full SHA
    c2bca4a View commit details
    Browse the repository at this point in the history

Commits on Feb 29, 2024

  1. [CIR][NFC] Add unimplemented feature guard for dialect code (llvm#481)

    As discussed in pull llvm#401 , The present `UnimplementedFeature` class is
    made for the CIRGen submodule and we need similar facilities for code
    under `clang/lib/CIR/Dialect/IR`. This NFC patch adds a new
    `CIRDialectUnimplementedFeature` class that provides unimplemented
    feature guards for CIR dialect code.
    Lancern authored and lanza committed Feb 29, 2024
    Configuration menu
    Copy the full SHA
    85a48c7 View commit details
    Browse the repository at this point in the history
  2. [CIR][Lowering] More cir.asm lowering (llvm#472)

    This PR adds lowering for `cir.asm`.
    
    Also, two flags were added to the `cir.asm` : `hasSideEffects` and
    `isStackAligned` in order to match with the llvm dialect.
    
    Also, I added several simple tests for lowering.
    
    I'm not sure but most likely the next PR will be the last one in this
    story about assembly support )
    gitoleg authored and lanza committed Feb 29, 2024
    Configuration menu
    Copy the full SHA
    9a69667 View commit details
    Browse the repository at this point in the history

Commits on Mar 5, 2024

  1. [CIR][CIRGen] Emit cir.unreachable on implicit returns (llvm#486)

    This patch changes the emission of implicit returns from functions whose
    return type is not `void`. Instead of emitting `cir.return`, this PR
    aligns to the original clang CodeGen and emits a `cir.unreachable`
    operation.
    
    Related issue: llvm#457 .
    Lancern authored and lanza committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    0ba4f5a View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Add support for builtin bit operations (llvm#474)

    This PR adds CIRGen support for the following built-in bit operations:
    
      - `__builtin_ffs{,l,ll,g}`
      - `__builtin_clz{,l,ll,g}`
      - `__builtin_ctz{,l,ll,g}`
      - `__builtin_clrsb{,l,ll,g}`
      - `__builtin_popcount{,l,ll,g}`
      - `__builtin_parity{,l,ll,g}`
    
    This PR adds a new operation, `cir.bits`, to represent such bit
    operations on the input integers. LLVMIR lowering support is not
    included in this PR.
    
    > [!NOTE]
    > As a side note, C++20 adds the `<bit>` header which includes some bit
    operation functions with similar functionalities to the built-in
    functions mentioned above. However, these standard library functions
    have slightly different semantics than the built-in ones and this PR
    does not include support for these standard library functions. Support
    for these functions may be added later, or amended into this PR if the
    reviewers request so.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    116a86d View commit details
    Browse the repository at this point in the history
  3. [CIR] Vector types - part 4 (llvm#490)

    This is part 4 of implementing vector types and vector operations in
    ClangIR, issue llvm#284. This change has three small additions.
    
    Implement a "vector splat" conversion, which converts a scalar into
    vector, initializing all the elements of the vector with the scalar.
    
    Implement incomplete initialization of a vector, where the number of
    explicit initializers is less than the number of elements in the vector.
    The rest of the elements are implicitly zero initialized.
    
    Implement conversions between different vector types. The language rules
    require that the two types be the same size (in bytes, not necessarily
    in the number of elements). These conversions are always implemented
    with a bitcast.
    
    The first two changes only required changes to the AST -> ClangIR code
    gen. There are no changes to the ClangIR dialect, so no changes to the
    LLVM lowering were needed.
    
    The third part only required a change to a validation rule. The code to
    implement a vector bitcast was already present. The compiler just needed
    to stop rejecting it as invalid ClangIR.
    dkolsen-pgi authored and lanza committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    19de5fc View commit details
    Browse the repository at this point in the history
  4. [CIR][CIRGen] Support for __builtin_expect (llvm#478)

    This PR adds the new `cir.expect` opcode which is similar to llvm.expect
    intricnsics.
    Codegen of `__builtin_expect` emits `cir.expect` opcode. Then
    `cir.expect` will be lowered to `llvm.expect` intrinsic.
    
    When implementing __builtin_expect I faced with minor issue.
    CIR lowering of `if` often emits the lllvm IR with redundant cast
    instructions. Like this:
    ```
    %0 = call i64 @llvm.expect.i64(i64 %any, i64 1), !dbg !13
    %1 = icmp ne i64 %0, 0
    %2 = zext i1 %0 to i8   // redundant
    %3 = trunc i8 %1 to i1 // redundant
    br i1 %3, label %l1, label %l2
    ```
    But the llvm pass `LowerExpectIntrinsicPass` (that should replace
    `llvm.expect` with branch metadata) performs only simple
    pattern-matching. And it can't handle this zext/trunc intructions. So
    this pass in such cases just removes the `llvm.expect` without updating
    a branch metadata.
    In this reason this PR also avoid emitting the redundant zext/cast
    instruction sequence.
    YazZz1k authored and lanza committed Mar 5, 2024
    Configuration menu
    Copy the full SHA
    9d55d0f View commit details
    Browse the repository at this point in the history

Commits on Mar 6, 2024

  1. [CIR][CIRGen] Partial support for offsetof (llvm#492)

    Support `offset` expression in case when we can evaluate offset
    expression as integer.
    YazZz1k authored and lanza committed Mar 6, 2024
    Configuration menu
    Copy the full SHA
    6191da3 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Support for CStyleCastExprClass in buildCastLValue (llv…

    …m#494)
    
    Change is taken from original llvm codegen
    YazZz1k authored and lanza committed Mar 6, 2024
    Configuration menu
    Copy the full SHA
    2ab8d1e View commit details
    Browse the repository at this point in the history

Commits on Mar 7, 2024

  1. [CIR] Add cir.trap operation (llvm#496)

    This PR adds the `cir.trap` operation, which corresponds to the
    `__builtin_trap` builtin function. When executed, the operation
    terminates the program abnormally in an implementation-defined manner.
    
    This PR also includes CIRGen and LLVM lowering support for the new
    operation.
    Lancern authored and lanza committed Mar 7, 2024
    Configuration menu
    Copy the full SHA
    bfc16da View commit details
    Browse the repository at this point in the history

Commits on Mar 8, 2024

  1. [CIR][FrontendTool] Fix overly conservative compatible flags

    Remove check since paths that aren't related to ClangIR shouldn't be affected
    at all, even if the flag is ON. Also, this conservative error message wasn't
    tested.
    bcardosolopes authored and lanza committed Mar 8, 2024
    Configuration menu
    Copy the full SHA
    e10f9d9 View commit details
    Browse the repository at this point in the history

Commits on Mar 9, 2024

  1. [CIR] Vector ternary operator (llvm#500)

    Implement the vector version of the ternary (`?:`) operator. This is a
    separate MLIR op than the regular `?:` operator because the vector
    version is not short-circuiting and always evaluates all its arguments.
    dkolsen-pgi authored and lanza committed Mar 9, 2024
    Configuration menu
    Copy the full SHA
    62e97a7 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    062b69e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    460cffa View commit details
    Browse the repository at this point in the history

Commits on Mar 11, 2024

  1. [CIR][CIRGen] Emit more delete calls

    bcardosolopes authored and lanza committed Mar 11, 2024
    Configuration menu
    Copy the full SHA
    cc4fddd View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    26e1ad1 View commit details
    Browse the repository at this point in the history

Commits on Mar 12, 2024

  1. [CIR][Lowering] Add LLVMIR lowering support for CIR bit operations (l…

    …lvm#501)
    
    This PR adds the LLVMIR lowering support for CIR bit operations.
    
    For `cir.bit.clz`, `cir.bit.ctz`, and `cir.bit.popcount`, they can be
    lowered directly to LLVM intrinsic calls to `@llvm.ctlz`, `@llvm.cttz`,
    and `@llvm.ctpop`, respectively.
    
    For the other three bit operations, namely `cir.bit.clrsb`,
    `cir.bit.ffs`, and `cir.bit.parity`, they are lowered to a sequence of
    LLVM IR instructions that implements their functionalities. This
    lowering scheme is also used by the original clang CodeGen.
    Lancern authored and lanza committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    1ee9340 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Enable support of bool increment (llvm#493)

    CIRGenFunction::buildFromMemory can handle the `cir.bool` values. So we
    no longer need to emit the `NIY` error here.
    YazZz1k authored and lanza committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    829dd95 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Inline asm: operand attributes (llvm#491)

    This is the next step in inline assembly support and it's more like a
    service PR and mostly dedicated to the in/out argument types.
    
    Also, operand attributes are added and it's the last change in the
    `cir.asm` operation afaik. But I would wait untill the next PR,
    which will contain more examples and maybe will help us to get more
    readable format for the operation.
    Note, that we have to add an attribute for each operand - because the
    lowering of the llvm dialect to LLVM IR iterates over them in the same
    order.
    
    The next PR will be last one (so far) in the series of PRs dedicated to
    the inline assembly support. It will add storing of the results.
    gitoleg authored and lanza committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    d7d62a6 View commit details
    Browse the repository at this point in the history
  4. [CIR] Vector type cleanup and refactoring (llvm#503)

    Three small changes, all cleanup or refactoring in nature.
    
    1. Fix the assemblyFormat for all the vector operations in the ClangIR
    dialect so that vector types appear in ClangIR as `!cir.vector<type x
    n>` instead of as just `<type x n>`. When I first created the vector
    ops, I forgot to use `qualified` as necessary when writing out types.
    This change fixes that. There is no change in behavior, but there is a
    change to the text version of ClangIR, which required changing the
    ClangIR expected results and ClangIR inputs in the tests.
    
    2. Create a new `cir.vec.splat` operation and use that for "vector
    splat", i.e. a conversion from a scalar to a vector. A "vector splat"
    conversion had been implemented with `cir.vec.create` before. This
    change results in different ClangIR and different LLVM IR, which again
    required updating the tests, but no noticeable change in compiler
    behavior.
    
    3. Create an `IntegerVector` type constraint, which requires that the
    given type be a vector whose element type is an integer. It can be any
    integral type, and the vector can be of any size. Use the new type
    constraint in the definition of `cir.vec.ternary`, whose condition
    operand must be an `IntegerVector`. Remove the integral type check from
    `VecTernaryOp::verify`, since doing the check there is now redundant.
    The only possibly visible change is to the text of an error message when
    validation of `cir.vec.ternary` fails. The expected output of a
    validation test was updated with the new message.
    dkolsen-pgi authored and lanza committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    108d233 View commit details
    Browse the repository at this point in the history
  5. [CIR][Codegen][Lowering] Introduce new bitfield layout (llvm#487)

    This PR intends to fix some problems with packed structures support, so
    the llvm#473 will work.
    
    Basically, the main problem for the packed structures support is an
    absence of arbitrary sized integers in CIR. Well, one workaround is to
    use `mlir::IntegerType` for that, but it's kind of wrong way (please
    correct me if I'm wrong). Another way is to introduce this type in CIR.
    So far I suggest this way: instead of arbitrary sized integers we will
    create an array of bytes for bitfield storages whenever they doesn't fit
    into the CIR `IntType`.
    
    Well, the original codegen creates storages with alignment 8 - so it can
    be `i24` storage type for instance. Previously, we just created storages
    that could be represented as CIR `IntType`: 8, 16, 32, 64. And it was
    working before I came up with a necessity to support packed structures.
    At first glance it's not a problem - just add `determinePacked` method
    from the original codegen and that's it. But it turned out that this
    method _infers_ the fact if a structure is packed or not. It doesn't use
    the AST attribute for that as one could think - it works with offsets
    and alignments of fields. Thus, we either need to invent our own way to
    determine packed structures (which is error prone and maybe not doable
    at all) or try to use the existing one. Also, we go closer to the
    original lllvm's data layout in this case.
    
    1) I had to move the lowering details from the `LoweringPrepare` to the
    `LowerToLLVM`, because it's not possible to do a `load` from the array
    of bytes to the integer type - and it's ok in llvm dialect. Thus, all
    the math operations can be expressed without any problems. Basically the
    most of the diff you see is because of the changes in the lowering. The
    remaining part is more or less easy to read.
    2) There are minor changes in `CIRRecordLayoutBuilder` - as described
    above, we use may generate an array of bytes as a storage.
    3) Some cosmetic changes in `CIRGenExpr` - since we don't want to infer
    the storage type again and just use the one stored in the
    `CIRGenBitFieldInfo`.
    4) Helpers are introduced in the lowering - but nothing hard - just
    shifts and logical ops.
    5) I removed `bitfield-ops` test - because now the test cases covered
    there are all in `bitfields.c` and `bitfields.cpp` .
    
    So ... This is still a suggestion, though I believe it's a good one. So
    you are welcome to discuss, suggest another ways to solve the problem
    and etc.
    gitoleg authored and lanza committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    47c2e56 View commit details
    Browse the repository at this point in the history
  6. [CIR][CIRGen] Add support for ctor/dtor based array init/destroy

    Still missing lowering support, which will come next.
    bcardosolopes authored and lanza committed Mar 12, 2024
    Configuration menu
    Copy the full SHA
    65f27ad View commit details
    Browse the repository at this point in the history

Commits on Mar 14, 2024

  1. Configuration menu
    Copy the full SHA
    a7910b8 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    c550e90 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen][NFC] Skeleton for atomics support

    This doesn't change existing functionality, for existing crashes related to
    atomics we just hit asserts a bit further now, but no support added just yet.
    Next set of commits will introduce functionlity with testcases.
    bcardosolopes authored and lanza committed Mar 14, 2024
    Configuration menu
    Copy the full SHA
    15903b6 View commit details
    Browse the repository at this point in the history
  4. [CIR][CIRGen][Atomics][NFC] Skeleton for constant order codegen

    Just like previous commit, add more infra pieces, still NFC since all relevant
    testcases hit asserts, just a bit deeper.
    bcardosolopes authored and lanza committed Mar 14, 2024
    Configuration menu
    Copy the full SHA
    2c680f1 View commit details
    Browse the repository at this point in the history

Commits on Mar 15, 2024

  1. [CIR][Codegen] Initial support for packed structures (llvm#473)

    This PR adds a support for packed structures.
    
    Basically, now both `pragma pack(...)` and
    `__attribute__((aligned(...)))` should work.
    The only problem is that `getAlignment` is not a total one - I fix only
    a couple of issues I faced with - for struct types and arrays.
    gitoleg authored and lanza committed Mar 15, 2024
    Configuration menu
    Copy the full SHA
    90786c8 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Support for initialization of unions. (llvm#495)

    PR adds support for initialization of unions. The change is copy-pasted
    from the original CodeGen.
    YazZz1k authored and lanza committed Mar 15, 2024
    Configuration menu
    Copy the full SHA
    3d86b46 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Support for __builtin_prefetch (llvm#504)

    This PR adds support for `__builtin_prefetch`. CIRGen of this builtin
    emits the new 'cir.prefetch' opcode. Then `cir.prefetch` lowers to
    `llvm.prefetch` intrinsic.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Mar 15, 2024
    Configuration menu
    Copy the full SHA
    7c7c4ff View commit details
    Browse the repository at this point in the history
  4. [CIR] Add MemRead/MemWrite markers to bitfield ops (llvm#507)

    This PR adds MemRead/MemWrite markers to the `GetBitfieldOp` and
    `SetBitfieldOp` (as discussed in llvm#487)
    Also, minor renaming in the `SetBitfieldOp`
    
    ---------
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Mar 15, 2024
    Configuration menu
    Copy the full SHA
    1f8f096 View commit details
    Browse the repository at this point in the history
  5. [CIR][CIRGen] Support for __builtin_constant_p (llvm#506)

    This PR adds support for `__builtin_constant_p`.
    Implementation introduces the new `cr.is_constant` opcode to it during
    the codegeneration of builtin.
    Codegeneration is taken from the original llvm codegen.
    YazZz1k authored and lanza committed Mar 15, 2024
    Configuration menu
    Copy the full SHA
    2a0fcd5 View commit details
    Browse the repository at this point in the history

Commits on Mar 19, 2024

  1. [CIR][CIRGen] Support for C++20 three-way comparison (llvm#485)

    This patch adds CIRGen support for the C++20 three-way comparison
    operator `<=>`. The binary operator is directly lowered to existing CIR
    operations.
    
    Most of the changes are tests.
    Lancern authored and lanza committed Mar 19, 2024
    Configuration menu
    Copy the full SHA
    9fde505 View commit details
    Browse the repository at this point in the history

Commits on Mar 21, 2024

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

Commits on Mar 22, 2024

  1. [CIR][CIRGen] Support for compound literal lvalue (llvm#515)

    This change is taken from the original codegen.
    YazZz1k authored and lanza committed Mar 22, 2024
    Configuration menu
    Copy the full SHA
    fd354e5 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Support for __attribute__((fallthrough)) statement (llv…

    …m#517)
    
    This PR adds handling of AttributedStmt to support fallthrough
    attribute.
    YazZz1k authored and lanza committed Mar 22, 2024
    Configuration menu
    Copy the full SHA
    8d87565 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Add handling __extension__ keyword for lvalue (llvm#519)

    This change is taken from the original codegen
    YazZz1k authored and lanza committed Mar 22, 2024
    Configuration menu
    Copy the full SHA
    c9dd759 View commit details
    Browse the repository at this point in the history

Commits on Apr 2, 2024

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

Commits on Apr 3, 2024

  1. [CIR] Introduce a flattening pass (llvm#516)

    We start our journey towards `goto` support and this is a first step on
    this way.
    
    There are some discussion in llvm#508 and according to the plan we do the
    following here:
    - a new pass called `cir-flatten-cfg` that is a stub now but later will
    be responsible for the regions inlining. The pass works only if
    `-emit-flat-cir` is passed in cmd line. Thus, the clang behavior is not
    changed here from the user's point of view.
    - The pass will be accomplished with `goto` solver later, so we talk
    about several passes that are mandatory for the lowering into `llvm`
    dialect. There are at least two clients of this pass that will be
    affected: `clang` itself and `cir-opt`, so we need a common point for
    them: and `populateCIRFlatteningPasses` and `populateCIRToLLVMPasses`
    guarantee that `CIR` will be in the correct state for all the clients,
    whatever new passes we will add later.
    gitoleg authored and lanza committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    49b609b View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Add support for __atomic_add_fetch

    This introduces CIRGen and LLVM lowering for the first of a bunch
    of these atomic operations, incremental work should generelize the
    current constructs.
    bcardosolopes authored and lanza committed Apr 3, 2024
    Configuration menu
    Copy the full SHA
    e58a597 View commit details
    Browse the repository at this point in the history

Commits on Apr 5, 2024

  1. [CIR] shufflevector and convertvector built-ins (llvm#530)

    Implement `__builtin_shufflevector` and `__builtin_convertvector` in
    ClangIR. This change contributes to the implemention of issue llvm#284.
    
    `__builtin_convertvector` is implemented as a cast. LLVM IR uses the
    same instructions for arithmetic conversions of both individual scalars
    and entire vectors. So ClangIR does the same. The code for handling
    conversions, in both CodeGen and Lowering, is cleaned up to correctly
    handle vector types. To simplify the lowering code and avoid `if
    (type.isa<VectorType>())` statements everywhere, the utility function
    `elementTypeIfVector` was added to `LowerToLLVM.cpp`.
    
    `__builtin_shufflevector` has two forms, only one of which appears to be
    documented.
    
    The documented form, which takes a variable-sized list of integer
    constants for the indices, is implemented with the new ClangIR operation
    `cir.vec.shuffle.ints`. This operation is lowered to the
    `llvm.shufflevector` op.
    
    The undocumented form, which gets the indices from a vector operand, is
    implemented with the new ClangIR operation `cir.vec.shuffle.vec`. LLVM
    IR does not have an instruction for this, so it gets lowered to a long
    series of `llvm.extractelement` and `llvm.insertelement` operations.
    dkolsen-pgi authored and lanza committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    d18777b View commit details
    Browse the repository at this point in the history

Commits on Apr 6, 2024

  1. [CIR] Add support for byteswap intrinsic (llvm#523)

    This PR adds support for the following intrinsic functions:
    - `__builtin_bswap{16, 32, 64}`
    - `_byteswap_{ushort, ulong, uint64}`
    
    This PR adds a new `cir.bswap` operation to represent such an intrinsic
    call. CIRGen and LLVMIR lowering for the new operation is included in
    this PR.
    Lancern authored and lanza committed Apr 6, 2024
    Configuration menu
    Copy the full SHA
    84851f8 View commit details
    Browse the repository at this point in the history
  2. [CIR] GNU vector type cleanup (llvm#531)

    This is the final commit for issue llvm#284. Vector types other than GNU
    vector types will be covered by other yet-to-be-created issues.
    
    Now that GNU vector types (the ones defined via the vector_size
    attribute) are implemented, do a final cleanup of the assertions and
    other checks related to vector types.
    
    Remove `UnimplementedFeature::cirVectorType()`. Deal with the remaining
    calls to that function. When the that is not yet implemented has to do
    with Arm SVE vectors, the assert was changed to
    `UnimplementedFeature::scalableVectors()` instead. The assertion was
    removed in cases where the code correctly handle GNU vector types.
    
    While cleaning up the assertion checks, I noticed that BinOp handling of
    vector types wasn't quite complete. Any special handling for integer or
    floating-point types wasn't happening when the operands were vector
    types. To fix this, split `BinOpInfo::Ty` into two fields, `FullType`
    and `CompType`. `FullType` is the type of the operands. `CompType` is
    normally the same as `FullType`, but is the element type when `FullType`
    is a vector type.
    dkolsen-pgi authored and lanza committed Apr 6, 2024
    Configuration menu
    Copy the full SHA
    4b49152 View commit details
    Browse the repository at this point in the history

Commits on Apr 8, 2024

  1. Configuration menu
    Copy the full SHA
    a853799 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8ba2142 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Add support for __atomic_fetch_binop

    Note this is different from __atomic_binop_fetch. See added docs.
    bcardosolopes authored and lanza committed Apr 8, 2024
    Configuration menu
    Copy the full SHA
    eaea071 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    a5c9aca View commit details
    Browse the repository at this point in the history

Commits on Apr 9, 2024

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

Commits on Apr 10, 2024

  1. [CIR][CIRGen] Add missing CIRGen for generic bit operation builtins (l…

    …lvm#540)
    
    This patch adds the CIRGen for the following builtin functions:
    
    - `__builtin_clzg`;
    - `__builtin_ctzg`;
    - `__builtin_popcountg`.
    
    CIRGen for these three functions are missing in the original PR which
    introduces CIR bit ops.
    Lancern authored and lanza committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    459f6f5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    7804db0 View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Add support for __attribute__((constructor))

    Also add skeleton for upcoming dtor support.
    bcardosolopes authored and lanza committed Apr 10, 2024
    Configuration menu
    Copy the full SHA
    ccd551b View commit details
    Browse the repository at this point in the history

Commits on Apr 11, 2024

  1. Configuration menu
    Copy the full SHA
    06cf3c3 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    17c8db6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    58b8bc7 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    90710ce View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    a0e3c1c View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    91685f8 View commit details
    Browse the repository at this point in the history

Commits on Apr 12, 2024

  1. Configuration menu
    Copy the full SHA
    6233ee0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a1bc344 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    906c314 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    7865351 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    84ebc8c View commit details
    Browse the repository at this point in the history

Commits on Apr 15, 2024

  1. [CIR][Codegen] IfOp flattening (llvm#537)

    This PR perform flattening for `cir::IfOp`
    Basically, we just move the code from `LowerToLLVM.cpp` to
    `FlattenCFG.cpp`.
    There are several important things though I would like to highlight.
    1) Consider the next code from the tests:
    ```
    cir.func @foo(%arg0: !s32i) -> !s32i {
        %4 = cir.cast(int_to_bool, %arg0 : !s32i), !cir.bool
        cir.if %4 {
          %5 = cir.const(#cir.int<1> : !s32i) : !s32i
          cir.return %5 : !s32i
        } else {
          %5 = cir.const(#cir.int<0> : !s32i) : !s32i
          cir.return %5 : !s32i
        }
        cir.return %arg0 : !s32i
      }
    ```
    The last `cir.return` becomes unreachable after flattening and hence is
    not reachable in the lowering. So we got the next error:
    ```
    error: 'cir.return' op expects parent op to be one of 'cir.func, cir.scope, cir.if, cir.switch, cir.do, cir.while, cir.for'
        cir.return %arg0 : !s32i
    ```
    the parent after lowering is `llvm.func`.
    And this is only the beginning - the more operations will be flatten,
    the more similar fails will happen. Thus, I added lowering for the
    unreachable code as well in `LowerToLLVM.cpp`. But may be you have
    another solution in your mind.
    
    2) Please, pay attention on the flattening pass - I'm not that familiar
    with `mlir` builders as you are, so may be I'm doing something wrong.
    The idea was to start flattening from the most nested operations.
    
    3) As you requested in llvm#516, `cir-to-llvm-internal` is renamed to
    `cir-flat-to-llvm`. The only thing remain undone is related to the
    following:
    
    > Since it would be wrong to run cir-flat-to-llvm without running
    cir-flatten-cfg, we should make cir-flat-to-llvm pass to require
    cir-flatten-cfg pass to be run before.
    
    And I'm not sure I know how to do it exactly - is there something
    similar to pass dependencies from LLVM IR?
    
    4) The part of `IfOp` lowering related to elimination of the vain casts
    for condition branch moved directly to the lowering of `BrCondOp` with
    some refactoring and guarding.
    
    5) Just note, that now `cir-opt` is able to dump the flat cir as well:
    `cir-opt -cir-flat-cfg`
    gitoleg authored and lanza committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    440f02e View commit details
    Browse the repository at this point in the history
  2. [CIR] Add initial support for bit-precise integer types (llvm#538)

    This PR adds initial support for the bit-precise integer type
    `_BitInt(N)`. This type goes into the C23 standard, and has already been
    supported by clang since 2020, previously known as `_ExtInt(N)`.
    
    This PR is quite simple and straight-forward. Basically it leverages the
    existing `cir.int` type to represent such types. Previously `cir.int`
    verifies that its width must be a multiple of 8, and this verification
    has been removed in this PR.
    Lancern authored and lanza committed Apr 15, 2024
    Configuration menu
    Copy the full SHA
    12fb4ed View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    7380a63 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    275f0e4 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    267dd72 View commit details
    Browse the repository at this point in the history

Commits on Apr 16, 2024

  1. [CIR][LLVMLowering] Lower cir.objectsize (llvm#545)

    Lowers `cir.objectsize` to `llvm.objectsize`
    ghehg authored and lanza committed Apr 16, 2024
    Configuration menu
    Copy the full SHA
    a53950f View commit details
    Browse the repository at this point in the history

Commits on Apr 17, 2024

  1. [CIR][LLVMLowering] Fix handling of dense array conversions from cons…

    …t arrays
    
    We were lacking handling of trailing zeros for constant arrays.
    bcardosolopes authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    62c6a86 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    2db13d8 View commit details
    Browse the repository at this point in the history
  3. [CIR][CodeGen] Inline assembly: store the results (llvm#512)

    This PR adds storing of the results of inline assembly operation.
    
    This is a **final** step (I hope: ) ) from my side to support inline
    assembly.
    
    There are some features that remains unimplemented, but basic things
    should work now, For example, we can do addition and get the results - I
    explicitly added several tests for that, so you can test them in real.
    For instance, the next program being compiled with CIR should give you 7
    as the result:
    ```
    int add(int x, int y) {
      int a;
      __asm__("addl %[y], %[x]"
          : "=r" (a)
          : [x] "r" (x),
            [y] "r" (y)
          );
    
      return a;
    }
    
    int main() {
      printf("run %d\n", add(3, 4));
      return 0;
    }
    ```
    
    So, the main thing remains is pretty printing. As I said I added several
    examples, and may be it will become more clear how to print better.
    
    Also, I added several tests from original codegen in order to check that
    we don't fail. And I can add some checks there as well when we come to
    better solution on printing.
    gitoleg authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    730ffda View commit details
    Browse the repository at this point in the history
  4. Revert "[CIR][LLVMLowering] Lower cir.objectsize (llvm#545)"

    This reverts commit 87a61f3.
    
    It's deleting code it isn't supposed to touch.
    bcardosolopes authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    8b4c7e0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    5348562 View commit details
    Browse the repository at this point in the history
  6. [CIR][NFC] Fix few compiler warnings

    bcardosolopes authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    043f8dc View commit details
    Browse the repository at this point in the history
  7. [CIR][CodeGen] Flattening for ScopeOp and LoopOpInterface (llvm#546)

    This PR is the next step towards goto support and adds flattening for
    `ScopeOp` and `LoopOpInterface`.
    
    Looks like I can't separate this operations and create two PRs, since
    some errors occur if I do so, e.g. `reference to block defined in
    another region`. Seems we need to flatten both operations in the same
    time. Given it's a copy-pasta, I think there is no need to try to make
    several PRs.
    
    I added several tests - just copied them from the lowering part just to
    demonstrate how it looks like.
    
    Note, that changes in `dot.cir` caused by `BrCondOp` updates in the
    previous PR, when we removed the following casts:
    ```
        %20 = llvm.zext %19 : i1 to i8
        %21 = llvm.trunc %20 : i8 to i1
        llvm.cond_br %21 ...
    ```
    gitoleg authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    7740a8d View commit details
    Browse the repository at this point in the history
  8. [CIR][Codegen] Fix union init with constant (llvm#548)

    Minor fix for the case when union fields have different sizes and union
    is inited with a constant.
    Example:
    ```
    typedef union {
      short a;
      int b;
    } A;
    ```
    gitoleg authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    080f276 View commit details
    Browse the repository at this point in the history
  9. [CIR][CodeGen][Lowering] Support Integer overflow with fwrap (llvm#539)

    This PR fixes some cases when a program compiled with `-fwrapv` fails
    with `NYI` .
    Basically, the default behavior  is no overlap:
    ```
    void baz(int x, int y) {
      int z = x - y;
    }
    ```
    LLVM IR (no CIR enabled):
    ```
    %sub = sub nsw i32 %0, %1
    ```
    and with `-fwrapv` :
    ```
    %sub = sub i32 %0, %1
    ```
    We need something similar in CIR. The only way I see how to implement it
    is to add a couple of attributes to the `BinOp` to make things even with
    the llvm dialect.
    
    Well, are there any other ideas?
    
    ---------
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Apr 17, 2024
    Configuration menu
    Copy the full SHA
    95e11a5 View commit details
    Browse the repository at this point in the history

Commits on Apr 18, 2024

  1. [CIR][CIRGen] Clean up call arrangement

    Catch up with upstream and also update Address.h with one more
    helper method for `cir::Address`.
    bcardosolopes authored and lanza committed Apr 18, 2024
    Configuration menu
    Copy the full SHA
    4c07a3c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    4361c2d View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    c1311f5 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    dce1725 View commit details
    Browse the repository at this point in the history

Commits on Apr 19, 2024

  1. Configuration menu
    Copy the full SHA
    c0061fc View commit details
    Browse the repository at this point in the history
  2. [CIR] Add cir.dyn_cast operation (llvm#483)

    This PR adds the `cir.dyn_cast` operation for representing
    `dynamic_cast` in C++. It contains the following contents:
    
    - [x] A new `cir.dyn_cast` operation.
    - [x] ~Two new attributes that will be attached to `cir.dyn_cast`
    operations:~
    - [x] ~`#cir.dyn_cast_info` attributes, which gives general information
    about a dynamic cast (e.g. the source RTTI pointer, the dest RTTI
    pointer, etc.)~
    - [x] ~`#cir.downcast_info` attribute, which gives even more detailed
    information about a dynamic cast that is a down-cast. These information
    will be used when rewriting the `cir.dyn_cast` operation with more
    fundamental CIR operations.~
    - [x] CIRGen support for the new operation and attributes.
    - [x] Rewrite the new operation with more fundamental CIR operations in
    LoweringPrepare.
    
    ~This is a draft PR. Now I only added the new operation / attributes,
    and updated the CIRGen part. The LoweringPrepare for the new operation
    is not implemented. Hopefully the draft can get some initial feedbacks
    from the community and make sure it is on the right direction so we
    don't waste time on wrong things.~
    
    Related issue: llvm#470 .
    Lancern authored and lanza committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    b5429f1 View commit details
    Browse the repository at this point in the history
  3. [CIR][Codegen] TernaryOp flattening (llvm#550)

    This PR adds flattening for the `cir.ternary`. This PR is just a copy
    pasta from the lowering + tests added/fixed.
    Given the complexity of `switch` flattening, I decided to open one more
    PR for flattening.
    gitoleg authored and lanza committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    73da668 View commit details
    Browse the repository at this point in the history
  4. [CIR][CIRGen][NFC] Update buildPointerWithAlignment with LLVM upstrea…

    …m codegen approach
    bcardosolopes authored and lanza committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    536d4c2 View commit details
    Browse the repository at this point in the history
  5. [CIR] Add support for long double type (llvm#536)

    This PR adds support for the `long double` type in C/C++. It includes a
    new CIR type `!cir.long_double` to represent the `long double` type.
    CIRGen and LLVMIR lowering support for the new type is also added.
    
    Since the underlying floating point format used by a `long double` value
    is implementation-defined, the `!cir.long_double` type is parameterized
    to include information about the underlying floating point format.
    Specifically, a `long double` value may have one of the following
    formats:
    
      1) IEEE-754 binary64 format (i.e. the same format used by `double`);
      2) x87 80-bit floating point format;
      3) IEEE-754 binary128 format;
      4) PowerPC double double format.
    
    This PR invents 3 more CIR types to represent the above floating-point
    formats, and `!cir.long_double` is parameterized by another CIR
    floating-point type which represents its underlying format:
    
      - `!cir.long_double<!cir.double>` represents the 1st variant above;
      - `!cir.long_double<!cir.f80>` represents the 2nd variant above;
      - `!cir.long_double<!cir.f128>` represents the 3rd variant above;
    - `!cir.long_double<!cir.ppc_doubledouble>` represents the 4th variant
    above.
    
    Co-authored-by: Bruno Cardoso Lopes <bcardosolopes@users.noreply.github.com>
    2 people authored and lanza committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    8daf005 View commit details
    Browse the repository at this point in the history
  6. [CIR][CIRGen] Introduce initial support for ASTAllocaAddressSpace (ll…

    …vm#551)
    
    ASTAllocaAddressSpace is a target-specific definition specificed by the
    codegen target info.
    In this commit, initial support is introduced which asserts that only
    the default (no qualifier) address space is supported.
    orbiri authored and lanza committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    1c3cd0a View commit details
    Browse the repository at this point in the history

Commits on Apr 20, 2024

  1. [CIR] Introduce StructLayoutAttr

    Mostly NFC.
    
    StructType currently holds optional member variables to track layout specific
    information. Those are lazily computed at time of layout queries. Change the
    implementation to use an attribute as the internal implementation - later on we
    should perhaps incorporate parsing/printing.
    
    This is pre req work for computing alignment based on elements offsets,
    very soon we're gonna also store of array of offsets.
    bcardosolopes authored and lanza committed Apr 20, 2024
    Configuration menu
    Copy the full SHA
    9327912 View commit details
    Browse the repository at this point in the history
  2. [CIR] Extend StructLayoutAttr to support querying offset for members

    Testcase not added because we are not using the printers and parsers,
    but upcoming atomic work will exercise the path and testcases.
    bcardosolopes authored and lanza committed Apr 20, 2024
    Configuration menu
    Copy the full SHA
    8ef3b36 View commit details
    Browse the repository at this point in the history

Commits on Apr 22, 2024

  1. [CIR][CodeGen] Adds SwitchOp flattening (llvm#549)

    This PR adds flattening for `SwitchOp`. Despite of the previous PRs,
    here we have to introduce an operation for the flattening, since later
    we'll need to create `llvm.switch` in the lowering.
    So `cir.flat.switch` is a new operation, which barely copied from the
    dialect. I added several tests as well.
    gitoleg authored and lanza committed Apr 22, 2024
    Configuration menu
    Copy the full SHA
    9c305cb View commit details
    Browse the repository at this point in the history
  2. [CIR][NFC] Improve verifier related error messages (llvm#553)

    Fix `CastOp::Verify` and invalid.cir error message. Let these error
    messages with consistent format. llvm#318
    gxsoar authored and lanza committed Apr 22, 2024
    Configuration menu
    Copy the full SHA
    b51fcf7 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b64cb19 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    5d9a961 View commit details
    Browse the repository at this point in the history

Commits on Apr 23, 2024

  1. Configuration menu
    Copy the full SHA
    b61cf01 View commit details
    Browse the repository at this point in the history
  2. [CIR] Lower certain cir.cmp3way operations to LLVM intrinsics (llvm…

    …#556)
    
    LLVM recently added two families of intrinsics named `llvm.scmp.*` and
    `llvm.ucmp.*` that generate potentially better code for three-way
    comparison operations. This PR lowers certain `cir.cmp3way` operations
    to these intrinsics.
    
    Not all `cir.cmp3way` operations can be lowered to these intrinsics. The
    qualifying conditions are: 1) the comparison is between two integers,
    and 2) the comparison produces a strong ordering. `cir.cmp3way`
    operations that are not qualified are not affected by this PR.
    
    Qualifying `cir.cmp3way` operations may still need some canonicalization
    work before lowering. The "canonicalized" form of a qualifying three-way
    comparison operation yields -1 for lt, 0 for eq, and 1 for gt. This PR
    converts those non-canonicalized but qualifying `cir.cmp3way` operations
    to their canonical forms in the LLVM lowering prepare pass.
    
    This PR addresses llvm#514 .
    Lancern authored and lanza committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    77f4a0c View commit details
    Browse the repository at this point in the history
  3. [CIR][CIRGen] Atomics: Add skeleton for compare and exchange

    NFCI. Any input code still hits an assertion, just a bit down the road.
    bcardosolopes authored and lanza committed Apr 23, 2024
    Configuration menu
    Copy the full SHA
    da1dd0f View commit details
    Browse the repository at this point in the history

Commits on Apr 24, 2024

  1. Configuration menu
    Copy the full SHA
    68fe3ed View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    9daae1b View commit details
    Browse the repository at this point in the history

Commits on Apr 25, 2024

  1. Configuration menu
    Copy the full SHA
    7402372 View commit details
    Browse the repository at this point in the history
  2. [CIR][CIRGen] Add dynamic builtin alloca intrinsics support (llvm#547)

    This patch adds the CIRGen for the following builtin functions:
    
    - `alloca`;
    - `_alloca`;
    - `__builtin_alloca`;
    - `__builtin_alloca_uninitialized`.
    
    Missing support to add in the future:
    - Non-default auto initialization setting. The default is to not
    initialize the allocated buffer, which is simpler to implement. This
    commit is leaving the skeleton to implement this feature following
    clang's codegen pattern.
    - It may be possible that the frontend has set non-default address space
    for the alloca's return value. This is the case for OpenCL or AMDGPU
    codes for example. This is handled in clang codegen via address space
    cast, and is left for future implementation. This commit introduces a
    guard-rail around this behaviour.
    orbiri authored and lanza committed Apr 25, 2024
    Configuration menu
    Copy the full SHA
    96722f7 View commit details
    Browse the repository at this point in the history
  3. [CIR[CIRGen][NFC] Refactor build switch op (llvm#552)

    Make logic cleaner and more extensible.
    
    Separate collecting `SwitchStmt` information and building op logic into
    different functions.
    Add more UT to cover nested switch, which also worked before this pr.
    
    This pr is split from llvm#528.
    wenpen authored and lanza committed Apr 25, 2024
    Configuration menu
    Copy the full SHA
    7cda6e9 View commit details
    Browse the repository at this point in the history
  4. [CIR][NFC] Create LLVM intrinsic calls through `createCallLLVMIntrins…

    …icOp` (llvm#564)
    
    This PR does not introduce any functional changes. It cleans up code in
    `LowerToLLVM.cpp` and creates all LLVM intrinsic calls through the
    unified `createCallLLVMIntrinsicOp` function, as suggested by [this
    comment](llvm#556 (comment))
    in llvm#556 .
    
    Some LLVM intrinsics already have specialized LLVMIR operations. CIR
    operations that depend on these intrinsics are lowered to those
    specialized operations rather than `llvm.call_intrinsic` operation.
    Lancern authored and lanza committed Apr 25, 2024
    Configuration menu
    Copy the full SHA
    116e184 View commit details
    Browse the repository at this point in the history
  5. [CIR][Lowering] Add MLIR lowering support for CIR cos operations (llv…

    …m#565)
    
    llvm#563 This PR add cir.cos lowering to MLIR math dialect, now it only
    surpport single and double float types, I add an assertation for the
    long double and other unimplemented types
    
    ---------
    
    Signed-off-by: zhoujing <jing.zhou@terapines.com>
    zhoujingya authored and lanza committed Apr 25, 2024
    Configuration menu
    Copy the full SHA
    ded2fa7 View commit details
    Browse the repository at this point in the history
  6. [CIR] Remove redundant error from parseConstantValue (llvm#567)

    ASMParser::parseAttribute is responsible for emitting its own errors or
    forwarding errors of the parsers below it. There is no reason to emit a
    subsequent error as it doesn't add extra information to the user.
    
    As a driveby, beutify a bit the tests that "relied" on this error and
    make the expected error easier to read by moving it to the line before.
    orbiri authored and lanza committed Apr 25, 2024
    Configuration menu
    Copy the full SHA
    5718db5 View commit details
    Browse the repository at this point in the history

Commits on Apr 26, 2024

  1. Configuration menu
    Copy the full SHA
    a1cb2c0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    80f74eb View commit details
    Browse the repository at this point in the history
  3. [CIR][Lowering] Add long double types for cos operation lowering (llv…

    …m#568)
    
    Add left long double types lowering for cos operation llvm#565
    
    ---------
    
    Signed-off-by: zhoujing <jing.zhou@terapines.com>
    zhoujingya authored and lanza committed Apr 26, 2024
    Configuration menu
    Copy the full SHA
    26a5b07 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    67fa2b7 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    426233f View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    ccddaa4 View commit details
    Browse the repository at this point in the history

Commits on Apr 27, 2024

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

Commits on Apr 30, 2024

  1. [CIR] Support lowering GlobalOp and GetGlobalOp to memref (llvm#574)

    This commit introduce CIRGlobalOpLowering and CIRGetGlobalOpLowering for
    lowering to memref.
    ShivaChen committed Apr 30, 2024
    Configuration menu
    Copy the full SHA
    97b7280 View commit details
    Browse the repository at this point in the history

Commits on May 1, 2024

  1. TO BE UPSTREAMED !! [MLIR] Extend floating point parsing support

    Parsing support for floating point types was missing a few features:
    1. Parsing floating point attributes from integer literals was supported only
       for types with bitwidth smaller or equal to 64.
    2. Downstream users could not use `AsmParser::parseFloat` to parse float types
       which are printed as integer literals.
    
    This commit addresses both these points. It extends
    `Parser::parseFloatFromIntegerLiteral` to support arbitrary bitwidth, and
    exposes a new API to parse arbitrary floating point given an fltSemantics as
    input. The usage of this new API is introduced in the Test Dialect.
    orbiri committed May 1, 2024
    Configuration menu
    Copy the full SHA
    f780f38 View commit details
    Browse the repository at this point in the history
  2. [CIR] Extend support for floating point attributes

    This commit extends the support for floating point attributes parsing by using
    the new `AsmParser::parseFloat(fltSemnatics, APFloat&)` interface.
    As a drive-by, this commit also harmonizes the cir.fp print/parse namespace
    usage, and adds the constraint of supporting only "CIRFPType"s for cir.fp in
    tablegen instead of verifying it manually in the parsing logic.
    orbiri committed May 1, 2024
    Configuration menu
    Copy the full SHA
    d3d3988 View commit details
    Browse the repository at this point in the history