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

  • Home
  • SEARCH
  • 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 to insert a zero in a record that contains a null value
i want insert this form value to datanase : <input type=checkbox name=brand1 id=brand1 value=1>
I want insert a custom snippet into an XML file from code within an
I want to insert a record into a MySQL database table from a formulaire.
I want to insert a date record to an Access database. Here is my
I want to insert given text to existing pdf at X,Y location provided. I
I want to insert the following include tag into my webpage using JavaScript. <!--#include
I want to insert widgets into my ItemsControl and make them resizeable. How do
i want to insert all processes that running into listbox, and also how to
I want to insert some items to mysql db. When I did it in

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.