LCOV - code coverage report
Current view: top level - lib/IR - LLVMContextImpl.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 95 96 99.0 %
Date: 2017-09-14 15:23:50 Functions: 12 12 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- LLVMContextImpl.cpp - Implement LLVMContextImpl --------------------===//
       2             : //
       3             : //                     The LLVM Compiler Infrastructure
       4             : //
       5             : // This file is distributed under the University of Illinois Open Source
       6             : // License. See LICENSE.TXT for details.
       7             : //
       8             : //===----------------------------------------------------------------------===//
       9             : //
      10             : //  This file implements the opaque LLVMContextImpl.
      11             : //
      12             : //===----------------------------------------------------------------------===//
      13             : 
      14             : #include "LLVMContextImpl.h"
      15             : #include "llvm/IR/Module.h"
      16             : #include "llvm/IR/OptBisect.h"
      17             : #include "llvm/IR/Type.h"
      18             : #include "llvm/Support/ManagedStatic.h"
      19             : #include <cassert>
      20             : #include <utility>
      21             : 
      22             : using namespace llvm;
      23             : 
      24       37586 : LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
      25             :   : VoidTy(C, Type::VoidTyID),
      26             :     LabelTy(C, Type::LabelTyID),
      27             :     HalfTy(C, Type::HalfTyID),
      28             :     FloatTy(C, Type::FloatTyID),
      29             :     DoubleTy(C, Type::DoubleTyID),
      30             :     MetadataTy(C, Type::MetadataTyID),
      31             :     TokenTy(C, Type::TokenTyID),
      32             :     X86_FP80Ty(C, Type::X86_FP80TyID),
      33             :     FP128Ty(C, Type::FP128TyID),
      34             :     PPC_FP128Ty(C, Type::PPC_FP128TyID),
      35             :     X86_MMXTy(C, Type::X86_MMXTyID),
      36             :     Int1Ty(C, 1),
      37             :     Int8Ty(C, 8),
      38             :     Int16Ty(C, 16),
      39             :     Int32Ty(C, 32),
      40             :     Int64Ty(C, 64),
      41     3232459 :     Int128Ty(C, 128) {}
      42             : 
      43     2309767 : LLVMContextImpl::~LLVMContextImpl() {
      44             :   // NOTE: We need to delete the contents of OwnedModules, but Module's dtor
      45             :   // will call LLVMContextImpl::removeModule, thus invalidating iterators into
      46             :   // the container. Avoid iterators during this operation:
      47       73384 :   while (!OwnedModules.empty())
      48          40 :     delete *OwnedModules.begin();
      49             : 
      50             :   // Drop references for MDNodes.  Do this before Values get deleted to avoid
      51             :   // unnecessary RAUW when nodes are still unresolved.
      52      163604 :   for (auto *I : DistinctMDNodes)
      53       16956 :     I->dropAllReferences();
      54             : #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
      55             :   for (auto *I : CLASS##s)                                                     \
      56             :     I->dropAllReferences();
      57             : #include "llvm/IR/Metadata.def"
      58             : 
      59             :   // Also drop references that come from the Value bridges.
      60      150397 :   for (auto &Pair : ValuesAsMetadata)
      61       80820 :     Pair.second->dropUsers();
      62      117874 :   for (auto &Pair : MetadataAsValues)
      63       15772 :     Pair.second->dropUse();
      64             : 
      65             :   // Destroy MDNodes.
      66      163608 :   for (MDNode *I : DistinctMDNodes)
      67       16956 :     I->deleteAsSubclass();
      68             : #define HANDLE_MDNODE_LEAF_UNIQUABLE(CLASS)                                    \
      69             :   for (CLASS * I : CLASS##s)                                                   \
      70             :     delete I;
      71             : #include "llvm/IR/Metadata.def"
      72             : 
      73             :   // Free the constants.
      74      192748 :   for (auto *I : ExprConstants)
      75        3146 :     I->dropAllReferences();
      76      184523 :   for (auto *I : ArrayConstants)
      77         403 :     I->dropAllReferences();
      78      189639 :   for (auto *I : StructConstants)
      79        2108 :     I->dropAllReferences();
      80      211245 :   for (auto *I : VectorConstants)
      81        9310 :     I->dropAllReferences();
      82       36663 :   ExprConstants.freeConstants();
      83       36662 :   ArrayConstants.freeConstants();
      84       36663 :   StructConstants.freeConstants();
      85       36663 :   VectorConstants.freeConstants();
      86       36663 :   InlineAsms.freeConstants();
      87             : 
      88       36663 :   CAZConstants.clear();
      89       36662 :   CPNConstants.clear();
      90       36663 :   UVConstants.clear();
      91       36663 :   IntConstants.clear();
      92       36663 :   FPConstants.clear();
      93             : 
      94      239516 :   for (auto &CDSConstant : CDSConstants)
      95       46432 :     delete CDSConstant.second;
      96       36663 :   CDSConstants.clear();
      97             : 
      98             :   // Destroy attributes.
      99       73325 :   for (FoldingSetIterator<AttributeImpl> I = AttrsSet.begin(),
     100      266867 :          E = AttrsSet.end(); I != E; ) {
     101      313756 :     FoldingSetIterator<AttributeImpl> Elem = I++;
     102      156878 :     delete &*Elem;
     103             :   }
     104             : 
     105             :   // Destroy attribute lists.
     106      199452 :   for (FoldingSetIterator<AttributeListImpl> I = AttrsLists.begin(),
     107       73326 :                                              E = AttrsLists.end();
     108      162789 :        I != E;) {
     109      252252 :     FoldingSetIterator<AttributeListImpl> Elem = I++;
     110      252252 :     delete &*Elem;
     111             :   }
     112             : 
     113             :   // Destroy attribute node lists.
     114      169197 :   for (FoldingSetIterator<AttributeSetNode> I = AttrsSetNodes.begin(),
     115      205860 :          E = AttrsSetNodes.end(); I != E; ) {
     116      191742 :     FoldingSetIterator<AttributeSetNode> Elem = I++;
     117      191742 :     delete &*Elem;
     118             :   }
     119             : 
     120             :   // Destroy MetadataAsValues.
     121             :   {
     122       73326 :     SmallVector<MetadataAsValue *, 8> MDVs;
     123       73326 :     MDVs.reserve(MetadataAsValues.size());
     124      117875 :     for (auto &Pair : MetadataAsValues)
     125        7886 :       MDVs.push_back(Pair.second);
     126       36663 :     MetadataAsValues.clear();
     127      117875 :     for (auto *V : MDVs)
     128        7886 :       delete V;
     129             :   }
     130             : 
     131             :   // Destroy ValuesAsMetadata.
     132      109989 :   for (auto &Pair : ValuesAsMetadata)
     133           0 :     delete Pair.second;
     134       36663 : }
     135             : 
     136         971 : void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
     137             :   bool Changed;
     138         983 :   do {
     139         983 :     Changed = false;
     140             : 
     141        5299 :     for (auto I = ArrayConstants.begin(), E = ArrayConstants.end(); I != E;) {
     142         576 :       auto *C = *I++;
     143         384 :       if (C->use_empty()) {
     144          12 :         Changed = true;
     145          12 :         C->destroyConstant();
     146             :       }
     147             :     }
     148             :   } while (Changed);
     149         971 : }
     150             : 
     151         971 : void Module::dropTriviallyDeadConstantArrays() {
     152         971 :   Context.pImpl->dropTriviallyDeadConstantArrays();
     153         971 : }
     154             : 
     155             : namespace llvm {
     156             : 
     157             : /// \brief Make MDOperand transparent for hashing.
     158             : ///
     159             : /// This overload of an implementation detail of the hashing library makes
     160             : /// MDOperand hash to the same value as a \a Metadata pointer.
     161             : ///
     162             : /// Note that overloading \a hash_value() as follows:
     163             : ///
     164             : /// \code
     165             : ///     size_t hash_value(const MDOperand &X) { return hash_value(X.get()); }
     166             : /// \endcode
     167             : ///
     168             : /// does not cause MDOperand to be transparent.  In particular, a bare pointer
     169             : /// doesn't get hashed before it's combined, whereas \a MDOperand would.
     170    36939596 : static const Metadata *get_hashable_data(const MDOperand &X) { return X.get(); }
     171             : 
     172             : } // end namespace llvm
     173             : 
     174       16996 : unsigned MDNodeOpsKey::calculateHash(MDNode *N, unsigned Offset) {
     175       50988 :   unsigned Hash = hash_combine_range(N->op_begin() + Offset, N->op_end());
     176             : #ifndef NDEBUG
     177             :   {
     178             :     SmallVector<Metadata *, 8> MDs(N->op_begin() + Offset, N->op_end());
     179             :     unsigned RawHash = calculateHash(MDs);
     180             :     assert(Hash == RawHash &&
     181             :            "Expected hash of MDOperand to equal hash of Metadata*");
     182             :   }
     183             : #endif
     184       16996 :   return Hash;
     185             : }
     186             : 
     187      313485 : unsigned MDNodeOpsKey::calculateHash(ArrayRef<Metadata *> Ops) {
     188      626970 :   return hash_combine_range(Ops.begin(), Ops.end());
     189             : }
     190             : 
     191      113971 : StringMapEntry<uint32_t> *LLVMContextImpl::getOrInsertBundleTag(StringRef Tag) {
     192      113971 :   uint32_t NewIdx = BundleTagCache.size();
     193      455884 :   return &*(BundleTagCache.insert(std::make_pair(Tag, NewIdx)).first);
     194             : }
     195             : 
     196        3629 : void LLVMContextImpl::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
     197        3629 :   Tags.resize(BundleTagCache.size());
     198       36306 :   for (const auto &T : BundleTagCache)
     199       32685 :     Tags[T.second] = T.first();
     200        3629 : }
     201             : 
     202          68 : uint32_t LLVMContextImpl::getOperandBundleTagID(StringRef Tag) const {
     203          68 :   auto I = BundleTagCache.find(Tag);
     204             :   assert(I != BundleTagCache.end() && "Unknown tag!");
     205          68 :   return I->second;
     206             : }
     207             : 
     208       86074 : SyncScope::ID LLVMContextImpl::getOrInsertSyncScopeID(StringRef SSN) {
     209       86074 :   auto NewSSID = SSC.size();
     210             :   assert(NewSSID < std::numeric_limits<SyncScope::ID>::max() &&
     211             :          "Hit the maximum number of synchronization scopes allowed!");
     212      344296 :   return SSC.insert(std::make_pair(SSN, SyncScope::ID(NewSSID))).first->second;
     213             : }
     214             : 
     215        3671 : void LLVMContextImpl::getSyncScopeNames(
     216             :     SmallVectorImpl<StringRef> &SSNs) const {
     217        3671 :   SSNs.resize(SSC.size());
     218       29516 :   for (const auto &SSE : SSC)
     219       22248 :     SSNs[SSE.second] = SSE.first();
     220        3671 : }
     221             : 
     222             : /// Singleton instance of the OptBisect class.
     223             : ///
     224             : /// This singleton is accessed via the LLVMContext::getOptBisect() function.  It
     225             : /// provides a mechanism to disable passes and individual optimizations at
     226             : /// compile time based on a command line option (-opt-bisect-limit) in order to
     227             : /// perform a bisecting search for optimization-related problems.
     228             : ///
     229             : /// Even if multiple LLVMContext objects are created, they will all return the
     230             : /// same instance of OptBisect in order to provide a single bisect count.  Any
     231             : /// code that uses the OptBisect object should be serialized when bisection is
     232             : /// enabled in order to enable a consistent bisect count.
     233             : static ManagedStatic<OptBisect> OptBisector;
     234             : 
     235     5645565 : OptBisect &LLVMContextImpl::getOptBisect() {
     236     5645565 :   return *OptBisector;
     237             : }

Generated by: LCOV version 1.13