diff options
| author | Zichen Lu <mikaovo2000@gmail.com> | 2024-11-20 20:22:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-20 13:22:08 +0100 |
| commit | 08e7609692af3cb84da510deac70eeb02cbceb6d (patch) | |
| tree | 279fc3ce2945980adb86a1fdef226ee2762edc0d /mlir/lib/Target/LLVM/ModuleToObject.cpp | |
| parent | 33fcd6acc75535c8b5e27b00eb99d35abf52954d (diff) | |
[mlir][fix] Add callback functions for ModuleToObject (#116916)
Here is the [merged
MR](https://github.com/llvm/llvm-project/pull/116007) which caused a
failure and [was
reverted](https://github.com/llvm/llvm-project/pull/116811).
Thanks to @joker-eph for the help, I fix it (miss constructing
`ModuleObject` with callback functions in
`mlir/lib/Target/LLVM/NVVM/Target.cpp`) and split unit tests from origin
test which don't need `ptxas` to make the test runs more widely.
Diffstat (limited to 'mlir/lib/Target/LLVM/ModuleToObject.cpp')
| -rw-r--r-- | mlir/lib/Target/LLVM/ModuleToObject.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/mlir/lib/Target/LLVM/ModuleToObject.cpp b/mlir/lib/Target/LLVM/ModuleToObject.cpp index 77391341adaa..3f5b3d5e3186 100644 --- a/mlir/lib/Target/LLVM/ModuleToObject.cpp +++ b/mlir/lib/Target/LLVM/ModuleToObject.cpp @@ -34,10 +34,17 @@ using namespace mlir; using namespace mlir::LLVM; -ModuleToObject::ModuleToObject(Operation &module, StringRef triple, - StringRef chip, StringRef features, int optLevel) +ModuleToObject::ModuleToObject( + Operation &module, StringRef triple, StringRef chip, StringRef features, + int optLevel, function_ref<void(llvm::Module &)> initialLlvmIRCallback, + function_ref<void(llvm::Module &)> linkedLlvmIRCallback, + function_ref<void(llvm::Module &)> optimizedLlvmIRCallback, + function_ref<void(StringRef)> isaCallback) : module(module), triple(triple), chip(chip), features(features), - optLevel(optLevel) {} + optLevel(optLevel), initialLlvmIRCallback(initialLlvmIRCallback), + linkedLlvmIRCallback(linkedLlvmIRCallback), + optimizedLlvmIRCallback(optimizedLlvmIRCallback), + isaCallback(isaCallback) {} ModuleToObject::~ModuleToObject() = default; @@ -215,6 +222,9 @@ std::optional<SmallVector<char, 0>> ModuleToObject::run() { } setDataLayoutAndTriple(*llvmModule); + if (initialLlvmIRCallback) + initialLlvmIRCallback(*llvmModule); + // Link bitcode files. handleModulePreLink(*llvmModule); { @@ -227,10 +237,16 @@ std::optional<SmallVector<char, 0>> ModuleToObject::run() { handleModulePostLink(*llvmModule); } + if (linkedLlvmIRCallback) + linkedLlvmIRCallback(*llvmModule); + // Optimize the module. if (failed(optimizeModule(*llvmModule, optLevel))) return std::nullopt; + if (optimizedLlvmIRCallback) + optimizedLlvmIRCallback(*llvmModule); + // Return the serialized object. return moduleToObject(*llvmModule); } |
