LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
LLVMContextImpl.cpp
Go to the documentation of this file.
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"
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/IR/Attributes.h"
17 #include "llvm/IR/Module.h"
18 #include <algorithm>
19 using namespace llvm;
20 
22  : TheTrueVal(0), TheFalseVal(0),
23  VoidTy(C, Type::VoidTyID),
24  LabelTy(C, Type::LabelTyID),
25  HalfTy(C, Type::HalfTyID),
26  FloatTy(C, Type::FloatTyID),
27  DoubleTy(C, Type::DoubleTyID),
28  MetadataTy(C, Type::MetadataTyID),
29  X86_FP80Ty(C, Type::X86_FP80TyID),
30  FP128Ty(C, Type::FP128TyID),
31  PPC_FP128Ty(C, Type::PPC_FP128TyID),
32  X86_MMXTy(C, Type::X86_MMXTyID),
33  Int1Ty(C, 1),
34  Int8Ty(C, 8),
35  Int16Ty(C, 16),
36  Int32Ty(C, 32),
37  Int64Ty(C, 64) {
41 }
42 
43 namespace {
44 struct DropReferences {
45  // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
46  // is a Constant*.
47  template<typename PairT>
48  void operator()(const PairT &P) {
49  P.second->dropAllReferences();
50  }
51 };
52 
53 // Temporary - drops pair.first instead of second.
54 struct DropFirst {
55  // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
56  // is a Constant*.
57  template<typename PairT>
58  void operator()(const PairT &P) {
59  P.first->dropAllReferences();
60  }
61 };
62 }
63 
65  // NOTE: We need to delete the contents of OwnedModules, but we have to
66  // duplicate it into a temporary vector, because the destructor of Module
67  // will try to remove itself from OwnedModules set. This would cause
68  // iterator invalidation if we iterated on the set directly.
69  std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
70  DeleteContainerPointers(Modules);
71 
72  // Free the constants. This is important to do here to ensure that they are
73  // freed before the LeakDetector is torn down.
74  std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
75  DropReferences());
77  DropFirst());
79  DropFirst());
81  DropFirst());
82  ExprConstants.freeConstants();
89  InlineAsms.freeConstants();
92 
94  E = CDSConstants.end(); I != E; ++I)
95  delete I->second;
96  CDSConstants.clear();
97 
98  // Destroy attributes.
100  E = AttrsSet.end(); I != E; ) {
102  delete &*Elem;
103  }
104 
105  // Destroy attribute lists.
107  E = AttrsLists.end(); I != E; ) {
109  delete &*Elem;
110  }
111 
112  // Destroy attribute node lists.
114  E = AttrsSetNodes.end(); I != E; ) {
116  delete &*Elem;
117  }
118 
119  // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
120  // and the NonUniquedMDNodes sets, so copy the values out first.
121  SmallVector<MDNode*, 8> MDNodes;
122  MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
123  for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
124  I != E; ++I)
125  MDNodes.push_back(&*I);
126  MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
128  E = MDNodes.end(); I != E; ++I)
129  (*I)->destroy();
130  assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
131  "Destroying all MDNodes didn't empty the Context's sets.");
132 
133  // Destroy MDStrings.
135 }
136 
137 // ConstantsContext anchors
138 void UnaryConstantExpr::anchor() { }
139 
140 void BinaryConstantExpr::anchor() { }
141 
142 void SelectConstantExpr::anchor() { }
143 
144 void ExtractElementConstantExpr::anchor() { }
145 
146 void InsertElementConstantExpr::anchor() { }
147 
148 void ShuffleVectorConstantExpr::anchor() { }
149 
150 void ExtractValueConstantExpr::anchor() { }
151 
152 void InsertValueConstantExpr::anchor() { }
153 
154 void GetElementPtrConstantExpr::anchor() { }
155 
156 void CompareConstantExpr::anchor() { }
void DeleteContainerSeconds(Container &C)
Definition: STLExtras.h:324
void DeleteContainerPointers(Container &C)
Definition: STLExtras.h:315
void reserve(unsigned N)
Definition: SmallVector.h:425
FoldingSet< AttributeImpl > AttrsSet
LLVMContext::InlineAsmDiagHandlerTy InlineAsmDiagHandler
FoldingSet< AttributeSetImpl > AttrsLists
This file contains the simple types necessary to represent the attributes associated with functions a...
LLVMContextImpl(LLVMContext &C)
const Type::TypeID FloatTyID
ArrayConstantsTy ArrayConstants
DenseMap< PointerType *, ConstantPointerNull * > CPNConstants
DenseMap< Type *, ConstantAggregateZero * > CAZConstants
#define P(N)
Type * Int32Ty
FoldingSet< MDNode > MDNodeSet
SmallPtrSet< MDNode *, 1 > NonUniquedMDNodes
void append(in_iter in_start, in_iter in_end)
Definition: SmallVector.h:445
ConstantUniqueMap< ExprMapKeyType, const ExprMapKeyType &, Type, ConstantExpr > ExprConstants
VectorConstantsTy VectorConstants
SmallPtrSet< Module *, 4 > OwnedModules
DenseMap< Type *, UndefValue * > UVConstants
StringMap< Value * > MDStringCache
#define I(x, y, z)
Definition: MD5.cpp:54
ConstantUniqueMap< InlineAsmKeyType, const InlineAsmKeyType &, PointerType, InlineAsm > InlineAsms
iterator end() const
Definition: SmallPtrSet.h:279
const Type::TypeID DoubleTyID
StructConstantsTy StructConstants
iterator begin() const
Definition: SmallPtrSet.h:276
FoldingSet< AttributeSetNode > AttrsSetNodes
StringMap< ConstantDataSequential * > CDSConstants