|
38 | 38 | #include "llvm/Support/VirtualFileSystem.h"
|
39 | 39 |
|
40 | 40 | #include <fstream>
|
| 41 | +#include <memory> |
41 | 42 | #include <stdlib.h>
|
42 | 43 |
|
43 | 44 | using namespace llvm;
|
@@ -241,40 +242,35 @@ class SpackInstallationDetector : public InstallationDetector {
|
241 | 242 | }
|
242 | 243 | };
|
243 | 244 |
|
244 |
| -InstallationDetector *CreatePathDetector(StringRef Path, |
245 |
| - bool isComgrPath = false) { |
| 245 | +std::shared_ptr<InstallationDetector> |
| 246 | +CreatePathDetector(StringRef Path, bool isComgrPath = false) { |
246 | 247 | StringRef DirName = llvm::sys::path::filename(Path);
|
247 | 248 | if ((!isComgrPath && DirName.starts_with("rocm-cmake-")) ||
|
248 | 249 | (isComgrPath && DirName.starts_with("comgr-"))) {
|
249 |
| - return new SpackInstallationDetector(Path, isComgrPath); |
| 250 | + return std::make_shared<SpackInstallationDetector>(Path, isComgrPath); |
250 | 251 | }
|
251 | 252 |
|
252 |
| - return new InstallationDetector(Path, isComgrPath); |
| 253 | + return std::make_shared<InstallationDetector>(Path, isComgrPath); |
253 | 254 | }
|
254 | 255 |
|
255 |
| -InstallationDetector *getDetectorImpl() { |
| 256 | +std::shared_ptr<InstallationDetector> getDetectorImpl() { |
256 | 257 | SmallString<128> ROCmInstallPath;
|
257 | 258 |
|
258 | 259 | static const char *EnvROCMPath = std::getenv("ROCM_PATH");
|
259 | 260 | if (EnvROCMPath) {
|
260 | 261 | ROCmInstallPath = EnvROCMPath;
|
261 | 262 | }
|
262 | 263 |
|
263 |
| - InstallationDetector *Detector; |
264 | 264 | if (ROCmInstallPath == "") {
|
265 | 265 | std::string ComgrInstallationPath = getComgrInstallPathFromExecutable();
|
266 |
| - Detector = |
267 |
| - CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */); |
268 |
| - } else { |
269 |
| - Detector = CreatePathDetector(ROCmInstallPath); |
| 266 | + return CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */); |
270 | 267 | }
|
271 |
| - |
272 |
| - return Detector; |
| 268 | + return CreatePathDetector(ROCmInstallPath); |
273 | 269 | }
|
274 | 270 |
|
275 | 271 | InstallationDetector *getDetector() {
|
276 |
| - static InstallationDetector *Detector = getDetectorImpl(); |
277 |
| - return Detector; |
| 272 | + static auto Detector = getDetectorImpl(); |
| 273 | + return Detector.get(); |
278 | 274 | }
|
279 | 275 |
|
280 | 276 | llvm::StringRef getROCMPath() { return getDetector()->getROCmPath(); }
|
|
0 commit comments