diff options
Diffstat (limited to 'tools')
60 files changed, 1471 insertions, 1481 deletions
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 49c73b7..75d203e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -11,11 +11,8 @@ if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/polly/CMakeLists.txt ) endif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/polly/CMakeLists.txt ) if( NOT WIN32 OR MSYS OR CYGWIN ) - # It is useful to build llvm-config before the other tools, so we - # have a fresh LibDeps.txt for regenerating the hard-coded library - # dependencies. llvm-config/CMakeLists.txt takes care of this but we - # must keep llvm-config as the first entry on the list of tools to - # be built. + # We currently require 'sed' to build llvm-config, so don't try to build it + # on pure Win32. add_subdirectory(llvm-config) endif() @@ -31,6 +28,7 @@ add_subdirectory(llvm-nm) add_subdirectory(llvm-size) add_subdirectory(llvm-ld) +add_subdirectory(llvm-cov) add_subdirectory(llvm-prof) add_subdirectory(llvm-link) add_subdirectory(lli) @@ -46,7 +44,6 @@ add_subdirectory(bugpoint) add_subdirectory(bugpoint-passes) add_subdirectory(llvm-bcanalyzer) add_subdirectory(llvm-stub) -add_subdirectory(edis) if( NOT WIN32 ) add_subdirectory(lto) diff --git a/tools/LLVMBuild.txt b/tools/LLVMBuild.txt new file mode 100644 index 0000000..aba990f --- /dev/null +++ b/tools/LLVMBuild.txt @@ -0,0 +1,24 @@ +;===- ./tools/LLVMBuild.txt ------------------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[common] +subdirectories = bugpoint llc lli llvm-ar llvm-as llvm-bcanalyzer llvm-cov llvm-diff llvm-dis llvm-dwarfdump llvm-extract llvm-ld llvm-link llvm-mc llvm-nm llvm-objdump llvm-prof llvm-ranlib llvm-rtdyld llvm-size llvm-stub macho-dump opt + +[component_0] +type = Group +name = Tools +parent = $ROOT diff --git a/tools/Makefile b/tools/Makefile index 2da3917..1953cb6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -56,14 +56,6 @@ ifeq ($(ENABLE_PIC),1) endif PARALLEL_DIRS += bugpoint-passes - - # The edis library is only supported if ARM and/or X86 are enabled, and if - # LLVM is being built PIC on platforms that support dylibs. - ifneq ($(DISABLE_EDIS),1) - ifneq ($(filter $(TARGETS_TO_BUILD), X86 ARM),) - PARALLEL_DIRS += edis - endif - endif endif ifdef LLVM_HAS_POLLY diff --git a/tools/bugpoint/BugDriver.cpp b/tools/bugpoint/BugDriver.cpp index 0b59a78..6b219bf 100644 --- a/tools/bugpoint/BugDriver.cpp +++ b/tools/bugpoint/BugDriver.cpp @@ -96,7 +96,7 @@ Module *llvm::ParseInputFile(const std::string &Filename, Triple TheTriple(Result->getTargetTriple()); if (TheTriple.getTriple().empty()) - TheTriple.setTriple(sys::getHostTriple()); + TheTriple.setTriple(sys::getDefaultTargetTriple()); TargetTriple.setTriple(TheTriple.getTriple()); } diff --git a/tools/bugpoint/CrashDebugger.cpp b/tools/bugpoint/CrashDebugger.cpp index f19ef62..a0aaf53 100644 --- a/tools/bugpoint/CrashDebugger.cpp +++ b/tools/bugpoint/CrashDebugger.cpp @@ -401,7 +401,8 @@ bool ReduceCrashingInstructions::TestInsts(std::vector<const Instruction*> for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE; ++FI) for (BasicBlock::iterator I = FI->begin(), E = FI->end(); I != E;) { Instruction *Inst = I++; - if (!Instructions.count(Inst) && !isa<TerminatorInst>(Inst)) { + if (!Instructions.count(Inst) && !isa<TerminatorInst>(Inst) && + !isa<LandingPadInst>(Inst)) { if (!Inst->getType()->isVoidTy()) Inst->replaceAllUsesWith(UndefValue::get(Inst->getType())); Inst->eraseFromParent(); @@ -574,6 +575,9 @@ static bool DebugACrash(BugDriver &BD, } else { if (BugpointIsInterrupted) goto ExitLoops; + if (isa<LandingPadInst>(I)) + continue; + outs() << "Checking instruction: " << *I; Module *M = BD.deleteInstructionFromProgram(I, Simplification); diff --git a/tools/bugpoint/ExtractFunction.cpp b/tools/bugpoint/ExtractFunction.cpp index 73b65ca..f2e61f8 100644 --- a/tools/bugpoint/ExtractFunction.cpp +++ b/tools/bugpoint/ExtractFunction.cpp @@ -340,7 +340,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const // If the BB doesn't have a name, give it one so we have something to key // off of. if (!BB->hasName()) BB->setName("tmpbb"); - BlocksToNotExtractFile.os() << BB->getParent()->getNameStr() << " " + BlocksToNotExtractFile.os() << BB->getParent()->getName() << " " << BB->getName() << "\n"; } BlocksToNotExtractFile.os().close(); diff --git a/tools/bugpoint/LLVMBuild.txt b/tools/bugpoint/LLVMBuild.txt new file mode 100644 index 0000000..549d9d0 --- /dev/null +++ b/tools/bugpoint/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/bugpoint/LLVMBuild.txt ---------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = bugpoint +parent = Tools +required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Linker Scalar diff --git a/tools/bugpoint/ToolRunner.cpp b/tools/bugpoint/ToolRunner.cpp index 0d98262..c2d3720 100644 --- a/tools/bugpoint/ToolRunner.cpp +++ b/tools/bugpoint/ToolRunner.cpp @@ -920,8 +920,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType, } else GCCArgs.push_back("-shared"); // `-shared' for Linux/X86, maybe others - if ((TargetTriple.getArch() == Triple::alpha) || - (TargetTriple.getArch() == Triple::x86_64)) + if (TargetTriple.getArch() == Triple::x86_64) GCCArgs.push_back("-fPIC"); // Requires shared objs to contain PIC if (TargetTriple.getArch() == Triple::sparc) diff --git a/tools/edis/CMakeLists.txt b/tools/edis/CMakeLists.txt deleted file mode 100644 index 1e162f9..0000000 --- a/tools/edis/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -set(SOURCES - ../../include/llvm-c/EnhancedDisassembly.h - EDMain.cpp - ) - -set(EDIS_DEPENDS LLVMMCDisassembler LLVMMCParser) -if( LLVM_TARGETS_TO_BUILD MATCHES X86 ) - list(APPEND EDIS_DEPENDS LLVMX86AsmPrinter LLVMX86AsmParser LLVMX86Disassembler LLVMX86Desc) -endif() -if( LLVM_TARGETS_TO_BUILD MATCHES ARM ) - list(APPEND EDIS_DEPENDS LLVMARMAsmPrinter LLVMARMAsmParser LLVMARMDisassembler LLVMARMDesc) -endif() - -add_llvm_library(EnhancedDisassembly ${SOURCES}) -set_property(TARGET EnhancedDisassembly PROPERTY - OUTPUT_NAME "EnhancedDisassembly") - -add_llvm_library_dependencies(EnhancedDisassembly - ${EDIS_DEPENDS}) diff --git a/tools/edis/EDMain.cpp b/tools/edis/EDMain.cpp deleted file mode 100644 index 16855b3..0000000 --- a/tools/edis/EDMain.cpp +++ /dev/null @@ -1,284 +0,0 @@ -//===-- EDMain.cpp - LLVM Enhanced Disassembly C API ----------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file implements the enhanced disassembler's public C API. -// -//===----------------------------------------------------------------------===// - -// FIXME: This code isn't layered right, the headers should be moved to -// include llvm/MC/MCDisassembler or something. -#include "../../lib/MC/MCDisassembler/EDDisassembler.h" -#include "../../lib/MC/MCDisassembler/EDInst.h" -#include "../../lib/MC/MCDisassembler/EDOperand.h" -#include "../../lib/MC/MCDisassembler/EDToken.h" -#include "llvm-c/EnhancedDisassembly.h" -using namespace llvm; - -int EDGetDisassembler(EDDisassemblerRef *disassembler, - const char *triple, - EDAssemblySyntax_t syntax) { - EDDisassembler::initialize(); - - EDDisassembler::AssemblySyntax Syntax; - switch (syntax) { - default: assert(0 && "Unknown assembly syntax!"); - case kEDAssemblySyntaxX86Intel: - Syntax = EDDisassembler::kEDAssemblySyntaxX86Intel; - break; - case kEDAssemblySyntaxX86ATT: - Syntax = EDDisassembler::kEDAssemblySyntaxX86ATT; - break; - case kEDAssemblySyntaxARMUAL: - Syntax = EDDisassembler::kEDAssemblySyntaxARMUAL; - break; - } - - EDDisassemblerRef ret = EDDisassembler::getDisassembler(triple, Syntax); - - if (!ret) - return -1; - *disassembler = ret; - return 0; -} - -int EDGetRegisterName(const char** regName, - EDDisassemblerRef disassembler, - unsigned regID) { - const char *name = ((EDDisassembler*)disassembler)->nameWithRegisterID(regID); - if (!name) - return -1; - *regName = name; - return 0; -} - -int EDRegisterIsStackPointer(EDDisassemblerRef disassembler, - unsigned regID) { - return ((EDDisassembler*)disassembler)->registerIsStackPointer(regID) ? 1 : 0; -} - -int EDRegisterIsProgramCounter(EDDisassemblerRef disassembler, - unsigned regID) { - return ((EDDisassembler*)disassembler)->registerIsProgramCounter(regID) ? 1:0; -} - -unsigned int EDCreateInsts(EDInstRef *insts, - unsigned int count, - EDDisassemblerRef disassembler, - ::EDByteReaderCallback byteReader, - uint64_t address, - void *arg) { - unsigned int index; - - for (index = 0; index < count; ++index) { - EDInst *inst = ((EDDisassembler*)disassembler)->createInst(byteReader, - address, arg); - - if (!inst) - return index; - - insts[index] = inst; - address += inst->byteSize(); - } - - return count; -} - -void EDReleaseInst(EDInstRef inst) { - delete ((EDInst*)inst); -} - -int EDInstByteSize(EDInstRef inst) { - return ((EDInst*)inst)->byteSize(); -} - -int EDGetInstString(const char **buf, - EDInstRef inst) { - return ((EDInst*)inst)->getString(*buf); -} - -int EDInstID(unsigned *instID, EDInstRef inst) { - *instID = ((EDInst*)inst)->instID(); - return 0; -} - -int EDInstIsBranch(EDInstRef inst) { - return ((EDInst*)inst)->isBranch(); -} - -int EDInstIsMove(EDInstRef inst) { - return ((EDInst*)inst)->isMove(); -} - -int EDBranchTargetID(EDInstRef inst) { - return ((EDInst*)inst)->branchTargetID(); -} - -int EDMoveSourceID(EDInstRef inst) { - return ((EDInst*)inst)->moveSourceID(); -} - -int EDMoveTargetID(EDInstRef inst) { - return ((EDInst*)inst)->moveTargetID(); -} - -int EDNumTokens(EDInstRef inst) { - return ((EDInst*)inst)->numTokens(); -} - -int EDGetToken(EDTokenRef *token, - EDInstRef inst, - int index) { - return ((EDInst*)inst)->getToken(*(EDToken**)token, index); -} - -int EDGetTokenString(const char **buf, - EDTokenRef token) { - return ((EDToken*)token)->getString(*buf); -} - -int EDOperandIndexForToken(EDTokenRef token) { - return ((EDToken*)token)->operandID(); -} - -int EDTokenIsWhitespace(EDTokenRef token) { - return ((EDToken*)token)->type() == EDToken::kTokenWhitespace; -} - -int EDTokenIsPunctuation(EDTokenRef token) { - return ((EDToken*)token)->type() == EDToken::kTokenPunctuation; -} - -int EDTokenIsOpcode(EDTokenRef token) { - return ((EDToken*)token)->type() == EDToken::kTokenOpcode; -} - -int EDTokenIsLiteral(EDTokenRef token) { - return ((EDToken*)token)->type() == EDToken::kTokenLiteral; -} - -int EDTokenIsRegister(EDTokenRef token) { - return ((EDToken*)token)->type() == EDToken::kTokenRegister; -} - -int EDTokenIsNegativeLiteral(EDTokenRef token) { - if (((EDToken*)token)->type() != EDToken::kTokenLiteral) - return -1; - - return ((EDToken*)token)->literalSign(); -} - -int EDLiteralTokenAbsoluteValue(uint64_t *value, EDTokenRef token) { - if (((EDToken*)token)->type() != EDToken::kTokenLiteral) - return -1; - - return ((EDToken*)token)->literalAbsoluteValue(*value); -} - -int EDRegisterTokenValue(unsigned *registerID, - EDTokenRef token) { - if (((EDToken*)token)->type() != EDToken::kTokenRegister) - return -1; - - return ((EDToken*)token)->registerID(*registerID); -} - -int EDNumOperands(EDInstRef inst) { - return ((EDInst*)inst)->numOperands(); -} - -int EDGetOperand(EDOperandRef *operand, - EDInstRef inst, - int index) { - return ((EDInst*)inst)->getOperand(*(EDOperand**)operand, index); -} - -int EDOperandIsRegister(EDOperandRef operand) { - return ((EDOperand*)operand)->isRegister(); -} - -int EDOperandIsImmediate(EDOperandRef operand) { - return ((EDOperand*)operand)->isImmediate(); -} - -int EDOperandIsMemory(EDOperandRef operand) { - return ((EDOperand*)operand)->isMemory(); -} - -int EDRegisterOperandValue(unsigned *value, EDOperandRef operand) { - if (!((EDOperand*)operand)->isRegister()) - return -1; - *value = ((EDOperand*)operand)->regVal(); - return 0; -} - -int EDImmediateOperandValue(uint64_t *value, EDOperandRef operand) { - if (!((EDOperand*)operand)->isImmediate()) - return -1; - *value = ((EDOperand*)operand)->immediateVal(); - return 0; -} - -int EDEvaluateOperand(uint64_t *result, EDOperandRef operand, - ::EDRegisterReaderCallback regReader, void *arg) { - return ((EDOperand*)operand)->evaluate(*result, regReader, arg); -} - -#ifdef __BLOCKS__ - -struct ByteReaderWrapper { - EDByteBlock_t byteBlock; -}; - -static int readerWrapperCallback(uint8_t *byte, - uint64_t address, - void *arg) { - struct ByteReaderWrapper *wrapper = (struct ByteReaderWrapper *)arg; - return wrapper->byteBlock(byte, address); -} - -unsigned int EDBlockCreateInsts(EDInstRef *insts, - int count, - EDDisassemblerRef disassembler, - EDByteBlock_t byteBlock, - uint64_t address) { - struct ByteReaderWrapper wrapper; - wrapper.byteBlock = byteBlock; - - return EDCreateInsts(insts, - count, - disassembler, - readerWrapperCallback, - address, - (void*)&wrapper); -} - -int EDBlockEvaluateOperand(uint64_t *result, EDOperandRef operand, - EDRegisterBlock_t regBlock) { - return ((EDOperand*)operand)->evaluate(*result, regBlock); -} - -int EDBlockVisitTokens(EDInstRef inst, ::EDTokenVisitor_t visitor) { - return ((EDInst*)inst)->visitTokens((llvm::EDTokenVisitor_t)visitor); -} - -#else - -extern "C" unsigned int EDBlockCreateInsts() { - return 0; -} - -extern "C" int EDBlockEvaluateOperand() { - return -1; -} - -extern "C" int EDBlockVisitTokens() { - return -1; -} - -#endif diff --git a/tools/edis/Makefile b/tools/edis/Makefile deleted file mode 100644 index 39a5cf7..0000000 --- a/tools/edis/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -##===- tools/edis/Makefile -----------------------------------*- Makefile -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## - -LEVEL := ../.. -LIBRARYNAME := EnhancedDisassembly -LINK_LIBS_IN_SHARED := 1 - -EXPORTED_SYMBOL_FILE = $(PROJ_SRC_DIR)/EnhancedDisassembly.exports - -# Include this here so we can get the configuration of the targets -# that have been configured for construction. We have to do this -# early so we can set up LINK_COMPONENTS before including Makefile.rules -include $(LEVEL)/Makefile.config - -LINK_COMPONENTS := mcdisassembler - -# If the X86 target is enabled, link in the asmprinter and disassembler. -ifneq ($(filter $(TARGETS_TO_BUILD), X86),) -LINK_COMPONENTS += x86asmprinter x86disassembler -endif - -# If the ARM target is enabled, link in the asmprinter and disassembler. -ifneq ($(filter $(TARGETS_TO_BUILD), ARM),) -LINK_COMPONENTS += armasmprinter armdisassembler -endif - -include $(LEVEL)/Makefile.common - -ifeq ($(HOST_OS),Darwin) - # extra options to override libtool defaults - LLVMLibsOptions := $(LLVMLibsOptions) \ - -Wl,-dead_strip - - ifdef EDIS_VERSION - LLVMLibsOptions := $(LLVMLibsOptions) -Wl,-current_version -Wl,$(EDIS_VERSION) \ - -Wl,-compatibility_version -Wl,1 - endif - - # Mac OS X 10.4 and earlier tools do not allow a second -install_name on command line - DARWIN_VERS := $(shell echo $(TARGET_TRIPLE) | sed 's/.*darwin\([0-9]*\).*/\1/') - ifneq ($(DARWIN_VERS),8) - LLVMLibsOptions := $(LLVMLibsOptions) \ - -Wl,-install_name \ - -Wl,"@rpath/lib$(LIBRARYNAME)$(SHLIBEXT)" - endif -endif - diff --git a/tools/gold/CMakeLists.txt b/tools/gold/CMakeLists.txt index eb4b6e6..2cc132f 100644 --- a/tools/gold/CMakeLists.txt +++ b/tools/gold/CMakeLists.txt @@ -40,6 +40,7 @@ else() set_property(SOURCE gold-plugin.cpp APPEND PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/exportsfile) - target_link_libraries(LLVMgold LTO -Wl,--version-script,exportsfile) + target_link_libraries(LLVMgold LTO + -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/exportsfile) add_dependencies(LLVMgold gold_exports) endif() diff --git a/tools/gold/Makefile b/tools/gold/Makefile index 78eda03..02f66d7 100644 --- a/tools/gold/Makefile +++ b/tools/gold/Makefile @@ -24,6 +24,6 @@ include $(LEVEL)/Makefile.config # Because off_t is used in the public API, the largefile parts are required for # ABI compatibility. CXXFLAGS += -I$(BINUTILS_INCDIR) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -CXXFLAGS += $(SharedLibDir)/$(SharedPrefix)LTO$(SHLIBEXT) +CXXFLAGS += -L$(SharedLibDir)/$(SharedPrefix) -lLTO include $(LEVEL)/Makefile.common diff --git a/tools/llc/Android.mk b/tools/llc/Android.mk index f9c76cc..86b79be 100644 --- a/tools/llc/Android.mk +++ b/tools/llc/Android.mk @@ -10,12 +10,29 @@ LLVM_ROOT_PATH := $(LOCAL_PATH)/../.. llvm_llc_SRC_FILES := \ llc.cpp -llvm_llc_STATIC_LIBRARIES := \ +llvm_llc_mips_STATIC_LIBRARIES := \ + libLLVMMipsInfo \ + libLLVMMipsCodeGen \ + libLLVMMipsDesc \ + libLLVMMipsAsmPrinter \ + +llvm_llc_x86_STATIC_LIBRARIES := \ + libLLVMX86Info \ + libLLVMX86AsmParser \ + libLLVMX86CodeGen \ + libLLVMX86Disassembler \ + libLLVMX86Desc \ + libLLVMX86AsmPrinter \ + libLLVMX86Utils + +llvm_llc_arm_STATIC_LIBRARIES := \ libLLVMARMCodeGen \ libLLVMARMDisassembler \ libLLVMARMAsmParser \ libLLVMARMDesc \ - libLLVMARMInfo \ + libLLVMARMInfo + +llvm_llc_STATIC_LIBRARIES := \ libLLVMAsmPrinter \ libLLVMAsmParser \ libLLVMBitReader \ @@ -32,9 +49,9 @@ llvm_llc_STATIC_LIBRARIES := \ libLLVMScalarOpts \ libLLVMTransformUtils \ libLLVMAnalysis \ + libLLVMTarget \ libLLVMCore \ - libLLVMSupport \ - libLLVMTarget + libLLVMSupport #===---------------------------------------------------------------=== @@ -49,15 +66,13 @@ LOCAL_MODULE_CLASS := EXECUTABLES LOCAL_IS_HOST_MODULE := true LOCAL_SRC_FILES := $(llvm_llc_SRC_FILES) + LOCAL_STATIC_LIBRARIES := \ - libLLVMX86Info \ - libLLVMX86AsmParser \ - libLLVMX86CodeGen \ - libLLVMX86Disassembler \ - libLLVMX86Desc \ - libLLVMX86AsmPrinter \ - libLLVMX86Utils \ + $(llvm_llc_arm_STATIC_LIBRARIES) \ + $(llvm_llc_mips_STATIC_LIBRARIES) \ + $(llvm_llc_x86_STATIC_LIBRARIES) \ $(llvm_llc_STATIC_LIBRARIES) + LOCAL_LDLIBS += -lpthread -lm -ldl LOCAL_C_INCLUDES += external/llvm/include @@ -79,12 +94,27 @@ LOCAL_MODULE_CLASS := EXECUTABLES LOCAL_SRC_FILES := $(llvm_llc_SRC_FILES) LOCAL_C_INCLUDES += external/llvm/include -LOCAL_STATIC_LIBRARIES := $(llvm_llc_STATIC_LIBRARIES) + +ifeq ($(TARGET_ARCH),arm) + LOCAL_STATIC_LIBRARIES := $(llvm_llc_arm_STATIC_LIBRARIES) +else + ifeq ($(TARGET_ARCH),mips) + LOCAL_STATIC_LIBRARIES := $(llvm_llc_mips_STATIC_LIBRARIES) + else + ifeq ($(TARGET_ARCH),x86) + LOCAL_STATIC_LIBRARIES := $(llvm_llc__STATIC_LIBRARIES) + else + $(error "Unsupport llc target $(TARGET_ARCH)") + endif + endif +endif + +LOCAL_STATIC_LIBRARIES += $(llvm_llc_STATIC_LIBRARIES) + LOCAL_SHARED_LIBRARIES := \ libdl \ libstlport - include $(LLVM_ROOT_PATH)/llvm.mk include $(LLVM_DEVICE_BUILD_MK) include $(LLVM_GEN_INTRINSICS_MK) diff --git a/tools/llc/LLVMBuild.txt b/tools/llc/LLVMBuild.txt new file mode 100644 index 0000000..8c8794f --- /dev/null +++ b/tools/llc/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llc/LLVMBuild.txt --------------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llc +parent = Tools +required_libraries = AsmParser BitReader all-targets diff --git a/tools/llc/llc.cpp b/tools/llc/llc.cpp index 4cb3cf1..58dafca 100644 --- a/tools/llc/llc.cpp +++ b/tools/llc/llc.cpp @@ -133,14 +133,142 @@ cl::opt<bool> DisableDotLoc("disable-dot-loc", cl::Hidden, cl::opt<bool> DisableCFI("disable-cfi", cl::Hidden, cl::desc("Do not use .cfi_* directives")); -cl::opt<bool> DisableDwarfDirectory("disable-dwarf-directory", cl::Hidden, - cl::desc("Do not use file directives with an explicit directory.")); +cl::opt<bool> EnableDwarfDirectory("enable-dwarf-directory", cl::Hidden, + cl::desc("Use .file directives with an explicit directory.")); static cl::opt<bool> DisableRedZone("disable-red-zone", cl::desc("Do not emit code that uses the red zone."), cl::init(false)); +static cl::opt<bool> +EnableFPMAD("enable-fp-mad", + cl::desc("Enable less precise MAD instructions to be generated"), + cl::init(false)); + +static cl::opt<bool> +PrintCode("print-machineinstrs", + cl::desc("Print generated machine code"), + cl::init(false)); + +static cl::opt<bool> +DisableFPElim("disable-fp-elim", + cl::desc("Disable frame pointer elimination optimization"), + cl::init(false)); + +static cl::opt<bool> +DisableFPElimNonLeaf("disable-non-leaf-fp-elim", + cl::desc("Disable frame pointer elimination optimization for non-leaf funcs"), + cl::init(false)); + +static cl::opt<bool> +DisableExcessPrecision("disable-excess-fp-precision", + cl::desc("Disable optimizations that may increase FP precision"), + cl::init(false)); + +static cl::opt<bool> +EnableUnsafeFPMath("enable-unsafe-fp-math", + cl::desc("Enable optimizations that may decrease FP precision"), + cl::init(false)); + +static cl::opt<bool> +EnableNoInfsFPMath("enable-no-infs-fp-math", + cl::desc("Enable FP math optimizations that assume no +-Infs"), + cl::init(false)); + +static cl::opt<bool> +EnableNoNaNsFPMath("enable-no-nans-fp-math", + cl::desc("Enable FP math optimizations that assume no NaNs"), + cl::init(false)); + +static cl::opt<bool> +EnableHonorSignDependentRoundingFPMath("enable-sign-dependent-rounding-fp-math", + cl::Hidden, + cl::desc("Force codegen to assume rounding mode can change dynamically"), + cl::init(false)); + +static cl::opt<bool> +GenerateSoftFloatCalls("soft-float", + cl::desc("Generate software floating point library calls"), + cl::init(false)); + +static cl::opt<llvm::FloatABI::ABIType> +FloatABIForCalls("float-abi", + cl::desc("Choose float ABI type"), + cl::init(FloatABI::Default), + cl::values( + clEnumValN(FloatABI::Default, "default", + "Target default float ABI type"), + clEnumValN(FloatABI::Soft, "soft", + "Soft float ABI (implied by -soft-float)"), + clEnumValN(FloatABI::Hard, "hard", + "Hard float ABI (uses FP registers)"), + clEnumValEnd)); + +static cl::opt<bool> +DontPlaceZerosInBSS("nozero-initialized-in-bss", + cl::desc("Don't place zero-initialized symbols into bss section"), + cl::init(false)); + +static cl::opt<bool> +EnableJITExceptionHandling("jit-enable-eh", + cl::desc("Emit exception handling information"), + cl::init(false)); + +// In debug builds, make this default to true. +#ifdef NDEBUG +#define EMIT_DEBUG false +#else +#define EMIT_DEBUG true +#endif +static cl::opt<bool> +EmitJitDebugInfo("jit-emit-debug", + cl::desc("Emit debug information to debugger"), + cl::init(EMIT_DEBUG)); +#undef EMIT_DEBUG + +static cl::opt<bool> +EmitJitDebugInfoToDisk("jit-emit-debug-to-disk", + cl::Hidden, + cl::desc("Emit debug info objfiles to disk"), + cl::init(false)); + +static cl::opt<bool> +EnableGuaranteedTailCallOpt("tailcallopt", + cl::desc("Turn fastcc calls into tail calls by (potentially) changing ABI."), + cl::init(false)); + +static cl::opt<unsigned> +OverrideStackAlignment("stack-alignment", + cl::desc("Override default stack alignment"), + cl::init(0)); + +static cl::opt<bool> +EnableRealignStack("realign-stack", + cl::desc("Realign stack if needed"), + cl::init(true)); + +static cl::opt<bool> +DisableSwitchTables(cl::Hidden, "disable-jump-tables", + cl::desc("Do not generate jump tables."), + cl::init(false)); + +static cl::opt<bool> +EnableStrongPHIElim(cl::Hidden, "strong-phi-elim", + cl::desc("Use strong PHI elimination."), + cl::init(false)); + +static cl::opt<std::string> +TrapFuncName("trap-func", cl::Hidden, + cl::desc("Emit a call to trap function rather than a trap instruction"), + cl::init("")); + +static cl::opt<bool> +SegmentedStacks("segmented-stacks", + cl::desc("Use segmented stacks if possible."), + cl::init(false)); + + // GetFileNameRoot - Helper function to get the basename of a filename. static inline std::string GetFileNameRoot(const std::string &InputFilename) { @@ -261,7 +389,7 @@ int main(int argc, char **argv) { Triple TheTriple(mod.getTargetTriple()); if (TheTriple.getTriple().empty()) - TheTriple.setTriple(sys::getHostTriple()); + TheTriple.setTriple(sys::getDefaultTargetTriple()); // Allocate target machine. First, check whether the user has explicitly // specified an architecture to compile for. If so we have to look it up by @@ -306,10 +434,47 @@ int main(int argc, char **argv) { FeaturesStr = Features.getString(); } + CodeGenOpt::Level OLvl = CodeGenOpt::Default; + switch (OptLevel) { + default: + errs() << argv[0] << ": invalid optimization level.\n"; + return 1; + case ' ': break; + case '0': OLvl = CodeGenOpt::None; break; + case '1': OLvl = CodeGenOpt::Less; break; + case '2': OLvl = CodeGenOpt::Default; break; + case '3': OLvl = CodeGenOpt::Aggressive; break; + } + + TargetOptions Options; + Options.LessPreciseFPMADOption = EnableFPMAD; + Options.PrintMachineCode = PrintCode; + Options.NoFramePointerElim = DisableFPElim; + Options.NoFramePointerElimNonLeaf = DisableFPElimNonLeaf; + Options.NoExcessFPPrecision = DisableExcessPrecision; + Options.UnsafeFPMath = EnableUnsafeFPMath; + Options.NoInfsFPMath = EnableNoInfsFPMath; + Options.NoNaNsFPMath = EnableNoNaNsFPMath; + Options.HonorSignDependentRoundingFPMathOption = + EnableHonorSignDependentRoundingFPMath; + Options.UseSoftFloat = GenerateSoftFloatCalls; + if (FloatABIForCalls != FloatABI::Default) + Options.FloatABIType = FloatABIForCalls; + Options.NoZerosInBSS = DontPlaceZerosInBSS; + Options.JITExceptionHandling = EnableJITExceptionHandling; + Options.JITEmitDebugInfo = EmitJitDebugInfo; + Options.JITEmitDebugInfoToDisk = EmitJitDebugInfoToDisk; + Options.GuaranteedTailCallOpt = EnableGuaranteedTailCallOpt; + Options.StackAlignmentOverride = OverrideStackAlignment; + Options.RealignStack = EnableRealignStack; + Options.DisableJumpTables = DisableSwitchTables; + Options.TrapFuncName = TrapFuncName; + Options.EnableSegmentedStacks = SegmentedStacks; + std::auto_ptr<TargetMachine> target(TheTarget->createTargetMachine(TheTriple.getTriple(), - MCPU, FeaturesStr, - RelocModel, CMModel)); + MCPU, FeaturesStr, Options, + RelocModel, CMModel, OLvl)); assert(target.get() && "Could not allocate target machine!"); TargetMachine &Target = *target.get(); @@ -319,8 +484,11 @@ int main(int argc, char **argv) { if (DisableCFI) Target.setMCUseCFI(false); - if (DisableDwarfDirectory) - Target.setMCUseDwarfDirectory(false); + if (EnableDwarfDirectory) + Target.setMCUseDwarfDirectory(true); + + if (GenerateSoftFloatCalls) + FloatABIForCalls = FloatABI::Soft; // Disable .loc support for older OS X versions. if (TheTriple.isMacOSX() && @@ -332,18 +500,6 @@ int main(int argc, char **argv) { (GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0])); if (!Out) return 1; - CodeGenOpt::Level OLvl = CodeGenOpt::Default; - switch (OptLevel) { - default: - errs() << argv[0] << ": invalid optimization level.\n"; - return 1; - case ' ': break; - case '0': OLvl = CodeGenOpt::None; break; - case '1': OLvl = CodeGenOpt::Less; break; - case '2': OLvl = CodeGenOpt::Default; break; - case '3': OLvl = CodeGenOpt::Aggressive; break; - } - // Build up all of the passes that we want to do to the module. PassManager PM; @@ -368,7 +524,7 @@ int main(int argc, char **argv) { formatted_raw_ostream FOS(Out->os()); // Ask the target to add backend passes as necessary. - if (Target.addPassesToEmitFile(PM, FOS, FileType, OLvl, NoVerify)) { + if (Target.addPassesToEmitFile(PM, FOS, FileType, NoVerify)) { errs() << argv[0] << ": target does not support generation of this" << " file type!\n"; return 1; diff --git a/tools/lli/LLVMBuild.txt b/tools/lli/LLVMBuild.txt new file mode 100644 index 0000000..4eb82bd --- /dev/null +++ b/tools/lli/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/lli/LLVMBuild.txt --------------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = lli +parent = Tools +required_libraries = AsmParser BitReader Interpreter JIT MCJIT NativeCodeGen SelectionDAG diff --git a/tools/llvm-ar/LLVMBuild.txt b/tools/llvm-ar/LLVMBuild.txt new file mode 100644 index 0000000..1f61a32 --- /dev/null +++ b/tools/llvm-ar/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-ar/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-ar +parent = Tools +required_libraries = Archive diff --git a/tools/llvm-as/LLVMBuild.txt b/tools/llvm-as/LLVMBuild.txt new file mode 100644 index 0000000..542470b --- /dev/null +++ b/tools/llvm-as/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-as/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-as +parent = Tools +required_libraries = AsmParser BitWriter diff --git a/tools/llvm-bcanalyzer/LLVMBuild.txt b/tools/llvm-bcanalyzer/LLVMBuild.txt new file mode 100644 index 0000000..ee77a7d --- /dev/null +++ b/tools/llvm-bcanalyzer/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-bcanalyzer/LLVMBuild.txt --------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-bcanalyzer +parent = Tools +required_libraries = BitReader diff --git a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 4ada64a..f1cb523 100644 --- a/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -102,14 +102,13 @@ static const char *GetBlockName(unsigned BlockID, default: return 0; case bitc::MODULE_BLOCK_ID: return "MODULE_BLOCK"; case bitc::PARAMATTR_BLOCK_ID: return "PARAMATTR_BLOCK"; - case bitc::TYPE_BLOCK_ID_OLD: return "TYPE_BLOCK_ID_OLD"; case bitc::TYPE_BLOCK_ID_NEW: return "TYPE_BLOCK_ID"; case bitc::CONSTANTS_BLOCK_ID: return "CONSTANTS_BLOCK"; case bitc::FUNCTION_BLOCK_ID: return "FUNCTION_BLOCK"; - case bitc::TYPE_SYMTAB_BLOCK_ID_OLD: return "TYPE_SYMTAB_OLD"; case bitc::VALUE_SYMTAB_BLOCK_ID: return "VALUE_SYMTAB"; case bitc::METADATA_BLOCK_ID: return "METADATA_BLOCK"; case bitc::METADATA_ATTACHMENT_ID: return "METADATA_ATTACHMENT_BLOCK"; + case bitc::USELIST_BLOCK_ID: return "USELIST_BLOCK_ID"; } } @@ -163,7 +162,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, default: return 0; case bitc::PARAMATTR_CODE_ENTRY: return "ENTRY"; } - case bitc::TYPE_BLOCK_ID_OLD: case bitc::TYPE_BLOCK_ID_NEW: switch (CodeID) { default: return 0; @@ -175,8 +173,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, case bitc::TYPE_CODE_OPAQUE: return "OPAQUE"; case bitc::TYPE_CODE_INTEGER: return "INTEGER"; case bitc::TYPE_CODE_POINTER: return "POINTER"; - case bitc::TYPE_CODE_FUNCTION: return "FUNCTION"; - case bitc::TYPE_CODE_STRUCT_OLD: return "STRUCT_OLD"; case bitc::TYPE_CODE_ARRAY: return "ARRAY"; case bitc::TYPE_CODE_VECTOR: return "VECTOR"; case bitc::TYPE_CODE_X86_FP80: return "X86_FP80"; @@ -186,6 +182,7 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, case bitc::TYPE_CODE_STRUCT_ANON: return "STRUCT_ANON"; case bitc::TYPE_CODE_STRUCT_NAME: return "STRUCT_NAME"; case bitc::TYPE_CODE_STRUCT_NAMED: return "STRUCT_NAMED"; + case bitc::TYPE_CODE_FUNCTION: return "FUNCTION"; } case bitc::CONSTANTS_BLOCK_ID: @@ -247,11 +244,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, case bitc::FUNC_CODE_INST_CALL: return "INST_CALL"; case bitc::FUNC_CODE_DEBUG_LOC: return "DEBUG_LOC"; } - case bitc::TYPE_SYMTAB_BLOCK_ID_OLD: - switch (CodeID) { - default: return 0; - case bitc::TST_CODE_ENTRY: return "ENTRY"; - } case bitc::VALUE_SYMTAB_BLOCK_ID: switch (CodeID) { default: return 0; @@ -273,6 +265,11 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, case bitc::METADATA_FN_NODE: return "METADATA_FN_NODE"; case bitc::METADATA_NAMED_NODE: return "METADATA_NAMED_NODE"; } + case bitc::USELIST_BLOCK_ID: + switch(CodeID) { + default:return 0; + case bitc::USELIST_CODE_ENTRY: return "USELIST_CODE_ENTRY"; + } } } diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in new file mode 100644 index 0000000..fe87afb --- /dev/null +++ b/tools/llvm-config/BuildVariables.inc.in @@ -0,0 +1,27 @@ +//===-- BuildVariables.inc.in - llvm-config build variables -*- C++ -*-----===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// 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 non .in variant of this file 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_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" +#define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" diff --git a/tools/llvm-config/CMakeLists.txt b/tools/llvm-config/CMakeLists.txt index 6016862..5ad58bf 100644 --- a/tools/llvm-config/CMakeLists.txt +++ b/tools/llvm-config/CMakeLists.txt @@ -1,140 +1,42 @@ -include(TestBigEndian) +set(LLVM_LINK_COMPONENTS support) -include(FindPerl) -if( NOT PERL_FOUND ) - message(FATAL_ERROR "Perl required but not found!") -endif( NOT PERL_FOUND ) - -set(PERL ${PERL_EXECUTABLE}) -set(VERSION PACKAGE_VERSION) -set(PREFIX ${CMAKE_INSTALL_PREFIX}) -set(abs_top_srcdir ${LLVM_MAIN_SRC_DIR}) -set(abs_top_builddir ${LLVM_BINARY_DIR}) -execute_process(COMMAND date - OUTPUT_VARIABLE LLVM_CONFIGTIME - OUTPUT_STRIP_TRAILING_WHITESPACE) -# LLVM_ON_UNIX and LLVM_ON_WIN32 already set. -# those are set to blank by `autoconf' on MinGW, so it seems they are not required: -#set(LLVMGCCDIR "") -#set(LLVMGCC "") -#set(LLVMGXX "") -test_big_endian(IS_BIG_ENDIAN) -if( IS_BIG_ENDIAN ) - set(ENDIAN "big") -else( IS_BIG_ENDIAN ) - set(ENDIAN "little") -endif( IS_BIG_ENDIAN ) -set(SHLIBEXT ${LTDL_SHLIB_EXT}) -#EXEEXT already set. -set(OS "${CMAKE_SYSTEM}") -set(target "${TARGET_TRIPLE}") -set(ARCH "${LLVM_NATIVE_ARCH}") +# We need to generate the BuildVariables.inc file containing values which are +# only defined when under certain build modes. Unfortunately, that precludes +# doing this inside CMake so we have to shell out to sed. For now, that means we +# can't expect to build llvm-config on Window.s +set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in) +set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc) +set(SEDSCRIPT_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.configure.sed) +# Compute the substitution values for various items. get_system_libs(LLVM_SYSTEM_LIBS_LIST) foreach(l ${LLVM_SYSTEM_LIBS_LIST}) - set(LLVM_SYSTEM_LIBS ${LLVM_SYSTEM_LIBS} "-l${l}") + set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}") endforeach() - -foreach(c ${LLVM_TARGETS_TO_BUILD}) - set(TARGETS_BUILT "${TARGETS_BUILT} ${c}") -endforeach(c) -set(TARGETS_TO_BUILD ${TARGETS_BUILT}) -set(TARGET_HAS_JIT "1") # TODO - -# Avoids replacement at config-time: -set(LLVM_CPPFLAGS "@LLVM_CPPFLAGS@") -set(LLVM_CFLAGS "@LLVM_CFLAGS@") -set(LLVM_CXXFLAGS "@LLVM_CXXFLAGS@") -set(LLVM_LDFLAGS "@LLVM_LDFLAGS@") -set(LIBS "@LIBS@") -set(LLVM_BUILDMODE "@LLVM_BUILDMODE@") - -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.in.in - ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in - @ONLY -) - -set(LIBDEPS LibDeps.txt) -set(LIBDEPS_TMP LibDeps.txt.tmp) -set(FINAL_LIBDEPS FinalLibDeps.txt) -set(LLVM_CONFIG ${LLVM_TOOLS_BINARY_DIR}/llvm-config) -set(LLVM_CONFIG_IN ${CMAKE_CURRENT_BINARY_DIR}/llvm-config.in) - -if( CMAKE_CROSSCOMPILING ) - set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY) -endif() - -find_program(NM_PATH nm PATH_SUFFIXES /bin) - -if( NOT NM_PATH ) - message(FATAL_ERROR "`nm' not found") -endif() - -get_property(llvm_libs GLOBAL PROPERTY LLVM_LIBS) - -add_custom_command(OUTPUT ${LIBDEPS_TMP} - COMMAND ${PERL_EXECUTABLE} ${LLVM_MAIN_SRC_DIR}/utils/GenLibDeps.pl -flat ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR} ${NM_PATH} > ${LIBDEPS_TMP} - DEPENDS ${llvm_libs} - COMMENT "Regenerating ${LIBDEPS_TMP}") - -add_custom_command(OUTPUT ${LIBDEPS} - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LIBDEPS_TMP} ${LIBDEPS} - DEPENDS ${LIBDEPS_TMP} - COMMENT "Updating ${LIBDEPS} if necessary...") - -# This must stop the build if find-cycles.pl returns error: -add_custom_command(OUTPUT ${FINAL_LIBDEPS} - COMMAND ${CMAKE_COMMAND} -E remove -f ${FINAL_LIBDEPS} ${FINAL_LIBDEPS}.tmp - COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/find-cycles.pl < ${LIBDEPS} > ${FINAL_LIBDEPS}.tmp - COMMAND ${CMAKE_COMMAND} -E copy ${FINAL_LIBDEPS}.tmp ${FINAL_LIBDEPS} - DEPENDS ${LIBDEPS} - COMMENT "Checking for cyclic dependencies between LLVM libraries.") - set(C_FLGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") set(CXX_FLGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") set(CPP_FLGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") -# We don't want certain flags on the output of -# llvm-config --cflags --cxxflags -macro(remove_option_from_llvm_config option) - llvm_replace_compiler_option(C_FLGS "${option}" "") - llvm_replace_compiler_option(CXX_FLGS "${option}" "") - llvm_replace_compiler_option(CPP_FLGS "${option}" "") -endmacro(remove_option_from_llvm_config) -remove_option_from_llvm_config("-pedantic") -remove_option_from_llvm_config("-Wall") -remove_option_from_llvm_config("-W") - -add_custom_command(OUTPUT ${LLVM_CONFIG} - COMMAND echo s!@LLVM_CPPFLAGS@!${CPP_FLGS}! > temp.sed - COMMAND echo s!@LLVM_CFLAGS@!${C_FLGS}! >> temp.sed - COMMAND echo s!@LLVM_CXXFLAGS@!${CXX_FLGS}! >> temp.sed +add_custom_command(OUTPUT ${BUILDVARIABLES_OBJPATH} + COMMAND echo s!@LLVM_SRC_ROOT@!${LLVM_MAIN_SRC_DIR}! > ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_OBJ_ROOT@!${LLVM_BINARY_DIR}! >> ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_CPPFLAGS@!${CPP_FLGS}! >> ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_CFLAGS@!${C_FLGS}! >> ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_CXXFLAGS@!${CXX_FLGS}! >> ${SEDSCRIPT_OBJPATH} # TODO: Use general flags for linking! not just for shared libs: - COMMAND echo s!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}! >> temp.sed - COMMAND echo s!@LIBS@!${LLVM_SYSTEM_LIBS}! >> temp.sed - COMMAND echo s!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}! >> temp.sed - COMMAND sed -f temp.sed < ${LLVM_CONFIG_IN} > ${LLVM_CONFIG} - COMMAND ${CMAKE_COMMAND} -E remove -f temp.sed - COMMAND cat ${FINAL_LIBDEPS} >> ${LLVM_CONFIG} - COMMAND chmod +x ${LLVM_CONFIG} + COMMAND echo s!@LLVM_LDFLAGS@!${CMAKE_SHARED_LINKER_FLAGS}! >> ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_BUILDMODE@!${CMAKE_BUILD_TYPE}! >> ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_SYSTEM_LIBS@!${SYSTEM_LIBS}! >> ${SEDSCRIPT_OBJPATH} + COMMAND echo s!@LLVM_TARGETS_BUILT@!${LLVM_TARGETS_TO_BUILD}! >> ${SEDSCRIPT_OBJPATH} + COMMAND sed -f ${SEDSCRIPT_OBJPATH} < ${BUILDVARIABLES_SRCPATH} > ${BUILDVARIABLES_OBJPATH} VERBATIM - DEPENDS ${FINAL_LIBDEPS} ${LLVM_CONFIG_IN} - COMMENT "Building llvm-config script." + COMMENT "Building BuildVariables.inc include." ) -add_custom_target(llvm-config.target ALL - DEPENDS ${LLVM_CONFIG}) - -add_dependencies( llvm-config.target ${llvm_libs} ) - -# Make sure that llvm-config builds before the llvm tools, so we have -# LibDeps.txt and can use it for updating the hard-coded library -# dependencies on cmake/modules/LLVMLibDeps.cmake when the tools' -# build fail due to outdated dependencies: -set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} llvm-config.target) +# Add the llvm-config tool. +add_llvm_tool(llvm-config + llvm-config.cpp + ) -install(FILES ${LLVM_CONFIG} - PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE - DESTINATION bin) +# Add the dependency on the generation step. +add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH}) diff --git a/tools/llvm-config/Makefile b/tools/llvm-config/Makefile index c7f7b32..3f11730 100644 --- a/tools/llvm-config/Makefile +++ b/tools/llvm-config/Makefile @@ -1,5 +1,5 @@ -##===- tools/llvm-config/Makefile --------------------------*- Makefile -*-===## -# +##===- tools/llvm-config/Makefile---------------------------*- Makefile -*-===## +# # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source @@ -7,97 +7,42 @@ # ##===----------------------------------------------------------------------===## -LEVEL = ../.. +LEVEL := ../.. +TOOLNAME := llvm-config +USEDLIBS := LLVMSupport.a -EXTRA_DIST = LibDeps.txt FinalLibDeps.txt llvm-config.in.in find-cycles.pl +# We generate sources in the build directory, make sure it is in the include +# paths. +INCLUDE_BUILD_DIR := 1 -include $(LEVEL)/Makefile.common +# This tool has no plugins, optimize startup time. +TOOL_NO_EXPORTS := 1 -# If we don't have Perl, we can't generate the library dependencies upon which -# llvm-config depends. Therefore, only if we detect perl will we do anything -# useful. -ifeq ($(HAVE_PERL),1) +# Note that we have to use lazy expansion here. +BUILDVARIABLES_SRCPATH = $(PROJ_SRC_ROOT)/tools/$(TOOLNAME)/BuildVariables.inc.in +BUILDVARIABLES_OBJPATH = $(ObjDir)/BuildVariables.inc +BUILT_SOURCES = $(BUILDVARIABLES_OBJPATH) + +include $(LEVEL)/Makefile.common # Combine preprocessor flags (except for -I) and CXX flags. -SUB_CPPFLAGS = ${CPP.BaseFlags} -SUB_CFLAGS = ${CPP.BaseFlags} ${C.Flags} -SUB_CXXFLAGS = ${CPP.BaseFlags} ${CXX.Flags} +SUB_CPPFLAGS := ${CPP.BaseFlags} +SUB_CFLAGS := ${CPP.BaseFlags} ${C.Flags} +SUB_CXXFLAGS := ${CPP.BaseFlags} ${CXX.Flags} # This is blank for now. We need to be careful about adding stuff here: # LDFLAGS tend not to be portable, and we don't currently require the # user to use libtool when linking against LLVM. -SUB_LDFLAGS = - -FinalLibDeps = $(PROJ_OBJ_DIR)/FinalLibDeps.txt -LibDeps = $(PROJ_OBJ_DIR)/LibDeps.txt -LibDepsTemp = $(PROJ_OBJ_DIR)/LibDeps.txt.tmp -GenLibDeps = $(PROJ_SRC_ROOT)/utils/GenLibDeps.pl - -$(LibDepsTemp): $(GenLibDeps) $(LibDir) $(wildcard $(LibDir)/*.a $(LibDir)/*.o) - $(Echo) "Regenerating LibDeps.txt.tmp" - $(Verb) $(PERL) $(GenLibDeps) -flat $(LibDir) "$(NM_PATH)" > $(LibDepsTemp) - -$(LibDeps): $(LibDepsTemp) - $(Verb) $(CMP) -s $@ $< || ( $(CP) $< $@ && \ - $(EchoCmd) Updated LibDeps.txt because dependencies changed ) - -# Find all the cyclic dependencies between various LLVM libraries, so we -# don't have to process them at runtime. -$(FinalLibDeps): find-cycles.pl $(LibDeps) - $(Echo) "Checking for cyclic dependencies between LLVM libraries." - $(Verb) $(PERL) $< < $(LibDeps) > $@ || rm -f $@ - -# Rerun our configure substitutions as needed. -ConfigInIn = $(PROJ_SRC_DIR)/llvm-config.in.in -llvm-config.in: $(ConfigInIn) $(ConfigStatusScript) - $(Verb) cd $(PROJ_OBJ_ROOT) ; \ - $(ConfigStatusScript) tools/llvm-config/llvm-config.in - -llvm-config-perobj: llvm-config.in $(GenLibDeps) $(LibDir) $(wildcard $(LibDir)/*.a) - $(Echo) "Generating llvm-config-perobj" - $(Verb) $(PERL) $(GenLibDeps) -perobj -flat $(LibDir) "$(NM_PATH)" >PerobjDeps.txt - $(Echo) "Checking for cyclic dependencies between LLVM objects." - $(Verb) $(PERL) $(PROJ_SRC_DIR)/find-cycles.pl < PerobjDepsIncl.txt > PerobjDepsInclFinal.txt || rm -f $@ - $(Verb) $(ECHO) 's/@LLVM_CPPFLAGS@/$(subst /,\/,$(SUB_CPPFLAGS))/' \ - > temp.sed - $(Verb) $(ECHO) 's/@LLVM_CFLAGS@/$(subst /,\/,$(SUB_CFLAGS))/' \ - >> temp.sed - $(Verb) $(ECHO) 's/@LLVM_CXXFLAGS@/$(subst /,\/,$(SUB_CXXFLAGS))/' \ - >> temp.sed - $(Verb) $(ECHO) 's/@LLVM_LDFLAGS@/$(subst /,\/,$(SUB_LDFLAGS))/' \ - >> temp.sed - $(Verb) $(ECHO) 's/@LLVM_BUILDMODE@/$(subst /,\/,$(BuildMode))/' \ - >> temp.sed - $(Verb) $(SED) -f temp.sed < $< > $@ - $(Verb) $(RM) temp.sed - $(Verb) cat PerobjDepsFinal.txt >> $@ - $(Verb) chmod +x $@ +SUB_LDFLAGS := -llvm-config-perobjincl: llvm-config.in $(GenLibDeps) $(LibDir) $(wildcard $(LibDir)/*.a) - $(Echo) "Generating llvm-config-perobjincl" - $(Verb) $(PERL) $(GenLibDeps) -perobj -perobjincl -flat $(LibDir) "$(NM_PATH)" >PerobjDepsIncl.txt - $(Echo) "Checking for cyclic dependencies between LLVM objects." - $(Verb) $(PERL) $(PROJ_SRC_DIR)/find-cycles.pl < PerobjDepsIncl.txt > PerobjDepsInclFinal.txt - $(Verb) $(ECHO) 's/@LLVM_CPPFLAGS@/$(subst /,\/,$(SUB_CPPFLAGS))/' \ - > temp.sed - $(Verb) $(ECHO) 's/@LLVM_CFLAGS@/$(subst /,\/,$(SUB_CFLAGS))/' \ - >> temp.sed - $(Verb) $(ECHO) 's/@LLVM_CXXFLAGS@/$(subst /,\/,$(SUB_CXXFLAGS))/' \ - >> temp.sed - $(Verb) $(ECHO) 's/@LLVM_LDFLAGS@/$(subst /,\/,$(SUB_LDFLAGS))/' \ - >> temp.sed - $(Verb) $(ECHO) 's/@LLVM_BUILDMODE@/$(subst /,\/,$(BuildMode))/' \ - >> temp.sed - $(Verb) $(SED) -f temp.sed < $< > $@ - $(Verb) $(RM) temp.sed - $(Verb) cat PerobjDepsInclFinal.txt >> $@ - $(Verb) chmod +x $@ - -# Build our final script. -$(ToolDir)/llvm-config: llvm-config.in $(FinalLibDeps) - $(Echo) "Building llvm-config script." - $(Verb) $(ECHO) 's/@LLVM_CPPFLAGS@/$(subst /,\/,$(SUB_CPPFLAGS))/' \ +$(ObjDir)/BuildVariables.inc: $(BUILDVARIABLES_SRCPATH) Makefile $(ObjDir)/.dir + $(Echo) "Building llvm-config BuildVariables.inc file." + $(Verb) $(ECHO) 's/@LLVM_SRC_ROOT@/$(subst /,\/,$(LLVM_SRC_ROOT))/' \ > temp.sed + $(Verb) $(ECHO) 's/@LLVM_OBJ_ROOT@/$(subst /,\/,$(LLVM_OBJ_ROOT))/' \ + >> temp.sed + $(Verb) $(ECHO) 's/@LLVM_CPPFLAGS@/$(subst /,\/,$(SUB_CPPFLAGS))/' \ + >> temp.sed $(Verb) $(ECHO) 's/@LLVM_CFLAGS@/$(subst /,\/,$(SUB_CFLAGS))/' \ >> temp.sed $(Verb) $(ECHO) 's/@LLVM_CXXFLAGS@/$(subst /,\/,$(SUB_CXXFLAGS))/' \ @@ -106,26 +51,9 @@ $(ToolDir)/llvm-config: llvm-config.in $(FinalLibDeps) >> temp.sed $(Verb) $(ECHO) 's/@LLVM_BUILDMODE@/$(subst /,\/,$(BuildMode))/' \ >> temp.sed + $(Verb) $(ECHO) 's/@LLVM_SYSTEM_LIBS@/$(subst /,\/,$(LIBS))/' \ + >> temp.sed + $(Verb) $(ECHO) 's/@LLVM_TARGETS_BUILT@/$(subst /,\/,$(TARGETS_TO_BUILD))/' \ + >> temp.sed $(Verb) $(SED) -f temp.sed < $< > $@ $(Verb) $(RM) temp.sed - $(Verb) cat $(FinalLibDeps) >> $@ - $(Verb) chmod +x $@ - -else -# We don't have perl, just generate a dummy llvm-config -$(ToolDir)/llvm-config: - $(Echo) "Building place holder llvm-config script." - $(Verb) $(ECHO) 'echo llvm-config: Perl not found so llvm-config could not be generated' >> $@ - $(Verb) chmod +x $@ - -endif -# Hook into the standard Makefile rules. -all-local:: $(ToolDir)/llvm-config -clean-local:: - $(Verb) $(RM) -f $(ToolDir)/llvm-config llvm-config.in $(FinalLibDeps) \ - $(LibDeps) GenLibDeps.out -install-local:: all-local - $(Echo) Installing llvm-config - $(Verb) $(MKDIR) $(DESTDIR)$(PROJ_bindir) - $(Verb) $(ScriptInstall) $(ToolDir)/llvm-config $(DESTDIR)$(PROJ_bindir) - diff --git a/tools/llvm-config/find-cycles.pl b/tools/llvm-config/find-cycles.pl deleted file mode 100755 index 5cbf5b4..0000000 --- a/tools/llvm-config/find-cycles.pl +++ /dev/null @@ -1,170 +0,0 @@ -#!/usr/bin/perl -# -# Program: find-cycles.pl -# -# Synopsis: Given a list of possibly cyclic dependencies, merge all the -# cycles. This makes it possible to topologically sort the -# dependencies between different parts of LLVM. -# -# Syntax: find-cycles.pl < LibDeps.txt > FinalLibDeps.txt -# -# Input: cycmem1: cycmem2 dep1 dep2 -# cycmem2: cycmem1 dep3 dep4 -# boring: dep4 -# -# Output: cycmem1 cycmem2: dep1 dep2 dep3 dep4 -# boring: dep4 -# -# This file was written by Eric Kidd, and is placed into the public domain. -# - -use 5.006; -use strict; -use warnings; - -my %DEPS; -my @CYCLES; -sub find_all_cycles; - -# Read our dependency information. -while (<>) { - chomp; - my ($module, $dependency_str) = /^\s*([^:]+):\s*(.*)\s*$/; - die "Malformed data: $_" unless defined $dependency_str; - my @dependencies = split(/ /, $dependency_str); - $DEPS{$module} = \@dependencies; -} - -# Partition our raw dependencies into sets of cyclically-connected nodes. -find_all_cycles(); - -# Print out the finished cycles, with their dependencies. -my @output; -my $cycles_found = 0; -foreach my $cycle (@CYCLES) { - my @modules = sort keys %{$cycle}; - - # Merge the dependencies of all modules in this cycle. - my %dependencies; - foreach my $module (@modules) { - @dependencies{@{$DEPS{$module}}} = 1; - } - - # Prune the known cyclic dependencies. - foreach my $module (@modules) { - delete $dependencies{$module}; - } - - # Warn about possible linker problems. - my @archives = grep(/\.a$/, @modules); - if (@archives > 1) { - $cycles_found = $cycles_found + 1; - print STDERR "find-cycles.pl: Circular dependency between *.a files:\n"; - print STDERR "find-cycles.pl: ", join(' ', @archives), "\n"; - push @modules, @archives; # WORKAROUND: Duplicate *.a files. Ick. - } elsif (@modules > 1) { - $cycles_found = $cycles_found + 1; - print STDERR "find-cycles.pl: Circular dependency between *.o files:\n"; - print STDERR "find-cycles.pl: ", join(' ', @modules), "\n"; - push @modules, @modules; # WORKAROUND: Duplicate *.o files. Ick. - } - - # Add to our output. (@modules is already as sorted as we need it to be.) - push @output, (join(' ', @modules) . ': ' . - join(' ', sort keys %dependencies) . "\n"); -} -print sort @output; - -exit $cycles_found; - -#========================================================================== -# Depedency Cycle Support -#========================================================================== -# For now, we have cycles in our dependency graph. Ideally, each cycle -# would be collapsed down to a single *.a file, saving us all this work. -# -# To understand this code, you'll need a working knowledge of Perl 5, -# and possibly some quality time with 'man perlref'. - -my %SEEN; -my %CYCLES; -sub find_cycles ($@); -sub found_cycles ($@); - -sub find_all_cycles { - # Find all multi-item cycles. - my @modules = sort keys %DEPS; - foreach my $module (@modules) { find_cycles($module); } - - # Build fake one-item "cycles" for the remaining modules, so we can - # treat them uniformly. - foreach my $module (@modules) { - unless (defined $CYCLES{$module}) { - my %cycle = ($module, 1); - $CYCLES{$module} = \%cycle; - } - } - - # Find all our unique cycles. We have to do this the hard way because - # we apparently can't store hash references as hash keys without making - # 'strict refs' sad. - my %seen; - foreach my $cycle (values %CYCLES) { - unless ($seen{$cycle}) { - $seen{$cycle} = 1; - push @CYCLES, $cycle; - } - } -} - -# Walk through our graph depth-first (keeping a trail in @path), and report -# any cycles we find. -sub find_cycles ($@) { - my ($module, @path) = @_; - if (str_in_list($module, @path)) { - found_cycle($module, @path); - } else { - return if defined $SEEN{$module}; - $SEEN{$module} = 1; - foreach my $dep (@{$DEPS{$module}}) { - find_cycles($dep, @path, $module); - } - } -} - -# Give a cycle, attempt to merge it with pre-existing cycle data. -sub found_cycle ($@) { - my ($module, @path) = @_; - - # Pop any modules which aren't part of our cycle. - while ($path[0] ne $module) { shift @path; } - #print join("->", @path, $module) . "\n"; - - # Collect the modules in our cycle into a hash. - my %cycle; - foreach my $item (@path) { - $cycle{$item} = 1; - if (defined $CYCLES{$item}) { - # Looks like we intersect with an existing cycle, so merge - # all those in, too. - foreach my $old_item (keys %{$CYCLES{$item}}) { - $cycle{$old_item} = 1; - } - } - } - - # Update our global cycle table. - my $cycle_ref = \%cycle; - foreach my $item (keys %cycle) { - $CYCLES{$item} = $cycle_ref; - } - #print join(":", sort keys %cycle) . "\n"; -} - -sub str_in_list ($@) { - my ($str, @list) = @_; - foreach my $item (@list) { - return 1 if ($item eq $str); - } - return 0; -} diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp new file mode 100644 index 0000000..2bb0aeb --- /dev/null +++ b/tools/llvm-config/llvm-config.cpp @@ -0,0 +1,329 @@ +//===-- llvm-config.cpp - LLVM project configuration utility --------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// 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/ADT/STLExtras.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Config/config.h" +#include "llvm/Config/llvm-config.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/raw_ostream.h" +#include <cstdlib> +#include <set> +#include <vector> + +using namespace llvm; + +// 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" + +/// \brief 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. +static void VisitComponent(StringRef Name, + const StringMap<AvailableComponent*> &ComponentMap, + std::set<AvailableComponent*> &VisitedComponents, + std::vector<StringRef> &RequiredLibs) { + // Lookup the component. + AvailableComponent *AC = ComponentMap.lookup(Name); + 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; + } + + // Otherwise, visit all the dependencies. + for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) { + VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents, + RequiredLibs); + } + + // Add to the required library list. + if (AC->Library) + RequiredLibs.push_back(AC->Library); +} + +/// \brief 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 RequiredLibs [out] - On return, the ordered list of libraries that +/// are required to link the given components. +void ComputeLibsForComponents(const std::vector<StringRef> &Components, + std::vector<StringRef> &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); + } + + // 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()); +} + +/* *** */ + +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\ + --version Print LLVM 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\ + --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\ + --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\ +Typical components:\n\ + all All LLVM libraries (default).\n\ + engine Either a native JIT or a bitcode interpreter.\n"; + exit(1); +} + +/// \brief Compute the path to the main executable. +llvm::sys::Path 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::Path::GetMainExecutable(Argv0, P); +} + +int main(int argc, char **argv) { + std::vector<StringRef> Components; + bool PrintLibs = false, PrintLibNames = false, PrintLibFiles = 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, DevelopmentTreeLayoutIsCMakeStyle; + llvm::SmallString<256> CurrentPath(GetExecutablePath(argv[0]).str()); + std::string CurrentExecPrefix; + std::string ActiveObjRoot; + + // 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). This could be wrong in the face of + // symbolic links, but is good enough. + if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/" + LLVM_BUILDMODE) { + IsInDevelopmentTree = true; + DevelopmentTreeLayoutIsCMakeStyle = false; + + // If we are in a development tree, then check if we are in a BuildTools + // directory. This indicates we are built for the build triple, but we + // always want to provide information for the host triple. + if (sys::path::filename(LLVM_OBJ_ROOT) == "BuildTools") { + ActiveObjRoot = sys::path::parent_path(LLVM_OBJ_ROOT); + } else { + ActiveObjRoot = LLVM_OBJ_ROOT; + } + } else if (CurrentExecPrefix == std::string(LLVM_OBJ_ROOT) + "/bin") { + IsInDevelopmentTree = true; + DevelopmentTreeLayoutIsCMakeStyle = true; + ActiveObjRoot = LLVM_OBJ_ROOT; + } else { + IsInDevelopmentTree = false; + } + + // Compute various directory locations based on the derived location + // information. + std::string ActivePrefix, ActiveBinDir, ActiveIncludeDir, ActiveLibDir; + 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. + if (DevelopmentTreeLayoutIsCMakeStyle) { + ActiveBinDir = ActiveObjRoot + "/bin/" + LLVM_BUILDMODE; + ActiveLibDir = ActiveObjRoot + "/lib/" + LLVM_BUILDMODE; + } else { + ActiveBinDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/bin"; + ActiveLibDir = ActiveObjRoot + "/" + LLVM_BUILDMODE + "/lib"; + } + + // We need to include files from both the source and object trees. + ActiveIncludeOption = ("-I" + ActiveIncludeDir + " " + + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; + ActiveIncludeDir = ActivePrefix + "/include"; + ActiveBinDir = ActivePrefix + "/bin"; + ActiveLibDir = ActivePrefix + "/lib"; + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + + raw_ostream &OS = outs(); + for (int i = 1; i != argc; ++i) { + StringRef Arg = argv[i]; + + if (Arg.startswith("-")) { + HasAnyOption = true; + if (Arg == "--version") { + OS << PACKAGE_VERSION << '\n'; + } else if (Arg == "--prefix") { + OS << ActivePrefix << '\n'; + } else if (Arg == "--bindir") { + OS << ActiveBinDir << '\n'; + } else if (Arg == "--includedir") { + OS << ActiveIncludeDir << '\n'; + } else if (Arg == "--libdir") { + OS << ActiveLibDir << '\n'; + } else if (Arg == "--cppflags") { + OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n'; + } else if (Arg == "--cflags") { + OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n'; + } else if (Arg == "--cxxflags") { + OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n'; + } else if (Arg == "--ldflags") { + OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS + << ' ' << LLVM_SYSTEM_LIBS << '\n'; + } else if (Arg == "--libs") { + PrintLibs = true; + } else if (Arg == "--libnames") { + PrintLibNames = true; + } else if (Arg == "--libfiles") { + PrintLibFiles = true; + } else if (Arg == "--components") { + for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) { + OS << ' '; + OS << AvailableComponents[j].Name; + } + OS << '\n'; + } else if (Arg == "--targets-built") { + OS << LLVM_TARGETS_BUILT << '\n'; + } else if (Arg == "--host-target") { + OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n'; + } else if (Arg == "--build-mode") { + OS << LLVM_BUILDMODE << '\n'; + } else if (Arg == "--obj-root") { + OS << LLVM_OBJ_ROOT << '\n'; + } else if (Arg == "--src-root") { + OS << LLVM_SRC_ROOT << '\n'; + } else { + usage(); + } + } else { + Components.push_back(Arg); + } + } + + if (!HasAnyOption) + usage(); + + if (PrintLibs || PrintLibNames || PrintLibFiles) { + // If no components were specified, default to "all". + if (Components.empty()) + Components.push_back("all"); + + // Construct the list of all the required libraries. + std::vector<StringRef> RequiredLibs; + ComputeLibsForComponents(Components, RequiredLibs); + + for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) { + StringRef Lib = RequiredLibs[i]; + if (i) + OS << ' '; + + if (PrintLibNames) { + OS << Lib; + } else if (PrintLibFiles) { + OS << ActiveLibDir << '/' << Lib; + } else if (PrintLibs) { + // If this is a typical library name, include it using -l. + if (Lib.startswith("lib") && Lib.endswith(".a")) { + OS << "-l" << Lib.slice(3, Lib.size()-2); + continue; + } + + // Otherwise, print the full path. + OS << ActiveLibDir << '/' << Lib; + } + } + OS << '\n'; + } else if (!Components.empty()) { + errs() << "llvm-config: error: components given, but unused\n\n"; + usage(); + } + + return 0; +} diff --git a/tools/llvm-config/llvm-config.in.in b/tools/llvm-config/llvm-config.in.in deleted file mode 100644 index 03efb03..0000000 --- a/tools/llvm-config/llvm-config.in.in +++ /dev/null @@ -1,467 +0,0 @@ -#!@PERL@ -##===- tools/llvm-config ---------------------------------------*- perl -*-===## -# -# The LLVM Compiler Infrastructure -# -# This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. -# -##===----------------------------------------------------------------------===## -# -# Synopsis: Prints out compiler options needed to build against an installed -# copy of LLVM. -# -# Syntax: llvm-config OPTIONS... [COMPONENTS...] -# -##===----------------------------------------------------------------------===## - -use 5.006; -use strict; -use warnings; -use Cwd 'abs_path'; - -#---- begin autoconf values ---- -my $PACKAGE_NAME = q{@PACKAGE_NAME@}; -my $VERSION = q{@PACKAGE_VERSION@}; -my $PREFIX = q{@LLVM_PREFIX@}; -my $LLVM_CONFIGTIME = q{@LLVM_CONFIGTIME@}; -my $LLVM_SRC_ROOT = q{@abs_top_srcdir@}; -my $LLVM_OBJ_ROOT = q{@abs_top_builddir@}; -my $ARCH = lc(q{@ARCH@}); -my $TARGET_TRIPLE = q{@target@}; -my $TARGETS_TO_BUILD = q{@TARGETS_TO_BUILD@}; -my $TARGET_HAS_JIT = q{@TARGET_HAS_JIT@}; -my @TARGETS_BUILT = map { lc($_) } qw{@TARGETS_TO_BUILD@}; -#---- end autoconf values ---- - -# Must pretend x86_64 architecture is really x86, otherwise the native backend -# won't get linked in. -$ARCH = "x86" if $ARCH eq "x86_64"; - -#---- begin Makefile values ---- -my $CPPFLAGS = q{@LLVM_CPPFLAGS@}; -my $CFLAGS = q{@LLVM_CFLAGS@}; -my $CXXFLAGS = q{@LLVM_CXXFLAGS@}; -my $LDFLAGS = q{@LLVM_LDFLAGS@}; -my $SYSTEM_LIBS = q{@LIBS@}; -my $LLVM_BUILDMODE = q{@LLVM_BUILDMODE@}; -#---- end Makefile values ---- - -# Figure out where llvm-config is being run from. Primarily, we care if it has -# been installed, or is running from the build directory, which changes the -# locations of some files. - -# Convert the current executable name into its directory (e.g. "."). -my ($RUN_DIR) = ($0 =~ /^(.*)\/.*$/); - -# Turn the directory into an absolute directory on the file system, also pop up -# from "bin" into the build or prefix dir. -my $ABS_RUN_DIR = abs_path("$RUN_DIR/.."); -chomp($ABS_RUN_DIR); - -# Compute the absolute object directory build, e.g. "foo/llvm/Debug". -my $ABS_OBJ_ROOT = "$LLVM_OBJ_ROOT/$LLVM_BUILDMODE"; -$ABS_OBJ_ROOT = abs_path("$ABS_OBJ_ROOT") if (-d $ABS_OBJ_ROOT); -chomp($ABS_OBJ_ROOT); - -my $INCLUDEDIR = "$ABS_RUN_DIR/include"; -my $INCLUDEOPTION = "-I$INCLUDEDIR"; -my $LIBDIR = "$ABS_RUN_DIR/lib"; -my $BINDIR = "$ABS_RUN_DIR/bin"; -if ($ABS_RUN_DIR eq $ABS_OBJ_ROOT) { - # If we are running out of the build directory, the include dir is in the - # srcdir. - $INCLUDEDIR = "$LLVM_SRC_ROOT/include"; - # We need include files from both the srcdir and objdir. - $INCLUDEOPTION = "-I$INCLUDEDIR -I$LLVM_OBJ_ROOT/include" -} else { - # If installed, ignore the prefix the tree was configured with, use the - # current prefix. - $PREFIX = $ABS_RUN_DIR; -} - -sub usage; -sub fix_library_names (@); -sub fix_library_files (@); -sub expand_dependencies (@); -sub name_map_entries; - -# Parse our command-line arguments. -usage if @ARGV == 0; -my @components; -my $has_opt = 0; -my $want_libs = 0; -my $want_libnames = 0; -my $want_libfiles = 0; -my $want_components = 0; -foreach my $arg (@ARGV) { - if ($arg =~ /^-/) { - if ($arg eq "--version") { - $has_opt = 1; print "$VERSION\n"; - } elsif ($arg eq "--prefix") { - $has_opt = 1; print "$PREFIX\n"; - } elsif ($arg eq "--bindir") { - $has_opt = 1; print "$BINDIR\n"; - } elsif ($arg eq "--includedir") { - $has_opt = 1; print "$INCLUDEDIR\n"; - } elsif ($arg eq "--libdir") { - $has_opt = 1; print "$LIBDIR\n"; - } elsif ($arg eq "--cppflags") { - $has_opt = 1; print "$INCLUDEOPTION $CPPFLAGS\n"; - } elsif ($arg eq "--cflags") { - $has_opt = 1; print "$INCLUDEOPTION $CFLAGS\n"; - } elsif ($arg eq "--cxxflags") { - $has_opt = 1; print "$INCLUDEOPTION $CXXFLAGS\n"; - } elsif ($arg eq "--ldflags") { - $has_opt = 1; print "-L$LIBDIR $LDFLAGS $SYSTEM_LIBS\n"; - } elsif ($arg eq "--libs") { - $has_opt = 1; $want_libs = 1; - } elsif ($arg eq "--libnames") { - $has_opt = 1; $want_libnames = 1; - } elsif ($arg eq "--libfiles") { - $has_opt = 1; $want_libfiles = 1; - } elsif ($arg eq "--components") { - $has_opt = 1; print join(' ', name_map_entries), "\n"; - } elsif ($arg eq "--targets-built") { - $has_opt = 1; print join(' ', @TARGETS_BUILT), "\n"; - } elsif ($arg eq "--host-target") { - $has_opt = 1; print "$TARGET_TRIPLE\n"; - } elsif ($arg eq "--build-mode") { - $has_opt = 1; print "$LLVM_BUILDMODE\n"; - } elsif ($arg eq "--obj-root") { - $has_opt = 1; print abs_path("$LLVM_OBJ_ROOT/"); - } elsif ($arg eq "--src-root") { - $has_opt = 1; print abs_path("$LLVM_SRC_ROOT/"); - } else { - usage(); - } - } else { - push @components, $arg; - } -} - -# If no options were specified, fail. -usage unless $has_opt; - -# If no components were specified, default to 'all'. -if (@components == 0) { - push @components, 'all'; -} - -# Force component names to lower case. -@components = map lc, @components; - -# Handle any arguments which require building our dependency graph. -if ($want_libs || $want_libnames || $want_libfiles) { - my @libs = expand_dependencies(@components); - print join(' ', fix_library_names(@libs)), "\n" if ($want_libs); - print join(' ', @libs), "\n" if ($want_libnames); - print join(' ', fix_library_files(@libs)), "\n" if ($want_libfiles); -} - -exit 0; - -#========================================================================== -# Support Routines -#========================================================================== - -sub usage { - print STDERR <<__EOD__; -Usage: llvm-config <OPTION>... [<COMPONENT>...] - -Get various configuration information needed to compile programs which use -LLVM. Typically called from 'configure' scripts. Examples: - llvm-config --cxxflags - llvm-config --ldflags - llvm-config --libs engine bcreader scalaropts - -Options: - --version Print LLVM version. - --prefix Print the installation prefix. - --src-root Print the source root LLVM was built from. - --obj-root Print the object root used to build LLVM. - --bindir Directory containing LLVM executables. - --includedir Directory containing LLVM headers. - --libdir Directory containing LLVM libraries. - --cppflags C preprocessor flags for files that include LLVM headers. - --cflags C compiler flags for files that include LLVM headers. - --cxxflags C++ compiler flags for files that include LLVM headers. - --ldflags Print Linker flags. - --libs Libraries needed to link against LLVM components. - --libnames Bare library names for in-tree builds. - --libfiles Fully qualified library filenames for makefile depends. - --components List of all possible components. - --targets-built List of all targets currently built. - --host-target Target triple used to configure LLVM. - --build-mode Print build mode of LLVM tree (e.g. Debug or Release). -Typical components: - all All LLVM libraries (default). - backend Either a native backend or the C backend. - engine Either a native JIT or a bitcode interpreter. -__EOD__ - exit(1); -} - -# Use -lfoo instead of libfoo.a whenever possible, and add directories to -# files which can't be found using -L. -sub fix_library_names (@) { - my @libs = @_; - my @result; - foreach my $lib (@libs) { - # Transform the bare library name appropriately. - my ($basename) = ($lib =~ /^lib([^.]*)\.a/); - if (defined $basename) { - push @result, "-l$basename"; - } else { - push @result, "$LIBDIR/$lib"; - } - } - return @result; -} - -# Turn the list of libraries into a list of files. -sub fix_library_files(@) { - my @libs = @_; - my @result; - foreach my $lib (@libs) { - # Transform the bare library name into a filename. - push @result, "$LIBDIR/$lib"; - } - return @result; -} - -#========================================================================== -# Library Dependency Analysis -#========================================================================== -# Given a few human-readable library names, find all their dependencies -# and sort them into an order which the linker will like. If we packed -# our libraries into fewer archives, we could make the linker do much -# of this work for us. -# -# Libraries have two different types of names in this code: Human-friendly -# "component" names entered on the command-line, and the raw file names -# we use internally (and ultimately pass to the linker). -# -# To understand this code, you'll need a working knowledge of Perl 5, -# and possibly some quality time with 'man perlref'. - -sub load_dependencies; -sub build_name_map; -sub have_native_backend; -sub find_best_engine; -sub expand_names (@); -sub find_all_required_sets (@); -sub find_all_required_sets_helper ($$@); - -# Each "set" contains one or more libraries which must be included as a -# group (due to cyclic dependencies). Sets are represented as a Perl array -# reference pointing to a list of internal library names. -my @SETS; - -# Various mapping tables. -my %LIB_TO_SET_MAP; # Maps internal library names to their sets. -my %SET_DEPS; # Maps sets to a list of libraries they depend on. -my %NAME_MAP; # Maps human-entered names to internal names. - -# Have our dependencies been loaded yet? -my $DEPENDENCIES_LOADED = 0; - -# Given a list of human-friendly component names, translate them into a -# complete set of linker arguments. -sub expand_dependencies (@) { - my @libs = @_; - load_dependencies; - my @required_sets = find_all_required_sets(expand_names(@libs)); - my @sorted_sets = topologically_sort_sets(@required_sets); - - # Expand the library sets into libraries. - my @result; - foreach my $set (@sorted_sets) { push @result, @{$set}; } - return @result; -} - -# Load in the raw dependency data stored at the end of this file. -sub load_dependencies { - return if $DEPENDENCIES_LOADED; - $DEPENDENCIES_LOADED = 1; - while (<DATA>) { - # Parse our line. - my ($libs, $deps) = /^\s*([^:]+):\s*(.*)\s*$/; - die "Malformed dependency data" unless defined $deps; - my @libs = split(' ', $libs); - my @deps = split(' ', $deps); - - # Record our dependency data. - my $set = \@libs; - push @SETS, $set; - foreach my $lib (@libs) { $LIB_TO_SET_MAP{$lib} = $set; } - $SET_DEPS{$set} = \@deps; - } - build_name_map; -} - -# Build a map converting human-friendly component names into internal -# library names. -sub build_name_map { - # Add entries for all the actual libraries. - foreach my $set (@SETS) { - foreach my $lib (sort @$set) { - my $short_name = $lib; - $short_name =~ s/^(lib)?LLVM([^.]*)\..*$/$2/; - $short_name =~ tr/A-Z/a-z/; - $NAME_MAP{$short_name} = [$lib]; - } - } - - # Add target-specific entries - my @all_targets; - foreach my $target (@TARGETS_BUILT) { - # FIXME: Temporary, until we don't switch all targets - if (defined $NAME_MAP{$target.'asmprinter'}) { - $NAME_MAP{$target} = [$target.'info', - $target.'asmprinter', - $target.'codegen'] - } elsif (defined $NAME_MAP{$target.'codegen'}) { - $NAME_MAP{$target} = [$target.'info', - $target.'codegen'] - } else { - $NAME_MAP{$target} = [$target.'info', - $NAME_MAP{$target}[0]] - } - - if (defined $NAME_MAP{$target.'asmparser'}) { - push @{$NAME_MAP{$target}},$target.'asmparser' - } - - if (defined $NAME_MAP{$target.'disassembler'}) { - push @{$NAME_MAP{$target}},$target.'disassembler' - } - - push @all_targets, $target; - } - - # Add virtual entries. - $NAME_MAP{'native'} = have_native_backend() ? [$ARCH] : []; - $NAME_MAP{'nativecodegen'} = have_native_backend() ? [$ARCH.'codegen'] : []; - $NAME_MAP{'backend'} = have_native_backend() ? ['native'] : ['cbackend']; - $NAME_MAP{'engine'} = find_best_engine; - $NAME_MAP{'all-targets'} = \@all_targets; - $NAME_MAP{'all'} = [name_map_entries]; # Must be last. -} - -# Return true if we have a native backend to use. -sub have_native_backend { - my %BUILT; - foreach my $target (@TARGETS_BUILT) { $BUILT{$target} = 1; } - return defined $NAME_MAP{$ARCH} && defined $BUILT{$ARCH}; -} - -# Find a working subclass of ExecutionEngine for this platform. -sub find_best_engine { - if (have_native_backend && $TARGET_HAS_JIT) { - return ['jit', 'native']; - } else { - return ['interpreter']; - } -} - -# Get all the human-friendly component names. -sub name_map_entries { - load_dependencies; - return sort keys %NAME_MAP; -} - -# Map human-readable names to internal library names. -sub expand_names (@) { - my @names = @_; - my @result; - foreach my $name (@names) { - if (defined $LIB_TO_SET_MAP{$name}) { - # We've hit bottom: An actual library name. - push @result, $name; - } elsif (defined $NAME_MAP{$name}) { - # We've found a short name to expand. - push @result, expand_names(@{$NAME_MAP{$name}}); - } else { - print STDERR "llvm-config: unknown component name: $name\n"; - exit(1); - } - } - return @result; -} - -# Given a list of internal library names, return all sets of libraries which -# will need to be included by the linker (in no particular order). -sub find_all_required_sets (@) { - my @libs = @_; - my %sets_added; - my @result; - find_all_required_sets_helper(\%sets_added, \@result, @libs); - return @result; -} - -# Recursive closures are pretty broken in Perl, so we're going to separate -# this function from find_all_required_sets and pass in the state we need -# manually, as references. Yes, this is fairly unpleasant. -sub find_all_required_sets_helper ($$@) { - my ($sets_added, $result, @libs) = @_; - foreach my $lib (@libs) { - my $set = $LIB_TO_SET_MAP{$lib}; - next if defined $$sets_added{$set}; - $$sets_added{$set} = 1; - push @$result, $set; - find_all_required_sets_helper($sets_added, $result, @{$SET_DEPS{$set}}); - } -} - -# Print a list of sets, with a label. Used for debugging. -sub print_sets ($@) { - my ($label, @sets) = @_; - my @output; - foreach my $set (@sets) { push @output, join(',', @$set); } - print "$label: ", join(';', @output), "\n"; -} - -# Returns true if $lib is a key in $added. -sub has_lib_been_added ($$) { - my ($added, $lib) = @_; - return defined $$added{$LIB_TO_SET_MAP{$lib}}; -} - -# Returns true if all the dependencies of $set appear in $added. -sub have_all_deps_been_added ($$) { - my ($added, $set) = @_; - #print_sets(" Checking", $set); - #print_sets(" Wants", $SET_DEPS{$set}); - foreach my $lib (@{$SET_DEPS{$set}}) { - return 0 unless has_lib_been_added($added, $lib); - } - return 1; -} - -# Given a list of sets, topologically sort them using dependencies. -sub topologically_sort_sets (@) { - my @sets = @_; - my %added; - my @result; - SCAN: while (@sets) { # We'll delete items from @sets as we go. - #print_sets("So far", reverse(@result)); - #print_sets("Remaining", @sets); - for (my $i = 0; $i < @sets; ++$i) { - my $set = $sets[$i]; - if (have_all_deps_been_added(\%added, $set)) { - push @result, $set; - $added{$set} = 1; - #print "Removing $i.\n"; - splice(@sets, $i, 1); - next SCAN; # Restart our scan. - } - } - die "Can't find a library with no dependencies"; - } - return reverse(@result); -} - -# Our library dependency data will be added after the '__END__' token, and will -# be read through the magic <DATA> filehandle. -__END__ diff --git a/tools/llvm-cov/LLVMBuild.txt b/tools/llvm-cov/LLVMBuild.txt new file mode 100644 index 0000000..87e00d1 --- /dev/null +++ b/tools/llvm-cov/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-cov/LLVMBuild.txt ---------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-cov +parent = Tools +required_libraries = Instrumentation diff --git a/tools/llvm-diff/DiffConsumer.cpp b/tools/llvm-diff/DiffConsumer.cpp index c23e8fb..d9e1814 100644 --- a/tools/llvm-diff/DiffConsumer.cpp +++ b/tools/llvm-diff/DiffConsumer.cpp @@ -64,6 +64,10 @@ void DiffConsumer::printValue(Value *V, bool isL) { } return; } + if (isa<Constant>(V)) { + out << *V; + return; + } unsigned N = contexts.size(); while (N > 0) { diff --git a/tools/llvm-diff/DifferenceEngine.cpp b/tools/llvm-diff/DifferenceEngine.cpp index b240d8c..435cd87 100644 --- a/tools/llvm-diff/DifferenceEngine.cpp +++ b/tools/llvm-diff/DifferenceEngine.cpp @@ -327,7 +327,7 @@ class FunctionDifferenceEngine { if (LCase) { if (TryUnify) tryUnify(LCase, RI->getSuccessor(I)); LCases.erase(CaseValue); - } else if (!Difference) { + } else if (Complain || !Difference) { if (Complain) Engine.logf("right switch has extra case %r") << CaseValue; Difference = true; diff --git a/tools/llvm-diff/LLVMBuild.txt b/tools/llvm-diff/LLVMBuild.txt new file mode 100644 index 0000000..fa06a03 --- /dev/null +++ b/tools/llvm-diff/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-diff/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-diff +parent = Tools +required_libraries = AsmParser BitReader diff --git a/tools/llvm-dis/Android.mk b/tools/llvm-dis/Android.mk new file mode 100644 index 0000000..22d44fd --- /dev/null +++ b/tools/llvm-dis/Android.mk @@ -0,0 +1,25 @@ +LOCAL_PATH:= $(call my-dir) + +llvm_dis_SRC_FILES := \ + llvm-dis.cpp + +include $(CLEAR_VARS) + +LOCAL_MODULE := llvm-dis +LOCAL_MODULE_CLASS := EXECUTABLES +LOCAL_MODULE_TAGS := optional +LOCAL_SRC_FILES := $(llvm_dis_SRC_FILES) +LOCAL_LDLIBS += -lpthread -lm -ldl + +REQUIRES_EH := 1 +REQUIRES_RTTI := 1 + +LOCAL_STATIC_LIBRARIES := \ + libLLVMAnalysis \ + libLLVMBitReader \ + libLLVMCore \ + libLLVMSupport + +include $(LLVM_HOST_BUILD_MK) +include $(LLVM_GEN_INTRINSICS_MK) +include $(BUILD_HOST_EXECUTABLE) diff --git a/tools/llvm-dis/LLVMBuild.txt b/tools/llvm-dis/LLVMBuild.txt new file mode 100644 index 0000000..4525010 --- /dev/null +++ b/tools/llvm-dis/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-dis/LLVMBuild.txt ---------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-dis +parent = Tools +required_libraries = Analysis BitReader diff --git a/tools/llvm-dwarfdump/LLVMBuild.txt b/tools/llvm-dwarfdump/LLVMBuild.txt new file mode 100644 index 0000000..28b7c4c --- /dev/null +++ b/tools/llvm-dwarfdump/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-dwarfdump/LLVMBuild.txt ---------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-dwarfdump +parent = Tools +required_libraries = DebugInfo Object diff --git a/tools/llvm-extract/LLVMBuild.txt b/tools/llvm-extract/LLVMBuild.txt new file mode 100644 index 0000000..1b1a4c3 --- /dev/null +++ b/tools/llvm-extract/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-extract/LLVMBuild.txt -----------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-extract +parent = Tools +required_libraries = AsmParser BitReader BitWriter IPO diff --git a/tools/llvm-ld/Android.mk b/tools/llvm-ld/Android.mk new file mode 100644 index 0000000..22c65fb --- /dev/null +++ b/tools/llvm-ld/Android.mk @@ -0,0 +1,37 @@ +LOCAL_PATH:= $(call my-dir) + +llvm_ld_SRC_FILES := \ + Optimize.cpp \ + llvm-ld.cpp + +llvm_ld_STATIC_LIBRARIES := \ + libLLVMBitWriter \ + libLLVMLinker \ + libLLVMBitReader \ + libLLVMArchive \ + libLLVMipo \ + libLLVMScalarOpts \ + libLLVMInstCombine \ + libLLVMTransformUtils \ + libLLVMipa \ + libLLVMAnalysis \ + libLLVMTarget \ + libLLVMCore \ + libLLVMSupport + +#===---------------------------------------------------------------=== +# llvm-ld command line tool (host) +#===---------------------------------------------------------------=== + +include $(CLEAR_VARS) + +LOCAL_MODULE := llvm-ld +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := EXECUTABLES +LOCAL_SRC_FILES := $(llvm_ld_SRC_FILES) +LOCAL_STATIC_LIBRARIES := $(llvm_ld_STATIC_LIBRARIES) +LOCAL_LDLIBS += -lpthread -lm -ldl + +include $(LLVM_HOST_BUILD_MK) +include $(LLVM_GEN_INTRINSICS_MK) +include $(BUILD_HOST_EXECUTABLE) diff --git a/tools/llvm-ld/LLVMBuild.txt b/tools/llvm-ld/LLVMBuild.txt new file mode 100644 index 0000000..eed0452 --- /dev/null +++ b/tools/llvm-ld/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-ld/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-ld +parent = Tools +required_libraries = Archive BitWriter IPO Linker Scalar diff --git a/tools/llvm-link/LLVMBuild.txt b/tools/llvm-link/LLVMBuild.txt new file mode 100644 index 0000000..6399ded --- /dev/null +++ b/tools/llvm-link/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-link/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-link +parent = Tools +required_libraries = AsmParser BitReader BitWriter Linker diff --git a/tools/llvm-mc/Disassembler.cpp b/tools/llvm-mc/Disassembler.cpp index e006488..1b5aa57 100644 --- a/tools/llvm-mc/Disassembler.cpp +++ b/tools/llvm-mc/Disassembler.cpp @@ -249,7 +249,6 @@ int Disassembler::disassembleEnhanced(const std::string &TS, break; } - EDDisassembler::initialize(); OwningPtr<EDDisassembler> disassembler(EDDisassembler::getDisassembler(TS.c_str(), AS)); diff --git a/tools/llvm-mc/LLVMBuild.txt b/tools/llvm-mc/LLVMBuild.txt new file mode 100644 index 0000000..dff5358 --- /dev/null +++ b/tools/llvm-mc/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-mc/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-mc +parent = Tools +required_libraries = MC MCDisassembler MCParser Support all-targets diff --git a/tools/llvm-mc/llvm-mc.cpp b/tools/llvm-mc/llvm-mc.cpp index 280a1bb..4281259 100644 --- a/tools/llvm-mc/llvm-mc.cpp +++ b/tools/llvm-mc/llvm-mc.cpp @@ -152,6 +152,10 @@ NoInitialTextSection("n", cl::desc("Don't assume assembly file starts " static cl::opt<bool> SaveTempLabels("L", cl::desc("Don't discard temporary labels")); +static cl::opt<bool> +GenDwarfForAssembly("g", cl::desc("Generate dwarf debugging info for assembly " + "source files")); + enum ActionType { AC_AsLex, AC_Assemble, @@ -175,7 +179,7 @@ Action(cl::desc("Action to perform:"), static const Target *GetTarget(const char *ProgName) { // Figure out the target triple. if (TripleName.empty()) - TripleName = sys::getHostTriple(); + TripleName = sys::getDefaultTargetTriple(); Triple TheTriple(Triple::normalize(TripleName)); const Target *TheTarget = 0; @@ -230,6 +234,17 @@ static tool_output_file *GetOutputStream() { return Out; } +static std::string DwarfDebugFlags; +static void setDwarfDebugFlags(int argc, char **argv) { + if (!getenv("RC_DEBUG_OPTIONS")) + return; + for (int i = 0; i < argc; i++) { + DwarfDebugFlags += argv[i]; + if (i + 1 < argc) + DwarfDebugFlags += " "; + } +} + static int AsLexInput(const char *ProgName) { OwningPtr<MemoryBuffer> BufferPtr; if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) { @@ -377,6 +392,10 @@ static int AssembleInput(const char *ProgName) { if (SaveTempLabels) Ctx.setAllowTemporaryLabels(false); + Ctx.setGenDwarfForAssembly(GenDwarfForAssembly); + if (!DwarfDebugFlags.empty()) + Ctx.setDwarfDebugFlags(StringRef(DwarfDebugFlags)); + // Package up features to be passed to target/subtarget std::string FeaturesStr; if (MAttrs.size()) { @@ -412,7 +431,7 @@ static int AssembleInput(const char *ProgName) { /*useCFI*/ true, /*useDwarfDirectory*/ true, IP, CE, MAB, ShowInst)); - + } else if (FileType == OFT_Null) { Str.reset(createNullStreamer(Ctx)); } else { @@ -502,6 +521,7 @@ int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); TripleName = Triple::normalize(TripleName); + setDwarfDebugFlags(argc, argv); switch (Action) { default: diff --git a/tools/llvm-nm/LLVMBuild.txt b/tools/llvm-nm/LLVMBuild.txt new file mode 100644 index 0000000..38ecbfd --- /dev/null +++ b/tools/llvm-nm/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-nm/LLVMBuild.txt ----------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-nm +parent = Tools +required_libraries = Archive BitReader Object diff --git a/tools/llvm-nm/llvm-nm.cpp b/tools/llvm-nm/llvm-nm.cpp index 550ca4f..3e159c7 100644 --- a/tools/llvm-nm/llvm-nm.cpp +++ b/tools/llvm-nm/llvm-nm.cpp @@ -27,6 +27,7 @@ #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Signals.h" #include "llvm/Support/Format.h" @@ -110,6 +111,19 @@ namespace { std::string ToolName; } + +static void error(Twine message, Twine path = Twine()) { + errs() << ToolName << ": " << path << ": " << message << ".\n"; +} + +static bool error(error_code ec, Twine path = Twine()) { + if (ec) { + error(ec.message(), path); + return true; + } + return false; +} + namespace { struct NMSymbol { uint64_t Address; @@ -144,14 +158,6 @@ namespace { StringRef CurrentFilename; typedef std::vector<NMSymbol> SymbolListT; SymbolListT SymbolList; - - bool error(error_code ec) { - if (!ec) return false; - - outs() << ToolName << ": error reading file: " << ec.message() << ".\n"; - outs().flush(); - return true; - } } static void SortAndPrintSymbolList() { @@ -192,9 +198,9 @@ static void SortAndPrintSymbolList() { strcpy(SymbolSizeStr, " "); if (i->Address != object::UnknownAddressOrSize) - format("%08x", i->Address).print(SymbolAddrStr, sizeof(SymbolAddrStr)); + format("%08"PRIx64, i->Address).print(SymbolAddrStr, sizeof(SymbolAddrStr)); if (i->Size != object::UnknownAddressOrSize) - format("%08x", i->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr)); + format("%08"PRIx64, i->Size).print(SymbolSizeStr, sizeof(SymbolSizeStr)); if (OutputFormat == posix) { outs() << i->Name << " " << i->TypeChar << " " @@ -286,7 +292,7 @@ static void DumpSymbolNamesFromObject(ObjectFile *obj) { if (error(i->getSize(s.Size))) break; } if (PrintAddress) - if (error(i->getOffset(s.Address))) break; + if (error(i->getAddress(s.Address))) break; if (error(i->getNMTypeChar(s.TypeChar))) break; if (error(i->getName(s.Name))) break; SymbolList.push_back(s); @@ -297,33 +303,34 @@ static void DumpSymbolNamesFromObject(ObjectFile *obj) { } static void DumpSymbolNamesFromFile(std::string &Filename) { + if (Filename != "-" && !sys::fs::exists(Filename)) { + errs() << ToolName << ": '" << Filename << "': " << "No such file\n"; + return; + } + + OwningPtr<MemoryBuffer> Buffer; + if (error(MemoryBuffer::getFileOrSTDIN(Filename, Buffer), Filename)) + return; + + sys::fs::file_magic magic = sys::fs::identify_magic(Buffer->getBuffer()); + LLVMContext &Context = getGlobalContext(); std::string ErrorMessage; - sys::Path aPath(Filename); - bool exists; - if (sys::fs::exists(aPath.str(), exists) || !exists) - errs() << ToolName << ": '" << Filename << "': " << "No such file\n"; - // Note: Currently we do not support reading an archive from stdin. - if (Filename == "-" || aPath.isBitcodeFile()) { - OwningPtr<MemoryBuffer> Buffer; - if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buffer)) - ErrorMessage = ec.message(); + if (magic == sys::fs::file_magic::bitcode) { Module *Result = 0; - if (Buffer.get()) - Result = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage); - + Result = ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage); if (Result) { DumpSymbolNamesFromModule(Result); delete Result; - } else - errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; - - } else if (aPath.isArchive()) { - OwningPtr<Binary> arch; - if (error_code ec = object::createBinary(aPath.str(), arch)) { - errs() << ToolName << ": " << Filename << ": " << ec.message() << ".\n"; + } else { + error(ErrorMessage, Filename); return; } + } else if (magic == sys::fs::file_magic::archive) { + OwningPtr<Binary> arch; + if (error(object::createBinary(Buffer.take(), arch), Filename)) + return; + if (object::Archive *a = dyn_cast<object::Archive>(arch.get())) { for (object::Archive::child_iterator i = a->begin_children(), e = a->end_children(); i != e; ++i) { @@ -347,12 +354,10 @@ static void DumpSymbolNamesFromFile(std::string &Filename) { } } } - } else if (aPath.isObjectFile()) { + } else if (magic.is_object()) { OwningPtr<Binary> obj; - if (error_code ec = object::createBinary(aPath.str(), obj)) { - errs() << ToolName << ": " << Filename << ": " << ec.message() << ".\n"; + if (error(object::createBinary(Buffer.take(), obj), Filename)) return; - } if (object::ObjectFile *o = dyn_cast<ObjectFile>(obj.get())) DumpSymbolNamesFromObject(o); } else { @@ -370,6 +375,10 @@ int main(int argc, char **argv) { llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. cl::ParseCommandLineOptions(argc, argv, "llvm symbol table dumper\n"); + // llvm-nm only reads binary files. + if (error(sys::Program::ChangeStdinToBinary())) + return 1; + ToolName = argv[0]; if (BSDFormat) OutputFormat = bsd; if (POSIXFormat) OutputFormat = posix; diff --git a/tools/llvm-objdump/LLVMBuild.txt b/tools/llvm-objdump/LLVMBuild.txt new file mode 100644 index 0000000..d16c501 --- /dev/null +++ b/tools/llvm-objdump/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-objdump/LLVMBuild.txt -----------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-objdump +parent = Tools +required_libraries = DebugInfo MC MCDisassembler MCParser Object all-targets diff --git a/tools/llvm-objdump/MachODump.cpp b/tools/llvm-objdump/MachODump.cpp index c61ec4c..ffeea88 100644 --- a/tools/llvm-objdump/MachODump.cpp +++ b/tools/llvm-objdump/MachODump.cpp @@ -385,7 +385,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) { bool symbolTableWorked = false; // Parse relocations. - std::vector<std::pair<uint64_t, uint32_t> > Relocs; + std::vector<std::pair<uint64_t, SymbolRef> > Relocs; error_code ec; for (relocation_iterator RI = Sections[SectIdx].begin_relocations(), RE = Sections[SectIdx].end_relocations(); RI != RE; RI.increment(ec)) { @@ -394,10 +394,10 @@ void llvm::DisassembleInputMachO(StringRef Filename) { Sections[SectIdx].getAddress(SectionAddress); RelocOffset -= SectionAddress; - uint32_t RelocInfo; - RI->getType(RelocInfo); + SymbolRef RelocSym; + RI->getSymbol(RelocSym); - Relocs.push_back(std::make_pair(RelocOffset, RelocInfo)); + Relocs.push_back(std::make_pair(RelocOffset, RelocSym)); } array_pod_sort(Relocs.begin(), Relocs.end()); @@ -419,7 +419,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) { // Start at the address of the symbol relative to the section's address. uint64_t Start = 0; - Symbols[SymIdx].getOffset(Start); + Symbols[SymIdx].getAddress(Start); // Stop disassembling either at the beginning of the next symbol or at // the end of the section. @@ -432,7 +432,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) { if (NextSymType == SymbolRef::ST_Function) { Sections[SectIdx].containsSymbol(Symbols[NextSymIdx], containsNextSym); - Symbols[NextSymIdx].getOffset(NextSym); + Symbols[NextSymIdx].getAddress(NextSym); break; } ++NextSymIdx; @@ -459,7 +459,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) { DebugOut, nulls())) { uint64_t SectAddress = 0; Sections[SectIdx].getAddress(SectAddress); - outs() << format("%8llx:\t", SectAddress + Index); + outs() << format("%8" PRIx64 ":\t", SectAddress + Index); DumpBytes(StringRef(Bytes.data() + Index, Size)); IP->printInst(&Inst, outs(), ""); @@ -579,7 +579,7 @@ void llvm::DisassembleInputMachO(StringRef Filename) { outs() << FunctionMap[SectAddress + Inst.Address]-> getName() << ":\n"; - outs() << format("%8llx:\t", SectAddress + Inst.Address); + outs() << format("%8" PRIx64 ":\t", SectAddress + Inst.Address); DumpBytes(StringRef(Bytes.data() + Inst.Address, Inst.Size)); if (fi->second.contains(fi->first)) // Indent simple loops. @@ -594,8 +594,8 @@ void llvm::DisassembleInputMachO(StringRef Filename) { Relocs[j].first < SectAddress + Inst.Address + Inst.Size) { StringRef SymName; uint64_t Addr; - UnsortedSymbols[Relocs[j].second].getName(SymName); - UnsortedSymbols[Relocs[j].second].getAddress(Addr); + Relocs[j].second.getAddress(Addr); + Relocs[j].second.getName(SymName); outs() << "\t# " << SymName << ' '; DumpAddress(Addr, Sections, MachOObj, outs()); diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index 0b6bd22..bcfecb3 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -186,7 +186,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { bool contains; if (!error(i->containsSymbol(*si, contains)) && contains) { uint64_t Address; - if (error(si->getOffset(Address))) break; + if (error(si->getAddress(Address))) break; StringRef Name; if (error(si->getName(Name))) break; Symbols.push_back(std::make_pair(Address, Name)); @@ -289,7 +289,7 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { if (DisAsm->getInstruction(Inst, Size, memoryObject, Index, DebugOut, nulls())) { - outs() << format("%8x:\t", SectionAddr + Index); + outs() << format("%8"PRIx64":\t", SectionAddr + Index); DumpBytes(StringRef(Bytes.data() + Index, Size)); IP->printInst(&Inst, outs(), ""); outs() << "\n"; @@ -301,16 +301,22 @@ static void DisassembleObject(const ObjectFile *Obj, bool InlineRelocs) { // Print relocation for instruction. while (rel_cur != rel_end) { + bool hidden = false; uint64_t addr; SmallString<16> name; SmallString<32> val; + + // If this relocation is hidden, skip it. + if (error(rel_cur->getHidden(hidden))) goto skip_print_rel; + if (hidden) goto skip_print_rel; + if (error(rel_cur->getAddress(addr))) goto skip_print_rel; // Stop when rel_cur's address is past the current instruction. - if (addr > Index + Size) break; + if (addr >= Index + Size) break; if (error(rel_cur->getTypeName(name))) goto skip_print_rel; if (error(rel_cur->getValueString(val))) goto skip_print_rel; - outs() << format("\t\t\t%8x: ", SectionAddr + addr) << name << "\t" + outs() << format("\t\t\t%8"PRIx64": ", SectionAddr + addr) << name << "\t" << val << "\n"; skip_print_rel: @@ -336,9 +342,12 @@ static void PrintRelocations(const ObjectFile *o) { ri != re; ri.increment(ec)) { if (error(ec)) return; + bool hidden; uint64_t address; SmallString<32> relocname; SmallString<32> valuestr; + if (error(ri->getHidden(hidden))) continue; + if (hidden) continue; if (error(ri->getTypeName(relocname))) continue; if (error(ri->getAddress(address))) continue; if (error(ri->getValueString(valuestr))) continue; @@ -391,7 +400,7 @@ static void PrintSectionContents(const ObjectFile *o) { // Dump out the content as hex and printable ascii characters. for (std::size_t addr = 0, end = Contents.size(); addr < end; addr += 16) { - outs() << format(" %04x ", BaseAddr + addr); + outs() << format(" %04"PRIx64" ", BaseAddr + addr); // Dump line of hex. for (std::size_t i = 0; i < 16; ++i) { if (i != 0 && i % 4 == 0) @@ -468,7 +477,7 @@ static void PrintSymbolTable(const ObjectFile *o) { se = o->end_symbols(); si != se; si.increment(ec)) { if (error(ec)) return; StringRef Name; - uint64_t Offset; + uint64_t Address; bool Global; SymbolRef::Type Type; bool Weak; @@ -476,7 +485,7 @@ static void PrintSymbolTable(const ObjectFile *o) { uint64_t Size; section_iterator Section = o->end_sections(); if (error(si->getName(Name))) continue; - if (error(si->getOffset(Offset))) continue; + if (error(si->getAddress(Address))) continue; if (error(si->isGlobal(Global))) continue; if (error(si->getType(Type))) continue; if (error(si->isWeak(Weak))) continue; @@ -484,8 +493,10 @@ static void PrintSymbolTable(const ObjectFile *o) { if (error(si->getSize(Size))) continue; if (error(si->getSection(Section))) continue; - if (Offset == UnknownAddressOrSize) - Offset = 0; + if (Address == UnknownAddressOrSize) + Address = 0; + if (Size == UnknownAddressOrSize) + Size = 0; char GlobLoc = ' '; if (Type != SymbolRef::ST_External) GlobLoc = Global ? 'g' : 'l'; @@ -497,7 +508,7 @@ static void PrintSymbolTable(const ObjectFile *o) { else if (Type == SymbolRef::ST_Function) FileFunc = 'F'; - outs() << format("%08x", Offset) << " " + outs() << format("%08"PRIx64, Address) << " " << GlobLoc // Local -> 'l', Global -> 'g', Neither -> ' ' << (Weak ? 'w' : ' ') // Weak? << ' ' // Constructor. Not supported yet. @@ -517,7 +528,7 @@ static void PrintSymbolTable(const ObjectFile *o) { outs() << SectionName; } outs() << '\t' - << format("%08x ", Size) + << format("%08"PRIx64" ", Size) << Name << '\n'; } @@ -547,8 +558,10 @@ static void DumpArchive(const Archive *a) { e = a->end_children(); i != e; ++i) { OwningPtr<Binary> child; if (error_code ec = i->getAsBinary(child)) { - errs() << ToolName << ": '" << a->getFileName() << "': " << ec.message() - << ".\n"; + // Ignore non-object files. + if (ec != object_error::invalid_file_type) + errs() << ToolName << ": '" << a->getFileName() << "': " << ec.message() + << ".\n"; continue; } if (ObjectFile *o = dyn_cast<ObjectFile>(child.get())) diff --git a/tools/llvm-prof/LLVMBuild.txt b/tools/llvm-prof/LLVMBuild.txt new file mode 100644 index 0000000..d59127c --- /dev/null +++ b/tools/llvm-prof/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-prof/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-prof +parent = Tools +required_libraries = Analysis BitReader diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp index 9d0b468..d9b6713 100644 --- a/tools/llvm-prof/llvm-prof.cpp +++ b/tools/llvm-prof/llvm-prof.cpp @@ -200,9 +200,9 @@ bool ProfileInfoPrinterPass::runOnModule(Module &M) { } outs() << format("%3d", i+1) << ". " - << format("%5.2g", FunctionCounts[i].second) << "/" - << format("%g", TotalExecutions) << " " - << FunctionCounts[i].first->getNameStr() << "\n"; + << format("%5.2g", FunctionCounts[i].second) << "/" + << format("%g", TotalExecutions) << " " + << FunctionCounts[i].first->getName() << "\n"; } std::set<Function*> FunctionsToPrint; @@ -225,12 +225,12 @@ bool ProfileInfoPrinterPass::runOnModule(Module &M) { for (unsigned i = 0; i != BlocksToPrint; ++i) { if (Counts[i].second == 0) break; Function *F = Counts[i].first->getParent(); - outs() << format("%3d", i+1) << ". " - << format("%5g", Counts[i].second/(double)TotalExecutions*100) << "% " - << format("%5.0f", Counts[i].second) << "/" - << format("%g", TotalExecutions) << "\t" - << F->getNameStr() << "() - " - << Counts[i].first->getNameStr() << "\n"; + outs() << format("%3d", i+1) << ". " + << format("%5g", Counts[i].second/(double)TotalExecutions*100)<<"% " + << format("%5.0f", Counts[i].second) << "/" + << format("%g", TotalExecutions) << "\t" + << F->getName() << "() - " + << Counts[i].first->getName() << "\n"; FunctionsToPrint.insert(F); } diff --git a/tools/llvm-ranlib/LLVMBuild.txt b/tools/llvm-ranlib/LLVMBuild.txt new file mode 100644 index 0000000..23015c5 --- /dev/null +++ b/tools/llvm-ranlib/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-ranlib/LLVMBuild.txt ------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-ranlib +parent = Tools +required_libraries = Archive diff --git a/tools/llvm-rtdyld/LLVMBuild.txt b/tools/llvm-rtdyld/LLVMBuild.txt new file mode 100644 index 0000000..b36d13c --- /dev/null +++ b/tools/llvm-rtdyld/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-rtdyld/LLVMBuild.txt ------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-rtdyld +parent = Tools +required_libraries = JIT MC Object RuntimeDyld Support all-targets diff --git a/tools/llvm-size/LLVMBuild.txt b/tools/llvm-size/LLVMBuild.txt new file mode 100644 index 0000000..b4c538a --- /dev/null +++ b/tools/llvm-size/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-size/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-size +parent = Tools +required_libraries = Object diff --git a/tools/llvm-size/llvm-size.cpp b/tools/llvm-size/llvm-size.cpp index 70e5cb9..462da40 100644 --- a/tools/llvm-size/llvm-size.cpp +++ b/tools/llvm-size/llvm-size.cpp @@ -96,13 +96,13 @@ static void PrintObjectSectionSizes(ObjectFile *o) { const char *radix_fmt = 0; switch (Radix) { case octal: - radix_fmt = "llo"; + radix_fmt = PRIo64; break; case decimal: - radix_fmt = "llu"; + radix_fmt = PRIu64; break; case hexadecimal: - radix_fmt = "llx"; + radix_fmt = PRIx64; break; } if (OutputFormat == sysv) { @@ -223,8 +223,8 @@ static void PrintObjectSectionSizes(ObjectFile *o) { total_data, total_bss); fmtbuf.clear(); - fmt << "%7" << (Radix == octal ? "llo" : "llu") << " " - << "%7llx "; + fmt << "%7" << (Radix == octal ? PRIo64 : PRIu64) << " " + << "%7" PRIx64 " "; outs() << format(fmt.str().c_str(), total, total); diff --git a/tools/llvm-stub/LLVMBuild.txt b/tools/llvm-stub/LLVMBuild.txt new file mode 100644 index 0000000..5c3534c --- /dev/null +++ b/tools/llvm-stub/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-stub/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-stub +parent = Tools +required_libraries = diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp index 6c8dbad..77d7dfe 100644 --- a/tools/lto/LTOCodeGenerator.cpp +++ b/tools/lto/LTOCodeGenerator.cpp @@ -90,10 +90,6 @@ LTOCodeGenerator::~LTOCodeGenerator() bool LTOCodeGenerator::addModule(LTOModule* mod, std::string& errMsg) { - - if(mod->getLLVVMModule()->MaterializeAllPermanently(&errMsg)) - return true; - bool ret = _linker.LinkInModule(mod->getLLVVMModule(), &errMsg); const std::vector<const char*> &undefs = mod->getAsmUndefinedRefs(); @@ -243,7 +239,7 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) if ( _target == NULL ) { std::string Triple = _linker.getModule()->getTargetTriple(); if (Triple.empty()) - Triple = sys::getHostTriple(); + Triple = sys::getDefaultTargetTriple(); // create target machine from info for merged modules const Target *march = TargetRegistry::lookupTarget(Triple, errMsg); @@ -269,7 +265,8 @@ bool LTOCodeGenerator::determineTarget(std::string& errMsg) SubtargetFeatures Features; Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); std::string FeatureStr = Features.getString(); - _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, + TargetOptions Options; + _target = march->createTargetMachine(Triple, _mCpu, FeatureStr, Options, RelocModel); } return false; diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index 4ba8985..0b73729 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -30,9 +30,7 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/system_error.h" -#include "llvm/Target/Mangler.h" #include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCContext.h" #include "llvm/MC/MCExpr.h" #include "llvm/MC/MCInst.h" #include "llvm/MC/MCParser/MCAsmParser.h" @@ -63,7 +61,6 @@ bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length, return isTargetMatch(buffer, triplePrefix); } - bool LTOModule::isBitcodeFileForTarget(const char *path, const char *triplePrefix) { OwningPtr<MemoryBuffer> buffer; @@ -76,13 +73,14 @@ bool LTOModule::isBitcodeFileForTarget(const char *path, bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) { std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext()); delete buffer; - return (strncmp(Triple.c_str(), triplePrefix, - strlen(triplePrefix)) == 0); + return strncmp(Triple.c_str(), triplePrefix, strlen(triplePrefix)) == 0; } LTOModule::LTOModule(Module *m, TargetMachine *t) - : _module(m), _target(t) + : _module(m), _target(t), + _context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(), NULL), + _mangler(_context, *_target->getTargetData()) { } @@ -97,8 +95,7 @@ LTOModule *LTOModule::makeLTOModule(const char *path, } LTOModule *LTOModule::makeLTOModule(int fd, const char *path, - size_t size, - std::string &errMsg) { + size_t size, std::string &errMsg) { return makeLTOModule(fd, path, size, size, 0, errMsg); } @@ -122,7 +119,6 @@ MemoryBuffer *LTOModule::makeBuffer(const void *mem, size_t length) { return MemoryBuffer::getMemBuffer(StringRef(startPtr, length), "", false); } - LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length, std::string &errMsg) { OwningPtr<MemoryBuffer> buffer(makeBuffer(mem, length)); @@ -151,7 +147,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, std::string Triple = m->getTargetTriple(); if (Triple.empty()) - Triple = sys::getHostTriple(); + Triple = sys::getDefaultTargetTriple(); // find machine architecture for this module const Target *march = TargetRegistry::lookupTarget(Triple, errMsg); @@ -163,17 +159,18 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer, Features.getDefaultSubtargetFeatures(llvm::Triple(Triple)); std::string FeatureStr = Features.getString(); std::string CPU; - TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr); + TargetOptions Options; + TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr, + Options); LTOModule *Ret = new LTOModule(m.take(), target); - bool Err = Ret->ParseSymbols(errMsg); - if (Err) { + if (Ret->ParseSymbols(errMsg)) { delete Ret; return NULL; } + return Ret; } - const char *LTOModule::getTargetTriple() { return _module->getTargetTriple().c_str(); } @@ -182,9 +179,9 @@ void LTOModule::setTargetTriple(const char *triple) { _module->setTargetTriple(triple); } -void LTOModule::addDefinedFunctionSymbol(Function *f, Mangler &mangler) { +void LTOModule::addDefinedFunctionSymbol(Function *f) { // add to list of defined symbols - addDefinedSymbol(f, mangler, true); + addDefinedSymbol(f, true); } // Get string that data pointer points to. @@ -206,83 +203,84 @@ bool LTOModule::objcClassNameFromExpression(Constant *c, std::string &name) { // Parse i386/ppc ObjC class data structure. void LTOModule::addObjCClass(GlobalVariable *clgv) { - if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) { - // second slot in __OBJC,__class is pointer to superclass name - std::string superclassName; - if (objcClassNameFromExpression(c->getOperand(1), superclassName)) { - NameAndAttributes info; - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(superclassName); - if (!entry.getValue().name) { - const char *symbolName = entry.getKey().data(); - info.name = symbolName; - info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - entry.setValue(info); - } - } - // third slot in __OBJC,__class is pointer to class name - std::string className; - if (objcClassNameFromExpression(c->getOperand(2), className)) { - StringSet::value_type &entry = - _defines.GetOrCreateValue(className); - entry.setValue(1); - NameAndAttributes info; - info.name = entry.getKey().data(); - info.attributes = (lto_symbol_attributes) - (LTO_SYMBOL_PERMISSIONS_DATA | - LTO_SYMBOL_DEFINITION_REGULAR | - LTO_SYMBOL_SCOPE_DEFAULT); - _symbols.push_back(info); + ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer()); + if (!c) return; + + // second slot in __OBJC,__class is pointer to superclass name + std::string superclassName; + if (objcClassNameFromExpression(c->getOperand(1), superclassName)) { + NameAndAttributes info; + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(superclassName); + if (!entry.getValue().name) { + const char *symbolName = entry.getKey().data(); + info.name = symbolName; + info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + entry.setValue(info); } } + + // third slot in __OBJC,__class is pointer to class name + std::string className; + if (objcClassNameFromExpression(c->getOperand(2), className)) { + StringSet::value_type &entry = _defines.GetOrCreateValue(className); + entry.setValue(1); + NameAndAttributes info; + info.name = entry.getKey().data(); + info.attributes = lto_symbol_attributes(LTO_SYMBOL_PERMISSIONS_DATA | + LTO_SYMBOL_DEFINITION_REGULAR | + LTO_SYMBOL_SCOPE_DEFAULT); + _symbols.push_back(info); + } } // Parse i386/ppc ObjC category data structure. void LTOModule::addObjCCategory(GlobalVariable *clgv) { - if (ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer())) { - // second slot in __OBJC,__category is pointer to target class name - std::string targetclassName; - if (objcClassNameFromExpression(c->getOperand(1), targetclassName)) { - NameAndAttributes info; + ConstantStruct *c = dyn_cast<ConstantStruct>(clgv->getInitializer()); + if (!c) return; - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(targetclassName); + // second slot in __OBJC,__category is pointer to target class name + std::string targetclassName; + if (!objcClassNameFromExpression(c->getOperand(1), targetclassName)) + return; - if (entry.getValue().name) - return; + NameAndAttributes info; + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(targetclassName); - const char *symbolName = entry.getKey().data(); - info.name = symbolName; - info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - entry.setValue(info); - } - } + if (entry.getValue().name) + return; + + const char *symbolName = entry.getKey().data(); + info.name = symbolName; + info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + entry.setValue(info); } // Parse i386/ppc ObjC class list data structure. void LTOModule::addObjCClassRef(GlobalVariable *clgv) { std::string targetclassName; - if (objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) { - NameAndAttributes info; + if (!objcClassNameFromExpression(clgv->getInitializer(), targetclassName)) + return; - StringMap<NameAndAttributes>::value_type &entry = - _undefines.GetOrCreateValue(targetclassName); - if (entry.getValue().name) - return; + NameAndAttributes info; + StringMap<NameAndAttributes>::value_type &entry = + _undefines.GetOrCreateValue(targetclassName); + if (entry.getValue().name) + return; - const char *symbolName = entry.getKey().data(); - info.name = symbolName; - info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; - entry.setValue(info); - } + const char *symbolName = entry.getKey().data(); + info.name = symbolName; + info.attributes = LTO_SYMBOL_DEFINITION_UNDEFINED; + entry.setValue(info); } -void LTOModule::addDefinedDataSymbol(GlobalValue *v, Mangler &mangler) { +void LTOModule::addDefinedDataSymbol(GlobalValue *v) { // Add to list of defined symbols. - addDefinedSymbol(v, mangler, false); + addDefinedSymbol(v, false); // Special case i386/ppc ObjC data structures in magic sections: // The issue is that the old ObjC object format did some strange @@ -327,16 +325,14 @@ void LTOModule::addDefinedDataSymbol(GlobalValue *v, Mangler &mangler) { } } - -void LTOModule::addDefinedSymbol(GlobalValue *def, Mangler &mangler, - bool isFunction) { +void LTOModule::addDefinedSymbol(GlobalValue *def, bool isFunction) { // ignore all llvm.* symbols if (def->getName().startswith("llvm.")) return; // string is owned by _defines SmallString<64> Buffer; - mangler.getNameWithPrefix(Buffer, def, false); + _mangler.getNameWithPrefix(Buffer, def, false); // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); @@ -426,8 +422,7 @@ void LTOModule::addAsmGlobalSymbolUndef(const char *name) { entry.setValue(info); } -void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, - Mangler &mangler) { +void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl) { // ignore all llvm.* symbols if (decl->getName().startswith("llvm.")) return; @@ -437,7 +432,7 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, return; SmallString<64> name; - mangler.getNameWithPrefix(name, decl, false); + _mangler.getNameWithPrefix(name, decl, false); StringMap<NameAndAttributes>::value_type &entry = _undefines.GetOrCreateValue(name); @@ -457,7 +452,6 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue *decl, entry.setValue(info); } - namespace { class RecordStreamer : public MCStreamer { public: @@ -613,17 +607,17 @@ namespace { }; } -bool LTOModule::addAsmGlobalSymbols(MCContext &Context, std::string &errMsg) { +bool LTOModule::addAsmGlobalSymbols(std::string &errMsg) { const std::string &inlineAsm = _module->getModuleInlineAsm(); if (inlineAsm.empty()) return false; - OwningPtr<RecordStreamer> Streamer(new RecordStreamer(Context)); + OwningPtr<RecordStreamer> Streamer(new RecordStreamer(_context)); MemoryBuffer *Buffer = MemoryBuffer::getMemBuffer(inlineAsm); SourceMgr SrcMgr; SrcMgr.AddNewSourceBuffer(Buffer, SMLoc()); OwningPtr<MCAsmParser> Parser(createMCAsmParser(SrcMgr, - Context, *Streamer, + _context, *Streamer, *_target->getMCAsmInfo())); OwningPtr<MCSubtargetInfo> STI(_target->getTarget(). createMCSubtargetInfo(_target->getTargetTriple(), @@ -670,38 +664,34 @@ static bool isAliasToDeclaration(const GlobalAlias &V) { } bool LTOModule::ParseSymbols(std::string &errMsg) { - // Use mangler to add GlobalPrefix to names to match linker names. - MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL); - Mangler mangler(Context, *_target->getTargetData()); - // add functions for (Module::iterator f = _module->begin(); f != _module->end(); ++f) { if (isDeclaration(*f)) - addPotentialUndefinedSymbol(f, mangler); + addPotentialUndefinedSymbol(f); else - addDefinedFunctionSymbol(f, mangler); + addDefinedFunctionSymbol(f); } // add data for (Module::global_iterator v = _module->global_begin(), e = _module->global_end(); v != e; ++v) { if (isDeclaration(*v)) - addPotentialUndefinedSymbol(v, mangler); + addPotentialUndefinedSymbol(v); else - addDefinedDataSymbol(v, mangler); + addDefinedDataSymbol(v); } // add asm globals - if (addAsmGlobalSymbols(Context, errMsg)) + if (addAsmGlobalSymbols(errMsg)) return true; // add aliases for (Module::alias_iterator i = _module->alias_begin(), e = _module->alias_end(); i != e; ++i) { if (isAliasToDeclaration(*i)) - addPotentialUndefinedSymbol(i, mangler); + addPotentialUndefinedSymbol(i); else - addDefinedDataSymbol(i, mangler); + addDefinedDataSymbol(i); } // make symbols for all undefines @@ -717,12 +707,10 @@ bool LTOModule::ParseSymbols(std::string &errMsg) { return false; } - uint32_t LTOModule::getSymbolCount() { return _symbols.size(); } - lto_symbol_attributes LTOModule::getSymbolAttributes(uint32_t index) { if (index < _symbols.size()) return _symbols[index].attributes; diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index ca08aea..35a0935 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -15,8 +15,10 @@ #define LTO_MODULE_H #include "llvm/Module.h" -#include "llvm/ADT/OwningPtr.h" +#include "llvm/MC/MCContext.h" +#include "llvm/Target/Mangler.h" #include "llvm/Target/TargetMachine.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringMap.h" #include "llvm-c/lto.h" @@ -27,7 +29,6 @@ // forward references to llvm classes namespace llvm { - class Mangler; class MemoryBuffer; class GlobalValue; class Value; @@ -77,17 +78,12 @@ private: LTOModule(llvm::Module* m, llvm::TargetMachine* t); bool ParseSymbols(std::string &errMsg); - void addDefinedSymbol(llvm::GlobalValue* def, - llvm::Mangler& mangler, - bool isFunction); - void addPotentialUndefinedSymbol(llvm::GlobalValue* decl, - llvm::Mangler &mangler); - void addDefinedFunctionSymbol(llvm::Function* f, - llvm::Mangler &mangler); - void addDefinedDataSymbol(llvm::GlobalValue* v, - llvm::Mangler &mangler); - bool addAsmGlobalSymbols(llvm::MCContext &Context, - std::string &errMsg); + void addDefinedSymbol(llvm::GlobalValue* def, + bool isFunction); + void addPotentialUndefinedSymbol(llvm::GlobalValue* decl); + void addDefinedFunctionSymbol(llvm::Function* f); + void addDefinedDataSymbol(llvm::GlobalValue* v); + bool addAsmGlobalSymbols(std::string &errMsg); void addAsmGlobalSymbol(const char *, lto_symbol_attributes scope); void addAsmGlobalSymbolUndef(const char *); @@ -118,6 +114,9 @@ private: StringSet _defines; llvm::StringMap<NameAndAttributes> _undefines; std::vector<const char*> _asm_undefines; + llvm::MCContext _context; + // Use mangler to add GlobalPrefix to names to match linker names. + llvm::Mangler _mangler; }; #endif // LTO_MODULE_H diff --git a/tools/macho-dump/LLVMBuild.txt b/tools/macho-dump/LLVMBuild.txt new file mode 100644 index 0000000..1ad9b84 --- /dev/null +++ b/tools/macho-dump/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/macho-dump/LLVMBuild.txt -------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = macho-dump +parent = Tools +required_libraries = Object Support diff --git a/tools/opt/LLVMBuild.txt b/tools/opt/LLVMBuild.txt new file mode 100644 index 0000000..4de99f5 --- /dev/null +++ b/tools/opt/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/opt/LLVMBuild.txt --------------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = opt +parent = Tools +required_libraries = AsmParser BitReader BitWriter IPO Instrumentation Scalar diff --git a/tools/opt/PrintSCC.cpp b/tools/opt/PrintSCC.cpp index 533f49e..11efdcd 100644 --- a/tools/opt/PrintSCC.cpp +++ b/tools/opt/PrintSCC.cpp @@ -101,8 +101,8 @@ bool CallGraphSCC::runOnModule(Module &M) { errs() << "\nSCC #" << ++sccNum << " : "; for (std::vector<CallGraphNode*>::const_iterator I = nextSCC.begin(), E = nextSCC.end(); I != E; ++I) - errs() << ((*I)->getFunction() ? (*I)->getFunction()->getNameStr() - : std::string("external node")) << ", "; + errs() << ((*I)->getFunction() ? (*I)->getFunction()->getName() + : "external node") << ", "; if (nextSCC.size() == 1 && SCCI.hasLoop()) errs() << " (Has self-loop)."; } diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp index 8be4e83..5161364 100644 --- a/tools/opt/opt.cpp +++ b/tools/opt/opt.cpp @@ -291,8 +291,8 @@ struct RegionPassPrinter : public RegionPass { virtual bool runOnRegion(Region *R, RGPassManager &RGM) { if (!Quiet) { Out << "Printing analysis '" << PassToPrint->getPassName() << "' for " - << "region: '" << R->getNameStr() << "' in function '" - << R->getEntry()->getParent()->getNameStr() << "':\n"; + << "region: '" << R->getNameStr() << "' in function '" + << R->getEntry()->getParent()->getName() << "':\n"; } // Get and print pass... getAnalysisID<Pass>(PassToPrint->getTypeInfo()).print(Out, @@ -407,6 +407,8 @@ static inline void addPass(PassManagerBase &PM, Pass *P) { /// OptLevel - Optimization Level static void AddOptimizationPasses(PassManagerBase &MPM,FunctionPassManager &FPM, unsigned OptLevel) { + FPM.add(createVerifierPass()); // Verify that input is correct + PassManagerBuilder Builder; Builder.OptLevel = OptLevel; |
