#include "llvm/Analysis/Verifier.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
cl::desc("Aggregate arguments to code-extracted functions"));
namespace {
- class VISIBILITY_HIDDEN CodeExtractor {
+ class CodeExtractor {
typedef std::vector<Value*> Values;
std::set<BasicBlock*> BlocksToExtract;
DominatorTree* DT;
// Old dominates New. New node domiantes all other nodes dominated
//by Old.
DomTreeNode *OldNode = DT->getNode(*I);
- std::vector<DomTreeNode *> Children;
+ SmallVector<DomTreeNode*, 8> Children;
for (DomTreeNode::iterator DI = OldNode->begin(), DE = OldNode->end();
DI != DE; ++DI)
Children.push_back(*DI);
DomTreeNode *NewNode = DT->addNewBlock(New, *I);
- for (std::vector<DomTreeNode *>::iterator I = Children.begin(),
+ for (SmallVector<DomTreeNode*, 8>::iterator I = Children.begin(),
E = Children.end(); I != E; ++I)
DT->changeImmediateDominator(*I, NewNode);
}
BasicBlock *newHeader,
Function *oldFunction,
Module *M) {
- DEBUG(errs() << "inputs: " << inputs.size() << "\n");
- DEBUG(errs() << "outputs: " << outputs.size() << "\n");
+ DEBUG(dbgs() << "inputs: " << inputs.size() << "\n");
+ DEBUG(dbgs() << "outputs: " << outputs.size() << "\n");
// This function returns unsigned, outputs will go back by reference.
switch (NumExitBlocks) {
for (Values::const_iterator i = inputs.begin(),
e = inputs.end(); i != e; ++i) {
const Value *value = *i;
- DEBUG(errs() << "value used in func: " << *value << "\n");
+ DEBUG(dbgs() << "value used in func: " << *value << "\n");
paramTy.push_back(value->getType());
}
// Add the types of the output values to the function's argument list.
for (Values::const_iterator I = outputs.begin(), E = outputs.end();
I != E; ++I) {
- DEBUG(errs() << "instr used in func: " << **I << "\n");
+ DEBUG(dbgs() << "instr used in func: " << **I << "\n");
if (AggregateArgs)
paramTy.push_back((*I)->getType());
else
paramTy.push_back(PointerType::getUnqual((*I)->getType()));
}
- DEBUG(errs() << "Function type: " << *RetTy << " f(");
+ DEBUG(dbgs() << "Function type: " << *RetTy << " f(");
for (std::vector<const Type*>::iterator i = paramTy.begin(),
e = paramTy.end(); i != e; ++i)
- DEBUG(errs() << **i << ", ");
- DEBUG(errs() << ")\n");
+ DEBUG(dbgs() << **i << ", ");
+ DEBUG(dbgs() << ")\n");
if (AggregateArgs && (inputs.size() + outputs.size() > 0)) {
PointerType *StructPtr =
return newFunction;
}
+/// FindPhiPredForUseInBlock - Given a value and a basic block, find a PHI
+/// that uses the value within the basic block, and return the predecessor
+/// block associated with that use, or return 0 if none is found.
+static BasicBlock* FindPhiPredForUseInBlock(Value* Used, BasicBlock* BB) {
+ for (Value::use_iterator UI = Used->use_begin(),
+ UE = Used->use_end(); UI != UE; ++UI) {
+ PHINode *P = dyn_cast<PHINode>(*UI);
+ if (P && P->getParent() == BB)
+ return P->getIncomingBlock(UI);
+ }
+
+ return 0;
+}
+
/// emitCallAndSwitchStatement - This method sets up the caller side by adding
/// the call instruction, splitting any PHI nodes in the header block as
/// necessary.
// then we need to test for dominance of the phi's predecessor
// instead. Unfortunately, this a little complicated since we
// have already rewritten uses of the value to uses of the reload.
- for (Value::use_iterator UI = Reloads[out]->use_begin(),
- UE = Reloads[out]->use_end(); UI != UE; ++UI) {
- PHINode *P = dyn_cast<PHINode>(*UI);
- if (!P || P->getParent() != OldTarget) continue;
-
- BasicBlock* pred = P->getIncomingBlock(UI);
- if (DT->dominates(DefBlock, pred)) {
- DominatesDef = true;
- break;
- }
- }
+ BasicBlock* pred = FindPhiPredForUseInBlock(Reloads[out],
+ OldTarget);
+ if (pred && DT && DT->dominates(DefBlock, pred))
+ DominatesDef = true;
}
if (DominatesDef) {