[XLA:CPU] Guard LLVM command line options when infering target machine

PiperOrigin-RevId: 825233596
This commit is contained in:
Karlo Basioli 2025-10-28 15:36:06 -07:00 committed by TensorFlower Gardener
parent 281fa6f4d3
commit 8ab9ebee94
2 changed files with 11 additions and 0 deletions

View File

@ -2170,6 +2170,7 @@ cc_library(
"//xla/service:compiler", "//xla/service:compiler",
"//xla/service:executable", "//xla/service:executable",
"//xla/service:hlo_module_config", "//xla/service:hlo_module_config",
"//xla/service/llvm_ir:llvm_command_line_options",
"//xla/tsl/platform:errors", "//xla/tsl/platform:errors",
"//xla/tsl/platform:statusor", "//xla/tsl/platform:statusor",
"@com_google_absl//absl/log", "@com_google_absl//absl/log",

View File

@ -40,6 +40,7 @@ limitations under the License.
#include "xla/service/cpu/runtime_symbol_generator.h" #include "xla/service/cpu/runtime_symbol_generator.h"
#include "xla/service/executable.h" #include "xla/service/executable.h"
#include "xla/service/hlo_module_config.h" #include "xla/service/hlo_module_config.h"
#include "xla/service/llvm_ir/llvm_command_line_options.h"
#include "xla/tsl/platform/errors.h" #include "xla/tsl/platform/errors.h"
#include "xla/tsl/platform/statusor.h" #include "xla/tsl/platform/statusor.h"
#include "xla/util.h" #include "xla/util.h"
@ -88,6 +89,11 @@ absl::StatusOr<std::unique_ptr<FunctionLibrary>> LoadFunctionLibrary(
absl::Span<const ObjFileProto> obj_files, const HloModule* hlo_module) { absl::Span<const ObjFileProto> obj_files, const HloModule* hlo_module) {
const HloModuleConfig& config = hlo_module->config(); const HloModuleConfig& config = hlo_module->config();
const DebugOptions& debug_options = config.debug_options(); const DebugOptions& debug_options = config.debug_options();
auto llvm_options = llvm_ir::ExtractXlaBackendExtraOptions(
config.debug_options().xla_backend_extra_options());
llvm_ir::LLVMCommandLineOptionsLock llvm_lock(llvm_options);
TF_ASSIGN_OR_RETURN( TF_ASSIGN_OR_RETURN(
std::unique_ptr<llvm::TargetMachine> target_machine, std::unique_ptr<llvm::TargetMachine> target_machine,
IrCompiler::InferTargetMachine( IrCompiler::InferTargetMachine(
@ -159,6 +165,10 @@ CpuAotLoader::LoadAotCompilationResult(
std::unique_ptr<HloModule> hlo_module, std::unique_ptr<HloModule> hlo_module,
HloModule::CreateFromProtoWithConfig(aot_result_proto.hlo_module())); HloModule::CreateFromProtoWithConfig(aot_result_proto.hlo_module()));
auto llvm_options = llvm_ir::ExtractXlaBackendExtraOptions(
hlo_module->config().debug_options().xla_backend_extra_options());
llvm_ir::LLVMCommandLineOptionsLock llvm_lock(llvm_options);
TF_ASSIGN_OR_RETURN( TF_ASSIGN_OR_RETURN(
std::unique_ptr<llvm::TargetMachine> target_machine, std::unique_ptr<llvm::TargetMachine> target_machine,
IrCompiler::InferTargetMachine( IrCompiler::InferTargetMachine(