Sketch out a framework for delaying the activation of a cleanup.

Not yet complete or used.

llvm-svn: 111044
This commit is contained in:
John McCall
2010-08-13 21:20:51 +00:00
parent d1191ee43c
commit 612942d65f
4 changed files with 119 additions and 7 deletions

View File

@@ -1275,6 +1275,73 @@ void CodeGenFunction::ResolveBranchFixups(llvm::BasicBlock *Block) {
EHStack.popNullFixups();
}
/// Activate a cleanup that was created in an inactivated state.
void CodeGenFunction::ActivateCleanup(EHScopeStack::stable_iterator C) {
assert(C != EHStack.stable_end() && "activating bottom of stack?");
EHCleanupScope &Scope = cast<EHCleanupScope>(*EHStack.find(C));
assert(!Scope.isActive() && "double activation");
// Calculate whether the cleanup was used:
bool Used = false;
// - as a normal cleanup
if (Scope.isNormalCleanup()) {
bool NormalUsed = false;
if (Scope.getNormalBlock()) {
NormalUsed = true;
} else {
// Check whether any enclosed cleanups were needed.
for (EHScopeStack::stable_iterator
I = EHStack.getInnermostNormalCleanup(); I != C; ) {
assert(C.strictlyEncloses(I));
EHCleanupScope &S = cast<EHCleanupScope>(*EHStack.find(I));
if (S.getNormalBlock()) {
NormalUsed = true;
break;
}
I = S.getEnclosingNormalCleanup();
}
}
if (NormalUsed)
Used = true;
else
Scope.setActivatedBeforeNormalUse(true);
}
// - as an EH cleanup
if (Scope.isEHCleanup()) {
bool EHUsed = false;
if (Scope.getEHBlock()) {
EHUsed = true;
} else {
// Check whether any enclosed cleanups were needed.
for (EHScopeStack::stable_iterator
I = EHStack.getInnermostEHCleanup(); I != C; ) {
assert(C.strictlyEncloses(I));
EHCleanupScope &S = cast<EHCleanupScope>(*EHStack.find(I));
if (S.getEHBlock()) {
EHUsed = true;
break;
}
I = S.getEnclosingEHCleanup();
}
}
if (EHUsed)
Used = true;
else
Scope.setActivatedBeforeEHUse(true);
}
llvm::AllocaInst *Var = EHCleanupScope::activeSentinel();
if (Used) {
Var = CreateTempAlloca(Builder.getInt1Ty());
InitTempAlloca(Var, Builder.getFalse());
}
Scope.setActiveVar(Var);
}
llvm::Value *CodeGenFunction::getNormalCleanupDestSlot() {
if (!NormalCleanupDest)
NormalCleanupDest =