From cd9172ed6236a72a366db5678e44d5412f167295 Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sun, 29 Dec 2013 23:43:36 -0800 Subject: [PATCH] Resetting the builder arena. May be a bug or two here still. --- src/alloy/arena.cc | 8 ++++++++ src/alloy/arena.h | 1 + src/alloy/backend/ivm/ivm_assembler.cc | 5 ++++- src/alloy/hir/hir_builder.cc | 17 +++++++++++++++++ src/alloy/hir/hir_builder.h | 2 ++ 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/alloy/arena.cc b/src/alloy/arena.cc index c708fecf5..1649771dd 100644 --- a/src/alloy/arena.cc +++ b/src/alloy/arena.cc @@ -35,6 +35,14 @@ void Arena::Reset() { } } +void Arena::DebugFill() { + auto chunk = head_chunk_; + while (chunk) { + memset(chunk->buffer, 0xCD, chunk->capacity); + chunk = chunk->next; + } +} + void* Arena::Alloc(size_t size) { if (active_chunk_) { if (active_chunk_->capacity - active_chunk_->offset < size) { diff --git a/src/alloy/arena.h b/src/alloy/arena.h index 4375a12b2..2041f1375 100644 --- a/src/alloy/arena.h +++ b/src/alloy/arena.h @@ -22,6 +22,7 @@ public: ~Arena(); void Reset(); + void DebugFill(); void* Alloc(size_t size); template T* Alloc() { diff --git a/src/alloy/backend/ivm/ivm_assembler.cc b/src/alloy/backend/ivm/ivm_assembler.cc index ec75bcf5a..58053a950 100644 --- a/src/alloy/backend/ivm/ivm_assembler.cc +++ b/src/alloy/backend/ivm/ivm_assembler.cc @@ -69,9 +69,12 @@ int IVMAssembler::Assemble( ctx.scratch_arena = &scratch_arena_; ctx.label_ref_head = NULL; + // Reset label tags as we use them. + builder->ResetLabelTags(); + // Function prologue. - Block* block = builder->first_block(); + auto block = builder->first_block(); while (block) { Label* label = block->label_head; while (label) { diff --git a/src/alloy/hir/hir_builder.cc b/src/alloy/hir/hir_builder.cc index ff058ae45..5b2032012 100644 --- a/src/alloy/hir/hir_builder.cc +++ b/src/alloy/hir/hir_builder.cc @@ -42,6 +42,10 @@ void HIRBuilder::Reset() { next_value_ordinal_ = 0; block_head_ = block_tail_ = NULL; current_block_ = NULL; +#if XE_DEBUG + arena_->DebugFill(); +#endif + arena_->Reset(); } int HIRBuilder::Finalize() { @@ -319,6 +323,19 @@ void HIRBuilder::InsertLabel(Label* label, Instr* prev_instr) { } } +void HIRBuilder::ResetLabelTags() { + // TODO(benvanik): make this faster? + auto block = block_head_; + while (block) { + auto label = block->label_head; + while (label) { + label->tag = 0; + label = label->next; + } + block = block->next; + } +} + Block* HIRBuilder::AppendBlock() { Block* block = arena_->Alloc(); block->arena = arena_; diff --git a/src/alloy/hir/hir_builder.h b/src/alloy/hir/hir_builder.h index 356e73b4d..050d398ec 100644 --- a/src/alloy/hir/hir_builder.h +++ b/src/alloy/hir/hir_builder.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -47,6 +48,7 @@ public: Label* NewLabel(); void MarkLabel(Label* label, Block* block = 0); void InsertLabel(Label* label, Instr* prev_instr); + void ResetLabelTags(); // static allocations: // Value* AllocStatic(size_t length);