From: Easwaran Raman Date: Thu, 3 Dec 2015 20:57:37 +0000 (+0000) Subject: Interface to attach maximum function count from PGO to module as module flags. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=52c4f7de0934eef2019b77a14dc94415459d3fc1;p=oota-llvm.git Interface to attach maximum function count from PGO to module as module flags. 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 the frontend. Differential Revision: http://reviews.llvm.org/D15003 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254647 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/IR/Module.h b/include/llvm/IR/Module.h index 4e99c425673..6cf75e747e0 100644 --- a/include/llvm/IR/Module.h +++ b/include/llvm/IR/Module.h @@ -15,6 +15,7 @@ #ifndef LLVM_IR_MODULE_H #define LLVM_IR_MODULE_H +#include "llvm/ADT/Optional.h" #include "llvm/ADT/iterator_range.h" #include "llvm/IR/Comdat.h" #include "llvm/IR/DataLayout.h" @@ -639,6 +640,16 @@ public: /// \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 getMaximumFunctionCount(); + /// @} }; /// An raw_ostream inserter for modules. diff --git a/lib/IR/Module.cpp b/lib/IR/Module.cpp index 2b9adad44ba..2acd9db210d 100644 --- a/lib/IR/Module.cpp +++ b/lib/IR/Module.cpp @@ -491,3 +491,15 @@ PICLevel::Level Module::getPICLevel() const { void Module::setPICLevel(PICLevel::Level PL) { addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL); } + +void Module::setMaximumFunctionCount(uint64_t Count) { + addModuleFlag(ModFlagBehavior::Error, "MaxFunctionCount", Count); +} + +Optional Module::getMaximumFunctionCount() { + auto *Val = + cast_or_null(getModuleFlag("MaxFunctionCount")); + if (!Val) + return None; + return cast(Val->getValue())->getZExtValue(); +}