Enzyme main
Loading...
Searching...
No Matches
BaseType.h
Go to the documentation of this file.
1//===- BaseType.h - Category of type used in Type Analysis ------------===//
2//
3// Enzyme Project
4//
5// Part of the Enzyme Project, under the Apache License v2.0 with LLVM
6// Exceptions. See https://llvm.org/LICENSE.txt for license information.
7// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8//
9// If using this code in an academic setting, please cite the following:
10// @incollection{enzymeNeurips,
11// title = {Instead of Rewriting Foreign Code for Machine Learning,
12// Automatically Synthesize Fast Gradients},
13// author = {Moses, William S. and Churavy, Valentin},
14// booktitle = {Advances in Neural Information Processing Systems 33},
15// year = {2020},
16// note = {To appear in},
17// }
18//
19//===----------------------------------------------------------------------===//
20//
21// This file contains the implementation of an enum representing the potential
22// types used in Type Analysis
23//
24//===----------------------------------------------------------------------===//
25#ifndef ENZYME_TYPE_ANALYSIS_BASE_TYPE_H
26#define ENZYME_TYPE_ANALYSIS_BASE_TYPE_H 1
27
28#include "llvm/ADT/StringRef.h"
29#include <string>
30
31/// Categories of potential types
32enum class BaseType {
33 // integral type which doesn't represent a pointer
34 Integer,
35 // floating point
36 Float,
37 // pointer
38 Pointer,
39 // can be anything of users choosing [usually result of a constant such as 0]
41 // insufficient information
43};
44
45/// Convert Basetype to string
46static inline std::string to_string(BaseType t) {
47 switch (t) {
49 return "Integer";
50 case BaseType::Float:
51 return "Float";
53 return "Pointer";
55 return "Anything";
57 return "Unknown";
58 }
59 assert(0 && "unknown inttype");
60 return "<Invalid IntType>";
61}
62
63/// Convert string to BaseType
64static inline BaseType parseBaseType(llvm::StringRef str) {
65 if (str == "Integer")
66 return BaseType::Integer;
67 if (str == "Float")
68 return BaseType::Float;
69 if (str == "Pointer")
70 return BaseType::Pointer;
71 if (str == "Anything")
72 return BaseType::Anything;
73 if (str == "Unknown")
74 return BaseType::Unknown;
75 assert(0 && "Unknown BaseType string");
76 return BaseType::Unknown;
77}
78#endif
static BaseType parseBaseType(llvm::StringRef str)
Convert string to BaseType.
Definition BaseType.h:64
static std::string to_string(BaseType t)
Convert Basetype to string.
Definition BaseType.h:46
BaseType
Categories of potential types.
Definition BaseType.h:32
static std::string str(AugmentedStruct c)
Definition EnzymeLogic.h:62