mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 15:41:46 +00:00
Initial FLO commit.
Summary: Directory created. (cherry picked from FBD28105260)
This commit is contained in:
parent
25b976aa12
commit
575b24d719
18
bolt/CMakeLists.txt
Normal file
18
bolt/CMakeLists.txt
Normal file
@ -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
|
||||
)
|
22
bolt/LLVMBuild.txt
Normal file
22
bolt/LLVMBuild.txt
Normal file
@ -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
|
112
bolt/llvm-flo.cpp
Normal file
112
bolt/llvm-flo.cpp
Normal file
@ -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 <algorithm>
|
||||
#include <map>
|
||||
#include <system_error>
|
||||
|
||||
using namespace llvm;
|
||||
using namespace object;
|
||||
|
||||
// Tool options.
|
||||
static cl::opt<std::string>
|
||||
InputFilename(cl::Positional, cl::desc("<executable>"), cl::Required);
|
||||
|
||||
static cl::opt<std::string>
|
||||
InputDataFilename("data", cl::desc("<data file>"), cl::Optional);
|
||||
|
||||
static cl::opt<std::string>
|
||||
OutputFilename("o", cl::desc("<output file>"), cl::Required);
|
||||
|
||||
static cl::list<std::string>
|
||||
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<OwningBinary<Binary>> BinaryOrErr = createBinary(InputFilename);
|
||||
if (std::error_code EC = BinaryOrErr.getError())
|
||||
report_error(InputFilename, EC);
|
||||
Binary &Binary = *BinaryOrErr.get().getBinary();
|
||||
|
||||
if (ELFObjectFileBase *e = dyn_cast<ELFObjectFileBase>(&Binary)) {
|
||||
outs() << "mind blown : " << e << "!\n";
|
||||
} else {
|
||||
report_error(InputFilename, object_error::invalid_file_type);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user