diff --git a/llvm/test/tools/llvm-exegesis/X86/mcpu_not_set_during_cross_compilation.s b/llvm/test/tools/llvm-exegesis/X86/mcpu_not_set_during_cross_compilation.s new file mode 100644 index 0000000000000..f2a4e51552eb1 --- /dev/null +++ b/llvm/test/tools/llvm-exegesis/X86/mcpu_not_set_during_cross_compilation.s @@ -0,0 +1,3 @@ +# RUN: not llvm-exegesis -mtriple=riscv64-unknown-linux-gnu -mode=latency --benchmark-phase=assemble-measured-code -opcode-name=ADD 2>&1 | FileCheck %s + +# CHECK: llvm-exegesis error: A CPU must be explicitly specified when cross compiling. To see all possible options for riscv64-unknown-linux-gnu triple use -mcpu=help diff --git a/llvm/tools/llvm-exegesis/lib/LlvmState.cpp b/llvm/tools/llvm-exegesis/lib/LlvmState.cpp index 9502cae993f67..88c0d67694afb 100644 --- a/llvm/tools/llvm-exegesis/lib/LlvmState.cpp +++ b/llvm/tools/llvm-exegesis/lib/LlvmState.cpp @@ -42,8 +42,17 @@ Expected LLVMState::Create(std::string TripleName, // Update Triple with the updated triple from the target lookup. TripleName = TheTriple.str(); - if (CpuName == "native") + if (CpuName == "native") { + // case for cross generating, when native arch and target mismatch + if ((Triple(sys::getProcessTriple()).getArch() != + Triple(TripleName).getArch())) + return make_error( + "A CPU must be explicitly specified when cross compiling. To see all " + "possible options for " + + TripleName + " triple use -mcpu=help", + inconvertibleErrorCode()); CpuName = std::string(sys::getHostCPUName()); + } std::unique_ptr STI( TheTarget->createMCSubtargetInfo(TripleName, CpuName, ""));