cleanups per review. Mostly cosmetic, plus use SmallVector in place of std::vector.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79287 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jim Grosbach 2009-08-17 21:40:03 +00:00
parent 46c8181412
commit 606f3d696f

View File

@ -25,12 +25,12 @@
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/Local.h"
#include "llvm/ADT/Statistic.h" #include "llvm/ADT/Statistic.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h" #include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetLowering.h"
#include <set>
using namespace llvm; using namespace llvm;
STATISTIC(NumInvokes, "Number of invokes replaced"); STATISTIC(NumInvokes, "Number of invokes replaced");
@ -71,7 +71,7 @@ namespace {
void markInvokeCallSite(InvokeInst *II, unsigned InvokeNo, void markInvokeCallSite(InvokeInst *II, unsigned InvokeNo,
Value *CallSite, Value *CallSite,
SwitchInst *CatchSwitch); SwitchInst *CatchSwitch);
void splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes); void splitLiveRangesLiveAcrossInvokes(SmallVector<InvokeInst*,16> &Invokes);
bool insertSjLjEHSupport(Function &F); bool insertSjLjEHSupport(Function &F);
}; };
} // end anonymous namespace } // end anonymous namespace
@ -165,12 +165,12 @@ static void MarkBlocksLiveIn(BasicBlock *BB, std::set<BasicBlock*> &LiveBBs) {
MarkBlocksLiveIn(*PI, LiveBBs); MarkBlocksLiveIn(*PI, LiveBBs);
} }
// live across unwind edges. Each value that is live across an unwind edge /// splitLiveRangesAcrossInvokes - Each value that is live across an unwind edge
// we spill into a stack location, guaranteeing that there is nothing live /// we spill into a stack location, guaranteeing that there is nothing live
// across the unwind edge. This process also splits all critical edges /// across the unwind edge. This process also splits all critical edges
// coming out of invoke's. /// coming out of invoke's.
void SjLjEHPass:: void SjLjEHPass::
splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes) { splitLiveRangesLiveAcrossInvokes(SmallVector<InvokeInst*,16> &Invokes) {
// First step, split all critical edges from invoke instructions. // First step, split all critical edges from invoke instructions.
for (unsigned i = 0, e = Invokes.size(); i != e; ++i) { for (unsigned i = 0, e = Invokes.size(); i != e; ++i) {
InvokeInst *II = Invokes[i]; InvokeInst *II = Invokes[i];
@ -223,7 +223,7 @@ splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes) {
continue; continue;
// Avoid iterator invalidation by copying users to a temporary vector. // Avoid iterator invalidation by copying users to a temporary vector.
std::vector<Instruction*> Users; SmallVector<Instruction*,16> Users;
for (Value::use_iterator UI = Inst->use_begin(), E = Inst->use_end(); for (Value::use_iterator UI = Inst->use_begin(), E = Inst->use_end();
UI != E; ++UI) { UI != E; ++UI) {
Instruction *User = cast<Instruction>(*UI); Instruction *User = cast<Instruction>(*UI);
@ -231,11 +231,6 @@ splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes) {
Users.push_back(User); Users.push_back(User);
} }
// Scan all of the uses and see if the live range is live across an unwind
// edge. If we find a use live across an invoke edge, create an alloca
// and spill the value.
std::set<InvokeInst*> InvokesWithStoreInserted;
// Find all of the blocks that this value is live in. // Find all of the blocks that this value is live in.
std::set<BasicBlock*> LiveBBs; std::set<BasicBlock*> LiveBBs;
LiveBBs.insert(Inst->getParent()); LiveBBs.insert(Inst->getParent());
@ -273,9 +268,9 @@ splitLiveRangesLiveAcrossInvokes(std::vector<InvokeInst*> &Invokes) {
} }
bool SjLjEHPass::insertSjLjEHSupport(Function &F) { bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
std::vector<ReturnInst*> Returns; SmallVector<ReturnInst*,16> Returns;
std::vector<UnwindInst*> Unwinds; SmallVector<UnwindInst*,16> Unwinds;
std::vector<InvokeInst*> Invokes; SmallVector<InvokeInst*,16> Invokes;
// Look through the terminators of the basic blocks to find invokes, returns // Look through the terminators of the basic blocks to find invokes, returns
// and unwinds // and unwinds
@ -346,11 +341,9 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
// SJLJ, we always use the same personality for the whole function, // SJLJ, we always use the same personality for the whole function,
// not on a per-selector basis. // not on a per-selector basis.
// FIXME: That's a bit ugly. Better way? // FIXME: That's a bit ugly. Better way?
std::vector<CallInst*> EH_Selectors; SmallVector<CallInst*,16> EH_Selectors;
std::vector<CallInst*> EH_Exceptions; SmallVector<CallInst*,16> EH_Exceptions;
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
// for (unsigned i = 0, e = Invokes.size(); i != e; ++i) {
// BasicBlock *Pad = Invokes[0]->getUnwindDest();
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
if (CallInst *CI = dyn_cast<CallInst>(I)) { if (CallInst *CI = dyn_cast<CallInst>(I)) {
if (CI->getCalledFunction() == Selector32Fn || if (CI->getCalledFunction() == Selector32Fn ||
@ -381,9 +374,8 @@ bool SjLjEHPass::insertSjLjEHSupport(Function &F) {
// the instruction hasn't already been removed. // the instruction hasn't already been removed.
if (!I->getParent()) continue; if (!I->getParent()) continue;
Value *Val = new LoadInst(ExceptionAddr, "exception", true, I); Value *Val = new LoadInst(ExceptionAddr, "exception", true, I);
Val = CastInst::Create(Instruction::IntToPtr, Val, Type *Ty = PointerType::getUnqual(Type::getInt8Ty(F.getContext()));
PointerType::getUnqual(Type::getInt8Ty(F.getContext())), Val = CastInst::Create(Instruction::IntToPtr, Val, Ty, "", I);
"", I);
I->replaceAllUsesWith(Val); I->replaceAllUsesWith(Val);
I->eraseFromParent(); I->eraseFromParent();