From lattner at cs.uiuc.edu Mon Mar 3 10:13:02 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 10:13:02 2003 Subject: [llvm-commits] CVS: llvm/test/Programs/MultiSource/Ptrdist-ft/random.c-back Fsanity.c random.c Message-ID: <200303031612.KAA10151@apoc.cs.uiuc.edu> Changes in directory llvm/test/Programs/MultiSource/Ptrdist-ft: random.c-back added (r1.1) Fsanity.c updated: 1.1 -> 1.2 random.c (r1.1) removed --- Log message: Get the benchmark to compile! --- Diffs of the changes: Index: llvm/test/Programs/MultiSource/Ptrdist-ft/Fsanity.c diff -u llvm/test/Programs/MultiSource/Ptrdist-ft/Fsanity.c:1.1 llvm/test/Programs/MultiSource/Ptrdist-ft/Fsanity.c:1.2 --- llvm/test/Programs/MultiSource/Ptrdist-ft/Fsanity.c:1.1 Tue Nov 5 12:47:47 2002 +++ llvm/test/Programs/MultiSource/Ptrdist-ft/Fsanity.c Mon Mar 3 10:11:58 2003 @@ -24,7 +24,7 @@ * * ------------------------------------------------------------------------ * - * $Id: Fsanity.c,v 1.1 2002/11/05 18:47:47 hldnbrnd Exp $ + * $Id: Fsanity.c,v 1.2 2003/03/03 16:11:58 lattner Exp $ * */ @@ -158,7 +158,7 @@ h1 = h; do { - PrintItem(ITEM(h1)); + //PrintItem(ITEM(h1)); printf("[%u] ", RANK(h1)); PrettyPrint(CHILD(h1)); h1 = FORWARD(h1); From lattner at cs.uiuc.edu Mon Mar 3 11:14:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 11:14:01 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/Analysis/DSNode.h Message-ID: <200303031713.LAA10336@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm/Analysis: DSNode.h updated: 1.22 -> 1.23 --- Log message: Don't apply type information to loads --- Diffs of the changes: Index: llvm/include/llvm/Analysis/DSNode.h diff -u llvm/include/llvm/Analysis/DSNode.h:1.22 llvm/include/llvm/Analysis/DSNode.h:1.23 --- llvm/include/llvm/Analysis/DSNode.h:1.22 Thu Feb 13 13:08:57 2003 +++ llvm/include/llvm/Analysis/DSNode.h Mon Mar 3 11:13:22 2003 @@ -181,7 +181,8 @@ /// This method returns true if the node is completely folded, otherwise /// false. /// - bool mergeTypeInfo(const Type *Ty, unsigned Offset); + bool mergeTypeInfo(const Type *Ty, unsigned Offset, + bool FoldIfIncompatible = true); /// foldNodeCompletely - If we determine that this node has some funny /// behavior happening to it that we cannot represent, we fold it down to a From lattner at cs.uiuc.edu Mon Mar 3 11:14:04 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 11:14:04 2003 Subject: [llvm-commits] CVS: llvm/lib/Analysis/DataStructure/DataStructure.cpp Local.cpp Message-ID: <200303031713.LAA10345@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Analysis/DataStructure: DataStructure.cpp updated: 1.96 -> 1.97 Local.cpp updated: 1.51 -> 1.52 --- Log message: Don't apply type information to load instructions if it will cause collapsing --- Diffs of the changes: Index: llvm/lib/Analysis/DataStructure/DataStructure.cpp diff -u llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.96 llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.97 --- llvm/lib/Analysis/DataStructure/DataStructure.cpp:1.96 Fri Feb 14 17:27:18 2003 +++ llvm/lib/Analysis/DataStructure/DataStructure.cpp Mon Mar 3 11:13:31 2003 @@ -152,7 +152,8 @@ /// /// This method returns true if the node is completely folded, otherwise false. /// -bool DSNode::mergeTypeInfo(const Type *NewTy, unsigned Offset) { +bool DSNode::mergeTypeInfo(const Type *NewTy, unsigned Offset, + bool FoldIfIncompatible) { // Check to make sure the Size member is up-to-date. Size can be one of the // following: // Size = 0, Ty = Void: Nothing is known about this node. @@ -213,14 +214,14 @@ // It is illegal to grow this node if we have treated it as an array of // objects... if (isArray()) { - foldNodeCompletely(); + if (FoldIfIncompatible) foldNodeCompletely(); return true; } if (Offset) { // We could handle this case, but we don't for now... DEBUG(std::cerr << "UNIMP: Trying to merge a growth type into " << "offset != 0: Collapsing!\n"); - foldNodeCompletely(); + if (FoldIfIncompatible) foldNodeCompletely(); return true; } @@ -277,7 +278,7 @@ break; } default: - foldNodeCompletely(); + if (FoldIfIncompatible) foldNodeCompletely(); return true; } } @@ -356,7 +357,7 @@ << "\n due to:" << NewTy << " @ " << Offset << "!\n" << "SubType: " << SubType << "\n\n"); - foldNodeCompletely(); + if (FoldIfIncompatible) foldNodeCompletely(); return true; } Index: llvm/lib/Analysis/DataStructure/Local.cpp diff -u llvm/lib/Analysis/DataStructure/Local.cpp:1.51 llvm/lib/Analysis/DataStructure/Local.cpp:1.52 --- llvm/lib/Analysis/DataStructure/Local.cpp:1.51 Thu Feb 13 22:55:58 2003 +++ llvm/lib/Analysis/DataStructure/Local.cpp Mon Mar 3 11:13:31 2003 @@ -368,7 +368,7 @@ Ptr.getNode()->NodeType |= DSNode::Read; // Ensure a typerecord exists... - Ptr.getNode()->mergeTypeInfo(LI.getType(), Ptr.getOffset()); + Ptr.getNode()->mergeTypeInfo(LI.getType(), Ptr.getOffset(), false); if (isPointerType(LI.getType())) setDestTo(LI, getLink(Ptr)); From lattner at cs.uiuc.edu Mon Mar 3 11:26:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 11:26:01 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/Transforms/Utils/PromoteMemToReg.h Message-ID: <200303031725.LAA10511@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm/Transforms/Utils: PromoteMemToReg.h updated: 1.1 -> 1.2 --- Log message: Change the mem2reg interface to accept a TargetData argument --- Diffs of the changes: Index: llvm/include/llvm/Transforms/Utils/PromoteMemToReg.h diff -u llvm/include/llvm/Transforms/Utils/PromoteMemToReg.h:1.1 llvm/include/llvm/Transforms/Utils/PromoteMemToReg.h:1.2 --- llvm/include/llvm/Transforms/Utils/PromoteMemToReg.h:1.1 Sat Feb 22 17:04:52 2003 +++ llvm/include/llvm/Transforms/Utils/PromoteMemToReg.h Mon Mar 3 11:25:15 2003 @@ -10,12 +10,13 @@ class AllocaInst; class DominanceFrontier; +class TargetData; #include /// isAllocaPromotable - Return true if this alloca is legal for promotion. /// This is true if there are only loads and stores to the alloca... /// -bool isAllocaPromotable(const AllocaInst *AI); +bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD); /// PromoteMemToReg - Promote the specified list of alloca instructions into /// scalar registers, inserting PHI nodes as appropriate. This function makes @@ -23,7 +24,6 @@ /// of the function at all. All allocas must be from the same function. /// void PromoteMemToReg(const std::vector &Allocas, - DominanceFrontier &DF); - + DominanceFrontier &DF, const TargetData &TD); #endif From lattner at cs.uiuc.edu Mon Mar 3 11:26:02 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 11:26:02 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LICM.cpp Mem2Reg.cpp Message-ID: <200303031725.LAA10520@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LICM.cpp updated: 1.24 -> 1.25 Mem2Reg.cpp updated: 1.1 -> 1.2 --- Log message: Change the mem2reg interface to accept a TargetData argument --- Diffs of the changes: Index: llvm/lib/Transforms/Scalar/LICM.cpp diff -u llvm/lib/Transforms/Scalar/LICM.cpp:1.24 llvm/lib/Transforms/Scalar/LICM.cpp:1.25 --- llvm/lib/Transforms/Scalar/LICM.cpp:1.24 Fri Feb 28 13:21:40 2003 +++ llvm/lib/Transforms/Scalar/LICM.cpp Mon Mar 3 11:25:16 2003 @@ -27,6 +27,7 @@ #include "llvm/Analysis/Dominators.h" #include "llvm/Instructions.h" #include "llvm/DerivedTypes.h" +#include "llvm/Target/TargetData.h" #include "llvm/Support/InstVisitor.h" #include "llvm/Support/CFG.h" #include "Support/Statistic.h" @@ -457,7 +458,8 @@ PromotedAllocas.reserve(PromotedValues.size()); for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i) PromotedAllocas.push_back(PromotedValues[i].first); - PromoteMemToReg(PromotedAllocas, getAnalysis()); + PromoteMemToReg(PromotedAllocas, getAnalysis(), + AA->getTargetData()); } /// findPromotableValuesInLoop - Check the current loop for stores to definate Index: llvm/lib/Transforms/Scalar/Mem2Reg.cpp diff -u llvm/lib/Transforms/Scalar/Mem2Reg.cpp:1.1 llvm/lib/Transforms/Scalar/Mem2Reg.cpp:1.2 --- llvm/lib/Transforms/Scalar/Mem2Reg.cpp:1.1 Sat Feb 22 17:57:06 2003 +++ llvm/lib/Transforms/Scalar/Mem2Reg.cpp Mon Mar 3 11:25:16 2003 @@ -10,6 +10,7 @@ #include "llvm/Analysis/Dominators.h" #include "llvm/iMemory.h" #include "llvm/Function.h" +#include "llvm/Target/TargetData.h" #include "Support/Statistic.h" namespace { @@ -25,6 +26,7 @@ // virtual void getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); + AU.addRequired(); AU.setPreservesCFG(); } }; @@ -34,6 +36,7 @@ bool PromotePass::runOnFunction(Function &F) { std::vector Allocas; + const TargetData &TD = getAnalysis(); BasicBlock &BB = F.getEntryNode(); // Get the entry node for the function @@ -41,11 +44,11 @@ // the entry node for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) if (AllocaInst *AI = dyn_cast(&*I)) // Is it an alloca? - if (isAllocaPromotable(AI)) + if (isAllocaPromotable(AI, TD)) Allocas.push_back(AI); if (!Allocas.empty()) { - PromoteMemToReg(Allocas, getAnalysis()); + PromoteMemToReg(Allocas, getAnalysis(), TD); NumPromoted += Allocas.size(); return true; } From lattner at cs.uiuc.edu Mon Mar 3 11:26:03 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 11:26:03 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Message-ID: <200303031725.LAA10527@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: PromoteMemoryToRegister.cpp updated: 1.35 -> 1.36 --- Log message: Change the mem2reg interface to accept a TargetData argument --- Diffs of the changes: Index: llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp diff -u llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.35 llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.36 --- llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp:1.35 Sat Feb 22 17:57:48 2003 +++ llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp Mon Mar 3 11:25:18 2003 @@ -28,7 +28,10 @@ /// isAllocaPromotable - Return true if this alloca is legal for promotion. /// This is true if there are only loads and stores to the alloca... /// -bool isAllocaPromotable(const AllocaInst *AI) { +bool isAllocaPromotable(const AllocaInst *AI, const TargetData &TD) { + // FIXME: If the memory unit is of pointer or integer type, we can permit + // assignments to subsections of the memory unit. + // Only allow direct loads and stores... for (Value::use_const_iterator UI = AI->use_begin(), UE = AI->use_end(); UI != UE; ++UI) // Loop over all of the uses of the alloca @@ -48,6 +51,7 @@ struct PromoteMem2Reg { const std::vector &Allocas; // the alloca instructions.. DominanceFrontier &DF; + const TargetData &TD; std::map AllocaLookup; // reverse mapping of above @@ -60,8 +64,9 @@ std::vector > NewPhiNodes; // the PhiNodes we're adding public: - PromoteMem2Reg(const std::vector &A, DominanceFrontier &df) - :Allocas(A), DF(df) {} + PromoteMem2Reg(const std::vector &A, DominanceFrontier &df, + const TargetData &td) + : Allocas(A), DF(df), TD(td) {} void run(); @@ -81,7 +86,7 @@ Function &F = *DF.getRoot()->getParent(); for (unsigned i = 0, e = Allocas.size(); i != e; ++i) { - assert(isAllocaPromotable(Allocas[i]) && + assert(isAllocaPromotable(Allocas[i], TD) && "Cannot promote non-promotable alloca!"); assert(Allocas[i]->getParent()->getParent() == &F && "All allocas should be in the same function, which is same as DF!"); @@ -240,6 +245,6 @@ /// of the function at all. All allocas must be from the same function. /// void PromoteMemToReg(const std::vector &Allocas, - DominanceFrontier &DF) { - PromoteMem2Reg(Allocas, DF).run(); + DominanceFrontier &DF, const TargetData &TD) { + PromoteMem2Reg(Allocas, DF, TD).run(); } From lattner at cs.uiuc.edu Mon Mar 3 13:58:15 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 13:58:15 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/IPO/FunctionResolution.cpp Message-ID: <200303031957.NAA20614@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/IPO: FunctionResolution.cpp updated: 1.22 -> 1.23 --- Log message: Eliminate tons of bogus warnings --- Diffs of the changes: Index: llvm/lib/Transforms/IPO/FunctionResolution.cpp diff -u llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.22 llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.23 --- llvm/lib/Transforms/IPO/FunctionResolution.cpp:1.22 Thu Feb 27 14:55:48 2003 +++ llvm/lib/Transforms/IPO/FunctionResolution.cpp Mon Mar 3 13:57:46 2003 @@ -128,7 +128,8 @@ const FunctionType *OldMT = Old->getFunctionType(); const FunctionType *ConcreteMT = Concrete->getFunctionType(); - if (OldMT->getParamTypes().size() <= ConcreteMT->getParamTypes().size()) + if (OldMT->getParamTypes().size() < ConcreteMT->getParamTypes().size() && + !ConcreteMT->isVarArg()) if (!Old->use_empty()) { std::cerr << "WARNING: Linking function '" << Old->getName() << "' is causing arguments to be dropped.\n"; @@ -145,13 +146,14 @@ unsigned NumArguments = std::min(OldMT->getParamTypes().size(), ConcreteMT->getParamTypes().size()); - for (unsigned i = 0; i < NumArguments; ++i) - if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) { - std::cerr << "funcresolve: Function [" << Old->getName() - << "]: Parameter types conflict for: '" << OldMT - << "' and '" << ConcreteMT << "'\n"; - return Changed; - } + if (!Old->use_empty() && !Concrete->use_empty()) + for (unsigned i = 0; i < NumArguments; ++i) + if (OldMT->getParamTypes()[i] != ConcreteMT->getParamTypes()[i]) { + std::cerr << "WARNING: Function [" << Old->getName() + << "]: Parameter types conflict for: '" << OldMT + << "' and '" << ConcreteMT << "'\n"; + return Changed; + } // Attempt to convert all of the uses of the old function to the // concrete form of the function. If there is a use of the fn that From lattner at cs.uiuc.edu Mon Mar 3 14:29:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 14:29:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/CFrontend/2003-03-03-DeferredType.c Message-ID: <200303032028.OAA22749@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/CFrontend: 2003-03-03-DeferredType.c added (r1.1) --- Log message: Add new testcase for forward reference of struct type --- Diffs of the changes: From lattner at cs.uiuc.edu Mon Mar 3 15:30:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 15:30:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Assembler/2003-03-03-DuplicateConstant.ll Message-ID: <200303032129.PAA26247@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Assembler: 2003-03-03-DuplicateConstant.ll added (r1.1) --- Log message: New testcase --- Diffs of the changes: From lattner at cs.uiuc.edu Mon Mar 3 17:28:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 17:28:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/BasicAA/licmtest.ll Message-ID: <200303032327.RAA00738@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/BasicAA: licmtest.ll updated: 1.5 -> 1.6 --- Log message: Make the testcase more interesting, test that two different array elements don't alias --- Diffs of the changes: Index: llvm/test/Regression/Transforms/BasicAA/licmtest.ll diff -u llvm/test/Regression/Transforms/BasicAA/licmtest.ll:1.5 llvm/test/Regression/Transforms/BasicAA/licmtest.ll:1.6 --- llvm/test/Regression/Transforms/BasicAA/licmtest.ll:1.5 Wed Feb 26 10:18:00 2003 +++ llvm/test/Regression/Transforms/BasicAA/licmtest.ll Mon Mar 3 17:27:15 2003 @@ -10,6 +10,7 @@ %A = global int 7 %B = global int 8 +%C = global [2 x int ] [ int 4, int 8 ] implementation int %test(bool %c) { @@ -22,6 +23,23 @@ br bool %c, label %Out, label %Loop Out: %X = sub int %ToRemove, %Atmp + ret int %X +} + +int %test2(bool %c) { + br label %Loop +Loop: + %AVal = load int* %A + %C0 = getelementptr [2 x int ]* %C, long 0, long 0 + store int %AVal, int* %C0 ; Store cannot alias %A + + %BVal = load int* %B + %C1 = getelementptr [2 x int ]* %C, long 0, long 1 + store int %BVal, int* %C1 ; Store cannot alias %A, %B, or %C0 + + br bool %c, label %Out, label %Loop +Out: + %X = sub int %AVal, %BVal ret int %X } From lattner at cs.uiuc.edu Mon Mar 3 17:29:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 17:29:01 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/Analysis/AliasSetTracker.h Message-ID: <200303032328.RAA00755@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm/Analysis: AliasSetTracker.h updated: 1.3 -> 1.4 --- Log message: Add a few new 'add' methods. Move the iterator around --- Diffs of the changes: Index: llvm/include/llvm/Analysis/AliasSetTracker.h diff -u llvm/include/llvm/Analysis/AliasSetTracker.h:1.3 llvm/include/llvm/Analysis/AliasSetTracker.h:1.4 --- llvm/include/llvm/Analysis/AliasSetTracker.h:1.3 Wed Feb 26 16:10:55 2003 +++ llvm/include/llvm/Analysis/AliasSetTracker.h Mon Mar 3 17:27:52 2003 @@ -93,6 +93,36 @@ }; unsigned AliasTy : 1; + friend class ilist_traits; + AliasSet *getPrev() const { return Prev; } + AliasSet *getNext() const { return Next; } + void setPrev(AliasSet *P) { Prev = P; } + void setNext(AliasSet *N) { Next = N; } + +public: + /// Accessors... + bool isRef() const { return AccessTy & Refs; } + bool isMod() const { return AccessTy & Mods; } + bool isMustAlias() const { return AliasTy == MustAlias; } + bool isMayAlias() const { return AliasTy == MayAlias; } + + /// isForwardingAliasSet - Return true if this alias set should be ignored as + /// part of the AliasSetTracker object. + bool isForwardingAliasSet() const { return Forward; } + + /// mergeSetIn - Merge the specified alias set into this alias set... + /// + void mergeSetIn(AliasSet &AS); + + // Alias Set iteration - Allow access to all of the pointer which are part of + // this alias set... + class iterator; + iterator begin() const { return iterator(PtrListHead); } + iterator end() const { return iterator(); } + + void print(std::ostream &OS) const; + void dump() const; + /// Define an iterator for alias sets... this is just a forward iterator. class iterator : public forward_iterator { HashNodePair *CurNode; @@ -125,31 +155,6 @@ } }; - friend class ilist_traits; - AliasSet *getPrev() const { return Prev; } - AliasSet *getNext() const { return Next; } - void setPrev(AliasSet *P) { Prev = P; } - void setNext(AliasSet *N) { Next = N; } - -public: - /// Accessors... - bool isRef() const { return AccessTy & Refs; } - bool isMod() const { return AccessTy & Mods; } - bool isMustAlias() const { return AliasTy == MustAlias; } - bool isMayAlias() const { return AliasTy == MayAlias; } - - /// mergeSetIn - Merge the specified alias set into this alias set... - /// - void mergeSetIn(AliasSet &AS); - - // Alias Set iteration - Allow access to all of the pointer which are part of - // this alias set... - iterator begin() const { return iterator(PtrListHead); } - iterator end() const { return iterator(); } - - void print(std::ostream &OS) const; - void dump() const; - private: // Can only be created by AliasSetTracker AliasSet() : PtrListHead(0), PtrListTail(0), Forward(0), RefCount(0), @@ -216,10 +221,12 @@ /// void add(LoadInst *LI); void add(StoreInst *SI); - void add(CallSite CS); // Call/Invoke instructions - void add(CallInst *CI) { add(CallSite(CI)); } + void add(CallSite CS); // Call/Invoke instructions + void add(CallInst *CI) { add(CallSite(CI)); } void add(InvokeInst *II) { add(CallSite(II)); } - void add(Instruction *I); // Dispatch to one of the other add methods... + void add(Instruction *I); // Dispatch to one of the other add methods... + void add(BasicBlock &BB); // Add all instructions in basic block + void add(const AliasSetTracker &AST); // Add alias relations from another AST /// getAliasSets - Return the alias sets that are active. const ilist &getAliasSets() const { return AliasSets; } From lattner at cs.uiuc.edu Mon Mar 3 17:29:02 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 17:29:02 2003 Subject: [llvm-commits] CVS: llvm/lib/Analysis/AliasSetTracker.cpp Message-ID: <200303032328.RAA00764@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Analysis: AliasSetTracker.cpp updated: 1.4 -> 1.5 --- Log message: ADd two new 'add' methods --- Diffs of the changes: Index: llvm/lib/Analysis/AliasSetTracker.cpp diff -u llvm/lib/Analysis/AliasSetTracker.cpp:1.4 llvm/lib/Analysis/AliasSetTracker.cpp:1.5 --- llvm/lib/Analysis/AliasSetTracker.cpp:1.4 Wed Feb 26 16:11:00 2003 +++ llvm/lib/Analysis/AliasSetTracker.cpp Mon Mar 3 17:28:05 2003 @@ -211,6 +211,34 @@ add(II); } +void AliasSetTracker::add(BasicBlock &BB) { + for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ++I) + add(I); +} + +void AliasSetTracker::add(const AliasSetTracker &AST) { + assert(&AA == &AST.AA && + "Merging AliasSetTracker objects with different Alias Analyses!"); + + // Loop over all of the alias sets in AST, adding the pointers contained + // therein into the current alias sets. This can cause alias sets to be + // merged together in the current AST. + for (const_iterator I = AST.begin(), E = AST.end(); I != E; ++I) + if (!I->Forward) { // Ignore forwarding alias sets + AliasSet &AS = const_cast(*I); + + // If there are any call sites in the alias set, add them to this AST. + for (unsigned i = 0, e = AS.CallSites.size(); i != e; ++i) + add(AS.CallSites[i]); + + // Loop over all of the pointers in this alias set... + AliasSet::iterator I = AS.begin(), E = AS.end(); + for (; I != E; ++I) + addPointer(I->first, I->second.getSize(), + (AliasSet::AccessType)AS.AccessTy); + } +} + //===----------------------------------------------------------------------===// // AliasSet/AliasSetTracker Printing Support //===----------------------------------------------------------------------===// From lattner at cs.uiuc.edu Mon Mar 3 17:30:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 17:30:01 2003 Subject: [llvm-commits] CVS: llvm/lib/AsmParser/llvmAsmParser.y Message-ID: <200303032329.RAA00775@apoc.cs.uiuc.edu> Changes in directory llvm/lib/AsmParser: llvmAsmParser.y updated: 1.101 -> 1.102 --- Log message: Fix bug: Assembler/2003-03-03-DuplicateConstant.ll --- Diffs of the changes: Index: llvm/lib/AsmParser/llvmAsmParser.y diff -u llvm/lib/AsmParser/llvmAsmParser.y:1.101 llvm/lib/AsmParser/llvmAsmParser.y:1.102 --- llvm/lib/AsmParser/llvmAsmParser.y:1.101 Sun Feb 2 10:40:20 2003 +++ llvm/lib/AsmParser/llvmAsmParser.y Mon Mar 3 17:28:55 2003 @@ -501,10 +501,12 @@ // Otherwise, we are a simple redefinition of a value, check to see if it // is defined the same as the old one... - if (const Type *Ty = dyn_cast(Existing)) { - if (Ty == cast(V)) return true; // Yes, it's equal. + if (const Type *Ty = dyn_cast(Existing)) { + if (Ty == cast(V)) return true; // Yes, it's equal. // std::cerr << "Type: " << Ty->getDescription() << " != " // << cast(V)->getDescription() << "!\n"; + } else if (const Constant *C = dyn_cast(Existing)) { + if (C == V) return true; // Constants are equal to themselves } else if (GlobalVariable *EGV = dyn_cast(Existing)) { // We are allowed to redefine a global variable in two circumstances: // 1. If at least one of the globals is uninitialized or @@ -1097,8 +1099,8 @@ // ConstPool - Constants with optional names assigned to them. ConstPool : ConstPool OptAssign CONST ConstVal { - if (setValueName($4, $2)) { assert(0 && "No redefinitions allowed!"); } - InsertValue($4); + if (!setValueName($4, $2)) + InsertValue($4); } | ConstPool OptAssign TYPE TypesV { // Types can be defined in the const pool // Eagerly resolve types. This is not an optimization, this is a From lattner at cs.uiuc.edu Mon Mar 3 17:33:00 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Mon Mar 3 17:33:00 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/LICM.cpp Message-ID: <200303032332.RAA00792@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: LICM.cpp updated: 1.25 -> 1.26 --- Log message: Convert LICM over to use AliasSetTracker. Besides being nicer, this automatically allows LICM to use access sizes to help alias analysis be more precise. --- Diffs of the changes: Index: llvm/lib/Transforms/Scalar/LICM.cpp diff -u llvm/lib/Transforms/Scalar/LICM.cpp:1.25 llvm/lib/Transforms/Scalar/LICM.cpp:1.26 --- llvm/lib/Transforms/Scalar/LICM.cpp:1.25 Mon Mar 3 11:25:16 2003 +++ llvm/lib/Transforms/Scalar/LICM.cpp Mon Mar 3 17:32:45 2003 @@ -24,6 +24,7 @@ #include "llvm/Transforms/Utils/Local.h" #include "llvm/Analysis/LoopInfo.h" #include "llvm/Analysis/AliasAnalysis.h" +#include "llvm/Analysis/AliasSetTracker.h" #include "llvm/Analysis/Dominators.h" #include "llvm/Instructions.h" #include "llvm/DerivedTypes.h" @@ -43,106 +44,6 @@ Statistic<> NumHoistedLoads("licm", "Number of load insts hoisted"); Statistic<> NumPromoted("licm", "Number of memory locations promoted to registers"); - /// LoopBodyInfo - We recursively traverse loops from most-deeply-nested to - /// least-deeply-nested. For all of the loops nested within the current one, - /// we keep track of information so that we don't have to repeat queries. - /// - struct LoopBodyInfo { - std::vector Calls; // Call instructions in loop - std::vector Invokes; // Invoke instructions in loop - - // StoredPointers - Targets of store instructions... - std::set StoredPointers; - - // LoadedPointers - Source pointers for load instructions... - std::set LoadedPointers; - - enum PointerClass { - PointerUnknown = 0, // Nothing is known about this pointer yet - PointerMustStore, // Memory is stored to ONLY through this pointer - PointerMayStore, // Memory is stored to through this or other pointers - PointerNoStore // Memory is not modified in this loop - }; - - // PointerIsModified - Keep track of information as we find out about it in - // the loop body... - // - std::map PointerIsModified; - - /// CantModifyAnyPointers - Return true if no memory modifying instructions - /// occur in this loop. This is just a conservative approximation, because - /// a call may not actually store anything. - bool CantModifyAnyPointers() const { - return Calls.empty() && Invokes.empty() && StoredPointers.empty(); - } - - /// incorporate - Incorporate information about a subloop into the current - /// loop. - void incorporate(const LoopBodyInfo &OtherLBI); - void incorporate(BasicBlock &BB); // do the same for a basic block - - PointerClass getPointerInfo(Value *V, AliasAnalysis &AA) { - PointerClass &VInfo = PointerIsModified[V]; - if (VInfo == PointerUnknown) - VInfo = calculatePointerInfo(V, AA); - return VInfo; - } - private: - /// calculatePointerInfo - Calculate information about the specified - /// pointer. - PointerClass calculatePointerInfo(Value *V, AliasAnalysis &AA) const; - }; -} - -/// incorporate - Incorporate information about a subloop into the current loop. -void LoopBodyInfo::incorporate(const LoopBodyInfo &OtherLBI) { - // Do not incorporate NonModifiedPointers (which is just a cache) because it - // is too much trouble to make sure it's still valid. - Calls.insert (Calls.end(), OtherLBI.Calls.begin(), OtherLBI.Calls.end()); - Invokes.insert(Invokes.end(),OtherLBI.Invokes.begin(),OtherLBI.Invokes.end()); - StoredPointers.insert(OtherLBI.StoredPointers.begin(), - OtherLBI.StoredPointers.end()); - LoadedPointers.insert(OtherLBI.LoadedPointers.begin(), - OtherLBI.LoadedPointers.end()); -} - -void LoopBodyInfo::incorporate(BasicBlock &BB) { - for (BasicBlock::iterator I = BB.begin(), E = --BB.end(); I != E; ++I) - if (CallInst *CI = dyn_cast(&*I)) - Calls.push_back(CI); - else if (StoreInst *SI = dyn_cast(&*I)) - StoredPointers.insert(SI->getOperand(1)); - else if (LoadInst *LI = dyn_cast(&*I)) - LoadedPointers.insert(LI->getOperand(0)); - - if (InvokeInst *II = dyn_cast(BB.getTerminator())) - Invokes.push_back(II); -} - - -// calculatePointerInfo - Calculate information about the specified pointer. -LoopBodyInfo::PointerClass LoopBodyInfo::calculatePointerInfo(Value *V, - AliasAnalysis &AA) const { - for (unsigned i = 0, e = Calls.size(); i != e; ++i) - if (AA.getModRefInfo(Calls[i], V, ~0)) - return PointerMayStore; - - for (unsigned i = 0, e = Invokes.size(); i != e; ++i) - if (AA.getModRefInfo(Invokes[i], V, ~0)) - return PointerMayStore; - - PointerClass Result = PointerNoStore; - for (std::set::const_iterator I = StoredPointers.begin(), - E = StoredPointers.end(); I != E; ++I) - if (AA.alias(V, ~0, *I, ~0)) - if (V == *I) - Result = PointerMustStore; // If this is the only alias, return must - else - return PointerMayStore; // We have to return may - return Result; -} - -namespace { struct LICM : public FunctionPass, public InstVisitor { virtual bool runOnFunction(Function &F); @@ -154,7 +55,7 @@ AU.addRequiredID(LoopPreheadersID); AU.addRequired(); AU.addRequired(); - AU.addRequired(); + AU.addRequired(); // For scalar promotion (mem2reg) AU.addRequired(); } @@ -164,11 +65,11 @@ bool Changed; // Set to true when we change anything. BasicBlock *Preheader; // The preheader block of the current loop... Loop *CurLoop; // The current loop we are working on... - LoopBodyInfo *CurLBI; // Information about the current loop... + AliasSetTracker *CurAST; // AliasSet information for the current loop... /// visitLoop - Hoist expressions out of the specified loop... /// - void visitLoop(Loop *L, LoopBodyInfo &LBI); + void visitLoop(Loop *L, AliasSetTracker &AST); /// HoistRegion - Walk the specified region of the CFG (defined by all /// blocks dominated by the specified block, and that are in the current @@ -198,8 +99,8 @@ /// store into the memory location pointed to by V. /// bool pointerInvalidatedByLoop(Value *V) { - // Check to see if any of the basic blocks in CurLoop invalidate V. - return CurLBI->getPointerInfo(V, *AA) != LoopBodyInfo::PointerNoStore; + // Check to see if any of the basic blocks in CurLoop invalidate *V. + return CurAST->getAliasSetForPointer(V, 0).isMod(); } /// isLoopInvariant - Return true if the specified value is loop invariant @@ -269,8 +170,8 @@ const std::vector &TopLevelLoops = LI->getTopLevelLoops(); for (std::vector::const_iterator I = TopLevelLoops.begin(), E = TopLevelLoops.end(); I != E; ++I) { - LoopBodyInfo LBI; - LICM::visitLoop(*I, LBI); + AliasSetTracker AST(*AA); + LICM::visitLoop(*I, AST); } return Changed; } @@ -278,32 +179,32 @@ /// visitLoop - Hoist expressions out of the specified loop... /// -void LICM::visitLoop(Loop *L, LoopBodyInfo &LBI) { +void LICM::visitLoop(Loop *L, AliasSetTracker &AST) { // Recurse through all subloops before we process this loop... for (std::vector::const_iterator I = L->getSubLoops().begin(), E = L->getSubLoops().end(); I != E; ++I) { - LoopBodyInfo SubLBI; - LICM::visitLoop(*I, SubLBI); + AliasSetTracker SubAST(*AA); + LICM::visitLoop(*I, SubAST); // Incorporate information about the subloops into this loop... - LBI.incorporate(SubLBI); + AST.add(SubAST); } CurLoop = L; - CurLBI = &LBI; + CurAST = &AST; // Get the preheader block to move instructions into... Preheader = L->getLoopPreheader(); assert(Preheader&&"Preheader insertion pass guarantees we have a preheader!"); // Loop over the body of this loop, looking for calls, invokes, and stores. - // Because subloops have already been incorporated into LBI, we skip blocks in + // Because subloops have already been incorporated into AST, we skip blocks in // subloops. // const std::vector &LoopBBs = L->getBlocks(); for (std::vector::const_iterator I = LoopBBs.begin(), E = LoopBBs.end(); I != E; ++I) if (LI->getLoopFor(*I) == L) // Ignore blocks in subloops... - LBI.incorporate(**I); // Incorporate the specified basic block + AST.add(**I); // Incorporate the specified basic block // We want to visit all of the instructions in this loop... that are not parts // of our subloops (they have already had their invariants hoisted out of @@ -472,57 +373,37 @@ std::map &ValueToAllocaMap) { Instruction *FnStart = CurLoop->getHeader()->getParent()->begin()->begin(); - for (std::set::iterator I = CurLBI->StoredPointers.begin(), - E = CurLBI->StoredPointers.end(); I != E; ++I) { - Value *V = *I; - if (isLoopInvariant(V) && - CurLBI->getPointerInfo(V, *AA) == LoopBodyInfo::PointerMustStore) { - - // Don't add a new entry for this stored pointer if it aliases something - // we have already processed. - std::map::iterator V2AMI = - ValueToAllocaMap.lower_bound(V); - if (V2AMI == ValueToAllocaMap.end() || V2AMI->first != V) { - // Check to make sure that any loads in the loop are either NO or MUST - // aliases. We cannot rewrite loads that _might_ come from this memory - // location. - - bool PointerOk = true; - for (std::set::const_iterator I =CurLBI->LoadedPointers.begin(), - E = CurLBI->LoadedPointers.end(); PointerOk && I != E; ++I) - switch (AA->alias(V, ~0, *I, ~0)) { - case AliasAnalysis::MustAlias: - if (V->getType() != (*I)->getType()) - PointerOk = false; - break; - case AliasAnalysis::MayAlias: - PointerOk = false; - case AliasAnalysis::NoAlias: - break; - } - - if (PointerOk) { - const Type *Ty = cast(V->getType())->getElementType(); - AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart); - PromotedValues.push_back(std::make_pair(AI, V)); - ValueToAllocaMap.insert(V2AMI, std::make_pair(V, AI)); - - DEBUG(std::cerr << "LICM: Promoting value: " << *V << "\n"); - - // Loop over all of the loads and stores that alias this pointer, - // adding them to the Value2AllocaMap as well... - for (std::set::const_iterator - I = CurLBI->LoadedPointers.begin(), - E = CurLBI->LoadedPointers.end(); I != E; ++I) - if (AA->alias(V, ~0, *I, ~0) == AliasAnalysis::MustAlias) - ValueToAllocaMap[*I] = AI; - - for (std::set::const_iterator - I = CurLBI->StoredPointers.begin(), - E = CurLBI->StoredPointers.end(); I != E; ++I) - if (AA->alias(V, ~0, *I, ~0) == AliasAnalysis::MustAlias) - ValueToAllocaMap[*I] = AI; + // Loop over all of the alias sets in the tracker object... + for (AliasSetTracker::iterator I = CurAST->begin(), E = CurAST->end(); + I != E; ++I) { + AliasSet &AS = *I; + // We can promote this alias set if it has a store, if it is a "Must" alias + // set, and if the pointer is loop invariant. + if (!AS.isForwardingAliasSet() && AS.isMod() && AS.isMustAlias() && + isLoopInvariant(AS.begin()->first)) { + assert(AS.begin() != AS.end() && + "Must alias set should have at least one pointer element in it!"); + Value *V = AS.begin()->first; + + // Check that all of the pointers in the alias set have the same type. We + // cannot (yet) promote a memory location that is loaded and stored in + // different sizes. + bool PointerOk = true; + for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I) + if (V->getType() != I->first->getType()) { + PointerOk = false; + break; } + + if (PointerOk) { + const Type *Ty = cast(V->getType())->getElementType(); + AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart); + PromotedValues.push_back(std::make_pair(AI, V)); + + for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I) + ValueToAllocaMap.insert(std::make_pair(I->first, AI)); + + DEBUG(std::cerr << "LICM: Promoting value: " << *V << "\n"); } } } From lattner at cs.uiuc.edu Tue Mar 4 10:35:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue Mar 4 10:35:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/BasicAA/2003-03-04-GEPCrash.ll Message-ID: <200303041634.KAA09084@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/BasicAA: 2003-03-04-GEPCrash.ll added (r1.1) --- Log message: New testcase --- Diffs of the changes: From lattner at cs.uiuc.edu Tue Mar 4 10:41:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue Mar 4 10:41:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Analysis/BasicAliasAnalysis.cpp Message-ID: <200303041640.KAA09257@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Analysis: BasicAliasAnalysis.cpp updated: 1.4 -> 1.5 --- Log message: Fix bug: BasicAA/2003-03-04-GEPCrash.ll --- Diffs of the changes: Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp diff -u llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.4 llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.5 --- llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.4 Sun Mar 2 17:43:34 2003 +++ llvm/lib/Analysis/BasicAliasAnalysis.cpp Tue Mar 4 10:40:17 2003 @@ -274,24 +274,18 @@ Indices1.push_back((Value*)Op1); else { // GEP1 is known to produce a value less than GEP2. To be - // conservatively correct, we must assume the largest - // possible constant is used in this position. This cannot - // be the initial index to the GEP instructions (because we - // know we have at least one element before this one with - // the different constant arguments), so we know that the - // current index must be into either a struct or array. - // Because of this, we can calculate the maximum value - // possible. + // conservatively correct, we must assume the largest possible constant + // is used in this position. This cannot be the initial index to the + // GEP instructions (because we know we have at least one element before + // this one with the different constant arguments), so we know that the + // current index must be into either a struct or array. Because we know + // it's not constant, this cannot be a structure index. Because of + // this, we can calculate the maximum value possible. // - const Type *ElTy = GEP1->getIndexedType(GEPPointerTy, - Indices1, true); - if (const StructType *STy = dyn_cast(ElTy)) { - Indices1.push_back(ConstantUInt::get(Type::UByteTy, - STy->getNumContainedTypes())); - } else { - Indices1.push_back(ConstantSInt::get(Type::LongTy, - cast(ElTy)->getNumElements())); - } + const ArrayType *ElTy = + cast(GEP1->getIndexedType(GEPPointerTy, Indices1, true)); + Indices1.push_back(ConstantSInt::get(Type::LongTy, + ElTy->getNumElements()-1)); } if (isa(Op2)) From lattner at cs.uiuc.edu Tue Mar 4 13:38:02 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue Mar 4 13:38:02 2003 Subject: [llvm-commits] CVS: llvm/www/docs/AliasAnalysis.html Message-ID: <200303041938.NAA05994@tank.cs.uiuc.edu> Changes in directory llvm/www/docs: AliasAnalysis.html added (r1.1) --- Log message: Initial checkin of AliasAnalysis doc --- Diffs of the changes: From lattner at cs.uiuc.edu Tue Mar 4 13:43:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue Mar 4 13:43:01 2003 Subject: [llvm-commits] CVS: llvm/www/www-index.html Message-ID: <200303041942.NAA06122@tank.cs.uiuc.edu> Changes in directory llvm/www: www-index.html updated: 1.14 -> 1.15 --- Log message: Add a link to the new AliasAnalysis documentation --- Diffs of the changes: Index: llvm/www/www-index.html diff -u llvm/www/www-index.html:1.14 llvm/www/www-index.html:1.15 --- llvm/www/www-index.html:1.14 Thu Feb 6 13:48:33 2003 +++ llvm/www/www-index.html Tue Mar 4 13:42:00 2003 @@ -193,6 +193,13 @@ + + + + + + We currently do not have an LLVM package available for public + consumption. However, we may be willing to make the LLVM + package available in beta form for people who are interested in + using it. Please contact + us if you are interested in trying it out as a beta + site.

+ + + + + + + + - - - - - - + + consumption. We are currently working towards making our "1.0" + release as solid and reliable as possible, and hope to have a + distribution available by sometime in Summer, 2003. If + you are interested in the project please + email us + and we will notify you when a release is available.

From lattner at cs.uiuc.edu Thu Mar 6 10:34:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 10:34:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/ReadConst.cpp ReadInst.cpp Reader.cpp Message-ID: <200303061633.KAA05636@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: ReadConst.cpp updated: 1.40 -> 1.41 ReadInst.cpp updated: 1.39 -> 1.40 Reader.cpp updated: 1.41 -> 1.42 --- Log message: Use the std namespace explicitly --- Diffs of the changes: Index: llvm/lib/Bytecode/Reader/ReadConst.cpp diff -u llvm/lib/Bytecode/Reader/ReadConst.cpp:1.40 llvm/lib/Bytecode/Reader/ReadConst.cpp:1.41 --- llvm/lib/Bytecode/Reader/ReadConst.cpp:1.40 Sun Oct 13 22:33:02 2002 +++ llvm/lib/Bytecode/Reader/ReadConst.cpp Thu Mar 6 10:32:25 2003 @@ -13,8 +13,6 @@ #include "llvm/Constants.h" #include -using std::make_pair; - const Type *BytecodeParser::parseTypeConstant(const uchar *&Buf, const uchar *EndBuf) { unsigned PrimType; @@ -336,7 +334,7 @@ if (!(GV = dyn_cast(Val))) return true; BCR_TRACE(5, "Value Found in ValueTable!\n"); } else { // Nope... find or create a forward ref. for it - GlobalRefsType::iterator I = GlobalRefs.find(make_pair(PT, Slot)); + GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PT, Slot)); if (I != GlobalRefs.end()) { BCR_TRACE(5, "Previous forward ref found!\n"); @@ -349,7 +347,7 @@ new GlobalVariable(PT->getElementType(), false, true); // Keep track of the fact that we have a forward ref to recycle it - GlobalRefs.insert(make_pair(make_pair(PT, Slot), GVar)); + GlobalRefs.insert(std::make_pair(std::make_pair(PT, Slot), GVar)); // Must temporarily push this value into the module table... TheModule->getGlobalList().push_back(GVar); Index: llvm/lib/Bytecode/Reader/ReadInst.cpp diff -u llvm/lib/Bytecode/Reader/ReadInst.cpp:1.39 llvm/lib/Bytecode/Reader/ReadInst.cpp:1.40 --- llvm/lib/Bytecode/Reader/ReadInst.cpp:1.39 Sun Oct 13 14:39:10 2002 +++ llvm/lib/Bytecode/Reader/ReadInst.cpp Thu Mar 6 10:32:25 2003 @@ -16,8 +16,6 @@ #include "llvm/iMemory.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" -using std::vector; -using std::cerr; bool BytecodeParser::ParseRawInst(const uchar *&Buf, const uchar *EndBuf, RawInst &Result) { @@ -78,7 +76,7 @@ switch (Result.NumOperands) { case 0: - cerr << "Zero Arg instr found!\n"; + std::cerr << "Zero Arg instr found!\n"; return true; // This encoding is invalid! case 1: if (read_vbr(Buf, EndBuf, Result.Arg1)) return true; @@ -97,7 +95,7 @@ read_vbr(Buf, EndBuf, Result.Arg2)) return true; // Allocate a vector to hold arguments 3, 4, 5, 6 ... - Result.VarArgs = new vector(Result.NumOperands-2); + Result.VarArgs = new std::vector(Result.NumOperands-2); for (unsigned a = 0; a < Result.NumOperands-2; a++) if (read_vbr(Buf, EndBuf, (*Result.VarArgs)[a])) return true; break; @@ -107,9 +105,9 @@ } #if 0 - cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode - << " Ty: " << Result.Ty->getDescription() << " arg1: " << Result.Arg1 - << " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << "\n"; + std::cerr << "NO: " << Result.NumOperands << " opcode: " << Result.Opcode + << " Ty: " << Result.Ty->getDescription() << " arg1: "<< Result.Arg1 + << " arg2: " << Result.Arg2 << " arg3: " << Result.Arg3 << "\n"; #endif return false; } @@ -135,7 +133,7 @@ case Instruction::Cast: { V = getValue(Raw.Ty, Raw.Arg1); const Type *Ty = getType(Raw.Arg2); - if (V == 0 || Ty == 0) { cerr << "Invalid cast!\n"; return true; } + if (V == 0 || Ty == 0) { std::cerr << "Invalid cast!\n"; return true; } Res = new CastInst(V, Ty); return false; } @@ -144,7 +142,7 @@ switch (Raw.NumOperands) { case 0: case 1: - case 3: cerr << "Invalid phi node encountered!\n"; + case 3: std::cerr << "Invalid phi node encountered!\n"; delete PN; return true; case 2: PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), @@ -154,11 +152,11 @@ PN->addIncoming(getValue(Raw.Ty, Raw.Arg1), cast(getValue(Type::LabelTy, Raw.Arg2))); if (Raw.VarArgs->size() & 1) { - cerr << "PHI Node with ODD number of arguments!\n"; + std::cerr << "PHI Node with ODD number of arguments!\n"; delete PN; return true; } else { - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; for (unsigned i = 0; i < args.size(); i+=2) PN->addIncoming(getValue(Raw.Ty, args[i]), cast(getValue(Type::LabelTy, args[i+1]))); @@ -204,12 +202,12 @@ if (Raw.NumOperands < 3) return false; // No destinations? Wierd. if (Raw.NumOperands == 3 || Raw.VarArgs->size() & 1) { - cerr << "Switch statement with odd number of arguments!\n"; + std::cerr << "Switch statement with odd number of arguments!\n"; delete I; return true; } - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; for (unsigned i = 0; i < args.size(); i += 2) I->dest_push_back(cast(getValue(Raw.Ty, args[i])), cast(getValue(Type::LabelTy, args[i+1]))); @@ -228,14 +226,14 @@ const FunctionType *MTy = dyn_cast(PTy->getElementType()); if (MTy == 0) return true; - vector Params; + std::vector Params; const FunctionType::ParamTypes &PL = MTy->getParamTypes(); if (!MTy->isVarArg()) { FunctionType::ParamTypes::const_iterator It = PL.begin(); switch (Raw.NumOperands) { - case 0: cerr << "Invalid call instruction encountered!\n"; + case 0: std::cerr << "Invalid call instruction encountered!\n"; return true; case 1: break; case 2: Params.push_back(getValue(*It++, Raw.Arg2)); break; @@ -245,7 +243,7 @@ default: Params.push_back(getValue(*It++, Raw.Arg2)); { - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; for (unsigned i = 0; i < args.size(); i++) { if (It == PL.end()) return true; // TODO: Check getValue for null! @@ -257,7 +255,7 @@ if (It != PL.end()) return true; } else { if (Raw.NumOperands > 2) { - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; if (args.size() < 1) return true; if ((args.size() & 1) != 0) @@ -288,9 +286,9 @@ const FunctionType *MTy = dyn_cast(PTy->getElementType()); if (MTy == 0) return true; - vector Params; + std::vector Params; const FunctionType::ParamTypes &PL = MTy->getParamTypes(); - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; BasicBlock *Normal, *Except; @@ -352,12 +350,12 @@ case Instruction::Load: case Instruction::GetElementPtr: { - vector Idx; + std::vector Idx; if (!isa(Raw.Ty)) return true; const CompositeType *TopTy = dyn_cast(Raw.Ty); switch (Raw.NumOperands) { - case 0: cerr << "Invalid load encountered!\n"; return true; + case 0: std::cerr << "Invalid load encountered!\n"; return true; case 1: break; case 2: if (!TopTy) return true; @@ -382,7 +380,7 @@ Idx.push_back(V = getValue(TopTy->getIndexType(), Raw.Arg2)); if (!V) return true; - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; for (unsigned i = 0, E = args.size(); i != E; ++i) { const Type *ETy = GetElementPtrInst::getIndexedType(Raw.Ty, Idx, true); const CompositeType *ElTy = dyn_cast_or_null(ETy); @@ -397,8 +395,8 @@ if (Raw.Opcode == Instruction::Load) { Value *Src = getValue(Raw.Ty, Raw.Arg1); if (!Idx.empty()) { - cerr << "WARNING: Bytecode contains load instruction with indices. " - << "Replacing with getelementptr/load pair\n"; + std::cerr << "WARNING: Bytecode contains load instruction with indices." + << " Replacing with getelementptr/load pair\n"; assert(GetElementPtrInst::getIndexedType(Raw.Ty, Idx) && "Bad indices for Load!"); Src = new GetElementPtrInst(Src, Idx); @@ -414,13 +412,13 @@ return false; } case Instruction::Store: { - vector Idx; + std::vector Idx; if (!isa(Raw.Ty)) return true; const CompositeType *TopTy = dyn_cast(Raw.Ty); switch (Raw.NumOperands) { case 0: - case 1: cerr << "Invalid store encountered!\n"; return true; + case 1: std::cerr << "Invalid store encountered!\n"; return true; case 2: break; case 3: if (!TopTy) return true; @@ -428,7 +426,7 @@ if (!V) return true; break; default: - vector &args = *Raw.VarArgs; + std::vector &args = *Raw.VarArgs; const CompositeType *ElTy = TopTy; unsigned i, E; for (i = 0, E = args.size(); ElTy && i != E; ++i) { @@ -447,8 +445,8 @@ Value *Ptr = getValue(Raw.Ty, Raw.Arg2); if (!Idx.empty()) { - cerr << "WARNING: Bytecode contains load instruction with indices. " - << "Replacing with getelementptr/load pair\n"; + std::cerr << "WARNING: Bytecode contains load instruction with indices. " + << "Replacing with getelementptr/load pair\n"; const Type *ElType = GetElementPtrInst::getIndexedType(Raw.Ty, Idx); if (ElType == 0) return true; @@ -465,7 +463,7 @@ } } // end switch(Raw.Opcode) - cerr << "Unrecognized instruction! " << Raw.Opcode - << " ADDR = 0x" << (void*)Buf << "\n"; + std::cerr << "Unrecognized instruction! " << Raw.Opcode + << " ADDR = 0x" << (void*)Buf << "\n"; return true; } Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.41 llvm/lib/Bytecode/Reader/Reader.cpp:1.42 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.41 Wed Nov 20 12:31:59 2002 +++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Mar 6 10:32:25 2003 @@ -23,9 +23,6 @@ #include #include #include -using std::cerr; -using std::pair; -using std::make_pair; bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) { if (Ty->isPrimitiveType()) { @@ -115,8 +112,8 @@ Value *d = 0; switch (Ty->getPrimitiveID()) { case Type::FunctionTyID: - cerr << "Creating method pholder! : " << type << ":" << oNum << " " - << Ty->getName() << "\n"; + std::cerr << "Creating method pholder! : " << type << ":" << oNum << " " + << Ty->getName() << "\n"; d = new FunctionPHolder(Ty, oNum); if (insertValue(d, LateResolveModuleValues) == -1) return 0; return d; @@ -143,7 +140,7 @@ if (Value *V = getValue(Ty, Slot, false)) return dyn_cast(V); // If we already have the value parsed... - GlobalRefsType::iterator I = GlobalRefs.find(make_pair(Ty, Slot)); + GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(Ty, Slot)); if (I != GlobalRefs.end()) { BCR_TRACE(5, "Previous forward ref found!\n"); return cast(I->second); @@ -154,7 +151,7 @@ Constant *C = new ConstPHolder(Ty, Slot); // Keep track of the fact that we have a forward ref to recycle it - GlobalRefs.insert(make_pair(make_pair(Ty, Slot), C)); + GlobalRefs.insert(std::make_pair(std::make_pair(Ty, Slot), C)); return C; } } @@ -175,8 +172,8 @@ Value *NewDef = getValue(D->getType(), IDNumber, false); if (NewDef == 0) { Error = true; // Unresolved thinger - cerr << "Unresolvable reference found: <" - << D->getType()->getDescription() << ">:" << IDNumber << "!\n"; + std::cerr << "Unresolvable reference found: <" + << D->getType()->getDescription() << ">:" << IDNumber <<"!\n"; } else { // Fixup all of the uses of this placeholder def... D->replaceAllUsesWith(NewDef); @@ -241,7 +238,7 @@ return true; } BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D; - if (!isa(D)) cerr << "\n"); + if (!isa(D)) std::cerr << "\n"); D->setName(Name, ST); } @@ -252,7 +249,8 @@ } void BytecodeParser::ResolveReferencesToValue(Value *NewV, unsigned Slot) { - GlobalRefsType::iterator I = GlobalRefs.find(make_pair(NewV->getType(),Slot)); + GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(NewV->getType(), + Slot)); if (I == GlobalRefs.end()) return; // Never forward referenced? BCR_TRACE(3, "Mutating forward refs!\n"); @@ -476,7 +474,7 @@ // methods are loaded... // FunctionSignatureList.push_back( - make_pair(cast(Val->getType()), SlotNo)); + std::make_pair(cast(Val->getType()), SlotNo)); if (read_vbr(Buf, End, FnSignature)) return true; BCR_TRACE(2, "Function of type: " << Ty << "\n"); } From lattner at cs.uiuc.edu Thu Mar 6 10:38:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 10:38:01 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/iPHINode.h Message-ID: <200303061637.KAA05670@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm: iPHINode.h updated: 1.7 -> 1.8 --- Log message: Add new getIncomingValueForBlock method Relax a bit about constness --- Diffs of the changes: Index: llvm/include/llvm/iPHINode.h diff -u llvm/include/llvm/iPHINode.h:1.7 llvm/include/llvm/iPHINode.h:1.8 --- llvm/include/llvm/iPHINode.h:1.7 Wed Mar 5 15:15:11 2003 +++ llvm/include/llvm/iPHINode.h Thu Mar 6 10:36:28 2003 @@ -33,13 +33,12 @@ unsigned getNumIncomingValues() const { return Operands.size()/2; } /// getIncomingValue - Return incoming value #x - const Value *getIncomingValue(unsigned i) const { - return Operands[i*2]; - } - Value *getIncomingValue(unsigned i) { + Value *getIncomingValue(unsigned i) const { + assert(i*2 < Operands.size() && "Invalid value number!"); return Operands[i*2]; } void setIncomingValue(unsigned i, Value *V) { + assert(i*2 < Operands.size() && "Invalid value number!"); Operands[i*2] = V; } inline unsigned getOperandNumForIncomingValue(unsigned i) { @@ -47,16 +46,15 @@ } /// getIncomingBlock - Return incoming basic block #x - const BasicBlock *getIncomingBlock(unsigned i) const { - return (const BasicBlock*)Operands[i*2+1].get(); - } - inline BasicBlock *getIncomingBlock(unsigned i) { + BasicBlock *getIncomingBlock(unsigned i) const { + assert(i*2+1 < Operands.size() && "Invalid value number!"); return (BasicBlock*)Operands[i*2+1].get(); } - inline void setIncomingBlock(unsigned i, BasicBlock *BB) { + void setIncomingBlock(unsigned i, BasicBlock *BB) { + assert(i*2+1 < Operands.size() && "Invalid value number!"); Operands[i*2+1] = (Value*)BB; } - inline unsigned getOperandNumForIncomingBlock(unsigned i) { + unsigned getOperandNumForIncomingBlock(unsigned i) { return i*2+1; } @@ -91,6 +89,10 @@ for (unsigned i = 0; i < Operands.size()/2; ++i) if (getIncomingBlock(i) == BB) return i; return -1; + } + + Value *getIncomingValueForBlock(const BasicBlock *BB) const { + return getIncomingValue(getBasicBlockIndex(BB)); } /// Methods for support type inquiry through isa, cast, and dyn_cast: From lattner at cs.uiuc.edu Thu Mar 6 10:39:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 10:39:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Analysis/BasicAliasAnalysis.cpp Message-ID: <200303061638.KAA05691@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Analysis: BasicAliasAnalysis.cpp updated: 1.5 -> 1.6 --- Log message: Remove unneccesary forward decl --- Diffs of the changes: Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp diff -u llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.5 llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.6 --- llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.5 Tue Mar 4 10:40:17 2003 +++ llvm/lib/Analysis/BasicAliasAnalysis.cpp Thu Mar 6 10:37:29 2003 @@ -18,7 +18,7 @@ // Make sure that anything that uses AliasAnalysis pulls in this file... void BasicAAStub() {} -class GetElementPtrInst; + namespace { struct BasicAliasAnalysis : public ImmutablePass, public AliasAnalysis { From lattner at cs.uiuc.edu Thu Mar 6 10:52:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 10:52:01 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/Bytecode/Reader.h Message-ID: <200303061651.KAA05764@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm/Bytecode: Reader.h updated: 1.7 -> 1.8 --- Log message: Generalize interface a bit --- Diffs of the changes: Index: llvm/include/llvm/Bytecode/Reader.h diff -u llvm/include/llvm/Bytecode/Reader.h:1.7 llvm/include/llvm/Bytecode/Reader.h:1.8 --- llvm/include/llvm/Bytecode/Reader.h:1.7 Fri Oct 25 17:53:56 2002 +++ llvm/include/llvm/Bytecode/Reader.h Thu Mar 6 10:50:21 2003 @@ -20,6 +20,7 @@ // Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr = 0); -Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned BufferSize); +Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned BufferSize, + std::string *ErrorStr = 0); #endif From lattner at cs.uiuc.edu Thu Mar 6 10:52:03 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 10:52:03 2003 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp Message-ID: <200303061651.KAA05771@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: Reader.cpp updated: 1.42 -> 1.43 --- Log message: Pull common code out --- Diffs of the changes: Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.42 llvm/lib/Bytecode/Reader/Reader.cpp:1.43 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.42 Thu Mar 6 10:32:25 2003 +++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Mar 6 10:50:32 2003 @@ -581,15 +581,17 @@ } -Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length) { +Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length, + std::string *ErrorStr) { BytecodeParser Parser; - return Parser.ParseBytecode(Buffer, Buffer+Length); + Module *R = Parser.ParseBytecode(Buffer, Buffer+Length); + if (ErrorStr) *ErrorStr = Parser.getError(); + return R; } // Parse and return a class file... // Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) { - struct stat StatBuf; Module *Result = 0; if (Filename != std::string("-")) { // Read from a file... @@ -599,26 +601,25 @@ return 0; } - if (fstat(FD, &StatBuf) == -1) { close(FD); return 0; } - - int Length = StatBuf.st_size; - if (Length == 0) { + struct stat StatBuf; + if (fstat(FD, &StatBuf) == -1 || + StatBuf.st_size == 0) { if (ErrorStr) *ErrorStr = "Error stat'ing file!"; close(FD); return 0; } - uchar *Buffer = (uchar*)mmap(0, Length, PROT_READ, - MAP_PRIVATE, FD, 0); + + int Length = StatBuf.st_size; + unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ, + MAP_PRIVATE, FD, 0); if (Buffer == (uchar*)-1) { if (ErrorStr) *ErrorStr = "Error mmapping file!"; close(FD); return 0; } - BytecodeParser Parser; - Result = Parser.ParseBytecode(Buffer, Buffer+Length); + Result = ParseBytecodeBuffer(Buffer, Length, ErrorStr); munmap((char*)Buffer, Length); close(FD); - if (ErrorStr) *ErrorStr = Parser.getError(); } else { // Read from stdin size_t FileSize = 0; int BlockSize; @@ -647,16 +648,13 @@ uchar *Buf = FileData; #endif - BytecodeParser Parser; - Result = Parser.ParseBytecode(Buf, Buf+FileSize); + Result = ParseBytecodeBuffer(Buf, FileSize, ErrorStr); #if ALIGN_PTRS munmap((char*)Buf, FileSize); // Free mmap'd data area #else free(FileData); // Free realloc'd block of memory #endif - - if (ErrorStr) *ErrorStr = Parser.getError(); } return Result; From lattner at cs.uiuc.edu Thu Mar 6 11:04:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 11:04:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp Message-ID: <200303061703.LAA05874@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: Reader.cpp updated: 1.43 -> 1.44 --- Log message: Cleanup error handling constructs --- Diffs of the changes: Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.43 llvm/lib/Bytecode/Reader/Reader.cpp:1.44 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.43 Thu Mar 6 10:50:32 2003 +++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Mar 6 11:03:28 2003 @@ -308,7 +308,7 @@ while (Buf < EndBuf) { unsigned Type, Size; - const uchar *OldBuf = Buf; + const unsigned char *OldBuf = Buf; if (readBlock(Buf, EndBuf, Type, Size)) { Error = "Error reading Function level block!"; delete M; return true; @@ -493,7 +493,7 @@ } bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf, - Module *&Mod) { + Module *&Mod) { unsigned Type, Size; if (readBlock(Buf, EndBuf, Type, Size)) return true; @@ -513,7 +513,7 @@ TheModule = Mod = new Module(); while (Buf < EndBuf) { - const uchar *OldBuf = Buf; + const unsigned char *OldBuf = Buf; if (readBlock(Buf, EndBuf, Type, Size)) { delete Mod; return true;} switch (Type) { case BytecodeFormat::ConstantPool: @@ -589,71 +589,81 @@ return R; } + +/// FDHandle - Simple handle class to make sure a file descriptor gets closed +/// when the object is destroyed. +class FDHandle { + int FD; +public: + FDHandle(int fd) : FD(fd) {} + operator int() const { return FD; } + ~FDHandle() { + if (FD != -1) close(FD); + } +}; + +static inline Module *Error(std::string *ErrorStr, const char *Message) { + if (ErrorStr) *ErrorStr = Message; + return 0; +} + // Parse and return a class file... // Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) { Module *Result = 0; if (Filename != std::string("-")) { // Read from a file... - int FD = open(Filename.c_str(), O_RDONLY); - if (FD == -1) { - if (ErrorStr) *ErrorStr = "Error opening file!"; - return 0; - } + FDHandle FD = open(Filename.c_str(), O_RDONLY); + if (FD == -1) + return Error(ErrorStr, "Error opening file!"); + // Stat the file to get its length... struct stat StatBuf; - if (fstat(FD, &StatBuf) == -1 || - StatBuf.st_size == 0) { - if (ErrorStr) *ErrorStr = "Error stat'ing file!"; - close(FD); return 0; - } + if (fstat(FD, &StatBuf) == -1 || StatBuf.st_size == 0) + return Error(ErrorStr, "Error stat'ing file!"); + // mmap in the file all at once... int Length = StatBuf.st_size; unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ, MAP_PRIVATE, FD, 0); - if (Buffer == (uchar*)-1) { - if (ErrorStr) *ErrorStr = "Error mmapping file!"; - close(FD); return 0; - } + if (Buffer == (unsigned char*)MAP_FAILED) + return Error(ErrorStr, "Error mmapping file!"); + // Parse the bytecode we mmapped in Result = ParseBytecodeBuffer(Buffer, Length, ErrorStr); + // Unmmap the bytecode... munmap((char*)Buffer, Length); - close(FD); } else { // Read from stdin - size_t FileSize = 0; int BlockSize; - uchar Buffer[4096], *FileData = 0; - while ((BlockSize = read(0, Buffer, 4096))) { - if (BlockSize == -1) { free(FileData); return 0; } - - FileData = (uchar*)realloc(FileData, FileSize+BlockSize); - memcpy(FileData+FileSize, Buffer, BlockSize); - FileSize += BlockSize; - } + uchar Buffer[4096*4]; + std::vector FileData; - if (FileSize == 0) { - if (ErrorStr) *ErrorStr = "Standard Input empty!"; - free(FileData); return 0; + // Read in all of the data from stdin, we cannot mmap stdin... + while ((BlockSize = read(0 /*stdin*/, Buffer, 4096*4))) { + if (BlockSize == -1) + return Error(ErrorStr, "Error reading from stdin!"); + + FileData.insert(FileData.end(), Buffer, Buffer+BlockSize); } + if (FileData.empty()) + return Error(ErrorStr, "Standard Input empty!"); + #define ALIGN_PTRS 0 #if ALIGN_PTRS - uchar *Buf = (uchar*)mmap(0, FileSize, PROT_READ|PROT_WRITE, + uchar *Buf = (uchar*)mmap(0, FileData.size(), PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); assert((Buf != (uchar*)-1) && "mmap returned error!"); - memcpy(Buf, FileData, FileSize); - free(FileData); + memcpy(Buf, &FileData[0], FileData.size()); #else - uchar *Buf = FileData; + unsigned char *Buf = &FileData[0]; #endif - Result = ParseBytecodeBuffer(Buf, FileSize, ErrorStr); + Result = ParseBytecodeBuffer(Buf, FileData.size(), ErrorStr); #if ALIGN_PTRS - munmap((char*)Buf, FileSize); // Free mmap'd data area -#else - free(FileData); // Free realloc'd block of memory + munmap((char*)Buf, FileData.size()); // Free mmap'd data area #endif } From lattner at cs.uiuc.edu Thu Mar 6 11:16:00 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 11:16:00 2003 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp ReaderInternals.h Message-ID: <200303061715.LAA06040@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: Reader.cpp updated: 1.44 -> 1.45 ReaderInternals.h updated: 1.29 -> 1.30 --- Log message: Continue simplifying error handling, s/method/function --- Diffs of the changes: Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.44 llvm/lib/Bytecode/Reader/Reader.cpp:1.45 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.44 Thu Mar 6 11:03:28 2003 +++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Mar 6 11:15:19 2003 @@ -28,7 +28,7 @@ if (Ty->isPrimitiveType()) { Slot = Ty->getPrimitiveID(); } else { - // Check the method level types first... + // Check the function level types first... TypeValuesListTy::iterator I = find(MethodTypeValues.begin(), MethodTypeValues.end(), Ty); if (I != MethodTypeValues.end()) { @@ -90,7 +90,7 @@ if (Num < ModuleTypeValues.size()) return (Value*)ModuleTypeValues[Num].get(); - // Nope, is it a method level type? + // Nope, is it a function level type? Num -= ModuleTypeValues.size(); if (Num < MethodTypeValues.size()) return (Value*)MethodTypeValues[Num].get(); @@ -112,7 +112,7 @@ Value *d = 0; switch (Ty->getPrimitiveID()) { case Type::FunctionTyID: - std::cerr << "Creating method pholder! : " << type << ":" << oNum << " " + std::cerr << "Creating function pholder! : " << type << ":" << oNum << " " << Ty->getName() << "\n"; d = new FunctionPHolder(Ty, oNum); if (insertValue(d, LateResolveModuleValues) == -1) return 0; @@ -274,18 +274,17 @@ GlobalRefs.erase(I); // Remove the map entry for it } -bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf, - Module *C) { +bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf) { // Clear out the local values table... Values.clear(); if (FunctionSignatureList.empty()) { Error = "Function found, but FunctionSignatureList empty!"; - return true; // Unexpected method! + return true; // Unexpected function! } const PointerType *PMTy = FunctionSignatureList.back().first; // PtrMeth const FunctionType *MTy = dyn_cast(PMTy->getElementType()); - if (MTy == 0) return true; // Not ptr to method! + if (MTy == 0) return true; // Not ptr to function! unsigned isInternal; if (read_vbr(Buf, EndBuf, isInternal)) return true; @@ -294,14 +293,14 @@ FunctionSignatureList.pop_back(); Function *M = new Function(MTy, isInternal != 0); - BCR_TRACE(2, "METHOD TYPE: " << MTy << "\n"); + BCR_TRACE(2, "FUNCTION TYPE: " << MTy << "\n"); const FunctionType::ParamTypes &Params = MTy->getParamTypes(); Function::aiterator AI = M->abegin(); for (FunctionType::ParamTypes::const_iterator It = Params.begin(); It != Params.end(); ++It, ++AI) { if (insertValue(AI, Values) == -1) { - Error = "Error reading method arguments!\n"; + Error = "Error reading function arguments!\n"; delete M; return true; } } @@ -358,7 +357,7 @@ if (postResolveValues(LateResolveValues) || postResolveValues(LateResolveModuleValues)) { - Error = "Error resolving method values!"; + Error = "Error resolving function values!"; delete M; return true; // Unresolvable references! } @@ -370,15 +369,15 @@ assert(!getTypeSlot(MTy, type) && "How can meth type not exist?"); getTypeSlot(PMTy, type); - C->getFunctionList().push_back(M); + TheModule->getFunctionList().push_back(M); - // Replace placeholder with the real method pointer... + // Replace placeholder with the real function pointer... ModuleValues[type][MethSlot] = M; - // Clear out method level types... + // Clear out function level types... MethodTypeValues.clear(); - // If anyone is using the placeholder make them use the real method instead + // If anyone is using the placeholder make them use the real function instead FunctionPHolder->replaceAllUsesWith(M); // We don't need the placeholder anymore! @@ -389,8 +388,7 @@ return false; } -bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, - Module *Mod) { +bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End){ if (!FunctionSignatureList.empty()) { Error = "Two ModuleGlobalInfo packets found!"; return true; // Two ModuleGlobal blocks? @@ -430,7 +428,7 @@ int DestSlot = insertValue(GV, ModuleValues); if (DestSlot == -1) return true; - Mod->getGlobalList().push_back(GV); + TheModule->getGlobalList().push_back(GV); ResolveReferencesToValue(GV, (unsigned)DestSlot); @@ -440,7 +438,7 @@ if (read_vbr(Buf, End, VarType)) return true; } - // Read the method signatures for all of the methods that are coming, and + // Read the function signatures for all of the functions that are coming, and // create fillers in the Value tables. unsigned FnSignature; if (read_vbr(Buf, End, FnSignature)) return true; @@ -452,13 +450,13 @@ return true; } - // We create methods by passing the underlying FunctionType to create... + // We create functions by passing the underlying FunctionType to create... Ty = cast(Ty)->getElementType(); - // When the ModuleGlobalInfo section is read, we load the type of each - // method and the 'ModuleValues' slot that it lands in. We then load a - // placeholder into its slot to reserve it. When the method is loaded, this - // placeholder is replaced. + // When the ModuleGlobalInfo section is read, we load the type of each + // function and the 'ModuleValues' slot that it lands in. We then load a + // placeholder into its slot to reserve it. When the function is loaded, + // this placeholder is replaced. // Insert the placeholder... Value *Val = new FunctionPHolder(Ty, 0); @@ -471,7 +469,7 @@ unsigned SlotNo = ModuleValues[TypeSlot].size()-1; // Keep track of this information in a linked list that is emptied as - // methods are loaded... + // functions are loaded... // FunctionSignatureList.push_back( std::make_pair(cast(Val->getType()), SlotNo)); @@ -492,9 +490,7 @@ return false; } -bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf, - Module *&Mod) { - +bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf) { unsigned Type, Size; if (readBlock(Buf, EndBuf, Type, Size)) return true; if (Type != BytecodeFormat::Module || Buf+Size != EndBuf) { @@ -510,40 +506,31 @@ if (align32(Buf, EndBuf)) return true; BCR_TRACE(1, "FirstDerivedTyID = " << FirstDerivedTyID << "\n"); - TheModule = Mod = new Module(); - while (Buf < EndBuf) { const unsigned char *OldBuf = Buf; - if (readBlock(Buf, EndBuf, Type, Size)) { delete Mod; return true;} + if (readBlock(Buf, EndBuf, Type, Size)) return true; switch (Type) { case BytecodeFormat::ConstantPool: BCR_TRACE(1, "BLOCK BytecodeFormat::ConstantPool: {\n"); - if (ParseConstantPool(Buf, Buf+Size, ModuleValues, ModuleTypeValues)) { - delete Mod; return true; - } + if (ParseConstantPool(Buf, Buf+Size, ModuleValues, ModuleTypeValues)) + return true; break; case BytecodeFormat::ModuleGlobalInfo: BCR_TRACE(1, "BLOCK BytecodeFormat::ModuleGlobalInfo: {\n"); - - if (ParseModuleGlobalInfo(Buf, Buf+Size, Mod)) { - delete Mod; return true; - } + if (ParseModuleGlobalInfo(Buf, Buf+Size)) return true; break; case BytecodeFormat::Function: { BCR_TRACE(1, "BLOCK BytecodeFormat::Function: {\n"); - if (ParseMethod(Buf, Buf+Size, Mod)) { - delete Mod; return true; // Error parsing function - } + if (ParseMethod(Buf, Buf+Size)) return true; // Error parsing function break; } case BytecodeFormat::SymbolTable: BCR_TRACE(1, "BLOCK BytecodeFormat::SymbolTable: {\n"); - if (ParseSymbolTable(Buf, Buf+Size, &Mod->getSymbolTable())) { - delete Mod; return true; - } + if (ParseSymbolTable(Buf, Buf+Size, &TheModule->getSymbolTable())) + return true; break; default: @@ -553,10 +540,10 @@ break; } BCR_TRACE(1, "} end block\n"); - if (align32(Buf, EndBuf)) { delete Mod; return true; } + if (align32(Buf, EndBuf)) return true; } - if (!FunctionSignatureList.empty()) { // Expected more methods! + if (!FunctionSignatureList.empty()) { // Expected more functions! Error = "Function expected, but bytecode stream at end!"; return true; } @@ -565,19 +552,25 @@ return false; } +static inline Module *Error(std::string *ErrorStr, const char *Message) { + if (ErrorStr) *ErrorStr = Message; + return 0; +} + Module *BytecodeParser::ParseBytecode(const uchar *Buf, const uchar *EndBuf) { LateResolveValues.clear(); unsigned Sig; // Read and check signature... if (read(Buf, EndBuf, Sig) || - Sig != ('l' | ('l' << 8) | ('v' << 16) | 'm' << 24)) { - Error = "Invalid bytecode signature!"; - return 0; // Invalid signature! - } + Sig != ('l' | ('l' << 8) | ('v' << 16) | 'm' << 24)) + return ::Error(&Error, "Invalid bytecode signature!"); - Module *Result; - if (ParseModule(Buf, EndBuf, Result)) return 0; - return Result; + TheModule = new Module(); + if (ParseModule(Buf, EndBuf)) { + delete TheModule; + TheModule = 0; + } + return TheModule; } @@ -601,11 +594,6 @@ if (FD != -1) close(FD); } }; - -static inline Module *Error(std::string *ErrorStr, const char *Message) { - if (ErrorStr) *ErrorStr = Message; - return 0; -} // Parse and return a class file... // Index: llvm/lib/Bytecode/Reader/ReaderInternals.h diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.29 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.30 --- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.29 Sun Oct 13 22:33:02 2002 +++ llvm/lib/Bytecode/Reader/ReaderInternals.h Thu Mar 6 11:15:19 2003 @@ -89,10 +89,10 @@ std::vector > FunctionSignatureList; private: - bool ParseModule (const uchar * Buf, const uchar *End, Module *&); - bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End, Module *); + bool ParseModule (const uchar * Buf, const uchar *End); + bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End); bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *); - bool ParseMethod (const uchar *&Buf, const uchar *End, Module *); + bool ParseMethod (const uchar *&Buf, const uchar *End); bool ParseBasicBlock (const uchar *&Buf, const uchar *End, BasicBlock *&); bool ParseInstruction (const uchar *&Buf, const uchar *End, Instruction *&, BasicBlock *BB /*HACK*/); From lattner at cs.uiuc.edu Thu Mar 6 11:19:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 11:19:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/ReadConst.cpp Reader.cpp ReaderInternals.h Message-ID: <200303061718.LAA06117@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: ReadConst.cpp updated: 1.41 -> 1.42 Reader.cpp updated: 1.45 -> 1.46 ReaderInternals.h updated: 1.30 -> 1.31 --- Log message: s/Method/Function in variable and method names --- Diffs of the changes: Index: llvm/lib/Bytecode/Reader/ReadConst.cpp diff -u llvm/lib/Bytecode/Reader/ReadConst.cpp:1.41 llvm/lib/Bytecode/Reader/ReadConst.cpp:1.42 --- llvm/lib/Bytecode/Reader/ReadConst.cpp:1.41 Thu Mar 6 10:32:25 2003 +++ llvm/lib/Bytecode/Reader/ReadConst.cpp Thu Mar 6 11:18:14 2003 @@ -102,9 +102,9 @@ if (OldType == NewType && OldType->isAbstract()) return; // Type is modified, but same - TypeValuesListTy::iterator I = find(MethodTypeValues.begin(), - MethodTypeValues.end(), OldType); - if (I == MethodTypeValues.end()) { + TypeValuesListTy::iterator I = find(FunctionTypeValues.begin(), + FunctionTypeValues.end(), OldType); + if (I == FunctionTypeValues.end()) { I = find(ModuleTypeValues.begin(), ModuleTypeValues.end(), OldType); assert(I != ModuleTypeValues.end() && "Can't refine a type I don't know about!"); Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.45 llvm/lib/Bytecode/Reader/Reader.cpp:1.46 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.45 Thu Mar 6 11:15:19 2003 +++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Mar 6 11:18:14 2003 @@ -29,11 +29,11 @@ Slot = Ty->getPrimitiveID(); } else { // Check the function level types first... - TypeValuesListTy::iterator I = find(MethodTypeValues.begin(), - MethodTypeValues.end(), Ty); - if (I != MethodTypeValues.end()) { + TypeValuesListTy::iterator I = find(FunctionTypeValues.begin(), + FunctionTypeValues.end(), Ty); + if (I != FunctionTypeValues.end()) { Slot = FirstDerivedTyID+ModuleTypeValues.size()+ - (&*I - &MethodTypeValues[0]); + (&*I - &FunctionTypeValues[0]); } else { I = find(ModuleTypeValues.begin(), ModuleTypeValues.end(), Ty); if (I == ModuleTypeValues.end()) return true; // Didn't find type! @@ -92,8 +92,8 @@ // Nope, is it a function level type? Num -= ModuleTypeValues.size(); - if (Num < MethodTypeValues.size()) - return (Value*)MethodTypeValues[Num].get(); + if (Num < FunctionTypeValues.size()) + return (Value*)FunctionTypeValues[Num].get(); return 0; } @@ -274,7 +274,7 @@ GlobalRefs.erase(I); // Remove the map entry for it } -bool BytecodeParser::ParseMethod(const uchar *&Buf, const uchar *EndBuf) { +bool BytecodeParser::ParseFunction(const uchar *&Buf, const uchar *EndBuf) { // Clear out the local values table... Values.clear(); if (FunctionSignatureList.empty()) { @@ -316,7 +316,7 @@ switch (Type) { case BytecodeFormat::ConstantPool: BCR_TRACE(2, "BLOCK BytecodeFormat::ConstantPool: {\n"); - if (ParseConstantPool(Buf, Buf+Size, Values, MethodTypeValues)) { + if (ParseConstantPool(Buf, Buf+Size, Values, FunctionTypeValues)) { delete M; return true; } break; @@ -362,7 +362,7 @@ } Value *FunctionPHolder = getValue(PMTy, MethSlot, false); - assert(FunctionPHolder && "Something is broken no placeholder found!"); + assert(FunctionPHolder && "Something is broken, no placeholder found!"); assert(isa(FunctionPHolder) && "Not a function?"); unsigned type; // Type slot @@ -375,7 +375,7 @@ ModuleValues[type][MethSlot] = M; // Clear out function level types... - MethodTypeValues.clear(); + FunctionTypeValues.clear(); // If anyone is using the placeholder make them use the real function instead FunctionPHolder->replaceAllUsesWith(M); @@ -523,7 +523,7 @@ case BytecodeFormat::Function: { BCR_TRACE(1, "BLOCK BytecodeFormat::Function: {\n"); - if (ParseMethod(Buf, Buf+Size)) return true; // Error parsing function + if (ParseFunction(Buf, Buf+Size)) return true; // Error parsing function break; } Index: llvm/lib/Bytecode/Reader/ReaderInternals.h diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.30 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.31 --- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.30 Thu Mar 6 11:15:19 2003 +++ llvm/lib/Bytecode/Reader/ReaderInternals.h Thu Mar 6 11:18:14 2003 @@ -76,7 +76,7 @@ // typedef std::vector > TypeValuesListTy; TypeValuesListTy ModuleTypeValues; - TypeValuesListTy MethodTypeValues; + TypeValuesListTy FunctionTypeValues; // Information read from the ModuleGlobalInfo section of the file... unsigned FirstDerivedTyID; @@ -92,7 +92,7 @@ bool ParseModule (const uchar * Buf, const uchar *End); bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End); bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *); - bool ParseMethod (const uchar *&Buf, const uchar *End); + bool ParseFunction (const uchar *&Buf, const uchar *End); bool ParseBasicBlock (const uchar *&Buf, const uchar *End, BasicBlock *&); bool ParseInstruction (const uchar *&Buf, const uchar *End, Instruction *&, BasicBlock *BB /*HACK*/); From lattner at cs.uiuc.edu Thu Mar 6 11:56:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 11:56:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp ReaderInternals.h Message-ID: <200303061755.LAA06524@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Bytecode/Reader: Reader.cpp updated: 1.46 -> 1.47 ReaderInternals.h updated: 1.31 -> 1.32 --- Log message: Infrastructure for more compact bytecode files and REAL support for versioning --- Diffs of the changes: Index: llvm/lib/Bytecode/Reader/Reader.cpp diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.46 llvm/lib/Bytecode/Reader/Reader.cpp:1.47 --- llvm/lib/Bytecode/Reader/Reader.cpp:1.46 Thu Mar 6 11:18:14 2003 +++ llvm/lib/Bytecode/Reader/Reader.cpp Thu Mar 6 11:55:45 2003 @@ -60,8 +60,12 @@ if (getTypeSlot(Val->getType(), type)) return -1; assert(type != Type::TypeTyID && "Types should never be insertValue'd!"); - if (ValueTab.size() <= type) - ValueTab.resize(type+1, ValueList()); + while (ValueTab.size() <= type) { + ValueTab.push_back(ValueList()); + if (HasImplicitZeroInitializer) // add a zero initializer if appropriate + ValueTab.back().push_back( + Constant::getNullValue(getType(ValueTab.size()-1))); + } //cerr << "insertValue Values[" << type << "][" << ValueTab[type].size() // << "] = " << Val << "\n"; @@ -194,8 +198,7 @@ while (Buf < EndBuf) { Instruction *Inst; - if (ParseInstruction(Buf, EndBuf, Inst, - /*HACK*/BB)) { + if (ParseInstruction(Buf, EndBuf, Inst, /*HACK*/BB)) { delete BB; return true; } @@ -490,6 +493,38 @@ return false; } +bool BytecodeParser::ParseVersionInfo(const uchar *&Buf, const uchar *EndBuf) { + unsigned Version; + if (read_vbr(Buf, EndBuf, Version)) return true; + + // Unpack version number: low four bits are for flags, top bits = version + isBigEndian = Version & 1; + hasLongPointers = Version & 2; + RevisionNum = Version >> 4; + HasImplicitZeroInitializer = true; + + switch (RevisionNum) { + case 0: // Initial revision + if (Version != 14) return true; // Unknown revision 0 flags? + FirstDerivedTyID = 14; + HasImplicitZeroInitializer = false; + isBigEndian = hasLongPointers = true; + break; + case 1: + FirstDerivedTyID = 14; + break; + default: + Error = "Unknown bytecode version number!"; + return true; + } + + BCR_TRACE(1, "Bytecode Rev = " << (unsigned)RevisionNum << "\n"); + BCR_TRACE(1, "BigEndian/LongPointers = " << isBigEndian << "," + << hasLongPointers << "\n"); + BCR_TRACE(1, "HasImplicitZeroInit = " << HasImplicitZeroInitializer << "\n"); + return false; +} + bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf) { unsigned Type, Size; if (readBlock(Buf, EndBuf, Type, Size)) return true; @@ -502,9 +537,8 @@ FunctionSignatureList.clear(); // Just in case... // Read into instance variables... - if (read_vbr(Buf, EndBuf, FirstDerivedTyID)) return true; + if (ParseVersionInfo(Buf, EndBuf)) return true; if (align32(Buf, EndBuf)) return true; - BCR_TRACE(1, "FirstDerivedTyID = " << FirstDerivedTyID << "\n"); while (Buf < EndBuf) { const unsigned char *OldBuf = Buf; Index: llvm/lib/Bytecode/Reader/ReaderInternals.h diff -u llvm/lib/Bytecode/Reader/ReaderInternals.h:1.31 llvm/lib/Bytecode/Reader/ReaderInternals.h:1.32 --- llvm/lib/Bytecode/Reader/ReaderInternals.h:1.31 Thu Mar 6 11:18:14 2003 +++ llvm/lib/Bytecode/Reader/ReaderInternals.h Thu Mar 6 11:55:45 2003 @@ -57,6 +57,12 @@ private: // All of this data is transient across calls to ParseBytecode Module *TheModule; // Current Module being read into... + // Information about the module, extracted from the bytecode revision number. + unsigned char RevisionNum; // The rev # itself + unsigned char FirstDerivedTyID; // First variable index to use for type + bool HasImplicitZeroInitializer; // Is entry 0 of every slot implicity zeros? + bool isBigEndian, hasLongPointers;// Information about the target compiled for + typedef std::vector ValueList; typedef std::vector ValueTable; ValueTable Values, LateResolveValues; @@ -78,9 +84,6 @@ TypeValuesListTy ModuleTypeValues; TypeValuesListTy FunctionTypeValues; - // Information read from the ModuleGlobalInfo section of the file... - unsigned FirstDerivedTyID; - // When the ModuleGlobalInfo section is read, we load the type of each // function and the 'ModuleValues' slot that it lands in. We then load a // placeholder into its slot to reserve it. When the function is loaded, this @@ -90,6 +93,7 @@ private: bool ParseModule (const uchar * Buf, const uchar *End); + bool ParseVersionInfo (const uchar *&Buf, const uchar *End); bool ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End); bool ParseSymbolTable (const uchar *&Buf, const uchar *End, SymbolTable *); bool ParseFunction (const uchar *&Buf, const uchar *End); From lattner at cs.uiuc.edu Thu Mar 6 14:00:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 14:00:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Assembler/2002-05-02-ParseError.ll 2002-08-15-ConstantExprProblem.ll 2002-08-15-UnresolvedGlobalReference.ll Message-ID: <200303061959.NAA12474@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Assembler: 2002-05-02-ParseError.ll updated: 1.2 -> 1.3 2002-08-15-ConstantExprProblem.ll updated: 1.1 -> 1.2 2002-08-15-UnresolvedGlobalReference.ll updated: 1.1 -> 1.2 --- Log message: Update testcases to use long to index gep --- Diffs of the changes: Index: llvm/test/Regression/Assembler/2002-05-02-ParseError.ll diff -u llvm/test/Regression/Assembler/2002-05-02-ParseError.ll:1.2 llvm/test/Regression/Assembler/2002-05-02-ParseError.ll:1.3 --- llvm/test/Regression/Assembler/2002-05-02-ParseError.ll:1.2 Thu May 2 14:58:05 2002 +++ llvm/test/Regression/Assembler/2002-05-02-ParseError.ll Thu Mar 6 13:59:08 2003 @@ -1,10 +1,8 @@ -; This should parse correctly without an 'implementation', but there seems to -; be a problem... +; This should parse correctly without an 'implementation', but our current YACC +; based parser doesn't have the required 2 token lookahead... %T = type int * -%T "test"() -begin +%T %test() { ret %T null -end - +} Index: llvm/test/Regression/Assembler/2002-08-15-ConstantExprProblem.ll diff -u llvm/test/Regression/Assembler/2002-08-15-ConstantExprProblem.ll:1.1 llvm/test/Regression/Assembler/2002-08-15-ConstantExprProblem.ll:1.2 --- llvm/test/Regression/Assembler/2002-08-15-ConstantExprProblem.ll:1.1 Thu Aug 15 12:04:39 2002 +++ llvm/test/Regression/Assembler/2002-08-15-ConstantExprProblem.ll Thu Mar 6 13:59:08 2003 @@ -6,7 +6,7 @@ br label %BB1 BB1: ;[#uses=2] - %ret = phi sbyte* [ getelementptr ([12 x sbyte]* %.LC0, uint 0, uint 0), %0 ], [ null, %BB2 ] + %ret = phi sbyte* [ getelementptr ([12 x sbyte]* %.LC0, long 0, long 0), %0 ], [ null, %BB2 ] ret sbyte* %ret BB2: Index: llvm/test/Regression/Assembler/2002-08-15-UnresolvedGlobalReference.ll diff -u llvm/test/Regression/Assembler/2002-08-15-UnresolvedGlobalReference.ll:1.1 llvm/test/Regression/Assembler/2002-08-15-UnresolvedGlobalReference.ll:1.2 --- llvm/test/Regression/Assembler/2002-08-15-UnresolvedGlobalReference.ll:1.1 Thu Aug 15 12:04:40 2002 +++ llvm/test/Regression/Assembler/2002-08-15-UnresolvedGlobalReference.ll Thu Mar 6 13:59:08 2003 @@ -3,6 +3,6 @@ implementation ; Functions: sbyte* %test() { - ret sbyte* getelementptr ([12 x sbyte]* %.LC0, uint 0, uint 0) + ret sbyte* getelementptr ([12 x sbyte]* %.LC0, long 0, long 0) } From lattner at cs.uiuc.edu Thu Mar 6 15:03:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 15:03:01 2003 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp Message-ID: <200303062102.PAA13543@apoc.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Constants.cpp updated: 1.32 -> 1.33 --- Log message: Remove #include Extend getNullValue to work with struct and array types --- Diffs of the changes: Index: llvm/lib/VMCore/Constants.cpp diff -u llvm/lib/VMCore/Constants.cpp:1.32 llvm/lib/VMCore/Constants.cpp:1.33 --- llvm/lib/VMCore/Constants.cpp:1.32 Sun Oct 13 22:30:23 2002 +++ llvm/lib/VMCore/Constants.cpp Thu Mar 6 15:02:18 2003 @@ -9,7 +9,6 @@ #include "llvm/iMemory.h" #include "llvm/SymbolTable.h" #include "llvm/Module.h" -#include "llvm/SlotCalculator.h" #include "Support/StringExtras.h" #include @@ -80,7 +79,25 @@ case Type::PointerTyID: return ConstantPointerNull::get(cast(Ty)); + case Type::StructTyID: { + const StructType *ST = cast(Ty); + + const StructType::ElementTypes &ETs = ST->getElementTypes(); + std::vector Elements; + Elements.resize(ETs.size()); + for (unsigned i = 0, e = ETs.size(); i != e; ++i) + Elements[i] = Constant::getNullValue(ETs[i]); + return ConstantStruct::get(ST, Elements); + } + case Type::ArrayTyID: { + const ArrayType *AT = cast(Ty); + Constant *El = Constant::getNullValue(AT->getElementType()); + unsigned NumElements = AT->getNumElements(); + return ConstantArray::get(AT, std::vector(NumElements, El)); + } default: + // Function, Type, Label, or Opaque type? + assert(0 && "Cannot create a null constant of that type!"); return 0; } } From lattner at cs.uiuc.edu Thu Mar 6 15:03:04 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 15:03:04 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/Constants.h Message-ID: <200303062102.PAA13554@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm: Constants.h updated: 1.18 -> 1.19 --- Log message: Extend struct and array constants to support isNullValue --- Diffs of the changes: Index: llvm/include/llvm/Constants.h diff -u llvm/include/llvm/Constants.h:1.18 llvm/include/llvm/Constants.h:1.19 --- llvm/include/llvm/Constants.h:1.18 Sun Oct 13 22:30:13 2002 +++ llvm/include/llvm/Constants.h Thu Mar 6 15:02:43 2003 @@ -289,7 +289,14 @@ /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. - virtual bool isNullValue() const { return false; } + virtual bool isNullValue() const { + // FIXME: This should be made to be MUCH faster. Just check against well + // known null value! + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) + if (!cast(getOperand(i))->isNullValue()) + return false; + return true; + } virtual void destroyConstant(); virtual void replaceUsesOfWithOnConstant(Value *From, Value *To); @@ -328,7 +335,14 @@ /// isNullValue - Return true if this is the value that would be returned by /// getNullValue. - virtual bool isNullValue() const { return false; } + virtual bool isNullValue() const { + // FIXME: This should be made to be MUCH faster. Just check against well + // known null value! + for (unsigned i = 0, e = getNumOperands(); i != e; ++i) + if (!cast(getOperand(i))->isNullValue()) + return false; + return true; + } virtual void destroyConstant(); virtual void replaceUsesOfWithOnConstant(Value *From, Value *To); From lattner at cs.uiuc.edu Thu Mar 6 17:24:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu Mar 6 17:24:01 2003 Subject: [llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp Message-ID: <200303062323.RAA14960@apoc.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: AsmWriter.cpp updated: 1.80 -> 1.81 --- Log message: Clean up cruft --- Diffs of the changes: Index: llvm/lib/VMCore/AsmWriter.cpp diff -u llvm/lib/VMCore/AsmWriter.cpp:1.80 llvm/lib/VMCore/AsmWriter.cpp:1.81 --- llvm/lib/VMCore/AsmWriter.cpp:1.80 Wed Nov 20 12:33:41 2002 +++ llvm/lib/VMCore/AsmWriter.cpp Thu Mar 6 17:23:32 2003 @@ -334,10 +334,7 @@ } } else if (const ConstantExpr *CE = dyn_cast(CV)) { - Out << CE->getOpcodeName(); - - bool isGEP = CE->getOpcode() == Instruction::GetElementPtr; - Out << " ("; + Out << CE->getOpcodeName() << " ("; for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) { printTypeInt(Out, (*OI)->getType(), TypeTable); From lattner at cs.uiuc.edu Fri Mar 7 11:44:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri Mar 7 11:44:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/SimplifyCFG/2003-03-07-DominateProblem.ll Message-ID: <200303071743.LAA28261@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/SimplifyCFG: 2003-03-07-DominateProblem.ll added (r1.1) --- Log message: New testcase --- Diffs of the changes: From lattner at cs.uiuc.edu Fri Mar 7 12:05:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri Mar 7 12:05:01 2003 Subject: [llvm-commits] CVS: llvm/www/www-index.html Message-ID: <200303071804.MAA23433@tank.cs.uiuc.edu> Changes in directory llvm/www: www-index.html updated: 1.18 -> 1.19 --- Log message: Change download message --- Diffs of the changes: Index: llvm/www/www-index.html diff -u llvm/www/www-index.html:1.18 llvm/www/www-index.html:1.19 --- llvm/www/www-index.html:1.18 Wed Mar 5 17:19:47 2003 +++ llvm/www/www-index.html Fri Mar 7 12:04:06 2003 @@ -162,13 +162,14 @@ + We are working towards a public release of the LLVM + infrastructure, and hope to have a distribution with a C + front-end available by the end of Summer 2003. If you are + interested, please email us + and we will notify you when the release is available. We also + welcome e-mail questions about the expected contents of the + release.

From lattner at cs.uiuc.edu Fri Mar 7 12:14:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri Mar 7 12:14:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200303071813.MAA28621@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.9 -> 1.10 --- Log message: Fix bug: SimplifyCFG/2003-03-07-DominateProblem.ll --- Diffs of the changes: Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.9 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.10 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.9 Wed Mar 5 15:36:33 2003 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Fri Mar 7 12:13:41 2003 @@ -141,9 +141,11 @@ // if (!PropagatePredecessorsForPHIs(BB, Succ)) { //cerr << "Killing Trivial BB: \n" << BB; - BB->replaceAllUsesWith(Succ); std::string OldName = BB->getName(); + std::vector + OldSuccPreds(pred_begin(Succ), pred_end(Succ)); + // Move all PHI nodes in BB to Succ if they are alive, otherwise // delete them. while (PHINode *PN = dyn_cast(&BB->front())) @@ -152,10 +154,25 @@ else { // The instruction is alive, so this means that Succ must have // *ONLY* had BB as a predecessor, and the PHI node is still valid - // now. Simply move it into Succ. + // now. Simply move it into Succ, because we know that BB + // strictly dominated Succ. BB->getInstList().remove(BB->begin()); Succ->getInstList().push_front(PN); + + // We need to add new entries for the PHI node to account for + // predecessors of Succ that the PHI node does not take into + // account. At this point, since we know that BB dominated succ, + // this means that we should any newly added incoming edges should + // use the PHI node as the value for these edges, because they are + // loop back edges. + + for (unsigned i = 0, e = OldSuccPreds.size(); i != e; ++i) + if (OldSuccPreds[i] != BB) + PN->addIncoming(PN, OldSuccPreds[i]); } + + // Everything that jumped to BB now goes to Succ... + BB->replaceAllUsesWith(Succ); // Delete the old basic block... M->getBasicBlockList().erase(BB); From lattner at cs.uiuc.edu Fri Mar 7 12:18:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri Mar 7 12:18:01 2003 Subject: [llvm-commits] CVS: llvm/tools/bugpoint/ExtractFunction.cpp Message-ID: <200303071817.MAA28662@apoc.cs.uiuc.edu> Changes in directory llvm/tools/bugpoint: ExtractFunction.cpp updated: 1.3 -> 1.4 --- Log message: Make sure that intermediate code is verifier clean to avoid wierd problems. --- Diffs of the changes: Index: llvm/tools/bugpoint/ExtractFunction.cpp diff -u llvm/tools/bugpoint/ExtractFunction.cpp:1.3 llvm/tools/bugpoint/ExtractFunction.cpp:1.4 --- llvm/tools/bugpoint/ExtractFunction.cpp:1.3 Fri Feb 28 10:13:20 2003 +++ llvm/tools/bugpoint/ExtractFunction.cpp Fri Mar 7 12:17:13 2003 @@ -11,6 +11,7 @@ #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/Analysis/Verifier.h" #include "llvm/Type.h" #include "llvm/Constant.h" @@ -33,6 +34,7 @@ Passes.add(createGlobalDCEPass()); // Delete unreachable globals Passes.add(createFunctionResolvingPass()); // Delete prototypes Passes.add(createDeadTypeEliminationPass()); // Remove dead types... + Passes.add(createVerifierPass()); Passes.run(*Result); return Result; } @@ -78,6 +80,8 @@ Passes.add(createDeadCodeEliminationPass()); if (Simplification) Passes.add(createCFGSimplificationPass()); // Delete dead control flow + + Passes.add(createVerifierPass()); Passes.run(*Result); return Result; } @@ -90,6 +94,7 @@ PassManager CleanupPasses; CleanupPasses.add(createFunctionResolvingPass()); CleanupPasses.add(createGlobalDCEPass()); + CleanupPasses.add(createVerifierPass()); Module *M = CloneModule(Program); CleanupPasses.run(*M); return M; From brukman at neo.cs.uiuc.edu Sat Mar 8 18:00:01 2003 From: brukman at neo.cs.uiuc.edu (Misha Brukman) Date: Sat Mar 8 18:00:01 2003 Subject: [llvm-commits] CVS: llvm/www/docs/OpenProjects.html Message-ID: <200303082359.h28NxGt04473@neo.cs.uiuc.edu> Changes in directory llvm/www/docs: OpenProjects.html updated: 1.3 -> 1.4 --- Log message: The word 'independent' has no 'a'. --- Diffs of the changes: Index: llvm/www/docs/OpenProjects.html diff -u llvm/www/docs/OpenProjects.html:1.3 llvm/www/docs/OpenProjects.html:1.4 --- llvm/www/docs/OpenProjects.html:1.3 Wed Feb 26 10:38:22 2003 +++ llvm/www/docs/OpenProjects.html Sat Mar 8 17:59:05 2003 @@ -132,7 +132,7 @@
  • Add support for a volatile attribute on loads and stores
  • Support for variable argument functions
  • Add a new conditional move instruction: X = select bool Cond, Y, Z -
  • Add support for platform independant prefetch support. The GCC Add support for platform independent prefetch support. The GCC prefetch project page has a good survey of the prefetching capabilities of a variety of modern processors.
  • Mar 4th, 2003-Added a new + Alias Analysis + document, describing Alias Analysis in LLVM.
    Feb 6th, 2003 - Added a new @@ -320,7 +327,12 @@ an LLVM Pass - Information on how to write LLVM transformations and analyses. -
  • Open projects in +
  • Alias Analysis in + LLVM - Information on how to write a new alias + analysis implementation or how to use existing + analyses.
  • + +
  • Open Projects in the LLVM system. Look here if you are interested in doing something with LLVM, but aren't sure what needs to be done.
  • From lattner at cs.uiuc.edu Tue Mar 4 13:44:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Tue Mar 4 13:44:01 2003 Subject: [llvm-commits] CVS: llvm/www/www-index.html Message-ID: <200303041943.NAA06150@tank.cs.uiuc.edu> Changes in directory llvm/www: www-index.html updated: 1.15 -> 1.16 --- Log message: Reword download section to make it sound less promising --- Diffs of the changes: Index: llvm/www/www-index.html diff -u llvm/www/www-index.html:1.15 llvm/www/www-index.html:1.16 --- llvm/www/www-index.html:1.15 Tue Mar 4 13:42:00 2003 +++ llvm/www/www-index.html Tue Mar 4 13:42:54 2003 @@ -365,13 +365,12 @@
    - We currently do not have an LLVM package - available for public consumption. However, we are - are willing to make the LLVM package available in - beta form for anyone who is interested in using - it. Please contact - us if you are interested in trying it out as - a beta site.

    Changes in directory llvm/www: www-index.html updated: 1.16 -> 1.17 --- Log message: Move the download section to the other column to make the columns more balanced again --- Diffs of the changes: Index: llvm/www/www-index.html diff -u llvm/www/www-index.html:1.16 llvm/www/www-index.html:1.17 --- llvm/www/www-index.html:1.16 Tue Mar 4 13:42:54 2003 +++ llvm/www/www-index.html Tue Mar 4 13:43:57 2003 @@ -154,6 +154,22 @@ #CCR-0209202).

    Download
    + We currently do not have an LLVM package available for public + consumption. However, we may be willing to make the LLVM + package available in beta form for people who are interested in + using it. Please contact + us if you are interested in trying it out as a beta + site.

    Download
    - We currently do not have an LLVM package available for public - consumption. However, we may be willing to make the LLVM - package available in beta form for people who are interested in - using it. Please contact - us if you are interested in trying it out as a beta - site.

    Changes in directory llvm/test/Regression/Transforms/CFGSimplify: PhiBlockMerge.ll added (r1.1) --- Log message: Add testcase for new feature for simplifycfg pass --- Diffs of the changes: From lattner at cs.uiuc.edu Wed Mar 5 14:36:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 14:36:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/CFGSimplify/EqualPHIEdgeBlockMerge.ll Message-ID: <200303052035.OAA29760@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/CFGSimplify: EqualPHIEdgeBlockMerge.ll added (r1.1) --- Log message: New testcase for feature simplifycfg should handle --- Diffs of the changes: From lattner at cs.uiuc.edu Wed Mar 5 15:03:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 15:03:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200303052102.PAA30123@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.7 -> 1.8 --- Log message: Implement testcase CFGSimplify/EqualPHIEdgeBlockMerge.ll --- Diffs of the changes: Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.7 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.8 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.7 Tue Oct 29 17:04:01 2002 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Wed Mar 5 15:01:52 2003 @@ -14,8 +14,9 @@ // PropagatePredecessors - This gets "Succ" ready to have the predecessors from // "BB". This is a little tricky because "Succ" has PHI nodes, which need to // have extra slots added to them to hold the merge edges from BB's -// predecessors. This function returns true (failure) if the Succ BB already -// has a predecessor that is a predecessor of BB. +// predecessors, and BB itself might have had PHI nodes in it. This function +// returns true (failure) if the Succ BB already has a predecessor that is a +// predecessor of BB and incoming PHI arguments would not be discernable. // // Assumption: Succ is the single successor for BB. // @@ -31,12 +32,27 @@ const std::vector BBPreds(pred_begin(BB), pred_end(BB)); // Check to see if one of the predecessors of BB is already a predecessor of - // Succ. If so, we cannot do the transformation! + // Succ. If so, we cannot do the transformation if there are any PHI nodes + // with incompatible values coming in from the two edges! // - for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ); - PI != PE; ++PI) - if (find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) - return true; + for (pred_iterator PI = pred_begin(Succ), PE = pred_end(Succ); PI != PE; ++PI) + if (find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) { + // Loop over all of the PHI nodes checking to see if there are + // incompatible values coming in. + BasicBlock::iterator BBI = Succ->begin(); + while (PHINode *PN = dyn_cast(&*BBI++)) { + // Loop up the entries in the PHI node for BB and for *PI if the values + // coming in are non-equal, we cannot merge these two blocks (instead we + // should insert a conditional move or something, then merge the + // blocks). + int Idx1 = PN->getBasicBlockIndex(BB); + int Idx2 = PN->getBasicBlockIndex(*PI); + assert(Idx1 != -1 && Idx2 != -1 && + "Didn't have entries for my predecessors??"); + if (PN->getIncomingValue(Idx1) != PN->getIncomingValue(Idx2)) + return true; // Values are not equal... + } + } // Loop over all of the PHI nodes in the successor BB for (BasicBlock::iterator I = Succ->begin(); @@ -57,9 +73,7 @@ // SimplifyCFG - This function is used to do simplification of a CFG. For // example, it adjusts branches to branches to eliminate the extra hop, it // eliminates unreachable basic blocks, and does other "peephole" optimization -// of the CFG. It returns true if a modification was made, and returns an -// iterator that designates the first element remaining after the block that -// was deleted. +// of the CFG. It returns true if a modification was made. // // WARNING: The entry node of a function may not be simplified. // From lattner at cs.uiuc.edu Wed Mar 5 15:16:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 15:16:01 2003 Subject: [llvm-commits] CVS: llvm/include/llvm/iPHINode.h Message-ID: <200303052115.PAA30946@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm: iPHINode.h updated: 1.6 -> 1.7 --- Log message: Simplify some of the PHI node interfaces --- Diffs of the changes: Index: llvm/include/llvm/iPHINode.h diff -u llvm/include/llvm/iPHINode.h:1.6 llvm/include/llvm/iPHINode.h:1.7 --- llvm/include/llvm/iPHINode.h:1.6 Tue Oct 8 16:31:56 2002 +++ llvm/include/llvm/iPHINode.h Wed Mar 5 15:15:11 2003 @@ -61,7 +61,12 @@ } /// addIncoming - Add an incoming value to the end of the PHI list - void addIncoming(Value *D, BasicBlock *BB); + void addIncoming(Value *D, BasicBlock *BB) { + assert(getType() == D->getType() && + "All operands to PHI node must be the same type as the PHI node!"); + Operands.push_back(Use(D, this)); + Operands.push_back(Use((Value*)BB, this)); + } /// removeIncomingValue - Remove an incoming value. This is useful if a /// predecessor basic block is deleted. The value removed is returned. @@ -71,8 +76,13 @@ /// dummy values. The only time there should be zero incoming values to a PHI /// node is when the block is dead, so this strategy is sound. /// - Value *removeIncomingValue(const BasicBlock *BB, - bool DeletePHIIfEmpty = true); + Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true); + + Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty =true){ + int Idx = getBasicBlockIndex(BB); + assert(Idx >= 0 && "Invalid basic block argument to remove!"); + return removeIncomingValue(Idx, DeletePHIIfEmpty); + } /// getBasicBlockIndex - Return the first index of the specified basic /// block in the value list for this PHI. Returns -1 if no instance. From lattner at cs.uiuc.edu Wed Mar 5 15:16:03 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 15:16:03 2003 Subject: [llvm-commits] CVS: llvm/lib/VMCore/InstrTypes.cpp Message-ID: <200303052115.PAA30953@apoc.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: InstrTypes.cpp updated: 1.19 -> 1.20 --- Log message: Simplify some of the PHI node interfaces --- Diffs of the changes: Index: llvm/lib/VMCore/InstrTypes.cpp diff -u llvm/lib/VMCore/InstrTypes.cpp:1.19 llvm/lib/VMCore/InstrTypes.cpp:1.20 --- llvm/lib/VMCore/InstrTypes.cpp:1.19 Tue Oct 8 16:34:58 2002 +++ llvm/lib/VMCore/InstrTypes.cpp Wed Mar 5 15:15:12 2003 @@ -33,22 +33,13 @@ } } -void PHINode::addIncoming(Value *D, BasicBlock *BB) { - assert(getType() == D->getType() && - "All operands to PHI node must be the same type as the PHI node!"); - Operands.push_back(Use(D, this)); - Operands.push_back(Use(BB, this)); -} - // removeIncomingValue - Remove an incoming value. This is useful if a // predecessor basic block is deleted. -Value *PHINode::removeIncomingValue(const BasicBlock *BB, - bool DeletePHIIfEmpty) { - op_iterator Idx = find(Operands.begin(), Operands.end(), (const Value*)BB); - assert(Idx != Operands.end() && "BB not in PHI node!"); - --Idx; // Back up to value prior to Basic block - Value *Removed = *Idx; - Operands.erase(Idx, Idx+2); // Erase Value and BasicBlock +Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) { + assert(Idx*2 < Operands.size() && "BB not in PHI node!"); + Value *Removed = Operands[Idx*2]; + Operands.erase(Operands.begin()+Idx*2, // Erase Value and BasicBlock + Operands.begin()+Idx*2+2); // If the PHI node is dead, because it has zero entries, nuke it now. if (getNumOperands() == 0 && DeletePHIIfEmpty) { From jstanley at cs.uiuc.edu Wed Mar 5 15:21:01 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 15:21:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/ Message-ID: <200303052120.PAA26152@tank.cs.uiuc.edu> Changes in directory llvm/lib/Reoptimizer/Inst: --- Log message: Directory /home/vadve/vadve/Research/DynOpt/CVSRepository/llvm/lib/Reoptimizer/Inst added to the repository --- Diffs of the changes: From jstanley at cs.uiuc.edu Wed Mar 5 15:22:00 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 15:22:00 2003 Subject: [llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/Test/ Message-ID: <200303052121.PAA26165@tank.cs.uiuc.edu> Changes in directory llvm/lib/Reoptimizer/Inst/Test: --- Log message: Directory /home/vadve/vadve/Research/DynOpt/CVSRepository/llvm/lib/Reoptimizer/Inst/Test added to the repository --- Diffs of the changes: From jstanley at cs.uiuc.edu Wed Mar 5 15:25:00 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 15:25:00 2003 Subject: [llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/Makefile PerfInst.cpp design.txt Message-ID: <200303052124.PAA26237@tank.cs.uiuc.edu> Changes in directory llvm/lib/Reoptimizer/Inst: Makefile added (r1.1) PerfInst.cpp added (r1.1) design.txt added (r1.1) --- Log message: --- Diffs of the changes: From jstanley at cs.uiuc.edu Wed Mar 5 15:28:00 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 15:28:00 2003 Subject: [llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/Test/Test1.c Message-ID: <200303052127.PAA26390@tank.cs.uiuc.edu> Changes in directory llvm/lib/Reoptimizer/Inst/Test: Test1.c added (r1.1) --- Log message: --- Diffs of the changes: From jstanley at cs.uiuc.edu Wed Mar 5 15:31:01 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 15:31:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Reoptimizer/Inst/Test/Test1.c Message-ID: <200303052130.PAA26547@tank.cs.uiuc.edu> Changes in directory llvm/lib/Reoptimizer/Inst/Test: Test1.c (r1.1) removed --- Log message: --- Diffs of the changes: From lattner at cs.uiuc.edu Wed Mar 5 15:35:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 15:35:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/CFGSimplify/PhiBlockMerge2.ll Message-ID: <200303052134.PAA32452@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/CFGSimplify: PhiBlockMerge2.ll added (r1.1) --- Log message: Add new testcase --- Diffs of the changes: From lattner at cs.uiuc.edu Wed Mar 5 15:37:00 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 15:37:00 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/SimplifyCFG.cpp Message-ID: <200303052136.PAA32465@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: SimplifyCFG.cpp updated: 1.8 -> 1.9 --- Log message: Implement CFGSimplify/PhiBlockMerge*.ll --- Diffs of the changes: Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp diff -u llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.8 llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.9 --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp:1.8 Wed Mar 5 15:01:52 2003 +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp Wed Mar 5 15:36:33 2003 @@ -39,8 +39,8 @@ if (find(BBPreds.begin(), BBPreds.end(), *PI) != BBPreds.end()) { // Loop over all of the PHI nodes checking to see if there are // incompatible values coming in. - BasicBlock::iterator BBI = Succ->begin(); - while (PHINode *PN = dyn_cast(&*BBI++)) { + for (BasicBlock::iterator I = Succ->begin(); + PHINode *PN = dyn_cast(&*I); ++I) { // Loop up the entries in the PHI node for BB and for *PI if the values // coming in are non-equal, we cannot merge these two blocks (instead we // should insert a conditional move or something, then merge the @@ -60,10 +60,19 @@ Value *OldVal = PN->removeIncomingValue(BB, false); assert(OldVal && "No entry in PHI for Pred BB!"); - for (std::vector::const_iterator PredI = BBPreds.begin(), - End = BBPreds.end(); PredI != End; ++PredI) { - // Add an incoming value for each of the new incoming values... - PN->addIncoming(OldVal, *PredI); + // If this incoming value is one of the PHI nodes in BB... + if (isa(OldVal) && cast(OldVal)->getParent() == BB) { + PHINode *OldValPN = cast(OldVal); + for (std::vector::const_iterator PredI = BBPreds.begin(), + End = BBPreds.end(); PredI != End; ++PredI) { + PN->addIncoming(OldValPN->getIncomingValueForBlock(*PredI), *PredI); + } + } else { + for (std::vector::const_iterator PredI = BBPreds.begin(), + End = BBPreds.end(); PredI != End; ++PredI) { + // Add an incoming value for each of the new incoming values... + PN->addIncoming(OldVal, *PredI); + } } } return false; @@ -84,7 +93,6 @@ assert(BB->getTerminator() && "Degenerate basic block encountered!"); assert(&BB->getParent()->front() != BB && "Can't Simplify entry block!"); - // Remove basic blocks that have no predecessors... which are unreachable. if (pred_begin(BB) == pred_end(BB) && !BB->hasConstantReferences()) { @@ -113,11 +121,16 @@ return true; } - // Check to see if this block has no instructions and only a single - // successor. If so, replace block references with successor. + // Check to see if this block has no non-phi instructions and only a single + // successor. If so, replace references to this basic block with references + // to the successor. succ_iterator SI(succ_begin(BB)); if (SI != succ_end(BB) && ++SI == succ_end(BB)) { // One succ? - if (BB->front().isTerminator()) { // Terminator is the only instruction! + + BasicBlock::iterator BBI = BB->begin(); // Skip over phi nodes... + while (isa(*BBI)) ++BBI; + + if (BBI->isTerminator()) { // Terminator is the only non-phi instruction! BasicBlock *Succ = *succ_begin(BB); // There is exactly one successor if (Succ != BB) { // Arg, don't hurt infinite loops! @@ -130,6 +143,19 @@ //cerr << "Killing Trivial BB: \n" << BB; BB->replaceAllUsesWith(Succ); std::string OldName = BB->getName(); + + // Move all PHI nodes in BB to Succ if they are alive, otherwise + // delete them. + while (PHINode *PN = dyn_cast(&BB->front())) + if (PN->use_empty()) + BB->getInstList().erase(BB->begin()); // Nuke instruction... + else { + // The instruction is alive, so this means that Succ must have + // *ONLY* had BB as a predecessor, and the PHI node is still valid + // now. Simply move it into Succ. + BB->getInstList().remove(BB->begin()); + Succ->getInstList().push_front(PN); + } // Delete the old basic block... M->getBasicBlockList().erase(BB); From jstanley at cs.uiuc.edu Wed Mar 5 15:52:01 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 15:52:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Reoptimizer/inst/ Message-ID: <200303052151.PAA27178@tank.cs.uiuc.edu> Changes in directory llvm/test/Regression/Reoptimizer/inst: --- Log message: Directory /home/vadve/vadve/Research/DynOpt/CVSRepository/llvm/test/Regression/Reoptimizer/inst added to the repository --- Diffs of the changes: From jstanley at cs.uiuc.edu Wed Mar 5 16:02:02 2003 From: jstanley at cs.uiuc.edu (Joel Stanley) Date: Wed Mar 5 16:02:02 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Reoptimizer/inst/Test1.c Message-ID: <200303052201.QAA27423@tank.cs.uiuc.edu> Changes in directory llvm/test/Regression/Reoptimizer/inst: Test1.c added (r1.1) --- Log message: --- Diffs of the changes: From lattner at cs.uiuc.edu Wed Mar 5 16:33:00 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 16:33:00 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/getelementptr.ll Message-ID: <200303052232.QAA01649@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: getelementptr.ll updated: 1.7 -> 1.8 --- Log message: Add testcase for new instcombine xform --- Diffs of the changes: Index: llvm/test/Regression/Transforms/InstCombine/getelementptr.ll diff -u llvm/test/Regression/Transforms/InstCombine/getelementptr.ll:1.7 llvm/test/Regression/Transforms/InstCombine/getelementptr.ll:1.8 --- llvm/test/Regression/Transforms/InstCombine/getelementptr.ll:1.7 Mon Nov 4 10:35:14 2002 +++ llvm/test/Regression/Transforms/InstCombine/getelementptr.ll Wed Mar 5 16:32:48 2003 @@ -1,6 +1,6 @@ ; The %A getelementptr instruction should be eliminated here -; RUN: if as < %s | opt -instcombine -die | dis | grep getelementptr | grep '%A' +; RUN: if as < %s | opt -instcombine -die | dis | grep getelementptr | grep '%A ' ; RUN: then exit 1 ; RUN: else exit 0 ; RUN: fi @@ -9,7 +9,7 @@ implementation -int *"foo1"(int * %I) { ; Test noop elimination +int *%foo1(int* %I) { ; Test noop elimination %A = getelementptr int* %I, long 0 ret int * %A } @@ -40,5 +40,11 @@ %M = malloc [4 x int] %A = getelementptr [4 x int]* %M, long 0, long 0 %B = getelementptr int* %A, long 2 + ret int* %B +} + +int* %foo7(int* %I, long %C, long %D) { + %A = getelementptr int* %I, long %C + %B = getelementptr int* %A, long %D ret int* %B } From lattner at cs.uiuc.edu Wed Mar 5 16:34:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 16:34:01 2003 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp Message-ID: <200303052233.QAA01660@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Scalar: InstructionCombining.cpp updated: 1.69 -> 1.70 --- Log message: Implement %test7 in InstCombine/getelementptr.ll --- Diffs of the changes: Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.69 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.70 --- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.69 Tue Feb 18 13:57:07 2003 +++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp Wed Mar 5 16:33:14 2003 @@ -807,14 +807,28 @@ std::vector Indices; // Can we combine the two pointer arithmetics offsets? - if (Src->getNumOperands() == 2 && isa(Src->getOperand(1)) && - isa(GEP.getOperand(1))) { - // Replace the index list on this GEP with the index on the getelementptr - Indices.insert(Indices.end(), GEP.idx_begin(), GEP.idx_end()); - Indices[0] = *cast(Src->getOperand(1)) + + if (Src->getNumOperands() == 2 && isa(Src->getOperand(1)) && + isa(GEP.getOperand(1))) { + // Replace: gep (gep %P, long C1), long C2, ... + // With: gep %P, long (C1+C2), ... + Value *Sum = *cast(Src->getOperand(1)) + *cast(GEP.getOperand(1)); - assert(Indices[0] != 0 && "Constant folding of uint's failed!?"); - + assert(Sum && "Constant folding of longs failed!?"); + GEP.setOperand(0, Src->getOperand(0)); + GEP.setOperand(1, Sum); + AddUsesToWorkList(*Src); // Reduce use count of Src + return &GEP; + } else if (Src->getNumOperands() == 2 && Src->use_size() == 1) { + // Replace: gep (gep %P, long B), long A, ... + // With: T = long A+B; gep %P, T, ... + // + Value *Sum = BinaryOperator::create(Instruction::Add, Src->getOperand(1), + GEP.getOperand(1), + Src->getName()+".sum", &GEP); + GEP.setOperand(0, Src->getOperand(0)); + GEP.setOperand(1, Sum); + WorkList.push_back(cast(Sum)); + return &GEP; } else if (*GEP.idx_begin() == Constant::getNullValue(Type::LongTy) && Src->getNumOperands() != 1) { // Otherwise we can do the fold if the first index of the GEP is a zero From lattner at cs.uiuc.edu Wed Mar 5 16:48:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 16:48:01 2003 Subject: [llvm-commits] CVS: llvm/test/Fragments/NullStone/AliasOptimizationBA.c ForwardStore.c LoopFusion.c Message-ID: <200303052247.QAA02179@apoc.cs.uiuc.edu> Changes in directory llvm/test/Fragments/NullStone: AliasOptimizationBA.c updated: 1.1 -> 1.2 ForwardStore.c updated: 1.1 -> 1.2 LoopFusion.c updated: 1.1 -> 1.2 --- Log message: Tweak testcases so they work properly --- Diffs of the changes: Index: llvm/test/Fragments/NullStone/AliasOptimizationBA.c diff -u llvm/test/Fragments/NullStone/AliasOptimizationBA.c:1.1 llvm/test/Fragments/NullStone/AliasOptimizationBA.c:1.2 --- llvm/test/Fragments/NullStone/AliasOptimizationBA.c:1.1 Sun May 5 23:18:11 2002 +++ llvm/test/Fragments/NullStone/AliasOptimizationBA.c Wed Mar 5 16:47:37 2003 @@ -1,5 +1,5 @@ -int *a, *b; +int a[100], b[100]; void g(int, int); void f (int i, int j) Index: llvm/test/Fragments/NullStone/ForwardStore.c diff -u llvm/test/Fragments/NullStone/ForwardStore.c:1.1 llvm/test/Fragments/NullStone/ForwardStore.c:1.2 --- llvm/test/Fragments/NullStone/ForwardStore.c:1.1 Sun May 5 23:18:11 2002 +++ llvm/test/Fragments/NullStone/ForwardStore.c Wed Mar 5 16:47:37 2003 @@ -1,5 +1,5 @@ -int *a; +int a[100]; int sum; void f (void) Index: llvm/test/Fragments/NullStone/LoopFusion.c diff -u llvm/test/Fragments/NullStone/LoopFusion.c:1.1 llvm/test/Fragments/NullStone/LoopFusion.c:1.2 --- llvm/test/Fragments/NullStone/LoopFusion.c:1.1 Sun May 5 23:18:13 2002 +++ llvm/test/Fragments/NullStone/LoopFusion.c Wed Mar 5 16:47:37 2003 @@ -1,4 +1,4 @@ -int *a, *b; +int a[300], b[300]; void f() { unsigned i; From lattner at cs.uiuc.edu Wed Mar 5 16:52:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 16:52:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/cast-set.ll Message-ID: <200303052251.QAA02445@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: cast-set.ll updated: 1.4 -> 1.5 --- Log message: Add another testcase that may eventually be handled... --- Diffs of the changes: Index: llvm/test/Regression/Transforms/InstCombine/cast-set.ll diff -u llvm/test/Regression/Transforms/InstCombine/cast-set.ll:1.4 llvm/test/Regression/Transforms/InstCombine/cast-set.ll:1.5 --- llvm/test/Regression/Transforms/InstCombine/cast-set.ll:1.4 Thu Aug 15 14:38:03 2002 +++ llvm/test/Regression/Transforms/InstCombine/cast-set.ll Wed Mar 5 16:50:55 2003 @@ -31,3 +31,10 @@ ret bool %cst222 } +int %test4(int %A) { + %B = cast int %A to uint + %C = shl uint %B, ubyte 1 + %D = cast uint %C to int + ret int %D +} + From lattner at cs.uiuc.edu Wed Mar 5 16:58:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 16:58:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/pow.ll Message-ID: <200303052257.QAA02518@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: pow.ll added (r1.1) --- Log message: New testcase for pow builtin recognition --- Diffs of the changes: From lattner at cs.uiuc.edu Wed Mar 5 17:03:01 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 17:03:01 2003 Subject: [llvm-commits] CVS: llvm/test/Regression/Transforms/InstCombine/pow.ll Message-ID: <200303052302.RAA02545@apoc.cs.uiuc.edu> Changes in directory llvm/test/Regression/Transforms/InstCombine: pow.ll updated: 1.1 -> 1.2 --- Log message: Add a link to source of inspiration --- Diffs of the changes: Index: llvm/test/Regression/Transforms/InstCombine/pow.ll diff -u llvm/test/Regression/Transforms/InstCombine/pow.ll:1.1 llvm/test/Regression/Transforms/InstCombine/pow.ll:1.2 --- llvm/test/Regression/Transforms/InstCombine/pow.ll:1.1 Wed Mar 5 16:56:59 2003 +++ llvm/test/Regression/Transforms/InstCombine/pow.ll Wed Mar 5 17:02:25 2003 @@ -1,4 +1,7 @@ ; Testcase for calls to the standard C "pow" function +; +; Equivalent to: http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01786.html + ; RUN: if as < %s | opt -instcombine | dis | grep 'call double %pow' ; RUN: then exit 1 ; RUN: else exit 0 From lattner at cs.uiuc.edu Wed Mar 5 17:20:02 2003 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Wed Mar 5 17:20:02 2003 Subject: [llvm-commits] CVS: llvm/www/www-index.html Message-ID: <200303052319.RAA29446@tank.cs.uiuc.edu> Changes in directory llvm/www: www-index.html updated: 1.17 -> 1.18 --- Log message: Retract the offer for the beta distro --- Diffs of the changes: Index: llvm/www/www-index.html diff -u llvm/www/www-index.html:1.17 llvm/www/www-index.html:1.18 --- llvm/www/www-index.html:1.17 Tue Mar 4 13:43:57 2003 +++ llvm/www/www-index.html Wed Mar 5 17:19:47 2003 @@ -163,11 +163,12 @@
    We currently do not have an LLVM package available for public - consumption. However, we may be willing to make the LLVM - package available in beta form for people who are interested in - using it. Please contact - us if you are interested in trying it out as a beta - site.

    - We currently do not have an LLVM package available for public - consumption. We are currently working towards making our "1.0" - release as solid and reliable as possible, and hope to have a - distribution available by sometime in Summer, 2003. If - you are interested in the project please - email us - and we will notify you when a release is available.