[llvm-dev] Extract injected metadata value from Function metadata

Ehsan Amiryousefi via llvm-dev llvm-dev at lists.llvm.org
Sun Feb 19 05:38:49 PST 2017


Hello Dear All,
I am writing a LLVM pass in which I inject some metadata to the parent
function, if the function belongs to OpenMp region. Then, I want to get the
injected metadata(including an ID) using the following code but I do not
get the expected result. tAs I check the instrumented LLVM IR code the
metadata is inserted correctly in the expected regions  but I just can't
retrieve them. Could you please let me know how can I get this value
here.(I am using llvm 3.9)
currentRegion refers to the current function.
ompRegionsUID is a counter to make each region's ID unique.

What I am looking for is to extract the injected ID in the metadata of the
current function.Which is an integer  called currrRegionId. I have also
tried to cast he output of the getOperand() command but still no expected
result.




if(currentRegion->getMetadata("omp.region.ID <http://omp.region.id/>
")==NULL)
      {
        Metadata *Ops[1] = {ConstantAsMetadata::get(ConstantInt::get(Int32,
ompRegionsUID++))};
        llvm::MDNode *N = llvm::MDNode::get(C, Ops);
        currentRegion->setMetadata("omp.region.ID <http://omp.region.id/>",
N);
        int currrRegionId =currentRegion->getMetadata("omp.region.ID
<http://omp.region.id/>")->getOperand(0);

        errs()<<"Omp region number: " <<
currentRegion->getName()<<"currentRegionId:
" << currrRegionId << "\n";

      }


Thank you in advance for your time and considerations,

Kind Regards,
Ehsan


-- 
*E.Amiryousefi*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170219/b930ec05/attachment.html>


More information about the llvm-dev mailing list