Proteus
Programmable JIT compilation and optimization for C/C++ using LLVM
Loading...
Searching...
No Matches
CompilerInterfaceRuntimeConstantInfo.h
Go to the documentation of this file.
1#ifndef PROTEUS_COMPILER_INTERFACE_RUNTIME_CONSTANT_INFO_H
2#define PROTEUS_COMPILER_INTERFACE_RUNTIME_CONSTANT_INFO_H
3
4#include <optional>
5
7#include "proteus/Error.h"
9
10namespace proteus {
11
12using namespace llvm;
13
14// This struct holds the information passed from the compiler pass for a runtime
15// constant argument to a function.
23
24// This struct holds the information from the compiler pass for a runtime
25// constant array, that is the number of elements, if a known compile time
26// constant, or a runtime constant argument as the number of elements, and the
27// element type.
29 int32_t NumElts = 0;
31
32 std::optional<RuntimeConstantArgInfo> OptNumEltsRCInfo = std::nullopt;
33
38 RuntimeConstantType NumEltsType,
39 int32_t NumEltsPos)
41 OptNumEltsRCInfo{RuntimeConstantArgInfo{NumEltsType, NumEltsPos}} {}
42};
43
44// This struct holds the information from the compiler pass for a runtime
45// constant object assumed trivially copyable, that is the size of the object
46// and whether it is passed by value.
54
55// This struct holds the information from the compiler pass for a runtime
56// constant, be it a scalar or an array. If the runtime constant is an array,
57// there is an optional variable to store the runtime constant array info.
60 std::optional<RuntimeConstantArrayInfo> OptArrInfo = std::nullopt;
61 std::optional<RuntimeConstantObjectInfo> OptObjInfo = std::nullopt;
62
64 : ArgInfo{Type, Pos} {
66 PROTEUS_FATAL_ERROR("Missing array info");
67 }
68
70 int32_t NumElts, RuntimeConstantType EltType)
71 : ArgInfo{Type, Pos},
73 if ((Type != RuntimeConstantType::ARRAY) &&
76 PROTEUS_FATAL_ERROR("Expected array runtime constant but type is " +
77 toString(Type));
78 }
79
81 RuntimeConstantType EltType,
82 RuntimeConstantType NumEltsType,
83 int32_t NumEltsPos)
84 : ArgInfo{Type, Pos},
85 OptArrInfo{RuntimeConstantArrayInfo{EltType, NumEltsType, NumEltsPos}} {
87 PROTEUS_FATAL_ERROR("Expected array runtime constant but type is " +
88 std::to_string(Type));
89 }
90
92 int32_t Size, bool PassByValue)
93 : ArgInfo{Type, Pos},
94 OptObjInfo{RuntimeConstantObjectInfo{Size, PassByValue}} {
96 PROTEUS_FATAL_ERROR("Expected object runtime constant but type is " +
97 std::to_string(Type));
98 }
99
100 bool operator==(const RuntimeConstantInfo &O) const {
101 return ((ArgInfo.Type == O.ArgInfo.Type) && (ArgInfo.Pos == O.ArgInfo.Pos));
102 }
103 bool operator!=(const RuntimeConstantInfo &O) const { return !(*this == O); }
104
105 // Compare by Pos.
106 bool operator<(const RuntimeConstantInfo &O) const {
107 return ArgInfo.Pos < O.ArgInfo.Pos;
108 }
109};
110
111}; // namespace proteus
112
113#endif
#define PROTEUS_FATAL_ERROR(x)
Definition Error.h:7
Definition Helpers.h:76
Definition CppJitModule.cpp:21
static int Pos
Definition JitInterface.hpp:105
RuntimeConstantType
Definition CompilerInterfaceTypes.h:20
@ ARRAY
Definition CompilerInterfaceTypes.h:33
@ VECTOR
Definition CompilerInterfaceTypes.h:32
@ STATIC_ARRAY
Definition CompilerInterfaceTypes.h:31
@ OBJECT
Definition CompilerInterfaceTypes.h:34
size_t NumElts
Definition JitInterface.hpp:43
std::string toString(CodegenOption Option)
Definition Config.hpp:23
Definition CompilerInterfaceRuntimeConstantInfo.h:16
int32_t Pos
Definition CompilerInterfaceRuntimeConstantInfo.h:18
RuntimeConstantType Type
Definition CompilerInterfaceRuntimeConstantInfo.h:17
RuntimeConstantArgInfo(RuntimeConstantType Type, int32_t Pos)
Definition CompilerInterfaceRuntimeConstantInfo.h:20
Definition CompilerInterfaceRuntimeConstantInfo.h:28
int32_t NumElts
Definition CompilerInterfaceRuntimeConstantInfo.h:29
RuntimeConstantType EltType
Definition CompilerInterfaceRuntimeConstantInfo.h:30
RuntimeConstantArrayInfo(RuntimeConstantType EltType, RuntimeConstantType NumEltsType, int32_t NumEltsPos)
Definition CompilerInterfaceRuntimeConstantInfo.h:37
std::optional< RuntimeConstantArgInfo > OptNumEltsRCInfo
Definition CompilerInterfaceRuntimeConstantInfo.h:32
RuntimeConstantArrayInfo(int32_t NumElts, RuntimeConstantType EltType)
Definition CompilerInterfaceRuntimeConstantInfo.h:34
Definition CompilerInterfaceRuntimeConstantInfo.h:58
bool operator!=(const RuntimeConstantInfo &O) const
Definition CompilerInterfaceRuntimeConstantInfo.h:103
RuntimeConstantInfo(RuntimeConstantType Type, int32_t Pos)
Definition CompilerInterfaceRuntimeConstantInfo.h:63
std::optional< RuntimeConstantArrayInfo > OptArrInfo
Definition CompilerInterfaceRuntimeConstantInfo.h:60
RuntimeConstantInfo(RuntimeConstantType Type, int32_t Pos, int32_t NumElts, RuntimeConstantType EltType)
Definition CompilerInterfaceRuntimeConstantInfo.h:69
RuntimeConstantInfo(RuntimeConstantType Type, int32_t Pos, int32_t Size, bool PassByValue)
Definition CompilerInterfaceRuntimeConstantInfo.h:91
bool operator<(const RuntimeConstantInfo &O) const
Definition CompilerInterfaceRuntimeConstantInfo.h:106
bool operator==(const RuntimeConstantInfo &O) const
Definition CompilerInterfaceRuntimeConstantInfo.h:100
RuntimeConstantArgInfo ArgInfo
Definition CompilerInterfaceRuntimeConstantInfo.h:59
RuntimeConstantInfo(RuntimeConstantType Type, int32_t Pos, RuntimeConstantType EltType, RuntimeConstantType NumEltsType, int32_t NumEltsPos)
Definition CompilerInterfaceRuntimeConstantInfo.h:80
std::optional< RuntimeConstantObjectInfo > OptObjInfo
Definition CompilerInterfaceRuntimeConstantInfo.h:61
Definition CompilerInterfaceRuntimeConstantInfo.h:47
bool PassByValue
Definition CompilerInterfaceRuntimeConstantInfo.h:49
int32_t Size
Definition CompilerInterfaceRuntimeConstantInfo.h:48
RuntimeConstantObjectInfo(int32_t Size, bool PassByValue)
Definition CompilerInterfaceRuntimeConstantInfo.h:51