[PATCH] D33662: [CMake] Introduce LLVM_TARGET_TRIPLE_ENV as an option to override LLVM_DEFAULT_TARGET_TRIPLE at runtime.

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 16:01:22 PDT 2017


Ping.

On Tue, May 30, 2017 at 9:57 AM NAKAMURA Takumi via Phabricator <
reviews at reviews.llvm.org> wrote:

> chapuni created this revision.
> Herald added a subscriber: mgorny.
>
> No behavior is changed if LLVM_TARGET_TRIPLE_ENV is blank or undefined.
>
> If LLVM_TARGET_TRIPLE_ENV is "TEST_TARGET_TRIPLE" and $TEST_TARGET_TRIPLE
> is not blank,
> llvm::sys::getDefaultTargetTriple() returns $TEST_TARGET_TRIPLE.
> Lit resets config.target_triple and
> config.environment[LLVM_TARGET_TRIPLE_ENV] to change the default target.
>
> Without changing LLVM_DEFAULT_TARGET_TRIPLE nor rebuilding, lit can be run;
>
>   TEST_TARGET_TRIPLE=i686-pc-win32 bin/llvm-lit -sv path/to/test/
>   TEST_TARGET_TRIPLE=i686-pc-win32 ninja check-clang-tools
>
> Why I make the name of an environment variable configurable? Because...
>
> - Let this functionality configurable.
> - I'd not like to hear "Why $CLANG_TARGET is unavailable in spite of
> $LLVM_TARGET there"
>
> In the future, I am planning to implement running triple matrix in Lit.
> For example, running each test for each triple
> {i686|x86_64}-{mingw32|win32}.
> Then, some commands, like FileCheck and commands with an explicit triple,
> aren't required to run iteratively.
>
>
> Repository:
>   rL LLVM
>
> https://reviews.llvm.org/D33662
>
> Files:
>   llvm/trunk/CMakeLists.txt
>   llvm/trunk/cmake/modules/AddLLVM.cmake
>   llvm/trunk/include/llvm/Config/config.h.cmake
>   llvm/trunk/lib/Support/Unix/Host.inc
>   llvm/trunk/lib/Support/Windows/Host.inc
>
>
> Index: llvm/trunk/lib/Support/Windows/Host.inc
> ===================================================================
> --- llvm/trunk/lib/Support/Windows/Host.inc
> +++ llvm/trunk/lib/Support/Windows/Host.inc
> @@ -18,5 +18,13 @@
>  using namespace llvm;
>
>  std::string sys::getDefaultTargetTriple() {
> -  return Triple::normalize(LLVM_DEFAULT_TARGET_TRIPLE);
> +  const char *Triple = LLVM_DEFAULT_TARGET_TRIPLE;
> +
> +  // Override the default target with an environment variable named by
> LLVM_TARGET_TRIPLE_ENV.
> +#if defined(LLVM_TARGET_TRIPLE_ENV)
> +  if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
> +    Triple = EnvTriple;
> +#endif
> +
> +  return Triple::normalize(Triple);
>  }
> Index: llvm/trunk/lib/Support/Unix/Host.inc
> ===================================================================
> --- llvm/trunk/lib/Support/Unix/Host.inc
> +++ llvm/trunk/lib/Support/Unix/Host.inc
> @@ -45,5 +45,11 @@
>      TargetTripleString += getOSVersion();
>    }
>
> +  // Override the default target with an environment variable named by
> LLVM_TARGET_TRIPLE_ENV.
> +#if defined(LLVM_TARGET_TRIPLE_ENV)
> +  if (const char *EnvTriple = std::getenv(LLVM_TARGET_TRIPLE_ENV))
> +    TargetTripleString = EnvTriple;
> +#endif
> +
>    return Triple::normalize(TargetTripleString);
>  }
> Index: llvm/trunk/include/llvm/Config/config.h.cmake
> ===================================================================
> --- llvm/trunk/include/llvm/Config/config.h.cmake
> +++ llvm/trunk/include/llvm/Config/config.h.cmake
> @@ -377,6 +377,9 @@
>  /* Define if this is Win32ish platform */
>  #cmakedefine LLVM_ON_WIN32 ${LLVM_ON_WIN32}
>
> +/* Define if overriding target triple is enabled */
> +#cmakedefine LLVM_TARGET_TRIPLE_ENV "${LLVM_TARGET_TRIPLE_ENV}"
> +
>  /* Define if we have the Intel JIT API runtime support library */
>  #cmakedefine01 LLVM_USE_INTEL_JITEVENTS
>
> Index: llvm/trunk/cmake/modules/AddLLVM.cmake
> ===================================================================
> --- llvm/trunk/cmake/modules/AddLLVM.cmake
> +++ llvm/trunk/cmake/modules/AddLLVM.cmake
> @@ -1133,6 +1133,19 @@
>
>    set(LIT_SITE_CFG_IN_HEADER  "## Autogenerated from ${input}\n## Do not
> edit!")
>
> +  # Override config_target_triple (and the env)
> +  if(LLVM_TARGET_TRIPLE_ENV)
> +    # This is expanded into the heading.
> +    string(CONCAT LIT_SITE_CFG_IN_HEADER "${LIT_SITE_CFG_IN_HEADER}\n\n"
> +      "import os\n"
> +      "target_env = \"${LLVM_TARGET_TRIPLE_ENV}\"\n"
> +      "config.target_triple = config.environment[target_env] =
> os.environ.get(target_env, \"${TARGET_TRIPLE}\")\n"
> +      )
> +
> +    # This is expanded to; config.target_triple =
> ""+config.target_triple+""
> +    set(TARGET_TRIPLE "\"+config.target_triple+\"")
> +  endif()
> +
>    configure_file(${input} ${output} @ONLY)
>  endfunction()
>
> Index: llvm/trunk/CMakeLists.txt
> ===================================================================
> --- llvm/trunk/CMakeLists.txt
> +++ llvm/trunk/CMakeLists.txt
> @@ -569,6 +569,10 @@
>    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
>  endif()
>
> +# Override the default target with an environment variable named by
> LLVM_TARGET_TRIPLE_ENV.
> +set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable
> to override default target. Disabled by blank.")
> +mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
> +
>  # All options referred to from HandleLLVMOptions have to be specified
>  # BEFORE this include, otherwise options will not be correctly set on
>  # first cmake run
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170615/ae0258f2/attachment.html>


More information about the llvm-commits mailing list