Opened 4 years ago

Closed 4 years ago

#4299 closed feature request (fixed)

a less forceful INLINE pragma

Reported by: simonmar Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.12.3
Keywords: Cc: johan.tibell@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty: Moderate (less than a day)
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The INLINE pragmas currently does two things:

  1. it saves an unoptimised definition of the function in the interface file, and
  2. it unfolds the definition at (almost) every call site, before optimising it further in situ.

I'm proposing that we have a variant of the INLINE pragma that does (1) without necessarily unfolding the definition at every call site. GHC's simplifier already has some well-tuned heuristics for deciding whether to inline something or not based on information about the context, and when we use INLINE we bypass all this and potentially end up with unnecessary code bloat and maybe even a loss of performance in some cases.

If we had an INLINEABLE pragma that did (1) without forcing (2), then the decision about whether to inline or not is deferred to the call site, where the user can decide how they want to trade off code size against speed. Right now the user doesn't get to decide - the library writer does.

Change History (3)

comment:1 Changed 4 years ago by tibbe

  • Cc johan.tibell@… added

comment:2 Changed 4 years ago by simonpj

Simon and I decided this was worth doing. An important feature of INLINABLE is that if you say (inline f e1 e2) in another module, you get your specified inlining for f. You can do this on a per-call-site basis.

Documentation will come in a second patch. Here's the payload:

Wed Sep 15 05:44:42 PDT 2010  simonpj@microsoft.com
  * Implement INLINABLE pragma 
  
  Implements Trac #4299.  Documentation to come.

    M ./compiler/basicTypes/BasicTypes.lhs -15 +37
    M ./compiler/basicTypes/MkId.lhs -1 +1
    M ./compiler/coreSyn/CoreFVs.lhs -1 +1
    M ./compiler/coreSyn/CoreSubst.lhs -4 +4
    M ./compiler/coreSyn/CoreSyn.lhs -29 +31
    M ./compiler/coreSyn/CoreUnfold.lhs -48 +63
    M ./compiler/coreSyn/PprCore.lhs -3 +3
    M ./compiler/deSugar/DsBinds.lhs -10 +18
    M ./compiler/deSugar/DsForeign.lhs -1 +1
    M ./compiler/deSugar/DsMeta.hs -6 +8
    M ./compiler/hsSyn/Convert.lhs -1 +5
    M ./compiler/iface/BinIface.hs -3 +18
    M ./compiler/iface/IfaceSyn.lhs -5 +8
    M ./compiler/iface/MkIface.lhs -7 +9
    M ./compiler/iface/TcIface.lhs -4 +7
    M ./compiler/main/TidyPgm.lhs -2 +2
    M ./compiler/parser/Lexer.x -6 +7
    M ./compiler/parser/Parser.y.pp -11 +7
    M ./compiler/parser/RdrHsSyn.lhs -8 +7
    M ./compiler/simplCore/OccurAnal.lhs -1 +1
    M ./compiler/simplCore/SetLevels.lhs -1 +1
    M ./compiler/simplCore/Simplify.lhs -6 +7
    M ./compiler/specialise/Specialise.lhs -5 +5
    M ./compiler/stranal/WorkWrap.lhs -9 +5
    M ./compiler/vectorise/Vectorise.hs -2 +2
    M ./compiler/vectorise/Vectorise/Exp.hs -1 +1
    M ./compiler/vectorise/Vectorise/Type/Env.hs -1 +1
    M ./compiler/vectorise/Vectorise/Type/PADict.hs -1 +1
    M ./compiler/vectorise/Vectorise/Utils/Closure.hs -1 +1
    M ./compiler/vectorise/Vectorise/Utils/Hoisting.hs -2 +2

comment:3 Changed 4 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed

Here's the documentation patch.

Wed Sep 15 08:42:35 PDT 2010  simonpj@microsoft.com
  * Documentation for INLINABLE

    M ./compiler/prelude/primops.txt.pp -5 +3
    M ./docs/users_guide/glasgow_exts.xml -10 +104

Done! Not very thoroughly tested, mind you, but all the API changes are in, and seems to work.

Simon

Note: See TracTickets for help on using tickets.