mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
Fix code extraction of unwind blocks. This fixed bugs that bugpoint can
run into. This should go into 1.3 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15679 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -513,21 +513,24 @@ emitCallAndSwitchStatement(Function *newFunction, BasicBlock *codeReplacer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now that we've done the deed, simplify the switch instruction.
|
// Now that we've done the deed, simplify the switch instruction.
|
||||||
|
const Type *OldFnRetTy = TheSwitch->getParent()->getParent()->getReturnType();
|
||||||
switch (NumExitBlocks) {
|
switch (NumExitBlocks) {
|
||||||
case 0:
|
case 0:
|
||||||
// There is only 1 successor (the block containing the switch itself), which
|
// There are no successors (the block containing the switch itself), which
|
||||||
// means that previously this was the last part of the function, and hence
|
// means that previously this was the last part of the function, and hence
|
||||||
// this should be rewritten as a `ret'
|
// this should be rewritten as a `ret'
|
||||||
|
|
||||||
// Check if the function should return a value
|
// Check if the function should return a value
|
||||||
if (TheSwitch->getParent()->getParent()->getReturnType() != Type::VoidTy &&
|
if (OldFnRetTy == Type::VoidTy) {
|
||||||
TheSwitch->getParent()->getParent()->getReturnType() ==
|
new ReturnInst(0, TheSwitch); // Return void
|
||||||
TheSwitch->getCondition()->getType())
|
} else if (OldFnRetTy == TheSwitch->getCondition()->getType()) {
|
||||||
// return what we have
|
// return what we have
|
||||||
new ReturnInst(TheSwitch->getCondition(), TheSwitch);
|
new ReturnInst(TheSwitch->getCondition(), TheSwitch);
|
||||||
else
|
} else {
|
||||||
// just return
|
// Otherwise we must have code extracted an unwind or something, just
|
||||||
new ReturnInst(0, TheSwitch);
|
// return whatever we want.
|
||||||
|
new ReturnInst(Constant::getNullValue(OldFnRetTy), TheSwitch);
|
||||||
|
}
|
||||||
|
|
||||||
TheSwitch->getParent()->getInstList().erase(TheSwitch);
|
TheSwitch->getParent()->getInstList().erase(TheSwitch);
|
||||||
break;
|
break;
|
||||||
@ -583,8 +586,8 @@ void CodeExtractor::moveCodeToFunction(Function *newFunction) {
|
|||||||
/// for each scalar output in the function: at every exit, store intermediate
|
/// for each scalar output in the function: at every exit, store intermediate
|
||||||
/// computed result back into memory.
|
/// computed result back into memory.
|
||||||
///
|
///
|
||||||
Function *CodeExtractor::ExtractCodeRegion(const std::vector<BasicBlock*> &code)
|
Function *CodeExtractor::
|
||||||
{
|
ExtractCodeRegion(const std::vector<BasicBlock*> &code) {
|
||||||
if (!isEligible(code))
|
if (!isEligible(code))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user