MCPcopy Create free account
hub / github.com/KhronosGroup/SPIRV-Tools / GetBoolConstantKind

Function GetBoolConstantKind

source/opt/folding_rules.cpp:3035–3061  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3033}
3034
3035std::optional<bool> GetBoolConstantKind(const analysis::Constant* c) {
3036 if (!c) {
3037 return {};
3038 }
3039 if (auto composite = c->AsCompositeConstant()) {
3040 auto& components = composite->GetComponents();
3041 if (components.empty()) {
3042 return {};
3043 }
3044 auto first = GetBoolConstantKind(components[0]);
3045 if (!first) {
3046 return {};
3047 }
3048 if (std::all_of(std::begin(components) + 1, std::end(components),
3049 [first](const analysis::Constant* c2) {
3050 return GetBoolConstantKind(c2) == first;
3051 })) {
3052 return first;
3053 }
3054 return {};
3055 } else if (c->AsNullConstant()) {
3056 return false;
3057 } else if (c->AsBoolConstant()) {
3058 return c->AsBoolConstant()->value();
3059 }
3060 return {};
3061}
3062
3063// Fold OpSelect instructions which have constant booleans as their result.
3064// x ? true : false = x

Callers 4

RedundantLogicalAndFunction · 0.85
RedundantLogicalOrFunction · 0.85
RedundantLogicalEqualFunction · 0.85

Calls 5

AsCompositeConstantMethod · 0.45
emptyMethod · 0.45
AsNullConstantMethod · 0.45
AsBoolConstantMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected