Use a more efficient printer for code generation
This implements #21853 (closed).
The changes in GHC.Utils.Outputable
are the bulk of the patch and drive the rest.
The types HLine
and HDoc
in Outputable can be used instead of SDoc
and support printing directly to a handle with bPutHDoc
. See Note [SDoc versus HDoc] and Note [HLine versus HDoc].
The classes IsLine
and IsDoc
are used to make the existing code polymorphic over HLine
/HDoc
and SDoc
. This is done for X86, PPC, AArch64, DWARF and dependencies (printing module names, labels etc.).
LLVM and CmmToC are not changed yet (future work, not for this MR).
This is a new version of !8684 (closed). It does not change the Outputable
class resulting in a smaller diff. The previous version included a workaround for a specializer issue which is no longer necessary thanks to !8897 (merged).
Allocation stats:
Metrics: compile_time/bytes allocated
-------------------------------------
Baseline
Test Metric value New value Change
---------------------------------------------------------------------------------------
CoOpt_Read(normal) ghc/alloc 831,553,280 805,437,056 -3.1% GOOD
CoOpt_Singletons(normal) ghc/alloc 942,808,704 936,495,976 -0.7%
InstanceMatching(normal) ghc/alloc 5,039,936,744 5,039,969,312 +0.0%
InstanceMatching1(normal) ghc/alloc 27,518,541,912 27,518,608,832 +0.0%
LargeRecord(normal) ghc/alloc 3,022,541,584 3,004,482,528 -0.6%
ManyAlternatives(normal) ghc/alloc 730,527,112 697,267,976 -4.6% GOOD
ManyConstructors(normal) ghc/alloc 3,933,632,440 3,800,539,344 -3.4% GOOD
MultiComponentModules(normal) ghc/alloc 1,850,074,856 1,850,778,264 +0.0%
MultiComponentModulesRecomp(normal) ghc/alloc 800,403,496 801,102,120 +0.1%
MultiLayerModules(normal) ghc/alloc 3,149,500,864 3,142,164,248 -0.2%
MultiLayerModulesRecomp(normal) ghc/alloc 888,056,328 888,094,304 +0.0%
MultiLayerModulesTH_Make(normal) ghc/alloc 629,773,384 629,703,376 -0.0%
MultiLayerModulesTH_OneShot(normal) ghc/alloc 2,570,879,496 2,570,807,848 -0.0%
PmSeriesG(normal) ghc/alloc 43,658,608 43,561,304 -0.2%
PmSeriesS(normal) ghc/alloc 53,317,944 52,144,240 -2.2%
PmSeriesT(normal) ghc/alloc 75,256,672 73,132,088 -2.8%
PmSeriesV(normal) ghc/alloc 52,522,008 51,453,016 -2.0%
T10421(normal) ghc/alloc 115,532,448 113,123,680 -2.1% GOOD
T10421a(normal) ghc/alloc 83,169,512 81,409,928 -2.1%
T10547(normal) ghc/alloc 27,924,112 27,957,592 +0.1%
T10858(normal) ghc/alloc 131,456,736 129,050,816 -1.8%
T11195(normal) ghc/alloc 233,322,160 221,547,264 -5.0%
T11276(normal) ghc/alloc 95,887,152 92,755,568 -3.3%
T11303b(normal) ghc/alloc 39,897,328 39,342,904 -1.4%
T11374(normal) ghc/alloc 191,009,200 178,289,160 -6.7%
T11545(normal) ghc/alloc 84,616,832 83,657,720 -1.1%
T11822(normal) ghc/alloc 99,920,736 96,244,752 -3.7%
T12150(optasm) ghc/alloc 79,328,592 79,020,944 -0.4%
T12227(normal) ghc/alloc 480,444,704 478,828,696 -0.3%
T12234(optasm) ghc/alloc 56,030,848 55,455,832 -1.0%
T12425(optasm) ghc/alloc 88,871,832 87,530,528 -1.5% GOOD
T12545(normal) ghc/alloc 1,625,284,152 1,602,578,872 -1.4%
T12707(normal) ghc/alloc 938,892,024 852,595,624 -9.2% GOOD
T13035(normal) ghc/alloc 101,117,560 98,207,168 -2.9% GOOD
T13056(optasm) ghc/alloc 317,614,808 310,571,184 -2.2% GOOD
T13253(normal) ghc/alloc 334,910,272 327,030,072 -2.4% GOOD
T13253-spj(normal) ghc/alloc 123,823,360 121,915,024 -1.5%
T13379(normal) ghc/alloc 342,971,744 307,078,408 -10.5% GOOD
T13386(normal) ghc/alloc 875,437,088 875,387,048 -0.0%
T13701(normal) ghc/alloc 2,416,291,344 2,404,907,256 -0.5%
T13719(normal) ghc/alloc 5,137,357,632 5,109,068,296 -0.6%
T14052(ghci) ghc/alloc 3,770,574,504 3,770,607,888 +0.0%
T14052Type(ghci) ghc/alloc 6,367,970,008 6,368,003,472 +0.0%
T14683(normal) ghc/alloc 2,845,268,168 2,795,407,000 -1.8%
T14697(normal) ghc/alloc 351,325,960 350,110,088 -0.3%
T14766(normal) ghc/alloc 964,259,536 962,977,768 -0.1%
T15164(normal) ghc/alloc 1,260,193,512 1,237,701,752 -1.8%
T15304(normal) ghc/alloc 1,280,960,120 1,259,139,472 -1.7%
T15630(normal) ghc/alloc 160,161,168 156,449,176 -2.3%
T15703(normal) ghc/alloc 516,015,248 511,717,208 -0.8%
T16190(normal) ghc/alloc 273,133,888 272,244,264 -0.3%
T16577(normal) ghc/alloc 8,056,636,488 7,958,420,272 -1.2%
T16875(normal) ghc/alloc 34,625,496 34,564,952 -0.2%
T17096(normal) ghc/alloc 215,147,840 203,461,840 -5.4%
T17516(normal) ghc/alloc 1,834,054,632 1,784,382,160 -2.7%
T17836(normal) ghc/alloc 833,247,360 819,589,776 -1.6%
T17836b(normal) ghc/alloc 45,068,896 44,664,792 -0.9%
T17977(normal) ghc/alloc 40,086,128 39,613,224 -1.2%
T17977b(normal) ghc/alloc 37,845,832 37,418,176 -1.1%
T18140(normal) ghc/alloc 75,844,968 74,069,520 -2.3% GOOD
T18223(normal) ghc/alloc 481,437,080 481,383,736 -0.0%
T18282(normal) ghc/alloc 144,678,648 140,800,608 -2.7% GOOD
T18304(normal) ghc/alloc 76,450,272 75,438,392 -1.3%
T18478(normal) ghc/alloc 500,016,680 475,094,528 -5.0%
T18698a(normal) ghc/alloc 198,513,360 195,053,976 -1.7% GOOD
T18698b(normal) ghc/alloc 219,447,248 215,751,152 -1.7% GOOD
T18923(normal) ghc/alloc 66,749,128 65,601,640 -1.7%
T1969(normal) ghc/alloc 705,518,888 687,020,528 -2.6% GOOD
T19695(normal) ghc/alloc 1,408,023,752 1,387,721,568 -1.4%
T20049(normal) ghc/alloc 90,680,512 88,594,936 -2.3% GOOD
T20261(normal) ghc/alloc 596,697,264 578,682,768 -3.0%
T3064(normal) ghc/alloc 181,324,096 175,546,248 -3.2% GOOD
T3294(normal) ghc/alloc 1,623,590,312 1,275,928,896 -21.4% GOOD
T4801(normal) ghc/alloc 302,111,024 271,923,168 -10.0% GOOD
T5030(normal) ghc/alloc 352,750,000 349,055,328 -1.0%
T5321FD(normal) ghc/alloc 249,069,344 231,012,072 -7.2% GOOD
T5321Fun(normal) ghc/alloc 277,245,992 259,277,536 -6.5% GOOD
T5631(normal) ghc/alloc 527,089,048 516,347,112 -2.0% GOOD
T5642(normal) ghc/alloc 466,813,640 460,270,984 -1.4%
T5837(normal) ghc/alloc 35,470,840 35,238,720 -0.7%
T6048(optasm) ghc/alloc 99,113,544 96,606,480 -2.5% GOOD
T783(normal) ghc/alloc 380,383,592 352,082,528 -7.4% GOOD
T8095(normal) ghc/alloc 3,135,445,432 3,134,886,800 -0.0%
T9020(optasm) ghc/alloc 239,566,496 239,515,384 -0.0%
T9198(normal) ghc/alloc 45,958,648 44,044,184 -4.2% GOOD
T9233(normal) ghc/alloc 723,779,984 713,464,552 -1.4% GOOD
T9630(normal) ghc/alloc 1,019,602,544 1,004,066,056 -1.5%
T9675(optasm) ghc/alloc 447,387,848 443,947,520 -0.8%
T9872a(normal) ghc/alloc 1,668,582,640 1,668,616,120 +0.0%
T9872b(normal) ghc/alloc 1,931,935,472 1,931,968,952 +0.0%
T9872b_defer(normal) ghc/alloc 2,965,686,904 2,965,297,688 -0.0%
T9872c(normal) ghc/alloc 1,629,251,392 1,629,284,872 +0.0%
T9872d(normal) ghc/alloc 398,986,832 397,809,880 -0.3%
T9961(normal) ghc/alloc 366,940,200 364,768,712 -0.6%
TcPlugin_RewritePerf(normal) ghc/alloc 2,125,166,056 2,123,237,424 -0.1%
WWRec(normal) ghc/alloc 565,973,328 559,910,376 -1.1%
hard_hole_fits(normal) ghc/alloc 419,150,528 419,579,496 +0.1%
hie002(normal) ghc/alloc 9,162,506,272 9,162,539,760 +0.0%
parsing001(normal) ghc/alloc 451,733,440 451,766,928 +0.0%
geo. mean -2.1%
minimum -21.4%
maximum +0.1%
Co-authored-by: Alexis King lexi.lambda@gmail.com