summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Utils
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-08 19:26:32 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-04-08 19:26:32 +0000
commitbb2c3e199e9e95ff7b07efb084b94960b76e6556 (patch)
tree7e6d08809e93196a4fd04919e4b32ec6fb828db2 /llvm/lib/Transforms/Utils
parent41725a1e7a1666374a5f63b837d7c22fe503ba22 (diff)
downloadbcm5719-llvm-bb2c3e199e9e95ff7b07efb084b94960b76e6556.tar.gz
bcm5719-llvm-bb2c3e199e9e95ff7b07efb084b94960b76e6556.zip
ValueMapper: Extract llvm::RemapFunction from IRMover.cpp, NFC
Strip out the remapping parts of IRLinker::linkFunctionBody and put them in ValueMapper.cpp under the name Mapper::remapFunction (with a top-level entry-point llvm::RemapFunction). This is a nice cleanup on its own since it puts the remapping code together and shares a single Mapper context for the entire IRLinker::linkFunctionBody Call. Besides that, this will make it easier to break the co-recursion between IRMover.cpp and ValueMapper.cpp in follow ups. llvm-svn: 265835
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 5eebccdd7c8..76875ec7385 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -80,6 +80,7 @@ public:
Value *mapValue(const Value *V);
void remapInstruction(Instruction *I);
+ void remapFunction(Function &F);
/// Map metadata.
///
@@ -801,3 +802,32 @@ void Mapper::remapInstruction(Instruction *I) {
}
I->mutateType(TypeMapper->remapType(I->getType()));
}
+
+void llvm::RemapFunction(Function &F, ValueToValueMapTy &VM, RemapFlags Flags,
+ ValueMapTypeRemapper *TypeMapper,
+ ValueMaterializer *Materializer) {
+ Mapper(VM, Flags, TypeMapper, Materializer).remapFunction(F);
+}
+
+void Mapper::remapFunction(Function &F) {
+ // Remap the operands.
+ for (Use &Op : F.operands())
+ if (Op)
+ Op = mapValue(Op);
+
+ // Remap the metadata attachments.
+ SmallVector<std::pair<unsigned, MDNode *>, 8> MDs;
+ F.getAllMetadata(MDs);
+ for (const auto &I : MDs)
+ F.setMetadata(I.first, cast_or_null<MDNode>(mapMetadata(I.second)));
+
+ // Remap the argument types.
+ if (TypeMapper)
+ for (Argument &A : F.args())
+ A.mutateType(TypeMapper->remapType(A.getType()));
+
+ // Remap the instructions.
+ for (BasicBlock &BB : F)
+ for (Instruction &I : BB)
+ remapInstruction(&I);
+}
OpenPOWER on IntegriCloud