diff options
-rw-r--r-- | llvm/include/llvm/IR/Constants.h | 6 | ||||
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/IR/LLVMContextImpl.h | 4 |
3 files changed, 19 insertions, 2 deletions
diff --git a/llvm/include/llvm/IR/Constants.h b/llvm/include/llvm/IR/Constants.h index 1acf5b6cc83..448d82931a6 100644 --- a/llvm/include/llvm/IR/Constants.h +++ b/llvm/include/llvm/IR/Constants.h @@ -757,6 +757,12 @@ public: /// block must be embedded into a function. static BlockAddress *get(BasicBlock *BB); + /// \brief Lookup an existing \c BlockAddress constant for the given + /// BasicBlock. + /// + /// \returns 0 if \c !BB->hasAddressTaken(), otherwise the \c BlockAddress. + static BlockAddress *lookup(const BasicBlock *BB); + /// Transparently provide more efficient getOperand methods. DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 1f6f5ac4270..ecd2cfd9fd1 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1375,6 +1375,17 @@ BlockAddress::BlockAddress(Function *F, BasicBlock *BB) BB->AdjustBlockAddressRefCount(1); } +BlockAddress *BlockAddress::lookup(const BasicBlock *BB) { + if (!BB->hasAddressTaken()) + return 0; + + const Function *F = BB->getParent(); + assert(F != 0 && "Block must have a parent"); + BlockAddress *BA = + F->getContext().pImpl->BlockAddresses.lookup(std::make_pair(F, BB)); + assert(BA && "Refcount and block address map disagree!"); + return BA; +} // destroyConstant - Remove the constant from the constant table. // diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h index 39e5d778ed6..04338272463 100644 --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -281,8 +281,8 @@ public: StringMap<ConstantDataSequential*> CDSConstants; - - DenseMap<std::pair<Function*, BasicBlock*> , BlockAddress*> BlockAddresses; + DenseMap<std::pair<const Function *, const BasicBlock *>, BlockAddress *> + BlockAddresses; ConstantUniqueMap<ExprMapKeyType, const ExprMapKeyType&, Type, ConstantExpr> ExprConstants; |