source: src/ResolvExpr/Cost.h @ 9a34b5a

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 9a34b5a 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
RevLine 
[a32b204]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//
[b46e3bd]7// Cost.h --
[a32b204]8//
9// Author           : Richard C. Bilson
10// Created On       : Sun May 17 09:39:50 2015
[5aa708c]11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Jul 22 16:43:10 2015
13// Update Count     : 4
[a32b204]14//
15
16#ifndef COST_H
17#define COST_H
[51b7345]18
19#include <iostream>
20
21namespace ResolvExpr {
[a32b204]22        class Cost {
[89be1c68]23          private:
[7ebaa56]24                Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost );
[b46e3bd]25
[89be1c68]26          public:
27                Cost & incUnsafe( int inc = 1 );
28                Cost & incPoly( int inc = 1 );
29                Cost & incSafe( int inc = 1 );
[7ebaa56]30                Cost & incReference( int inc = 1 );
[b46e3bd]31
[a32b204]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 );
[b46e3bd]39
[a32b204]40                static const Cost zero;
41                static const Cost infinity;
[7ebaa56]42
[b46e3bd]43                static const Cost unsafe;
44                static const Cost poly;
45                static const Cost safe;
[7ebaa56]46                static const Cost reference;
[a32b204]47          private:
48                int compare( const Cost &other ) const;
49
[b46e3bd]50                int unsafeCost;
51                int polyCost;
52                int safeCost;
[7ebaa56]53                int referenceCost;
[a32b204]54        };
55
[7ebaa56]56        inline Cost::Cost( int unsafeCost, int polyCost, int safeCost, int referenceCost ) : unsafeCost( unsafeCost ), polyCost( polyCost ), safeCost( safeCost ), referenceCost( referenceCost ) {}
[a32b204]57
[89be1c68]58        inline Cost & Cost::incUnsafe( int inc ) {
[b46e3bd]59                unsafeCost += inc;
[89be1c68]60                return *this;
[a32b204]61        }
62
[89be1c68]63        inline Cost & Cost::incPoly( int inc ) {
[b46e3bd]64                polyCost += inc;
[89be1c68]65                return *this;
[a32b204]66        }
67
[89be1c68]68        inline Cost & Cost::incSafe( int inc ) {
[b46e3bd]69                safeCost += inc;
[89be1c68]70                return *this;
[a32b204]71        }
72
[7ebaa56]73        inline Cost & Cost::incReference( int inc ) {
74                referenceCost += inc;
75                return *this;
76        }
77
[a32b204]78        inline Cost Cost::operator+( const Cost &other ) const {
[7ebaa56]79                return Cost( unsafeCost + other.unsafeCost, polyCost + other.polyCost, safeCost + other.safeCost, referenceCost + other.referenceCost );
[a32b204]80        }
81
82        inline Cost Cost::operator-( const Cost &other ) const {
[7ebaa56]83                return Cost( unsafeCost - other.unsafeCost, polyCost - other.polyCost, safeCost - other.safeCost, referenceCost - other.referenceCost );
[a32b204]84        }
85
86        inline Cost &Cost::operator+=( const Cost &other ) {
[b46e3bd]87                unsafeCost += other.unsafeCost;
88                polyCost += other.polyCost;
89                safeCost += other.safeCost;
[7ebaa56]90                referenceCost += other.referenceCost;
[a32b204]91                return *this;
92        }
93
94        inline bool Cost::operator<( const Cost &other ) const {
[b46e3bd]95                if ( *this == infinity ) return false;
96                if ( other == infinity ) return true;
97
98                if ( unsafeCost > other.unsafeCost ) {
[a32b204]99                        return false;
[b46e3bd]100                } else if ( unsafeCost < other.unsafeCost ) {
[a32b204]101                        return true;
[b46e3bd]102                } else if ( polyCost > other.polyCost ) {
[a32b204]103                        return false;
[b46e3bd]104                } else if ( polyCost < other.polyCost ) {
[a32b204]105                        return true;
[b46e3bd]106                } else if ( safeCost > other.safeCost ) {
[a32b204]107                        return false;
[b46e3bd]108                } else if ( safeCost < other.safeCost ) {
[a32b204]109                        return true;
[7ebaa56]110                } else if ( referenceCost > other.referenceCost ) {
111                        return false;
112                } else if ( referenceCost < other.referenceCost ) {
113                        return true;
[b46e3bd]114                } else {
[a32b204]115                        return false;
[b46e3bd]116                } // if
[d9a0e76]117        }
118
[a32b204]119        inline bool Cost::operator==( const Cost &other ) const {
[b46e3bd]120                return unsafeCost == other.unsafeCost
121                        && polyCost == other.polyCost
[7ebaa56]122                        && safeCost == other.safeCost
123                        && referenceCost == other.referenceCost;
[a32b204]124        }
[d9a0e76]125
[a32b204]126        inline bool Cost::operator!=( const Cost &other ) const {
127                return !( *this == other );
128        }
[d9a0e76]129
[a32b204]130        inline std::ostream &operator<<( std::ostream &os, const Cost &cost ) {
[7ebaa56]131                os << "( " << cost.unsafeCost << ", " << cost.polyCost << ", " << cost.safeCost << ", " << cost.referenceCost << " )";
[a32b204]132                return os;
133        }
[51b7345]134} // namespace ResolvExpr
135
[a32b204]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.