aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore/Function.cpp
diff options
context:
space:
mode:
authorGordon Henriksen <gordonhenriksen@mac.com>2007-12-10 03:18:06 +0000
committerGordon Henriksen <gordonhenriksen@mac.com>2007-12-10 03:18:06 +0000
commit80a75bfae980df96f969f1c05b0c4a80ce975240 (patch)
treeb17b6964d35ffeaa66a62793e9cb123e67b69310 /lib/VMCore/Function.cpp
parentafba8fe662d65b25b4baf46bb26cc18e1f9cc0a5 (diff)
downloadexternal_llvm-80a75bfae980df96f969f1c05b0c4a80ce975240.zip
external_llvm-80a75bfae980df96f969f1c05b0c4a80ce975240.tar.gz
external_llvm-80a75bfae980df96f969f1c05b0c4a80ce975240.tar.bz2
Adding a collector name attribute to Function in the IR. These
methods are new to Function: bool hasCollector() const; const std::string &getCollector() const; void setCollector(const std::string &); void clearCollector(); The assembly representation is as such: define void @f() gc "shadow-stack" { ... The implementation uses an on-the-side table to map Functions to collector names, such that there is no overhead. A StringPool is further used to unique collector names, which are extremely likely to be unique per process. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44769 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Function.cpp')
-rw-r--r--lib/VMCore/Function.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp
index 04db3aa..18effea 100644
--- a/lib/VMCore/Function.cpp
+++ b/lib/VMCore/Function.cpp
@@ -17,8 +17,10 @@
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/Support/LeakDetector.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/StringPool.h"
#include "SymbolTableListTraitsImpl.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringExtras.h"
using namespace llvm;
@@ -297,6 +299,9 @@ Function::~Function() {
// Drop our reference to the parameter attributes, if any.
if (ParamAttrs)
ParamAttrs->dropRef();
+
+ // Remove the function from the on-the-side collector table.
+ clearCollector();
}
void Function::BuildLazyArguments() const {
@@ -379,6 +384,40 @@ void Function::dropAllReferences() {
BasicBlocks.clear(); // Delete all basic blocks...
}
+// Maintain the collector name for each function in an on-the-side table. This
+// saves allocating an additional word in Function for programs which do not use
+// GC (i.e., most programs) at the cost of increased overhead for clients which
+// do use GC.
+static DenseMap<const Function*,PooledStringPtr> *CollectorNames;
+static StringPool *CollectorNamePool;
+
+bool Function::hasCollector() const {
+ return CollectorNames && CollectorNames->count(this);
+}
+
+const char *Function::getCollector() const {
+ assert(hasCollector() && "Function has no collector");
+ return *(*CollectorNames)[this];
+}
+
+void Function::setCollector(const char *Str) {
+ if (!CollectorNamePool)
+ CollectorNamePool = new StringPool();
+ if (!CollectorNames)
+ CollectorNames = new DenseMap<const Function*,PooledStringPtr>();
+ (*CollectorNames)[this] = CollectorNamePool->intern(Str);
+}
+
+void Function::clearCollector() {
+ if (CollectorNames) {
+ CollectorNames->erase(this);
+ if (CollectorNames->empty()) {
+ delete CollectorNames;
+ CollectorNames = 0;
+ }
+ }
+}
+
/// getIntrinsicID - This method returns the ID number of the specified
/// function, or Intrinsic::not_intrinsic if the function is not an
/// intrinsic, or if the pointer is null. This value is always defined to be