#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"
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;
* 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 -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
struct CachingOptions {
std::string Path; // Path to the cache, empty to disable.
- int PruningInterval = 1200; // seconds, -1 to disable pruning.
- unsigned int Expiration = 7 * 24 * 3600; // seconds (1w default).
- unsigned MaxPercentageOfAvailableSpace = 75; // percentage.
+ 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 prune of the cache. Set to a
- /// negative value (default) to disable pruning. A value of 0 will be ignored.
+ /// 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)
- CacheOptions.PruningInterval = 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.Expiration = 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 the disk. Set to 100 to
- * indicate no limit, 50 to indicate that the cache size will not be left over
+ * 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.
*
*/
void setMaxCacheSizeRelativeToAvailableSpace(unsigned Percentage) {
if (Percentage)
- CacheOptions.MaxPercentageOfAvailableSpace = 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(uint64_t 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;
}
/**@}*/
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;
*/
void optimize(Module &Module);
- /**
- * Perform ThinLTO CodeGen.
- */
- std::unique_ptr<MemoryBuffer> codegen(Module &Module);
-
/**@}*/
private:
/// Vector holding the input buffers containing the bitcode modules to
/// process.
- std::vector<MemoryBufferRef> Modules;
+ std::vector<ThinLTOBuffer> Modules;
/// Set of symbols that need to be preserved outside of the set of bitcode
/// files.
/// 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;
};