-
Notifications
You must be signed in to change notification settings - Fork 340
Enable pass timings reporting with NewPassManager #1163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
08a9a4b
4f21d54
90fe538
ee3b12a
fd81b94
35da642
86255fe
395a996
f23b7a2
fb95e35
8b1ca66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,10 @@ typedef OpaquePipelineTuningOptions *LLVMPipelineTuningOptionsRef; | |
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(PipelineTuningOptions, | ||
LLVMPipelineTuningOptionsRef) | ||
|
||
struct OpaqueTimePassesHandler; | ||
typedef OpaqueTimePassesHandler *LLVMTimePassesHandlerRef; | ||
DEFINE_SIMPLE_CONVERSION_FUNCTIONS(TimePassesHandler, LLVMTimePassesHandlerRef) | ||
|
||
static TargetMachine *unwrap(LLVMTargetMachineRef P) { | ||
return reinterpret_cast<TargetMachine *>(P); | ||
} | ||
|
@@ -281,21 +285,55 @@ LLVMPY_DisposePipelineTuningOptions(LLVMPipelineTuningOptionsRef PTO) { | |
|
||
// PB | ||
|
||
API_EXPORT(LLVMTimePassesHandlerRef) | ||
LLVMPY_CreateLLVMTimePassesHandler() { | ||
return llvm::wrap(new TimePassesHandler(true)); | ||
yashssh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
API_EXPORT(void) | ||
LLVMPY_DisposeLLVMTimePassesHandler(LLVMTimePassesHandlerRef TimePassesRef) { | ||
yashssh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
delete llvm::unwrap(TimePassesRef); | ||
} | ||
|
||
API_EXPORT(void) | ||
LLVMPY_SetTimePassesNPM(LLVMPassBuilderRef PBRef, LLVMTimePassesHandlerRef TimePassesRef) { | ||
yashssh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TimePassesHandler *TP = llvm::unwrap(TimePassesRef); | ||
TimePassesIsEnabled = true; | ||
PassBuilder *PB = llvm::unwrap(PBRef); | ||
PassInstrumentationCallbacks *PIC = PB->getPassInstrumentationCallbacks(); | ||
TP->registerCallbacks(*PIC); | ||
} | ||
|
||
API_EXPORT(void) | ||
LLVMPY_ReportAndResetTimingsNPM(LLVMTimePassesHandlerRef TimePassesRef, | ||
const char **outmsg) { | ||
std::string osbuf; | ||
raw_string_ostream os(osbuf); | ||
TimePassesHandler *TP = llvm::unwrap(TimePassesRef); | ||
TP->setOutStream(os); | ||
TP->print(); | ||
os.flush(); | ||
*outmsg = LLVMPY_CreateString(os.str().c_str()); | ||
TimePassesIsEnabled = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there some asymmetry here - do pass instrumentation callbacks need to be unregistered if we've disabled pass timing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. A unique There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you start and finish pass timing, and then start pass timing again, do you end up with the callbacks registered twice though? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TimePassesHandler::registerCallbacks has an early exit which will prevent this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see how that early exist handler helps in this scenario, in which the user at the Python level has written
At this point pass timing is re-enabled, and it looks like the callbacks will be registered a second time at https://github.com/numba/llvmlite/pull/1163/files#diff-45eef2a2ab57512c9c03ab44fbebc4228722e001d790af044bd2ca511df08414R306 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah you are right. Sorry, I read the code wrong.
I get an asserting failure from LLVM:
Which is also consistent with the fact we allow running the optimisation pipeline with the PassManger object only once. Should we try to handle this in Python? Imo we can ignore this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can't have CPython get killed by a user's Python coding error. We could have a check in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I have added a mechanism to prevent enabling time passes multiple times, what do you think? |
||
} | ||
|
||
API_EXPORT(LLVMPassBuilderRef) | ||
LLVMPY_CreatePassBuilder(LLVMTargetMachineRef TM, | ||
LLVMPipelineTuningOptionsRef PTO) { | ||
TargetMachine *target = llvm::unwrap(TM); | ||
PipelineTuningOptions *pt = llvm::unwrap(PTO); | ||
LLVMPY_CreatePassBuilder(LLVMTargetMachineRef TMRef, | ||
LLVMPipelineTuningOptionsRef PTORef) { | ||
TargetMachine *TM = llvm::unwrap(TMRef); | ||
PipelineTuningOptions *PTO = llvm::unwrap(PTORef); | ||
PassInstrumentationCallbacks *PIC = new PassInstrumentationCallbacks(); | ||
#if LLVM_VERSION_MAJOR < 16 | ||
return llvm::wrap(new PassBuilder(target, *pt, None, PIC)); | ||
return llvm::wrap(new PassBuilder(TM, *PTO, None, PIC)); | ||
#else | ||
return llvm::wrap(new PassBuilder(target, *pt, std::nullopt, PIC)); | ||
return llvm::wrap(new PassBuilder(TM, *PTO, std::nullopt, PIC)); | ||
#endif | ||
} | ||
|
||
API_EXPORT(void) | ||
LLVMPY_DisposePassBuilder(LLVMPassBuilderRef PB) { delete llvm::unwrap(PB); } | ||
LLVMPY_DisposePassBuilder(LLVMPassBuilderRef PBRef) { | ||
delete llvm::unwrap(PBRef); | ||
} | ||
|
||
static OptimizationLevel mapLevel(int speed_level, int size_level) { | ||
switch (size_level) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.