summaryrefslogtreecommitdiff
path: root/compiler/cmm/CmmSpillReload.hs
Commit message (Collapse)AuthorAgeFilesLines
* Snapshot of codegen refactoring to share with simonpjSimon Marlow2011-08-251-1/+1
|
* Merge branch 'master' of http://darcs.haskell.org/ghcIan Lynagh2011-06-171-89/+20
|\
| * Refactor CmmLive and CmmSpillReload.Edward Z. Yang2011-06-171-89/+20
| | | | | | | | | | | | | | | | | | | | * Move dead assignment elimination to CmmLive * Kill off dead code in CmmSpillReload related to non-splitting procpoints case * Refactor dual liveness transfer function to more closely mimic CmmLive's liveness transfer. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* | Fix buildIan Lynagh2011-06-171-7/+1
| | | | | | | | | | I'm not sure what's going on with these warnings, but for now I've suppressed them all.
* | Fix the build with GHC 6.12Ian Lynagh2011-06-171-2/+7
|/
* Refactoring CmmSpillReload and CmmLive.Edward Z. Yang2011-06-171-24/+34
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Fix build for GHC earlier than 7.0.1.Edward Z. Yang2011-06-151-2/+2
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Implement regslot inlining, document soundness concerns.Edward Z. Yang2011-06-141-5/+9
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Split out assignment rewriting to own module.Edward Z. Yang2011-06-141-464/+1
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Extra comment about WithRegUsage.Edward Z. Yang2011-06-131-0/+4
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Work around lack of saving volatile registers from unsafe foreign calls.Edward Z. Yang2011-05-151-10/+25
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* More aggressive clobber detection with Hp and RegSlot.Edward Z. Yang2011-05-151-3/+19
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* More aggressive CmmRegOff inlining, and fix failure to inline to assignments.Edward Z. Yang2011-05-151-13/+29
| | | | Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Generalized assignment rewriting pass.Edward Z. Yang2011-05-151-100/+415
| | | | | | | This assignment rewriting pass subsumes the previous reload sinking pass, and also performs basic inlining. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Unsafe foreign calls (fat machine instructions) do not kill all registers.Edward Z. Yang2011-04-111-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | The new code generator was doing some interesting spilling across unsafe foreign calls: _c1ao::I32 = Hp - 4; I32[Sp - 20] = _c1ao::I32; foreign "ccall" newCAF((BaseReg, PtrHint), (R1, PtrHint))[_unsafe_call_]; _c1ao::I32 = I32[Sp - 20]; This is fairly unnecessary, and resulted from over-conservative liveness analysis from CmmLive. We can see that the old code generator only saved volatile registers across unsafe foreign calls: spilling variables was done by saveVolatileVarsAndRegs, which was only performed for ordinary calls. This commit removes the excess kill from the liveness analysis, as well as the *redundant* excess kill from spilling-and-reloading, and adds a note to CmmNode to this effect. The only registers we need to kill are the ones that the foreign call assigns to, just like any other machine instruction. Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
* Fix warningsSimon Marlow2011-01-281-1/+7
|
* Merge in new code generator branch.Simon Marlow2011-01-241-165/+156
| | | | | | | | | | | | | | | | | | | | | | | | | | This changes the new code generator to make use of the Hoopl package for dataflow analysis. Hoopl is a new boot package, and is maintained in a separate upstream git repository (as usual, GHC has its own lagging darcs mirror in http://darcs.haskell.org/packages/hoopl). During this merge I squashed recent history into one patch. I tried to rebase, but the history had some internal conflicts of its own which made rebase extremely confusing, so I gave up. The history I squashed was: - Update new codegen to work with latest Hoopl - Add some notes on new code gen to cmm-notes - Enable Hoopl lag package. - Add SPJ note to cmm-notes - Improve GC calls on new code generator. Work in this branch was done by: - Milan Straka <fox@ucw.cz> - John Dias <dias@cs.tufts.edu> - David Terei <davidterei@gmail.com> Edward Z. Yang <ezyang@mit.edu> merged in further changes from GHC HEAD and fixed a few bugs.
* Remove code that is dead now that we need >= 6.12 to buildIan Lynagh2010-12-151-2/+0
|
* Fix build with 6.10Ian Lynagh2010-09-131-0/+2
|
* Super-monster patch implementing the new typechecker -- at lastsimonpj@microsoft.com2010-09-131-0/+3
| | | | | | | | | This major patch implements the new OutsideIn constraint solving algorithm in the typecheker, following our JFP paper "Modular type inference with local assumptions". Done with major help from Dimitrios Vytiniotis and Brent Yorgey.
* Comments onlysimonpj@microsoft.com2009-11-121-14/+17
|
* More sensible use of -fnew-codegen and less debugging outputdias@cs.tufts.edu2009-09-181-1/+1
|
* Remove GHC's haskell98 dependencyIan Lynagh2009-07-241-2/+2
|
* Remove unused importsIan Lynagh2009-07-071-2/+0
|
* stack overflows and out of memory'sdias@eecs.tufts.edu2009-03-161-1/+1
| | | | | | | 1. Stack overflow fixed by making dataflow monad strict in the state. 2. Out of memory fixed by "forgetting" lastoutfacts in the dataflow monad where we should. We were creating an unnecessarily long list that grew exponentially...
* A few bug fixes; some improvements spurred by paper writingdias@eecs.harvard.edu2009-03-031-72/+57
| | | | | | | | | | | | Among others: - Fixed Stg->C-- translation of let-no-escapes -- it's important to use the right continuation... - Fixed infinite recursion in X86 backend (shortcutJump mishandled infinite loops) - Fixed yet another wrong calling convention -- primops take args only in vanilla regs, but they may return results on the stack! - Removed StackInfo from LGraph and Block -- now in LastCall and CmmZ - Updated avail-variable and liveness code
* Removed warnings, made Haddock happy, added examples in documentationdias@eecs.harvard.edu2008-10-171-8/+8
| | | | | The interesting examples talk about our story with heap checks in case alternatives and our story with the case scrutinee as a Boolean.
* Fixed linear regalloc bug, dropped some tracing codedias@eecs.harvard.edu2008-10-161-2/+2
| | | | | | | | | o The linear-scan register allocator sometimes allocated a block before allocating one of its predecessors, which could lead to inconsistent allocations. Now, we allocate a block only if a predecessor has set the "incoming" assignments for the block (or if it's the procedure's entry block). o Also commented out some tracing code on the new codegen path.
* Big collection of patches for the new codegen branch.dias@eecs.harvard.edu2008-10-131-77/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | o Fixed bug that emitted the copy-in code for closure entry in the wrong place -- at the initialization of the closure. o Refactored some of the closure entry code. o Added code to check that no LocalRegs are live-in to a procedure -- trip up some buggy programs earlier o Fixed environment bindings for thunks -- we weren't (re)binding the free variables in a thunk o Fixed a bug in proc-point splitting that dropped some updates to the entry block in a procedure. o Fixed improper calls to code that generates CmmLit's for strings o New invariant on cg_loc in CgIdInfo: the expression is always tagged o Code to load free vars on entry to a thunk was (wrongly) placed before the heap check. o Some of the StgCmm code was redundantly passing around Id's along with CgIdInfo's; no more. o Initialize the LocalReg's that point to a closure before allocating and initializing the closure itself -- otherwise, we have problems with recursive closure bindings o BlockEnv and BlockSet types are now abstract. o Update frames: - push arguments in Old call area - keep track of the return sp in the FCode monad - keep the return sp in every call, tail call, and return (because it might be different at different call sites, e.g. tail calls to the gc after a heap check are performed before pushing the update frame) - set the sp appropriately on returns and tail calls o Reduce call, tail call, and return to a single LastCall node o Added slow entry code, using different calling conventions on entry and tail call o More fixes to the calling convention code. The tricky stuff is all about the closure environment: it must be passed in R1, but in non-closures, there is no such argument, so we can't treat all arguments the same way: the closure environment is special. Maybe the right step forward would be to define a different calling convention for closure arguments. o Let-no-escapes need to be emitted out-of-line -- otherwise, we drop code. o Respect RTS requirement of word alignment for pointers My stack allocation can pack sub-word values into a single word on the stack, but it wasn't requiring word-alignment for pointers. It does now, by word-aligning both pointer registers and call areas. o CmmLint was over-aggresively ruling out non-word-aligned memory references, which may be kosher now that we can spill small values into a single word. o Wrong label order on a conditional branch when compiling switches. o void args weren't dropped in many cases. To help prevent this kind of mistake, I defined a NonVoid wrapper, which I'm applying only to Id's for now, although there are probably other good candidates. o A little code refactoring: separate modules for procpoint analysis splitting, stack layout, and building infotables. o Stack limit check: insert along with the heap limit check, using a symbolic constant (a special CmmLit), then replace it when the stack layout is known. o Removed last node: MidAddToContext o Adding block id as a literal: means that the lowering of the calling conventions no longer has to produce labels early, which was inhibiting common-block elimination. Will also make it easier for the non-procpoint-splitting path. o Info tables: don't try to describe the update frame! o Over aggressive use of NonVoid!!!! Don't drop the non-void args before setting the type of the closure!!! o Sanity checking: Added a pass to stub dead dead slots on the stack (only ~10 lines with the dataflow framework) o More sanity checking: Check that incoming pointer arguments are non-stubbed. Note: these checks are still subject to dead-code removal, but they should still be quite helpful. o Better sanity checking: why stop at function arguments? Instead, in mkAssign, check that _any_ assignment to a pointer type is non-null -- the sooner the crash, the easier it is to debug. Still need to add the debugging flag to turn these checks on explicitly. o Fixed yet another calling convention bug. This time, the calls to the GC were wrong. I've added a new convention for GC calls and invoked it where appropriate. We should really straighten out the calling convention stuff: some of the code (and documentation) is spread across the compiler, and there's some magical use of the node register that should really be handled (not avoided) by calling conventions. o Switch bug: the arms in mkCmmLitSwitch weren't returning to a single join point. o Environment shadowing problem in Stg->Cmm: When a closure f is bound at the top-level, we should not bind f to the node register on entry to the closure. Why? Because if the body of f contains a let-bound closure g that refers to f, we want to make sure that it refers to the static closure for f. Normally, this would all be fine, because when we compile a closure, we rebind free variables in the environment. But f doesn't look like a free variable because it's a static value. So, the binding for f remains in the environment when we compile g, inconveniently referring to the wrong thing. Now, I bind the variable in the local environment only if the closure is not bound at the top level. It's still okay to make assumptions about the node holding the closure environment; we just won't find the binding in the environment, so code that names the closure will now directly get the label of the static closure, not the node register holding a pointer to the static closure. o Don't generate bogus Cmm code containing SRTs during the STG -> Cmm pass! The tables made reference to some labels that don't exist when we compute and generate the tables in the back end. o Safe foreign calls need some special treatment (at least until we have the integrated codegen). In particular: o they need info tables o they are not procpoints -- the successor had better be in the same procedure o we cannot (yet) implement the calling conventions early, which means we have to carry the calling-conv info all the way to the end o We weren't following the old convention when registering a module. Now, we use update frames to push any new modules that have to be registered and enter the youngest one on the stack. We also use the update frame machinery to specify that the return should pop the return address off the stack. o At each safe foreign call, an infotable must be at the bottom of the stack, and the TSO->sp must point to it. o More problems with void args in a direct call to a function: We were checking the args (minus voids) to check whether the call was saturated, which caused problems when the function really wasn't saturated because it took an extra void argument. o Forgot to distinguish integer != from floating != during Stg->Cmm o Updating slotEnv and areaMap to include safe foreign calls The dataflow analyses that produce the slotEnv and areaMap give results for each basic block, but we also need the results for a safe foreign call, which is a middle node. After running the dataflow analysis, we have another pass that updates the results to includ any safe foreign calls. o Added a static flag for the debugging technique that inserts instructions to stub dead slots on the stack and crashes when a stubbed value is loaded into a pointer-typed LocalReg. o C back end expects to see return continuations before their call sites. Sorted the flowgraphs appropriately after splitting. o PrimOp calling conventions are special -- unlimited registers, no stack Yet another calling convention... o More void value problems: if the RHS of a case arm is a void-typed variable, don't try to return it. o When calling some primOp, they may allocate memory; if so, we need to do a heap check when we return from the call.
* Merging in the new codegen branchdias@eecs.harvard.edu2008-08-141-155/+90
| | | | | | | | | | | | | | | | | | This merge does not turn on the new codegen (which only compiles a select few programs at this point), but it does introduce some changes to the old code generator. The high bits: 1. The Rep Swamp patch is finally here. The highlight is that the representation of types at the machine level has changed. Consequently, this patch contains updates across several back ends. 2. The new Stg -> Cmm path is here, although it appears to have a fair number of bugs lurking. 3. Many improvements along the CmmCPSZ path, including: o stack layout o some code for infotables, half of which is right and half wrong o proc-point splitting
* Replacing copyins and copyouts with data-movement instructionsdias@eecs.harvard.edu2008-05-291-33/+28
| | | | | | | | | | | | | | o Moved BlockId stuff to a new file to avoid module recursion o Defined stack areas for parameter-passing locations and spill slots o Part way through replacing copy in and copy out nodes - added movement instructions for stack pointer - added movement instructions for call and return parameters (but not with the proper calling conventions) o Inserting spills and reloads for proc points is now procpoint-aware (it was relying on the presence of a CopyIn node as a proxy for procpoint knowledge) o Changed ZipDataflow to expect AGraphs (instead of being polymorphic in the type of graph)
* Cmm back end upgradesdias@eecs.harvard.edu2008-05-291-104/+131
| | | | | | | | | | | | | | | | | | | | | Several changes in this patch, partially bug fixes, partially new code: o bug fixes in ZipDataflow - added some checks to verify that facts converge - removed some erroneous checks of convergence on entry nodes - added some missing applications of transfer functions o changed dataflow clients to use ZipDataflow, making ZipDataflow0 obsolete o eliminated DFA monad (no need for separate analysis and rewriting monads with ZipDataflow) o started stack layout changes - no longer generating CopyIn and CopyOut nodes (not yet fully expunged though) - still not using proper calling conventions o simple new optimizations: - common block elimination -- have not yet tried to move the Adams opt out of CmmProcPointZ - block concatenation o piped optimization fuel up to the HscEnv - can be limited by a command-line flag - not tested, and probably not yet properly used by clients o added unique supply to FuelMonad, also lifted unique supply to DFMonad
* minor changes to Cmm left over from September 2007Norman Ramsey2008-05-031-2/+3
| | | | | | | Nothing too deep here; primarily tinking with prettyprinting and names. Also eliminated some warnings. This patch covers most (but not all) of the code NR changed at the very end of September 2007, just before ICFP hit...
* Make the instance of DebugNodes more H98-likesimonpj@microsoft.com2008-01-041-1/+1
|
* move and generalize another instance (#1405)Isaac Dupree2007-12-261-3/+0
| | | | | | | | | | | was instance Outputable CmmGraph type CmmGraph = LGraph Middle Last now instance (ctx) => Outputable (LGraph m l), in module with LGraph where it belongs This also let us reduce the context of DebugNodes to Haskell98, leaving that class's only extension being multi-parameter. (also Outputable (LGraph M Last) with M = ExtendWithSpills Middle was another redundant instance that was then removed)
* massive convulsion in ZipDataflowNorman Ramsey2007-09-211-13/+30
| | | | | | | | | | After my talk, I got the idea of 'shallow rewriting' for the dataflow framework. Here it is implemented, along with some related ideas late making Graph and not LGraph primary. The only bad thing is that the whole bit is stitched together out of ill-fitting pieces, kind of like Frankenstein's monster. A new ZipDataflow will rise out of the ashes.
* added node to push a closure onto the current call contextNorman Ramsey2007-09-171-0/+1
|
* tightened some dataflow code as part of preparing a talkNorman Ramsey2007-09-171-17/+28
|
* reloads are now sunk as deep as possibleNorman Ramsey2007-09-151-3/+65
|
* get rid of MidNopNorman Ramsey2007-09-151-2/+1
|
* tidying cmm/CmmSpillReload.hsNorman Ramsey2007-09-131-16/+12
|
* remove remaining redundancies from ZipCfgCmmRepNorman Ramsey2007-09-121-3/+3
| | | | | | | -- LastBranch no longer takes parameters -- LastJump and LastReturn no longer carry CmmActuals; instead, those are carried by a CopyOut in the same basic block
* Remove warning flags from individual compiler modulesIan Lynagh2007-09-121-1/+0
| | | | We now set the flags once and for all in compiler/Makefile.
* change the zipper representation of callsNorman Ramsey2007-09-121-7/+7
| | | | | | | | | | | | | | | This patch combines two changes: 1. As requested by SimonPJ, the redundancy inherent in having LastCall bear actual parameters has been removed. The actual parameters are now carried by a separate CopyOut node. 2. The internal (to zipper) representation of calls has changed; the representation of calling conventions is more orthogonal, and there is now no such thing as a 'safe' or 'final' call to a CallishMachOp. This change has affected the interface to MkZipCfgCmm, which now provides a static guarantee. Simon's new upstream code will be affected; I've patched the existing code in CmmCvt (which becomes ever hairier).
* split the CmmGraph constructor interface from the representationNorman Ramsey2007-09-111-1/+1
| | | | | | | Interface MkZipCfgCmm should now be sufficient for all construction needs, though some identifiers are re-exported from (and explained in) MkZipCfg. ZipCfgCmmRep should be used only by modules involved in analysis, optimization, or translation of Cmm programs.
* no registers are available after a callNorman Ramsey2007-09-071-0/+1
|
* wrote an analysis to help in sinking Reload instructionsNorman Ramsey2007-09-071-16/+69
|
* a good deal of salutory renamingNorman Ramsey2007-09-071-9/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I've renamed a number of type and data constructors within Cmm so that the names used in the compiler may more closely reflect the C-- specification 2.1. I've done a bit of other renaming as well. Highlights: CmmFormal and CmmActual now bear a CmmKind (which for now is a MachHint as before) CmmFormals = [CmmFormal] and CmmActuals = [CmmActual] suitable changes have been made to both code and nonterminals in the Cmm parser (which is as yet untested) For reasons I don't understand, parts of the code generator use a sequence of 'formal parameters' with no C-- kinds. For these we now have the types type CmmFormalWithoutKind = LocalReg type CmmFormalsWithoutKinds = [CmmFormalWithoutKind] A great many appearances of (Tau, MachHint) have been simplified to the appropriate CmmFormal or CmmActual, though I'm sure there are more opportunities. Kind and its data constructors are now renamed to data GCKind = GCKindPtr | GCKindNonPtr to avoid confusion with the Kind used in the type checker and with CmmKind. Finally, in a somewhat unrelated bit (and in honor of Simon PJ, who thought of the name), the Whalley/Davidson 'transaction limit' is now called 'OptimizationFuel' with the net effect that there are no longer two unrelated uses of the abbreviation 'tx'.
* adding new files to do with new cmm functionalityNorman Ramsey2007-09-071-0/+231