summaryrefslogtreecommitdiff
path: root/lib/Target/SparcV9/InternalGlobalMapper.cpp
diff options
context:
space:
mode:
authorBrian Gaeke <gaeke@uiuc.edu>2004-06-03 05:03:37 +0000
committerBrian Gaeke <gaeke@uiuc.edu>2004-06-03 05:03:37 +0000
commit8c4174a0a73e5f8716f6741f39d69f726c7df6cb (patch)
tree015339fab5528144bd11bc671ef6cc33d7b1f3b5 /lib/Target/SparcV9/InternalGlobalMapper.cpp
parentf36b5f0fb6867c4dfbfbc6f966eee55039d3b441 (diff)
downloadllvm-8c4174a0a73e5f8716f6741f39d69f726c7df6cb.tar.gz
llvm-8c4174a0a73e5f8716f6741f39d69f726c7df6cb.tar.bz2
llvm-8c4174a0a73e5f8716f6741f39d69f726c7df6cb.tar.xz
Add new internal-global-symbol mapping info pass... may its life be short
and sweet. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13983 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target/SparcV9/InternalGlobalMapper.cpp')
-rw-r--r--lib/Target/SparcV9/InternalGlobalMapper.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/lib/Target/SparcV9/InternalGlobalMapper.cpp b/lib/Target/SparcV9/InternalGlobalMapper.cpp
new file mode 100644
index 0000000000..8df87fd000
--- /dev/null
+++ b/lib/Target/SparcV9/InternalGlobalMapper.cpp
@@ -0,0 +1,80 @@
+//===-- InternalGlobalMapper.cpp - Mapping Info for Internal Globals ------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// InternalGlobalMapper is a pass that helps the runtime trace optimizer map
+// the names of internal GlobalValues (which may have mangled,
+// unreconstructible names in the executable) to pointers. If the name mangler
+// is changed at some point in the future to allow its results to be
+// reconstructible (for instance, by making the type mangling symbolic instead
+// of using a UniqueID) this pass should probably be phased out.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Constants.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Type.h"
+#include "llvm/DerivedTypes.h"
+using namespace llvm;
+
+namespace llvm {
+
+typedef std::vector<Constant *> GVVectorTy;
+
+class InternalGlobalMapper : public Pass {
+public:
+ bool run (Module &M);
+};
+
+Pass *llvm::createInternalGlobalMapperPass () {
+ return new InternalGlobalMapper ();
+}
+
+static void maybeAddInternalValueToVector (GVVectorTy &Vector, GlobalValue &GV){
+ // If it's a GlobalValue with internal linkage and a name (i.e. it's going to
+ // be mangled), then put the GV, casted to sbyte*, in the vector. Otherwise
+ // add a null.
+ if (GV.hasInternalLinkage () && GV.hasName ())
+ Vector.push_back (ConstantExpr::getCast
+ (ConstantPointerRef::get (&GV), PointerType::get (Type::SByteTy)));
+ else
+ Vector.push_back (ConstantPointerNull::get (PointerType::get
+ (Type::SByteTy)));
+}
+
+bool InternalGlobalMapper::run (Module &M) {
+ GVVectorTy gvvector;
+
+ // Populate the vector with internal global values and their names.
+ for (Module::giterator i = M.gbegin (), e = M.gend (); i != e; ++i)
+ maybeAddInternalValueToVector (gvvector, *i);
+ for (Module::iterator i = M.begin (), e = M.end (); i != e; ++i)
+ maybeAddInternalValueToVector (gvvector, *i);
+
+ // Convert the vector to a constant struct of type {Size, [Size x sbyte*]}.
+ ArrayType *ATy = ArrayType::get (PointerType::get (Type::SByteTy),
+ gvvector.size ());
+ std::vector<const Type *> FieldTypes;
+ FieldTypes.push_back (Type::UIntTy);
+ FieldTypes.push_back (ATy);
+ StructType *STy = StructType::get (FieldTypes);
+ std::vector<Constant *> FieldValues;
+ FieldValues.push_back (ConstantUInt::get (Type::UIntTy, gvvector.size ()));
+ FieldValues.push_back (ConstantArray::get (ATy, gvvector));
+
+ // Add the constant struct to M as an external global symbol named
+ // "_llvm_internalGlobals".
+ new GlobalVariable (STy, true, GlobalValue::ExternalLinkage,
+ ConstantStruct::get (STy, FieldValues),
+ "_llvm_internalGlobals", &M);
+
+ return true; // Module was modified.
+}
+
+} // end namespace llvm