@@ -40,15 +40,25 @@ IRTempVariable getIRTempVariable(Locatable ast, TempVariableTag tag) {
40
40
result .getTag ( ) = tag
41
41
}
42
42
43
- /** Gets an operand of `binOp `. */
44
- private Expr getAnOperand ( BinaryOperation binOp ) { result = binOp .getAnOperand ( ) }
43
+ /** Gets an operand of `op `. */
44
+ private Expr getAnOperand ( Operation op ) { result = op .getAnOperand ( ) }
45
45
46
46
/**
47
- * Gets the number of nested operands of `binOp `. For example,
47
+ * Gets the number of nested operands of `op `. For example,
48
48
* `getNumberOfNestedBinaryOperands((1 + 2) + 3))` is `3`.
49
49
*/
50
- private int getNumberOfNestedBinaryOperands ( BinaryOperation binOp ) {
51
- result = count ( getAnOperand * ( binOp ) )
50
+ private int getNumberOfNestedBinaryOperands ( Operation op ) { result = count ( getAnOperand * ( op ) ) }
51
+
52
+ /**
53
+ * Holds if `op` should not be translated to a `ConstantInstruction` as part of
54
+ * IR generation, even if the value of `op` is constant.
55
+ */
56
+ private predicate ignoreConstantValue ( Operation op ) {
57
+ op instanceof BitwiseAndExpr
58
+ or
59
+ op instanceof BitwiseOrExpr
60
+ or
61
+ op instanceof BitwiseXorExpr
52
62
}
53
63
54
64
/**
@@ -58,14 +68,14 @@ private int getNumberOfNestedBinaryOperands(BinaryOperation binOp) {
58
68
*/
59
69
predicate isIRConstant ( Expr expr ) {
60
70
exists ( expr .getValue ( ) ) and
61
- // We avoid constant folding binary operations since it's often useful to
71
+ // We avoid constant folding certain operations since it's often useful to
62
72
// mark one of those as a source in dataflow, and if the operation is
63
73
// constant folded it's not possible to mark its operands as a source (or
64
74
// sink).
65
75
// But to avoid creating an outrageous amount of IR from very large
66
76
// constant expressions we fall back to constant folding if the operation
67
77
// has more than 50 operands (i.e., 1 + 2 + 3 + 4 + ... + 50)
68
- if expr instanceof BinaryOperation then getNumberOfNestedBinaryOperands ( expr ) > 50 else any ( )
78
+ if ignoreConstantValue ( expr ) then getNumberOfNestedBinaryOperands ( expr ) > 50 else any ( )
69
79
}
70
80
71
81
// Pulled out for performance. See
0 commit comments