[llvm] r229742 - IR: Add MDSubprogram::replaceFunction()
Duncan P. N. Exon Smith
dexonsmith at apple.com
Wed Feb 18 12:32:57 PST 2015
Author: dexonsmith
Date: Wed Feb 18 14:32:57 2015
New Revision: 229742
URL: http://llvm.org/viewvc/llvm-project?rev=229742&view=rev
Log:
IR: Add MDSubprogram::replaceFunction()
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
llvm/trunk/lib/IR/DebugInfoMetadata.cpp
llvm/trunk/unittests/IR/MetadataTest.cpp
Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=229742&r1=229741&r2=229742&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Wed Feb 18 14:32:57 2015
@@ -968,6 +968,17 @@ public:
Metadata *getDeclaration() const { return getOperand(9); }
Metadata *getVariables() const { return getOperand(10); }
+ /// \brief Replace the function.
+ ///
+ /// If \a isUniqued() and not \a isResolved(), this could node will be
+ /// RAUW'ed and deleted out from under the caller. Use a \a TrackingMDRef if
+ /// that's a problem.
+ /// @{
+ void replaceFunction(Function *F);
+ void replaceFunction(ConstantAsMetadata *MD) { replaceOperandWith(7, MD); }
+ void replaceFunction(std::nullptr_t) { replaceOperandWith(7, nullptr); }
+ /// @}
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDSubprogramKind;
}
Modified: llvm/trunk/lib/IR/DebugInfoMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/DebugInfoMetadata.cpp?rev=229742&r1=229741&r2=229742&view=diff
==============================================================================
--- llvm/trunk/lib/IR/DebugInfoMetadata.cpp (original)
+++ llvm/trunk/lib/IR/DebugInfoMetadata.cpp Wed Feb 18 14:32:57 2015
@@ -14,6 +14,7 @@
#include "llvm/IR/DebugInfoMetadata.h"
#include "LLVMContextImpl.h"
#include "MetadataImpl.h"
+#include "llvm/IR/Function.h"
using namespace llvm;
@@ -264,6 +265,11 @@ MDSubprogram *MDSubprogram::getImpl(
Ops);
}
+void MDSubprogram::replaceFunction(Function *F) {
+ replaceFunction(F ? ConstantAsMetadata::get(F)
+ : static_cast<ConstantAsMetadata *>(nullptr));
+}
+
MDLexicalBlock *MDLexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
Metadata *File, unsigned Line,
unsigned Column, StorageType Storage,
Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=229742&r1=229741&r2=229742&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Wed Feb 18 14:32:57 2015
@@ -10,6 +10,7 @@
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
@@ -1189,6 +1190,42 @@ TEST_F(MDSubprogramTest, get) {
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
+TEST_F(MDSubprogramTest, replaceFunction) {
+ Metadata *Scope = MDTuple::getDistinct(Context, None);
+ StringRef Name = "name";
+ StringRef LinkageName = "linkage";
+ Metadata *File = MDTuple::getDistinct(Context, None);
+ unsigned Line = 2;
+ Metadata *Type = MDTuple::getDistinct(Context, None);
+ bool IsLocalToUnit = false;
+ bool IsDefinition = true;
+ unsigned ScopeLine = 3;
+ Metadata *ContainingType = MDTuple::getDistinct(Context, None);
+ unsigned Virtuality = 4;
+ unsigned VirtualIndex = 5;
+ unsigned Flags = 6;
+ bool IsOptimized = false;
+ Metadata *TemplateParams = MDTuple::getDistinct(Context, None);
+ Metadata *Declaration = MDTuple::getDistinct(Context, None);
+ Metadata *Variables = MDTuple::getDistinct(Context, None);
+
+ auto *N = MDSubprogram::get(
+ Context, Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
+ IsDefinition, ScopeLine, ContainingType, Virtuality, VirtualIndex, Flags,
+ IsOptimized, nullptr, TemplateParams, Declaration, Variables);
+
+ EXPECT_EQ(nullptr, N->getFunction());
+
+ std::unique_ptr<Function> F(
+ Function::Create(FunctionType::get(Type::getVoidTy(Context), false),
+ GlobalValue::ExternalLinkage));
+ N->replaceFunction(F.get());
+ EXPECT_EQ(ConstantAsMetadata::get(F.get()), N->getFunction());
+
+ N->replaceFunction(nullptr);
+ EXPECT_EQ(nullptr, N->getFunction());
+}
+
typedef MetadataTest MDLexicalBlockTest;
TEST_F(MDLexicalBlockTest, get) {
More information about the llvm-commits
mailing list