git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: update arithmetic operator inlining to 0.9
a0d4389Andy Arvanitis
src/Language/PureScript/CodeGen/Cpp/Optimizer/Inliner.hs+12−5
@@ -105,11 +105,16 @@ inlineCommonValues = everywhereOnCpp convert
105 | isDict' [semiringNumber, semiringInt] dict && isFn fnOne fn = CppNumericLiteral (Left 1)
105 | isDict' [semiringNumber, semiringInt] dict && isFn fnOne fn = CppNumericLiteral (Left 1)
106 | isDict boundedBoolean dict && isFn fnBottom fn = CppBooleanLiteral False
106 | isDict boundedBoolean dict && isFn fnBottom fn = CppBooleanLiteral False
107 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
107 | isDict boundedBoolean dict && isFn fnTop fn = CppBooleanLiteral True
108+ convert (CppApp fn [dict, x, y])
109+ | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
110+ | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
111+ | isDict euclideanRingInt dict && isFn fnDivide fn = CppBinary Divide x y
112+ | isDict ringInt dict && isFn fnSubtract fn = CppBinary Subtract x y
108 convert (CppApp (CppApp (CppApp fn [dict]) [x]) [y])
113 convert (CppApp (CppApp (CppApp fn [dict]) [x]) [y])
109− | isDict semiringInt dict && isFn fnAdd fn = intOp Add x y
114+ | isDict semiringInt dict && isFn fnAdd fn = CppBinary Add x y
110− | isDict semiringInt dict && isFn fnMultiply fn = intOp Multiply x y
115+ | isDict semiringInt dict && isFn fnMultiply fn = CppBinary Multiply x y
111− | isDict euclideanRingInt dict && isFn fnDivide fn = intOp Divide x y
116+ | isDict euclideanRingInt dict && isFn fnDivide fn = CppBinary Divide x y
112− | isDict ringInt dict && isFn fnSubtract fn = intOp Subtract x y
117+ | isDict ringInt dict && isFn fnSubtract fn = CppBinary Subtract x y
113 convert other = other
118 convert other = other
114 fnZero = (C.dataSemiring, C.zero)
119 fnZero = (C.dataSemiring, C.zero)
115 fnOne = (C.dataSemiring, C.one)
120 fnOne = (C.dataSemiring, C.one)
@@ -119,7 +124,6 @@ inlineCommonValues = everywhereOnCpp convert
119 fnDivide = (C.dataEuclideanRing, C.div)
124 fnDivide = (C.dataEuclideanRing, C.div)
120 fnMultiply = (C.dataSemiring, C.mul)
125 fnMultiply = (C.dataSemiring, C.mul)
121 fnSubtract = (C.dataRing, C.sub)
126 fnSubtract = (C.dataRing, C.sub)
122− intOp op x y = CppBinary BitwiseOr (CppBinary op x y) (CppNumericLiteral (Left 0))
123
127
124inlineOperator :: (String, String) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
128inlineOperator :: (String, String) -> (Cpp -> Cpp -> Cpp) -> Cpp -> Cpp
125inlineOperator (m, op) f = everywhereOnCpp convert
129inlineOperator (m, op) f = everywhereOnCpp convert
@@ -198,18 +202,21 @@ inlineCommonOperators = applyAll $
198 binary dict fns op = everywhereOnCpp convert
202 binary dict fns op = everywhereOnCpp convert
199 where
203 where
200 convert :: Cpp -> Cpp
204 convert :: Cpp -> Cpp
205+ convert (CppApp fn [dict', x, y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
201 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
206 convert (CppApp (CppApp (CppApp fn [dict']) [x]) [y]) | isDict dict dict' && isFn fns fn = CppBinary op x y
202 convert other = other
207 convert other = other
203 binary' :: String -> String -> BinaryOperator -> Cpp -> Cpp
208 binary' :: String -> String -> BinaryOperator -> Cpp -> Cpp
204 binary' moduleName opString op = everywhereOnCpp convert
209 binary' moduleName opString op = everywhereOnCpp convert
205 where
210 where
206 convert :: Cpp -> Cpp
211 convert :: Cpp -> Cpp
212+ convert (CppApp fn [x, y]) | isFn (moduleName, opString) fn = CppBinary op x y
207 convert (CppApp (CppApp fn [x]) [y]) | isFn (moduleName, opString) fn = CppBinary op x y
213 convert (CppApp (CppApp fn [x]) [y]) | isFn (moduleName, opString) fn = CppBinary op x y
208 convert other = other
214 convert other = other
209 unary :: (String, String) -> (String, String) -> UnaryOperator -> Cpp -> Cpp
215 unary :: (String, String) -> (String, String) -> UnaryOperator -> Cpp -> Cpp
210 unary dicts fns op = everywhereOnCpp convert
216 unary dicts fns op = everywhereOnCpp convert
211 where
217 where
212 convert :: Cpp -> Cpp
218 convert :: Cpp -> Cpp
219+ convert (CppApp fn [dict', x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
213 convert (CppApp (CppApp fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
220 convert (CppApp (CppApp fn [dict']) [x]) | isDict dicts dict' && isFn fns fn = CppUnary op x
214 convert other = other
221 convert other = other
215 unary' :: String -> String -> UnaryOperator -> Cpp -> Cpp
222 unary' :: String -> String -> UnaryOperator -> Cpp -> Cpp