<commit_before>#include "RegisterAliasing.h"

#include <cassert>
#include <memory>

#include "X86InstrInfo.h"
#include "llvm/Support/Host.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace exegesis {
namespace {

class RegisterAliasingTest : public ::testing::Test {
protected:
  RegisterAliasingTest() {
    const std::string TT = llvm::sys::getProcessTriple();
    std::string error;
    const llvm::Target *const TheTarget =
        llvm::TargetRegistry::lookupTarget(TT, error);
    assert(TheTarget);
    MCRegInfo.reset(TheTarget->createMCRegInfo(TT));
  }

  static void SetUpTestCase() { llvm::InitializeNativeTarget(); }

  const llvm::MCRegisterInfo &getMCRegInfo() { return *MCRegInfo; }

private:
  std::unique_ptr<const llvm::MCRegisterInfo> MCRegInfo;
};

TEST_F(RegisterAliasingTest, TrackSimpleRegister) {
  const auto &RegInfo = getMCRegInfo();
  const RegisterAliasingTracker tracker(RegInfo, llvm::X86::EAX);
  const std::set<llvm::MCPhysReg> ActualAliasedRegisters(
      tracker.aliasedBits().set_bits().begin(),
      tracker.aliasedBits().set_bits().end());
  const std::set<llvm::MCPhysReg> ExpectedAliasedRegisters = {
      llvm::X86::AL,  llvm::X86::AH,  llvm::X86::AX,
      llvm::X86::EAX, llvm::X86::HAX, llvm::X86::RAX};<commit_msg>Fix r332592 : X86 tests should use the X86 target, not the native targets.<commit_after>#include "RegisterAliasing.h"

#include <cassert>
#include <memory>

#include "X86InstrInfo.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

namespace exegesis {
namespace {

class RegisterAliasingTest : public ::testing::Test {
protected:
  RegisterAliasingTest() {
    const std::string TT = "x86_64-unknown-linux";
    std::string error;
    const llvm::Target *const TheTarget =
        llvm::TargetRegistry::lookupTarget(TT, error);
    if (!TheTarget) {
      llvm::errs() << error << "\n";
      return;
    }
    MCRegInfo.reset(TheTarget->createMCRegInfo(TT));
  }

  static void SetUpTestCase() {
    LLVMInitializeX86TargetInfo();
    LLVMInitializeX86Target();
    LLVMInitializeX86TargetMC();
  }

  const llvm::MCRegisterInfo &getMCRegInfo() {
    assert(MCRegInfo);
    return *MCRegInfo;
  }

private:
  std::unique_ptr<const llvm::MCRegisterInfo> MCRegInfo;
};

TEST_F(RegisterAliasingTest, TrackSimpleRegister) {
  const auto &RegInfo = getMCRegInfo();
  const RegisterAliasingTracker tracker(RegInfo, llvm::X86::EAX);
  const std::set<llvm::MCPhysReg> ActualAliasedRegisters(
      tracker.aliasedBits().set_bits().begin(),
      tracker.aliasedBits().set_bits().end());
  const std::set<llvm::MCPhysReg> ExpectedAliasedRegisters = {
      llvm::X86::AL,  llvm::X86::AH,  llvm::X86::AX,
      llvm::X86::EAX, llvm::X86::HAX, llvm::X86::RAX};
{'fraction_non_alphanumeric': 0.14849428868120457, 'fraction_numerical': 0.017999307718933887, 'mean_word_length': 5.296296296296297, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7657807', 'n_tokens_mistral': 1005, 'n_tokens_neox': 1007, 'n_words': 173}