Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update compiler to use latest LLVM version (#471)
* Start branch to rework LLVM generation The plan is to generate a .ll file directly and compile and link that, to move away from the unmaintained Haskell interface to LLVM. * Remove all dependencies on llvm-hs and shim out all LLVM generation code. * Compiler successfully builds, but doesn't generate LLVM * A couple of minor code cleanups * First version of prelude and set up for LLVM * Add generated .ll file as a sample. * Generate external declarations for resources. * Make resource globals undef instead of extern * Clean up resource global declaration generation * Add code to write LPVM code into LPVM section * Don't add 1 to specified lengths of strings * Introduce LLVM state monad, currently just holding file handle * Generate LLVM function signatures: start of code generation * Take signature info from ProcImpln (PrimProto instead of Proto) * pick lint * First go at generating LLVM proc bodies; much is wrong. * Generate foreign LLVM instructions and simple branches. Will need to convert from single assignment to true SSA. * Generate proper SSA; built and disassemble tuples for multi-argument return. * Generate LLVM switches for LPVM forks with more than 2 branches. * Generate C code to report sizes of C types. Start work on generating foreign lpvm instructions. Fix generation of llvm switches. * Generate string constants and use them when generating code. * Generate decimal integers as character constants in LLVM code. * Introduce new CPointer TypeRepresentation, used to represent opaque pointers, represented as 'ptr' in LLVM. Add type representation in 'representation is' Wybe type declarations. Use CPointer as the type of manifest string constants. Generate an LLVM declaration for each string constant, and use that constant by name everywhere a manifest string constant appears in the code. * Fix fencepost bug in switch generation. * Implement LPVM cast, load, and store * Now generates declarations of external called functions; generates good LLVM code for many library modules. * Define the size of a C pointer Also document assumptions made by c_config.c * Generate correct form for Wybe strings; add code to generate constant structures, needed to generate manifest constant strings. * Handle lpvm access and mutate; improve logging Not handling OutByReference or TakeReference yet. * Partially handle FlowOutByReference and FlowTakeReference * Add separate partitionArgsWithRefs function to handle by-ref arguments * Improve doc; start work on handling out-by-reference arguments. * Reformat description of LLVM output parts * regenerate src directory README * Improve LLVM module doc * Reorganise LLVM module * More LLVM module reorg * Now handle FlowTakeReference and FlowOutByReference; untested. * Improve generated README.md * fix duplicated types in type conversion exprs * Fix bugs in deferring calls; add more logging * Bug fixes, more logging * Slight cleanup * avoid use of bitcast for var = var assignment use LLVMName for both local and global vars * Use conversion instrs except for constants include temp counter with proc dumps * bug fix: temp counter was messed up by expansion with fusion * Properly set up LLVM monad for each proc * Eliminate unwanted args/parameters Exclude phantom and unneeded arguments and parameters from calls and definitions. Include source type in constant type conversion expressions. * Be more systematic with LLVM arguments; fix bug Generate \\ for backslash character in C strings; was generating single \. Avoid conversion instruction when marshalling constants to pass in C function call. * Generate HO calls * Supply new 'volatile' argument to memcpy intrinsic * Generate LLVM for proc specialisations, too Scan specialisation bodies when scanning bodies for strings and externs to generate. Generate separate LLVM definitions for specialisation bodies. * Systematially use LLVM names for instructions * typo * Fix type convertion during LLVM generation Automatically convert between representations when generating LLVM code. Remove cast from smaller to larger type in generating unboxed representations of small constructors. Make type checker aware of automatic conversion during LLVM generation, so it can be more forgiving. Conversion includes zero and sign extension, truncation, and bitcasting. * Support switching on signed integers. * Add XXX comments * Fix generation of switch defaults * Ensure SSA form by renaming assigned variables * Fix generation of unboxed mutator * Fix handling of load and store instructions * Log LLVM code; generate .s files on request Fix logging to include logging of LLVM code Make a few changes to make LLVM logging closer to old LLVM logging Add support for generating .s (native assembler) files. * delete accidentally added file * Improve compatibility with old LLVM generation * Fix empty variable name for main LLVM section * update version number to 0.2 * Fix problems with extern declarations Generate extern declarations for imported resources, but only if they're used. Name the main proc 'main', and use ccc instead of fastcc for it. Quote names if they contain characters other than alphanumerics, underscore and period. * Write LLVM code for submodules along with parent * Reduce change to logged LLVM code; Don't include submodules in generated LLVM when logging, because logging is already recursive. Omit git hash from header comment in .ll file, because it gives spurious diffs when testing. Explicitly specify C calling convention when calling C code. Generate extern decl for memcpy intrinsic last instead of first. * Get most tests to pass ... although many still fail. Updated update-exp script to give tighter diffs Understand void and intrinsic_bool (i1) C types Show Pointer type as "pointer" instead of "address". Include "ccc" in calls to wybe_malloc. Correctly consider string constants to be Pointers instead of CPointers. Eliminate many spurious bitcasts of constants (but accidentally add one in at least one place). * Delete spurious directory * Distinguish between wybe strings and C strings Unfortunately, this change renumbers all the string constants, but also, we don't generate a wybe string constant when only a C string is used. * filter out target triple when checking expected results. * Bug fix: non-destructive lpvm mutate mutated wrong structure * bug fix: declare wybe_malloc for non-destructive lpvm mutate * Bug fix: lpvm cast fields of unboxed constructors while constructing. * Bug fix: support resources in submodules * Track whether to prefix with 'tail' or 'musttail' based on alloca calls * Finish omitted comment * some code reorganisation * Fix handling of HO calls; drop mustinline in defs * Properly load outByRef value from the ref after the call, when it wasn't created by a takeRef * Insert date at top of ERRS file * Allocate closures on the heap Ensure wybe_malloc is declared Handle type conversion of closures correctly Fix generation of alloca instruction * Correct generation of HO trampoline * Eliminate more unnecessary bitcasts * more trivial bitcast removal test cases * XXX turn HO call to known closure into FO call * refactor LLVM prescanning to be monadic * Rename fns to generalise from strings to consts * Generate static constants for all-constant closures * Don't turn all HO arguments to i64 * Fix duplicated externs, building dynamic closures Generates externs in a different order now. * Add a log message * Store value through out-by-ref pointer as needed Wherever a value is stored in a variable that was an out-by-reference parameter, store the value where the out-by-reference pointer points. Use new function makeLLVMArg wherever we append an llvm type and llvm value, separated by a space. * Store floats in closures as floats, not ints * Fix handling of externs for mutually recursive modules * No conversion needed for equivalent types + add doc * Handle conversions better Just use bitcast for automatic integer <-> float converstions, to preserve all information. Track assigned LLVM variable types, so we can convert when the value is subsequently used as a different type. This happens for generics, when a typed value is supplied for a generic value. This really isn't ideal, but the type checker can give the same variable different types in this case. * Ignore changes to source_filename and target triple in complex tests * Fix syntax error in last commit * Fix bug in out-by-reference call argument Handle the case where out-by-reference argument is also an out-by-reference parameter. In this case, we can just use the pointer parameter, rather than passing a pointer to alloca-ed memory and fetching the contents after the call. This allows the call to be tail recursive. * Delete no-longer-used source files * Fix expected output for one test; fix test case to be more readable. * Address most of Jame's review comments * Install llvm package for CI testing * Code cleanup, remove unused code, changesome XXX comments to TODO * Update github CI runners to recent OSes; don't specify llvm 9 * Try debugging CI workflow * Another try to debug github CI * Heuristic for final-dump tests to show actual output for error cases rather than diff * Explicitly specify llvm version in ubuntu CI workflow * Also install llvm-18-dev for CI * Keep trying to get ubuntu workflow working * attempt to fix ubuntu build; normalise spaced LLVM array type syntax (#472) * attempt to fix ubuntu build; normalie spaced LLVM array type syntax * clean CConfig * one more lpvm section name * normalise tmp dir in complex tests * normalise more paths * add path to complx-test call; fix type on signum * derive path in python * Do LLVM type conversions (bitcasts) on call and return * Fix: delete .ll file after generating a .s file. * Fix generated trampolines Update trampoline parameters to have type AnyType and generated name, and generate code to convert from AnyType to the actual type of the parameter on entry, and similarly on exit for output parameters. Do similarly for closure arguments. * Delete accidental file; fix up documentation * Some cleanups, mostly removing commented-out code --------- Co-authored-by: James <[email protected]>
- Loading branch information