Skip to content

Commit

Permalink
[XLA:CPU] Store ThreadSafeModule in LlvmIrKernelSource
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 719321299
  • Loading branch information
WillFroom authored and Google-ML-Automation committed Jan 27, 2025
1 parent fd2988c commit 7ea5233
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 3 additions & 1 deletion xla/codegen/llvm_ir_kernel_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ limitations under the License.

#include <string>

#include "llvm/IR/Module.h"
#include "xla/service/llvm_ir/llvm_util.h"

namespace xla {

std::string LlvmIrKernelSource::ToString() const {
return llvm_ir::DumpToString(module_.get());
return module_.withModuleDo(
[&](llvm::Module& m) { return llvm_ir::DumpToString(&m); });
}

} // namespace xla
7 changes: 3 additions & 4 deletions xla/codegen/llvm_ir_kernel_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@ class LlvmIrKernelSource final : public KernelSource {
public:
LlvmIrKernelSource(llvm::orc::ThreadSafeContext context,
std::unique_ptr<llvm::Module> module)
: context_(std::move(context)), module_(std::move(module)) {}
: module_(std::move(module), std::move(context)) {}

LlvmIrKernelSource(LlvmIrKernelSource&& other) = default;
LlvmIrKernelSource& operator=(LlvmIrKernelSource&& other) = default;

llvm::orc::ThreadSafeModule thread_safe_module() && {
return llvm::orc::ThreadSafeModule(std::move(module_), context_);
return std::move(module_);
}

std::string ToString() const final;

private:
llvm::orc::ThreadSafeContext context_;
std::unique_ptr<llvm::Module> module_;
llvm::orc::ThreadSafeModule module_;
};

} // namespace xla
Expand Down

0 comments on commit 7ea5233

Please sign in to comment.