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

Futhark.Analysis.PrimExp

Description

A primitive expression is an expression where the non-leaves are primitive operators. Our representation does not guarantee that the expression is type-correct.

Synopsis

Documentation

data PrimExp v Source #

A primitive expression parametrised over the representation of free variables. Note that the Functor, Traversable, and Num instances perform automatic (but simple) constant folding.

Note also that the Num instance assumes OverflowUndef semantics!

Instances

Instances details
Foldable PrimExp Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

fold :: Monoid m => PrimExp m -> m #

foldMap :: Monoid m => (a -> m) -> PrimExp a -> m #

foldMap' :: Monoid m => (a -> m) -> PrimExp a -> m #

foldr :: (a -> b -> b) -> b -> PrimExp a -> b #

foldr' :: (a -> b -> b) -> b -> PrimExp a -> b #

foldl :: (b -> a -> b) -> b -> PrimExp a -> b #

foldl' :: (b -> a -> b) -> b -> PrimExp a -> b #

foldr1 :: (a -> a -> a) -> PrimExp a -> a #

foldl1 :: (a -> a -> a) -> PrimExp a -> a #

toList :: PrimExp a -> [a] #

null :: PrimExp a -> Bool #

length :: PrimExp a -> Int #

elem :: Eq a => a -> PrimExp a -> Bool #

maximum :: Ord a => PrimExp a -> a #

minimum :: Ord a => PrimExp a -> a #

sum :: Num a => PrimExp a -> a #

product :: Num a => PrimExp a -> a #

Traversable PrimExp Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

traverse :: Applicative f => (a -> f b) -> PrimExp a -> f (PrimExp b) #

sequenceA :: Applicative f => PrimExp (f a) -> f (PrimExp a) #

mapM :: Monad m => (a -> m b) -> PrimExp a -> m (PrimExp b) #

sequence :: Monad m => PrimExp (m a) -> m (PrimExp a) #

Functor PrimExp Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

fmap :: (a -> b) -> PrimExp a -> PrimExp b #

(<$) :: a -> PrimExp b -> PrimExp a #

