Jacques Menu TvTMail
2012-Jan-19 15:33 UTC
[LLVMdev] 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, -- Faulty line above is part of the following function: define i8* @lista_sprintf_double(double %number, i32 %taille, i32 %decimales) { entry: %_castInttoDbl = sitofp i32 %decimales to double ; <double> [#uses=1] %0 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr1, i32 0, i32 0), double %_castInttoDbl) ; <i8*> [#uses=2] %_castInttoDbl4 = sitofp i32 %taille to double ; <double> [#uses=1] %1 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr3, i32 0, i32 0), double %_castInttoDbl4) ; <i8*> [#uses=2] %_lenL = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ; <i32> [#uses=1] %_lenR = call i32 @strlen(i8* %1) ; <i32> [#uses=1] %_totallen = add i32 %_lenL, 1 ; <i32> [#uses=1] %2 = add i32 %_totallen, %_lenR ; <i32> [#uses=1] %_malloc = malloc i8, i32 %2 ; <i8*> [#uses=1] %_strcpy = call i8* @strcpy(i8* %_malloc, i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ; <i8*> [#uses=1] %_strcat = call i8* @strcat(i8* %_strcpy, i8* %1) ; <i8*> [#uses=2] %_lenL5 = call i32 @strlen(i8* %_strcat) ; <i32> [#uses=1] %_lenR6 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ; <i32> [#uses=1] %_totallen7 = add i32 %_lenL5, 1 ; <i32> [#uses=1] %3 = add i32 %_totallen7, %_lenR6 ; <i32> [#uses=1] %_malloc8 = malloc i8, i32 %3 ; <i8*> [#uses=1] %_strcpy9 = call i8* @strcpy(i8* %_malloc8, i8* %_strcat) ; <i8*> [#uses=1] %_strcat10 = call i8* @strcat(i8* %_strcpy9, i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ; <i8*> [#uses=2] %_lenL11 = call i32 @strlen(i8* %_strcat10) ; <i32> [#uses=1] %_lenR12 = call i32 @strlen(i8* %0) ; <i32> [#uses=1] %_totallen13 = add i32 %_lenL11, 1 ; <i32> [#uses=1] %4 = add i32 %_totallen13, %_lenR12 ; <i32> [#uses=1] %_malloc14 = malloc i8, i32 %4 ; <i8*> [#uses=1] %_strcpy15 = call i8* @strcpy(i8* %_malloc14, i8* %_strcat10) ; <i8*> [#uses=1] %_strcat16 = call i8* @strcat(i8* %_strcpy15, i8* %0) ; <i8*> [#uses=2] %_lenL17 = call i32 @strlen(i8* %_strcat16) ; <i32> [#uses=1] %_lenR18 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ; <i32> [#uses=1] %_totallen19 = add i32 %_lenL17, 1 ; <i32> [#uses=1] %5 = add i32 %_totallen19, %_lenR18 ; <i32> [#uses=1] %_malloc20 = malloc i8, i32 %5 ; <i8*> [#uses=1] %_strcpy21 = call i8* @strcpy(i8* %_malloc20, i8* %_strcat16) ; <i8*> [#uses=1] %_strcat22 = call i8* @strcat(i8* %_strcpy21, i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ; <i8*> [#uses=1] %6 = call i8* @lista_sprintf(i8* %_strcat22, double %number) ; <i8*> [#uses=1] ret i8* %6 } -- Dr Jacques MENU Chargé de cours Centre Universitaire d'Informatique Université de Genève mailto://Jacques.Menu at unige.ch http://cui.unige.ch/~menu
On 1/19/12 10:33 AM, Jacques Menu TvTMail wrote:> 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.> > Thanks for your help! > > Regards, > > -- > > Faulty line above is part of the following function: > > define i8* @lista_sprintf_double(double %number, i32 %taille, i32 %decimales) { > entry: > %_castInttoDbl = sitofp i32 %decimales to double ;<double> [#uses=1] > %0 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr1, i32 0, i32 0), double %_castInttoDbl) ;<i8*> [#uses=2] > %_castInttoDbl4 = sitofp i32 %taille to double ;<double> [#uses=1] > %1 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr3, i32 0, i32 0), double %_castInttoDbl4) ;<i8*> [#uses=2] > %_lenL = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i32> [#uses=1] > %_lenR = call i32 @strlen(i8* %1) ;<i32> [#uses=1] > %_totallen = add i32 %_lenL, 1 ;<i32> [#uses=1] > %2 = add i32 %_totallen, %_lenR ;<i32> [#uses=1] > %_malloc = malloc i8, i32 %2 ;<i8*> [#uses=1] > %_strcpy = call i8* @strcpy(i8* %_malloc, i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i8*> [#uses=1] > %_strcat = call i8* @strcat(i8* %_strcpy, i8* %1) ;<i8*> [#uses=2] > %_lenL5 = call i32 @strlen(i8* %_strcat) ;<i32> [#uses=1] > %_lenR6 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i32> [#uses=1] > %_totallen7 = add i32 %_lenL5, 1 ;<i32> [#uses=1] > %3 = add i32 %_totallen7, %_lenR6 ;<i32> [#uses=1] > %_malloc8 = malloc i8, i32 %3 ;<i8*> [#uses=1] > %_strcpy9 = call i8* @strcpy(i8* %_malloc8, i8* %_strcat) ;<i8*> [#uses=1] > %_strcat10 = call i8* @strcat(i8* %_strcpy9, i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i8*> [#uses=2] > %_lenL11 = call i32 @strlen(i8* %_strcat10) ;<i32> [#uses=1] > %_lenR12 = call i32 @strlen(i8* %0) ;<i32> [#uses=1] > %_totallen13 = add i32 %_lenL11, 1 ;<i32> [#uses=1] > %4 = add i32 %_totallen13, %_lenR12 ;<i32> [#uses=1] > %_malloc14 = malloc i8, i32 %4 ;<i8*> [#uses=1] > %_strcpy15 = call i8* @strcpy(i8* %_malloc14, i8* %_strcat10) ;<i8*> [#uses=1] > %_strcat16 = call i8* @strcat(i8* %_strcpy15, i8* %0) ;<i8*> [#uses=2] > %_lenL17 = call i32 @strlen(i8* %_strcat16) ;<i32> [#uses=1] > %_lenR18 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i32> [#uses=1] > %_totallen19 = add i32 %_lenL17, 1 ;<i32> [#uses=1] > %5 = add i32 %_totallen19, %_lenR18 ;<i32> [#uses=1] > %_malloc20 = malloc i8, i32 %5 ;<i8*> [#uses=1] > %_strcpy21 = call i8* @strcpy(i8* %_malloc20, i8* %_strcat16) ;<i8*> [#uses=1] > %_strcat22 = call i8* @strcat(i8* %_strcpy21, i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i8*> [#uses=1] > %6 = call i8* @lista_sprintf(i8* %_strcat22, double %number) ;<i8*> [#uses=1] > ret i8* %6 > } > > > -- > > Dr Jacques MENU > Chargé de cours > Centre Universitaire d'Informatique > Université de Genève > mailto://Jacques.Menu at unige.ch > http://cui.unige.ch/~menu > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
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. -- Sanjoy Das http://playingwithpointers.com
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.> > Thanks for your help! > > Regards, > > -- > > Faulty line above is part of the following function: > > define i8* @lista_sprintf_double(double %number, i32 %taille, i32 %decimales) { > entry: > %_castInttoDbl = sitofp i32 %decimales to double ;<double> [#uses=1] > %0 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr1, i32 0, i32 0), double %_castInttoDbl) ;<i8*> [#uses=2] > %_castInttoDbl4 = sitofp i32 %taille to double ;<double> [#uses=1] > %1 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr3, i32 0, i32 0), double %_castInttoDbl4) ;<i8*> [#uses=2] > %_lenL = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i32> [#uses=1] > %_lenR = call i32 @strlen(i8* %1) ;<i32> [#uses=1] > %_totallen = add i32 %_lenL, 1 ;<i32> [#uses=1] > %2 = add i32 %_totallen, %_lenR ;<i32> [#uses=1] > %_malloc = malloc i8, i32 %2 ;<i8*> [#uses=1] > %_strcpy = call i8* @strcpy(i8* %_malloc, i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i8*> [#uses=1] > %_strcat = call i8* @strcat(i8* %_strcpy, i8* %1) ;<i8*> [#uses=2] > %_lenL5 = call i32 @strlen(i8* %_strcat) ;<i32> [#uses=1] > %_lenR6 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i32> [#uses=1] > %_totallen7 = add i32 %_lenL5, 1 ;<i32> [#uses=1] > %3 = add i32 %_totallen7, %_lenR6 ;<i32> [#uses=1] > %_malloc8 = malloc i8, i32 %3 ;<i8*> [#uses=1] > %_strcpy9 = call i8* @strcpy(i8* %_malloc8, i8* %_strcat) ;<i8*> [#uses=1] > %_strcat10 = call i8* @strcat(i8* %_strcpy9, i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i8*> [#uses=2] > %_lenL11 = call i32 @strlen(i8* %_strcat10) ;<i32> [#uses=1] > %_lenR12 = call i32 @strlen(i8* %0) ;<i32> [#uses=1] > %_totallen13 = add i32 %_lenL11, 1 ;<i32> [#uses=1] > %4 = add i32 %_totallen13, %_lenR12 ;<i32> [#uses=1] > %_malloc14 = malloc i8, i32 %4 ;<i8*> [#uses=1] > %_strcpy15 = call i8* @strcpy(i8* %_malloc14, i8* %_strcat10) ;<i8*> [#uses=1] > %_strcat16 = call i8* @strcat(i8* %_strcpy15, i8* %0) ;<i8*> [#uses=2] > %_lenL17 = call i32 @strlen(i8* %_strcat16) ;<i32> [#uses=1] > %_lenR18 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i32> [#uses=1] > %_totallen19 = add i32 %_lenL17, 1 ;<i32> [#uses=1] > %5 = add i32 %_totallen19, %_lenR18 ;<i32> [#uses=1] > %_malloc20 = malloc i8, i32 %5 ;<i8*> [#uses=1] > %_strcpy21 = call i8* @strcpy(i8* %_malloc20, i8* %_strcat16) ;<i8*> [#uses=1] > %_strcat22 = call i8* @strcat(i8* %_strcpy21, i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i8*> [#uses=1] > %6 = call i8* @lista_sprintf(i8* %_strcat22, double %number) ;<i8*> [#uses=1] > ret i8* %6 > } > > > -- > > Dr Jacques MENU > Chargé de cours > Centre Universitaire d'Informatique > Université de Genève > mailto://Jacques.Menu at unige.ch > http://cui.unige.ch/~menu > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Jacques Menu TvTMail
2012-Jan-20 05:49 UTC
[LLVMdev] What happened to "malloc" in LLVM 3.0 IR?
Hello, Thanks a lot for the fast and most useful answers, I can now fix this issue. A nice day! Regards, Le 19 janv. 2012 à 17:25, Duncan Sands a écrit :> 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. > >> >> Thanks for your help! >> >> Regards, >> >> -- >> >> Faulty line above is part of the following function: >> >> define i8* @lista_sprintf_double(double %number, i32 %taille, i32 %decimales) { >> entry: >> %_castInttoDbl = sitofp i32 %decimales to double ;<double> [#uses=1] >> %0 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr1, i32 0, i32 0), double %_castInttoDbl) ;<i8*> [#uses=2] >> %_castInttoDbl4 = sitofp i32 %taille to double ;<double> [#uses=1] >> %1 = call i8* @lista_sprintf(i8* getelementptr inbounds ([5 x i8]* @_stringexpr3, i32 0, i32 0), double %_castInttoDbl4) ;<i8*> [#uses=2] >> %_lenL = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i32> [#uses=1] >> %_lenR = call i32 @strlen(i8* %1) ;<i32> [#uses=1] >> %_totallen = add i32 %_lenL, 1 ;<i32> [#uses=1] >> %2 = add i32 %_totallen, %_lenR ;<i32> [#uses=1] >> %_malloc = malloc i8, i32 %2 ;<i8*> [#uses=1] >> %_strcpy = call i8* @strcpy(i8* %_malloc, i8* getelementptr inbounds ([2 x i8]* @_stringexpr4, i32 0, i32 0)) ;<i8*> [#uses=1] >> %_strcat = call i8* @strcat(i8* %_strcpy, i8* %1) ;<i8*> [#uses=2] >> %_lenL5 = call i32 @strlen(i8* %_strcat) ;<i32> [#uses=1] >> %_lenR6 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i32> [#uses=1] >> %_totallen7 = add i32 %_lenL5, 1 ;<i32> [#uses=1] >> %3 = add i32 %_totallen7, %_lenR6 ;<i32> [#uses=1] >> %_malloc8 = malloc i8, i32 %3 ;<i8*> [#uses=1] >> %_strcpy9 = call i8* @strcpy(i8* %_malloc8, i8* %_strcat) ;<i8*> [#uses=1] >> %_strcat10 = call i8* @strcat(i8* %_strcpy9, i8* getelementptr inbounds ([2 x i8]* @_stringexpr2, i32 0, i32 0)) ;<i8*> [#uses=2] >> %_lenL11 = call i32 @strlen(i8* %_strcat10) ;<i32> [#uses=1] >> %_lenR12 = call i32 @strlen(i8* %0) ;<i32> [#uses=1] >> %_totallen13 = add i32 %_lenL11, 1 ;<i32> [#uses=1] >> %4 = add i32 %_totallen13, %_lenR12 ;<i32> [#uses=1] >> %_malloc14 = malloc i8, i32 %4 ;<i8*> [#uses=1] >> %_strcpy15 = call i8* @strcpy(i8* %_malloc14, i8* %_strcat10) ;<i8*> [#uses=1] >> %_strcat16 = call i8* @strcat(i8* %_strcpy15, i8* %0) ;<i8*> [#uses=2] >> %_lenL17 = call i32 @strlen(i8* %_strcat16) ;<i32> [#uses=1] >> %_lenR18 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i32> [#uses=1] >> %_totallen19 = add i32 %_lenL17, 1 ;<i32> [#uses=1] >> %5 = add i32 %_totallen19, %_lenR18 ;<i32> [#uses=1] >> %_malloc20 = malloc i8, i32 %5 ;<i8*> [#uses=1] >> %_strcpy21 = call i8* @strcpy(i8* %_malloc20, i8* %_strcat16) ;<i8*> [#uses=1] >> %_strcat22 = call i8* @strcat(i8* %_strcpy21, i8* getelementptr inbounds ([2 x i8]* @_stringexpr, i32 0, i32 0)) ;<i8*> [#uses=1] >> %6 = call i8* @lista_sprintf(i8* %_strcat22, double %number) ;<i8*> [#uses=1] >> ret i8* %6 >> } >> >> >> -- >> >> Dr Jacques MENU >> Chargé de cours >> Centre Universitaire d'Informatique >> Université de Genève >> mailto://Jacques.Menu at unige.ch >> http://cui.unige.ch/~menu >> >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev