2002-06-26 00:13:24 +08:00
|
|
|
//===-- llvm/SymbolTableListTraitsImpl.h - Implementation ------*- C++ -*--===//
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2005-04-22 07:48:37 +08:00
|
|
|
//
|
2003-10-21 23:17:13 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-06-26 00:13:24 +08:00
|
|
|
//
|
|
|
|
// This file implements the stickier parts of the SymbolTableListTraits class,
|
|
|
|
// and is explicitly instantiated where needed to avoid defining all this code
|
|
|
|
// in a widely used header.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
|
|
|
|
#define LLVM_LIB_IR_SYMBOLTABLELISTTRAITSIMPL_H
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2013-01-02 19:36:10 +08:00
|
|
|
#include "llvm/IR/SymbolTableListTraits.h"
|
|
|
|
#include "llvm/IR/ValueSymbolTable.h"
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2003-11-12 06:41:34 +08:00
|
|
|
namespace llvm {
|
|
|
|
|
[IR] Lazily number instructions for local dominance queries
Essentially, fold OrderedBasicBlock into BasicBlock, and make it
auto-invalidate the instruction ordering when new instructions are
added. Notably, we don't need to invalidate it when removing
instructions, which is helpful when a pass mostly delete dead
instructions rather than transforming them.
The downside is that Instruction grows from 56 bytes to 64 bytes. The
resulting LLVM code is substantially simpler and automatically handles
invalidation, which makes me think that this is the right speed and size
tradeoff.
The important change is in SymbolTableTraitsImpl.h, where the numbering
is invalidated. Everything else should be straightforward.
We probably want to implement a fancier re-numbering scheme so that
local updates don't invalidate the ordering, but I plan for that to be
future work, maybe for someone else.
Reviewed By: lattner, vsk, fhahn, dexonsmith
Differential Revision: https://reviews.llvm.org/D51664
2020-02-19 06:33:54 +08:00
|
|
|
/// Notify basic blocks when an instruction is inserted.
|
|
|
|
template <typename ParentClass>
|
|
|
|
inline void invalidateParentIListOrdering(ParentClass *Parent) {}
|
|
|
|
template <> void invalidateParentIListOrdering(BasicBlock *BB);
|
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
/// setSymTabObject - This is called when (f.e.) the parent of a basic block
|
|
|
|
/// changes. This requires us to remove all the instruction symtab entries from
|
|
|
|
/// the current function and reinsert them into the new function.
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
template <typename TPtr>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::setSymTabObject(TPtr *Dest,
|
|
|
|
TPtr Src) {
|
2007-04-17 11:26:42 +08:00
|
|
|
// Get the old symtab and value list before doing the assignment.
|
2015-10-07 05:31:07 +08:00
|
|
|
ValueSymbolTable *OldST = getSymTab(getListOwner());
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// Do it.
|
|
|
|
*Dest = Src;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// Get the new SymTab object.
|
2015-10-07 05:31:07 +08:00
|
|
|
ValueSymbolTable *NewST = getSymTab(getListOwner());
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// If there is nothing to do, quick exit.
|
|
|
|
if (OldST == NewST) return;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
// Move all the elements from the old symtab to the new one.
|
2015-10-08 04:05:10 +08:00
|
|
|
ListTy &ItemList = getList(getListOwner());
|
2007-04-17 11:26:42 +08:00
|
|
|
if (ItemList.empty()) return;
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
if (OldST) {
|
|
|
|
// Remove all entries from the previous symtab.
|
2015-10-07 06:37:47 +08:00
|
|
|
for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
|
2007-04-17 11:26:42 +08:00
|
|
|
if (I->hasName())
|
|
|
|
OldST->removeValueName(I->getValueName());
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2007-04-17 11:26:42 +08:00
|
|
|
if (NewST) {
|
|
|
|
// Add all of the items to the new symtab.
|
2015-10-07 06:37:47 +08:00
|
|
|
for (auto I = ItemList.begin(); I != ItemList.end(); ++I)
|
2007-04-17 11:26:42 +08:00
|
|
|
if (I->hasName())
|
2015-10-09 07:49:46 +08:00
|
|
|
NewST->reinsertValue(&*I);
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
2018-07-31 03:41:25 +08:00
|
|
|
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::addNodeToList(ValueSubClass *V) {
|
2014-04-28 12:05:08 +08:00
|
|
|
assert(!V->getParent() && "Value already in a container!!");
|
2007-04-17 12:04:14 +08:00
|
|
|
ItemParentClass *Owner = getListOwner();
|
|
|
|
V->setParent(Owner);
|
[IR] Lazily number instructions for local dominance queries
Essentially, fold OrderedBasicBlock into BasicBlock, and make it
auto-invalidate the instruction ordering when new instructions are
added. Notably, we don't need to invalidate it when removing
instructions, which is helpful when a pass mostly delete dead
instructions rather than transforming them.
The downside is that Instruction grows from 56 bytes to 64 bytes. The
resulting LLVM code is substantially simpler and automatically handles
invalidation, which makes me think that this is the right speed and size
tradeoff.
The important change is in SymbolTableTraitsImpl.h, where the numbering
is invalidated. Everything else should be straightforward.
We probably want to implement a fancier re-numbering scheme so that
local updates don't invalidate the ordering, but I plan for that to be
future work, maybe for someone else.
Reviewed By: lattner, vsk, fhahn, dexonsmith
Differential Revision: https://reviews.llvm.org/D51664
2020-02-19 06:33:54 +08:00
|
|
|
invalidateParentIListOrdering(Owner);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (V->hasName())
|
2015-10-07 05:31:07 +08:00
|
|
|
if (ValueSymbolTable *ST = getSymTab(Owner))
|
2007-04-17 11:26:42 +08:00
|
|
|
ST->reinsertValue(V);
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::removeNodeFromList(
|
|
|
|
ValueSubClass *V) {
|
2014-04-28 12:05:08 +08:00
|
|
|
V->setParent(nullptr);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (V->hasName())
|
2015-10-07 05:31:07 +08:00
|
|
|
if (ValueSymbolTable *ST = getSymTab(getListOwner()))
|
2007-04-17 11:26:42 +08:00
|
|
|
ST->removeValueName(V->getValueName());
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
|
2015-10-08 04:05:10 +08:00
|
|
|
template <typename ValueSubClass>
|
|
|
|
void SymbolTableListTraits<ValueSubClass>::transferNodesFromList(
|
2016-09-03 09:22:56 +08:00
|
|
|
SymbolTableListTraits &L2, iterator first, iterator last) {
|
[IR] Lazily number instructions for local dominance queries
Essentially, fold OrderedBasicBlock into BasicBlock, and make it
auto-invalidate the instruction ordering when new instructions are
added. Notably, we don't need to invalidate it when removing
instructions, which is helpful when a pass mostly delete dead
instructions rather than transforming them.
The downside is that Instruction grows from 56 bytes to 64 bytes. The
resulting LLVM code is substantially simpler and automatically handles
invalidation, which makes me think that this is the right speed and size
tradeoff.
The important change is in SymbolTableTraitsImpl.h, where the numbering
is invalidated. Everything else should be straightforward.
We probably want to implement a fancier re-numbering scheme so that
local updates don't invalidate the ordering, but I plan for that to be
future work, maybe for someone else.
Reviewed By: lattner, vsk, fhahn, dexonsmith
Differential Revision: https://reviews.llvm.org/D51664
2020-02-19 06:33:54 +08:00
|
|
|
// Transfering nodes, even within the same BB, invalidates the ordering. The
|
|
|
|
// list that we removed the nodes from still has a valid ordering.
|
|
|
|
ItemParentClass *NewIP = getListOwner();
|
|
|
|
invalidateParentIListOrdering(NewIP);
|
|
|
|
|
|
|
|
// Nothing else needs to be done if we're reording nodes within the same list.
|
|
|
|
ItemParentClass *OldIP = L2.getListOwner();
|
2019-01-24 06:59:52 +08:00
|
|
|
if (NewIP == OldIP)
|
|
|
|
return;
|
2002-06-26 00:13:24 +08:00
|
|
|
|
2003-10-11 01:54:14 +08:00
|
|
|
// We only have to update symbol table entries if we are transferring the
|
2002-06-26 00:13:24 +08:00
|
|
|
// instructions to a different symtab object...
|
2015-10-07 05:31:07 +08:00
|
|
|
ValueSymbolTable *NewST = getSymTab(NewIP);
|
|
|
|
ValueSymbolTable *OldST = getSymTab(OldIP);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (NewST != OldST) {
|
2002-06-26 00:13:24 +08:00
|
|
|
for (; first != last; ++first) {
|
|
|
|
ValueSubClass &V = *first;
|
|
|
|
bool HasName = V.hasName();
|
2007-04-17 11:26:42 +08:00
|
|
|
if (OldST && HasName)
|
|
|
|
OldST->removeValueName(V.getValueName());
|
2002-06-26 00:13:24 +08:00
|
|
|
V.setParent(NewIP);
|
2007-04-17 11:26:42 +08:00
|
|
|
if (NewST && HasName)
|
|
|
|
NewST->reinsertValue(&V);
|
2002-06-26 00:13:24 +08:00
|
|
|
}
|
|
|
|
} else {
|
2003-10-11 01:54:14 +08:00
|
|
|
// Just transferring between blocks in the same function, simply update the
|
2002-06-26 00:13:24 +08:00
|
|
|
// parent fields in the instructions...
|
|
|
|
for (; first != last; ++first)
|
|
|
|
first->setParent(NewIP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 17:49:53 +08:00
|
|
|
} // End llvm namespace
|
2003-11-12 06:41:34 +08:00
|
|
|
|
2002-06-26 00:13:24 +08:00
|
|
|
#endif
|