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

vla5924-practice / compiler-project / 14040113630

24 Mar 2025 04:07PM UTC coverage: 82.756% (-0.1%) from 82.886%
14040113630

Pull #227

github

web-flow
Merge 06b6abbc2 into 7fcb1ec48
Pull Request #227: Add replace for results in OptBuilder

0 of 9 new or added lines in 1 file covered. (0.0%)

5 existing lines in 1 file now uncovered.

4756 of 5747 relevant lines covered (82.76%)

268.68 hits per line

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

77.94
/compiler/lib/backend/optree/optimizer/opt_builder.cpp
1
#include "optimizer/opt_builder.hpp"
2

3
#include <functional>
4

5
#include "compiler/optree/builder.hpp"
6
#include "compiler/optree/operation.hpp"
7
#include "compiler/optree/value.hpp"
8
#include "compiler/utils/debug.hpp"
9
#include "compiler/utils/helpers.hpp"
10

11
using namespace optree;
12
using namespace optree::optimizer;
13

14
using dbg = utils::DebugPrinter;
15

16
namespace {
17

18
void notifyInsertRecursively(const Operation::Ptr &op, const OptBuilder::Notifier &notifier) {
4✔
19
    for (const auto &nestedOp : op->body) {
4✔
20
        notifyInsertRecursively(nestedOp, notifier);
×
21
        notifier.notifyInsert(nestedOp);
×
22
    }
23
}
4✔
24

25
} // namespace
26

27
OptBuilder::Notifier::Notifier(const Callback &onInsert, const Callback &onUpdate, const Callback &onErase)
×
28
    : onInsert(onInsert), onUpdate(onUpdate), onErase(onErase) {
×
29
}
×
30

31
void OptBuilder::Notifier::notifyInsert(const Operation::Ptr &op) const {
37✔
32
    if (onInsert)
37✔
33
        onInsert(op);
37✔
34
}
37✔
35

36
void OptBuilder::Notifier::notifyUpdate(const Operation::Ptr &op) const {
4✔
37
    if (onUpdate)
4✔
38
        onUpdate(op);
4✔
39
}
4✔
40

41
void OptBuilder::Notifier::notifyErase(const Operation::Ptr &op) const {
83✔
42
    if (onErase)
83✔
43
        onErase(op);
60✔
44
}
83✔
45

46
void OptBuilder::insert(const Operation::Ptr &op) {
37✔
47
    COMPILER_DEBUG(dbg::get() << "  Insert " << op->name << '\n');
37✔
48
    Builder::insert(op);
37✔
49
    notifier.notifyInsert(op);
37✔
50
}
37✔
51

52
Operation::Ptr OptBuilder::clone(const Operation::Ptr &op) {
4✔
53
    COMPILER_DEBUG(dbg::get() << "  Clone " << op->name << "{\n");
4✔
54
    auto newOp = op->clone();
4✔
55
    notifyInsertRecursively(newOp, notifier);
4✔
56
    insert(newOp);
4✔
57
    COMPILER_DEBUG(dbg::get() << "  }\n");
4✔
58
    return newOp;
4✔
59
}
×
60

61
void OptBuilder::erase(const Operation::Ptr &op) {
83✔
62
    if (op->parent)
83✔
63
        setInsertPointAfter(op);
83✔
64
    while (!op->body.empty()) {
113✔
65
        erase(op->body.back());
30✔
66
    }
67
    COMPILER_DEBUG(dbg::get() << "  Erase " << op->name << '\n');
83✔
68
    notifier.notifyErase(op);
83✔
69
    op->erase();
83✔
70
}
83✔
71

72
void OptBuilder::update(const Operation::Ptr &op, const std::function<void()> &actor) {
4✔
73
    COMPILER_DEBUG(dbg::get() << "  Update " << op->name << '\n');
4✔
74
    if (actor)
4✔
75
        actor();
4✔
76
    notifier.notifyUpdate(op);
4✔
77
}
4✔
78

79
void OptBuilder::replace(const Operation::Ptr &op, const Operation::Ptr &newOp) {
37✔
80
    COMPILER_DEBUG(dbg::get() << "  Replace " << op->name << '\n');
37✔
81
    for (const auto &[oldResult, newResult] : utils::zip(op->results, newOp->results)) {
74✔
82
        for (const auto &use : oldResult->uses) {
41✔
83
            auto user = use.lock();
4✔
84
            update(user, [&] { user->operand(use.operandNumber) = newResult; });
8✔
85
        }
4✔
86
        newResult->uses.splice_after(newResult->uses.before_begin(), oldResult->uses);
37✔
87
    }
37✔
88
    erase(op);
37✔
89
}
37✔
90

NEW
91
void OptBuilder::replace(const Value::Ptr &result, const Value::Ptr &newResult) {
×
NEW
92
    COMPILER_DEBUG(dbg::get() << "  Replace result " << '\n');
×
NEW
93
    for (const auto &use : result->uses) {
×
NEW
94
        auto user = use.lock();
×
NEW
UNCOV
95
        update(user, [&] { user->operand(use.operandNumber) = newResult; });
×
NEW
UNCOV
96
    }
×
NEW
UNCOV
97
    newResult->uses.splice_after(newResult->uses.before_begin(), result->uses);
×
NEW
UNCOV
98
    erase(result->owner.lock());
×
NEW
UNCOV
99
}
×
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