| 43 | using CallInlinerTest = HloTestBase; |
| 44 | |
| 45 | TEST_F(CallInlinerTest, ControlDependenciesAreCarriedToCaller) { |
| 46 | // "inner" computation just has a control dependency from the "zero" value to |
| 47 | // the "one" value. |
| 48 | HloComputation::Builder inner(TestName() + ".inner"); |
| 49 | HloInstruction* zero = inner.AddInstruction( |
| 50 | HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(24.0f))); |
| 51 | HloInstruction* one = inner.AddInstruction( |
| 52 | HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(42.0f))); |
| 53 | TF_ASSERT_OK(zero->AddControlDependencyTo(one)); |
| 54 | auto module = CreateNewVerifiedModule(); |
| 55 | HloComputation* inner_computation = |
| 56 | module->AddEmbeddedComputation(inner.Build()); |
| 57 | |
| 58 | // "outer" computation just calls the "inner" computation. |
| 59 | HloComputation::Builder outer(TestName() + ".outer"); |
| 60 | Shape r0f32 = ShapeUtil::MakeShape(F32, {}); |
| 61 | outer.AddInstruction( |
| 62 | HloInstruction::CreateCall(r0f32, {}, inner_computation)); |
| 63 | |
| 64 | auto computation = module->AddEntryComputation(outer.Build()); |
| 65 | |
| 66 | CallInliner call_inliner; |
| 67 | TF_ASSERT_OK_AND_ASSIGN(bool mutated, call_inliner.Run(module.get())); |
| 68 | ASSERT_TRUE(mutated); |
| 69 | EXPECT_THAT(computation->root_instruction(), op::Constant()); |
| 70 | EXPECT_EQ(computation->root_instruction()->literal().GetFirstElement<float>(), |
| 71 | 42); |
| 72 | ASSERT_EQ(1, computation->root_instruction()->control_predecessors().size()); |
| 73 | auto prior = computation->root_instruction()->control_predecessors()[0]; |
| 74 | EXPECT_THAT(prior, op::Constant()); |
| 75 | EXPECT_EQ(prior->literal().GetFirstElement<float>(), 24); |
| 76 | } |
| 77 | |
| 78 | // Tests for referential transparency (a function that calls a function that |
| 79 | // returns false should be identical to just returning false). |
nothing calls this directly
no test coverage detected