Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 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" |
Jeffrey Yasskin | 4cfb3a7 | 2010-03-21 21:17:34 +0000 | [diff] [blame] | 15 | |
| 16 | LLVMContextImpl::LLVMContextImpl(LLVMContext &C) |
| 17 | : TheTrueVal(0), TheFalseVal(0), |
| 18 | VoidTy(C, Type::VoidTyID), |
| 19 | LabelTy(C, Type::LabelTyID), |
| 20 | FloatTy(C, Type::FloatTyID), |
| 21 | DoubleTy(C, Type::DoubleTyID), |
| 22 | MetadataTy(C, Type::MetadataTyID), |
| 23 | X86_FP80Ty(C, Type::X86_FP80TyID), |
| 24 | FP128Ty(C, Type::FP128TyID), |
| 25 | PPC_FP128Ty(C, Type::PPC_FP128TyID), |
| 26 | Int1Ty(C, 1), |
| 27 | Int8Ty(C, 8), |
| 28 | Int16Ty(C, 16), |
| 29 | Int32Ty(C, 32), |
| 30 | Int64Ty(C, 64), |
| 31 | AlwaysOpaqueTy(new OpaqueType(C)) { |
| 32 | // Make sure the AlwaysOpaqueTy stays alive as long as the Context. |
| 33 | AlwaysOpaqueTy->addRef(); |
| 34 | OpaqueTypes.insert(AlwaysOpaqueTy); |
| 35 | } |
| 36 | |
| 37 | LLVMContextImpl::~LLVMContextImpl() { |
| 38 | ExprConstants.freeConstants(); |
| 39 | ArrayConstants.freeConstants(); |
| 40 | StructConstants.freeConstants(); |
| 41 | VectorConstants.freeConstants(); |
| 42 | AggZeroConstants.freeConstants(); |
| 43 | NullPtrConstants.freeConstants(); |
| 44 | UndefValueConstants.freeConstants(); |
| 45 | InlineAsms.freeConstants(); |
| 46 | for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end(); |
| 47 | I != E; ++I) { |
| 48 | if (I->second->use_empty()) |
| 49 | delete I->second; |
| 50 | } |
| 51 | for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end(); |
| 52 | I != E; ++I) { |
| 53 | if (I->second->use_empty()) |
| 54 | delete I->second; |
| 55 | } |
| 56 | AlwaysOpaqueTy->dropRef(); |
| 57 | for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end(); |
| 58 | I != E; ++I) { |
| 59 | (*I)->AbstractTypeUsers.clear(); |
| 60 | delete *I; |
| 61 | } |
| 62 | // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet |
| 63 | // and the NonUniquedMDNodes sets, so copy the values out first. |
| 64 | SmallVector<MDNode*, 8> MDNodes; |
| 65 | MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size()); |
| 66 | for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end(); |
| 67 | I != E; ++I) { |
| 68 | MDNodes.push_back(&*I); |
| 69 | } |
| 70 | MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end()); |
| 71 | for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(), |
| 72 | E = MDNodes.end(); I != E; ++I) { |
| 73 | (*I)->destroy(); |
| 74 | } |
| 75 | assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() && |
| 76 | "Destroying all MDNodes didn't empty the Context's sets."); |
| 77 | // Destroy MDStrings. |
| 78 | for (StringMap<MDString*>::iterator I = MDStringCache.begin(), |
| 79 | E = MDStringCache.end(); I != E; ++I) { |
| 80 | delete I->second; |
| 81 | } |
| 82 | } |