aboutsummaryrefslogtreecommitdiff
path: root/backend/unittests/CodeGen/LiveRegUnitsTest.cpp
blob: 7f224ac677ef4dc670a6c2b96be64406dc10f6ee (plain)
1
2
3
4
5
6
7
8
9
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
// SPDX-License-Identifier: GPL-3.0-or-later

#include "rcc/CodeGen/LiveRegUnits.h"

#include "LiveTestSupport.h"

namespace {

using namespace rcc::test::liveness;

void testLiveRegUnits(TestContext &Context) {
  const rcc::RegisterUnitID Unit = rcc::RegisterUnitID::fromValue(9);
  rcc::LiveRegUnits Present;
  rcc::LiveRegUnits Removed;
  Present.add(Unit, rcc::LaneMask::fromRaw(0x3));
  Removed.add(Unit, rcc::LaneMask::fromRaw(0x2));
  Present.subtract(Removed);
  Context.expect(Present.lanes(Unit) == rcc::LaneMask::fromRaw(0x1) &&
                     Present.contains(Unit, rcc::LaneMask::fromRaw(0x1)) &&
                     !Present.intersects(Unit, rcc::LaneMask::fromRaw(0x2)),
                 "LiveRegUnits must preserve partial union and subtraction");
  Present.unite(Removed);
  Context.expect(Present.contains(Unit, rcc::LaneMask::fromRaw(0x3)),
                 "LiveRegUnits union must restore all selected lanes");
}

} // namespace

int main() {
  TestContext Context;
  auto Target = createTarget();
  Context.expect(Target.has_value(), "liveness TestTarget must be created");
  if (!Target)
    return Context.result();
  testLiveRegUnits(Context);
  return Context.result();
}