diff options
author | Moritz Angermann <moritz.angermann@gmail.com> | 2020-10-22 12:08:34 +0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-06-05 10:29:57 -0400 |
commit | 3b1aa7dba7c006b473855a6b199b15fa3a3d77a0 (patch) | |
tree | 631816f4aef8d28ee596b51b70a0a0ba2df12230 /compiler/GHC/CmmToAsm/PIC.hs | |
parent | 8c90e6c758769b068aea2891b26cc17577b6d36a (diff) | |
download | haskell-3b1aa7dba7c006b473855a6b199b15fa3a3d77a0.tar.gz |
Adds AArch64 Native Code Generator
In which we add a new code generator to the Glasgow Haskell
Compiler. This codegen supports ELF and Mach-O targets, thus covering
Linux, macOS, and BSDs in principle. It was tested only on macOS and
Linux. The NCG follows a similar structure as the other native code
generators we already have, and should therfore be realtively easy to
follow.
It supports most of the features required for a proper native code
generator, but does not claim to be perfect or fully optimised. There
are still opportunities for optimisations.
Metric Decrease:
ManyAlternatives
ManyConstructors
MultiLayerModules
PmSeriesG
PmSeriesS
PmSeriesT
PmSeriesV
T10421
T10421a
T10858
T11195
T11276
T11303b
T11374
T11822
T12227
T12545
T12707
T13035
T13253
T13253-spj
T13379
T13701
T13719
T14683
T14697
T15164
T15630
T16577
T17096
T17516
T17836
T17836b
T17977
T17977b
T18140
T18282
T18304
T18478
T18698a
T18698b
T18923
T1969
T3064
T5030
T5321FD
T5321Fun
T5631
T5642
T5837
T783
T9198
T9233
T9630
T9872d
T9961
WWRec
Metric Increase:
T4801
Diffstat (limited to 'compiler/GHC/CmmToAsm/PIC.hs')
-rw-r--r-- | compiler/GHC/CmmToAsm/PIC.hs | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/compiler/GHC/CmmToAsm/PIC.hs b/compiler/GHC/CmmToAsm/PIC.hs index 7fe90c3ec6..81ce9d34a9 100644 --- a/compiler/GHC/CmmToAsm/PIC.hs +++ b/compiler/GHC/CmmToAsm/PIC.hs @@ -122,6 +122,15 @@ cmmMakeDynamicReference config referenceKind lbl addImport stub return $ CmmLit $ CmmLabel stub + -- GOT relative loads work differently on AArch64. We don't do two + -- step loads. The got symbol is loaded directly, and not through an + -- additional load. Thus we do not need the CmmLoad decoration we have + -- on other platforms. + AccessViaSymbolPtr | ArchAArch64 <- platformArch platform -> do + let symbolPtr = mkDynamicLinkerLabel SymbolPtr lbl + addImport symbolPtr + return $ cmmMakePicReference config symbolPtr + AccessViaSymbolPtr -> do let symbolPtr = mkDynamicLinkerLabel SymbolPtr lbl addImport symbolPtr @@ -135,7 +144,6 @@ cmmMakeDynamicReference config referenceKind lbl -- so just jump there if it's a call or a jump _ -> return $ CmmLit $ CmmLabel lbl - -- ----------------------------------------------------------------------------- -- Create a position independent reference to a label. -- (but do not bother with dynamic linking). @@ -150,6 +158,11 @@ cmmMakePicReference config lbl | OSMinGW32 <- platformOS platform = CmmLit $ CmmLabel lbl + -- no pic base reg on AArch64, however indicate this symbol should go through + -- the global offset table (GOT). + | ArchAArch64 <- platformArch platform + = CmmLit $ CmmLabel lbl + | OSAIX <- platformOS platform = CmmMachOp (MO_Add W32) [ CmmReg (CmmGlobal PicBaseReg) @@ -241,6 +254,20 @@ howToAccessLabel config _arch OSMinGW32 _kind lbl | otherwise = AccessDirectly +-- On AArch64, relocations for JUMP and CALL will be emitted with 26bits, this +-- is enough for ~64MB of range. Anything else will need to go through a veneer, +-- which is the job of the linker to build. We might only want to lookup +-- Data References through the GOT. +howToAccessLabel config ArchAArch64 _os _kind lbl + | not (ncgExternalDynamicRefs config) + = AccessDirectly + + | labelDynamic config lbl + = AccessViaSymbolPtr + + | otherwise + = AccessDirectly + -- Mach-O (Darwin, Mac OS X) -- @@ -275,7 +302,7 @@ howToAccessLabel config arch OSDarwin JumpReference lbl -- dyld code stubs don't work for tailcalls because the -- stack alignment is only right for regular calls. -- Therefore, we have to go via a symbol pointer: - | arch == ArchX86 || arch == ArchX86_64 + | arch == ArchX86 || arch == ArchX86_64 || arch == ArchAArch64 , labelDynamic config lbl = AccessViaSymbolPtr @@ -283,15 +310,15 @@ howToAccessLabel config arch OSDarwin JumpReference lbl howToAccessLabel config arch OSDarwin _kind lbl -- Code stubs are the usual method of choice for imported code; -- not needed on x86_64 because Apple's new linker, ld64, generates - -- them automatically. + -- them automatically, neither on Aarch64 (arm64). | arch /= ArchX86_64 + , arch /= ArchAArch64 , labelDynamic config lbl = AccessViaStub | otherwise = AccessDirectly - ---------------------------------------------------------------------------- -- AIX @@ -616,7 +643,9 @@ pprImportedSymbol config importedLbl = case (arch,os) of | otherwise -> empty - (_, OSDarwin) -> empty + (ArchAArch64, OSDarwin) + -> empty + -- XCOFF / AIX |