@@ -206,7 +206,7 @@ class XlaHloToLhloPass
206206// instruction. If `num_operands` is valid, then only the first `num_operands`
207207// operands of the HLO instruction will be considered.
208208Status LhloDialectEmitter::CreateOperands (
209- HloInstruction* instr, absl::optional<xla::int64> num_operands,
209+ const HloInstruction* instr, absl::optional<xla::int64> num_operands,
210210 llvm::SmallVectorImpl<Value>& operands, size_t & num_arguments,
211211 size_t & num_results) {
212212 if (num_operands.value_or (0 ) > instr->operand_count ())
@@ -222,7 +222,7 @@ Status LhloDialectEmitter::CreateOperands(
222222}
223223
224224template <typename OpType>
225- OpType LhloDialectEmitter::CreateOpWithoutAttrs (HloInstruction* instr,
225+ OpType LhloDialectEmitter::CreateOpWithoutAttrs (const HloInstruction* instr,
226226 ValueRange operands) {
227227 Location loc = getLocation (instr);
228228 NamedAttribute attrs[] = {{Identifier::get (" name" , builder_.getContext ()),
@@ -232,15 +232,16 @@ OpType LhloDialectEmitter::CreateOpWithoutAttrs(HloInstruction* instr,
232232
233233template <typename OpType>
234234StatusOr<OpType> LhloDialectEmitter::CreateOpWithoutAttrs (
235- HloInstruction* instr, size_t & num_arguments, size_t & num_results,
235+ const HloInstruction* instr, size_t & num_arguments, size_t & num_results,
236236 absl::optional<xla::int64> num_operands) {
237237 llvm::SmallVector<Value, 4 > operands;
238238 TF_RETURN_IF_ERROR (CreateOperands (instr, num_operands, operands,
239239 num_arguments, num_results));
240240 return CreateOpWithoutAttrs<OpType>(instr, operands);
241241}
242242
243- StatusOr<mlir::Operation*> LhloDialectEmitter::EmitOp (HloInstruction* instr) {
243+ StatusOr<mlir::Operation*> LhloDialectEmitter::EmitOp (
244+ const HloInstruction* instr) {
244245 using xla::HloOpcode;
245246 switch (instr->opcode ()) {
246247 case HloOpcode::kAbs :
@@ -363,11 +364,12 @@ StatusOr<mlir::Operation*> LhloDialectEmitter::EmitOp(HloInstruction* instr) {
363364 }
364365}
365366
366- Status LhloDialectEmitter::DefaultAction (HloInstruction* instr) {
367+ Status LhloDialectEmitter::DefaultAction (const HloInstruction* instr) {
367368 return EmitOp (instr).status ();
368369}
369370
370- StatusOr<lmhlo::SortOp> LhloDialectEmitter::EmitSortOp (HloInstruction* instr) {
371+ StatusOr<lmhlo::SortOp> LhloDialectEmitter::EmitSortOp (
372+ const HloInstruction* instr) {
371373 TF_ASSIGN_OR_RETURN (auto sort, CreateOpWithoutAttrs<lmhlo::SortOp>(instr));
372374 auto * sort_instr = xla::Cast<xla::HloSortInstruction>(instr);
373375 sort.dimensionAttr (builder_.getI64IntegerAttr (sort_instr->sort_dimension ()));
@@ -425,7 +427,7 @@ StatusOr<Value> LhloDialectEmitter::RewriteFusionOperand(
425427}
426428
427429StatusOr<lmhlo::FusionOp> LhloDialectEmitter::EmitFusionOp (
428- HloInstruction* instr) {
430+ const HloInstruction* instr) {
429431 Location loc = getLocation (instr);
430432
431433 auto * fusion_instr = xla::Cast<xla::HloFusionInstruction>(instr);
@@ -494,7 +496,7 @@ StatusOr<lmhlo::FusionOp> LhloDialectEmitter::EmitFusionOp(
494496}
495497
496498StatusOr<mhlo::ScatterDimensionNumbers>
497- LhloDialectEmitter::GetScatterDimensionNumbers (HloInstruction* instr) {
499+ LhloDialectEmitter::GetScatterDimensionNumbers (const HloInstruction* instr) {
498500 auto * scatter_instr = xla::Cast<xla::HloScatterInstruction>(instr);
499501
500502 const xla::ScatterDimensionNumbers& xla_scatter_dim =
@@ -509,7 +511,7 @@ LhloDialectEmitter::GetScatterDimensionNumbers(HloInstruction* instr) {
509511}
510512
511513StatusOr<lmhlo::ScatterOp> LhloDialectEmitter::EmitScatterOp (
512- HloInstruction* instr) {
514+ const HloInstruction* instr) {
513515 TF_ASSIGN_OR_RETURN (auto scatter,
514516 CreateOpWithoutAttrs<lmhlo::ScatterOp>(instr));
515517
@@ -533,7 +535,7 @@ StatusOr<lmhlo::ScatterOp> LhloDialectEmitter::EmitScatterOp(
533535}
534536
535537StatusOr<lmhlo::SelectAndScatterOp> LhloDialectEmitter::EmitSelectAndScatterOp (
536- HloInstruction* instr) {
538+ const HloInstruction* instr) {
537539 TF_ASSIGN_OR_RETURN (auto select_and_scatter,
538540 CreateOpWithoutAttrs<lmhlo::SelectAndScatterOp>(instr));
539541
@@ -566,7 +568,7 @@ StatusOr<lmhlo::SelectAndScatterOp> LhloDialectEmitter::EmitSelectAndScatterOp(
566568}
567569
568570StatusOr<mlir::Operation*> LhloDialectEmitter::EmitCustomCallOp (
569- HloInstruction* instr) {
571+ const HloInstruction* instr) {
570572 auto * custom_call_instr = xla::Cast<xla::HloCustomCallInstruction>(instr);
571573
572574 if (xla::gpu::IsCustomCallToCusolver (*instr)) {
@@ -601,7 +603,7 @@ StatusOr<mlir::Operation*> LhloDialectEmitter::EmitCustomCallOp(
601603}
602604
603605StatusOr<lmhlo_gpu::CholeskyOp> LhloDialectEmitter::EmitCholesky (
604- HloCustomCallInstruction* custom_call) {
606+ const HloCustomCallInstruction* custom_call) {
605607 TF_ASSIGN_OR_RETURN (auto cholesky_op,
606608 CreateOpWithoutAttrs<lmhlo_gpu::CholeskyOp>(custom_call));
607609 TF_ASSIGN_OR_RETURN (xla::CholeskyOptions options,
@@ -611,7 +613,7 @@ StatusOr<lmhlo_gpu::CholeskyOp> LhloDialectEmitter::EmitCholesky(
611613}
612614
613615StatusOr<Operation*> LhloDialectEmitter::EmitGemm (
614- HloCustomCallInstruction* custom_call) {
616+ const HloCustomCallInstruction* custom_call) {
615617 TF_ASSIGN_OR_RETURN (
616618 auto const config,
617619 custom_call->backend_config <xla::gpu::GemmBackendConfig>());
@@ -675,7 +677,7 @@ static StatusOr<mlir::lmhlo_gpu::Activation> GetLHLOActivation(
675677}
676678
677679StatusOr<Operation*> LhloDialectEmitter::EmitDnnConvolution (
678- HloCustomCallInstruction* custom_call) {
680+ const HloCustomCallInstruction* custom_call) {
679681 TF_ASSIGN_OR_RETURN (
680682 auto const backend_config,
681683 custom_call->backend_config <xla::gpu::CudnnConvBackendConfig>());
@@ -796,7 +798,7 @@ StatusOr<Operation*> LhloDialectEmitter::EmitDnnConvolution(
796798}
797799
798800StatusOr<Operation*> LhloDialectEmitter::EmitDnnBatchNorm (
799- HloCustomCallInstruction* custom_call) {
801+ const HloCustomCallInstruction* custom_call) {
800802 const xla::int64 num_operands = custom_call->operand_count ();
801803 auto set_batchnorm_attributes = [&](auto op) -> StatusOr<Operation*> {
802804 // The last 2 operands of a custom call for batch norm are the epsilon and
@@ -895,7 +897,7 @@ StatusOr<mlir::GetGlobalMemrefOp> LhloDialectEmitter::EmitConstant(
895897}
896898
897899StatusOr<lmhlo::ReduceOp> LhloDialectEmitter::EmitReduceOp (
898- HloInstruction* instr) {
900+ const HloInstruction* instr) {
899901 TF_ASSIGN_OR_RETURN (auto reduce_op,
900902 CreateOpWithoutAttrs<lmhlo::ReduceOp>(instr));
901903 auto * reduce = xla::Cast<xla::HloReduceInstruction>(instr);
@@ -907,7 +909,8 @@ StatusOr<lmhlo::ReduceOp> LhloDialectEmitter::EmitReduceOp(
907909 return reduce_op;
908910}
909911
910- StatusOr<lmhlo::MapOp> LhloDialectEmitter::EmitMapOp (HloInstruction* instr) {
912+ StatusOr<lmhlo::MapOp> LhloDialectEmitter::EmitMapOp (
913+ const HloInstruction* instr) {
911914 TF_ASSIGN_OR_RETURN (auto map_op, CreateOpWithoutAttrs<lmhlo::MapOp>(instr));
912915 auto * map = xla::Cast<xla::HloMapInstruction>(instr);
913916 std::vector<int64_t > dimensions (map->dimensions ().begin (),
@@ -919,7 +922,7 @@ StatusOr<lmhlo::MapOp> LhloDialectEmitter::EmitMapOp(HloInstruction* instr) {
919922}
920923
921924StatusOr<lmhlo::CompareOp> LhloDialectEmitter::EmitCompareOp (
922- HloInstruction* instr) {
925+ const HloInstruction* instr) {
923926 TF_ASSIGN_OR_RETURN (auto compare_op,
924927 CreateOpWithoutAttrs<lmhlo::CompareOp>(instr));
925928
@@ -960,7 +963,7 @@ StatusOr<lmhlo::CompareOp> LhloDialectEmitter::EmitCompareOp(
960963}
961964
962965StatusOr<lmhlo::ReducePrecisionOp> LhloDialectEmitter::EmitReducePrecisionOp (
963- HloInstruction* instr) {
966+ const HloInstruction* instr) {
964967 TF_ASSIGN_OR_RETURN (auto reduce_precision_op,
965968 CreateOpWithoutAttrs<lmhlo::ReducePrecisionOp>(instr));
966969 auto * reduce_precision = xla::Cast<xla::HloReducePrecisionInstruction>(instr);
@@ -972,7 +975,7 @@ StatusOr<lmhlo::ReducePrecisionOp> LhloDialectEmitter::EmitReducePrecisionOp(
972975}
973976
974977StatusOr<lmhlo::AllReduceOp> LhloDialectEmitter::EmitAllReduceOp (
975- HloInstruction* instr) {
978+ const HloInstruction* instr) {
976979 TF_ASSIGN_OR_RETURN (auto all_reduce_op,
977980 CreateOpWithoutAttrs<lmhlo::AllReduceOp>(instr));
978981 auto * all_reduce = xla::Cast<xla::HloAllReduceInstruction>(instr);
@@ -993,8 +996,8 @@ StatusOr<lmhlo::AllReduceOp> LhloDialectEmitter::EmitAllReduceOp(
993996}
994997
995998StatusOr<lmhlo::InfeedOp> LhloDialectEmitter::EmitInfeedOp (
996- HloInstruction* instr) {
997- HloInfeedInstruction* infeed = xla::Cast<HloInfeedInstruction>(instr);
999+ const HloInstruction* instr) {
1000+ const HloInfeedInstruction* infeed = xla::Cast<HloInfeedInstruction>(instr);
9981001 // HLO Infeed instruction has a single operand of token type and a tuple
9991002 // with buffers and a token as its output. LMHLO Infeed operation does not
10001003 // need the token operand or result, so drop it.
@@ -1006,8 +1009,9 @@ StatusOr<lmhlo::InfeedOp> LhloDialectEmitter::EmitInfeedOp(
10061009}
10071010
10081011StatusOr<lmhlo::OutfeedOp> LhloDialectEmitter::EmitOutfeedOp (
1009- HloInstruction* instr) {
1010- HloOutfeedInstruction* outfeed = xla::Cast<HloOutfeedInstruction>(instr);
1012+ const HloInstruction* instr) {
1013+ const HloOutfeedInstruction* outfeed =
1014+ xla::Cast<HloOutfeedInstruction>(instr);
10111015 // HLO outfeed instruction has 2 operands, the source and a token, and a
10121016 // single token output. LMHLO Outfeed does not need the token operand and
10131017 // result, do drop it.
@@ -1223,7 +1227,7 @@ Status HloToLhloModule(const BufferAssignment& assignment,
12231227 module .getContext ()
12241228 ->loadDialect <StandardOpsDialect, mhlo::MhloDialect, lmhlo::LmhloDialect,
12251229 lmhlo_gpu::LmhloGpuDialect>();
1226- HloComputation* computation = hlo_module.entry_computation ();
1230+ const HloComputation* computation = hlo_module.entry_computation ();
12271231
12281232 LhloDialectEmitter emitter (assignment, *computation, module );
12291233 TF_RETURN_IF_ERROR (emitter.Initialize ());
0 commit comments