OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [CC64/] [source/] [CSE.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
// ============================================================================
2
//        __
3
//   \\__/ o\    (C) 2017-2018  Robert Finch, Waterloo
4
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
// CC64 - 'C' derived language compiler
9
//  - 64 bit CPU
10
//
11
// This source file is free software: you can redistribute it and/or modify 
12
// it under the terms of the GNU Lesser General Public License as published 
13
// by the Free Software Foundation, either version 3 of the License, or     
14
// (at your option) any later version.                                      
15
//                                                                          
16
// This source file is distributed in the hope that it will be useful,      
17
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
18
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
19
// GNU General Public License for more details.                             
20
//                                                                          
21
// You should have received a copy of the GNU General Public License        
22
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
23
//                                                                          
24
// ============================================================================
25
//
26
#include "stdafx.h"
27
 
28
//
29
// Returns the desirability of optimization for a subexpression.
30
//
31
// Immediate constants have low priority because small constants
32
// can be directly encoded in the instruction. There's no value to
33
// placing them in registers.
34
 
35
int CSE::OptimizationDesireability()
36
{
37
        if (exp==nullptr)
38
                return (0);
39
        if( voidf || (exp->nodetype == en_icon &&
40
                       exp->i < 32768 && exp->i >= -32768))
41
        return (0);
42
 /* added this line to disable register optimization of global variables.
43
    The compiler would assign a register to a global variable ignoring
44
    the fact that the value might change due to a subroutine call.
45
  */
46
        if (exp->nodetype == en_nacon)
47
                return (0);
48
        // No value to optimizing function call names, the called function
49
        // address will typically fit in a single 32/48 bit opcode. It's faster
50
        // to call a fixed label rather than an address in a register, because
51
        // the address is known at the fetch phase of the processor. A register
52
        // based address may be predicted by the processor and so is almost as
53
        // fast. Storing the address in a register can reduce the size of code.
54
        // If the function name can be optimized to a register then
55
        // a 16-bit compressed JAL can be used.
56
        if (exp->nodetype == en_cnacon && !opt_size)
57
                return (0);
58
        if (exp->isVolatile)
59
                return (0);
60
        // Prevent Inline code from being allocated a pointer in a register.
61
        if (exp->sym) {
62
                if (exp->sym->fi) {
63
                        if (exp->sym->fi->IsInline)
64
                                return (0);
65
                }
66
        }
67
        // Left values are worth more to optimization than right values.
68
    if( IsLValue(exp) )
69
            return (2 * uses);
70
    return (uses);
71
}
72
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.