head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.1
	netbsd-11-0-RC3:1.1.1.1
	netbsd-11-0-RC2:1.1.1.1
	netbsd-11-0-RC1:1.1.1.1
	perseant-exfatfs-base-20250801:1.1.1.1
	netbsd-11:1.1.1.1.0.10
	netbsd-11-base:1.1.1.1
	netbsd-10-1-RELEASE:1.1.1.1
	perseant-exfatfs-base-20240630:1.1.1.1
	perseant-exfatfs:1.1.1.1.0.8
	perseant-exfatfs-base:1.1.1.1
	netbsd-10-0-RELEASE:1.1.1.1
	netbsd-10-0-RC6:1.1.1.1
	netbsd-10-0-RC5:1.1.1.1
	netbsd-10-0-RC4:1.1.1.1
	netbsd-10-0-RC3:1.1.1.1
	netbsd-10-0-RC2:1.1.1.1
	netbsd-10-0-RC1:1.1.1.1
	netbsd-10:1.1.1.1.0.6
	netbsd-10-base:1.1.1.1
	cjep_sun2x-base1:1.1.1.1
	cjep_sun2x:1.1.1.1.0.4
	cjep_sun2x-base:1.1.1.1
	cjep_staticlib_x:1.1.1.1.0.2
	cjep_staticlib_x-base1:1.1.1.1
	LLVM-249b40b558955afe5ac2b549edcf2d7f859c8cc9:1.1.1.1
	LLVM:1.1.1;
locks; strict;
comment	@// @;


1.1
date	2021.05.30.01.25.56;	author joerg;	state Exp;
branches
	1.1.1.1;
next	;
commitid	uhgdinROdC6tU6VC;

1.1.1.1
date	2021.05.30.01.25.56;	author joerg;	state Exp;
branches
	1.1.1.1.2.1;
next	;
commitid	uhgdinROdC6tU6VC;

1.1.1.1.2.1
date	2021.05.30.01.25.56;	author cjep;	state dead;
branches;
next	1.1.1.1.2.2;
commitid	eWz9SBW0XqKjJlVC;

1.1.1.1.2.2
date	2021.05.31.22.07.11;	author cjep;	state Exp;
branches;
next	;
commitid	eWz9SBW0XqKjJlVC;


desc
@@


1.1
log
@Initial revision
@
text
@//===--- Block.cpp - Allocated blocks for the interpreter -------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Defines the classes describing allocated blocks.
//
//===----------------------------------------------------------------------===//

#include "InterpBlock.h"
#include "Pointer.h"

using namespace clang;
using namespace clang::interp;



void Block::addPointer(Pointer *P) {
  if (IsStatic)
    return;
  if (Pointers)
    Pointers->Prev = P;
  P->Next = Pointers;
  P->Prev = nullptr;
  Pointers = P;
}

void Block::removePointer(Pointer *P) {
  if (IsStatic)
    return;
  if (Pointers == P)
    Pointers = P->Next;
  if (P->Prev)
    P->Prev->Next = P->Next;
  if (P->Next)
    P->Next->Prev = P->Prev;
}

void Block::cleanup() {
  if (Pointers == nullptr && IsDead)
    (reinterpret_cast<DeadBlock *>(this + 1) - 1)->free();
}

void Block::movePointer(Pointer *From, Pointer *To) {
  if (IsStatic)
    return;
  To->Prev = From->Prev;
  if (To->Prev)
    To->Prev->Next = To;
  To->Next = From->Next;
  if (To->Next)
    To->Next->Prev = To;
  if (Pointers == From)
    Pointers = To;

  From->Prev = nullptr;
  From->Next = nullptr;
}

DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
    : Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
  // Add the block to the chain of dead blocks.
  if (Root)
    Root->Prev = this;

  Next = Root;
  Prev = nullptr;
  Root = this;

  // Transfer pointers.
  B.Pointers = Blk->Pointers;
  for (Pointer *P = Blk->Pointers; P; P = P->Next)
    P->Pointee = &B;
}

void DeadBlock::free() {
  if (Prev)
    Prev->Next = Next;
  if (Next)
    Next->Prev = Prev;
  if (Root == this)
    Root = Next;
  ::free(this);
}
@


1.1.1.1
log
@Import clang 249b40b558955afe5ac2b549edcf2d7f859c8cc9.
@
text
@@


1.1.1.1.2.1
log
@file InterpBlock.cpp was added on branch cjep_staticlib_x on 2021-05-31 22:07:11 +0000
@
text
@d1 87
@


1.1.1.1.2.2
log
@sync with head
@
text
@a0 87
//===--- Block.cpp - Allocated blocks for the interpreter -------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Defines the classes describing allocated blocks.
//
//===----------------------------------------------------------------------===//

#include "InterpBlock.h"
#include "Pointer.h"

using namespace clang;
using namespace clang::interp;



void Block::addPointer(Pointer *P) {
  if (IsStatic)
    return;
  if (Pointers)
    Pointers->Prev = P;
  P->Next = Pointers;
  P->Prev = nullptr;
  Pointers = P;
}

void Block::removePointer(Pointer *P) {
  if (IsStatic)
    return;
  if (Pointers == P)
    Pointers = P->Next;
  if (P->Prev)
    P->Prev->Next = P->Next;
  if (P->Next)
    P->Next->Prev = P->Prev;
}

void Block::cleanup() {
  if (Pointers == nullptr && IsDead)
    (reinterpret_cast<DeadBlock *>(this + 1) - 1)->free();
}

void Block::movePointer(Pointer *From, Pointer *To) {
  if (IsStatic)
    return;
  To->Prev = From->Prev;
  if (To->Prev)
    To->Prev->Next = To;
  To->Next = From->Next;
  if (To->Next)
    To->Next->Prev = To;
  if (Pointers == From)
    Pointers = To;

  From->Prev = nullptr;
  From->Next = nullptr;
}

DeadBlock::DeadBlock(DeadBlock *&Root, Block *Blk)
    : Root(Root), B(Blk->Desc, Blk->IsStatic, Blk->IsExtern, /*isDead=*/true) {
  // Add the block to the chain of dead blocks.
  if (Root)
    Root->Prev = this;

  Next = Root;
  Prev = nullptr;
  Root = this;

  // Transfer pointers.
  B.Pointers = Blk->Pointers;
  for (Pointer *P = Blk->Pointers; P; P = P->Next)
    P->Pointee = &B;
}

void DeadBlock::free() {
  if (Prev)
    Prev->Next = Next;
  if (Next)
    Next->Prev = Prev;
  if (Root == this)
    Root = Next;
  ::free(this);
}
@


