Changes between Version 2 and Version 3 of Commentary/Compiler/Backends/LLVM/GHC_LLVMPorting

Jun 28, 2011 1:11:39 AM (4 years ago)

add some notes from email to a guy in past


  • Commentary/Compiler/Backends/LLVM/GHC_LLVMPorting

    v2 v3  
    1515'''(6)''' Once '''(5)''' is working you have it all running except TABLES_NEXT_TO_CODE. So change that to Yes in your and get that working. This will probably involve changing the mangler used by LLVM to work on the platform you are targeting. 
     18Here is an expanded version of what needs to be done in step 5 and 6 to get a registerised port of LLVM working: 
     201. GHC in registerised mode stores some of its virtual registers in 
     21 real hardware registers for performance. You will need to decide on a 
     22 mapping of GHC's virtual registers to hardware registers. So how 
     23 many registers you want to map and which virtual registers to store 
     24 and where. GHC's design for this on X86 is basically to use as many 
     25 hardware registers as it can and to store the more frequently accessed 
     26 virtual registers like the stack pointer in callee saved registers 
     27 rather than caller saved registers. You can find the mappings that GHC 
     28 currently uses for supported architectures in 
     29 'includes/stg/MachRegs.h'. 
     31 2. You will need to implement a custom calling convention for LLVM for your platform 
     32 that supports passing arguments using the register map you 
     33 decided on. You can see the calling convention I have created for X86 
     34 in the llvm source file 'lib/Target/X86/'. 
     36 3. Get GHC's build system running on your platform in registerised mode. 
     38 4. Add new inline assembly code for your platform to ghc's RTS. See files like 
     39 'rts/StgCRun.c' that include assembly code for the architectures GHC 
     40 supports. This is the main place as its where the boundary between the 
     41 RTS and haskell code is but I'm sure there are defiantly other places 
     42 that will need to be changed. Just grep the source code to find 
     43 existing assembly and add code for your platform appropriately. 
     45 5. Will need to change a few things in LLVM code gen. 
     47 5.1 'compiler/llvmGen/LlvmCodeGen/Ppr.hs' defines a platform specific 
     48 string that is included in all generated llvm code. Add one for your platform. 
     49 This string specifies the datalayout parameters for the platform (e.g 
     50 pointer size, word size..). If you don't include one llvm should still 
     51 work but wont optimise as aggressively. 
     52 5.2 'compiler/llvmGen/LlvmCodeGen/CodeGen.hs' has some platform 
     53 specific code on how write barriers should be handled. 
     55 6. Probably some stuff elsewhere in ghc that needs to be changed (most 
     56 likely in the main/ subfolder which is where most the compiler driver 
     57 lives or in codegen/ which is the Cmm code generator). 
     59 7. This is just what I know needs to be done, I'm sure there is many 
     60 small pieces missing although they should all fall into one of the 
     61 above categories. In the end just trial and error your way to success.