A couple questions

Question 1:

I am trying to get a function not to be inlined. What are llvm's rules pertaining to inlining? I have tried all of the standard gcc options for turning off inlining and they do not seem to work. Here is the sample code that I am working with:

#include <stdio.h>

  void print_string(char* strval);

int main()
{
  char* strval = "Hello world\n";

  while(1){
    print_string(strval);
    sleep(15);
  }
  return 0;
}

void
print_string(char* strval)
{
  int i;
  for(i=0;i<12;i++){
    putc(strval[i], stdout);
  }
}

gcc 3.2.2 does not inline this by default. Also, on llvm.cs.uiuc.edu/demo, the compiler does not inline the function. However, on my version of the compiler, the function print_string is inlined by default.

Question 2:

What is the behavior of the function "recompileAndRelinkFunction" (in VM.{h,cpp}) if a program running in lli is currently executing within the function that is being recompiled?

Thanks in advance,
Brian

Brian M. Fahs
Graduate Student
University of Illinois

Brian Fahs wrote:

Question 1:

I am trying to get a function not to be inlined. What are llvm's rules pertaining to inlining? I have tried all of the standard gcc options for turning off inlining and they do not seem to work. Here is the sample code that I am working with:

  With LLVM, the linker optimizes the bytecode (I believe this is to allow for the inter-procedural optimizations that LLVM can do). IIRC, the llvm-gcc options won't affect whether or not the LLVM linker (gccld) inlines functions.

  Try using the "-Wl,-disable-inlining" option to llvm-gcc/g++. That should pass the option to gccld to tell it not to do any inlining. You can use gccld --help to display other options that control gccld's optimizations.

#include <stdio.h>

void print_string(char* strval);

int main()
{
    char* strval = "Hello world\n";

    while(1){
        print_string(strval);
        sleep(15);
    }
    return 0;
}

void
print_string(char* strval)
{
    int i;
    for(i=0;i<12;i++){
        putc(strval[i], stdout);
    }
}

gcc 3.2.2 does not inline this by default. Also, on llvm.cs.uiuc.edu/demo, the compiler does not inline the function. However, on my version of the compiler, the function print_string is inlined by default.

Question 2:

What is the behavior of the function "recompileAndRelinkFunction" (in VM.{h,cpp}) if a program running in lli is currently executing within the function that is being recompiled?

  Sorry. I don't know the answer to this question. Other members of the LLVM team can answer this, but unfortunetly, most of them are at MICRO this week.

  If you really need an answer sooner rather than later, I can try to find some time and dig into the function to see what it does. Or, if you want, you can try jumping into the code and seeing what it does.

  However, I find it odd that the JIT would try to recompile and relink a function that is currently executing. I believe it only compiles functions when they are called but not yet generated. Are you seeing this behavior occur, or does your project require re-generating a function that is currently running?

Thanks in advance,
Brian

Brian M. Fahs
Graduate Student
University of Illinois

_______________________________________________
LLVM Developers mailing list
LLVMdev@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev

Regards,

John T. Criswell

Question 1:
I am trying to get a function not to be inlined.
[...]
gcc 3.2.2 does not inline this by default. Also, on
llvm.cs.uiuc.edu/demo, the compiler does not inline the function.
However, on my version of the compiler, the function print_string is
inlined by default.

As John pointed out, it's the optimizing linker (gccld) that is doing the
inlining. All I have to add is, if you want to see this on the demo page,
you have to check the box for "run link-time optimizer".

Question 2:

What is the behavior of the function "recompileAndRelinkFunction" (in
VM.{h,cpp}) if a program running in lli is currently executing within
the function that is being recompiled?

If you're currently running within a function that you call
recompileAndRelinkFunction() on, what I expect will happen is: further
invocations of that function will be modified, but any invocations
currently running will not be modified. It's currently implemented by
writing a branch at the beginning of the function's old native machine code to
its new native machine code (i.e., overwriting the beginning of its entry
basic block.)

Let us know if you have further questions.

Hope this helps,
-Brian