diff options
Diffstat (limited to 'llvm/lib/IR/Function.cpp')
-rw-r--r-- | llvm/lib/IR/Function.cpp | 19 |
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; +} |