From 4f2bb50b208bdbe00d66b138874b8c3e4131b8a3 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 25 Mar 2016 05:57:41 +0000 Subject: [PATCH] Add GUID/getGlobalIdentifier() non-static API to global value Summary: These are just helpers calling their static counter part to simplify client code. Reviewers: tejohnson Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18339 From: Mehdi Amini llvm-svn: 264382 --- llvm/include/llvm/IR/GlobalValue.h | 10 +++++++++- llvm/lib/IR/Globals.cpp | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/IR/GlobalValue.h b/llvm/include/llvm/IR/GlobalValue.h index 9d578d4..c6a88e4 100644 --- a/llvm/include/llvm/IR/GlobalValue.h +++ b/llvm/include/llvm/IR/GlobalValue.h @@ -316,10 +316,18 @@ public: GlobalValue::LinkageTypes Linkage, StringRef FileName); + /// Return the modified name for this global value suitable to be + /// used as the key for a global lookup (e.g. profile or ThinLTO). + std::string getGlobalIdentifier(); + /// Return a 64-bit global unique ID constructed from global value name - /// (i.e. returned by getGlobalIdentifier). + /// (i.e. returned by getGlobalIdentifier()). static uint64_t getGUID(StringRef GlobalName) { return MD5Hash(GlobalName); } + /// Return a 64-bit global unique ID constructed from global value name + /// (i.e. returned by getGlobalIdentifier()). + uint64_t getGUID() { return getGUID(getGlobalIdentifier()); } + /// @name Materialization /// Materialization is used to construct functions only as they're needed. /// This diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp index b0d00a4..c96cc67 100644 --- a/llvm/lib/IR/Globals.cpp +++ b/llvm/lib/IR/Globals.cpp @@ -123,6 +123,11 @@ std::string GlobalValue::getGlobalIdentifier(StringRef Name, return NewName; } +std::string GlobalValue::getGlobalIdentifier() { + return getGlobalIdentifier(getName(), getLinkage(), + getParent()->getSourceFileName()); +} + const char *GlobalValue::getSection() const { if (auto *GA = dyn_cast(this)) { // In general we cannot compute this at the IR level, but we try. -- 2.7.4