Hello group,<br><br>Per my posting on the Clang Newsgroup.<br><br>I'm interested in doing some loop optimizations, towards this end I would like to add some custom Metadata to a Loop header.<br><br>Loops in LLVM are represented using BasicBlocks, but unfortunately you can NOT add MetaData to a BasicBlock. Although you can add Metadata to an instruction. So I'm proposing to add the Metadata manipulation methods and state from class "Instruction" to class "BasicBlock".<br>
<br>The class "Instruction" stores a private enumeration:<br> <br>enum <br>{<br> // HasMetadataBit - This is a bit stored in the SubClassData field which<br> // indicates whether this instruction has metadata attached to it or not.<br>
<br> HasMetadataBit = 1 << 15<br>};<br><br>This enumeration is then utilized by hasMetadata() which is inlined in class Instruction:<br><br>// hasMetadata() - Return true if this instruction has any metadata attached to it.<br>
<br>bool hasMetadata() const <br>{<br> return (getSubclassDataFromValue() & HasMetadataBit) != 0;<br>}<br><br>>> First Question:<br><br>Since I do not expect to require any subclasses of BasicBlock, should I just implement in BasicBlock the following:<br>
<br>bool hasMetadata() const <br>{<br> return (HasMetadataBit) != 0;<br>}<br><br>>> Second Question:<br><br>Additionally, after studying the way Metadata is manipulated in class "Instruction", I propose to add the following methods from class "Instruction" to class "BasicBlock":<br>
<br> public:<br> bool hasMetadata() const<br> MDNode *getMetadata(unsigned KindID) const;<br> MDNode *getMetadata(const char *Kind) const;<br> void getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode*> > &MDs)const;<br>
void setMetadata(unsigned KindID, MDNode *Node);<br> void setMetadata(const char *Kind, MDNode *Node);<br><br> private:<br> // These are all implemented in Metadata.cpp.<br> MDNode *getMetadataImpl(unsigned KindID) const;<br>
MDNode *getMetadataImpl(const char *Kind) const;<br> void getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned,MDNode*> > &)const;<br> void removeAllMetadata();<br><br>I noticed that BasicBlock seems to be referenced by almost every class in LLVM, so I wanted to ask which particular client classes I will need to update so I don't break any existing code. It seems to me, that all I'm doing is adding code, so I shouldn't break any of the client classes, but I will need to update the classes that will need to utilize these new methods in class BasicBlock.<br>
<br>Per Chris's earlier comment, I realize that BitcodeReader / BitcodeWriter & LLParser will need to be updated. For the moment I am just trying to make sure that I can procedurally add Metadata to a Loop Header via adding Metadata to a BasicBlock.<br>
<br>>> Third Question:<br><br>I had some trouble understanding the implementation of SetMetadata in the Instruction class, is this where Metadata is "attached" to an Instruction?<br><br>Any detailed comments / suggestions as to which client LLVM IR classes I need to dig into as well as what all the changes I will have to make would be greatly appreciated.<br>
<br>Thanks,<br>-- <br>Kalyan Ponnala<br>phone: 8163772059<br>
<div style="display: inline;"></div>
<div style="display: inline;"></div>
<div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style>