@@ -29,16 +29,16 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
2929 std::vector<Record *> IntrProperties =
3030 RC.getAllDerivedDefinitions (" IntrinsicProperty" );
3131
32- std::vector<Record *> DefaultProperties;
33- for (Record *Rec : IntrProperties)
32+ std::vector<const Record *> DefaultProperties;
33+ for (const Record *Rec : IntrProperties)
3434 if (Rec->getValueAsBit (" IsDefault" ))
3535 DefaultProperties.push_back (Rec);
3636
3737 std::vector<Record *> Defs = RC.getAllDerivedDefinitions (" Intrinsic" );
3838 Intrinsics.reserve (Defs.size ());
3939
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));
4242
4343 llvm::sort (Intrinsics,
4444 [](const CodeGenIntrinsic &LHS, const CodeGenIntrinsic &RHS) {
@@ -54,61 +54,43 @@ CodeGenIntrinsicTable::CodeGenIntrinsicTable(const RecordKeeper &RC) {
5454 Targets.back ().Count = Intrinsics.size () - Targets.back ().Offset ;
5555}
5656
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 ();
6161 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 ;
7862
79- if (DefName.size () <= 4 || DefName. substr ( 0 , 4 ) != " int_" )
63+ if (! DefName.starts_with ( " int_" ) )
8064 PrintFatalError (DefLoc,
8165 " Intrinsic '" + DefName + " ' does not start with 'int_'!" );
8266
8367 EnumName = DefName.substr (4 );
8468
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 ( " " );
9074
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 ( );
9377
9478 if (Name == " " ) {
9579 // 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, ' _' , ' .' );
10082 } else {
10183 // Verify it starts with "llvm.".
102- if (Name. size () <= 5 || Name. substr ( 0 , 5 ) != " llvm." )
84+ if (! StringRef ( Name). starts_with ( " llvm." ) )
10385 PrintFatalError (DefLoc, " Intrinsic '" + DefName +
10486 " 's name does not start with 'llvm.'!" );
10587 }
10688
10789 // If TargetPrefix is specified, make sure that Name starts with
10890 // "llvm.<targetprefix>.".
10991 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 ( ' . ' ))
11294 PrintFatalError (DefLoc, " Intrinsic '" + DefName +
11395 " ' does not start with 'llvm." +
11496 TargetPrefix + " .'!" );
@@ -129,15 +111,15 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
129111 // Parse the intrinsic properties.
130112 ListInit *PropList = R->getValueAsListInit (" IntrProperties" );
131113 for (unsigned i = 0 , e = PropList->size (); i != e; ++i) {
132- Record *Property = PropList->getElementAsRecord (i);
114+ const Record *Property = PropList->getElementAsRecord (i);
133115 assert (Property->isSubClassOf (" IntrinsicProperty" ) &&
134116 " Expected a property!" );
135117
136118 setProperty (Property);
137119 }
138120
139121 // Set default properties to true.
140- setDefaultProperties (R, DefaultProperties);
122+ setDefaultProperties (DefaultProperties);
141123
142124 // Also record the SDPatternOperator Properties.
143125 Properties = parseSDPatternOperatorProperties (R);
@@ -148,16 +130,16 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R,
148130}
149131
150132void CodeGenIntrinsic::setDefaultProperties (
151- Record *R, ArrayRef<Record *> DefaultProperties) {
133+ ArrayRef<const Record *> DefaultProperties) {
152134 // opt-out of using default attributes.
153- if (R ->getValueAsBit (" DisableDefaultAttributes" ))
135+ if (TheDef ->getValueAsBit (" DisableDefaultAttributes" ))
154136 return ;
155137
156- for (Record *Rec : DefaultProperties)
138+ for (const Record *Rec : DefaultProperties)
157139 setProperty (Rec);
158140}
159141
160- void CodeGenIntrinsic::setProperty (Record *R) {
142+ void CodeGenIntrinsic::setProperty (const Record *R) {
161143 if (R->getName () == " IntrNoMem" )
162144 ME = MemoryEffects::none ();
163145 else if (R->getName () == " IntrReadMem" ) {
0 commit comments