Skip to content

Commit 2bea75a

Browse files
committed
Revert llvm#110102, llvm#124767, and dependent patches.
This reverts commits: de9b0dd 8578b81 822f74a 8ad9e1e 4424c44 548ecde
1 parent 548ecde commit 2bea75a

30 files changed

+36
-501
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,15 +527,15 @@ New Compiler Flags
527527
Clang to generate code that tries to preserve the liveness of source variables
528528
through optimizations, meaning that variables will typically be visible in a
529529
debugger more often. The flag has two levels: ``-fextend-variable-liveness``,
530-
or ``-fextend-variable-liveness=all``, extends the liveness of all user
531-
variables and the ``this`` pointer. Alternatively
532-
``-fextend-variable-liveness=this`` has the same behaviour but applies only to
533-
the ``this`` variable in C++ class member functions, meaning its effect is a
534-
strict subset of ``-fextend-variable-liveness``. Note that this flag modifies
535-
the results of optimizations that Clang performs, which will result in reduced
536-
performance in generated code; however, this feature will not extend the
537-
liveness of some variables in cases where doing so would likely have a severe
538-
impact on generated code performance.
530+
or ``-fextend-variable-liveness=all``, extendes the liveness of all user
531+
variables and the ``this`` pointer. Alternatively ``-fextend-this-ptr``, or
532+
``-fextend-variable-liveness=this``, has the same behaviour but applies only
533+
to the ``this`` variable in C++ class member functions, meaning its effect is
534+
a strict subset of ``-fextend-variable-liveness``. Note that this flag
535+
modifies the results of optimizations that Clang performs, which will result
536+
in reduced performance in generated code; however, this feature will not
537+
extend the liveness of some variables in cases where doing so would likely
538+
have a severe impact on generated code performance.
539539

540540
- The ``-Warray-compare`` warning has been added to warn about array comparison
541541
on versions older than C++20.

clang/include/clang/Driver/Options.td

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4352,11 +4352,19 @@ def stack_usage_file : Separate<["-"], "stack-usage-file">,
43524352
def fextend_variable_liveness_EQ : Joined<["-"], "fextend-variable-liveness=">,
43534353
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
43544354
HelpText<"Extend the liveness of user variables through optimizations to "
4355-
"prevent stale or optimized-out variable values when debugging.">,
4355+
"prevent stale or optimized-out variable values when debugging. Can "
4356+
"be applied to all user variables, or just to the C++ 'this' ptr. "
4357+
"May choose not to extend the liveness of some variables, such as "
4358+
"non-scalars larger than 4 unsigned ints, or variables in any "
4359+
"inlined functions.">,
43564360
Values<"all,this,none">,
43574361
NormalizedValues<["All", "This", "None"]>,
43584362
NormalizedValuesScope<"CodeGenOptions::ExtendVariableLivenessKind">,
43594363
MarshallingInfoEnum<CodeGenOpts<"ExtendVariableLiveness">, "None">;
4364+
def fextend_this_ptr_liveness : Flag<["-"], "fextend-this-ptr-liveness">,
4365+
Visibility<[ClangOption, CC1Option]>,
4366+
Alias<fextend_variable_liveness_EQ>, AliasArgs<["this"]>,
4367+
HelpText<"Alias for -fextend-variable-liveness=this.">;
43604368
def fextend_variable_liveness : Flag<["-"], "fextend-variable-liveness">,
43614369
Visibility<[ClangOption, CC1Option]>,
43624370
Alias<fextend_variable_liveness_EQ>, AliasArgs<["all"]>,

