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"
15 #include "llvm/Module.h"
16 #include "llvm/ADT/STLExtras.h"
20 LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
21 : TheTrueVal(0), TheFalseVal(0),
22 VoidTy(C, Type::VoidTyID),
23 LabelTy(C, Type::LabelTyID),
24 HalfTy(C, Type::HalfTyID),
25 FloatTy(C, Type::FloatTyID),
26 DoubleTy(C, Type::DoubleTyID),
27 MetadataTy(C, Type::MetadataTyID),
28 X86_FP80Ty(C, Type::X86_FP80TyID),
29 FP128Ty(C, Type::FP128TyID),
30 PPC_FP128Ty(C, Type::PPC_FP128TyID),
31 X86_MMXTy(C, Type::X86_MMXTyID),
37 InlineAsmDiagHandler = 0;
38 InlineAsmDiagContext = 0;
39 NamedStructTypesUniqueID = 0;
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();
52 // Temporary - drops pair.first instead of second.
54 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
56 template<typename PairT>
57 void operator()(const PairT &P) {
58 P.first->dropAllReferences();
63 LLVMContextImpl::~LLVMContextImpl() {
64 // NOTE: We need to delete the contents of OwnedModules, but we have to
65 // duplicate it into a temporary vector, because the destructor of Module
66 // will try to remove itself from OwnedModules set. This would cause
67 // iterator invalidation if we iterated on the set directly.
68 std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
69 DeleteContainerPointers(Modules);
71 // Free the constants. This is important to do here to ensure that they are
72 // freed before the LeakDetector is torn down.
73 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
75 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
77 std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
79 std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
81 ExprConstants.freeConstants();
82 ArrayConstants.freeConstants();
83 StructConstants.freeConstants();
84 VectorConstants.freeConstants();
85 DeleteContainerSeconds(CAZConstants);
86 DeleteContainerSeconds(CPNConstants);
87 DeleteContainerSeconds(UVConstants);
88 InlineAsms.freeConstants();
89 DeleteContainerSeconds(IntConstants);
90 DeleteContainerSeconds(FPConstants);
92 for (StringMap<ConstantDataSequential*>::iterator I = CDSConstants.begin(),
93 E = CDSConstants.end(); I != E; ++I)
97 // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
98 // and the NonUniquedMDNodes sets, so copy the values out first.
99 SmallVector<MDNode*, 8> MDNodes;
100 MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
101 for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
103 MDNodes.push_back(&*I);
104 MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
105 for (SmallVectorImpl<MDNode *>::iterator I = MDNodes.begin(),
106 E = MDNodes.end(); I != E; ++I)
108 assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
109 "Destroying all MDNodes didn't empty the Context's sets.");
110 // Destroy MDStrings.
111 DeleteContainerSeconds(MDStringCache);
114 // ConstantsContext anchors
115 void UnaryConstantExpr::anchor() { }
117 void BinaryConstantExpr::anchor() { }
119 void SelectConstantExpr::anchor() { }
121 void ExtractElementConstantExpr::anchor() { }
123 void InsertElementConstantExpr::anchor() { }
125 void ShuffleVectorConstantExpr::anchor() { }
127 void ExtractValueConstantExpr::anchor() { }
129 void InsertValueConstantExpr::anchor() { }
131 void GetElementPtrConstantExpr::anchor() { }
133 void CompareConstantExpr::anchor() { }