@@ -29,16 +29,16 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
29
29
std::vector<Record *> IntrProperties =
30
30
RC.getAllDerivedDefinitions (" IntrinsicProperty" );
31
31
32
- std::vector<Record *> DefaultProperties;
33
- for (Record *Rec : IntrProperties)
32
+ std::vector<const Record *> DefaultProperties;
33
+ for (const Record *Rec : IntrProperties)
34
34
if (Rec->getValueAsBit (" IsDefault" ))
35
35
DefaultProperties.push_back (Rec);
36
36
37
37
std::vector<Record *> Defs = RC.getAllDerivedDefinitions (" Intrinsic" );
38
38
Intrinsics.reserve (Defs.size ());
39
39
40
- for (unsigned I = 0 , e = Defs. size (); I != e; ++I )
41
- Intrinsics.push_back (CodeGenIntrinsic (Defs[I] , DefaultProperties));
40
+ for (const Record *Def : Defs)
41
+ Intrinsics.push_back (CodeGenIntrinsic (Def , DefaultProperties));
42
42
43
43
llvm::sort (Intrinsics,
44
44
[](const CodeGenIntrinsic &LHS, const CodeGenIntrinsic &RHS) {
@@ -54,61 +54,43 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
54
54
Targets.back ().Count = Intrinsics.size () - Targets.back ().Offset ;
55
55
}
56
56
57
- CodeGenIntrinsic::CodeGenIntrinsic (Record *R,
58
- ArrayRef<Record *> DefaultProperties) {
59
- TheDef = R;
60
- std::string DefName = std::string (R ->getName () );
57
+ CodeGenIntrinsic::CodeGenIntrinsic (const Record *R,
58
+ ArrayRef<const Record *> DefaultProperties)
59
+ : TheDef(R) {
60
+ StringRef DefName = TheDef ->getName ();
61
61
ArrayRef<SMLoc> DefLoc = R->getLoc ();
62
- Properties = 0 ;
63
- isOverloaded = false ;
64
- isCommutative = false ;
65
- canThrow = false ;
66
- isNoReturn = false ;
67
- isNoCallback = false ;
68
- isNoSync = false ;
69
- isNoFree = false ;
70
- isWillReturn = false ;
71
- isCold = false ;
72
- isNoDuplicate = false ;
73
- isNoMerge = false ;
74
- isConvergent = false ;
75
- isSpeculatable = false ;
76
- hasSideEffects = false ;
77
- isStrictFP = false ;
78
62
79
- if (DefName.size () <= 4 || DefName. substr ( 0 , 4 ) != " int_" )
63
+ if (! DefName.starts_with ( " int_" ) )
80
64
PrintFatalError (DefLoc,
81
65
" Intrinsic '" + DefName + " ' does not start with 'int_'!" );
82
66
83
67
EnumName = DefName.substr (4 );
84
68
85
- if (R-> getValue (
86
- " ClangBuiltinName" )) // Ignore a missing ClangBuiltinName field.
87
- ClangBuiltinName = std::string ( R->getValueAsString (" ClangBuiltinName" ));
88
- if (R-> getValue ( " MSBuiltinName " )) // Ignore a missing MSBuiltinName field.
89
- MSBuiltinName = std::string ( R->getValueAsString (" MSBuiltinName" ));
69
+ // Ignore a missing ClangBuiltinName field.
70
+ ClangBuiltinName =
71
+ R->getValueAsOptionalString (" ClangBuiltinName" ). value_or ( " " );
72
+ // Ignore a missing MSBuiltinName field.
73
+ MSBuiltinName = R->getValueAsOptionalString (" MSBuiltinName" ). value_or ( " " );
90
74
91
- TargetPrefix = std::string ( R->getValueAsString (" TargetPrefix" ) );
92
- Name = std::string ( R->getValueAsString (" LLVMName" ));
75
+ TargetPrefix = R->getValueAsString (" TargetPrefix" );
76
+ Name = R->getValueAsString (" LLVMName" ). str ( );
93
77
94
78
if (Name == " " ) {
95
79
// If an explicit name isn't specified, derive one from the DefName.
96
- Name = " llvm." ;
97
-
98
- for (unsigned i = 0 , e = EnumName.size (); i != e; ++i)
99
- Name += (EnumName[i] == ' _' ) ? ' .' : EnumName[i];
80
+ Name = " llvm." + EnumName.str ();
81
+ llvm::replace (Name, ' _' , ' .' );
100
82
} else {
101
83
// Verify it starts with "llvm.".
102
- if (Name. size () <= 5 || Name. substr ( 0 , 5 ) != " llvm." )
84
+ if (! StringRef ( Name). starts_with ( " llvm." ) )
103
85
PrintFatalError (DefLoc, " Intrinsic '" + DefName +
104
86
" 's name does not start with 'llvm.'!" );
105
87
}
106
88
107
89
// If TargetPrefix is specified, make sure that Name starts with
108
90
// "llvm.<targetprefix>.".
109
91
if (!TargetPrefix.empty ()) {
110
- if (Name. size () < 6 + TargetPrefix. size () ||
111
- Name. substr ( 5 , 1 + TargetPrefix. size ()) != (TargetPrefix + " . " ))
92
+ StringRef Prefix = StringRef (Name). drop_front ( 5 ); // Drop llvm.
93
+ if (!Prefix. consume_front (TargetPrefix) || !Prefix. starts_with ( ' . ' ))
112
94
PrintFatalError (DefLoc, " Intrinsic '" + DefName +
113
95
" ' does not start with 'llvm." +
114
96
TargetPrefix + " .'!" );
@@ -129,15 +111,15 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
129
111
// Parse the intrinsic properties.
130
112
ListInit *PropList = R->getValueAsListInit (" IntrProperties" );
131
113
for (unsigned i = 0 , e = PropList->size (); i != e; ++i) {
132
- Record *Property = PropList->getElementAsRecord (i);
114
+ const Record *Property = PropList->getElementAsRecord (i);
133
115
assert (Property->isSubClassOf (" IntrinsicProperty" ) &&
134
116
" Expected a property!" );
135
117
136
118
setProperty (Property);
137
119
}
138
120
139
121
// Set default properties to true.
140
- setDefaultProperties (R, DefaultProperties);
122
+ setDefaultProperties (DefaultProperties);
141
123
142
124
// Also record the SDPatternOperator Properties.
143
125
Properties = parseSDPatternOperatorProperties (R);
@@ -148,16 +130,16 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
148
130
}
149
131
150
132
void CodeGenIntrinsic::setDefaultProperties (
151
- Record *R, ArrayRef<Record *> DefaultProperties) {
133
+ ArrayRef<const Record *> DefaultProperties) {
152
134
// opt-out of using default attributes.
153
- if (R ->getValueAsBit (" DisableDefaultAttributes" ))
135
+ if (TheDef ->getValueAsBit (" DisableDefaultAttributes" ))
154
136
return ;
155
137
156
- for (Record *Rec : DefaultProperties)
138
+ for (const Record *Rec : DefaultProperties)
157
139
setProperty (Rec);
158
140
}
159
141
160
- void CodeGenIntrinsic::setProperty (Record *R) {
142
+ void CodeGenIntrinsic::setProperty (const Record *R) {
161
143
if (R->getName () == " IntrNoMem" )
162
144
ME = MemoryEffects::none ();
163
145
else if (R->getName () == " IntrReadMem" ) {
0 commit comments