clang/lib/CodeGen/CGCall.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,26 +3581,15 @@ static llvm::StoreInst *findDominatingStoreToReturnValue(CodeGenFunction &CGF) {
35813581
llvm::BasicBlock *IP = CGF.Builder.GetInsertBlock();
35823582
if (IP->empty()) return nullptr;
35833583

3584-
// Look at directly preceding instruction, skipping bitcasts, lifetime
3585-
// markers, and fake uses and their operands.
3586-
const llvm::Instruction *LoadIntoFakeUse = nullptr;
3584+
// Look at directly preceding instruction, skipping bitcasts and lifetime
3585+
// markers.
35873586
for (llvm::Instruction &I : make_range(IP->rbegin(), IP->rend())) {
3588-
// Ignore instructions that are just loads for fake uses; the load should
3589-
// immediately precede the fake use, so we only need to remember the
3590-
// operand for the last fake use seen.
3591-
if (LoadIntoFakeUse == &I)
3592-
continue;
35933587
if (isa<llvm::BitCastInst>(&I))
35943588
continue;
3595-
if (auto *II = dyn_cast<llvm::IntrinsicInst>(&I)) {
3589+
if (auto *II = dyn_cast<llvm::IntrinsicInst>(&I))
35963590
if (II->getIntrinsicID() == llvm::Intrinsic::lifetime_end)
35973591
continue;
35983592

3599-
if (II->getIntrinsicID() == llvm::Intrinsic::fake_use) {
3600-
LoadIntoFakeUse = dyn_cast<llvm::Instruction>(II->getArgOperand(0));
3601-
continue;
3602-
}
3603-
}
36043593
return GetStoreIfValid(&I);
36053594
}
36063595
return nullptr;

clang/lib/CodeGen/CGCleanup.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,11 @@ void EHScopeStack::deallocate(size_t Size) {
112112
StartOfData += llvm::alignTo(Size, ScopeStackAlignment);
113113
}
114114

115-
bool EHScopeStack::containsOnlyNoopCleanups(
115+
bool EHScopeStack::containsOnlyLifetimeMarkers(
116116
EHScopeStack::stable_iterator Old) const {
117117
for (EHScopeStack::iterator it = begin(); stabilize(it) != Old; it++) {
118118
EHCleanupScope *cleanup = dyn_cast<EHCleanupScope>(&*it);
119-
// If this is anything other than a lifetime marker or fake use cleanup,
120-
// then the scope stack does not contain only noop cleanups.
121-
if (!cleanup)
122-
return false;
123-
if (!cleanup->isLifetimeMarker() && !cleanup->isFakeUse())
119+
if (!cleanup || !cleanup->isLifetimeMarker())
124120
return false;
125121
}
126122

@@ -158,7 +154,6 @@ void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) {
158154
bool IsNormalCleanup = Kind & NormalCleanup;
159155
bool IsEHCleanup = Kind & EHCleanup;
160156
bool IsLifetimeMarker = Kind & LifetimeMarker;
161-
bool IsFakeUse = Kind & FakeUse;
162157

163158
// Per C++ [except.terminate], it is implementation-defined whether none,
164159
// some, or all cleanups are called before std::terminate. Thus, when
@@ -181,8 +176,6 @@ void *EHScopeStack::pushCleanup(CleanupKind Kind, size_t Size) {
181176
InnermostEHScope = stable_begin();
182177
if (IsLifetimeMarker)
183178
Scope->setLifetimeMarker();
184-
if (IsFakeUse)
185-
Scope->setFakeUse();
186179

187180
// With Windows -EHa, Invoke llvm.seh.scope.begin() for EHCleanup
188181
// If exceptions are disabled/ignored and SEH is not in use, then there is no

clang/lib/CodeGen/CGCleanup.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ class EHScope {
8787
LLVM_PREFERRED_TYPE(bool)
8888
unsigned IsLifetimeMarker : 1;
8989

90-
/// Whether this cleanup is a fake use
91-
LLVM_PREFERRED_TYPE(bool)
92-
unsigned IsFakeUse : 1;
93-
9490
/// Whether the normal cleanup should test the activation flag.
9591
LLVM_PREFERRED_TYPE(bool)
9692
unsigned TestFlagInNormalCleanup : 1;
@@ -356,7 +352,6 @@ class alignas(8) EHCleanupScope : public EHScope {
356352
CleanupBits.IsEHCleanup = isEH;
357353
CleanupBits.IsActive = true;
358354
CleanupBits.IsLifetimeMarker = false;
359-
CleanupBits.IsFakeUse = false;
360355
CleanupBits.TestFlagInNormalCleanup = false;
361356
CleanupBits.TestFlagInEHCleanup = false;
362357
CleanupBits.CleanupSize = cleanupSize;
@@ -389,9 +384,6 @@ class alignas(8) EHCleanupScope : public EHScope {
389384
bool isLifetimeMarker() const { return CleanupBits.IsLifetimeMarker; }
390385
void setLifetimeMarker() { CleanupBits.IsLifetimeMarker = true; }
391386

392-
bool isFakeUse() const { return CleanupBits.IsFakeUse; }
393-
void setFakeUse() { CleanupBits.IsFakeUse = true; }
394-
395387
bool hasActiveFlag() const { return ActiveFlag.isValid(); }
396388
Address getActiveFlag() const {
397389
return ActiveFlag;

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,14 +1355,6 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
13551355
C->setDoesNotThrow();
13561356
}
13571357

1358-
void CodeGenFunction::EmitFakeUse(Address Addr) {
1359-
auto NL = ApplyDebugLocation::CreateEmpty(*this);
1360-
llvm::Value *V = Builder.CreateLoad(Addr, "fake.use");
1361-
llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMFakeUseFn(), {V});
1362-
C->setDoesNotThrow();
1363-
C->setTailCallKind(llvm::CallInst::TCK_NoTail);
1364-
}
1365-
13661358
void CodeGenFunction::EmitAndRegisterVariableArrayDimensions(
13671359
CGDebugInfo *DI, const VarDecl &D, bool EmitDebugInfo) {
13681360
// For each dimension stores its QualType and corresponding
@@ -1422,39 +1414,6 @@ void CodeGenFunction::EmitAndRegisterVariableArrayDimensions(
14221414
}
14231415
}
14241416

1425-
/// Return the maximum size of an aggregate for which we generate a fake use
1426-
/// intrinsic when -fextend-variable-liveness is in effect.
1427-
static uint64_t maxFakeUseAggregateSize(const ASTContext &C) {
1428-
return 4 * C.getTypeSize(C.UnsignedIntTy);
1429-
}
1430-
1431-
// Helper function to determine whether a variable's or parameter's lifetime
1432-
// should be extended.
1433-
static bool shouldExtendLifetime(const ASTContext &Context,
1434-
const Decl *FuncDecl, const VarDecl &D,
1435-
ImplicitParamDecl *CXXABIThisDecl) {
1436-
// When we're not inside a valid function it is unlikely that any
1437-
// lifetime extension is useful.
1438-
if (!FuncDecl)
1439-
return false;
1440-
if (FuncDecl->isImplicit())
1441-
return false;
1442-
// Do not extend compiler-created variables except for the this pointer.
1443-
if (D.isImplicit() && &D != CXXABIThisDecl)
1444-
return false;
1445-
QualType Ty = D.getType();
1446-
// No need to extend volatiles, they have a memory location.
1447-
if (Ty.isVolatileQualified())
1448-
return false;
1449-
// Don't extend variables that exceed a certain size.
1450-
if (Context.getTypeSize(Ty) > maxFakeUseAggregateSize(Context))
1451-
return false;
1452-
// Do not extend variables in nodebug or optnone functions.
1453-
if (FuncDecl->hasAttr<NoDebugAttr>() || FuncDecl->hasAttr<OptimizeNoneAttr>())
1454-
return false;
1455-
return true;
1456-
}
1457-
14581417
/// EmitAutoVarAlloca - Emit the alloca and debug information for a
14591418
/// local variable. Does not emit initialization or destruction.
14601419
CodeGenFunction::AutoVarEmission
@@ -1707,18 +1666,6 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
17071666
emission.getOriginalAllocatedAddress(),
17081667
emission.getSizeForLifetimeMarkers());
17091668

1710-
// Analogous to lifetime markers, we use a 'cleanup' to emit fake.use
1711-
// calls for local variables. We are exempting volatile variables and
1712-
// non-scalars larger than 4 times the size of an unsigned int. Larger
1713-
// non-scalars are often allocated in memory and may create unnecessary
1714-
// overhead.
1715-
if (CGM.getCodeGenOpts().getExtendVariableLiveness() ==
1716-
CodeGenOptions::ExtendVariableLivenessKind::All) {
1717-
if (shouldExtendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl))
1718-
EHStack.pushCleanup<FakeUse>(NormalFakeUse,
1719-
emission.getAllocatedAddress());
1720-
}
1721-
17221669
return emission;
17231670
}
17241671

@@ -2585,15 +2532,6 @@ llvm::Function *CodeGenModule::getLLVMLifetimeEndFn() {
25852532
return LifetimeEndFn;
25862533
}
25872534

2588-
/// Lazily declare the @llvm.fake.use intrinsic.
2589-
llvm::Function *CodeGenModule::getLLVMFakeUseFn() {
2590-
if (FakeUseFn)
2591-
return FakeUseFn;
2592-
FakeUseFn = llvm::Intrinsic::getOrInsertDeclaration(
2593-
&getModule(), llvm::Intrinsic::fake_use);
2594-
return FakeUseFn;
2595-
}
2596-
25972535
namespace {
25982536
/// A cleanup to perform a release of an object at the end of a
25992537
/// function. This is used to balance out the incoming +1 of a
@@ -2787,18 +2725,6 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
27872725

27882726
setAddrOfLocalVar(&D, DeclPtr);
27892727

2790-
// Push a FakeUse 'cleanup' object onto the EHStack for the parameter,
2791-
// which may be the 'this' pointer. This causes the emission of a fake.use
2792-
// call with the parameter as argument at the end of the function.
2793-
if (CGM.getCodeGenOpts().getExtendVariableLiveness() ==
2794-
CodeGenOptions::ExtendVariableLivenessKind::All ||
2795-
(CGM.getCodeGenOpts().getExtendVariableLiveness() ==
2796-
CodeGenOptions::ExtendVariableLivenessKind::This &&
2797-
&D == CXXABIThisDecl)) {
2798-
if (shouldExtendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl))
2799-
EHStack.pushCleanup<FakeUse>(NormalFakeUse, DeclPtr);
2800-
}
2801-
28022728
// Emit debug info for param declarations in non-thunk functions.
28032729
if (CGDebugInfo *DI = getDebugInfo()) {
28042730
if (CGM.getCodeGenOpts().hasReducedDebugInfo() && !CurFuncIsThunk &&

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ void CodeGenFunction::FinishFunction(SourceLocation EndLoc) {
404404
// important to do this before we enter the return block or return
405405
// edges will be *really* confused.
406406
bool HasCleanups = EHStack.stable_begin() != PrologueCleanupDepth;
407-
bool HasOnlyNoopCleanups =
408-
HasCleanups && EHStack.containsOnlyNoopCleanups(PrologueCleanupDepth);
409-
bool EmitRetDbgLoc = !HasCleanups || HasOnlyNoopCleanups;
407+
bool HasOnlyLifetimeMarkers =
408+
HasCleanups && EHStack.containsOnlyLifetimeMarkers(PrologueCleanupDepth);
409+
bool EmitRetDbgLoc = !HasCleanups || HasOnlyLifetimeMarkers;
410410

411411
std::optional<ApplyDebugLocation> OAL;
412412
if (HasCleanups) {

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -723,20 +723,6 @@ class CodeGenFunction : public CodeGenTypeCache {
723723
}
724724
};
725725

726-
// We are using objects of this 'cleanup' class to emit fake.use calls
727-
// for -fextend-variable-liveness. They are placed at the end of a variable's
728-
// scope analogous to lifetime markers.
729-
class FakeUse final : public EHScopeStack::Cleanup {
730-
Address Addr;
731-
732-
public:
733-
FakeUse(Address addr) : Addr(addr) {}
734-
735-
void Emit(CodeGenFunction &CGF, Flags flags) override {
736-
CGF.EmitFakeUse(Addr);
737-
}
738-
};
739-
740726
/// Header for data within LifetimeExtendedCleanupStack.
741727
struct LifetimeExtendedCleanupHeader {
742728
/// The size of the following cleanup object.
@@ -5089,8 +5075,6 @@ class CodeGenFunction : public CodeGenTypeCache {
50895075

50905076
RValue EmitAtomicExpr(AtomicExpr *E);
50915077

5092-
void EmitFakeUse(Address Addr);
5093-
50945078
//===--------------------------------------------------------------------===//
50955079
// Annotations Emission
50965080
//===--------------------------------------------------------------------===//

clang/lib/CodeGen/CodeGenModule.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,6 @@ class CodeGenModule : public CodeGenTypeCache {
647647
/// void @llvm.lifetime.end(i64 %size, i8* nocapture <ptr>)
648648
llvm::Function *LifetimeEndFn = nullptr;
649649

650-
/// void @llvm.fake.use(...)
651-
llvm::Function *FakeUseFn = nullptr;
652-
653650
std::unique_ptr<SanitizerMetadata> SanitizerMD;
654651

655652
llvm::MapVector<const Decl *, bool> DeferredEmptyCoverageMappingDecls;
@@ -1329,7 +1326,6 @@ class CodeGenModule : public CodeGenTypeCache {
13291326

13301327
llvm::Function *getLLVMLifetimeStartFn();
13311328
llvm::Function *getLLVMLifetimeEndFn();
1332-
llvm::Function *getLLVMFakeUseFn();
13331329

13341330
// Make sure that this type is translated.
13351331
void UpdateCompletedType(const TagDecl *TD);

clang/lib/CodeGen/EHScopeStack.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,6 @@ enum CleanupKind : unsigned {
8787

8888
LifetimeMarker = 0x8,
8989
NormalEHLifetimeMarker = LifetimeMarker | NormalAndEHCleanup,
90-
91-
// FakeUse needs to be recognized as a special cleanup similar to lifetime
92-
// markers chiefly to be ignored in most contexts.
93-
FakeUse = 0x10,
94-
NormalFakeUse = FakeUse | NormalCleanup,
9590
};
9691

9792
/// A stack of scopes which respond to exceptions, including cleanups
@@ -357,8 +352,8 @@ class EHScopeStack {
357352
void popTerminate();
358353

359354
// Returns true iff the current scope is either empty or contains only
360-
// noop cleanups, i.e. lifetime markers and fake uses.
361-
bool containsOnlyNoopCleanups(stable_iterator Old) const;
355+
// lifetime markers, i.e. no real cleanup code
356+
bool containsOnlyLifetimeMarkers(stable_iterator Old) const;
362357

363358
/// Determines whether the exception-scopes stack is empty.
364359
bool empty() const { return StartOfData == EndOfBuffer; }

clang/test/CodeGen/extend-variable-liveness-except.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

clang/test/CodeGen/extend-variable-liveness-wide-scalar.cpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)