Changeset 0fa0201d for doc/proposals
- Timestamp:
- Dec 16, 2023, 1:01:32 AM (12 months ago)
- Branches:
- master
- Children:
- 5546eee4
- Parents:
- dc80280
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/proposals/enum.tex
rdc80280 r0fa0201d 232 232 233 233 \subsection{Enumeration Data} 234 It is a work in progress, outlined the idea but will update with more information later... 235 A \CFA enumeration is backed by data structures to store necessary data. Specifically, an enumeration has arrays to store its labels and values. 236 \begin{lstlisting}[label=lst:enumeration_back_data] 237 enum(T) E; 234 \begin{lstlisting}[label=lst:enumeration_backing_data] 235 enum(T) E { ... }; 238 236 // backing data 239 237 T* E_values; 240 238 char** E_labels; 241 239 \end{lstlisting} 242 Depending on the use cases, the value and label array might not be necessary to the program. 240 Storing values and labels as arrays can sometimes help support enumeration features. However, the data structures are the overhead for the programs. We want to reduce the memory usage for enumeration support by: 241 \begin{itemize} 242 \item Only generates the data array if necessary 243 \item The compilation units share the data structures. No extra overhead if the data structures are requested multiple times. 244 \end{itemize} 245 246 247 \subsection{Aggressive Inline} 248 To avoid allocating memory for enumeration data structures, \CFA inline the result of enumeration attribute pseudo-function whenever it is possible. 249 \begin{lstlisting}[label=lst:enumeration_inline] 250 enum(int) OddNumber { A=1, B=3 }; 251 sout | "A: " | OddNumber.A | "B: " | OddNumber.B | "A+B: " | OddNumber.A + OddNumber.B 252 \end{lstlisting} 253 Instead of calling pseudo-function @value@ on expression $OddNumber.A$ and $OddNumber.B$, because the result is known statistically, \CFA will inline the constant expression 1 and 3, respectively. Because no runtime lookup for enumeration value is necessary, \CFA will not generate data structure for enumeration OddNumber. 243 254 244 255 \subsection{Weak Reference} 245 If the value and label need to be determined at the runtime, the data arrays are necessary. However, allocating the attribute arrays in every compilation unit can take up a lot of memory and it is not ideal. \CFA Optimized it by using GCC weak reference ( @__attribute(weak)__@ ). 246 247 \subsection{Aggressive Inline} 248 If the label and value can be determined during the compilation, \CFA can inline the attributes and no allocation is needed. 256 \begin{lstlisting}[label=lst:week_ref] 257 enum(int) OddNumber { A=1, B=3 }; 258 enum OddNumber i = ...; 259 ... 260 sout | OddNumber; 261 \end{lstlisting} 262 In this example, \CFA cannot determine the static value of the enum variable i, and Runtime lookup is necessary. The OddNumber can be referenced in multiple compilations, and allocating the arrays in all compilation units is not desirable. \CFA addresses this by declaring the value array as a weak reference. All compilation units reference OddNumber have weak references to the same enumeration data structure. No extra memory is allocated if more compilation units reference OddNumber, and the OddNumber is initialized once. 249 263 250 264 \section{Unification}
Note: See TracChangeset
for help on using the changeset viewer.