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

vla5924-practice / compiler-project / 13884489619

16 Mar 2025 02:44PM UTC coverage: 77.883% (+1.2%) from 76.638%
13884489619

Pull #212

github

web-flow
Merge 37571da47 into 9f356f9ca
Pull Request #212: Implement fold control flow optimization

25 of 37 new or added lines in 1 file covered. (67.57%)

323 existing lines in 11 files now uncovered.

4437 of 5697 relevant lines covered (77.88%)

250.1 hits per line

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

73.79
/compiler/lib/optree/adaptors.cpp
1
#include "adaptors.hpp"
2

3
#include <string>
4
#include <vector>
5

6
#include "definitions.hpp"
7
#include "operation.hpp"
8
#include "types.hpp"
9
#include "value.hpp"
10

11
using namespace optree;
12

13
// The following definitions for the methods of the operation classes should be arranged in alphabetical order.
14

15
void AllocateOp::init(const Type::Ptr &type, const Value::Ptr &dynamicSize) {
41✔
16
    op->results.emplace_back(Value::make(type, op));
41✔
17
    if (dynamicSize)
41✔
18
        op->addOperand(dynamicSize);
2✔
19
}
41✔
20

21
Value::Ptr AllocateOp::dynamicSize() const {
2✔
22
    if (op->numOperands() == 1)
2✔
23
        return op->operand(0);
2✔
24
    return {};
×
25
}
26

27
void AllocateOp::setDynamicSize(const Value::Ptr &value) {
×
28
    if (op->numOperands() == 1)
×
29
        op->operand(0) = value;
×
30
    else
31
        op->addOperand(value);
×
32
}
×
33

34
void ArithBinaryOp::init(ArithBinOpKind kind, const Type::Ptr &resultType, const Value::Ptr &lhs,
103✔
35
                         const Value::Ptr &rhs) {
36
    BinaryOp::init(resultType, lhs, rhs);
103✔
37
    op->addAttr(kind);
103✔
38
}
103✔
39

40
void ArithBinaryOp::init(ArithBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs) {
94✔
41
    init(kind, lhs->type, lhs, rhs);
94✔
42
}
94✔
43

44
void ArithCastOp::init(ArithCastOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value) {
30✔
45
    UnaryOp::init(resultType, value);
30✔
46
    op->addAttr(kind);
30✔
47
}
30✔
48

UNCOV
49
void ArithUnaryOp::init(ArithUnaryOpKind kind, const Type::Ptr &resultType, const Value::Ptr &value) {
×
UNCOV
50
    UnaryOp::init(resultType, value);
×
UNCOV
51
    op->addAttr(kind);
×
UNCOV
52
}
×
53

UNCOV
54
void ArithUnaryOp::init(ArithUnaryOpKind kind, const Value::Ptr &value) {
×
55
    init(kind, value->type, value);
×
56
}
×
57

58
void BinaryOp::init(const Type::Ptr &resultType, const Value::Ptr &lhs, const Value::Ptr &rhs) {
148✔
59
    op->addResult(resultType);
148✔
60
    op->addOperand(lhs);
148✔
61
    op->addOperand(rhs);
148✔
62
}
148✔
63

64
void ConditionOp::init() {
×
65
}
×
66

UNCOV
67
Value::Ptr ConditionOp::terminator() const {
×
UNCOV
68
    if (op->body.empty())
×
UNCOV
69
        return {};
×
UNCOV
70
    return op->body.back()->result(0);
×
71
}
72

UNCOV
73
void ElseOp::init() {
×
UNCOV
74
}
×
75

76
void ForOp::init(const Type::Ptr &iteratorType, const Value::Ptr &start, const Value::Ptr &stop,
8✔
77
                 const Value::Ptr &step) {
78
    op->addOperand(start);
8✔
79
    op->addOperand(stop);
8✔
80
    op->addOperand(step);
8✔
81
    op->addInward(iteratorType);
8✔
82
}
8✔
83

84
void FunctionOp::init(const std::string &name, const Type::Ptr &funcType) {
134✔
85
    op->addAttr(name);
134✔
86
    op->addAttr(funcType);
134✔
87
    for (const auto &argType : funcType->as<FunctionType>().arguments)
267✔
88
        op->addInward(argType);
133✔
89
}
134✔
90

91
void FunctionCallOp::init(const std::string &name, const Type::Ptr &resultType,
47✔
92
                          const std::vector<Value::Ptr> &arguments) {
93
    op->operands = arguments;
47✔
94
    op->results.emplace_back(Value::make(resultType, op));
47✔
95
    op->addAttr(name);
47✔
96
}
47✔
97

UNCOV
98
void FunctionCallOp::init(const FunctionOp &callee, const std::vector<Value::Ptr> &arguments) {
×
UNCOV
99
    init(callee.name(), callee.type().result, arguments);
×
UNCOV
100
}
×
101

102
void IfOp::init(const Value::Ptr &cond, bool withElse) {
7✔
103
    op->addOperand(cond);
7✔
104
    op->addToBody(Operation::make<ThenOp>(op).op);
7✔
105
    if (withElse)
7✔
106
        op->addToBody(Operation::make<ElseOp>(op).op);
4✔
107
}
7✔
108

109
ThenOp IfOp::thenOp() const {
12✔
110
    return {op->body.front()};
12✔
111
}
112

113
ElseOp IfOp::elseOp() const {
7✔
114
    return {op->body.size() == 2 ? op->body.back() : nullptr};
7✔
115
}
116

117
void InputOp::init(const Value::Ptr &dst) {
10✔
118
    op->addOperand(dst);
10✔
119
}
10✔
120

121
void LoadOp::init(const Type::Ptr &resultType, const Value::Ptr &src, const Value::Ptr &offset) {
32✔
122
    op->addOperand(src);
32✔
123
    if (offset)
32✔
124
        op->addOperand(offset);
10✔
125
    op->results.emplace_back(Value::make(resultType, op));
32✔
126
}
32✔
127

128
void LoadOp::init(const Value::Ptr &src, const Value::Ptr &offset) {
32✔
129
    auto resultType = src->type->as<PointerType>().pointee;
32✔
130
    init(resultType, src, offset);
32✔
131
}
32✔
132

133
Value::Ptr LoadOp::offset() const {
27✔
134
    if (op->numOperands() == 2)
27✔
135
        return op->operand(1);
10✔
136
    return {};
17✔
137
}
138

UNCOV
139
void LoadOp::setOffset(const Value::Ptr &value) {
×
UNCOV
140
    if (op->numOperands() == 2)
×
UNCOV
141
        op->operand(1) = value;
×
142
    else
UNCOV
143
        op->addOperand(value);
×
UNCOV
144
}
×
145

146
void LogicBinaryOp::init(LogicBinOpKind kind, const Value::Ptr &lhs, const Value::Ptr &rhs) {
44✔
147
    BinaryOp::init(TypeStorage::boolType(), lhs, rhs);
44✔
148
    op->addAttr(kind);
44✔
149
}
44✔
150

151
void LogicUnaryOp::init(LogicUnaryOpKind kind, const Value::Ptr &value) {
5✔
152
    UnaryOp::init(TypeStorage::boolType(), value);
5✔
153
    op->addAttr(kind);
5✔
154
}
5✔
155

UNCOV
156
void ModuleOp::init() {
×
UNCOV
157
}
×
158

159
void PrintOp::init(const Value::Ptr &valueToPrint) {
6✔
160
    op->addOperand(valueToPrint);
6✔
161
}
6✔
162

163
void PrintOp::init(const std::vector<Value::Ptr> &valuesToPrint) {
17✔
164
    for (const auto &value : valuesToPrint)
54✔
165
        op->addOperand(value);
37✔
166
}
17✔
167

168
void ReturnOp::init() {
116✔
169
}
116✔
170

171
void ReturnOp::init(const Value::Ptr &value) {
11✔
172
    op->addOperand(value);
11✔
173
}
11✔
174

175
void StoreOp::init(const Value::Ptr &dst, const Value::Ptr &valueToStore, const Value::Ptr &offset) {
39✔
176
    op->addOperand(dst);
39✔
177
    op->addOperand(valueToStore);
39✔
178
    if (offset)
39✔
179
        op->addOperand(offset);
13✔
180
}
39✔
181

182
Value::Ptr StoreOp::offset() const {
18✔
183
    if (op->numOperands() == 3)
18✔
184
        return op->operand(2);
13✔
185
    return {};
5✔
186
}
187

UNCOV
188
void StoreOp::setOffset(const Value::Ptr &value) {
×
UNCOV
189
    if (op->numOperands() == 3)
×
UNCOV
190
        op->operand(2) = value;
×
191
    else
UNCOV
192
        op->addOperand(value);
×
UNCOV
193
}
×
194

UNCOV
195
void ThenOp::init() {
×
UNCOV
196
}
×
197

198
void UnaryOp::init(const Type::Ptr &resultType, const Value::Ptr &value) {
35✔
199
    op->addResult(resultType);
35✔
200
    op->addOperand(value);
35✔
201
}
35✔
202

203
void WhileOp::init() {
1✔
204
    op->addToBody(Operation::make<ConditionOp>(op).op);
1✔
205
}
1✔
206

207
ConditionOp WhileOp::conditionOp() const {
1✔
208
    return {op->body.front()};
1✔
209
}
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

© 2025 Coveralls, Inc