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"
18 LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
19 : TheTrueVal(0), TheFalseVal(0),
20 VoidTy(C, Type::VoidTyID),
21 LabelTy(C, Type::LabelTyID),
22 FloatTy(C, Type::FloatTyID),
23 DoubleTy(C, Type::DoubleTyID),
24 MetadataTy(C, Type::MetadataTyID),
25 X86_FP80Ty(C, Type::X86_FP80TyID),
26 FP128Ty(C, Type::FP128TyID),
27 PPC_FP128Ty(C, Type::PPC_FP128TyID),
33 AlwaysOpaqueTy(new OpaqueType(C)) {
34 InlineAsmDiagHandler = 0;
35 InlineAsmDiagContext = 0;
37 // Make sure the AlwaysOpaqueTy stays alive as long as the Context.
38 AlwaysOpaqueTy->addRef();
39 OpaqueTypes.insert(AlwaysOpaqueTy);
43 struct DropReferences {
44 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
46 template<typename PairT>
47 void operator()(const PairT &P) {
48 P.second->dropAllReferences();
53 LLVMContextImpl::~LLVMContextImpl() {
54 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
56 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
58 std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
60 std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
62 ExprConstants.freeConstants();
63 ArrayConstants.freeConstants();
64 StructConstants.freeConstants();
65 VectorConstants.freeConstants();
66 AggZeroConstants.freeConstants();
67 NullPtrConstants.freeConstants();
68 UndefValueConstants.freeConstants();
69 InlineAsms.freeConstants();
70 for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end();
74 for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end();
78 AlwaysOpaqueTy->dropRef();
79 for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
81 (*I)->AbstractTypeUsers.clear();
84 // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
85 // and the NonUniquedMDNodes sets, so copy the values out first.
86 SmallVector<MDNode*, 8> MDNodes;
87 MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
88 for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
90 MDNodes.push_back(&*I);
92 MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
93 for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(),
94 E = MDNodes.end(); I != E; ++I) {
97 assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
98 "Destroying all MDNodes didn't empty the Context's sets.");
100 for (StringMap<MDString*>::iterator I = MDStringCache.begin(),
101 E = MDStringCache.end(); I != E; ++I) {