If there are no machine instructions emitted for a function, then insert
a "nop" instruction so that we don't have the function's label associated with something that it's not supposed to be associated with. llvm-svn: 46394
This commit is contained in:
parent
c4dc3dc3a2
commit
5079483957
|
@ -30,6 +30,7 @@
|
||||||
#include "llvm/CodeGen/MachineModuleInfo.h"
|
#include "llvm/CodeGen/MachineModuleInfo.h"
|
||||||
#include "llvm/CodeGen/MachineFunctionPass.h"
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
||||||
#include "llvm/CodeGen/MachineInstr.h"
|
#include "llvm/CodeGen/MachineInstr.h"
|
||||||
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
#include "llvm/Support/MathExtras.h"
|
#include "llvm/Support/MathExtras.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
|
@ -813,6 +814,18 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
||||||
// Emit pre-function debug information.
|
// Emit pre-function debug information.
|
||||||
DW.BeginFunction(&MF);
|
DW.BeginFunction(&MF);
|
||||||
|
|
||||||
|
// If the function is empty, then we need to emit *something*. Otherwise, the
|
||||||
|
// function's label might be associated with something that it wasn't meant to
|
||||||
|
// be associated with. We emit a noop in this situation.
|
||||||
|
MachineFunction::iterator I = MF.begin();
|
||||||
|
|
||||||
|
if (++I == MF.end()) {
|
||||||
|
MachineBasicBlock &MBB = MF.front();
|
||||||
|
|
||||||
|
if (MBB.begin() == MBB.end())
|
||||||
|
BuildMI(MBB, MBB.end(), TM.getInstrInfo()->get(PPC::NOP));
|
||||||
|
}
|
||||||
|
|
||||||
// Print out code for the function.
|
// Print out code for the function.
|
||||||
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
|
@ -821,8 +834,8 @@ bool DarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
||||||
printBasicBlockLabel(I, true);
|
printBasicBlockLabel(I, true);
|
||||||
O << '\n';
|
O << '\n';
|
||||||
}
|
}
|
||||||
for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
|
for (MachineBasicBlock::const_iterator II = I->begin(), IE = I->end();
|
||||||
II != E; ++II) {
|
II != IE; ++II) {
|
||||||
// Print the assembly for the instruction.
|
// Print the assembly for the instruction.
|
||||||
O << "\t";
|
O << "\t";
|
||||||
printMachineInstruction(II);
|
printMachineInstruction(II);
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "llvm/Transforms/Utils/Local.h"
|
#include "llvm/Transforms/Utils/Local.h"
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Intrinsics.h"
|
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/ParameterAttributes.h"
|
#include "llvm/ParameterAttributes.h"
|
||||||
#include "llvm/Support/CFG.h"
|
#include "llvm/Support/CFG.h"
|
||||||
|
@ -155,20 +154,8 @@ static bool RemoveUnreachableBlocks(Function &F) {
|
||||||
bool Changed = MarkAliveBlocks(F.begin(), Reachable);
|
bool Changed = MarkAliveBlocks(F.begin(), Reachable);
|
||||||
|
|
||||||
// If there are unreachable blocks in the CFG...
|
// If there are unreachable blocks in the CFG...
|
||||||
if (Reachable.size() == F.size()) {
|
if (Reachable.size() == F.size())
|
||||||
if (F.size() == 1) {
|
|
||||||
// If the function has only one block with an "unreachable" instruction,
|
|
||||||
// then we should create *some* code for it. Issue a "trap" instead.
|
|
||||||
BasicBlock &BB = F.front();
|
|
||||||
|
|
||||||
if (BB.size() == 1 && dyn_cast<UnreachableInst>(&BB.front()))
|
|
||||||
new CallInst(Intrinsic::getDeclaration(F.getParent(),
|
|
||||||
Intrinsic::trap),
|
|
||||||
"", &BB.front());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
}
|
|
||||||
|
|
||||||
assert(Reachable.size() < F.size());
|
assert(Reachable.size() < F.size());
|
||||||
NumSimpl += F.size()-Reachable.size();
|
NumSimpl += F.size()-Reachable.size();
|
||||||
|
|
Loading…
Reference in New Issue