[LLVMdev] Inlining

Dustin Laurence dllaurence at dslextreme.com
Fri Jan 8 15:08:42 PST 2010


On 01/08/2010 02:10 PM, John McCall wrote:

> 'llc' is an IR-to-assembly compiler;  at -O3 it does some pretty neat
> machine-code and object-file optimizations, but it does not apply
> high-level optimizations like CSE or inlining.  'opt' is the tool
> which does IR-to-IR optimization.

A vital clue, but I'm still not getting it:

---
gemini:~/Projects/Nil/nil(0)$ make testInline.optdis.ll
llvm-as testInline.ll
opt -always-inline testInline.bc -o testInline.optbc
llvm-dis -f testInline.optbc -o testInline.optdis.ll
rm testInline.bc testInline.optbc
gemini:~/Projects/Nil/nil(0)$ cat testInline.optdis.ll
; ModuleID = 'testInline.optbc'

define linkonce fastcc i32 @foo(i32 %arg) alwaysinline {
  %result = mul i32 %arg, 7                       ; <i32> [#uses=1]
  ret i32 %result
}

define i32 @main(i32 %argc, i8** %argv) {
  %retVal = call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1]
  ret i32 %retVal
}
gemini:~/Projects/Nil/nil(0)$
---

Perhaps the -always-inline pass has a prerequisite pass?  I also tried
it with "-O3 -always-inline", which got halfway there:

---
; ModuleID = 'testInline.optbc'

define linkonce fastcc i32 @foo(i32 %arg) alwaysinline {
  %result = mul i32 %arg, 7                       ; <i32> [#uses=1]
  ret i32 %result
}

define i32 @main(i32 %argc, i8** nocapture %argv) {
  %retVal = tail call fastcc i32 @foo(i32 6) alwaysinline ; <i32> [#uses=1]
  ret i32 %retVal
}
---

I'm pleased to get the tailcall optimization, but in this case was
looking for the 'no call at all' optimization. :-)

Dustin




More information about the llvm-dev mailing list