[Open64-devel] RE: [Ipf-orc-support] Re: Reading and writing binary WHIRL
Brought to you by:
ributzka,
suneeljain
From: Lin, J. H <jas...@in...> - 2003-12-17 12:05:32
|
Well, it's pretty tricky. The problem lies in the IR file tiny.N, which is dumped after LNO, one phase in back end. The tiny.N has 3 sections: WT_SYMTAB, WT_TREE, WT_DEPGRAPH. If BACK_END is not defined, Read_Local_Info() will only read in WT_SYMTAB and WT_TREE section. Similarly, Write_PU_Info() will only write out WT_SYMTAB and WT_TREE section. Thus, the output file result.N will lose WT_DEPGRAPH section. In Write_Global_Info(), the compiler will throw err msg because WT_DEPGRAPH section exists in input file while is not written in output file. If you use .B file as input file (the IR file generated by front end), your program will work correctly. If you do want to work with .N file, you must try to define BACK_END in the Makefile.=20 Best regards, Jason -----Original Message----- From: ipf...@li... [mailto:ipf...@li...] On Behalf Of Marc Gonzalez-Sigler Sent: Monday, December 15, 2003 10:11 PM To: Open64; ORC Subject: [Ipf-orc-support] Re: Reading and writing binary WHIRL Hello, I am completely lost. I wrote the following program: #include "wn.h" #include "pu_info.h" #include "ir_bread.h" #include "ir_bwrite.h" int main() { MEM_Initialize(); Open_Input_Info("tiny.N"); Open_Output_Info("result.N"); Initialize_Symbol_Tables(FALSE); New_Scope(GLOBAL_SYMTAB, Malloc_Mem_Pool, FALSE); PU_Info *pu_tree =3D Read_Global_Info(NULL); for (PU_Info *pu =3D pu_tree; pu !=3D NULL; pu =3D PU_Info_next(pu)) { Read_Local_Info(MEM_pu_nz_pool_ptr, pu); Write_PU_Info(pu); } Write_Global_Info(pu_tree); Close_Output_Info(); Free_Input_Info(); return EXIT_SUCCESS; } /* Make the linker happy with dummy definitions */ void Signal_Cleanup(INT sig) { return; } char *Host_Format_Parm(INT kind, MEM_PTR parm) { return NULL; } INT8 Debug_Level =3D 0; I saved this file as orc-2.1/src/osprey1.0/ir_tools/ir_a2b.cxx and=20 compiled with "gmake -C osprey1.0/targia32_ia64_nodebug/ir_tools=20 ir_b2a BUILD_OPTIMIZE=3DDEBUG". I've attached tiny.N to this email (I hope binary attachments are=20 allowed). When I run ./ir_b2a from the command line, it goes into an infinite=20 loop, with 100% CPU utilization. When I run ./ir_b2a inside gdb, it=20 fails inside Write_Global_Info(). I am really pulling my hair over this. It works with a more=20 complicated example (equake from SPECfp2000) which has over 20 PUs. Does anyone spot an obvious mistake? I've been working on this for=20 so long that I might be missing the obvious... Regards, Marc Lin, Jason H wrote: > Marc, >=20 > The steps of reading/writing WHIRL file should be something like that: > =20 > 1. Open_Input_Info (input_file); > Open_Output_Info (output_file); >=20 > 2. Initialize_Symbol_Tables (FALSE); > 3. New_Scope (GLOBAL_SYMTAB, Malloc_Mem_Pool, FALSE); > 4. pu_tree =3D Read_Global_Info (NULL); >=20 > for (pu =3D pu_tree; pu !=3D NULL; pu =3D PU_Info_next (pu))=20 > { > 5. Read_Local_Info(MEM_pu_nz_pool_ptr, pu) > Write_PU_Info (pu); > } >=20 > 6. Write_Global_Info(pu_tree); > 7. Close_Output_Info (); > Free_Input_Info (); >=20 > Step 1 sets up file handles for reading and writing, it's easy to=20 > understand. >=20 > Step 2 Initializes all symbol tables. This function must be called=20 > before any symbol table operation is performed. As a general rule, the > first entry of each table has index 1; index 0 is reserved to stand=20 > for uninitialized index value. So If you are reading the symtab from a > file, the parameter `reserve_index_zero' should be FALSE; if you're=20 > adding new symbols, the parameter should be TRUE. >=20 > Step 3 allocates memory for global symbol tables. >=20 > Step 4 reads all the global tables and the PU section header and=20 > returns a pointer to the PU_Info tree. >=20 > Step 5 iterates all the PU, reads PU info from files and then writes=20 > it to file. >=20 > Step 6 writes out global info, including the PU-section header. This=20 > routine is called after all the PUs have been written out. I guess=20 > your program might violate this criteria. >=20 > Step 7 closes input/output info. >=20 > Best regards, > Jason >=20 >=20 > -----Original Message----- > From: ipf...@li... > [mailto:ipf...@li...] On Behalf Of Marc > Gonzalez-Sigler > Sent: Thursday, December 11, 2003 5:46 PM > To: Open64; ORC > Subject: [Ipf-orc-support] Reading and writing binary WHIRL >=20 >=20 > Hello all, >=20 > For the past week, I've been trying to read a binary WHIRL file to > memory, then write it back to a different file. I thought this would=20 > be easy and straightforward, but I found that it is quite harder=20 > than I had anticipated. >=20 > I've examined the code for ir_b2a and the backend driver. It seems > the steps should be: >=20 > // Initialize all the memory pools in memory.c > // otherwise Read_Global_Info() will fail. > MEM_Initialize(); >=20 > // Open_Inpur_Info will map toto.N to memory using > // mmap() and initialize several variables. Open_Input_Info("toto.N"); >=20 > // I don't know what these functions do. From their name, > // I suppose it has something to do with the symbol tables > // In any case, if I don't call both of them, then my > // program dumps core when I call Read_Global_Info().=20 > Initialize_Symbol_Tables(FALSE); New_Scope(GLOBAL_SYMTAB,=20 > Malloc_Mem_Pool, FALSE); >=20 > /*** SOMETHING MISSING HERE? ***/ >=20 > // Finally, request a pointer to the PU tree. > pu_tree =3D Read_Global_Info(&num_of_PU); >=20 > // PERHAPS I NEED THE FOLLOWING? > // for (pu =3D pu_tree; pu !=3D NULL; pu =3D PU_Info_next (pu)) > // Read_Local_Info(MEM_pu_nz_pool_ptr, pu); >=20 > /* At this point, I want to write pu_tree back to a file */ >=20 > // Open a new file for output. > Open_Output_Info("mycopy.N"); >=20 > // Again, I'm not sure what these functions do *exactly* but // I=20 > believe they write the WHIRL header, the different tables, // and the=20 > actual WHIRL node tree. My program consistently // crashes.=20 > Write_PU_Info(pu_tree); Write_Global_Info(pu_tree);=20 > Close_Output_Info(); >=20 > ### Compiler Error during Writing WHIRL file phase: > ### Can't write PU headers section in intermediate compiler file=20 > bidon.N >=20 > I know I have a fundamental misunderstanding of the WHIRL layout, > especially the global and local symbol tables, and my understanding=20 > of ir_bread.cxx and ir_bwrite.cxx is really lacking. Could someone,=20 > please, shed some light? I am desperate. |