diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h index d3497716ca844..02232f6dc2f62 100644 --- a/llvm/include/llvm/IR/Function.h +++ b/llvm/include/llvm/IR/Function.h @@ -144,7 +144,7 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node { void clearArguments(); - void deleteBodyImpl(bool ShouldDrop); + void deleteBodyImpl(bool ShouldDrop, bool PreserveMetadata); /// Function ctor - If the (optional) Module argument is specified, the /// function is automatically inserted into the end of the function list for @@ -727,8 +727,8 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node { /// deleteBody - This method deletes the body of the function, and converts /// the linkage to external. /// - void deleteBody() { - deleteBodyImpl(/*ShouldDrop=*/false); + void deleteBody(bool PreserveMetadata = false) { + deleteBodyImpl(/*ShouldDrop=*/false, PreserveMetadata); setLinkage(ExternalLinkage); } @@ -982,7 +982,7 @@ class LLVM_ABI Function : public GlobalObject, public ilist_node { /// including any contained basic blocks. /// void dropAllReferences() { - deleteBodyImpl(/*ShouldDrop=*/true); + deleteBodyImpl(/*ShouldDrop=*/true, /*PreserveMetadata=*/false); } /// hasAddressTaken - returns true if there are any uses of this function diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp index fc067459dcba3..d50a711b83fa9 100644 --- a/llvm/lib/IR/Function.cpp +++ b/llvm/lib/IR/Function.cpp @@ -600,7 +600,7 @@ void Function::stealArgumentListFrom(Function &Src) { Src.setValueSubclassData(Src.getSubclassDataFromValue() | (1 << 0)); } -void Function::deleteBodyImpl(bool ShouldDrop) { +void Function::deleteBodyImpl(bool ShouldDrop, bool PreserveMetadata) { setIsMaterializable(false); for (BasicBlock &BB : *this) @@ -627,7 +627,8 @@ void Function::deleteBodyImpl(bool ShouldDrop) { } // Metadata is stored in a side-table. - clearMetadata(); + if (!PreserveMetadata) + clearMetadata(); } void Function::addAttributeAtIndex(unsigned i, Attribute Attr) {