mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
5009074e9e
* Introduce `ShrinkInstructionOperandsPass`: a transformation shrinking operands and the results of instructions if they are zero/sign-extended immediately before and after the instruction. * Introduce `ConstantRangeSet`: similar to `ConstantRange` but allows disjoint ranges. * Introduce `MaterializedValue`: a class that can represent a constant value or a symbol plus offset pair. * Introduce `DropHelperCallsPass`: a transformation removing calls to helpers and replacing them with a function call reading the CSVs that the helper reads and writing the CSVs that the helper writes (according to CSAA). * Introduce `DropRangeMetadataPass`: a transformation dropping the `range` metadata, which, in certain situations, lowers the quality of the results provided by `LazyValueInfo`. * Introduce `AdvancedValueInfo`: an analysis exploiting results of `LazyValueInfo` but collecting them as `ConstantRangeSet` with a monotone framework. It produces `MaterializedValue`. * Anticipate linking of helpers: `AVI` requires `CSAA`, which requires helper functions to be linked in. * Drop `--no-link`. * Force x86-64 `DataLayout`. * Reorganize harvesting to either collect simple literals or go with (incremental) `AVI`. * Drop `SET`, `OSRA`, the reaching definition analysis, the `SimplifyComparisonsPass` and all the sumjump-related code: e now clone `root`, optimize it and analyze it with `AVI`. * Temporarily drop the `NoReturnAnalysis`. * Link `libLLVMInstCombine`, `libLLVMCodeGen` and `libLLVMPasses`. * Introduce tests for `AdvancedValueInfo`, `ShrinkInstructionOperandsPass` and `ConstantRangeSet`. * Fix test results. * Add `llvm.bswap.i64` and `@pc` to the LLVM template module for unit tests.
58 lines
1.6 KiB
C++
58 lines
1.6 KiB
C++
/// \file ConstantrangeSet.cpp
|
|
/// \brief Tests for ConstantrangeSet
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
// Boost includes
|
|
#define BOOST_TEST_MODULE ConstantrangeSet
|
|
bool init_unit_test();
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
// Local libraries includes
|
|
#include "revng/ADT/ConstantRangeSet.h"
|
|
|
|
BOOST_AUTO_TEST_CASE(TestEnumerate) {
|
|
using CRS = ConstantRangeSet;
|
|
|
|
auto Range = [](uint32_t Start, uint32_t End) {
|
|
return CRS({ { 32, Start }, { 32, End } });
|
|
};
|
|
|
|
std::pair<CRS, std::vector<uint64_t>> Ranges[] = {
|
|
{ CRS(), {} },
|
|
{ CRS(4, true), { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } },
|
|
{ CRS(4, false), {} },
|
|
{ Range(10, 20), { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 } },
|
|
{ Range(10, 20).unionWith(Range(30, 40)),
|
|
{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
|
|
30, 31, 32, 33, 34, 35, 36, 37, 38, 39 } },
|
|
{ CRS({ { 8, 250 }, { 8, 5 } }),
|
|
{ 0, 1, 2, 3, 4, 250, 251, 252, 253, 254, 255 } },
|
|
{ Range(10, 20).unionWith(Range(30, 40)).unionWith(Range(15, 35)),
|
|
{ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
|
|
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39 } }
|
|
};
|
|
|
|
for (auto &P : Ranges) {
|
|
const ConstantRangeSet &Range = P.first;
|
|
const std::vector<uint64_t> &Expected = P.second;
|
|
|
|
Range.dump();
|
|
dbg << ": ";
|
|
|
|
unsigned I = 0;
|
|
auto It = Range.begin();
|
|
auto End = Range.end();
|
|
while (It != End) {
|
|
uint64_t Value = (*It).getLimitedValue();
|
|
revng_check(Value == Expected[I]);
|
|
dbg << " " << Value;
|
|
++It;
|
|
I++;
|
|
}
|
|
dbg << "\n";
|
|
}
|
|
}
|