1 //===- CodeGenIntrinsic.h - Intrinsic Class Wrapper ------------*- C++ -*--===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines a wrapper class for the 'Intrinsic' TableGen class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
15 #define LLVM_UTILS_TABLEGEN_CODEGENINTRINSICS_H
16 
17 #include "llvm/CodeGen/MachineValueType.h"
18 #include <string>
19 #include <vector>
20 
21 namespace llvm {
22   class Record;
23   class RecordKeeper;
24   class CodeGenTarget;
25 
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.
33 
34     /// 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
38     /// continues from there through the parameter list. This is useful for
39     /// "matching" types.
40     struct IntrinsicSignature {
41       /// RetVTs - The MVT::SimpleValueType for each return type. Note that this
42       /// 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.
45       std::vector<MVT::SimpleValueType> RetVTs;
46 
47       /// RetTypeDefs - The records for each return type.
48       std::vector<Record*> RetTypeDefs;
49 
50       /// ParamVTs - The MVT::SimpleValueType for each parameter type. Note that
51       /// 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.
54       std::vector<MVT::SimpleValueType> ParamVTs;
55 
56       /// ParamTypeDefs - The records for each parameter type.
57       std::vector<Record*> ParamTypeDefs;
58     };
59 
60     IntrinsicSignature IS;
61 
62     // Memory mod/ref behavior of this intrinsic.
63     enum ModRefKind {
64       NoMem, ReadArgMem, ReadMem, ReadWriteArgMem, ReadWriteMem
65     };
66     ModRefKind ModRef;
67 
68     /// This is set to true if the intrinsic is overloaded by its argument
69     /// types.
70     bool isOverloaded;
71 
72     /// isCommutative - True if the intrinsic is commutative.
73     bool isCommutative;
74 
75     /// canThrow - True if the intrinsic can throw.
76     bool canThrow;
77 
78     /// isNoDuplicate - True if the intrinsic is marked as noduplicate.
79     bool isNoDuplicate;
80 
81     /// isNoReturn - True if the intrinsic is no-return.
82     bool isNoReturn;
83 
84     /// isConvergent - True if the intrinsic is marked as convergent.
85     bool isConvergent;
86 
87     enum ArgAttribute {
88       NoCapture,
89       ReadOnly,
90       ReadNone
91     };
92     std::vector<std::pair<unsigned, ArgAttribute> > ArgumentAttributes;
93 
94     CodeGenIntrinsic(Record *R);
95   };
96 
97   /// LoadIntrinsics - Read all of the intrinsics defined in the specified
98   /// .td file.
99   std::vector<CodeGenIntrinsic> LoadIntrinsics(const RecordKeeper &RC,
100                                                bool TargetOnly);
101 }
102 
103 #endif
104