Author: mgorny Date: Fri Apr 26 06:21:46 2019 New Revision: 359303 URL: http://llvm.org/viewvc/llvm-project?rev=359303&view=rev Log: [lldb] [lit] Add feature flags for native CPU features
Add a new lit-cpuid tool that detects CPU features used by some of the tests, and use it to populate available_features in lit. For now, this means that the test for MM/XMM register read will be run only when the host CPU support SSE instruction set. However, this is going to make it possible to introduce additional tests relying on AVX. Differential Revision: https://reviews.llvm.org/D61073 Added: lldb/trunk/utils/lit-cpuid/ lldb/trunk/utils/lit-cpuid/CMakeLists.txt lldb/trunk/utils/lit-cpuid/lit-cpuid.cpp Modified: lldb/trunk/CMakeLists.txt lldb/trunk/lit/CMakeLists.txt lldb/trunk/lit/Register/x86-mm-xmm-read.test lldb/trunk/lit/lit.cfg.py Modified: lldb/trunk/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/CMakeLists.txt?rev=359303&r1=359302&r2=359303&view=diff ============================================================================== --- lldb/trunk/CMakeLists.txt (original) +++ lldb/trunk/CMakeLists.txt Fri Apr 26 06:21:46 2019 @@ -138,6 +138,7 @@ if(LLDB_INCLUDE_TESTS) add_subdirectory(test) add_subdirectory(unittests) add_subdirectory(lit) + add_subdirectory(utils/lit-cpuid) add_subdirectory(utils/lldb-dotest) endif() Modified: lldb/trunk/lit/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/CMakeLists.txt?rev=359303&r1=359302&r2=359303&view=diff ============================================================================== --- lldb/trunk/lit/CMakeLists.txt (original) +++ lldb/trunk/lit/CMakeLists.txt Fri Apr 26 06:21:46 2019 @@ -20,6 +20,7 @@ string(REPLACE ${CMAKE_CFG_INTDIR} ${LLV list(APPEND LLDB_TEST_DEPS LLDBUnitTests dsymutil + lit-cpuid llc lldb lldb-test Modified: lldb/trunk/lit/Register/x86-mm-xmm-read.test URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/Register/x86-mm-xmm-read.test?rev=359303&r1=359302&r2=359303&view=diff ============================================================================== --- lldb/trunk/lit/Register/x86-mm-xmm-read.test (original) +++ lldb/trunk/lit/Register/x86-mm-xmm-read.test Fri Apr 26 06:21:46 2019 @@ -1,6 +1,6 @@ # XFAIL: system-darwin # XFAIL: system-windows -# REQUIRES: native && (target-x86 || target-x86_64) +# REQUIRES: native && (target-x86 || target-x86_64) && native-cpu-sse # RUN: %clangxx %p/Inputs/x86-mm-xmm-read.cpp -o %t # RUN: %lldb -b -s %s %t | FileCheck %s process launch Modified: lldb/trunk/lit/lit.cfg.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/lit.cfg.py?rev=359303&r1=359302&r2=359303&view=diff ============================================================================== --- lldb/trunk/lit/lit.cfg.py (original) +++ lldb/trunk/lit/lit.cfg.py Fri Apr 26 06:21:46 2019 @@ -73,3 +73,17 @@ for i in ['module-cache-clang', 'module- if os.path.isdir(cachedir): print("Deleting module cache at %s."%cachedir) shutil.rmtree(cachedir) + +# If running tests natively, check for CPU features needed for some tests. + +if 'native' in config.available_features: + cpuid_exe = lit.util.which('lit-cpuid', config.lldb_tools_dir) + if cpuid_exe is None: + lit_config.warning("lit-cpuid not found, tests requiring CPU extensions will be skipped") + else: + out, err, exitcode = lit.util.executeCommand([cpuid_exe]) + if exitcode == 0: + for x in out.split(): + config.available_features.add('native-cpu-%s' % x) + else: + lit_config.warning("lit-cpuid failed: %s" % err) Added: lldb/trunk/utils/lit-cpuid/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lit-cpuid/CMakeLists.txt?rev=359303&view=auto ============================================================================== --- lldb/trunk/utils/lit-cpuid/CMakeLists.txt (added) +++ lldb/trunk/utils/lit-cpuid/CMakeLists.txt Fri Apr 26 06:21:46 2019 @@ -0,0 +1,5 @@ +add_llvm_utility(lit-cpuid + lit-cpuid.cpp + ) + +target_link_libraries(lit-cpuid PRIVATE LLVMSupport) Added: lldb/trunk/utils/lit-cpuid/lit-cpuid.cpp URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/utils/lit-cpuid/lit-cpuid.cpp?rev=359303&view=auto ============================================================================== --- lldb/trunk/utils/lit-cpuid/lit-cpuid.cpp (added) +++ lldb/trunk/utils/lit-cpuid/lit-cpuid.cpp Fri Apr 26 06:21:46 2019 @@ -0,0 +1,33 @@ +//===- lit-cpuid.cpp - Get CPU feature flags for lit exported features ----===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// lit-cpuid obtains the feature list for the currently running CPU, and outputs +// those flags that are interesting for LLDB lit tests. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringMap.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +int main(int argc, char **argv) { +#if defined(__i386__) || defined(_M_IX86) || \ + defined(__x86_64__) || defined(_M_X64) + StringMap<bool> features; + + if (!sys::getHostCPUFeatures(features)) + return 1; + + if (features["sse"]) + outs() << "sse\n"; +#endif + + return 0; +} _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits