#include "llvm/IntrinsicInst.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Support/LeakDetector.h"
+#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/StringPool.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/System/RWMutex.h"
#include "SymbolTableListTraitsImpl.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
// use GC.
static DenseMap<const Function*,PooledStringPtr> *GCNames;
static StringPool *GCNamePool;
+static ManagedStatic<sys::RWMutex> GCLock;
bool Function::hasGC() const {
- return GCNames && GCNames->count(this);
+ if (llvm_is_multithreaded()) {
+ sys::ScopedReader Reader(&*GCLock);
+ return GCNames && GCNames->count(this);
+ } else
+ return GCNames && GCNames->count(this);
}
const char *Function::getGC() const {
assert(hasGC() && "Function has no collector");
- return *(*GCNames)[this];
+ if (llvm_is_multithreaded()) {
+ sys::ScopedReader Reader(&*GCLock);
+ return *(*GCNames)[this];
+ } else
+ return *(*GCNames)[this];
}
void Function::setGC(const char *Str) {
+ if (llvm_is_multithreaded()) GCLock->writer_acquire();
if (!GCNamePool)
GCNamePool = new StringPool();
if (!GCNames)
GCNames = new DenseMap<const Function*,PooledStringPtr>();
(*GCNames)[this] = GCNamePool->intern(Str);
+ if (llvm_is_multithreaded()) GCLock->writer_release();
}
void Function::clearGC() {
+ if (llvm_is_multithreaded()) GCLock->writer_acquire();
if (GCNames) {
GCNames->erase(this);
if (GCNames->empty()) {
}
}
}
+ if (llvm_is_multithreaded()) GCLock->writer_release();
}
/// copyAttributesFrom - copy all additional attributes (those not needed to
#include "llvm/Intrinsics.gen"
#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN
+ /// hasAddressTaken - returns true if there are any uses of this function
+ /// other than direct calls or invokes to it.
+bool Function::hasAddressTaken() const {
+ for (Value::use_const_iterator I = use_begin(), E = use_end(); I != E; ++I) {
+ if (I.getOperandNo() != 0 ||
+ (!isa<CallInst>(*I) && !isa<InvokeInst>(*I)))
+ return true;
+ }
+ return false;
+}
+
// vim: sw=2 ai