module LinearScan.ScanState where
import Debug.Trace (trace, traceShow, traceShowId)
import qualified Prelude
import qualified Data.IntMap
import qualified Data.IntSet
import qualified Data.List
import qualified Data.Ord
import qualified Data.Functor.Identity
import qualified Hask.Utils
import qualified LinearScan.Interval as Interval
import qualified LinearScan.List1 as List1
import qualified LinearScan.Vector0 as Vector0
import qualified LinearScan.Eqtype as Eqtype
import qualified LinearScan.Fintype as Fintype
import qualified LinearScan.Seq as Seq
import qualified LinearScan.Ssrbool as Ssrbool
#ifdef __GLASGOW_HASKELL__
import qualified GHC.Base as GHC.Base
import qualified GHC.Prim as GHC.Prim
#else
import qualified LinearScan.IOExts as IOExts
#endif
#ifdef __GLASGOW_HASKELL__
unsafeCoerce = GHC.Base.unsafeCoerce#
#else
unsafeCoerce = IOExts.unsafeCoerce
#endif
type PhysReg = Prelude.Int
type FixedIntervalsType = Vector0.Vec (Prelude.Maybe Interval.IntervalDesc)
data ScanStateDesc =
Build_ScanStateDesc Prelude.Int (Vector0.Vec Interval.IntervalDesc)
FixedIntervalsType ([] ((,) Prelude.Int Prelude.Int)) ([]
((,) Prelude.Int
PhysReg)) ([]
((,)
Prelude.Int
PhysReg))
([] ((,) Prelude.Int (Prelude.Maybe PhysReg)))
nextInterval :: Prelude.Int -> ScanStateDesc -> Prelude.Int
nextInterval maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> nextInterval0}
type IntervalId = Prelude.Int
intervals :: Prelude.Int -> ScanStateDesc -> Vector0.Vec
Interval.IntervalDesc
intervals maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> intervals0}
fixedIntervals :: Prelude.Int -> ScanStateDesc -> FixedIntervalsType
fixedIntervals maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> fixedIntervals0}
unhandled :: Prelude.Int -> ScanStateDesc -> [] ((,) IntervalId Prelude.Int)
unhandled maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> unhandled0}
active :: Prelude.Int -> ScanStateDesc -> [] ((,) IntervalId PhysReg)
active maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> active0}
inactive :: Prelude.Int -> ScanStateDesc -> [] ((,) IntervalId PhysReg)
inactive maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> inactive0}
handled :: Prelude.Int -> ScanStateDesc -> []
((,) IntervalId (Prelude.Maybe PhysReg))
handled maxReg s =
case s of {
Build_ScanStateDesc nextInterval0 intervals0 fixedIntervals0 unhandled0
active0 inactive0 handled0 -> handled0}
handledIds :: Prelude.Int -> ScanStateDesc -> [] IntervalId
handledIds maxReg s =
Prelude.map (\i -> Prelude.fst i) (handled maxReg s)
sortRegisterVector :: Prelude.Int -> (Vector0.Vec Prelude.Bool) ->
(Vector0.Vec (Prelude.Maybe Prelude.Int)) -> []
((,) PhysReg (Prelude.Maybe Prelude.Int))
sortRegisterVector maxReg fixedAndIntersects =
Vector0.vfoldl_with_index maxReg (\reg acc mpos ->
let {
f = \x y ->
case x of {
(,) xreg xmpos ->
case y of {
(,) yreg ympos ->
let {xfi = Vector0.vnth maxReg fixedAndIntersects xreg} in
let {yfi = Vector0.vnth maxReg fixedAndIntersects yreg} in
case (Prelude.&&) xfi (Prelude.not yfi) of {
Prelude.True -> Prelude.False;
Prelude.False ->
case xmpos of {
Prelude.Just xn ->
case ympos of {
Prelude.Just yn -> (Prelude.<=) ((Prelude.succ) yn) xn;
Prelude.Nothing -> Prelude.False};
Prelude.Nothing -> Prelude.True}}}}}
in
List1.insert f ((,) reg mpos) acc) []
registerWithHighestPos :: Prelude.Int -> (Vector0.Vec Prelude.Bool) ->
(Vector0.Vec (Prelude.Maybe Prelude.Int)) -> (,)
PhysReg (Prelude.Maybe Prelude.Int)
registerWithHighestPos maxReg fixedAndIntersects =
(Prelude..) (Seq.head ((,) ( 0) (Prelude.Just 0)))
(sortRegisterVector maxReg fixedAndIntersects)
handledIntervalDescsForReg :: Prelude.Int -> ScanStateDesc -> PhysReg -> []
Interval.IntervalDesc
handledIntervalDescsForReg maxReg sd reg =
Prelude.map (\x ->
Interval.getIntervalDesc
(
(Vector0.vnth (nextInterval maxReg sd) (intervals maxReg sd)
(Prelude.fst x))))
(Prelude.filter (\x ->
Eqtype.eq_op (Eqtype.option_eqType (Fintype.ordinal_eqType maxReg))
(Prelude.snd (unsafeCoerce x)) (unsafeCoerce (Prelude.Just reg)))
(handled maxReg sd))
verifyNewHandled :: Prelude.Int -> ScanStateDesc -> Interval.IntervalDesc ->
PhysReg -> Prelude.Bool
verifyNewHandled maxReg sd int reg =
let {
check = \y ->
Prelude.not (Ssrbool.isSome (Interval.intervalsIntersect int y))}
in
(Prelude.&&) (Seq.all check (handledIntervalDescsForReg maxReg sd reg))
(case Vector0.vnth maxReg (fixedIntervals maxReg sd) reg of {
Prelude.Just i ->
Prelude.not
(Ssrbool.isSome (Interval.intervalIntersectsWithSubrange int ( i)));
Prelude.Nothing -> Prelude.True})
data ScanStateStatus =
Pending
| InUse
type ScanStateSig = ScanStateDesc
packScanState :: Prelude.Int -> ScanStateStatus -> ScanStateDesc ->
ScanStateDesc
packScanState maxReg b sd =
sd