From lattner at cs.uiuc.edu Mon Dec 22 13:25:28 2003
From: lattner at cs.uiuc.edu (Chris Lattner)
Date: Mon Dec 22 13:25:28 2003
Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
Message-ID: <200312220953.DAA13036@zion.cs.uiuc.edu>
Changes in directory llvm/lib/Transforms/Scalar:
IndVarSimplify.cpp updated: 1.49 -> 1.50
---
Log message:
Don't mind me, I'm just refactoring away. This patch makes room for LFTR, but
contains no functionality changes.
---
Diffs of the changes: (+128 -88)
Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
diff -u llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.49 llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.50
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp:1.49 Sun Dec 21 23:02:01 2003
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp Mon Dec 22 03:53:29 2003
@@ -52,6 +52,9 @@
return TD->getTypeSize(Ty); // Must be a pointer
}
+ Value *ComputeAuxIndVarValue(InductionVariable &IV, Value *CIV);
+ void ReplaceIndVar(InductionVariable &IV, Value *Counter);
+
bool runOnLoop(Loop *L);
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
@@ -192,104 +195,141 @@
DEBUG(IV->print(std::cerr));
- while (isa(AfterPHIIt)) ++AfterPHIIt;
-
// Don't modify the canonical indvar or unrecognized indvars...
if (IV != Canonical && IV->InductionType != InductionVariable::Unknown) {
- const Type *IVTy = IV->Phi->getType();
- if (isa(IVTy)) // If indexing into a pointer, make the
- IVTy = TD->getIntPtrType(); // index the appropriate type.
-
- Instruction *Val = IterCount;
- if (!isa(IV->Step) || // If the step != 1
- !cast(IV->Step)->equalsInt(1)) {
-
- // If the types are not compatible, insert a cast now...
- if (Val->getType() != IVTy)
- Val = new CastInst(Val, IVTy, Val->getName(), AfterPHIIt);
- if (IV->Step->getType() != IVTy)
- IV->Step = new CastInst(IV->Step, IVTy, IV->Step->getName(),
- AfterPHIIt);
+ ReplaceIndVar(*IV, IterCount);
+ Changed = true;
+ ++NumRemoved;
+ }
+ }
- Val = BinaryOperator::create(Instruction::Mul, Val, IV->Step,
- IV->Phi->getName()+"-scale", AfterPHIIt);
- }
+ return Changed;
+}
- // If this is a pointer indvar...
- if (isa(IV->Phi->getType())) {
- std::vector Idx;
- // FIXME: this should not be needed when we fix PR82!
- if (Val->getType() != Type::LongTy)
- Val = new CastInst(Val, Type::LongTy, Val->getName(), AfterPHIIt);
- Idx.push_back(Val);
- Val = new GetElementPtrInst(IV->Start, Idx,
- IV->Phi->getName()+"-offset",
- AfterPHIIt);
-
- } else if (!isa(IV->Start) || // If Start != 0...
- !cast(IV->Start)->isNullValue()) {
- // If the types are not compatible, insert a cast now...
- if (Val->getType() != IVTy)
- Val = new CastInst(Val, IVTy, Val->getName(), AfterPHIIt);
- if (IV->Start->getType() != IVTy)
- IV->Start = new CastInst(IV->Start, IVTy, IV->Start->getName(),
- AfterPHIIt);
-
- // Insert the instruction after the phi nodes...
- Val = BinaryOperator::create(Instruction::Add, Val, IV->Start,
- IV->Phi->getName()+"-offset", AfterPHIIt);
- }
+/// ComputeAuxIndVarValue - Given an auxillary induction variable, compute and
+/// return a value which will always be equal to the induction variable PHI, but
+/// is based off of the canonical induction variable CIV.
+///
+Value *IndVarSimplify::ComputeAuxIndVarValue(InductionVariable &IV, Value *CIV){
+ Instruction *Phi = IV.Phi;
+ const Type *IVTy = Phi->getType();
+ if (isa(IVTy)) // If indexing into a pointer, make the
+ IVTy = TD->getIntPtrType(); // index the appropriate type.
- // If the PHI node has a different type than val is, insert a cast now...
- if (Val->getType() != IV->Phi->getType())
- Val = new CastInst(Val, IV->Phi->getType(), Val->getName(), AfterPHIIt);
-
+ BasicBlock::iterator AfterPHIIt = Phi;
+ while (isa(AfterPHIIt)) ++AfterPHIIt;
+
+ Value *Val = CIV;
+ if (Val->getType() != IVTy)
+ Val = new CastInst(Val, IVTy, Val->getName(), AfterPHIIt);
+
+ if (!isa(IV.Step) || // If the step != 1
+ !cast(IV.Step)->equalsInt(1)) {
+
+ // If the types are not compatible, insert a cast now...
+ if (IV.Step->getType() != IVTy)
+ IV.Step = new CastInst(IV.Step, IVTy, IV.Step->getName(), AfterPHIIt);
+
+ Val = BinaryOperator::create(Instruction::Mul, Val, IV.Step,
+ Phi->getName()+"-scale", AfterPHIIt);
+ }
+
+ // If this is a pointer indvar...
+ if (isa(Phi->getType())) {
+ std::vector Idx;
+ // FIXME: this should not be needed when we fix PR82!
+ if (Val->getType() != Type::LongTy)
+ Val = new CastInst(Val, Type::LongTy, Val->getName(), AfterPHIIt);
+ Idx.push_back(Val);
+ Val = new GetElementPtrInst(IV.Start, Idx,
+ Phi->getName()+"-offset",
+ AfterPHIIt);
+
+ } else if (!isa(IV.Start) || // If Start != 0...
+ !cast(IV.Start)->isNullValue()) {
+ // If the types are not compatible, insert a cast now...
+ if (IV.Start->getType() != IVTy)
+ IV.Start = new CastInst(IV.Start, IVTy, IV.Start->getName(),
+ AfterPHIIt);
+
+ // Insert the instruction after the phi nodes...
+ Val = BinaryOperator::create(Instruction::Add, Val, IV.Start,
+ Phi->getName()+"-offset", AfterPHIIt);
+ }
+
+ // If the PHI node has a different type than val is, insert a cast now...
+ if (Val->getType() != Phi->getType())
+ Val = new CastInst(Val, Phi->getType(), Val->getName(), AfterPHIIt);
+
+ // Move the PHI name to it's new equivalent value...
+ std::string OldName = Phi->getName();
+ Phi->setName("");
+ Val->setName(OldName);
+
+ return Val;
+}
+
+
+// ReplaceIndVar - Replace all uses of the specified induction variable with
+// expressions computed from the specified loop iteration counter variable.
+// Return true if instructions were deleted.
+void IndVarSimplify::ReplaceIndVar(InductionVariable &IV, Value *CIV) {
+ Value *IndVarVal = 0;
+ PHINode *Phi = IV.Phi;
+
+ assert(Phi->getNumOperands() == 4 &&
+ "Only expect induction variables in canonical loops!");
+
+ // Remember the incoming values used by the PHI node
+ std::vector PHIOps;
+ PHIOps.reserve(2);
+ PHIOps.push_back(Phi->getIncomingValue(0));
+ PHIOps.push_back(Phi->getIncomingValue(1));
+
+ // Delete all of the operands of the PHI node... FIXME, this should be more
+ // intelligent.
+ Phi->dropAllReferences();
+
+ // Now that we are rid of unneeded uses of the PHI node, replace any remaining
+ // ones with the appropriate code using the canonical induction variable.
+ while (!Phi->use_empty()) {
+ Instruction *U = cast(Phi->use_back());
+
+ // TODO: Perform LFTR here if possible
+ if (0) {
+
+ } else {
// Replace all uses of the old PHI node with the new computed value...
- IV->Phi->replaceAllUsesWith(Val);
+ if (IndVarVal == 0)
+ IndVarVal = ComputeAuxIndVarValue(IV, CIV);
+ U->replaceUsesOfWith(Phi, IndVarVal);
+ }
+ }
- // Move the PHI name to it's new equivalent value...
- std::string OldName = IV->Phi->getName();
- IV->Phi->setName("");
- Val->setName(OldName);
-
- // Get the incoming values used by the PHI node
- std::vector PHIOps;
- PHIOps.reserve(IV->Phi->getNumIncomingValues());
- for (unsigned i = 0, e = IV->Phi->getNumIncomingValues(); i != e; ++i)
- PHIOps.push_back(IV->Phi->getIncomingValue(i));
-
- // Delete the old, now unused, phi node...
- Header->getInstList().erase(IV->Phi);
-
- // If the PHI is the last user of any instructions for computing PHI nodes
- // that are irrelevant now, delete those instructions.
- while (!PHIOps.empty()) {
- Instruction *MaybeDead = dyn_cast(PHIOps.back());
- PHIOps.pop_back();
-
- if (MaybeDead && isInstructionTriviallyDead(MaybeDead)) {
- PHIOps.insert(PHIOps.end(), MaybeDead->op_begin(),
- MaybeDead->op_end());
- MaybeDead->getParent()->getInstList().erase(MaybeDead);
-
- // Erase any duplicates entries in the PHIOps list.
- std::vector::iterator It =
- std::find(PHIOps.begin(), PHIOps.end(), MaybeDead);
- while (It != PHIOps.end()) {
- PHIOps.erase(It);
- It = std::find(PHIOps.begin(), PHIOps.end(), MaybeDead);
- }
-
- // Erasing the instruction could invalidate the AfterPHI iterator!
- AfterPHIIt = Header->begin();
- }
+ // If the PHI is the last user of any instructions for computing PHI nodes
+ // that are irrelevant now, delete those instructions.
+ while (!PHIOps.empty()) {
+ Instruction *MaybeDead = dyn_cast(PHIOps.back());
+ PHIOps.pop_back();
+
+ if (MaybeDead && isInstructionTriviallyDead(MaybeDead) &&
+ (!isa(MaybeDead) ||
+ MaybeDead->getParent() != Phi->getParent())) {
+ PHIOps.insert(PHIOps.end(), MaybeDead->op_begin(),
+ MaybeDead->op_end());
+ MaybeDead->getParent()->getInstList().erase(MaybeDead);
+
+ // Erase any duplicates entries in the PHIOps list.
+ std::vector::iterator It =
+ std::find(PHIOps.begin(), PHIOps.end(), MaybeDead);
+ while (It != PHIOps.end()) {
+ PHIOps.erase(It);
+ It = std::find(PHIOps.begin(), PHIOps.end(), MaybeDead);
}
-
- Changed = true;
- ++NumRemoved;
}
}
- return Changed;
+ // Delete the old, now unused, phi node...
+ Phi->getParent()->getInstList().erase(Phi);
}
From vadve at cs.uiuc.edu Mon Dec 22 13:25:38 2003
From: vadve at cs.uiuc.edu (Vikram Adve)
Date: Mon Dec 22 13:25:38 2003
Subject: [llvm-commits] CVS: llvm-www/www-index.html
Message-ID: <200312221852.MAA02440@psmith.cs.uiuc.edu>
Changes in directory llvm-www:
www-index.html updated: 1.93 -> 1.94
---
Log message:
Fix paragraph on outside contributions.
---
Diffs of the changes: (+5 -5)
Index: llvm-www/www-index.html
diff -u llvm-www/www-index.html:1.93 llvm-www/www-index.html:1.94
--- llvm-www/www-index.html:1.93 Wed Dec 17 17:02:40 2003
+++ llvm-www/www-index.html Mon Dec 22 12:52:44 2003
@@ -61,15 +61,15 @@
even if you only have a semester in a University course.
- LLVM was originally a product of the LLVM is a product of the Lifelong
Code Optimization Project, led by Vikram Adve in the Department of Computer Science at the
- University of Illinois,
- Urbana-Champaign. Since our initial public release, however, our
- scope has expanded to include contributions from several other people!
+ University of Illinois,
+ Urbana-Champaign. Since our public release, LLVM grown to include
+ contributions from several other people! We welcome external contributions, so please send e-mail to llvmdev at cs.uiuc.edu if you are interested in contributing code to the LLVM infrastructure.
Want to learn more?
From criswell at cs.uiuc.edu Mon Dec 22 13:26:28 2003
From: criswell at cs.uiuc.edu (John Criswell)
Date: Mon Dec 22 13:26:28 2003
Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/ArchiveReader.cpp
Message-ID: <200312221623.KAA02113@choi.cs.uiuc.edu>
Changes in directory llvm/lib/Bytecode/Reader:
ArchiveReader.cpp updated: 1.12 -> 1.13
---
Log message:
Reverted back to revision 1.11. The previous fix doesn't really fix
anything; it just causes the bug to go dormant.
---
Diffs of the changes: (+3 -12)
Index: llvm/lib/Bytecode/Reader/ArchiveReader.cpp
diff -u llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.12 llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.13
--- llvm/lib/Bytecode/Reader/ArchiveReader.cpp:1.12 Sat Dec 20 16:37:29 2003
+++ llvm/lib/Bytecode/Reader/ArchiveReader.cpp Mon Dec 22 10:22:49 2003
@@ -122,17 +122,8 @@
while (endp[-1] == ' ')
--endp;
}
-
- //
- // We now have the beginning and the end of the object name.
- // Convert this into a dynamically allocated std::string to pass
- // to the routines that create the Module object. We do this
- // (I think) because the created Module object will outlive this function,
- // but statically declared std::string's won't.
- //
std::string MemberName (startp, endp);
- std::string * FullMemberName;
- FullMemberName = new std::string (ArchiveName + "(" + MemberName + ")");
+ std::string FullMemberName = ArchiveName + "(" + MemberName + ")";
switch (getObjectType(Hdr, MemberData, MemberSize)) {
case SVR4LongFilename:
@@ -142,7 +133,7 @@
break;
case UserObject: {
Module *M = ParseBytecodeBuffer(MemberData, MemberSize,
- *(FullMemberName), ErrorStr);
+ FullMemberName, ErrorStr);
if (!M) return true;
Objects.push_back(M);
break;
@@ -153,7 +144,7 @@
break;
default:
std::cerr << "ReadArchiveBuffer: WARNING: Skipping unknown file: "
- << *(FullMemberName) << "\n";
+ << FullMemberName << "\n";
break; // Just ignore unknown files.
}
From alkis at cs.uiuc.edu Mon Dec 22 13:26:43 2003
From: alkis at cs.uiuc.edu (Alkis Evlogimenos)
Date: Mon Dec 22 13:26:43 2003
Subject: [llvm-commits] CVS: llvm/lib/CodeGen/LiveIntervals.cpp
Message-ID: <200312221354.HAA06680@morpheus.cs.uiuc.edu>
Changes in directory llvm/lib/CodeGen:
LiveIntervals.cpp updated: 1.14 -> 1.15
---
Log message:
Fix crash when compiling twolf.
---
Diffs of the changes: (+2 -1)
Index: llvm/lib/CodeGen/LiveIntervals.cpp
diff -u llvm/lib/CodeGen/LiveIntervals.cpp:1.14 llvm/lib/CodeGen/LiveIntervals.cpp:1.15
--- llvm/lib/CodeGen/LiveIntervals.cpp:1.14 Sun Dec 21 14:19:10 2003
+++ llvm/lib/CodeGen/LiveIntervals.cpp Mon Dec 22 07:54:29 2003
@@ -146,7 +146,8 @@
unsigned liveBlockIndex = it->first;
MachineBasicBlock* liveBlock = it->second;
if (liveBlockIndex < vi.AliveBlocks.size() &&
- vi.AliveBlocks[liveBlockIndex]) {
+ vi.AliveBlocks[liveBlockIndex] &&
+ !liveBlock->empty()) {
unsigned start = getInstructionIndex(liveBlock->front());
unsigned end = getInstructionIndex(liveBlock->back()) + 1;
interval->addRange(start, end);
From brukman at cs.uiuc.edu Mon Dec 22 17:15:02 2003
From: brukman at cs.uiuc.edu (Misha Brukman)
Date: Mon Dec 22 17:15:02 2003
Subject: [llvm-commits] CVS: llvm-www/www-index.html
Message-ID: <200312222314.RAA07214@zion.cs.uiuc.edu>
Changes in directory llvm-www:
www-index.html updated: 1.94 -> 1.95
---
Log message:
* `has grown' instead of `grown'
* Wrap code (as much as possible) at 80 columns
---
Diffs of the changes: (+5 -2)
Index: llvm-www/www-index.html
diff -u llvm-www/www-index.html:1.94 llvm-www/www-index.html:1.95
--- llvm-www/www-index.html:1.94 Mon Dec 22 12:52:44 2003
+++ llvm-www/www-index.html Mon Dec 22 17:14:04 2003
@@ -67,9 +67,12 @@
href="http://www-faculty.cs.uiuc.edu/~vadve/">Vikram Adve in the Department of Computer Science at the
University of Illinois,
- Urbana-Champaign. Since our public release, LLVM grown to include
+ Urbana-Champaign. Since our public release, LLVM has grown to include
contributions from several other people! We welcome external contributions, so please send e-mail to llvmdev at cs.uiuc.edu if you are interested in contributing code to the LLVM infrastructure.
+ href="/cvsweb/cvsweb.cgi/llvm/CREDITS.TXT?rev=HEAD&content-type=text/x-cvsweb-markup">several
+ other people! We welcome external contributions, so please send e-mail
+ to llvmdev at cs.uiuc.edu if you are
+ interested in contributing code to the LLVM infrastructure.
Want to learn more?
From lattner at cs.uiuc.edu Mon Dec 22 17:50:01 2003
From: lattner at cs.uiuc.edu (Chris Lattner)
Date: Mon Dec 22 17:50:01 2003
Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/ConstantMerge.cpp
Message-ID: <200312222349.RAA07970@zion.cs.uiuc.edu>
Changes in directory llvm/lib/Transforms/IPO:
ConstantMerge.cpp updated: 1.24 -> 1.25
---
Log message:
Fix memory corruption bug PR193
---
Diffs of the changes: (+26 -20)
Index: llvm/lib/Transforms/IPO/ConstantMerge.cpp
diff -u llvm/lib/Transforms/IPO/ConstantMerge.cpp:1.24 llvm/lib/Transforms/IPO/ConstantMerge.cpp:1.25
--- llvm/lib/Transforms/IPO/ConstantMerge.cpp:1.24 Fri Nov 21 15:54:21 2003
+++ llvm/lib/Transforms/IPO/ConstantMerge.cpp Mon Dec 22 17:49:36 2003
@@ -40,8 +40,15 @@
bool ConstantMerge::run(Module &M) {
std::map CMap;
- bool MadeChanges = false;
-
+
+ // Replacements - This vector contains a list of replacements to perform.
+ std::vector > Replacements;
+
+ // First pass: identify all globals that can be merged together, filling in
+ // the Replacements vector. We cannot do the replacement in this pass because
+ // doing so may cause initializers of other globals to be rewritten,
+ // invalidating the Constant* pointers in CMap.
+ //
for (Module::giterator GV = M.gbegin(), E = M.gend(); GV != E; ++GV)
// Only process constants with initializers
if (GV->isConstant() && GV->hasInitializer()) {
@@ -54,28 +61,27 @@
CMap.insert(I, std::make_pair(Init, GV));
} else if (GV->hasInternalLinkage()) { // Yup, this is a duplicate!
// Make all uses of the duplicate constant use the canonical version...
- GV->replaceAllUsesWith(I->second);
-
- // Delete the global value from the module... and back up iterator to
- // not skip the next global...
- GV = --M.getGlobalList().erase(GV);
-
- ++NumMerged;
- MadeChanges = true;
+ Replacements.push_back(std::make_pair(GV, I->second));
} else if (I->second->hasInternalLinkage()) {
// Make all uses of the duplicate constant use the canonical version...
- I->second->replaceAllUsesWith(GV);
-
- // Delete the global value from the module... and back up iterator to
- // not skip the next global...
- M.getGlobalList().erase(I->second);
+ Replacements.push_back(std::make_pair(I->second, GV));
I->second = GV;
-
- ++NumMerged;
- MadeChanges = true;
}
}
- return MadeChanges;
-}
+ if (Replacements.empty()) return false;
+ CMap.clear();
+ // Now that we have figured out which replacements must be made, do them all
+ // now. This avoid invalidating the pointers in CMap, which are unneeded now.
+ for (unsigned i = 0, e = Replacements.size(); i != e; ++i) {
+ // Eliminate any uses of the dead global...
+ Replacements[i].first->replaceAllUsesWith(Replacements[i].second);
+
+ // Delete the global value from the module...
+ M.getGlobalList().erase(Replacements[i].first);
+ }
+
+ NumMerged += Replacements.size();
+ return true;
+}
From lattner at cs.uiuc.edu Mon Dec 22 17:57:01 2003
From: lattner at cs.uiuc.edu (Chris Lattner)
Date: Mon Dec 22 17:57:01 2003
Subject: [llvm-commits] CVS: llvm/docs/ReleaseNotes.html
Message-ID: <200312222356.RAA22711@choi.cs.uiuc.edu>
Changes in directory llvm/docs:
ReleaseNotes.html updated: 1.93 -> 1.94
---
Log message:
bug fixed
---
Diffs of the changes: (+3 -1)
Index: llvm/docs/ReleaseNotes.html
diff -u llvm/docs/ReleaseNotes.html:1.93 llvm/docs/ReleaseNotes.html:1.94
--- llvm/docs/ReleaseNotes.html:1.93 Sun Dec 21 22:06:24 2003
+++ llvm/docs/ReleaseNotes.html Mon Dec 22 17:56:37 2003
@@ -151,6 +151,8 @@
infrequent crash
[indvars] Induction variable
canonicalization always makes 32-bit indvars
+[constantmerge] Merging globals can
+cause use of invalid pointers!
@@ -596,7 +598,7 @@
src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" />
The LLVM Compiler Infrastructure
- Last modified: $Date: 2003/12/22 04:06:24 $
+ Last modified: $Date: 2003/12/22 23:56:37 $