aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-30 22:33:29 +0000
committerChris Lattner <sabre@nondot.org>2009-10-30 22:33:29 +0000
commit3821176b2eb9fe5e66929f3df6f204fa6cb2e4d6 (patch)
tree3dc967f7b4c55152dddb6a5e1fdad3bd3a168a84
parent57f224a5a473462f85e94c457c7548af27c37f0b (diff)
downloadexternal_llvm-3821176b2eb9fe5e66929f3df6f204fa6cb2e4d6.zip
external_llvm-3821176b2eb9fe5e66929f3df6f204fa6cb2e4d6.tar.gz
external_llvm-3821176b2eb9fe5e66929f3df6f204fa6cb2e4d6.tar.bz2
make hasAddressTaken() constant time by storing a refcount in BB's subclass data.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85625 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/BasicBlock.h13
-rw-r--r--lib/VMCore/BasicBlock.cpp8
-rw-r--r--lib/VMCore/Constants.cpp12
3 files changed, 18 insertions, 15 deletions
diff --git a/include/llvm/BasicBlock.h b/include/llvm/BasicBlock.h
index c6e6080..10f2577 100644
--- a/include/llvm/BasicBlock.h
+++ b/include/llvm/BasicBlock.h
@@ -23,6 +23,7 @@ namespace llvm {
class TerminatorInst;
class LLVMContext;
+class BlockAddress;
template<> struct ilist_traits<Instruction>
: public SymbolTableListTraits<Instruction, BasicBlock> {
@@ -66,7 +67,7 @@ private:
/// @brief LLVM Basic Block Representation
class BasicBlock : public Value, // Basic blocks are data objects also
public ilist_node<BasicBlock> {
-
+ friend class BlockAddress;
public:
typedef iplist<Instruction> InstListType;
private:
@@ -238,7 +239,15 @@ public:
/// hasAddressTaken - returns true if there are any uses of this basic block
/// other than direct branches, switches, etc. to it.
- bool hasAddressTaken() const;
+ bool hasAddressTaken() const { return SubclassData != 0; }
+private:
+ /// AdjustBlockAddressRefCount - BasicBlock stores the number of BlockAddress
+ /// objects using it. This is almost always 0, sometimes one, possibly but
+ /// almost never 2, and inconceivably 3 or more.
+ void AdjustBlockAddressRefCount(int Amt) {
+ SubclassData += Amt;
+ assert((int)(char)SubclassData >= 0 && "Refcount wrap-around");
+ }
};
} // End llvm namespace
diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp
index ede2d12..e8069c0 100644
--- a/lib/VMCore/BasicBlock.cpp
+++ b/lib/VMCore/BasicBlock.cpp
@@ -278,11 +278,3 @@ BasicBlock *BasicBlock::splitBasicBlock(iterator I, const Twine &BBName) {
return New;
}
-/// hasAddressTaken - returns true if there are any uses of this basic block
-/// other than direct branches, switches, etc. to it.
-bool BasicBlock::hasAddressTaken() const {
- for (Value::use_const_iterator I = use_begin(), E = use_end(); I != E; ++I)
- if (isa<BlockAddress>(*I))
- return true;
- return false;
-}
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 0d7faba..2d3d71b 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -44,7 +44,7 @@ using namespace llvm;
// Constructor to create a '0' constant of arbitrary type...
static const uint64_t zero[2] = {0, 0};
-Constant* Constant::getNullValue(const Type* Ty) {
+Constant *Constant::getNullValue(const Type *Ty) {
switch (Ty->getTypeID()) {
case Type::IntegerTyID:
return ConstantInt::get(Ty, 0);
@@ -72,7 +72,7 @@ Constant* Constant::getNullValue(const Type* Ty) {
}
}
-Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) {
+Constant* Constant::getIntegerValue(const Type *Ty, const APInt &V) {
const Type *ScalarTy = Ty->getScalarType();
// Create the base integer constant.
@@ -89,13 +89,13 @@ Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) {
return C;
}
-Constant* Constant::getAllOnesValue(const Type* Ty) {
- if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
+Constant* Constant::getAllOnesValue(const Type *Ty) {
+ if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty))
return ConstantInt::get(Ty->getContext(),
APInt::getAllOnesValue(ITy->getBitWidth()));
std::vector<Constant*> Elts;
- const VectorType* VTy = cast<VectorType>(Ty);
+ const VectorType *VTy = cast<VectorType>(Ty);
Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
assert(Elts[0] && "Not a vector integer type!");
return cast<ConstantVector>(ConstantVector::get(Elts));
@@ -1045,6 +1045,7 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
&Op<0>(), 2) {
Op<0>() = F;
Op<1>() = BB;
+ BB->AdjustBlockAddressRefCount(1);
}
@@ -1053,6 +1054,7 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB)
void BlockAddress::destroyConstant() {
getFunction()->getType()->getContext().pImpl
->BlockAddresses.erase(std::make_pair(getFunction(), getBasicBlock()));
+ getBasicBlock()->AdjustBlockAddressRefCount(-1);
destroyConstantImpl();
}