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(UnionConstants.map_begin(), UnionConstants.map_end(),
62 std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
64 ExprConstants.freeConstants();
65 ArrayConstants.freeConstants();
66 StructConstants.freeConstants();
67 UnionConstants.freeConstants();
68 VectorConstants.freeConstants();
69 AggZeroConstants.freeConstants();
70 NullPtrConstants.freeConstants();
71 UndefValueConstants.freeConstants();
72 InlineAsms.freeConstants();
73 for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end();
77 for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end();
81 AlwaysOpaqueTy->dropRef();
82 for (OpaqueTypesTy::iterator I = OpaqueTypes.begin(), E = OpaqueTypes.end();
84 (*I)->AbstractTypeUsers.clear();
87 // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
88 // and the NonUniquedMDNodes sets, so copy the values out first.
89 SmallVector<MDNode*, 8> MDNodes;
90 MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
91 for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
93 MDNodes.push_back(&*I);
95 MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
96 for (SmallVector<MDNode*, 8>::iterator I = MDNodes.begin(),
97 E = MDNodes.end(); I != E; ++I) {
100 assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
101 "Destroying all MDNodes didn't empty the Context's sets.");
102 // Destroy MDStrings.
103 for (StringMap<MDString*>::iterator I = MDStringCache.begin(),
104 E = MDStringCache.end(); I != E; ++I) {