Skip to content

Commit 315446d

Browse files
committed
Add [PATCH] AArch64: Fix broken conditional jumps for offsets >= 1MB
This is added for aarch64 for now only as that's the only affeted platform.
1 parent eb3d141 commit 315446d

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

overlays/bootstrap.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ in {
298298
# this one is to allow linking extra symbols from iserv.
299299
++ final.lib.optional (versionAtLeast "9.6.1" && versionLessThan"9.10" && final.stdenv.targetPlatform.isAndroid) ./patches/ghc/iserv-syms.patch
300300
++ final.lib.optional (versionAtLeast "9.4" && final.stdenv.targetPlatform.isWindows) ./patches/ghc/ghc-9.6-fix-code-symbol-jumps.patch
301-
++ final.lib.optional (versionAtLeast "9.6.3" && versionLessThan "9.10" && final.stdenv.targetPlatform.isAndroid) ./patches/ghc/ghc-9.6-iog.patch ./patches/ghc/iserv-syms.patch
301+
++ final.lib.optional (versionAtLeast "9.6.3" && versionLessThan "9.10" && final.stdenv.targetPlatform.isAndroid) ./patches/ghc/ghc-9.6-iog.patch
302302
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.12" && final.stdenv.targetPlatform.is32bit) ./patches/ghc/ghc-9.6-genapply-cross-arch.patch
303303
;
304304
in ({

overlays/patches/ghc/2adc050857a9c1b992040fbfd55fbe65b2851b19.patch

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ index 1d489178673..a251370bfaf 100644
2626
+++ b/compiler/GHC/CmmToAsm.hs
2727
@@ -655,13 +655,14 @@ cmmNativeGen logger ncgImpl us fileIds dbgMap cmm count
2828
text "cfg not in lockstep") ()
29-
29+
3030
---- sequence blocks
3131
- let sequenced :: [NatCmmDecl statics instr]
3232
- sequenced =
@@ -43,20 +43,20 @@ index 1d489178673..a251370bfaf 100644
4343
+ shorted
4444
+
4545
+ -- massert (checkLayout shorted sequenced)
46-
46+
4747
let branchOpt :: [NatCmmDecl statics instr]
4848
branchOpt =
4949
@@ -684,7 +685,7 @@ cmmNativeGen logger ncgImpl us fileIds dbgMap cmm count
5050
addUnwind acc proc =
5151
acc `mapUnion` computeUnwinding config ncgImpl proc
52-
52+
5353
- return ( usAlloc
5454
+ return ( us_seq
5555
, fileIds'
5656
, branchOpt
5757
, lastMinuteImports ++ imports
5858
@@ -704,10 +705,10 @@ maybeDumpCfg logger (Just cfg) msg proc_name
59-
59+
6060
-- | Make sure all blocks we want the layout algorithm to place have been placed.
6161
checkLayout :: [NatCmmDecl statics instr] -> [NatCmmDecl statics instr]
6262
- -> [NatCmmDecl statics instr]
@@ -94,7 +94,7 @@ index b77aa73e52b..2a1fa03b1bc 100644
9494
, generateJumpTableForInstr
9595
+ , makeFarBranches
9696
)
97-
97+
9898
where
9999
@@ -43,9 +44,11 @@ import GHC.Cmm.Utils
100100
import GHC.Cmm.Switch
@@ -105,7 +105,7 @@ index b77aa73e52b..2a1fa03b1bc 100644
105105
import GHC.Types.Tickish ( GenTickish(..) )
106106
import GHC.Types.SrcLoc ( srcSpanFile, srcSpanStartLine, srcSpanStartCol )
107107
+import GHC.Types.Unique.Supply
108-
108+
109109
-- The rest:
110110
import GHC.Data.OrdList
111111
@@ -61,6 +64,9 @@ import GHC.Data.FastString
@@ -115,21 +115,21 @@ index b77aa73e52b..2a1fa03b1bc 100644
115115
+import GHC.Utils.Monad (mapAccumLM)
116116
+
117117
+import GHC.Cmm.Dataflow.Collections
118-
118+
119119
-- Note [General layout of an NCG]
120120
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
121121
@@ -161,15 +167,17 @@ basicBlockCodeGen block = do
122122
let
123123
(top,other_blocks,statics) = foldrOL mkBlocks ([],[],[]) instrs
124-
124+
125125
- mkBlocks (NEWBLOCK id) (instrs,blocks,statics)
126126
- = ([], BasicBlock id instrs : blocks, statics)
127127
- mkBlocks (LDATA sec dat) (instrs,blocks,statics)
128128
- = (instrs, blocks, CmmData sec dat:statics)
129129
- mkBlocks instr (instrs,blocks,statics)
130130
- = (instr:instrs, blocks, statics)
131131
return (BasicBlock id top : other_blocks, statics)
132-
132+
133133
-
134134
+mkBlocks :: Instr
135135
+ -> ([Instr], [GenBasicBlock Instr], [GenCmmDecl RawCmmStatics h g])
@@ -144,7 +144,7 @@ index b77aa73e52b..2a1fa03b1bc 100644
144144
-- | Utilities
145145
ann :: SDoc -> Instr -> Instr
146146
@@ -1217,6 +1225,7 @@ assignReg_FltCode = assignReg_IntCode
147-
147+
148148
-- -----------------------------------------------------------------------------
149149
-- Jumps
150150
+
@@ -154,7 +154,7 @@ index b77aa73e52b..2a1fa03b1bc 100644
154154
@@ -1302,6 +1311,22 @@ genCondJump bid expr = do
155155
_ -> pprPanic "AArch64.genCondJump:case mop: " (text $ show expr)
156156
_ -> pprPanic "AArch64.genCondJump: " (text $ show expr)
157-
157+
158158
+-- A conditional jump with at least +/-128M jump range
159159
+genCondFarJump :: MonadUnique m => Cond -> Target -> m InstrBlock
160160
+genCondFarJump cond far_target = do
@@ -171,7 +171,7 @@ index b77aa73e52b..2a1fa03b1bc 100644
171171
+ , NEWBLOCK jmp_lbl_id
172172
+ , B far_target
173173
+ , NEWBLOCK skip_lbl_id]
174-
174+
175175
genCondBranch
176176
:: BlockId -- the source of the jump
177177
@@ -1816,3 +1841,163 @@ genCCall target dest_regs arg_regs bid = do
@@ -344,12 +344,12 @@ index 687daccfda1..7efbb9c70bf 100644
344344
+++ b/compiler/GHC/CmmToAsm/AArch64/Cond.hs
345345
@@ -1,6 +1,6 @@
346346
module GHC.CmmToAsm.AArch64.Cond where
347-
347+
348348
-import GHC.Prelude
349349
+import GHC.Prelude hiding (EQ)
350-
350+
351351
-- https://developer.arm.com/documentation/den0024/a/the-a64-instruction-set/data-processing-instructions/conditional-instructions
352-
352+
353353
@@ -60,7 +60,13 @@ data Cond
354354
| UOGE -- b.pl
355355
| UOGT -- b.hi
@@ -374,8 +374,8 @@ index d8dd1a4dc0c..1fb8193612f 100644
374374
| TLabel CLabel
375375
| TReg Reg
376376
+ deriving (Eq, Ord)
377-
378-
377+
378+
379379
-- Extension
380380
diff --git a/compiler/GHC/CmmToAsm/AArch64/Ppr.hs b/compiler/GHC/CmmToAsm/AArch64/Ppr.hs
381381
index fd56d37cd39..c672c342376 100644
@@ -384,12 +384,12 @@ index fd56d37cd39..c672c342376 100644
384384
@@ -1,7 +1,7 @@
385385
{-# OPTIONS_GHC -fno-warn-orphans #-}
386386
{-# LANGUAGE CPP #-}
387-
387+
388388
-module GHC.CmmToAsm.AArch64.Ppr (pprNatCmmDecl, pprInstr) where
389389
+module GHC.CmmToAsm.AArch64.Ppr (pprNatCmmDecl, pprInstr, pprBasicBlock) where
390-
390+
391391
import GHC.Prelude hiding (EQ)
392-
392+
393393
@@ -353,7 +353,10 @@ pprInstr platform instr = case instr of
394394
-> line (text "\t.loc" <+> int file <+> int line' <+> int col)
395395
DELTA d -> dualDoc (asmComment $ text "\tdelta = " <> int d) empty
@@ -400,17 +400,17 @@ index fd56d37cd39..c672c342376 100644
400400
+ -- print it for debugging purposes.
401401
+ line (text "BLOCK " <> pprAsmLabel platform (blockLbl blockid))
402402
LDATA _ _ -> panic "pprInstr: LDATA"
403-
403+
404404
-- Pseudo Instructions -------------------------------------------------------
405405
@@ -567,7 +570,7 @@ pprCond c = case c of
406406
UGE -> text "hs" -- Carry set/unsigned higher or same ; Greater than or equal, or unordered
407407
UGT -> text "hi" -- Unsigned higher ; Greater than, or unordered
408-
408+
409409
- NEVER -> text "nv" -- Never
410410
+ -- NEVER -> text "nv" -- Never
411411
VS -> text "vs" -- Overflow ; Unordered (at least one NaN operand)
412412
VC -> text "vc" -- No overflow ; Not unordered
413-
413+
414414
diff --git a/compiler/GHC/CmmToAsm/BlockLayout.hs b/compiler/GHC/CmmToAsm/BlockLayout.hs
415415
index fa0929348ce..e2096c90209 100644
416416
--- a/compiler/GHC/CmmToAsm/BlockLayout.hs
@@ -420,7 +420,7 @@ index fa0929348ce..e2096c90209 100644
420420
import Control.Monad (foldM, unless)
421421
import GHC.Data.UnionFind
422422
+import GHC.Types.Unique.Supply (UniqSM)
423-
423+
424424
{-
425425
Note [CFG based code layout]
426426
@@ -794,29 +795,32 @@ sequenceTop
@@ -476,7 +476,7 @@ index fa0929348ce..e2096c90209 100644
476476
+ far_blocks <- (ncgMakeFarBranches ncgImpl) platform info seq_blocks
477477
+ pure $ CmmProc info lbl live $ ListGraph far_blocks
478478
+
479-
479+
480480
-- The old algorithm:
481481
-- It is very simple (and stupid): We make a graph out of
482482
diff --git a/compiler/GHC/CmmToAsm/Monad.hs b/compiler/GHC/CmmToAsm/Monad.hs
@@ -508,7 +508,7 @@ index 3fedcc1fc40..8682d1db9d8 100644
508508
+++ b/compiler/GHC/CmmToAsm/PPC/Instr.hs
509509
@@ -688,12 +688,13 @@ takeRegRegMoveInstr _ = Nothing
510510
-- big, we have to work around this limitation.
511-
511+
512512
makeFarBranches
513513
- :: LabelMap RawCmmStatics
514514
+ :: Platform
@@ -538,6 +538,6 @@ index a82674afe8f..a13fa2e4656 100644
538538
, extractUnwindPoints = X86.extractUnwindPoints
539539
, invertCondBranches = X86.invertCondBranches
540540
}
541-
--
541+
--
542542
GitLab
543543

0 commit comments

Comments
 (0)