• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tudasc / TypeART / 25177145272

30 Apr 2026 04:30PM UTC coverage: 84.647% (-5.6%) from 90.246%
25177145272

Pull #188

github

web-flow
Merge 88918912c into 278119205
Pull Request #188: GPU memory allocation support

127 of 259 new or added lines in 19 files covered. (49.03%)

200 existing lines in 18 files now uncovered.

4510 of 5328 relevant lines covered (84.65%)

27776.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.54
/lib/passes/support/DefUseChain.h
1
// TypeART library
2
//
3
// Copyright (c) 2017-2026 TypeART Authors
4
// Distributed under the BSD 3-Clause license.
5
// (See accompanying file LICENSE.txt or copy at
6
// https://opensource.org/licenses/BSD-3-Clause)
7
//
8
// Project home: https://github.com/tudasc/TypeART
9
//
10
// SPDX-License-Identifier: BSD-3-Clause
11
//
12

13
#ifndef TYPEART_DEFUSECHAIN_H
14
#define TYPEART_DEFUSECHAIN_H
15

16
#include "support/Logger.h"
17
#include "support/Util.h"
18

19
#include "llvm/ADT/SmallPtrSet.h"
20
#include "llvm/IR/Instructions.h"
21

22
#include <algorithm>
23
#include <functional>
24
#include <optional>
25

26
namespace typeart::util {
27

28
struct DefUseChain {
135✔
29
 public:
30
  enum MatchResult { kNoMatch = 0, kMatch, kCancel, kSkip };
31

32
 private:
33
  llvm::SmallVector<llvm::Value*, 16> working_set;
34
  llvm::SmallPtrSet<llvm::Value*, 16> seen_set;
35

36
  void addToWorkS(llvm::Value* v) {
2,070✔
37
    if (v != nullptr && seen_set.find(v) == seen_set.end()) {
2,070✔
38
      working_set.push_back(v);
2,010✔
39
      seen_set.insert(v);
2,010✔
40
    }
2,010✔
41
  }
2,070✔
42

43
  template <typename Range>
44
  void addToWork(Range&& vals) {
2,145✔
45
    for (auto v : vals) {
4,215✔
46
      addToWorkS(v);
2,070✔
47
    }
48
  }
2,145✔
49

50
  auto peek() -> llvm::Value* {
2,010✔
51
    if (working_set.empty()) {
2,010✔
52
      return nullptr;
×
53
    }
54
    auto user_iter = working_set.end() - 1;
2,010✔
55
    auto* value    = *user_iter;
2,010✔
56
    working_set.erase(user_iter);
2,010✔
57
    return value;
2,010✔
58
  }
2,010✔
59

60
  template <typename AllowedTy, typename SDirection, typename CallBackF>
61
  void do_traverse(SDirection&& search, llvm::Value* start, CallBackF match) {
135✔
62
    const auto should_search = [](auto user) {
2,010✔
63
      return llvm::isa<AllowedTy>(user) && !llvm::isa<llvm::ConstantData>(user);
2,010✔
64
    };
65
    const auto apply_search = [&](auto val) {
2,280✔
66
      auto value = search(val);
2,145✔
67
      if (value) {
2,145✔
68
        addToWork(value.value());
2,145✔
69
      }
2,145✔
70
    };
2,145✔
71

72
    apply_search(start);
135✔
73

74
    while (!working_set.empty()) {
2,145✔
75
      auto user = peek();
2,010✔
76
      if (user == nullptr) {
2,010✔
77
        continue;
×
78
      }
79
      if (MatchResult m = match(user); m != kNoMatch) {
2,010✔
80
        switch (m) {
125✔
81
          case kSkip:
82
            continue;
×
83
          case kCancel:
84
            break;
125✔
85
          default:
86
            break;
×
87
        }
88
      }
125✔
89
      if (should_search(user)) {
2,010✔
90
        apply_search(user);
2,010✔
91
      }
2,010✔
92
    }
93
    working_set.clear();
135✔
94
    seen_set.clear();
135✔
95
  }
135✔
96

97
 public:
98
  template <typename CallBackF>
99
  void traverse(llvm::Value* start, CallBackF&& match) {
135✔
100
    LOG_DEBUG("Start traversal for value: " << util::dump(*start));
101
    do_traverse<llvm::Value>([](auto val) -> std::optional<decltype(val->users())> { return val->users(); }, start,
2,415✔
102
                             std::forward<CallBackF>(match));
135✔
103
    LOG_DEBUG("Finished traversal");
104
  }
135✔
105

106
  template <typename Search, typename CallBackF>
UNCOV
107
  void traverse_custom(llvm::Value* start, Search&& s, CallBackF&& match) {
×
108
    LOG_DEBUG("Start traversal for value: " << util::dump(*start));
UNCOV
109
    do_traverse<llvm::Value>(std::forward<Search>(s), start, std::forward<CallBackF>(match));
×
110
    LOG_DEBUG("Finished traversal");
UNCOV
111
  }
×
112

113
  template <typename CallBackF>
114
  void traverse_with_store(llvm::Value* start, CallBackF&& match) {
115
    LOG_DEBUG("Start traversal for value: " << util::dump(*start));
116
    do_traverse<llvm::Value>(
117
        [](auto val) -> std::optional<decltype(val->users())> {
118
          if (auto cinst = llvm::dyn_cast<llvm::StoreInst>(val)) {
119
            return cinst->getPointerOperand()->users();
120
          }
121
          return val->users();
122
        },
123
        start, std::forward<CallBackF>(match));
124
    LOG_DEBUG("Finished traversal");
125
  }
126
};
127

128
}  // namespace typeart::util
129

130
#endif  // TYPEART_DEFUSECHAIN_H
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc