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

vla5924-practice / compiler-project / 13526105148

25 Feb 2025 04:29PM UTC coverage: 83.551% (+0.4%) from 83.152%
13526105148

Pull #191

github

web-flow
Merge 925f7fa16 into 5d7c8614a
Pull Request #191: Implement an accurate up to layout operation comparison function

33 of 35 new or added lines in 2 files covered. (94.29%)

3256 of 3897 relevant lines covered (83.55%)

275.64 hits per line

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

88.24
/compiler/lib/optree/helpers.cpp
1
#include "helpers.hpp"
2

3
#include <algorithm>
4

5
#include "compiler/utils/source_ref.hpp"
6

7
#include "compiler/optree/adaptors.hpp"
8
#include "compiler/optree/attribute.hpp"
9
#include "compiler/optree/base_adaptor.hpp"
10
#include "compiler/optree/builder.hpp"
11
#include "compiler/optree/definitions.hpp"
12
#include "compiler/optree/types.hpp"
13
#include "compiler/optree/value.hpp"
14

15
namespace optree {
16

17
Type::Ptr deduceTargetCastType(const Type::Ptr &outType, const Type::Ptr &inType, bool isAssignment) {
5✔
18
    if (isAssignment)
5✔
19
        return outType;
1✔
20
    if (inType == outType)
4✔
21
        return inType;
×
22
    bool fromInt = inType->is<IntegerType>();
4✔
23
    bool fromFloat = inType->is<FloatType>();
4✔
24
    bool toInt = outType->is<IntegerType>();
4✔
25
    bool toFloat = outType->is<FloatType>();
4✔
26
    bool isExt = inType->bitWidth() < outType->bitWidth();
4✔
27
    if (fromFloat && toInt)
4✔
28
        return inType;
3✔
29
    if (fromInt && toFloat)
1✔
30
        return outType;
1✔
31
    if (fromFloat && toFloat || fromInt && toInt)
×
32
        return isExt ? outType : inType;
×
33
    return {};
×
34
}
35

36
ArithCastOp insertNumericCastOp(const Type::Ptr &resultType, const Value::Ptr &value, Builder &builder,
11✔
37
                                utils::SourceRef &ref) {
38
    const auto &inType = value->type;
11✔
39
    if (inType == resultType)
11✔
40
        return {};
4✔
41
    bool fromInt = inType->is<IntegerType>();
7✔
42
    bool fromFloat = inType->is<FloatType>();
7✔
43
    bool toInt = resultType->is<IntegerType>();
7✔
44
    bool toFloat = resultType->is<FloatType>();
7✔
45
    bool isExt = inType->bitWidth() < resultType->bitWidth();
7✔
46
    auto kind = ArithCastOpKind::Unknown;
7✔
47
    if (fromInt && toInt)
7✔
48
        kind = isExt ? ArithCastOpKind::ExtI : ArithCastOpKind::TruncI;
×
49
    else if (fromFloat && toFloat)
7✔
50
        kind = isExt ? ArithCastOpKind::ExtF : ArithCastOpKind::TruncF;
×
51
    else if (fromInt && toFloat)
7✔
52
        kind = ArithCastOpKind::IntToFloat;
4✔
53
    else if (fromFloat && toInt)
3✔
54
        kind = ArithCastOpKind::FloatToInt;
2✔
55
    else
56
        return {};
1✔
57
    return builder.insert<ArithCastOp>(ref, kind, resultType, value);
6✔
58
}
59

60
bool similar(const Operation::Ptr &lhs, const Operation::Ptr &rhs, bool checkBody) {
94✔
61
    if (lhs->name != rhs->name)
94✔
62
        return false;
4✔
63
    if (lhs->as<Adaptor>().getSpecId() != rhs->as<Adaptor>().getSpecId())
90✔
NEW
64
        return false;
×
65
    auto attrEqual = [](const Attribute &lhs, const Attribute &rhs) { return lhs == rhs; };
84✔
66
    if (!std::ranges::equal(lhs->attributes, rhs->attributes, attrEqual))
90✔
67
        return false;
13✔
68
    auto operandEqual = [&lhs, &rhs](const Value::Ptr &lhsValue, const Value::Ptr &rhsValue) {
66✔
69
        bool type = lhsValue->sameType(rhsValue);
22✔
70
        auto lhsOwner = lhsValue->owner.lock();
22✔
71
        auto rhsOwner = rhsValue->owner.lock();
22✔
72
        bool sameGlobalOwner = lhsOwner == rhsOwner;
22✔
73
        bool similarLocalOwner = false;
22✔
74
        if (!sameGlobalOwner && lhsOwner != lhs && rhsOwner != rhs) {
22✔
75
            similarLocalOwner = similar(lhsOwner, rhsOwner, false);
22✔
76
        }
77
        return type && (sameGlobalOwner || similarLocalOwner);
44✔
78
    };
22✔
79
    if (!std::ranges::equal(lhs->operands, rhs->operands, operandEqual))
77✔
80
        return false;
3✔
81
    auto valueEqual = [](const Value::Ptr &lhsValue, const Value::Ptr &rhsValue) {
66✔
82
        return lhsValue->sameType(rhsValue);
66✔
83
    };
84
    if (!std::ranges::equal(lhs->inwards, rhs->inwards, valueEqual))
74✔
NEW
85
        return false;
×
86
    if (!std::ranges::equal(lhs->results, rhs->results, valueEqual))
74✔
87
        return false;
2✔
88
    bool body = true;
72✔
89
    if (checkBody) {
72✔
90
        body = std::ranges::equal(lhs->body, rhs->body, [](const Operation::Ptr &lhs, const Operation::Ptr &rhs) {
53✔
91
            return similar(lhs, rhs, true);
37✔
92
        });
93
    }
94
    return body;
72✔
95
}
96

97
} // namespace optree
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