OSDN Git Service

Remove instructions instead of attempting to delete them.
authorNicolas Capens <capn@google.com>
Mon, 12 Sep 2016 19:40:25 +0000 (15:40 -0400)
committerNicolas Capens <nicolascapens@google.com>
Tue, 13 Sep 2016 21:35:19 +0000 (21:35 +0000)
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 <nicolascapens@google.com>
Reviewed-by: Jim Stichnoth <stichnot@chromium.org>
src/IceCfgNode.cpp
src/IceInst.h

index c7dac53..d8e95af 100644 (file)
@@ -74,7 +74,7 @@ template <typename List> 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);
     }
index 68bd1a2..d038d53 100644 (file)
@@ -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) {