Helper to get the ids of float constants 0.0 and 1.0, creating them if necessary.
| 124 | // Helper to get the ids of float constants 0.0 and 1.0, creating them if |
| 125 | // necessary. |
| 126 | std::pair<uint32_t, uint32_t> FindOrCreateFloatZeroAndOne( |
| 127 | opt::IRContext* ir_context, opt::analysis::Float* float_type) { |
| 128 | float one = 1.0; |
| 129 | uint32_t one_as_uint; |
| 130 | memcpy(&one_as_uint, &one, sizeof(float)); |
| 131 | std::vector<uint32_t> zero_bytes = {0}; |
| 132 | std::vector<uint32_t> one_bytes = {one_as_uint}; |
| 133 | auto constant_zero = ir_context->get_constant_mgr()->RegisterConstant( |
| 134 | MakeUnique<opt::analysis::FloatConstant>(float_type, zero_bytes)); |
| 135 | auto constant_one = ir_context->get_constant_mgr()->RegisterConstant( |
| 136 | MakeUnique<opt::analysis::FloatConstant>(float_type, one_bytes)); |
| 137 | auto constant_zero_id = ir_context->get_constant_mgr() |
| 138 | ->GetDefiningInstruction(constant_zero) |
| 139 | ->result_id(); |
| 140 | auto constant_one_id = ir_context->get_constant_mgr() |
| 141 | ->GetDefiningInstruction(constant_one) |
| 142 | ->result_id(); |
| 143 | return std::pair<uint32_t, uint32_t>(constant_zero_id, constant_one_id); |
| 144 | } |
| 145 | |
| 146 | std::unique_ptr<TransformationReplaceConstantWithUniform> |
| 147 | MakeConstantUniformReplacement(opt::IRContext* ir_context, |
no test coverage detected