| 99 | }; |
| 100 | |
| 101 | TEST_P(HloDataflowAnalysisTest, BinaryOperation) { |
| 102 | // Test the dataflow for a simple binary operation (Add). |
| 103 | auto builder = HloComputation::Builder(TestName()); |
| 104 | auto constant1 = builder.AddInstruction( |
| 105 | HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(1.0))); |
| 106 | auto constant2 = builder.AddInstruction( |
| 107 | HloInstruction::CreateConstant(LiteralUtil::CreateR0<float>(2.0))); |
| 108 | auto add = builder.AddInstruction(HloInstruction::CreateBinary( |
| 109 | scalar_shape_, HloOpcode::kAdd, constant1, constant2)); |
| 110 | module_->AddEntryComputation(builder.Build()); |
| 111 | SCOPED_TRACE(module_->ToString()); |
| 112 | |
| 113 | bool ssa_form = GetParam(); |
| 114 | const HloDataflowAnalysis& analysis = RunAnalysis(ssa_form); |
| 115 | |
| 116 | // Each instruction should define a single value. |
| 117 | EXPECT_EQ(analysis.values().size(), 3); |
| 118 | EXPECT_TRUE(analysis.ValueIsDefinedAt(constant1)); |
| 119 | EXPECT_TRUE(analysis.ValueIsDefinedAt(constant2)); |
| 120 | EXPECT_TRUE(analysis.ValueIsDefinedAt(add)); |
| 121 | |
| 122 | // Verify the positions of the values. These positions are all trivial because |
| 123 | // there are no instructions which forward values. |
| 124 | EXPECT_THAT(analysis.GetValueDefinedAt(constant1).positions(), |
| 125 | UnorderedElementsAre(HloPosition{constant1, {}})); |
| 126 | EXPECT_THAT(analysis.GetValueDefinedAt(constant2).positions(), |
| 127 | UnorderedElementsAre(HloPosition{constant2, {}})); |
| 128 | EXPECT_THAT(analysis.GetValueDefinedAt(add).positions(), |
| 129 | UnorderedElementsAre(HloPosition{add, {}})); |
| 130 | |
| 131 | // Verify the uses of the values. |
| 132 | EXPECT_THAT(analysis.GetValueDefinedAt(constant1).uses(), |
| 133 | UnorderedElementsAre(HloUse{add, 0, {}})); |
| 134 | EXPECT_THAT(analysis.GetValueDefinedAt(constant2).uses(), |
| 135 | UnorderedElementsAre(HloUse{add, 1, {}})); |
| 136 | EXPECT_TRUE(analysis.GetValueDefinedAt(add).uses().empty()); |
| 137 | |
| 138 | // Verify liveout values from the module. |
| 139 | EXPECT_FALSE(analysis.GetValueDefinedAt(constant1).live_out_of_module()); |
| 140 | EXPECT_FALSE(analysis.GetValueDefinedAt(constant2).live_out_of_module()); |
| 141 | EXPECT_TRUE(analysis.GetValueDefinedAt(add).live_out_of_module()); |
| 142 | } |
| 143 | |
| 144 | TEST_P(HloDataflowAnalysisTest, TupleAndGtes) { |
| 145 | // Verify the dataflow through a Tuple and GetTupleElement instructions. |
nothing calls this directly
no test coverage detected