https://github.com/E00N777 commented:
@xlauko @Lancern I added a verify function for checking producer of ptr
operand is `AllocaOp`. And I tried to add token like this way:
```
//===----------------------------------------------------------------------===//
/ LifetimeTokenType
//===----------------------------------------------------------------------===//
def CIR_LifetimeTokenType : CIR_Type<"LifetimeToken", "lifetime_token"> {
let summary = "SSA token pairing a `cir.lifetime.start` with its
`cir.lifetime.end`";
let description = [{
A value of `!cir.lifetime_token` is produced by `cir.lifetime.start`
and
consumed by `cir.lifetime.end`. It carries no runtime data; its sole
purpose is to make the start/end pairing explicit in the IR via SSA
use-def edges, so that the verifier and optimizer can rely on it.
Example:
```
%tok = cir.lifetime.start %ptr : !cir.ptr<!s32i>
cir.lifetime.end %tok
```
}];
}
```
Lowering the token turned out to be costly, though. Since
`!cir.lifetime_token` is pure metadata it has to vanish during lowering, but
the auto-generated patterns are 1:1 and the framework requires every operand to
map to exactly one value — a token → 0 types conversion makes
`cir.lifetime.end`'s token operand a zero-length range that the 1:1 adaptor
rejects, and there's no LLVM type it can honestly map to. Erasing a consumed
SSA value cleanly would need a custom 1:N pattern (or a pre-lowering CIR pass,
as the EH tokens do).Please give me some suggestions.
Following @andykaylor 's suggestion to keep this PR as the simplest mapping
onto the LLVM intrinsics, I've dropped the token for now.
@erichkeane I've dropped the CIRGen emission — Clang doesn't generate these
markers. This PR just defines the ops (with verifier + lowering) so a later
pass can produce them when needed.
Thank you very much for all your suggestions and discussions. They have been
very helpful to me.
https://github.com/llvm/llvm-project/pull/199599
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits