Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ollef committed Jul 20, 2024
1 parent d38065b commit 3398131
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions rts/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ void sixten_increase_reference_count(uintptr_t heap_object) {
++header->reference_count;
}

void sixten_increase_reference_counts(uintptr_t* data, uint32_t count) {
for (uint32_t i = 0; i < count; ++i) {
sixten_increase_reference_count(data[i]);
}
}

void sixten_decrease_reference_count(uintptr_t heap_object) {
uint8_t* pointer = heap_object_pointer(heap_object);
if (pointer == 0) {
Expand Down
1 change: 1 addition & 0 deletions rts/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ void sixten_copy(
uint32_t non_pointer_bytes
);
void sixten_increase_reference_count(uintptr_t heap_object);
void sixten_increase_reference_counts(uintptr_t* data, uint32_t count);
void sixten_decrease_reference_count(uintptr_t heap_object);
void sixten_decrease_reference_counts(uintptr_t* data, uint32_t count);
4 changes: 2 additions & 2 deletions src/Lower.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ definition name = \case
seq_ $ Store (Global Representation.int initedName) (Literal $ Literal.Integer 1) Representation.int
_ <- storeTerm CC.empty Index.Seq.Empty (Global repr (Name.Lowered name Name.Original)) term
pure $ Undefined Representation.Empty
letValue Representation.Empty "case_result" $ Case inited [LiteralBranch (Literal.Integer 0) initBranch] $ Just $ Operand $ Undefined Representation.Empty
_ <- letValue Representation.Empty "case_result" $ Case inited [LiteralBranch (Literal.Integer 0) initBranch] $ Just $ Operand $ Undefined Representation.Empty
pure $ Undefined Representation.Empty
let init = readback Index.Map.Empty initValue
pure
Expand Down Expand Up @@ -620,7 +620,7 @@ moduleInit moduleName definitions = do
forM_ constantsToInitialize \defName ->
letValue Representation.Empty "init-result" $ Call defName []
pure $ Undefined Representation.Empty
letValue Representation.Empty "case-result" $ Case inited [LiteralBranch (Literal.Integer 0) initBranch] $ Just $ Operand $ Undefined Representation.Empty
_ <- letValue Representation.Empty "case-result" $ Case inited [LiteralBranch (Literal.Integer 0) initBranch] $ Just $ Operand $ Undefined Representation.Empty
pure $ Undefined Representation.Empty
let init = readback Index.Map.Empty initValue
pure
Expand Down
23 changes: 11 additions & 12 deletions src/ReferenceCounting.hs
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ referenceCount passBy value = case value of
pure (Let passValBy name var dead val''' body'', Just $ Owned (PassBy.Value repr) 1)
_ -> pure (Let passValBy name var dead val'' body', bodyProvenance)
Seq lhs rhs -> do
(lhs', lhsProvenance) <- referenceCount (PassBy.Value mempty) lhs
when (isJust lhsProvenance) $ panic $ "Seq with provenance " <> show lhs'
(increaseBefores, decreaseAfters) <- referenceCountSeqOperation lhs
(rhs', rhsProvenance) <- referenceCount passBy rhs
pure (Seq lhs' rhs', rhsProvenance)

Expand Down Expand Up @@ -318,23 +317,23 @@ referenceCountLetOperation passBy operation = case operation of
pure (operation, Child <$> maybeParent, maybeToList decreaseSrc)

referenceCountSeqOperation
:: PassBy
-> SeqOperation
-> ReferenceCount ([(Var, Representation)], [(Var, Representation)])
referenceCountSeqOperation passBy operation = case operation of
Copy dst src _ -> do
:: SeqOperation
-> ReferenceCount ([(Operand, Either Representation Operand)], [(Var, Representation)])
referenceCountSeqOperation operation = case operation of
Copy dst src repr -> do
decreaseDst <- referenceCountOperand dst
decreaseSrc <- referenceCountOperand src
-- TODO
pure ([], catMaybes [decreaseDst decreaseSrc])
pure case (src, decreaseSrc) of
(Var Killed srcVar, Just (srcVar', _))
| srcVar == srcVar' -> ([], maybeToList decreaseDst)
_ -> ([(src, Right repr)], catMaybes [decreaseDst, decreaseSrc])
Store dst src repr -> do
decreaseDst <- referenceCountOperand dst
decreaseSrc <- referenceCountOperand src
pure case (src, decreaseSrc) of
(Var Killed srcVar, Just (srcVar', _))
| srcVar == srcVar' ->
([], maybeToList decreaseDst)
_ -> ([(src, repr)], catMaybes [decreaseDst, decreaseSrc])
| srcVar == srcVar' -> ([], maybeToList decreaseDst)
_ -> ([(src, Left repr)], catMaybes [decreaseDst, decreaseSrc])
IncreaseReferenceCount {} -> panic "RC operations before reference counting"
DecreaseReferenceCount {} -> panic "RC operations before reference counting"

Expand Down

0 comments on commit 3398131

Please sign in to comment.