File tree Expand file tree Collapse file tree 5 files changed +57
-6
lines changed Expand file tree Collapse file tree 5 files changed +57
-6
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,22 @@ Comgr supports an environment variable to help locate LLVM:
114
114
installation, which is currently used to locate the clang resource directory
115
115
and clang binary path, allowing for additional optimizations.
116
116
117
+ Comgr utilizes a cache to preserve the results of compilations between executions.
118
+ The cache's status (enabled/disabled), storage location for its results,
119
+ and eviction policy can be manipulated through specific environment variables.
120
+ If an issue arises during cache initialization, the execution will proceed with
121
+ the cache turned off.
122
+
123
+ * ` AMD_COMGR_CACHE_DIR ` : When set to "", the cache is turned off. If assigned a
124
+ value, that value is used as the path for cache storage. By default, it is
125
+ directed to "$XDG_CACHE_HOME/comgr_cache" (which defaults to
126
+ "$USER/.cache/comgr_cache" on Linux, and "%LOCALAPPDATA%\cache\comgr_cache"
127
+ on Windows).
128
+ * ` AMD_COMGR_CACHE_POLICY ` : If assigned a value, the string is interpreted and
129
+ applied to the cache pruning policy. The cache is pruned only upon program
130
+ termination. The string format aligns with [ Clang's ThinLTO cache pruning policy] ( https://clang.llvm.org/docs/ThinLTO.html#cache-pruning ) .
131
+ The default policy is set as: "prune_interval=1h: prune_expiration =0h: cache_size =75%: cache_size_bytes =30g: cache_size_files =0".
132
+
117
133
Comgr also supports some environment variables to aid in debugging. These
118
134
include:
119
135
Original file line number Diff line number Diff line change 37
37
#include " llvm/ADT/Twine.h"
38
38
#include " llvm/Support/VirtualFileSystem.h"
39
39
40
- #include < fstream>
41
- #include < memory>
42
- #include < stdlib.h>
43
-
44
40
using namespace llvm ;
45
41
46
42
namespace COMGR {
@@ -79,5 +75,28 @@ llvm::StringRef getLLVMPath() {
79
75
return EnvLLVMPath;
80
76
}
81
77
78
+ StringRef getCachePolicy () {
79
+ static const char *EnvCachePolicy = std::getenv (" AMD_COMGR_CACHE_POLICY" );
80
+ return EnvCachePolicy;
81
+ }
82
+
83
+ StringRef getCacheDirectory () {
84
+ static const char *EnvCacheDirectory = std::getenv (" AMD_COMGR_CACHE_DIR" );
85
+ if (EnvCacheDirectory)
86
+ return EnvCacheDirectory;
87
+
88
+ // mark Result as static to keep it cached across calls
89
+ static SmallString<256 > Result;
90
+ if (!Result.empty ())
91
+ return Result;
92
+
93
+ if (sys::path::cache_directory (Result)) {
94
+ sys::path::append (Result, Twine (" comgr_cache" ));
95
+ return Result;
96
+ }
97
+
98
+ return " " ;
99
+ }
100
+
82
101
} // namespace env
83
102
} // namespace COMGR
Original file line number Diff line number Diff line change @@ -59,6 +59,15 @@ bool needTimeStatistics();
59
59
// / otherwise return the default LLVM path.
60
60
llvm::StringRef getLLVMPath ();
61
61
62
+ // / If environment variable AMD_COMGR_CACHE_POLICY is set, return the
63
+ // / environment variable, otherwise return empty
64
+ llvm::StringRef getCachePolicy ();
65
+
66
+ // / If environment variable AMD_COMGR_CACHE_DIR is set, return the environment
67
+ // / variable, otherwise return the default path: On Linux it's typically
68
+ // / $HOME/.cache/comgr_cache (depends on XDG_CACHE_HOME)
69
+ llvm::StringRef getCacheDirectory ();
70
+
62
71
} // namespace env
63
72
} // namespace COMGR
64
73
Original file line number Diff line number Diff line change 14
14
15
15
if not config .comgr_disable_spirv :
16
16
config .available_features .add ("comgr-has-spirv" )
17
+
18
+ # By default, disable the cache for the tests.
19
+ # Test for the cache must explicitly enable this variable.
20
+ config .environment ['AMD_COMGR_CACHE_DIR' ] = ""
Original file line number Diff line number Diff line change @@ -193,9 +193,12 @@ endif()
193
193
add_dependencies (check-comgr ${name} )
194
194
# Windows binaries have no equivalent to RPATH, so we must set their PATH to
195
195
# include the .lib/.dll directory.
196
- if (NOT ( UNIX ) )
196
+ if (UNIX )
197
197
set_tests_properties (${test_name}
198
- PROPERTIES ENVIRONMENT "PATH=$<TARGET_LINKER_FILE_DIR:amd_comgr>" )
198
+ PROPERTIES ENVIRONMENT "AMD_COMGR_CACHE_DIR=;" )
199
+ else ()
200
+ set_tests_properties (${test_name}
201
+ PROPERTIES ENVIRONMENT "PATH=$<TARGET_LINKER_FILE_DIR:amd_comgr>;AMD_COMGR_CACHE_DIR=;" )
199
202
endif ()
200
203
endmacro ()
201
204
You can’t perform that action at this time.
0 commit comments