LLVM API Documentation

LLVMContext.cpp

Go to the documentation of this file.
00001 //===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file implements LLVMContext, as a wrapper around the opaque
00011 //  class LLVMContextImpl.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #include "llvm/LLVMContext.h"
00016 #include "llvm/Constants.h"
00017 #include "llvm/Instruction.h"
00018 #include "llvm/Support/ManagedStatic.h"
00019 #include "LLVMContextImpl.h"
00020 #include <set>
00021 
00022 using namespace llvm;
00023 
00024 static ManagedStatic<LLVMContext> GlobalContext;
00025 
00026 LLVMContext& llvm::getGlobalContext() {
00027   return *GlobalContext;
00028 }
00029 
00030 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
00031 LLVMContext::~LLVMContext() { delete pImpl; }
00032 
00033 GetElementPtrConstantExpr::GetElementPtrConstantExpr
00034   (Constant *C,
00035    const std::vector<Constant*> &IdxList,
00036    const Type *DestTy)
00037     : ConstantExpr(DestTy, Instruction::GetElementPtr,
00038                    OperandTraits<GetElementPtrConstantExpr>::op_end(this)
00039                    - (IdxList.size()+1),
00040                    IdxList.size()+1) {
00041   OperandList[0] = C;
00042   for (unsigned i = 0, E = IdxList.size(); i != E; ++i)
00043     OperandList[i+1] = IdxList[i];
00044 }
00045 
00046 bool LLVMContext::RemoveDeadMetadata() {
00047   std::vector<const MDNode *> DeadMDNodes;
00048   bool Changed = false;
00049   while (1) {
00050 
00051     for (LLVMContextImpl::MDNodeMapTy::MapTy::iterator
00052            I = pImpl->MDNodes.map_begin(),
00053            E = pImpl->MDNodes.map_end(); I != E; ++I) {
00054       const MDNode *N = cast<MDNode>(I->second);
00055       if (N->use_empty()) 
00056         DeadMDNodes.push_back(N);
00057     }
00058     
00059     if (DeadMDNodes.empty())
00060       return Changed;
00061 
00062     while (!DeadMDNodes.empty()) {
00063       const MDNode *N = DeadMDNodes.back(); DeadMDNodes.pop_back();
00064       delete N;
00065     }
00066   }
00067   return Changed;
00068 }