mirror of
https://github.com/RPCSX/llvm.git
synced 2025-02-12 07:40:58 +00:00
do not access arguments via low-level interface, do not multiply dereference use_iterators
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@109100 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
85e01df73d
commit
efdf039aec
@ -82,8 +82,9 @@ SpecializeFunction(Function* F,
|
|||||||
ii != ee; ) {
|
ii != ee; ) {
|
||||||
Value::use_iterator i = ii;
|
Value::use_iterator i = ii;
|
||||||
++ii;
|
++ii;
|
||||||
if (isa<CallInst>(i) || isa<InvokeInst>(i)) {
|
User *U = *i;
|
||||||
CallSite CS(cast<Instruction>(i));
|
if (isa<CallInst>(U) || isa<InvokeInst>(U)) {
|
||||||
|
CallSite CS(cast<Instruction>(U));
|
||||||
if (CS.getCalledFunction() == F) {
|
if (CS.getCalledFunction() == F) {
|
||||||
|
|
||||||
SmallVector<Value*, 6> args;
|
SmallVector<Value*, 6> args;
|
||||||
@ -105,13 +106,13 @@ SpecializeFunction(Function* F,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Value* NCall;
|
Value* NCall;
|
||||||
if (CallInst *CI = dyn_cast<CallInst>(i)) {
|
if (CallInst *CI = dyn_cast<CallInst>(U)) {
|
||||||
NCall = CallInst::Create(NF, args.begin(), args.end(),
|
NCall = CallInst::Create(NF, args.begin(), args.end(),
|
||||||
CI->getName(), CI);
|
CI->getName(), CI);
|
||||||
cast<CallInst>(NCall)->setTailCall(CI->isTailCall());
|
cast<CallInst>(NCall)->setTailCall(CI->isTailCall());
|
||||||
cast<CallInst>(NCall)->setCallingConv(CI->getCallingConv());
|
cast<CallInst>(NCall)->setCallingConv(CI->getCallingConv());
|
||||||
} else {
|
} else {
|
||||||
InvokeInst *II = cast<InvokeInst>(i);
|
InvokeInst *II = cast<InvokeInst>(U);
|
||||||
NCall = InvokeInst::Create(NF, II->getNormalDest(),
|
NCall = InvokeInst::Create(NF, II->getNormalDest(),
|
||||||
II->getUnwindDest(),
|
II->getUnwindDest(),
|
||||||
args.begin(), args.end(),
|
args.begin(), args.end(),
|
||||||
@ -123,8 +124,7 @@ SpecializeFunction(Function* F,
|
|||||||
++numReplaced;
|
++numReplaced;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
next_use:
|
next_use:;
|
||||||
;
|
|
||||||
}
|
}
|
||||||
return NF;
|
return NF;
|
||||||
}
|
}
|
||||||
@ -174,14 +174,14 @@ void PartSpec::scanForInterest(Function& F, InterestingArgVector& args) {
|
|||||||
ui != ue; ++ui) {
|
ui != ue; ++ui) {
|
||||||
|
|
||||||
bool interesting = false;
|
bool interesting = false;
|
||||||
|
User *U = *ui;
|
||||||
if (isa<CmpInst>(ui)) interesting = true;
|
if (isa<CmpInst>(U)) interesting = true;
|
||||||
else if (isa<CallInst>(ui))
|
else if (isa<CallInst>(U))
|
||||||
interesting = ui->getOperand(0) == ii;
|
interesting = ui->getOperand(0) == ii;
|
||||||
else if (isa<InvokeInst>(ui))
|
else if (isa<InvokeInst>(U))
|
||||||
interesting = ui->getOperand(0) == ii;
|
interesting = ui->getOperand(0) == ii;
|
||||||
else if (isa<SwitchInst>(ui)) interesting = true;
|
else if (isa<SwitchInst>(U)) interesting = true;
|
||||||
else if (isa<BranchInst>(ui)) interesting = true;
|
else if (isa<BranchInst>(U)) interesting = true;
|
||||||
|
|
||||||
if (interesting) {
|
if (interesting) {
|
||||||
args.push_back(std::distance(F.arg_begin(), ii));
|
args.push_back(std::distance(F.arg_begin(), ii));
|
||||||
@ -196,14 +196,16 @@ int PartSpec::scanDistribution(Function& F, int arg,
|
|||||||
std::map<Constant*, int>& dist) {
|
std::map<Constant*, int>& dist) {
|
||||||
bool hasIndirect = false;
|
bool hasIndirect = false;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for(Value::use_iterator ii = F.use_begin(), ee = F.use_end();
|
for (Value::use_iterator ii = F.use_begin(), ee = F.use_end();
|
||||||
ii != ee; ++ii)
|
ii != ee; ++ii) {
|
||||||
if ((isa<CallInst>(ii) || isa<InvokeInst>(ii))
|
User *U = *ii;
|
||||||
&& ii->getOperand(0) == &F) {
|
CallSite CS(U);
|
||||||
++dist[dyn_cast<Constant>(ii->getOperand(arg + 1))];
|
if (CS && CS.getCalledFunction() == &F) {
|
||||||
|
++dist[dyn_cast<Constant>(CS.getArgument(arg))];
|
||||||
++total;
|
++total;
|
||||||
} else
|
} else
|
||||||
hasIndirect = true;
|
hasIndirect = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Preserve the original address taken function even if all other uses
|
// Preserve the original address taken function even if all other uses
|
||||||
// will be specialized.
|
// will be specialized.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user