From lattner at cs.uiuc.edu Sun Oct 27 23:00:01 2002 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun Oct 27 23:00:01 2002 Subject: [llvm-commits] CVS: llvm/lib/Target/MachineSchedInfo.cpp Message-ID: <200210280459.WAA02023@apoc.cs.uiuc.edu> Changes in directory llvm/lib/Target: MachineSchedInfo.cpp updated: 1.6 -> 1.7 --- Log message: Make sched class unsigned --- Diffs of the changes: Index: llvm/lib/Target/MachineSchedInfo.cpp diff -u llvm/lib/Target/MachineSchedInfo.cpp:1.6 llvm/lib/Target/MachineSchedInfo.cpp:1.7 --- llvm/lib/Target/MachineSchedInfo.cpp:1.6 Sat Oct 12 19:37:46 2002 +++ llvm/lib/Target/MachineSchedInfo.cpp Sun Oct 27 22:59:43 2002 @@ -126,7 +126,7 @@ // First get the resource usage information from the class resource usages. for (MachineOpCode op = 0; op < numOpCodes; ++op) { InstrSchedClass sc = getSchedClass(op); - assert(sc >= 0 && sc < numSchedClasses); + assert(sc < numSchedClasses); instrRUsages[op] = instrRUForClasses[sc]; } From lattner at cs.uiuc.edu Sun Oct 27 23:31:00 2002 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun Oct 27 23:31:00 2002 Subject: [llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineBasicBlock.h MachineFunction.h Message-ID: <200210280530.XAA04691@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm/CodeGen: MachineBasicBlock.h updated: 1.8 -> 1.9 MachineFunction.h updated: 1.13 -> 1.14 --- Log message: Change MachineBasicBlock's to not be Annotations, instead they are kept as part of a linked list tracked by MachineFunction. MachineBasicBlock::get is now linear time instead of constant time, and thus is deprecated! --- Diffs of the changes: Index: llvm/include/llvm/CodeGen/MachineBasicBlock.h diff -u llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.8 llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.9 --- llvm/include/llvm/CodeGen/MachineBasicBlock.h:1.8 Sun Oct 27 20:08:43 2002 +++ llvm/include/llvm/CodeGen/MachineBasicBlock.h Sun Oct 27 23:30:41 2002 @@ -7,31 +7,28 @@ #ifndef LLVM_CODEGEN_MACHINEBASICBLOCK_H #define LLVM_CODEGEN_MACHINEBASICBLOCK_H -#include "llvm/Annotation.h" #include class BasicBlock; class MachineInstr; template struct ilist_traits; -extern AnnotationID MCFBB_AID; - -class MachineBasicBlock : public Annotation { +class MachineBasicBlock { std::vector Insts; MachineBasicBlock *Prev, *Next; + BasicBlock *BB; public: - MachineBasicBlock() : Annotation(MCFBB_AID) {} + MachineBasicBlock(BasicBlock *bb = 0) : Prev(0), Next(0), BB(bb) {} ~MachineBasicBlock() {} - // Static methods to retrieve or destroy the MachineBasicBlock - // object for a given basic block. - static MachineBasicBlock& get(const BasicBlock *BB) { - return *(MachineBasicBlock*) - ((Annotable*)BB)->getOrCreateAnnotation(MCFBB_AID); - } - - static void destroy(const BasicBlock *BB) { - ((Annotable*)BB)->deleteAnnotation(MCFBB_AID); - } + // get - This deprecated static method returns the MachineBasicBlock object + // for the specified BasicBlock. + // + static MachineBasicBlock& get(const BasicBlock *BB); + + /// getBasicBlock - Return the LLVM basic block that this instance + /// corresponded to originally. + /// + BasicBlock *getBasicBlock() const { return BB; } typedef std::vector::iterator iterator; typedef std::vector::const_iterator const_iterator; Index: llvm/include/llvm/CodeGen/MachineFunction.h diff -u llvm/include/llvm/CodeGen/MachineFunction.h:1.13 llvm/include/llvm/CodeGen/MachineFunction.h:1.14 --- llvm/include/llvm/CodeGen/MachineFunction.h:1.13 Sun Oct 27 20:08:43 2002 +++ llvm/include/llvm/CodeGen/MachineFunction.h Sun Oct 27 23:30:41 2002 @@ -10,6 +10,7 @@ #define LLVM_CODEGEN_MACHINEFUNCTION_H #include "llvm/CodeGen/MachineBasicBlock.h" +#include "llvm/Annotation.h" #include "Support/NonCopyable.h" #include "Support/HashExtras.h" #include "Support/hash_set" @@ -59,9 +60,38 @@ static MachineFunction& construct(const Function *method, const TargetMachine &target); static void destruct(const Function *F); - static MachineFunction& get(const Function* function); - + static MachineFunction& get(const Function *F); + // Provide accessors for the MachineBasicBlock list... + typedef iplist BasicBlockListType; + typedef BasicBlockListType::iterator iterator; + typedef BasicBlockListType::const_iterator const_iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef std::reverse_iterator reverse_iterator; + + // Provide accessors for basic blocks... + const BasicBlockListType &getBasicBlockList() const { return BasicBlocks; } + BasicBlockListType &getBasicBlockList() { return BasicBlocks; } + + //===--------------------------------------------------------------------===// + // BasicBlock iterator forwarding functions + // + iterator begin() { return BasicBlocks.begin(); } + const_iterator begin() const { return BasicBlocks.begin(); } + iterator end () { return BasicBlocks.end(); } + const_iterator end () const { return BasicBlocks.end(); } + + reverse_iterator rbegin() { return BasicBlocks.rbegin(); } + const_reverse_iterator rbegin() const { return BasicBlocks.rbegin(); } + reverse_iterator rend () { return BasicBlocks.rend(); } + const_reverse_iterator rend () const { return BasicBlocks.rend(); } + + unsigned size() const { return BasicBlocks.size(); } + bool empty() const { return BasicBlocks.empty(); } + const MachineBasicBlock &front() const { return BasicBlocks.front(); } + MachineBasicBlock &front() { return BasicBlocks.front(); } + const MachineBasicBlock &back() const { return BasicBlocks.back(); } + MachineBasicBlock &back() { return BasicBlocks.back(); } //===--------------------------------------------------------------------===// // From lattner at cs.uiuc.edu Sun Oct 27 23:31:01 2002 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun Oct 27 23:31:01 2002 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp MachineBasicBlock.cpp Message-ID: <200210280530.XAA04698@apoc.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: MachineFunction.cpp updated: 1.22 -> 1.23 MachineBasicBlock.cpp (r1.4) removed --- Log message: Change MachineBasicBlock's to not be Annotations, instead they are kept as part of a linked list tracked by MachineFunction. MachineBasicBlock::get is now linear time instead of constant time, and thus is deprecated! --- Diffs of the changes: Index: llvm/lib/CodeGen/MachineFunction.cpp diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.22 llvm/lib/CodeGen/MachineFunction.cpp:1.23 --- llvm/lib/CodeGen/MachineFunction.cpp:1.22 Sun Oct 27 20:01:35 2002 +++ llvm/lib/CodeGen/MachineFunction.cpp Sun Oct 27 23:30:44 2002 @@ -72,6 +72,21 @@ } +// get - This deprecated static method returns the MachineBasicBlock object +// for the specified BasicBlock. +// +MachineBasicBlock& MachineBasicBlock::get(const BasicBlock *BB) { + const Function *F = BB->getParent(); + MachineFunction &MF = MachineFunction::get(F); + + for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) + if (I->getBasicBlock() == BB) + return *I; + assert(0 && "MachineBasicBlock object not found for specified block!"); + return get(BB); +} + + //===---------------------------------------------------------------------===// // MachineFunction implementation //===---------------------------------------------------------------------===// From lattner at cs.uiuc.edu Sun Oct 27 23:31:01 2002 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun Oct 27 23:31:01 2002 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp Message-ID: <200210280530.XAA04705@apoc.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen/InstrSelection: InstrSelection.cpp updated: 1.51 -> 1.52 --- Log message: Change MachineBasicBlock's to not be Annotations, instead they are kept as part of a linked list tracked by MachineFunction. MachineBasicBlock::get is now linear time instead of constant time, and thus is deprecated! --- Diffs of the changes: Index: llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp diff -u llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp:1.51 llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp:1.52 --- llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp:1.51 Sun Oct 27 20:01:37 2002 +++ llvm/lib/CodeGen/InstrSelection/InstrSelection.cpp Sun Oct 27 23:30:46 2002 @@ -139,14 +139,20 @@ } // - // Record instructions in the vector for each basic block + // Create the MachineBasicBlock records and add all of the MachineInstrs + // defined in the MachineCodeForInstruction objects to also live in the + // MachineBasicBlock objects. // - for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) + MachineFunction &MF = MachineFunction::get(&F); + for (Function::iterator BI = F.begin(), BE = F.end(); BI != BE; ++BI) { + MachineBasicBlock *MCBB = new MachineBasicBlock(BI); + MF.getBasicBlockList().push_back(MCBB); + for (BasicBlock::iterator II = BI->begin(); II != BI->end(); ++II) { MachineCodeForInstruction &mvec = MachineCodeForInstruction::get(II); - MachineBasicBlock &MCBB = MachineBasicBlock::get(BI); - MCBB.insert(MCBB.end(), mvec.begin(), mvec.end()); + MCBB->insert(MCBB->end(), mvec.begin(), mvec.end()); } + } // Insert phi elimination code InsertCodeForPhis(F); From lattner at cs.uiuc.edu Sun Oct 27 23:59:01 2002 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun Oct 27 23:59:01 2002 Subject: [llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineFunction.h Message-ID: <200210280558.XAA06311@apoc.cs.uiuc.edu> Changes in directory llvm/include/llvm/CodeGen: MachineFunction.h updated: 1.14 -> 1.15 --- Log message: s/method/function --- Diffs of the changes: Index: llvm/include/llvm/CodeGen/MachineFunction.h diff -u llvm/include/llvm/CodeGen/MachineFunction.h:1.14 llvm/include/llvm/CodeGen/MachineFunction.h:1.15 --- llvm/include/llvm/CodeGen/MachineFunction.h:1.14 Sun Oct 27 23:30:41 2002 +++ llvm/include/llvm/CodeGen/MachineFunction.h Sun Oct 27 23:58:42 2002 @@ -27,7 +27,8 @@ Pass *createMachineCodeDestructionPass(); class MachineFunction : private Annotation { - const Function *method; + const Function *Fn; + const TargetMachine &Target; // List of machine basic blocks in function iplist BasicBlocks; @@ -47,8 +48,15 @@ bool automaticVarsAreaFrozen; public: - MachineFunction(const Function* function, - const TargetMachine& target); + MachineFunction(const Function *Fn, const TargetMachine& target); + + /// getFunction - Return the LLVM function that this machine code represents + /// + const Function *getFunction() const { return Fn; } + + /// getTarget - Return the target machine this machine code is compiled with + /// + const TargetMachine &getTarget() const { return Target; } // The next two methods are used to construct and to retrieve // the MachineFunction object for the given method. @@ -57,8 +65,8 @@ // This should not be called before "construct()" // for a given Method. // - static MachineFunction& construct(const Function *method, - const TargetMachine &target); + static MachineFunction& construct(const Function *Fn, + const TargetMachine &target); static void destruct(const Function *F); static MachineFunction& get(const Function *F); From lattner at cs.uiuc.edu Sun Oct 27 23:59:02 2002 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Sun Oct 27 23:59:02 2002 Subject: [llvm-commits] CVS: llvm/lib/CodeGen/MachineFunction.cpp Message-ID: <200210280558.XAA06318@apoc.cs.uiuc.edu> Changes in directory llvm/lib/CodeGen: MachineFunction.cpp updated: 1.23 -> 1.24 --- Log message: s/method/function --- Diffs of the changes: Index: llvm/lib/CodeGen/MachineFunction.cpp diff -u llvm/lib/CodeGen/MachineFunction.cpp:1.23 llvm/lib/CodeGen/MachineFunction.cpp:1.24 --- llvm/lib/CodeGen/MachineFunction.cpp:1.23 Sun Oct 27 23:30:44 2002 +++ llvm/lib/CodeGen/MachineFunction.cpp Sun Oct 27 23:58:46 2002 @@ -99,24 +99,23 @@ // for a given Function. // MachineFunction& -MachineFunction::construct(const Function *M, const TargetMachine &Tar) +MachineFunction::construct(const Function *Fn, const TargetMachine &Tar) { - assert(M->getAnnotation(MCFM_AID) == 0 && + assert(Fn->getAnnotation(MCFM_AID) == 0 && "Object already exists for this function!"); - MachineFunction* mcInfo = new MachineFunction(M, Tar); - M->addAnnotation(mcInfo); + MachineFunction* mcInfo = new MachineFunction(Fn, Tar); + Fn->addAnnotation(mcInfo); return *mcInfo; } void -MachineFunction::destruct(const Function *M) +MachineFunction::destruct(const Function *Fn) { - bool Deleted = M->deleteAnnotation(MCFM_AID); + bool Deleted = Fn->deleteAnnotation(MCFM_AID); assert(Deleted && "Machine code did not exist for function!"); } -MachineFunction& -MachineFunction::get(const Function *F) +MachineFunction& MachineFunction::get(const Function *F) { MachineFunction *mc = (MachineFunction*)F->getAnnotation(MCFM_AID); assert(mc && "Call construct() method first to allocate the object"); @@ -191,15 +190,15 @@ /*ctor*/ MachineFunction::MachineFunction(const Function *F, - const TargetMachine& target) + const TargetMachine& target) : Annotation(MCFM_AID), - method(F), staticStackSize(0), + Fn(F), Target(target), staticStackSize(0), automaticVarsSize(0), regSpillsSize(0), maxOptionalArgsSize(0), maxOptionalNumArgs(0), currentTmpValuesSize(0), maxTmpValuesSize(0), compiledAsLeaf(false), spillsAreaFrozen(false), automaticVarsAreaFrozen(false) { - maxOptionalArgsSize = ComputeMaxOptionalArgsSize(target, method, + maxOptionalArgsSize = ComputeMaxOptionalArgsSize(target, Fn, maxOptionalNumArgs); staticStackSize = maxOptionalArgsSize + target.getFrameInfo().getMinStackFrameSize(); @@ -310,10 +309,10 @@ void MachineFunction::dump() const { - std::cerr << "\n" << method->getReturnType() - << " \"" << method->getName() << "\"\n"; + std::cerr << "\n" << Fn->getReturnType() + << " \"" << Fn->getName() << "\"\n"; - for (Function::const_iterator BB = method->begin(); BB != method->end(); ++BB) + for (Function::const_iterator BB = Fn->begin(); BB != Fn->end(); ++BB) { std::cerr << "\n" << BB->getName() << " (" << (const void*)BB << ")" << ":" << "\n"; @@ -321,5 +320,5 @@ for (unsigned i=0; i < mvec.size(); i++) std::cerr << "\t" << *mvec[i]; } - std::cerr << "\nEnd function \"" << method->getName() << "\"\n\n"; + std::cerr << "\nEnd function \"" << Fn->getName() << "\"\n\n"; }