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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:13:17+00:00 2026-06-13T13:13:17+00:00

I am writing some code using C and LLVM. I know LLVMGetOperand returns a

  • 0

I am writing some code using C and LLVM. I know LLVMGetOperand returns a LLVMValueRef but I was wondering what exactly it is because it seems like LLVMValueRef can be a number of different things. Does LLVMGetOperand return the instruction that creates the operand?

What I ultimately need to do is get an instructions operands and get the instruction who creates the value. As in

%3 = ADD %1 %2
...
%5 = ADD ...
...
%8 = SUB %3 %5

If I know the instruction %8 = SUB %3 %5, I want to get the operands %3 and %5 and then with those values get the instructions %3 = ADD %1 %2 and %5 = ADD .... I know I need to use LLVMGetOperand() but I dont know what it returns and how to use it to get the instruction I need. Would be nice if it just returned the instruction.

I also looked into LLVMGetFirstUse(). Does LLVMGetFirstUse() take in an instruction and then return the first use of the value the instruction produces?

I know about llvm.org and have been using it, I just need more clarification than what is given on that website.

  • 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-13T13:13:18+00:00Added an answer on June 13, 2026 at 1:13 pm

    Since the C bindings mirror the structure of the C++ code, it is in general a good idea to acquaint yourself with how the things are done in C++. One place to start is the LLVM Programmer’s Manual.

    The ValueRef you mention is just Value* in the C code. Here’s how it is described in the manual:

    The Value class is the most important class in the LLVM Source base.
    It represents a typed value that may be used (among other things) as
    an operand to an instruction. There are many different types of
    Values, such as Constants, Arguments. Even Instructions and Functions
    are Values.

    Now, for assembling basic blocks you usually use the IRBuilder class. In the C code this corresponds to the LLVMBuild* family of functions. For example, here’s the signature of the function for creating the sub instruction:

    LLVMValueRef LLVMBuildSub(LLVMBuilderRef, LLVMValueRef LHS, LLVMValueRef RHS,
                              const char *Name);
    

    The first parameter is the reference to the IRBuilder object, the second is the first operand, the third is the second operand, and the last is the optional name for the resulting value. So your example would look something like this (not tested):

    /* I'm assuming that you have already created a basic block bb. */
    LLVMBuilderRef builder = LLVMCreateBuilder(); 
    LLVMPositionBuilderAtEnd(builder, bb);
    LLVMValueRef lhs = LLVMBuildAdd(builder, 
        LLVMConstInt(LLVMInt32Type(), 1, 0), 
        LLVMConstInt(LLVMInt32Type(), 2, 0), NULL);
    LLVMValueRef rhs = LLVMBuildAdd(builder, 
        LLVMConstInt(LLVMInt32Type(), 3, 0), 
        LLVMConstInt(LLVMInt32Type(), 4, 0), NULL);
    LLVMBuildSub(build, lhs, rhs, NULL);
    

    With regards to LLVMGetFirstUse: given a Value, you can iterate over all places where it’s used. LLVMGetFirstUse gives you an iterator (LLVMUseRef) pointing to the head of the use-list that you can increment (LLVMGetNextUse) and dereference (LLVMGetUser). See llvm/Use.h for more information.

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

Sidebar

Related Questions

I'm writing some code using a simple clone pattern, I'd like it if I
I am writing some code where I would like render a MVC BeginForm but
I am writing some code to type strings using the Robot class. Everything is
I am writing some code that connects to a website, and using C#, and
I am writing some Java code that authenticates to Active Directory using SASL GSSAPI.
I am re-writing some code for a new re-design and I am wondering if
I'm writing some code using PacketDotNet and SharpPCap to parse H.225 packets for a
Greetings all. I am writing some code using the Boost Units library and have
Lately I've been writing some JS code using jQuery and JavaScript as it is
I'm writing some MVC JavaScript code using Prototype. The problem is that when I

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.