1 //===-- LLVMContextImpl.cpp - Implement LLVMContextImpl -------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the opaque LLVMContextImpl.
12 //===----------------------------------------------------------------------===//
14 #include "LLVMContextImpl.h"
17 LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
18 : TheTrueVal(0), TheFalseVal(0),
19 VoidTy(C, Type::VoidTyID),
20 LabelTy(C, Type::LabelTyID),
21 FloatTy(C, Type::FloatTyID),
22 DoubleTy(C, Type::DoubleTyID),
23 MetadataTy(C, Type::MetadataTyID),
24 X86_FP80Ty(C, Type::X86_FP80TyID),
25 FP128Ty(C, Type::FP128TyID),
26 PPC_FP128Ty(C, Type::PPC_FP128TyID),
32 AlwaysOpaqueTy(new OpaqueType(C)) {
33 // Make sure the AlwaysOpaqueTy stays alive as long as the Context.
34 AlwaysOpaqueTy->addRef();
35 OpaqueTypes.insert(AlwaysOpaqueTy);
39 struct DropReferences {
40 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
42 template<typename PairT>
43 void operator()(const PairT &P) {
44 P.second->dropAllReferences();
49 LLVMContextImpl::~LLVMContextImpl() {
50 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
52 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
54 std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
56 std::for_each(UnionConstants.map_begin(), UnionConstants.map_end(),
58 std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
60 ExprConstants.freeConstants();
61 ArrayConstants.freeConstants();
62 StructConstants.freeConstants();
63 UnionConstants.freeConstants();
64 VectorConstants.freeConstants();
65 AggZeroConstants.freeConstants();
66 NullPtrConstants.freeConstants();
67 UndefValueConstants.freeConstants();
68 InlineAsms.freeConstants();
69 for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end();
73 for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end();
77 AlwaysOpaqueTy->dropRef();
78 for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
80 (*I)->AbstractTypeUsers.clear();
83 // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
84 // and the NonUniquedMDNodes sets, so copy the values out first.
85 SmallVector<MDNode*, 8> MDNodes;
86 MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
87 for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
89 MDNodes.push_back(&*I);
91 MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
92 for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(),
93 E = MDNodes.end(); I != E; ++I) {
96 assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
97 "Destroying all MDNodes didn't empty the Context's sets.");
99 for (StringMap<MDString*>::iterator I = MDStringCache.begin(),
100 E = MDStringCache.end(); I != E; ++I) {