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

Futhark.Analysis.PrimExp

Contents

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
Functor PrimExp Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

Methods

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

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

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) #

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 #

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 #

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

Defined in Futhark.Analysis.PrimExp

Methods

ppr :: PrimExp v -> Doc #

pprPrec :: Int -> PrimExp v -> Doc #

pprList :: [PrimExp v] -> Doc #

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

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

Defined in Futhark.Analysis.PrimExp.Convert

Methods

toExp :: MonadBinder m => PrimExp v -> m (Exp (Lore m)) Source #

ToExp (PrimExp VName) Source # 
Instance details

Defined in Futhark.CodeGen.ImpGen

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
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 #

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) #

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 #

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

(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 #

(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 #

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 #

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 #

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

Defined in Futhark.Analysis.PrimExp

Methods

ppr :: TPrimExp t v -> Doc #

pprPrec :: Int -> TPrimExp t v -> Doc #

pprList :: [TPrimExp t v] -> Doc #

(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 #

divUp :: TPrimExp t v -> TPrimExp t v -> TPrimExp t v 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

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

Defined in Futhark.Analysis.PrimExp.Convert

Methods

toExp :: MonadBinder m => TPrimExp t v -> m (Exp (Lore m)) Source #

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.

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.

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 Source #

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

Instances

Instances details
IntExp Int8 Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

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

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.

Instances

Instances details
FloatExp Double Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

FloatExp Float Source # 
Instance details

Defined in Futhark.Analysis.PrimExp

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.

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

Lifted logical conjunction.

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

Lifted logical conjunction.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

(.<<.) :: 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.

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

64-bit float minimum.

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

64-bit float maximum.