From 81ebfb18025ac5fcb21b96f78312f75b86ac3bc0 Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Sat, 14 Mar 2015 19:48:31 +0000 Subject: [PATCH] AsmWriter: Split out SlotTracker::processInstructionMetadata(), NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232273 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/AsmWriter.cpp | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index 321c55d0f89..0fcfe23d2a2 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -606,6 +606,9 @@ private: /// Add all of the functions arguments, basic blocks, and instructions. void processFunction(); + /// Add all of the metadata from an instruction. + void processInstructionMetadata(const Instruction &I); + SlotTracker(const SlotTracker &) = delete; void operator=(const SlotTracker &) = delete; }; @@ -715,8 +718,6 @@ void SlotTracker::processFunction() { ST_DEBUG("Inserting Instructions:\n"); - SmallVector, 4> MDForInst; - // Add all of the basic blocks and instructions with no names. for (auto &BB : *TheFunction) { if (!BB.hasName()) @@ -726,17 +727,11 @@ void SlotTracker::processFunction() { if (!I.getType()->isVoidTy() && !I.hasName()) CreateFunctionSlot(&I); - // Intrinsics can directly use metadata. We allow direct calls to any - // llvm.foo function here, because the target may not be linked into the - // optimizer. - if (const CallInst *CI = dyn_cast(&I)) { - if (Function *F = CI->getCalledFunction()) - if (F->isIntrinsic()) - for (auto &Op : I.operands()) - if (auto *V = dyn_cast_or_null(Op)) - if (MDNode *N = dyn_cast(V->getMetadata())) - CreateMetadataSlot(N); + processInstructionMetadata(I); + // We allow direct calls to any llvm.foo function here, because the + // target may not be linked into the optimizer. + if (const CallInst *CI = dyn_cast(&I)) { // Add all the call attributes to the table. AttributeSet Attrs = CI->getAttributes().getFnAttributes(); if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) @@ -747,12 +742,6 @@ void SlotTracker::processFunction() { if (Attrs.hasAttributes(AttributeSet::FunctionIndex)) CreateAttributeSetSlot(Attrs); } - - // Process metadata attached with this instruction. - I.getAllMetadata(MDForInst); - for (auto &MD : MDForInst) - CreateMetadataSlot(MD.second); - MDForInst.clear(); } } @@ -761,6 +750,23 @@ void SlotTracker::processFunction() { ST_DEBUG("end processFunction!\n"); } +void SlotTracker::processInstructionMetadata(const Instruction &I) { + // Process metadata used directly by intrinsics. + if (const CallInst *CI = dyn_cast(&I)) + if (Function *F = CI->getCalledFunction()) + if (F->isIntrinsic()) + for (auto &Op : I.operands()) + if (auto *V = dyn_cast_or_null(Op)) + if (MDNode *N = dyn_cast(V->getMetadata())) + CreateMetadataSlot(N); + + // Process metadata attached to this instruction. + SmallVector, 4> MDs; + I.getAllMetadata(MDs); + for (auto &MD : MDs) + CreateMetadataSlot(MD.second); +} + /// Clean up after incorporating a function. This is the only way to get out of /// the function incorporation state that affects get*Slot/Create*Slot. Function /// incorporation state is indicated by TheFunction != 0.