GCC Middle and Back End API Reference
|
#include <lto-ltrans-cache.h>
Data Structures | |
struct | item |
Public Member Functions | |
ltrans_file_cache (const char *dir, const char *prefix, const char *suffix, size_t soft_cache_size) | |
~ltrans_file_cache () | |
void | load_cache () |
void | save_cache () |
bool | add_to_cache (const char *filename, item *&_item) |
item * | get_item (const char *input) |
void | try_prune () |
void | cleanup () |
operator bool () | |
Data Fields | |
lockfile | creation_lock |
lockfile | deletion_lock |
const char * | dir |
Private Member Functions | |
void | add_item (item *item) |
item * | create_item (checksum_t checksum) |
void | prune () |
std::string | filename_cachedata () |
Private Attributes | |
std::vector< item * > | items |
std::map< checksum_t, item * > | map_checksum |
std::map< std::string, item * > | map_input |
const char * | prefix |
const char * | suffix |
size_t | soft_cache_size |
uint32_t | usage_counter |
std::string | cache_prefix |
uint32_t | cache_free_idx |
char * | str_buffer |
ltrans_file_cache::ltrans_file_cache | ( | const char * | dir, |
const char * | prefix, | ||
const char * | suffix, | ||
size_t | soft_cache_size ) |
Constructor. Resulting cache item filenames will be in format `prefix%d[.ltrans]suffix`.
References cache_free_idx, cache_prefix, creation_lock, deletion_lock, dir, prefix, str_buffer, and suffix.
ltrans_file_cache::~ltrans_file_cache | ( | ) |
Destructor.
References cleanup(), free(), and str_buffer.
|
private |
Adds given cache item to all relevant datastructures.
References ltrans_file_cache::item::input, ltrans_file_cache::item::input_checksum, items, ltrans_file_cache::item::last_used, map_checksum, map_input, and usage_counter.
Referenced by add_to_cache(), load_cache(), and prune().
Adds input file into cache. Cache item with input file identical to added input file will be returned as _item. If the file was already cached, `true` is returned, `false` otherwise. The added input file is deleted (or moved). Must be called with creation_lock held to prevent data race.
References add_item(), create_item(), file_checksum(), files_identical(), ltrans_file_cache::item::input, ltrans_file_cache::item::last_used, map_checksum, and usage_counter.
Referenced by run_gcc().
void ltrans_file_cache::cleanup | ( | ) |
Clears cache class, as if only constructor was called.
References items, map_checksum, map_input, and usage_counter.
Referenced by load_cache(), prune(), and ~ltrans_file_cache().
|
private |
Creates new cache item with given checksum. New input/output files are chosen to not collide with other items. Must be called with creation_lock held to prevent data race.
References cache_free_idx, cache_prefix, map_input, str_buffer, suffix, and usage_counter.
Referenced by add_to_cache().
|
private |
Creates cachedata filename for save/load.
References dir.
Referenced by load_cache(), and save_cache().
ltrans_file_cache::item * ltrans_file_cache::get_item | ( | const char * | input | ) |
void ltrans_file_cache::load_cache | ( | ) |
Loads data about previously cached items from cachedata file. Sorts items by last_used and remaps last_used to small integers. Must be called with creation_lock or deletion_lock held to prevent data race.
References a, add_item(), b, cleanup(), dir, filename_cachedata(), fopen, i, items, read_cache_item(), and usage_counter.
|
private |
Prunes oldest unused cache items over limit. Must be called with deletion_lock held to prevent data race.
References add_item(), cleanup(), file_exists(), i, ltrans_file_cache::item::input, items, load_cache(), ltrans_file_cache::item::output, save_cache(), and soft_cache_size.
Referenced by try_prune().
void ltrans_file_cache::save_cache | ( | ) |
Rewrites data about cache items into cachedata file. Must be only called when creation_lock or deletion_lock was held since last call to load_cache.
References dir, filename_cachedata(), fopen, items, and write_cache_item().
void ltrans_file_cache::try_prune | ( | ) |
If no other process holds the deletion_lock, prunes oldest unused cache items over limit.
References deletion_lock, prune(), lockfile::try_lock_write(), and lockfile::unlock().
Referenced by run_gcc().
|
private |
Referenced by create_item(), and ltrans_file_cache().
|
private |
Referenced by create_item(), and ltrans_file_cache().
lockfile ltrans_file_cache::creation_lock |
Referenced by ltrans_file_cache(), and run_gcc().
lockfile ltrans_file_cache::deletion_lock |
Referenced by ltrans_file_cache(), run_gcc(), and try_prune().
const char* ltrans_file_cache::dir |
Referenced by filename_cachedata(), load_cache(), ltrans_file_cache(), operator bool(), read_cache_item(), save_cache(), and write_cache_item().
|
private |
Referenced by add_item(), cleanup(), load_cache(), prune(), and save_cache().
|
private |
Referenced by add_item(), add_to_cache(), and cleanup().
|
private |
Referenced by add_item(), cleanup(), create_item(), and get_item().
|
private |
Referenced by ltrans_file_cache().
|
private |
Referenced by prune().
|
private |
Referenced by create_item(), ltrans_file_cache(), and ~ltrans_file_cache().
|
private |
Referenced by create_item(), and ltrans_file_cache().
|
private |
Referenced by add_item(), add_to_cache(), cleanup(), create_item(), and load_cache().