2009-06-30 08:48:55 +08:00
|
|
|
//===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-07-01 01:06:46 +08:00
|
|
|
//
|
|
|
|
// This file implements LLVMContext, as a wrapper around the opaque
|
2009-08-12 01:45:13 +08:00
|
|
|
// class LLVMContextImpl.
|
2009-07-01 01:06:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2009-06-30 08:48:55 +08:00
|
|
|
|
|
|
|
#include "llvm/LLVMContext.h"
|
|
|
|
#include "llvm/Constants.h"
|
2009-07-13 12:09:18 +08:00
|
|
|
#include "llvm/Instruction.h"
|
2009-07-01 07:39:59 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2009-06-30 08:48:55 +08:00
|
|
|
#include "LLVMContextImpl.h"
|
2009-08-11 14:31:57 +08:00
|
|
|
#include <set>
|
2009-06-30 08:48:55 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2009-07-01 07:39:59 +08:00
|
|
|
static ManagedStatic<LLVMContext> GlobalContext;
|
|
|
|
|
2009-07-02 07:13:44 +08:00
|
|
|
LLVMContext& llvm::getGlobalContext() {
|
2009-07-02 05:22:36 +08:00
|
|
|
return *GlobalContext;
|
2009-07-01 07:39:59 +08:00
|
|
|
}
|
|
|
|
|
2009-08-14 07:27:32 +08:00
|
|
|
LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
|
2009-06-30 08:48:55 +08:00
|
|
|
LLVMContext::~LLVMContext() { delete pImpl; }
|
2009-08-05 06:41:48 +08:00
|
|
|
|
|
|
|
GetElementPtrConstantExpr::GetElementPtrConstantExpr
|
|
|
|
(Constant *C,
|
|
|
|
const std::vector<Constant*> &IdxList,
|
|
|
|
const Type *DestTy)
|
|
|
|
: ConstantExpr(DestTy, Instruction::GetElementPtr,
|
|
|
|
OperandTraits<GetElementPtrConstantExpr>::op_end(this)
|
|
|
|
- (IdxList.size()+1),
|
|
|
|
IdxList.size()+1) {
|
|
|
|
OperandList[0] = C;
|
|
|
|
for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
|
|
|
|
OperandList[i+1] = IdxList[i];
|
|
|
|
}
|
2009-08-11 14:31:57 +08:00
|
|
|
|
|
|
|
bool LLVMContext::RemoveDeadMetadata() {
|
|
|
|
std::vector<const MDNode *> DeadMDNodes;
|
|
|
|
bool Changed = false;
|
|
|
|
while (1) {
|
|
|
|
|
|
|
|
for (LLVMContextImpl::MDNodeMapTy::MapTy::iterator
|
|
|
|
I = pImpl->MDNodes.map_begin(),
|
|
|
|
E = pImpl->MDNodes.map_end(); I != E; ++I) {
|
|
|
|
const MDNode *N = cast<MDNode>(I->second);
|
|
|
|
if (N->use_empty())
|
|
|
|
DeadMDNodes.push_back(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (DeadMDNodes.empty())
|
|
|
|
return Changed;
|
|
|
|
|
|
|
|
while (!DeadMDNodes.empty()) {
|
|
|
|
const MDNode *N = DeadMDNodes.back(); DeadMDNodes.pop_back();
|
|
|
|
delete N;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|