What happened to "malloc" in LLVM 3.0 IR?

Hello folks,

I have a compiler written with LLVM 2.6 by a student that produces .ll files, It behaved fine at the time.

Trying to take the work over using version 3.0, I run into the problem that "malloc" in the IR is no longer valid:

semac1 menu > llvm-as Carre.ll
llvm-as: Carre.ll:68:14: error: expected instruction opcode
  %_malloc = malloc i8, i32 %2 ; <i8*> [#uses=1]
             ^

Couldn't find any hint on the web about how to modify the code generation in this compiler to go ahead.

Thanks for your help!

Regards,

Hello folks,

I have a compiler written with LLVM 2.6 by a student that produces .ll files, It behaved fine at the time.

Trying to take the work over using version 3.0, I run into the problem that "malloc" in the IR is no longer valid:

semac1 menu> llvm-as Carre.ll
llvm-as: Carre.ll:68:14: error: expected instruction opcode
   %_malloc = malloc i8, i32 %2 ;<i8*> [#uses=1]
              ^

Couldn't find any hint on the web about how to modify the code generation in this compiler to go ahead.

Newer versions of LLVM do not have a malloc instruction. Instead, the IR simply has calls to a function called malloc. I think LLVM 2.6 has a pass that converts malloc instructions to call instructions that call the @malloc function; you could use that.

That said, I would not try to convert LLVM bitcode or assembly files from LLVM 2.6 to LLVM 3.0 format. It would be better to update your LLVM tools to LLVM 3.0 and recompile the programs you compiled originally with LLVM 2.6.

-- John T.

Hi,

I'm not aware of why the malloc instruction was removed, but I'd fix
this by replacing the malloc instructions by calls to a standard
malloc implementation.

Hi Jacques,

I have a compiler written with LLVM 2.6 by a student that produces .ll files, It behaved fine at the time.

Trying to take the work over using version 3.0, I run into the problem that "malloc" in the IR is no longer valid:

semac1 menu> llvm-as Carre.ll
llvm-as: Carre.ll:68:14: error: expected instruction opcode
   %_malloc = malloc i8, i32 %2 ;<i8*> [#uses=1]
              ^

Couldn't find any hint on the web about how to modify the code generation in this compiler to go ahead.

the malloc instruction was removed because it no longer offered any advantages
over recognizing the standard library call "malloc". So the frontend should
just be modified to generate a call to the "malloc" function.
You can auto-upgrade any existing IR by using tools from 2.7, 2.8, ..., 3.0
along the lines of:
   "opt-2.7 old_bitcode -o - | opt-2.8 -o - | opt-2.9 -o - | opt-3.0 -o new_bitcode"
You can probably omit most of those versions if you are lucky.

Ciao, Duncan.

Hello,

Thanks a lot for the fast and most useful answers, I can now fix this issue.

A nice day!

Regards,