Skip to content

Commit 804d966

Browse files
committed
Remove O0-exclusivity, use enum-typed arg, address minor comments
1 parent e8a38f0 commit 804d966

15 files changed

+30
-88
lines changed

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,11 +1353,6 @@ void CodeGenFunction::EmitLifetimeEnd(llvm::Value *Size, llvm::Value *Addr) {
13531353
}
13541354

13551355
void CodeGenFunction::EmitFakeUse(Address Addr) {
1356-
// We do not emit a fake use if we want to apply optnone to this function,
1357-
// even if we might not apply it anyway due to minsize or similar attributes.
1358-
if (!CGM.getCodeGenOpts().DisableO0ImplyOptNone &&
1359-
CGM.getCodeGenOpts().OptimizationLevel == 0)
1360-
return;
13611356
auto NL = ApplyDebugLocation::CreateEmpty(*this);
13621357
llvm::Value *V = Builder.CreateLoad(Addr, "fake.use");
13631358
llvm::CallInst *C = Builder.CreateCall(CGM.getLLVMFakeUseFn(), {V});
@@ -1432,9 +1427,9 @@ static uint64_t maxFakeUseAggregateSize(const ASTContext &C) {
14321427

14331428
// Helper function to determine whether a variable's or parameter's lifetime
14341429
// should be extended.
1435-
static bool extendLifetime(const ASTContext &Context, const Decl *FuncDecl,
1436-
const VarDecl &D,
1437-
ImplicitParamDecl *CXXABIThisDecl) {
1430+
static bool shouldExtendLifetime(const ASTContext &Context,
1431+
const Decl *FuncDecl, const VarDecl &D,
1432+
ImplicitParamDecl *CXXABIThisDecl) {
14381433
// When we're not inside a valid function it is unlikely that any
14391434
// lifetime extension is useful.
14401435
if (!FuncDecl)
@@ -1711,13 +1706,14 @@ CodeGenFunction::EmitAutoVarAlloca(const VarDecl &D) {
17111706

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

17231719
return emission;
@@ -2785,9 +2781,12 @@ void CodeGenFunction::EmitParmDecl(const VarDecl &D, ParamValue Arg,
27852781
// Push a FakeUse 'cleanup' object onto the EHStack for the parameter,
27862782
// which may be the 'this' pointer. This causes the emission of a fake.use
27872783
// call with the parameter as argument at the end of the function.
2788-
if (CGM.getCodeGenOpts().ExtendLifetimes ||
2789-
(CGM.getCodeGenOpts().ExtendThisPtr && &D == CXXABIThisDecl)) {
2790-
if (extendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl))
2784+
if (CGM.getCodeGenOpts().getExtendVariableLiveness() ==
2785+
CodeGenOptions::ExtendVariableLivenessKind::All ||
2786+
(CGM.getCodeGenOpts().getExtendVariableLiveness() ==
2787+
CodeGenOptions::ExtendVariableLivenessKind::This &&
2788+
&D == CXXABIThisDecl)) {
2789+
if (shouldExtendLifetime(getContext(), CurCodeDecl, D, CXXABIThisDecl))
27912790
EHStack.pushCleanup<FakeUse>(NormalFakeUse, DeclPtr);
27922791
}
27932792

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,13 +1834,6 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
18341834
Opts.setInlining(CodeGenOptions::NormalInlining);
18351835
}
18361836

1837-
// Extended lifetimes are meaningless if we are not going to run any
1838-
// optimizations, so skip them here.
1839-
if (Opts.OptimizationLevel == 0 && !Opts.DisableO0ImplyOptNone) {
1840-
Opts.ExtendLifetimes = false;
1841-
Opts.ExtendThisPtr = false;
1842-
}
1843-
18441837
// PIC defaults to -fno-direct-access-external-data while non-PIC defaults to
18451838
// -fdirect-access-external-data.
18461839
Opts.DirectAccessExternalData =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -fextend-lifetimes -fcxx-exceptions -fexceptions -o - | FileCheck %s
1+
// RUN: %clang_cc1 %s -emit-llvm -fextend-variable-liveness -fcxx-exceptions -fexceptions -o - | FileCheck %s
22
// This test checks that the fake uses can be generated in exception handling
33
// blocks and that we can emit fake uses for the __int128 data type.
44

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -disable-O0-optnone -emit-llvm -fextend-lifetimes -triple x86_64-unknown-linux -o - | FileCheck %s
1+
// RUN: %clang_cc1 %s -emit-llvm -fextend-variable-liveness -triple x86_64-unknown-linux -o - | FileCheck %s
22
// REQUIRES: x86-registered-target
33
// This test checks that the fake uses can be generated in exception handling
44
// blocks and that we can emit fake uses for the __int128 data type.

clang/test/CodeGen/extend-liveness1.c renamed to clang/test/CodeGen/extend-variable-liveness.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -fextend-lifetimes -o - | FileCheck %s --implicit-check-not=llvm.fake.use
1+
// RUN: %clang_cc1 %s -emit-llvm -fextend-variable-liveness -o - | FileCheck %s --implicit-check-not=llvm.fake.use
22
// Check that fake use calls are emitted at the correct locations, i.e.
33
// at the end of lexical blocks and at the end of the function.
44

clang/test/CodeGen/fake-use-determinism.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -O0 -disable-O0-optnone -emit-llvm -fextend-lifetimes %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -emit-llvm -fextend-variable-liveness %s -o - | FileCheck %s
22
//
33
// We are checking that the fake.use calls for i, j and k appear
44
// in a particular order. It is not the order itself that is important

clang/test/CodeGen/fake-use-lambda.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -triple=%itanium_abi_triple -O1 -emit-llvm -fextend-lifetimes -o - | FileCheck %s
1+
// RUN: %clang_cc1 %s -triple=%itanium_abi_triple -O1 -emit-llvm -fextend-variable-liveness -o - | FileCheck %s
22
// Make sure we don't crash compiling a lambda that is not nested in a function.
33
// We also check that fake uses are properly issued in lambdas.
44

clang/test/CodeGen/fake-use-landingpad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -O0 -disable-O0-optnone -emit-llvm -fextend-lifetimes -fexceptions -o - | FileCheck %s --implicit-check-not="landingpad {"
1+
// RUN: %clang_cc1 %s -emit-llvm -fextend-variable-liveness -fexceptions -o - | FileCheck %s --implicit-check-not="landingpad {"
22

33
// Check that fake uses do not mistakenly cause a landing pad to be generated when
44
// exceptions are enabled.

clang/test/CodeGen/fake-use-noreturn.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 %s -emit-llvm -fextend-lifetimes -O0 -disable-O0-optnone -o - | FileCheck %s
1+
// RUN: %clang_cc1 %s -emit-llvm -fextend-variable-liveness -o - | FileCheck %s
22
//
33
// Check we can correctly produce fake uses for function-level variables even
44
// when we have a return in a nested conditional and there is no code at the end

clang/test/CodeGen/fake-use-return-line.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -emit-llvm -O0 -disable-O0-optnone -debug-info-kind=limited -fextend-lifetimes -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -fextend-variable-liveness -o - %s | FileCheck %s
22

33
// Clang adjusts the line numbers of returns based on the line numbers of
44
// dominating stores to %retval; we test that fake use intrinsics do not affect

0 commit comments

Comments
 (0)