]> git.proxmox.com Git - rustc.git/blame - src/llvm/lib/IR/LLVMContextImpl.cpp
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / lib / IR / LLVMContextImpl.cpp
CommitLineData
223e47cc
LB
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"
223e47cc 15#include "llvm/ADT/STLExtras.h"
970d7e83 16#include "llvm/IR/Attributes.h"
1a4d82fc 17#include "llvm/IR/DiagnosticInfo.h"
970d7e83 18#include "llvm/IR/Module.h"
223e47cc
LB
19#include <algorithm>
20using namespace llvm;
21
22LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
1a4d82fc 23 : TheTrueVal(nullptr), TheFalseVal(nullptr),
223e47cc
LB
24 VoidTy(C, Type::VoidTyID),
25 LabelTy(C, Type::LabelTyID),
26 HalfTy(C, Type::HalfTyID),
27 FloatTy(C, Type::FloatTyID),
28 DoubleTy(C, Type::DoubleTyID),
29 MetadataTy(C, Type::MetadataTyID),
30 X86_FP80Ty(C, Type::X86_FP80TyID),
31 FP128Ty(C, Type::FP128TyID),
32 PPC_FP128Ty(C, Type::PPC_FP128TyID),
33 X86_MMXTy(C, Type::X86_MMXTyID),
34 Int1Ty(C, 1),
35 Int8Ty(C, 8),
36 Int16Ty(C, 16),
37 Int32Ty(C, 32),
38 Int64Ty(C, 64) {
1a4d82fc
JJ
39 InlineAsmDiagHandler = nullptr;
40 InlineAsmDiagContext = nullptr;
41 DiagnosticHandler = nullptr;
42 DiagnosticContext = nullptr;
43 RespectDiagnosticFilters = false;
44 YieldCallback = nullptr;
45 YieldOpaqueHandle = nullptr;
223e47cc
LB
46 NamedStructTypesUniqueID = 0;
47}
48
49namespace {
50struct DropReferences {
51 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
52 // is a Constant*.
1a4d82fc 53 template <typename PairT> void operator()(const PairT &P) {
223e47cc
LB
54 P.second->dropAllReferences();
55 }
56};
57
58// Temporary - drops pair.first instead of second.
59struct DropFirst {
60 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
61 // is a Constant*.
62 template<typename PairT>
63 void operator()(const PairT &P) {
64 P.first->dropAllReferences();
65 }
66};
67}
68
69LLVMContextImpl::~LLVMContextImpl() {
1a4d82fc
JJ
70 // NOTE: We need to delete the contents of OwnedModules, but Module's dtor
71 // will call LLVMContextImpl::removeModule, thus invalidating iterators into
72 // the container. Avoid iterators during this operation:
73 while (!OwnedModules.empty())
74 delete *OwnedModules.begin();
85aaf69f
SL
75
76 // Drop references for MDNodes. Do this before Values get deleted to avoid
77 // unnecessary RAUW when nodes are still unresolved.
78 for (auto *I : DistinctMDNodes)
79 I->dropAllReferences();
80 for (auto *I : MDTuples)
81 I->dropAllReferences();
82 for (auto *I : MDLocations)
83 I->dropAllReferences();
84
85 // Also drop references that come from the Value bridges.
86 for (auto &Pair : ValuesAsMetadata)
87 Pair.second->dropUsers();
88 for (auto &Pair : MetadataAsValues)
89 Pair.second->dropUse();
90
91 // Destroy MDNodes.
92 for (UniquableMDNode *I : DistinctMDNodes)
93 I->deleteAsSubclass();
94 for (MDTuple *I : MDTuples)
95 delete I;
96 for (MDLocation *I : MDLocations)
97 delete I;
98
223e47cc
LB
99 // Free the constants. This is important to do here to ensure that they are
100 // freed before the LeakDetector is torn down.
101 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
1a4d82fc 102 DropFirst());
223e47cc
LB
103 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
104 DropFirst());
105 std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
106 DropFirst());
107 std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
108 DropFirst());
109 ExprConstants.freeConstants();
110 ArrayConstants.freeConstants();
111 StructConstants.freeConstants();
112 VectorConstants.freeConstants();
113 DeleteContainerSeconds(CAZConstants);
114 DeleteContainerSeconds(CPNConstants);
115 DeleteContainerSeconds(UVConstants);
116 InlineAsms.freeConstants();
117 DeleteContainerSeconds(IntConstants);
118 DeleteContainerSeconds(FPConstants);
119
120 for (StringMap<ConstantDataSequential*>::iterator I = CDSConstants.begin(),
121 E = CDSConstants.end(); I != E; ++I)
122 delete I->second;
123 CDSConstants.clear();
124
125 // Destroy attributes.
970d7e83
LB
126 for (FoldingSetIterator<AttributeImpl> I = AttrsSet.begin(),
127 E = AttrsSet.end(); I != E; ) {
128 FoldingSetIterator<AttributeImpl> Elem = I++;
129 delete &*Elem;
130 }
131
132 // Destroy attribute lists.
133 for (FoldingSetIterator<AttributeSetImpl> I = AttrsLists.begin(),
134 E = AttrsLists.end(); I != E; ) {
135 FoldingSetIterator<AttributeSetImpl> Elem = I++;
136 delete &*Elem;
137 }
138
139 // Destroy attribute node lists.
140 for (FoldingSetIterator<AttributeSetNode> I = AttrsSetNodes.begin(),
141 E = AttrsSetNodes.end(); I != E; ) {
142 FoldingSetIterator<AttributeSetNode> Elem = I++;
143 delete &*Elem;
144 }
145
85aaf69f
SL
146 // Destroy MetadataAsValues.
147 {
148 SmallVector<MetadataAsValue *, 8> MDVs;
149 MDVs.reserve(MetadataAsValues.size());
150 for (auto &Pair : MetadataAsValues)
151 MDVs.push_back(Pair.second);
152 MetadataAsValues.clear();
153 for (auto *V : MDVs)
154 delete V;
155 }
156
157 // Destroy ValuesAsMetadata.
158 for (auto &Pair : ValuesAsMetadata)
159 delete Pair.second;
223e47cc
LB
160
161 // Destroy MDStrings.
85aaf69f 162 MDStringCache.clear();
223e47cc
LB
163}
164
165// ConstantsContext anchors
166void UnaryConstantExpr::anchor() { }
167
168void BinaryConstantExpr::anchor() { }
169
170void SelectConstantExpr::anchor() { }
171
172void ExtractElementConstantExpr::anchor() { }
173
174void InsertElementConstantExpr::anchor() { }
175
176void ShuffleVectorConstantExpr::anchor() { }
177
178void ExtractValueConstantExpr::anchor() { }
179
180void InsertValueConstantExpr::anchor() { }
181
182void GetElementPtrConstantExpr::anchor() { }
183
184void CompareConstantExpr::anchor() { }