From da54d0e8f7efb83515a85c84b49c9311001f777f Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 20 Nov 2019 22:12:27 +0000 Subject: [PATCH] + patch by J. Gareth Moreton: new method TAOptObj.CanDoJumpOpts and arm specific implementation git-svn-id: trunk@43519 - --- compiler/aoptobj.pas | 44 +++++++++++++++++++++++----------------- compiler/arm/aoptcpu.pas | 13 ++++++++++++ 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/compiler/aoptobj.pas b/compiler/aoptobj.pas index aa4a870ffc..45241a9734 100644 --- a/compiler/aoptobj.pas +++ b/compiler/aoptobj.pas @@ -401,6 +401,9 @@ Unit AoptObj; function OptimizeConditionalJump(CJLabel: TAsmLabel; var p: tai; hp1: tai; var stoploop: Boolean): Boolean; {$endif JVM} + { Function to determine if the jump optimisations can be performed } + function CanDoJumpOpts: Boolean; virtual; + { Jump/label optimisation entry method } function DoJumpOptimizations(var p: tai; var stoploop: Boolean): Boolean; @@ -2105,6 +2108,13 @@ Unit AoptObj; end; + function TAOptObj.CanDoJumpOpts: Boolean; + begin + { Always allow by default } + Result := True; + end; + + function TAOptObj.DoJumpOptimizations(var p: tai; var stoploop: Boolean): Boolean; var hp1, hp2: tai; @@ -2356,8 +2366,10 @@ Unit AoptObj; procedure TAOptObj.PeepHoleOptPass1; var p,hp1,hp2,hp3 : tai; - stoploop, FirstInstruction: boolean; + stoploop, FirstInstruction, JumpOptsAvailable: boolean; begin + JumpOptsAvailable := CanDoJumpOpts(); + StartPoint := BlockStart; repeat @@ -2379,25 +2391,19 @@ Unit AoptObj; InsertLLItem(tai(p.Previous),p,tai_comment.create(strpnew(GetAllocationString(UsedRegs)))); {$endif DEBUG_OPTALLOC} - { Handle Jmp Optimizations first } -{$if defined(ARM)} - { Cannot perform these jump optimisations if the ARM architecture has 16-bit thumb codes } - if not ( - (current_settings.instructionset = is_thumb) and not(CPUARM_HAS_THUMB2 in cpu_capabilities[current_settings.cputype]) - ) then -{$endif defined(ARM)} - if DoJumpOptimizations(p, stoploop) then - begin - UpdateUsedRegs(p); - if FirstInstruction then - { Update StartPoint, since the old p was removed; - don't set FirstInstruction to False though, as - the new p might get removed too. } - StartPoint := p; + { Handle jump optimizations first } + if JumpOptsAvailable and DoJumpOptimizations(p, stoploop) then + begin + UpdateUsedRegs(p); + if FirstInstruction then + { Update StartPoint, since the old p was removed; + don't set FirstInstruction to False though, as + the new p might get removed too. } + StartPoint := p; - if (p.typ = ait_instruction) and IsJumpToLabel(taicpu(p)) then - Continue; - end; + if (p.typ = ait_instruction) and IsJumpToLabel(taicpu(p)) then + Continue; + end; if PeepHoleOptPass1Cpu(p) then begin diff --git a/compiler/arm/aoptcpu.pas b/compiler/arm/aoptcpu.pas index 487fe349ab..107cfdb69d 100644 --- a/compiler/arm/aoptcpu.pas +++ b/compiler/arm/aoptcpu.pas @@ -34,6 +34,9 @@ uses cgbase, cgutils, cpubase, aasmtai, aasmcpu,aopt, aoptobj; Type TCpuAsmOptimizer = class(TAsmOptimizer) + { Can't be done in some cases due to the limited range of jumps } + function CanDoJumpOpts: Boolean; override; + { uses the same constructor as TAopObj } function PeepHoleOptPass1Cpu(var p: tai): boolean; override; procedure PeepHoleOptPass2;override; @@ -379,6 +382,16 @@ Implementation end; {$endif DEBUG_AOPTCPU} + + function TCpuAsmOptimizer.CanDoJumpOpts: Boolean; + begin + { Cannot perform these jump optimisations if the ARM architecture has 16-bit thumb codes } + Result := not ( + (current_settings.instructionset = is_thumb) and not (CPUARM_HAS_THUMB2 in cpu_capabilities[current_settings.cputype]) + ); + end; + + function TCpuAsmOptimizer.RemoveSuperfluousMove(const p: tai; movp: tai; const optimizer: string):boolean; var alloc,