annotate lib/IR/AttributeImpl.h @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents c2174574ed3a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1 //===- AttributeImpl.h - Attribute Internals --------------------*- C++ -*-===//
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 ///
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 /// \file
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
10 /// This file defines various helper methods and classes used by
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 /// LLVMContextImpl for creating and managing attributes.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 ///
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
15 #ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
16 #define LLVM_LIB_IR_ATTRIBUTEIMPL_H
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
18 #include "llvm/ADT/ArrayRef.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 #include "llvm/ADT/FoldingSet.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
20 #include "llvm/ADT/StringRef.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "llvm/IR/Attributes.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
22 #include "llvm/Support/TrailingObjects.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
23 #include <cassert>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
24 #include <cstddef>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
25 #include <cstdint>
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include <string>
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
27 #include <utility>
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 namespace llvm {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 class LLVMContext;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
32 class Type;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 /// \class
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
36 /// This class represents a single, uniqued attribute. That attribute
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 /// could be a single enum, a tuple, or a string.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 class AttributeImpl : public FoldingSetNode {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 unsigned char KindID; ///< Holds the AttrEntryKind of the attribute
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 protected:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 enum AttrEntryKind {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 EnumAttrEntry,
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
44 IntAttrEntry,
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
45 StringAttrEntry,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
46 TypeAttrEntry,
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 public:
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
52 // AttributesImpl is uniqued, these should not be available.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
53 AttributeImpl(const AttributeImpl &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
54 AttributeImpl &operator=(const AttributeImpl &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
55
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 virtual ~AttributeImpl();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 bool isEnumAttribute() const { return KindID == EnumAttrEntry; }
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
59 bool isIntAttribute() const { return KindID == IntAttrEntry; }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 bool isStringAttribute() const { return KindID == StringAttrEntry; }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
61 bool isTypeAttribute() const { return KindID == TypeAttrEntry; }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 bool hasAttribute(Attribute::AttrKind A) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 bool hasAttribute(StringRef Kind) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
66 Attribute::AttrKind getKindAsEnum() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
67 uint64_t getValueAsInt() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
68
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
69 StringRef getKindAsString() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
70 StringRef getValueAsString() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
71
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
72 Type *getValueAsType() const;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
73
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
74 /// Used when sorting the attributes.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
75 bool operator<(const AttributeImpl &AI) const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
76
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 void Profile(FoldingSetNodeID &ID) const {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 if (isEnumAttribute())
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
79 Profile(ID, getKindAsEnum(), static_cast<uint64_t>(0));
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
80 else if (isIntAttribute())
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81 Profile(ID, getKindAsEnum(), getValueAsInt());
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
82 else if (isStringAttribute())
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
83 Profile(ID, getKindAsString(), getValueAsString());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
84 else
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
85 Profile(ID, getKindAsEnum(), getValueAsType());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
86 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
87
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
88 static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 uint64_t Val) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
90 ID.AddInteger(Kind);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
91 if (Val) ID.AddInteger(Val);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
92 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
93
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
94 static void Profile(FoldingSetNodeID &ID, StringRef Kind, StringRef Values) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 ID.AddString(Kind);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 if (!Values.empty()) ID.AddString(Values);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
97 }
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
98
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
99 static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
100 Type *Ty) {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
101 ID.AddInteger(Kind);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
102 ID.AddPointer(Ty);
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
103 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
107 /// \class
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
108 /// A set of classes that contain the value of the
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
109 /// attribute object. There are three main categories: enum attribute entries,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 /// represented by Attribute::AttrKind; alignment attribute entries; and string
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 /// attribute enties, which are for target-dependent attributes.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
112
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
113 class EnumAttributeImpl : public AttributeImpl {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
114 virtual void anchor();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
115
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 Attribute::AttrKind Kind;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
118 protected:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 EnumAttributeImpl(AttrEntryKind ID, Attribute::AttrKind Kind)
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 : AttributeImpl(ID), Kind(Kind) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
121
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 public:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 EnumAttributeImpl(Attribute::AttrKind Kind)
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 : AttributeImpl(EnumAttrEntry), Kind(Kind) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
125
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
126 Attribute::AttrKind getEnumKind() const { return Kind; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
127 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
128
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
129 class IntAttributeImpl : public EnumAttributeImpl {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
130 uint64_t Val;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
131
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
132 void anchor() override;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
133
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 public:
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
135 IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
136 : EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
137 assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment ||
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
138 Kind == Attribute::Dereferenceable ||
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
139 Kind == Attribute::DereferenceableOrNull ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
140 Kind == Attribute::AllocSize) &&
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
141 "Wrong kind for int attribute!");
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
143
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
144 uint64_t getValue() const { return Val; }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
146
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 class StringAttributeImpl : public AttributeImpl {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 virtual void anchor();
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
149
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 std::string Kind;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 std::string Val;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
152
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 public:
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 StringAttributeImpl(StringRef Kind, StringRef Val = StringRef())
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 : AttributeImpl(StringAttrEntry), Kind(Kind), Val(Val) {}
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
156
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 StringRef getStringKind() const { return Kind; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 StringRef getStringValue() const { return Val; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
160
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
161 class TypeAttributeImpl : public EnumAttributeImpl {
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
162 virtual void anchor();
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
163
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
164 Type *Ty;
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
165
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
166 public:
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
167 TypeAttributeImpl(Attribute::AttrKind Kind, Type *Ty)
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
168 : EnumAttributeImpl(TypeAttrEntry, Kind), Ty(Ty) {}
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
169
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
170 Type *getTypeValue() const { return Ty; }
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
171 };
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
172
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
173 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
174 /// \class
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
175 /// This class represents a group of attributes that apply to one
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
176 /// element: function, return type, or parameter.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
177 class AttributeSetNode final
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
178 : public FoldingSetNode,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
179 private TrailingObjects<AttributeSetNode, Attribute> {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
180 friend TrailingObjects;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
181
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
182 unsigned NumAttrs; ///< Number of attributes in this node.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
183 /// Bitset with a bit for each available attribute Attribute::AttrKind.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
184 uint8_t AvailableAttrs[12] = {};
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
185
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
186 AttributeSetNode(ArrayRef<Attribute> Attrs);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
187
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
188 public:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
189 // AttributesSetNode is uniqued, these should not be available.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
190 AttributeSetNode(const AttributeSetNode &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
191 AttributeSetNode &operator=(const AttributeSetNode &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
192
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
193 void operator delete(void *p) { ::operator delete(p); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
194
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
195 static AttributeSetNode *get(LLVMContext &C, const AttrBuilder &B);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
196
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
197 static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
198
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
199 /// Return the number of attributes this AttributeList contains.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
200 unsigned getNumAttributes() const { return NumAttrs; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
201
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
202 bool hasAttribute(Attribute::AttrKind Kind) const {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
203 return AvailableAttrs[Kind / 8] & ((uint64_t)1) << (Kind % 8);
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
204 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
205 bool hasAttribute(StringRef Kind) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
206 bool hasAttributes() const { return NumAttrs != 0; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
207
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
208 Attribute getAttribute(Attribute::AttrKind Kind) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
209 Attribute getAttribute(StringRef Kind) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
210
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
211 unsigned getAlignment() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
212 unsigned getStackAlignment() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
213 uint64_t getDereferenceableBytes() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
214 uint64_t getDereferenceableOrNullBytes() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
215 std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
216 std::string getAsString(bool InAttrGrp) const;
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
217 Type *getByValType() const;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
218
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
219 using iterator = const Attribute *;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
220
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
221 iterator begin() const { return getTrailingObjects<Attribute>(); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
222 iterator end() const { return begin() + NumAttrs; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
223
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
224 void Profile(FoldingSetNodeID &ID) const {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
225 Profile(ID, makeArrayRef(begin(), end()));
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
226 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
227
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
228 static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
229 for (const auto &Attr : AttrList)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
230 Attr.Profile(ID);
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
231 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
232 };
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
233
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
234 using IndexAttrPair = std::pair<unsigned, AttributeSet>;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
235
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 /// \class
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
238 /// This class represents a set of attributes that apply to the function,
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 /// return type, and parameters.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
240 class AttributeListImpl final
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
241 : public FoldingSetNode,
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
242 private TrailingObjects<AttributeListImpl, AttributeSet> {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
243 friend class AttributeList;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
244 friend TrailingObjects;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
246 private:
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
247 LLVMContext &Context;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
248 unsigned NumAttrSets; ///< Number of entries in this set.
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
249 /// Bitset with a bit for each available attribute Attribute::AttrKind.
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
250 uint8_t AvailableFunctionAttrs[12] = {};
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
252 // Helper fn for TrailingObjects class.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
253 size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
254
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
255 public:
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
256 AttributeListImpl(LLVMContext &C, ArrayRef<AttributeSet> Sets);
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
257
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
258 // AttributesSetImpt is uniqued, these should not be available.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
259 AttributeListImpl(const AttributeListImpl &) = delete;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
260 AttributeListImpl &operator=(const AttributeListImpl &) = delete;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
261
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
262 void operator delete(void *p) { ::operator delete(p); }
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
263
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
264 /// Get the context that created this AttributeListImpl.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 LLVMContext &getContext() { return Context; }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
266
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
267 /// Return true if the AttributeSet or the FunctionIndex has an
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
268 /// enum attribute of the given kind.
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
269 bool hasFnAttribute(Attribute::AttrKind Kind) const {
147
c2174574ed3a LLVM 10
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 121
diff changeset
270 return AvailableFunctionAttrs[Kind / 8] & ((uint64_t)1) << (Kind % 8);
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
271 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 95
diff changeset
272
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
273 using iterator = const AttributeSet *;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
274
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
275 iterator begin() const { return getTrailingObjects<AttributeSet>(); }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
276 iterator end() const { return begin() + NumAttrSets; }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
277
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
278 void Profile(FoldingSetNodeID &ID) const;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
279 static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeSet> Nodes);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
280
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 void dump() const;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 };
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
283
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
284 } // end namespace llvm
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
285
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
286 #endif // LLVM_LIB_IR_ATTRIBUTEIMPL_H