blob: 1c82e05d1a5f21c02a22b063fcfb7d516e49e18a [file] [log] [blame]
Chris Lattnerc313d0b2006-03-03 02:32:46 +00001//===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner8adcd9f2007-12-29 20:37:13 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnerc313d0b2006-03-03 02:32:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines a wrapper class for the 'Intrinsic' TableGen class.
11//
12//===----------------------------------------------------------------------===//
13
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000014#ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
15#define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
Chris Lattnerc313d0b2006-03-03 02:32:46 +000016
Patrik Hagglund8d09a6c2014-03-15 09:11:41 +000017#include "llvm/CodeGen/MachineValueType.h"
Chris Lattnerc313d0b2006-03-03 02:32:46 +000018#include <string>
19#include <vector>
20
21namespace llvm {
Justin Bogneracf564c2016-07-08 20:14:27 +000022class Record;
23class RecordKeeper;
24class CodeGenTarget;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000025
Justin Bogneracf564c2016-07-08 20:14:27 +000026struct 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.
Duncan Sands13237ac2008-06-06 12:08:01 +000033
Justin Bogneracf564c2016-07-08 20:14:27 +000034 /// 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
43 /// pointer size.
44 std::vector<MVT::SimpleValueType> RetVTs;
Duncan Sands13237ac2008-06-06 12:08:01 +000045
Justin Bogneracf564c2016-07-08 20:14:27 +000046 /// The records for each return type.
47 std::vector<Record *> RetTypeDefs;
Bill Wendling91821472008-11-13 09:08:33 +000048
Justin Bogneracf564c2016-07-08 20:14:27 +000049 /// 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
52 /// pointer size.
53 std::vector<MVT::SimpleValueType> ParamVTs;
Bill Wendling91821472008-11-13 09:08:33 +000054
Justin Bogneracf564c2016-07-08 20:14:27 +000055 /// The records for each parameter type.
56 std::vector<Record *> ParamTypeDefs;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000057 };
58
Justin Bogneracf564c2016-07-08 20:14:27 +000059 IntrinsicSignature IS;
60
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.
64 enum ModRefBits {
65 /// The intrinsic may access memory anywhere, i.e. it is not restricted
66 /// to access through pointer arguments.
67 MR_Anywhere = 1,
68
69 /// The intrinsic may read memory.
70 MR_Ref = 2,
71
72 /// The intrinsic may write memory.
73 MR_Mod = 4,
74
75 /// The intrinsic may both read and write memory.
76 MR_ModRef = MR_Ref | MR_Mod,
77 };
78
79 /// Memory mod/ref behavior of this intrinsic, corresponding to intrinsic
80 /// properties (IntrReadMem, IntrArgMemOnly, etc.).
81 enum ModRefBehavior {
82 NoMem = 0,
83 ReadArgMem = MR_Ref,
84 ReadMem = MR_Ref | MR_Anywhere,
85 WriteArgMem = MR_Mod,
86 WriteMem = MR_Mod | MR_Anywhere,
87 ReadWriteArgMem = MR_ModRef,
88 ReadWriteMem = MR_ModRef | MR_Anywhere,
89 };
90 ModRefBehavior ModRef;
91
92 /// This is set to true if the intrinsic is overloaded by its argument
93 /// types.
94 bool isOverloaded;
95
96 /// True if the intrinsic is commutative.
97 bool isCommutative;
98
99 /// True if the intrinsic can throw.
100 bool canThrow;
101
102 /// True if the intrinsic is marked as noduplicate.
103 bool isNoDuplicate;
104
105 /// True if the intrinsic is no-return.
106 bool isNoReturn;
107
108 /// True if the intrinsic is marked as convergent.
109 bool isConvergent;
110
111 enum ArgAttribute { NoCapture, ReadOnly, WriteOnly, ReadNone };
112 std::vector<std::pair<unsigned, ArgAttribute>> ArgumentAttributes;
113
114 CodeGenIntrinsic(Record *R);
115};
116
117/// Read all of the intrinsics defined in the specified .td file.
118std::vector<CodeGenIntrinsic> LoadIntrinsics(const RecordKeeper &RC,
119 bool TargetOnly);
Chris Lattnerc313d0b2006-03-03 02:32:46 +0000120}
121
122#endif