blob: 2b479537dfe993bfeb2a3dea6517444ac1b1fc36 [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 {
22 class Record;
23 class RecordKeeper;
Chris Lattnerc92f6882006-03-27 22:48:18 +000024 class CodeGenTarget;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000025
26 struct CodeGenIntrinsic {
Reid Spencere67d0c22007-04-01 07:20:02 +000027 Record *TheDef; // The actual record defining this intrinsic.
Chris Lattnerc313d0b2006-03-03 02:32:46 +000028 std::string Name; // The name of the LLVM function "llvm.bswap.i32"
29 std::string EnumName; // The name of the enum "bswap_i32"
Chris Lattnerfea17a92006-03-13 23:08:44 +000030 std::string GCCBuiltinName;// Name of the corresponding GCC builtin, or "".
Saleem Abdulrasool4e63fc42014-07-04 18:42:25 +000031 std::string MSBuiltinName; // Name of the corresponding MS builtin, or "".
Chris Lattner402a5732006-03-15 01:33:26 +000032 std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
Duncan Sands13237ac2008-06-06 12:08:01 +000033
Bill Wendling91821472008-11-13 09:08:33 +000034 /// IntrinsicSignature - This structure holds the return values and
35 /// parameter values of an intrinsic. If the number of return values is > 1,
36 /// then the intrinsic implicitly returns a first-class aggregate. The
37 /// numbering of the types starts at 0 with the first return value and
Jim Grosbach975c1cb2009-03-26 16:17:51 +000038 /// continues from there through the parameter list. This is useful for
Bill Wendling91821472008-11-13 09:08:33 +000039 /// "matching" types.
40 struct IntrinsicSignature {
Owen Anderson9f944592009-08-11 20:47:22 +000041 /// RetVTs - The MVT::SimpleValueType for each return type. Note that this
Bill Wendling91821472008-11-13 09:08:33 +000042 /// list is only populated when in the context of a target .td file. When
43 /// building Intrinsics.td, this isn't available, because we don't know
44 /// the target pointer size.
Owen Anderson9f944592009-08-11 20:47:22 +000045 std::vector<MVT::SimpleValueType> RetVTs;
Duncan Sands13237ac2008-06-06 12:08:01 +000046
Bill Wendling91821472008-11-13 09:08:33 +000047 /// RetTypeDefs - The records for each return type.
48 std::vector<Record*> RetTypeDefs;
49
Owen Anderson9f944592009-08-11 20:47:22 +000050 /// ParamVTs - The MVT::SimpleValueType for each parameter type. Note that
Bill Wendling91821472008-11-13 09:08:33 +000051 /// this list is only populated when in the context of a target .td file.
52 /// When building Intrinsics.td, this isn't available, because we don't
53 /// know the target pointer size.
Owen Anderson9f944592009-08-11 20:47:22 +000054 std::vector<MVT::SimpleValueType> ParamVTs;
Bill Wendling91821472008-11-13 09:08:33 +000055
56 /// ParamTypeDefs - The records for each parameter type.
57 std::vector<Record*> ParamTypeDefs;
58 };
59
60 IntrinsicSignature IS;
61
Nicolai Haehnleb48275f2016-04-19 21:58:33 +000062 /// Bit flags describing the type (ref/mod) and location of memory
63 /// accesses that may be performed by the intrinsics. Analogous to
64 /// \c FunctionModRefBehaviour.
65 enum ModRefBits {
66 /// The intrinsic may access memory anywhere, i.e. it is not restricted
67 /// to access through pointer arguments.
68 MR_Anywhere = 1,
69
70 /// The intrinsic may read memory.
71 MR_Ref = 2,
72
73 /// The intrinsic may write memory.
74 MR_Mod = 4,
75
76 /// The intrinsic may both read and write memory.
77 MR_ModRef = MR_Ref | MR_Mod,
Igor Laevsky30143ae2015-08-13 17:40:04 +000078 };
Nicolai Haehnleb48275f2016-04-19 21:58:33 +000079
80 /// Memory mod/ref behavior of this intrinsic, corresponding to
Nicolai Haehnle97788022016-04-21 17:48:02 +000081 /// intrinsic properties (IntrReadMem, IntrArgMemOnly, etc.).
Nicolai Haehnleb48275f2016-04-19 21:58:33 +000082 enum ModRefBehavior {
83 NoMem = 0,
84 ReadArgMem = MR_Ref,
85 ReadMem = MR_Ref | MR_Anywhere,
86 WriteArgMem = MR_Mod,
87 WriteMem = MR_Mod | MR_Anywhere,
88 ReadWriteArgMem = MR_ModRef,
89 ReadWriteMem = MR_ModRef | MR_Anywhere,
90 };
91 ModRefBehavior ModRef;
Chris Lattnerc313d0b2006-03-03 02:32:46 +000092
Chris Lattner9a3113a2009-01-12 01:12:03 +000093 /// This is set to true if the intrinsic is overloaded by its argument
94 /// types.
Reid Spencere67d0c22007-04-01 07:20:02 +000095 bool isOverloaded;
96
Chris Lattner9a3113a2009-01-12 01:12:03 +000097 /// isCommutative - True if the intrinsic is commutative.
Evan Cheng49bad4c2008-06-16 20:29:38 +000098 bool isCommutative;
John McCall375dcc92011-05-28 06:31:34 +000099
100 /// canThrow - True if the intrinsic can throw.
101 bool canThrow;
Chris Lattnerff9e08b2012-05-27 23:20:41 +0000102
Eli Bendersky2281ef92014-03-18 23:51:07 +0000103 /// isNoDuplicate - True if the intrinsic is marked as noduplicate.
104 bool isNoDuplicate;
105
Chris Lattnerff9e08b2012-05-27 23:20:41 +0000106 /// isNoReturn - True if the intrinsic is no-return.
107 bool isNoReturn;
108
Owen Anderson85fa7d52015-05-26 23:48:40 +0000109 /// isConvergent - True if the intrinsic is marked as convergent.
110 bool isConvergent;
111
Chris Lattner9a3113a2009-01-12 01:12:03 +0000112 enum ArgAttribute {
Nick Lewyckyc2ec0722013-07-06 00:29:58 +0000113 NoCapture,
114 ReadOnly,
115 ReadNone
Chris Lattner9a3113a2009-01-12 01:12:03 +0000116 };
117 std::vector<std::pair<unsigned, ArgAttribute> > ArgumentAttributes;
Evan Cheng49bad4c2008-06-16 20:29:38 +0000118
Dan Gohmanfc4ad7de2008-04-03 00:02:49 +0000119 CodeGenIntrinsic(Record *R);
Chris Lattnerc313d0b2006-03-03 02:32:46 +0000120 };
121
122 /// LoadIntrinsics - Read all of the intrinsics defined in the specified
123 /// .td file.
Dale Johannesenb842d522009-02-05 01:49:45 +0000124 std::vector<CodeGenIntrinsic> LoadIntrinsics(const RecordKeeper &RC,
125 bool TargetOnly);
Chris Lattnerc313d0b2006-03-03 02:32:46 +0000126}
127
128#endif