summaryrefslogtreecommitdiff
path: root/compiler/nativeGen
Commit message (Collapse)AuthorAgeFilesLines
* DWARF: Use .short to render half-machine-wordsBen Gamari2017-06-261-8/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The binutils documentation states that .short is a synonym for .word, which I assumed to mean "machine word", leading me to believe that we needed to use .hword to render half-machine-words. However, Darwin's toolchain doesn't understand .hword, so there we instead used .short. However, as it turns out the binutils documentation confusingly uses "word" to refer to a 16-bit word, so .short should work fine. Moreover, LLVM's internal assembler also doesn't understand .hword, so using .short consistently simplies things remarkably. Test Plan: Validate using binutils and LLVM internal assembler, validate on Darwin Reviewers: niteria, austin Reviewed By: niteria Subscribers: rwbarton, thomie GHC Trac Issues: #13866 Differential Revision: https://phabricator.haskell.org/D3667
* Hoopl: remove dependency on Hoopl packageMichal Terepeta2017-06-2319-21/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This copies the subset of Hoopl's functionality needed by GHC to `cmm/Hoopl` and removes the dependency on the Hoopl package. The main motivation for this change is the confusing/noisy interface between GHC and Hoopl: - Hoopl has `Label` which is GHC's `BlockId` but different than GHC's `CLabel` - Hoopl has `Unique` which is different than GHC's `Unique` - Hoopl has `Unique{Map,Set}` which are different than GHC's `Uniq{FM,Set}` - GHC has its own specialized copy of `Dataflow`, so `cmm/Hoopl` is needed just to filter the exposed functions (filter out some of the Hoopl's and add the GHC ones) With this change, we'll be able to simplify this significantly. It'll also be much easier to do invasive changes (Hoopl is a public package on Hackage with users that depend on the current behavior) This should introduce no changes in functionality - it merely copies the relevant code. Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com> Test Plan: ./validate Reviewers: austin, bgamari, simonmar Reviewed By: bgamari, simonmar Subscribers: simonpj, kavon, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3616
* Use lengthIs and friends in more placesRyan Scott2017-06-021-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | While investigating #12545, I discovered several places in the code that performed length-checks like so: ``` length ts == 4 ``` This is not ideal, since the length of `ts` could be much longer than 4, and we'd be doing way more work than necessary! There are already a slew of helper functions in `Util` such as `lengthIs` that are designed to do this efficiently, so I found every place where they ought to be used and did just that. I also defined a couple more utility functions for list length that were common patterns (e.g., `ltLength`). Test Plan: ./validate Reviewers: austin, hvr, goldfire, bgamari, simonmar Reviewed By: bgamari, simonmar Subscribers: goldfire, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3622
* PPC NCG: Lower MO_*_Fabs as PowerPC fabs instructionPeter Trommler2017-05-013-0/+12
| | | | | | | | | | | | | | | | In Phab:D3265 we introduced MO_F32_Fabs and MO_F64_Fabs. This patch improves code generation by generating PowerPC fabs instructions. Test Plan: run numeric/should_run/numrun015 or validate Reviewers: austin, bgamari, hvr, simonmar, erikd Reviewed By: erikd Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3512
* nativeGen: Use SSE2 SQRT instructionBen Gamari2017-04-283-7/+15
| | | | | | | | | | Reviewers: austin, dfeuer Subscribers: dfeuer, rwbarton, thomie GHC Trac Issues: #13629 Differential Revision: https://phabricator.haskell.org/D3508
* PPC NCG: Implement callish prim opsPeter Trommler2017-04-254-176/+591
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Provide PowerPC optimised implementations of callish prim ops. MO_?_QuotRem The generic implementation of quotient remainder prim ops uses a division and a remainder operation. There is no remainder on PowerPC and so we need to implement remainder "by hand" which results in a duplication of the divide operation when using the generic code. Avoid this duplication by implementing the prim op in the native code generator. MO_U_Mul2 Use PowerPC's instructions for long multiplication. Addition and subtraction Use PowerPC add/subtract with carry/overflow instructions MO_Clz and MO_Ctz Use PowerPC's CNTLZ instruction and implement count trailing zeros using count leading zeros MO_QuotRem2 Implement an algorithm given by Henry Warren in "Hacker's Delight" using PowerPC divide instruction. TODO: Use long division instructions when available (POWER7 and later). Test Plan: validate on AIX and 32-bit Linux Reviewers: simonmar, erikd, hvr, austin, bgamari Reviewed By: erikd, hvr, bgamari Subscribers: trofi, kgardas, thomie Differential Revision: https://phabricator.haskell.org/D2973
* cpp: Use #pragma once instead of #ifndef guardsBen Gamari2017-04-231-4/+1
| | | | | | | | | | | | | | This both says what we mean and silences a bunch of spurious CPP linting warnings. This pragma is supported by all CPP implementations which we support. Reviewers: austin, erikd, simonmar, hvr Reviewed By: simonmar Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3482
* Typos in comments [ci skip]Gabor Greif2017-04-051-1/+1
|
* Replace Digraph's Node type synonym with a data typeMatthew Pickering2017-04-043-28/+26
| | | | | | | | | | | | | This refactoring makes it more obvious when we are constructing a Node for the digraph rather than a less useful 3-tuple. Reviewers: austin, goldfire, bgamari, simonmar, dfeuer Reviewed By: dfeuer Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3414
* x86 nativeGen: Fix test with mask in range [128,255] (#13425)Reid Barton2017-03-241-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | My commit bdb0c43c7 optimized the encoding of instructions to test tag bits, but it did not always set exactly the same condition codes since the testb instruction does a single-byte comparison, rather than a full-word comparison. It would be correct to optimize the expression `x .&. 128 > 0` to the sequence testb $128, %al seta %al ; note: 'a' for unsigned comparison, ; not 'g' for signed comparison but the pretty-printer is not the right place to make this kind of context-sensitive optimization. Test Plan: harbormaster Reviewers: trofi, austin, bgamari, dfeuer Reviewed By: trofi, dfeuer Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3359
* Typos in comments (notes too) [ci skip]Gabor Greif2017-03-241-1/+1
|
* Typos in manual and commentsGabor Greif2017-03-141-2/+2
|
* implement missing Fabs{32,64} on i386 NCG and UNREGSergei Trofimovich2017-03-101-2/+2
| | | | | | | | | | | Noticed breakage as build failure on i386 freebsd build bot: http://haskell.inf.elte.hu/builders/freebsd-i386-head/1267/10.html ghc-stage1: panic! (the 'impossible' happened) (GHC version 8.1.20170310 for i386-portbld-freebsd): outOfLineCmmOp: MO_F64_Fabs not supported here Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* Generate better fp abs for X86 and llvm with default cmm otherwiseDominic Steinitz2017-03-074-4/+44
| | | | | | | | | | | | | | | | | | | | | | | Currently we have this in libraries/base/GHC/Float.hs: ``` abs x | x == 0 = 0 -- handles (-0.0) | x > 0 = x | otherwise = negateFloat x ``` But 3-4 years ago it was noted that this was inefficient: https://mail.haskell.org/pipermail/libraries/2013-April/019690.html We can generate better code for X86 and llvm and for others generate some custom cmm code which is similar to what the compiler generates now. Reviewers: austin, simonmar, hvr, bgamari Reviewed By: bgamari Subscribers: dfeuer, thomie Differential Revision: https://phabricator.haskell.org/D3265
* Upgrade UniqSet to a newtypeDavid Feuer2017-03-018-38/+42
| | | | | | | | | | | | | | | | | | | | | The fundamental problem with `type UniqSet = UniqFM` is that `UniqSet` has a key invariant `UniqFM` does not. For example, `fmap` over `UniqSet` will generally produce nonsense. * Upgrade `UniqSet` from a type synonym to a newtype. * Remove unused and shady `extendVarSet_C` and `addOneToUniqSet_C`. * Use cached unique in `tyConsOfType` by replacing `unitNameEnv (tyConName tc) tc` with `unitUniqSet tc`. Reviewers: austin, hvr, goldfire, simonmar, niteria, bgamari Reviewed By: niteria Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3146
* Spelling only [ci skip]Gabor Greif2017-02-231-1/+1
|
* Honour -dsuppress-uniques more thoroughlySimon Peyton Jones2017-02-174-23/+23
| | | | | | | | | | | I found that tests parser/should_compile/DumpRenamedAst and friends were printing uniques, which makes the test fragile. But -dsuppress-uniques made no difference! It turned out that pprName wasn't properly consulting Opt_SuppressUniques. This patch fixes the problem, and updates those three tests to use -dsuppress-uniques
* Debug: Use local symbols for unwind points (#13278)Ben Gamari2017-02-142-3/+4
| | | | | | | | | | | | | | | | | | | While this apparently didn't matter on Linux, the OS X toolchain seems to treat local and external symbols differently during linking. Namely, the linker assumes that an external symbol marks the beginning of a new, unused procedure, and consequently drops it. Fixes regression introduced in D2741. Test Plan: `debug` testcase on OS X Reviewers: austin, simonmar, rwbarton Reviewed By: rwbarton Subscribers: rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D3135
* Dwarf.Types: Use DW_CFA_same_value encoding when possibleBen Gamari2017-02-111-6/+15
| | | | | | | | | | | | | | | This is a bit smaller than the alternative, DW_CFA_val_expression. Also a bit of refactoring. Test Plan: Validate Reviewers: scpmw, simonmar, austin Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2745
* Cmm: Add support for undefined unwinding statementsBen Gamari2017-02-083-20/+37
| | | | | | | | | | | | | | And use to mark `stg_stack_underflow_frame`, which we are unable to determine a caller from. To simplify parsing at the moment we steal the `return` keyword to indicate an undefined unwind value. Perhaps this should be revisited. Reviewers: scpmw, simonmar, austin, erikd Subscribers: dfeuer, thomie Differential Revision: https://phabricator.haskell.org/D2738
* Generalize CmmUnwind and pass unwind information through NCGBen Gamari2017-02-087-56/+211
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As discussed in D1532, Trac Trac #11337, and Trac Trac #11338, the stack unwinding information produced by GHC is currently quite approximate. Essentially we assume that register values do not change at all within a basic block. While this is somewhat true in normal Haskell code, blocks containing foreign calls often break this assumption. This results in unreliable call stacks, especially in the code containing foreign calls. This is worse than it sounds as unreliable unwinding information can at times result in segmentation faults. This patch set attempts to improve this situation by tracking unwinding information with finer granularity. By dispensing with the assumption of one unwinding table per block, we allow the compiler to accurately represent the areas surrounding foreign calls. Towards this end we generalize the representation of unwind information in the backend in three ways, * Multiple CmmUnwind nodes can occur per block * CmmUnwind nodes can now carry unwind information for multiple registers (while not strictly necessary; this makes emitting unwinding information a bit more convenient in the compiler) * The NCG backend is given an opportunity to modify the unwinding records since it may need to make adjustments due to, for instance, native calling convention requirements for foreign calls (see #11353). This sets the stage for resolving #11337 and #11338. Test Plan: Validate Reviewers: scpmw, simonmar, austin, erikd Subscribers: qnikst, thomie Differential Revision: https://phabricator.haskell.org/D2741
* Nix typo and redundant where-clausesRyan Scott2017-01-251-2/+0
|
* nativeGen: Use `foldl'` instead of `foldr` in free register accumulationBen Gamari2017-01-246-9/+13
| | | | | | | | | | | | | | | | | | | Manipulations of `FreeRegs` values are all just bit-operations on a word. Turning these `foldr`s into `foldl'`s has a very small but consistent effect on compiler allocations, ``` -1 s.d. ----- -0.065% +1 s.d. ----- -0.018% Average ----- -0.042% ``` Test Plan: Validate Reviewers: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2966
* Fix terminal corruption bug and clean up SDoc interface.Phil Ruffwind2017-01-101-4/+3
| | | | | | | | | | | | | | | | | | | | | | | - Fix #13076 by wrapping `printDoc_` so that the terminal color is reset even if an exception occurs. - Add `printSDoc`, `printSDocLn`, and `bufLeftRenderSDoc` to keep `SDoc` values abstract (they are wrappers of `printDoc_`, `printDoc`, and `bufLeftRender` respectively). - Remove unused function: `printForAsm` Test Plan: manual Reviewers: RyanGlScott, austin, dfeuer, bgamari Reviewed By: dfeuer, bgamari Subscribers: dfeuer, mpickering, thomie Differential Revision: https://phabricator.haskell.org/D2932 GHC Trac Issues: #13076
* Typofixes in manual and comments [ci skip]Gabor Greif2017-01-041-1/+1
|
* Fix string merging with -split-sectionsSimon Brenner2016-12-161-3/+14
| | | | | | | | | | | | | | | | | | The added flags for string literal merging ended up printed in the middle of the section name when -split-sections was enabled. Break it up to put the flags after the name. Test Plan: validate with SplitSections=YES Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2865 GHC Trac Issues: #9577
* CLabel: Kill redundant UnitId argument from labelDynamicBen Gamari2016-12-161-8/+8
| | | | | | | | | | | | | | | | | | | | | | | | | It already has access to the current package's UnitId via the Module. Edward Yang pointed out that there is one wrinkle, however: the following invariant isn't true at all stages of compilation, if I am compiling the module (this_mod :: Module), then thisPackage dflags == moduleUnitId this_mod. Specifically, this is only true after desugaring; it may be broken when typechecking an indefinite signature. However, it's safe to assume this in the native codegen. I've updated Note to state this invariant more directly. Test Plan: Validate Reviewers: austin, ezyang, simonmar Reviewed By: ezyang, simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2863
* NCG: Implement trivColorable for PowerPC 64-bitPeter Trommler2016-12-091-4/+4
| | | | | | | | | | | | | | | Define constants for 64-bit PowerPC in graph coloring register allocator. Test Plan: ./validate Reviewers: simonmar, austin, erikd, bgamari, hvr Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2791
* BlockId: remove BlockMap and BlockSet synonymsMichal Terepeta2016-12-0814-23/+32
| | | | | | | | | | | | | | | | | | | | This continues removal of `BlockId` module in favor of Hoopl's `Label`. Most of the changes here are mechanical, apart from the orphan `Outputable` instances for `LabelMap` and `LabelSet`. For now I've moved them to `cmm/Hoopl`, since it's already trying to manage all imports from Hoopl (to avoid any collisions). Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com> Test Plan: validate Reviewers: bgamari, austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2800
* nativeGen: Fix string merging on WindowsBen Gamari2016-12-081-3/+6
| | | | | | | | | | | | | | | | | | | D1290 places string constants in the `.rodata.str` section with `aMS` section flags so that the linker can merge them. However, it seems that ld doesn't understand these flags. It appears that `gcc -fmerge-constants` uses the `dr` flags on Windows. Make GHC do the same. Test Plan: Validate on Windows Reviewers: xnyhps, austin, Phyx Reviewed By: Phyx Subscribers: thomie, trommler Differential Revision: https://phabricator.haskell.org/D2797 GHC Trac Issues: #9577
* Reduce the size of string literals in binaries.Thijs Alkemade2016-12-064-5/+33
| | | | | | | | | | | | | | | Removed the alignment for strings and mark then as cstring sections in the generated asm so the linker can merge duplicate sections. Reviewers: rwbarton, trofi, austin, trommler, simonmar, hvr, bgamari Reviewed By: hvr, bgamari Subscribers: simonpj, hvr, thomie Differential Revision: https://phabricator.haskell.org/D1290 GHC Trac Issues: #9577
* Remove most functions from cmm/BlockIdMichal Terepeta2016-11-295-11/+12
| | | | | | | | | | | | | | | | | | | | It seems that `BlockId` module could simply go away in favor of Hoopl's `Label`. This is the first step to do that. In a few places I had to add some type signatures, but most of them seem to help with code readability. Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com> Test Plan: ./validate Reviewers: austin, simonmar, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2765
* NCGMonad: Add MonadUnique NatM instanceBen Gamari2016-11-291-0/+8
| | | | | | | | | | | | Test Plan: Validate Reviewers: austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2737
* AsmCodeGen: Refactor worker in cmmNativeGensBen Gamari2016-11-291-10/+13
| | | | | | | | | | | | Test Plan: Validate Reviewers: austin, simonmar, michalt Reviewed By: simonmar, michalt Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2736
* Purge GHC of literate PerlDemi Obenour2016-11-291-1/+1
| | | | | | | | | | | | | | Test Plan: GHC CI Reviewers: austin, bgamari Reviewed By: bgamari Subscribers: snowleopard, thomie Maniphest Tasks: T74 Differential Revision: https://phabricator.haskell.org/D2732
* Correct spelling of command-line option in commentGabor Greif2016-11-171-1/+1
|
* Inline compiler/NOTES into X86/Ppr.hsMatthew Pickering2016-11-163-2/+20
| | | | | | | | Reviewers: austin, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2721
* Test for unnecessary register spillsThomas Jakway2016-11-151-1/+12
| | | | | | | | | | | | Reviewers: mainland, simonmar, michalt, bgamari, austin Reviewed By: bgamari Subscribers: simonpj, mpickering, thomie Differential Revision: https://phabricator.haskell.org/D2638 GHC Trac Issues: #12744, #12745
* Typos in commentsGabor Greif2016-10-171-1/+1
|
* RegAlloc: Make some pattern matched completeJoachim Breitner2016-10-062-5/+8
| | | | | | | these actually are complete, but due to the use of pattern guards, the compiler does not see that. Refactor the code that it does. Differential Revision: https://phabricator.haskell.org/D2574
* PPC/CodeGen: fix lwa instruction generationPeter Trommler2016-10-011-4/+12
| | | | | | | | | | | | | | | | | | | Opcode lwa is a 64-bit opcode and allows a DS-form only. This patch generates lwa opcodes only when the offset is a multiple of 4. Fixes #12621 Test Plan: validate Reviewers: erikd, hvr, simonmar, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2547 GHC Trac Issues: #12621
* CodeGen X86: fix unsafe foreign calls wrt inliningSylvain HENRY2016-10-011-36/+75
| | | | | | | | | | | | | | | | | | | | | | | | | Foreign calls (unsafe and safe) interact badly with inlining and register passing ABIs (see #11792 and #12614): the inlined code to compute a parameter of the call may overwrite a register already set to pass a preceding parameter. With this patch, we compute all parameters which are not simple expressions before assigning them to fixed registers required by the ABI. Test Plan: - Add test (test both reg and stack parameters) - Validate Reviewers: osa1, bgamari, austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2263 GHC Trac Issues: #11792, #12614
* Comments and manual only: spellingGabor Greif2016-09-281-1/+1
|
* Fix codegen bug in PIC version of genSwitch (#12433)Simon Marlow2016-09-151-3/+6
| | | | | | | | | | | | | | | | | | Summary: * getNonClobberedReg instead of getSomeReg, because the reg needs to survive across t_code * Use a new reg for the table offset calculation instead of clobbering the reg returned by expr (this was the bug affecting #12433) Test Plan: New unit test; validate Reviewers: rwbarton, bgamari, austin, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2529 GHC Trac Issues: #12433
* PPC NCG: Implement minimal stack frame header.Peter Trommler2016-08-312-8/+27
| | | | | | | | | | | | | | | | | | | | | | | | According to the ABI specifications a minimal stack frame consists of a header and a minimum size parameter save area. We reserve the minimal size for each ABI. On PowerPC 64-bil Linux and AIX the parameter save area can accomodate up to eight parameters. So calls with eight parameters and fewer can be done without allocating a new stack frame and deallocating that stack frame after the call. On AIX one additional spill slot is available on the stack. Code size for all nofib benchmarks is 0.3 % smaller on powerpc64. Test Plan: validate on AIX Reviewers: hvr!, erikd, austin, simonmar, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2445
* Revert "codeGen: Remove binutils<2.17 hack, fixes T11758"Simon Peyton Jones2016-08-192-3/+35
| | | | | | | This reverts commit e3e2e49a8f6952e1c8a19321c729c17b294d8c92. I'm reverting because it makes ghc-stage2 seg-fault on 64-bit Windows machines. Even ghc-stage2 --version seg-faults.
* RegAlloc: Use IntSet/IntMaps instead of generic Set/MapsÖmer Sinan Ağacan2016-08-063-28/+22
|
* RegAlloc: Remove duplicate seqList (use seqList from Util)Ömer Sinan Ağacan2016-08-061-14/+7
|
* AsmCodeGen: Give linear-scan and coloring reg. allocators different cc namesÖmer Sinan Ağacan2016-08-061-2/+2
|
* codeGen: Remove binutils<2.17 hack, fixes T11758Alex Dzyoba2016-08-052-35/+3
| | | | | | | | | | | | | | | | | | | There was a complication on the x86_64 platform, where pointers were 64 bits, but the tools didn't support 64-bit relative relocations. This was true before binutils 2.17, which nowadays is quite standart (even CentOs 5 is shipped with 2.17). Hacks were removed from x86 genSwitch and asm pretty printer. Also [x86-64-relative] note was dropped from includes/rts/storage/InfoTables.h as it's not referenced anywhere now. Reviewers: austin, simonmar, rwbarton, erikd, bgamari Reviewed By: simonmar, erikd, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2426