source: src/ResolvExpr/Cost.h @ e6cee92

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since e6cee92 was 7ebaa56, checked in by Rob Schluntz <rschlunt@…>, 7 years ago

Add reference cost field to cost tuple

  • Property mode set to 100644
File size: 3.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// Cost.h --
8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 09:39:50 2015
11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Jul 22 16:43:10 2015
13// Update Count     : 4
14//
15
16#ifndef COST_H
17#define COST_H
18
19#include <iostream>
20
21namespace ResolvExpr {
22        class Cost {
23          private:
24                Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost );
25
26          public:
27                Cost & incUnsafe( int inc = 1 );
28                Cost & incPoly( int inc = 1 );
29                Cost & incSafe( int inc = 1 );
30                Cost & incReference( int inc = 1 );
31
32                Cost operator+( const Cost &other ) const;
33                Cost operator-( const Cost &other ) const;
34                Cost &operator+=( const Cost &other );
35                bool operator<( const Cost &other ) const;
36                bool operator==( const Cost &other ) const;
37                bool operator!=( const Cost &other ) const;
38                friend std::ostream &operator<<( std::ostream &os, const Cost &cost );
39
40                static const Cost zero;
41                static const Cost infinity;
42
43                static const Cost unsafe;
44                static const Cost poly;
45                static const Cost safe;
46                static const Cost reference;
47          private:
48                int compare( const Cost &other ) const;
49
50                int unsafeCost;
51                int polyCost;
52                int safeCost;
53                int referenceCost;
54        };
55
56        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {}
57
58        inline Cost & Cost::incUnsafe( int inc ) {
59                unsafeCost += inc;
60                return *this;
61        }
62
63        inline Cost & Cost::incPoly( int inc ) {
64                polyCost += inc;
65                return *this;
66        }
67
68        inline Cost & Cost::incSafe( int inc ) {
69                safeCost += inc;
70                return *this;
71        }
72
73        inline Cost & Cost::incReference( int inc ) {
74                referenceCost += inc;
75                return *this;
76        }
77
78        inline Cost Cost::operator+( const Cost &other ) const {
79                return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost );
80        }
81
82        inline Cost Cost::operator-( const Cost &other ) const {
83                return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost );
84        }
85
86        inline Cost &Cost::operator+=( const Cost &other ) {
87                unsafeCost += other.unsafeCost;
88                polyCost += other.polyCost;
89                safeCost += other.safeCost;
90                referenceCost += other.referenceCost;
91                return *this;
92        }
93
94        inline bool Cost::operator<( const Cost &other ) const {
95                if ( *this == infinity ) return false;
96                if ( other == infinity ) return true;
97
98                if ( unsafeCost > other.unsafeCost ) {
99                        return false;
100                } else if ( unsafeCost < other.unsafeCost ) {
101                        return true;
102                } else if ( polyCost > other.polyCost ) {
103                        return false;
104                } else if ( polyCost < other.polyCost ) {
105                        return true;
106                } else if ( safeCost > other.safeCost ) {
107                        return false;
108                } else if ( safeCost < other.safeCost ) {
109                        return true;
110                } else if ( referenceCost > other.referenceCost ) {
111                        return false;
112                } else if ( referenceCost < other.referenceCost ) {
113                        return true;
114                } else {
115                        return false;
116                } // if
117        }
118
119        inline bool Cost::operator==( const Cost &other ) const {
120                return unsafeCost == other.unsafeCost
121                        && polyCost == other.polyCost
122                        && safeCost == other.safeCost
123                        && referenceCost == other.referenceCost;
124        }
125
126        inline bool Cost::operator!=( const Cost &other ) const {
127                return !( *this == other );
128        }
129
130        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
131                os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )";
132                return os;
133        }
134} // namespace ResolvExpr
135
136#endif // COST_H
137
138// Local Variables: //
139// tab-width: 4 //
140// mode: c++ //
141// compile-command: "make install" //
142// End: //
Note: See TracBrowser for help on using the repository browser.