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/Constants.h"
17 #include "llvm/Instruction.h"
18 #include "llvm/Support/ManagedStatic.h"
19 #include "LLVMContextImpl.h"
24 static ManagedStatic
<LLVMContext
> GlobalContext
;
26 LLVMContext
& llvm::getGlobalContext() {
27 return *GlobalContext
;
30 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
31 LLVMContext::~LLVMContext() { delete pImpl
; }
33 GetElementPtrConstantExpr::GetElementPtrConstantExpr
35 const std::vector
<Constant
*> &IdxList
,
37 : ConstantExpr(DestTy
, Instruction::GetElementPtr
,
38 OperandTraits
<GetElementPtrConstantExpr
>::op_end(this)
42 for (unsigned i
= 0, E
= IdxList
.size(); i
!= E
; ++i
)
43 OperandList
[i
+1] = IdxList
[i
];
46 bool LLVMContext::RemoveDeadMetadata() {
47 std::vector
<const MDNode
*> DeadMDNodes
;
51 for (LLVMContextImpl::MDNodeMapTy::MapTy::iterator
52 I
= pImpl
->MDNodes
.map_begin(),
53 E
= pImpl
->MDNodes
.map_end(); I
!= E
; ++I
) {
54 const MDNode
*N
= cast
<MDNode
>(I
->second
);
56 DeadMDNodes
.push_back(N
);
59 if (DeadMDNodes
.empty())
62 while (!DeadMDNodes
.empty()) {
63 const MDNode
*N
= DeadMDNodes
.back(); DeadMDNodes
.pop_back();