1 //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a wrapper class for the 'Intrinsic' TableGen class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
15 #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
17 #include "llvm/CodeGen/MachineValueType.h"
26 struct CodeGenIntrinsic {
27 Record *TheDef; // The actual record defining this intrinsic.
28 std::string Name; // The name of the LLVM function "llvm.bswap.i32"
29 std::string EnumName; // The name of the enum "bswap_i32"
30 std::string GCCBuiltinName; // Name of the corresponding GCC builtin, or "".
31 std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".
32 std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
34 /// This structure holds the return values and parameter values of an
35 /// intrinsic. If the number of return values is > 1, then the intrinsic
36 /// implicitly returns a first-class aggregate. The numbering of the types
37 /// starts at 0 with the first return value and continues from there through
38 /// the parameter list. This is useful for "matching" types.
39 struct IntrinsicSignature {
40 /// The MVT::SimpleValueType for each return type. Note that this list is
41 /// only populated when in the context of a target .td file. When building
42 /// Intrinsics.td, this isn't available, because we don't know the target
44 std::vector<MVT::SimpleValueType> RetVTs;
46 /// The records for each return type.
47 std::vector<Record *> RetTypeDefs;
49 /// The MVT::SimpleValueType for each parameter type. Note that this list is
50 /// only populated when in the context of a target .td file. When building
51 /// Intrinsics.td, this isn't available, because we don't know the target
53 std::vector<MVT::SimpleValueType> ParamVTs;
55 /// The records for each parameter type.
56 std::vector<Record *> ParamTypeDefs;
59 IntrinsicSignature IS;
61 /// Bit flags describing the type (ref/mod) and location of memory
62 /// accesses that may be performed by the intrinsics. Analogous to
63 /// \c FunctionModRefBehaviour.
65 /// The intrinsic may access memory that is otherwise inaccessible via
67 MR_InaccessibleMem = 1,
69 /// The intrinsic may access memory through pointer arguments.
73 /// The intrinsic may access memory anywhere, i.e. it is not restricted
74 /// to access through pointer arguments.
75 MR_Anywhere = 4 | MR_ArgMem | MR_InaccessibleMem,
77 /// The intrinsic may read memory.
80 /// The intrinsic may write memory.
83 /// The intrinsic may both read and write memory.
84 MR_ModRef = MR_Ref | MR_Mod,
87 /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic
88 /// properties (IntrReadMem, IntrArgMemOnly, etc.).
91 ReadArgMem = MR_Ref | MR_ArgMem,
92 ReadInaccessibleMem = MR_Ref | MR_InaccessibleMem,
93 ReadInaccessibleMemOrArgMem = MR_Ref | MR_ArgMem | MR_InaccessibleMem,
94 ReadMem = MR_Ref | MR_Anywhere,
95 WriteArgMem = MR_Mod | MR_ArgMem,
96 WriteInaccessibleMem = MR_Mod | MR_InaccessibleMem,
97 WriteInaccessibleMemOrArgMem = MR_Mod | MR_ArgMem | MR_InaccessibleMem,
98 WriteMem = MR_Mod | MR_Anywhere,
99 ReadWriteArgMem = MR_ModRef | MR_ArgMem,
100 ReadWriteInaccessibleMem = MR_ModRef | MR_InaccessibleMem,
101 ReadWriteInaccessibleMemOrArgMem = MR_ModRef | MR_ArgMem |
103 ReadWriteMem = MR_ModRef | MR_Anywhere,
105 ModRefBehavior ModRef;
107 /// This is set to true if the intrinsic is overloaded by its argument
111 /// True if the intrinsic is commutative.
114 /// True if the intrinsic can throw.
117 /// True if the intrinsic is marked as noduplicate.
120 /// True if the intrinsic is no-return.
123 /// True if the intrinsic is marked as convergent.
126 /// True if the intrinsic has side effects that aren't captured by any
127 /// of the other flags.
130 // True if the intrinsic is marked as speculatable.
133 enum ArgAttribute { NoCapture, Returned, ReadOnly, WriteOnly, ReadNone };
134 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
136 CodeGenIntrinsic(Record *R);
139 class CodeGenIntrinsicTable {
140 std::vector<CodeGenIntrinsic> Intrinsics;
148 std::vector<TargetSet> Targets;
150 explicit CodeGenIntrinsicTable(const RecordKeeper &RC, bool TargetOnly);
151 CodeGenIntrinsicTable() = default;
153 bool empty() const { return Intrinsics.empty(); }
154 size_t size() const { return Intrinsics.size(); }
155 CodeGenIntrinsic &operator[](size_t Pos) { return Intrinsics[Pos]; }
156 const CodeGenIntrinsic &operator[](size_t Pos) const {
157 return Intrinsics[Pos];