- unsigned PDData = getSubclassDataFromValue();
- LLVMContextImpl::PrologueDataMapTy &PDMap = getContext().pImpl->PrologueDataMap;
- ReturnInst *&PDHolder = PDMap[this];
- if (PrologueData) {
- if (PDHolder)
- PDHolder->setOperand(0, PrologueData);
- else
- PDHolder = ReturnInst::Create(getContext(), PrologueData);
- PDData |= (1<<2);
+ unsigned SCData = getSubclassDataFromValue();
+ SCData = setFunctionData(this, getContext().pImpl->PrologueDataMap,
+ PrologueData, SCData, /*Bit=*/2);
+ setValueSubclassData(SCData);
+}
+
+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;
+}
+
+void Function::setPersonalityFn(Constant *C) {
+ if (!C) {
+ if (hasPersonalityFn()) {
+ // Note, the num operands is used to compute the offset of the operand, so
+ // the order here matters. Clearing the operand then clearing the num
+ // operands ensures we have the correct offset to the operand.
+ Op<0>().set(nullptr);
+ setFunctionNumOperands(0);
+ }