futhark-0.15.8: An optimising compiler for a functional, array-oriented language.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Futhark.Analysis.ScalExp

Description

A legacy representation of scalar expressions used solely for algebraic simplification. Never use this. Use Futhark.Analysis.PrimExp instead.

Synopsis

Documentation

data RelOp0 Source #

Relational operators.

Constructors

LTH0 
LEQ0 

Instances

Instances details
Bounded RelOp0 Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Enum RelOp0 Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Eq RelOp0 Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Methods

(==) :: RelOp0 -> RelOp0 -> Bool #

(/=) :: RelOp0 -> RelOp0 -> Bool #

Ord RelOp0 Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Show RelOp0 Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

data ScalExp Source #

Representation of a scalar expression, which is:

(i) an algebraic expression, e.g., min(a+b, a*b),

(ii) a relational expression: a+b < 5,

(iii) a logical expression: e1 and (not (a+b>5)

Instances

Instances details
Eq ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Methods

(==) :: ScalExp -> ScalExp -> Bool #

(/=) :: ScalExp -> ScalExp -> Bool #

Num ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Ord ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Show ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Pretty ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Methods

ppr :: ScalExp -> Doc #

pprPrec :: Int -> ScalExp -> Doc #

pprList :: [ScalExp] -> Doc #

FreeIn ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Methods

freeIn' :: ScalExp -> FV Source #

Substitute ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

Rename ScalExp Source # 
Instance details

Defined in Futhark.Analysis.ScalExp

scalExpType :: ScalExp -> PrimType Source #

The type of a scalar expression.

scalExpSize :: ScalExp -> Int Source #

Number of nodes in the scalar expression.

subExpToScalExp :: SubExp -> PrimType -> ScalExp Source #

Non-recursively convert a subexpression to a ScalExp. The (scalar) type of the subexpression must be given in advance.

toScalExp :: (HasScope t f, Monad f) => LookupVar -> Exp lore -> f (Maybe ScalExp) Source #

Recursively convert an expression to a scalar expression.

expandScalExp :: LookupVar -> ScalExp -> ScalExp Source #

If you have a scalar expression that has been created with incomplete symbol table information, you can use this function to grow its Id leaves.

type LookupVar = VName -> Maybe ScalExp Source #

A function that checks whether a variable name corresponds to a scalar expression.

data ConvOp Source #

Conversion operators try to generalise the from t0 x to t1 instructions from LLVM.

Constructors

ZExt IntType IntType

Zero-extend the former integer type to the latter. If the new type is smaller, the result is a truncation.

SExt IntType IntType

Sign-extend the former integer type to the latter. If the new type is smaller, the result is a truncation.

FPConv FloatType FloatType

Convert value of the former floating-point type to the latter. If the new type is smaller, the result is a truncation.

FPToUI FloatType IntType

Convert a floating-point value to the nearest unsigned integer (rounding towards zero).

FPToSI FloatType IntType

Convert a floating-point value to the nearest signed integer (rounding towards zero).

UIToFP IntType FloatType

Convert an unsigned integer to a floating-point value.

SIToFP IntType FloatType

Convert a signed integer to a floating-point value.

IToB IntType

Convert an integer to a boolean value. Zero becomes false; anything else is true.

BToI IntType

Convert a boolean to an integer. True is converted to 1 and False to 0.

Instances

Instances details
Eq ConvOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

(==) :: ConvOp -> ConvOp -> Bool #

(/=) :: ConvOp -> ConvOp -> Bool #

Ord ConvOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Show ConvOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Pretty ConvOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: ConvOp -> Doc #

pprPrec :: Int -> ConvOp -> Doc #

pprList :: [ConvOp] -> Doc #

data CmpOp Source #

Comparison operators are like BinOps, but they always return a boolean value. The somewhat ugly constructor names are straight out of LLVM.

Constructors

CmpEq PrimType

All types equality.

CmpUlt IntType

Unsigned less than.

CmpUle IntType

Unsigned less than or equal.

CmpSlt IntType

Signed less than.

CmpSle IntType

Signed less than or equal.

FCmpLt FloatType

Floating-point less than.

FCmpLe FloatType

Floating-point less than or equal.

CmpLlt

Boolean less than.

CmpLle

Boolean less than or equal.

Instances

Instances details
Eq CmpOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

(==) :: CmpOp -> CmpOp -> Bool #

(/=) :: CmpOp -> CmpOp -> Bool #

Ord CmpOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

compare :: CmpOp -> CmpOp -> Ordering #

(<) :: CmpOp -> CmpOp -> Bool #

(<=) :: CmpOp -> CmpOp -> Bool #

(>) :: CmpOp -> CmpOp -> Bool #

(>=) :: CmpOp -> CmpOp -> Bool #

max :: CmpOp -> CmpOp -> CmpOp #

min :: CmpOp -> CmpOp -> CmpOp #

Show CmpOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

showsPrec :: Int -> CmpOp -> ShowS #

show :: CmpOp -> String #

showList :: [CmpOp] -> ShowS #

Pretty CmpOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: CmpOp -> Doc #

pprPrec :: Int -> CmpOp -> Doc #

pprList :: [CmpOp] -> Doc #

data BinOp Source #

Binary operators. These correspond closely to the binary operators in LLVM. Most are parametrised by their expected input and output types.

Constructors

Add IntType Overflow

Integer addition.

FAdd FloatType

Floating-point addition.

Sub IntType Overflow

Integer subtraction.

FSub FloatType

Floating-point subtraction.

Mul IntType Overflow

Integer multiplication.

FMul FloatType

Floating-point multiplication.

UDiv IntType

Unsigned integer division. Rounds towards negativity infinity. Note: this is different from LLVM.

FDiv FloatType

Floating-point division.

FMod FloatType

Floating-point modulus.

UMod IntType

Unsigned integer modulus; the countepart to UDiv.

SMin IntType

Returns the smallest of two signed integers.

UMin IntType

Returns the smallest of two unsigned integers.

FMin FloatType

Returns the smallest of two floating-point numbers.

SMax IntType

Returns the greatest of two signed integers.

UMax IntType

Returns the greatest of two unsigned integers.

FMax FloatType

Returns the greatest of two floating-point numbers.

Shl IntType

Left-shift.

LShr IntType

Logical right-shift, zero-extended.

AShr IntType

Arithmetic right-shift, sign-extended.

And IntType

Bitwise and.

Or IntType

Bitwise or.

Xor IntType

Bitwise exclusive-or.

Pow IntType

Integer exponentiation.

FPow FloatType

Floating-point exponentiation.

LogAnd

Boolean and - not short-circuiting.

LogOr

Boolean or - not short-circuiting.

Instances

Instances details
Eq BinOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

(==) :: BinOp -> BinOp -> Bool #

(/=) :: BinOp -> BinOp -> Bool #

Ord BinOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

compare :: BinOp -> BinOp -> Ordering #

(<) :: BinOp -> BinOp -> Bool #

(<=) :: BinOp -> BinOp -> Bool #

(>) :: BinOp -> BinOp -> Bool #

(>=) :: BinOp -> BinOp -> Bool #

max :: BinOp -> BinOp -> BinOp #

min :: BinOp -> BinOp -> BinOp #

Show BinOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

showsPrec :: Int -> BinOp -> ShowS #

show :: BinOp -> String #

showList :: [BinOp] -> ShowS #

Pretty BinOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: BinOp -> Doc #

pprPrec :: Int -> BinOp -> Doc #

pprList :: [BinOp] -> Doc #

data Overflow Source #

What to do in case of arithmetic overflow. Futhark's semantics are that overflow does wraparound, but for generated code (like address arithmetic), it can be beneficial for overflow to be undefined behaviour, as it allows better optimisation of things such as GPU kernels.

Note that all values of this type are considered equal for Eq and Ord.

Instances

Instances details
Eq Overflow Source # 
Instance details

Defined in Futhark.IR.Primitive

Ord Overflow Source # 
Instance details

Defined in Futhark.IR.Primitive

Show Overflow Source # 
Instance details

Defined in Futhark.IR.Primitive

data UnOp Source #

Various unary operators. It is a bit ad-hoc what is a unary operator and what is a built-in function. Perhaps these should all go away eventually.

Constructors

Not

E.g., ! True == False.

Complement IntType

E.g., ~(~1) = 1.

Abs IntType

abs(-2) = 2.

FAbs FloatType

fabs(-2.0) = 2.0.

USignum IntType

Unsigned sign function: usignum(2) = 1.

Instances

Instances details
Eq UnOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

(==) :: UnOp -> UnOp -> Bool #

(/=) :: UnOp -> UnOp -> Bool #

Ord UnOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

compare :: UnOp -> UnOp -> Ordering #

(<) :: UnOp -> UnOp -> Bool #

(<=) :: UnOp -> UnOp -> Bool #

(>) :: UnOp -> UnOp -> Bool #

(>=) :: UnOp -> UnOp -> Bool #

max :: UnOp -> UnOp -> UnOp #

min :: UnOp -> UnOp -> UnOp #

Show UnOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

showsPrec :: Int -> UnOp -> ShowS #

show :: UnOp -> String #

showList :: [UnOp] -> ShowS #

Pretty UnOp Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: UnOp -> Doc #

pprPrec :: Int -> UnOp -> Doc #

pprList :: [UnOp] -> Doc #

data PrimValue Source #

Non-array values.

Constructors

IntValue !IntValue 
FloatValue !FloatValue 
BoolValue !Bool 
Checked

The only value of type cert.

Instances

Instances details
Eq PrimValue Source # 
Instance details

Defined in Futhark.IR.Primitive

Ord PrimValue Source # 
Instance details

Defined in Futhark.IR.Primitive

Show PrimValue Source # 
Instance details

Defined in Futhark.IR.Primitive

ToExp PrimValue Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericC

Methods

toExp :: PrimValue -> SrcLoc -> Exp #

Pretty PrimValue Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: PrimValue -> Doc #

pprPrec :: Int -> PrimValue -> Doc #

pprList :: [PrimValue] -> Doc #

IsValue PrimValue Source # 
Instance details

Defined in Futhark.IR.Prop.Constants

data FloatValue Source #

A floating-point value.

data IntValue Source #

An integer value.

Instances

Instances details
Eq IntValue Source # 
Instance details

Defined in Futhark.IR.Primitive

Ord IntValue Source # 
Instance details

Defined in Futhark.IR.Primitive

Show IntValue Source # 
Instance details

Defined in Futhark.IR.Primitive

ToExp IntValue Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericC

Methods

toExp :: IntValue -> SrcLoc -> Exp #

Pretty IntValue Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: IntValue -> Doc #

pprPrec :: Int -> IntValue -> Doc #

pprList :: [IntValue] -> Doc #

IsValue IntValue Source # 
Instance details

Defined in Futhark.IR.Prop.Constants

data PrimType Source #

Low-level primitive types.

data FloatType Source #

A floating point type.

Constructors

Float32 
Float64 

data IntType Source #

An integer type, ordered by size. Note that signedness is not a property of the type, but a property of the operations performed on values of these types.

Constructors

Int8 
Int16 
Int32 
Int64 

Instances

Instances details
Bounded IntType Source # 
Instance details

Defined in Futhark.IR.Primitive

Enum IntType Source # 
Instance details

Defined in Futhark.IR.Primitive

Eq IntType Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

(==) :: IntType -> IntType -> Bool #

(/=) :: IntType -> IntType -> Bool #

Ord IntType Source # 
Instance details

Defined in Futhark.IR.Primitive

Show IntType Source # 
Instance details

Defined in Futhark.IR.Primitive

Pretty IntType Source # 
Instance details

Defined in Futhark.IR.Primitive

Methods

ppr :: IntType -> Doc #

pprPrec :: Int -> IntType -> Doc #

pprList :: [IntType] -> Doc #

allIntTypes :: [IntType] Source #

A list of all integer types.

allFloatTypes :: [FloatType] Source #

A list of all floating-point types.

allPrimTypes :: [PrimType] Source #

A list of all primitive types.

intValue :: Integral int => IntType -> int -> IntValue Source #

Create an IntValue from a type and an Integer.

intValueType :: IntValue -> IntType Source #

The type of an integer value.

valueIntegral :: Integral int => IntValue -> int Source #

Convert an IntValue to any Integral type.

floatValue :: Real num => FloatType -> num -> FloatValue Source #

Create a FloatValue from a type and a Rational.

floatValueType :: FloatValue -> FloatType Source #

The type of a floating-point value.

primValueType :: PrimValue -> PrimType Source #

The type of a basic value.

blankPrimValue :: PrimType -> PrimValue Source #

A "blank" value of the given primitive type - this is zero, or whatever is close to it. Don't depend on this value, but use it for e.g. creating arrays to be populated by do-loops.

allUnOps :: [UnOp] Source #

A list of all unary operators for all types.

allBinOps :: [BinOp] Source #

A list of all binary operators for all types.

allCmpOps :: [CmpOp] Source #

A list of all comparison operators for all types.

allConvOps :: [ConvOp] Source #

A list of all conversion operators for all types.

doUnOp :: UnOp -> PrimValue -> Maybe PrimValue Source #

Apply an UnOp to an operand. Returns Nothing if the application is mistyped.

doComplement :: IntValue -> IntValue Source #

E.g., ~(~1) = 1.

doAbs :: IntValue -> IntValue Source #

abs(-2) = 2.

doFAbs :: FloatValue -> FloatValue Source #

abs(-2.0) = 2.0.

doSSignum :: IntValue -> IntValue Source #

ssignum(-2) = -1.

doUSignum :: IntValue -> IntValue Source #

usignum(-2) = -1.

doBinOp :: BinOp -> PrimValue -> PrimValue -> Maybe PrimValue Source #

Apply a BinOp to an operand. Returns Nothing if the application is mistyped, or outside the domain (e.g. division by zero).

doAdd :: IntValue -> IntValue -> IntValue Source #

Integer addition.

doMul :: IntValue -> IntValue -> IntValue Source #

Integer multiplication.

doSDiv :: IntValue -> IntValue -> Maybe IntValue Source #

Signed integer division. Rounds towards negativity infinity. Note: this is different from LLVM.

doSMod :: IntValue -> IntValue -> Maybe IntValue Source #

Signed integer modulus; the countepart to SDiv.

doPow :: IntValue -> IntValue -> Maybe IntValue Source #

Signed integer exponentatation.

doConvOp :: ConvOp -> PrimValue -> Maybe PrimValue Source #

Apply a ConvOp to an operand. Returns Nothing if the application is mistyped.

doZExt :: IntValue -> IntType -> IntValue Source #

Zero-extend the given integer value to the size of the given type. If the type is smaller than the given value, the result is a truncation.

doSExt :: IntValue -> IntType -> IntValue Source #

Sign-extend the given integer value to the size of the given type. If the type is smaller than the given value, the result is a truncation.

doFPConv :: FloatValue -> FloatType -> FloatValue Source #

Convert the former floating-point type to the latter.

doFPToUI :: FloatValue -> IntType -> IntValue Source #

Convert a floating-point value to the nearest unsigned integer (rounding towards zero).

doFPToSI :: FloatValue -> IntType -> IntValue Source #

Convert a floating-point value to the nearest signed integer (rounding towards zero).

doUIToFP :: IntValue -> FloatType -> FloatValue Source #

Convert an unsigned integer to a floating-point value.

doSIToFP :: IntValue -> FloatType -> FloatValue Source #

Convert a signed integer to a floating-point value.

doCmpOp :: CmpOp -> PrimValue -> PrimValue -> Maybe Bool Source #

Apply a CmpOp to an operand. Returns Nothing if the application is mistyped.

doCmpEq :: PrimValue -> PrimValue -> Bool Source #

Compare any two primtive values for exact equality.

doCmpUlt :: IntValue -> IntValue -> Bool Source #

Unsigned less than.

doCmpUle :: IntValue -> IntValue -> Bool Source #

Unsigned less than or equal.

doCmpSlt :: IntValue -> IntValue -> Bool Source #

Signed less than.

doCmpSle :: IntValue -> IntValue -> Bool Source #

Signed less than or equal.

doFCmpLt :: FloatValue -> FloatValue -> Bool Source #

Floating-point less than.

doFCmpLe :: FloatValue -> FloatValue -> Bool Source #

Floating-point less than or equal.

intToWord64 :: IntValue -> Word64 Source #

Translate an IntValue to Word64. This is guaranteed to fit.

intToInt64 :: IntValue -> Int64 Source #

Translate an IntValue to Int64. This is guaranteed to fit.

binOpType :: BinOp -> PrimType Source #

The result type of a binary operator.

cmpOpType :: CmpOp -> PrimType Source #

The operand types of a comparison operator.

unOpType :: UnOp -> PrimType Source #

The operand and result type of a unary operator.

convOpType :: ConvOp -> (PrimType, PrimType) Source #

The input and output types of a conversion operator.

primFuns :: Map String ([PrimType], PrimType, [PrimValue] -> Maybe PrimValue) Source #

A mapping from names of primitive functions to their parameter types, their result type, and a function for evaluating them.

zeroIsh :: PrimValue -> Bool Source #

Is the given value kind of zero?

oneIsh :: PrimValue -> Bool Source #

Is the given value kind of one?

negativeIsh :: PrimValue -> Bool Source #

Is the given value kind of negative?

zeroIshInt :: IntValue -> Bool Source #

Is the given integer value kind of zero?

oneIshInt :: IntValue -> Bool Source #

Is the given integer value kind of one?

primBitSize :: PrimType -> Int Source #

The size of a value of a given primitive type in bites.

primByteSize :: Num a => PrimType -> a Source #

The size of a value of a given primitive type in eight-bit bytes.

intByteSize :: Num a => IntType -> a Source #

The size of a value of a given integer type in eight-bit bytes.

floatByteSize :: Num a => FloatType -> a Source #

The size of a value of a given floating-point type in eight-bit bytes.

commutativeBinOp :: BinOp -> Bool Source #

True if the given binary operator is commutative.

convOpFun :: ConvOp -> String Source #

The human-readable name for a ConvOp. This is used to expose the ConvOp in the intrinsics module of a Futhark program.

prettySigned :: Bool -> PrimType -> String Source #

True if signed. Only makes a difference for integer types.