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 7594571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:27:07+00:00 2026-05-30T21:27:07+00:00

I want to insert a zero extension instruction and a multiply instruction to a

  • 0

I want to insert a zero extension instruction and a multiply instruction to a basic block. The input is,

define void @DriverInit() {
    EntryBlock:
      %abc = call i32 @cuInit(i32 0)
      ret void
    }

I want to transform it to,

define void @DriverInit() {
        EntryBlock:
          %abc = call i32 @cuInit(i32 0)
          %2 = zext i32 1 to i64
     %3 = mul i64 %2, ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
          ret void
        }

How to do it using LLVM C++ APIs? I use the below code to create the zero extension instruction, but i am unable to do it.

IRBuilder<> builder(BB);
Value *One = builder.getInt32(1);

Value *zer=builder.CreateZExt(One, IntegerType::getInt64Ty(M.getContext()),"1");

The second argument to CreateZExt is the destination type to which I want to zero extend,correct me if I am wrong.

I am a beginner in LLVM and find it difficult to get info on what functions to use in the passes. What resources are available except the doxygen documentation for the source code?

  • 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-05-30T21:27:08+00:00Added an answer on May 30, 2026 at 9:27 pm

    Once you have some experience with LLVM, you know where to look in the code. Until you gain that experience, you can use the C++ backend to generate API calls equivalent to the given IR for you.

    One way to do that is to compile the IR with llc using the C++ backend. For example, I take this simplified IR:

    define void @DriverInit() {
    EntryBlock:
      %0 = zext i32 1 to i64
      %1 = mul i64 %0, ptrtoint (i1** getelementptr (i1** null, i32 1) to i64)
      ret void
    }
    

    Save it to a file named z.ll and run:

    llc -march=cpp -O0 -cppgen=program z.ll
    

    You need to have LLVM installed or built somewhere to have access to llc. It produces z.cpp which has the C++ API calls to create the whole module. The relevant part for the EntryBlock basic block is:

     // Function: DriverInit (func_DriverInit)
     {
    
      BasicBlock* label_EntryBlock = BasicBlock::Create(mod->getContext(), "EntryBlock",func_DriverInit,0);
    
      // Block EntryBlock (label_EntryBlock)
      CastInst* int64_6 = new ZExtInst(const_int32_1, IntegerType::get(mod->getContext(), 64), "", label_EntryBlock);
      BinaryOperator* int64_7 = BinaryOperator::Create(Instruction::Mul, int64_6, const_int64_2, "", label_EntryBlock);
      ReturnInst::Create(mod->getContext(), label_EntryBlock);
     }
    

    In which you see how to use the zExtInstr constructor and later the BinaryOperator::Create call correctly to generate that IR.

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

Sidebar

Related Questions

i want insert this form value to datanase : <input type=checkbox name=brand1 id=brand1 value=1>
I want to insert say 50,000 records into sql server database 2000 at a
I want to insert something into a STL list in C++, but I only
I want to insert a new row into an Access database. I'm looking at
I want to insert multiple invisible watermarks into my JPEG pictures through C# code.
I want to insert a pair< string, vector<float> > into a map, first it
I want to insert a group box in the form and put in 3
I want to insert the following as the value for a variable in some
I want to insert a row into the Database using SqlDataAdapter. I've 2 tables
I want to insert this margin, but I don't know why... I want it

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.