[PATCH] D15003: Interface to attach maximum function count from PGO to module as module flags.

Easwaran Raman via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 25 16:35:22 PST 2015


eraman created this revision.
eraman added a reviewer: llvm-commits.
eraman added subscribers: davidxl, dnovillo.
eraman set the repository for this revision to rL LLVM.

This provides interface to get and set maximum function counts to Module. This would allow things like determination of function hotness. The actual setting of this max function count will have to be done in clang.

Repository:
  rL LLVM

http://reviews.llvm.org/D15003

Files:
  include/llvm/IR/Module.h
  lib/IR/Module.cpp

Index: lib/IR/Module.cpp
===================================================================
--- lib/IR/Module.cpp
+++ lib/IR/Module.cpp
@@ -491,3 +491,14 @@
 void Module::setPICLevel(PICLevel::Level PL) {
   addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL);
 }
+
+void Module::setMaximumFunctionCount(uint64_t Count) {
+  addModuleFlag(ModFlagBehavior::Error, "MaxFunctionCount", Count);
+}
+
+Optional<uint64_t> Module::getMaximumFunctionCount() {
+  auto *Val =
+      cast_or_null<ConstantAsMetadata>(getModuleFlag("MaxFunctionCount"));
+  if (!Val) return None;
+  return cast<ConstantInt>(Val->getValue())->getZExtValue();
+}
Index: include/llvm/IR/Module.h
===================================================================
--- include/llvm/IR/Module.h
+++ include/llvm/IR/Module.h
@@ -15,6 +15,8 @@
 #ifndef LLVM_IR_MODULE_H
 #define LLVM_IR_MODULE_H
 
+#include <system_error>
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/iterator_range.h"
 #include "llvm/IR/Comdat.h"
 #include "llvm/IR/DataLayout.h"
@@ -25,7 +27,6 @@
 #include "llvm/Support/CBindingWrapping.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/DataTypes.h"
-#include <system_error>
 
 namespace llvm {
 class FunctionType;
@@ -639,6 +640,16 @@
   /// \brief Set the PIC level (small or large model)
   void setPICLevel(PICLevel::Level PL);
 /// @}
+
+  /// @name Utility functions for querying and setting PGO counts
+  /// @{
+
+  /// \brief Set maximum function count in PGO mode
+  void setMaximumFunctionCount(uint64_t);
+
+  /// \brief Returns maximum function count in PGO mode
+  Optional<uint64_t> getMaximumFunctionCount();
+  /// @}
 };
 
 /// An raw_ostream inserter for modules.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15003.41196.patch
Type: text/x-patch
Size: 1693 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20151126/f1a63acf/attachment.bin>


More information about the llvm-commits mailing list