Skip to content

Commit

Permalink
[llvm-exegesis][NFC] More tests for ExegesisTarget::fillMemoryOperand…
Browse files Browse the repository at this point in the history
…s().

Reviewers: gchatelet

Subscribers: tschuett, llvm-commits

Differential Revision: https://reviews.llvm.org/D54304

llvm-svn: 347209
  • Loading branch information
legrosbuffle committed Nov 19, 2018
1 parent fef3036 commit bbab546
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
13 changes: 7 additions & 6 deletions llvm/tools/llvm-exegesis/lib/LlvmState.cpp
Expand Up @@ -22,15 +22,16 @@
namespace llvm {
namespace exegesis {

LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName) {
LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName,
const std::string &Features) {
std::string Error;
const llvm::Target *const TheTarget =
llvm::TargetRegistry::lookupTarget(Triple, Error);
assert(TheTarget && "unknown target for host");
const llvm::TargetOptions Options;
TargetMachine.reset(static_cast<llvm::LLVMTargetMachine *>(
TheTarget->createTargetMachine(Triple, CpuName, /*Features*/ "", Options,
llvm::Reloc::Model::Static)));
TargetMachine.reset(
static_cast<llvm::LLVMTargetMachine *>(TheTarget->createTargetMachine(
Triple, CpuName, Features, Options, llvm::Reloc::Model::Static)));
TheExegesisTarget = ExegesisTarget::lookup(TargetMachine->getTargetTriple());
if (!TheExegesisTarget) {
llvm::errs() << "no exegesis target for " << Triple << ", using default\n";
Expand All @@ -45,8 +46,8 @@ LLVMState::LLVMState(const std::string &Triple, const std::string &CpuName) {

LLVMState::LLVMState(const std::string &CpuName)
: LLVMState(llvm::sys::getProcessTriple(),
CpuName.empty() ? llvm::sys::getHostCPUName().str() : CpuName) {
}
CpuName.empty() ? llvm::sys::getHostCPUName().str() : CpuName,
"") {}

std::unique_ptr<llvm::LLVMTargetMachine>
LLVMState::createTargetMachine() const {
Expand Down
3 changes: 2 additions & 1 deletion llvm/tools/llvm-exegesis/lib/LlvmState.h
Expand Up @@ -40,7 +40,8 @@ class LLVMState {
LLVMState(const std::string &CpuName);

LLVMState(const std::string &Triple,
const std::string &CpuName); // For tests.
const std::string &CpuName,
const std::string &Features = ""); // For tests.

const llvm::TargetMachine &getTargetMachine() const { return *TargetMachine; }
std::unique_ptr<llvm::LLVMTargetMachine> createTargetMachine() const;
Expand Down
48 changes: 32 additions & 16 deletions llvm/unittests/tools/llvm-exegesis/X86/TargetTest.cpp
Expand Up @@ -104,14 +104,7 @@ constexpr const char kTriple[] = "x86_64-unknown-linux";

class X86TargetTest : public ::testing::Test {
protected:
X86TargetTest(const char *Features)
: ExegesisTarget_(ExegesisTarget::lookup(llvm::Triple(kTriple))) {
EXPECT_THAT(ExegesisTarget_, NotNull());
std::string error;
Target_ = llvm::TargetRegistry::lookupTarget(kTriple, error);
EXPECT_THAT(Target_, NotNull());
STI_.reset(Target_->createMCSubtargetInfo(kTriple, "core2", Features));
}
X86TargetTest(const char *Features) : State(kTriple, "core2", Features) {}

static void SetUpTestCase() {
LLVMInitializeX86TargetInfo();
Expand All @@ -121,12 +114,11 @@ class X86TargetTest : public ::testing::Test {
}

std::vector<MCInst> setRegTo(unsigned Reg, const APInt &Value) {
return ExegesisTarget_->setRegTo(*STI_, Reg, Value);
return State.getExegesisTarget().setRegTo(State.getSubtargetInfo(), Reg,
Value);
}

const llvm::Target *Target_;
const ExegesisTarget *const ExegesisTarget_;
std::unique_ptr<llvm::MCSubtargetInfo> STI_;
LLVMState State;
};

class Core2TargetTest : public X86TargetTest {
Expand Down Expand Up @@ -360,8 +352,7 @@ TEST_F(Core2TargetTest, SetRegToFP1_32Bits) {
IsMovValueToStack(llvm::X86::MOV32mi, 0x11112222UL, 0),
IsMovValueToStack(llvm::X86::MOV32mi, 0x00000000UL, 4),
IsMovValueToStack(llvm::X86::MOV16mi, 0x0000UL, 8),
OpcodeIs(llvm::X86::LD_Fp80m),
IsStackDeallocate(10)));
OpcodeIs(llvm::X86::LD_Fp80m), IsStackDeallocate(10)));
}

TEST_F(Core2TargetTest, SetRegToFP1_4Bits) {
Expand All @@ -371,8 +362,33 @@ TEST_F(Core2TargetTest, SetRegToFP1_4Bits) {
IsMovValueToStack(llvm::X86::MOV32mi, 0x00000001UL, 0),
IsMovValueToStack(llvm::X86::MOV32mi, 0x00000000UL, 4),
IsMovValueToStack(llvm::X86::MOV16mi, 0x0000UL, 8),
OpcodeIs(llvm::X86::LD_Fp80m),
IsStackDeallocate(10)));
OpcodeIs(llvm::X86::LD_Fp80m), IsStackDeallocate(10)));
}

TEST_F(Core2Avx512TargetTest, FillMemoryOperands_ADD64rm) {
Instruction I(State.getInstrInfo(), State.getRATC(), X86::ADD64rm);
InstructionTemplate IT(I);
constexpr const int kOffset = 42;
State.getExegesisTarget().fillMemoryOperands(IT, X86::RDI, kOffset);
// Memory is operands 2-6.
EXPECT_THAT(IT.getValueFor(I.Operands[2]), IsReg(X86::RDI));
EXPECT_THAT(IT.getValueFor(I.Operands[3]), IsImm(1));
EXPECT_THAT(IT.getValueFor(I.Operands[4]), IsReg(0));
EXPECT_THAT(IT.getValueFor(I.Operands[5]), IsImm(kOffset));
EXPECT_THAT(IT.getValueFor(I.Operands[6]), IsReg(0));
}

TEST_F(Core2Avx512TargetTest, FillMemoryOperands_VGATHERDPSZ128rm) {
Instruction I(State.getInstrInfo(), State.getRATC(), X86::VGATHERDPSZ128rm);
InstructionTemplate IT(I);
constexpr const int kOffset = 42;
State.getExegesisTarget().fillMemoryOperands(IT, X86::RDI, kOffset);
// Memory is operands 4-8.
EXPECT_THAT(IT.getValueFor(I.Operands[4]), IsReg(X86::RDI));
EXPECT_THAT(IT.getValueFor(I.Operands[5]), IsImm(1));
EXPECT_THAT(IT.getValueFor(I.Operands[6]), IsReg(0));
EXPECT_THAT(IT.getValueFor(I.Operands[7]), IsImm(kOffset));
EXPECT_THAT(IT.getValueFor(I.Operands[8]), IsReg(0));
}

} // namespace
Expand Down

0 comments on commit bbab546

Please sign in to comment.