]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSAUtils.java
(refs #7088) Improvements to tail call optimization
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / utils / SSAUtils.java
diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSAUtils.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SSAUtils.java
new file mode 100644 (file)
index 0000000..7de1ab4
--- /dev/null
@@ -0,0 +1,31 @@
+package org.simantics.scl.compiler.internal.codegen.utils;
+
+import org.simantics.scl.compiler.internal.codegen.references.Val;
+import org.simantics.scl.compiler.internal.codegen.references.ValRef;
+import org.simantics.scl.compiler.types.Type;
+import org.simantics.scl.compiler.types.Types;
+
+public class SSAUtils {
+
+    public static boolean representSameValue(Val a, ValRef b) {
+        if(b.getTypeParameters().length > 0)
+            return false;
+        return representSameValue(a, b.getBinding());
+    }
+    
+    public static boolean representSameValue(Val a, Val b) {
+        if(a == b)
+            return true;
+        Type aT = a.getType();
+        Type bT = b.getType();
+        if(!Types.equals(aT, bT))
+            return false;
+        return isSingletonType(aT);
+    }
+
+    public static boolean isSingletonType(Type type) {
+        type = Types.canonical(type);
+        return type == Types.UNIT || type == Types.PUNIT;
+    }
+    
+}