Commit Graph

166 Commits

Author SHA1 Message Date
Nikolay Nikolov
a8b4c0772c * fixed bug that caused 'c in ['a'..'z']' to fail on the WebAssembly target, when code is compiled with {$packset 1} 2024-01-10 03:11:13 +02:00
Jonas Maebe
29bae2297f tcginnode.pass_generate_code: use tlhcgobj.g_undefined_ok
Also override the code that uses this for LLVM with a variant that does not
need it for LLVM versions that do not support the freeze instruction.
2023-01-20 21:07:18 +01:00
Pierre Muller
c06a3f2ca3 Avoid range check error inside tcgcasenode.pass_generate_code method 2022-01-05 16:38:54 +00:00
Yuriy Sydorov
b78761efd3 * Removed obsolete OLDREGVARS ifdefs. 2021-11-02 17:08:08 +02:00
Nikolay Nikolov
12a2c56461 - removed thlcgwasm.incblock, .decblock and br_blocks, as branching is now done
entirely with labels
2021-10-22 17:42:29 +03:00
nickysn
c4e8f091ec * generate jumpless code for the IN node for WebAssembly. TODO: this needs to be
refactored, so the WebAssembly-specific code generation code goes in the wasm
  in node descendant class.

git-svn-id: branches/wasm@48178 -
2021-01-18 22:32:35 +00:00
pierre
8fd0a27875 Avoid range check error for avr/i8086 CPU by changing local variable dist type to asizeuint
git-svn-id: trunk@42741 -
2019-08-19 20:22:22 +00:00
Jonas Maebe
ba1b4b1c92 + support for verifying whether a case statements handles all possibilities
(based on patch by Martok)
   o enabled by default in ISO and Extended Pascal: compile-time error if not
     the case in ISO mode, warning and run-time error in Extended Pascal mode
   o warning enabled by default in all other modes for boolean, enumeration and
     subrange integer types with ranges different from the default ones
     (i.e., different from 0..255, -128..127, 0..65536, etc)
   o warnings for all ordinal types can be enabled in all modes with
     -CC

git-svn-id: trunk@42047 -
2019-05-12 14:29:11 +00:00
Jonas Maebe
281b3ad276 * fix case completeness and unreachable code warnings in compiler that would
be introduced by the next commit

