Coverage Report

Created: 2026-08-14 07:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/solidity/libyul/optimiser/EquivalentFunctionDetector.cpp
Line
Count
Source
1
/*
2
  This file is part of solidity.
3
4
  solidity is free software: you can redistribute it and/or modify
5
  it under the terms of the GNU General Public License as published by
6
  the Free Software Foundation, either version 3 of the License, or
7
  (at your option) any later version.
8
9
  solidity is distributed in the hope that it will be useful,
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
  GNU General Public License for more details.
13
14
  You should have received a copy of the GNU General Public License
15
  along with solidity.  If not, see <http://www.gnu.org/licenses/>.
16
*/
17
// SPDX-License-Identifier: GPL-3.0
18
/**
19
 * Optimiser component that combines syntactically equivalent functions.
20
 */
21
22
#include <libyul/optimiser/EquivalentFunctionDetector.h>
23
#include <libyul/optimiser/SyntacticalEquality.h>
24
25
#include <libyul/AST.h>
26
#include <libyul/optimiser/Metrics.h>
27
28
using namespace solidity;
29
using namespace solidity::yul;
30
31
void EquivalentFunctionDetector::operator()(FunctionDefinition const& _fun)
32
850k
{
33
850k
  uint64_t bodyHash = m_blockHashes[&_fun.body];
34
850k
  auto& candidates = m_candidates[bodyHash];
35
850k
  for (auto const& candidate: candidates)
36
164k
    if (SyntacticallyEqual{}.statementEqual(_fun, *candidate))
37
136k
    {
38
136k
      m_duplicates[_fun.name] = candidate;
39
136k
      return;
40
136k
    }
41
713k
  candidates.push_back(&_fun);
42
713k
}