|
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;
|
@@ -245,40 +246,35 @@ class SpackInstallationDetector : public InstallationDetector {
|
245 | 246 | }
|
246 | 247 | };
|
247 | 248 |
|
248 |
| -InstallationDetector *CreatePathDetector(StringRef Path, |
249 |
| - bool isComgrPath = false) { |
| 249 | +std::shared_ptr<InstallationDetector> |
| 250 | +CreatePathDetector(StringRef Path, bool isComgrPath = false) { |
250 | 251 | StringRef DirName = llvm::sys::path::filename(Path);
|
251 | 252 | if ((!isComgrPath && DirName.starts_with("rocm-cmake-")) ||
|
252 | 253 | (isComgrPath && DirName.starts_with("comgr-"))) {
|
253 |
| - return new SpackInstallationDetector(Path, isComgrPath); |
| 254 | + return std::make_shared<SpackInstallationDetector>(Path, isComgrPath); |
254 | 255 | }
|
255 | 256 |
|
256 |
| - return new InstallationDetector(Path, isComgrPath); |
| 257 | + return std::make_shared<InstallationDetector>(Path, isComgrPath); |
257 | 258 | }
|
258 | 259 |
|
259 |
| -InstallationDetector *getDetectorImpl() { |
| 260 | +std::shared_ptr<InstallationDetector> getDetectorImpl() { |
260 | 261 | SmallString<128> ROCmInstallPath;
|
261 | 262 |
|
262 | 263 | static const char *EnvROCMPath = std::getenv("ROCM_PATH");
|
263 | 264 | if (EnvROCMPath) {
|
264 | 265 | ROCmInstallPath = EnvROCMPath;
|
265 | 266 | }
|
266 | 267 |
|
267 |
| - InstallationDetector *Detector; |
268 | 268 | if (ROCmInstallPath == "") {
|
269 | 269 | std::string ComgrInstallationPath = getComgrInstallPathFromExecutable();
|
270 |
| - Detector = |
271 |
| - CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */); |
272 |
| - } else { |
273 |
| - Detector = CreatePathDetector(ROCmInstallPath); |
| 270 | + return CreatePathDetector(ComgrInstallationPath, true /* isComgrPath */); |
274 | 271 | }
|
275 |
| - |
276 |
| - return Detector; |
| 272 | + return CreatePathDetector(ROCmInstallPath); |
277 | 273 | }
|
278 | 274 |
|
279 | 275 | InstallationDetector *getDetector() {
|
280 |
| - static InstallationDetector *Detector = getDetectorImpl(); |
281 |
| - return Detector; |
| 276 | + static auto Detector = getDetectorImpl(); |
| 277 | + return Detector.get(); |
282 | 278 | }
|
283 | 279 |
|
284 | 280 | llvm::StringRef getROCMPath() { return getDetector()->getROCmPath(); }
|
|
0 commit comments