1 //===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
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 LLVMContext, as a wrapper around the opaque
11 // class LLVMContextImpl.
13 //===----------------------------------------------------------------------===//
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 "LLVMContextImpl.h"
25 static ManagedStatic<LLVMContext> GlobalContext;
27 LLVMContext& llvm::getGlobalContext() {
28 return *GlobalContext;
31 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
32 LLVMContext::~LLVMContext() { delete pImpl; }
34 GetElementPtrConstantExpr::GetElementPtrConstantExpr
36 const std::vector<Constant*> &IdxList,
38 : ConstantExpr(DestTy, Instruction::GetElementPtr,
39 OperandTraits<GetElementPtrConstantExpr>::op_end(this)
43 for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
44 OperandList[i+1] = IdxList[i];
47 bool LLVMContext::RemoveDeadMetadata() {
48 std::vector<const MDNode *> DeadMDNodes;
52 for (FoldingSet<MDNode>::iterator
53 I = pImpl->MDNodeSet.begin(),
54 E = pImpl->MDNodeSet.end(); I != E; ++I) {
55 const MDNode *N = &(*I);
57 DeadMDNodes.push_back(N);
60 if (DeadMDNodes.empty())
63 while (!DeadMDNodes.empty()) {
64 const MDNode *N = DeadMDNodes.back(); DeadMDNodes.pop_back();