Skip to content

Conversation

@wizardengineer
Copy link
Collaborator

@wizardengineer wizardengineer commented Aug 26, 2025

From PR: llvm/clangir#1859

  1. Catch Entry Parsing: parseCatchEntry in CIRDialect.cpp now properly handles #cir.unwind attributes

  2. Resume Operation: Fix record definition of cir.resume in order to handle locations correctly

Issue:

  • error: expected '{' to begin a region when parsing catch [#cir.unwind {
  • error: undefined symbol alias id when parsing cir.resume loc(#loc)

AdUhTkJm and others added 30 commits April 9, 2025 15:02
This is Part 3 of registration function generation.

This generates `__cuda_module_dtor`. It cannot be placed in global dtors
list, as treating it as a normal destructor will result in double-free
in recent CUDA versions (see comments in OG). Rather, the function is
passed as callback of `atexit`, which is called at the end of
`__cuda_module_ctor`.
Traditional clang implementation:
https://github.com/llvm/clangir/blob/a1ab6bf6cd3b83d0982c16f29e8c98958f69c024/clang/lib/CodeGen/CGBuiltin.cpp#L3618-L3632

The problem here is that `__builtin_clz` allows undefined result, while
`__lzcnt` doesn't. As a result, I have to create a new CIR for
`__lzcnt`. Since the return type of those two builtin differs, I decided
to change return type of current `CIR_BitOp` to allow new `CIR_LzcntOp`
to inherit from it.

I would like to hear your suggestions. C.c. @Lancern
This PR adds support for compiling builtin variables like `threadIdx`
down to the appropriate intrinsic.

---------

Co-authored-by: Aidan Wong <[email protected]>
Co-authored-by: anominos <[email protected]>
I have now fixed the test. Earlier I made some commits with other
changes because we were testing something on my fork. This should be
resolved now
CIR is currently ignoring the `signext` and `zeroext` for function
arguments and return types produced by CallConvLowering.

This PR lowers them to LLVM IR.
I realized I committed a new file with CRLF before. Really sorry about
that >_<

Related: llvm/clangir#1404
The choice of adding a separate file imitates that of OG.
This PR removes a useless argument `convertToInt` and removes hardcoded
`Sint32Type`.

I realized I committed a new file with CRLF before. Really sorry about
that >_<
There are some subtleties here.

This is the code in OG:
```cpp
// note: this is different from default ABI
if (!RetTy->isScalarType())
  return ABIArgInfo::getDirect();
```
which says we should return structs directly. It's correct, has have the
same behaviour as `nvcc`, and it obeys the PTX ABI as well.
The comment dates back to 2013 (see [this
commit](llvm@f9329ff)
-- it didn't provide any explanation either), so I believe it's
outdated. I didn't include this comment in the PR.
…lvm#1486)

The pattern `call {{.*}} i32` mismatches `call i32` due to double spaces
surrounding `{{.*}}`. This patch removes the first space to fix the
failure.
…1487)

This PR resolves an assertion failure in
`CIRGenTypes::isFuncParamTypeConvertible`, which is involved when trying
to emit a vtable entry to a virtual function whose type includes a
pointer-to-member-function.
…lvm#1431)

Implements `::verify` for operations cir.atomic.xchg and
cir.atomic.cmp_xchg

I believe the existing regression tests don't get to the CIR level type
check failure and I was not able to implement a case that does.

Most attempts of reproducing cir.atomic.xchg type check failure were
along the lines of:
```
int a;
long long b,c;
__atomic_exchange(&a, &b, &c, memory_order_seq_cst);
```

And they seem to never trigger the failure on `::verify` because they
fail earlier in function parameter checking:
```
exmp.cpp:7:27: error: cannot initialize a parameter of type 'int *' with an rvalue of type 'long long *'
    7 |     __atomic_exchange(&a, &b, &c, memory_order_seq_cst);
      |                           ^~
```

Closes llvm#1378 .
This PR adds a new boolean flag to the `cir.load` and the `cir.store`
operation that distinguishes nontemporal loads and stores. Besides, this
PR also adds support for the `__builtin_nontemporal_load` and the
`__builtin_nontemporal_store` intrinsic function.
This PR adds a new boolean flag to the `cir.load` and the `cir.store`
operation that distinguishes nontemporal loads and stores. Besides, this
PR also adds support for the `__builtin_nontemporal_load` and the
`__builtin_nontemporal_store` intrinsic function.
This PR adds an insertion guard for the try body scope for try-catch.
Currently, the following code snippet fails during CodeGen:

```
void foo() {
  int r = 1;
  try {
    ++r;
    return;
  } catch (...) {
  }
}
```

The insertion point doesn't get reset properly and the cleanup is being
ran for a wrong/deleted block causing a segmentation fault. I also added
a test.
The comments suggested that we should use TableGen to generate the
recognizing functions. However, I think templates might be more suitable
for generating them -- and I can't find any existing TableGen backends
that let us generate arbitrary functions.

My choice of design is to offer a template to match standard library
functions:
```cpp
// matches std::find with 3 arguments, and raise it into StdFindOp
StdRecognizer<3, StdFindOp, StdFuncsID::Find>
```
I have to use a TableGen'd enum to map names to IDs, as we can't pass
string literals to template arguments easily in C++17.

This also constraints design of future `StdXXXOp`s: they must take
operands the same way of StdFindOp, where the first one is the original
function, and the rest are function arguments.

I'm not sure if this approach is the best way. Please tell me if you
have concerns or any alternative ways.
…was set explicitly (llvm#1482)

This is backported from a change made in
llvm#131181

---------

Co-authored-by: Morris Hafner <[email protected]>
…R attribute. (llvm#1467)

Started decorating CUDA shadow variables with the shadow_name CIR
attribute which will be used for registering the globals.
… target was set explicitly" (llvm#1509)

Reverts llvm/clangir#1482

@mmha this is crashing on macos on asserts build:
```
FAIL: Clang :: CIR/Tools/cir-translate/warn-default-triple.cir (472 of 552)
******************** TEST 'Clang :: CIR/Tools/cir-translate/warn-default-triple.cir' FAILED ********************
Exit Code: 134

Command Output (stdout):
--
Assertion failed: (!DataLayoutString.empty() && "Uninitialized DataLayout!"), function getDataLayoutString, file TargetInfo.h, line 1282.
```

Perhaps besides picking a default you maybe need to do some missing
datalayout init?
Jezurko and others added 28 commits May 23, 2025 14:18
…vm#135772) (#36)

Add APIntParameter with custom implementation for comparison and use it
in llvm.constant_range attribute. This is necessary because the default
equality operator of APInt asserts when the bit widths of the compared
APInts differ. The comparison is used by StorageUniquer when hashes of
two ranges with different bit widths collide.

Co-authored-by: Robert Konicar <[email protected]>
… circular dependency (#37)

* [CIR-link] move link interface implementation into dialect to prevent circular dependency

* expose interfaces

* expose conlict resolution

* [CIR] Initialize flag for target dialect (#38)

---------

Co-authored-by: 2over12 <[email protected]>
Co-authored-by: Andrew Pan <[email protected]>
This is a workaround for importing multiple modules into a single
context. The downside of this solution is that it accepts invalid IRs
where there is a redefinition of the named type, but solving that in the
parser is not possible.
* [CIR-link] Refactor nest/updateState

* Formatting
…ll (llvm#135895) (#40)

LLVM IR currently [accepts](https://godbolt.org/z/nqnEsW1ja):
```
define void @incompatible_call_and_callee_types() {
  call void @callee(i64 0)
  ret void
}

define void @callee({ptr, i64}, i32) {
  ret void
}
```

This currently fails to import. Even though these constructs are
dangerous and probably indicate some ODR violation (or optimization
bug), they are "valid" and should be imported into LLVM IR dialect. This
PR implements that by using an indirect call to represent it.
Translation already works nicely and outputs the same source llvm IR
file.

The error is now a warning, the tests in
`mlir/test/Target/LLVMIR/Import/import-failure.ll` already use `CHECK`
lines, so no need to add extra diagnostic tests.

Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…op linkage fix (#42)

* [MLIR][LLVMIR] Add support for the full form of global_{ctor,dtor} (llvm#133176)

Currently only ctor/dtor list and their priorities are supported. This
PR adds support for the missing data field.

Few implementation notes:
- The assembly printer has a fixed form because previous `attr_dict`
will sort the dict by key name, making global_dtor and global_ctor
differ in the order of printed arguments.
- LLVM's `ptr null` is being converted to `#llvm.zero` otherwise we'd
have to create a region to use the default operation conversion from
`ptr null`, which is silly given that the field only support null or a
symbol.

* [MLIR][LLVM] Add weak_odr to allowed linkage for alias (llvm#132840)

I missed this when originally introduced the feature (note the verifier
message already contains it), this fixes a small bug.

---------

Co-authored-by: Bruno Cardoso Lopes <[email protected]>
…lvm#138986) (#43)

`GlobalOp` was parsing `thread_local` after `unnamed_addr`, but printing in the reverse order.

While here, make `AliasOp` match the same behavior and share common parts of global and alias printing.

Co-authored-by: Bruno Cardoso Lopes <[email protected]>
Adds support for resolving Appending linkage for the LLVM dialect.
Currently, the implementation lacks support for a corner case of appending globals that are a mix between globals with an initializer attribute and a global with intializer region.
…inkerInterface (#47)

An external user of the linker interface might be using some custom scheme between getting conflict resolution and applying it, therefore bypassing the single argument version of  `resolveConflict`. Make it so that we still get the necessary info for appending when this happens
…sing (#46)

This modifies the workaround in #34.

If an opaque type name collides with a different named type, the opaque type takes the specified body now, instead of being renamed.

* [MLIR] Hack in "linking" of opaque types with bodies during parsing

* Import llvm-link test for opaque type linking
…es (#51)

* [MLIR][mlir-link] Add structors in llvm ctors/dtors ops to dependencies

LLVM dialect Global{C,D}torsOp references symbols in special attributes.
This needs to be handled as a special case for symbol dependency
computation.

* Fix possible invalid ArrayRef
* [mlir][debuginfo] Add flags to attribute creation where necessary

* [MLIR][mlir-link] Cache symbol tables and use SymbolUserMap for replacement lookups

* [MLIR][mlir-link] Use ModuleOp as key for symbolUserMap holding map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.