From gaeke at cs.uiuc.edu Mon May 17 15:37:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 15:37:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/ Message-ID: <200405172036.PAA21232@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: --- Log message: Directory /home/vadve/shared/InternalCVS/reopt/lib/TraceToFunction added to the repository --- Diffs of the changes: (+0 -0) From gaeke at cs.uiuc.edu Mon May 17 15:38:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 15:38:03 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/Makefile Message-ID: <200405172037.PAA21245@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: Makefile added (r1.1) --- Log message: Splitting traceToFunction transformation out into its own library --- Diffs of the changes: (+4 -0) Index: reopt/lib/TraceToFunction/Makefile diff -c /dev/null reopt/lib/TraceToFunction/Makefile:1.1 *** /dev/null Mon May 17 15:37:31 2004 --- reopt/lib/TraceToFunction/Makefile Mon May 17 15:37:21 2004 *************** *** 0 **** --- 1,4 ---- + LEVEL = ../.. + LIBRARYNAME = tracetofunction + + include $(LEVEL)/Makefile.common From gaeke at cs.uiuc.edu Mon May 17 15:57:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 15:57:04 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceCache/InstrUtils.cpp VirtualMem.cpp Message-ID: <200405172056.PAA22388@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceCache: InstrUtils.cpp updated: 1.18 -> 1.19 VirtualMem.cpp updated: 1.17 -> 1.18 --- Log message: Add debug printouts to doFlush and VirtualMem's write methods --- Diffs of the changes: (+7 -0) Index: reopt/lib/TraceCache/InstrUtils.cpp diff -u reopt/lib/TraceCache/InstrUtils.cpp:1.18 reopt/lib/TraceCache/InstrUtils.cpp:1.19 --- reopt/lib/TraceCache/InstrUtils.cpp:1.18 Mon Apr 26 15:02:59 2004 +++ reopt/lib/TraceCache/InstrUtils.cpp Mon May 17 15:56:09 2004 @@ -6,6 +6,7 @@ //===----------------------------------------------------------------------===// #include "reopt/InstrUtils.h" +#include "Support/Debug.h" #include #include @@ -201,6 +202,7 @@ } void doFlush(uint64_t st_addr, uint64_t end_addr){ + DEBUG (std::cerr << "doFlush(" << st_addr << ", " << end_addr << ")\n"); #ifdef __sparc__ if(st_addr % 8 != 0) st_addr &= ~7; // Round down to the next lower doubleword boundary Index: reopt/lib/TraceCache/VirtualMem.cpp diff -u reopt/lib/TraceCache/VirtualMem.cpp:1.17 reopt/lib/TraceCache/VirtualMem.cpp:1.18 --- reopt/lib/TraceCache/VirtualMem.cpp:1.17 Mon Apr 26 14:49:59 2004 +++ reopt/lib/TraceCache/VirtualMem.cpp Mon May 17 15:56:09 2004 @@ -9,6 +9,7 @@ #include "reopt/InstrUtils.h" #include "reopt/TraceCache.h" #include "reopt/GetTraceTime.h" +#include "Support/Debug.h" #include #include #include @@ -54,6 +55,8 @@ /// writeInstToVM - Emit the word newInstr to memory at address destAddr. /// void VirtualMem::writeInstToVM (uint64_t destAddr, unsigned int newInstr) { + DEBUG (std::cerr << "writeInstToVM (" << std::hex << destAddr << ", " + << newInstr << ");\n" << std::dec); lseek (fp, destAddr, SEEK_SET); write (fp, &newInstr, sizeof (unsigned int)); } @@ -63,6 +66,8 @@ /// void VirtualMem::writeTraceToVM (uint64_t destAddr, std::vector &newInstrs) { + DEBUG (std::cerr << "writeTraceToVM ("< Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.35 -> 1.36 --- Log message: TraceToFunction.h has moved. --- Diffs of the changes: (+1 -1) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.35 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.36 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.35 Sat May 15 19:52:05 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon May 17 16:00:47 2004 @@ -23,7 +23,7 @@ // //===----------------------------------------------------------------------===// -#include "TraceToFunction.h" +#include "reopt/TraceToFunction.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Pass.h" #include "llvm/Module.h" From gaeke at cs.uiuc.edu Mon May 17 16:01:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:01:04 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceToFunction.cpp TraceToFunction.h Message-ID: <200405172100.QAA22419@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: TraceToFunction.cpp (r1.35) removed TraceToFunction.h (r1.11) removed --- Log message: Moving these files. --- Diffs of the changes: (+0 -0) From gaeke at cs.uiuc.edu Mon May 17 16:01:05 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:01:05 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp UnpackTraceFunction.cpp Message-ID: <200405172100.QAA22412@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.31 -> 1.32 UnpackTraceFunction.cpp updated: 1.60 -> 1.61 --- Log message: TraceToFunction's header file has been moved. --- Diffs of the changes: (+2 -2) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.31 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.32 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.31 Wed May 5 14:12:32 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Mon May 17 16:00:19 2004 @@ -14,7 +14,7 @@ //===----------------------------------------------------------------------===// #include "ReoptimizerInternal.h" -#include "TraceToFunction.h" +#include "reopt/TraceToFunction.h" #include "reopt/VirtualMem.h" #include "reopt/InstrUtils.h" #include "Support/Debug.h" Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.60 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.61 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.60 Mon May 10 16:06:20 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Mon May 17 16:00:19 2004 @@ -13,7 +13,7 @@ // //===----------------------------------------------------------------------===// -#include "TraceToFunction.h" +#include "reopt/TraceToFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" #include "llvm/CodeGen/MachineFunctionInfo.h" #include "llvm/CodeGen/MachineInstr.h" From gaeke at cs.uiuc.edu Mon May 17 16:16:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:16:04 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Verifier.cpp Message-ID: <200405172115.QAA23053@seraph.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Verifier.cpp updated: 1.97 -> 1.98 --- Log message: Fold two assertions with backwards error messages into one with a correct error message. --- Diffs of the changes: (+3 -6) Index: llvm/lib/VMCore/Verifier.cpp diff -u llvm/lib/VMCore/Verifier.cpp:1.97 llvm/lib/VMCore/Verifier.cpp:1.98 --- llvm/lib/VMCore/Verifier.cpp:1.97 Tue May 4 16:46:05 2004 +++ llvm/lib/VMCore/Verifier.cpp Mon May 17 16:15:18 2004 @@ -303,12 +303,9 @@ Assert1(PN->getNumIncomingValues() != 0, "PHI nodes must have at least one entry. If the block is dead, " "the PHI should be removed!", PN); - Assert1(PN->getNumIncomingValues() >= Preds.size(), - "PHINode has more entries than the basic block has predecessors!", - PN); - Assert1(PN->getNumIncomingValues() <= Preds.size(), - "PHINode has less entries than the basic block has predecessors!", - PN); + Assert1(PN->getNumIncomingValues() == Preds.size(), + "PHINode should have one entry for each predecessor of its " + "parent basic block!", PN); // Get and sort all incoming values in the PHI node... std::vector > Values; From gaeke at cs.uiuc.edu Mon May 17 16:18:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:18:03 2004 Subject: [llvm-commits] CVS: reopt/tools/ttftest/ Message-ID: <200405172118.QAA23080@seraph.cs.uiuc.edu> Changes in directory reopt/tools/ttftest: --- Log message: Directory /home/vadve/shared/InternalCVS/reopt/tools/ttftest added to the repository --- Diffs of the changes: (+0 -0) From gaeke at cs.uiuc.edu Mon May 17 16:18:06 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:18:06 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Analysis/Trace.h Message-ID: <200405172117.QAA23068@seraph.cs.uiuc.edu> Changes in directory llvm/include/llvm/Analysis: Trace.h updated: 1.2 -> 1.3 --- Log message: Define erase forwarding method on traces --- Diffs of the changes: (+3 -0) Index: llvm/include/llvm/Analysis/Trace.h diff -u llvm/include/llvm/Analysis/Trace.h:1.2 llvm/include/llvm/Analysis/Trace.h:1.3 --- llvm/include/llvm/Analysis/Trace.h:1.2 Mon Mar 8 15:07:12 2004 +++ llvm/include/llvm/Analysis/Trace.h Mon May 17 16:17:21 2004 @@ -101,6 +101,9 @@ unsigned size() const { return BasicBlocks.size(); } bool empty() const { return BasicBlocks.empty(); } + iterator erase(iterator q) { return BasicBlocks.erase (q); } + iterator erase(iterator q1, iterator q2) { return BasicBlocks.erase (q1, q2); } + /// print - Write trace to output stream. /// void print (std::ostream &O) const; From gaeke at cs.uiuc.edu Mon May 17 16:26:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:26:02 2004 Subject: [llvm-commits] CVS: reopt/tools/ttftest/Makefile ttftest.cpp Message-ID: <200405172125.QAA23283@seraph.cs.uiuc.edu> Changes in directory reopt/tools/ttftest: Makefile added (r1.1) ttftest.cpp added (r1.1) --- Log message: Add ttftest (TraceToFunction tester) program --- Diffs of the changes: (+114 -0) Index: reopt/tools/ttftest/Makefile diff -c /dev/null reopt/tools/ttftest/Makefile:1.1 *** /dev/null Mon May 17 16:25:35 2004 --- reopt/tools/ttftest/Makefile Mon May 17 16:25:25 2004 *************** *** 0 **** --- 1,9 ---- + LEVEL = ../.. + TOOLNAME = ttftest + USEDLIBS = tracetofunction + LLVMLIBS = vmcore bcreader analysis.a transformutils.a support.a + + TOOLLINKOPTS = $(PLATFORMLIBDL) + + include $(LEVEL)/Makefile.common + Index: reopt/tools/ttftest/ttftest.cpp diff -c /dev/null reopt/tools/ttftest/ttftest.cpp:1.1 *** /dev/null Mon May 17 16:25:35 2004 --- reopt/tools/ttftest/ttftest.cpp Mon May 17 16:25:25 2004 *************** *** 0 **** --- 1,105 ---- + //===- ttftest.cpp - Test TraceToFunction transformation ------------------===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for + // details. + // + //===----------------------------------------------------------------------===// + // + // A simple program for testing TraceToFunction. This reads in a trace + // from a file, converts it to a function, and tries to verify the + // function. + // + //===----------------------------------------------------------------------===// + + #include "llvm/Analysis/Trace.h" + #include "llvm/Analysis/Verifier.h" + #include "llvm/Bytecode/Reader.h" + #include "reopt/TraceToFunction.h" + #include "llvm/Module.h" + #include + #include + #include + #include + using namespace llvm; + + /// getBasicBlockByNum - Returns the basic block in F whose index is + /// bbNum. + /// + BasicBlock *getBasicBlockByNum (Function *F, int bbNum) { + Function::iterator block = F->begin(); + std::advance (block, bbNum); + return block; + } + + /// ReadTraceFromFile - Given a module, read a trace for some function + /// in that module from the named file. Returns the Trace object, or a null + /// pointer (and sets ErrorStr) if there was an error. + /// + Trace *ReadTraceFromFile (Module *M, const char *filename, + std::string *ErrorStr) { + std::ifstream in (filename); + if (!in.good()) { + if (ErrorStr) + *ErrorStr = std::string("Can't open '") + filename + "': " + + strerror(errno); + return 0; + } + char functionName[160]; + in.getline(functionName, 160, '\n'); + Function *F = M->getNamedFunction (functionName); + if (!F) { + if (ErrorStr) + *ErrorStr = std::string("Function '") + functionName + + "' not found in module"; + return 0; + } + std::cerr << "Function name: '" << functionName << "'\n" << "Basic blocks: "; + std::vector vBB; + do { + int basicBlockNum; + in >> basicBlockNum; + if (!in.eof ()) { + std::cerr << basicBlockNum << " "; + vBB.push_back (getBasicBlockByNum (F, basicBlockNum)); + } + } while (!in.eof ()); + std::cerr << "\n"; + return new Trace (vBB); + } + + int main (int argc, char **argv) { + const char *bytecodeFileName = argv[1]; + const char *traceFileName = argv[2]; + + // Read bytecode file + std::string err; + Module *M = ParseBytecodeFile(bytecodeFileName, &err); + if (!M) { + std::cerr << "Error reading bytecode: " << err << "\n"; + exit (1); + } + + // Read trace file + std::vector vBB; + Trace *T = ReadTraceFromFile (M, traceFileName, &err); + if (!T) { + std::cerr << "Error reading trace: " << err << "\n"; + exit (1); + } + + // Run TraceToFunction on the Trace + TraceFunction *TF = TraceFunction::get (*T); + std::cerr << *TF->TraceFn << "\n\n"; + + // Run Verifier on the resulting TraceFunction + if (verifyFunction (*TF->TraceFn, PrintMessageAction)) { + std::cerr << "Verifier fails.\n"; + exit (1); + } else { + std::cerr << "Verifier passes.\n"; + exit (0); + } + } From gaeke at cs.uiuc.edu Mon May 17 16:32:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:32:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405172131.QAA23494@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.36 -> 1.37 --- Log message: Rename isFirstLevelInstrumentationBlock to getFLIEdgeTarget. Add corresponding getFLIEdgeSource method. Wrap long comment lines. Only get branch successor node once, and store it in a value, in fixupFunctionBodyBB(). --- Diffs of the changes: (+34 -10) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.36 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.37 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.36 Mon May 17 16:00:47 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon May 17 16:30:55 2004 @@ -410,24 +410,47 @@ fixupPhisAndCalls (FI, O2CMap); } -/// isFirstLevelInstrumentationBlock - returns a nonzero value iff BB is a +/// getFLIEdgeTarget - returns a nonzero value iff BB is a /// basic block containing only a call to the first-level instrumentation /// function. Basic blocks of this form are inserted by the -instloops pass on /// loop back-edges. The return value is the target of the back-edge. /// -static BasicBlock *isFirstLevelInstrumentationBlock (BasicBlock *BB) { +static BasicBlock *getFLIEdgeTarget (BasicBlock *BB) { BasicBlock::iterator i = BB->begin (); // starts with llvm_first_trigger call if (!isFirstTriggerCall (*i)) - return false; - // Next instr. should be an unconditional branch - return its target, or NULL if - // there is a mismatch. + return 0; + // Next instr. should be an unconditional branch - return its target, + // or NULL if there is a mismatch. BranchInst *BI = dyn_cast (++i); if (!(BI && BI->isUnconditional())) return 0; return BI->getSuccessor (0); } +/// getFLIEdgeSource - returns a nonzero value iff BB is a +/// basic block containing only a call to the first-level instrumentation +/// function. Basic blocks of this form are inserted by the -instloops pass on +/// loop back-edges. The return value is the source of the back-edge. +/// +static BasicBlock *getFLIEdgeSource (BasicBlock *BB) { + BasicBlock::iterator i = BB->begin (); + // starts with llvm_first_trigger call + if (!isFirstTriggerCall (*i)) + return 0; + // Next instr. should be an unconditional branch. Return NULL if + // there is a mismatch. + BranchInst *BI = dyn_cast (++i); + if (!(BI && BI->isUnconditional())) + return 0; + // Use CFG predecessor iterator to get the predecessor of the FLI block + pred_iterator PI = pred_begin (BB); + DEBUG(pred_iterator NextPI = PI; ++NextPI; + assert (NextPI == pred_end (BB) && + "FLI block must have only one predecessor")); + return *PI; +} + /// fixupFunctionBodyBB - Given srcB in T and its clone dstB in F, and /// the map O2CMap detailing the correspondences between values in T /// and values in F, fix up dstB so that its contents are internally @@ -480,13 +503,14 @@ && "Trace-exiting branch's clone is null, or not a branch?"); BranchInst *BIinF = cast (V); for (unsigned i = 0; i < BI->getNumSuccessors (); ++i) { + BasicBlock *successor = BI->getSuccessor (i); if (BasicBlock *backEdgeTarget = - isFirstLevelInstrumentationBlock (BI->getSuccessor (i))) { + getFLIEdgeTarget (successor)) { std::cerr << "Branch instr " << *BI << " looks like an instrumented " << "backedge from " << srcB->getName() << " to " << backEdgeTarget->getName () << "\n"; } - if (!T.contains (BI->getSuccessor (i))) { + if (!T.contains (successor)) { // This is a trace-exiting destination of branch BI. Create a new // basic block FB for its destination in the function. std::string name ("exitfixup" + utostr (BranchNumber[BI]) + "_" @@ -496,7 +520,7 @@ BIinF->setSuccessor (i, FB); // Remember that FB's "return" instruction would involve a // return to the off-trace successor we just found. - TF->ReturnBlockForTraceExit[FB] = BI->getSuccessor (i); + TF->ReturnBlockForTraceExit[FB] = successor; // Add the getelementptr/store instruction pairs here that // correspond to each live-out variable. unsigned Slot = 0; @@ -524,13 +548,13 @@ } else { // This is a non-trace-exiting destination of branch BI. Fix up // its clone's destination to point to its successor's clone. - Value *V2 = O2CMap[BI->getSuccessor (i)]; + Value *V2 = O2CMap[successor]; DEBUG(if (!V2) { std::cerr << "I'm confused: saw non-trace-exiting dest. of branch " << *BI << " whose clone is " << *BIinF << " successor number is " << i << " and successor is " - << *BI->getSuccessor (i) << ", but where's its clone?\n"; + << *successor << ", but where's its clone?\n"; assert(V2 && "Clone of basic block on trace is null?"); }); assert(isa (V2) From gaeke at cs.uiuc.edu Mon May 17 16:38:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:38:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405172137.QAA23768@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.37 -> 1.38 --- Log message: If we find FLI blocks in the trace, remove them. We don't want any FLI in the optimized trace code. --- Diffs of the changes: (+9 -0) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.37 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.38 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.37 Mon May 17 16:30:55 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon May 17 16:37:13 2004 @@ -384,6 +384,8 @@ } } +static BasicBlock *getFLIEdgeTarget (BasicBlock *BB); + /// fillInFunctionBody - Clone the BBs of T into F, then do all /// necessary fixups to ensure that F's new contents are internally /// consistent and that the live-outs So get stored in F's first @@ -392,6 +394,13 @@ void TraceFunctionBuilder::fillInFunctionBody (Trace &T, Function *F, LiveVariableSet &So) { ValueMap &O2CMap = TF->O2CMap; + + // Remove any FLI blocks which ended up in the trace. + Trace::iterator i; + while ((i = std::find_if (T.begin (), T.end (), getFLIEdgeTarget)) + != T.end ()) + T.erase (i); + // First copy the basic blocks from the trace. cloneTraceBBsIntoFunction (T, F, O2CMap); From gaeke at cs.uiuc.edu Mon May 17 16:39:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:39:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405172138.QAA23786@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.38 -> 1.39 --- Log message: Removing FLI calls should no longer be necessary at this later stage. --- Diffs of the changes: (+0 -6) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.38 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.39 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.38 Mon May 17 16:37:13 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon May 17 16:38:18 2004 @@ -364,12 +364,6 @@ "Sorry, fixupPhisAndCalls mishandled a Phi node")); } - // Remove calls to first-level instrumentation if we find them. - for (BasicBlock::iterator BI = dstB->begin (), BE = dstB->end (); - BI != BE; ++BI) - if (isFirstTriggerCall (*BI)) - goners.push_back (BI); - while (!goners.empty ()) { assert (goners.back ()->use_size () == 0 && "Whoops, I was going to delete something which still has uses"); From gaeke at cs.uiuc.edu Mon May 17 16:50:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Mon May 17 16:50:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405172149.QAA23896@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.39 -> 1.40 --- Log message: Fold branches that go to FLI blocks, and PHI sources that come from FLI blocks. Untabify. --- Diffs of the changes: (+25 -12) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.39 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.40 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.39 Mon May 17 16:38:18 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Mon May 17 16:49:37 2004 @@ -482,17 +482,22 @@ // to guess which one it is. Assume it's any phi value source in // the entry BB which is not in the trace. for (BasicBlock::iterator BI = srcB->begin (); - PHINode *PN = dyn_cast (BI); ++BI) - for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) - if (!T.contains (PN->getIncomingBlock (i))) { - // FIXME: Assert that O2CMap[PN]'s value i is live in. - Value *V = O2CMap[PN]; - assert (V && "Can't find clone of Phi node from trace entry BB"); - PHINode *PNinF = dyn_cast (V); - assert (PNinF - && "Clone of Phi node from entry BB is not a Phi node"); - PNinF->setIncomingBlock (i, EntryFixup); - } + PHINode *PN = dyn_cast (BI); ++BI) + for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) { + // Fold Phi sources which come from FLI blocks + BasicBlock *phiSource = PN->getIncomingBlock (i); + if (BasicBlock *realSource = getFLIEdgeSource (phiSource)) + phiSource = realSource; + if (!T.contains (phiSource)) { + // FIXME: Assert that O2CMap[PN]'s value i is live in. + Value *V = O2CMap[PN]; + assert (V && "Can't find clone of Phi node from trace entry BB"); + PHINode *PNinF = dyn_cast (V); + assert (PNinF + && "Clone of Phi node from entry BB is not a Phi node"); + PNinF->setIncomingBlock (i, EntryFixup); + } + } } // If srcB contains a trace-exiting branch B, fix up B's clone in @@ -507,11 +512,13 @@ BranchInst *BIinF = cast (V); for (unsigned i = 0; i < BI->getNumSuccessors (); ++i) { BasicBlock *successor = BI->getSuccessor (i); + // Fold branches which go to FLI blocks if (BasicBlock *backEdgeTarget = getFLIEdgeTarget (successor)) { std::cerr << "Branch instr " << *BI << " looks like an instrumented " - << "backedge from " << srcB->getName() << " to " + << "back-edge from " << srcB->getName() << " to " << backEdgeTarget->getName () << "\n"; + successor = backEdgeTarget; } if (!T.contains (successor)) { // This is a trace-exiting destination of branch BI. Create a new @@ -573,6 +580,12 @@ Instruction &I = *BI; for (unsigned i = 0; i < I.getNumOperands (); ++i) { Value *V = I.getOperand (i); + // Fold Phi sources which come from FLI blocks + if (isa (&I)) + if (BasicBlock *phiSource = dyn_cast (V)) + if (BasicBlock *realSource = getFLIEdgeSource (phiSource)) + V = realSource; + // If the instruction I has an operand which is in the live-in // set of the trace, then we must replace that operand with // the corresponding argument of F. We can find out which From brukman at cs.uiuc.edu Mon May 17 17:25:02 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Mon May 17 17:25:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/BasicBlock.h Message-ID: <200405172225.RAA19380@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: BasicBlock.h updated: 1.38 -> 1.39 --- Log message: * Minor aesthetic alignment of iterator declarations * Removed redundant function comments --- Diffs of the changes: (+2 -5) Index: llvm/include/llvm/BasicBlock.h diff -u llvm/include/llvm/BasicBlock.h:1.38 llvm/include/llvm/BasicBlock.h:1.39 --- llvm/include/llvm/BasicBlock.h:1.38 Tue Feb 10 19:17:58 2004 +++ llvm/include/llvm/BasicBlock.h Mon May 17 17:25:12 2004 @@ -61,17 +61,14 @@ public: /// Instruction iterators... - typedef InstListType::iterator iterator; - typedef InstListType::const_iterator const_iterator; + typedef InstListType::iterator iterator; + typedef InstListType::const_iterator const_iterator; typedef std::reverse_iterator const_reverse_iterator; typedef std::reverse_iterator reverse_iterator; /// BasicBlock ctor - If the function parameter is specified, the basic block /// is automatically inserted at either the end of the function (if /// InsertBefore is null), or before the specified basic block. - /// - /// BasicBlock ctor - If the InsertBefore parameter is specified, the basic - /// block is automatically inserted right before the specified block. /// BasicBlock(const std::string &Name = "", Function *Parent = 0, BasicBlock *InsertBefore = 0); From brukman at cs.uiuc.edu Mon May 17 17:28:01 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Mon May 17 17:28:01 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/BasicBlock.h Message-ID: <200405172228.RAA21428@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm: BasicBlock.h updated: 1.39 -> 1.40 --- Log message: Minor aesthetic alignments; no functional changes. --- Diffs of the changes: (+3 -3) Index: llvm/include/llvm/BasicBlock.h diff -u llvm/include/llvm/BasicBlock.h:1.39 llvm/include/llvm/BasicBlock.h:1.40 --- llvm/include/llvm/BasicBlock.h:1.39 Mon May 17 17:25:12 2004 +++ llvm/include/llvm/BasicBlock.h Mon May 17 17:28:21 2004 @@ -108,12 +108,12 @@ inline reverse_iterator rend () { return InstList.rend(); } inline const_reverse_iterator rend () const { return InstList.rend(); } - inline unsigned size() const { return InstList.size(); } + inline unsigned size() const { return InstList.size(); } inline bool empty() const { return InstList.empty(); } inline const Instruction &front() const { return InstList.front(); } inline Instruction &front() { return InstList.front(); } - inline const Instruction &back() const { return InstList.back(); } - inline Instruction &back() { return InstList.back(); } + inline const Instruction &back() const { return InstList.back(); } + inline Instruction &back() { return InstList.back(); } /// getInstList() - Return the underlying instruction list container. You /// need to access it directly if you want to modify it currently. From brukman at cs.uiuc.edu Mon May 17 19:21:01 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Mon May 17 19:21:01 2004 Subject: [llvm-commits] [parallel] CVS: llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp Message-ID: <200405180020.TAA17850@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Parallel: BreakJoinBlocks.cpp updated: 1.1.2.1 -> 1.1.2.2 --- Log message: * Also consider LLVM thread start calls, not just the intrinsic * Split before and after the join, so that it's the only remaining part of the basic block, apart from the terminator --- Diffs of the changes: (+15 -4) Index: llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp diff -u llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp:1.1.2.1 llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp:1.1.2.2 --- llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp:1.1.2.1 Thu May 6 11:34:58 2004 +++ llvm/lib/Transforms/Parallel/BreakJoinBlocks.cpp Mon May 17 19:20:27 2004 @@ -11,9 +11,10 @@ // //===----------------------------------------------------------------------===// -#include "llvm/iOther.h" -#include "llvm/Function.h" #include "llvm/BasicBlock.h" +#include "llvm/Function.h" +#include "llvm/iOther.h" +#include "llvm/iTerminators.h" #include "llvm/Pass.h" #include "llvm/Transforms/Utils/FunctionUtils.h" using namespace llvm; @@ -44,9 +45,18 @@ BasicBlock *BB = Worklist.back(); Worklist.pop_back(); if (CallInst *CI = findJoin(BB)) { + // Break away everything after the join + BasicBlock::iterator Next(CI); ++Next; + if (!isa(Next) || isa(Next)) { + BasicBlock *newBB = + BB->splitBasicBlock(Next, BB->getName() + "_postsplit"); + if (newBB) Worklist.push_back(newBB); + } + + // Break away the join from anything before it BasicBlock::iterator II(CI); if (II != BB->begin()) { - BasicBlock *newBB = BB->splitBasicBlock(II, BB->getName() + "_split"); + BasicBlock *newBB = BB->splitBasicBlock(II, BB->getName() +"_presplit"); if (newBB) Worklist.push_back(newBB); } } @@ -58,7 +68,8 @@ CallInst* BreakJoin::findJoin(BasicBlock *BB) { for (BasicBlock::iterator i = BB->begin(), e = BB->end(); i != e; ++i) if (CallInst *CI = dyn_cast(i)) - if (CI->getCalledFunction()->getName() == "llvm.join") + if (CI->getCalledFunction()->getName() == "llvm.join" || + CI->getCalledFunction()->getName() == "__llvm_thread_join") return CI; return 0; From brukman at cs.uiuc.edu Mon May 17 19:25:01 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Mon May 17 19:25:01 2004 Subject: [llvm-commits] [parallel] CVS: llvm/lib/Transforms/Parallel/LowerParaBr.cpp Message-ID: <200405180024.TAA17947@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Parallel: LowerParaBr.cpp updated: 1.1.2.2 -> 1.1.2.3 --- Log message: Create a unified join block which contains all the join calls for the region --- Diffs of the changes: (+75 -8) Index: llvm/lib/Transforms/Parallel/LowerParaBr.cpp diff -u llvm/lib/Transforms/Parallel/LowerParaBr.cpp:1.1.2.2 llvm/lib/Transforms/Parallel/LowerParaBr.cpp:1.1.2.3 --- llvm/lib/Transforms/Parallel/LowerParaBr.cpp:1.1.2.2 Fri May 7 16:37:09 2004 +++ llvm/lib/Transforms/Parallel/LowerParaBr.cpp Mon May 17 19:24:12 2004 @@ -16,10 +16,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/BasicBlock.h" #include "llvm/DerivedTypes.h" -#include "llvm/Module.h" #include "llvm/iOther.h" #include "llvm/iTerminators.h" +#include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Type.h" #include "llvm/Analysis/ParallelInfo.h" @@ -44,6 +45,7 @@ private: void straightenSequence(ParallelSeq *PS); Function* getJoinIntrinsic(Module *M); + Function* getFuncThreadJoin(Module &M); }; RegisterOpt X("lowerpbr", "Lower pbr to sequential code"); @@ -67,10 +69,21 @@ return Changed; } -static bool contains(std::vector haystack, BasicBlock *needle) { +static inline bool +contains(const std::vector &haystack, const BasicBlock *needle) { return std::find(haystack.begin(), haystack.end(), needle) != haystack.end(); } +static inline bool +containsJoin(const std::vector &haystack, const CallInst *needle) { + for (std::vector::const_iterator h = haystack.begin(), + he = haystack.end(); h != he; ++h) + if ((*h)->getOperand(1) == needle->getOperand(1)) + return true; + + return false; +} + /// straightenSequence - Recursively process parallel sequences /// void LowerParaBr::straightenSequence(ParallelSeq *PS) { @@ -80,15 +93,16 @@ { PrevPR = PR; PR = *i; +#if 0 for (ParallelRegion::seqiterator ci = PR->seqbegin(), ce = PR->seqend(); ci != ce; ++ci) straightenSequence(*ci); - - // Stitch previous region to the current one by all branches to the join - // block instead branch to the first block of the second region +#endif if (PrevPR) { + // Stitch previous region to the current one by all branches to the join + // block instead branch to the first block of the second region std::vector &PrevJoinBlocks = PrevPR->getJoinBlocks(), - &PRBlocks = PR->getBlocks(); + &PRJoinBlocks = PR->getJoinBlocks(), &PRBlocks = PR->getBlocks(); BasicBlock *PRFirstBB = PRBlocks[0]; for (std::vector::iterator j = PrevJoinBlocks.begin(), je = PrevJoinBlocks.end(); j != je; ++j) { @@ -96,9 +110,55 @@ for (std::vector::iterator u = JUsers.begin(), ue = JUsers.end(); u != ue; ++u) if (Instruction *I = dyn_cast(*u)) - if (contains(PR->getBlocks(), I->getParent())) + if (contains(PrevPR->getBlocks(), I->getParent())) I->replaceUsesOfWith(*j, PRFirstBB); } + + // Make a new join block that will house all the (coallesced) joins from + // both regions + BasicBlock *SumJoins = new BasicBlock("allJoins", PRFirstBB->getParent()); + + // Find the unique set of calls to the llvm.join intrinsic + std::vector AllJoins; + for (std::vector::iterator i = PrevJoinBlocks.begin(), + e = PrevJoinBlocks.end(); i != e; ++i) { + BasicBlock *BB = *i; + for (BasicBlock::iterator j = BB->begin(), je = BB->end(); j!=je; ++j) + if (CallInst *CI = dyn_cast(j)) + if (CI->getCalledFunction()->getName() == "__llvm_thread_join") + if (!containsJoin(AllJoins, CI)) + AllJoins.push_back(CI); + } + for (std::vector::iterator i = PRJoinBlocks.begin(), + e = PRJoinBlocks.end(); i != e; ++i) { + BasicBlock *BB = *i; + for (BasicBlock::iterator j = BB->begin(), je = BB->end(); j!=je; ++j) + if (CallInst *CI = dyn_cast(j)) + if (CI->getCalledFunction()->getName() == "__llvm_thread_join") + if (!containsJoin(AllJoins, CI)) + AllJoins.push_back(CI); + } + + // Add all unique joins to the coallesced joins block + for (std::vector::iterator c = AllJoins.begin(), + ce = AllJoins.end(); c != ce; ++c) + SumJoins->getInstList().push_back((*c)->clone()); + + // Terminate the Joins block with a branch to the post-join code + Instruction *TI = PRJoinBlocks[0]->getTerminator(); + if (TI) + SumJoins->getInstList().push_back(TI->clone()); + + // Branch to the all-joins block from the main code + for (std::vector::iterator j = PRJoinBlocks.begin(), + je = PRJoinBlocks.end(); j != je; ++j) { + std::vector JUsers((*j)->use_begin(), (*j)->use_end()); + for (std::vector::iterator u = JUsers.begin(), ue = JUsers.end(); + u != ue; ++u) + if (Instruction *I = dyn_cast(*u)) + if (contains(PR->getBlocks(), I->getParent())) + I->replaceUsesOfWith(*j, SumJoins); + } } } @@ -115,7 +175,6 @@ // Remove pbr ParaBrInst *pbr = dyn_cast(PS->getHeader()->getTerminator()); - //assert(pbr && "Terminator of ParaSeq header is not a pbr"); if (pbr) { new BranchInst(pbr->getSuccessor(0), pbr); pbr->getParent()->getInstList().erase(pbr); @@ -125,4 +184,12 @@ Function* LowerParaBr::getJoinIntrinsic(Module *M) { return M->getOrInsertFunction("llvm.join", Type::VoidTy, PointerType::get(Type::SByteTy), 0); +} + +/// getFuncThreadJoin - +/// +Function* LowerParaBr::getFuncThreadJoin(Module &M) { + // void __llvm_thread_join(int); + return M.getOrInsertFunction("__llvm_thread_join", Type::VoidTy, Type::IntTy, + 0); } From brukman at cs.uiuc.edu Mon May 17 19:25:03 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Mon May 17 19:25:03 2004 Subject: [llvm-commits] [parallel] CVS: llvm/lib/Transforms/Parallel/ParallelCallsToThreads.cpp Message-ID: <200405180024.TAA17928@zion.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Parallel: ParallelCallsToThreads.cpp updated: 1.1.2.3 -> 1.1.2.4 --- Log message: Fix comment to be up-to-date. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Transforms/Parallel/ParallelCallsToThreads.cpp diff -u llvm/lib/Transforms/Parallel/ParallelCallsToThreads.cpp:1.1.2.3 llvm/lib/Transforms/Parallel/ParallelCallsToThreads.cpp:1.1.2.4 --- llvm/lib/Transforms/Parallel/ParallelCallsToThreads.cpp:1.1.2.3 Fri May 7 16:37:56 2004 +++ llvm/lib/Transforms/Parallel/ParallelCallsToThreads.cpp Mon May 17 19:24:30 2004 @@ -77,7 +77,7 @@ bool Changed = false; ParallelInfo &PI = getAnalysis(); - // Convert parallel calls to pthread_create() invocations + // Convert parallel calls to __llvm_thread_start() invocations for (ParallelInfo::iterator i = PI.begin(), e = PI.end(); i != e; ++i) { ParallelSeq *PS = *i; for (ParallelSeq::riterator r = PS->rbegin(), re = PS->rend(); From gaeke at cs.uiuc.edu Tue May 18 11:52:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 18 11:52:01 2004 Subject: [llvm-commits] CVS: reopt/tools/ttftest/ttftest.cpp Message-ID: <200405181651.LAA26137@zion.cs.uiuc.edu> Changes in directory reopt/tools/ttftest: ttftest.cpp updated: 1.1 -> 1.2 --- Log message: Write out traces to files when they are loaded, for testing purposes. --- Diffs of the changes: (+34 -0) Index: reopt/tools/ttftest/ttftest.cpp diff -u reopt/tools/ttftest/ttftest.cpp:1.1 reopt/tools/ttftest/ttftest.cpp:1.2 --- reopt/tools/ttftest/ttftest.cpp:1.1 Mon May 17 16:25:25 2004 +++ reopt/tools/ttftest/ttftest.cpp Tue May 18 11:51:30 2004 @@ -19,6 +19,8 @@ #include "llvm/Bytecode/Reader.h" #include "reopt/TraceToFunction.h" #include "llvm/Module.h" +#include "Support/FileUtilities.h" +#include "Support/StringExtras.h" #include #include #include @@ -34,6 +36,7 @@ return block; } + /// ReadTraceFromFile - Given a module, read a trace for some function /// in that module from the named file. Returns the Trace object, or a null /// pointer (and sets ErrorStr) if there was an error. @@ -70,6 +73,36 @@ return new Trace (vBB); } + +/// getBasicBlockIndex - Returns the index of BB in its parent function. +/// +int getBasicBlockIndex (BasicBlock *BB) { + int bbNum = 0; + Function *F = BB->getParent (); + Function::iterator block = F->begin(); + while (&*block != BB) { + ++block; + ++bbNum; + } + return bbNum; +} + +void WriteTraceToFile (Trace &T) { + std::string filename; + unsigned count = 0; + do { + ++count; + filename = T.getFunction ()->getName () + ".trace" + utostr (count) + + ".txt"; + } while (FileOpenable(filename)); + std::ofstream out (filename.c_str ()); + out << T.getFunction ()->getName () << "\n"; + for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) + out << getBasicBlockIndex (*i) << " "; + out << "\n"; + out.close (); +} + int main (int argc, char **argv) { const char *bytecodeFileName = argv[1]; const char *traceFileName = argv[2]; @@ -89,6 +122,7 @@ std::cerr << "Error reading trace: " << err << "\n"; exit (1); } + WriteTraceToFile (*T); // Run TraceToFunction on the Trace TraceFunction *TF = TraceFunction::get (*T); From gaeke at cs.uiuc.edu Tue May 18 11:52:06 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 18 11:52:06 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405181651.LAA26123@zion.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.32 -> 1.33 --- Log message: Write out traces to files when they are detected, for use with ttftest. --- Diffs of the changes: (+32 -0) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.32 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.33 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.32 Mon May 17 16:00:19 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Tue May 18 11:51:28 2004 @@ -19,6 +19,7 @@ #include "reopt/InstrUtils.h" #include "Support/Debug.h" #include "Support/StringExtras.h" +#include "Support/FileUtilities.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Assembly/PrintModulePass.h" #include "llvm/CodeGen/MachineFunction.h" @@ -31,6 +32,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetMachineImpls.h" +#include namespace llvm { @@ -65,6 +67,35 @@ ///==----------------------------------------------------------------------==/// +/// getBasicBlockIndex - Returns the index of BB in its parent function. +/// +int getBasicBlockIndex (BasicBlock *BB) { + int bbNum = 0; + Function *F = BB->getParent (); + Function::iterator block = F->begin(); + while (&*block != BB) { + ++block; + ++bbNum; + } + return bbNum; +} + +void WriteTraceToFile (Trace &T) { + std::string filename; + unsigned count = 0; + do { + ++count; + filename = T.getFunction ()->getName () + ".trace" + utostr (count) + + ".txt"; + } while (FileOpenable(filename)); + std::ofstream out (filename.c_str ()); + out << T.getFunction ()->getName () << "\n"; + for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) + out << getBasicBlockIndex (*i) << " "; + out << "\n"; + out.close (); +} + /// This method is called when we have finally constructed a /// trace. The first parameter is the vector of basic blocks that form /// the trace; the second parameter is the starting @@ -89,6 +120,7 @@ // Turn the vector of basic blocks into a Trace, and then turn the Trace into // a TraceFunction. Trace T (vBB); + WriteTraceToFile (T); TraceFunction *TF = TraceFunction::get (T); // Force the SPARCv9 register allocator to save its state into a global From gaeke at cs.uiuc.edu Tue May 18 11:52:08 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 18 11:52:08 2004 Subject: [llvm-commits] CVS: reopt/test/TEST.reopt.Makefile Message-ID: <200405181651.LAA26130@zion.cs.uiuc.edu> Changes in directory reopt/test: TEST.reopt.Makefile updated: 1.11 -> 1.12 --- Log message: Link in tracetofunction library. --- Diffs of the changes: (+1 -1) Index: reopt/test/TEST.reopt.Makefile diff -u reopt/test/TEST.reopt.Makefile:1.11 reopt/test/TEST.reopt.Makefile:1.12 --- reopt/test/TEST.reopt.Makefile:1.11 Wed Mar 31 10:36:43 2004 +++ reopt/test/TEST.reopt.Makefile Tue May 18 11:51:29 2004 @@ -28,7 +28,7 @@ # Libraries that contain the Reoptimizer itself REOPTIMIZER_OBJS = $(REOPTLIBDIR)/firstTrigger.o \ $(REOPTLIBDIR)/tracecache.o $(REOPTLIBDIR)/mapinfo.o \ - $(REOPTLIBDIR)/scratchmemory.o + $(REOPTLIBDIR)/scratchmemory.o $(REOPTLIBDIR)/tracetofunction.o # Object files that contain common LLVM code the Reoptimizer depends on REOPTIMIZER_LLVMOBJS = $(DESTLIBCURRENT)/vmcore.o \ From alkis at cs.uiuc.edu Tue May 18 14:24:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 18 14:24:01 2004 Subject: [llvm-commits] CVS: llvm-java/autoconf/configure.ac Message-ID: <200405181923.OAA27464@zion.cs.uiuc.edu> Changes in directory llvm-java/autoconf: configure.ac updated: 1.5 -> 1.6 --- Log message: Look for JAVA and JAVAC executables. --- Diffs of the changes: (+2 -0) Index: llvm-java/autoconf/configure.ac diff -u llvm-java/autoconf/configure.ac:1.5 llvm-java/autoconf/configure.ac:1.6 --- llvm-java/autoconf/configure.ac:1.5 Wed Apr 21 11:32:31 2004 +++ llvm-java/autoconf/configure.ac Tue May 18 14:23:31 2004 @@ -25,6 +25,8 @@ dnl * Check for programs. dnl ************************************************************************** AC_CHECK_PROG(JIKES, jikes, jikes) +AC_CHECK_PROG(JAVAC, javac, javac) +AC_CHECK_PROG(JAVA, java, java) dnl Verify that the source directory is valid AC_CONFIG_SRCDIR(Makefile.common.in) From alkis at cs.uiuc.edu Tue May 18 14:24:05 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 18 14:24:05 2004 Subject: [llvm-commits] CVS: llvm-java/configure Message-ID: <200405181923.OAA27465@zion.cs.uiuc.edu> Changes in directory llvm-java: configure updated: 1.4 -> 1.5 --- Log message: Look for JAVA and JAVAC executables. --- Diffs of the changes: (+73 -1) Index: llvm-java/configure diff -u llvm-java/configure:1.4 llvm-java/configure:1.5 --- llvm-java/configure:1.4 Thu Apr 15 23:37:54 2004 +++ llvm-java/configure Tue May 18 14:23:31 2004 @@ -274,7 +274,7 @@ PACKAGE_BUGREPORT='llvmbugs at cs.uiuc.edu' ac_unique_file="Makefile.common.in" -ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS JIKES LLVM_SRC LLVM_OBJ LIBOBJS LTLIBOBJS' +ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS JIKES JAVAC JAVA LLVM_SRC LLVM_OBJ LIBOBJS LTLIBOBJS' ac_subst_files='' # Initialize some variables set by options. @@ -1314,6 +1314,76 @@ echo "${ECHO_T}no" >&6 fi +# Extract the first word of "javac", so it can be a program name with args. +set dummy javac; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_JAVAC+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$JAVAC"; then + ac_cv_prog_JAVAC="$JAVAC" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_JAVAC="javac" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +JAVAC=$ac_cv_prog_JAVAC +if test -n "$JAVAC"; then + echo "$as_me:$LINENO: result: $JAVAC" >&5 +echo "${ECHO_T}$JAVAC" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + +# Extract the first word of "java", so it can be a program name with args. +set dummy java; ac_word=$2 +echo "$as_me:$LINENO: checking for $ac_word" >&5 +echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6 +if test "${ac_cv_prog_JAVA+set}" = set; then + echo $ECHO_N "(cached) $ECHO_C" >&6 +else + if test -n "$JAVA"; then + ac_cv_prog_JAVA="$JAVA" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_JAVA="java" + echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done + +fi +fi +JAVA=$ac_cv_prog_JAVA +if test -n "$JAVA"; then + echo "$as_me:$LINENO: result: $JAVA" >&5 +echo "${ECHO_T}$JAVA" >&6 +else + echo "$as_me:$LINENO: result: no" >&5 +echo "${ECHO_T}no" >&6 +fi + @@ -2001,6 +2071,8 @@ s, at ECHO_T@,$ECHO_T,;t t s, at LIBS@,$LIBS,;t t s, at JIKES@,$JIKES,;t t +s, at JAVAC@,$JAVAC,;t t +s, at JAVA@,$JAVA,;t t s, at LLVM_SRC@,$LLVM_SRC,;t t s, at LLVM_OBJ@,$LLVM_OBJ,;t t s, at LIBOBJS@,$LIBOBJS,;t t From alkis at cs.uiuc.edu Tue May 18 14:27:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 18 14:27:02 2004 Subject: [llvm-commits] CVS: llvm-java/Makefile.rules Message-ID: <200405181924.OAA27487@zion.cs.uiuc.edu> Changes in directory llvm-java: Makefile.rules updated: 1.1 -> 1.2 --- Log message: Upadate rule to use JAVAC instead of JIKES. --- Diffs of the changes: (+2 -3) Index: llvm-java/Makefile.rules diff -u llvm-java/Makefile.rules:1.1 llvm-java/Makefile.rules:1.2 --- llvm-java/Makefile.rules:1.1 Wed Apr 21 11:33:48 2004 +++ llvm-java/Makefile.rules Tue May 18 14:24:48 2004 @@ -1,4 +1,4 @@ -#===-- Makefile.rules - Common make rules for LLVM -------*- makefile -*--==== +##==-- Makefile.rules - Common make rules for Java -------*- makefile -*--====## # # The LLVM Compiler Infrastructure # @@ -10,7 +10,6 @@ ifdef BUILD_JAVA_SOURCE all:: .class-stamp .class-stamp: $(shell find . -name '*.java') - $(JIKES) --bootclasspath $(BOOTCLASSPATH) $? + $(JAVAC) $? touch .class-stamp endif - From alkis at cs.uiuc.edu Tue May 18 15:15:10 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Tue May 18 15:15:10 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405182013.PAA29286@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h added (r1.1) --- Log message: Add java bytecode constants header. It currently only contains the java opcodes. --- Diffs of the changes: (+229 -0) Index: llvm-java/include/llvm/Java/Bytecode.h diff -c /dev/null llvm-java/include/llvm/Java/Bytecode.h:1.1 *** /dev/null Tue May 18 15:13:47 2004 --- llvm-java/include/llvm/Java/Bytecode.h Tue May 18 15:13:37 2004 *************** *** 0 **** --- 1,229 ---- + //===-- Bytecode.h - Java bytecode constants --------------------*- C++ -*-===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file contains Java bytecode constants. + // + //===----------------------------------------------------------------------===// + + #include + #include + + #include + + namespace llvm { namespace Java { + + enum Opcode { + NOP = 0x00, + ACONST_NULL = 0x01, + ICONST_M1 = 0x02, + ICONST_0 = 0x03, + ICONST_1 = 0x04, + ICONST_2 = 0x05, + ICONST_3 = 0x06, + ICONST_4 = 0x07, + ICONST_5 = 0x08, + LCONST_0 = 0x09, + LCONST_1 = 0x0A, + FCONST_0 = 0x0B, + FCONST_1 = 0x0C, + FCONST_2 = 0x0D, + DCONST_0 = 0x0E, + DCONST_1 = 0x0F, + BIPUSH = 0x10, + SIPUSH = 0x11, + LDC = 0x12, + LDC_W = 0x13, + LDC2_W = 0x14, + ILOAD = 0x15, + LLOAD = 0x16, + FLOAD = 0x17, + DLOAD = 0x18, + ALOAD = 0x19, + ILOAD_0 = 0x1A, + ILOAD_1 = 0x1B, + ILOAD_2 = 0x1C, + ILOAD_3 = 0x1D, + LLOAD_0 = 0x1E, + LLOAD_1 = 0x1F, + LLOAD_2 = 0x20, + LLOAD_3 = 0x21, + FLOAD_0 = 0x22, + FLOAD_1 = 0x23, + FLOAD_2 = 0x24, + FLOAD_3 = 0x25, + DLOAD_0 = 0x26, + DLOAD_1 = 0x27, + DLOAD_2 = 0x28, + DLOAD_3 = 0x29, + ALOAD_0 = 0x2A, + ALOAD_1 = 0x2B, + ALOAD_2 = 0x2C, + ALOAD_3 = 0x2D, + IALOAD = 0x2E, + LALOAD = 0x2F, + FALOAD = 0x30, + DALOAD = 0x31, + AALOAD = 0x32, + BALOAD = 0x33, + CALOAD = 0x34, + SALOAD = 0x35, + ISTORE = 0x36, + LSTORE = 0x37, + FSTORE = 0x38, + DSTORE = 0x39, + ASTORE = 0x3A, + ISTORE_0 = 0x3B, + ISTORE_1 = 0x3C, + ISTORE_2 = 0x3D, + ISTORE_3 = 0x3E, + LSTORE_0 = 0x3F, + LSTORE_1 = 0x40, + LSTORE_2 = 0x41, + LSTORE_3 = 0x42, + FSTORE_0 = 0x43, + FSTORE_1 = 0x44, + FSTORE_2 = 0x45, + FSTORE_3 = 0x46, + DSTORE_0 = 0x47, + DSTORE_1 = 0x48, + DSTORE_2 = 0x49, + DSTORE_3 = 0x4A, + ASTORE_0 = 0x4B, + ASTORE_1 = 0x4C, + ASTORE_2 = 0x4D, + ASTORE_3 = 0x4E, + IASTORE = 0x4F, + LASTORE = 0x50, + FASTORE = 0x51, + DASTORE = 0x52, + AASTORE = 0x53, + BASTORE = 0x54, + CASTORE = 0x55, + SASTORE = 0x56, + POP = 0x57, + POP2 = 0x58, + DUP = 0x59, + DUP_X1 = 0x5A, + DUP_X2 = 0x5B, + DUP2 = 0x5C, + DUP2_X1 = 0x5D, + DUP2_X2 = 0x5E, + SWAP = 0x5F, + IADD = 0x60, + LADD = 0x61, + FADD = 0x62, + DADD = 0x63, + ISUB = 0x64, + LSUB = 0x65, + FSUB = 0x66, + DSUB = 0x67, + IMUL = 0x68, + LMUL = 0x69, + FMUL = 0x6A, + DMUL = 0x6B, + IDIV = 0x6C, + LDIV = 0x6D, + FDIV = 0x6E, + DDIV = 0x6F, + IREM = 0x70, + LREM = 0x71, + FREM = 0x72, + DREM = 0x73, + INEG = 0x74, + LNEG = 0x75, + FNEG = 0x76, + DNEG = 0x77, + ISHL = 0x78, + LSHL = 0x79, + ISHR = 0x7A, + LSHR = 0x7B, + IUSHR = 0x7C, + LUSHR = 0x7D, + IAND = 0x7E, + LAND = 0x7F, + IOR = 0x80, + LOR = 0x81, + IXOR = 0x82, + LXOR = 0x83, + IINC = 0x84, + I2L = 0x85, + I2F = 0x86, + I2D = 0x87, + L2I = 0x88, + L2F = 0x89, + L2D = 0x8A, + F2I = 0x8B, + F2L = 0x8C, + F2D = 0x8D, + D2I = 0x8E, + D2L = 0x8F, + D2F = 0x90, + I2B = 0x91, + I2C = 0x92, + I2S = 0x93, + LCMP = 0x94, + FCMPL = 0x95, + FCMPG = 0x96, + DCMPL = 0x97, + DCMPG = 0x98, + IFEQ = 0x99, + IFNE = 0x9A, + IFLT = 0x9B, + IFGE = 0x9C, + IFGT = 0x9D, + IFLE = 0x9E, + IF_ICMPEQ = 0x9F, + IF_ICMPNE = 0xA0, + IF_ICMPLT = 0xA1, + IF_ICMPGE = 0xA2, + IF_ICMPGT = 0xA3, + IF_ICMPLE = 0xA4, + IF_ICMPACMPEQ = 0xA5, + IF_ICMPACMPNE = 0xA6, + GOTO = 0xA7, + JSR = 0xA8, + RET = 0xA9, + TABLESWITCH = 0xAA, + LOOKUPSWITCH = 0xAB, + IRETURN = 0xAC, + LRETURN = 0xAD, + FRETURN = 0xAE, + DRETURN = 0xAF, + ARETURN = 0xB0, + RETURN = 0xB1, + GETSTATIC = 0xB2, + PUTSTATIC = 0xB3, + GETFIELD = 0xB4, + PUTFIELD = 0xB5, + INVOKEVIRTUAL = 0xB6, + INVOKESPECIAL = 0xB7, + INVOKESTATIC = 0xB8, + INVOKEINTERFACE = 0xB9, + XXXUNUSEDXXX = 0xBA, + NEW = 0xBB, + NEWARRAY = 0xBC, + ANEWARRAY = 0xBD, + ARRAYLENGTH = 0xBE, + ATHROW = 0xBF, + CHECKCAST = 0xC0, + INSTANCEOF = 0xC1, + MONITORENTER = 0xC2, + MONITOREXIT = 0xC3, + WIDE = 0xC4, + MULTIANEWARRAY = 0xC5, + IFNULL = 0xC6, + IFNONNULL = 0xC7, + GOTO_W = 0xC8, + JSR_W = 0xC9, + BREAKPOINT = 0xCA, + IMPDEP1 = 0xFE, + IMPDEP2 = 0xFF, + }; + + } } // namespace llvm::Java From gaeke at cs.uiuc.edu Tue May 18 16:05:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 18 16:05:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405182104.QAA14294@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.40 -> 1.41 --- Log message: Significant changes to how we deal with FLI: now we make a pass over the trace's matrix function (before cloning the trace), and find all the FLI blocks and their associated edges. Then we clone the trace, and get rid of FLI blocks and thread branches (and their corresponding PHIs) on back-edges which have been instrumented with FLI. --- Diffs of the changes: (+114 -45) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.40 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.41 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.40 Mon May 17 16:49:37 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Tue May 18 16:04:37 2004 @@ -45,18 +45,27 @@ typedef std::vector TypeVector; typedef std::map BranchNumberMap; +// maps FLI blocks to the corresponding pair: +typedef std::map > FLIMapTy; + /// TraceFunctionBuilder - a Method Object which encapsulates the algorithm /// for building TraceFunctions given Traces. /// class TraceFunctionBuilder { BranchNumberMap BranchNumber; TraceFunction *TF; - virtual TypeVector createFunctionArgTypeVector (PointerType *ST, - LiveVariableSet S); - virtual void fillInFunctionBody (Trace &T, Function *F, LiveVariableSet &So); - virtual void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB, - BasicBlock *dstB, ValueMap &O2CMap, - LiveVariableSet &So); + + FLIMapTy FLIMap; + BasicBlock *getFLIEdgeSource (BasicBlock *BB); + BasicBlock *getFLIEdgeTarget (BasicBlock *BB); + void threadFLIEdges (Function *F); + void buildFLIMap (Trace &T, FLIMapTy &FLIMap); + + TypeVector createFunctionArgTypeVector (PointerType *ST, LiveVariableSet S); + void fillInFunctionBody (Trace &T, Function *F, LiveVariableSet &So); + void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB, + BasicBlock *dstB, ValueMap &O2CMap, + LiveVariableSet &So); public: TraceFunctionBuilder () { } virtual ~TraceFunctionBuilder () { } @@ -378,8 +387,6 @@ } } -static BasicBlock *getFLIEdgeTarget (BasicBlock *BB); - /// fillInFunctionBody - Clone the BBs of T into F, then do all /// necessary fixups to ensure that F's new contents are internally /// consistent and that the live-outs So get stored in F's first @@ -389,15 +396,13 @@ LiveVariableSet &So) { ValueMap &O2CMap = TF->O2CMap; - // Remove any FLI blocks which ended up in the trace. - Trace::iterator i; - while ((i = std::find_if (T.begin (), T.end (), getFLIEdgeTarget)) - != T.end ()) - T.erase (i); - + buildFLIMap (T, FLIMap); + // First copy the basic blocks from the trace. cloneTraceBBsIntoFunction (T, F, O2CMap); + threadFLIEdges (F); + numberExitBranchesInTrace (T, BranchNumber); // Fix up the cloned basic blocks of the function so that they are @@ -413,45 +418,109 @@ fixupPhisAndCalls (FI, O2CMap); } -/// getFLIEdgeTarget - returns a nonzero value iff BB is a -/// basic block containing only a call to the first-level instrumentation -/// function. Basic blocks of this form are inserted by the -instloops pass on -/// loop back-edges. The return value is the target of the back-edge. -/// -static BasicBlock *getFLIEdgeTarget (BasicBlock *BB) { - BasicBlock::iterator i = BB->begin (); - // starts with llvm_first_trigger call - if (!isFirstTriggerCall (*i)) - return 0; - // Next instr. should be an unconditional branch - return its target, - // or NULL if there is a mismatch. - BranchInst *BI = dyn_cast (++i); - if (!(BI && BI->isUnconditional())) - return 0; - return BI->getSuccessor (0); -} - -/// getFLIEdgeSource - returns a nonzero value iff BB is a -/// basic block containing only a call to the first-level instrumentation -/// function. Basic blocks of this form are inserted by the -instloops pass on -/// loop back-edges. The return value is the source of the back-edge. +/// identifyFLIEdge - returns a true value iff BB is a basic block containing +/// only a call to the first-level instrumentation function. Basic blocks of +/// this form are inserted by the -instloops pass on loop back-edges. The side +/// effect of this function, if it returns true, is to fill in the pair "edge" +/// with the source and target of the back-edge. /// -static BasicBlock *getFLIEdgeSource (BasicBlock *BB) { +static bool identifyFLIEdge (BasicBlock *BB, std::pair &edge) { BasicBlock::iterator i = BB->begin (); // starts with llvm_first_trigger call if (!isFirstTriggerCall (*i)) - return 0; - // Next instr. should be an unconditional branch. Return NULL if + return false; + // Next instr. should be an unconditional branch. Return false if // there is a mismatch. BranchInst *BI = dyn_cast (++i); if (!(BI && BI->isUnconditional())) - return 0; - // Use CFG predecessor iterator to get the predecessor of the FLI block + return false; + // Record the FLI edge's sink. + edge.second = BI->getSuccessor (0); + // Use CFG predecessor iterator to get the predecessor of the FLI block. + // FIXME: should check that there is only one predecessor. pred_iterator PI = pred_begin (BB); - DEBUG(pred_iterator NextPI = PI; ++NextPI; - assert (NextPI == pred_end (BB) && - "FLI block must have only one predecessor")); - return *PI; + edge.first = *PI; + return true; +} + +void TraceFunctionBuilder::threadFLIEdges (Function *F) { + for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) + for (BasicBlock::iterator Inst = FI->begin (), BE = FI->end (); Inst != BE; ++Inst) { + if (isa (Inst)) { + // In a PHI node, replace references to FLI blocks with the + // corresponding edge's source. + for (unsigned OI = 0, OE = Inst->getNumOperands(); OI != OE; ++OI) { + Value *op = Inst->getOperand (OI); + if (isa (op)) { + BasicBlock *BB = cast (op); + FLIMapTy::iterator It = FLIMap.find (BB); + if (It != FLIMap.end ()) { + DEBUG (std::cerr << "threadFLIEdges: threading operand " << OI + << " (FLI block " << BB->getName () << " --> <[" + << It->second.first->getName () << "], " + << It->second.second->getName () << ">) of instruction: " + << *Inst << "\n"); + Inst->setOperand (OI, It->second.first); + } + } + } + } else if (isa (Inst)) { + // If it's a branch, replace references to FLI blocks with the + // corresponding edge's target. + for (unsigned OI = 0, OE = Inst->getNumOperands(); OI != OE; ++OI) { + Value *op = Inst->getOperand (OI); + if (isa (op)) { + BasicBlock *BB = cast (op); + FLIMapTy::iterator It = FLIMap.find (BB); + if (It != FLIMap.end ()) { + DEBUG (std::cerr << "threadFLIEdges: threading operand " << OI + << " (FLI block " << BB->getName () << " --> <" + << It->second.first->getName () << ", [" + << It->second.second->getName () << "]>) of instruction: " + << *Inst << "\n"); + Inst->setOperand (OI, It->second.second); + } + } + } + } + } +} + +/// buildFLIMap - Removes any FLI blocks which ended up in the trace, and +/// identifies the source and sink BasicBlocks of all FLI-instrumented +/// back-edges. Information about FLI edges is stored in the FLIMap. +/// +void TraceFunctionBuilder::buildFLIMap (Trace &T, FLIMapTy &FLIMap) { + Function *F = T.getFunction (); + for (Function::iterator i = F->begin (), e = F->end (); i != e; ++i) { + std::pair edge; + if (identifyFLIEdge (i, edge)) { + DEBUG (std::cerr << "buildFLIMap: identified FLI block " << i->getName() + << " on edge <" << edge.first->getName () << ", " + << edge.second->getName () << ">\n"); + // 1. remove the block from the trace if it is in there + BasicBlock *bb = i; + Trace::iterator TI = std::find (T.begin (), T.end (), bb); + if (TI != T.end ()) { + DEBUG (std::cerr << "buildFLIMap: removing it from the trace\n"); + T.erase (TI); + } + // 2. record its source and target in the map + FLIMap[i] = edge; + } + } +} + +BasicBlock *TraceFunctionBuilder::getFLIEdgeSource (BasicBlock *BB) { + FLIMapTy::iterator i = FLIMap.find (BB); + if (i == FLIMap.end ()) return 0; + return i->second.first; +} + +BasicBlock *TraceFunctionBuilder::getFLIEdgeTarget (BasicBlock *BB) { + FLIMapTy::iterator i = FLIMap.find (BB); + if (i == FLIMap.end ()) return 0; + return i->second.second; } /// fixupFunctionBodyBB - Given srcB in T and its clone dstB in F, and From gaeke at cs.uiuc.edu Tue May 18 16:24:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Tue May 18 16:24:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405182123.QAA14501@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.41 -> 1.42 --- Log message: Give cloned trace basic blocks more reasonable names. --- Diffs of the changes: (+1 -2) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.41 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.42 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.41 Tue May 18 16:04:37 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Tue May 18 16:23:06 2004 @@ -282,13 +282,12 @@ /// to O2CMap. /// static void cloneTraceBBsIntoFunction (Trace &T, Function *F, ValueMap &O2CMap){ - unsigned BBCount = 0; // Clone each basic block into the new function. for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI) { BasicBlock *srcB = *TI; // Create a new BasicBlock dstB that corresponds to srcB in T. BasicBlock *dstB = CloneBasicBlock (srcB, O2CMap, ".ttf"); - DEBUG(dstB->setName ("trace" + utostr(BBCount++))); + DEBUG(dstB->setName (srcB->getName () + ".ttf")); // Add dstB to F. F->getBasicBlockList ().push_back (dstB); // Remember the correspondence between srcB and dstB. (CloneFunction does From gaeke at cs.uiuc.edu Wed May 19 01:52:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 01:52:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/Makefile Message-ID: <200405190651.BAA26425@zion.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: Makefile updated: 1.8 -> 1.9 --- Log message: Makefile changes due to TraceToFunction move. --- Diffs of the changes: (+1 -1) Index: reopt/lib/LightWtProfiling/Makefile diff -u reopt/lib/LightWtProfiling/Makefile:1.8 reopt/lib/LightWtProfiling/Makefile:1.9 --- reopt/lib/LightWtProfiling/Makefile:1.8 Sun May 16 00:24:37 2004 +++ reopt/lib/LightWtProfiling/Makefile Wed May 19 01:50:57 2004 @@ -5,7 +5,7 @@ include $(LEVEL)/Makefile.config ifneq ($(ARCH),Sparc) -Source := FirstTrigger.cpp Initialization.cpp RuntimeOptimizations.cpp SLI.cpp TraceOptEmitter.cpp TraceToFunction.cpp UnpackTraceFunction.cpp +Source := FirstTrigger.cpp Initialization.cpp RuntimeOptimizations.cpp SLI.cpp TraceOptEmitter.cpp UnpackTraceFunction.cpp all :: @echo "This code assumes an LP64 machine- please ignore ptr cast warnings!" endif From gaeke at cs.uiuc.edu Wed May 19 01:52:06 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 01:52:06 2004 Subject: [llvm-commits] CVS: reopt/lib/Makefile Message-ID: <200405190651.BAA26418@zion.cs.uiuc.edu> Changes in directory reopt/lib: Makefile updated: 1.19 -> 1.20 --- Log message: Makefile changes due to TraceToFunction move. --- Diffs of the changes: (+1 -1) Index: reopt/lib/Makefile diff -u reopt/lib/Makefile:1.19 reopt/lib/Makefile:1.20 --- reopt/lib/Makefile:1.19 Wed Apr 28 12:27:36 2004 +++ reopt/lib/Makefile Wed May 19 01:50:56 2004 @@ -1,5 +1,5 @@ LEVEL = .. -DIRS := BinInterface Mapping TraceCache Trigger LightWtProfiling Inst +DIRS := BinInterface Mapping TraceCache Trigger LightWtProfiling Inst TraceToFunction include $(LEVEL)/Makefile.config From gaeke at cs.uiuc.edu Wed May 19 03:45:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 03:45:01 2004 Subject: [llvm-commits] CVS: reopt/tools/ttftest/ttftest.cpp Message-ID: <200405190844.DAA19093@seraph.cs.uiuc.edu> Changes in directory reopt/tools/ttftest: ttftest.cpp updated: 1.2 -> 1.3 --- Log message: Change this tool to use the CommandLine library. Remove the (duplicated) trace-writing code from this file. Minor edits to comments. --- Diffs of the changes: (+18 -29) Index: reopt/tools/ttftest/ttftest.cpp diff -u reopt/tools/ttftest/ttftest.cpp:1.2 reopt/tools/ttftest/ttftest.cpp:1.3 --- reopt/tools/ttftest/ttftest.cpp:1.2 Tue May 18 11:51:30 2004 +++ reopt/tools/ttftest/ttftest.cpp Wed May 19 03:44:44 2004 @@ -19,6 +19,7 @@ #include "llvm/Bytecode/Reader.h" #include "reopt/TraceToFunction.h" #include "llvm/Module.h" +#include "Support/CommandLine.h" #include "Support/FileUtilities.h" #include "Support/StringExtras.h" #include @@ -27,6 +28,13 @@ #include using namespace llvm; +namespace { + cl::opt TraceFile("trace", + cl::desc("Name of file containing trace"), cl::value_desc("traceFileName")); + cl::opt BytecodeFile("bc", + cl::desc("Name of file containing module"), cl::value_desc("bytecodeFileName")); +}; + /// getBasicBlockByNum - Returns the basic block in F whose index is /// bbNum. /// @@ -36,14 +44,13 @@ return block; } - /// ReadTraceFromFile - Given a module, read a trace for some function /// in that module from the named file. Returns the Trace object, or a null /// pointer (and sets ErrorStr) if there was an error. /// -Trace *ReadTraceFromFile (Module *M, const char *filename, +Trace *ReadTraceFromFile (Module *M, const std::string &filename, std::string *ErrorStr) { - std::ifstream in (filename); + std::ifstream in (filename.c_str ()); if (!in.good()) { if (ErrorStr) *ErrorStr = std::string("Can't open '") + filename + "': " @@ -73,7 +80,6 @@ return new Trace (vBB); } - /// getBasicBlockIndex - Returns the index of BB in its parent function. /// int getBasicBlockIndex (BasicBlock *BB) { @@ -87,48 +93,31 @@ return bbNum; } -void WriteTraceToFile (Trace &T) { - std::string filename; - unsigned count = 0; - do { - ++count; - filename = T.getFunction ()->getName () + ".trace" + utostr (count) - + ".txt"; - } while (FileOpenable(filename)); - std::ofstream out (filename.c_str ()); - out << T.getFunction ()->getName () << "\n"; - for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) - out << getBasicBlockIndex (*i) << " "; - out << "\n"; - out.close (); -} - int main (int argc, char **argv) { - const char *bytecodeFileName = argv[1]; - const char *traceFileName = argv[2]; + // Get command line arguments. + cl::ParseCommandLineOptions(argc, argv, " trace-to-function tester\n"); - // Read bytecode file + // Read bytecode file. std::string err; - Module *M = ParseBytecodeFile(bytecodeFileName, &err); + Module *M = ParseBytecodeFile (BytecodeFile, &err); if (!M) { std::cerr << "Error reading bytecode: " << err << "\n"; exit (1); } - // Read trace file + // Read trace file. std::vector vBB; - Trace *T = ReadTraceFromFile (M, traceFileName, &err); + Trace *T = ReadTraceFromFile (M, TraceFile, &err); if (!T) { std::cerr << "Error reading trace: " << err << "\n"; exit (1); } - WriteTraceToFile (*T); - // Run TraceToFunction on the Trace + // Run TraceToFunction on the Trace. TraceFunction *TF = TraceFunction::get (*T); std::cerr << *TF->TraceFn << "\n\n"; - // Run Verifier on the resulting TraceFunction + // Run the LLVM Verifier on the resulting TraceFunction. if (verifyFunction (*TF->TraceFn, PrintMessageAction)) { std::cerr << "Verifier fails.\n"; exit (1); From gaeke at cs.uiuc.edu Wed May 19 03:48:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 03:48:03 2004 Subject: [llvm-commits] CVS: reopt/tools/Makefile Message-ID: <200405190847.DAA19112@seraph.cs.uiuc.edu> Changes in directory reopt/tools: Makefile updated: 1.3 -> 1.4 --- Log message: Build ttftest by default --- Diffs of the changes: (+1 -1) Index: reopt/tools/Makefile diff -u reopt/tools/Makefile:1.3 reopt/tools/Makefile:1.4 --- reopt/tools/Makefile:1.3 Wed Nov 19 16:51:54 2003 +++ reopt/tools/Makefile Wed May 19 03:47:01 2004 @@ -1,6 +1,6 @@ LEVEL := .. -DIRS := +DIRS := ttftest include $(LEVEL)/Makefile.config From gaeke at cs.uiuc.edu Wed May 19 03:49:00 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 03:49:00 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405190848.DAA19130@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.33 -> 1.34 --- Log message: When writing out a trace, also write out the module into a separate file. This allows us to test trace-based optimizations based on exactly what the trace optimizer would get as input. --- Diffs of the changes: (+17 -7) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.33 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.34 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.33 Tue May 18 11:51:28 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Wed May 19 03:48:36 2004 @@ -22,6 +22,7 @@ #include "Support/FileUtilities.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Assembly/PrintModulePass.h" +#include "llvm/Bytecode/Writer.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/MachineCodeEmitter.h" @@ -81,20 +82,29 @@ } void WriteTraceToFile (Trace &T) { - std::string filename; + // Get unique filename for trace & corresponding module. + std::string traceFileName, bytecodeFileName; + Function *F = T.getFunction (); unsigned count = 0; do { ++count; - filename = T.getFunction ()->getName () + ".trace" + utostr (count) - + ".txt"; - } while (FileOpenable(filename)); - std::ofstream out (filename.c_str ()); - out << T.getFunction ()->getName () << "\n"; + traceFileName = F->getName () + ".trace" + utostr (count) + ".txt"; + bytecodeFileName = F->getName () + ".trace" + utostr (count) + ".bc"; + } while (FileOpenable(traceFileName) || FileOpenable(bytecodeFileName)); + + // Write out trace. + std::ofstream out (traceFileName.c_str ()); + out << F->getName () << "\n"; for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) out << getBasicBlockIndex (*i) << " "; out << "\n"; out.close (); -} + + // Write out bytecode. + std::ofstream bout (bytecodeFileName.c_str ()); + WriteBytecodeToFile(F->getParent (), bout); + bout.close (); +} /// This method is called when we have finally constructed a /// trace. The first parameter is the vector of basic blocks that form From gaeke at cs.uiuc.edu Wed May 19 03:54:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 03:54:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405190853.DAA19252@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.42 -> 1.43 --- Log message: Use new trace cloner --- Diffs of the changes: (+13 -12) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.42 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.43 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.42 Tue May 18 16:23:06 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed May 19 03:53:20 2004 @@ -282,18 +282,17 @@ /// to O2CMap. /// static void cloneTraceBBsIntoFunction (Trace &T, Function *F, ValueMap &O2CMap){ - // Clone each basic block into the new function. - for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI) { - BasicBlock *srcB = *TI; - // Create a new BasicBlock dstB that corresponds to srcB in T. - BasicBlock *dstB = CloneBasicBlock (srcB, O2CMap, ".ttf"); - DEBUG(dstB->setName (srcB->getName () + ".ttf")); - // Add dstB to F. - F->getBasicBlockList ().push_back (dstB); - // Remember the correspondence between srcB and dstB. (CloneFunction does - // this, but we aren't cloning the whole function.) - O2CMap[srcB] = dstB; - } + for (Function::aiterator AI = T.getFunction ()->abegin (), + AE = T.getFunction ()->aend (); AI != AE; ++AI) + O2CMap[AI] = AI; + for (Function::iterator FI = T.getFunction ()->begin (), + FE = T.getFunction ()->end (); FI != FE; ++FI) + if (!T.contains (FI)) { + O2CMap[FI] = FI; + for (BasicBlock::iterator BI = FI->begin (), BE = FI->end (); BI != BE; ++BI) + O2CMap[BI] = BI; + } + CloneTraceInto (F, T, O2CMap, ".ttf"); } /// isFirstTriggerCall - Returns true iff I is a call instruction which appears @@ -403,6 +402,8 @@ threadFLIEdges (F); numberExitBranchesInTrace (T, BranchNumber); + + DEBUG (std::cerr << "\n FUNCTION BEFORE FIXUPS: \n" << *F << "\n\n"); // Fix up the cloned basic blocks of the function so that they are // internally consistent. From gaeke at cs.uiuc.edu Wed May 19 04:09:00 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 04:09:00 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/CloneTrace.cpp Message-ID: <200405190908.EAA19859@seraph.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: CloneTrace.cpp updated: 1.6 -> 1.7 --- Log message: Add CloneTraceInto(), which is based on (and has mostly the same effects as) CloneFunctionInto(). --- Diffs of the changes: (+33 -0) Index: llvm/lib/Transforms/Utils/CloneTrace.cpp diff -u llvm/lib/Transforms/Utils/CloneTrace.cpp:1.6 llvm/lib/Transforms/Utils/CloneTrace.cpp:1.7 --- llvm/lib/Transforms/Utils/CloneTrace.cpp:1.6 Tue Feb 3 19:19:43 2004 +++ llvm/lib/Transforms/Utils/CloneTrace.cpp Wed May 19 04:08:14 2004 @@ -15,9 +15,11 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Analysis/Trace.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/iPHINode.h" #include "llvm/Function.h" +#include "ValueMapper.h" using namespace llvm; //Clones the trace (a vector of basic blocks) @@ -84,3 +86,34 @@ //return new vector of basic blocks return clonedTrace; } + +/// CloneTraceInto - Clone T into NewFunc. Original<->clone mapping is +/// saved in ValueMap. +/// +void llvm::CloneTraceInto(Function *NewFunc, Trace &T, + std::map &ValueMap, + const char *NameSuffix) { + assert(NameSuffix && "NameSuffix cannot be null!"); + + // Loop over all of the basic blocks in the trace, cloning them as + // appropriate. + // + for (Trace::const_iterator BI = T.begin(), BE = T.end(); BI != BE; ++BI) { + const BasicBlock *BB = *BI; + + // Create a new basic block and copy instructions into it! + BasicBlock *CBB = CloneBasicBlock(BB, ValueMap, NameSuffix, NewFunc); + ValueMap[BB] = CBB; // Add basic block mapping. + } + + // Loop over all of the instructions in the new function, fixing up operand + // references as we go. This uses ValueMap to do all the hard work. + // + for (Function::iterator BB = + cast(ValueMap[T.getEntryBasicBlock()]), + BE = NewFunc->end(); BB != BE; ++BB) + // Loop over all instructions, fixing each one as we find it... + for (BasicBlock::iterator II = BB->begin(); II != BB->end(); ++II) + RemapInstruction(II, ValueMap); +} + From gaeke at cs.uiuc.edu Wed May 19 04:09:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 04:09:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Transforms/Utils/CloneFunction.cpp ValueMapper.cpp ValueMapper.h Message-ID: <200405190908.EAA19852@seraph.cs.uiuc.edu> Changes in directory llvm/lib/Transforms/Utils: CloneFunction.cpp updated: 1.21 -> 1.22 ValueMapper.cpp updated: 1.11 -> 1.12 ValueMapper.h updated: 1.4 -> 1.5 --- Log message: Move RemapInstruction() to ValueMapper, so that it can be shared with CloneTrace, and because it is primarily an operation on ValueMaps. It is now a global (non-static) function which can be pulled in using ValueMapper.h. --- Diffs of the changes: (+26 -22) Index: llvm/lib/Transforms/Utils/CloneFunction.cpp diff -u llvm/lib/Transforms/Utils/CloneFunction.cpp:1.21 llvm/lib/Transforms/Utils/CloneFunction.cpp:1.22 --- llvm/lib/Transforms/Utils/CloneFunction.cpp:1.21 Wed Feb 4 15:44:26 2004 +++ llvm/lib/Transforms/Utils/CloneFunction.cpp Wed May 19 04:08:11 2004 @@ -20,25 +20,6 @@ #include "ValueMapper.h" using namespace llvm; -// RemapInstruction - Convert the instruction operands from referencing the -// current values into those specified by ValueMap. -// -static inline void RemapInstruction(Instruction *I, - std::map &ValueMap) { - for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) { - const Value *Op = I->getOperand(op); - Value *V = MapValue(Op, ValueMap); -#ifndef NDEBUG - if (!V) { - std::cerr << "Val = \n" << Op << "Addr = " << (void*)Op; - std::cerr << "\nInst = " << I; - } -#endif - assert(V && "Referenced value not in value map!"); - I->setOperand(op, V); - } -} - // CloneBasicBlock - See comments in Cloning.h BasicBlock *llvm::CloneBasicBlock(const BasicBlock *BB, std::map &ValueMap, Index: llvm/lib/Transforms/Utils/ValueMapper.cpp diff -u llvm/lib/Transforms/Utils/ValueMapper.cpp:1.11 llvm/lib/Transforms/Utils/ValueMapper.cpp:1.12 --- llvm/lib/Transforms/Utils/ValueMapper.cpp:1.11 Sat Feb 14 23:55:13 2004 +++ llvm/lib/Transforms/Utils/ValueMapper.cpp Wed May 19 04:08:12 2004 @@ -99,3 +99,22 @@ assert(0 && "Unknown value type: why didn't it get resolved?!"); return 0; } + +/// RemapInstruction - Convert the instruction operands from referencing the +/// current values into those specified by ValueMap. +/// +void llvm::RemapInstruction(Instruction *I, + std::map &ValueMap) { + for (unsigned op = 0, E = I->getNumOperands(); op != E; ++op) { + const Value *Op = I->getOperand(op); + Value *V = MapValue(Op, ValueMap); +#ifndef NDEBUG + if (!V) { + std::cerr << "Val = \n" << Op << "Addr = " << (void*)Op; + std::cerr << "\nInst = " << I; + } +#endif + assert(V && "Referenced value not in value map!"); + I->setOperand(op, V); + } +} Index: llvm/lib/Transforms/Utils/ValueMapper.h diff -u llvm/lib/Transforms/Utils/ValueMapper.h:1.4 llvm/lib/Transforms/Utils/ValueMapper.h:1.5 --- llvm/lib/Transforms/Utils/ValueMapper.h:1.4 Fri Jan 9 00:12:26 2004 +++ llvm/lib/Transforms/Utils/ValueMapper.h Wed May 19 04:08:12 2004 @@ -12,14 +12,18 @@ // //===----------------------------------------------------------------------===// -#ifndef LIB_TRANSFORMS_UTILS_VALUE_MAPPER_H -#define LIB_TRANSFORMS_UTILS_VALUE_MAPPER_H +#ifndef VALUEMAPPER_H +#define VALUEMAPPER_H #include namespace llvm { class Value; - Value *MapValue(const Value *V, std::map &VM); + class Instruction; + typedef std::map ValueMapTy; + + Value *MapValue(const Value *V, ValueMapTy &VM); + void RemapInstruction(Instruction *I, ValueMapTy &VM); } // End llvm namespace #endif From gaeke at cs.uiuc.edu Wed May 19 04:38:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 04:38:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405190937.EAA20391@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.43 -> 1.44 --- Log message: Rewrite threadFLIEdges() not to use RTTI so wastefully, and to skip over most instructions. --- Diffs of the changes: (+35 -38) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.43 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.44 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.43 Wed May 19 03:53:20 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed May 19 04:37:04 2004 @@ -197,7 +197,7 @@ for (unsigned i = 0; i < BI->getNumSuccessors (); ++i) { BasicBlock *BIT = BI->getSuccessor (i); if (!T.contains (BIT)) - return BI; + return BI; } return NULL; } @@ -444,46 +444,43 @@ } void TraceFunctionBuilder::threadFLIEdges (Function *F) { - for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) - for (BasicBlock::iterator Inst = FI->begin (), BE = FI->end (); Inst != BE; ++Inst) { - if (isa (Inst)) { - // In a PHI node, replace references to FLI blocks with the - // corresponding edge's source. - for (unsigned OI = 0, OE = Inst->getNumOperands(); OI != OE; ++OI) { - Value *op = Inst->getOperand (OI); - if (isa (op)) { - BasicBlock *BB = cast (op); - FLIMapTy::iterator It = FLIMap.find (BB); - if (It != FLIMap.end ()) { - DEBUG (std::cerr << "threadFLIEdges: threading operand " << OI - << " (FLI block " << BB->getName () << " --> <[" - << It->second.first->getName () << "], " - << It->second.second->getName () << ">) of instruction: " - << *Inst << "\n"); - Inst->setOperand (OI, It->second.first); - } - } - } - } else if (isa (Inst)) { - // If it's a branch, replace references to FLI blocks with the - // corresponding edge's target. - for (unsigned OI = 0, OE = Inst->getNumOperands(); OI != OE; ++OI) { - Value *op = Inst->getOperand (OI); - if (isa (op)) { - BasicBlock *BB = cast (op); - FLIMapTy::iterator It = FLIMap.find (BB); - if (It != FLIMap.end ()) { - DEBUG (std::cerr << "threadFLIEdges: threading operand " << OI - << " (FLI block " << BB->getName () << " --> <" - << It->second.first->getName () << ", [" - << It->second.second->getName () << "]>) of instruction: " - << *Inst << "\n"); - Inst->setOperand (OI, It->second.second); - } - } + for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) { + // Replace references to FLI blocks in PHI nodes with the + // corresponding edge's source. + for (BasicBlock::iterator Inst = FI->begin (); + PHINode *PN = dyn_cast (Inst); ++Inst) + for (unsigned i = 0, e = PN->getNumIncomingValues (); i != e; ++i) { + FLIMapTy::iterator It = FLIMap.find (PN->getIncomingBlock (i)); + if (It != FLIMap.end ()) { + DEBUG (std::cerr << "threadFLIEdges: threading incoming block " << i + << " (FLI block " << It->first->getName () << " --> <[" + << It->second.first->getName () << "], " + << It->second.second->getName () << ">) of PHI node: " + << *PN << "\n"); + PN->setIncomingBlock (i, It->second.first); } } + + // Look for a branch at the end of the basic block. + TerminatorInst *TI = FI->getTerminator (); + if (!TI) continue; + BranchInst *BI = dyn_cast (TI); + if (!BI) continue; + + // Replace references to FLI blocks in branches with the + // corresponding edge's target. + for (unsigned i = 0, e = BI->getNumSuccessors (); i != e; ++i) { + FLIMapTy::iterator It = FLIMap.find (BI->getSuccessor (i)); + if (It != FLIMap.end ()) { + DEBUG (std::cerr << "threadFLIEdges: threading successor " << i + << " (FLI block " << It->first->getName () << " --> <" + << It->second.first->getName () << ", [" + << It->second.second->getName () << "]>) of branch: " + << *BI << "\n"); + BI->setSuccessor (i, It->second.second); + } } + } } /// buildFLIMap - Removes any FLI blocks which ended up in the trace, and From gaeke at cs.uiuc.edu Wed May 19 05:00:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 05:00:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405190959.EAA20780@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.44 -> 1.45 --- Log message: Make CloneTraceInto do the work of connecting live-in arguments to their uses. (cloneTraceBBsIntoFunction now takes a TraceFunction arg.) Give threadFLIEdges a doc comment. --- Diffs of the changes: (+21 -13) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.44 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.45 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.44 Wed May 19 04:37:04 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed May 19 04:59:45 2004 @@ -276,23 +276,27 @@ } } -/// cloneTraceBBsIntoFunction - Copy the BasicBlocks of the trace T into -/// the new Function F, which should be initially empty. Correspondences -/// between Original instructions (in T) and their Clones (in F) are added -/// to O2CMap. +/// cloneTraceBBsIntoFunction - Copy the BasicBlocks of the trace into +/// the new TraceFn, which should be initially empty. Correspondences +/// between Original instructions (in the trace) and their Clones (in +/// TraceFn) are added to TF->O2CMap. /// -static void cloneTraceBBsIntoFunction (Trace &T, Function *F, ValueMap &O2CMap){ - for (Function::aiterator AI = T.getFunction ()->abegin (), - AE = T.getFunction ()->aend (); AI != AE; ++AI) +static void cloneTraceBBsIntoFunction (TraceFunction *TF) { + Function *MF = TF->MatrixFn; + LiveVariableSet &Si = TF->LiveInSet; + ValueMap &O2CMap = TF->O2CMap; + for (Function::aiterator AI = MF->abegin (), AE = MF->aend (); AI != AE; ++AI) O2CMap[AI] = AI; - for (Function::iterator FI = T.getFunction ()->begin (), - FE = T.getFunction ()->end (); FI != FE; ++FI) - if (!T.contains (FI)) { + for (Function::iterator FI = MF->begin (), FE = MF->end (); FI != FE; ++FI) + if (!TF->T.contains (FI)) { O2CMap[FI] = FI; - for (BasicBlock::iterator BI = FI->begin (), BE = FI->end (); BI != BE; ++BI) + for (BasicBlock::iterator BI = FI->begin (), BE = FI->end (); BI != BE; + ++BI) O2CMap[BI] = BI; } - CloneTraceInto (F, T, O2CMap, ".ttf"); + for (LiveVariableSet::iterator I = Si.begin (), E = Si.end (); I != E; ++I) + O2CMap[*I] = getFunctionArg (TF->TraceFn, TF->LiveInToParameterMap[*I]); + CloneTraceInto (TF->TraceFn, TF->T, O2CMap, ".ttf"); } /// isFirstTriggerCall - Returns true iff I is a call instruction which appears @@ -397,7 +401,7 @@ buildFLIMap (T, FLIMap); // First copy the basic blocks from the trace. - cloneTraceBBsIntoFunction (T, F, O2CMap); + cloneTraceBBsIntoFunction (TF); threadFLIEdges (F); @@ -443,6 +447,10 @@ return true; } +/// threadFLIEdges - Replace all references to FLI blocks in the given +/// function: at PHI nodes, with the corresponding edge's source, and at +/// branches, with the corresponding edge's target. +/// void TraceFunctionBuilder::threadFLIEdges (Function *F) { for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) { // Replace references to FLI blocks in PHI nodes with the From gaeke at cs.uiuc.edu Wed May 19 05:11:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 05:11:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405191010.FAA21030@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.45 -> 1.46 --- Log message: Simplifications allowed by new FLI threader and trace cloner --- Diffs of the changes: (+1 -22) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.45 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.46 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.45 Wed May 19 04:59:45 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed May 19 05:10:09 2004 @@ -654,33 +654,12 @@ Instruction &I = *BI; for (unsigned i = 0; i < I.getNumOperands (); ++i) { Value *V = I.getOperand (i); - // Fold Phi sources which come from FLI blocks - if (isa (&I)) - if (BasicBlock *phiSource = dyn_cast (V)) - if (BasicBlock *realSource = getFLIEdgeSource (phiSource)) - V = realSource; - - // If the instruction I has an operand which is in the live-in - // set of the trace, then we must replace that operand with - // the corresponding argument of F. We can find out which - // operands to replace by looking them up in - // TF->LiveInToParameterMap. - if (TF->LiveInToParameterMap.find (V) != TF->LiveInToParameterMap.end ()){ - DEBUG(WriteAsOperand (std::cerr, V, true, true, - TF->MatrixFn->getParent ()); - std::cerr << " in instruction:\n " << I << " is argument " - << TF->LiveInToParameterMap[V] << " in new function\n"); - assert (V->getType () == - getFunctionArg (F, TF->LiveInToParameterMap[V])->getType () - && "Live-in Value's type doesn't match corresponding arg type"); - I.setOperand(i, getFunctionArg (F, TF->LiveInToParameterMap[V])); - } // If the instruction I has an operand which is in the // trace, that operand will have been cloned into the // function, and I will still reference the version from // outside the function. Replace any reference to an operand // which has had a clone made with a reference to its clone. - else if (O2CMap.find (V) != O2CMap.end () && O2CMap[V]) { + if (O2CMap.find (V) != O2CMap.end () && O2CMap[V]) { DEBUG(std::cerr << *V << " in instruction " << I << " is value " << O2CMap[V] << " in new function\n"); assert (V->getType () == O2CMap[V]->getType () From gaeke at cs.uiuc.edu Wed May 19 05:33:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 05:33:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405191032.FAA21420@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.46 -> 1.47 --- Log message: Minor simplification: merge two asserts; remove a dyn_cast --- Diffs of the changes: (+3 -5) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.46 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.47 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.46 Wed May 19 05:10:09 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Wed May 19 05:32:12 2004 @@ -565,11 +565,9 @@ if (!T.contains (phiSource)) { // FIXME: Assert that O2CMap[PN]'s value i is live in. Value *V = O2CMap[PN]; - assert (V && "Can't find clone of Phi node from trace entry BB"); - PHINode *PNinF = dyn_cast (V); - assert (PNinF - && "Clone of Phi node from entry BB is not a Phi node"); - PNinF->setIncomingBlock (i, EntryFixup); + assert (V && isa (V) + && "Clone of PHINode from trace entry BB missing or mangled"); + cast (V)->setIncomingBlock (i, EntryFixup); } } } From alkis at cs.uiuc.edu Wed May 19 14:19:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 19 14:19:03 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Transforms/Utils/Cloning.h Message-ID: <200405191917.OAA11151@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Transforms/Utils: Cloning.h updated: 1.14 -> 1.15 --- Log message: Declare function defined in namespace llvm as gcc-3.4 doesn't accept a definition in a namespace of a non-declared function. --- Diffs of the changes: (+8 -0) Index: llvm/include/llvm/Transforms/Utils/Cloning.h diff -u llvm/include/llvm/Transforms/Utils/Cloning.h:1.14 llvm/include/llvm/Transforms/Utils/Cloning.h:1.15 --- llvm/include/llvm/Transforms/Utils/Cloning.h:1.14 Tue Feb 3 21:59:08 2004 +++ llvm/include/llvm/Transforms/Utils/Cloning.h Wed May 19 14:17:48 2004 @@ -31,6 +31,7 @@ class InvokeInst; class ReturnInst; class CallSite; +class Trace; /// CloneModule - Return an exact copy of the specified module /// @@ -94,6 +95,13 @@ std::vector &Returns, const char *NameSuffix = ""); + +/// CloneTraceInto - Clone T into NewFunc. Original<->clone mapping is +/// saved in ValueMap. +/// +void CloneTraceInto(Function *NewFunc, Trace &T, + std::map &ValueMap, + const char *NameSuffix); /// InlineFunction - This function inlines the called function into the basic /// block of the caller. This returns false if it is not possible to inline From gaeke at cs.uiuc.edu Wed May 19 15:17:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 15:17:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceWriter.cpp RuntimeOptimizations.cpp Message-ID: <200405192016.PAA24407@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: TraceWriter.cpp added (r1.1) RuntimeOptimizations.cpp updated: 1.34 -> 1.35 --- Log message: Must resist the urge to entangle trace writer with runtime trace optimizer! --- Diffs of the changes: (+64 -37) Index: reopt/lib/LightWtProfiling/TraceWriter.cpp diff -c /dev/null reopt/lib/LightWtProfiling/TraceWriter.cpp:1.1 *** /dev/null Wed May 19 15:16:23 2004 --- reopt/lib/LightWtProfiling/TraceWriter.cpp Wed May 19 15:16:12 2004 *************** *** 0 **** --- 1,63 ---- + //===-- LightWtProfiling/TraceWriter.cpp -------------------------*- C++ -*--=// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file exports a method which can be used to save a trace to + // disk, along with the module it refers to. + // + //===----------------------------------------------------------------------===// + + #include "llvm/Analysis/Trace.h" + #include "llvm/Bytecode/Writer.h" + #include "llvm/Function.h" + #include "Support/FileUtilities.h" + #include "Support/StringExtras.h" + #include + using namespace llvm; + + namespace llvm { + + /// getBasicBlockIndex - Returns the index of BB in its parent function. + /// + static inline int getBasicBlockIndex (BasicBlock *BB) { + int bbNum = 0; + Function *F = BB->getParent (); + Function::iterator block = F->begin(); + while (&*block != BB) { + ++block; + ++bbNum; + } + return bbNum; + } + + void WriteTraceToFile (Trace &T) { + // Get unique filename for trace & corresponding module. + std::string traceFileName, bytecodeFileName; + Function *F = T.getFunction (); + unsigned count = 0; + do { + ++count; + traceFileName = F->getName () + ".trace" + utostr (count) + ".txt"; + bytecodeFileName = F->getName () + ".trace" + utostr (count) + ".bc"; + } while (FileOpenable(traceFileName) || FileOpenable(bytecodeFileName)); + + // Write out trace. + std::ofstream out (traceFileName.c_str ()); + out << F->getName () << "\n"; + for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) + out << getBasicBlockIndex (*i) << " "; + out << "\n"; + out.close (); + + // Write out bytecode. + std::ofstream bout (bytecodeFileName.c_str ()); + WriteBytecodeToFile(F->getParent (), bout); + bout.close (); + } + + } // end namespace llvm Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.34 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.35 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.34 Wed May 19 03:48:36 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Wed May 19 15:16:11 2004 @@ -68,43 +68,7 @@ ///==----------------------------------------------------------------------==/// -/// getBasicBlockIndex - Returns the index of BB in its parent function. -/// -int getBasicBlockIndex (BasicBlock *BB) { - int bbNum = 0; - Function *F = BB->getParent (); - Function::iterator block = F->begin(); - while (&*block != BB) { - ++block; - ++bbNum; - } - return bbNum; -} - -void WriteTraceToFile (Trace &T) { - // Get unique filename for trace & corresponding module. - std::string traceFileName, bytecodeFileName; - Function *F = T.getFunction (); - unsigned count = 0; - do { - ++count; - traceFileName = F->getName () + ".trace" + utostr (count) + ".txt"; - bytecodeFileName = F->getName () + ".trace" + utostr (count) + ".bc"; - } while (FileOpenable(traceFileName) || FileOpenable(bytecodeFileName)); - - // Write out trace. - std::ofstream out (traceFileName.c_str ()); - out << F->getName () << "\n"; - for (Trace::iterator i = T.begin (), e = T.end (); i != e; ++i) - out << getBasicBlockIndex (*i) << " "; - out << "\n"; - out.close (); - - // Write out bytecode. - std::ofstream bout (bytecodeFileName.c_str ()); - WriteBytecodeToFile(F->getParent (), bout); - bout.close (); -} +extern void WriteTraceToFile (Trace &T); /// This method is called when we have finally constructed a /// trace. The first parameter is the vector of basic blocks that form From alkis at cs.uiuc.edu Wed May 19 15:46:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 19 15:46:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/classdump/classdump.cpp Message-ID: <200405192044.PAA07160@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/classdump: classdump.cpp updated: 1.3 -> 1.4 --- Log message: Use an auto_ptr instead of a raw pointer. --- Diffs of the changes: (+4 -2) Index: llvm-java/tools/classdump/classdump.cpp diff -u llvm-java/tools/classdump/classdump.cpp:1.3 llvm-java/tools/classdump/classdump.cpp:1.4 --- llvm-java/tools/classdump/classdump.cpp:1.3 Fri Apr 16 19:55:08 2004 +++ llvm-java/tools/classdump/classdump.cpp Wed May 19 15:44:40 2004 @@ -16,15 +16,17 @@ #include #include +#include using namespace llvm; int main(int argc, char* argv[]) { try { - Java::ClassFile* cf = Java::ClassFile::readClassFile(std::cin); + std::auto_ptr cf( + Java::ClassFile::readClassFile(std::cin)); + cf->dump(std::cout); - delete cf; } catch (std::exception& e) { std::cerr << e.what() << '\n'; From alkis at cs.uiuc.edu Wed May 19 16:11:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Wed May 19 16:11:01 2004 Subject: [llvm-commits] CVS: llvm-java/test/ClassFile/Simple.java Message-ID: <200405192110.QAA16393@zion.cs.uiuc.edu> Changes in directory llvm-java/test/ClassFile: Simple.java updated: 1.1 -> 1.2 --- Log message: Put Simple class in a package. --- Diffs of the changes: (+2 -0) Index: llvm-java/test/ClassFile/Simple.java diff -u llvm-java/test/ClassFile/Simple.java:1.1 llvm-java/test/ClassFile/Simple.java:1.2 --- llvm-java/test/ClassFile/Simple.java:1.1 Wed Apr 21 11:36:04 2004 +++ llvm-java/test/ClassFile/Simple.java Wed May 19 16:10:18 2004 @@ -1,3 +1,5 @@ +package edu.uiuc.cs.llvm; + public class Simple { public static int main(String[] args) { From brukman at cs.uiuc.edu Wed May 19 16:19:02 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Wed May 19 16:19:02 2004 Subject: [llvm-commits] CVS: llvm/test/Programs/TEST.nightly.Makefile Message-ID: <200405192117.QAA02148@zion.cs.uiuc.edu> Changes in directory llvm/test/Programs: TEST.nightly.Makefile updated: 1.28 -> 1.29 --- Log message: The syntax for the vim mode is wrong as nothing else can be on the same line. --- Diffs of the changes: (+1 -1) Index: llvm/test/Programs/TEST.nightly.Makefile diff -u llvm/test/Programs/TEST.nightly.Makefile:1.28 llvm/test/Programs/TEST.nightly.Makefile:1.29 --- llvm/test/Programs/TEST.nightly.Makefile:1.28 Sun Feb 29 22:43:08 2004 +++ llvm/test/Programs/TEST.nightly.Makefile Wed May 19 16:17:35 2004 @@ -1,4 +1,4 @@ -##===- test/Programs/TEST.nightly.Makefile --*- Makefile -*- vim:ft=make --===## +##===- test/Programs/TEST.nightly.Makefile ----------------*- Makefile -*--===## # # This test is used in conjunction with the llvm/utils/NightlyTest* stuff to # generate information about program status for the nightly report. From brukman at cs.uiuc.edu Wed May 19 16:22:05 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Wed May 19 16:22:05 2004 Subject: [llvm-commits] CVS: llvm/utils/vim/README Message-ID: <200405192120.QAA04696@zion.cs.uiuc.edu> Changes in directory llvm/utils/vim: README updated: 1.3 -> 1.4 --- Log message: Add hint about syntax-highlighting non-standardly-named LLVM Makefiles. --- Diffs of the changes: (+9 -0) Index: llvm/utils/vim/README diff -u llvm/utils/vim/README:1.3 llvm/utils/vim/README:1.4 --- llvm/utils/vim/README:1.3 Mon Aug 11 13:05:19 2003 +++ llvm/utils/vim/README Wed May 19 16:20:40 2004 @@ -32,3 +32,12 @@ Note: If you notice missing or incorrect syntax highlighting, please contact ; if you wish to provide a patch to improve the functionality, it will be most appreciated. Thank you. + +If you find yourself working with LLVM Makefiles often, but you don't get syntax +highlighting (because the files have names such as Makefile.rules or +TEST.nightly.Makefile), add the following to your ~/.vimrc: + + " LLVM Makefile highlighting mode + augroup filetype + au! BufRead,BufNewFile *Makefile* set filetype=make + augroup END From gaeke at cs.uiuc.edu Wed May 19 16:31:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Wed May 19 16:31:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp Message-ID: <200405192130.QAA29459@seraph.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9CodeEmitter.cpp updated: 1.60 -> 1.61 --- Log message: Minor simplification: eliminate a dyn_cast. Fix a typo in a debug message. --- Diffs of the changes: (+4 -9) Index: llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp diff -u llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp:1.60 llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp:1.61 --- llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp:1.60 Fri Apr 23 13:10:38 2004 +++ llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp Wed May 19 16:30:01 2004 @@ -596,14 +596,9 @@ DEBUG(std::cerr << "Saving reference to BB (VReg)\n"); unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue(); BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI))); - } else if (const Constant *C = dyn_cast(V)) { - if (const ConstantInt *CI = dyn_cast(C)) { - rv = CI->getRawValue() - MCE.getCurrentPCValue(); - } else { - std::cerr << "Cannot have non-integral const in instruction: " - << *C; - abort(); - } + } else if (const ConstantInt *CI = dyn_cast(V)) { + // Make constant PC-relative by subtracting the PC from it. + rv = CI->getRawValue() - MCE.getCurrentPCValue(); } else if (GlobalValue *GV = dyn_cast(V)) { // same as MO.isGlobalAddress() DEBUG(std::cerr << "GlobalValue: "); @@ -777,7 +772,7 @@ if (binCode == (1 << 30)) { // this is an invalid call: the addr is out of bounds. that means a code // sequence has already been emitted, and this is a no-op - DEBUG(std::cerr << "Call supressed: already emitted far call.\n"); + DEBUG(std::cerr << "Call suppressed: already emitted far call.\n"); } else { emitWord(binCode); } From gaeke at cs.uiuc.edu Thu May 20 02:44:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 02:44:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp Message-ID: <200405200743.CAA03040@seraph.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9CodeEmitter.cpp updated: 1.61 -> 1.62 --- Log message: Fix a bug in outputting branches to constant PCs. Since the PC is supplied as a full 64-bit address, it must be adjusted to fit in the branch instruction's immediate field. (This is only used in the reoptimizer, for now.) --- Diffs of the changes: (+3 -2) Index: llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp diff -u llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp:1.61 llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp:1.62 --- llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp:1.61 Wed May 19 16:30:01 2004 +++ llvm/lib/Target/SparcV9/SparcV9CodeEmitter.cpp Thu May 20 02:43:40 2004 @@ -597,8 +597,9 @@ unsigned* CurrPC = (unsigned*)(intptr_t)MCE.getCurrentPCValue(); BBRefs.push_back(std::make_pair(BB, std::make_pair(CurrPC, &MI))); } else if (const ConstantInt *CI = dyn_cast(V)) { - // Make constant PC-relative by subtracting the PC from it. - rv = CI->getRawValue() - MCE.getCurrentPCValue(); + // The real target of the branch is CI = PC + (rv * 4) + // So undo that: give the instruction (CI - PC) / 4 + rv = (CI->getRawValue() - MCE.getCurrentPCValue()) / 4; } else if (GlobalValue *GV = dyn_cast(V)) { // same as MO.isGlobalAddress() DEBUG(std::cerr << "GlobalValue: "); From gaeke at cs.uiuc.edu Thu May 20 12:03:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 12:03:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405201700.MAA26611@zion.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.35 -> 1.36 --- Log message: Add a hook which is easy to set a breakpoint on for debugging purposes. For extra bonus points, it even prints out gdb breakpoint commands you'll want to use. --- Diffs of the changes: (+7 -0) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.35 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.36 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.35 Wed May 19 15:16:11 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Thu May 20 12:00:45 2004 @@ -70,6 +70,12 @@ extern void WriteTraceToFile (Trace &T); +extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr) { + std::cerr << "\n*** About to return from optimizeTrace(). GDB breakpoints:\n" + << std::hex << "display/i $pc\n" << "b *0x" << a << "\n" << "b *0x" + << traceStartAddr << std::dec << "\n"; +} + /// This method is called when we have finally constructed a /// trace. The first parameter is the vector of basic blocks that form /// the trace; the second parameter is the starting @@ -132,6 +138,7 @@ << " to point to 0x" << traceStartAddr << std::dec << "\n"); vm->writeBranchInstruction(a, traceStartAddr); doFlush (a, a + 4); + TraceOptimizerDone(a, traceStartAddr); } } // end namespace llvm From gaeke at cs.uiuc.edu Thu May 20 12:13:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 12:13:04 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405201711.MAA26886@zion.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.61 -> 1.62 --- Log message: Print out more debugging information about the mapping info we got from LLC about the return basic block. --- Diffs of the changes: (+8 -2) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.61 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.62 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.61 Mon May 17 16:00:19 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Thu May 20 12:11:48 2004 @@ -530,8 +530,14 @@ assert ((TF->ReturnBlockForTraceExit.find (RBB) != TF->ReturnBlockForTraceExit.end ()) && "Can't find matrix fn BB address to return to from trace"); - uint64_t ReturnAddress = - getBasicBlockInfo(TF->ReturnBlockForTraceExit[RBB]).first; + std::pair BlockAddrs = + getBasicBlockInfo(TF->ReturnBlockForTraceExit[RBB]); + uint64_t ReturnAddress = BlockAddrs.first; + DEBUG (std::cerr << "Return block for trace exit path is: " + << *TF->ReturnBlockForTraceExit[RBB] << "\n" + << "Mapping info says addresses are: return address = 0x" + << std::hex << BlockAddrs.first << ", end of block = 0x" + << BlockAddrs.second << std::dec << "\n"); // Insert a branch back to the return BasicBlock of the matrix fn. insertBranchMachineInstrs (ReturnAddress, MBB); } From gaeke at cs.uiuc.edu Thu May 20 13:06:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 13:06:02 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405201805.NAA05093@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.62 -> 1.63 --- Log message: We were restoring fp without saving it in the first place. This was causing a crash on return from the MatrixFn, when it tried to RESTORE its caller's stack. --- Diffs of the changes: (+5 -0) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.62 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.63 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.62 Thu May 20 12:11:48 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Thu May 20 13:05:22 2004 @@ -226,6 +226,10 @@ regsUsed.insert (SparcV9::fsr); if (intCCRegSeen) regsUsed.insert (SparcV9::ccr); + + // Always put fp in the set because it is restored unconditionally. + static const unsigned fp = SparcV9::i6; + regsUsed.insert (fp); } void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, @@ -485,6 +489,7 @@ for (std::vector::iterator vi = mvec.begin (), ve = mvec.end (); vi != ve; ++vi) MBB.push_back (*vi); + regsUsed.erase (fp); // Insert copies from each live-out variable's reg. in the trace // to its reg. in the matrix function. From gaeke at cs.uiuc.edu Thu May 20 13:10:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 13:10:03 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp TraceOptEmitter.cpp Message-ID: <200405201809.NAA05211@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.36 -> 1.37 TraceOptEmitter.cpp updated: 1.8 -> 1.9 --- Log message: Put DEBUG(...) around more debugging printouts and stuff. --- Diffs of the changes: (+8 -8) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.36 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.37 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.36 Thu May 20 12:00:45 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Thu May 20 13:09:30 2004 @@ -71,9 +71,9 @@ extern void WriteTraceToFile (Trace &T); extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr) { - std::cerr << "\n*** About to return from optimizeTrace(). GDB breakpoints:\n" - << std::hex << "display/i $pc\n" << "b *0x" << a << "\n" << "b *0x" - << traceStartAddr << std::dec << "\n"; + DEBUG (std::cerr << "\n*** About to return from optimizeTrace(). GDB" + << " breakpoints:\n" << std::hex << "display/i $pc\n" << "b *0x" << a + << "\n" << "b *0x" << traceStartAddr << std::dec << "\n"); } /// This method is called when we have finally constructed a @@ -100,7 +100,7 @@ // Turn the vector of basic blocks into a Trace, and then turn the Trace into // a TraceFunction. Trace T (vBB); - WriteTraceToFile (T); + DEBUG (WriteTraceToFile (T)); TraceFunction *TF = TraceFunction::get (T); // Force the SPARCv9 register allocator to save its state into a global Index: reopt/lib/LightWtProfiling/TraceOptEmitter.cpp diff -u reopt/lib/LightWtProfiling/TraceOptEmitter.cpp:1.8 reopt/lib/LightWtProfiling/TraceOptEmitter.cpp:1.9 --- reopt/lib/LightWtProfiling/TraceOptEmitter.cpp:1.8 Wed Apr 28 16:41:09 2004 +++ reopt/lib/LightWtProfiling/TraceOptEmitter.cpp Thu May 20 13:09:30 2004 @@ -166,16 +166,16 @@ void TraceOptEmitter::emitWord(unsigned W) { // This won't work if the endianness of the host and target don't agree! (For // a JIT this can't happen though. :) - std::cerr << "TraceOptEmitter: emitting word 0x" << std::hex << W - << " at cursor: " << CurByte << std::dec << "\n"; + DEBUG (std::cerr << "TraceOptEmitter: emitting word 0x" << std::hex << W + << " at cursor: " << CurByte << std::dec << "\n"); vm->writeInstToVM (CurByte, W); // does: *(unsigned*)CurByte = W; doFlush (CurByte - sizeof (unsigned), (uint64_t) CurByte + sizeof (unsigned)); CurByte += sizeof(unsigned); } void TraceOptEmitter::emitWordAt(unsigned W, unsigned *Ptr) { - std::cerr << "TraceOptEmitter: emitting word 0x" << std::hex << W - << std::dec << " at pointer: " << Ptr << "\n"; + DEBUG (std::cerr << "TraceOptEmitter: emitting word 0x" << std::hex << W + << std::dec << " at pointer: " << Ptr << "\n"); vm->writeInstToVM ((uint64_t) Ptr, W); // does: *Ptr = W; doFlush ((uint64_t) Ptr - sizeof (unsigned), (uint64_t) Ptr + sizeof (unsigned)); } From gaeke at cs.uiuc.edu Thu May 20 13:24:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 13:24:03 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405201822.NAA06321@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.47 -> 1.48 --- Log message: Put DEBUG(...) around more debugging printouts and stuff. --- Diffs of the changes: (+3 -3) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.47 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.48 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.47 Wed May 19 05:32:12 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Thu May 20 13:22:48 2004 @@ -587,9 +587,9 @@ // Fold branches which go to FLI blocks if (BasicBlock *backEdgeTarget = getFLIEdgeTarget (successor)) { - std::cerr << "Branch instr " << *BI << " looks like an instrumented " - << "back-edge from " << srcB->getName() << " to " - << backEdgeTarget->getName () << "\n"; + DEBUG (std::cerr << "Branch instr " << *BI << " looks like an" + << " instrumented back-edge from " << srcB->getName() + << " to " << backEdgeTarget->getName () << "\n"); successor = backEdgeTarget; } if (!T.contains (successor)) { From gaeke at cs.uiuc.edu Thu May 20 14:36:12 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 14:36:12 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405201934.OAA27641@zion.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.48 -> 1.49 --- Log message: Eliminate a dyn_cast. Rename fixupPhisAndCalls to fixupPhis, because it no longer needs to deal with calls. --- Diffs of the changes: (+5 -6) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.48 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.49 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.48 Thu May 20 13:22:48 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Thu May 20 14:34:26 2004 @@ -316,7 +316,7 @@ return false; } -static void fixupPhisAndCalls (BasicBlock *dstB, ValueMap &O2CMap) { +static void fixupPhis (BasicBlock *dstB, ValueMap &O2CMap) { std::vector goners; Function *F = dstB->getParent (); // Fix up Phi nodes: @@ -366,13 +366,12 @@ } } while (lastOffTraceSrcFound != -1); // Continue until none found. } - } // Make sure that our Phi fixups did the Right Thing. - DEBUG(if (PHINode *PN = dyn_cast (&I)) - if (PN->use_size () != 0) // 0-use nodes get deleted later + DEBUG(if (PN->use_size () != 0) // 0-use nodes get deleted later for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) assert (PN->getIncomingBlock (i)->getParent () == F && - "Sorry, fixupPhisAndCalls mishandled a Phi node")); + "Sorry, fixupPhis mishandled a Phi node")); + } } while (!goners.empty ()) { @@ -419,7 +418,7 @@ fixupFunctionBodyBB (T, F, srcB, dstB, O2CMap, So); } for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) - fixupPhisAndCalls (FI, O2CMap); + fixupPhis (FI, O2CMap); } /// identifyFLIEdge - returns a true value iff BB is a basic block containing From gaeke at cs.uiuc.edu Thu May 20 14:52:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 14:52:03 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405201950.OAA27892@zion.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.49 -> 1.50 --- Log message: In fixupPhis(), only iterate over Phi nodes in each cloned BasicBlock, not the whole BasicBlock. Also, untabify most of this function. Merge two asserts in fixupFunctionBodyBB(). --- Diffs of the changes: (+48 -61) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.49 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.50 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.49 Thu May 20 14:34:26 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Thu May 20 14:50:44 2004 @@ -320,66 +320,61 @@ std::vector goners; Function *F = dstB->getParent (); // Fix up Phi nodes: - for (BasicBlock::iterator BI = dstB->begin (), BE = dstB->end (); - BI != BE; ++BI) { - Instruction &I = *BI; - // In all cases, if a Phi node source in T was an on-trace basic - // block, then it will already have been fixed up to point to - // that block's clone, so we find off-trace sources by looking - // for source BBs which are not in F. - if (PHINode *PN = dyn_cast (&I)) { - unsigned onTraceSources = 0; - int lastSrcFound = -1; - for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) - if (PN->getIncomingBlock (i)->getParent () == F) { - lastSrcFound = i; - ++onTraceSources; - } - // Case 0. If the phi node has 0 sources on the trace, abort, - // because that should really never happen. - assert (onTraceSources != 0 - && "Phi node on trace has ALL its sources from off-trace!"); - // Case 1. If it has 1 source S on the trace, replace its uses - // with S. - if (onTraceSources == 1) { - DEBUG(std::cerr << "Replacing Phi node" << *PN - << " with its lone on-trace input " - << *PN->getIncomingValue (lastSrcFound) << "\n"); - PN->replaceAllUsesWith (PN->getIncomingValue (lastSrcFound)); - goners.push_back (BI); // Delete non-used phi node later. - } else { - // Case N. If the phi node has >1 source on the trace, just - // delete sources from the Phi node that are not on the trace. - int lastOffTraceSrcFound; - do { - lastOffTraceSrcFound = -1; - for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) - if (PN->getIncomingBlock (i)->getParent () != F) { - lastOffTraceSrcFound = i; // Found an off-trace source. - break; - } - if (lastOffTraceSrcFound != -1) { // Found one? - DEBUG(std::cerr << "Removing off-trace input " - << *PN->getIncomingValue (lastOffTraceSrcFound) - << " from Phi node " << *PN << "\n"); - PN->removeIncomingValue (lastOffTraceSrcFound); // Delete it. - } - } while (lastOffTraceSrcFound != -1); // Continue until none found. + for (BasicBlock::iterator Inst = dstB->begin (); + PHINode *PN = dyn_cast (Inst); ++Inst) { + // If a Phi node source in T was an on-trace basic block, then it + // will already have been fixed up to point to that block's clone, so we + // find off-trace sources by looking for source BBs which are not in F. + unsigned onTraceSources = 0; + int lastSrcFound = -1; + for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) + if (PN->getIncomingBlock (i)->getParent () == F) { + lastSrcFound = i; + ++onTraceSources; } + // Case 0. If the phi node has 0 sources on the trace, abort, + // because that should really never happen. + assert (onTraceSources != 0 + && "Phi node on trace has ALL its sources from off-trace!"); + // Case 1. If it has 1 source S on the trace, replace its uses + // with S. + if (onTraceSources == 1) { + DEBUG(std::cerr << "Replacing Phi node" << *PN << " with its lone" + << " on-trace input " << *PN->getIncomingValue (lastSrcFound) << "\n"); + PN->replaceAllUsesWith (PN->getIncomingValue (lastSrcFound)); + goners.push_back (PN); // Delete non-used phi node later. + } else { + // Case N. If the phi node has >1 source on the trace, just + // delete sources from the Phi node that are not on the trace. + int lastOffTraceSrcFound; + do { + lastOffTraceSrcFound = -1; + for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) + if (PN->getIncomingBlock (i)->getParent () != F) { + lastOffTraceSrcFound = i; // Found an off-trace source. + break; + } + if (lastOffTraceSrcFound != -1) { // Found one? + DEBUG(std::cerr << "Removing off-trace input " + << *PN->getIncomingValue (lastOffTraceSrcFound) + << " from Phi node " << *PN << "\n"); + PN->removeIncomingValue (lastOffTraceSrcFound); // Delete it. + } + } while (lastOffTraceSrcFound != -1); // Continue until none found. + } // Make sure that our Phi fixups did the Right Thing. DEBUG(if (PN->use_size () != 0) // 0-use nodes get deleted later - for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) - assert (PN->getIncomingBlock (i)->getParent () == F && - "Sorry, fixupPhis mishandled a Phi node")); - } + for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) + assert (PN->getIncomingBlock (i)->getParent () == F && + "Sorry, fixupPhis mishandled a Phi node")); } while (!goners.empty ()) { assert (goners.back ()->use_size () == 0 - && "Whoops, I was going to delete something which still has uses"); + && "Whoops, I was going to delete something which still has uses"); dstB->getInstList ().erase (goners.back ()); for (ValueMap::iterator i = O2CMap.begin(), e = O2CMap.end(); i != e; ++i) { - if (i->second == goners.back ()) { + if (i->second == goners.back ()) { O2CMap.erase (i); break; } @@ -630,16 +625,8 @@ // This is a non-trace-exiting destination of branch BI. Fix up // its clone's destination to point to its successor's clone. Value *V2 = O2CMap[successor]; - DEBUG(if (!V2) { - std::cerr - << "I'm confused: saw non-trace-exiting dest. of branch " - << *BI << " whose clone is " << *BIinF - << " successor number is " << i << " and successor is " - << *successor << ", but where's its clone?\n"; - assert(V2 && "Clone of basic block on trace is null?"); - }); - assert(isa (V2) - && "Clone of basic block on trace is not a basic block?"); + assert(V2 && isa (V2) + && "Clone of basic block on trace not found, or not a basic block"); BIinF->setSuccessor (i, cast (V2)); } } From gaeke at cs.uiuc.edu Thu May 20 15:06:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 15:06:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405202004.PAA28027@zion.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.50 -> 1.51 --- Log message: Clone of a constant is just the identity function, so don't fix up uses of constants --- Diffs of the changes: (+1 -1) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.50 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.51 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.50 Thu May 20 14:50:44 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Thu May 20 15:04:27 2004 @@ -643,7 +643,7 @@ // function, and I will still reference the version from // outside the function. Replace any reference to an operand // which has had a clone made with a reference to its clone. - if (O2CMap.find (V) != O2CMap.end () && O2CMap[V]) { + if (O2CMap.find (V) != O2CMap.end () && O2CMap[V] && !isa (V)) { DEBUG(std::cerr << *V << " in instruction " << I << " is value " << O2CMap[V] << " in new function\n"); assert (V->getType () == O2CMap[V]->getType () From lattner at cs.uiuc.edu Thu May 20 15:27:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Thu May 20 15:27:02 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/CBackend/Writer.cpp Message-ID: <200405202026.PAA28495@zion.cs.uiuc.edu> Changes in directory llvm/lib/Target/CBackend: Writer.cpp updated: 1.174 -> 1.175 --- Log message: Fix to make the CBE always emit comparisons inline. Hopefully this will fix the really bad code we're getting on PPC. --- Diffs of the changes: (+4 -0) Index: llvm/lib/Target/CBackend/Writer.cpp diff -u llvm/lib/Target/CBackend/Writer.cpp:1.174 llvm/lib/Target/CBackend/Writer.cpp:1.175 --- llvm/lib/Target/CBackend/Writer.cpp:1.174 Sun May 9 15:41:32 2004 +++ llvm/lib/Target/CBackend/Writer.cpp Thu May 20 15:25:50 2004 @@ -126,6 +126,10 @@ // printed and an extra copy of the expr is not emitted. // static bool isInlinableInst(const Instruction &I) { + // Always inline setcc instructions, even if they are shared by multiple + // expressions. GCC generates horrible code if we don't. + if (isa(I)) return true; + // Must be an expression, must be used exactly once. If it is dead, we // emit it inline where it would go. if (I.getType() == Type::VoidTy || !I.hasOneUse() || From gaeke at cs.uiuc.edu Thu May 20 15:39:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Thu May 20 15:39:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405202038.PAA20868@zion.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.51 -> 1.52 --- Log message: Make cloneMapDump() into a method that is easier to call from the debugger. Don't call it by default, because it takes a long time on big modules. --- Diffs of the changes: (+12 -11) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.51 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.52 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.51 Thu May 20 15:04:27 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Thu May 20 15:38:04 2004 @@ -66,6 +66,8 @@ void fixupFunctionBodyBB (Trace &T, Function *F, BasicBlock *srcB, BasicBlock *dstB, ValueMap &O2CMap, LiveVariableSet &So); + + void cloneMapDump (); public: TraceFunctionBuilder () { } virtual ~TraceFunctionBuilder () { } @@ -668,20 +670,21 @@ } /// Dump out the O2CMap for the given TraceFunction to stderr. -/// Only called when debugging. +/// You can call this from the debugger if you want to see the gory details, +/// because it takes a really long time on big modules. /// -static void cloneMapDump (TraceFunction *TF, std::ostream &OS) { - OS << "\n; TraceFunctionBuilder Original-->Clone map follows:\n"; +void TraceFunctionBuilder::cloneMapDump () { + std::cerr << "\n; TraceFunctionBuilder Original-->Clone map follows:\n"; for (ValueMap::const_iterator i = TF->O2CMap.begin(), e = TF->O2CMap.end(); i != e; ++i) { const std::pair &elem = *i; - OS << "(original-value \""; - WriteAsOperand (OS, i->first, true, true, TF->MatrixFn->getParent ()); - OS << "\" maps-to \""; - WriteAsOperand (OS, i->second, true, true, TF->TraceFn->getParent ()); - OS << "\")\n"; + std::cerr << "(original-value \""; + WriteAsOperand (std::cerr, i->first, true, true, TF->MatrixFn->getParent ()); + std::cerr << "\" maps-to \""; + WriteAsOperand (std::cerr, i->second, true, true, TF->TraceFn->getParent ()); + std::cerr << "\")\n"; } - OS << "\n"; + std::cerr << "\n"; } TraceFunction *TraceFunctionBuilder::buildTraceFunction (Trace &T) { @@ -709,8 +712,6 @@ T.getModule ()); DEBUG(giveNamesToFunctionArgs (TF->LiveInSet, TF->TraceFn)); fillInFunctionBody (T, TF->TraceFn, TF->LiveOutSet); - - DEBUG(cloneMapDump(TF, std::cerr)); return TF; } From alkis at cs.uiuc.edu Thu May 20 16:20:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 16:20:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405202119.QAA32651@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.3 -> 1.4 --- Log message: Pull commonly used typedefs out of the ClassFile class. --- Diffs of the changes: (+25 -41) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.3 llvm-java/lib/ClassFile/ClassFile.cpp:1.4 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.3 Sat Apr 17 02:52:15 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Thu May 20 16:19:06 2004 @@ -60,7 +60,7 @@ return tmp.out; } - void readConstantPool(ClassFile::ConstantPool& cp, std::istream& is) + void readConstantPool(ConstantPool& cp, std::istream& is) { assert(cp.empty() && "Should not call with a non-empty constant pool"); uint16_t count = readU2(is); @@ -71,9 +71,7 @@ cp.push_back(Constant::readConstant(cp, is)); } - void readInterfaces(ClassFile::Interfaces& i, - const ClassFile::ConstantPool& cp, - std::istream& is) + void readInterfaces(Classes& i, const ConstantPool& cp, std::istream& is) { assert(i.empty() && "Should not call with a non-empty interfaces vector"); @@ -86,9 +84,7 @@ } } - void readFields(ClassFile::Fields& f, - const ClassFile::ConstantPool& cp, - std::istream& is) + void readFields(Fields& f, const ConstantPool& cp, std::istream& is) { assert(f.empty() && "Should not call with a non-empty fields vector"); uint16_t count = readU2(is); @@ -97,9 +93,7 @@ f.push_back(Field::readField(cp, is)); } - void readMethods(ClassFile::Methods& m, - const ClassFile::ConstantPool& cp, - std::istream& is) + void readMethods(Methods& m, const ConstantPool& cp, std::istream& is) { assert(m.empty() && "Should not call with a non-empty methods vector"); uint16_t count = readU2(is); @@ -108,8 +102,8 @@ m.push_back(Method::readMethod(cp, is)); } - void readAttributes(ClassFile::Attributes& a, - const ClassFile::ConstantPool& cp, + void readAttributes(Attributes& a, + const ConstantPool& cp, std::istream& is) { assert(a.empty() && @@ -212,7 +206,7 @@ //===----------------------------------------------------------------------===// // Constant implementation -Constant* Constant::readConstant(const ClassFile::ConstantPool& cp, +Constant* Constant::readConstant(const ConstantPool& cp, std::istream& is) { Constant::Tag tag = static_cast(readU1(is)); @@ -251,8 +245,7 @@ } -ConstantMemberRef::ConstantMemberRef(const ClassFile::ConstantPool&cp, - std::istream& is) +ConstantMemberRef::ConstantMemberRef(const ConstantPool&cp, std::istream& is) : Constant(cp), classIdx_(readU2(is)), nameAndTypeIdx_(readU2(is)) @@ -265,8 +258,7 @@ return os << *getNameAndType() << '(' << *getClass() << ')'; } -ConstantClass::ConstantClass(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantClass::ConstantClass(const ConstantPool& cp, std::istream& is) : Constant(cp), nameIdx_(readU2(is)) { @@ -278,8 +270,7 @@ return os << *getName(); } -ConstantString::ConstantString(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantString::ConstantString(const ConstantPool& cp, std::istream& is) : Constant(cp), stringIdx_(readU2(is)) { @@ -291,8 +282,7 @@ return os << "string " << *getValue(); } -ConstantInteger::ConstantInteger(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantInteger::ConstantInteger(const ConstantPool& cp, std::istream& is) : Constant(cp), value_(static_cast(readU4(is))) { @@ -304,8 +294,7 @@ return os << value_; } -ConstantFloat::ConstantFloat(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantFloat::ConstantFloat(const ConstantPool& cp, std::istream& is) : Constant(cp), value_(int2float(readU4(is))) { @@ -317,8 +306,7 @@ return os << value_; } -ConstantLong::ConstantLong(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantLong::ConstantLong(const ConstantPool& cp, std::istream& is) : Constant(cp), value_(static_cast(readU8(is))) { @@ -330,8 +318,7 @@ return os << value_; } -ConstantDouble::ConstantDouble(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantDouble::ConstantDouble(const ConstantPool& cp, std::istream& is) : Constant(cp), value_(long2double(readU8(is))) { @@ -343,7 +330,7 @@ return os << value_; } -ConstantNameAndType::ConstantNameAndType(const ClassFile::ConstantPool& cp, +ConstantNameAndType::ConstantNameAndType(const ConstantPool& cp, std::istream& is) : Constant(cp), nameIdx_(readU2(is)), @@ -357,8 +344,7 @@ return os << *getDescriptor() << ' ' << *getName(); } -ConstantUtf8::ConstantUtf8(const ClassFile::ConstantPool& cp, - std::istream& is) +ConstantUtf8::ConstantUtf8(const ConstantPool& cp, std::istream& is) : Constant(cp) { uint16_t length = readU2(is); @@ -377,7 +363,7 @@ //===----------------------------------------------------------------------===// // Field implementation -Field::Field(const ClassFile::ConstantPool& cp, std::istream& is) +Field::Field(const ConstantPool& cp, std::istream& is) { accessFlags_ = readU2(is); if (!name_) @@ -414,7 +400,7 @@ //===----------------------------------------------------------------------===// // Method implementation -Method::Method(const ClassFile::ConstantPool& cp, std::istream& is) +Method::Method(const ConstantPool& cp, std::istream& is) { accessFlags_ = readU2(is); name_ = dynamic_cast(cp[readU2(is)]); @@ -453,8 +439,7 @@ //===----------------------------------------------------------------------===// // Attribute implementation -Attribute* Attribute::readAttribute(const ClassFile::ConstantPool& cp, - std::istream& is) +Attribute* Attribute::readAttribute(const ConstantPool& cp, std::istream& is) { ConstantUtf8* name = dynamic_cast(cp[readU2(is)]); if (!name) @@ -473,7 +458,7 @@ } Attribute::Attribute(ConstantUtf8* name, - const ClassFile::ConstantPool& cp, + const ConstantPool& cp, std::istream& is) : name_(name) { @@ -492,10 +477,9 @@ //===----------------------------------------------------------------------===// // AttributeConstantValue implementation -AttributeConstantValue::AttributeConstantValue( - ConstantUtf8* name, - const ClassFile::ConstantPool& cp, - std::istream& is) +AttributeConstantValue::AttributeConstantValue(ConstantUtf8* name, + const ConstantPool& cp, + std::istream& is) : Attribute(name, cp, is) { uint32_t length = readU4(is); @@ -513,7 +497,7 @@ //===----------------------------------------------------------------------===// // Attribute code AttributeCode::AttributeCode(ConstantUtf8* name, - const ClassFile::ConstantPool& cp, + const ConstantPool& cp, std::istream& is) : Attribute(name, cp, is) { @@ -553,7 +537,7 @@ return os; } -AttributeCode::Exception::Exception(const ClassFile::ConstantPool& cp, +AttributeCode::Exception::Exception(const ConstantPool& cp, std::istream& is) { startPc_ = readU2(is); From alkis at cs.uiuc.edu Thu May 20 16:20:07 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 16:20:07 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405202119.QAA32658@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.4 -> 1.5 --- Log message: Pull commonly used typedefs out of the ClassFile class. --- Diffs of the changes: (+38 -48) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.4 llvm-java/include/llvm/Java/ClassFile.h:1.5 --- llvm-java/include/llvm/Java/ClassFile.h:1.4 Sat Apr 17 02:52:16 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Thu May 20 16:19:06 2004 @@ -46,14 +46,13 @@ ACC_STRICT = 0x0800, }; - class ClassFile { - public: - typedef std::vector ConstantPool; - typedef std::vector Interfaces; - typedef std::vector Fields; - typedef std::vector Methods; - typedef std::vector Attributes; + typedef std::vector ConstantPool; + typedef std::vector Classes; + typedef std::vector Fields; + typedef std::vector Methods; + typedef std::vector Attributes; + class ClassFile { public: static ClassFile* readClassFile(std::istream& is); @@ -73,7 +72,7 @@ const ConstantClass* getThisClass() const { return thisClass_; } const ConstantClass* getSuperClass() const { return superClass_; } - const Interfaces& getInterfaces() const { return interfaces_; } + const Classes& getInterfaces() const { return interfaces_; } const Fields& getFields() const { return fields_; } @@ -90,7 +89,7 @@ uint16_t accessFlags_; ConstantClass* thisClass_; ConstantClass* superClass_; - Interfaces interfaces_; + Classes interfaces_; Fields fields_; Methods methods_; Attributes attributes_; @@ -104,9 +103,9 @@ class Constant { protected: - const ClassFile::ConstantPool& cPool_; + const ConstantPool& cPool_; - Constant(const ClassFile::ConstantPool& cp) + Constant(const ConstantPool& cp) : cPool_(cp) { } public: @@ -124,7 +123,7 @@ UTF8 = 1 }; - static Constant* readConstant(const ClassFile::ConstantPool& cp, + static Constant* readConstant(const ConstantPool& cp, std::istream& is); virtual ~Constant(); @@ -139,7 +138,7 @@ class ConstantClass : public Constant { uint16_t nameIdx_; public: - ConstantClass(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantClass(const ConstantPool& cp, std::istream& is); const ConstantUtf8* getName() const { return (const ConstantUtf8*) cPool_[nameIdx_]; } @@ -150,7 +149,7 @@ uint16_t classIdx_; uint16_t nameAndTypeIdx_; protected: - ConstantMemberRef(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantMemberRef(const ConstantPool& cp, std::istream& is); public: const ConstantClass* getClass() const { @@ -163,25 +162,24 @@ }; struct ConstantFieldRef : public ConstantMemberRef { - ConstantFieldRef(const ClassFile::ConstantPool& cp, std::istream& is) + ConstantFieldRef(const ConstantPool& cp, std::istream& is) : ConstantMemberRef(cp, is) { } }; struct ConstantMethodRef : public ConstantMemberRef { - ConstantMethodRef(const ClassFile::ConstantPool& cp, std::istream& is) + ConstantMethodRef(const ConstantPool& cp, std::istream& is) : ConstantMemberRef(cp, is) { } }; struct ConstantInterfaceMethodRef : public ConstantMemberRef { - ConstantInterfaceMethodRef(const ClassFile::ConstantPool& cp, - std::istream& is) + ConstantInterfaceMethodRef(const ConstantPool& cp, std::istream& is) : ConstantMemberRef(cp, is) { } }; class ConstantString : public Constant { uint16_t stringIdx_; public: - ConstantString(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantString(const ConstantPool& cp, std::istream& is); const ConstantUtf8* getValue() const { return (const ConstantUtf8*) cPool_[stringIdx_]; } @@ -191,7 +189,7 @@ class ConstantInteger : public Constant { int32_t value_; public: - ConstantInteger(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantInteger(const ConstantPool& cp, std::istream& is); int32_t getValue() const { return value_; } std::ostream& dump(std::ostream& os) const; }; @@ -199,7 +197,7 @@ class ConstantFloat : public Constant { float value_; public: - ConstantFloat(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantFloat(const ConstantPool& cp, std::istream& is); float getValue() const { return value_; } std::ostream& dump(std::ostream& os) const; }; @@ -207,7 +205,7 @@ class ConstantLong : public Constant { int64_t value_; public: - ConstantLong(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantLong(const ConstantPool& cp, std::istream& is); int64_t getValue() const { return value_; } std::ostream& dump(std::ostream& os) const; }; @@ -215,7 +213,7 @@ class ConstantDouble : public Constant { double value_; public: - ConstantDouble(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantDouble(const ConstantPool& cp, std::istream& is); double getValue() const { return value_; } std::ostream& dump(std::ostream& os) const; }; @@ -224,7 +222,7 @@ uint16_t nameIdx_; uint16_t descriptorIdx_; public: - ConstantNameAndType(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantNameAndType(const ConstantPool& cp, std::istream& is); const ConstantUtf8* getName() const { return (const ConstantUtf8*) cPool_[nameIdx_]; } @@ -237,7 +235,7 @@ class ConstantUtf8 : public Constant { std::string utf8_; public: - ConstantUtf8(const ClassFile::ConstantPool& cp, std::istream& is); + ConstantUtf8(const ConstantPool& cp, std::istream& is); operator const char* const() const { return utf8_.c_str(); } operator const std::string&() const { return utf8_; } @@ -249,13 +247,12 @@ uint16_t accessFlags_; ConstantUtf8* name_; ConstantUtf8* descriptor_; - ClassFile::Attributes attributes_; + Attributes attributes_; - Field(const ClassFile::ConstantPool& cp, std::istream& is); + Field(const ConstantPool& cp, std::istream& is); public: - static Field* readField(const ClassFile::ConstantPool& cp, - std::istream& is) { + static Field* readField(const ConstantPool& cp, std::istream& is) { return new Field(cp, is); } @@ -271,9 +268,7 @@ ConstantUtf8* getName() const { return name_; } ConstantUtf8* getDescriptor() const { return descriptor_; } - const ClassFile::Attributes& getAttributes() const { - return attributes_; - } + const Attributes& getAttributes() const { return attributes_; } std::ostream& dump(std::ostream& os) const; }; @@ -286,13 +281,12 @@ uint16_t accessFlags_; ConstantUtf8* name_; ConstantUtf8* descriptor_; - ClassFile::Attributes attributes_; + Attributes attributes_; - Method(const ClassFile::ConstantPool& cp, std::istream& is); + Method(const ConstantPool& cp, std::istream& is); public: - static Method* readMethod(const ClassFile::ConstantPool& cp, - std::istream& is) { + static Method* readMethod(const ConstantPool& cp, std::istream& is) { return new Method(cp, is); } @@ -310,9 +304,7 @@ ConstantUtf8* getName() const { return name_; } ConstantUtf8* getDescriptor() const { return descriptor_; } - const ClassFile::Attributes& getAttributes() const { - return attributes_; - } + const Attributes& getAttributes() const { return attributes_; } std::ostream& dump(std::ostream& os) const; }; @@ -326,11 +318,11 @@ protected: Attribute(ConstantUtf8* name, - const ClassFile::ConstantPool& cp, + const ConstantPool& cp, std::istream& is); public: - static Attribute* readAttribute(const ClassFile::ConstantPool& cp, + static Attribute* readAttribute(const ConstantPool& cp, std::istream& is); virtual ~Attribute(); @@ -348,7 +340,7 @@ Constant* value_; public: AttributeConstantValue(ConstantUtf8* name, - const ClassFile::ConstantPool& cp, + const ConstantPool& cp, std::istream& is); Constant* getValue() const { return value_; } @@ -365,7 +357,7 @@ ConstantClass* catchType_; public: - Exception(const ClassFile::ConstantPool& cp, std::istream& is); + Exception(const ConstantPool& cp, std::istream& is); uint16_t getStartPc() const { return startPc_; } uint16_t getEndPc() const { return endPc_; } @@ -383,11 +375,11 @@ uint32_t codeSize_; char* code_; Exceptions exceptions_; - ClassFile::Attributes attributes_; + Attributes attributes_; public: AttributeCode(ConstantUtf8* name, - const ClassFile::ConstantPool& cp, + const ConstantPool& cp, std::istream& is); ~AttributeCode(); uint16_t getMaxStack() const { return maxStack_; } @@ -395,9 +387,7 @@ const char* getCode() const { return code_; } uint32_t getCodeSize() const { return codeSize_; } const Exceptions& getExceptions() const { return exceptions_; } - const ClassFile::Attributes& getAttributes() const { - return attributes_; - } + const Attributes& getAttributes() const { return attributes_; } std::ostream& dump(std::ostream& os) const; From alkis at cs.uiuc.edu Thu May 20 16:33:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 16:33:01 2004 Subject: [llvm-commits] CVS: llvm/Makefile.rules Message-ID: <200405202131.QAA00391@zion.cs.uiuc.edu> Changes in directory llvm: Makefile.rules updated: 1.181 -> 1.182 --- Log message: Change DEPRECATED macro to ATTR_DEPRECATED as this conflicts with some java constants. --- Diffs of the changes: (+1 -1) Index: llvm/Makefile.rules diff -u llvm/Makefile.rules:1.181 llvm/Makefile.rules:1.182 --- llvm/Makefile.rules:1.181 Fri Apr 23 19:10:56 2004 +++ llvm/Makefile.rules Thu May 20 16:31:43 2004 @@ -294,7 +294,7 @@ CPPFLAGS += -D__STDC_LIMIT_MACROS ### FIXME: this is GCC specific -CPPFLAGS += -DDEPRECATED='__attribute__ ((deprecated))' +CPPFLAGS += -DATTR_DEPRECATED='__attribute__ ((deprecated))' CompileCommonOpts := -Wall -W -Wwrite-strings -Wno-unused CompileOptimizeOpts := -O3 -DNDEBUG -finline-functions From alkis at cs.uiuc.edu Thu May 20 17:22:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 17:22:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405202220.RAA00704@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.4 -> 1.5 --- Log message: Remove implicit conversions for ConstantUtf8. Add attribute strings for known attributes. --- Diffs of the changes: (+12 -2) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.4 llvm-java/lib/ClassFile/ClassFile.cpp:1.5 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.4 Thu May 20 16:19:06 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Thu May 20 17:20:15 2004 @@ -439,6 +439,16 @@ //===----------------------------------------------------------------------===// // Attribute implementation +const std::string Attribute::CONSTANT_VALUE = "ConstantValue"; +const std::string Attribute::CODE = "Code"; +const std::string Attribute::EXCEPTIONS = "Exceptions"; +const std::string Attribute::INNER_CLASSES = "InnerClasses"; +const std::string Attribute::SYNTHETIC = "Synthetic"; +const std::string Attribute::SOURCE_FILE = "SourceFile"; +const std::string Attribute::LINE_NUMBER_TABLE = "LineNumberTable"; +const std::string Attribute::LOCAL_VARIABLE_TABLE = "LocalVariableTable"; +const std::string Attribute::DEPRECATED = "Deprecated"; + Attribute* Attribute::readAttribute(const ConstantPool& cp, std::istream& is) { ConstantUtf8* name = dynamic_cast(cp[readU2(is)]); @@ -446,9 +456,9 @@ throw ClassFileSemanticError( "Representation of attribute name is not of type ConstantUtf8"); - if (strcmp(*name, "ConstantValue") == 0) + if (CONSTANT_VALUE == name->str()) return new AttributeConstantValue(name, cp, is); - else if (strcmp(*name, "Code") == 0) + else if (CODE == name->str()) return new AttributeCode(name, cp, is); else { uint32_t length = readU4(is); From alkis at cs.uiuc.edu Thu May 20 17:22:07 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 17:22:07 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405202220.RAA00711@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.5 -> 1.6 --- Log message: Remove implicit conversions for ConstantUtf8. Add attribute strings for known attributes. --- Diffs of the changes: (+11 -2) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.5 llvm-java/include/llvm/Java/ClassFile.h:1.6 --- llvm-java/include/llvm/Java/ClassFile.h:1.5 Thu May 20 16:19:06 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Thu May 20 17:20:15 2004 @@ -236,8 +236,7 @@ std::string utf8_; public: ConstantUtf8(const ConstantPool& cp, std::istream& is); - operator const char* const() const { return utf8_.c_str(); } - operator const std::string&() const { return utf8_; } + const std::string& str() const { return utf8_; } std::ostream& dump(std::ostream& os) const; }; @@ -330,6 +329,16 @@ ConstantUtf8* getName() const { return name_; } virtual std::ostream& dump(std::ostream& os) const; + + static const std::string CONSTANT_VALUE; + static const std::string CODE; + static const std::string EXCEPTIONS; + static const std::string INNER_CLASSES; + static const std::string SYNTHETIC; + static const std::string SOURCE_FILE; + static const std::string LINE_NUMBER_TABLE; + static const std::string LOCAL_VARIABLE_TABLE; + static const std::string DEPRECATED; }; inline std::ostream& operator<<(std::ostream& os, const Attribute& a) { From alkis at cs.uiuc.edu Thu May 20 17:44:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 17:44:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405202242.RAA00857@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.5 -> 1.6 --- Log message: Implement Exceptions attribute. --- Diffs of the changes: (+25 -5) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.5 llvm-java/lib/ClassFile/ClassFile.cpp:1.6 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.5 Thu May 20 17:20:15 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Thu May 20 17:42:15 2004 @@ -71,15 +71,16 @@ cp.push_back(Constant::readConstant(cp, is)); } - void readInterfaces(Classes& i, const ConstantPool& cp, std::istream& is) + void readClasses(Classes& i, const ConstantPool& cp, std::istream& is) { assert(i.empty() && - "Should not call with a non-empty interfaces vector"); + "Should not call with a non-empty classes vector"); uint16_t count = readU2(is); i.reserve(count); while (count--) { ConstantClass* c = dynamic_cast(cp[readU2(is)]); - if (!c) throw "FIXME: give better error message"; + if (!c) + throw ClassFileSemanticError("ConstantClass expected"); i.push_back(c); } } @@ -156,7 +157,7 @@ if (!superClass_) throw ClassFileSemanticError( "Representation of super class is not of type ConstantClass"); - readInterfaces(interfaces_, cPool_, is); + readClasses(interfaces_, cPool_, is); readFields(fields_, cPool_, is); readMethods(methods_, cPool_, is); readAttributes(attributes_, cPool_, is); @@ -505,7 +506,7 @@ } //===----------------------------------------------------------------------===// -// Attribute code +// AttributeCode implementation AttributeCode::AttributeCode(ConstantUtf8* name, const ConstantPool& cp, std::istream& is) @@ -565,4 +566,23 @@ << "Start PC: " << startPc_ << '\n' << "End PC: " << endPc_ << '\n' << "Handler PC: " << handlerPc_; +} + +//===----------------------------------------------------------------------===// +// AttributeExceptions implementation +AttributeExceptions::AttributeExceptions(ConstantUtf8* name, + const ConstantPool& cp, + std::istream& is) + : Attribute(name, cp, is) +{ + uint32_t length = readU4(is); + readClasses(exceptions_, cp, is); +} + +std::ostream& AttributeExceptions::dump(std::ostream& is) const +{ + for (Classes::const_iterator + i = exceptions_.begin(), e = exceptions_.end(); i != e; ++i) + is << *i << ' '; + return is; } From alkis at cs.uiuc.edu Thu May 20 17:44:07 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 17:44:07 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405202242.RAA00865@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.6 -> 1.7 --- Log message: Implement Exceptions attribute. --- Diffs of the changes: (+15 -1) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.6 llvm-java/include/llvm/Java/ClassFile.h:1.7 --- llvm-java/include/llvm/Java/ClassFile.h:1.6 Thu May 20 17:20:15 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Thu May 20 17:42:15 2004 @@ -399,13 +399,27 @@ const Attributes& getAttributes() const { return attributes_; } std::ostream& dump(std::ostream& os) const; - }; inline std::ostream& operator<<(std::ostream& os, const AttributeCode::Exception& e) { return e.dump(os); } + + class AttributeExceptions : public Attribute { + private: + ConstantUtf8* name_; + Classes exceptions_; + + public: + AttributeExceptions(ConstantUtf8* name, + const ConstantPool& cp, + std::istream& is); + + const Classes& getExceptions() const { return exceptions_; } + + std::ostream& dump(std::ostream& os) const; + }; class ClassFileParseError : public std::exception { std::string msg_; From alkis at cs.uiuc.edu Thu May 20 18:52:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 18:52:02 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405202350.SAA17983@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.7 -> 1.8 --- Log message: Rename subclasses of Attribute from AttributeSomething to SomethingAttribute. --- Diffs of the changes: (+8 -8) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.7 llvm-java/include/llvm/Java/ClassFile.h:1.8 --- llvm-java/include/llvm/Java/ClassFile.h:1.7 Thu May 20 17:42:15 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Thu May 20 18:50:30 2004 @@ -345,10 +345,10 @@ return a.dump(os); } - class AttributeConstantValue : public Attribute { + class ConstantValueAttribute : public Attribute { Constant* value_; public: - AttributeConstantValue(ConstantUtf8* name, + ConstantValueAttribute(ConstantUtf8* name, const ConstantPool& cp, std::istream& is); @@ -357,7 +357,7 @@ std::ostream& dump(std::ostream& os) const; }; - class AttributeCode : public Attribute { + class CodeAttribute : public Attribute { public: class Exception { uint16_t startPc_; @@ -387,10 +387,10 @@ Attributes attributes_; public: - AttributeCode(ConstantUtf8* name, + CodeAttribute(ConstantUtf8* name, const ConstantPool& cp, std::istream& is); - ~AttributeCode(); + ~CodeAttribute(); uint16_t getMaxStack() const { return maxStack_; } uint16_t getMaxLocals() const { return maxLocals_; } const char* getCode() const { return code_; } @@ -402,17 +402,17 @@ }; inline std::ostream& operator<<(std::ostream& os, - const AttributeCode::Exception& e) { + const CodeAttribute::Exception& e) { return e.dump(os); } - class AttributeExceptions : public Attribute { + class ExceptionsAttribute : public Attribute { private: ConstantUtf8* name_; Classes exceptions_; public: - AttributeExceptions(ConstantUtf8* name, + ExceptionsAttribute(ConstantUtf8* name, const ConstantPool& cp, std::istream& is); From alkis at cs.uiuc.edu Thu May 20 18:52:06 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 18:52:06 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405202350.SAA17978@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.6 -> 1.7 --- Log message: Rename subclasses of Attribute from AttributeSomething to SomethingAttribute. --- Diffs of the changes: (+15 -14) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.6 llvm-java/lib/ClassFile/ClassFile.cpp:1.7 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.6 Thu May 20 17:42:15 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Thu May 20 18:50:30 2004 @@ -458,9 +458,9 @@ "Representation of attribute name is not of type ConstantUtf8"); if (CONSTANT_VALUE == name->str()) - return new AttributeConstantValue(name, cp, is); + return new ConstantValueAttribute(name, cp, is); else if (CODE == name->str()) - return new AttributeCode(name, cp, is); + return new CodeAttribute(name, cp, is); else { uint32_t length = readU4(is); is.ignore(length); @@ -488,7 +488,7 @@ //===----------------------------------------------------------------------===// // AttributeConstantValue implementation -AttributeConstantValue::AttributeConstantValue(ConstantUtf8* name, +ConstantValueAttribute::ConstantValueAttribute(ConstantUtf8* name, const ConstantPool& cp, std::istream& is) : Attribute(name, cp, is) @@ -496,18 +496,18 @@ uint32_t length = readU4(is); if (length != 2) throw ClassFileSemanticError( - "Length of AttributeConstantValue is not 2"); + "Length of ConstantValueAttribute is not 2"); value_ = cp[readU2(is)]; } -std::ostream& AttributeConstantValue::dump(std::ostream& os) const +std::ostream& ConstantValueAttribute::dump(std::ostream& os) const { return Attribute::dump(os) << ": " << *value_; } //===----------------------------------------------------------------------===// // AttributeCode implementation -AttributeCode::AttributeCode(ConstantUtf8* name, +CodeAttribute::CodeAttribute(ConstantUtf8* name, const ConstantPool& cp, std::istream& is) : Attribute(name, cp, is) @@ -528,14 +528,14 @@ readAttributes(attributes_, cp, is); } -AttributeCode::~AttributeCode() +CodeAttribute::~CodeAttribute() { delete[] code_; for_each(exceptions_.begin(), exceptions_.end(), deleter); for_each(attributes_.begin(), attributes_.end(), deleter); } -std::ostream& AttributeCode::dump(std::ostream& os) const +std::ostream& CodeAttribute::dump(std::ostream& os) const { Attribute::dump(os) << '\n' @@ -548,7 +548,7 @@ return os; } -AttributeCode::Exception::Exception(const ConstantPool& cp, +CodeAttribute::Exception::Exception(const ConstantPool& cp, std::istream& is) { startPc_ = readU2(is); @@ -560,7 +560,7 @@ "Representation of catch type is not of type ConstantClass"); } -std::ostream& AttributeCode::Exception::dump(std::ostream& os) const +std::ostream& CodeAttribute::Exception::dump(std::ostream& os) const { return os << *getCatchType() << '\n' << "Start PC: " << startPc_ << '\n' @@ -570,7 +570,7 @@ //===----------------------------------------------------------------------===// // AttributeExceptions implementation -AttributeExceptions::AttributeExceptions(ConstantUtf8* name, +ExceptionsAttribute::ExceptionsAttribute(ConstantUtf8* name, const ConstantPool& cp, std::istream& is) : Attribute(name, cp, is) @@ -579,10 +579,11 @@ readClasses(exceptions_, cp, is); } -std::ostream& AttributeExceptions::dump(std::ostream& is) const +std::ostream& ExceptionsAttribute::dump(std::ostream& os) const { + os << Attribute::dump(os) << ": "; for (Classes::const_iterator i = exceptions_.begin(), e = exceptions_.end(); i != e; ++i) - is << *i << ' '; - return is; + os << *i << ' '; + return os; } From alkis at cs.uiuc.edu Thu May 20 19:07:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 19:07:03 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405210006.TAA25554@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.8 -> 1.9 --- Log message: Add utility functions to easily access attributes. --- Diffs of the changes: (+5 -0) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.8 llvm-java/include/llvm/Java/ClassFile.h:1.9 --- llvm-java/include/llvm/Java/ClassFile.h:1.8 Thu May 20 18:50:30 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Thu May 20 19:05:59 2004 @@ -22,6 +22,7 @@ // Forward declarations class Attribute; + class CodeAttribute; class Constant; class ConstantClass; class ConstantNameAndType; @@ -51,6 +52,10 @@ typedef std::vector Fields; typedef std::vector Methods; typedef std::vector Attributes; + + const Attribute* getAttribute(const Attributes& attrs, + const std::string& name); + const CodeAttribute* getCodeAttribute(const Attributes& attrs); class ClassFile { public: From alkis at cs.uiuc.edu Thu May 20 19:07:08 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Thu May 20 19:07:08 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405210006.TAA25549@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.7 -> 1.8 --- Log message: Add utility functions to easily access attributes. --- Diffs of the changes: (+22 -1) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.7 llvm-java/lib/ClassFile/ClassFile.cpp:1.8 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.7 Thu May 20 18:50:30 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Thu May 20 19:05:59 2004 @@ -23,7 +23,7 @@ using namespace llvm::Java; //===----------------------------------------------------------------------===// -// Utility functions +// Internal utility functions namespace { uint8_t readU1(std::istream& is) { @@ -189,6 +189,27 @@ dumpCollection(attributes_, "Attribute", os); return os; +} + +//===----------------------------------------------------------------------===// +// Utility functions +const Attribute* llvm::Java::getAttribute(const Attributes& attrs, + const std::string& name) +{ + for (Attributes::const_iterator + i = attrs.begin(), e = attrs.end(); i != e; ++i) { + const Attribute* attr = *i; + if (attr->getName()->str() == name) + return attr; + } + + return NULL; +} + +const CodeAttribute* llvm::Java::getCodeAttribute(const Attributes& attrs) +{ + return static_cast( + getAttribute(attrs, Attribute::CODE)); } //===----------------------------------------------------------------------===// From brukman at cs.uiuc.edu Thu May 20 19:11:01 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Thu May 20 19:11:01 2004 Subject: [llvm-commits] CVS: llvm/Makefile.rules Message-ID: <200405210009.TAA25630@zion.cs.uiuc.edu> Changes in directory llvm: Makefile.rules updated: 1.182 -> 1.183 --- Log message: Pass given flags on to recursive sub-makes. --- Diffs of the changes: (+1 -1) Index: llvm/Makefile.rules diff -u llvm/Makefile.rules:1.182 llvm/Makefile.rules:1.183 --- llvm/Makefile.rules:1.182 Thu May 20 16:31:43 2004 +++ llvm/Makefile.rules Thu May 20 19:09:21 2004 @@ -402,7 +402,7 @@ $(MKDIR) $$dir; \ cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \ fi; \ - ($(MAKE) -C $$dir $@) || exit 1; \ + ($(MAKE) -C $$dir $@ $(MFLAGS)) || exit 1; \ done endif From gaeke at cs.uiuc.edu Fri May 21 02:46:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 21 02:46:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405210745.CAA14218@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.52 -> 1.53 --- Log message: Simplify isFirstTriggerCall(); eliminate debug message. --- Diffs of the changes: (+2 -6) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.52 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.53 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.52 Thu May 20 15:38:04 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Fri May 21 02:45:05 2004 @@ -308,12 +308,8 @@ if (CallInst *CI = dyn_cast (&I)) { Function *CF = CI->getCalledFunction (); // Look for an external function call with no args to "llvm_first_trigger". - if (CF && CF->isExternal () && CF->hasName() - && CF->getName () == "llvm_first_trigger" && CF->asize () == 0) { - DEBUG(std::cerr << " (Found a call instruction " << *CI - << " ... Smells like llvm_first_trigger.)\n"); - return true; - } + return (CF && CF->isExternal () && CF->hasName() + && CF->getName () == "llvm_first_trigger" && CF->asize () == 0); } return false; } From gaeke at cs.uiuc.edu Fri May 21 02:59:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 21 02:59:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405210758.CAA14281@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.63 -> 1.64 --- Log message: Don't worry about saving or restoring %g0. Don't print out a line of spam for every piece of register allocator state we scan through. --- Diffs of the changes: (+2 -3) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.63 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.64 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.63 Thu May 20 13:05:22 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Fri May 21 02:58:43 2004 @@ -212,8 +212,8 @@ } else if (TRI.getRegType(regNo) == SparcV9RegInfo::FloatCCRegType || TRI.getRegType(regNo) == SparcV9RegInfo::SpecialRegType) { floatCCRegSeen = true; - } else { - regsUsed.insert (MO.getReg ()); + } else if (regNo != SparcV9::g0) { // Ignore defs of the zero register + regsUsed.insert (regNo); } } } @@ -456,7 +456,6 @@ << " tuples to search.\n"); for (unsigned i = 0, s = FState.size (); i < s; ++i) { AllocInfo &T = FState[i]; - DEBUG(std::cerr << "Considering: " << T << "\n"); if (T.Instruction == InstructionKey && T.Operand == OperandKey) return T; } From gaeke at cs.uiuc.edu Fri May 21 05:06:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 21 05:06:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405211005.FAA14956@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.53 -> 1.54 --- Log message: Give fixupFunctionBodyBB much better debugging printouts (and make them less incredibly verbose). Untabify. --- Diffs of the changes: (+59 -50) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.53 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.54 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.53 Fri May 21 02:45:05 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Fri May 21 05:05:48 2004 @@ -455,8 +455,7 @@ DEBUG (std::cerr << "threadFLIEdges: threading incoming block " << i << " (FLI block " << It->first->getName () << " --> <[" << It->second.first->getName () << "], " - << It->second.second->getName () << ">) of PHI node: " - << *PN << "\n"); + << It->second.second->getName () << ">) of PHI node:\n" << *PN); PN->setIncomingBlock (i, It->second.first); } } @@ -475,8 +474,7 @@ DEBUG (std::cerr << "threadFLIEdges: threading successor " << i << " (FLI block " << It->first->getName () << " --> <" << It->second.first->getName () << ", [" - << It->second.second->getName () << "]>) of branch: " - << *BI << "\n"); + << It->second.second->getName () << "]>) of branch:\n" << *BI); BI->setSuccessor (i, It->second.second); } } @@ -572,61 +570,67 @@ // Fix up this exit branch. Value *V = O2CMap[BI]; assert(V && isa (V) - && "Trace-exiting branch's clone is null, or not a branch?"); + && "Trace-exiting branch's clone is null, or not a branch?"); BranchInst *BIinF = cast (V); for (unsigned i = 0; i < BI->getNumSuccessors (); ++i) { BasicBlock *successor = BI->getSuccessor (i); + BasicBlock *newSuccessor = 0; // Fold branches which go to FLI blocks if (BasicBlock *backEdgeTarget = getFLIEdgeTarget (successor)) { - DEBUG (std::cerr << "Branch instr " << *BI << " looks like an" - << " instrumented back-edge from " << srcB->getName() + DEBUG (std::cerr << "fixupFunctionBodyBB: Branch instruction:\n" << *BI + << " looks like an instrumented back-edge from " << srcB->getName() << " to " << backEdgeTarget->getName () << "\n"); successor = backEdgeTarget; } if (!T.contains (successor)) { - // This is a trace-exiting destination of branch BI. Create a new - // basic block FB for its destination in the function. - std::string name ("exitfixup" + utostr (BranchNumber[BI]) + "_" - + utostr (i)); - BasicBlock *FB = new BasicBlock (name, F); - // Change BI's clone's destination to FB. - BIinF->setSuccessor (i, FB); - // Remember that FB's "return" instruction would involve a - // return to the off-trace successor we just found. - TF->ReturnBlockForTraceExit[FB] = successor; - // Add the getelementptr/store instruction pairs here that - // correspond to each live-out variable. - unsigned Slot = 0; - for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); - SI != SE; ++SI) { - if (dominates (T, cast ((*SI))->getParent (), - BI->getParent ())) { - std::vector Index; - Index.push_back (Constant::getNullValue (Type::LongTy)); //long 0 - Index.push_back (ConstantUInt::get (Type::UIntTy, Slot));//uint Slot - GetElementPtrInst *GEP = - new GetElementPtrInst (getFunctionArg (F, 0), Index, - "liveOutP" + utostr (BranchNumber[BI]) - + "_" + utostr (i) + "_" + utostr (Slot)); - FB->getInstList ().push_back (GEP); - FB->getInstList ().push_back (new StoreInst (O2CMap[*SI], GEP)); - } - ++Slot; - } - // Make FB contain a return instruction that returns the - // number of the taken exit-branch. Add it to the end of FB: - FB->getInstList ().push_back - (new ReturnInst (ConstantUInt::get (Type::UIntTy, - BranchNumber[BI]))); + // This is a trace-exiting destination of branch BI. Create a new + // basic block FB for its destination in the function. + std::string name ("exitfixup" + utostr (BranchNumber[BI]) + "_" + + utostr (i)); + BasicBlock *FB = new BasicBlock (name, F); + // Remember to change BI's clone's destination to FB. + newSuccessor = FB; + // Remember that FB's "return" instruction would involve a + // return to the off-trace successor we just found. + TF->ReturnBlockForTraceExit[FB] = successor; + // Add the getelementptr/store instruction pairs here that + // correspond to each live-out variable. + unsigned Slot = 0; + for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); + SI != SE; ++SI) { + if (dominates (T, cast ((*SI))->getParent (), + BI->getParent ())) { + std::vector Index; + Index.push_back (Constant::getNullValue (Type::LongTy)); //long 0 + Index.push_back (ConstantUInt::get (Type::UIntTy, Slot));//uint Slot + GetElementPtrInst *GEP = + new GetElementPtrInst (getFunctionArg (F, 0), Index, + "liveOutP" + utostr (BranchNumber[BI]) + + "_" + utostr (i) + "_" + utostr (Slot)); + FB->getInstList ().push_back (GEP); + FB->getInstList ().push_back (new StoreInst (O2CMap[*SI], GEP)); + } + ++Slot; + } + // Make FB contain a return instruction that returns the + // number of the taken exit-branch. Add it to the end of FB: + FB->getInstList ().push_back + (new ReturnInst (ConstantUInt::get (Type::UIntTy, + BranchNumber[BI]))); } else { - // This is a non-trace-exiting destination of branch BI. Fix up - // its clone's destination to point to its successor's clone. - Value *V2 = O2CMap[successor]; - assert(V2 && isa (V2) - && "Clone of basic block on trace not found, or not a basic block"); - BIinF->setSuccessor (i, cast (V2)); - } + // This is a non-trace-exiting destination of branch BI. Fix up + // its clone's destination to point to its successor's clone. + Value *V2 = O2CMap[successor]; + assert(V2 && isa (V2) + && "Clone of BasicBlock on trace missing, or not a BasicBlock"); + newSuccessor = cast (V2); + } + DEBUG(std::cerr << "fixupFunctionBodyBB: Changing successor " << i + << " of trace-exiting branch instruction:\n" << *BIinF << " from " + << BIinF->getSuccessor(i)->getName () << " to " + << newSuccessor->getName () << "\n"); + BIinF->setSuccessor (i, newSuccessor); } } @@ -642,8 +646,13 @@ // outside the function. Replace any reference to an operand // which has had a clone made with a reference to its clone. if (O2CMap.find (V) != O2CMap.end () && O2CMap[V] && !isa (V)) { - DEBUG(std::cerr << *V << " in instruction " << I - << " is value " << O2CMap[V] << " in new function\n"); + DEBUG(std::cerr << "fixupFunctionBodyBB: Replacing "; + WriteAsOperand (std::cerr, V, true, true, + TF->TraceFn->getParent ()); + std::cerr << " in instruction:\n" << I << " with value "; + WriteAsOperand (std::cerr, O2CMap[V], true, true, + TF->TraceFn->getParent ()); + std::cerr << "\n"); assert (V->getType () == O2CMap[V]->getType () && "Value's type doesn't match clone's type"); I.setOperand(i, O2CMap[V]); From gaeke at cs.uiuc.edu Fri May 21 05:29:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 21 05:29:02 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405211028.FAA15437@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.54 -> 1.55 --- Log message: Minor cleanups in fillInFunctionBody(): Make 'function before fixups' debug message stand out more. Eliminate a dyn_cast. In fixupFunctionBodyBB(), reduce the number of times we look each operand up in O2CMap from 5 to 1, and don't look constants or global values up at all. --- Diffs of the changes: (+12 -10) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.54 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.55 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.54 Fri May 21 05:05:48 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Fri May 21 05:28:42 2004 @@ -388,8 +388,6 @@ /// void TraceFunctionBuilder::fillInFunctionBody (Trace &T, Function *F, LiveVariableSet &So) { - ValueMap &O2CMap = TF->O2CMap; - buildFLIMap (T, FLIMap); // First copy the basic blocks from the trace. @@ -399,15 +397,16 @@ numberExitBranchesInTrace (T, BranchNumber); - DEBUG (std::cerr << "\n FUNCTION BEFORE FIXUPS: \n" << *F << "\n\n"); + DEBUG (std::cerr << "\n ---- FUNCTION BEFORE FIXUPS: --- \n" << *F << "\n\n"); // Fix up the cloned basic blocks of the function so that they are // internally consistent. + ValueMap &O2CMap = TF->O2CMap; for (Trace::iterator TI = T.begin (), TE = T.end (); TI != TE; ++TI) { BasicBlock *srcB = *TI; - assert (O2CMap[srcB] && "Can't find clone of basic block I just cloned"); - BasicBlock *dstB = dyn_cast (O2CMap[srcB]); - assert (dstB && "Clone of basic block I just cloned is not a basic block"); + assert (O2CMap[srcB] && isa (O2CMap[srcB]) + && "Clone of trace BasicBlock is missing or not a BasicBlock"); + BasicBlock *dstB = cast (O2CMap[srcB]); fixupFunctionBodyBB (T, F, srcB, dstB, O2CMap, So); } for (Function::iterator FI = F->begin (), FE = F->end (); FI != FE; ++FI) @@ -645,17 +644,20 @@ // function, and I will still reference the version from // outside the function. Replace any reference to an operand // which has had a clone made with a reference to its clone. - if (O2CMap.find (V) != O2CMap.end () && O2CMap[V] && !isa (V)) { + if (isa (V) || isa (V)) continue; + ValueMap::iterator It = O2CMap.find (V); + if (It != O2CMap.end ()) { + Value *newV = It->second; DEBUG(std::cerr << "fixupFunctionBodyBB: Replacing "; WriteAsOperand (std::cerr, V, true, true, TF->TraceFn->getParent ()); std::cerr << " in instruction:\n" << I << " with value "; - WriteAsOperand (std::cerr, O2CMap[V], true, true, + WriteAsOperand (std::cerr, newV, true, true, TF->TraceFn->getParent ()); std::cerr << "\n"); - assert (V->getType () == O2CMap[V]->getType () + assert (V->getType () == newV->getType () && "Value's type doesn't match clone's type"); - I.setOperand(i, O2CMap[V]); + I.setOperand(i, newV); } } From lattner at cs.uiuc.edu Fri May 21 11:48:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 21 11:48:01 2004 Subject: [llvm-commits] CVS: llvm/test/Regression/Verifier/2004-05-21-SwitchConstantMismatch.ll Message-ID: <200405211647.LAA10878@zion.cs.uiuc.edu> Changes in directory llvm/test/Regression/Verifier: 2004-05-21-SwitchConstantMismatch.ll added (r1.1) --- Log message: Testcase for PR340: http://llvm.cs.uiuc.edu/PR340 : Verifier misses malformed switch instruction This testcase was reduced by John, thanks! --- Diffs of the changes: (+11 -0) Index: llvm/test/Regression/Verifier/2004-05-21-SwitchConstantMismatch.ll diff -c /dev/null llvm/test/Regression/Verifier/2004-05-21-SwitchConstantMismatch.ll:1.1 *** /dev/null Fri May 21 11:47:13 2004 --- llvm/test/Regression/Verifier/2004-05-21-SwitchConstantMismatch.ll Fri May 21 11:47:02 2004 *************** *** 0 **** --- 1,11 ---- + + + int %main() { + start1: + switch uint 0, label %brt0 [int 3, label %brt1 ] + brt0: + ret int 0 + brt1: + ret int 0 + } + From lattner at cs.uiuc.edu Fri May 21 11:49:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 21 11:49:01 2004 Subject: [llvm-commits] CVS: llvm/lib/VMCore/Verifier.cpp Message-ID: <200405211647.LAA10890@zion.cs.uiuc.edu> Changes in directory llvm/lib/VMCore: Verifier.cpp updated: 1.98 -> 1.99 --- Log message: Fix for PR340: http://llvm.cs.uiuc.edu/PR340 : Verifier misses malformed switch instruction --- Diffs of the changes: (+12 -0) Index: llvm/lib/VMCore/Verifier.cpp diff -u llvm/lib/VMCore/Verifier.cpp:1.98 llvm/lib/VMCore/Verifier.cpp:1.99 --- llvm/lib/VMCore/Verifier.cpp:1.98 Mon May 17 16:15:18 2004 +++ llvm/lib/VMCore/Verifier.cpp Fri May 21 11:47:21 2004 @@ -173,6 +173,7 @@ void visitInstruction(Instruction &I); void visitTerminatorInst(TerminatorInst &I); void visitReturnInst(ReturnInst &RI); + void visitSwitchInst(SwitchInst &SI); void visitSelectInst(SelectInst &SI); void visitUserOp1(Instruction &I); void visitUserOp2(Instruction &I) { visitUserOp1(I); } @@ -360,6 +361,17 @@ // Check to make sure that the return value has necessary properties for // terminators... visitTerminatorInst(RI); +} + +void Verifier::visitSwitchInst(SwitchInst &SI) { + // Check to make sure that all of the constants in the switch instruction + // have the same type as the switched-on value. + const Type *SwitchTy = SI.getCondition()->getType(); + for (unsigned i = 1, e = SI.getNumCases(); i != e; ++i) + Assert1(SI.getCaseValue(i)->getType() == SwitchTy, + "Switch constants must all be same type as switch value!", &SI); + + visitTerminatorInst(SI); } void Verifier::visitSelectInst(SelectInst &SI) { From lattner at cs.uiuc.edu Fri May 21 11:50:01 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 21 11:50:01 2004 Subject: [llvm-commits] CVS: llvm/docs/ReleaseNotes.html Message-ID: <200405211648.LAA11492@zion.cs.uiuc.edu> Changes in directory llvm/docs: ReleaseNotes.html updated: 1.179 -> 1.180 --- Log message: Bug fixed --- Diffs of the changes: (+2 -1) Index: llvm/docs/ReleaseNotes.html diff -u llvm/docs/ReleaseNotes.html:1.179 llvm/docs/ReleaseNotes.html:1.180 --- llvm/docs/ReleaseNotes.html:1.179 Wed May 12 16:46:05 2004 +++ llvm/docs/ReleaseNotes.html Fri May 21 11:48:20 2004 @@ -213,6 +213,7 @@ of the same name, both having constant pools
  • [livevar] Live variables missed physical register use of aliased definition
  • +
  • Verifier misses malformed switch instruction
  • Bugs in the C/C++ front-end:

    @@ -645,7 +646,7 @@ src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /> The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/12 21:46:05 $ + Last modified: $Date: 2004/05/21 16:48:20 $ From lattner at cs.uiuc.edu Fri May 21 11:50:07 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 21 11:50:07 2004 Subject: [llvm-commits] CVS: llvm-www/releases/1.2/docs/ReleaseNotes.html Message-ID: <200405211649.LAA12094@zion.cs.uiuc.edu> Changes in directory llvm-www/releases/1.2/docs: ReleaseNotes.html updated: 1.16 -> 1.17 --- Log message: Bug found --- Diffs of the changes: (+4 -1) Index: llvm-www/releases/1.2/docs/ReleaseNotes.html diff -u llvm-www/releases/1.2/docs/ReleaseNotes.html:1.16 llvm-www/releases/1.2/docs/ReleaseNotes.html:1.17 --- llvm-www/releases/1.2/docs/ReleaseNotes.html:1.16 Mon May 10 09:29:17 2004 +++ llvm-www/releases/1.2/docs/ReleaseNotes.html Fri May 21 11:48:51 2004 @@ -356,6 +356,9 @@
  • [adce] Crash handling unreachable code that unwinds
  • [vmcore] Linker causes erroneous asssertion
  • + +
  • Verifier misses malformed switch instruction
  • + @@ -683,7 +686,7 @@ src="http://www.w3.org/Icons/valid-html401" alt="Valid HTML 4.01!" /> The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/10 14:29:17 $ + Last modified: $Date: 2004/05/21 16:48:51 $ From lattner at cs.uiuc.edu Fri May 21 13:39:02 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 21 13:39:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/CFG.h Message-ID: <200405211837.NAA13655@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: CFG.h updated: 1.20 -> 1.21 --- Log message: Starting an identifier with an _ is not legal C/C++ code. --- Diffs of the changes: (+7 -7) Index: llvm/include/llvm/Support/CFG.h diff -u llvm/include/llvm/Support/CFG.h:1.20 llvm/include/llvm/Support/CFG.h:1.21 --- llvm/include/llvm/Support/CFG.h:1.20 Sat May 1 16:05:34 2004 +++ llvm/include/llvm/Support/CFG.h Fri May 21 13:37:13 2004 @@ -90,20 +90,20 @@ // BasicBlock succ_iterator definition //===--------------------------------------------------------------------===// -template // Successor Iterator -class SuccIterator : public bidirectional_iterator<_BB, ptrdiff_t> { - const _Term Term; +template // Successor Iterator +class SuccIterator : public bidirectional_iterator { + const Term_ Term; unsigned idx; - typedef bidirectional_iterator<_BB, ptrdiff_t> super; + typedef bidirectional_iterator super; public: - typedef SuccIterator<_Term, _BB> _Self; + typedef SuccIterator _Self; typedef typename super::pointer pointer; // TODO: This can be random access iterator, need operator+ and stuff tho - inline SuccIterator(_Term T) : Term(T), idx(0) { // begin iterator + inline SuccIterator(Term_ T) : Term(T), idx(0) { // begin iterator assert(T && "getTerminator returned null!"); } - inline SuccIterator(_Term T, bool) // end iterator + inline SuccIterator(Term_ T, bool) // end iterator : Term(T), idx(Term->getNumSuccessors()) { assert(T && "getTerminator returned null!"); } From lattner at cs.uiuc.edu Fri May 21 13:40:03 2004 From: lattner at cs.uiuc.edu (Chris Lattner) Date: Fri May 21 13:40:03 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Analysis/Dominators.h Message-ID: <200405211838.NAA13730@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/Analysis: Dominators.h updated: 1.44 -> 1.45 --- Log message: It's not clear to me whether the old version was correct C++ code, but in any case it's not portable. --- Diffs of the changes: (+3 -3) Index: llvm/include/llvm/Analysis/Dominators.h diff -u llvm/include/llvm/Analysis/Dominators.h:1.44 llvm/include/llvm/Analysis/Dominators.h:1.45 --- llvm/include/llvm/Analysis/Dominators.h:1.44 Thu Mar 11 17:08:20 2004 +++ llvm/include/llvm/Analysis/Dominators.h Fri May 21 13:38:16 2004 @@ -365,9 +365,9 @@ /// changeImmediateDominator - This method is used to update the dominator /// tree information when a node's immediate dominator changes. /// - void changeImmediateDominator(Node *Node, Node *NewIDom) { - assert(Node && NewIDom && "Cannot change null node pointers!"); - Node->setIDom(NewIDom); + void changeImmediateDominator(Node *N, Node *NewIDom) { + assert(N && NewIDom && "Cannot change null node pointers!"); + N->setIDom(NewIDom); } /// print - Convert to human readable form From gaeke at cs.uiuc.edu Fri May 21 15:55:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Fri May 21 15:55:01 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405212054.PAA23761@kain.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.55 -> 1.56 --- Log message: Fix two important bugs in live-in set calculation: 1) phis which reference values defined in the trace are not live-in 2) phis which define values in the entry basic block are live-in (still need to add fixup code in entry BB for these though!) --- Diffs of the changes: (+7 -0) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.55 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.56 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.55 Fri May 21 05:28:42 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Fri May 21 15:54:44 2004 @@ -113,6 +113,9 @@ Instruction *UInst = dyn_cast (*ui); if (!UInst) // Non-Instruction Users scare me, mommy return false; + if (isa (UInst)) + continue; // If a Phi node uses a value that's defined in the + // trace, the def. must have originally dominated the Phi. BasicBlock *UBlock = UInst->getParent (); if (Block == UBlock) { // Start at Block->begin() traversing next pointers; if UInst @@ -163,6 +166,10 @@ } } } + // Add phis from entry BB + for (BasicBlock::iterator Inst = T.getEntryBasicBlock ()->begin (); + PHINode *PN = dyn_cast (Inst); ++Inst) + S.insert (PN); return S; } From alkis at cs.uiuc.edu Fri May 21 16:37:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Fri May 21 16:37:01 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405212136.QAA29631@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.1 -> 1.2 --- Log message: Use nested Opcode namespace for opcodes. --- Diffs of the changes: (+3 -3) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.1 llvm-java/include/llvm/Java/Bytecode.h:1.2 --- llvm-java/include/llvm/Java/Bytecode.h:1.1 Tue May 18 15:13:37 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Fri May 21 16:35:56 2004 @@ -16,9 +16,9 @@ #include -namespace llvm { namespace Java { +namespace llvm { namespace Java { namespace Opcode { - enum Opcode { + enum { NOP = 0x00, ACONST_NULL = 0x01, ICONST_M1 = 0x02, @@ -226,4 +226,4 @@ IMPDEP2 = 0xFF, }; -} } // namespace llvm::Java +} } } // namespace llvm::Java::BC From brukman at cs.uiuc.edu Fri May 21 18:23:00 2004 From: brukman at cs.uiuc.edu (Misha Brukman) Date: Fri May 21 18:23:00 2004 Subject: [llvm-commits] CVS: llvm/Makefile.rules Message-ID: <200405212321.SAA21412@zion.cs.uiuc.edu> Changes in directory llvm: Makefile.rules updated: 1.183 -> 1.184 --- Log message: Pass the Makefile flags to recursive makes in {PARALLEL,OPTIONAL}_DIRS targets. --- Diffs of the changes: (+2 -2) Index: llvm/Makefile.rules diff -u llvm/Makefile.rules:1.183 llvm/Makefile.rules:1.184 --- llvm/Makefile.rules:1.183 Thu May 20 19:09:21 2004 +++ llvm/Makefile.rules Fri May 21 18:21:11 2004 @@ -422,7 +422,7 @@ $(MKDIR) $(@D); \ cp $(SourceDir)/$(@D)/Makefile $(@D)/Makefile; \ fi; \ - $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) + $(MAKE) -C $(@D) $(subst $(@D)/.make,,$@) $(MFLAGS) endif # Handle directories that may or may not exist @@ -436,7 +436,7 @@ $(MKDIR) $$dir; \ cp $(SourceDir)/$$dir/Makefile $$dir/Makefile; \ fi; \ - ($(MAKE) -C$$dir $@) || exit 1; \ + ($(MAKE) -C$$dir $@ $(MFLAGS)) || exit 1; \ fi \ done endif From llvm at cs.uiuc.edu Fri May 21 20:06:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Fri May 21 20:06:01 2004 Subject: [llvm-commits] CVS: llvm/docs/Stacker.html Message-ID: <200405220104.UAA30209@zion.cs.uiuc.edu> Changes in directory llvm/docs: Stacker.html updated: 1.12 -> 1.13 --- Log message: Removed the 64-bit fix from the "to do" list since the bug is fixed. --- Diffs of the changes: (+1 -6) Index: llvm/docs/Stacker.html diff -u llvm/docs/Stacker.html:1.12 llvm/docs/Stacker.html:1.13 --- llvm/docs/Stacker.html:1.12 Wed May 12 19:37:23 2004 +++ llvm/docs/Stacker.html Fri May 21 20:04:19 2004 @@ -1374,11 +1374,6 @@
  • Write an LLVM pass to compute the correct stack depth needed by the program. Currently the stack is set to a fixed number which means programs with large numbers of definitions might fail.
  • -
  • Enhance to run on 64-bit platforms like SPARC. Right now the size of a - pointer on 64-bit machines will cause incorrect results because of the - 32-bit size of a stack element currently supported. This feature was not - implemented because LLVM needs a union type to be able to support the - different sizes correctly (portably and efficiently).
  • Write an LLVM pass to optimize the use of the global stack. The code emitted currently is somewhat wasteful. It gets cleaned up a lot by existing passes but more could be done.
  • @@ -1410,7 +1405,7 @@ Reid Spencer
    LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/13 00:37:23 $ + Last modified: $Date: 2004/05/22 01:04:19 $ From llvm at cs.uiuc.edu Fri May 21 21:30:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Fri May 21 21:30:01 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html index.html Message-ID: <200405220228.VAA30722@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html added (r1.1) index.html updated: 1.14 -> 1.15 --- Log message: Added an initial template/overview for documentation of the LLVM Bytecode file format. This format is being extracted from the source code and the small recesses of Chris' brain. --- Diffs of the changes: (+250 -1) Index: llvm/docs/BytecodeFormat.html diff -c /dev/null llvm/docs/BytecodeFormat.html:1.1 *** /dev/null Fri May 21 21:28:46 2004 --- llvm/docs/BytecodeFormat.html Fri May 21 21:28:36 2004 *************** *** 0 **** --- 1,248 ---- + + + + LLVM Bytecode File Format + + + + +
    LLVM Bytecode File Format
    +
      +
    1. Abstract
    2. +
    3. General Concepts
    4. +
        +
      1. Blocks
      2. +
      3. Lists
      4. +
      5. Fields
      6. +
      7. Alignment
      8. +
      +
    5. Detailed Layout +
        +
      1. Notation
      2. +
      3. Blocks Types
      4. +
      5. Header Block
      6. +
      7. Global Type Pool
      8. +
      9. Module Info Block
      10. +
      11. Global Constant Pool
      12. +
      13. Function Blocks
      14. +
      15. Module Symbol Table
      16. +
      +
    6. +
    +
    +

    Written by Reid Spencer + and Chris Lattner

    +

    +
    + + + +
    +

    This document is an (after the fact) specification of the LLVM bytecode + file format. It documents the binary encoding rules of the bytecode file format + so that equivalent systems can encode bytecode files correctly. The LLVM + bytecode representation is used to store the intermediate representation on + disk in compacted form. +

    +
    + + + +
    +

    This section describes the general concepts of the bytecode file format + without getting into bit and byte level specifics.

    +
    + + +
    +

    LLVM bytecode files consist simply of a sequence of blocks of bytes. + Each block begins with an identification value that determines the type of + the next block. The possible types of blocks are described below in the section + Block Types. The block identifier is used because + it is possible for entire blocks to be omitted from the file if they are + empty. The block identifier helps the reader determine which kind of block is + next in the file.

    +

    + Except for the Header Block all blocks are variable + length. The consume just enough bytes to express their contents.

    +
    + + +
    +

    Most blocks are constructed of lists of information. Lists can be constructed + of other lists, etc. This decomposition of information follows the containment + hierarchy of the LLVM Intermediate Representation. For example, a function is + composed of a list of basic blocks. Each basic block is composed of a set of + instructions. This list of list nesting and hierarchy is maintained in the + bytecode file.

    +

    A list is encoded into the file simply by encoding the number of entries as + an integer followed by each of the entries. The reader knows when the list is + done because it will have filled the list with the required numbe of entries. +

    +
    + + +
    +

    Fields are units of information that LLVM knows how to write atomically. + Most fields have a uniform length or some kind of length indication built into + their encoding. For example, a constant string (array of SByte or UByte) is + written simply as the length followed by the characters. Although this is + similar to a list, constant strings are treated atomically and are thus + fields.

    +

    Fields use a condensed bit format specific to the type of information + they must contain. As few bits as possible are written for each field. The + sections that follow will provide the details on how these fields are + written and how the bits are to be interpreted.

    +
    + + +
    +

    To support cross-platform differences, the bytecode file is aligned on + certain boundaries. This means that a small amount of padding (at most 3 bytes) + will be added to ensure that the next entry is aligned to a 32-bit boundary. +

    +
    + + + +
    +

    This section provides the detailed layout of the LLVM bytecode file format. + bit and byte level specifics.

    +
    + + +
    +

    The descriptions of the bytecode format that follow describe the bit + fields in detail. These descriptions are provided in tabular form. Each table + has four columns that specify:

    +
      +
    1. Byte(s). The offset in bytes of the field from the start of + its container (block, list, other field).
    2. +
    3. Bit(s). The offset in bits of the field from the start of + the byte field. Bits are always little endian. That is, bit addresses with + smaller values have smaller address (i.e. 2^0 is at bit 0, 2^1 at 1, etc.) +
    4. +
    5. Align? Indicates if this field is aligned to 32 bits or not. + This indicates where the next field starts, always on a 32 bit + boundary.
    6. +
    7. Description. Descripts the contents of the field.
    8. +
    +
    + + +
    +

    The bytecode format encodes the intermediate representation into groups + of bytes known as blocks. The blocks are written sequentially to the file in + the following order:

    +
      +
    1. Header. This block contains the file signature + (magic number), machine description and file format version (not LLVM + version).
    2. +
    3. Global Type Pool. This block contains all the + global (module) level types.
    4. +
    5. Module Info. This block contains the types of the + global variables and functions in the module as well as the constant + initializers for the global variables
    6. +
    7. Constants. This block contains all the global + constants except function arguments, global values and constant strings.
    8. +
    9. Functions. One function block is written for + each function in the module.
    10. +
    11. Symbol Table. The module level symbol table that + provides names for the various other entries in the file is the final block + written.
    12. +
    +
    + + +
    +

    The Header Block occurs in every LLVM bytecode file and is always first. It + simply provides a few bytes of data to identify the file, its format, and the + bytecode version. This block is fixed length and always eight bytes, as follows: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Byte(s)Bit(s)Align?Field Description
    0000-07NoConstant "l"
    0100-07NoConstant "l"
    0200-07NoConstant "v"
    0300-07NoConstant "m"
    04-0700NoTarget is big endian
    04-0701NoTarget has long pointers
    04-0702NoTarget has no endianess
    04-0703NoTarget has no pointer size
    04-0704-31YesThe LLVM bytecode format version number
    +

    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + + +
    +
    + Valid CSS! + Valid HTML 4.01! + + Reid Spencer and + Chris Lattner
    + The LLVM Compiler Infrastructure
    + Last modified: $Date: 2004/05/22 02:28:36 $ +
    + + + Index: llvm/docs/index.html diff -u llvm/docs/index.html:1.14 llvm/docs/index.html:1.15 --- llvm/docs/index.html:1.14 Fri May 14 13:54:04 2004 +++ llvm/docs/index.html Fri May 21 21:28:36 2004 @@ -114,6 +114,7 @@
  • Command Line Library
  • Extending LLVM
  • Coding Standards
  • +
  • LLVM Bytecode File Format
  • @@ -178,7 +179,7 @@ John Criswell
    LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/14 18:54:04 $ + Last modified: $Date: 2004/05/22 02:28:36 $ From llvm at cs.uiuc.edu Sat May 22 00:58:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sat May 22 00:58:01 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html Message-ID: <200405220556.AAA31202@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html updated: 1.1 -> 1.2 --- Log message: Some additional data added to the bytecode specification. --- Diffs of the changes: (+36 -21) Index: llvm/docs/BytecodeFormat.html diff -u llvm/docs/BytecodeFormat.html:1.1 llvm/docs/BytecodeFormat.html:1.2 --- llvm/docs/BytecodeFormat.html:1.1 Fri May 21 21:28:36 2004 +++ llvm/docs/BytecodeFormat.html Sat May 22 00:56:41 2004 @@ -67,9 +67,21 @@ it is possible for entire blocks to be omitted from the file if they are empty. The block identifier helps the reader determine which kind of block is next in the file.

    -

    -Except for the Header Block all blocks are variable -length. The consume just enough bytes to express their contents.

    +

    The following block identifiers are currently in use +(from llvm/Bytecode/Format.h):

    +
      +
    1. Module (0x01).
    2. +
    3. Function (0x11).
    4. +
    5. ConstantPool (0x12).
    6. +
    7. SymbolTable (0x13).
    8. +
    9. ModuleGlobalInfo (0x14).
    10. +
    11. GlobalTypePlane (0x15).
    12. +
    13. BasicBlock (0x31).
    14. +
    15. InstructionList (0x32).
    16. +
    17. CompactionTable (0x33).
    18. +
    +

    Except for the Header Block all blocks are variable +length. They consume just enough bytes to express their contents.

    @@ -130,6 +142,7 @@
  • Align? Indicates if this field is aligned to 32 bits or not. This indicates where the next field starts, always on a 32 bit boundary.
  • +
  • Type. The basic type of information contained in the field.
  • Description. Descripts the contents of the field.
  • @@ -168,42 +181,43 @@ Byte(s) Bit(s) Align? + Type Field Description - 0000-07No - Constant "l" + 0000-07NoChar + Constant "l" (0x6C) - 0100-07No - Constant "l" + 0100-07NoChar + Constant "l" (0x6C) - 0200-07No - Constant "v" + 0200-07NoChar + Constant "v" (0x76) - 0300-07No - Constant "m" + 0300-07NoChar + Constant "m" (0x6D) - 04-0700No - Target is big endian + 04-0700NoBool + Target is big endian? - 04-0701No - Target has long pointers + 04-0701NoBool + Target has long pointers? - 04-0702No - Target has no endianess + 04-0702NoBool + Target has no endianess? - 04-0703No - Target has no pointer size + 04-0703NoBool + Target has no pointer size? - 04-0704-31Yes + 04-0704-31YesUnsigned The LLVM bytecode format version number @@ -227,6 +241,7 @@
    +

    The module symbol table is a list of

    @@ -240,7 +255,7 @@ Reid Spencer and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/22 02:28:36 $ + Last modified: $Date: 2004/05/22 05:56:41 $ From alkis at cs.uiuc.edu Sat May 22 00:59:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 00:59:03 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/ClassFile.h Message-ID: <200405220557.AAA31230@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: ClassFile.h updated: 1.9 -> 1.10 --- Log message: Make code be an array of uint8_t's instead of char's. --- Diffs of the changes: (+2 -2) Index: llvm-java/include/llvm/Java/ClassFile.h diff -u llvm-java/include/llvm/Java/ClassFile.h:1.9 llvm-java/include/llvm/Java/ClassFile.h:1.10 --- llvm-java/include/llvm/Java/ClassFile.h:1.9 Thu May 20 19:05:59 2004 +++ llvm-java/include/llvm/Java/ClassFile.h Sat May 22 00:57:09 2004 @@ -387,7 +387,7 @@ uint16_t maxStack_; uint16_t maxLocals_; uint32_t codeSize_; - char* code_; + uint8_t* code_; Exceptions exceptions_; Attributes attributes_; @@ -398,7 +398,7 @@ ~CodeAttribute(); uint16_t getMaxStack() const { return maxStack_; } uint16_t getMaxLocals() const { return maxLocals_; } - const char* getCode() const { return code_; } + const uint8_t* getCode() const { return code_; } uint32_t getCodeSize() const { return codeSize_; } const Exceptions& getExceptions() const { return exceptions_; } const Attributes& getAttributes() const { return attributes_; } From alkis at cs.uiuc.edu Sat May 22 00:59:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 00:59:09 2004 Subject: [llvm-commits] CVS: llvm-java/lib/ClassFile/ClassFile.cpp Message-ID: <200405220557.AAA31223@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/ClassFile: ClassFile.cpp updated: 1.8 -> 1.9 --- Log message: Make code be an array of uint8_t's instead of char's. --- Diffs of the changes: (+2 -2) Index: llvm-java/lib/ClassFile/ClassFile.cpp diff -u llvm-java/lib/ClassFile/ClassFile.cpp:1.8 llvm-java/lib/ClassFile/ClassFile.cpp:1.9 --- llvm-java/lib/ClassFile/ClassFile.cpp:1.8 Thu May 20 19:05:59 2004 +++ llvm-java/lib/ClassFile/ClassFile.cpp Sat May 22 00:57:09 2004 @@ -537,8 +537,8 @@ maxStack_ = readU2(is); maxLocals_ = readU2(is); codeSize_ = readU4(is); - code_ = new char[codeSize_]; - std::streamsize s = is.rdbuf()->sgetn(code_, codeSize_); + code_ = new uint8_t[codeSize_]; + std::streamsize s = is.rdbuf()->sgetn(reinterpret_cast(code_), codeSize_); if (s != (std::streamsize) codeSize_) throw ClassFileParseError( "Could not read code from input stream"); From alkis at cs.uiuc.edu Sat May 22 00:59:15 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 00:59:15 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/ Message-ID: <200405220557.AAA31277@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: --- Log message: Directory /home/vadve/shared/PublicCVS/llvm-java/lib/Compiler added to the repository --- Diffs of the changes: (+0 -0) From alkis at cs.uiuc.edu Sat May 22 01:00:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 01:00:03 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405220558.AAA31330@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp added (r1.1) --- Log message: Add an initial implementation of a Java bytecode to LLVM compiler. --- Diffs of the changes: (+428 -0) Index: llvm-java/lib/Compiler/Compiler.cpp diff -c /dev/null llvm-java/lib/Compiler/Compiler.cpp:1.1 *** /dev/null Sat May 22 00:58:36 2004 --- llvm-java/lib/Compiler/Compiler.cpp Sat May 22 00:58:26 2004 *************** *** 0 **** --- 1,428 ---- + //===-- Compiler.cpp - Java bytecode compiler -------------------*- C++ -*-===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file contains Java bytecode to LLVM bytecode compiler. + // + //===----------------------------------------------------------------------===// + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + using namespace llvm; + + namespace { + + inline bool isTwoSlotValue(const Value* v) { + return v->getType() == Type::LongTy | v->getType() == Type::DoubleTy; + } + + inline bool isOneSlotValue(const Value* v) { + return !isTwoSlotValue(v); + } + + void compileMethod(Module& module, const Java::Method& method) { + using namespace llvm::Java::Opcode; + + Function* function = + module.getOrInsertFunction(method.getName()->str(), Type::VoidTy); + + const Java::CodeAttribute* codeAttr = + Java::getCodeAttribute(method.getAttributes()); + + std::stack opStack; + std::vector locals(codeAttr->getMaxLocals(), 0); + + const uint8_t* code = codeAttr->getCode(); + for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { + bool wide = code[i] == WIDE; + i += wide; + switch (code[i]) { + case ACONST_NULL: + // FIXME: should push a null pointer of type Object* + opStack.push( + ConstantPointerNull::get(PointerType::get(Type::VoidTy))); + break; + case ICONST_M1: + case ICONST_0: + case ICONST_1: + case ICONST_2: + case ICONST_3: + case ICONST_4: + case ICONST_5: + opStack.push(ConstantInt::get(Type::IntTy, code[i]-ICONST_0)); + break; + case LCONST_0: + case LCONST_1: + opStack.push(ConstantInt::get(Type::LongTy, code[i]-LCONST_0)); + break; + case FCONST_0: + case FCONST_1: + case FCONST_2: + opStack.push(ConstantFP::get(Type::FloatTy, code[i]-FCONST_0)); + break; + case DCONST_0: + case DCONST_1: + opStack.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); + break; + case BIPUSH: { + int imm = code[++i]; + opStack.push(ConstantInt::get(Type::IntTy, imm)); + break; + } + case SIPUSH: { + int imm = (code[++i] << 8) | code[++i]; + opStack.push(ConstantInt::get(Type::IntTy, imm)); + break; + } + case LDC: { + unsigned index = code[++i]; + // FIXME: load constant from constant pool + } + case LDC_W: { + unsigned index = (code[++i] << 8) | code[++i]; + // FIXME: load constant from constant pool + } + case LDC2_W: { + unsigned index = (code[++i] << 8) | code[++i]; + // FIXME: load constant from constant pool + } + case ILOAD: + case LLOAD: + case FLOAD: + case DLOAD: + case ALOAD: { + // FIXME: use opcodes to perform type checking + unsigned index = code[++i]; + opStack.push(locals[index]); + break; + } + case ILOAD_0: + case ILOAD_1: + case ILOAD_2: + case ILOAD_3: + opStack.push(locals[code[i]-ILOAD_0]); + break; + case LLOAD_0: + case LLOAD_1: + case LLOAD_2: + case LLOAD_3: + opStack.push(locals[code[i]-LLOAD_0]); + break; + case FLOAD_0: + case FLOAD_1: + case FLOAD_2: + case FLOAD_3: + opStack.push(locals[code[i]-FLOAD_0]); + break; + case DLOAD_0: + case DLOAD_1: + case DLOAD_2: + case DLOAD_3: + opStack.push(locals[code[i]-DLOAD_0]); + break; + case ALOAD_0: + case ALOAD_1: + case ALOAD_2: + case ALOAD_3: + opStack.push(locals[code[i]-ALOAD_0]); + break; + case IALOAD: + case LALOAD: + case FALOAD: + case DALOAD: + case AALOAD: + case BALOAD: + case CALOAD: + case SALOAD: + case ISTORE: + case LSTORE: + case FSTORE: + case DSTORE: + case ASTORE: + case ISTORE_0: + case ISTORE_1: + case ISTORE_2: + case ISTORE_3: + case LSTORE_0: + case LSTORE_1: + case LSTORE_2: + case LSTORE_3: + case FSTORE_0: + case FSTORE_1: + case FSTORE_2: + case FSTORE_3: + case DSTORE_0: + case DSTORE_1: + case DSTORE_2: + case DSTORE_3: + case ASTORE_0: + case ASTORE_1: + case ASTORE_2: + case ASTORE_3: + case IASTORE: + case LASTORE: + case FASTORE: + case DASTORE: + case AASTORE: + case BASTORE: + case CASTORE: + case SASTORE: + assert(0 && "not implemented"); + case POP: + opStack.pop(); + break; + case POP2: + opStack.pop(); + opStack.pop(); + break; + case DUP: + opStack.push(opStack.top()); + break; + case DUP_X1: { + Value* v1 = opStack.top(); opStack.pop(); + Value* v2 = opStack.top(); opStack.pop(); + opStack.push(v1); + opStack.push(v2); + opStack.push(v1); + break; + } + case DUP_X2: { + Value* v1 = opStack.top(); opStack.pop(); + Value* v2 = opStack.top(); opStack.pop(); + if (isOneSlotValue(v2)) { + Value* v3 = opStack.top(); opStack.pop(); + opStack.push(v1); + opStack.push(v3); + opStack.push(v2); + opStack.push(v1); + } + else { + opStack.push(v1); + opStack.push(v2); + opStack.push(v1); + } + break; + } + case DUP2: { + Value* v1 = opStack.top(); opStack.pop(); + if (isOneSlotValue(v1)) { + Value* v2 = opStack.top(); opStack.pop(); + opStack.push(v2); + opStack.push(v1); + opStack.push(v2); + opStack.push(v1); + } + else { + opStack.push(v1); + opStack.push(v1); + } + break; + } + case DUP2_X1: { + Value* v1 = opStack.top(); opStack.pop(); + Value* v2 = opStack.top(); opStack.pop(); + if (isOneSlotValue(v1)) { + Value* v3 = opStack.top(); opStack.pop(); + opStack.push(v2); + opStack.push(v1); + opStack.push(v3); + opStack.push(v2); + opStack.push(v1); + } + else { + opStack.push(v1); + opStack.push(v2); + opStack.push(v1); + } + break; + } + case DUP2_X2: { + Value* v1 = opStack.top(); opStack.pop(); + Value* v2 = opStack.top(); opStack.pop(); + if (isOneSlotValue(v1)) { + Value* v3 = opStack.top(); opStack.pop(); + if (isOneSlotValue(v3)) { + Value* v4 = opStack.top(); opStack.pop(); + opStack.push(v2); + opStack.push(v1); + opStack.push(v4); + opStack.push(v3); + opStack.push(v2); + opStack.push(v1); + } + else { + opStack.push(v2); + opStack.push(v1); + opStack.push(v3); + opStack.push(v2); + opStack.push(v1); + } + } + else { + if (isOneSlotValue(v2)) { + Value* v3 = opStack.top(); opStack.pop(); + opStack.push(v1); + opStack.push(v3); + opStack.push(v2); + opStack.push(v1); + } + else { + opStack.push(v1); + opStack.push(v2); + opStack.push(v1); + } + } + break; + } + case SWAP: { + Value* v1 = opStack.top(); opStack.pop(); + Value* v2 = opStack.top(); opStack.pop(); + opStack.push(v1); + opStack.push(v2); + break; + } + case IADD: + case LADD: + case FADD: + case DADD: + case ISUB: + case LSUB: + case FSUB: + case DSUB: + case IMUL: + case LMUL: + case FMUL: + case DMUL: + case IDIV: + case LDIV: + case FDIV: + case DDIV: + case IREM: + case LREM: + case FREM: + case DREM: + case INEG: + case LNEG: + case FNEG: + case DNEG: + case ISHL: + case LSHL: + case ISHR: + case LSHR: + case IUSHR: + case LUSHR: + case IAND: + case LAND: + case IOR: + case LOR: + case IXOR: + case LXOR: + case IINC: + case I2L: + case I2F: + case I2D: + case L2I: + case L2F: + case L2D: + case F2I: + case F2L: + case F2D: + case D2I: + case D2L: + case D2F: + case I2B: + case I2C: + case I2S: + case LCMP: + case FCMPL: + case FCMPG: + case DCMPL: + case DCMPG: + case IFEQ: + case IFNE: + case IFLT: + case IFGE: + case IFGT: + case IFLE: + case IF_ICMPEQ: + case IF_ICMPNE: + case IF_ICMPLT: + case IF_ICMPGE: + case IF_ICMPGT: + case IF_ICMPLE: + case IF_ICMPACMPEQ: + case IF_ICMPACMPNE: + case GOTO: + case JSR: + case RET: + case TABLESWITCH: + case LOOKUPSWITCH: + case IRETURN: + case LRETURN: + case FRETURN: + case DRETURN: + case ARETURN: + case RETURN: + case GETSTATIC: + case PUTSTATIC: + case GETFIELD: + case PUTFIELD: + case INVOKEVIRTUAL: + case INVOKESPECIAL: + case INVOKESTATIC: + case INVOKEINTERFACE: + case XXXUNUSEDXXX: + case NEW: + case NEWARRAY: + case ANEWARRAY: + case ARRAYLENGTH: + case ATHROW: + case CHECKCAST: + case INSTANCEOF: + case MONITORENTER: + case MONITOREXIT: + case WIDE: + case MULTIANEWARRAY: + case IFNULL: + case IFNONNULL: + case GOTO_W: + case JSR_W: + case BREAKPOINT: + case IMPDEP1: + case IMPDEP2: + case NOP: + break; + } + } + } + + } // namespace + + Module* llvm::Java::compile(const ClassFile& cf) + { + Module* module = new Module(cf.getThisClass()->getName()->str()); + + std::vector opStack; + + const Java::Methods& methods = cf.getMethods(); + for (Java::Methods::const_iterator + i = methods.begin(), e = methods.end(); i != e; ++i) { + compileMethod(*module, **i); + } + + return module; + } From alkis at cs.uiuc.edu Sat May 22 01:00:12 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 01:00:12 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Compiler.h Message-ID: <200405220558.AAA31337@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Compiler.h added (r1.1) --- Log message: Add an initial implementation of a Java bytecode to LLVM compiler. --- Diffs of the changes: (+25 -0) Index: llvm-java/include/llvm/Java/Compiler.h diff -c /dev/null llvm-java/include/llvm/Java/Compiler.h:1.1 *** /dev/null Sat May 22 00:58:36 2004 --- llvm-java/include/llvm/Java/Compiler.h Sat May 22 00:58:26 2004 *************** *** 0 **** --- 1,25 ---- + //===-- Compiler.h - Java bytecode compiler ---------------------*- C++ -*-===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This file contains Java bytecode to LLVM bytecode compiler. + // + //===----------------------------------------------------------------------===// + + #ifndef LLVM_JAVA_COMPILER_H + #define LLVM_JAVA_COMPILER_H + + #include + + namespace llvm { namespace Java { + + Module* compile(const ClassFile& cf); + + } } // namespace llvm::Java + + #endif//LLVM_JAVA_COMPILER_H From alkis at cs.uiuc.edu Sat May 22 01:11:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 01:11:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/classdump/classdump.cpp Message-ID: <200405220609.BAA31428@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/classdump: classdump.cpp updated: 1.4 -> 1.5 --- Log message: Fix comment. --- Diffs of the changes: (+1 -1) Index: llvm-java/tools/classdump/classdump.cpp diff -u llvm-java/tools/classdump/classdump.cpp:1.4 llvm-java/tools/classdump/classdump.cpp:1.5 --- llvm-java/tools/classdump/classdump.cpp:1.4 Wed May 19 15:44:40 2004 +++ llvm-java/tools/classdump/classdump.cpp Sat May 22 01:09:27 2004 @@ -7,7 +7,7 @@ // //===----------------------------------------------------------------------===// // -// This file a sample class reader driver. It is used to drive class +// This is a sample class reader driver. It is used to drive class // reader tests. // //===----------------------------------------------------------------------===// From alkis at cs.uiuc.edu Sat May 22 01:11:11 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 01:11:11 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Makefile Message-ID: <200405220609.BAA31447@zion.cs.uiuc.edu> Changes in directory llvm-java/lib: Makefile updated: 1.2 -> 1.3 --- Log message: Build the compiler library by default. --- Diffs of the changes: (+1 -1) Index: llvm-java/lib/Makefile diff -u llvm-java/lib/Makefile:1.2 llvm-java/lib/Makefile:1.3 --- llvm-java/lib/Makefile:1.2 Thu Apr 15 23:03:45 2004 +++ llvm-java/lib/Makefile Sat May 22 01:09:42 2004 @@ -8,6 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL := .. -PARALLEL_DIRS := ClassFile +PARALLEL_DIRS := ClassFile Compiler include $(LEVEL)/Makefile.common From alkis at cs.uiuc.edu Sat May 22 01:23:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 01:23:03 2004 Subject: [llvm-commits] CVS: llvm-java/Makefile.common.in Message-ID: <200405220621.BAA31571@zion.cs.uiuc.edu> Changes in directory llvm-java: Makefile.common.in updated: 1.2 -> 1.3 --- Log message: Add JAVAC and JAVA variables. --- Diffs of the changes: (+2 -0) Index: llvm-java/Makefile.common.in diff -u llvm-java/Makefile.common.in:1.2 llvm-java/Makefile.common.in:1.3 --- llvm-java/Makefile.common.in:1.2 Wed Apr 21 11:33:48 2004 +++ llvm-java/Makefile.common.in Sat May 22 01:21:36 2004 @@ -28,6 +28,8 @@ # Additional utilities # JIKES=@JIKES@ +JAVAC=@JAVAC@ +JAVA=@JAVA@ # # Include LLVM's build rules. From alkis at cs.uiuc.edu Sat May 22 01:50:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 01:50:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/classdump/classdump.cpp Makefile Message-ID: <200405220648.BAA31723@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/classdump: classdump.cpp updated: 1.5 -> 1.6 Makefile updated: 1.2 -> 1.3 --- Log message: Print a stack trace on a crash. --- Diffs of the changes: (+4 -0) Index: llvm-java/tools/classdump/classdump.cpp diff -u llvm-java/tools/classdump/classdump.cpp:1.5 llvm-java/tools/classdump/classdump.cpp:1.6 --- llvm-java/tools/classdump/classdump.cpp:1.5 Sat May 22 01:09:27 2004 +++ llvm-java/tools/classdump/classdump.cpp Sat May 22 01:48:35 2004 @@ -13,6 +13,7 @@ //===----------------------------------------------------------------------===// #include +#include #include #include @@ -22,6 +23,8 @@ int main(int argc, char* argv[]) { + PrintStackTraceOnErrorSignal(); + try { std::auto_ptr cf( Java::ClassFile::readClassFile(std::cin)); Index: llvm-java/tools/classdump/Makefile diff -u llvm-java/tools/classdump/Makefile:1.2 llvm-java/tools/classdump/Makefile:1.3 --- llvm-java/tools/classdump/Makefile:1.2 Thu Apr 15 23:03:45 2004 +++ llvm-java/tools/classdump/Makefile Sat May 22 01:48:35 2004 @@ -11,5 +11,6 @@ TOOLNAME := classdump USEDLIBS := classfile +LLVMLIBS := support vmcore include $(LEVEL)/Makefile.common From gaeke at cs.uiuc.edu Sat May 22 01:57:04 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 01:57:04 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/TraceWriter.cpp Message-ID: <200405220656.BAA00935@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: TraceWriter.cpp updated: 1.1 -> 1.2 --- Log message: Add a FIXME comment. --- Diffs of the changes: (+2 -1) Index: reopt/lib/LightWtProfiling/TraceWriter.cpp diff -u reopt/lib/LightWtProfiling/TraceWriter.cpp:1.1 reopt/lib/LightWtProfiling/TraceWriter.cpp:1.2 --- reopt/lib/LightWtProfiling/TraceWriter.cpp:1.1 Wed May 19 15:16:12 2004 +++ reopt/lib/LightWtProfiling/TraceWriter.cpp Sat May 22 01:56:38 2004 @@ -54,7 +54,8 @@ out << "\n"; out.close (); - // Write out bytecode. + // Write out bytecode. FIXME: Should extract function F (as w/ + // 'extract' tool) and write out only F, not its entire module. std::ofstream bout (bytecodeFileName.c_str ()); WriteBytecodeToFile(F->getParent (), bout); bout.close (); From gaeke at cs.uiuc.edu Sat May 22 01:57:14 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 01:57:14 2004 Subject: [llvm-commits] CVS: reopt/lib/TraceToFunction/TraceToFunction.cpp Message-ID: <200405220656.BAA00942@seraph.cs.uiuc.edu> Changes in directory reopt/lib/TraceToFunction: TraceToFunction.cpp updated: 1.56 -> 1.57 --- Log message: Three important changes regarding trace entry-BB Phi nodes: 1) In DEBUG mode, change their names to reflect their special status, and add better debug messages. 2) Assert that they are live-in (fixing a longstanding FIXME). 3) Rewrite their off-trace incoming values to be the argument of the TraceFn which carries their live-in value. --- Diffs of the changes: (+28 -12) Index: reopt/lib/TraceToFunction/TraceToFunction.cpp diff -u reopt/lib/TraceToFunction/TraceToFunction.cpp:1.56 reopt/lib/TraceToFunction/TraceToFunction.cpp:1.57 --- reopt/lib/TraceToFunction/TraceToFunction.cpp:1.56 Fri May 21 15:54:44 2004 +++ reopt/lib/TraceToFunction/TraceToFunction.cpp Sat May 22 01:56:39 2004 @@ -546,26 +546,42 @@ if (srcB == T.getEntryBasicBlock ()) { BasicBlock *EntryFixup = new BasicBlock ("entryfixup", F, dstB); EntryFixup->getInstList ().push_back (new BranchInst (dstB)); - // Replace the references to the trace's predecessor with a - // reference to EntryFixup now. This is kind of a dodge because we - // don't have a pointer to the trace's predecessor, so we have - // to guess which one it is. Assume it's any phi value source in - // the entry BB which is not in the trace. + // Rewrite phi nodes in the entry basic block, which carry values + // that are live-in to the trace: Off-trace phi sources must be + // rewritten to take their value from the entryfixup block, and get + // their value from the argument which carries the live-in value. for (BasicBlock::iterator BI = srcB->begin (); - PHINode *PN = dyn_cast (BI); ++BI) - for (unsigned i = 0; i < PN->getNumIncomingValues (); ++i) { + PHINode *oldPN = dyn_cast (BI); ++BI) { + DEBUG (std::cerr << "fixupFunctionBodyBB: Changing name of trace" + << " entry block Phi node:\n" << O2CMap[oldPN] << " to " + << O2CMap[oldPN]->getName() << ".phifixup\n"; + O2CMap[oldPN]->setName (O2CMap[oldPN]->getName () + ".phifixup")); + assert (TF->LiveInSet.find (oldPN) != TF->LiveInSet.end () + && "Phi nodes in trace entry BB must be live-in"); + unsigned argNum = TF->LiveInToParameterMap [oldPN]; + Argument *phiLiveIn = getFunctionArg (F, argNum); + for (unsigned i = 0; i < oldPN->getNumIncomingValues (); ++i) { // Fold Phi sources which come from FLI blocks - BasicBlock *phiSource = PN->getIncomingBlock (i); + BasicBlock *phiSource = oldPN->getIncomingBlock (i); if (BasicBlock *realSource = getFLIEdgeSource (phiSource)) phiSource = realSource; if (!T.contains (phiSource)) { - // FIXME: Assert that O2CMap[PN]'s value i is live in. - Value *V = O2CMap[PN]; + Value *V = O2CMap[oldPN]; assert (V && isa (V) && "Clone of PHINode from trace entry BB missing or mangled"); - cast (V)->setIncomingBlock (i, EntryFixup); + PHINode *newPN = cast (V); + DEBUG (std::cerr << "fixupFunctionBodyBB: Changing incoming block " + << i << " of trace entry block Phi node:\n" << *newPN << " from " + << newPN->getIncomingBlock (i)->getName () << " to entry-fixup " + << "block, and incoming value to argument " << argNum << " ("; + WriteAsOperand (std::cerr, phiLiveIn, true, true, + TF->TraceFn->getParent ()); + std::cerr << ")\n"); + newPN->setIncomingBlock (i, EntryFixup); + newPN->setIncomingValue (i, phiLiveIn); } - } + } + } } // If srcB contains a trace-exiting branch B, fix up B's clone in From gaeke at cs.uiuc.edu Sat May 22 01:57:21 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 01:57:21 2004 Subject: [llvm-commits] CVS: reopt/test/TEST.reopt.Makefile Message-ID: <200405220656.BAA00949@seraph.cs.uiuc.edu> Changes in directory reopt/test: TEST.reopt.Makefile updated: 1.12 -> 1.13 --- Log message: Don't dump the wholereoptimizer.o object file in llvm/lib/Debug; put it in llvm/projects/reopt/lib/Debug instead. --- Diffs of the changes: (+2 -2) Index: reopt/test/TEST.reopt.Makefile diff -u reopt/test/TEST.reopt.Makefile:1.12 reopt/test/TEST.reopt.Makefile:1.13 --- reopt/test/TEST.reopt.Makefile:1.12 Tue May 18 11:51:29 2004 +++ reopt/test/TEST.reopt.Makefile Sat May 22 01:56:40 2004 @@ -23,7 +23,7 @@ TESTNAME = $* -REOPTLIBDIR = $(PROJECT_DIR)/lib/Debug +REOPTLIBDIR = $(PROJECT_DIR)/lib/$(CONFIGURATION) # Libraries that contain the Reoptimizer itself REOPTIMIZER_OBJS = $(REOPTLIBDIR)/firstTrigger.o \ @@ -46,7 +46,7 @@ # Solaris libraries that the Reoptimizer depends on REOPTIMIZER_SOLARISLIBS = -lcpc -lm -lrt -lmalloc -ldl -WHOLE_REOPTIMIZER = $(DESTLIBCURRENT)/wholereoptimizer.o +WHOLE_REOPTIMIZER = $(REOPTLIBDIR)/wholereoptimizer.o $(WHOLE_REOPTIMIZER): $(REOPTIMIZER_OBJS) $(REOPTIMIZER_LLVMOBJS) /usr/ccs/bin/ld -r -o $@ $+ From gaeke at cs.uiuc.edu Sat May 22 01:57:26 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 01:57:26 2004 Subject: [llvm-commits] CVS: reopt/tools/ttftest/ttftest.cpp Message-ID: <200405220656.BAA00956@seraph.cs.uiuc.edu> Changes in directory reopt/tools/ttftest: ttftest.cpp updated: 1.3 -> 1.4 --- Log message: Add -q (quiet) flag, to suppress output unless it is absolutely necessary, for the benefit of the test script. --- Diffs of the changes: (+12 -7) Index: reopt/tools/ttftest/ttftest.cpp diff -u reopt/tools/ttftest/ttftest.cpp:1.3 reopt/tools/ttftest/ttftest.cpp:1.4 --- reopt/tools/ttftest/ttftest.cpp:1.3 Wed May 19 03:44:44 2004 +++ reopt/tools/ttftest/ttftest.cpp Sat May 22 01:56:41 2004 @@ -33,6 +33,7 @@ cl::desc("Name of file containing trace"), cl::value_desc("traceFileName")); cl::opt BytecodeFile("bc", cl::desc("Name of file containing module"), cl::value_desc("bytecodeFileName")); + cl::opt Quiet("q", cl::desc("Be quiet"), cl::init(false)); }; /// getBasicBlockByNum - Returns the basic block in F whose index is @@ -66,17 +67,19 @@ + "' not found in module"; return 0; } - std::cerr << "Function name: '" << functionName << "'\n" << "Basic blocks: "; + if (!Quiet) + std::cerr << "Function name: '" << functionName << "'\n" + << "Basic blocks: "; std::vector vBB; do { int basicBlockNum; in >> basicBlockNum; if (!in.eof ()) { - std::cerr << basicBlockNum << " "; + if (!Quiet) std::cerr << basicBlockNum << " "; vBB.push_back (getBasicBlockByNum (F, basicBlockNum)); } } while (!in.eof ()); - std::cerr << "\n"; + if (!Quiet) std::cerr << "\n"; return new Trace (vBB); } @@ -115,14 +118,16 @@ // Run TraceToFunction on the Trace. TraceFunction *TF = TraceFunction::get (*T); - std::cerr << *TF->TraceFn << "\n\n"; + if (!Quiet) { std::cerr << *TF->TraceFn << "\n\n"; } // Run the LLVM Verifier on the resulting TraceFunction. - if (verifyFunction (*TF->TraceFn, PrintMessageAction)) { - std::cerr << "Verifier fails.\n"; + VerifierFailureAction action = + (Quiet ? ReturnStatusAction : PrintMessageAction); + if (verifyFunction (*TF->TraceFn, action)) { + if (!Quiet) { std::cerr << "Verifier fails.\n"; } exit (1); } else { - std::cerr << "Verifier passes.\n"; + if (!Quiet) { std::cerr << "Verifier passes.\n"; } exit (0); } } From alkis at cs.uiuc.edu Sat May 22 02:02:06 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 02:02:06 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Makefile Message-ID: <200405220700.CAA31832@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Makefile added (r1.1) --- Log message: Add Compiler library makefile. --- Diffs of the changes: (+15 -0) Index: llvm-java/lib/Compiler/Makefile diff -c /dev/null llvm-java/lib/Compiler/Makefile:1.1 *** /dev/null Sat May 22 02:00:26 2004 --- llvm-java/lib/Compiler/Makefile Sat May 22 02:00:16 2004 *************** *** 0 **** --- 1,15 ---- + ##===- lib/Compiler/Makefile -------------------------------*- Makefile -*-===## + # + # The LLVM Compiler Infrastructure + # + # This file was developed by the LLVM research group and is distributed under + # the University of Illinois Open Source License. See LICENSE.TXT for details. + # + ##===----------------------------------------------------------------------===## + LEVEL := ../.. + + LIBRARYNAME := compiler + + BUILD_ARCHIVE = 1 + + include $(LEVEL)/Makefile.common From alkis at cs.uiuc.edu Sat May 22 02:09:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 02:09:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/class2llvm/ Message-ID: <200405220707.CAA02092@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/class2llvm: --- Log message: Directory /home/vadve/shared/PublicCVS/llvm-java/tools/class2llvm added to the repository --- Diffs of the changes: (+0 -0) From alkis at cs.uiuc.edu Sat May 22 02:10:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 02:10:02 2004 Subject: [llvm-commits] CVS: llvm-java/tools/class2llvm/class2llvm.cpp Makefile Message-ID: <200405220708.CAA03405@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/class2llvm: class2llvm.cpp added (r1.1) Makefile added (r1.1) --- Log message: Add class2llvm utility. --- Diffs of the changes: (+63 -0) Index: llvm-java/tools/class2llvm/class2llvm.cpp diff -c /dev/null llvm-java/tools/class2llvm/class2llvm.cpp:1.1 *** /dev/null Sat May 22 02:08:41 2004 --- llvm-java/tools/class2llvm/class2llvm.cpp Sat May 22 02:08:31 2004 *************** *** 0 **** --- 1,47 ---- + //===-- class2llvm.cpp - class2llvm utility ---------------------*- C++ -*-===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This is a sample class reader driver. It is used to drive class + // reader tests. + // + //===----------------------------------------------------------------------===// + + #include + #include + #include + #include + #include + + #include + #include + #include + + using namespace llvm; + + int main(int argc, char* argv[]) + { + PrintStackTraceOnErrorSignal(); + + try { + std::auto_ptr cf( + Java::ClassFile::readClassFile(std::cin)); + + Module* module = Java::compile(*cf); + + PassManager passes; + passes.add(new PrintModulePass(&std::cout)); + passes.run(*module); + } + catch (std::exception& e) { + std::cerr << e.what() << '\n'; + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; + } Index: llvm-java/tools/class2llvm/Makefile diff -c /dev/null llvm-java/tools/class2llvm/Makefile:1.1 *** /dev/null Sat May 22 02:08:41 2004 --- llvm-java/tools/class2llvm/Makefile Sat May 22 02:08:31 2004 *************** *** 0 **** --- 1,16 ---- + #===- tools/class2llvm/Makefile ----------------------------*- Makefile -*-===## + # + # The LLVM Compiler Infrastructure + # + # This file was developed by the LLVM research group and is distributed under + # the University of Illinois Open Source License. See LICENSE.TXT for details. + # + ##===----------------------------------------------------------------------===## + LEVEL := ../.. + + TOOLNAME := class2llvm + + USEDLIBS := classfile compiler + LLVMLIBS := support vmcore + + include $(LEVEL)/Makefile.common From alkis at cs.uiuc.edu Sat May 22 02:10:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 02:10:09 2004 Subject: [llvm-commits] CVS: llvm-java/tools/Makefile Message-ID: <200405220708.CAA03411@zion.cs.uiuc.edu> Changes in directory llvm-java/tools: Makefile updated: 1.2 -> 1.3 --- Log message: Add class2llvm utility. --- Diffs of the changes: (+1 -1) Index: llvm-java/tools/Makefile diff -u llvm-java/tools/Makefile:1.2 llvm-java/tools/Makefile:1.3 --- llvm-java/tools/Makefile:1.2 Thu Apr 15 23:03:45 2004 +++ llvm-java/tools/Makefile Sat May 22 02:08:31 2004 @@ -8,6 +8,6 @@ ##===----------------------------------------------------------------------===## LEVEL := .. -PARALLEL_DIRS := classdump +PARALLEL_DIRS := classdump class2llvm include $(LEVEL)/Makefile.common From alkis at cs.uiuc.edu Sat May 22 02:23:03 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 02:23:03 2004 Subject: [llvm-commits] CVS: llvm-java/test/Makefile Message-ID: <200405220721.CAA09408@zion.cs.uiuc.edu> Changes in directory llvm-java/test: Makefile added (r1.1) --- Log message: Add test Makefile. --- Diffs of the changes: (+13 -0) Index: llvm-java/test/Makefile diff -c /dev/null llvm-java/test/Makefile:1.1 *** /dev/null Sat May 22 02:21:26 2004 --- llvm-java/test/Makefile Sat May 22 02:21:16 2004 *************** *** 0 **** --- 1,13 ---- + ##===- tests/Makefile --------------------------------------*- Makefile -*-===## + # + # The LLVM Compiler Infrastructure + # + # This file was developed by the LLVM research group and is distributed under + # the University of Illinois Open Source License. See LICENSE.TXT for details. + # + ##===----------------------------------------------------------------------===## + LEVEL := .. + + BUILD_JAVA_SOURCE=1 + + include $(LEVEL)/Makefile.common From gaeke at cs.uiuc.edu Sat May 22 15:43:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 15:43:01 2004 Subject: [llvm-commits] CVS: reopt/lib/Optimizations/Makefile Message-ID: <200405222042.PAA01760@seraph.cs.uiuc.edu> Changes in directory reopt/lib/Optimizations: Makefile added (r1.1) --- Log message: Add makefile for runtimelicm. --- Diffs of the changes: (+4 -0) Index: reopt/lib/Optimizations/Makefile diff -c /dev/null reopt/lib/Optimizations/Makefile:1.1 *** /dev/null Sat May 22 15:42:05 2004 --- reopt/lib/Optimizations/Makefile Sat May 22 15:41:55 2004 *************** *** 0 **** --- 1,4 ---- + LEVEL = ../.. + LIBRARYNAME = runtimelicm + + include $(LEVEL)/Makefile.common From gaeke at cs.uiuc.edu Sat May 22 15:43:07 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 15:43:07 2004 Subject: [llvm-commits] CVS: reopt/lib/Optimizations/RuntimeLICM.cpp Message-ID: <200405222042.PAA01806@seraph.cs.uiuc.edu> Changes in directory reopt/lib/Optimizations: RuntimeLICM.cpp updated: 1.2 -> 1.3 --- Log message: Make this file compile again. Put code into llvm namespace. Get rid of using std:: directives. Use DEBUG() for debugging msgs. --- Diffs of the changes: (+10 -9) Index: reopt/lib/Optimizations/RuntimeLICM.cpp diff -u reopt/lib/Optimizations/RuntimeLICM.cpp:1.2 reopt/lib/Optimizations/RuntimeLICM.cpp:1.3 --- reopt/lib/Optimizations/RuntimeLICM.cpp:1.2 Thu Aug 21 15:55:17 2003 +++ reopt/lib/Optimizations/RuntimeLICM.cpp Sat May 22 15:41:41 2004 @@ -11,15 +11,14 @@ #include "llvm/iMemory.h" #include "llvm/iPHINode.h" #include "reopt/BinInterface/LLVMTrace.h" - +#include "Support/Debug.h" #include -#include #include +using namespace llvm; -using std::vector; -using std::set; +namespace llvm { -void RuntimeLICM(vector &trace, LLVMTrace <race) { +void RuntimeLICM(std::vector &trace, LLVMTrace <race) { //Put the trace in a set for faster searching std::set traceSet(trace.begin(), trace.end()); @@ -28,7 +27,7 @@ unsigned numLIC = 0; //loop over all the basic blocks in my trace - for(vector::iterator T = trace.begin(), End = trace.end(); + for(std::vector::iterator T = trace.begin(), End = trace.end(); T != End; ++T) { //loop over all the instructions in the basic block @@ -57,14 +56,16 @@ } if(isLoopInvariant) { - std::cerr << "Loop Invariant Instruction: " << i << "\n"; + DEBUG (std::cerr << "Loop Invariant Instruction: " << i << "\n"; + ++numLIC); //move to header block ltrace.moveInstrToSec(&(*i), 0); - ++numLIC; } } } } - std::cerr << "Number Loop Invariant: " << numLIC << "\n"; + DEBUG (std::cerr << "Number Loop Invariant: " << numLIC << "\n"); } + +} // end namespace llvm From gaeke at cs.uiuc.edu Sat May 22 15:43:11 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 15:43:11 2004 Subject: [llvm-commits] CVS: reopt/lib/Makefile Message-ID: <200405222042.PAA01818@seraph.cs.uiuc.edu> Changes in directory reopt/lib: Makefile updated: 1.20 -> 1.21 --- Log message: Add Optimizations directory to the build. --- Diffs of the changes: (+1 -1) Index: reopt/lib/Makefile diff -u reopt/lib/Makefile:1.20 reopt/lib/Makefile:1.21 --- reopt/lib/Makefile:1.20 Wed May 19 01:50:56 2004 +++ reopt/lib/Makefile Sat May 22 15:42:40 2004 @@ -1,5 +1,5 @@ LEVEL = .. -DIRS := BinInterface Mapping TraceCache Trigger LightWtProfiling Inst TraceToFunction +DIRS := BinInterface Mapping TraceCache Trigger LightWtProfiling Inst Optimizations TraceToFunction include $(LEVEL)/Makefile.config From alkis at cs.uiuc.edu Sat May 22 17:52:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 17:52:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405222249.RAA07727@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.1 -> 1.2 --- Log message: Add utility functions to read immediates and indices from bytecode. --- Diffs of the changes: (+27 -8) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.1 llvm-java/lib/Compiler/Compiler.cpp:1.2 --- llvm-java/lib/Compiler/Compiler.cpp:1.1 Sat May 22 00:58:26 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 22 17:49:14 2004 @@ -34,6 +34,22 @@ return !isTwoSlotValue(v); } + inline int readByteImmediate(const uint8_t* code, unsigned& i) { + return code[++i]; + } + + inline int readShortImmediate(const uint8_t* code, unsigned& i) { + return (code[++i] << 8) | code[++i]; + } + + inline unsigned readByteIndex(const uint8_t* code, unsigned& i) { + return code[++i]; + } + + inline unsigned readShortIndex(const uint8_t* code, unsigned& i) { + return (code[++i] << 8) | code[++i]; + } + void compileMethod(Module& module, const Java::Method& method) { using namespace llvm::Java::Opcode; @@ -43,11 +59,14 @@ const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); - std::stack opStack; - std::vector locals(codeAttr->getMaxLocals(), 0); + typedef std::stack OperandStack; + OperandStack opStack; + typedef std::vector Locals; + Locals locals(codeAttr->getMaxLocals(), 0); const uint8_t* code = codeAttr->getCode(); for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { + unsigned bcStart = i; bool wide = code[i] == WIDE; i += wide; switch (code[i]) { @@ -79,25 +98,25 @@ opStack.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); break; case BIPUSH: { - int imm = code[++i]; + int imm = readByteImmediate(code, i); opStack.push(ConstantInt::get(Type::IntTy, imm)); break; } case SIPUSH: { - int imm = (code[++i] << 8) | code[++i]; + int imm = readShortImmediate(code, i); opStack.push(ConstantInt::get(Type::IntTy, imm)); break; } case LDC: { - unsigned index = code[++i]; + unsigned index = readByteIndex(code, i); // FIXME: load constant from constant pool } case LDC_W: { - unsigned index = (code[++i] << 8) | code[++i]; + unsigned index = readShortIndex(code, i); // FIXME: load constant from constant pool } case LDC2_W: { - unsigned index = (code[++i] << 8) | code[++i]; + unsigned index = readShortIndex(code, i); // FIXME: load constant from constant pool } case ILOAD: @@ -106,7 +125,7 @@ case DLOAD: case ALOAD: { // FIXME: use opcodes to perform type checking - unsigned index = code[++i]; + unsigned index = readByteIndex(code, i); opStack.push(locals[index]); break; } From alkis at cs.uiuc.edu Sat May 22 18:27:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 18:27:01 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Compiler.h Message-ID: <200405222325.SAA07939@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Compiler.h updated: 1.1 -> 1.2 --- Log message: Put Java::compile free function in a Java::Compiler object. --- Diffs of the changes: (+17 -1) Index: llvm-java/include/llvm/Java/Compiler.h diff -u llvm-java/include/llvm/Java/Compiler.h:1.1 llvm-java/include/llvm/Java/Compiler.h:1.2 --- llvm-java/include/llvm/Java/Compiler.h:1.1 Sat May 22 00:58:26 2004 +++ llvm-java/include/llvm/Java/Compiler.h Sat May 22 18:25:22 2004 @@ -15,10 +15,26 @@ #define LLVM_JAVA_COMPILER_H #include +#include +#include namespace llvm { namespace Java { - Module* compile(const ClassFile& cf); + class Compiler { + public: + Module* compile(const ClassFile& cf); + + private: + void compileMethod(Module& module, const Method& method); + void initForCode(const CodeAttribute& codeAttr); + + private: + typedef std::stack > OperandStack; + typedef std::vector Locals; + + OperandStack opStack_; + Locals locals_; + }; } } // namespace llvm::Java From alkis at cs.uiuc.edu Sat May 22 18:27:06 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 18:27:06 2004 Subject: [llvm-commits] CVS: llvm-java/tools/class2llvm/class2llvm.cpp Message-ID: <200405222325.SAA07927@zion.cs.uiuc.edu> Changes in directory llvm-java/tools/class2llvm: class2llvm.cpp updated: 1.1 -> 1.2 --- Log message: Put Java::compile free function in a Java::Compiler object. --- Diffs of the changes: (+3 -1) Index: llvm-java/tools/class2llvm/class2llvm.cpp diff -u llvm-java/tools/class2llvm/class2llvm.cpp:1.1 llvm-java/tools/class2llvm/class2llvm.cpp:1.2 --- llvm-java/tools/class2llvm/class2llvm.cpp:1.1 Sat May 22 02:08:31 2004 +++ llvm-java/tools/class2llvm/class2llvm.cpp Sat May 22 18:25:22 2004 @@ -32,7 +32,9 @@ std::auto_ptr cf( Java::ClassFile::readClassFile(std::cin)); - Module* module = Java::compile(*cf); + Java::Compiler compiler; + + Module* module = compiler.compile(*cf); PassManager passes; passes.add(new PrintModulePass(&std::cout)); From alkis at cs.uiuc.edu Sat May 22 18:27:11 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 18:27:11 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405222325.SAA07934@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.2 -> 1.3 --- Log message: Put Java::compile free function in a Java::Compiler object. --- Diffs of the changes: (+374 -372) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.2 llvm-java/lib/Compiler/Compiler.cpp:1.3 --- llvm-java/lib/Compiler/Compiler.cpp:1.2 Sat May 22 17:49:14 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 22 18:25:22 2004 @@ -19,10 +19,9 @@ #include #include #include -#include -#include using namespace llvm; +using namespace llvm::Java; namespace { @@ -50,398 +49,401 @@ return (code[++i] << 8) | code[++i]; } - void compileMethod(Module& module, const Java::Method& method) { - using namespace llvm::Java::Opcode; - - Function* function = - module.getOrInsertFunction(method.getName()->str(), Type::VoidTy); +} // namespace - const Java::CodeAttribute* codeAttr = - Java::getCodeAttribute(method.getAttributes()); +void Compiler::initForCode(const CodeAttribute& codeAttr) +{ + while (!opStack_.empty()) + opStack_.pop(); - typedef std::stack OperandStack; - OperandStack opStack; - typedef std::vector Locals; - Locals locals(codeAttr->getMaxLocals(), 0); - - const uint8_t* code = codeAttr->getCode(); - for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { - unsigned bcStart = i; - bool wide = code[i] == WIDE; - i += wide; - switch (code[i]) { - case ACONST_NULL: - // FIXME: should push a null pointer of type Object* - opStack.push( - ConstantPointerNull::get(PointerType::get(Type::VoidTy))); - break; - case ICONST_M1: - case ICONST_0: - case ICONST_1: - case ICONST_2: - case ICONST_3: - case ICONST_4: - case ICONST_5: - opStack.push(ConstantInt::get(Type::IntTy, code[i]-ICONST_0)); - break; - case LCONST_0: - case LCONST_1: - opStack.push(ConstantInt::get(Type::LongTy, code[i]-LCONST_0)); - break; - case FCONST_0: - case FCONST_1: - case FCONST_2: - opStack.push(ConstantFP::get(Type::FloatTy, code[i]-FCONST_0)); - break; - case DCONST_0: - case DCONST_1: - opStack.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); - break; - case BIPUSH: { - int imm = readByteImmediate(code, i); - opStack.push(ConstantInt::get(Type::IntTy, imm)); - break; - } - case SIPUSH: { - int imm = readShortImmediate(code, i); - opStack.push(ConstantInt::get(Type::IntTy, imm)); - break; - } - case LDC: { - unsigned index = readByteIndex(code, i); - // FIXME: load constant from constant pool - } - case LDC_W: { - unsigned index = readShortIndex(code, i); - // FIXME: load constant from constant pool - } - case LDC2_W: { - unsigned index = readShortIndex(code, i); - // FIXME: load constant from constant pool - } - case ILOAD: - case LLOAD: - case FLOAD: - case DLOAD: - case ALOAD: { - // FIXME: use opcodes to perform type checking - unsigned index = readByteIndex(code, i); - opStack.push(locals[index]); - break; - } - case ILOAD_0: - case ILOAD_1: - case ILOAD_2: - case ILOAD_3: - opStack.push(locals[code[i]-ILOAD_0]); - break; - case LLOAD_0: - case LLOAD_1: - case LLOAD_2: - case LLOAD_3: - opStack.push(locals[code[i]-LLOAD_0]); - break; - case FLOAD_0: - case FLOAD_1: - case FLOAD_2: - case FLOAD_3: - opStack.push(locals[code[i]-FLOAD_0]); - break; - case DLOAD_0: - case DLOAD_1: - case DLOAD_2: - case DLOAD_3: - opStack.push(locals[code[i]-DLOAD_0]); - break; - case ALOAD_0: - case ALOAD_1: - case ALOAD_2: - case ALOAD_3: - opStack.push(locals[code[i]-ALOAD_0]); - break; - case IALOAD: - case LALOAD: - case FALOAD: - case DALOAD: - case AALOAD: - case BALOAD: - case CALOAD: - case SALOAD: - case ISTORE: - case LSTORE: - case FSTORE: - case DSTORE: - case ASTORE: - case ISTORE_0: - case ISTORE_1: - case ISTORE_2: - case ISTORE_3: - case LSTORE_0: - case LSTORE_1: - case LSTORE_2: - case LSTORE_3: - case FSTORE_0: - case FSTORE_1: - case FSTORE_2: - case FSTORE_3: - case DSTORE_0: - case DSTORE_1: - case DSTORE_2: - case DSTORE_3: - case ASTORE_0: - case ASTORE_1: - case ASTORE_2: - case ASTORE_3: - case IASTORE: - case LASTORE: - case FASTORE: - case DASTORE: - case AASTORE: - case BASTORE: - case CASTORE: - case SASTORE: - assert(0 && "not implemented"); - case POP: - opStack.pop(); - break; - case POP2: - opStack.pop(); - opStack.pop(); - break; - case DUP: - opStack.push(opStack.top()); - break; - case DUP_X1: { - Value* v1 = opStack.top(); opStack.pop(); - Value* v2 = opStack.top(); opStack.pop(); - opStack.push(v1); - opStack.push(v2); - opStack.push(v1); - break; + locals_.clear(); + locals_.assign(codeAttr.getMaxLocals(), NULL); +} + +void Compiler::compileMethod(Module& module, const Java::Method& method) { + using namespace llvm::Java::Opcode; + + const Java::CodeAttribute* codeAttr = + Java::getCodeAttribute(method.getAttributes()); + + initForCode(*codeAttr); + + Function* function = + module.getOrInsertFunction(method.getName()->str(), Type::VoidTy); + + const uint8_t* code = codeAttr->getCode(); + for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { + unsigned bcStart = i; + bool wide = code[i] == WIDE; + i += wide; + switch (code[i]) { + case ACONST_NULL: + // FIXME: should push a null pointer of type Object* + opStack_.push( + ConstantPointerNull::get(PointerType::get(Type::VoidTy))); + break; + case ICONST_M1: + case ICONST_0: + case ICONST_1: + case ICONST_2: + case ICONST_3: + case ICONST_4: + case ICONST_5: + opStack_.push(ConstantInt::get(Type::IntTy, code[i]-ICONST_0)); + break; + case LCONST_0: + case LCONST_1: + opStack_.push(ConstantInt::get(Type::LongTy, code[i]-LCONST_0)); + break; + case FCONST_0: + case FCONST_1: + case FCONST_2: + opStack_.push(ConstantFP::get(Type::FloatTy, code[i]-FCONST_0)); + break; + case DCONST_0: + case DCONST_1: + opStack_.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); + break; + case BIPUSH: { + int imm = readByteImmediate(code, i); + opStack_.push(ConstantInt::get(Type::IntTy, imm)); + break; + } + case SIPUSH: { + int imm = readShortImmediate(code, i); + opStack_.push(ConstantInt::get(Type::IntTy, imm)); + break; + } + case LDC: { + unsigned index = readByteIndex(code, i); + // FIXME: load constant from constant pool + } + case LDC_W: { + unsigned index = readShortIndex(code, i); + // FIXME: load constant from constant pool + } + case LDC2_W: { + unsigned index = readShortIndex(code, i); + // FIXME: load constant from constant pool + } + case ILOAD: + case LLOAD: + case FLOAD: + case DLOAD: + case ALOAD: { + // FIXME: use opcodes to perform type checking + unsigned index = readByteIndex(code, i); + opStack_.push(locals_[index]); + break; + } + case ILOAD_0: + case ILOAD_1: + case ILOAD_2: + case ILOAD_3: + opStack_.push(locals_[code[i]-ILOAD_0]); + break; + case LLOAD_0: + case LLOAD_1: + case LLOAD_2: + case LLOAD_3: + opStack_.push(locals_[code[i]-LLOAD_0]); + break; + case FLOAD_0: + case FLOAD_1: + case FLOAD_2: + case FLOAD_3: + opStack_.push(locals_[code[i]-FLOAD_0]); + break; + case DLOAD_0: + case DLOAD_1: + case DLOAD_2: + case DLOAD_3: + opStack_.push(locals_[code[i]-DLOAD_0]); + break; + case ALOAD_0: + case ALOAD_1: + case ALOAD_2: + case ALOAD_3: + opStack_.push(locals_[code[i]-ALOAD_0]); + break; + case IALOAD: + case LALOAD: + case FALOAD: + case DALOAD: + case AALOAD: + case BALOAD: + case CALOAD: + case SALOAD: + case ISTORE: + case LSTORE: + case FSTORE: + case DSTORE: + case ASTORE: + case ISTORE_0: + case ISTORE_1: + case ISTORE_2: + case ISTORE_3: + case LSTORE_0: + case LSTORE_1: + case LSTORE_2: + case LSTORE_3: + case FSTORE_0: + case FSTORE_1: + case FSTORE_2: + case FSTORE_3: + case DSTORE_0: + case DSTORE_1: + case DSTORE_2: + case DSTORE_3: + case ASTORE_0: + case ASTORE_1: + case ASTORE_2: + case ASTORE_3: + case IASTORE: + case LASTORE: + case FASTORE: + case DASTORE: + case AASTORE: + case BASTORE: + case CASTORE: + case SASTORE: + assert(0 && "not implemented"); + case POP: + opStack_.pop(); + break; + case POP2: + opStack_.pop(); + opStack_.pop(); + break; + case DUP: + opStack_.push(opStack_.top()); + break; + case DUP_X1: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + opStack_.push(v1); + opStack_.push(v2); + opStack_.push(v1); + break; + } + case DUP_X2: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + if (isOneSlotValue(v2)) { + Value* v3 = opStack_.top(); opStack_.pop(); + opStack_.push(v1); + opStack_.push(v3); + opStack_.push(v2); + opStack_.push(v1); + } + else { + opStack_.push(v1); + opStack_.push(v2); + opStack_.push(v1); } - case DUP_X2: { - Value* v1 = opStack.top(); opStack.pop(); - Value* v2 = opStack.top(); opStack.pop(); - if (isOneSlotValue(v2)) { - Value* v3 = opStack.top(); opStack.pop(); - opStack.push(v1); - opStack.push(v3); - opStack.push(v2); - opStack.push(v1); - } - else { - opStack.push(v1); - opStack.push(v2); - opStack.push(v1); - } - break; + break; + } + case DUP2: { + Value* v1 = opStack_.top(); opStack_.pop(); + if (isOneSlotValue(v1)) { + Value* v2 = opStack_.top(); opStack_.pop(); + opStack_.push(v2); + opStack_.push(v1); + opStack_.push(v2); + opStack_.push(v1); + } + else { + opStack_.push(v1); + opStack_.push(v1); } - case DUP2: { - Value* v1 = opStack.top(); opStack.pop(); - if (isOneSlotValue(v1)) { - Value* v2 = opStack.top(); opStack.pop(); - opStack.push(v2); - opStack.push(v1); - opStack.push(v2); - opStack.push(v1); - } - else { - opStack.push(v1); - opStack.push(v1); - } - break; + break; + } + case DUP2_X1: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + if (isOneSlotValue(v1)) { + Value* v3 = opStack_.top(); opStack_.pop(); + opStack_.push(v2); + opStack_.push(v1); + opStack_.push(v3); + opStack_.push(v2); + opStack_.push(v1); + } + else { + opStack_.push(v1); + opStack_.push(v2); + opStack_.push(v1); } - case DUP2_X1: { - Value* v1 = opStack.top(); opStack.pop(); - Value* v2 = opStack.top(); opStack.pop(); - if (isOneSlotValue(v1)) { - Value* v3 = opStack.top(); opStack.pop(); - opStack.push(v2); - opStack.push(v1); - opStack.push(v3); - opStack.push(v2); - opStack.push(v1); + break; + } + case DUP2_X2: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + if (isOneSlotValue(v1)) { + Value* v3 = opStack_.top(); opStack_.pop(); + if (isOneSlotValue(v3)) { + Value* v4 = opStack_.top(); opStack_.pop(); + opStack_.push(v2); + opStack_.push(v1); + opStack_.push(v4); + opStack_.push(v3); + opStack_.push(v2); + opStack_.push(v1); } else { - opStack.push(v1); - opStack.push(v2); - opStack.push(v1); + opStack_.push(v2); + opStack_.push(v1); + opStack_.push(v3); + opStack_.push(v2); + opStack_.push(v1); } - break; } - case DUP2_X2: { - Value* v1 = opStack.top(); opStack.pop(); - Value* v2 = opStack.top(); opStack.pop(); - if (isOneSlotValue(v1)) { - Value* v3 = opStack.top(); opStack.pop(); - if (isOneSlotValue(v3)) { - Value* v4 = opStack.top(); opStack.pop(); - opStack.push(v2); - opStack.push(v1); - opStack.push(v4); - opStack.push(v3); - opStack.push(v2); - opStack.push(v1); - } - else { - opStack.push(v2); - opStack.push(v1); - opStack.push(v3); - opStack.push(v2); - opStack.push(v1); - } + else { + if (isOneSlotValue(v2)) { + Value* v3 = opStack_.top(); opStack_.pop(); + opStack_.push(v1); + opStack_.push(v3); + opStack_.push(v2); + opStack_.push(v1); } else { - if (isOneSlotValue(v2)) { - Value* v3 = opStack.top(); opStack.pop(); - opStack.push(v1); - opStack.push(v3); - opStack.push(v2); - opStack.push(v1); - } - else { - opStack.push(v1); - opStack.push(v2); - opStack.push(v1); - } + opStack_.push(v1); + opStack_.push(v2); + opStack_.push(v1); } - break; - } - case SWAP: { - Value* v1 = opStack.top(); opStack.pop(); - Value* v2 = opStack.top(); opStack.pop(); - opStack.push(v1); - opStack.push(v2); - break; - } - case IADD: - case LADD: - case FADD: - case DADD: - case ISUB: - case LSUB: - case FSUB: - case DSUB: - case IMUL: - case LMUL: - case FMUL: - case DMUL: - case IDIV: - case LDIV: - case FDIV: - case DDIV: - case IREM: - case LREM: - case FREM: - case DREM: - case INEG: - case LNEG: - case FNEG: - case DNEG: - case ISHL: - case LSHL: - case ISHR: - case LSHR: - case IUSHR: - case LUSHR: - case IAND: - case LAND: - case IOR: - case LOR: - case IXOR: - case LXOR: - case IINC: - case I2L: - case I2F: - case I2D: - case L2I: - case L2F: - case L2D: - case F2I: - case F2L: - case F2D: - case D2I: - case D2L: - case D2F: - case I2B: - case I2C: - case I2S: - case LCMP: - case FCMPL: - case FCMPG: - case DCMPL: - case DCMPG: - case IFEQ: - case IFNE: - case IFLT: - case IFGE: - case IFGT: - case IFLE: - case IF_ICMPEQ: - case IF_ICMPNE: - case IF_ICMPLT: - case IF_ICMPGE: - case IF_ICMPGT: - case IF_ICMPLE: - case IF_ICMPACMPEQ: - case IF_ICMPACMPNE: - case GOTO: - case JSR: - case RET: - case TABLESWITCH: - case LOOKUPSWITCH: - case IRETURN: - case LRETURN: - case FRETURN: - case DRETURN: - case ARETURN: - case RETURN: - case GETSTATIC: - case PUTSTATIC: - case GETFIELD: - case PUTFIELD: - case INVOKEVIRTUAL: - case INVOKESPECIAL: - case INVOKESTATIC: - case INVOKEINTERFACE: - case XXXUNUSEDXXX: - case NEW: - case NEWARRAY: - case ANEWARRAY: - case ARRAYLENGTH: - case ATHROW: - case CHECKCAST: - case INSTANCEOF: - case MONITORENTER: - case MONITOREXIT: - case WIDE: - case MULTIANEWARRAY: - case IFNULL: - case IFNONNULL: - case GOTO_W: - case JSR_W: - case BREAKPOINT: - case IMPDEP1: - case IMPDEP2: - case NOP: - break; } + break; + } + case SWAP: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + opStack_.push(v1); + opStack_.push(v2); + break; + } + case IADD: + case LADD: + case FADD: + case DADD: + case ISUB: + case LSUB: + case FSUB: + case DSUB: + case IMUL: + case LMUL: + case FMUL: + case DMUL: + case IDIV: + case LDIV: + case FDIV: + case DDIV: + case IREM: + case LREM: + case FREM: + case DREM: + case INEG: + case LNEG: + case FNEG: + case DNEG: + case ISHL: + case LSHL: + case ISHR: + case LSHR: + case IUSHR: + case LUSHR: + case IAND: + case LAND: + case IOR: + case LOR: + case IXOR: + case LXOR: + case IINC: + case I2L: + case I2F: + case I2D: + case L2I: + case L2F: + case L2D: + case F2I: + case F2L: + case F2D: + case D2I: + case D2L: + case D2F: + case I2B: + case I2C: + case I2S: + case LCMP: + case FCMPL: + case FCMPG: + case DCMPL: + case DCMPG: + case IFEQ: + case IFNE: + case IFLT: + case IFGE: + case IFGT: + case IFLE: + case IF_ICMPEQ: + case IF_ICMPNE: + case IF_ICMPLT: + case IF_ICMPGE: + case IF_ICMPGT: + case IF_ICMPLE: + case IF_ICMPACMPEQ: + case IF_ICMPACMPNE: + case GOTO: + case JSR: + case RET: + case TABLESWITCH: + case LOOKUPSWITCH: + case IRETURN: + case LRETURN: + case FRETURN: + case DRETURN: + case ARETURN: + case RETURN: + case GETSTATIC: + case PUTSTATIC: + case GETFIELD: + case PUTFIELD: + case INVOKEVIRTUAL: + case INVOKESPECIAL: + case INVOKESTATIC: + case INVOKEINTERFACE: + case XXXUNUSEDXXX: + case NEW: + case NEWARRAY: + case ANEWARRAY: + case ARRAYLENGTH: + case ATHROW: + case CHECKCAST: + case INSTANCEOF: + case MONITORENTER: + case MONITOREXIT: + case WIDE: + case MULTIANEWARRAY: + case IFNULL: + case IFNONNULL: + case GOTO_W: + case JSR_W: + case BREAKPOINT: + case IMPDEP1: + case IMPDEP2: + case NOP: + break; } } +} -} // namespace - -Module* llvm::Java::compile(const ClassFile& cf) +Module* Compiler::compile(const ClassFile& cf) { Module* module = new Module(cf.getThisClass()->getName()->str()); - std::vector opStack; - const Java::Methods& methods = cf.getMethods(); for (Java::Methods::const_iterator - i = methods.begin(), e = methods.end(); i != e; ++i) { + i = methods.begin(), e = methods.end(); i != e; ++i) compileMethod(*module, **i); - } return module; } From gaeke at cs.uiuc.edu Sat May 22 19:11:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 19:11:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405230010.TAA03707@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.64 -> 1.65 --- Log message: Simplify the interface to retrieving register allocation state. Remove a dead reference to TF->LiveOutSet. --- Diffs of the changes: (+13 -9) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.64 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.65 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.64 Fri May 21 02:58:43 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sat May 22 19:09:59 2004 @@ -232,6 +232,12 @@ regsUsed.insert (fp); } +static std::pair +getValueAllocState (TraceFunction *TF, Value *V) { + return std::make_pair (getValueAllocStateFromModule (TF->MatrixFn, V), + getValueAllocStateFromGlobal (TF->TraceFn, TF->getCorrespondingValue (V))); +} + void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { const TargetRegInfo &TRI = TM->getRegInfo (); @@ -297,7 +303,7 @@ // 4. Insert copies from each live-in variable's reg. in the matrix fn. // to its reg. in the trace. Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn; - LiveVariableSet &Si = TF->LiveInSet, &So = TF->LiveOutSet; + LiveVariableSet &Si = TF->LiveInSet; std::vector EntryCopies; for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; ++SI) { @@ -306,11 +312,10 @@ << "rewriteProlog: Getting alloc state for live-in value "; WriteAsOperand (std::cerr, V, true, true, MatrixF->getParent ()); std::cerr << "\n"); - AllocInfo Source = getValueAllocStateFromModule (MatrixF, V), - Target = getValueAllocStateFromGlobal (TraceF, - TF->getCorrespondingValue (V)); - DEBUG(std::cerr << "rewriteProlog: Source = " << Source << "\n" - << "rewriteProlog: Target = " << Target << "\n"); + std::pair ai = getValueAllocState (TF, V); + AllocInfo &Source = ai.first, &Target = ai.second; + DEBUG(std::cerr << "rewriteProlog: Source in MatrixFn = " << Source << "\n" + << "rewriteProlog: Target in TraceFn = " << Target << "\n"); if (Source != Target) EntryCopies.push_back (CopyInfo (Source, Target, &E, V->getType ())); } @@ -495,9 +500,8 @@ for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); SI != SE; ++SI) { Value *V = *SI; - AllocInfo Source = - getValueAllocStateFromGlobal (TraceF, TF->getCorrespondingValue (V)); - AllocInfo Target = getValueAllocStateFromModule (MatrixF, V); + std::pair ai = getValueAllocState (TF, V); + AllocInfo &Target = ai.first, &Source = ai.second; if (Source != Target) insertCopyMachineInstrs (Source, Target, MBB, V->getType ()); } From alkis at cs.uiuc.edu Sat May 22 19:20:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 19:20:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405230018.TAA08130@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.3 -> 1.4 --- Log message: Rename utility functions for reading immediates from bytecode. Add functions to read ints as well. --- Diffs of the changes: (+24 -13) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.3 llvm-java/lib/Compiler/Compiler.cpp:1.4 --- llvm-java/lib/Compiler/Compiler.cpp:1.3 Sat May 22 18:25:22 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 22 19:18:36 2004 @@ -33,20 +33,31 @@ return !isTwoSlotValue(v); } - inline int readByteImmediate(const uint8_t* code, unsigned& i) { + inline int readByteSigned(const uint8_t* code, unsigned& i) { return code[++i]; } - inline int readShortImmediate(const uint8_t* code, unsigned& i) { - return (code[++i] << 8) | code[++i]; + inline unsigned readByteUnsigned(const uint8_t* code, unsigned& i) { + return code[++i]; } - inline unsigned readByteIndex(const uint8_t* code, unsigned& i) { - return code[++i]; + inline int readShortSigned(const uint8_t* code, unsigned& i) { + return (readByteSigned(code, i) << 8) | readByteUnsigned(code, i); + } + + inline unsigned readShortUnsigned(const uint8_t* code, unsigned& i) { + return (readByteUnsigned(code, i) << 8) | readByteUnsigned(code, i); + } + + inline int readIntSigned(const uint8_t* code, unsigned& i) { + return ((readByteUnsigned(code, i) << 24) | + (readByteUnsigned(code, i) << 16) | + (readByteUnsigned(code, i) << 8) | + readByteUnsigned(code, i)); } - inline unsigned readShortIndex(const uint8_t* code, unsigned& i) { - return (code[++i] << 8) | code[++i]; + inline unsigned readIntUnsigned(const uint8_t* code, unsigned& i) { + return readIntSigned(code, i); } } // namespace @@ -105,25 +116,25 @@ opStack_.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); break; case BIPUSH: { - int imm = readByteImmediate(code, i); + int imm = readByteSigned(code, i); opStack_.push(ConstantInt::get(Type::IntTy, imm)); break; } case SIPUSH: { - int imm = readShortImmediate(code, i); + int imm = readShortSigned(code, i); opStack_.push(ConstantInt::get(Type::IntTy, imm)); break; } case LDC: { - unsigned index = readByteIndex(code, i); + unsigned index = readByteUnsigned(code, i); // FIXME: load constant from constant pool } case LDC_W: { - unsigned index = readShortIndex(code, i); + unsigned index = readShortUnsigned(code, i); // FIXME: load constant from constant pool } case LDC2_W: { - unsigned index = readShortIndex(code, i); + unsigned index = readShortUnsigned(code, i); // FIXME: load constant from constant pool } case ILOAD: @@ -132,7 +143,7 @@ case DLOAD: case ALOAD: { // FIXME: use opcodes to perform type checking - unsigned index = readByteIndex(code, i); + unsigned index = readByteUnsigned(code, i); opStack_.push(locals_[index]); break; } From alkis at cs.uiuc.edu Sat May 22 20:18:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 20:18:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405230116.UAA08351@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.4 -> 1.5 --- Log message: Rename initForCode() to methodCompileInit(). Create a bytecode to llvm::BasicBlock* map in a separate pass before compilation. --- Diffs of the changes: (+130 -5) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.4 llvm-java/lib/Compiler/Compiler.cpp:1.5 --- llvm-java/lib/Compiler/Compiler.cpp:1.4 Sat May 22 19:18:36 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 22 20:15:53 2004 @@ -19,6 +19,7 @@ #include #include #include +#include using namespace llvm; using namespace llvm::Java; @@ -60,27 +61,151 @@ return readIntSigned(code, i); } + inline void skipPadBytes(const uint8_t* code, unsigned& i) { + while (((unsigned)&code[++i]) & 0XFF); + } + } // namespace -void Compiler::initForCode(const CodeAttribute& codeAttr) +void Compiler::compileMethodInit(Function& function, + const CodeAttribute& codeAttr) { while (!opStack_.empty()) opStack_.pop(); locals_.clear(); locals_.assign(codeAttr.getMaxLocals(), NULL); + + bc2bbMap_.clear(); + bc2bbMap_.assign(codeAttr.getCodeSize(), NULL); + bc2bbMap_[0] = new BasicBlock("entry", &function); + + const uint8_t* code = codeAttr.getCode(); + for (unsigned i = 0; i < codeAttr.getCodeSize(); ++i) { + using namespace llvm::Java::Opcode; + + unsigned bcStart = i; + bool wide = code[i] == WIDE; + i += wide; + switch (code[i]) { + case BIPUSH: + case LDC: + case NEWARRAY: + ++i; + break; + case ILOAD: + case LLOAD: + case FLOAD: + case DLOAD: + case ALOAD: + case ISTORE: + case LSTORE: + case FSTORE: + case DSTORE: + case ASTORE: + case RET: + i += 1 + wide; + break; + case SIPUSH: + case LDC_W: + case LDC2_W: + case GOTO: + case JSR: + case GETSTATIC: + case PUTSTATIC: + case GETFIELD: + case PUTFIELD: + case INVOKEVIRTUAL: + case INVOKESPECIAL: + case INVOKESTATIC: + case INVOKEINTERFACE: + case NEW: + case ANEWARRAY: + case ARRAYLENGTH: + case ATHROW: + case CHECKCAST: + case INSTANCEOF: + i += 2; + break; + case IFEQ: + case IFNE: + case IFLT: + case IFGE: + case IFGT: + case IFLE: + case IF_ICMPEQ: + case IF_ICMPNE: + case IF_ICMPLT: + case IF_ICMPGE: + case IF_ICMPGT: + case IF_ICMPLE: + case IF_ICMPACMPEQ: + case IF_ICMPACMPNE: + case IFNULL: + case IFNONNULL: { + unsigned index = readShortUnsigned(code, i); + bc2bbMap_[bcStart] = new BasicBlock( + std::string("bb at bc") + utostr(bcStart), &function); + break; + } + case TABLESWITCH: { + skipPadBytes(code, i); + readIntSigned(code, i); + int low = readIntSigned(code, i); + int high = readIntSigned(code, i); + unsigned offsetCount = high - low + 1; + while (offsetCount--) { + unsigned bcIndex = bcStart + readIntSigned(code, i); + bc2bbMap_[bcIndex] = new BasicBlock( + std::string("bb at bc") + utostr(bcIndex), &function); + } + break; + } + case LOOKUPSWITCH: { + skipPadBytes(code, i); + unsigned pairCount = readIntUnsigned(code, i); + while (pairCount--) { + readIntSigned(code, i); + unsigned bcIndex = bcStart + readIntSigned(code, i); + bc2bbMap_[bcIndex] = new BasicBlock( + std::string("bb at bc") + utostr(bcIndex), &function); + } + break; + } + case XXXUNUSEDXXX: + throw "FIXME: create new exception class"; + case MULTIANEWARRAY: + i += 3; + break; + case GOTO_W: + case JSR_W: + i+= 4; + break; + default: + break; + } + } + + unsigned i = 0; + BasicBlock* bb = bc2bbMap_[i]; + while (++i < codeAttr.getCodeSize()) { + if (bc2bbMap_[i]) + bc2bbMap_[i] = bb; + else + bb = bc2bbMap_[i]; + } } void Compiler::compileMethod(Module& module, const Java::Method& method) { using namespace llvm::Java::Opcode; + Function* function = + module.getOrInsertFunction(method.getName()->str(), Type::VoidTy); + const Java::CodeAttribute* codeAttr = Java::getCodeAttribute(method.getAttributes()); - initForCode(*codeAttr); - - Function* function = - module.getOrInsertFunction(method.getName()->str(), Type::VoidTy); + compileMethodInit(*function, *codeAttr); const uint8_t* code = codeAttr->getCode(); for (unsigned i = 0; i < codeAttr->getCodeSize(); ++i) { From alkis at cs.uiuc.edu Sat May 22 20:18:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 20:18:09 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Compiler.h Message-ID: <200405230116.UAA08356@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Compiler.h updated: 1.2 -> 1.3 --- Log message: Rename initForCode() to methodCompileInit(). Create a bytecode to llvm::BasicBlock* map in a separate pass before compilation. --- Diffs of the changes: (+4 -1) Index: llvm-java/include/llvm/Java/Compiler.h diff -u llvm-java/include/llvm/Java/Compiler.h:1.2 llvm-java/include/llvm/Java/Compiler.h:1.3 --- llvm-java/include/llvm/Java/Compiler.h:1.2 Sat May 22 18:25:22 2004 +++ llvm-java/include/llvm/Java/Compiler.h Sat May 22 20:15:53 2004 @@ -25,15 +25,18 @@ Module* compile(const ClassFile& cf); private: + void compileMethodInit(Function& function, + const CodeAttribute& codeAttr); void compileMethod(Module& module, const Method& method); - void initForCode(const CodeAttribute& codeAttr); private: typedef std::stack > OperandStack; typedef std::vector Locals; + typedef std::vector BC2BBMap; OperandStack opStack_; Locals locals_; + BC2BBMap bc2bbMap_; }; } } // namespace llvm::Java From alkis at cs.uiuc.edu Sat May 22 20:26:05 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 20:26:05 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405230124.UAA08403@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.5 -> 1.6 --- Log message: Make correct byte skips for local variable increament. --- Diffs of the changes: (+3 -0) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.5 llvm-java/lib/Compiler/Compiler.cpp:1.6 --- llvm-java/lib/Compiler/Compiler.cpp:1.5 Sat May 22 20:15:53 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 22 20:24:43 2004 @@ -127,6 +127,9 @@ case INSTANCEOF: i += 2; break; + case IINC: + i += 2 * (1 + wide); + break; case IFEQ: case IFNE: case IFLT: From gaeke at cs.uiuc.edu Sat May 22 21:03:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sat May 22 21:03:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405230202.VAA04409@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.65 -> 1.66 --- Log message: Save live-in values that originate in MatrixFn's register on TraceFn's stack. (Still need to reload them into TraceFn's registers from there.) Remove some dead references from rewriteProlog(). --- Diffs of the changes: (+25 -9) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.65 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.66 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.65 Sat May 22 19:09:59 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sat May 22 21:02:13 2004 @@ -270,11 +270,30 @@ E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-Size).addMReg (sp, MachineOperand::Def)); + std::set regsToSave (regsUsed); + // Save live-in values in registers onto the stack + LiveVariableSet &Si = TF->LiveInSet; + std::map > AllocStates; + for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; + ++SI) { + Value *V = *SI; + std::pair > as = + std::make_pair (V, getValueAllocState (TF, V)); + AllocStates.insert (as); + AllocInfo &Source = as.second.first, &Target = as.second.second; + if (Source != Target) + if (Source.AllocState == AllocInfo::Allocated) { + DEBUG (std::cerr << "Need to save incoming live value in reg " + << Source.Placement << " onto the stack\n"); + regsToSave.insert (Source.Placement); + } + } + // 3. Save used registers onto the stack. std::vector mvec; int RegType; - for (std::set::iterator i = regsUsed.begin (), e = regsUsed.end (); - i != e; ++i) { + for (std::set::iterator i = regsToSave.begin (), + e = regsToSave.end (); i != e; ++i) { mvec.clear (); unsigned R = *i; unsigned RegType = TRI.getRegType (R); @@ -300,25 +319,22 @@ } } + // 4. Insert copies from each live-in variable's reg. in the matrix fn. // to its reg. in the trace. - Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn; - LiveVariableSet &Si = TF->LiveInSet; + Function *MatrixF = TF->MatrixFn; std::vector EntryCopies; for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; ++SI) { Value *V = *SI; - DEBUG(std::cerr - << "rewriteProlog: Getting alloc state for live-in value "; - WriteAsOperand (std::cerr, V, true, true, MatrixF->getParent ()); - std::cerr << "\n"); - std::pair ai = getValueAllocState (TF, V); + std::pair &ai = AllocStates[V]; AllocInfo &Source = ai.first, &Target = ai.second; DEBUG(std::cerr << "rewriteProlog: Source in MatrixFn = " << Source << "\n" << "rewriteProlog: Target in TraceFn = " << Target << "\n"); if (Source != Target) EntryCopies.push_back (CopyInfo (Source, Target, &E, V->getType ())); } + for (std::vector::iterator i = EntryCopies.begin (), e = EntryCopies.end (); i != e; ++i) { DEBUG(std::cerr << "rewriteProlog: Inserting copy " << *i << "\n"); From alkis at cs.uiuc.edu Sat May 22 21:10:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sat May 22 21:10:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405230208.VAA08527@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.6 -> 1.7 --- Log message: Fix pop2 compilation. --- Diffs of the changes: (+5 -3) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.6 llvm-java/lib/Compiler/Compiler.cpp:1.7 --- llvm-java/lib/Compiler/Compiler.cpp:1.6 Sat May 22 20:24:43 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sat May 22 21:08:01 2004 @@ -350,10 +350,12 @@ case POP: opStack_.pop(); break; - case POP2: - opStack_.pop(); - opStack_.pop(); + case POP2: { + Value* v1 = opStack_.top(); opStack_.pop(); + if (isOneSlotValue(v1)) + opStack_.pop(); break; + } case DUP: opStack_.push(opStack_.top()); break; From gaeke at cs.uiuc.edu Sun May 23 00:06:02 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 00:06:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/CodeGen/MachineInstrBuilder.h Message-ID: <200405230504.AAA09340@zion.cs.uiuc.edu> Changes in directory llvm/include/llvm/CodeGen: MachineInstrBuilder.h updated: 1.21 -> 1.22 --- Log message: Fix a typo in the head-of-file comment. Rewrite the comments about the different versions of BuildMI, to better emphasize their differences. --- Diffs of the changes: (+21 -14) Index: llvm/include/llvm/CodeGen/MachineInstrBuilder.h diff -u llvm/include/llvm/CodeGen/MachineInstrBuilder.h:1.21 llvm/include/llvm/CodeGen/MachineInstrBuilder.h:1.22 --- llvm/include/llvm/CodeGen/MachineInstrBuilder.h:1.21 Wed Mar 31 22:03:10 2004 +++ llvm/include/llvm/CodeGen/MachineInstrBuilder.h Sun May 23 00:04:00 2004 @@ -10,7 +10,7 @@ // This file exposes a function named BuildMI, which is useful for dramatically // simplifying how MachineInstr's are created. Instead of using code like this: // -// M = new MachineInstr(X86::ADDrr32); +// M = new MachineInstr(X86::ADDrr8); // M->SetMachineOperandVal(0, MachineOperand::MO_VirtualRegister, argVal1); // M->SetMachineOperandVal(1, MachineOperand::MO_VirtualRegister, argVal2); // @@ -144,9 +144,9 @@ return MachineInstrBuilder(new MachineInstr(Opcode, NumOperands, true, true)); } -/// BuildMI - This version of the builder also sets up the first "operand" as a +/// BuildMI - This version of the builder sets up the first operand as a /// destination virtual register. NumOperands is the number of additional add* -/// calls that are expected, it does not include the destination register. +/// calls that are expected, not including the destination register. /// inline MachineInstrBuilder BuildMI( int Opcode, unsigned NumOperands, @@ -156,9 +156,12 @@ true, true)).addReg(DestReg, useType); } - -/// BuildMI - Insert the instruction before a specified location in the basic -/// block. +/// BuildMI - This version of the builder inserts the newly-built +/// instruction before the given position in the given MachineBasicBlock, and +/// sets up the first operand as a destination virtual register. +/// NumOperands is the number of additional add* calls that are expected, +/// not including the destination register. +/// inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineBasicBlock::iterator I, int Opcode, unsigned NumOperands, @@ -168,8 +171,10 @@ return MachineInstrBuilder(MI).addReg(DestReg, MachineOperand::Def); } -/// BMI - A special BuildMI variant that takes an iterator to insert the -/// instruction at as well as a basic block. +/// BuildMI - This version of the builder inserts the newly-built +/// instruction before the given position in the given MachineBasicBlock, and +/// does NOT take a destination register. +/// inline MachineInstrBuilder BuildMI(MachineBasicBlock &BB, MachineBasicBlock::iterator I, int Opcode, unsigned NumOperands) { @@ -178,18 +183,20 @@ return MachineInstrBuilder(MI); } -/// BuildMI - This version of the builder inserts the built MachineInstr into -/// the specified MachineBasicBlock. +/// BuildMI - This version of the builder inserts the newly-built +/// instruction at the end of the given MachineBasicBlock, and does NOT take a +/// destination register. /// inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode, unsigned NumOperands) { return BuildMI(*BB, BB->end(), Opcode, NumOperands); } -/// BuildMI - This version of the builder inserts the built MachineInstr into -/// the specified MachineBasicBlock, and also sets up the first "operand" as a -/// destination virtual register. NumOperands is the number of additional add* -/// calls that are expected, it does not include the destination register. +/// BuildMI - This version of the builder inserts the newly-built +/// instruction at the end of the given MachineBasicBlock, and sets up the first +/// operand as a destination virtual register. NumOperands is the number of +/// additional add* calls that are expected, not including the destination +/// register. /// inline MachineInstrBuilder BuildMI(MachineBasicBlock *BB, int Opcode, unsigned NumOperands, unsigned DestReg) { From gaeke at cs.uiuc.edu Sun May 23 00:11:03 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 00:11:03 2004 Subject: [llvm-commits] CVS: llvm/lib/Target/SparcV9/SparcV9InstrSelection.cpp Message-ID: <200405230510.AAA04993@seraph.cs.uiuc.edu> Changes in directory llvm/lib/Target/SparcV9: SparcV9InstrSelection.cpp updated: 1.140 -> 1.141 --- Log message: Fix a typo in a comment. --- Diffs of the changes: (+1 -1) Index: llvm/lib/Target/SparcV9/SparcV9InstrSelection.cpp diff -u llvm/lib/Target/SparcV9/SparcV9InstrSelection.cpp:1.140 llvm/lib/Target/SparcV9/SparcV9InstrSelection.cpp:1.141 --- llvm/lib/Target/SparcV9/SparcV9InstrSelection.cpp:1.140 Sun Apr 25 02:04:49 2004 +++ llvm/lib/Target/SparcV9/SparcV9InstrSelection.cpp Sun May 23 00:10:06 2004 @@ -2867,7 +2867,7 @@ // Make sure not to substitute an upwards-exposed use -- that would // introduce a use of `tmpI' with no preceding def. Therefore, // substitute a use or def-and-use operand only if a previous def - // operand has already been substituted (i.e., numSusbt > 0). + // operand has already been substituted (i.e., numSubst > 0). // numSubst += mvec[i]->substituteValue(dest, tmpI, /*defsOnly*/ numSubst == 0, From vadve at cs.uiuc.edu Sun May 23 02:36:02 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 02:36:02 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Analysis/DSNode.h Message-ID: <200405230735.CAA31737@psmith.cs.uiuc.edu> Changes in directory llvm/include/llvm/Analysis: DSNode.h updated: 1.41 -> 1.42 --- Log message: Fix size/offset assertion to allow negative offsets and folded nodes. --- Diffs of the changes: (+8 -1) Index: llvm/include/llvm/Analysis/DSNode.h diff -u llvm/include/llvm/Analysis/DSNode.h:1.41 llvm/include/llvm/Analysis/DSNode.h:1.42 --- llvm/include/llvm/Analysis/DSNode.h:1.41 Thu Mar 11 17:08:20 2004 +++ llvm/include/llvm/Analysis/DSNode.h Sun May 23 02:34:53 2004 @@ -386,7 +386,14 @@ // Define inline DSNodeHandle functions that depend on the definition of DSNode // inline DSNode *DSNodeHandle::getNode() const { - assert((!N || Offset < N->Size || (N->Size == 0 && Offset == 0) || + // Disabling this assertion because it is failing on a "magic" struct + // in named (from bind). The fourth field is an array of length 0, + // presumably used to create struct instances of different sizes. + assert((!N || + N->isNodeCompletelyFolded() || + (N->Size == 0 && Offset == 0) || + (int(Offset) >= 0 && Offset < N->Size) || + (int(Offset) < 0 && -int(Offset) < int(N->Size)) || N->isForwarding()) && "Node handle offset out of range!"); if (N == 0 || !N->isForwarding()) return N; From gaeke at cs.uiuc.edu Sun May 23 02:47:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 02:47:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405230746.CAA15917@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.66 -> 1.67 --- Log message: Move the calculation of stack sizes and register sets out of rewriteProlog(), and save the answers in the UnpackTraceFunction object for later use in rewriteEpilog(). Split regsUsed out into RegsToRestore and RegsToSave. findRegsUsedInFunction has been renamed to findRegsToRestore(). I haven't decided the fates of these sets yet. Refactor the calculation of stack offsets for saved registers in the trace function out into stackOffsetForReg(). Do not try to save and restore the stack pointer. Perform live-in value copies by loading them off the stack where they were saved. Do not batch live-in value copies into the EntryCopies vector. Ignore insertCopyMachineInstrs for now because it is going to screw up copies from the MatrixFn's stack to the TraceFn's stack. Other minor edits, primarily concerning debug messages. --- Diffs of the changes: (+105 -85) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.66 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.67 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.66 Sat May 22 21:02:13 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 23 02:46:26 2004 @@ -40,12 +40,24 @@ TargetMachine *TM; TraceFunction *TF; + /// Static stack size of the MachineFunction. Filled in by rewriteProlog () + /// by calling getStaticStackSize (), and then used again by rewriteEpilog (). + /// + unsigned StaticStackSize; + + /// Total stack size of the MachineFunction, including space for regs + /// modified in TraceFn to be saved. + /// + int TotalStackSize; + /// Registers clobbered in the trace. Filled in by findRegsUsedInFunction (). /// - std::set regsUsed; + std::set RegsToRestore; + std::set RegsToSave; unsigned getStaticStackSize (MachineFunction &MF); - void findRegsUsedInFunction (MachineFunction &MF); + unsigned stackOffsetForReg (unsigned R); + void findRegsToRestore (MachineFunction &MF); void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target, MachineBasicBlock &B, const Type *Ty); void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B); @@ -190,13 +202,13 @@ static AllocInfo getValueAllocStateFromGlobal (Function *F, Value *V); /// Fill in the set of registers used in this function, which is kept in -/// 'regsUsed' in the UnpackTraceFunction Pass object, and is used by +/// 'RegsToRestore' in the UnpackTraceFunction Pass object, and is used by /// rewriteProlog() and rewriteEpilog(). Registers are /// represented by their 'unified register numbers' as used in the SPARCv9 /// back-end. /// void -UnpackTraceFunction::findRegsUsedInFunction (MachineFunction &MF) { +UnpackTraceFunction::findRegsToRestore (MachineFunction &MF) { const TargetRegInfo &TRI = TM->getRegInfo (); bool intCCRegSeen = false, floatCCRegSeen = false; for (MachineFunction::iterator fi = MF.begin (), fe = MF.end (); @@ -212,8 +224,9 @@ } else if (TRI.getRegType(regNo) == SparcV9RegInfo::FloatCCRegType || TRI.getRegType(regNo) == SparcV9RegInfo::SpecialRegType) { floatCCRegSeen = true; - } else if (regNo != SparcV9::g0) { // Ignore defs of the zero register - regsUsed.insert (regNo); + } else if (regNo != SparcV9::g0 && regNo != SparcV9::o6 /* sp */) { + // Defs of certain registers are ignored + RegsToRestore.insert (regNo); } } } @@ -223,13 +236,19 @@ // If the intcc regs are used, then we only put %ccr in the // set, not the individual intcc regs. if (floatCCRegSeen) - regsUsed.insert (SparcV9::fsr); + RegsToRestore.insert (SparcV9::fsr); if (intCCRegSeen) - regsUsed.insert (SparcV9::ccr); + RegsToRestore.insert (SparcV9::ccr); // Always put fp in the set because it is restored unconditionally. static const unsigned fp = SparcV9::i6; - regsUsed.insert (fp); + RegsToRestore.insert (fp); + + DEBUG(std::cerr << "findRegsToRestore: RegsToRestore (size " + << RegsToRestore.size () << ") contains: ("; + for (std::set::iterator i = RegsToRestore.begin (), + e = RegsToRestore.end (); i != e; ++i) { std::cerr << *i << " "; } + std::cerr << " )\n"); } static std::pair @@ -238,6 +257,10 @@ getValueAllocStateFromGlobal (TF->TraceFn, TF->getCorrespondingValue (V))); } +unsigned UnpackTraceFunction::stackOffsetForReg (unsigned R) { + return (2047 + StaticStackSize + 176 + (R) * 8); +} + void UnpackTraceFunction::rewriteProlog (MachineFunction &MF, MachineBasicBlock &E) { const TargetRegInfo &TRI = TM->getRegInfo (); @@ -253,25 +276,14 @@ E.push_back (BuildMI (V9::ORr, 3).addMReg (sp).addZImm (0).addMReg (g1, MachineOperand::UseAndDef)); - // 1. Initialize regsUsed with the set of registers used in this function. - findRegsUsedInFunction (MF); - - unsigned stackSize = getStaticStackSize (MF); - DEBUG(std::cerr << "rewriteProlog: Static stack size is " - << stackSize << "\n" - << "rewriteProlog: Reg set (size " << regsUsed.size () - << ") contains: ("); - DEBUG(for (std::set::iterator i = regsUsed.begin (), - e = regsUsed.end (); i != e; ++i) { std::cerr << *i << " "; }); - DEBUG(std::cerr << " )\n"); - - // 2. Get some stack space: (Stack Frame Size + Slop + Space for Regs). - int Size = (stackSize + 176 + 104 * 8); - E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-Size).addMReg (sp, - MachineOperand::Def)); - - std::set regsToSave (regsUsed); - // Save live-in values in registers onto the stack + // 1. Emit ADD instruction to allocate the right amount of stack space. + E.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (-TotalStackSize) + .addMReg (sp, MachineOperand::Def)); + + // 2. Get the saved register allocator state for all live-in variables. + // We are going to need to save live-in values which reside in registers + // on the stack, so we need to dig their register numbers out now. + RegsToSave = RegsToRestore; LiveVariableSet &Si = TF->LiveInSet; std::map > AllocStates; for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; @@ -285,60 +297,57 @@ if (Source.AllocState == AllocInfo::Allocated) { DEBUG (std::cerr << "Need to save incoming live value in reg " << Source.Placement << " onto the stack\n"); - regsToSave.insert (Source.Placement); + RegsToSave.insert (Source.Placement); } } // 3. Save used registers onto the stack. std::vector mvec; int RegType; - for (std::set::iterator i = regsToSave.begin (), - e = regsToSave.end (); i != e; ++i) { + for (std::set::iterator i = RegsToSave.begin (), + e = RegsToSave.end (); i != e; ++i) { mvec.clear (); unsigned R = *i; unsigned RegType = TRI.getRegType (R); - static const char *RegTypeStrings[] = { "IntRegType", - "FPSingleRegType", "FPDoubleRegType", "IntCCRegType", - "FloatCCRegType", "SpecialRegType" }; + + static const char *RegTypeStrings[] = { "IntRegType", "FPSingleRegType", + "FPDoubleRegType", "IntCCRegType", "FloatCCRegType", "SpecialRegType" }; static const char *RegClassStrings[] = { "IntRegClassID", "FloatRegClassID", "IntCCRegClassID", "FloatCCRegClassID", "SpecialRegClassID" }; DEBUG (std::cerr << "rewriteProlog: Saving reg#" << R << ", type = " - << RegType << " (" << RegTypeStrings[RegType] - << "), Class = " << TRI.getRegClassIDOfRegType(RegType) - << " (" - << RegClassStrings[TRI.getRegClassIDOfRegType(RegType)] - << ")\n"); - TRI.cpReg2MemMI (mvec, R, sp, 2047 + stackSize + 176 + R * 8, RegType, g2); - // Add whatever the TargetRegInfo gave us to the MachineBasicBlock we are - // working on. + << RegType << " (" << RegTypeStrings[RegType] + << "), ClassID = " << TRI.getRegClassIDOfRegType(RegType) << " (" + << RegClassStrings[TRI.getRegClassIDOfRegType(RegType)] << ")\n"); + TRI.cpReg2MemMI (mvec, R, sp, stackOffsetForReg (R), RegType, g2); for (std::vector::iterator vi = mvec.begin (), - ve = mvec.end (); vi != ve; ++vi) { - DEBUG (std::cerr << "rewriteProlog: Insns: " << **vi); + ve = mvec.end (); vi != ve; ++vi) E.push_back (*vi); - } } - - // 4. Insert copies from each live-in variable's reg. in the matrix fn. - // to its reg. in the trace. - Function *MatrixF = TF->MatrixFn; - std::vector EntryCopies; + // 4. Insert a copy for each live-in variable to copy it from the stack + // to the register that was allocated for it in the TraceFn. for (LiveVariableSet::iterator SI = Si.begin (), SE = Si.end (); SI != SE; ++SI) { Value *V = *SI; std::pair &ai = AllocStates[V]; AllocInfo &Source = ai.first, &Target = ai.second; - DEBUG(std::cerr << "rewriteProlog: Source in MatrixFn = " << Source << "\n" - << "rewriteProlog: Target in TraceFn = " << Target << "\n"); - if (Source != Target) - EntryCopies.push_back (CopyInfo (Source, Target, &E, V->getType ())); - } - - for (std::vector::iterator i = EntryCopies.begin (), - e = EntryCopies.end (); i != e; ++i) { - DEBUG(std::cerr << "rewriteProlog: Inserting copy " << *i << "\n"); - insertCopyMachineInstrs (i->Src, i->Targ, *i->Blk, i->Ty); + if (Source != Target) { + assert (Target.AllocState == AllocInfo::Allocated + && "FIXME: can't do mem-->mem copy of live-ins yet"); + // FIXME: The following should really be using insertCopyMachineInstrs or + // something like it. + mvec.clear (); + assert (TRI.getRegType (Target.Placement) + == TRI.getRegType (Source.Placement) + && "Live-in value changed reg type?!"); + unsigned RegType = TRI.getRegType (Target.Placement); + TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (Source.Placement), + Target.Placement, RegType, g2); + for (std::vector::iterator vi = mvec.begin (), + ve = mvec.end (); vi != ve; ++vi) + E.push_back (*vi); + } } } @@ -432,10 +441,10 @@ // (InstructionKey, OperandKey, ...): for (unsigned i = 0; i < FAllocState->numTuples; ++i) { OperandAllocState &T = FAllocState->tuples[i]; - if (T.Instruction == InstructionKey && T.Operand == OperandKey) - return AllocInfo (T.Instruction, T.Operand, - (AllocInfo::AllocStateTy) T.AllocState, - T.Placement); + if (T.Instruction == InstructionKey && T.Operand == OperandKey) + return AllocInfo (T.Instruction, T.Operand, + (AllocInfo::AllocStateTy) T.AllocState, + T.Placement); } // By this time we had better have found it, otherwise we are about to do bad // things. @@ -493,8 +502,6 @@ const TargetRegInfo &TRI = TM->getRegInfo (); static const unsigned fp = SparcV9::i6, sp = SparcV9::o6, g0 = SparcV9::g0, g1 = SparcV9::g1, g2 = SparcV9::g2; - Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn; - LiveVariableSet &So = TF->LiveOutSet; // UTF epilog: start out by clearing everything out of the exit basic block // (FIXME: may not work once we start doing optimizations!!! We will probably @@ -503,16 +510,17 @@ // Restore old FP. std::vector mvec; - unsigned stackSize = getStaticStackSize (MF); - TRI.cpMem2RegMI (mvec, sp, 2047 + stackSize + 176 + fp * 8, fp, - TRI.getRegType(fp), g2); + TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (fp), fp, TRI.getRegType(fp), + g2); for (std::vector::iterator vi = mvec.begin (), ve = mvec.end (); vi != ve; ++vi) MBB.push_back (*vi); - regsUsed.erase (fp); + RegsToRestore.erase (fp); // Insert copies from each live-out variable's reg. in the trace // to its reg. in the matrix function. + Function *TraceF = TF->TraceFn, *MatrixF = TF->MatrixFn; + LiveVariableSet &So = TF->LiveOutSet; for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); SI != SE; ++SI) { Value *V = *SI; @@ -526,41 +534,38 @@ // rewriteProlog, earlier, and restore all used registers from stack // except SP. int RegType; - for (std::set::iterator i = regsUsed.begin (), e = regsUsed.end (); - i != e; ++i) { + for (std::set::iterator i = RegsToSave.begin (), + e = RegsToSave.end (); i != e; ++i) { mvec.clear (); unsigned R = *i; unsigned RegType = TRI.getRegType (R); DEBUG (std::cerr << "rewriteEpilog: Reloading reg#" << R << ", type = " - << RegType << ", " << "Class = " - << TRI.getRegClassIDOfRegType(RegType) << "\n"); - TRI.cpMem2RegMI (mvec, sp, 2047 + stackSize + 176 + R * 8, R, RegType, g2); - // Add whatever the TargetRegInfo gave us to the MachineBasicBlock we are - // working on. + << RegType << ", " << "ClassID = " + << TRI.getRegClassIDOfRegType(RegType) << "\n"); + TRI.cpMem2RegMI (mvec, sp, stackOffsetForReg (R), R, RegType, g2); for (std::vector::iterator vi = mvec.begin (), ve = mvec.end (); vi != ve; ++vi) MBB.push_back (*vi); } // Restore stack pointer. - int Size = (stackSize + 176 + 104 * 8); - MBB.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (Size).addMReg (sp, - MachineOperand::Def)); + MBB.push_back (BuildMI (V9::ADDi, 3).addMReg (sp).addSImm (TotalStackSize) + .addMReg (sp, MachineOperand::Def)); // Let ReturnAddress be the address in memory of the compiled // code for the MachineBasicBlock in MatrixF that RI would have // returned to. Find it by using mapping info. const BasicBlock *RBB = MBB.getBasicBlock (); assert ((TF->ReturnBlockForTraceExit.find (RBB) != - TF->ReturnBlockForTraceExit.end ()) - && "Can't find matrix fn BB address to return to from trace"); + TF->ReturnBlockForTraceExit.end ()) + && "Can't find matrix fn BB address to return to from trace"); std::pair BlockAddrs = getBasicBlockInfo(TF->ReturnBlockForTraceExit[RBB]); uint64_t ReturnAddress = BlockAddrs.first; - DEBUG (std::cerr << "Return block for trace exit path is: " + DEBUG (std::cerr << "rewriteEpilog: Return block for trace exit path is:\n" << *TF->ReturnBlockForTraceExit[RBB] << "\n" - << "Mapping info says addresses are: return address = 0x" - << std::hex << BlockAddrs.first << ", end of block = 0x" + << "rewriteEpilog: Mapping info says addresses are: return address =" + << " 0x" << std::hex << BlockAddrs.first << ", end of block = 0x" << BlockAddrs.second << std::dec << "\n"); // Insert a branch back to the return BasicBlock of the matrix fn. insertBranchMachineInstrs (ReturnAddress, MBB); @@ -585,6 +590,21 @@ DEBUG(std::cerr << "UnpackTraceFunction: unpacking " << MF.getFunction()->getName() << "()\n"); + + // Initialize RegsToRestore with the set of registers we'll need to restore + // in the epilog. This is a subset of the registers we'll need to save on the + // stack in the prolog! + findRegsToRestore (MF); + + // Calculate the stack size. + // The actual amount we will allocate is (Static Stack Frame Size + Slop + + // Space for Regs). The Slop = 176 number is from looking at the SparcV9 + // ABI. The Space for Regs = 104 number is the number of 64-bit registers + // that are known to the SparcV9 backend. + StaticStackSize = getStaticStackSize (MF); + TotalStackSize = (StaticStackSize + 176 + 104 * 8); + DEBUG(std::cerr << "rewriteProlog: Stack sizes: static = " << StaticStackSize + << ", total = " << TotalStackSize << "\n"); // Rewrite function prolog, found in the entry MachineBasicBlock of MF rewriteProlog (MF, MF.front ()); From gaeke at cs.uiuc.edu Sun May 23 02:47:08 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 02:47:08 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405230746.CAA15910@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.37 -> 1.38 --- Log message: Add another useful command to the gdb command printout in TraceOptimizerDone(), which makes it easy to print the trace disassembly. Make optimizeTrace() keep track of its own initialization, and make sure that it only runs it once (using the initDone flag). We should really get around to making this into a class sometime soon. By the time we get to optimizeTrace(), we have certainly called initModules(), so just assert that, instead of trying to clean up if we haven't. Make the FunctionPassManager and TargetData pointer static. --- Diffs of the changes: (+28 -19) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.37 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.38 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.37 Thu May 20 13:09:30 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Sun May 23 02:46:23 2004 @@ -37,8 +37,9 @@ namespace llvm { -static TargetMachine *Target = 0; static IntrinsicLowering *IL = 0; +static TargetMachine *Target = 0; +static const TargetData *TD = 0; static MachineCodeEmitter *MCE = 0; extern bool SaveStateToModule; @@ -70,10 +71,15 @@ extern void WriteTraceToFile (Trace &T); -extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr) { +extern "C" void TraceOptimizerDone (uint64_t a, uint64_t traceStartAddr, + uint64_t traceEndAddr) { DEBUG (std::cerr << "\n*** About to return from optimizeTrace(). GDB" - << " breakpoints:\n" << std::hex << "display/i $pc\n" << "b *0x" << a - << "\n" << "b *0x" << traceStartAddr << std::dec << "\n"); + << " commands:\n" << std::hex + << "display/i $pc\n" + << "b *0x" << a << "\n" + << "b *0x" << traceStartAddr << "\n" + << "disassemble 0x" << traceStartAddr << " 0x" << traceEndAddr << "\n" + << std::dec); } /// This method is called when we have finally constructed a @@ -91,11 +97,20 @@ // Initialization stuff: ensure module has been read in, and allocate a // target machine, if there isn't one already. - if (!MP) initModules (); - if (!IL) IL = new DefaultIntrinsicLowering (); - if (!Target) Target = allocateSparcV9TargetMachine (*MP->getModule (), IL); - const TargetData &TD = Target->getTargetData (); - if (!MCE) MCE = createTraceOptEmitter (TD); + static bool initDone = false; + if (!initDone) { + assert (MP); + if (!IL) IL = new DefaultIntrinsicLowering (); + if (!Target) Target = allocateSparcV9TargetMachine (*MP->getModule (), IL); + if (!TD) TD = &Target->getTargetData (); + if (!MCE) MCE = createTraceOptEmitter (*TD); + initDone = true; + + // Force the SPARCv9 register allocator to save its state into a global + // variable + SaveRegAllocState = true; + SaveStateToModule = false; + } // Turn the vector of basic blocks into a Trace, and then turn the Trace into // a TraceFunction. @@ -103,21 +118,15 @@ DEBUG (WriteTraceToFile (T)); TraceFunction *TF = TraceFunction::get (T); - // Force the SPARCv9 register allocator to save its state into a global - // variable - SaveRegAllocState = true; - SaveStateToModule = false; - // Verify that the generated function's bytecode is good, then compile it // down to machine code. Then, "unpack" it back into its matrix function. // FIXME: Register allocation hints also need to be added to the PassManager, // so that we do not get clobbered by the overhead of adding copies in // UnpackTraceFunction. - FunctionPassManager PM (MP); - DEBUG(PM.add (new PrintFunctionPass ("Function created from trace for " - + T.getFunction ()->getName () + ":\n", + static FunctionPassManager PM (MP); + DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n", &std::cerr))); - PM.add (new TargetData (TD)); + PM.add (new TargetData (*TD)); PM.add (createVerifierPass ()); Target->getJITInfo ()->addPassesToJITCompile (PM); DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, @@ -138,7 +147,7 @@ << " to point to 0x" << traceStartAddr << std::dec << "\n"); vm->writeBranchInstruction(a, traceStartAddr); doFlush (a, a + 4); - TraceOptimizerDone(a, traceStartAddr); + TraceOptimizerDone(a, traceStartAddr, MCE->getCurrentPCValue ()); } } // end namespace llvm From gaeke at cs.uiuc.edu Sun May 23 02:48:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 02:48:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/SLI.cpp Message-ID: <200405230747.CAA15922@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: SLI.cpp updated: 1.19 -> 1.20 --- Log message: By the time we get to doInlining(), we have certainly called initModules(), so just assert that, instead of trying to clean up if we haven't. --- Diffs of the changes: (+1 -2) Index: reopt/lib/LightWtProfiling/SLI.cpp diff -u reopt/lib/LightWtProfiling/SLI.cpp:1.19 reopt/lib/LightWtProfiling/SLI.cpp:1.20 --- reopt/lib/LightWtProfiling/SLI.cpp:1.19 Sun May 16 00:12:14 2004 +++ reopt/lib/LightWtProfiling/SLI.cpp Sun May 23 02:46:25 2004 @@ -451,8 +451,7 @@ void doInlining(uint64_t addr1, std::vector &stack, VirtualMem *vm){ // Make sure we have already parsed the LLVM bytecode and have the // resulting LLVM Module handy. - if (!M) - initModules(); + assert (M); Function *F = getRevFunction(M, addr1); From vadve at cs.uiuc.edu Sun May 23 02:56:01 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 02:56:01 2004 Subject: [llvm-commits] CVS: poolalloc/lib/PoolAllocate/PoolAllocate.cpp Message-ID: <200405230755.CAA32700@psmith.cs.uiuc.edu> Changes in directory poolalloc/lib/PoolAllocate: PoolAllocate.cpp updated: 1.68 -> 1.69 --- Log message: Pull out equivalance-class partitioning and graph merging into a separate pass (class EquivClassGraphs), and fix it to inline the resulting graphs bottom-up on the SCCs of the CBU call graph. --- Diffs of the changes: (+8 -182) Index: poolalloc/lib/PoolAllocate/PoolAllocate.cpp diff -u poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.68 poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.69 --- poolalloc/lib/PoolAllocate/PoolAllocate.cpp:1.68 Fri May 14 17:43:09 2004 +++ poolalloc/lib/PoolAllocate/PoolAllocate.cpp Sun May 23 02:55:12 2004 @@ -6,6 +6,7 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "PoolAllocator" +#include "EquivClassGraphs.h" #include "poolalloc/PoolAllocate.h" #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" @@ -77,20 +78,18 @@ void PoolAllocate::getAnalysisUsage(AnalysisUsage &AU) const { AU.addRequired(); + AU.addRequired(); AU.addRequired(); } bool PoolAllocate::run(Module &M) { if (M.begin() == M.end()) return false; CurModule = &M; - BU = &getAnalysis(); + ECGraphs = &getAnalysis(); // folded inlined CBU graphs // Add the pool* prototypes to the module AddPoolPrototypes(); - // Figure out what the equivalence classes are for indirectly called functions - BuildIndirectFunctionSets(M); - // Create the pools for memory objects reachable by global variables. if (SetupGlobalPools(M)) return true; @@ -223,186 +222,13 @@ } } -const PA::EquivClassInfo &PoolAllocate::getECIForIndirectCallSite(CallSite CS) { - Instruction *I = CS.getInstruction(); - assert(I && "Not a call site?"); - Function *thisFunc = I->getParent()->getParent(); - DSNode *calleeNode = BU->getDSGraph(*thisFunc).getNodeForValue(CS.getCalledValue()).getNode(); - if (!OneCalledFunction.count(calleeNode)) - return ECInfoForLeadersMap[0]; // Special null function for empty graphs - Function *Called = OneCalledFunction[calleeNode]; - Function *Leader = FuncECs.findClass(Called); - assert(Leader && "Leader not found for indirect call target!"); - assert(ECInfoForLeadersMap.count(Leader) && "No ECI for indirect call site!"); - return ECInfoForLeadersMap[Leader]; -} - -// BuildIndirectFunctionSets - Iterate over the module looking for indirect -// calls to functions. If a call site can invoke any functions [F1, F2... FN], -// unify the N functions together in the FuncECs set. -// -void PoolAllocate::BuildIndirectFunctionSets(Module &M) { - const CompleteBUDataStructures::ActualCalleesTy AC = BU->getActualCallees(); - - // Loop over all of the indirect calls in the program. If a call site can - // call multiple different functions, we need to unify all of the callees into - // the same equivalence class. - Instruction *LastInst = 0; - Function *FirstFunc = 0; - for (CompleteBUDataStructures::ActualCalleesTy::const_iterator I = AC.begin(), - E = AC.end(); I != E; ++I) { - CallSite CS = CallSite::get(I->first); - if (!CS.getCalledFunction() && // Ignore direct calls - !I->second->isExternal()) { // Ignore functions we cannot modify - //std::cerr << "CALLEE: " << I->second->getName() << " from : " << - //I->first; - if (I->first != LastInst) { - // This is the first callee from this call site. - LastInst = I->first; - FirstFunc = I->second; - //Instead of storing the lastInst For Indirection call Sites we store the - //DSNode for the function ptr arguemnt - Function *thisFunc = LastInst->getParent()->getParent(); - DSNode *calleeNode = BU->getDSGraph(*thisFunc).getNodeForValue(CS.getCalledValue()).getNode(); - OneCalledFunction[calleeNode] = FirstFunc; - FuncECs.addElement(I->second); - } else { - // This is not the first possible callee from a particular call site. - // Union the callee in with the other functions. - FuncECs.unionSetsWith(FirstFunc, I->second); - } - } - } - - // Now that all of the equivalences have been built, turn the union-find data - // structure into a simple map from each function in the equiv class to the - // DSGraph used to represent the union of graphs. - // - std::map &leaderMap = FuncECs.getLeaderMap(); - DEBUG(std::cerr << "Indirect Function Equivalence Map:\n"); - for (std::map::iterator LI = leaderMap.begin(), - LE = leaderMap.end(); LI != LE; ++LI) { - DEBUG(std::cerr << " " << LI->first->getName() << ": leader is " - << LI->second->getName() << "\n"); - - // Now the we have the equiv class info for this object, merge the DSGraph - // for this function into the composite DSGraph. - EquivClassInfo &ECI = ECInfoForLeadersMap[LI->second]; - - // If this is the first function in this equiv class, create the graph now. - if (ECI.G == 0) - ECI.G = new DSGraph(BU->getGlobalsGraph().getTargetData()); - - // Clone this member of the equivalence class into ECI. - DSGraph::NodeMapTy NodeMap; - ECI.G->cloneInto(BU->getDSGraph(*LI->first), ECI.G->getScalarMap(), - ECI.G->getReturnNodes(), NodeMap, 0); - - // This is N^2 with the number of functions in this equiv class, but I don't - // really care right now. FIXME! - for (unsigned i = 0, e = ECI.FuncsInClass.size(); i != e; ++i) { - Function *F = ECI.FuncsInClass[i]; - // Merge the return nodes together. - ECI.G->getReturnNodes()[F].mergeWith(ECI.G->getReturnNodes()[LI->first]); - - // Merge the arguments of the functions together. - Function::aiterator AI1 = F->abegin(); - Function::aiterator AI2 = LI->first->abegin(); - for (; AI1 != F->aend() && AI2 != LI->first->aend(); ++AI1,++AI2) - ECI.G->getNodeForValue(AI1).mergeWith(ECI.G->getNodeForValue(AI2)); - } - ECI.FuncsInClass.push_back(LI->first); - } - DEBUG(std::cerr << "\n"); - - // Now that we have created the graphs for each of the equivalence sets, we - // have to figure out which pool descriptors to pass into the functions. We - // must pass arguments for any pool descriptor that is needed by any function - // in the equiv. class. - for (ECInfoForLeadersMapTy::iterator ECII = ECInfoForLeadersMap.begin(), - E = ECInfoForLeadersMap.end(); ECII != E; ++ECII) { - EquivClassInfo &ECI = ECII->second; - - // Traverse part of the graph to provoke most of the node forwardings to - // occur. - DSGraph::ScalarMapTy &SM = ECI.G->getScalarMap(); - for (DSGraph::ScalarMapTy::iterator I = SM.begin(), E = SM.end(); I!=E; ++I) - I->second.getNode(); // Collapse forward references... - - // Remove breadcrumbs from merging nodes. - ECI.G->removeTriviallyDeadNodes(); - - // Loop over all of the functions in this equiv class, figuring out which - // pools must be passed in for each function. - for (unsigned i = 0, e = ECI.FuncsInClass.size(); i != e; ++i) { - Function *F = ECI.FuncsInClass[i]; - DSGraph &FG = BU->getDSGraph(*F); - - // Figure out which nodes need to be passed in for this function (if any) - hash_set &MarkedNodes = FunctionInfo[F].MarkedNodes; - MarkNodesWhichMustBePassedIn(MarkedNodes, *F, FG); - - if (!MarkedNodes.empty()) { - // If any nodes need to be passed in, figure out which nodes these are - // in the unified graph for this equivalence class. - DSGraph::NodeMapTy NodeMapping; - for (Function::aiterator I = F->abegin(), E = F->aend(); I != E; ++I) - DSGraph::computeNodeMapping(FG.getNodeForValue(I), - ECI.G->getNodeForValue(I), NodeMapping); - DSGraph::computeNodeMapping(FG.getReturnNodeFor(*F), - ECI.G->getReturnNodeFor(*F), NodeMapping); - - // Loop through all of the nodes which must be passed through for this - // callee, and add them to the arguments list. - for (hash_set::iterator I = MarkedNodes.begin(), - E = MarkedNodes.end(); I != E; ++I) { - DSNode *LocGraphNode = *I, *ECIGraphNode = NodeMapping[*I].getNode(); - - // Remember the mapping of this node - ECI.ECGraphToPrivateMap[std::make_pair(F,ECIGraphNode)] =LocGraphNode; - - // Add this argument to be passed in. Don't worry about duplicates, - // they will be eliminated soon. - ECI.ArgNodes.push_back(ECIGraphNode); - } - } - } - - // Okay, all of the functions have had their required nodes added to the - // ECI.ArgNodes list, but there might be duplicates. Eliminate the dups - // now. - std::sort(ECI.ArgNodes.begin(), ECI.ArgNodes.end()); - ECI.ArgNodes.erase(std::unique(ECI.ArgNodes.begin(), ECI.ArgNodes.end()), - ECI.ArgNodes.end()); - - // Uncomment this if you want to see the aggregate graph result - //ECI.G->viewGraph(); - } -} - void PoolAllocate::FindFunctionPoolArgs(Function &F) { - DSGraph &G = BU->getDSGraph(F); + DSGraph &G = ECGraphs->getDSGraph(F); FuncInfo &FI = FunctionInfo[&F]; // Create a new entry for F hash_set &MarkedNodes = FI.MarkedNodes; - // If this function is part of an indirectly called function equivalence - // class, we have to handle it specially. - if (Function *Leader = FuncECs.findClass(&F)) { - EquivClassInfo &ECI = ECInfoForLeadersMap[Leader]; - - // The arguments passed in will be the ones specified by the ArgNodes list. - for (unsigned i = 0, e = ECI.ArgNodes.size(); i != e; ++i) { - DSNode *ArgNode = - ECI.ECGraphToPrivateMap[std::make_pair(&F, ECI.ArgNodes[i])]; - FI.ArgNodes.push_back(ArgNode); - MarkedNodes.insert(ArgNode); - } - - return; - } - if (G.node_begin() == G.node_end()) return; // No memory activity, nothing is required @@ -419,7 +245,7 @@ // necessary, and return it. If not, just return null. // Function *PoolAllocate::MakeFunctionClone(Function &F) { - DSGraph &G = BU->getDSGraph(F); + DSGraph &G = ECGraphs->getDSGraph(F); if (G.node_begin() == G.node_end()) return 0; FuncInfo &FI = FunctionInfo[&F]; @@ -540,7 +366,7 @@ // bool PoolAllocate::SetupGlobalPools(Module &M) { // Get the globals graph for the program. - DSGraph &GG = BU->getGlobalsGraph(); + DSGraph &GG = ECGraphs->getGlobalsGraph(); // Get all of the nodes reachable from globals. hash_set GlobalHeapNodes; @@ -791,7 +617,7 @@ // the specified function... // void PoolAllocate::ProcessFunctionBody(Function &F, Function &NewF) { - DSGraph &G = BU->getDSGraph(F); + DSGraph &G = ECGraphs->getDSGraph(F); if (G.node_begin() == G.node_end()) return; // Quick exit if nothing to do... @@ -801,7 +627,7 @@ // Calculate which DSNodes are reachable from globals. If a node is reachable // from a global, we will create a global pool for it, so no argument passage // is required. - DSGraph &GG = BU->getGlobalsGraph(); + DSGraph &GG = ECGraphs->getGlobalsGraph(); DSGraph::NodeMapTy GlobalsGraphNodeMapping; for (DSScalarMap::global_iterator I = G.getScalarMap().global_begin(), E = G.getScalarMap().global_end(); I != E; ++I) { From vadve at cs.uiuc.edu Sun May 23 02:56:08 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 02:56:08 2004 Subject: [llvm-commits] CVS: poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp EquivClassGraphs.h Message-ID: <200405230755.CAA32692@psmith.cs.uiuc.edu> Changes in directory poolalloc/lib/PoolAllocate: EquivClassGraphs.cpp added (r1.1) EquivClassGraphs.h added (r1.1) --- Log message: Complete rewrite of the code that merges DS graphs for equivalence classes of functions called at a common call site. The rewrite inlines the resulting graphs bottom-up on the SCCs of the CBU call graph. It also simplifies the merging of equivalence classes by exploiting the fact that functions in non-trivial SCCs are already merged. --- Diffs of the changes: (+604 -0) Index: poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp diff -c /dev/null poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp:1.1 *** /dev/null Sun May 23 02:55:13 2004 --- poolalloc/lib/PoolAllocate/EquivClassGraphs.cpp Sun May 23 02:54:02 2004 *************** *** 0 **** --- 1,428 ---- + //===- EquivClassGraphs.cpp - Merge equiv-class graphs & inline bottom-up -===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This pass is the same as the complete bottom-up graphs, but + // with functions partitioned into equivalence classes and a single merged + // DS graph for all functions in an equivalence class. After this merging, + // graphs are inlined bottom-up on the SCCs of the final (CBU) call graph. + // + //===----------------------------------------------------------------------===// + + #define DEBUG_TYPE "ECGraphs" + #include "EquivClassGraphs.h" + #include "llvm/Analysis/DataStructure.h" + #include "llvm/Module.h" + #include "llvm/Pass.h" + #include "llvm/Analysis/DSGraph.h" + #include "llvm/Support/CallSite.h" + #include "Support/Debug.h" + #include "Support/SCCIterator.h" + #include "Support/Statistic.h" + #include "Support/EquivalenceClasses.h" + #include "Support/STLExtras.h" + using namespace llvm; + + namespace llvm { + namespace PA { + Statistic<> NumFoldGraphInlines("Inline equiv-class graphs bottom up", + "Number of graphs inlined"); + + } // End PA namespace + } // End llvm namespace + + + namespace { + RegisterAnalysis X("equivdatastructure", + "Equivalence-class Bottom-up Data Structure Analysis"); + Statistic<> NumEquivBUInlines("equivdatastructures", "Number of graphs inlined"); + } + + + // getDSGraphForCallSite - Return the common data structure graph for + // callees at the specified call site. + // + Function *llvm::PA::EquivClassGraphs::getSomeCalleeForCallSite(const CallSite &CS) const { + Function *thisFunc = CS.getCaller(); + assert(thisFunc && "getDSGraphForCallSite(): Not a valid call site?"); + DSNode *calleeNode = CBU->getDSGraph(*thisFunc). + getNodeForValue(CS.getCalledValue()).getNode(); + std::map::const_iterator I = + OneCalledFunction.find(calleeNode); + return (I == OneCalledFunction.end())? NULL : I->second; + } + + // computeFoldedGraphs - Calculate the bottom up data structure + // graphs for each function in the program. + // + void llvm::PA::EquivClassGraphs::computeFoldedGraphs(Module &M) { + CBU = &getAnalysis(); + + // Find equivalence classes of functions called from common call sites. + // Fold the CBU graphs for all functions in an equivalence class. + buildIndirectFunctionSets(M); + + // Stack of functions used for Tarjan's SCC-finding algorithm. + std::vector Stack; + hash_map ValMap; + unsigned NextID = 1; + + if (Function *Main = M.getMainFunction()) { + if (!Main->isExternal()) + processSCC(getOrCreateGraph(*Main), *Main, Stack, NextID, ValMap); + } else { + std::cerr << "Fold Graphs: No 'main' function found!\n"; + } + + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) + if (!I->isExternal() && !FoldedGraphsMap.count(I)) + processSCC(getOrCreateGraph(*I), *I, Stack, NextID, ValMap); + + getGlobalsGraph().removeTriviallyDeadNodes(); + } + + + // buildIndirectFunctionSets - Iterate over the module looking for indirect + // calls to functions. If a call site can invoke any functions [F1, F2... FN], + // unify the N functions together in the FuncECs set. + // + void llvm::PA::EquivClassGraphs::buildIndirectFunctionSets(Module &M) { + const ActualCalleesTy& AC = CBU->getActualCallees(); + + // Loop over all of the indirect calls in the program. If a call site can + // call multiple different functions, we need to unify all of the callees into + // the same equivalence class. + Instruction *LastInst = 0; + Function *FirstFunc = 0; + for (ActualCalleesTy::const_iterator I=AC.begin(), E=AC.end(); I != E; ++I) { + if (I->second->isExternal()) + continue; // Ignore functions we cannot modify + + CallSite CS = CallSite::get(I->first); + + if (CS.getCalledFunction()) { // Direct call: + FuncECs.addElement(I->second); // -- Make sure function has equiv class + FirstFunc = I->second; // -- First callee at this site + } else { // Else indirect call + // DEBUG(std::cerr << "CALLEE: " << I->second->getName() + // << " from : " << I->first); + if (I->first != LastInst) { + // This is the first callee from this call site. + LastInst = I->first; + FirstFunc = I->second; + // Instead of storing the lastInst For Indirection call Sites we store + // the DSNode for the function ptr arguemnt + Function *thisFunc = LastInst->getParent()->getParent(); + DSNode *calleeNode = CBU->getDSGraph(*thisFunc).getNodeForValue(CS.getCalledValue()).getNode(); + OneCalledFunction[calleeNode] = FirstFunc; + FuncECs.addElement(I->second); + } else { + // This is not the first possible callee from a particular call site. + // Union the callee in with the other functions. + FuncECs.unionSetsWith(FirstFunc, I->second); + #ifndef NDEBUG + Function *thisFunc = LastInst->getParent()->getParent(); + DSNode *calleeNode = CBU->getDSGraph(*thisFunc).getNodeForValue(CS.getCalledValue()).getNode(); + assert(OneCalledFunction.count(calleeNode) > 0 && "Missed a call?"); + #endif + } + } + + // Now include all functions that share a graph with any function in the + // equivalence class. More precisely, if F is in the class, and G(F) is + // its graph, then we include all other functions that are also in G(F). + // Currently, that is just the functions in the same call-graph-SCC as F. + // + DSGraph& funcDSGraph = CBU->getDSGraph(*I->second); + const DSGraph::ReturnNodesTy &RetNodes = funcDSGraph.getReturnNodes(); + for (DSGraph::ReturnNodesTy::const_iterator RI=RetNodes.begin(), + RE=RetNodes.end(); RI != RE; ++RI) + FuncECs.unionSetsWith(FirstFunc, RI->first); + } + + // Now that all of the equivalences have been built, merge the graphs for + // each equivalence class. + // + std::set &leaderSet = FuncECs.getLeaderSet(); + DEBUG(std::cerr << "\nIndirect Function Equivalence Sets:\n"); + for (std::set::iterator LI = leaderSet.begin(), + LE = leaderSet.end(); LI != LE; ++LI) { + + Function* LF = *LI; + const std::set& EqClass = FuncECs.getEqClass(LF); + + #ifndef NDEBUG + if (EqClass.size() > 1) { + DEBUG(std::cerr <<" Equivalence set for leader " <getName()<<" = "); + for (std::set::const_iterator EqI = EqClass.begin(), + EqEnd = EqClass.end(); EqI != EqEnd; ++EqI) + DEBUG(std::cerr << " " << (*EqI)->getName() << ","); + DEBUG(std::cerr << "\n"); + } + #endif + + if (EqClass.size() > 1) { + // This equiv class has multiple functions: merge their graphs. + // First, clone the CBU graph for the leader and make it the + // common graph for the equivalence graph. + DSGraph* mergedG = cloneGraph(*LF); + + // Record the argument nodes for use in merging later below + EquivClassGraphArgsInfo& GraphInfo = getECGraphInfo(mergedG); + for (Function::aiterator AI1 = LF->abegin(); AI1 != LF->aend(); ++AI1) + GraphInfo.argNodes.push_back(mergedG->getNodeForValue(AI1)); + + // Merge in the graphs of all other functions in this equiv. class. + // Note that two or more functions may have the same graph, and it + // only needs to be merged in once. Use a set to find repetitions. + std::set GraphsMerged; + for (std::set::const_iterator EqI = EqClass.begin(), + EqEnd = EqClass.end(); EqI != EqEnd; ++EqI) { + Function* F = *EqI; + DSGraph*& FG = FoldedGraphsMap[F]; + if (F == LF || FG == mergedG) + continue; + + // Record the "folded" graph for the function. + FG = mergedG; + + // Clone this member of the equivalence class into mergedG + DSGraph* CBUGraph = &CBU->getDSGraph(*F); + if (GraphsMerged.count(CBUGraph) > 0) + continue; + + GraphsMerged.insert(CBUGraph); + DSGraph::NodeMapTy NodeMap; + mergedG->cloneInto(*CBUGraph, mergedG->getScalarMap(), + mergedG->getReturnNodes(), NodeMap, 0); + + // Merge the return nodes of all functions together. + mergedG->getReturnNodes()[LF].mergeWith(mergedG->getReturnNodes()[F]); + + // Merge the function arguments with all argument nodes found so far. + // If there are extra function args, add them to the vector of argNodes + Function::aiterator AI2 = F->abegin(), AI2end = F->aend(); + for (unsigned arg=0, numArgs=GraphInfo.argNodes.size(); + arg < numArgs && AI2 != AI2end; ++AI2, ++arg) + GraphInfo.argNodes[arg].mergeWith(mergedG->getNodeForValue(AI2)); + for ( ; AI2 != AI2end; ++AI2) + GraphInfo.argNodes.push_back(mergedG->getNodeForValue(AI2)); + } + } + } + DEBUG(std::cerr << "\n"); + } + + + DSGraph &llvm::PA::EquivClassGraphs::getOrCreateGraph(Function &F) { + // Has the graph already been created? + DSGraph *&Graph = FoldedGraphsMap[&F]; + if (Graph) return *Graph; + + // Use the CBU graph directly without copying it. + // This automatically updates the FoldedGraphsMap via the reference. + Graph = &CBU->getDSGraph(F); + + return *Graph; + } + + DSGraph* llvm::PA::EquivClassGraphs::cloneGraph(Function &F) { + DSGraph *&Graph = FoldedGraphsMap[&F]; + DSGraph &CBUGraph = CBU->getDSGraph(F); + assert(Graph == NULL || Graph == &CBUGraph && "Cloning a graph twice?"); + + // Copy the CBU graph... + Graph = new DSGraph(CBUGraph); // updates the map via reference + Graph->setGlobalsGraph(&getGlobalsGraph()); + Graph->setPrintAuxCalls(); + + // Make sure to update the FoldedGraphsMap map for all functions in the graph! + for (DSGraph::ReturnNodesTy::iterator I = Graph->getReturnNodes().begin(); + I != Graph->getReturnNodes().end(); ++I) + if (I->first != &F) { + DSGraph*& FG = FoldedGraphsMap[I->first]; + assert(FG == NULL || FG == &CBU->getDSGraph(*I->first) && + "Merging function in SCC twice?"); + FG = Graph; + } + + return Graph; + } + + + unsigned llvm::PA::EquivClassGraphs::processSCC(DSGraph &FG, Function& F, + std::vector &Stack, + unsigned &NextID, + hash_map &ValMap) { + DEBUG(std::cerr << " ProcessSCC for function " << F.getName() << "\n"); + + assert(!ValMap.count(&F) && "Shouldn't revisit functions!"); + unsigned Min = NextID++, MyID = Min; + ValMap[&F] = Min; + Stack.push_back(&F); + + // The edges out of the current node are the call site targets... + for (unsigned i = 0, e = FG.getFunctionCalls().size(); i != e; ++i) { + Instruction *Call = FG.getFunctionCalls()[i].getCallSite().getInstruction(); + + // Loop over all of the actually called functions... + ActualCalleesTy::const_iterator I, E; + for (tie(I, E) = getActualCallees().equal_range(Call); I != E; ++I) + if (!I->second->isExternal()) { + DSGraph &CalleeG = getOrCreateGraph(*I->second); + + // Have we visited the destination function yet? + hash_map::iterator It = ValMap.find(I->second); + unsigned M = (It == ValMap.end()) // No, visit it now. + ? processSCC(CalleeG, *I->second, Stack, NextID, ValMap) + : It->second; // Yes, get it's number. + + if (M < Min) Min = M; + } + } + + assert(ValMap[&F] == MyID && "SCC construction assumption wrong!"); + if (Min != MyID) + return Min; // This is part of a larger SCC! + + // If this is a new SCC, process it now. + bool IsMultiNodeSCC = false; + while (Stack.back() != &F) { + DSGraph *NG = &getOrCreateGraph(* Stack.back()); + ValMap[Stack.back()] = ~0U; + + // Since all SCCs must be the same as those found in CBU, we do not need to + // do any merging. Make sure all functions in the SCC share the same graph. + assert(NG == &FG && + "FoldGraphs: Functions in the same SCC have different graphs?"); + + Stack.pop_back(); + IsMultiNodeSCC = true; + } + + // Clean up the graph before we start inlining a bunch again... + if (IsMultiNodeSCC) + FG.removeTriviallyDeadNodes(); + + Stack.pop_back(); + processGraph(FG, F); + ValMap[&F] = ~0U; + return MyID; + } + + + /// processGraph - Process the CBU graphs for the program in bottom-up order on + /// the SCC of the __ACTUAL__ call graph. This builds final folded CBU graphs. + void llvm::PA::EquivClassGraphs::processGraph(DSGraph &G, Function& F) { + DEBUG(std::cerr << " ProcessGraph for function " << F.getName() << "\n"); + + hash_set calls; + + DSGraph* CallerGraph = sameAsCBUGraph(F)? NULL : &getOrCreateGraph(F); + + // If the function has not yet been cloned, let's check if any callees + // need to be inlined before cloning it. + // + for (unsigned i=0, e=G.getFunctionCalls().size(); i!=e && !CallerGraph; ++i) { + const DSCallSite &CS = G.getFunctionCalls()[i]; + Instruction *TheCall = CS.getCallSite().getInstruction(); + + // Loop over all potential callees to find the first non-external callee. + // Some inlining is needed if there is such a callee and it has changed. + ActualCalleesTy::const_iterator I, E; + for (tie(I, E) = getActualCallees().equal_range(TheCall); I != E; ++I) + if (!I->second->isExternal() && !sameAsCBUGraph(*I->second)) { + // Ok, the caller does need to be cloned... go ahead and do it now. + // clone the CBU graph for F now because we have not cloned it so far + CallerGraph = cloneGraph(F); + break; + } + } + + if (!CallerGraph) { // No inlining is needed. + DEBUG(std::cerr << " --DONE ProcessGraph for function " << F.getName() + << " (NO INLINING NEEDED)\n"); + return; + } + + // Else we need to inline some callee graph. Visit all call sites. + // The edges out of the current node are the call site targets... + for (unsigned i=0, e = CallerGraph->getFunctionCalls().size(); i != e; ++i) { + const DSCallSite &CS = CallerGraph->getFunctionCalls()[i]; + Instruction *TheCall = CS.getCallSite().getInstruction(); + + assert(calls.insert(TheCall).second && + "Call instruction occurs multiple times in graph??"); + + // Inline the common callee graph into the current graph, if the callee + // graph has not changed. Note that all callees should have the same + // graph so we only need to do this once. + // + DSGraph* CalleeGraph = NULL; + ActualCalleesTy::const_iterator I, E; + tie(I, E) = getActualCallees().equal_range(TheCall); + unsigned TNum, Num; + + // Loop over all potential callees to find the first non-external callee. + for (TNum = 0, Num = std::distance(I, E); I != E; ++I, ++TNum) + if (!I->second->isExternal()) + break; + + // Now check if the graph has changed and if so, clone and inline it. + if (I != E && !sameAsCBUGraph(*I->second)) { + Function *CalleeFunc = I->second; + + // Merge the callee's graph into this graph, if not already the same. + // Callees in the same equivalence class (which subsumes those + // in the same SCCs) have the same graph. Note that all recursion + // including self-recursion have been folded in the equiv classes. + // + CalleeGraph = &getOrCreateGraph(*CalleeFunc); + if (CalleeGraph != CallerGraph) { + ++NumFoldGraphInlines; + CallerGraph->mergeInGraph(CS, *CalleeFunc, *CalleeGraph, + DSGraph::KeepModRefBits | + DSGraph::StripAllocaBit | + DSGraph::DontCloneCallNodes | + DSGraph::DontCloneAuxCallNodes); + DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1 + << ":" << TNum << "/" << Num-1 << "] for " + << CalleeFunc->getName() << "[" + << CalleeGraph->getGraphSize() << "+" + << CalleeGraph->getAuxFunctionCalls().size() + << "] into '" /*<< CallerGraph->getFunctionNames()*/ << "' [" + << CallerGraph->getGraphSize() << "+" + << CallerGraph->getAuxFunctionCalls().size() + << "]\n"); + } + } + + #ifndef NDEBUG + // Now loop over the rest of the callees and make sure they have the + // same graph as the one inlined above. + if (CalleeGraph) + for (++I, ++TNum; I != E; ++I, ++TNum) + if (!I->second->isExternal()) + assert(CalleeGraph == &getOrCreateGraph(*I->second) && + "Callees at a call site have different graphs?"); + #endif + } + + // Recompute the Incomplete markers + if (CallerGraph != NULL) { + assert(CallerGraph->getInlinedGlobals().empty()); + CallerGraph->maskIncompleteMarkers(); + CallerGraph->markIncompleteNodes(DSGraph::MarkFormalArgs); + + // Delete dead nodes. Treat globals that are unreachable but that can + // reach live nodes as live. + CallerGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals); + } + + DEBUG(std::cerr << " --DONE ProcessGraph for function " << F.getName() << "\n"); + } Index: poolalloc/lib/PoolAllocate/EquivClassGraphs.h diff -c /dev/null poolalloc/lib/PoolAllocate/EquivClassGraphs.h:1.1 *** /dev/null Sun May 23 02:55:13 2004 --- poolalloc/lib/PoolAllocate/EquivClassGraphs.h Sun May 23 02:54:02 2004 *************** *** 0 **** --- 1,176 ---- + //===-- EquivClassGraphs.h - Merge equiv-class graphs & inline bottom-up --===// + // + // The LLVM Compiler Infrastructure + // + // This file was developed by the LLVM research group and is distributed under + // the University of Illinois Open Source License. See LICENSE.TXT for details. + // + //===----------------------------------------------------------------------===// + // + // This pass is the same as the complete bottom-up graphs, but + // with functions partitioned into equivalence classes and a single merged + // DS graph for all functions in an equivalence class. After this merging, + // graphs are inlined bottom-up on the SCCs of the final (CBU) call graph. + // + //===----------------------------------------------------------------------===// + + + #include "llvm/Analysis/DataStructure.h" + #include "llvm/Analysis/DSGraph.h" + #include "Support/EquivalenceClasses.h" + #include "Support/STLExtras.h" + #include + #include + #include + + namespace llvm { + + class Module; + class Function; + + namespace PA { + + /// EquivClassGraphArgsInfo - Information about the set of argument nodes + /// in a DS graph (the number of argument nodes is the max of argument nodes + /// for all functions folded into the graph). + /// FIXME: This class is only used temporarily and could be eliminated. + /// + struct EquivClassGraphArgsInfo { + const DSGraph* ECGraph; + std::vector argNodes; + EquivClassGraphArgsInfo() : ECGraph(NULL) {} + }; + + /// EquivClassGraphs - This is the same as the complete bottom-up graphs, but + /// with functions partitioned into equivalence classes and a single merged + /// DS graph for all functions in an equivalence class. After this merging, + /// graphs are inlined bottom-up on the SCCs of the final (CBU) call graph. + /// + struct EquivClassGraphs : public Pass { + CompleteBUDataStructures *CBU; + + // FoldedGraphsMap, one graph for each function + hash_map FoldedGraphsMap; + + // Equivalence class where functions that can potentially be called via the + // same function pointer are in the same class. + EquivalenceClasses FuncECs; + + // Each equivalence class graph contains several functions. + // Remember their argument nodes (and return nodes?) + std::map ECGraphInfo; + + /// OneCalledFunction - For each indirect call, we keep track of one + /// target of the call. This is used to find equivalence class called by + /// a call site. + std::map OneCalledFunction; + + public: + /// EquivClassGraphs - Computes the equivalence classes and then the + /// folded DS graphs for each class. + /// + virtual bool run(Module &M) { computeFoldedGraphs(M); return true; } + + /// getCBUDataStructures - Get the CompleteBUDataStructures object + /// + CompleteBUDataStructures *getCBUDataStructures() { return CBU; } + + /// getDSGraph - Return the data structure graph for the specified function. + /// This returns the folded graph. The folded graph is the same as the CBU + /// graph iff the function is in a singleton equivalence class AND all its + /// callees also have the same folded graph as the CBU graph. + /// + DSGraph &getDSGraph(const Function &F) const { + hash_map::const_iterator I = + FoldedGraphsMap.find(const_cast(&F)); + assert(I != FoldedGraphsMap.end() && "No folded graph for function!"); + return *I->second; + } + + /// getSomeCalleeForCallSite - Return any one callee function at + /// a call site. + /// + Function *getSomeCalleeForCallSite(const CallSite &CS) const; + + /// getDSGraphForCallSite - Return the common data structure graph for + /// callees at the specified call site. + /// + DSGraph &getDSGraphForCallSite(const CallSite &CS) const { + return this->getDSGraph(*getSomeCalleeForCallSite(CS)); + } + + /// getEquivClassForCallSite - Get the set of functions in the equivalence + /// class for a given call site. + /// + const std::set& getEquivClassForCallSite(const CallSite& CS) { + Function* leaderF = FuncECs.findClass(getSomeCalleeForCallSite(CS)); + return FuncECs.getEqClass(leaderF); + } + + /// getECGraphInfo - Get the graph info object with arg nodes info + /// + EquivClassGraphArgsInfo &getECGraphInfo(const DSGraph* G) { + assert(G != NULL && "getECGraphInfo: Null graph!"); + EquivClassGraphArgsInfo& GraphInfo = ECGraphInfo[G]; + if (GraphInfo.ECGraph == NULL) + GraphInfo.ECGraph = G; + return GraphInfo; + } + + /// sameAsCBUGraph - Check if the folded graph for this function is + /// the same as the CBU graph. + bool sameAsCBUGraph(const Function &F) const { + DSGraph& foldedGraph = getDSGraph(F); + return (&foldedGraph == &CBU->getDSGraph(F)); + } + + DSGraph &getGlobalsGraph() const { + return CBU->getGlobalsGraph(); + } + + typedef llvm::BUDataStructures::ActualCalleesTy ActualCalleesTy; + const ActualCalleesTy &getActualCallees() const { + return CBU->getActualCallees(); + } + + virtual void getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + AU.addRequired(); + } + + /// print - Print out the analysis results... + /// + void print(std::ostream &O, const Module *M) const { CBU->print(O, M); } + + private: + void computeFoldedGraphs(Module &M); + + void buildIndirectFunctionSets(Module &M); + + unsigned processSCC(DSGraph &FG, Function &F, std::vector &Stack, + unsigned &NextID, + hash_map &ValMap); + + void processGraph(DSGraph &FG, Function &F); + + DSGraph &getOrCreateGraph(Function &F); + + DSGraph* cloneGraph(Function &F); + + bool hasFoldedGraph(const Function& F) const { + hash_map::const_iterator I = + FoldedGraphsMap.find(const_cast(&F)); + return (I != FoldedGraphsMap.end()); + } + + DSGraph* getOrCreateLeaderGraph(const Function& leader) { + DSGraph*& leaderGraph = FoldedGraphsMap[&leader]; + if (leaderGraph == NULL) + leaderGraph = new DSGraph(CBU->getGlobalsGraph().getTargetData()); + return leaderGraph; + } + }; + + }; // end PA namespace + + }; // end llvm namespace From vadve at cs.uiuc.edu Sun May 23 02:57:03 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 02:57:03 2004 Subject: [llvm-commits] CVS: poolalloc/include/poolalloc/PoolAllocate.h Message-ID: <200405230756.CAA32715@psmith.cs.uiuc.edu> Changes in directory poolalloc/include/poolalloc: PoolAllocate.h updated: 1.22 -> 1.23 --- Log message: Pull out equivalance-class partitioning and graph merging into a separate pass (class EquivClassGraphs). --- Diffs of the changes: (+7 -40) Index: poolalloc/include/poolalloc/PoolAllocate.h diff -u poolalloc/include/poolalloc/PoolAllocate.h:1.22 poolalloc/include/poolalloc/PoolAllocate.h:1.23 --- poolalloc/include/poolalloc/PoolAllocate.h:1.22 Fri May 14 17:41:35 2004 +++ poolalloc/include/poolalloc/PoolAllocate.h Sun May 23 02:56:05 2004 @@ -20,13 +20,15 @@ namespace llvm { -class CompleteBUDataStructures; class DSNode; class DSGraph; class Type; class AllocaInst; namespace PA { + + class EquivClassGraphs; + /// FuncInfo - Represent the pool allocation information for one function in /// the program. Note that many functions must actually be cloned in order /// for pool allocation to add arguments to the function signature. In this @@ -71,27 +73,7 @@ std::map NewToOldValueMap; }; - struct EquivClassInfo { - // FuncsInClass - This is a list of all of the functions in this equiv - // class. - std::vector FuncsInClass; - - // G - The DSGraph which contains a union of all of the nodes in this - // equivalence class. - DSGraph *G; - - // ECGraphToPrivateMap - This map, given a DSNode in the ECI DSGraph and a - // function, will tell you which DS node in the function DS graph this node - // corresponds to (or null if none). - std::map, DSNode*> ECGraphToPrivateMap; - - // ArgNodes - The list of DSNodes which require arguments to be passed in - // for all members of this equivalence class. - std::vector ArgNodes; - - EquivClassInfo() : G(0) {} - }; -} +}; // end PA namespace @@ -99,41 +81,26 @@ /// class PoolAllocate : public Pass { Module *CurModule; - CompleteBUDataStructures *BU; + PA::EquivClassGraphs *ECGraphs; std::map FunctionInfo; - // Equivalence class where functions that can potentially be called via the - // same function pointer are in the same class. - EquivalenceClasses FuncECs; - - // Each equivalence class leader has an EquivClassInfo object. This map holds - // them. - typedef std::map ECInfoForLeadersMapTy; - ECInfoForLeadersMapTy ECInfoForLeadersMap; - - /// OneCalledFunction - For each indirect function call, we keep track of one - /// target of the call. This is used to find the equivalence class called by - /// a call site. - std::map OneCalledFunction; - public: Function *PoolInit, *PoolDestroy, *PoolAlloc, *PoolAllocArray, *PoolFree; static const Type *PoolDescPtrTy; - const PA::EquivClassInfo &getECIForIndirectCallSite(CallSite CS); - /// GlobalNodes - For each node (with an H marker) in the globals graph, this /// map contains the global variable that holds the pool descriptor for the /// node. std::map GlobalNodes; + public: bool run(Module &M); virtual void getAnalysisUsage(AnalysisUsage &AU) const; - CompleteBUDataStructures &getBUDataStructures() const { return *BU; } + PA::EquivClassGraphs &getECGraphs() const { return *ECGraphs; } //Dinakar to get function info for all (cloned functions) PA::FuncInfo *getFunctionInfo(Function *F) { From vadve at cs.uiuc.edu Sun May 23 02:57:09 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 02:57:09 2004 Subject: [llvm-commits] CVS: poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp Message-ID: <200405230756.CAA32730@psmith.cs.uiuc.edu> Changes in directory poolalloc/lib/PoolAllocate: TransformFunctionBody.cpp updated: 1.23 -> 1.24 --- Log message: Rewrite to use results of new merging pass, EquivClassGraphs, instead of old ECI stuff. --- Diffs of the changes: (+50 -24) Index: poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp diff -u poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.23 poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.24 --- poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp:1.23 Fri Mar 5 00:54:55 2004 +++ poolalloc/lib/PoolAllocate/TransformFunctionBody.cpp Sun May 23 02:56:48 2004 @@ -5,6 +5,7 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "PoolAllocator" +#include "EquivClassGraphs.h" #include "poolalloc/PoolAllocate.h" #include "llvm/Analysis/DataStructure.h" #include "llvm/Analysis/DSGraph.h" @@ -75,15 +76,18 @@ FI.NewToOldValueMap.erase(I); } - DSNodeHandle& getDSNodeHFor(Value *V) { + Value* getOldValueIfAvailable(Value* V) { if (!FI.NewToOldValueMap.empty()) { // If the NewToOldValueMap is in effect, use it. std::map::iterator I = FI.NewToOldValueMap.find(V); if (I != FI.NewToOldValueMap.end()) V = (Value*)I->second; } + return V; + } - return G.getScalarMap()[V]; + DSNodeHandle& getDSNodeHFor(Value *V) { + return G.getScalarMap()[getOldValueIfAvailable(V)]; } Value *getPoolHandle(Value *V) { @@ -337,13 +341,16 @@ // between the graphs to figure out which pool descriptors need to be passed // in. The roots of this mapping is found from arguments and return values. // + EquivClassGraphs& ECGraphs = PAInfo.getECGraphs(); DSGraph::NodeMapTy NodeMapping; Instruction *NewCall; Value *NewCallee; std::vector ArgNodes; DSGraph *CalleeGraph; // The callee graph + // For indirect callees find any callee since all DS graphs have been merged. if (CF) { // Direct calls are nice and simple. + DEBUG(std::cerr << " Handling direct call: " << *TheCall); FuncInfo *CFI = PAInfo.getFuncInfo(*CF); if (CFI == 0 || CFI->Clone == 0) { // Nothing to transform... visitInstruction(*TheCall); @@ -352,30 +359,50 @@ NewCallee = CFI->Clone; ArgNodes = CFI->ArgNodes; - DEBUG(std::cerr << " Handling direct call: " << *TheCall); - CalleeGraph = &PAInfo.getBUDataStructures().getDSGraph(*CF); + CalleeGraph = &ECGraphs.getDSGraph(*CF); } else { DEBUG(std::cerr << " Handling indirect call: " << *TheCall); - // Figure out which set of functions this call may invoke - Instruction *OrigInst = CS.getInstruction(); - - // If this call site is in a clone function, map it back to the original - if (!FI.NewToOldValueMap.empty()) - OrigInst = cast((Value*)FI.NewToOldValueMap[OrigInst]); - const PA::EquivClassInfo &ECI = - PAInfo.getECIForIndirectCallSite(CallSite::get(OrigInst)); - - if (ECI.ArgNodes.empty()) - return; // No arguments to add? Transformation is a noop! - // Here we fill in CF with one of the possible called functions. Because we // merged together all of the arguments to all of the functions in the // equivalence set, it doesn't really matter which one we pick. - CalleeGraph = ECI.G; - CF = ECI.FuncsInClass.back(); - NewCallee = CS.getCalledValue(); - ArgNodes = ECI.ArgNodes; + // (If the function was cloned, we have to map the cloned call instruction + // in CS back to the original call instruction.) + Instruction *OrigInst = + cast(getOldValueIfAvailable(CS.getInstruction())); + CF = isa(OrigInst)? + ECGraphs.getSomeCalleeForCallSite(cast(OrigInst)) : + ECGraphs.getSomeCalleeForCallSite(cast(OrigInst)); + + if (!CF) { + // FIXME: Unknown callees for a call-site. Warn and ignore. + std::cerr << "\n***\n*** WARNING (FuncTransform::visitCallSite): " + << "Unknown callees for call-site in function " + << CS.getCaller()->getName() << "\n***\n"; + return; + } + + // Get the common graph for the set of functions this call may invoke. + CalleeGraph = &ECGraphs.getDSGraph(*CF); + +#ifndef NDEBUG + // Verify that all potential callees at call site have the same DS graph. + const BUDataStructures::ActualCalleesTy& ActualCallees = + ECGraphs.getCBUDataStructures()->getActualCallees(); + BUDataStructures::ActualCalleesTy::const_iterator I, E; + for (tie(I, E) = ActualCallees.equal_range(OrigInst); I != E; ++I) + if (!I->second->isExternal()) + assert(CalleeGraph == &ECGraphs.getDSGraph(*I->second) && + "Callees at call site do not have a common graph!"); +#endif + + // Find the DS nodes for the arguments that need to be added, if any. + FuncInfo *CFI = PAInfo.getFuncInfo(*CF); + assert(CFI && "No function info for callee at indirect call?"); + ArgNodes = CFI->ArgNodes; + + if (ArgNodes.empty()) + return; // No arguments to add? Transformation is a noop! // Cast the function pointer to an appropriate type! std::vector ArgTys(ArgNodes.size(), @@ -383,13 +410,12 @@ for (CallSite::arg_iterator I = CS.arg_begin(), E = CS.arg_end(); I != E; ++I) ArgTys.push_back((*I)->getType()); - + FunctionType *FTy = FunctionType::get(TheCall->getType(), ArgTys, false); PointerType *PFTy = PointerType::get(FTy); - // If there are any pool arguments cast the function pointer to the right - // type. - NewCallee = new CastInst(NewCallee, PFTy, "tmp", TheCall); + // If there are any pool arguments cast the func ptr to the right type. + NewCallee = new CastInst(CS.getCalledValue(), PFTy, "tmp", TheCall); } Function::aiterator FAI = CF->abegin(), E = CF->aend(); From gaeke at cs.uiuc.edu Sun May 23 02:58:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 02:58:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405230757.CAA15944@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.67 -> 1.68 --- Log message: Untabify. --- Diffs of the changes: (+3 -3) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.67 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.68 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.67 Sun May 23 02:46:26 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 23 02:57:26 2004 @@ -523,11 +523,11 @@ LiveVariableSet &So = TF->LiveOutSet; for (LiveVariableSet::iterator SI = So.begin (), SE = So.end (); SI != SE; ++SI) { - Value *V = *SI; + Value *V = *SI; std::pair ai = getValueAllocState (TF, V); AllocInfo &Target = ai.first, &Source = ai.second; - if (Source != Target) - insertCopyMachineInstrs (Source, Target, MBB, V->getType ()); + if (Source != Target) + insertCopyMachineInstrs (Source, Target, MBB, V->getType ()); } // Get the set of registers used in this function which we saved in From vadve at cs.uiuc.edu Sun May 23 03:01:01 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 03:01:01 2004 Subject: [llvm-commits] CVS: llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp Message-ID: <200405230800.DAA32767@psmith.cs.uiuc.edu> Changes in directory llvm/lib/Analysis/DataStructure: CompleteBottomUp.cpp updated: 1.10 -> 1.11 --- Log message: Inline both direct and indirect callees in the CBU phase because a direct callee may have indirect callees and so may have changed. --- Diffs of the changes: (+34 -34) Index: llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp diff -u llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp:1.10 llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp:1.11 --- llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp:1.10 Fri Mar 5 16:04:07 2004 +++ llvm/lib/Analysis/DataStructure/CompleteBottomUp.cpp Sun May 23 03:00:34 2004 @@ -37,14 +37,13 @@ GlobalsGraph = new DSGraph(BU.getGlobalsGraph()); GlobalsGraph->setPrintAuxCalls(); - // Our call graph is the same as the BU data structures call graph - ActualCallees = BU.getActualCallees(); - #if 1 // REMOVE ME EVENTUALLY // FIXME: TEMPORARY (remove once finalization of indirect call sites in the // globals graph has been implemented in the BU pass) TDDataStructures &TD = getAnalysis(); + ActualCallees.clear(); + // The call graph extractable from the TD pass is _much more complete_ and // trustable than that generated by the BU pass so far. Until this is fixed, // we hack it like this: @@ -53,17 +52,23 @@ const std::vector &CSs = TD.getDSGraph(*MI).getFunctionCalls(); for (unsigned CSi = 0, e = CSs.size(); CSi != e; ++CSi) { - if (CSs[CSi].isIndirectCall()) { - Instruction *TheCall = CSs[CSi].getCallSite().getInstruction(); + Instruction *TheCall = CSs[CSi].getCallSite().getInstruction(); + if (CSs[CSi].isIndirectCall()) { // indirect call: insert all callees const std::vector &Callees = CSs[CSi].getCalleeNode()->getGlobals(); for (unsigned i = 0, e = Callees.size(); i != e; ++i) if (Function *F = dyn_cast(Callees[i])) ActualCallees.insert(std::make_pair(TheCall, F)); + } else { // direct call: insert the single callee directly + ActualCallees.insert(std::make_pair(TheCall, + CSs[CSi].getCalleeFunc())); } } } +#else + // Our call graph is the same as the BU data structures call graph + ActualCallees = BU.getActualCallees(); #endif std::vector Stack; @@ -183,35 +188,30 @@ "Call instruction occurs multiple times in graph??"); - // The Normal BU pass will have taken care of direct calls well already, - // don't worry about them. - - // FIXME: if a direct callee had indirect callees, it seems like they could - // be updated and we would have to reinline even direct calls! - - if (!CS.getCallSite().getCalledFunction()) { - // Loop over all of the actually called functions... - ActualCalleesTy::iterator I, E; - tie(I, E) = ActualCallees.equal_range(TheCall); - unsigned TNum = 0, Num = std::distance(I, E); - for (; I != E; ++I, ++TNum) { - Function *CalleeFunc = I->second; - if (!CalleeFunc->isExternal()) { - // Merge the callee's graph into this graph. This works for normal - // calls or for self recursion within an SCC. - DSGraph &GI = getOrCreateGraph(*CalleeFunc); - ++NumCBUInlines; - G.mergeInGraph(CS, *CalleeFunc, GI, DSGraph::KeepModRefBits | - DSGraph::StripAllocaBit | DSGraph::DontCloneCallNodes | - DSGraph::DontCloneAuxCallNodes); - DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1 - << ":" << TNum << "/" << Num-1 << "] for " - << CalleeFunc->getName() << "[" - << GI.getGraphSize() << "+" << GI.getAuxFunctionCalls().size() - << "] into '" /*<< G.getFunctionNames()*/ << "' [" - << G.getGraphSize() << "+" << G.getAuxFunctionCalls().size() - << "]\n"); - } + // Loop over all of the potentially called functions... + // Inline direct calls as well as indirect calls because the direct + // callee may have indirect callees and so may have changed. + // + ActualCalleesTy::iterator I, E; + tie(I, E) = ActualCallees.equal_range(TheCall); + unsigned TNum = 0, Num = std::distance(I, E); + for (; I != E; ++I, ++TNum) { + Function *CalleeFunc = I->second; + if (!CalleeFunc->isExternal()) { + // Merge the callee's graph into this graph. This works for normal + // calls or for self recursion within an SCC. + DSGraph &GI = getOrCreateGraph(*CalleeFunc); + ++NumCBUInlines; + G.mergeInGraph(CS, *CalleeFunc, GI, DSGraph::KeepModRefBits | + DSGraph::StripAllocaBit | DSGraph::DontCloneCallNodes | + DSGraph::DontCloneAuxCallNodes); + DEBUG(std::cerr << " Inlining graph [" << i << "/" << e-1 + << ":" << TNum << "/" << Num-1 << "] for " + << CalleeFunc->getName() << "[" + << GI.getGraphSize() << "+" << GI.getAuxFunctionCalls().size() + << "] into '" /*<< G.getFunctionNames()*/ << "' [" + << G.getGraphSize() << "+" << G.getAuxFunctionCalls().size() + << "]\n"); } } } From vadve at cs.uiuc.edu Sun May 23 03:03:00 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 03:03:00 2004 Subject: [llvm-commits] CVS: llvm/include/llvm/Support/CallSite.h Message-ID: <200405230802.DAA00326@psmith.cs.uiuc.edu> Changes in directory llvm/include/llvm/Support: CallSite.h updated: 1.13 -> 1.14 --- Log message: Add getCaller() method. --- Diffs of the changes: (+5 -0) Index: llvm/include/llvm/Support/CallSite.h diff -u llvm/include/llvm/Support/CallSite.h:1.13 llvm/include/llvm/Support/CallSite.h:1.14 --- llvm/include/llvm/Support/CallSite.h:1.13 Tue Nov 11 16:41:31 2003 +++ llvm/include/llvm/Support/CallSite.h Sun May 23 03:02:45 2004 @@ -22,6 +22,7 @@ #define LLVM_SUPPORT_CALLSITE_H #include "llvm/Instruction.h" +#include "llvm/BasicBlock.h" namespace llvm { @@ -59,6 +60,10 @@ /// getInstruction - Return the instruction this call site corresponds to /// Instruction *getInstruction() const { return I; } + + /// getCaller - Return the caller function for this call site + /// + Function *getCaller() const { return I->getParent()->getParent(); } /// getCalledValue - Return the pointer to function that is being called... /// From vadve at cs.uiuc.edu Sun May 23 03:06:03 2004 From: vadve at cs.uiuc.edu (Vikram Adve) Date: Sun May 23 03:06:03 2004 Subject: [llvm-commits] CVS: llvm/include/Support/EquivalenceClasses.h Message-ID: <200405230805.DAA00348@psmith.cs.uiuc.edu> Changes in directory llvm/include/Support: EquivalenceClasses.h updated: 1.6 -> 1.7 --- Log message: Remember the set of leaders. Also compute on demand and cache the equiv class for each leader. Finally, rename Elem2ECLeaderMap to Elem2LeaderMap (most of the changed lines are only due to the latter). --- Diffs of the changes: (+52 -32) Index: llvm/include/Support/EquivalenceClasses.h diff -u llvm/include/Support/EquivalenceClasses.h:1.6 llvm/include/Support/EquivalenceClasses.h:1.7 --- llvm/include/Support/EquivalenceClasses.h:1.6 Tue Nov 11 16:41:29 2003 +++ llvm/include/Support/EquivalenceClasses.h Sun May 23 03:05:14 2004 @@ -18,6 +18,7 @@ #define SUPPORT_EQUIVALENCECLASSES_H #include +#include #include namespace llvm { @@ -26,69 +27,88 @@ class EquivalenceClasses { // Maps each element to the element that is the leader of its // equivalence class. - std::map Elem2ECLeaderMap; + std::map Elem2LeaderMap; + // Maintains the set of leaders + std::set LeaderSet; + + // Caches the equivalence class for each leader + std::map > LeaderToEqClassMap; + // Make Element2 the leader of the union of classes Element1 and Element2 // Element1 and Element2 are presumed to be leaders of their respective // equivalence classes. void attach(ElemTy Element1, ElemTy Element2) { for (typename std::map::iterator ElemI = - Elem2ECLeaderMap.begin(), ElemE = Elem2ECLeaderMap.end(); + Elem2LeaderMap.begin(), ElemE = Elem2LeaderMap.end(); ElemI != ElemE; ++ElemI) { if (ElemI->second == Element1) - Elem2ECLeaderMap[ElemI->first] = Element2; + Elem2LeaderMap[ElemI->first] = Element2; } } public: - - void addElement (ElemTy NewElement) { - if (Elem2ECLeaderMap.find(NewElement) == Elem2ECLeaderMap.end()) - Elem2ECLeaderMap[NewElement] = NewElement; + // If an element has not yet in any class, make it a separate new class. + // Return the leader of the class containing the element. + ElemTy addElement (ElemTy NewElement) { + typename std::map::iterator ElemI = + Elem2LeaderMap.find(NewElement); + if (ElemI == Elem2LeaderMap.end()) { + Elem2LeaderMap[NewElement] = NewElement; + LeaderSet.insert(NewElement); + return NewElement; + } + else + return ElemI->second; } - ElemTy findClass(ElemTy Element) { - if (Elem2ECLeaderMap.find(Element) == Elem2ECLeaderMap.end()) - return 0; - else - return Elem2ECLeaderMap[Element]; + ElemTy findClass(ElemTy Element) const { + typename std::map::const_iterator I = + Elem2LeaderMap.find(Element); + return (I == Elem2LeaderMap.end())? (ElemTy) 0 : I->second; } /// Attach the set with Element1 to the set with Element2 adding Element1 and /// Element2 to the set of equivalence classes if they are not there already. /// Implication: Make Element1 the element in the smaller set. + /// Take Leader[Element1] out of the set of leaders. void unionSetsWith(ElemTy Element1, ElemTy Element2) { // If either Element1 or Element2 does not already exist, include it - if (Elem2ECLeaderMap.find(Element1) == Elem2ECLeaderMap.end()) - Elem2ECLeaderMap[Element1] = Element1; - if (Elem2ECLeaderMap.find(Element2) == Elem2ECLeaderMap.end()) - Elem2ECLeaderMap[Element2] = Element2; - - attach(Elem2ECLeaderMap[Element1], Elem2ECLeaderMap[Element2]); + const ElemTy& leader1 = addElement(Element1); + const ElemTy& leader2 = addElement(Element2); + assert(leader1 != (ElemTy) 0 && leader2 != (ElemTy) 0); + if (leader1 != leader2) { + attach(leader1, leader2); + LeaderSet.erase(leader1); + } } - // Returns a vector containing all the elements in the equivalent class + // Returns a vector containing all the elements in the equivalence class // including Element1 - std::vector getEqClass(ElemTy Element1) { - std::vector EqClass; + const std::set & getEqClass(ElemTy Element1) { + assert(Elem2LeaderMap.find(Element1) != Elem2LeaderMap.end()); + const ElemTy classLeader = Elem2LeaderMap[Element1]; - if (Elem2ECLeaderMap.find(EqClass) == Elem2ECLeaderMap.end()) - return EqClass; + std::set & EqClass = LeaderToEqClassMap[classLeader]; - ElemTy classLeader = Elem2ECLeaderMap[Element1]; - for (typename std::map::iterator ElemI = - Elem2ECLeaderMap.begin(), ElemE = Elem2ECLeaderMap.end(); - ElemI != ElemE; ++ElemI) { - if (ElemI->second == classLeader) - EqClass.push_back(ElemI->first); + // If the EqClass vector is empty, it has not been computed yet: do it now + if (EqClass.empty()) { + for (typename std::map::iterator + ElemI = Elem2LeaderMap.begin(), ElemE = Elem2LeaderMap.end(); + ElemI != ElemE; ++ElemI) + if (ElemI->second == classLeader) + EqClass.insert(ElemI->first); + assert(! EqClass.empty()); // must at least include the leader } return EqClass; } - std::map& getLeaderMap() { - return Elem2ECLeaderMap ; - } + std::set& getLeaderSet() { return LeaderSet; } + const std::set& getLeaderSet() const { return LeaderSet; } + + std::map& getLeaderMap() { return Elem2LeaderMap;} + const std::map& getLeaderMap() const { return Elem2LeaderMap;} }; } // End llvm namespace From gaeke at cs.uiuc.edu Sun May 23 05:06:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 05:06:01 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Message-ID: <200405231005.FAA00467@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: UnpackTraceFunction.cpp updated: 1.68 -> 1.69 --- Log message: Move declaration of UnpackTraceFunction to reopt/UnpackTraceFunction.h. Include it. Prune other excess #includes. createUnpackTraceFunctionPass() is history. Give UnpackTraceFunction::runOnMachineFunction() a new doxygen comment. --- Diffs of the changes: (+8 -63) Index: reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp diff -u reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.68 reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.69 --- reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp:1.68 Sun May 23 02:57:26 2004 +++ reopt/lib/LightWtProfiling/UnpackTraceFunction.cpp Sun May 23 05:05:02 2004 @@ -13,16 +13,15 @@ // //===----------------------------------------------------------------------===// +#include "reopt/UnpackTraceFunction.h" #include "reopt/TraceToFunction.h" -#include "llvm/CodeGen/MachineFunctionPass.h" +#include "reopt/MappingInfo.h" #include "llvm/CodeGen/MachineFunctionInfo.h" -#include "llvm/CodeGen/MachineInstr.h" #include "llvm/Module.h" #include "llvm/Argument.h" #include "llvm/Assembly/Writer.h" #include "llvm/Support/InstIterator.h" #include "Support/Debug.h" -#include "reopt/MappingInfo.h" #include "../../../../lib/Target/SparcV9/RegAlloc/AllocInfo.h" #include "../../../../lib/Target/SparcV9/RegAlloc/PhyRegAlloc.h" #include "../../../../lib/Target/SparcV9/SparcV9RegInfo.h" @@ -30,47 +29,6 @@ namespace llvm { -/// This pass inserts copies in two places in the machine -/// code for TF->TraceFn: first, at the entry basic block to copy the values in -/// TF->LiveInSet from TF->MatrixFn's registers to TF->TraceFn's registers, and -/// second, at each exit basic block to copy the values in TF->LiveOutSet from -/// TF->TraceFn's registers to TF->MatrixFn's registers. -/// -class UnpackTraceFunction : public MachineFunctionPass { - TargetMachine *TM; - TraceFunction *TF; - - /// Static stack size of the MachineFunction. Filled in by rewriteProlog () - /// by calling getStaticStackSize (), and then used again by rewriteEpilog (). - /// - unsigned StaticStackSize; - - /// Total stack size of the MachineFunction, including space for regs - /// modified in TraceFn to be saved. - /// - int TotalStackSize; - - /// Registers clobbered in the trace. Filled in by findRegsUsedInFunction (). - /// - std::set RegsToRestore; - std::set RegsToSave; - - unsigned getStaticStackSize (MachineFunction &MF); - unsigned stackOffsetForReg (unsigned R); - void findRegsToRestore (MachineFunction &MF); - void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target, - MachineBasicBlock &B, const Type *Ty); - void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B); - const MachineInstr *containsReturnInstr (MachineBasicBlock &B); - void rewriteProlog (MachineFunction &MF, MachineBasicBlock &MBB); - void rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB); -public: - UnpackTraceFunction (TargetMachine *_TM, TraceFunction *_TF) : - TM (_TM), TF (_TF) { } - const char *getPassName () const { return "Unpack trace function"; } - virtual bool runOnMachineFunction (MachineFunction &MF); -}; - /// Structure describing a single live variable copy. /// struct CopyInfo { @@ -91,15 +49,6 @@ return OS; } -/// Create a new UnpackTraceFunction pass that will unpack a given -/// TraceFunction, for which machine code has been generated, into -/// its matrix function. -/// -FunctionPass *createUnpackTraceFunctionPass (TargetMachine *TM, - TraceFunction *TF) { - return new UnpackTraceFunction (TM, TF); -} - // Ripped off from SparcV9PrologEpilogInserter unsigned UnpackTraceFunction::getStaticStackSize (MachineFunction &MF) { const TargetFrameInfo& frameInfo = MF.getTarget().getFrameInfo(); @@ -571,16 +520,12 @@ insertBranchMachineInstrs (ReturnAddress, MBB); } -/// This method is provided with MF, which is the -/// machine code for TF->TraceFn. We modify it (according to the description -/// of the pass, above) using the information provided along with TF when this -/// Pass object was created. -/// -/// Admittedly, that is a pretty lame design, but for now, it means that we can -/// only deal with one TraceFn and one MatrixFn in any given -/// UnpackTraceFunction pass. If this stuff gets popular, we can have -/// TraceFunctionPasses and TraceMachineFunctionPasses, or the Trace stuff can -/// be an AnalysisPass, or something. +/// runOnMachineFunction - Prepare MF, which is the machine code for +/// TF->TraceFn, to be executed using a low-overhead calling convention for +/// traces. We use the live-variable and return-block information in TF and the +/// mapping information provided by the SparcV9 backend. We assume that +/// someone has called setTraceFunction(TraceFunction *) to set TF to point to +/// the TraceFunction we are interested in. /// bool UnpackTraceFunction::runOnMachineFunction (MachineFunction &MF) { // Make sure we are looking at the MachineFunction corresponding to the From gaeke at cs.uiuc.edu Sun May 23 05:06:08 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 05:06:08 2004 Subject: [llvm-commits] CVS: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Message-ID: <200405231005.FAA00460@seraph.cs.uiuc.edu> Changes in directory reopt/lib/LightWtProfiling: RuntimeOptimizations.cpp updated: 1.38 -> 1.39 --- Log message: Include UnpackTraceFunction.h. Explicitly save the UnpackTraceFunction object so that we can call setTraceFunction() on it as necessary. Move the FunctionPassManager out to global scope. Move the adding of passes into addPassesToReoptimizeTrace(). In optimizeTrace()'s initialization section, don't check each pointer individually. Also, set up the FunctionPassManager here and add passes to it. This means that the only thing we need to do on second and subsequent calls to optimizeTrace() is set the TraceFunction and run the PassManager. --- Diffs of the changes: (+36 -23) Index: reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp diff -u reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.38 reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.39 --- reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp:1.38 Sun May 23 02:46:23 2004 +++ reopt/lib/LightWtProfiling/RuntimeOptimizations.cpp Sun May 23 05:05:01 2004 @@ -14,6 +14,7 @@ //===----------------------------------------------------------------------===// #include "ReoptimizerInternal.h" +#include "reopt/UnpackTraceFunction.h" #include "reopt/TraceToFunction.h" #include "reopt/VirtualMem.h" #include "reopt/InstrUtils.h" @@ -41,6 +42,8 @@ static TargetMachine *Target = 0; static const TargetData *TD = 0; static MachineCodeEmitter *MCE = 0; +static FunctionPassManager *PM = 0; +static UnpackTraceFunction *UTF = 0; extern bool SaveStateToModule; extern bool SaveRegAllocState; @@ -82,6 +85,29 @@ << std::dec); } +static void addPassesToReoptimizeTrace (FunctionPassManager &PM, + const TargetData *TD, + TargetMachine *Target, + MachineCodeEmitter *MCE) { + // Verify that the generated function's bytecode is good, then compile it + // down to machine code. Then, "unpack" it back into its matrix function. + // FIXME: Register allocation hints also need to be added to the PassManager, + // so that we do not get clobbered by the overhead of adding copies in + // UnpackTraceFunction. + DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n", + &std::cerr))); + PM.add (new TargetData (*TD)); + DEBUG (PM.add (createVerifierPass ())); + Target->getJITInfo ()->addPassesToJITCompile (PM); + DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, + "Before unpacking:\n"))); + UTF = new UnpackTraceFunction (Target); + PM.add (UTF); + DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, + "After unpacking:\n"))); + Target->addPassesToEmitMachineCode (PM, *MCE); +} + /// This method is called when we have finally constructed a /// trace. The first parameter is the vector of basic blocks that form /// the trace; the second parameter is the starting @@ -100,10 +126,13 @@ static bool initDone = false; if (!initDone) { assert (MP); - if (!IL) IL = new DefaultIntrinsicLowering (); - if (!Target) Target = allocateSparcV9TargetMachine (*MP->getModule (), IL); - if (!TD) TD = &Target->getTargetData (); - if (!MCE) MCE = createTraceOptEmitter (*TD); + IL = new DefaultIntrinsicLowering (); + Target = allocateSparcV9TargetMachine (*MP->getModule (), IL); + TD = &Target->getTargetData (); + MCE = createTraceOptEmitter (*TD); + // Set up the pass manager and trace function unpacker + PM = new FunctionPassManager (MP); + addPassesToReoptimizeTrace (*PM, TD, Target, MCE); initDone = true; // Force the SPARCv9 register allocator to save its state into a global @@ -118,31 +147,15 @@ DEBUG (WriteTraceToFile (T)); TraceFunction *TF = TraceFunction::get (T); - // Verify that the generated function's bytecode is good, then compile it - // down to machine code. Then, "unpack" it back into its matrix function. - // FIXME: Register allocation hints also need to be added to the PassManager, - // so that we do not get clobbered by the overhead of adding copies in - // UnpackTraceFunction. - static FunctionPassManager PM (MP); - DEBUG(PM.add (new PrintFunctionPass ("Function created from trace:\n", - &std::cerr))); - PM.add (new TargetData (*TD)); - PM.add (createVerifierPass ()); - Target->getJITInfo ()->addPassesToJITCompile (PM); - DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, - "Before unpacking:\n"))); - PM.add (createUnpackTraceFunctionPass (Target, TF)); - DEBUG(PM.add (createMachineFunctionPrinterPass (&std::cerr, - "After unpacking:\n"))); - Target->addPassesToEmitMachineCode (PM, *MCE); - PM.run (*TF->TraceFn); + // Run optimization passes, then unpack the trace function. + UTF->setTraceFunction (TF); // Pass out-of-band information to UTF... + PM->run (*TF->TraceFn); // Add a branch from address A (the parameter to this method) to the // entry basic block of the unpacked TraceFn. Future executions of the trace // will proceed from the optimized version of the code. uint64_t traceStartAddr = getPointerToGlobalIfAvailable (TF->TraceFn); assert (traceStartAddr && "Address of code for TraceFn was NULL after JIT?!"); - DEBUG(std::cerr << "Writing branch at 0x" << std::hex << a << " to point to 0x" << traceStartAddr << std::dec << "\n"); vm->writeBranchInstruction(a, traceStartAddr); From gaeke at cs.uiuc.edu Sun May 23 05:06:14 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 05:06:14 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/TraceToFunction.h Message-ID: <200405231005.FAA00453@seraph.cs.uiuc.edu> Changes in directory reopt/include/reopt: TraceToFunction.h updated: 1.11 -> 1.12 --- Log message: Remove declaration of createUnpackTraceFunctionPass(). --- Diffs of the changes: (+0 -6) Index: reopt/include/reopt/TraceToFunction.h diff -u reopt/include/reopt/TraceToFunction.h:1.11 reopt/include/reopt/TraceToFunction.h:1.12 --- reopt/include/reopt/TraceToFunction.h:1.11 Mon May 10 19:20:00 2004 +++ reopt/include/reopt/TraceToFunction.h Sun May 23 05:05:00 2004 @@ -89,12 +89,6 @@ } }; -class FunctionPass; -class TargetMachine; - -FunctionPass *createUnpackTraceFunctionPass (TargetMachine *TM, - TraceFunction *TF); - } // end namespace llvm #endif // TRACETOFUNCTION_H From gaeke at cs.uiuc.edu Sun May 23 05:09:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 05:09:01 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/UnpackTraceFunction.h Message-ID: <200405231008.FAA00501@seraph.cs.uiuc.edu> Changes in directory reopt/include/reopt: UnpackTraceFunction.h added (r1.1) --- Log message: Definition of class UnpackTraceFunction moved into this public header file. --- Diffs of the changes: (+64 -0) Index: reopt/include/reopt/UnpackTraceFunction.h diff -c /dev/null reopt/include/reopt/UnpackTraceFunction.h:1.1 *** /dev/null Sun May 23 05:08:48 2004 --- reopt/include/reopt/UnpackTraceFunction.h Sun May 23 05:08:38 2004 *************** *** 0 **** --- 1,64 ---- + //===- reopt/UnpackTraceFunction.h -------------------------------*- C++ -*--=// + // + // Unpackage functions previously formed from traces by TraceToFunction. + // + //===----------------------------------------------------------------------===// + + #ifndef REOPT_UNPACKTRACEFUNCTION_H + #define REOPT_UNPACKTRACEFUNCTION_H + + #include "llvm/CodeGen/MachineFunctionPass.h" + #include + + namespace llvm { + + class TargetMachine; + class TraceFunction; + class AllocInfo; + class Type; + + /// This pass inserts copies in two places in the machine + /// code for TF->TraceFn: first, at the entry basic block to copy the values in + /// TF->LiveInSet from TF->MatrixFn's registers to TF->TraceFn's registers, and + /// second, at each exit basic block to copy the values in TF->LiveOutSet from + /// TF->TraceFn's registers to TF->MatrixFn's registers. + /// + class UnpackTraceFunction : public MachineFunctionPass { + TargetMachine *TM; + TraceFunction *TF; + + /// Static stack size of the MachineFunction. Filled in by rewriteProlog () + /// by calling getStaticStackSize (), and then used again by rewriteEpilog (). + /// + unsigned StaticStackSize; + + /// Total stack size of the MachineFunction, including space for regs + /// modified in TraceFn to be saved. + /// + int TotalStackSize; + + /// Registers clobbered in the trace. Filled in by findRegsUsedInFunction (). + /// + std::set RegsToRestore; + std::set RegsToSave; + + unsigned getStaticStackSize (MachineFunction &MF); + unsigned stackOffsetForReg (unsigned R); + void findRegsToRestore (MachineFunction &MF); + void insertCopyMachineInstrs (AllocInfo &Source, AllocInfo &Target, + MachineBasicBlock &B, const Type *Ty); + void insertBranchMachineInstrs (uint64_t Target, MachineBasicBlock &B); + const MachineInstr *containsReturnInstr (MachineBasicBlock &B); + void rewriteProlog (MachineFunction &MF, MachineBasicBlock &MBB); + void rewriteEpilog (MachineFunction &MF, MachineBasicBlock &MBB); + + public: + UnpackTraceFunction (TargetMachine *TM_) : TM (TM_), TF (0) { } + void setTraceFunction (TraceFunction *TF_) { TF = TF_; } + const char *getPassName () const { return "Unpack trace function"; } + virtual bool runOnMachineFunction (MachineFunction &MF); + }; + + } // end namespace llvm + + #endif // REOPT_UNPACKTRACEFUNCTION_H From gaeke at cs.uiuc.edu Sun May 23 05:10:01 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 05:10:01 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/GetTraceTime.h CFG.h Message-ID: <200405231009.FAA00541@seraph.cs.uiuc.edu> Changes in directory reopt/include/reopt: GetTraceTime.h updated: 1.6 -> 1.7 CFG.h updated: 1.3 -> 1.4 --- Log message: Regularize #include guards. --- Diffs of the changes: (+4 -4) Index: reopt/include/reopt/GetTraceTime.h diff -u reopt/include/reopt/GetTraceTime.h:1.6 reopt/include/reopt/GetTraceTime.h:1.7 --- reopt/include/reopt/GetTraceTime.h:1.6 Wed Nov 19 16:51:41 2003 +++ reopt/include/reopt/GetTraceTime.h Sun May 23 05:09:42 2004 @@ -7,8 +7,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_REOPTIMIZER_TRACECACHE_GETTRACETIME_H -#define LLVM_REOPTIMIZER_TRACECACHE_GETTRACETIME_H +#ifndef REOPT_GETTRACETIME_H +#define REOPT_GETTRACETIME_H namespace llvm { Index: reopt/include/reopt/CFG.h diff -u reopt/include/reopt/CFG.h:1.3 reopt/include/reopt/CFG.h:1.4 --- reopt/include/reopt/CFG.h:1.3 Wed Nov 19 16:51:41 2003 +++ reopt/include/reopt/CFG.h Sun May 23 05:09:42 2004 @@ -4,8 +4,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_REOPTIMIZER_CFG_H -#define LLVM_REOPTIMIZER_CFG_H +#ifndef REOPT_CFG_H +#define REOPT_CFG_H #include #include From gaeke at cs.uiuc.edu Sun May 23 05:10:08 2004 From: gaeke at cs.uiuc.edu (Brian Gaeke) Date: Sun May 23 05:10:08 2004 Subject: [llvm-commits] CVS: reopt/include/reopt/TraceToFunction.h Message-ID: <200405231009.FAA00548@seraph.cs.uiuc.edu> Changes in directory reopt/include/reopt: TraceToFunction.h updated: 1.12 -> 1.13 --- Log message: Regularize #include guards and fix head-of-file comment. --- Diffs of the changes: (+4 -4) Index: reopt/include/reopt/TraceToFunction.h diff -u reopt/include/reopt/TraceToFunction.h:1.12 reopt/include/reopt/TraceToFunction.h:1.13 --- reopt/include/reopt/TraceToFunction.h:1.12 Sun May 23 05:05:00 2004 +++ reopt/include/reopt/TraceToFunction.h Sun May 23 05:09:43 2004 @@ -1,12 +1,12 @@ -//===- LightWtProfiling/TraceToFunction.h ------------------------*- C++ -*--=// +//===- reopt/TraceToFunction.h -----------------------------------*- C++ -*--=// // // Repackage traces as functions, so that global (function-level) optimizations // can be applied to traces. // //===----------------------------------------------------------------------===// -#ifndef TRACETOFUNCTION_H -#define TRACETOFUNCTION_H +#ifndef REOPT_TRACETOFUNCTION_H +#define REOPT_TRACETOFUNCTION_H #include "llvm/Analysis/Trace.h" #include "llvm/Function.h" @@ -91,4 +91,4 @@ } // end namespace llvm -#endif // TRACETOFUNCTION_H +#endif // REOPT_TRACETOFUNCTION_H From alkis at cs.uiuc.edu Sun May 23 05:14:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 05:14:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405231012.FAA12392@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.7 -> 1.8 --- Log message: Correct java opcode name. --- Diffs of the changes: (+4 -4) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.7 llvm-java/lib/Compiler/Compiler.cpp:1.8 --- llvm-java/lib/Compiler/Compiler.cpp:1.7 Sat May 22 21:08:01 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sun May 23 05:11:59 2004 @@ -142,8 +142,8 @@ case IF_ICMPGE: case IF_ICMPGT: case IF_ICMPLE: - case IF_ICMPACMPEQ: - case IF_ICMPACMPNE: + case IF_IACMPEQ: + case IF_IACMPNE: case IFNULL: case IFNONNULL: { unsigned index = readShortUnsigned(code, i); @@ -531,8 +531,8 @@ case IF_ICMPGE: case IF_ICMPGT: case IF_ICMPLE: - case IF_ICMPACMPEQ: - case IF_ICMPACMPNE: + case IF_IACMPEQ: + case IF_IACMPNE: case GOTO: case JSR: case RET: From alkis at cs.uiuc.edu Sun May 23 05:14:09 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 05:14:09 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405231012.FAA12393@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.2 -> 1.3 --- Log message: Correct java opcode name. --- Diffs of the changes: (+2 -2) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.2 llvm-java/include/llvm/Java/Bytecode.h:1.3 --- llvm-java/include/llvm/Java/Bytecode.h:1.2 Fri May 21 16:35:56 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Sun May 23 05:12:00 2004 @@ -184,8 +184,8 @@ IF_ICMPGE = 0xA2, IF_ICMPGT = 0xA3, IF_ICMPLE = 0xA4, - IF_ICMPACMPEQ = 0xA5, - IF_ICMPACMPNE = 0xA6, + IF_IACMPEQ = 0xA5, + IF_IACMPNE = 0xA6, GOTO = 0xA7, JSR = 0xA8, RET = 0xA9, From alkis at cs.uiuc.edu Sun May 23 05:19:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 05:19:01 2004 Subject: [llvm-commits] CVS: llvm-java/include/llvm/Java/Bytecode.h Message-ID: <200405231017.FAA13159@zion.cs.uiuc.edu> Changes in directory llvm-java/include/llvm/Java: Bytecode.h updated: 1.3 -> 1.4 --- Log message: Move immediate reading functions to bytecode header. --- Diffs of the changes: (+244 -209) Index: llvm-java/include/llvm/Java/Bytecode.h diff -u llvm-java/include/llvm/Java/Bytecode.h:1.3 llvm-java/include/llvm/Java/Bytecode.h:1.4 --- llvm-java/include/llvm/Java/Bytecode.h:1.3 Sun May 23 05:12:00 2004 +++ llvm-java/include/llvm/Java/Bytecode.h Sun May 23 05:17:31 2004 @@ -16,214 +16,249 @@ #include -namespace llvm { namespace Java { namespace Opcode { +namespace llvm { namespace Java { - enum { - NOP = 0x00, - ACONST_NULL = 0x01, - ICONST_M1 = 0x02, - ICONST_0 = 0x03, - ICONST_1 = 0x04, - ICONST_2 = 0x05, - ICONST_3 = 0x06, - ICONST_4 = 0x07, - ICONST_5 = 0x08, - LCONST_0 = 0x09, - LCONST_1 = 0x0A, - FCONST_0 = 0x0B, - FCONST_1 = 0x0C, - FCONST_2 = 0x0D, - DCONST_0 = 0x0E, - DCONST_1 = 0x0F, - BIPUSH = 0x10, - SIPUSH = 0x11, - LDC = 0x12, - LDC_W = 0x13, - LDC2_W = 0x14, - ILOAD = 0x15, - LLOAD = 0x16, - FLOAD = 0x17, - DLOAD = 0x18, - ALOAD = 0x19, - ILOAD_0 = 0x1A, - ILOAD_1 = 0x1B, - ILOAD_2 = 0x1C, - ILOAD_3 = 0x1D, - LLOAD_0 = 0x1E, - LLOAD_1 = 0x1F, - LLOAD_2 = 0x20, - LLOAD_3 = 0x21, - FLOAD_0 = 0x22, - FLOAD_1 = 0x23, - FLOAD_2 = 0x24, - FLOAD_3 = 0x25, - DLOAD_0 = 0x26, - DLOAD_1 = 0x27, - DLOAD_2 = 0x28, - DLOAD_3 = 0x29, - ALOAD_0 = 0x2A, - ALOAD_1 = 0x2B, - ALOAD_2 = 0x2C, - ALOAD_3 = 0x2D, - IALOAD = 0x2E, - LALOAD = 0x2F, - FALOAD = 0x30, - DALOAD = 0x31, - AALOAD = 0x32, - BALOAD = 0x33, - CALOAD = 0x34, - SALOAD = 0x35, - ISTORE = 0x36, - LSTORE = 0x37, - FSTORE = 0x38, - DSTORE = 0x39, - ASTORE = 0x3A, - ISTORE_0 = 0x3B, - ISTORE_1 = 0x3C, - ISTORE_2 = 0x3D, - ISTORE_3 = 0x3E, - LSTORE_0 = 0x3F, - LSTORE_1 = 0x40, - LSTORE_2 = 0x41, - LSTORE_3 = 0x42, - FSTORE_0 = 0x43, - FSTORE_1 = 0x44, - FSTORE_2 = 0x45, - FSTORE_3 = 0x46, - DSTORE_0 = 0x47, - DSTORE_1 = 0x48, - DSTORE_2 = 0x49, - DSTORE_3 = 0x4A, - ASTORE_0 = 0x4B, - ASTORE_1 = 0x4C, - ASTORE_2 = 0x4D, - ASTORE_3 = 0x4E, - IASTORE = 0x4F, - LASTORE = 0x50, - FASTORE = 0x51, - DASTORE = 0x52, - AASTORE = 0x53, - BASTORE = 0x54, - CASTORE = 0x55, - SASTORE = 0x56, - POP = 0x57, - POP2 = 0x58, - DUP = 0x59, - DUP_X1 = 0x5A, - DUP_X2 = 0x5B, - DUP2 = 0x5C, - DUP2_X1 = 0x5D, - DUP2_X2 = 0x5E, - SWAP = 0x5F, - IADD = 0x60, - LADD = 0x61, - FADD = 0x62, - DADD = 0x63, - ISUB = 0x64, - LSUB = 0x65, - FSUB = 0x66, - DSUB = 0x67, - IMUL = 0x68, - LMUL = 0x69, - FMUL = 0x6A, - DMUL = 0x6B, - IDIV = 0x6C, - LDIV = 0x6D, - FDIV = 0x6E, - DDIV = 0x6F, - IREM = 0x70, - LREM = 0x71, - FREM = 0x72, - DREM = 0x73, - INEG = 0x74, - LNEG = 0x75, - FNEG = 0x76, - DNEG = 0x77, - ISHL = 0x78, - LSHL = 0x79, - ISHR = 0x7A, - LSHR = 0x7B, - IUSHR = 0x7C, - LUSHR = 0x7D, - IAND = 0x7E, - LAND = 0x7F, - IOR = 0x80, - LOR = 0x81, - IXOR = 0x82, - LXOR = 0x83, - IINC = 0x84, - I2L = 0x85, - I2F = 0x86, - I2D = 0x87, - L2I = 0x88, - L2F = 0x89, - L2D = 0x8A, - F2I = 0x8B, - F2L = 0x8C, - F2D = 0x8D, - D2I = 0x8E, - D2L = 0x8F, - D2F = 0x90, - I2B = 0x91, - I2C = 0x92, - I2S = 0x93, - LCMP = 0x94, - FCMPL = 0x95, - FCMPG = 0x96, - DCMPL = 0x97, - DCMPG = 0x98, - IFEQ = 0x99, - IFNE = 0x9A, - IFLT = 0x9B, - IFGE = 0x9C, - IFGT = 0x9D, - IFLE = 0x9E, - IF_ICMPEQ = 0x9F, - IF_ICMPNE = 0xA0, - IF_ICMPLT = 0xA1, - IF_ICMPGE = 0xA2, - IF_ICMPGT = 0xA3, - IF_ICMPLE = 0xA4, - IF_IACMPEQ = 0xA5, - IF_IACMPNE = 0xA6, - GOTO = 0xA7, - JSR = 0xA8, - RET = 0xA9, - TABLESWITCH = 0xAA, - LOOKUPSWITCH = 0xAB, - IRETURN = 0xAC, - LRETURN = 0xAD, - FRETURN = 0xAE, - DRETURN = 0xAF, - ARETURN = 0xB0, - RETURN = 0xB1, - GETSTATIC = 0xB2, - PUTSTATIC = 0xB3, - GETFIELD = 0xB4, - PUTFIELD = 0xB5, - INVOKEVIRTUAL = 0xB6, - INVOKESPECIAL = 0xB7, - INVOKESTATIC = 0xB8, - INVOKEINTERFACE = 0xB9, - XXXUNUSEDXXX = 0xBA, - NEW = 0xBB, - NEWARRAY = 0xBC, - ANEWARRAY = 0xBD, - ARRAYLENGTH = 0xBE, - ATHROW = 0xBF, - CHECKCAST = 0xC0, - INSTANCEOF = 0xC1, - MONITORENTER = 0xC2, - MONITOREXIT = 0xC3, - WIDE = 0xC4, - MULTIANEWARRAY = 0xC5, - IFNULL = 0xC6, - IFNONNULL = 0xC7, - GOTO_W = 0xC8, - JSR_W = 0xC9, - BREAKPOINT = 0xCA, - IMPDEP1 = 0xFE, - IMPDEP2 = 0xFF, - }; + namespace Opcode { -} } } // namespace llvm::Java::BC + enum { + NOP = 0x00, + ACONST_NULL = 0x01, + ICONST_M1 = 0x02, + ICONST_0 = 0x03, + ICONST_1 = 0x04, + ICONST_2 = 0x05, + ICONST_3 = 0x06, + ICONST_4 = 0x07, + ICONST_5 = 0x08, + LCONST_0 = 0x09, + LCONST_1 = 0x0A, + FCONST_0 = 0x0B, + FCONST_1 = 0x0C, + FCONST_2 = 0x0D, + DCONST_0 = 0x0E, + DCONST_1 = 0x0F, + BIPUSH = 0x10, + SIPUSH = 0x11, + LDC = 0x12, + LDC_W = 0x13, + LDC2_W = 0x14, + ILOAD = 0x15, + LLOAD = 0x16, + FLOAD = 0x17, + DLOAD = 0x18, + ALOAD = 0x19, + ILOAD_0 = 0x1A, + ILOAD_1 = 0x1B, + ILOAD_2 = 0x1C, + ILOAD_3 = 0x1D, + LLOAD_0 = 0x1E, + LLOAD_1 = 0x1F, + LLOAD_2 = 0x20, + LLOAD_3 = 0x21, + FLOAD_0 = 0x22, + FLOAD_1 = 0x23, + FLOAD_2 = 0x24, + FLOAD_3 = 0x25, + DLOAD_0 = 0x26, + DLOAD_1 = 0x27, + DLOAD_2 = 0x28, + DLOAD_3 = 0x29, + ALOAD_0 = 0x2A, + ALOAD_1 = 0x2B, + ALOAD_2 = 0x2C, + ALOAD_3 = 0x2D, + IALOAD = 0x2E, + LALOAD = 0x2F, + FALOAD = 0x30, + DALOAD = 0x31, + AALOAD = 0x32, + BALOAD = 0x33, + CALOAD = 0x34, + SALOAD = 0x35, + ISTORE = 0x36, + LSTORE = 0x37, + FSTORE = 0x38, + DSTORE = 0x39, + ASTORE = 0x3A, + ISTORE_0 = 0x3B, + ISTORE_1 = 0x3C, + ISTORE_2 = 0x3D, + ISTORE_3 = 0x3E, + LSTORE_0 = 0x3F, + LSTORE_1 = 0x40, + LSTORE_2 = 0x41, + LSTORE_3 = 0x42, + FSTORE_0 = 0x43, + FSTORE_1 = 0x44, + FSTORE_2 = 0x45, + FSTORE_3 = 0x46, + DSTORE_0 = 0x47, + DSTORE_1 = 0x48, + DSTORE_2 = 0x49, + DSTORE_3 = 0x4A, + ASTORE_0 = 0x4B, + ASTORE_1 = 0x4C, + ASTORE_2 = 0x4D, + ASTORE_3 = 0x4E, + IASTORE = 0x4F, + LASTORE = 0x50, + FASTORE = 0x51, + DASTORE = 0x52, + AASTORE = 0x53, + BASTORE = 0x54, + CASTORE = 0x55, + SASTORE = 0x56, + POP = 0x57, + POP2 = 0x58, + DUP = 0x59, + DUP_X1 = 0x5A, + DUP_X2 = 0x5B, + DUP2 = 0x5C, + DUP2_X1 = 0x5D, + DUP2_X2 = 0x5E, + SWAP = 0x5F, + IADD = 0x60, + LADD = 0x61, + FADD = 0x62, + DADD = 0x63, + ISUB = 0x64, + LSUB = 0x65, + FSUB = 0x66, + DSUB = 0x67, + IMUL = 0x68, + LMUL = 0x69, + FMUL = 0x6A, + DMUL = 0x6B, + IDIV = 0x6C, + LDIV = 0x6D, + FDIV = 0x6E, + DDIV = 0x6F, + IREM = 0x70, + LREM = 0x71, + FREM = 0x72, + DREM = 0x73, + INEG = 0x74, + LNEG = 0x75, + FNEG = 0x76, + DNEG = 0x77, + ISHL = 0x78, + LSHL = 0x79, + ISHR = 0x7A, + LSHR = 0x7B, + IUSHR = 0x7C, + LUSHR = 0x7D, + IAND = 0x7E, + LAND = 0x7F, + IOR = 0x80, + LOR = 0x81, + IXOR = 0x82, + LXOR = 0x83, + IINC = 0x84, + I2L = 0x85, + I2F = 0x86, + I2D = 0x87, + L2I = 0x88, + L2F = 0x89, + L2D = 0x8A, + F2I = 0x8B, + F2L = 0x8C, + F2D = 0x8D, + D2I = 0x8E, + D2L = 0x8F, + D2F = 0x90, + I2B = 0x91, + I2C = 0x92, + I2S = 0x93, + LCMP = 0x94, + FCMPL = 0x95, + FCMPG = 0x96, + DCMPL = 0x97, + DCMPG = 0x98, + IFEQ = 0x99, + IFNE = 0x9A, + IFLT = 0x9B, + IFGE = 0x9C, + IFGT = 0x9D, + IFLE = 0x9E, + IF_ICMPEQ = 0x9F, + IF_ICMPNE = 0xA0, + IF_ICMPLT = 0xA1, + IF_ICMPGE = 0xA2, + IF_ICMPGT = 0xA3, + IF_ICMPLE = 0xA4, + IF_IACMPEQ = 0xA5, + IF_IACMPNE = 0xA6, + GOTO = 0xA7, + JSR = 0xA8, + RET = 0xA9, + TABLESWITCH = 0xAA, + LOOKUPSWITCH = 0xAB, + IRETURN = 0xAC, + LRETURN = 0xAD, + FRETURN = 0xAE, + DRETURN = 0xAF, + ARETURN = 0xB0, + RETURN = 0xB1, + GETSTATIC = 0xB2, + PUTSTATIC = 0xB3, + GETFIELD = 0xB4, + PUTFIELD = 0xB5, + INVOKEVIRTUAL = 0xB6, + INVOKESPECIAL = 0xB7, + INVOKESTATIC = 0xB8, + INVOKEINTERFACE = 0xB9, + XXXUNUSEDXXX = 0xBA, + NEW = 0xBB, + NEWARRAY = 0xBC, + ANEWARRAY = 0xBD, + ARRAYLENGTH = 0xBE, + ATHROW = 0xBF, + CHECKCAST = 0xC0, + INSTANCEOF = 0xC1, + MONITORENTER = 0xC2, + MONITOREXIT = 0xC3, + WIDE = 0xC4, + MULTIANEWARRAY = 0xC5, + IFNULL = 0xC6, + IFNONNULL = 0xC7, + GOTO_W = 0xC8, + JSR_W = 0xC9, + BREAKPOINT = 0xCA, + IMPDEP1 = 0xFE, + IMPDEP2 = 0xFF, + }; + + } // namespace Opcode + + inline int readSByte(const uint8_t* code, unsigned& i) { + return code[++i]; + } + + inline unsigned readUByte(const uint8_t* code, unsigned& i) { + return code[++i]; + } + + inline int readSShort(const uint8_t* code, unsigned& i) { + return (readSByte(code, i) << 8) | readUByte(code, i); + } + + inline unsigned readUShort(const uint8_t* code, unsigned& i) { + return (readUByte(code, i) << 8) | readUByte(code, i); + } + + inline int readSInt(const uint8_t* code, unsigned& i) { + return ((readUByte(code, i) << 24) | + (readUByte(code, i) << 16) | + (readUByte(code, i) << 8) | + readUByte(code, i)); + } + + inline unsigned readUInt(const uint8_t* code, unsigned& i) { + return readSInt(code, i); + } + + inline void skipPadBytes(const uint8_t* code, unsigned& i) { + while (((unsigned)&code[++i]) & 0XFF); + } + +} } // namespace llvm::Java From alkis at cs.uiuc.edu Sun May 23 05:19:07 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 05:19:07 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405231017.FAA13152@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.8 -> 1.9 --- Log message: Move immediate reading functions to bytecode header. --- Diffs of the changes: (+14 -45) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.8 llvm-java/lib/Compiler/Compiler.cpp:1.9 --- llvm-java/lib/Compiler/Compiler.cpp:1.8 Sun May 23 05:11:59 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sun May 23 05:17:31 2004 @@ -34,37 +34,6 @@ return !isTwoSlotValue(v); } - inline int readByteSigned(const uint8_t* code, unsigned& i) { - return code[++i]; - } - - inline unsigned readByteUnsigned(const uint8_t* code, unsigned& i) { - return code[++i]; - } - - inline int readShortSigned(const uint8_t* code, unsigned& i) { - return (readByteSigned(code, i) << 8) | readByteUnsigned(code, i); - } - - inline unsigned readShortUnsigned(const uint8_t* code, unsigned& i) { - return (readByteUnsigned(code, i) << 8) | readByteUnsigned(code, i); - } - - inline int readIntSigned(const uint8_t* code, unsigned& i) { - return ((readByteUnsigned(code, i) << 24) | - (readByteUnsigned(code, i) << 16) | - (readByteUnsigned(code, i) << 8) | - readByteUnsigned(code, i)); - } - - inline unsigned readIntUnsigned(const uint8_t* code, unsigned& i) { - return readIntSigned(code, i); - } - - inline void skipPadBytes(const uint8_t* code, unsigned& i) { - while (((unsigned)&code[++i]) & 0XFF); - } - } // namespace void Compiler::compileMethodInit(Function& function, @@ -146,19 +115,19 @@ case IF_IACMPNE: case IFNULL: case IFNONNULL: { - unsigned index = readShortUnsigned(code, i); + unsigned index = readUShort(code, i); bc2bbMap_[bcStart] = new BasicBlock( std::string("bb at bc") + utostr(bcStart), &function); break; } case TABLESWITCH: { skipPadBytes(code, i); - readIntSigned(code, i); - int low = readIntSigned(code, i); - int high = readIntSigned(code, i); + readSInt(code, i); + int low = readSInt(code, i); + int high = readSInt(code, i); unsigned offsetCount = high - low + 1; while (offsetCount--) { - unsigned bcIndex = bcStart + readIntSigned(code, i); + unsigned bcIndex = bcStart + readSInt(code, i); bc2bbMap_[bcIndex] = new BasicBlock( std::string("bb at bc") + utostr(bcIndex), &function); } @@ -166,10 +135,10 @@ } case LOOKUPSWITCH: { skipPadBytes(code, i); - unsigned pairCount = readIntUnsigned(code, i); + unsigned pairCount = readUInt(code, i); while (pairCount--) { - readIntSigned(code, i); - unsigned bcIndex = bcStart + readIntSigned(code, i); + readSInt(code, i); + unsigned bcIndex = bcStart + readSInt(code, i); bc2bbMap_[bcIndex] = new BasicBlock( std::string("bb at bc") + utostr(bcIndex), &function); } @@ -244,25 +213,25 @@ opStack_.push(ConstantFP::get(Type::DoubleTy, code[i]-DCONST_0)); break; case BIPUSH: { - int imm = readByteSigned(code, i); + int imm = readSByte(code, i); opStack_.push(ConstantInt::get(Type::IntTy, imm)); break; } case SIPUSH: { - int imm = readShortSigned(code, i); + int imm = readSShort(code, i); opStack_.push(ConstantInt::get(Type::IntTy, imm)); break; } case LDC: { - unsigned index = readByteUnsigned(code, i); + unsigned index = readUByte(code, i); // FIXME: load constant from constant pool } case LDC_W: { - unsigned index = readShortUnsigned(code, i); + unsigned index = readUShort(code, i); // FIXME: load constant from constant pool } case LDC2_W: { - unsigned index = readShortUnsigned(code, i); + unsigned index = readUShort(code, i); // FIXME: load constant from constant pool } case ILOAD: @@ -271,7 +240,7 @@ case DLOAD: case ALOAD: { // FIXME: use opcodes to perform type checking - unsigned index = readByteUnsigned(code, i); + unsigned index = readUByte(code, i); opStack_.push(locals_[index]); break; } From alkis at cs.uiuc.edu Sun May 23 05:35:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 05:35:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405231033.FAA14633@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.9 -> 1.10 --- Log message: Remove one variable from tableswitch skipping code. Fix lookupswitch skipping code. --- Diffs of the changes: (+2 -2) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.9 llvm-java/lib/Compiler/Compiler.cpp:1.10 --- llvm-java/lib/Compiler/Compiler.cpp:1.9 Sun May 23 05:17:31 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sun May 23 05:33:37 2004 @@ -125,8 +125,7 @@ readSInt(code, i); int low = readSInt(code, i); int high = readSInt(code, i); - unsigned offsetCount = high - low + 1; - while (offsetCount--) { + while (low++ <= high) { unsigned bcIndex = bcStart + readSInt(code, i); bc2bbMap_[bcIndex] = new BasicBlock( std::string("bb at bc") + utostr(bcIndex), &function); @@ -135,6 +134,7 @@ } case LOOKUPSWITCH: { skipPadBytes(code, i); + readSInt(code, i); unsigned pairCount = readUInt(code, i); while (pairCount--) { readSInt(code, i); From alkis at cs.uiuc.edu Sun May 23 06:13:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 06:13:02 2004 Subject: [llvm-commits] CVS: llvm/docs/OpenProjects.html Message-ID: <200405231111.GAA17416@zion.cs.uiuc.edu> Changes in directory llvm/docs: OpenProjects.html updated: 1.25 -> 1.26 --- Log message: Put back the inlined bug list. Use the OBJECT tag to make it HTML-4.01 (Strict)-compliant. --- Diffs of the changes: (+3 -2) Index: llvm/docs/OpenProjects.html diff -u llvm/docs/OpenProjects.html:1.25 llvm/docs/OpenProjects.html:1.26 --- llvm/docs/OpenProjects.html:1.25 Wed May 12 13:57:54 2004 +++ llvm/docs/OpenProjects.html Sun May 23 06:10:55 2004 @@ -57,7 +57,8 @@

    The projects in this page are open-ended. More specific projects are filed as unassigned enhancements in the -LLVM bug tracker. See the list of currently outstanding issues if you wish to help improve LLVM.

    +LLVM bug tracker. Here is the current list: +

    @@ -333,7 +334,7 @@ Chris Lattner
    LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/12 18:57:54 $ + Last modified: $Date: 2004/05/23 11:10:55 $ From alkis at cs.uiuc.edu Sun May 23 06:16:01 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 06:16:01 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405231114.GAA17929@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.10 -> 1.11 --- Log message: Use ConstantSInt::get instead of ConstantInt::get so that all possible int values can be handled. --- Diffs of the changes: (+4 -4) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.10 llvm-java/lib/Compiler/Compiler.cpp:1.11 --- llvm-java/lib/Compiler/Compiler.cpp:1.10 Sun May 23 05:33:37 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sun May 23 06:14:42 2004 @@ -197,11 +197,11 @@ case ICONST_3: case ICONST_4: case ICONST_5: - opStack_.push(ConstantInt::get(Type::IntTy, code[i]-ICONST_0)); + opStack_.push(ConstantSInt::get(Type::IntTy, code[i]-ICONST_0)); break; case LCONST_0: case LCONST_1: - opStack_.push(ConstantInt::get(Type::LongTy, code[i]-LCONST_0)); + opStack_.push(ConstantSInt::get(Type::LongTy, code[i]-LCONST_0)); break; case FCONST_0: case FCONST_1: @@ -214,12 +214,12 @@ break; case BIPUSH: { int imm = readSByte(code, i); - opStack_.push(ConstantInt::get(Type::IntTy, imm)); + opStack_.push(ConstantSInt::get(Type::IntTy, imm)); break; } case SIPUSH: { int imm = readSShort(code, i); - opStack_.push(ConstantInt::get(Type::IntTy, imm)); + opStack_.push(ConstantSInt::get(Type::IntTy, imm)); break; } case LDC: { From alkis at cs.uiuc.edu Sun May 23 06:25:02 2004 From: alkis at cs.uiuc.edu (Alkis Evlogimenos) Date: Sun May 23 06:25:02 2004 Subject: [llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp Message-ID: <200405231123.GAA18529@zion.cs.uiuc.edu> Changes in directory llvm-java/lib/Compiler: Compiler.cpp updated: 1.11 -> 1.12 --- Log message: Add compilation for add, sub, mul, div, rem, shl, shr, ushr, and, or, xor, if*, tableswitch, lookupswitch, and *return opcodes. --- Diffs of the changes: (+182 -19) Index: llvm-java/lib/Compiler/Compiler.cpp diff -u llvm-java/lib/Compiler/Compiler.cpp:1.11 llvm-java/lib/Compiler/Compiler.cpp:1.12 --- llvm-java/lib/Compiler/Compiler.cpp:1.11 Sun May 23 06:14:42 2004 +++ llvm-java/lib/Compiler/Compiler.cpp Sun May 23 06:23:24 2004 @@ -434,39 +434,108 @@ case IADD: case LADD: case FADD: - case DADD: + case DADD: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Add, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case ISUB: case LSUB: case FSUB: - case DSUB: + case DSUB: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Sub, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IMUL: case LMUL: case FMUL: - case DMUL: + case DMUL: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Mul, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IDIV: case LDIV: case FDIV: - case DDIV: + case DDIV: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Div, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IREM: case LREM: case FREM: - case DREM: + case DREM: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Rem, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case INEG: case LNEG: case FNEG: case DNEG: case ISHL: - case LSHL: + case LSHL: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = new ShiftInst(Instruction::Shl, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case ISHR: - case LSHR: + case LSHR: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = new ShiftInst(Instruction::Shr, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IUSHR: - case LUSHR: + case LUSHR: { + Value* v1 = opStack_.top(); opStack_.pop(); + Instruction* in = + new CastInst(v1, v1->getType()->getUnsignedVersion()); + bc2bbMap_[bcStart]->getInstList().push_back(in); + Value* v2 = opStack_.top(); opStack_.pop(); + in = new ShiftInst(Instruction::Shr, in, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IAND: - case LAND: + case LAND: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::And, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IOR: - case LOR: + case LOR: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Or, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IXOR: - case LXOR: + case LXOR: { + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = BinaryOperator::create(Instruction::Xor, v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + break; + } case IINC: case I2L: case I2F: @@ -493,26 +562,104 @@ case IFLT: case IFGE: case IFGT: - case IFLE: + case IFLE: { + static Instruction::BinaryOps java2llvm[] = { + Instruction::SetEQ, + Instruction::SetNE, + Instruction::SetLT, + Instruction::SetGE, + Instruction::SetGT, + Instruction::SetLE, + }; + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = ConstantSInt::get(Type::IntTy, 0); + Instruction* in = new SetCondInst(java2llvm[i-IFEQ], v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], + bc2bbMap_[i + 1], + bc2bbMap_[bcStart]); + break; + } case IF_ICMPEQ: case IF_ICMPNE: case IF_ICMPLT: case IF_ICMPGE: case IF_ICMPGT: - case IF_ICMPLE: + case IF_ICMPLE: { + static Instruction::BinaryOps java2llvm[] = { + Instruction::SetEQ, + Instruction::SetNE, + Instruction::SetLT, + Instruction::SetGE, + Instruction::SetGT, + Instruction::SetLE, + }; + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = new SetCondInst(java2llvm[i-IF_ICMPEQ], v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], + bc2bbMap_[i + 1], + bc2bbMap_[bcStart]); + break; + } case IF_IACMPEQ: - case IF_IACMPNE: + case IF_IACMPNE: { + static Instruction::BinaryOps java2llvm[] = { + Instruction::SetEQ, + Instruction::SetNE, + }; + Value* v1 = opStack_.top(); opStack_.pop(); + Value* v2 = opStack_.top(); opStack_.pop(); + Instruction* in = new SetCondInst(java2llvm[i-IF_IACMPEQ], v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], + bc2bbMap_[i + 1], + bc2bbMap_[bcStart]); + break; + } case GOTO: + new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)]); + break; case JSR: case RET: - case TABLESWITCH: - case LOOKUPSWITCH: + case TABLESWITCH: { + Value* v1 = opStack_.top(); opStack_.pop(); + skipPadBytes(code, i); + int def = readSInt(code, i); + int low = readSInt(code, i); + int high = readSInt(code, i); + SwitchInst* in = + new SwitchInst(v1, bc2bbMap_[bcStart + def],bc2bbMap_[bcStart]); + while (low <= high) + in->addCase(ConstantSInt::get(Type::IntTy, low++), + bc2bbMap_[bcStart + readSInt(code, i)]); + break; + } + case LOOKUPSWITCH: { + Value* v1 = opStack_.top(); opStack_.pop(); + skipPadBytes(code, i); + int def = readSInt(code, i); + unsigned pairCount = readUInt(code, i); + SwitchInst* in = + new SwitchInst(v1, bc2bbMap_[bcStart + def],bc2bbMap_[bcStart]); + while (pairCount--) + in->addCase(ConstantSInt::get(Type::IntTy, readSInt(code, i)), + bc2bbMap_[bcStart + readSInt(code, i)]); + break; + } case IRETURN: case LRETURN: case FRETURN: case DRETURN: - case ARETURN: + case ARETURN: { + Value* v1 = opStack_.top(); opStack_.pop(); + new ReturnInst(v1, bc2bbMap_[bcStart]); + break; + } case RETURN: + new ReturnInst(NULL, bc2bbMap_[bcStart]); + break; case GETSTATIC: case PUTSTATIC: case GETFIELD: @@ -531,11 +678,27 @@ case INSTANCEOF: case MONITORENTER: case MONITOREXIT: - case WIDE: +// case WIDE: case MULTIANEWARRAY: case IFNULL: - case IFNONNULL: + case IFNONNULL: { + static Instruction::BinaryOps java2llvm[] = { + Instruction::SetEQ, + Instruction::SetNE, + }; + Value* v1 = opStack_.top(); opStack_.pop(); + // FIXME: should compare to a null pointer of type Object* + Value* v2 =ConstantPointerNull::get(PointerType::get(Type::VoidTy)); + Instruction* in = new SetCondInst(java2llvm[i-IFNULL], v1, v2); + bc2bbMap_[bcStart]->getInstList().push_back(in); + new BranchInst(bc2bbMap_[bcStart + readSShort(code, i)], + bc2bbMap_[i + 1], + bc2bbMap_[bcStart]); + break; + } case GOTO_W: + new BranchInst(bc2bbMap_[bcStart + readSInt(code, i)]); + break; case JSR_W: case BREAKPOINT: case IMPDEP1: From llvm at cs.uiuc.edu Sun May 23 12:07:01 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sun May 23 12:07:01 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html Message-ID: <200405231705.MAA27293@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html updated: 1.2 -> 1.3 --- Log message: Additional content describing variable bit rate encoding, correcting the definition of the signature block and module block, and adding definitions of the global type pool and symbol table. More still to come. --- Diffs of the changes: (+238 -48) Index: llvm/docs/BytecodeFormat.html diff -u llvm/docs/BytecodeFormat.html:1.2 llvm/docs/BytecodeFormat.html:1.3 --- llvm/docs/BytecodeFormat.html:1.2 Sat May 22 00:56:41 2004 +++ llvm/docs/BytecodeFormat.html Sun May 23 12:05:09 2004 @@ -6,7 +6,7 @@ @@ -19,13 +19,15 @@
  • Blocks
  • Lists
  • Fields
  • +
  • Encoding Rules
  • Alignment
  • Detailed Layout
    1. Notation
    2. Blocks Types
    3. -
    4. Header Block
    5. +
    6. Signature Block
    7. +
    8. Module Block
    9. Global Type Pool
    10. Module Info Block
    11. Global Constant Pool
    12. @@ -63,7 +65,7 @@

      LLVM bytecode files consist simply of a sequence of blocks of bytes. Each block begins with an identification value that determines the type of the next block. The possible types of blocks are described below in the section -Block Types. The block identifier is used because +Block Types. The block identifier is used because it is possible for entire blocks to be omitted from the file if they are empty. The block identifier helps the reader determine which kind of block is next in the file.

      @@ -80,8 +82,9 @@
    13. InstructionList (0x32).
    14. CompactionTable (0x33).
    -

    Except for the Header Block all blocks are variable -length. They consume just enough bytes to express their contents.

    +

    All blocks are variable length. They consume just enough bytes to express +their contents. Each block begins with an integer identifier and the length +of the block.

    @@ -112,6 +115,88 @@ written and how the bits are to be interpreted.

    + +
    +

    Each field that can be put out is encoded into the file using a small set +of primitives. The rules for these primitives are described below.

    +

    Variable Bit Rate Encoding

    +

    To minimize the number of bytes written for small quantities, an encoding +scheme similar to UTF-8 is used to write integer data. The scheme is known as +variable bit rate (vbr) encoding. In this encoding, the high bit of each +byte is used to indicate if more bytes follow. If (byte & 0x80) is non-zero +in any given byte, it means there is another byte immediately following that +also contributes to the value. For the final byte (byte & 0x80) is false +(the high bit is not set). In each byte only the low seven bits contribute to +the value. Consequently 32-bit quantities can take from one to five +bytes to encode. In general, smaller quantities will encode in fewer bytes, +as follows:

    + + + + + + + + + + + + + + + + +
    Byte #Significant BitsMaximum Value
    10-6127
    27-1316,383
    314-202,097,151
    421-27268,435,455
    528-3434,359,738,367
    635-414,398,046,511,103
    742-48562,949,953,421,311
    849-5572,057,594,037,927,935
    956-629,223,372,036,854,775,807
    1063-691,180,591,620,717,411,303,423
    +

    Note that in practice, the tenth byte could only encode bits 63 and 64 +since the maximum quantity to use this encoding is a 64-bit integer.

    +

    The table below defines the encoding rules for type names used in the +descriptions of blocks and fields in the next section. Any type name with +the suffix _vbr indicate a quantity that is encoded using +variable bit rate encoding as described above.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    TypeRule
    unsignedA 32-bit unsigned integer that always occupies four + consecutive bytes. The unsigned integer is encoded using LSB first + ordering. That is bits 20 through 27 are in the + byte with the lowest file offset (little endian).
    uint_vbrA 32-bit unsigned integer that occupies from one to five + bytes using variable bit rate encoding.
    uint64_vbrA 64-bit unsigned integer that occupies from one to ten + bytes using variable bit rate encoding.
    int64_vbrA 64-bit signed integer that occupies from one to ten + bytes using variable bit rate encoding.
    charA single unsigned character encoded into one byte
    bitA single bit within a byte.
    stringA uint_vbr indicating the length of the character string + immediately followed by the characters of the string. There is no + terminating null byte in the string. Characters are interpreted as unsigned + char and are generally US-ASCII encoded.
    dataAn arbitrarily long segment of data to which no + interpretation is implied. This is used for float, double, and constant + initializers.
    +
    +

    To support cross-platform differences, the bytecode file is aligned on @@ -123,8 +208,8 @@

    -

    This section provides the detailed layout of the LLVM bytecode file format. - bit and byte level specifics.

    +

    This section provides the detailed layout of the LLVM bytecode file format. +bit and byte level specifics.

    @@ -153,9 +238,10 @@ of bytes known as blocks. The blocks are written sequentially to the file in the following order:

      -
    1. Header. This block contains the file signature - (magic number), machine description and file format version (not LLVM - version).
    2. +
    3. Signature. This block contains the file signature + (magic number) that identifies the file as LLVM bytecode.
    4. +
    5. Module Block. This is the top level block in a + bytecode file. It contains all the other blocks.
    6. Global Type Pool. This block contains all the global (module) level types.
    7. Module Info. This block contains the types of the @@ -171,77 +257,181 @@
    - +
    -

    The Header Block occurs in every LLVM bytecode file and is always first. It -simply provides a few bytes of data to identify the file, its format, and the -bytecode version. This block is fixed length and always eight bytes, as follows: - +

    The signature block occurs in every LLVM bytecode file and is always first. +It simply provides a few bytes of data to identify the file as being an LLVM +bytecode file. This block is always four bytes in length and differs from the +other blocks because there is no identifier and no block length at the start +of the block. Essentially, this block is just the "magic number" for the file. +

    - - - + + - - - + + - - - + + - - - + + +
    Byte(s) Bit(s) Align? Type Field Description
    0000-07NoChar
    00-Nochar Constant "l" (0x6C)
    0100-07NoChar
    01-Nochar Constant "l" (0x6C)
    0200-07NoChar
    02-Nochar Constant "v" (0x76)
    0300-07NoChar
    03-Nochar Constant "m" (0x6D)
    +

    + + +
    +

    The module block contains a small pre-amble and all the other blocks in +the file. Of particular note, the bytecode format number is simply a 28-bit +monotonically increase integer that identifiers the version of the bytecode +format. While the bytecode format version is not related to the LLVM release +(it doesn't automatically get increased with each new LLVM release), there is +a definite correspondence between the bytecode format version and the LLVM +release.

    +

    The table below shows the format of the module block header. The blocks it +contains are detailed in other sections.

    + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    04-0700NoBoolTarget is big endian?
    04-0701NoBoolTarget has long pointers?
    04-0702NoBoolTarget has no endianess?
    04-0703NoBoolTarget has no pointer size?
    04-0704-31YesUnsignedThe LLVM bytecode format version numberByte(s)Bit(s)Align?TypeField Description
    04-07-NounsignedModule Identifier (0x01)
    08-11-NounsignedSize of the module block in bytes
    12-1500Yesuint32_vbrFormat Information
    ''0-bitBig Endian?
    ''1-bitPointers Are 64-bit?
    ''2-bitHas No Endianess?
    ''3-bitHas No Pointer Size?
    ''4-31-bitBytecode Format Version
    16-end--blocksThe remaining bytes in the block consist + solely of other block types in sequence.
    +

    The global type pool consists of type definitions. Their order of appearnce +in the file determines their slot number (0 based). Slot numbers are used to +replace pointers in the intermediate representation. Each slot number uniquely +identifies one entry in a type plane (a collection of values of the same type). +Since all values have types and are associated with the order in which the type +pool is written, the global type pool must be written as the first +block of a module. If it is not, attempts to read the file will fail because +both forward and backward type resolution will not be possible.

    +

    The type pool is simply a list of types definitions, as shown in the table +below.

    + + + + + + + + + + + + + + + + + + + + + + + + +
    Byte(s)Bit(s)Align?TypeField Description
    00-03-NounsignedType Pool Identifier (0x13)
    04-07-NounsignedSize in bytes of the symbol table block.
    08-111-Nouint32_vbrNumber of entries in type plane
    12-151-Nouint32_vbrType plane index for following entries
    16-end1,2-NotypeEach of the type definitions.
    1Maximum length shown, + may be smaller
    2Repeated field. +
    +

    To be determined.

    +

    To be determined.

    +

    To be determined.

    - +
    -

    The module symbol table is a list of +

    A symbol table can be put out in conjunction with a module or a function. +A symbol table is a list of type planes. Each type plane starts with the number +of entries in the plane and the type plane's slot number (so the type can be +looked up in the global type pool). For each entry in a type plane, the slot +number of the value and the name associated with that value are written. The +format is given in the table below.

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Byte(s)Bit(s)Align?TypeField Description
    00-03-NounsignedSymbol Table Identifier (0x13)
    04-07-NounsignedSize in bytes of the symbol table block.
    08-111-Nouint32_vbrNumber of entries in type plane
    12-151-Nouint32_vbrType plane index for following entries
    16-191,2-Nouint32_vbrSlot number of a value.
    variable1,2-NostringName of the value in the symbol table.
    1Maximum length shown, + may be smaller
    2Repeated field. +
    @@ -255,7 +445,7 @@ Reid Spencer and Chris Lattner
    The LLVM Compiler Infrastructure
    - Last modified: $Date: 2004/05/22 05:56:41 $ + Last modified: $Date: 2004/05/23 17:05:09 $ From llvm at cs.uiuc.edu Sun May 23 12:15:08 2004 From: llvm at cs.uiuc.edu (LLVM) Date: Sun May 23 12:15:08 2004 Subject: [llvm-commits] CVS: llvm/docs/BytecodeFormat.html Message-ID: <200405231712.MAA27360@zion.cs.uiuc.edu> Changes in directory llvm/docs: BytecodeFormat.html updated: 1.3 -> 1.4 --- Log message: Make the file HTML 4.01 (Strict) clean. --- Diffs of the changes: (+7 -5) Index: llvm/docs/BytecodeFormat.html diff -u llvm/docs/BytecodeFormat.html:1.3 llvm/docs/BytecodeFormat.html:1.4 --- llvm/docs/BytecodeFormat.html:1.3 Sun May 23 12:05:09 2004 +++ llvm/docs/BytecodeFormat.html Sun May 23 12:12:45 2004 @@ -4,7 +4,7 @@ LLVM Bytecode File Format -