1 //===--------------- LLVMContextImpl.cpp - Implementation ------*- C++ -*--===//
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 LLVMContextImpl, the opaque implementation
13 //===----------------------------------------------------------------------===//
15 #include "LLVMContextImpl.h"
16 #include "llvm/Constants.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/LLVMContext.h"
19 #include "llvm/Metadata.h"
22 LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
23 Context(C), TheTrueVal(0), TheFalseVal(0) { }
25 MDString *LLVMContextImpl::getMDString(const char *StrBegin,
27 sys::SmartScopedWriter<true> Writer(ConstantsLock);
28 StringMapEntry<MDString *> &Entry =
29 MDStringCache.GetOrCreateValue(StringRef(StrBegin, StrLength));
30 MDString *&S = Entry.getValue();
31 if (!S) S = new MDString(Entry.getKeyData(),
32 Entry.getKeyLength());
37 MDNode *LLVMContextImpl::getMDNode(Value*const* Vals, unsigned NumVals) {
39 for (unsigned i = 0; i != NumVals; ++i)
40 ID.AddPointer(Vals[i]);
42 ConstantsLock.reader_acquire();
44 MDNode *N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
45 ConstantsLock.reader_release();
48 sys::SmartScopedWriter<true> Writer(ConstantsLock);
49 N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint);
51 // InsertPoint will have been set by the FindNodeOrInsertPos call.
52 N = new MDNode(Vals, NumVals);
53 MDNodeSet.InsertNode(N, InsertPoint);
60 // *** erase methods ***
62 void LLVMContextImpl::erase(MDString *M) {
63 sys::SmartScopedWriter<true> Writer(ConstantsLock);
64 MDStringCache.erase(MDStringCache.find(M->getString()));
67 void LLVMContextImpl::erase(MDNode *M) {
68 sys::SmartScopedWriter<true> Writer(ConstantsLock);
69 MDNodeSet.RemoveNode(M);