mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-17 21:29:20 +00:00
80 column and trailing whitespace fixes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52539 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
df0891d2ff
commit
7e43b3be88
@ -48,11 +48,12 @@ namespace {
|
|||||||
/// argument. Used so that arguments and return values can be used
|
/// argument. Used so that arguments and return values can be used
|
||||||
/// interchangably.
|
/// interchangably.
|
||||||
struct RetOrArg {
|
struct RetOrArg {
|
||||||
RetOrArg(const Function* F, unsigned Idx, bool IsArg) : F(F), Idx(Idx), IsArg(IsArg) {}
|
RetOrArg(const Function* F, unsigned Idx, bool IsArg) : F(F), Idx(Idx),
|
||||||
|
IsArg(IsArg) {}
|
||||||
const Function *F;
|
const Function *F;
|
||||||
unsigned Idx;
|
unsigned Idx;
|
||||||
bool IsArg;
|
bool IsArg;
|
||||||
|
|
||||||
/// Make RetOrArg comparable, so we can put it into a map
|
/// Make RetOrArg comparable, so we can put it into a map
|
||||||
bool operator<(const RetOrArg &O) const {
|
bool operator<(const RetOrArg &O) const {
|
||||||
if (F != O.F)
|
if (F != O.F)
|
||||||
@ -68,7 +69,7 @@ namespace {
|
|||||||
return F == O.F && Idx == O.Idx && IsArg == O.IsArg;
|
return F == O.F && Idx == O.Idx && IsArg == O.IsArg;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Liveness enum - During our initial pass over the program, we determine
|
/// Liveness enum - During our initial pass over the program, we determine
|
||||||
/// that things are either definately alive, definately dead, or in need of
|
/// that things are either definately alive, definately dead, or in need of
|
||||||
/// interprocedural analysis (MaybeLive).
|
/// interprocedural analysis (MaybeLive).
|
||||||
@ -76,13 +77,17 @@ namespace {
|
|||||||
enum Liveness { Live, MaybeLive, Dead };
|
enum Liveness { Live, MaybeLive, Dead };
|
||||||
|
|
||||||
/// Convenience wrapper
|
/// Convenience wrapper
|
||||||
RetOrArg CreateRet(const Function *F, unsigned Idx) { return RetOrArg(F, Idx, false); }
|
RetOrArg CreateRet(const Function *F, unsigned Idx) {
|
||||||
|
return RetOrArg(F, Idx, false);
|
||||||
|
}
|
||||||
/// Convenience wrapper
|
/// Convenience wrapper
|
||||||
RetOrArg CreateArg(const Function *F, unsigned Idx) { return RetOrArg(F, Idx, true); }
|
RetOrArg CreateArg(const Function *F, unsigned Idx) {
|
||||||
|
return RetOrArg(F, Idx, true);
|
||||||
|
}
|
||||||
|
|
||||||
typedef std::multimap<RetOrArg, RetOrArg> UseMap;
|
typedef std::multimap<RetOrArg, RetOrArg> UseMap;
|
||||||
/// This map maps a return value or argument to all return values or
|
/// This map maps a return value or argument to all return values or
|
||||||
/// arguments it uses.
|
/// arguments it uses.
|
||||||
/// For example (indices are left out for clarity):
|
/// For example (indices are left out for clarity):
|
||||||
/// - Uses[ret F] = ret G
|
/// - Uses[ret F] = ret G
|
||||||
/// This means that F calls G, and F returns the value returned by G.
|
/// This means that F calls G, and F returns the value returned by G.
|
||||||
@ -100,7 +105,7 @@ namespace {
|
|||||||
|
|
||||||
/// This set contains all values that have been determined to be live
|
/// This set contains all values that have been determined to be live
|
||||||
LiveSet LiveValues;
|
LiveSet LiveValues;
|
||||||
|
|
||||||
typedef SmallVector<RetOrArg, 5> UseVector;
|
typedef SmallVector<RetOrArg, 5> UseVector;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -112,11 +117,13 @@ namespace {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Liveness IsMaybeLive(RetOrArg Use, UseVector &MaybeLiveUses);
|
Liveness IsMaybeLive(RetOrArg Use, UseVector &MaybeLiveUses);
|
||||||
Liveness SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses, unsigned RetValNum = 0);
|
Liveness SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses,
|
||||||
|
unsigned RetValNum = 0);
|
||||||
Liveness SurveyUses(Value *V, UseVector &MaybeLiveUses);
|
Liveness SurveyUses(Value *V, UseVector &MaybeLiveUses);
|
||||||
|
|
||||||
void SurveyFunction(Function &F);
|
void SurveyFunction(Function &F);
|
||||||
void MarkValue(const RetOrArg &RA, Liveness L, const UseVector &MaybeLiveUses);
|
void MarkValue(const RetOrArg &RA, Liveness L,
|
||||||
|
const UseVector &MaybeLiveUses);
|
||||||
void MarkLive(RetOrArg RA);
|
void MarkLive(RetOrArg RA);
|
||||||
bool RemoveDeadStuffFromFunction(Function *F);
|
bool RemoveDeadStuffFromFunction(Function *F);
|
||||||
bool DeleteDeadVarargs(Function &Fn);
|
bool DeleteDeadVarargs(Function &Fn);
|
||||||
@ -291,7 +298,8 @@ DAE::Liveness DAE::IsMaybeLive(RetOrArg Use, UseVector &MaybeLiveUses) {
|
|||||||
/// RetValNum is the return value number to use when this use is used in a
|
/// RetValNum is the return value number to use when this use is used in a
|
||||||
/// return instruction. This is used in the recursion, you should always leave
|
/// return instruction. This is used in the recursion, you should always leave
|
||||||
/// it at 0.
|
/// it at 0.
|
||||||
DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses, unsigned RetValNum) {
|
DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses,
|
||||||
|
unsigned RetValNum) {
|
||||||
Value *V = *U;
|
Value *V = *U;
|
||||||
if (ReturnInst *RI = dyn_cast<ReturnInst>(V)) {
|
if (ReturnInst *RI = dyn_cast<ReturnInst>(V)) {
|
||||||
// The value is returned from another function. It's only live when the
|
// The value is returned from another function. It's only live when the
|
||||||
@ -299,9 +307,10 @@ DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses, un
|
|||||||
RetOrArg Use = CreateRet(RI->getParent()->getParent(), RetValNum);
|
RetOrArg Use = CreateRet(RI->getParent()->getParent(), RetValNum);
|
||||||
// We might be live, depending on the liveness of Use
|
// We might be live, depending on the liveness of Use
|
||||||
return IsMaybeLive(Use, MaybeLiveUses);
|
return IsMaybeLive(Use, MaybeLiveUses);
|
||||||
}
|
}
|
||||||
if (InsertValueInst *IV = dyn_cast<InsertValueInst>(V)) {
|
if (InsertValueInst *IV = dyn_cast<InsertValueInst>(V)) {
|
||||||
if (U.getOperandNo() != InsertValueInst::getAggregateOperandIndex() && IV->hasIndices())
|
if (U.getOperandNo() != InsertValueInst::getAggregateOperandIndex()
|
||||||
|
&& IV->hasIndices())
|
||||||
// The use we are examining is inserted into an aggregate. Our liveness
|
// The use we are examining is inserted into an aggregate. Our liveness
|
||||||
// depends on all uses of that aggregate, but if it is used as a return
|
// depends on all uses of that aggregate, but if it is used as a return
|
||||||
// value, only index at which we were inserted counts.
|
// value, only index at which we were inserted counts.
|
||||||
@ -309,7 +318,7 @@ DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses, un
|
|||||||
|
|
||||||
// Note that if we are used as the aggregate operand to the insertvalue,
|
// Note that if we are used as the aggregate operand to the insertvalue,
|
||||||
// we don't change RetValNum, but do survey all our uses.
|
// we don't change RetValNum, but do survey all our uses.
|
||||||
|
|
||||||
Liveness Result = Dead;
|
Liveness Result = Dead;
|
||||||
for (Value::use_iterator I = IV->use_begin(),
|
for (Value::use_iterator I = IV->use_begin(),
|
||||||
E = V->use_end(); I != E; ++I) {
|
E = V->use_end(); I != E; ++I) {
|
||||||
@ -324,7 +333,7 @@ DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses, un
|
|||||||
Function *F = CS.getCalledFunction();
|
Function *F = CS.getCalledFunction();
|
||||||
if (F) {
|
if (F) {
|
||||||
// Used in a direct call
|
// Used in a direct call
|
||||||
|
|
||||||
// Check for vararg. Do - 1 to skip the first operand to call (the
|
// Check for vararg. Do - 1 to skip the first operand to call (the
|
||||||
// function itself).
|
// function itself).
|
||||||
if (U.getOperandNo() - 1 >= F->getFunctionType()->getNumParams())
|
if (U.getOperandNo() - 1 >= F->getFunctionType()->getNumParams())
|
||||||
@ -384,10 +393,11 @@ void DAE::SurveyFunction(Function &F) {
|
|||||||
typedef SmallVector<UseVector, 5> RetUses;
|
typedef SmallVector<UseVector, 5> RetUses;
|
||||||
// Intialized to a list of RetCount empty lists
|
// Intialized to a list of RetCount empty lists
|
||||||
RetUses MaybeLiveRetUses(RetCount);
|
RetUses MaybeLiveRetUses(RetCount);
|
||||||
|
|
||||||
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
|
||||||
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator()))
|
if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator()))
|
||||||
if (RI->getNumOperands() != 0 && RI->getOperand(0)->getType() != F.getFunctionType()->getReturnType()) {
|
if (RI->getNumOperands() != 0 && RI->getOperand(0)->getType()
|
||||||
|
!= F.getFunctionType()->getReturnType()) {
|
||||||
// We don't support old style multiple return values
|
// We don't support old style multiple return values
|
||||||
FunctionIntrinsicallyLive = true;
|
FunctionIntrinsicallyLive = true;
|
||||||
break;
|
break;
|
||||||
@ -417,20 +427,20 @@ void DAE::SurveyFunction(Function &F) {
|
|||||||
FunctionIntrinsicallyLive = true;
|
FunctionIntrinsicallyLive = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we end up here, we are looking at a direct call to our function.
|
// If we end up here, we are looking at a direct call to our function.
|
||||||
|
|
||||||
// Now, check how our return value(s) is/are used in this caller. Don't
|
// Now, check how our return value(s) is/are used in this caller. Don't
|
||||||
// bother checking return values if all of them are live already
|
// bother checking return values if all of them are live already
|
||||||
if (NumLiveRetVals != RetCount) {
|
if (NumLiveRetVals != RetCount) {
|
||||||
if (STy) {
|
if (STy) {
|
||||||
// Check all uses of the return value
|
// Check all uses of the return value
|
||||||
for (Value::use_iterator I = TheCall->use_begin(),
|
for (Value::use_iterator I = TheCall->use_begin(),
|
||||||
E = TheCall->use_end(); I != E; ++I) {
|
E = TheCall->use_end(); I != E; ++I) {
|
||||||
ExtractValueInst *Ext = dyn_cast<ExtractValueInst>(*I);
|
ExtractValueInst *Ext = dyn_cast<ExtractValueInst>(*I);
|
||||||
if (Ext && Ext->hasIndices()) {
|
if (Ext && Ext->hasIndices()) {
|
||||||
// This use uses a part of our return value, survey the uses of that
|
// This use uses a part of our return value, survey the uses of
|
||||||
// part and store the results for this index only.
|
// that part and store the results for this index only.
|
||||||
unsigned Idx = *Ext->idx_begin();
|
unsigned Idx = *Ext->idx_begin();
|
||||||
if (RetValLiveness[Idx] != Live) {
|
if (RetValLiveness[Idx] != Live) {
|
||||||
RetValLiveness[Idx] = SurveyUses(Ext, MaybeLiveRetUses[Idx]);
|
RetValLiveness[Idx] = SurveyUses(Ext, MaybeLiveRetUses[Idx]);
|
||||||
@ -468,7 +478,7 @@ void DAE::SurveyFunction(Function &F) {
|
|||||||
MarkLive(CreateRet(&F, i));
|
MarkLive(CreateRet(&F, i));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now we've inspected all callers, record the liveness of our return values.
|
// Now we've inspected all callers, record the liveness of our return values.
|
||||||
for (unsigned i = 0, e = RetValLiveness.size(); i != e; ++i) {
|
for (unsigned i = 0, e = RetValLiveness.size(); i != e; ++i) {
|
||||||
RetOrArg Ret = CreateRet(&F, i);
|
RetOrArg Ret = CreateRet(&F, i);
|
||||||
@ -480,7 +490,7 @@ void DAE::SurveyFunction(Function &F) {
|
|||||||
// Now, check all of our arguments
|
// Now, check all of our arguments
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
UseVector MaybeLiveArgUses;
|
UseVector MaybeLiveArgUses;
|
||||||
for (Function::arg_iterator AI = F.arg_begin(),
|
for (Function::arg_iterator AI = F.arg_begin(),
|
||||||
E = F.arg_end(); AI != E; ++AI, ++i) {
|
E = F.arg_end(); AI != E; ++AI, ++i) {
|
||||||
// See what the effect of this use is (recording any uses that cause
|
// See what the effect of this use is (recording any uses that cause
|
||||||
// MaybeLive in MaybeLiveArgUses)
|
// MaybeLive in MaybeLiveArgUses)
|
||||||
@ -496,7 +506,8 @@ void DAE::SurveyFunction(Function &F) {
|
|||||||
/// MarkValue - This function marks the liveness of RA depending on L. If L is
|
/// MarkValue - This function marks the liveness of RA depending on L. If L is
|
||||||
/// MaybeLive, it also records any uses in MaybeLiveUses such that RA will be
|
/// MaybeLive, it also records any uses in MaybeLiveUses such that RA will be
|
||||||
/// marked live if any use in MaybeLiveUses gets marked live later on.
|
/// marked live if any use in MaybeLiveUses gets marked live later on.
|
||||||
void DAE::MarkValue(const RetOrArg &RA, Liveness L, const UseVector &MaybeLiveUses) {
|
void DAE::MarkValue(const RetOrArg &RA, Liveness L,
|
||||||
|
const UseVector &MaybeLiveUses) {
|
||||||
switch (L) {
|
switch (L) {
|
||||||
case Live: MarkLive(RA); break;
|
case Live: MarkLive(RA); break;
|
||||||
case MaybeLive:
|
case MaybeLive:
|
||||||
@ -504,7 +515,7 @@ void DAE::MarkValue(const RetOrArg &RA, Liveness L, const UseVector &MaybeLiveUs
|
|||||||
// Note any uses of this value, so this return value can be
|
// Note any uses of this value, so this return value can be
|
||||||
// marked live whenever one of the uses becomes live.
|
// marked live whenever one of the uses becomes live.
|
||||||
UseMap::iterator Where = Uses.begin();
|
UseMap::iterator Where = Uses.begin();
|
||||||
for (UseVector::const_iterator UI = MaybeLiveUses.begin(),
|
for (UseVector::const_iterator UI = MaybeLiveUses.begin(),
|
||||||
UE = MaybeLiveUses.end(); UI != UE; ++UI)
|
UE = MaybeLiveUses.end(); UI != UE; ++UI)
|
||||||
Where = Uses.insert(Where, UseMap::value_type(*UI, RA));
|
Where = Uses.insert(Where, UseMap::value_type(*UI, RA));
|
||||||
break;
|
break;
|
||||||
@ -521,9 +532,11 @@ void DAE::MarkLive(RetOrArg RA) {
|
|||||||
return; // We were already marked Live
|
return; // We were already marked Live
|
||||||
|
|
||||||
if (RA.IsArg)
|
if (RA.IsArg)
|
||||||
DOUT << "DAE - Marking argument " << RA.Idx << " to function " << RA.F->getNameStart() << " live\n";
|
DOUT << "DAE - Marking argument " << RA.Idx << " to function "
|
||||||
|
<< RA.F->getNameStart() << " live\n";
|
||||||
else
|
else
|
||||||
DOUT << "DAE - Marking return value " << RA.Idx << " of function " << RA.F->getNameStart() << " live\n";
|
DOUT << "DAE - Marking return value " << RA.Idx << " of function "
|
||||||
|
<< RA.F->getNameStart() << " live\n";
|
||||||
|
|
||||||
// We don't use upper_bound (or equal_range) here, because our recursive call
|
// We don't use upper_bound (or equal_range) here, because our recursive call
|
||||||
// to ourselves is likely to mark the upper_bound (which is the first value
|
// to ourselves is likely to mark the upper_bound (which is the first value
|
||||||
@ -562,9 +575,9 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
// The existing function return attributes.
|
// The existing function return attributes.
|
||||||
ParameterAttributes RAttrs = PAL.getParamAttrs(0);
|
ParameterAttributes RAttrs = PAL.getParamAttrs(0);
|
||||||
|
|
||||||
|
|
||||||
// Find out the new return value
|
// Find out the new return value
|
||||||
|
|
||||||
const Type *RetTy = FTy->getReturnType();
|
const Type *RetTy = FTy->getReturnType();
|
||||||
const Type *NRetTy;
|
const Type *NRetTy;
|
||||||
unsigned RetCount = NumRetVals(F);
|
unsigned RetCount = NumRetVals(F);
|
||||||
@ -584,7 +597,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
NewRetIdxs[i] = RetTypes.size() - 1;
|
NewRetIdxs[i] = RetTypes.size() - 1;
|
||||||
} else {
|
} else {
|
||||||
++NumRetValsEliminated;
|
++NumRetValsEliminated;
|
||||||
DOUT << "DAE - Removing return value " << i << " from " << F->getNameStart() << "\n";
|
DOUT << "DAE - Removing return value " << i << " from "
|
||||||
|
<< F->getNameStart() << "\n";
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -594,17 +608,18 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
RetTypes.push_back(RetTy);
|
RetTypes.push_back(RetTy);
|
||||||
NewRetIdxs[0] = 0;
|
NewRetIdxs[0] = 0;
|
||||||
} else {
|
} else {
|
||||||
DOUT << "DAE - Removing return value from " << F->getNameStart() << "\n";
|
DOUT << "DAE - Removing return value from " << F->getNameStart()
|
||||||
|
<< "\n";
|
||||||
++NumRetValsEliminated;
|
++NumRetValsEliminated;
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
if (RetTypes.size() > 1 || (STy && STy->getNumElements() == RetTypes.size()))
|
if (RetTypes.size() > 1 || STy && STy->getNumElements() == RetTypes.size())
|
||||||
// More than one return type? Return a struct with them. Also, if we used
|
// More than one return type? Return a struct with them. Also, if we used
|
||||||
// to return a struct and didn't change the number of return values,
|
// to return a struct and didn't change the number of return values,
|
||||||
// return a struct again. This prevents chaning {something} into something
|
// return a struct again. This prevents chaning {something} into something
|
||||||
// and {} into void.
|
// and {} into void.
|
||||||
// Make the new struct packed if we used to return a packed struct
|
// Make the new struct packed if we used to return a packed struct
|
||||||
// already.
|
// already.
|
||||||
NRetTy = StructType::get(RetTypes, STy->isPacked());
|
NRetTy = StructType::get(RetTypes, STy->isPacked());
|
||||||
else if (RetTypes.size() == 1)
|
else if (RetTypes.size() == 1)
|
||||||
// One return type? Just a simple value then, but only if we didn't use to
|
// One return type? Just a simple value then, but only if we didn't use to
|
||||||
@ -616,12 +631,12 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
} else {
|
} else {
|
||||||
NRetTy = Type::VoidTy;
|
NRetTy = Type::VoidTy;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any incompatible attributes
|
// Remove any incompatible attributes
|
||||||
RAttrs &= ~ParamAttr::typeIncompatible(NRetTy);
|
RAttrs &= ~ParamAttr::typeIncompatible(NRetTy);
|
||||||
if (RAttrs)
|
if (RAttrs)
|
||||||
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, RAttrs));
|
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(0, RAttrs));
|
||||||
|
|
||||||
// Remember which arguments are still alive
|
// Remember which arguments are still alive
|
||||||
SmallVector<bool, 10> ArgAlive(FTy->getNumParams(), false);
|
SmallVector<bool, 10> ArgAlive(FTy->getNumParams(), false);
|
||||||
// Construct the new parameter list from non-dead arguments. Also construct
|
// Construct the new parameter list from non-dead arguments. Also construct
|
||||||
@ -634,14 +649,15 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
if (LiveValues.erase(Arg)) {
|
if (LiveValues.erase(Arg)) {
|
||||||
Params.push_back(I->getType());
|
Params.push_back(I->getType());
|
||||||
ArgAlive[i] = true;
|
ArgAlive[i] = true;
|
||||||
|
|
||||||
// Get the original parameter attributes (skipping the first one, that is
|
// Get the original parameter attributes (skipping the first one, that is
|
||||||
// for the return value
|
// for the return value
|
||||||
if (ParameterAttributes Attrs = PAL.getParamAttrs(i + 1))
|
if (ParameterAttributes Attrs = PAL.getParamAttrs(i + 1))
|
||||||
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), Attrs));
|
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), Attrs));
|
||||||
} else {
|
} else {
|
||||||
++NumArgumentsEliminated;
|
++NumArgumentsEliminated;
|
||||||
DOUT << "DAE - Removing argument " << i << " (" << I->getNameStart() << ") from " << F->getNameStart() << "\n";
|
DOUT << "DAE - Removing argument " << i << " (" << I->getNameStart()
|
||||||
|
<< ") from " << F->getNameStart() << "\n";
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -663,14 +679,15 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
|
|
||||||
// Create the new function type based on the recomputed parameters.
|
// Create the new function type based on the recomputed parameters.
|
||||||
FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg());
|
FunctionType *NFTy = FunctionType::get(NRetTy, Params, FTy->isVarArg());
|
||||||
|
|
||||||
// No change?
|
// No change?
|
||||||
if (NFTy == FTy)
|
if (NFTy == FTy)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// The function type is only allowed to be different if we actually left out
|
// The function type is only allowed to be different if we actually left out
|
||||||
// an argument or return value
|
// an argument or return value
|
||||||
assert(Changed && "Function type changed while no arguments or retrurn values were removed!");
|
assert(Changed && "Function type changed while no arguments or retrurn values"
|
||||||
|
"were removed!");
|
||||||
|
|
||||||
// Create the new function body and insert it into the module...
|
// Create the new function body and insert it into the module...
|
||||||
Function *NF = Function::Create(NFTy, F->getLinkage());
|
Function *NF = Function::Create(NFTy, F->getLinkage());
|
||||||
@ -702,7 +719,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
// Declare these outside of the loops, so we can reuse them for the second
|
// Declare these outside of the loops, so we can reuse them for the second
|
||||||
// loop, which loops the varargs
|
// loop, which loops the varargs
|
||||||
CallSite::arg_iterator I = CS.arg_begin();
|
CallSite::arg_iterator I = CS.arg_begin();
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
// Loop over those operands, corresponding to the normal arguments to the
|
// Loop over those operands, corresponding to the normal arguments to the
|
||||||
// original function, and add those that are still alive.
|
// original function, and add those that are still alive.
|
||||||
for (unsigned e = FTy->getNumParams(); i != e; ++I, ++i)
|
for (unsigned e = FTy->getNumParams(); i != e; ++I, ++i)
|
||||||
@ -759,11 +776,13 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
// all extractvalue instructions).
|
// all extractvalue instructions).
|
||||||
for (Value::use_iterator I = Call->use_begin(), E = Call->use_end();
|
for (Value::use_iterator I = Call->use_begin(), E = Call->use_end();
|
||||||
I != E;) {
|
I != E;) {
|
||||||
assert(isa<ExtractValueInst>(*I) && "Return value not only used by extractvalue?");
|
assert(isa<ExtractValueInst>(*I) && "Return value not only used by"
|
||||||
|
"extractvalue?");
|
||||||
ExtractValueInst *EV = cast<ExtractValueInst>(*I);
|
ExtractValueInst *EV = cast<ExtractValueInst>(*I);
|
||||||
// Increment now, since we're about to throw away this use.
|
// Increment now, since we're about to throw away this use.
|
||||||
++I;
|
++I;
|
||||||
assert(EV->hasIndices() && "Return value used by extractvalue without indices?");
|
assert(EV->hasIndices() && "Return value used by extractvalue without"
|
||||||
|
"indices?");
|
||||||
unsigned Idx = *EV->idx_begin();
|
unsigned Idx = *EV->idx_begin();
|
||||||
if (NewRetIdxs[Idx] != -1) {
|
if (NewRetIdxs[Idx] != -1) {
|
||||||
if (RetTypes.size() > 1) {
|
if (RetTypes.size() > 1) {
|
||||||
@ -771,7 +790,9 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
// instruction with the first index updated
|
// instruction with the first index updated
|
||||||
std::vector<unsigned> NewIdxs(EV->idx_begin(), EV->idx_end());
|
std::vector<unsigned> NewIdxs(EV->idx_begin(), EV->idx_end());
|
||||||
NewIdxs[0] = NewRetIdxs[Idx];
|
NewIdxs[0] = NewRetIdxs[Idx];
|
||||||
Value *NEV = ExtractValueInst::Create(New, NewIdxs.begin(), NewIdxs.end(), "retval", EV);
|
Value *NEV = ExtractValueInst::Create(New, NewIdxs.begin(),
|
||||||
|
NewIdxs.end(), "retval",
|
||||||
|
EV);
|
||||||
EV->replaceAllUsesWith(NEV);
|
EV->replaceAllUsesWith(NEV);
|
||||||
EV->eraseFromParent();
|
EV->eraseFromParent();
|
||||||
} else {
|
} else {
|
||||||
@ -788,7 +809,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
New->takeName(Call);
|
New->takeName(Call);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, remove the old call from the program, reducing the use-count of
|
// Finally, remove the old call from the program, reducing the use-count of
|
||||||
@ -839,19 +860,21 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
|
|||||||
RetVal = llvm::UndefValue::get(NRetTy);
|
RetVal = llvm::UndefValue::get(NRetTy);
|
||||||
for (unsigned i = 0; i != RetCount; ++i)
|
for (unsigned i = 0; i != RetCount; ++i)
|
||||||
if (NewRetIdxs[i] != -1) {
|
if (NewRetIdxs[i] != -1) {
|
||||||
ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i, "newret", RI);
|
ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i,
|
||||||
|
"newret", RI);
|
||||||
if (RetTypes.size() > 1) {
|
if (RetTypes.size() > 1) {
|
||||||
// We're still returning a struct, so reinsert the value into
|
// We're still returning a struct, so reinsert the value into
|
||||||
// our new return value at the new index
|
// our new return value at the new index
|
||||||
|
|
||||||
RetVal = InsertValueInst::Create(RetVal, EV, NewRetIdxs[i], "oldret");
|
RetVal = InsertValueInst::Create(RetVal, EV, NewRetIdxs[i],
|
||||||
|
"oldret");
|
||||||
} else {
|
} else {
|
||||||
// We are now only returning a simple value, so just return the
|
// We are now only returning a simple value, so just return the
|
||||||
// extracted value
|
// extracted value
|
||||||
RetVal = EV;
|
RetVal = EV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Replace the return instruction with one returning the new return
|
// Replace the return instruction with one returning the new return
|
||||||
// value (possibly 0 if we became void).
|
// value (possibly 0 if we became void).
|
||||||
ReturnInst::Create(RetVal, RI);
|
ReturnInst::Create(RetVal, RI);
|
||||||
|
Loading…
Reference in New Issue
Block a user