@@ -222,7 +222,7 @@ def __init__(self, tm, pto):
222
222
super ().__init__ (ffi .lib .LLVMPY_CreatePassBuilder (tm , pto ))
223
223
self ._pto = pto
224
224
self ._tm = tm
225
- self ._time_passes_handler = TimePassesHandler ()
225
+ self ._time_passes_handler = None
226
226
227
227
def getModulePassManager (self ):
228
228
return ModulePassManager (
@@ -238,18 +238,32 @@ def getFunctionPassManager(self):
238
238
239
239
def start_pass_timing (self ):
240
240
"""Enable the pass timers.
241
+
242
+ Raises
243
+ ------
244
+ RuntimeError
245
+ If pass timing is already enabled.
241
246
"""
247
+ if self ._time_passes_handler :
248
+ raise RuntimeError ("Pass builder should only have one \
249
+ pass timer at a time" )
250
+ self ._time_passes_handler = TimePassesHandler ()
242
251
ffi .lib .LLVMPY_EnableTimePasses (self , self ._time_passes_handler )
243
252
244
253
def finish_pass_timing (self ):
245
254
"""Returns the pass timings report and disables the LLVM internal
246
255
timers. Pass timers are enabled by ``start_pass_timing()``. If the
247
256
timers are not enabled, this function will return an empty string.
257
+
248
258
Returns
249
259
-------
250
260
res : str
251
261
LLVM generated timing report.
252
262
"""
263
+
264
+ if not self ._time_passes_handler :
265
+ raise RuntimeError ("Pass timing is not enabled" )
266
+
253
267
with ffi .OutputString () as buf :
254
268
ffi .lib .LLVMPY_ReportAndDisableTimePasses (
255
269
self ._time_passes_handler , buf )
0 commit comments