[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)
Stephen Tozer via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 12 07:05:44 PST 2024
================
@@ -1664,6 +1710,17 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
emission.getOriginalAllocatedAddress(),
emission.getSizeForLifetimeMarkers());
+ // Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
+ // calls for local variables. We are exempting volatile variables and
+ // non-scalars larger than 4 times the size of an unsigned int (32 bytes).
+ // Larger non-scalars are often allocated in memory and may create unnecessary
+ // overhead.
+ if (CGM.getCodeGenOpts().ExtendLifetimes) {
+ if (extendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl))
+ EHStack.pushCleanup<FakeUse>(NormalFakeUse,
+ emission.getAllocatedAddress());
----------------
SLTozer wrote:
Looks like the difference is about allocas in a non-default address space - essentially we'll get either:
```
%i = alloca i32, align 4, addrspace(5)
%i.ascast = addrspacecast ptr addrspace(5) %i to ptr
store i32 %someval, ptr %i.ascast, align 4
; getAllocatedAddress
%fake.use = load i32, ptr %i.ascast, align 4
call void (...) @llvm.fake.use(i32 %fake.use)
; getOriginalAllocatedAddress
%fake.use = load i32, ptr addrspace(5) %i, align 4
call void (...) @llvm.fake.use(i32 %fake.use)
```
In practice, both of them result in extended variable lifetimes (the fake use will continue to track `%someval` in both cases), so I _think_ this is unimportant. On the one hand, the pointer that we use to store and load is `%i.ascast`, so it seems consistent for the fake use to use that; on the other hand, if a `#dbg_declare` is created, it will refer to `ptr addrspace(5) %i`, so that could be more appropriate for the fake use. In summary: I don't know, and I don't think it matters.
https://github.com/llvm/llvm-project/pull/110102
More information about the cfe-commits
mailing list