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

vla5924-practice / compiler-project / 14006464010

22 Mar 2025 07:26AM UTC coverage: 82.895% (+0.009%) from 82.886%
14006464010

Pull #197

github

web-flow
Merge 0ab7716ba into a5e3ea566
Pull Request #197: Perform convergent transformation within CascadeTransform

125 of 138 new or added lines in 8 files covered. (90.58%)

1 existing line in 1 file now uncovered.

4759 of 5741 relevant lines covered (82.89%)

268.98 hits per line

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

90.32
/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/utils/debug.hpp"
8
#include "compiler/utils/helpers.hpp"
9

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

13
using dbg = utils::DebugPrinter;
14

15
namespace {
16

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

24
} // namespace
25

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

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

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

40
void OptBuilder::Notifier::notifyErase(const Operation::Ptr &op) const {
83✔
41
    if (onErase) {
83✔
42
        std::cerr << "Call notifier on erase!\n";
60✔
43
        onErase(op);
60✔
44
        std::cerr << "Called notifier on erase!\n";
60✔
45
    } else
46
        std::cerr << "No notifier on erase!\n";
23✔
47
}
83✔
48

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

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

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

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

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