From c425c51963854f592da4b9dbccef198959619cd6 Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Sat, 29 Jun 2019 12:17:49 +0000 Subject: [PATCH] * simplify and optimize generated LLVM code for case statements git-svn-id: trunk@42305 - --- .gitattributes | 1 + compiler/llvm/llvmnode.pas | 2 +- compiler/llvm/nllvmset.pas | 53 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 compiler/llvm/nllvmset.pas diff --git a/.gitattributes b/.gitattributes index 5ab21c8878..6f44a9ab48 100644 --- a/.gitattributes +++ b/.gitattributes @@ -363,6 +363,7 @@ compiler/llvm/nllvminl.pas svneol=native#text/plain compiler/llvm/nllvmld.pas svneol=native#text/plain compiler/llvm/nllvmmat.pas svneol=native#text/plain compiler/llvm/nllvmmem.pas svneol=native#text/plain +compiler/llvm/nllvmset.pas svneol=native#text/plain compiler/llvm/nllvmtcon.pas svneol=native#text/plain compiler/llvm/nllvmutil.pas svneol=native#text/plain compiler/llvm/rgllvm.pas svneol=native#text/plain diff --git a/compiler/llvm/llvmnode.pas b/compiler/llvm/llvmnode.pas index d305633544..729225c9e0 100644 --- a/compiler/llvm/llvmnode.pas +++ b/compiler/llvm/llvmnode.pas @@ -38,7 +38,7 @@ implementation ncgadd,ncgcal,ncgmat,ncginl, tgllvm,hlcgllvm, nllvmadd,nllvmbas,nllvmcal,nllvmcnv,nllvmcon,nllvmflw,nllvminl,nllvmld, - nllvmmat,nllvmmem,nllvmtcon,nllvmutil, + nllvmmat,nllvmmem,nllvmset,nllvmtcon,nllvmutil, llvmpara,llvmpi, symllvm, llvmcfi; diff --git a/compiler/llvm/nllvmset.pas b/compiler/llvm/nllvmset.pas new file mode 100644 index 0000000000..c3470625f9 --- /dev/null +++ b/compiler/llvm/nllvmset.pas @@ -0,0 +1,53 @@ +{ + Copyright (c) 2019 by Jonas Maebe + + Generate LLVM bytecode for set/case nodes + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + **************************************************************************** +} +unit nllvmset; + +{$i fpcdefs.inc} + +interface + + uses + nset, ncgset; + + type + tllvmcasenode = class(tcgcasenode) + protected + procedure genlinearlist(hp: pcaselabel); override; + end; + + +implementation + + procedure tllvmcasenode.genlinearlist(hp: pcaselabel); + begin + { genlinearlist constantly updates the case value in the register, + which causes tons of spilling with LLVM due to the need to bring + it back into SSA form. LLVM will recognise and optimise the linear + cmp list just as well (or even better), while the code that FPC + has to generate is much smaller (no spilling) } + genlinearcmplist(hp); + end; + +begin + ccasenode:=tllvmcasenode; +end. +