Skip to content

Commit bac705b

Browse files
authored
Merge pull request #116 from hzqst/dev
Checking SEHorCXXSEH before disabling lifetime marker
2 parents c20879f + c92893d commit bac705b

File tree

3 files changed

+53
-30
lines changed

3 files changed

+53
-30
lines changed

llvm/lib/CodeGen/AtomicExpandPass.cpp

+30-20
Original file line numberDiff line numberDiff line change
@@ -1847,6 +1847,12 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18471847
Args.push_back(ConstantInt::get(DL.getIntPtrType(Ctx), Size));
18481848
}
18491849

1850+
bool bShouldDisableLifetimeMarker = false;
1851+
1852+
if (I->getParent() && I->getParent()->getParent() && I->getParent()->getParent()->hasSEHOrCXXSEH()) {
1853+
bShouldDisableLifetimeMarker = true;
1854+
}
1855+
18501856
// 'ptr' argument.
18511857
// note: This assumes all address spaces share a common libfunc
18521858
// implementation and that addresses are convertable. For systems without
@@ -1860,9 +1866,11 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18601866
if (CASExpected) {
18611867
AllocaCASExpected = AllocaBuilder.CreateAlloca(CASExpected->getType());
18621868
AllocaCASExpected->setAlignment(AllocaAlignment);
1863-
#ifndef _WIN32
1864-
Builder.CreateLifetimeStart(AllocaCASExpected, SizeVal64);
1865-
#endif
1869+
if (!bShouldDisableLifetimeMarker) {
1870+
1871+
Builder.CreateLifetimeStart(AllocaCASExpected, SizeVal64);
1872+
}
1873+
18661874
Builder.CreateAlignedStore(CASExpected, AllocaCASExpected, AllocaAlignment);
18671875
Args.push_back(AllocaCASExpected);
18681876
}
@@ -1876,9 +1884,10 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18761884
} else {
18771885
AllocaValue = AllocaBuilder.CreateAlloca(ValueOperand->getType());
18781886
AllocaValue->setAlignment(AllocaAlignment);
1879-
#ifndef _WIN32
1880-
Builder.CreateLifetimeStart(AllocaValue, SizeVal64);
1881-
#endif
1887+
if (!bShouldDisableLifetimeMarker) {
1888+
Builder.CreateLifetimeStart(AllocaValue, SizeVal64);
1889+
}
1890+
18821891
Builder.CreateAlignedStore(ValueOperand, AllocaValue, AllocaAlignment);
18831892
Args.push_back(AllocaValue);
18841893
}
@@ -1888,9 +1897,10 @@ bool AtomicExpand::expandAtomicOpToLibcall(
18881897
if (!CASExpected && HasResult && !UseSizedLibcall) {
18891898
AllocaResult = AllocaBuilder.CreateAlloca(I->getType());
18901899
AllocaResult->setAlignment(AllocaAlignment);
1891-
#ifndef _WIN32
1892-
Builder.CreateLifetimeStart(AllocaResult, SizeVal64);
1893-
#endif
1900+
if (!bShouldDisableLifetimeMarker) {
1901+
Builder.CreateLifetimeStart(AllocaResult, SizeVal64);
1902+
}
1903+
18941904
Args.push_back(AllocaResult);
18951905
}
18961906

@@ -1920,21 +1930,21 @@ bool AtomicExpand::expandAtomicOpToLibcall(
19201930
CallInst *Call = Builder.CreateCall(LibcallFn, Args);
19211931
Call->setAttributes(Attr);
19221932
Value *Result = Call;
1923-
#ifndef _WIN32
1924-
// And then, extract the results...
1925-
if (ValueOperand && !UseSizedLibcall)
1926-
Builder.CreateLifetimeEnd(AllocaValue, SizeVal64);
1927-
#endif
1933+
if (!bShouldDisableLifetimeMarker) {
1934+
// And then, extract the results...
1935+
if (ValueOperand && !UseSizedLibcall)
1936+
Builder.CreateLifetimeEnd(AllocaValue, SizeVal64);
1937+
}
19281938
if (CASExpected) {
19291939
// The final result from the CAS is {load of 'expected' alloca, bool result
19301940
// from call}
19311941
Type *FinalResultTy = I->getType();
19321942
Value *V = PoisonValue::get(FinalResultTy);
19331943
Value *ExpectedOut = Builder.CreateAlignedLoad(
19341944
CASExpected->getType(), AllocaCASExpected, AllocaAlignment);
1935-
#ifndef _WIN32
1936-
Builder.CreateLifetimeEnd(AllocaCASExpected, SizeVal64);
1937-
#endif
1945+
if (!bShouldDisableLifetimeMarker) {
1946+
Builder.CreateLifetimeEnd(AllocaCASExpected, SizeVal64);
1947+
}
19381948
V = Builder.CreateInsertValue(V, ExpectedOut, 0);
19391949
V = Builder.CreateInsertValue(V, Result, 1);
19401950
I->replaceAllUsesWith(V);
@@ -1945,9 +1955,9 @@ bool AtomicExpand::expandAtomicOpToLibcall(
19451955
else {
19461956
V = Builder.CreateAlignedLoad(I->getType(), AllocaResult,
19471957
AllocaAlignment);
1948-
#ifndef _WIN32
1949-
Builder.CreateLifetimeEnd(AllocaResult, SizeVal64);
1950-
#endif
1958+
if (!bShouldDisableLifetimeMarker) {
1959+
Builder.CreateLifetimeEnd(AllocaResult, SizeVal64);
1960+
}
19511961
}
19521962
I->replaceAllUsesWith(V);
19531963
}

llvm/lib/Transforms/Scalar/SROA.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -3504,16 +3504,22 @@ class AllocaSliceRewriter : public InstVisitor<AllocaSliceRewriter, bool> {
35043504
// for the new alloca slice.
35053505
Type *PointerTy = IRB.getPtrTy(OldPtr->getType()->getPointerAddressSpace());
35063506
Value *Ptr = getNewAllocaSlicePtr(IRB, PointerTy);
3507-
#ifndef _WIN32
3507+
bool bShouldDisableLifetimeMarker = false;
3508+
3509+
if (II.getParent() && II.getParent()->getParent() && II.getParent()->getParent()->hasSEHOrCXXSEH()) {
3510+
bShouldDisableLifetimeMarker = true;
3511+
}
3512+
3513+
if (!bShouldDisableLifetimeMarker) {
35083514
Value *New;
35093515
if (II.getIntrinsicID() == Intrinsic::lifetime_start)
35103516
New = IRB.CreateLifetimeStart(Ptr, Size);
35113517
else
35123518
New = IRB.CreateLifetimeEnd(Ptr, Size);
35133519

3514-
(void)New;
3515-
LLVM_DEBUG(dbgs() << " to: " << *New << "\n");
3516-
#endif
3520+
(void)New;
3521+
LLVM_DEBUG(dbgs() << " to: " << *New << "\n");
3522+
}
35173523
return true;
35183524
}
35193525

llvm/lib/Transforms/Utils/InlineFunction.cpp

+13-6
Original file line numberDiff line numberDiff line change
@@ -2610,9 +2610,17 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
26102610
AllocaArraySize * AllocaTypeSize);
26112611
}
26122612
}
2613-
#ifndef _WIN32
2614-
builder.CreateLifetimeStart(AI, AllocaSize);
2615-
#endif
2613+
2614+
2615+
bool bShouldDisableLifetimeMarker = false;
2616+
2617+
if (AI->getParent() && AI->getParent()->getParent() && AI->getParent()->getParent()->hasSEHOrCXXSEH()) {
2618+
bShouldDisableLifetimeMarker = true;
2619+
}
2620+
2621+
if (!bShouldDisableLifetimeMarker)
2622+
builder.CreateLifetimeStart(AI, AllocaSize);
2623+
26162624
for (ReturnInst *RI : Returns) {
26172625
// Don't insert llvm.lifetime.end calls between a musttail or deoptimize
26182626
// call and a return. The return kills all local allocas.
@@ -2622,9 +2630,8 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
26222630
if (InlinedDeoptimizeCalls &&
26232631
RI->getParent()->getTerminatingDeoptimizeCall())
26242632
continue;
2625-
#ifndef _WIN32
2626-
IRBuilder<>(RI).CreateLifetimeEnd(AI, AllocaSize);
2627-
#endif
2633+
if (!bShouldDisableLifetimeMarker)
2634+
IRBuilder<>(RI).CreateLifetimeEnd(AI, AllocaSize);
26282635
}
26292636
}
26302637
}

0 commit comments

Comments
 (0)