Use BranchProbability instead of floating points in IfConverter.
[llvm/stm8.git] / lib / VMCore / LLVMContextImpl.cpp
blob0b7ae6c9272e45c7e335254fc78c41f2406855d4
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.
12 //===----------------------------------------------------------------------===//
14 #include "LLVMContextImpl.h"
15 #include "llvm/Module.h"
16 #include <algorithm>
17 using namespace llvm;
19 LLVMContextImpl::LLVMContextImpl(LLVMContext &C)
20 : TheTrueVal(0), TheFalseVal(0),
21 VoidTy(C, Type::VoidTyID),
22 LabelTy(C, Type::LabelTyID),
23 FloatTy(C, Type::FloatTyID),
24 DoubleTy(C, Type::DoubleTyID),
25 MetadataTy(C, Type::MetadataTyID),
26 X86_FP80Ty(C, Type::X86_FP80TyID),
27 FP128Ty(C, Type::FP128TyID),
28 PPC_FP128Ty(C, Type::PPC_FP128TyID),
29 X86_MMXTy(C, Type::X86_MMXTyID),
30 Int1Ty(C, 1),
31 Int8Ty(C, 8),
32 Int16Ty(C, 16),
33 Int32Ty(C, 32),
34 Int64Ty(C, 64) {
35 InlineAsmDiagHandler = 0;
36 InlineAsmDiagContext = 0;
37 NamedStructTypesUniqueID = 0;
40 namespace {
41 struct DropReferences {
42 // Takes the value_type of a ConstantUniqueMap's internal map, whose 'second'
43 // is a Constant*.
44 template<typename PairT>
45 void operator()(const PairT &P) {
46 P.second->dropAllReferences();
51 LLVMContextImpl::~LLVMContextImpl() {
52 // NOTE: We need to delete the contents of OwnedModules, but we have to
53 // duplicate it into a temporary vector, because the destructor of Module
54 // will try to remove itself from OwnedModules set. This would cause
55 // iterator invalidation if we iterated on the set directly.
56 std::vector<Module*> Modules(OwnedModules.begin(), OwnedModules.end());
57 for (std::vector<Module*>::iterator I = Modules.begin(), E = Modules.end();
58 I != E; ++I)
59 delete *I;
61 std::for_each(ExprConstants.map_begin(), ExprConstants.map_end(),
62 DropReferences());
63 std::for_each(ArrayConstants.map_begin(), ArrayConstants.map_end(),
64 DropReferences());
65 std::for_each(StructConstants.map_begin(), StructConstants.map_end(),
66 DropReferences());
67 std::for_each(VectorConstants.map_begin(), VectorConstants.map_end(),
68 DropReferences());
69 ExprConstants.freeConstants();
70 ArrayConstants.freeConstants();
71 StructConstants.freeConstants();
72 VectorConstants.freeConstants();
73 AggZeroConstants.freeConstants();
74 NullPtrConstants.freeConstants();
75 UndefValueConstants.freeConstants();
76 InlineAsms.freeConstants();
77 for (IntMapTy::iterator I = IntConstants.begin(), E = IntConstants.end();
78 I != E; ++I) {
79 delete I->second;
81 for (FPMapTy::iterator I = FPConstants.begin(), E = FPConstants.end();
82 I != E; ++I) {
83 delete I->second;
86 // Destroy MDNodes. ~MDNode can move and remove nodes between the MDNodeSet
87 // and the NonUniquedMDNodes sets, so copy the values out first.
88 SmallVector<MDNode*, 8> MDNodes;
89 MDNodes.reserve(MDNodeSet.size() + NonUniquedMDNodes.size());
90 for (FoldingSetIterator<MDNode> I = MDNodeSet.begin(), E = MDNodeSet.end();
91 I != E; ++I) {
92 MDNodes.push_back(&*I);
94 MDNodes.append(NonUniquedMDNodes.begin(), NonUniquedMDNodes.end());
95 for (SmallVectorImpl<MDNode *>::iterator I = MDNodes.begin(),
96 E = MDNodes.end(); I != E; ++I) {
97 (*I)->destroy();
99 assert(MDNodeSet.empty() && NonUniquedMDNodes.empty() &&
100 "Destroying all MDNodes didn't empty the Context's sets.");
101 // Destroy MDStrings.
102 for (StringMap<MDString*>::iterator I = MDStringCache.begin(),
103 E = MDStringCache.end(); I != E; ++I)
104 delete I->second;