git-svn-id: trunk@42046 -
2019-05-12 14:29:03 +00:00
Jonas Maebe
eb71a30933 * fix false possitive tconstexprint range errors after r41441 (mantis #35144)
git-svn-id: trunk@41469 -
2019-02-25 20:48:49 +00:00
Jonas Maebe
07bd4ba517 * let all the case code generation work with tconstexprint instead of aint,
so it also works for 32 bit targets and a high level code generator
    (where aint is still 32 bit, but 64 bit operations are not decomposed)

git-svn-id: trunk@41441 -
2019-02-24 19:58:37 +00:00
Jonas Maebe
04d295f186 * first step towards supporting 32 bit targets with the LLVM code generator:
use the generic code in more cases when cpuhighleveltarget is defined

git-svn-id: trunk@41133 -
2019-01-29 21:39:09 +00:00
florian
644c47e121 * when deciding about the case code generation in case of size optimization, the number of labels is relevant, not the covered range, resolves #34818
git-svn-id: trunk@40851 -
2019-01-13 10:32:00 +00:00
florian
a2cee252e8 * when optimizing range checks in case nodes, unsigned comparisions must be used, resolves #34782
git-svn-id: trunk@40721 -
2019-01-01 01:11:13 +00:00
florian
bd4b7a6bc4 * more case fixes
git-svn-id: trunk@40706 -
2018-12-29 21:53:52 +00:00
florian
f6e32ae90e * (modified) path by Gareth Moreton to fix case handling
git-svn-id: trunk@40686 -
2018-12-28 20:56:43 +00:00
florian
7f5c2fa3aa * (modified) patch by Gareth Moreton: Speed improvement in case blocks, resolves #0034762
This patch improves the compiler where "case" statements are concerned, using jump tables more often and creating more efficient machine code in some situations:
  * If a case block only contains one branch (not including the else block), the initial range check is removed, since this becomes wasted effort.
  * If the else block is empty, the else label is set to the end label - though this doesn't decrease the code size, it takes a bit of strain off the peephole optimizer.
  * On -O2 and above, some node analysis is now done on the branch labels. Most of the time this just redirects it to the end
    label for empty blocks, but if the block contains a goto statement, it will redirect it to its destination instead,
    thus increasing performance by not having multiple jumps (this won't get picked up by the peephole optimiser if the label addresses are in a jump table).
  * Some checks now use what I call the 'true count' rather than the 'label count'. The true count includes each
    individual value in a range - for example, 0..2 counts as 3. This increases the chance that a jump table will be
    utilised in situations where it is more efficient than a linear list.
  * For jump tables, if the case block almost covers the entire range (32 entries or fewer from full coverage),
    the initial range check is removed and the gaps included in the jump table (pointing to the else label).

git-svn-id: trunk@40676 -
2018-12-27 18:31:55 +00:00
pierre
b64e9700aa Avoid range errors or overflows on for AVR cpu, when computing address offsets
git-svn-id: trunk@40378 -
2018-11-27 10:21:37 +00:00
florian
68eb921d46 * broken compilation after r39347 fixed
git-svn-id: trunk@39349 -
2018-06-30 12:30:25 +00:00
florian
f08d3fdf8f * moved execution weight calculation into a separate pass, so the info is available already available before the code generation pass if needed
git-svn-id: trunk@38717 -
2018-04-08 20:51:27 +00:00
florian
29230ebdca + added comment why the code path is not yet enabled for 16 bit
git-svn-id: trunk@38281 -
2018-02-18 09:32:54 +00:00
florian
f37bad774c * do not use 32 bit operations on 8 bit cpu in tcginnode.pass_generate_code if not needed, resolves #32071
git-svn-id: trunk@38271 -
2018-02-17 18:38:03 +00:00
florian
cc44328109 * correctly calc case label distance after r36362, resolves #32115 and #32311
git-svn-id: trunk@37390 -
2017-10-03 20:36:09 +00:00
nickysn
ddba821561 * GetNextReg(), used by 16-bit and 8-bit code generators (i8086 and avr) moved
from cpubase unit to a method in the tcg class. The reason for doing that is
  that this is now a standard part of the 16-bit and 8-bit code generators and
  moving to the tcg class allows doing extra checks (not done yet, but for
  example, in the future, we can keep track of whether there was an extra
  register allocated with getintregister and halt with an internalerror in case
  GetNextReg() is called for registers, which weren't allocated as a part of a
  sequence, therefore catching a certain class of 8-bit and 16-bit code
  generator bugs at compile time, instead of generating wrong code).
- removed GetLastReg() from avr's cpubase unit, because it isn't used for
  anything. It might be added to the tcg class, in case it's ever needed, but
  for now I've left it out.
* GetOffsetReg() and GetOffsetReg64() were also moved to the tcg unit.

git-svn-id: trunk@37180 -
2017-09-11 14:53:06 +00:00
florian
991d962ae2 * more range check errors on 8 bit CPUs fixed
git-svn-id: trunk@36362 -
2017-05-28 08:59:55 +00:00
florian
b1dff29cbf * removed unused units
git-svn-id: trunk@36165 -
2017-05-09 19:53:14 +00:00
yury
95094e9a8f * Removed unused vars.
git-svn-id: trunk@36073 -
2017-05-04 10:38:49 +00:00
florian
50dba9ad66 * if both labels of a case label are equal, we still cannot skip the comparison in a jump tree, resolves #31589
git-svn-id: trunk@35880 -
2017-04-21 19:32:27 +00:00
florian
74423b88e0 * comment on border between linear list and jmp tree for case statements extended
git-svn-id: trunk@35661 -
2017-03-26 07:36:58 +00:00
svenbarth
abc4cf21d1 * fix compiling the 64-bit compiler with a 32-bit one
git-svn-id: trunk@35654 -
2017-03-24 15:47:36 +00:00
florian
1ae90bce53 * commented how the limit for a case jmp tree had been determined
git-svn-id: trunk@35647 -
2017-03-23 18:35:48 +00:00
florian
d5754cf47c * create jmp trees for really big case statements
git-svn-id: trunk@35645 -
2017-03-23 17:50:53 +00:00
Jonas Maebe
b156744b62 * left has been forced into a register of size uopdef a few statements
above, so pass uopdef rather than left.resultdef to a_bit_test_reg_loc_reg()
    (part of fixing tests/tbs/tb0219.pp for llvm)

git-svn-id: trunk@34122 -
2016-07-14 15:20:53 +00:00
Jonas Maebe
da696057ab * converted register_maybe_adjust_setbase() to the high level code generator
git-svn-id: trunk@32591 -
2015-12-05 18:03:37 +00:00
Jonas Maebe
2ad8bc3b27 * fixed operation size of comparison with maximum legal value in
tcginnode.passs_generate_code

git-svn-id: trunk@32522 -
2015-11-24 20:10:42 +00:00
Jonas Maebe
c8a5994e2e * fixed size used for left in in_smallset (it's been forced in a register
of size opdef a few lines before)

git-svn-id: trunk@32410 -
2015-11-21 12:36:58 +00:00
Jonas Maebe
09c8c5eba0 * adjusted comment after previous commit
git-svn-id: trunk@32297 -
2015-11-12 20:58:50 +00:00
Jonas Maebe
a32605bd38 * don't force setelementn's into a 32 bit modifiable register if they were
already in a register, as this changes the result location into a size
    different from what resultdef says (and only in that specific case)
   o modified the ppc code so that it always forces a setelementn to uinttype,
     as that is the size that is expected by the operations later on

git-svn-id: trunk@32296 -
2015-11-12 20:55:33 +00:00
Jonas Maebe
175f4376bc * give an internalerror if a setelementn is range in pass_generate_code,
as those constructs should have been converted to calls to
    fpc_varset_set_range by the parent addn

git-svn-id: trunk@32293 -
2015-11-11 20:46:49 +00:00
yury
b26fa07f1a * Fixed notes "var is assigned but not used".
git-svn-id: trunk@31734 -
2015-09-17 13:03:04 +00:00
Jonas Maebe
0fc1fd6ac1 * replaced current_procinfo.currtrue/falselabel with storing the true/false
labels of LOC_JUMP in the node's location. This generates some extra jumps
    for short circuit boolean and/or-expressions if optimizations are off, but
    with optimisations enabled the generated code is the same (except for JVM
    because the jump threading optimisation isn't enabled there yet).

git-svn-id: trunk@31431 -
2015-08-27 18:28:57 +00:00
Jonas Maebe
b9d4d9b141 * corrected type passed to a_bit_test_reg_loc_reg() (we force left into
a register of size opdef before)

git-svn-id: trunk@31056 -
2015-06-13 22:48:26 +00:00
florian
fa6bea9bbb * all the cg/hlcg routines take normally tcgint constants, so replace aint constants and casts in ncgset by tcgint ones
git-svn-id: trunk@30560 -
2015-04-12 20:32:37 +00:00
Jonas Maebe
2112713579 * converted the remaining parts of tcginnode.pass_generate_code() to thlcg
git-svn-id: trunk@30370 -
2015-03-29 18:16:51 +00:00
Jonas Maebe
67b8aceaee * synchronized with privatetrunk till r30095
git-svn-id: branches/hlcgllvm@30101 -
2015-03-05 20:32:15 +00:00
Jonas Maebe
33b1732ca2 * avoid unnecessary sign/zero-extensions in genlinearlist() when generating
code on a platform that doesn't have subregisters of the same size as
    the "case" value

git-svn-id: trunk@30031 -
2015-02-28 16:46:54 +00:00
Jonas Maebe
c6ddf0001c * simplified in_smallset() and removed some old cruft (there's no need
anymore to change the register size)

git-svn-id: branches/hlcgllvm@28400 -
2014-08-12 23:17:45 +00:00
nickysn
1d4de72aa7 + 8-bit ALU support in tcgcasenode.genlinearcmplist
git-svn-id: trunk@27660 -
2014-04-26 12:41:58 +00:00
Jonas Maebe
212f4d1152 * pass the size of the set rather than of the constant to
a_bit_test_const_loc_reg() (bug in hlcgobj conversion)

git-svn-id: trunk@27606 -
2014-04-20 14:34:57 +00:00
florian
4d5119bf1c * fixes several issues which cause warnings by the dfa code when using it to detect uninitialized variables
git-svn-id: trunk@26161 -
2013-12-01 17:02:08 +00:00