#include "llvm/LTO/legacy/LTOCodeGenerator.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/TargetTransformInfo.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/CodeGen/CommandFlags.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
#include "llvm/Config/config.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LLVMRemarkStreamer.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassTimingInfo.h"
#include "llvm/IR/Verifier.h"
#include "llvm/LTO/LTO.h"
#include "llvm/LTO/LTOBackend.h"
#include "llvm/LTO/legacy/LTOModule.h"
#include "llvm/LTO/legacy/UpdateCompilerUsed.h"
#include "llvm/Linker/Linker.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Remarks/HotnessThresholdParser.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/YAMLTraits.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetOptions.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/Transforms/IPO.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
#include <optional>
#include <system_error>
usingnamespacellvm;
const char* LTOCodeGenerator::getVersionString() { … }
namespace llvm {
cl::opt<bool> LTODiscardValueNames(
"lto-discard-value-names",
cl::desc("Strip names from Value during LTO (other than GlobalValue)."),
#ifdef NDEBUG
cl::init(true),
#else
cl::init(false),
#endif
cl::Hidden);
cl::opt<bool> RemarksWithHotness(
"lto-pass-remarks-with-hotness",
cl::desc("With PGO, include profile count in optimization remarks"),
cl::Hidden);
cl::opt<std::optional<uint64_t>, false, remarks::HotnessThresholdParser>
RemarksHotnessThreshold(
"lto-pass-remarks-hotness-threshold",
cl::desc("Minimum profile count required for an "
"optimization remark to be output."
" Use 'auto' to apply the threshold from profile summary."),
cl::value_desc("uint or 'auto'"), cl::init(0), cl::Hidden);
cl::opt<std::string>
RemarksFilename("lto-pass-remarks-output",
cl::desc("Output filename for pass remarks"),
cl::value_desc("filename"));
cl::opt<std::string>
RemarksPasses("lto-pass-remarks-filter",
cl::desc("Only record optimization remarks from passes whose "
"names match the given regular expression"),
cl::value_desc("regex"));
cl::opt<std::string> RemarksFormat(
"lto-pass-remarks-format",
cl::desc("The format used for serializing remarks (default: YAML)"),
cl::value_desc("format"), cl::init("yaml"));
cl::opt<std::string> LTOStatsFile(
"lto-stats-file",
cl::desc("Save statistics to the specified file"),
cl::Hidden);
cl::opt<std::string> AIXSystemAssemblerPath(
"lto-aix-system-assembler",
cl::desc("Path to a system assembler, picked up on AIX only"),
cl::value_desc("path"));
cl::opt<bool>
LTORunCSIRInstr("cs-profile-generate",
cl::desc("Perform context sensitive PGO instrumentation"));
cl::opt<std::string>
LTOCSIRProfile("cs-profile-path",
cl::desc("Context sensitive profile file path"));
}
LTOCodeGenerator::LTOCodeGenerator(LLVMContext &Context)
: … { … }
LTOCodeGenerator::~LTOCodeGenerator() = default;
void LTOCodeGenerator::setAsmUndefinedRefs(LTOModule *Mod) { … }
bool LTOCodeGenerator::addModule(LTOModule *Mod) { … }
void LTOCodeGenerator::setModule(std::unique_ptr<LTOModule> Mod) { … }
void LTOCodeGenerator::setTargetOptions(const TargetOptions &Options) { … }
void LTOCodeGenerator::setDebugInfo(lto_debug_model Debug) { … }
void LTOCodeGenerator::setOptLevel(unsigned Level) { … }
bool LTOCodeGenerator::writeMergedModules(StringRef Path) { … }
bool LTOCodeGenerator::useAIXSystemAssembler() { … }
bool LTOCodeGenerator::runAIXSystemAssembler(SmallString<128> &AssemblyFile) { … }
bool LTOCodeGenerator::compileOptimizedToFile(const char **Name) { … }
std::unique_ptr<MemoryBuffer>
LTOCodeGenerator::compileOptimized() { … }
bool LTOCodeGenerator::compile_to_file(const char **Name) { … }
std::unique_ptr<MemoryBuffer> LTOCodeGenerator::compile() { … }
bool LTOCodeGenerator::determineTarget() { … }
std::unique_ptr<TargetMachine> LTOCodeGenerator::createTargetMachine() { … }
void LTOCodeGenerator::preserveDiscardableGVs(
Module &TheModule,
llvm::function_ref<bool(const GlobalValue &)> mustPreserveGV) { … }
void LTOCodeGenerator::applyScopeRestrictions() { … }
void LTOCodeGenerator::restoreLinkageForExternals() { … }
void LTOCodeGenerator::verifyMergedModuleOnce() { … }
void LTOCodeGenerator::finishOptimizationRemarks() { … }
bool LTOCodeGenerator::optimize() { … }
bool LTOCodeGenerator::compileOptimized(AddStreamFn AddStream,
unsigned ParallelismLevel) { … }
void LTOCodeGenerator::setCodeGenDebugOptions(ArrayRef<StringRef> Options) { … }
void LTOCodeGenerator::parseCodeGenDebugOptions() { … }
void llvm::parseCommandLineOptions(std::vector<std::string> &Options) { … }
void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo &DI) { … }
namespace {
struct LTODiagnosticHandler : public DiagnosticHandler { … };
}
void
LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler,
void *Ctxt) { … }
namespace {
class LTODiagnosticInfo : public DiagnosticInfo { … };
}
void LTOCodeGenerator::emitError(const std::string &ErrMsg) { … }
void LTOCodeGenerator::emitWarning(const std::string &ErrMsg) { … }