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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:43:01+00:00 2026-05-31T02:43:01+00:00

I am trying to get started with LLVM in order to add just-in-time compilation

  • 0

I am trying to get started with LLVM in order to add just-in-time compilation for my code, but finding it very difficult find references on how to do the things I want in LLVM, despite having checked through the Kaleidoscope tutorial, the language reference manual, the programmer’s manual and the doxygen documentation. Are there more references to LLVM’s C++ API than these?

Now for the concrete question. I have allocated an array object with two elements (which I assume corresponds to double[2] in C++):

const llvm::Type* double_t = llvm::Type::getDoubleTy(llvm::getGlobalContext());
const llvm::Type* array_t =  llvm::ArrayType::get(double_t,2)

Later in the code, I create a function, where this array is one of the arguments. Then, in my function I extract the first element in the array and return it to the user:

llvm::Function::arg_iterator AI = jit_function_->arg_begin();
llvm::Value *x = AI;
llvm::Value *x0 = Builder.CreateExtractValue(x,0);
Builder.CreateRet(x0);

The code jits fine, but when I try to run it, it doesn’t work. For example:

typedef double (*GenType)(double[2]);
GenType FP = GenType(intptr_t(TheExecutionEngine->getPointerToFunction(jit_function_)));
double y[2] = {10,20};
double r = FP(y);
printf("r = %g\n", r);

The return value is just nonsense and I can’t see what I’m doing wrong. If I pass the values in the array (10 and 20) as scalar arguments to the function, it works fine.

  • 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-31T02:43:03+00:00Added an answer on May 31, 2026 at 2:43 am

    I think I am able to answer my own question. For the first part of the question, a good reference to LLVM (in addition to the ones mentioned above) is to write what you want in plain C and compile it with Clang and look at the LLVM output: clang -S -emit-llvm test.c -o -.

    For the concrete question, my problem was that I assumed that I was passing an array of two doubles to the jitted function, while in fact I was passing a pointer to an array with two values. So the solution is to change:

    const llvm::Type* array_t =  llvm::ArrayType::get(double_t,2);
    

    to

    const llvm::Type* array_t =  llvm::PointerType::getUnqual(llvm::ArrayType::get(double_t,2));
    

    And to add an additional dereferencing by changing

    llvm::Value *x0 = Builder.CreateExtractValue(x,0);
    

    to

    llvm::Value *x0 = Builder.CreateExtractValue(Builder.CreateLoad(x),0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just trying to get started with NDjango but am having issues running a
I am trying to get started with the Google Maps API, but I'm finding
I am trying to get started with PEAR's HTML_QuickForm but I'm having a problem.
I'm trying to get started with Three20 and just want to get a basic
I'm trying to get started with twitter4r but I'm having some issues: Why I
I'm trying to get started with the Android SDK on OS X 10.6.8 but
I'm trying to get started using agsXMPP , but I'm having some problems. I'm
Trying to get started with subsonic but have a simple question about stored procedures
Im just trying to get started with learning C http://fromlearncodethehardway.com . However I'm stuck
I'm trying to get started using git, but I'm having some troubles right away.

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.