summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/Function.cpp
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2015-05-13 15:13:45 +0000
committerDiego Novillo <dnovillo@google.com>2015-05-13 15:13:45 +0000
commit2567f3d0fb1f2812f99111ecd67d228ccae42c49 (patch)
tree365e1e894c459f612277ef5da02f2f53ecd2d384 /llvm/lib/IR/Function.cpp
parentbbcf75e59eaa027251e060043067257c64a866ba (diff)
downloadbcm5719-llvm-2567f3d0fb1f2812f99111ecd67d228ccae42c49.tar.gz
bcm5719-llvm-2567f3d0fb1f2812f99111ecd67d228ccae42c49.zip
Add function entry count metadata.
Summary: This adds three Function methods to handle function entry counts: setEntryCount() and getEntryCount(). Entry counts are stored under the MD_prof metadata node with the name "function_entry_count". They are unsigned 64 bit values set by profilers (instrumentation and sample profiler changes coming up). Added documentation for new profile metadata and tests. Reviewers: dexonsmith, bogner Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D9628 llvm-svn: 237260
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r--llvm/lib/IR/Function.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index f312f711c60..a5d4d1c4b1e 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -19,10 +19,13 @@
#include "llvm/ADT/StringExtras.h"
#include "llvm/CodeGen/ValueTypes.h"
#include "llvm/IR/CallSite.h"
+#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/LLVMContext.h"
+#include "llvm/IR/MDBuilder.h"
+#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/RWMutex.h"
@@ -986,3 +989,19 @@ void llvm::overrideFunctionAttribute(StringRef Kind, StringRef Value,
Attrs = Attrs.addAttribute(Ctx, AttributeSet::FunctionIndex, Kind, Value);
F.setAttributes(Attrs);
}
+
+void Function::setEntryCount(uint64_t Count) {
+ MDBuilder MDB(getContext());
+ setMetadata(LLVMContext::MD_prof, MDB.createFunctionEntryCount(Count));
+}
+
+Optional<uint64_t> Function::getEntryCount() const {
+ MDNode *MD = getMetadata(LLVMContext::MD_prof);
+ if (MD && MD->getOperand(0))
+ if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0)))
+ if (MDS->getString().equals("function_entry_count")) {
+ ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1));
+ return CI->getValue().getZExtValue();
+ }
+ return None;
+}
OpenPOWER on IntegriCloud