/// ID values are 1 or higher. This ID is set by RegisterMDKind.
typedef unsigned MDKindID;
class Metadata {
/// ID values are 1 or higher. This ID is set by RegisterMDKind.
typedef unsigned MDKindID;
class Metadata {
typedef std::pair<MDKindID, WeakVH> MDPairTy;
typedef SmallVector<MDPairTy, 2> MDMapTy;
typedef std::pair<MDKindID, WeakVH> MDPairTy;
typedef SmallVector<MDPairTy, 2> MDMapTy;
typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
/// MetadataStore - Collection of metadata used in this context.
typedef DenseMap<const Instruction *, MDMapTy> MDStoreTy;
/// MetadataStore - Collection of metadata used in this context.
StringMap<unsigned> MDHandlerNames;
public:
StringMap<unsigned> MDHandlerNames;
public:
/// RegisterMDKind - Register a new metadata kind and return its ID.
/// A metadata kind can be registered only once.
MDKindID RegisterMDKind(const char *Name);
/// RegisterMDKind - Register a new metadata kind and return its ID.
/// A metadata kind can be registered only once.
MDKindID RegisterMDKind(const char *Name);
/// If the metadata is not found then return 0.
MDNode *getMD(MDKindID Kind, const Instruction *Inst);
/// If the metadata is not found then return 0.
MDNode *getMD(MDKindID Kind, const Instruction *Inst);
+ /// getMDs - Get the metadata attached with an Instruction.
+ const MDMapTy *getMDs(const Instruction *Inst);
+
/// setMD - Attach the metadata of given kind with an Instruction.
void setMD(MDKindID Kind, MDNode *Node, Instruction *Inst);
/// setMD - Attach the metadata of given kind with an Instruction.
void setMD(MDKindID Kind, MDNode *Node, Instruction *Inst);
ST_DEBUG("Inserting Instructions:\n");
ST_DEBUG("Inserting Instructions:\n");
+ Metadata &TheMetadata = TheFunction->getContext().getMetadata();
+
// Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(),
E = TheFunction->end(); BB != E; ++BB) {
// Add all of the basic blocks and instructions with no names.
for (Function::const_iterator BB = TheFunction->begin(),
E = TheFunction->end(); BB != E; ++BB) {
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
CreateMetadataSlot(N);
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
if (MDNode *N = dyn_cast_or_null<MDNode>(I->getOperand(i)))
CreateMetadataSlot(N);
+
+ // Process metadata attached with this instruction.
+ const Metadata::MDMapTy *MDs = TheMetadata.getMDs(I);
+ if (MDs)
+ for (Metadata::MDMapTy::const_iterator MI = MDs->begin(),
+ ME = MDs->end(); MI != ME; ++MI)
+ if (MDNode *MDN = dyn_cast_or_null<MDNode>(MI->second))
+ CreateMetadataSlot(MDN);
FunctionProcessed = true;
ST_DEBUG("end processFunction!\n");
FunctionProcessed = true;
ST_DEBUG("end processFunction!\n");
// Each MDNode is assigned unique MetadataIDNo.
std::map<const MDNode *, unsigned> MDNodes;
unsigned MetadataIDNo;
// Each MDNode is assigned unique MetadataIDNo.
std::map<const MDNode *, unsigned> MDNodes;
unsigned MetadataIDNo;
public:
inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M,
public:
inline AssemblyWriter(formatted_raw_ostream &o, SlotTracker &Mac,
const Module *M,
Out << ", align " << cast<StoreInst>(I).getAlignment();
}
Out << ", align " << cast<StoreInst>(I).getAlignment();
}
+ // Print DebugInfo
+ Metadata &TheMetadata = I.getContext().getMetadata();
+ unsigned MDDbgKind = TheMetadata.getMDKind("dbg");
+ if (const MDNode *Dbg = TheMetadata.getMD(MDDbgKind, &I))
+ Out << ", dbg !" << Machine.getMetadataSlot(Dbg);
+/// getMDs - Get the metadata attached with an Instruction.
+const Metadata::MDMapTy *Metadata::getMDs(const Instruction *Inst) {
+ MDStoreTy::iterator I = MetadataStore.find(Inst);
+ if (I == MetadataStore.end())
+ return NULL;
+
+ return &(I->second);
+}
+
/// ValueIsDeleted - This handler is used to update metadata store
/// when a value is deleted.
void Metadata::ValueIsDeleted(const Instruction *Inst) {
/// ValueIsDeleted - This handler is used to update metadata store
/// when a value is deleted.
void Metadata::ValueIsDeleted(const Instruction *Inst) {