2009-07-17 02:04:31 +08:00
|
|
|
//===--------------- LLVMContextImpl.cpp - Implementation ------*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements LLVMContextImpl, the opaque implementation
|
|
|
|
// of LLVMContext.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "LLVMContextImpl.h"
|
|
|
|
#include "llvm/Constants.h"
|
|
|
|
#include "llvm/DerivedTypes.h"
|
|
|
|
#include "llvm/LLVMContext.h"
|
2009-07-29 05:49:47 +08:00
|
|
|
#include "llvm/Metadata.h"
|
2009-07-17 02:04:31 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2009-07-22 04:13:12 +08:00
|
|
|
LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
|
2009-07-25 07:12:02 +08:00
|
|
|
Context(C), TheTrueVal(0), TheFalseVal(0) { }
|
2009-07-22 04:13:12 +08:00
|
|
|
|
2009-07-17 06:11:26 +08:00
|
|
|
MDString *LLVMContextImpl::getMDString(const char *StrBegin,
|
2009-07-23 10:00:51 +08:00
|
|
|
unsigned StrLength) {
|
2009-07-17 06:11:26 +08:00
|
|
|
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
2009-07-23 10:00:51 +08:00
|
|
|
StringMapEntry<MDString *> &Entry =
|
2009-07-24 02:17:34 +08:00
|
|
|
MDStringCache.GetOrCreateValue(StringRef(StrBegin, StrLength));
|
2009-07-17 06:11:26 +08:00
|
|
|
MDString *&S = Entry.getValue();
|
|
|
|
if (!S) S = new MDString(Entry.getKeyData(),
|
2009-07-23 10:00:51 +08:00
|
|
|
Entry.getKeyLength());
|
2009-07-17 06:11:26 +08:00
|
|
|
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
2009-07-17 07:44:30 +08:00
|
|
|
MDNode *LLVMContextImpl::getMDNode(Value*const* Vals, unsigned NumVals) {
|
|
|
|
FoldingSetNodeID ID;
|
|
|
|
for (unsigned i = 0; i != NumVals; ++i)
|
|
|
|
ID.AddPointer(Vals[i]);
|
|
|
|
|
|
|
|
ConstantsLock.reader_acquire();
|
|
|
|
void *InsertPoint;
|
|
|
|
MDNode *N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
|
|
|
ConstantsLock.reader_release();
|
|
|
|
|
|
|
|
if (!N) {
|
|
|
|
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
|
|
|
N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
|
|
|
|
if (!N) {
|
|
|
|
// InsertPoint will have been set by the FindNodeOrInsertPos call.
|
2009-07-23 09:07:34 +08:00
|
|
|
N = new MDNode(Vals, NumVals);
|
2009-07-17 07:44:30 +08:00
|
|
|
MDNodeSet.InsertNode(N, InsertPoint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return N;
|
|
|
|
}
|
|
|
|
|
2009-07-17 06:11:26 +08:00
|
|
|
// *** erase methods ***
|
|
|
|
|
|
|
|
void LLVMContextImpl::erase(MDString *M) {
|
|
|
|
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
2009-07-26 07:55:21 +08:00
|
|
|
MDStringCache.erase(MDStringCache.find(M->getString()));
|
2009-07-17 06:11:26 +08:00
|
|
|
}
|
2009-07-17 07:44:30 +08:00
|
|
|
|
|
|
|
void LLVMContextImpl::erase(MDNode *M) {
|
|
|
|
sys::SmartScopedWriter<true> Writer(ConstantsLock);
|
|
|
|
MDNodeSet.RemoveNode(M);
|
|
|
|
}
|