Fix getMDs() interface such that it does not expose implementation details.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@84885 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Devang Patel
2009-10-22 18:55:16 +00:00
parent b5681b2293
commit f61b2371c8
5 changed files with 35 additions and 26 deletions

View File

@@ -254,7 +254,7 @@ public:
MDNode *getMD(unsigned Kind, const Instruction *Inst); MDNode *getMD(unsigned Kind, const Instruction *Inst);
/// getMDs - Get the metadata attached to an Instruction. /// getMDs - Get the metadata attached to an Instruction.
const MDMapTy *getMDs(const Instruction *Inst); void getMDs(const Instruction *Inst, SmallVectorImpl<MDPairTy> &MDs) const;
/// addMD - Attach the metadata of given kind to an Instruction. /// addMD - Attach the metadata of given kind to an Instruction.
void addMD(unsigned Kind, MDNode *Node, Instruction *Inst); void addMD(unsigned Kind, MDNode *Node, Instruction *Inst);

View File

@@ -561,14 +561,16 @@ static void WriteMetadataAttachment(const Function &F,
// Write metadata attachments // Write metadata attachments
// METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]] // METADATA_ATTACHMENT - [m x [value, [n x [id, mdnode]]]
MetadataContext &TheMetadata = F.getContext().getMetadata(); MetadataContext &TheMetadata = F.getContext().getMetadata();
typedef SmallVector<std::pair<unsigned, TrackingVH<MDNode> >, 2> MDMapTy;
MDMapTy MDs;
for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB) for (Function::const_iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); for (BasicBlock::const_iterator I = BB->begin(), E = BB->end();
I != E; ++I) { I != E; ++I) {
const MetadataContext::MDMapTy *P = TheMetadata.getMDs(I); MDs.clear();
if (!P) continue; TheMetadata.getMDs(I, MDs);
bool RecordedInstruction = false; bool RecordedInstruction = false;
for (MetadataContext::MDMapTy::const_iterator PI = P->begin(), for (MDMapTy::const_iterator PI = MDs.begin(), PE = MDs.end();
PE = P->end(); PI != PE; ++PI) { PI != PE; ++PI) {
if (RecordedInstruction == false) { if (RecordedInstruction == false) {
Record.push_back(VE.getInstructionID(I)); Record.push_back(VE.getInstructionID(I));
RecordedInstruction = true; RecordedInstruction = true;

View File

@@ -87,6 +87,8 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
EnumerateType(I->getType()); EnumerateType(I->getType());
MetadataContext &TheMetadata = F->getContext().getMetadata(); MetadataContext &TheMetadata = F->getContext().getMetadata();
typedef SmallVector<std::pair<unsigned, TrackingVH<MDNode> >, 2> MDMapTy;
MDMapTy MDs;
for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB) for (Function::const_iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){ for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E;++I){
for (User::const_op_iterator OI = I->op_begin(), E = I->op_end(); for (User::const_op_iterator OI = I->op_begin(), E = I->op_end();
@@ -99,11 +101,11 @@ ValueEnumerator::ValueEnumerator(const Module *M) {
EnumerateAttributes(II->getAttributes()); EnumerateAttributes(II->getAttributes());
// Enumerate metadata attached with this instruction. // Enumerate metadata attached with this instruction.
const MetadataContext::MDMapTy *MDs = TheMetadata.getMDs(I); MDs.clear();
if (MDs) TheMetadata.getMDs(I, MDs);
for (MetadataContext::MDMapTy::const_iterator MI = MDs->begin(), for (MDMapTy::const_iterator MI = MDs.begin(), ME = MDs.end(); MI != ME;
ME = MDs->end(); MI != ME; ++MI) ++MI)
EnumerateMetadata(MI->second); EnumerateMetadata(MI->second);
} }
} }

View File

@@ -680,6 +680,8 @@ void SlotTracker::processFunction() {
ST_DEBUG("Inserting Instructions:\n"); ST_DEBUG("Inserting Instructions:\n");
MetadataContext &TheMetadata = TheFunction->getContext().getMetadata(); MetadataContext &TheMetadata = TheFunction->getContext().getMetadata();
typedef SmallVector<std::pair<unsigned, TrackingVH<MDNode> >, 2> MDMapTy;
MDMapTy MDs;
// Add all of the basic blocks and instructions with no names. // Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(), for (Function::const_iterator BB = TheFunction->begin(),
@@ -696,11 +698,11 @@ void SlotTracker::processFunction() {
CreateMetadataSlot(N); CreateMetadataSlot(N);
// Process metadata attached with this instruction. // Process metadata attached with this instruction.
const MetadataContext::MDMapTy *MDs = TheMetadata.getMDs(I); MDs.clear();
if (MDs) TheMetadata.getMDs(I, MDs);
for (MetadataContext::MDMapTy::const_iterator MI = MDs->begin(), for (MDMapTy::const_iterator MI = MDs.begin(), ME = MDs.end(); MI != ME;
ME = MDs->end(); MI != ME; ++MI) ++MI)
CreateMetadataSlot(MI->second); CreateMetadataSlot(MI->second);
} }
} }
@@ -2034,12 +2036,13 @@ void AssemblyWriter::printInstruction(const Instruction &I) {
// Print Metadata info // Print Metadata info
if (!MDNames.empty()) { if (!MDNames.empty()) {
MetadataContext &TheMetadata = I.getContext().getMetadata(); MetadataContext &TheMetadata = I.getContext().getMetadata();
const MetadataContext::MDMapTy *MDMap = TheMetadata.getMDs(&I); typedef SmallVector<std::pair<unsigned, TrackingVH<MDNode> >, 2> MDMapTy;
if (MDMap) MDMapTy MDs;
for (MetadataContext::MDMapTy::const_iterator MI = MDMap->begin(), TheMetadata.getMDs(&I, MDs);
ME = MDMap->end(); MI != ME; ++MI) for (MDMapTy::const_iterator MI = MDs.begin(), ME = MDs.end(); MI != ME;
Out << ", !" << MDNames[MI->first] ++MI)
<< " !" << Machine.getMetadataSlot(MI->second); Out << ", !" << MDNames[MI->first]
<< " !" << Machine.getMetadataSlot(MI->second);
} }
printInfoComment(I); printInfoComment(I);
} }

View File

@@ -294,13 +294,15 @@ MDNode *MetadataContext::getMD(unsigned MDKind, const Instruction *Inst) {
} }
/// getMDs - Get the metadata attached to an Instruction. /// getMDs - Get the metadata attached to an Instruction.
const MetadataContext::MDMapTy * void MetadataContext::
MetadataContext::getMDs(const Instruction *Inst) { getMDs(const Instruction *Inst, SmallVectorImpl<MDPairTy> &MDs) const {
MDStoreTy::iterator I = MetadataStore.find(Inst); MDStoreTy::iterator I = MetadataStore.find(Inst);
if (I == MetadataStore.end()) if (I == MetadataStore.end())
return NULL; return;
for (MDMapTy::iterator MI = I->second.begin(), ME = I->second.end();
return &I->second; MI != ME; ++MI)
MDs.push_back(std::make_pair(MI->first, MI->second));
std::sort(MDs.begin(), MDs.end());
} }
/// getHandlerNames - Populate client supplied smallvector using custome /// getHandlerNames - Populate client supplied smallvector using custome