@@ -164,51 +164,6 @@ static std::string getDeviceLibraryFileName(StringRef BundleFileName,
164
164
return Result;
165
165
}
166
166
167
- // / @brief Checks if a code object \p CodeObjectInfo is compatible with a given
168
- // / target \p TargetInfo.
169
- // / @link https://clang.llvm.org/docs/ClangOffloadBundler.html#bundle-entry-id
170
- bool isCodeObjectCompatible (const OffloadTargetInfo &CodeObjectInfo,
171
- const OffloadTargetInfo &TargetInfo) {
172
-
173
- // Compatible in case of exact match.
174
- if (CodeObjectInfo == TargetInfo) {
175
- DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
176
- dbgs () << " Compatible: Exact match: \t [CodeObject: "
177
- << CodeObjectInfo.str ()
178
- << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
179
- return true ;
180
- }
181
-
182
- // Incompatible if Kinds or Triples mismatch.
183
- if (!CodeObjectInfo.isOffloadKindCompatible (TargetInfo.OffloadKind ) ||
184
- !CodeObjectInfo.Triple .isCompatibleWith (TargetInfo.Triple )) {
185
- DEBUG_WITH_TYPE (
186
- " CodeObjectCompatibility" ,
187
- dbgs () << " Incompatible: Kind/Triple mismatch \t [CodeObject: "
188
- << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
189
- << " ]\n " );
190
- return false ;
191
- }
192
-
193
- // Incompatible if target IDs are incompatible.
194
- if (!clang::isCompatibleTargetID (CodeObjectInfo.TargetID ,
195
- TargetInfo.TargetID )) {
196
- DEBUG_WITH_TYPE (
197
- " CodeObjectCompatibility" ,
198
- dbgs () << " Incompatible: target IDs are incompatible \t [CodeObject: "
199
- << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
200
- << " ]\n " );
201
- return false ;
202
- }
203
-
204
- DEBUG_WITH_TYPE (
205
- " CodeObjectCompatibility" ,
206
- dbgs () << " Compatible: Code Objects are compatible \t [CodeObject: "
207
- << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
208
- << " ]\n " );
209
- return true ;
210
- }
211
-
212
167
namespace {
213
168
// / Generic file handler interface.
214
169
class FileHandler {
@@ -1130,6 +1085,99 @@ Error OffloadBundler::ListBundleIDsInFile(
1130
1085
return FH->listBundleIDs (DecompressedInput);
1131
1086
}
1132
1087
1088
+ // / @brief Checks if a code object \p CodeObjectInfo is compatible with a given
1089
+ // / target \p TargetInfo.
1090
+ // / @link https://clang.llvm.org/docs/ClangOffloadBundler.html#bundle-entry-id
1091
+ bool isCodeObjectCompatible (const OffloadTargetInfo &CodeObjectInfo,
1092
+ const OffloadTargetInfo &TargetInfo) {
1093
+
1094
+ // Compatible in case of exact match.
1095
+ if (CodeObjectInfo == TargetInfo) {
1096
+ DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
1097
+ dbgs () << " Compatible: Exact match: \t [CodeObject: "
1098
+ << CodeObjectInfo.str ()
1099
+ << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1100
+ return true ;
1101
+ }
1102
+
1103
+ // Incompatible if Kinds or Triples mismatch.
1104
+ if (!CodeObjectInfo.isOffloadKindCompatible (TargetInfo.OffloadKind ) ||
1105
+ !CodeObjectInfo.Triple .isCompatibleWith (TargetInfo.Triple )) {
1106
+ DEBUG_WITH_TYPE (
1107
+ " CodeObjectCompatibility" ,
1108
+ dbgs () << " Incompatible: Kind/Triple mismatch \t [CodeObject: "
1109
+ << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
1110
+ << " ]\n " );
1111
+ return false ;
1112
+ }
1113
+
1114
+ // Incompatible if Processors mismatch.
1115
+ llvm::StringMap<bool > CodeObjectFeatureMap, TargetFeatureMap;
1116
+ std::optional<StringRef> CodeObjectProc = clang::parseTargetID (
1117
+ CodeObjectInfo.Triple , CodeObjectInfo.TargetID , &CodeObjectFeatureMap);
1118
+ std::optional<StringRef> TargetProc = clang::parseTargetID (
1119
+ TargetInfo.Triple , TargetInfo.TargetID , &TargetFeatureMap);
1120
+
1121
+ // Both TargetProc and CodeObjectProc can't be empty here.
1122
+ if (!TargetProc || !CodeObjectProc ||
1123
+ CodeObjectProc.value () != TargetProc.value ()) {
1124
+ DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
1125
+ dbgs () << " Incompatible: Processor mismatch \t [CodeObject: "
1126
+ << CodeObjectInfo.str ()
1127
+ << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1128
+ return false ;
1129
+ }
1130
+
1131
+ // Incompatible if CodeObject has more features than Target, irrespective of
1132
+ // type or sign of features.
1133
+ if (CodeObjectFeatureMap.getNumItems () > TargetFeatureMap.getNumItems ()) {
1134
+ DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
1135
+ dbgs () << " Incompatible: CodeObject has more features "
1136
+ " than target \t [CodeObject: "
1137
+ << CodeObjectInfo.str ()
1138
+ << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1139
+ return false ;
1140
+ }
1141
+
1142
+ // Compatible if each target feature specified by target is compatible with
1143
+ // target feature of code object. The target feature is compatible if the
1144
+ // code object does not specify it (meaning Any), or if it specifies it
1145
+ // with the same value (meaning On or Off).
1146
+ for (const auto &CodeObjectFeature : CodeObjectFeatureMap) {
1147
+ auto TargetFeature = TargetFeatureMap.find (CodeObjectFeature.getKey ());
1148
+ if (TargetFeature == TargetFeatureMap.end ()) {
1149
+ DEBUG_WITH_TYPE (
1150
+ " CodeObjectCompatibility" ,
1151
+ dbgs ()
1152
+ << " Incompatible: Value of CodeObject's non-ANY feature is "
1153
+ " not matching with Target feature's ANY value \t [CodeObject: "
1154
+ << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
1155
+ << " ]\n " );
1156
+ return false ;
1157
+ } else if (TargetFeature->getValue () != CodeObjectFeature.getValue ()) {
1158
+ DEBUG_WITH_TYPE (
1159
+ " CodeObjectCompatibility" ,
1160
+ dbgs () << " Incompatible: Value of CodeObject's non-ANY feature is "
1161
+ " not matching with Target feature's non-ANY value "
1162
+ " \t [CodeObject: "
1163
+ << CodeObjectInfo.str ()
1164
+ << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1165
+ return false ;
1166
+ }
1167
+ }
1168
+
1169
+ // CodeObject is compatible if all features of Target are:
1170
+ // - either, present in the Code Object's features map with the same sign,
1171
+ // - or, the feature is missing from CodeObjects's features map i.e. it is
1172
+ // set to ANY
1173
+ DEBUG_WITH_TYPE (
1174
+ " CodeObjectCompatibility" ,
1175
+ dbgs () << " Compatible: Target IDs are compatible \t [CodeObject: "
1176
+ << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
1177
+ << " ]\n " );
1178
+ return true ;
1179
+ }
1180
+
1133
1181
// / Bundle the files. Return true if an error was found.
1134
1182
Error OffloadBundler::BundleFiles () {
1135
1183
std::error_code EC;
@@ -1348,99 +1396,6 @@ static Archive::Kind getDefaultArchiveKindForHost() {
1348
1396
: Archive::K_GNU;
1349
1397
}
1350
1398
1351
- // / @brief Checks if a code object \p CodeObjectInfo is compatible with a given
1352
- // / target \p TargetInfo.
1353
- // / @link https://clang.llvm.org/docs/ClangOffloadBundler.html#bundle-entry-id
1354
- bool isCodeObjectCompatible (OffloadTargetInfo &CodeObjectInfo,
1355
- OffloadTargetInfo &TargetInfo) {
1356
-
1357
- // Compatible in case of exact match.
1358
- if (CodeObjectInfo == TargetInfo) {
1359
- DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
1360
- dbgs () << " Compatible: Exact match: \t [CodeObject: "
1361
- << CodeObjectInfo.str ()
1362
- << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1363
- return true ;
1364
- }
1365
-
1366
- // Incompatible if Kinds or Triples mismatch.
1367
- if (!CodeObjectInfo.isOffloadKindCompatible (TargetInfo.OffloadKind ) ||
1368
- !CodeObjectInfo.Triple .isCompatibleWith (TargetInfo.Triple )) {
1369
- DEBUG_WITH_TYPE (
1370
- " CodeObjectCompatibility" ,
1371
- dbgs () << " Incompatible: Kind/Triple mismatch \t [CodeObject: "
1372
- << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
1373
- << " ]\n " );
1374
- return false ;
1375
- }
1376
-
1377
- // Incompatible if Processors mismatch.
1378
- llvm::StringMap<bool > CodeObjectFeatureMap, TargetFeatureMap;
1379
- std::optional<StringRef> CodeObjectProc = clang::parseTargetID (
1380
- CodeObjectInfo.Triple , CodeObjectInfo.TargetID , &CodeObjectFeatureMap);
1381
- std::optional<StringRef> TargetProc = clang::parseTargetID (
1382
- TargetInfo.Triple , TargetInfo.TargetID , &TargetFeatureMap);
1383
-
1384
- // Both TargetProc and CodeObjectProc can't be empty here.
1385
- if (!TargetProc || !CodeObjectProc ||
1386
- CodeObjectProc.value () != TargetProc.value ()) {
1387
- DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
1388
- dbgs () << " Incompatible: Processor mismatch \t [CodeObject: "
1389
- << CodeObjectInfo.str ()
1390
- << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1391
- return false ;
1392
- }
1393
-
1394
- // Incompatible if CodeObject has more features than Target, irrespective of
1395
- // type or sign of features.
1396
- if (CodeObjectFeatureMap.getNumItems () > TargetFeatureMap.getNumItems ()) {
1397
- DEBUG_WITH_TYPE (" CodeObjectCompatibility" ,
1398
- dbgs () << " Incompatible: CodeObject has more features "
1399
- " than target \t [CodeObject: "
1400
- << CodeObjectInfo.str ()
1401
- << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1402
- return false ;
1403
- }
1404
-
1405
- // Compatible if each target feature specified by target is compatible with
1406
- // target feature of code object. The target feature is compatible if the
1407
- // code object does not specify it (meaning Any), or if it specifies it
1408
- // with the same value (meaning On or Off).
1409
- for (const auto &CodeObjectFeature : CodeObjectFeatureMap) {
1410
- auto TargetFeature = TargetFeatureMap.find (CodeObjectFeature.getKey ());
1411
- if (TargetFeature == TargetFeatureMap.end ()) {
1412
- DEBUG_WITH_TYPE (
1413
- " CodeObjectCompatibility" ,
1414
- dbgs ()
1415
- << " Incompatible: Value of CodeObject's non-ANY feature is "
1416
- " not matching with Target feature's ANY value \t [CodeObject: "
1417
- << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
1418
- << " ]\n " );
1419
- return false ;
1420
- } else if (TargetFeature->getValue () != CodeObjectFeature.getValue ()) {
1421
- DEBUG_WITH_TYPE (
1422
- " CodeObjectCompatibility" ,
1423
- dbgs () << " Incompatible: Value of CodeObject's non-ANY feature is "
1424
- " not matching with Target feature's non-ANY value "
1425
- " \t [CodeObject: "
1426
- << CodeObjectInfo.str ()
1427
- << " ]\t :\t [Target: " << TargetInfo.str () << " ]\n " );
1428
- return false ;
1429
- }
1430
- }
1431
-
1432
- // CodeObject is compatible if all features of Target are:
1433
- // - either, present in the Code Object's features map with the same sign,
1434
- // - or, the feature is missing from CodeObjects's features map i.e. it is
1435
- // set to ANY
1436
- DEBUG_WITH_TYPE (
1437
- " CodeObjectCompatibility" ,
1438
- dbgs () << " Compatible: Target IDs are compatible \t [CodeObject: "
1439
- << CodeObjectInfo.str () << " ]\t :\t [Target: " << TargetInfo.str ()
1440
- << " ]\n " );
1441
- return true ;
1442
- }
1443
-
1444
1399
// / @brief Computes a list of targets among all given targets which are
1445
1400
// / compatible with this code object
1446
1401
// / @param [in] CodeObjectInfo Code Object
@@ -1468,8 +1423,9 @@ getCompatibleOffloadTargets(OffloadTargetInfo &CodeObjectInfo,
1468
1423
// rule: for a specific processor, a feature either shows up in all target IDs,
1469
1424
// or does not show up in any target IDs. Otherwise the target ID combination is
1470
1425
// invalid.
1471
- static Error CheckHeterogeneousArchive (StringRef ArchiveName,
1472
- const OffloadBundlerConfig &BundlerConfig) {
1426
+ static Error
1427
+ CheckHeterogeneousArchive (StringRef ArchiveName,
1428
+ const OffloadBundlerConfig &BundlerConfig) {
1473
1429
std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
1474
1430
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
1475
1431
MemoryBuffer::getFileOrSTDIN (ArchiveName, true , false );
0 commit comments