[llvm] r229744 - IR: Add MDCompositeTypeBase::replace*()
Duncan P. N. Exon Smith
dexonsmith at apple.com
Wed Feb 18 12:47:53 PST 2015
Author: dexonsmith
Date: Wed Feb 18 14:47:52 2015
New Revision: 229744
URL: http://llvm.org/viewvc/llvm-project?rev=229744&view=rev
Log:
IR: Add MDCompositeTypeBase::replace*()
Add `replaceElements()`, `replaceVTableHolder()`, and
`replaceTemplateParams()` to `MDCompositeTypeBase`. Included an
assertion in `replaceElements()` to match the one in
`DICompositeType::replaceArrays()`.
Modified:
llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
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=229744&r1=229743&r2=229744&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Wed Feb 18 14:47:52 2015
@@ -576,6 +576,29 @@ public:
MDString *getRawIdentifier() const { return getOperandAs<MDString>(7); }
+ /// \brief Replace operands.
+ ///
+ /// If this \a isUniqued() and not \a isResolved(), on a uniquing collision
+ /// this will be RAUW'ed and deleted. Use a \a TrackingMDRef to keep track
+ /// of its movement if necessary.
+ /// @{
+ void replaceElements(MDTuple *Elements) {
+#ifndef NDEBUG
+ if (auto *Old = cast_or_null<MDTuple>(getElements()))
+ for (const auto &Op : Old->operands())
+ assert(std::find(Elements->op_begin(), Elements->op_end(), Op) &&
+ "Lost a member during member list replacement");
+#endif
+ replaceOperandWith(4, Elements);
+ }
+ void replaceVTableHolder(Metadata *VTableHolder) {
+ replaceOperandWith(5, VTableHolder);
+ }
+ void replaceTemplateParams(MDTuple *TemplateParams) {
+ replaceOperandWith(6, TemplateParams);
+ }
+ /// @}
+
static bool classof(const Metadata *MD) {
return MD->getMetadataID() == MDCompositeTypeKind ||
MD->getMetadataID() == MDSubroutineTypeKind;
Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=229744&r1=229743&r2=229744&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Wed Feb 18 14:47:52 2015
@@ -897,6 +897,47 @@ TEST_F(MDCompositeTypeTest, get) {
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
}
+TEST_F(MDCompositeTypeTest, replaceOperands) {
+ unsigned Tag = dwarf::DW_TAG_structure_type;
+ StringRef Name = "some name";
+ Metadata *File = MDTuple::getDistinct(Context, None);
+ unsigned Line = 1;
+ Metadata *Scope = MDTuple::getDistinct(Context, None);
+ Metadata *BaseType = MDTuple::getDistinct(Context, None);
+ unsigned SizeInBits = 2;
+ unsigned AlignInBits = 3;
+ unsigned OffsetInBits = 4;
+ unsigned Flags = 5;
+ unsigned RuntimeLang = 6;
+ StringRef Identifier = "some id";
+
+ auto *N = MDCompositeType::get(Context, Tag, Name, File, Line, Scope,
+ BaseType, SizeInBits, AlignInBits,
+ OffsetInBits, Flags, nullptr, RuntimeLang,
+ nullptr, nullptr, Identifier);
+
+ auto *Elements = MDTuple::getDistinct(Context, None);
+ EXPECT_EQ(nullptr, N->getElements());
+ N->replaceElements(Elements);
+ EXPECT_EQ(Elements, N->getElements());
+ N->replaceElements(nullptr);
+ EXPECT_EQ(nullptr, N->getElements());
+
+ auto *VTableHolder = MDTuple::getDistinct(Context, None);
+ EXPECT_EQ(nullptr, N->getVTableHolder());
+ N->replaceVTableHolder(VTableHolder);
+ EXPECT_EQ(VTableHolder, N->getVTableHolder());
+ N->replaceVTableHolder(nullptr);
+ EXPECT_EQ(nullptr, N->getVTableHolder());
+
+ auto *TemplateParams = MDTuple::getDistinct(Context, None);
+ EXPECT_EQ(nullptr, N->getTemplateParams());
+ N->replaceTemplateParams(TemplateParams);
+ EXPECT_EQ(TemplateParams, N->getTemplateParams());
+ N->replaceTemplateParams(nullptr);
+ EXPECT_EQ(nullptr, N->getTemplateParams());
+}
+
typedef MetadataTest MDSubroutineTypeTest;
TEST_F(MDSubroutineTypeTest, get) {
More information about the llvm-commits
mailing list