diff options
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/ccgstmts.nim | 4 | ||||
-rwxr-xr-x | compiler/cgen.nim | 19 | ||||
-rw-r--r-- | compiler/cgendata.nim | 1 | ||||
-rwxr-xr-x | compiler/nimrod.nim | 4 | ||||
-rwxr-xr-x | compiler/ropes.nim | 1 |
5 files changed, 12 insertions, 17 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index dfa624821..9c25a44ec 100755 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -265,6 +265,10 @@ proc genWhileStmt(p: BProc, t: PNode) = let label = assignLabel(p.blocks[p.breakIdx]) lineF(p, cpsStmts, "if (!$1) goto $2;$n", [rdLoc(a), label]) genStmts(p, t.sons[1]) + + if optProfiler in p.options: + # invoke at loop body exit: + lineCg(p, cpsStmts, "#nimProfile();$n") endBlock(p) dec(p.withinLoop) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 840b80ade..07ab15b33 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -680,27 +680,14 @@ proc genProcAux(m: BModule, prc: PSym) = app(generatedProc, initFrame(p, procname, filename)) else: app(generatedProc, p.s(cpsLocals)) - if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM): - if gProcProfile >= 64 * 1024: - InternalError(prc.info, "too many procedures for profiling") - discard cgsym(m, "profileData") - appf(p.s(cpsLocals), "\tticks NIM_profilingStart;$n") - if prc.loc.a < 0: - appf(m.s[cfsDebugInit], "\tprofileData[$1].procname = $2;$n", [ - toRope(gProcProfile), - makeCString(prc.name.s)]) - prc.loc.a = gProcProfile - inc(gProcProfile) - prepend(p.s(cpsInit), ropef("\tNIM_profilingStart = getticks();$n")) + if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM): + # invoke at proc entry for recursion: + appcg(p, cpsInit, "\t#nimProfile();$n", []) app(generatedProc, p.s(cpsInit)) app(generatedProc, p.s(cpsStmts)) if p.beforeRetNeeded: appf(generatedProc, "\tBeforeRet: ;$n") app(generatedProc, deinitGCFrame(p)) if optStackTrace in prc.options: app(generatedProc, deinitFrame(p)) - if (optProfiler in prc.options) and (gCmd != cmdCompileToLLVM): - appf(generatedProc, - "\tprofileData[$1].total += elapsed(getticks(), NIM_profilingStart);$n", - [toRope(prc.loc.a)]) app(generatedProc, returnStmt) appf(generatedProc, "}$N") app(m.s[cfsProcs], generatedProc) diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index f42381e59..57911c004 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -115,7 +115,6 @@ type var mainModProcs*, mainModInit*, mainDatInit*: PRope # parts of the main module gMapping*: PRope # the generated mapping file (if requested) - gProcProfile*: Natural # proc profile counter gPendingModules*: seq[BModule] = @[] # list of modules that are not # finished with code generation gModules*: seq[BModule] = @[] # list of all compiled modules diff --git a/compiler/nimrod.nim b/compiler/nimrod.nim index 1bd6698a7..0305396da 100755 --- a/compiler/nimrod.nim +++ b/compiler/nimrod.nim @@ -20,6 +20,10 @@ import when hasTinyCBackend: import tccgen +when defined(profiler): + {.hint: "Profiling support is turned on!".} + import nimprof + var arguments: string = "" # the arguments to be passed to the program that # should be run diff --git a/compiler/ropes.nim b/compiler/ropes.nim index 0107f5241..50c89e4d9 100755 --- a/compiler/ropes.nim +++ b/compiler/ropes.nim @@ -294,6 +294,7 @@ proc crcFromRopeAux(r: PRope, startVal: TCrc32): TCrc32 = result = crcFromRopeAux(r.right, result) proc newCrcFromRopeAux(r: PRope, startVal: TCrc32): TCrc32 = + # XXX profiling shows this is actually expensive var stack: TRopeSeq = @[r] result = startVal while len(stack) > 0: |