Show v => Show (PrimExp v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

showsPrec :: Int -> PrimExp v -> ShowS #

show :: PrimExp v -> String #

showList :: [PrimExp v] -> ShowS #

ToExp (PrimExp VName) Source # 
Instance details

Defined in Futhark.CodeGen.ImpGen

ToExp v => ToExp (PrimExp v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp.Convert

Methods

toExp :: MonadBuilder m => PrimExp v -> m (Exp (Rep m)) Source #

FreeIn v => FreeIn (PrimExp v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

freeIn' :: PrimExp v -> FV Source #

Substitute v => Substitute (PrimExp v) Source # 
Instance details

Defined in Futhark.Transform.Substitute

Eq v => Eq (PrimExp v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

(==) :: PrimExp v -> PrimExp v -> Bool #

(/=) :: PrimExp v -> PrimExp v -> Bool #

Ord v => Ord (PrimExp v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

compare :: PrimExp v -> PrimExp v -> Ordering #

(<) :: PrimExp v -> PrimExp v -> Bool #

(<=) :: PrimExp v -> PrimExp v -> Bool #

(>) :: PrimExp v -> PrimExp v -> Bool #

(>=) :: PrimExp v -> PrimExp v -> Bool #

max :: PrimExp v -> PrimExp v -> PrimExp v #

min :: PrimExp v -> PrimExp v -> PrimExp v #

Pretty v => Pretty (PrimExp v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

pretty :: PrimExp v -> Doc ann #

prettyList :: [PrimExp v] -> Doc ann #

newtype TPrimExp t v Source #

A PrimExp tagged with a phantom type used to provide type-safe construction. Does not guarantee that the underlying expression is actually type correct.

Constructors

TPrimExp 

Fields

Instances

Instances details
Foldable (TPrimExp t) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

fold :: Monoid m => TPrimExp t m -> m #

foldMap :: Monoid m => (a -> m) -> TPrimExp t a -> m #

foldMap' :: Monoid m => (a -> m) -> TPrimExp t a -> m #

foldr :: (a -> b -> b) -> b -> TPrimExp t a -> b #

foldr' :: (a -> b -> b) -> b -> TPrimExp t a -> b #

foldl :: (b -> a -> b) -> b -> TPrimExp t a -> b #

foldl' :: (b -> a -> b) -> b -> TPrimExp t a -> b #

foldr1 :: (a -> a -> a) -> TPrimExp t a -> a #

foldl1 :: (a -> a -> a) -> TPrimExp t a -> a #

toList :: TPrimExp t a -> [a] #

null :: TPrimExp t a -> Bool #

length :: TPrimExp t a -> Int #

elem :: Eq a => a -> TPrimExp t a -> Bool #

maximum :: Ord a => TPrimExp t a -> a #

minimum :: Ord a => TPrimExp t a -> a #

sum :: Num a => TPrimExp t a -> a #

product :: Num a => TPrimExp t a -> a #

Traversable (TPrimExp t) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

traverse :: Applicative f => (a -> f b) -> TPrimExp t a -> f (TPrimExp t b) #

sequenceA :: Applicative f => TPrimExp t (f a) -> f (TPrimExp t a) #

mapM :: Monad m => (a -> m b) -> TPrimExp t a -> m (TPrimExp t b) #

sequence :: Monad m => TPrimExp t (m a) -> m (TPrimExp t a) #

Functor (TPrimExp t) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

fmap :: (a -> b) -> TPrimExp t a -> TPrimExp t b #

(<$) :: a -> TPrimExp t b -> TPrimExp t a #

ToExp (TExp t) Source # 
Instance details

Defined in Futhark.CodeGen.Backends.GenericC.Code

Methods

toExp :: TExp t -> SrcLoc -> Exp #

Pretty v => Floating (TPrimExp Half v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Pretty v => Floating (TPrimExp Double v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Pretty v => Floating (TPrimExp Float v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

(NumExp t, Pretty v) => Num (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

(+) :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v #

(-) :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v #

(*) :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v #

negate :: TPrimExp t v -> TPrimExp t v #

abs :: TPrimExp t v -> TPrimExp t v #

signum :: TPrimExp t v -> TPrimExp t v #

fromInteger :: Integer -> TPrimExp t v #

(FloatExp t, Pretty v) => Fractional (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

(/) :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v #

recip :: TPrimExp t v -> TPrimExp t v #

fromRational :: Rational -> TPrimExp t v #

Show v => Show (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

showsPrec :: Int -> TPrimExp t v -> ShowS #

show :: TPrimExp t v -> String #

showList :: [TPrimExp t v] -> ShowS #

ToExp v => ToExp (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp.Convert

Methods

toExp :: MonadBuilder m => TPrimExp t v -> m (Exp (Rep m)) Source #

FreeIn v => FreeIn (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

freeIn' :: TPrimExp t v -> FV Source #

Substitute v => Substitute (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Transform.Substitute

(IntExp t, Pretty v) => IntegralExp (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

quot :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

rem :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

div :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

mod :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

sgn :: TPrimExp t v -> Maybe Int Source #

pow :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

divUp :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

nextMul :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

Eq v => Eq (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

(==) :: TPrimExp t v -> TPrimExp t v -> Bool #

(/=) :: TPrimExp t v -> TPrimExp t v -> Bool #

Ord v => Ord (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

compare :: TPrimExp t v -> TPrimExp t v -> Ordering #

(<) :: TPrimExp t v -> TPrimExp t v -> Bool #

(<=) :: TPrimExp t v -> TPrimExp t v -> Bool #

(>) :: TPrimExp t v -> TPrimExp t v -> Bool #

(>=) :: TPrimExp t v -> TPrimExp t v -> Bool #

max :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v #

min :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v #

Pretty v => Pretty (TPrimExp t v) Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

pretty :: TPrimExp t v -> Doc ann #

prettyList :: [TPrimExp t v] -> Doc ann #

isInt8 :: PrimExp v -> TPrimExp Int8 v Source #

This expression is of type Int8.

isInt16 :: PrimExp v -> TPrimExp Int16 v Source #

This expression is of type Int16.

isInt32 :: PrimExp v -> TPrimExp Int32 v Source #

This expression is of type Int32.

isInt64 :: PrimExp v -> TPrimExp Int64 v Source #

This expression is of type Int64.

isBool :: PrimExp v -> TPrimExp Bool v Source #

This is a boolean expression.

isF16 :: PrimExp v -> TPrimExp Half v Source #

This expression is of type Half.

isF32 :: PrimExp v -> TPrimExp Float v Source #

This expression is of type Float.

isF64 :: PrimExp v -> TPrimExp Double v Source #

This expression is of type Double.

evalPrimExp :: (Pretty v, MonadFail m) => (v -> m PrimValue) -> PrimExp v -> m PrimValue Source #

Evaluate a PrimExp in the given monad. Invokes fail on type errors.

primExpType :: PrimExp v -> PrimType Source #

The type of values returned by a PrimExp. This function returning does not imply that the PrimExp is type-correct.

primExpSizeAtLeast :: Int -> PrimExp v -> Bool Source #

True if the PrimExp has at least this many nodes. This can be much more efficient than comparing with length for large PrimExps, as this function is lazy.

coerceIntPrimExp :: IntType -> PrimExp v -> PrimExp v Source #

If the given PrimExp is a constant of the wrong integer type, coerce it to the given integer type. This is a workaround for an issue in the Num instance.

leafExpTypes :: Ord a => PrimExp a -> Set (a, PrimType) Source #

Produce a mapping from the leaves of the PrimExp to their designated types.

true :: TPrimExp Bool v Source #

Boolean-valued PrimExps.

false :: TPrimExp Bool v Source #

Boolean-valued PrimExps.

fromBool :: Bool -> TPrimExp Bool v Source #

Conversion from Bool to TPrimExp

constFoldPrimExp :: PrimExp v -> PrimExp v Source #

Perform quick and dirty constant folding on the top level of a PrimExp. This is necessary because we want to consider e.g. equality modulo constant folding.

Construction

class NumExp t where Source #

The class of numeric types that can be used for constructing TPrimExps.

Methods

fromInteger' :: Integer -> TPrimExp t v Source #

Construct a typed expression from an integer.

fromBoolExp :: TPrimExp Bool v -> TPrimExp t v Source #

Construct a numeric expression from a boolean expression. This can be used to encode arithmetic control flow.

class NumExp t => IntExp t where Source #

The class of integer types that can be used for constructing TPrimExps.

Methods

expIntType :: TPrimExp t v -> IntType Source #

The type of an expression, known to be an integer type.

Instances

Instances details
IntExp Int16 Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

IntExp Int32 Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

IntExp Int64 Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

IntExp Int8 Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

class NumExp t => FloatExp t where Source #

The class of floating-point types that can be used for constructing TPrimExps.

Methods

fromRational' :: Rational -> TPrimExp t v Source #

Construct a typed expression from a rational.

expFloatType :: TPrimExp t v -> FloatType Source #

The type of an expression, known to be a floating-point type.

sExt :: IntType -> PrimExp v -> PrimExp v Source #

Untyped smart constructor for sign extension that does a bit of constant folding.

zExt :: IntType -> PrimExp v -> PrimExp v Source #

Untyped smart constructor for zero extension that does a bit of constant folding.

(.&&.) :: Eq v => TPrimExp Bool v -> TPrimExp Bool v -> TPrimExp Bool v infixr 3 Source #

Lifted logical conjunction.

(.||.) :: Eq v => TPrimExp Bool v -> TPrimExp Bool v -> TPrimExp Bool v infixr 2 Source #

Lifted logical conjunction.

(.<.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp Bool v infix 4 Source #

Lifted relational operators; assuming signed numbers in case of integers.

(.<=.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp Bool v infix 4 Source #

Lifted relational operators; assuming signed numbers in case of integers.

(.>.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp Bool v infix 4 Source #

Lifted relational operators; assuming signed numbers in case of integers.

(.>=.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp Bool v infix 4 Source #

Lifted relational operators; assuming signed numbers in case of integers.

(.==.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp Bool v infix 4 Source #

Lifted relational operators; assuming signed numbers in case of integers.

(.&.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

Lifted bitwise operators. The right-shift is logical, *not* arithmetic.

(.|.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

Lifted bitwise operators. The right-shift is logical, *not* arithmetic.

(.^.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

Lifted bitwise operators. The right-shift is logical, *not* arithmetic.

(.>>.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

Lifted bitwise operators. The right-shift is logical, *not* arithmetic.

(.<<.) :: Eq v => TPrimExp t v -> TPrimExp t v -> TPrimExp t v Source #

Lifted bitwise operators. The right-shift is logical, *not* arithmetic.

bNot :: TPrimExp Bool v -> TPrimExp Bool v Source #

Boolean negation smart constructor.

sMax32 :: TPrimExp Int32 v -> TPrimExp Int32 v -> TPrimExp Int32 v Source #

SMax on 32-bit integers.

sMin32 :: TPrimExp Int32 v -> TPrimExp Int32 v -> TPrimExp Int32 v Source #

SMin on 32-bit integers.

sMax64 :: TPrimExp Int64 v -> TPrimExp Int64 v -> TPrimExp Int64 v Source #

SMax on 64-bit integers.

sMin64 :: TPrimExp Int64 v -> TPrimExp Int64 v -> TPrimExp Int64 v Source #

SMin on 64-bit integers.

sExt32 :: IntExp t => TPrimExp t v -> TPrimExp Int32 v Source #

Sign-extend to 32 bit integer.

sExt64 :: IntExp t => TPrimExp t v -> TPrimExp Int64 v Source #

Sign-extend to 64 bit integer.

zExt32 :: IntExp t => TPrimExp t v -> TPrimExp Int32 v Source #

Zero-extend to 32 bit integer.

zExt64 :: IntExp t => TPrimExp t v -> TPrimExp Int64 v Source #

Zero-extend to 64 bit integer.

sExtAs :: (IntExp to, IntExp from) => TPrimExp from v -> TPrimExp to v -> TPrimExp to v Source #

Convert result of some integer expression to have the same type as another, using sign extension.

fMin16 :: TPrimExp Half v -> TPrimExp Half v -> TPrimExp Half v Source #

16-bit float minimum.

fMin32 :: TPrimExp Float v -> TPrimExp Float v -> TPrimExp Float v Source #

32-bit float minimum.

fMin64 :: TPrimExp Double v -> TPrimExp Double v -> TPrimExp Double v Source #

64-bit float minimum.

fMax16 :: TPrimExp Half v -> TPrimExp Half v -> TPrimExp Half v Source #

16-bit float maximum.

fMax32 :: TPrimExp Float v -> TPrimExp Float v -> TPrimExp Float v Source #

32-bit float maximum.

fMax64 :: TPrimExp Double v -> TPrimExp Double v -> TPrimExp Double v Source #

64-bit float maximum.

Untyped construction

(~*~) :: PrimExp v -> PrimExp v -> PrimExp v infix 7 Source #

Multiplication of untyped PrimExps, which must have the same type. Uses OverflowWrap for integer operations.

(~/~) :: PrimExp v -> PrimExp v -> PrimExp v infix 7 Source #

Division of untyped PrimExps, which must have the same type. For integers, this is unsafe signed division.

(~+~) :: PrimExp v -> PrimExp v -> PrimExp v infix 6 Source #

Addition of untyped PrimExps, which must have the same type. Uses OverflowWrap for integer operations.

(~-~) :: PrimExp v -> PrimExp v -> PrimExp v infix 6 Source #

Subtraction of untyped PrimExps, which must have the same type. Uses OverflowWrap for integer operations.

(~==~) :: PrimExp v -> PrimExp v -> PrimExp v infix 4 Source #

Equality of untyped PrimExps, which must have the same type.