Commit 0ea93300 authored by Akash Kothari's avatar Akash Kothari
Browse files

Add hpvm-config

parent 957c5a34
include_directories(./include/)
add_subdirectory(lib)
add_subdirectory(projects)
add_subdirectory(tools)
add_subdirectory(test)
......
......@@ -104,6 +104,7 @@ if [ ! -d $HPVM_DIR ]; then
ln -s $CURRENT_DIR/lib $HPVM_DIR/
ln -s $CURRENT_DIR/projects $HPVM_DIR/
ln -s $CURRENT_DIR/test $HPVM_DIR/
ln -s $CURRENT_DIR/tools $HPVM_DIR/
else
echo $CURRENT_DIR/$LLVM_SRC/tools/hpvm exists.
fi
......
add_llvm_tool_subdirectory(hpvm-config)
//===-- BuildVariables.inc.in - llvm-config build variables -*- C++ -*-----===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file is configured by the build system to define the variables
// llvm-config wants to report to the user, but which can only be determined at
// build time.
//
// The variant of this file not ending with .in has been autogenerated by the
// LLVM build. Do not edit!
//
//===----------------------------------------------------------------------===//
#define LLVM_SRC_ROOT "@LLVM_SRC_ROOT@"
#define LLVM_OBJ_ROOT "@LLVM_OBJ_ROOT@"
#define LLVM_CPPFLAGS "@LLVM_CPPFLAGS@"
#define LLVM_CFLAGS "@LLVM_CFLAGS@"
#define LLVM_LDFLAGS "@LLVM_LDFLAGS@"
#define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@"
#define LLVM_BUILDMODE "@LLVM_BUILDMODE@"
#define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@"
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
#define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@"
#define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@"
#define LLVM_HAS_RTTI @LLVM_HAS_RTTI@
#define LLVM_ENABLE_DYLIB @LLVM_BUILD_LLVM_DYLIB@
#define LLVM_LINK_DYLIB @LLVM_LINK_LLVM_DYLIB@
#define LLVM_ENABLE_SHARED @BUILD_SHARED_LIBS@
#define LLVM_DYLIB_COMPONENTS "@LLVM_DYLIB_COMPONENTS@"
#define LLVM_DYLIB_VERSION "@LLVM_DYLIB_VERSION@"
#define LLVM_HAS_GLOBAL_ISEL @LLVM_HAS_GLOBAL_ISEL@
#define LLVM_TOOLS_INSTALL_DIR "@LLVM_TOOLS_INSTALL_DIR@"
set(LLVM_LINK_COMPONENTS support)
set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
# Add the hpvm-config tool.
add_llvm_tool(hpvm-config
hpvm-config.cpp
)
target_include_directories(
hpvm-config PRIVATE "${LLVM_BINARY_DIR}/tools/llvm-config"
)
# Compute the substitution values for various items.
get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)
foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
if(MSVC)
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
else()
if (l MATCHES "^-")
# If it's an option, pass it without changes.
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
else()
# Otherwise assume it's a library name we need to link with.
set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
endif()
endif()
endforeach()
string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
# Fetch target specific compile options, e.g. RTTI option
get_property(COMPILE_FLAGS TARGET hpvm-config PROPERTY COMPILE_FLAGS)
# The language standard potentially affects the ABI/API of LLVM, so we want
# to make sure it is reported by hpvm-config.
# NOTE: We don't want to start extracting any random C/CXX flags that the
# user may add that could affect the ABI. We only want to extract flags
# that have been added by the LLVM build system.
string(REGEX MATCH "-std=[^ ]\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS})
string(REGEX MATCH "-stdlib=[^ ]\+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
string(REGEX MATCH "-std=[^ ]\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
# Use configure_file to create BuildVariables.inc.
set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
set(LLVM_CXXFLAGS "${LLVM_CXX_STD_FLAG} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
set(LLVM_BUILD_SYSTEM cmake)
set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
set(LLVM_HAS_GLOBAL_ISEL "ON")
# Use the C++ link flags, since they should be a superset of C link flags.
set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
llvm_canonicalize_cmake_booleans(
LLVM_BUILD_LLVM_DYLIB
LLVM_LINK_LLVM_DYLIB
LLVM_HAS_RTTI
LLVM_HAS_GLOBAL_ISEL
BUILD_SHARED_LIBS)
configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
# Set build-time environment(s).
add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
if(LLVM_ENABLE_MODULES)
target_compile_options(hpvm-config PUBLIC
"-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
)
endif()
# Add the dependency on the generation step.
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/hpvm-config.cpp ${BUILDVARIABLES_OBJPATH})
if(CMAKE_CROSSCOMPILING AND NOT HPVM_CONFIG_PATH)
build_native_tool(hpvm-config HPVM_CONFIG_PATH)
set(HPVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
add_custom_target(NativeHPVMConfig DEPENDS ${HPVM_CONFIG_PATH})
add_dependencies(hpvm-config NativeHPVMConfig)
endif()
//===- llvm-build generated file --------------------------------*- C++ -*-===//
//
// Component Library Dependency Table
//
// Automatically generated file, do not edit!
//
//===----------------------------------------------------------------------===//
struct AvailableComponent {
/// The name of the component.
const char *Name;
/// The name of the library for this component (or NULL).
const char *Library;
/// Whether the component is installed.
bool IsInstalled;
/// The list of libraries required when linking this component.
const char *RequiredLibraries[24];
} AvailableComponents[73] = {
{ "aggressiveinstcombine", "LLVMAggressiveInstCombine", true, { "analysis", "core", "support", "transformutils" } },
{ "all", nullptr, true, { "all-targets", "coroutines", "coverage", "debuginfogsym", "dlltooldriver", "engine", "fuzzmutate", "gtest_main", "interpreter", "libdriver", "lineeditor", "lto", "mca", "mirparser", "nativecodegen", "objectyaml", "orcjit", "symbolize", "tablegen", "testingsupport", "textapi", "windowsmanifest", "xray" } },
{ "all-targets", nullptr, true, { "x86" } },
{ "analysis", "LLVMAnalysis", true, { "binaryformat", "core", "object", "profiledata", "support" } },
{ "asmparser", "LLVMAsmParser", true, { "binaryformat", "core", "support" } },
{ "asmprinter", "LLVMAsmPrinter", true, { "analysis", "binaryformat", "codegen", "core", "debuginfocodeview", "debuginfodwarf", "debuginfomsf", "mc", "mcparser", "remarks", "support", "target" } },
{ "binaryformat", "LLVMBinaryFormat", true, { "support" } },
{ "bitreader", "LLVMBitReader", true, { "bitstreamreader", "core", "support" } },
{ "bitstreamreader", "LLVMBitstreamReader", true, { "support" } },
{ "bitwriter", "LLVMBitWriter", true, { "analysis", "core", "mc", "object", "support" } },
{ "codegen", "LLVMCodeGen", true, { "analysis", "bitreader", "bitwriter", "core", "mc", "profiledata", "scalaropts", "support", "target", "transformutils" } },
{ "core", "LLVMCore", true, { "binaryformat", "remarks", "support" } },
{ "coroutines", "LLVMCoroutines", true, { "analysis", "core", "ipo", "scalaropts", "support", "transformutils" } },
{ "coverage", "LLVMCoverage", true, { "core", "object", "profiledata", "support" } },
{ "debuginfocodeview", "LLVMDebugInfoCodeView", true, { "support", "debuginfomsf" } },
{ "debuginfodwarf", "LLVMDebugInfoDWARF", true, { "binaryformat", "object", "mc", "support" } },
{ "debuginfogsym", "LLVMDebugInfoGSYM", true, { "support" } },
{ "debuginfomsf", "LLVMDebugInfoMSF", true, { "support" } },
{ "debuginfopdb", "LLVMDebugInfoPDB", true, { "object", "support", "debuginfocodeview", "debuginfomsf" } },
{ "demangle", "LLVMDemangle", true, { } },
{ "dlltooldriver", "LLVMDlltoolDriver", true, { "object", "option", "support" } },
{ "engine", nullptr, true, { "mcjit", "native" } },
{ "executionengine", "LLVMExecutionEngine", true, { "core", "mc", "object", "runtimedyld", "support", "target" } },
{ "fuzzmutate", "LLVMFuzzMutate", true, { "analysis", "bitreader", "bitwriter", "core", "scalaropts", "support", "target" } },
{ "globalisel", "LLVMGlobalISel", true, { "analysis", "codegen", "core", "mc", "selectiondag", "support", "target", "transformutils" } },
{ "gtest", "gtest", false, { "support" } },
{ "gtest_main", "gtest_main", false, { "gtest" } },
{ "instcombine", "LLVMInstCombine", true, { "analysis", "core", "support", "transformutils" } },
{ "instrumentation", "LLVMInstrumentation", true, { "analysis", "core", "mc", "support", "transformutils", "profiledata" } },
{ "interpreter", "LLVMInterpreter", true, { "codegen", "core", "executionengine", "support" } },
{ "ipo", "LLVMipo", true, { "aggressiveinstcombine", "analysis", "bitreader", "bitwriter", "core", "instcombine", "irreader", "linker", "object", "profiledata", "scalaropts", "support", "transformutils", "vectorize", "instrumentation" } },
{ "irreader", "LLVMIRReader", true, { "asmparser", "bitreader", "core", "support" } },
{ "jitlink", "LLVMJITLink", true, { "binaryformat", "object", "support" } },
{ "libdriver", "LLVMLibDriver", true, { "binaryformat", "bitreader", "object", "option", "support" } },
{ "lineeditor", "LLVMLineEditor", true, { "support" } },
{ "linker", "LLVMLinker", true, { "core", "support", "transformutils" } },
{ "lto", "LLVMLTO", true, { "aggressiveinstcombine", "analysis", "bitreader", "bitwriter", "codegen", "core", "ipo", "instcombine", "linker", "mc", "objcarcopts", "object", "passes", "remarks", "scalaropts", "support", "target", "transformutils" } },
{ "mc", "LLVMMC", true, { "support", "binaryformat", "debuginfocodeview" } },
{ "mca", "LLVMMCA", true, { "mc", "support" } },
{ "mcdisassembler", "LLVMMCDisassembler", true, { "mc", "support" } },
{ "mcjit", "LLVMMCJIT", true, { "core", "executionengine", "object", "runtimedyld", "support", "target" } },
{ "mcparser", "LLVMMCParser", true, { "mc", "support" } },
{ "mirparser", "LLVMMIRParser", true, { "asmparser", "binaryformat", "codegen", "core", "mc", "support", "target" } },
{ "native", nullptr, true, { "x86" } },
{ "nativecodegen", nullptr, true, { "x86codegen" } },
{ "objcarcopts", "LLVMObjCARCOpts", true, { "analysis", "core", "support", "transformutils" } },
{ "object", "LLVMObject", true, { "bitreader", "core", "mc", "binaryformat", "mcparser", "support" } },
{ "objectyaml", "LLVMObjectYAML", true, { "object", "support", "debuginfocodeview" } },
{ "option", "LLVMOption", true, { "support" } },
{ "orcjit", "LLVMOrcJIT", true, { "core", "executionengine", "jitlink", "object", "mc", "runtimedyld", "support", "target", "transformutils" } },
{ "passes", "LLVMPasses", true, { "aggressiveinstcombine", "analysis", "codegen", "core", "ipo", "instcombine", "scalaropts", "support", "target", "transformutils", "vectorize", "instrumentation" } },
{ "profiledata", "LLVMProfileData", true, { "core", "support" } },
{ "remarks", "LLVMRemarks", true, { "support" } },
{ "runtimedyld", "LLVMRuntimeDyld", true, { "mc", "object", "support" } },
{ "scalaropts", "LLVMScalarOpts", true, { "aggressiveinstcombine", "analysis", "core", "instcombine", "support", "transformutils" } },
{ "selectiondag", "LLVMSelectionDAG", true, { "analysis", "codegen", "core", "mc", "support", "target", "transformutils" } },
{ "support", "LLVMSupport", true, { "demangle" } },
{ "symbolize", "LLVMSymbolize", true, { "debuginfodwarf", "debuginfopdb", "object", "support", "demangle" } },
{ "tablegen", "LLVMTableGen", true, { "support" } },
{ "target", "LLVMTarget", true, { "analysis", "core", "mc", "support" } },
{ "testingsupport", "LLVMTestingSupport", false, { "support" } },
{ "textapi", "LLVMTextAPI", true, { "support", "binaryformat" } },
{ "transformutils", "LLVMTransformUtils", true, { "analysis", "core", "support" } },
{ "vectorize", "LLVMVectorize", true, { "analysis", "core", "support", "transformutils" } },
{ "windowsmanifest", "LLVMWindowsManifest", true, { "support" } },
{ "x86", nullptr, true, { "x86info", "x86utils", "x86desc", "x86codegen", "x86asmparser", "x86disassembler" } },
{ "x86asmparser", "LLVMX86AsmParser", true, { "mc", "mcparser", "support", "x86desc", "x86info" } },
{ "x86codegen", "LLVMX86CodeGen", true, { "analysis", "asmprinter", "codegen", "core", "mc", "selectiondag", "support", "target", "x86desc", "x86info", "x86utils", "globalisel", "profiledata" } },
{ "x86desc", "LLVMX86Desc", true, { "mc", "mcdisassembler", "object", "support", "x86info", "x86utils" } },
{ "x86disassembler", "LLVMX86Disassembler", true, { "mcdisassembler", "support", "x86info" } },
{ "x86info", "LLVMX86Info", true, { "support" } },
{ "x86utils", "LLVMX86Utils", true, { "support" } },
{ "xray", "LLVMXRay", true, { "support", "object" } },
};
//===-- llvm-config.cpp - LLVM project configuration utility --------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This tool encapsulates information about an LLVM project configuration for
// use by other project's build environments (to determine installed path,
// available features, required libraries, etc.).
//
// Note that although this tool *may* be used by some parts of LLVM's build
// itself (i.e., the Makefiles use it to compute required libraries when linking
// tools), this tool is primarily designed to support external projects.
//
//===----------------------------------------------------------------------===//
#include "llvm/Config/llvm-config.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Config/config.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include <cstdlib>
#include <set>
#include <unordered_set>
#include <vector>
using namespace llvm;
#define HPVM_PACKAGE_VERSION "0.5"
// Include the build time variables we can report to the user. This is generated
// at build time from the BuildVariables.inc.in file by the build system.
#include "BuildVariables.inc"
// Include the component table. This creates an array of struct
// AvailableComponent entries, which record the component name, library name,
// and required components for all of the available libraries.
//
// Not all components define a library, we also use "library groups" as a way to
// create entries for pseudo groups like x86 or all-targets.
#include "LibraryDependencies.inc"
// LinkMode determines what libraries and flags are returned by llvm-config.
enum LinkMode {
// LinkModeAuto will link with the default link mode for the installation,
// which is dependent on the value of LLVM_LINK_LLVM_DYLIB, and fall back
// to the alternative if the required libraries are not available.
LinkModeAuto = 0,
// LinkModeShared will link with the dynamic component libraries if they
// exist, and return an error otherwise.
LinkModeShared = 1,
// LinkModeStatic will link with the static component libraries if they
// exist, and return an error otherwise.
LinkModeStatic = 2,
};
/// Traverse a single component adding to the topological ordering in
/// \arg RequiredLibs.
///
/// \param Name - The component to traverse.
/// \param ComponentMap - A prebuilt map of component names to descriptors.
/// \param VisitedComponents [in] [out] - The set of already visited components.
/// \param RequiredLibs [out] - The ordered list of required
/// libraries.
/// \param GetComponentNames - Get the component names instead of the
/// library name.
static void VisitComponent(const std::string &Name,
const StringMap<AvailableComponent *> &ComponentMap,
std::set<AvailableComponent *> &VisitedComponents,
std::vector<std::string> &RequiredLibs,
bool IncludeNonInstalled, bool GetComponentNames,
const std::function<std::string(const StringRef &)>
*GetComponentLibraryPath,
std::vector<std::string> *Missing,
const std::string &DirSep) {
// Lookup the component.
AvailableComponent *AC = ComponentMap.lookup(Name);
if (!AC) {
errs() << "Can't find component: '" << Name << "' in the map. Available components are: ";
for (const auto &Component : ComponentMap) {
errs() << "'" << Component.first() << "' ";
}
errs() << "\n";
report_fatal_error("abort");
}
assert(AC && "Invalid component name!");
// Add to the visited table.
if (!VisitedComponents.insert(AC).second) {
// We are done if the component has already been visited.
return;
}
// Only include non-installed components if requested.
if (!AC->IsInstalled && !IncludeNonInstalled)
return;
// Otherwise, visit all the dependencies.
for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
RequiredLibs, IncludeNonInstalled, GetComponentNames,
GetComponentLibraryPath, Missing, DirSep);
}
if (GetComponentNames) {
RequiredLibs.push_back(Name);
return;
}
// Add to the required library list.
if (AC->Library) {
if (Missing && GetComponentLibraryPath) {
std::string path = (*GetComponentLibraryPath)(AC->Library);
if (DirSep == "\\") {
std::replace(path.begin(), path.end(), '/', '\\');
}
if (!sys::fs::exists(path))
Missing->push_back(path);
}
RequiredLibs.push_back(AC->Library);
}
}
/// Compute the list of required libraries for a given list of
/// components, in an order suitable for passing to a linker (that is, libraries
/// appear prior to their dependencies).
///
/// \param Components - The names of the components to find libraries for.
/// \param IncludeNonInstalled - Whether non-installed components should be
/// reported.
/// \param GetComponentNames - True if one would prefer the component names.
static std::vector<std::string> ComputeLibsForComponents(
const std::vector<StringRef> &Components, bool IncludeNonInstalled,
bool GetComponentNames, const std::function<std::string(const StringRef &)>
*GetComponentLibraryPath,
std::vector<std::string> *Missing, const std::string &DirSep) {
std::vector<std::string> RequiredLibs;
std::set<AvailableComponent *> VisitedComponents;
// Build a map of component names to information.
StringMap<AvailableComponent *> ComponentMap;
for (unsigned i = 0; i != array_lengthof(AvailableComponents); ++i) {
AvailableComponent *AC = &AvailableComponents[i];
ComponentMap[AC->Name] = AC;
}
// Visit the components.
for (unsigned i = 0, e = Components.size(); i != e; ++i) {
// Users are allowed to provide mixed case component names.
std::string ComponentLower = Components[i].lower();
// Validate that the user supplied a valid component name.
if (!ComponentMap.count(ComponentLower)) {
llvm::errs() << "llvm-config: unknown component name: " << Components[i]
<< "\n";
exit(1);
}
VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
RequiredLibs, IncludeNonInstalled, GetComponentNames,
GetComponentLibraryPath, Missing, DirSep);
}
// The list is now ordered with leafs first, we want the libraries to printed
// in the reverse order of dependency.
std::reverse(RequiredLibs.begin(), RequiredLibs.end());
return RequiredLibs;
}
/* *** */
static void usage() {
errs() << "\
usage: llvm-config <OPTION>... [<COMPONENT>...]\n\
\n\
Get various configuration information needed to compile programs which use\n\
LLVM. Typically called from 'configure' scripts. Examples:\n\
llvm-config --cxxflags\n\
llvm-config --ldflags\n\
llvm-config --libs engine bcreader scalaropts\n\
\n\
Options:\n\
--llvm-version Print LLVM version.\n\
--hpvm-version Print HPVM version.\n\
--version Print HPVM version.\n\
--prefix Print the installation prefix.\n\
--src-root Print the source root LLVM was built from.\n\
--obj-root Print the object root used to build LLVM.\n\
--bindir Directory containing LLVM executables.\n\
--includedir Directory containing LLVM headers.\n\
--libdir Directory containing LLVM libraries.\n\
--cmakedir Directory containing LLVM cmake modules.\n\
--cppflags C preprocessor flags for files that include LLVM headers.\n\
--cflags C compiler flags for files that include LLVM headers.\n\
--cxxflags C++ compiler flags for files that include LLVM headers.\n\
--ldflags Print Linker flags.\n\
--system-libs System Libraries needed to link against LLVM components.\n\
--libs Libraries needed to link against LLVM components.\n\
--libnames Bare library names for in-tree builds.\n\
--libfiles Fully qualified library filenames for makefile depends.\n\
--components List of all possible components.\n\
--targets-built List of all targets currently built.\n\
--host-target Target triple used to configure LLVM.\n\
--build-mode Print build mode of LLVM tree (e.g. Debug or Release).\n\
--assertion-mode Print assertion mode of LLVM tree (ON or OFF).\n\
--build-system Print the build system used to build LLVM (always cmake).\n\
--has-rtti Print whether or not LLVM was built with rtti (YES or NO).\n\
--has-global-isel Print whether or not LLVM was built with global-isel support (ON or OFF).\n\
--shared-mode Print how the provided components can be collectively linked (`shared` or `static`).\n\
--link-shared Link the components as shared libraries.\n\
--link-static Link the component libraries statically.\n\
--ignore-libllvm Ignore libLLVM and link component libraries instead.\n\
--genhpvm Generate textual representation for HPVM IR from LLVM IR.\n\
--dfg2llvm-cpu Generate code for CPU.\n\
--dfg2llvm-opencl Generate kernel code in OpenCL.\n\
--clearDFG Clean up HPVM dataflow graph and extraneous HPVM-specific instructions.\n\
Typical components:\n\
all All LLVM libraries (default).\n\
engine Either a native JIT or a bitcode interpreter.\n";
exit(1);
}
/// Compute the path to the main executable.
std::string GetExecutablePath(const char *Argv0) {
// This just needs to be some symbol in the binary; C++ doesn't
// allow taking the address of ::main however.
void *P = (void *)(intptr_t)GetExecutablePath;
return llvm::sys::fs::getMainExecutable(Argv0, P);
}
/// Expand the semi-colon delimited LLVM_DYLIB_COMPONENTS into
/// the full list of components.
std::vector<std::string> GetAllDyLibComponents(const bool IsInDevelopmentTree,
const bool GetComponentNames,
const std::string &DirSep) {
std::vector<StringRef> DyLibComponents;
StringRef DyLibComponentsStr(LLVM_DYLIB_COMPONENTS);
size_t Offset = 0;
while (true) {
const size_t NextOffset = DyLibComponentsStr.find(';', Offset);
DyLibComponents.push_back(DyLibComponentsStr.substr(Offset, NextOffset-Offset));
if (NextOffset == std::string::npos) {
break;
}
Offset = NextOffset + 1;
}
assert(!DyLibComponents.empty());
return ComputeLibsForComponents(DyLibComponents,
/*IncludeNonInstalled=*/IsInDevelopmentTree,
GetComponentNames, nullptr, nullptr, DirSep);
}
int main(int argc, char **argv) {
std::vector<StringRef> Components;
bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = false;
bool PrintSystemLibs = false, PrintSharedMode = false;
bool HasAnyOption = false;
// llvm-config is designed to support being run both from a development tree
// and from an installed path. We try and auto-detect which case we are in so
// that we can report the correct information when run from a development
// tree.
bool IsInDevelopmentTree;
enum { CMakeStyle, CMakeBuildModeStyle } DevelopmentTreeLayout;
llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0]));
std::string CurrentExecPrefix;
std::string ActiveObjRoot;
// If CMAKE_CFG_INTDIR is given, honor it as build mode.
char const *build_mode = LLVM_BUILDMODE;
#if defined(CMAKE_CFG_INTDIR)
if (!(CMAKE_CFG_INTDIR[0] == '.' && CMAKE_CFG_INTDIR[1] == '\0'))
build_mode = CMAKE_CFG_INTDIR;
#endif
// Create an absolute path, and pop up one directory (we expect to be inside a
// bin dir).
sys::fs::make_absolute(CurrentPath);
CurrentExecPrefix =
sys::path::parent_path(sys::path::parent_path(CurrentPath)).str();
// Check to see if we are inside a development tree by comparing to possible
// locations (prefix style or CMake style).
if (sys::fs::equivalent(CurrentExecPrefix, LLVM_OBJ_ROOT)) {
IsInDevelopmentTree = true;
DevelopmentTreeLayout = CMakeStyle;
ActiveObjRoot = LLVM_OBJ_ROOT;
} else if (sys::fs::equivalent(CurrentExecPrefix,
Twine(LLVM_OBJ_ROOT) + "/bin")) {
IsInDevelopmentTree = true;
DevelopmentTreeLayout = CMakeBuildModeStyle;
ActiveObjRoot = LLVM_OBJ_ROOT;
} else {
IsInDevelopmentTree = false;
DevelopmentTreeLayout = CMakeStyle; // Initialized to avoid warnings.
}
// Compute various directory locations based on the derived location
// information.
std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir,
ActiveCMakeDir;
std::string ActiveIncludeOption;
if (IsInDevelopmentTree) {
ActiveIncludeDir = std::string(LLVM_SRC_ROOT) + "/include";
ActivePrefix = CurrentExecPrefix;
// CMake organizes the products differently than a normal prefix style
// layout.
switch (DevelopmentTreeLayout) {
case CMakeStyle:
ActiveBinDir = ActiveObjRoot + "/bin";
ActiveLibDir = ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX;
ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
break;
case CMakeBuildModeStyle:
ActivePrefix = ActiveObjRoot;
ActiveBinDir = ActiveObjRoot + "/bin/" + build_mode;
ActiveLibDir =
ActiveObjRoot + "/lib" + LLVM_LIBDIR_SUFFIX + "/" + build_mode;
ActiveCMakeDir = ActiveLibDir + "/cmake/llvm";
break;
}
// We need to include files from both the source and object trees.
ActiveIncludeOption =
("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include");
} else {
ActivePrefix = CurrentExecPrefix;
ActiveIncludeDir = ActivePrefix + "/include";
SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR));
sys::fs::make_absolute(ActivePrefix, path);<