mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-14 03:50:48 +00:00

Instead of cloning distinct `MDNode`s when linking in a module, just move them over. The module linker destroys the source module, so the old node would otherwise just be leaked on the context. Create the new node in place. This also reduces the number of cloned uniqued nodes (since it's less likely their operands have changed). This mapping strategy is only correct when we're discarding the source, so the linker turns it on via a ValueMapper flag, `RF_MoveDistinctMDs`. There's nothing observable in terms of `llvm-link` output here: the linked module should be semantically identical. I'll be adding more 'distinct' nodes to the debug info metadata graph in order to break uniquing cycles, so the benefits of this will partly come in future commits. However, we should get some gains immediately, since we have a fair number of 'distinct' `DILocation`s being linked in. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243883 91177308-0d34-0410-b5e6-96231b3b80d8
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
//===- ValueMapper.cpp - Unit tests for ValueMapper -----------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
#include "llvm/IR/Metadata.h"
|
|
#include "llvm/Transforms/Utils/ValueMapper.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace llvm;
|
|
|
|
namespace {
|
|
|
|
TEST(ValueMapperTest, MapMetadataUnresolved) {
|
|
LLVMContext Context;
|
|
TempMDTuple T = MDTuple::getTemporary(Context, None);
|
|
|
|
ValueToValueMapTy VM;
|
|
EXPECT_EQ(T.get(), MapMetadata(T.get(), VM, RF_NoModuleLevelChanges));
|
|
}
|
|
|
|
TEST(ValueMapperTest, MapMetadataDistinct) {
|
|
LLVMContext Context;
|
|
auto *D = MDTuple::getDistinct(Context, None);
|
|
|
|
{
|
|
// The node should be cloned.
|
|
ValueToValueMapTy VM;
|
|
EXPECT_NE(D, MapMetadata(D, VM, RF_None));
|
|
}
|
|
{
|
|
// The node should be moved.
|
|
ValueToValueMapTy VM;
|
|
EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
|
|
}
|
|
}
|
|
|
|
TEST(ValueMapperTest, MapMetadataDistinctOperands) {
|
|
LLVMContext Context;
|
|
Metadata *Old = MDTuple::getDistinct(Context, None);
|
|
auto *D = MDTuple::getDistinct(Context, Old);
|
|
ASSERT_EQ(Old, D->getOperand(0));
|
|
|
|
Metadata *New = MDTuple::getDistinct(Context, None);
|
|
ValueToValueMapTy VM;
|
|
VM.MD()[Old].reset(New);
|
|
|
|
// Make sure operands are updated.
|
|
EXPECT_EQ(D, MapMetadata(D, VM, RF_MoveDistinctMDs));
|
|
EXPECT_EQ(New, D->getOperand(0));
|
|
}
|
|
|
|
}
|