Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:00:53+00:00 2026-06-18T14:00:53+00:00

I have a toolchain of two passes. First one, is a transformation pass that

  • 0

I have a toolchain of two passes. First one, is a transformation pass that should add metadata to some structures (instructions/variables) and the second pass is an analyzing pass which needs to access the added metadata. The problem is with my adding metadata transformation pass. There might be two problems(or both):

First, maybe I don’t add correctly metadata.

    LLVMContext& C = myInstruction->getContext();
    MDNode* N = MDNode::get(C, MDString::get(C, "add info"));
    myInstruction->setMetadata("important", N);
    errs()<<"\n"<<cast<MDString>(myInstruction->getMetadata("important")->getOperand(0))->getString();

However, “add info” is printed after running the pass.

Second, it seems that the transformations are not applied on the .bc of the target program.
The Test1.bc (clean) and Test2.bc (transformation applied) are the same. I just have

using namespace llvm;

namespace {
  struct metadata : public FunctionPass {
    const Function *F;
    static char ID; // Pass identifcation, replacement for typeid
    metadata() : FunctionPass(ID) {
      //initializeMemDepPrinterPass(*PassRegistry::getPassRegistry());
    }
    virtual bool runOnFunction(Function &F);
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
      AU.setPreservesAll();
    }

   // virtual void releaseMemory() {
    //  F = 0;
   // }
  };
}

char metadata::ID = 0;

static RegisterPass<metadata> X("my-metadata", "Adding metadata", false, true);

at the beginning of my transformation pass. Please tell me how can I add metadata persistently.

Thank you for your answers !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:00:55+00:00Added an answer on June 18, 2026 at 2:00 pm

    The issue of interactions between passes (as raised by Oak’s comments) nonwithstanding, it’s not hard to write a pass that actually modifies the module by adding metadata. Here’s a (basic-block, for easier writing) pass that adds the same metadata to each instruction it encounters. If you dump the module before and after running this pass, you will see that the module is indeed modified:

    class MyBBPass : public BasicBlockPass {
    public:
        static char ID;
    
        MyBBPass()
            : BasicBlockPass(ID)
        {}
    
        virtual bool runOnBasicBlock(BasicBlock &BB) {
            Value *A[] = {MDString::get(getGlobalContext(), "thing")};
            MDNode *Node = MDNode::get(getGlobalContext(), A);
            for (BasicBlock::iterator ii = BB.begin(), ii_e = BB.end();
                 ii != ii_e; ++ii) {
                ii->setMetadata("md", Node);
            }
    
            return true;
        }
    };
    
    char MyBBPass::ID = 0;
    

    Note that the run*** method returns true to signal to the pass manager that the basic block was indeed modified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First some background - I have three VS2010 C++/OpenCL projects that compile and run
I have a c++ Project that was compiled with the cygwin toolchain, now I
First of all I have to admit that I haven't upgraded to SDK 3.1
First up, I am a newbie to LLVM passes. I am trying to add
I have got the mips-gcc toolchain source code and binaries from some chipset maker.
Based on some limitations with the NDK standalone toolchain and bionic, I have rolled
I'm trying to use the NDK toolchain to build some native library I have
Assume I have a UIMA toolchain that does something like this: tokenize -> POS
I'm using a specific toolchain (the one that comes with the BlackBerry Playbook NDK).
I have some template code that works fine with Xcode 4.5 and LLVM 3.0,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.