diff --git a/bolt/CMakeLists.txt b/bolt/CMakeLists.txt new file mode 100644 index 000000000000..a28744c0b239 --- /dev/null +++ b/bolt/CMakeLists.txt @@ -0,0 +1,18 @@ +set(LLVM_LINK_COMPONENTS + ${LLVM_TARGETS_TO_BUILD} + CodeGen + Core + DebugInfoDWARF + MC + MCDisassembler + MCParser + Object + Orcjit + Support + ) + +add_llvm_tool(llvm-flo + llvm-flo.cpp + BinaryCFG.cpp + BinaryOptimizer.cpp + ) diff --git a/bolt/LLVMBuild.txt b/bolt/LLVMBuild.txt new file mode 100644 index 000000000000..770196d110bd --- /dev/null +++ b/bolt/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-flo/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-flo +parent = Tools +required_libraries = DebugInfoDWARF MC MCDisassembler MCParser Object all-targets diff --git a/bolt/llvm-flo.cpp b/bolt/llvm-flo.cpp new file mode 100644 index 000000000000..290e5cf4bb59 --- /dev/null +++ b/bolt/llvm-flo.cpp @@ -0,0 +1,112 @@ +//===-- llvm-flo.cpp - Feedback-directed layout optimizer -----------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/STLExtras.h" +#include "llvm/ExecutionEngine/Orc/LambdaResolver.h" +#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" +#include "llvm/ExecutionEngine/RTDyldMemoryManager.h" +#include "llvm/MC/MCAsmInfo.h" +#include "llvm/MC/MCContext.h" +#include "llvm/MC/MCDisassembler.h" +#include "llvm/MC/MCInstPrinter.h" +#include "llvm/MC/MCInstrAnalysis.h" +#include "llvm/MC/MCInstrInfo.h" +#include "llvm/MC/MCObjectFileInfo.h" +#include "llvm/MC/MCRegisterInfo.h" +#include "llvm/MC/MCStreamer.h" +#include "llvm/MC/MCSubtargetInfo.h" +#include "llvm/MC/MCSymbol.h" +#include "llvm/Object/ELFObjectFile.h" +#include "llvm/Object/ObjectFile.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/Errc.h" +#include "llvm/Support/ManagedStatic.h" +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Signals.h" +#include "llvm/Support/TargetSelect.h" +#include "llvm/Support/TargetRegistry.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Target/TargetMachine.h" + + +#include +#include +#include + +using namespace llvm; +using namespace object; + +// Tool options. +static cl::opt +InputFilename(cl::Positional, cl::desc(""), cl::Required); + +static cl::opt +InputDataFilename("data", cl::desc(""), cl::Optional); + +static cl::opt +OutputFilename("o", cl::desc(""), cl::Required); + +static cl::list +FunctionNames("funcs", cl::desc("list of functions to optimzize"), + cl::Optional); + + +static StringRef ToolName; + +static void report_error(StringRef Message, std::error_code EC) { + assert(EC); + errs() << ToolName << ": '" << Message << "': " << EC.message() << ".\n"; + exit(1); +} + +int main(int argc, char **argv) { + // Print a stack trace if we signal out. + sys::PrintStackTraceOnErrorSignal(); + PrettyStackTraceProgram X(argc, argv); + + llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. + + // Initialize targets and assembly printers/parsers. + llvm::InitializeAllTargetInfos(); + llvm::InitializeAllTargetMCs(); + llvm::InitializeAllAsmParsers(); + llvm::InitializeAllDisassemblers(); + + llvm::InitializeAllTargets(); + llvm::InitializeAllAsmPrinters(); + + // Register the target printer for --version. + cl::AddExtraVersionPrinter(TargetRegistry::printRegisteredTargetsForVersion); + + cl::ParseCommandLineOptions(argc, argv, + "llvm feedback-directed layout optimizer\n"); + + ToolName = argv[0]; + + if (!sys::fs::exists(InputFilename)) + report_error(InputFilename, errc::no_such_file_or_directory); + + // Attempt to open the binary. + ErrorOr> BinaryOrErr = createBinary(InputFilename); + if (std::error_code EC = BinaryOrErr.getError()) + report_error(InputFilename, EC); + Binary &Binary = *BinaryOrErr.get().getBinary(); + + if (ELFObjectFileBase *e = dyn_cast(&Binary)) { + outs() << "mind blown : " << e << "!\n"; + } else { + report_error(InputFilename, object_error::invalid_file_type); + } + + return EXIT_SUCCESS; +}