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:
Matthijs Kooijman 2008-06-20 15:34:07 +00:00
parent df0891d2ff
commit 7e43b3be88

View File

@ -48,7 +48,8 @@ namespace {
/// argument. Used so that arguments and return values can be used
/// interchangably.
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;
unsigned Idx;
bool IsArg;
@ -76,9 +77,13 @@ namespace {
enum Liveness { Live, MaybeLive, Dead };
/// 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
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;
/// This map maps a return value or argument to all return values or
@ -112,11 +117,13 @@ namespace {
private:
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);
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);
bool RemoveDeadStuffFromFunction(Function *F);
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
/// return instruction. This is used in the recursion, you should always leave
/// 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;
if (ReturnInst *RI = dyn_cast<ReturnInst>(V)) {
// The value is returned from another function. It's only live when the
@ -301,7 +309,8 @@ DAE::Liveness DAE::SurveyUse(Value::use_iterator U, UseVector &MaybeLiveUses, un
return IsMaybeLive(Use, MaybeLiveUses);
}
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
// depends on all uses of that aggregate, but if it is used as a return
// value, only index at which we were inserted counts.
@ -387,7 +396,8 @@ void DAE::SurveyFunction(Function &F) {
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
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
FunctionIntrinsicallyLive = true;
break;
@ -429,8 +439,8 @@ void DAE::SurveyFunction(Function &F) {
E = TheCall->use_end(); I != E; ++I) {
ExtractValueInst *Ext = dyn_cast<ExtractValueInst>(*I);
if (Ext && Ext->hasIndices()) {
// This use uses a part of our return value, survey the uses of that
// part and store the results for this index only.
// This use uses a part of our return value, survey the uses of
// that part and store the results for this index only.
unsigned Idx = *Ext->idx_begin();
if (RetValLiveness[Idx] != Live) {
RetValLiveness[Idx] = SurveyUses(Ext, MaybeLiveRetUses[Idx]);
@ -496,7 +506,8 @@ void DAE::SurveyFunction(Function &F) {
/// 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
/// 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) {
case Live: MarkLive(RA); break;
case MaybeLive:
@ -521,9 +532,11 @@ void DAE::MarkLive(RetOrArg RA) {
return; // We were already marked Live
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
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
// to ourselves is likely to mark the upper_bound (which is the first value
@ -584,7 +597,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
NewRetIdxs[i] = RetTypes.size() - 1;
} else {
++NumRetValsEliminated;
DOUT << "DAE - Removing return value " << i << " from " << F->getNameStart() << "\n";
DOUT << "DAE - Removing return value " << i << " from "
<< F->getNameStart() << "\n";
Changed = true;
}
}
@ -594,11 +608,12 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
RetTypes.push_back(RetTy);
NewRetIdxs[0] = 0;
} else {
DOUT << "DAE - Removing return value from " << F->getNameStart() << "\n";
DOUT << "DAE - Removing return value from " << F->getNameStart()
<< "\n";
++NumRetValsEliminated;
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
// to return a struct and didn't change the number of return values,
// return a struct again. This prevents chaning {something} into something
@ -641,7 +656,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
ParamAttrsVec.push_back(ParamAttrsWithIndex::get(Params.size(), Attrs));
} else {
++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;
}
}
@ -670,7 +686,8 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// The function type is only allowed to be different if we actually left out
// 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...
Function *NF = Function::Create(NFTy, F->getLinkage());
@ -759,11 +776,13 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// all extractvalue instructions).
for (Value::use_iterator I = Call->use_begin(), E = Call->use_end();
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);
// Increment now, since we're about to throw away this use.
++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();
if (NewRetIdxs[Idx] != -1) {
if (RetTypes.size() > 1) {
@ -771,7 +790,9 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
// instruction with the first index updated
std::vector<unsigned> NewIdxs(EV->idx_begin(), EV->idx_end());
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->eraseFromParent();
} else {
@ -839,12 +860,14 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
RetVal = llvm::UndefValue::get(NRetTy);
for (unsigned i = 0; i != RetCount; ++i)
if (NewRetIdxs[i] != -1) {
ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i, "newret", RI);
ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i,
"newret", RI);
if (RetTypes.size() > 1) {
// We're still returning a struct, so reinsert the value into
// 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 {
// We are now only returning a simple value, so just return the
// extracted value