39 lines · cpp
1//===- RegisterTest.cpp -----------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "llvm/CodeGen/Register.h"10#include "gtest/gtest.h"11 12using namespace llvm;13 14namespace {15TEST(RegisterTest, Idx2StackSlot) {16 EXPECT_EQ(Register::index2StackSlot(0), Register::StackSlotZero);17 EXPECT_EQ(Register::index2StackSlot(1), Register::StackSlotZero | 1);18 EXPECT_EQ(Register::index2StackSlot(-1),19 Register::StackSlotZero | Register::StackSlotMask);20 int MaxPowOf2 = 1 << (Register::MaxFrameIndexBitwidth - 1);21 // Check the highest possible value of frame index22 EXPECT_EQ(Register::index2StackSlot(MaxPowOf2 - 1),23 Register::StackSlotZero | (MaxPowOf2 - 1));24 // Check the lowest possible value of frame index25 EXPECT_EQ(Register::index2StackSlot(-MaxPowOf2),26 Register::StackSlotZero | (-MaxPowOf2 & Register::StackSlotMask));27}28 29TEST(RegisterTest, StackSlotIndex) {30 int MaxPowOf2 = 1 << (Register::MaxFrameIndexBitwidth - 1);31 std::vector<int> FIs = {0, 1 - 1, MaxPowOf2 - 1, -MaxPowOf2};32 33 for (int FI : FIs) {34 Register Reg = Register::index2StackSlot(FI);35 EXPECT_EQ(Reg.stackSlotIndex(), FI);36 }37}38} // end namespace39