Fix a comment typo.
[oota-llvm.git] / lib / VMCore / LLVMContext.cpp
1 //===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
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 LLVMContext, as a wrapper around the opaque
11 //  class LLVMContextImpl.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/LLVMContext.h"
16 #include "llvm/Metadata.h"
17 #include "llvm/Constants.h"
18 #include "llvm/Instruction.h"
19 #include "llvm/Support/ManagedStatic.h"
20 #include "llvm/Support/ValueHandle.h"
21 #include "LLVMContextImpl.h"
22 #include <set>
23
24 using namespace llvm;
25
26 static ManagedStatic<LLVMContext> GlobalContext;
27
28 LLVMContext& llvm::getGlobalContext() {
29   return *GlobalContext;
30 }
31
32 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
33 LLVMContext::~LLVMContext() { delete pImpl; }
34
35 GetElementPtrConstantExpr::GetElementPtrConstantExpr
36   (Constant *C,
37    const std::vector<Constant*> &IdxList,
38    const Type *DestTy)
39     : ConstantExpr(DestTy, Instruction::GetElementPtr,
40                    OperandTraits<GetElementPtrConstantExpr>::op_end(this)
41                    - (IdxList.size()+1),
42                    IdxList.size()+1) {
43   OperandList[0] = C;
44   for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
45     OperandList[i+1] = IdxList[i];
46 }
47
48 bool LLVMContext::RemoveDeadMetadata() {
49   std::vector<WeakVH> DeadMDNodes;
50   bool Changed = false;
51   while (1) {
52
53     for (FoldingSet<MDNode>::iterator 
54            I = pImpl->MDNodeSet.begin(),
55            E = pImpl->MDNodeSet.end(); I != E; ++I) {
56       MDNode *N = &(*I);
57       if (N->use_empty()) 
58         DeadMDNodes.push_back(WeakVH(N));
59     }
60     
61     if (DeadMDNodes.empty())
62       return Changed;
63
64     while (!DeadMDNodes.empty()) {
65       Value *V = DeadMDNodes.back(); DeadMDNodes.pop_back();
66       if (const MDNode *N = dyn_cast_or_null<MDNode>(V))
67         if (N->use_empty())
68           delete N;
69     }
70   }
71   return Changed;
72 }
73
74 MetadataContext &LLVMContext::getMetadata() {
75   return pImpl->TheMetadata;
76 }