From 038a9b9e2b3c3b2e2e532b6194a2b9f8351ad76c Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Mon, 12 Sep 2016 15:40:25 -0400 Subject: [PATCH] Remove instructions instead of attempting to delete them. Instructions are allocated using the ArenaAllocator which uses a memory pool of "slabs", so we can't use the regular C++ delete to deallocate them. Just remove them from the list. This change also provides an override for Inst's operator delete to use the custom allocator, which should currently not be called. BUG=swiftshader:8 Change-Id: Ibb166910402a70e7d9276b28e19b15caf64422f2 Reviewed-on: https://chromium-review.googlesource.com/384336 Tested-by: Nicolas Capens Reviewed-by: Jim Stichnoth --- src/IceCfgNode.cpp | 2 +- src/IceInst.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/IceCfgNode.cpp b/src/IceCfgNode.cpp index c7dac53f9..d8e95af9f 100644 --- a/src/IceCfgNode.cpp +++ b/src/IceCfgNode.cpp @@ -74,7 +74,7 @@ template void removeDeletedAndRenumber(List *L, Cfg *Func) { auto I = L->begin(), E = L->end(), Next = I; for (++Next; I != E; I = Next++) { if (DoDelete && I->isDeleted()) { - L->erase(I); + L->remove(I); } else { I->renumber(Func); } diff --git a/src/IceInst.h b/src/IceInst.h index 68bd1a2fe..d038d53c0 100644 --- a/src/IceInst.h +++ b/src/IceInst.h @@ -193,6 +193,12 @@ public: virtual ~Inst() = default; void replaceDest(Variable *Var) { Dest = Var; } + void operator delete(void *Ptr, std::size_t Size) { + assert(CfgAllocatorTraits::current() != nullptr); + CfgAllocatorTraits::current()->Deallocate(Ptr, Size); + llvm::report_fatal_error("Inst unexpectedly deleted"); + } + protected: Inst(Cfg *Func, InstKind Kind, SizeT MaxSrcs, Variable *Dest); void addSource(Operand *Src) { -- 2.11.0