Coverage Report

Created: 2023-09-21 18:56

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/ToolChains/LazyDetector.h
Line
Count
Source
1
//===--- LazyDetector.h - Lazy ToolChain Detection --------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
10
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H
11
12
#include "clang/Driver/Tool.h"
13
#include "clang/Driver/ToolChain.h"
14
#include <optional>
15
16
namespace clang {
17
18
/// Simple wrapper for toolchain detector with costly initialization. This
19
/// delays the creation of the actual detector until its first usage.
20
21
template <class T> class LazyDetector {
22
  const driver::Driver &D;
23
  llvm::Triple Triple;
24
  const llvm::opt::ArgList &Args;
25
26
  std::optional<T> Detector;
27
28
public:
29
  LazyDetector(const driver::Driver &D, const llvm::Triple &Triple,
30
               const llvm::opt::ArgList &Args)
31
39.8k
      : D(D), Triple(Triple), Args(Args) {}
clang::LazyDetector<clang::driver::CudaInstallationDetector>::LazyDetector(clang::driver::Driver const&, llvm::Triple const&, llvm::opt::ArgList const&)
Line
Count
Source
31
19.9k
      : D(D), Triple(Triple), Args(Args) {}
clang::LazyDetector<clang::driver::RocmInstallationDetector>::LazyDetector(clang::driver::Driver const&, llvm::Triple const&, llvm::opt::ArgList const&)
Line
Count
Source
31
19.9k
      : D(D), Triple(Triple), Args(Args) {}
32
2.04k
  T *operator->() {
33
2.04k
    if (!Detector)
34
865
      Detector.emplace(D, Triple, Args);
35
2.04k
    return &*Detector;
36
2.04k
  }
clang::LazyDetector<clang::driver::CudaInstallationDetector>::operator->()
Line
Count
Source
32
110
  T *operator->() {
33
110
    if (!Detector)
34
110
      Detector.emplace(D, Triple, Args);
35
110
    return &*Detector;
36
110
  }
clang::LazyDetector<clang::driver::RocmInstallationDetector>::operator->()
Line
Count
Source
32
1.93k
  T *operator->() {
33
1.93k
    if (!Detector)
34
755
      Detector.emplace(D, Triple, Args);
35
1.93k
    return &*Detector;
36
1.93k
  }
37
1.55k
  const T *operator->() const {
38
1.55k
    return const_cast<T const *>(
39
1.55k
        const_cast<LazyDetector &>(*this).operator->());
40
1.55k
  }
clang::LazyDetector<clang::driver::CudaInstallationDetector>::operator->() const
Line
Count
Source
37
110
  const T *operator->() const {
38
110
    return const_cast<T const *>(
39
110
        const_cast<LazyDetector &>(*this).operator->());
40
110
  }
clang::LazyDetector<clang::driver::RocmInstallationDetector>::operator->() const
Line
Count
Source
37
1.44k
  const T *operator->() const {
38
1.44k
    return const_cast<T const *>(
39
1.44k
        const_cast<LazyDetector &>(*this).operator->());
40
1.44k
  }
41
};
42
43
} // end namespace clang
44
45
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_LAZYDETECTOR_H