Import prebuilt clang toolchain for linux.
diff --git a/linux-x64/clang/include/llvm/LTO/legacy/LTOCodeGenerator.h b/linux-x64/clang/include/llvm/LTO/legacy/LTOCodeGenerator.h
new file mode 100644
index 0000000..f48ab02
--- /dev/null
+++ b/linux-x64/clang/include/llvm/LTO/legacy/LTOCodeGenerator.h
@@ -0,0 +1,244 @@
+//===-LTOCodeGenerator.h - LLVM Link Time Optimizer -----------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the LTOCodeGenerator class.
+//
+// LTO compilation consists of three phases: Pre-IPO, IPO and Post-IPO.
+//
+// The Pre-IPO phase compiles source code into bitcode file. The resulting
+// bitcode files, along with object files and libraries, will be fed to the
+// linker to through the IPO and Post-IPO phases. By using obj-file extension,
+// the resulting bitcode file disguises itself as an object file, and therefore
+// obviates the need of writing a special set of the make-rules only for LTO
+// compilation.
+//
+// The IPO phase perform inter-procedural analyses and optimizations, and
+// the Post-IPO consists two sub-phases: intra-procedural scalar optimizations
+// (SOPT), and intra-procedural target-dependent code generator (CG).
+//
+// As of this writing, we don't separate IPO and the Post-IPO SOPT. They
+// are intermingled together, and are driven by a single pass manager (see
+// PassManagerBuilder::populateLTOPassManager()).
+//
+// The "LTOCodeGenerator" is the driver for the IPO and Post-IPO stages.
+// The "CodeGenerator" here is bit confusing. Don't confuse the "CodeGenerator"
+// with the machine specific code generator.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LTO_LTOCODEGENERATOR_H
+#define LLVM_LTO_LTOCODEGENERATOR_H
+
+#include "llvm-c/lto.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/IR/GlobalValue.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
+#include <string>
+#include <vector>
+
+namespace llvm {
+template <typename T> class ArrayRef;
+ class LLVMContext;
+ class DiagnosticInfo;
+ class Linker;
+ class Mangler;
+ class MemoryBuffer;
+ class TargetLibraryInfo;
+ class TargetMachine;
+ class raw_ostream;
+ class raw_pwrite_stream;
+
+//===----------------------------------------------------------------------===//
+/// C++ class which implements the opaque lto_code_gen_t type.
+///
+struct LTOCodeGenerator {
+ static const char *getVersionString();
+
+ LTOCodeGenerator(LLVMContext &Context);
+ ~LTOCodeGenerator();
+
+ /// Merge given module. Return true on success.
+ ///
+ /// Resets \a HasVerifiedInput.
+ bool addModule(struct LTOModule *);
+
+ /// Set the destination module.
+ ///
+ /// Resets \a HasVerifiedInput.
+ void setModule(std::unique_ptr<LTOModule> M);
+
+ void setAsmUndefinedRefs(struct LTOModule *);
+ void setTargetOptions(const TargetOptions &Options);
+ void setDebugInfo(lto_debug_model);
+ void setCodePICModel(Optional<Reloc::Model> Model) { RelocModel = Model; }
+
+ /// Set the file type to be emitted (assembly or object code).
+ /// The default is TargetMachine::CGFT_ObjectFile.
+ void setFileType(TargetMachine::CodeGenFileType FT) { FileType = FT; }
+
+ void setCpu(StringRef MCpu) { this->MCpu = MCpu; }
+ void setAttr(StringRef MAttr) { this->MAttr = MAttr; }
+ void setOptLevel(unsigned OptLevel);
+
+ void setShouldInternalize(bool Value) { ShouldInternalize = Value; }
+ void setShouldEmbedUselists(bool Value) { ShouldEmbedUselists = Value; }
+
+ /// Restore linkage of globals
+ ///
+ /// When set, the linkage of globals will be restored prior to code
+ /// generation. That is, a global symbol that had external linkage prior to
+ /// LTO will be emitted with external linkage again; and a local will remain
+ /// local. Note that this option only affects the end result - globals may
+ /// still be internalized in the process of LTO and may be modified and/or
+ /// deleted where legal.
+ ///
+ /// The default behavior will internalize globals (unless on the preserve
+ /// list) and, if parallel code generation is enabled, will externalize
+ /// all locals.
+ void setShouldRestoreGlobalsLinkage(bool Value) {
+ ShouldRestoreGlobalsLinkage = Value;
+ }
+
+ void addMustPreserveSymbol(StringRef Sym) { MustPreserveSymbols[Sym] = 1; }
+
+ /// Pass options to the driver and optimization passes.
+ ///
+ /// These options are not necessarily for debugging purpose (the function
+ /// name is misleading). This function should be called before
+ /// LTOCodeGenerator::compilexxx(), and
+ /// LTOCodeGenerator::writeMergedModules().
+ void setCodeGenDebugOptions(StringRef Opts);
+
+ /// Parse the options set in setCodeGenDebugOptions.
+ ///
+ /// Like \a setCodeGenDebugOptions(), this must be called before
+ /// LTOCodeGenerator::compilexxx() and
+ /// LTOCodeGenerator::writeMergedModules().
+ void parseCodeGenDebugOptions();
+
+ /// Write the merged module to the file specified by the given path. Return
+ /// true on success.
+ ///
+ /// Calls \a verifyMergedModuleOnce().
+ bool writeMergedModules(StringRef Path);
+
+ /// Compile the merged module into a *single* output file; the path to output
+ /// file is returned to the caller via argument "name". Return true on
+ /// success.
+ ///
+ /// \note It is up to the linker to remove the intermediate output file. Do
+ /// not try to remove the object file in LTOCodeGenerator's destructor as we
+ /// don't who (LTOCodeGenerator or the output file) will last longer.
+ bool compile_to_file(const char **Name, bool DisableVerify,
+ bool DisableInline, bool DisableGVNLoadPRE,
+ bool DisableVectorization);
+
+ /// As with compile_to_file(), this function compiles the merged module into
+ /// single output file. Instead of returning the output file path to the
+ /// caller (linker), it brings the output to a buffer, and returns the buffer
+ /// to the caller. This function should delete the intermediate file once
+ /// its content is brought to memory. Return NULL if the compilation was not
+ /// successful.
+ std::unique_ptr<MemoryBuffer> compile(bool DisableVerify, bool DisableInline,
+ bool DisableGVNLoadPRE,
+ bool DisableVectorization);
+
+ /// Optimizes the merged module. Returns true on success.
+ ///
+ /// Calls \a verifyMergedModuleOnce().
+ bool optimize(bool DisableVerify, bool DisableInline, bool DisableGVNLoadPRE,
+ bool DisableVectorization);
+
+ /// Compiles the merged optimized module into a single output file. It brings
+ /// the output to a buffer, and returns the buffer to the caller. Return NULL
+ /// if the compilation was not successful.
+ std::unique_ptr<MemoryBuffer> compileOptimized();
+
+ /// Compile the merged optimized module into out.size() output files each
+ /// representing a linkable partition of the module. If out contains more
+ /// than one element, code generation is done in parallel with out.size()
+ /// threads. Output files will be written to members of out. Returns true on
+ /// success.
+ ///
+ /// Calls \a verifyMergedModuleOnce().
+ bool compileOptimized(ArrayRef<raw_pwrite_stream *> Out);
+
+ /// Enable the Freestanding mode: indicate that the optimizer should not
+ /// assume builtins are present on the target.
+ void setFreestanding(bool Enabled) { Freestanding = Enabled; }
+
+ void setDiagnosticHandler(lto_diagnostic_handler_t, void *);
+
+ LLVMContext &getContext() { return Context; }
+
+ void resetMergedModule() { MergedModule.reset(); }
+ void DiagnosticHandler(const DiagnosticInfo &DI);
+
+private:
+ void initializeLTOPasses();
+
+ /// Verify the merged module on first call.
+ ///
+ /// Sets \a HasVerifiedInput on first call and doesn't run again on the same
+ /// input.
+ void verifyMergedModuleOnce();
+
+ bool compileOptimizedToFile(const char **Name);
+ void restoreLinkageForExternals();
+ void applyScopeRestrictions();
+ void preserveDiscardableGVs(
+ Module &TheModule,
+ llvm::function_ref<bool(const GlobalValue &)> mustPreserveGV);
+
+ bool determineTarget();
+ std::unique_ptr<TargetMachine> createTargetMachine();
+
+ void emitError(const std::string &ErrMsg);
+ void emitWarning(const std::string &ErrMsg);
+
+ void finishOptimizationRemarks();
+
+ LLVMContext &Context;
+ std::unique_ptr<Module> MergedModule;
+ std::unique_ptr<Linker> TheLinker;
+ std::unique_ptr<TargetMachine> TargetMach;
+ bool EmitDwarfDebugInfo = false;
+ bool ScopeRestrictionsDone = false;
+ bool HasVerifiedInput = false;
+ Optional<Reloc::Model> RelocModel;
+ StringSet<> MustPreserveSymbols;
+ StringSet<> AsmUndefinedRefs;
+ StringMap<GlobalValue::LinkageTypes> ExternalSymbols;
+ std::vector<std::string> CodegenOptions;
+ std::string FeatureStr;
+ std::string MCpu;
+ std::string MAttr;
+ std::string NativeObjectPath;
+ TargetOptions Options;
+ CodeGenOpt::Level CGOptLevel = CodeGenOpt::Default;
+ const Target *MArch = nullptr;
+ std::string TripleStr;
+ unsigned OptLevel = 2;
+ lto_diagnostic_handler_t DiagHandler = nullptr;
+ void *DiagContext = nullptr;
+ bool ShouldInternalize = true;
+ bool ShouldEmbedUselists = false;
+ bool ShouldRestoreGlobalsLinkage = false;
+ TargetMachine::CodeGenFileType FileType = TargetMachine::CGFT_ObjectFile;
+ std::unique_ptr<ToolOutputFile> DiagnosticOutputFile;
+ bool Freestanding = false;
+};
+}
+#endif
diff --git a/linux-x64/clang/include/llvm/LTO/legacy/LTOModule.h b/linux-x64/clang/include/llvm/LTO/legacy/LTOModule.h
new file mode 100644
index 0000000..017e223
--- /dev/null
+++ b/linux-x64/clang/include/llvm/LTO/legacy/LTOModule.h
@@ -0,0 +1,208 @@
+//===-LTOModule.h - LLVM Link Time Optimizer ------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the LTOModule class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LTO_LTOMODULE_H
+#define LLVM_LTO_LTOMODULE_H
+
+#include "llvm-c/lto.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Object/IRObjectFile.h"
+#include "llvm/Object/ModuleSymbolTable.h"
+#include "llvm/Target/TargetMachine.h"
+#include <string>
+#include <vector>
+
+// Forward references to llvm classes.
+namespace llvm {
+ class Function;
+ class GlobalValue;
+ class MemoryBuffer;
+ class TargetOptions;
+ class Value;
+
+//===----------------------------------------------------------------------===//
+/// C++ class which implements the opaque lto_module_t type.
+///
+struct LTOModule {
+private:
+ struct NameAndAttributes {
+ StringRef name;
+ uint32_t attributes = 0;
+ bool isFunction = 0;
+ const GlobalValue *symbol = 0;
+ };
+
+ std::unique_ptr<LLVMContext> OwnedContext;
+
+ std::string LinkerOpts;
+
+ std::unique_ptr<Module> Mod;
+ MemoryBufferRef MBRef;
+ ModuleSymbolTable SymTab;
+ std::unique_ptr<TargetMachine> _target;
+ std::vector<NameAndAttributes> _symbols;
+
+ // _defines and _undefines only needed to disambiguate tentative definitions
+ StringSet<> _defines;
+ StringMap<NameAndAttributes> _undefines;
+ std::vector<StringRef> _asm_undefines;
+
+ LTOModule(std::unique_ptr<Module> M, MemoryBufferRef MBRef,
+ TargetMachine *TM);
+
+public:
+ ~LTOModule();
+
+ /// Returns 'true' if the file or memory contents is LLVM bitcode.
+ static bool isBitcodeFile(const void *mem, size_t length);
+ static bool isBitcodeFile(StringRef path);
+
+ /// Returns 'true' if the Module is produced for ThinLTO.
+ bool isThinLTO();
+
+ /// Returns 'true' if the memory buffer is LLVM bitcode for the specified
+ /// triple.
+ static bool isBitcodeForTarget(MemoryBuffer *memBuffer,
+ StringRef triplePrefix);
+
+ /// Returns a string representing the producer identification stored in the
+ /// bitcode, or "" if the bitcode does not contains any.
+ ///
+ static std::string getProducerString(MemoryBuffer *Buffer);
+
+ /// Create a MemoryBuffer from a memory range with an optional name.
+ static std::unique_ptr<MemoryBuffer>
+ makeBuffer(const void *mem, size_t length, StringRef name = "");
+
+ /// Create an LTOModule. N.B. These methods take ownership of the buffer. The
+ /// caller must have initialized the Targets, the TargetMCs, the AsmPrinters,
+ /// and the AsmParsers by calling:
+ ///
+ /// InitializeAllTargets();
+ /// InitializeAllTargetMCs();
+ /// InitializeAllAsmPrinters();
+ /// InitializeAllAsmParsers();
+ static ErrorOr<std::unique_ptr<LTOModule>>
+ createFromFile(LLVMContext &Context, StringRef path,
+ const TargetOptions &options);
+ static ErrorOr<std::unique_ptr<LTOModule>>
+ createFromOpenFile(LLVMContext &Context, int fd, StringRef path, size_t size,
+ const TargetOptions &options);
+ static ErrorOr<std::unique_ptr<LTOModule>>
+ createFromOpenFileSlice(LLVMContext &Context, int fd, StringRef path,
+ size_t map_size, off_t offset,
+ const TargetOptions &options);
+ static ErrorOr<std::unique_ptr<LTOModule>>
+ createFromBuffer(LLVMContext &Context, const void *mem, size_t length,
+ const TargetOptions &options, StringRef path = "");
+ static ErrorOr<std::unique_ptr<LTOModule>>
+ createInLocalContext(std::unique_ptr<LLVMContext> Context, const void *mem,
+ size_t length, const TargetOptions &options,
+ StringRef path);
+
+ const Module &getModule() const { return *Mod; }
+ Module &getModule() { return *Mod; }
+
+ std::unique_ptr<Module> takeModule() { return std::move(Mod); }
+
+ /// Return the Module's target triple.
+ const std::string &getTargetTriple() {
+ return getModule().getTargetTriple();
+ }
+
+ /// Set the Module's target triple.
+ void setTargetTriple(StringRef Triple) {
+ getModule().setTargetTriple(Triple);
+ }
+
+ /// Get the number of symbols
+ uint32_t getSymbolCount() {
+ return _symbols.size();
+ }
+
+ /// Get the attributes for a symbol at the specified index.
+ lto_symbol_attributes getSymbolAttributes(uint32_t index) {
+ if (index < _symbols.size())
+ return lto_symbol_attributes(_symbols[index].attributes);
+ return lto_symbol_attributes(0);
+ }
+
+ /// Get the name of the symbol at the specified index.
+ StringRef getSymbolName(uint32_t index) {
+ if (index < _symbols.size())
+ return _symbols[index].name;
+ return StringRef();
+ }
+
+ const GlobalValue *getSymbolGV(uint32_t index) {
+ if (index < _symbols.size())
+ return _symbols[index].symbol;
+ return nullptr;
+ }
+
+ StringRef getLinkerOpts() { return LinkerOpts; }
+
+ const std::vector<StringRef> &getAsmUndefinedRefs() { return _asm_undefines; }
+
+private:
+ /// Parse metadata from the module
+ // FIXME: it only parses "llvm.linker.options" metadata at the moment
+ void parseMetadata();
+
+ /// Parse the symbols from the module and model-level ASM and add them to
+ /// either the defined or undefined lists.
+ void parseSymbols();
+
+ /// Add a symbol which isn't defined just yet to a list to be resolved later.
+ void addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym,
+ bool isFunc);
+
+ /// Add a defined symbol to the list.
+ void addDefinedSymbol(StringRef Name, const GlobalValue *def,
+ bool isFunction);
+
+ /// Add a data symbol as defined to the list.
+ void addDefinedDataSymbol(ModuleSymbolTable::Symbol Sym);
+ void addDefinedDataSymbol(StringRef Name, const GlobalValue *v);
+
+ /// Add a function symbol as defined to the list.
+ void addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym);
+ void addDefinedFunctionSymbol(StringRef Name, const Function *F);
+
+ /// Add a global symbol from module-level ASM to the defined list.
+ void addAsmGlobalSymbol(StringRef, lto_symbol_attributes scope);
+
+ /// Add a global symbol from module-level ASM to the undefined list.
+ void addAsmGlobalSymbolUndef(StringRef);
+
+ /// Parse i386/ppc ObjC class data structure.
+ void addObjCClass(const GlobalVariable *clgv);
+
+ /// Parse i386/ppc ObjC category data structure.
+ void addObjCCategory(const GlobalVariable *clgv);
+
+ /// Parse i386/ppc ObjC class list data structure.
+ void addObjCClassRef(const GlobalVariable *clgv);
+
+ /// Get string that the data pointer points to.
+ bool objcClassNameFromExpression(const Constant *c, std::string &name);
+
+ /// Create an LTOModule (private version).
+ static ErrorOr<std::unique_ptr<LTOModule>>
+ makeLTOModule(MemoryBufferRef Buffer, const TargetOptions &options,
+ LLVMContext &Context, bool ShouldBeLazy);
+};
+}
+#endif
diff --git a/linux-x64/clang/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h b/linux-x64/clang/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
new file mode 100644
index 0000000..b32a972
--- /dev/null
+++ b/linux-x64/clang/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h
@@ -0,0 +1,356 @@
+//===-ThinLTOCodeGenerator.h - LLVM Link Time Optimizer -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the ThinLTOCodeGenerator class, similar to the
+// LTOCodeGenerator but for the ThinLTO scheme. It provides an interface for
+// linker plugin.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LTO_THINLTOCODEGENERATOR_H
+#define LLVM_LTO_THINLTOCODEGENERATOR_H
+
+#include "llvm-c/lto.h"
+#include "llvm/ADT/StringSet.h"
+#include "llvm/ADT/Triple.h"
+#include "llvm/IR/ModuleSummaryIndex.h"
+#include "llvm/Support/CachePruning.h"
+#include "llvm/Support/CodeGen.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Target/TargetOptions.h"
+
+#include <string>
+
+namespace llvm {
+class StringRef;
+class LLVMContext;
+class TargetMachine;
+
+/// Wrapper around MemoryBufferRef, owning the identifier
+class ThinLTOBuffer {
+ std::string OwnedIdentifier;
+ StringRef Buffer;
+
+public:
+ ThinLTOBuffer(StringRef Buffer, StringRef Identifier)
+ : OwnedIdentifier(Identifier), Buffer(Buffer) {}
+
+ MemoryBufferRef getMemBuffer() const {
+ return MemoryBufferRef(Buffer,
+ {OwnedIdentifier.c_str(), OwnedIdentifier.size()});
+ }
+ StringRef getBuffer() const { return Buffer; }
+ StringRef getBufferIdentifier() const { return OwnedIdentifier; }
+};
+
+/// Helper to gather options relevant to the target machine creation
+struct TargetMachineBuilder {
+ Triple TheTriple;
+ std::string MCpu;
+ std::string MAttr;
+ TargetOptions Options;
+ Optional<Reloc::Model> RelocModel;
+ CodeGenOpt::Level CGOptLevel = CodeGenOpt::Aggressive;
+
+ std::unique_ptr<TargetMachine> create() const;
+};
+
+/// This class define an interface similar to the LTOCodeGenerator, but adapted
+/// for ThinLTO processing.
+/// The ThinLTOCodeGenerator is not intended to be reuse for multiple
+/// compilation: the model is that the client adds modules to the generator and
+/// ask to perform the ThinLTO optimizations / codegen, and finally destroys the
+/// codegenerator.
+class ThinLTOCodeGenerator {
+public:
+ /// Add given module to the code generator.
+ void addModule(StringRef Identifier, StringRef Data);
+
+ /**
+ * Adds to a list of all global symbols that must exist in the final generated
+ * code. If a symbol is not listed there, it will be optimized away if it is
+ * inlined into every usage.
+ */
+ void preserveSymbol(StringRef Name);
+
+ /**
+ * Adds to a list of all global symbols that are cross-referenced between
+ * ThinLTO files. If the ThinLTO CodeGenerator can ensure that every
+ * references from a ThinLTO module to this symbol is optimized away, then
+ * the symbol can be discarded.
+ */
+ void crossReferenceSymbol(StringRef Name);
+
+ /**
+ * Process all the modules that were added to the code generator in parallel.
+ *
+ * Client can access the resulting object files using getProducedBinaries(),
+ * unless setGeneratedObjectsDirectory() has been called, in which case
+ * results are available through getProducedBinaryFiles().
+ */
+ void run();
+
+ /**
+ * Return the "in memory" binaries produced by the code generator. This is
+ * filled after run() unless setGeneratedObjectsDirectory() has been
+ * called, in which case results are available through
+ * getProducedBinaryFiles().
+ */
+ std::vector<std::unique_ptr<MemoryBuffer>> &getProducedBinaries() {
+ return ProducedBinaries;
+ }
+
+ /**
+ * Return the "on-disk" binaries produced by the code generator. This is
+ * filled after run() when setGeneratedObjectsDirectory() has been
+ * called, in which case results are available through getProducedBinaries().
+ */
+ std::vector<std::string> &getProducedBinaryFiles() {
+ return ProducedBinaryFiles;
+ }
+
+ /**
+ * \defgroup Options setters
+ * @{
+ */
+
+ /**
+ * \defgroup Cache controlling options
+ *
+ * These entry points control the ThinLTO cache. The cache is intended to
+ * support incremental build, and thus needs to be persistent accross build.
+ * The client enabled the cache by supplying a path to an existing directory.
+ * The code generator will use this to store objects files that may be reused
+ * during a subsequent build.
+ * To avoid filling the disk space, a few knobs are provided:
+ * - The pruning interval limit the frequency at which the garbage collector
+ * will try to scan the cache directory to prune it from expired entries.
+ * Setting to -1 disable the pruning (default). Setting to 0 will force
+ * pruning to occur.
+ * - The pruning expiration time indicates to the garbage collector how old
+ * an entry needs to be to be removed.
+ * - Finally, the garbage collector can be instructed to prune the cache till
+ * the occupied space goes below a threshold.
+ * @{
+ */
+
+ struct CachingOptions {
+ std::string Path; // Path to the cache, empty to disable.
+ CachePruningPolicy Policy;
+ };
+
+ /// Provide a path to a directory where to store the cached files for
+ /// incremental build.
+ void setCacheDir(std::string Path) { CacheOptions.Path = std::move(Path); }
+
+ /// Cache policy: interval (seconds) between two prunes of the cache. Set to a
+ /// negative value to disable pruning. A value of 0 will force pruning to
+ /// occur.
+ void setCachePruningInterval(int Interval) {
+ if(Interval < 0)
+ CacheOptions.Policy.Interval.reset();
+ else
+ CacheOptions.Policy.Interval = std::chrono::seconds(Interval);
+ }
+
+ /// Cache policy: expiration (in seconds) for an entry.
+ /// A value of 0 will be ignored.
+ void setCacheEntryExpiration(unsigned Expiration) {
+ if (Expiration)
+ CacheOptions.Policy.Expiration = std::chrono::seconds(Expiration);
+ }
+
+ /**
+ * Sets the maximum cache size that can be persistent across build, in terms
+ * of percentage of the available space on the disk. Set to 100 to indicate
+ * no limit, 50 to indicate that the cache size will not be left over
+ * half the available space. A value over 100 will be reduced to 100, and a
+ * value of 0 will be ignored.
+ *
+ *
+ * The formula looks like:
+ * AvailableSpace = FreeSpace + ExistingCacheSize
+ * NewCacheSize = AvailableSpace * P/100
+ *
+ */
+ void setMaxCacheSizeRelativeToAvailableSpace(unsigned Percentage) {
+ if (Percentage)
+ CacheOptions.Policy.MaxSizePercentageOfAvailableSpace = Percentage;
+ }
+
+ /// Cache policy: the maximum size for the cache directory in bytes. A value
+ /// over the amount of available space on the disk will be reduced to the
+ /// amount of available space. A value of 0 will be ignored.
+ void setCacheMaxSizeBytes(unsigned MaxSizeBytes) {
+ if (MaxSizeBytes)
+ CacheOptions.Policy.MaxSizeBytes = MaxSizeBytes;
+ }
+
+ /// Cache policy: the maximum number of files in the cache directory. A value
+ /// of 0 will be ignored.
+ void setCacheMaxSizeFiles(unsigned MaxSizeFiles) {
+ if (MaxSizeFiles)
+ CacheOptions.Policy.MaxSizeFiles = MaxSizeFiles;
+ }
+
+ /**@}*/
+
+ /// Set the path to a directory where to save temporaries at various stages of
+ /// the processing.
+ void setSaveTempsDir(std::string Path) { SaveTempsDir = std::move(Path); }
+
+ /// Set the path to a directory where to save generated object files. This
+ /// path can be used by a linker to request on-disk files instead of in-memory
+ /// buffers. When set, results are available through getProducedBinaryFiles()
+ /// instead of getProducedBinaries().
+ void setGeneratedObjectsDirectory(std::string Path) {
+ SavedObjectsDirectoryPath = std::move(Path);
+ }
+
+ /// CPU to use to initialize the TargetMachine
+ void setCpu(std::string Cpu) { TMBuilder.MCpu = std::move(Cpu); }
+
+ /// Subtarget attributes
+ void setAttr(std::string MAttr) { TMBuilder.MAttr = std::move(MAttr); }
+
+ /// TargetMachine options
+ void setTargetOptions(TargetOptions Options) {
+ TMBuilder.Options = std::move(Options);
+ }
+
+ /// Enable the Freestanding mode: indicate that the optimizer should not
+ /// assume builtins are present on the target.
+ void setFreestanding(bool Enabled) { Freestanding = Enabled; }
+
+ /// CodeModel
+ void setCodePICModel(Optional<Reloc::Model> Model) {
+ TMBuilder.RelocModel = Model;
+ }
+
+ /// CodeGen optimization level
+ void setCodeGenOptLevel(CodeGenOpt::Level CGOptLevel) {
+ TMBuilder.CGOptLevel = CGOptLevel;
+ }
+
+ /// IR optimization level: from 0 to 3.
+ void setOptLevel(unsigned NewOptLevel) {
+ OptLevel = (NewOptLevel > 3) ? 3 : NewOptLevel;
+ }
+
+ /// Disable CodeGen, only run the stages till codegen and stop. The output
+ /// will be bitcode.
+ void disableCodeGen(bool Disable) { DisableCodeGen = Disable; }
+
+ /// Perform CodeGen only: disable all other stages.
+ void setCodeGenOnly(bool CGOnly) { CodeGenOnly = CGOnly; }
+
+ /**@}*/
+
+ /**
+ * \defgroup Set of APIs to run individual stages in isolation.
+ * @{
+ */
+
+ /**
+ * Produce the combined summary index from all the bitcode files:
+ * "thin-link".
+ */
+ std::unique_ptr<ModuleSummaryIndex> linkCombinedIndex();
+
+ /**
+ * Perform promotion and renaming of exported internal functions,
+ * and additionally resolve weak and linkonce symbols.
+ * Index is updated to reflect linkage changes from weak resolution.
+ */
+ void promote(Module &Module, ModuleSummaryIndex &Index);
+
+ /**
+ * Compute and emit the imported files for module at \p ModulePath.
+ */
+ static void emitImports(StringRef ModulePath, StringRef OutputName,
+ ModuleSummaryIndex &Index);
+
+ /**
+ * Perform cross-module importing for the module identified by
+ * ModuleIdentifier.
+ */
+ void crossModuleImport(Module &Module, ModuleSummaryIndex &Index);
+
+ /**
+ * Compute the list of summaries needed for importing into module.
+ */
+ static void gatherImportedSummariesForModule(
+ StringRef ModulePath, ModuleSummaryIndex &Index,
+ std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
+
+ /**
+ * Perform internalization. Index is updated to reflect linkage changes.
+ */
+ void internalize(Module &Module, ModuleSummaryIndex &Index);
+
+ /**
+ * Perform post-importing ThinLTO optimizations.
+ */
+ void optimize(Module &Module);
+
+ /**
+ * Perform ThinLTO CodeGen.
+ */
+ std::unique_ptr<MemoryBuffer> codegen(Module &Module);
+
+ /**@}*/
+
+private:
+ /// Helper factory to build a TargetMachine
+ TargetMachineBuilder TMBuilder;
+
+ /// Vector holding the in-memory buffer containing the produced binaries, when
+ /// SavedObjectsDirectoryPath isn't set.
+ std::vector<std::unique_ptr<MemoryBuffer>> ProducedBinaries;
+
+ /// Path to generated files in the supplied SavedObjectsDirectoryPath if any.
+ std::vector<std::string> ProducedBinaryFiles;
+
+ /// Vector holding the input buffers containing the bitcode modules to
+ /// process.
+ std::vector<ThinLTOBuffer> Modules;
+
+ /// Set of symbols that need to be preserved outside of the set of bitcode
+ /// files.
+ StringSet<> PreservedSymbols;
+
+ /// Set of symbols that are cross-referenced between bitcode files.
+ StringSet<> CrossReferencedSymbols;
+
+ /// Control the caching behavior.
+ CachingOptions CacheOptions;
+
+ /// Path to a directory to save the temporary bitcode files.
+ std::string SaveTempsDir;
+
+ /// Path to a directory to save the generated object files.
+ std::string SavedObjectsDirectoryPath;
+
+ /// Flag to enable/disable CodeGen. When set to true, the process stops after
+ /// optimizations and a bitcode is produced.
+ bool DisableCodeGen = false;
+
+ /// Flag to indicate that only the CodeGen will be performed, no cross-module
+ /// importing or optimization.
+ bool CodeGenOnly = false;
+
+ /// Flag to indicate that the optimizer should not assume builtins are present
+ /// on the target.
+ bool Freestanding = false;
+
+ /// IR Optimization Level [0-3].
+ unsigned OptLevel = 3;
+};
+}
+#endif
diff --git a/linux-x64/clang/include/llvm/LTO/legacy/UpdateCompilerUsed.h b/linux-x64/clang/include/llvm/LTO/legacy/UpdateCompilerUsed.h
new file mode 100644
index 0000000..4be0027
--- /dev/null
+++ b/linux-x64/clang/include/llvm/LTO/legacy/UpdateCompilerUsed.h
@@ -0,0 +1,32 @@
+//==------ UpdateCompilerUsed.h - LLVM Link Time Optimizer Utility --------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares a helper class to update llvm.compiler_used metadata.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LTO_UPDATE_COMPILER_USED_H
+#define LLVM_LTO_UPDATE_COMPILER_USED_H
+
+#include "llvm/ADT/StringSet.h"
+#include "llvm/IR/GlobalValue.h"
+
+namespace llvm {
+class Module;
+class TargetMachine;
+
+/// Find all globals in \p TheModule that are referenced in
+/// \p AsmUndefinedRefs, as well as the user-supplied functions definitions that
+/// are also libcalls, and create or update the magic "llvm.compiler_used"
+/// global in \p TheModule.
+void updateCompilerUsed(Module &TheModule, const TargetMachine &TM,
+ const StringSet<> &AsmUndefinedRefs);
+}
+
+#endif // LLVM_LTO_UPDATE_COMPILER_USED_H