llvm.org GIT mirror llvm / 32f3dc4
[Triple] Add a helper to switch between big/little endian variants This will be used from clang's driver. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241527 91177308-0d34-0410-b5e6-96231b3b80d8 Benjamin Kramer 5 years ago
3 changed file(s) with 210 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
568568 /// architecture if no such variant can be found.
569569 llvm::Triple get64BitArchVariant() const;
570570
571 /// Form a triple with a big endian variant of the current architecture.
572 ///
573 /// This can be used to move across "families" of architectures where useful.
574 ///
575 /// \returns A new triple with a big endian architecture or an unknown
576 /// architecture if no such variant can be found.
577 llvm::Triple getBigEndianArchVariant() const;
578
579 /// Form a triple with a little endian variant of the current architecture.
580 ///
581 /// This can be used to move across "families" of architectures where useful.
582 ///
583 /// \returns A new triple with a little endian architecture or an unknown
584 /// architecture if no such variant can be found.
585 llvm::Triple getLittleEndianArchVariant() const;
586
571587 /// Get the (LLVM) name of the minimum ARM CPU for the arch we are targeting.
572588 ///
573589 /// \param Arch the architecture name (e.g., "armv7s"). If it is an empty
11641164 return T;
11651165 }
11661166
1167 Triple Triple::getBigEndianArchVariant() const {
1168 Triple T(*this);
1169 switch (getArch()) {
1170 case Triple::UnknownArch:
1171 case Triple::amdgcn:
1172 case Triple::amdil64:
1173 case Triple::amdil:
1174 case Triple::hexagon:
1175 case Triple::hsail64:
1176 case Triple::hsail:
1177 case Triple::kalimba:
1178 case Triple::le32:
1179 case Triple::le64:
1180 case Triple::msp430:
1181 case Triple::nvptx64:
1182 case Triple::nvptx:
1183 case Triple::r600:
1184 case Triple::shave:
1185 case Triple::spir64:
1186 case Triple::spir:
1187 case Triple::wasm32:
1188 case Triple::wasm64:
1189 case Triple::x86:
1190 case Triple::x86_64:
1191 case Triple::xcore:
1192
1193 // ARM is intentionally unsupported here, changing the architecture would
1194 // drop any arch suffixes.
1195 case Triple::arm:
1196 case Triple::thumb:
1197 T.setArch(UnknownArch);
1198 break;
1199
1200 case Triple::aarch64_be:
1201 case Triple::armeb:
1202 case Triple::bpfeb:
1203 case Triple::mips64:
1204 case Triple::mips:
1205 case Triple::ppc64:
1206 case Triple::ppc:
1207 case Triple::sparc:
1208 case Triple::sparcv9:
1209 case Triple::systemz:
1210 case Triple::tce:
1211 case Triple::thumbeb:
1212 // Already big endian.
1213 break;
1214
1215 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
1216 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
1217 case Triple::mips64el:T.setArch(Triple::mips64); break;
1218 case Triple::mipsel: T.setArch(Triple::mips); break;
1219 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
1220 case Triple::sparcel: T.setArch(Triple::sparc); break;
1221 }
1222 return T;
1223 }
1224
1225 Triple Triple::getLittleEndianArchVariant() const {
1226 Triple T(*this);
1227 switch (getArch()) {
1228 case Triple::UnknownArch:
1229 case Triple::ppc:
1230 case Triple::sparcv9:
1231 case Triple::systemz:
1232 case Triple::tce:
1233
1234 // ARM is intentionally unsupported here, changing the architecture would
1235 // drop any arch suffixes.
1236 case Triple::armeb:
1237 case Triple::thumbeb:
1238 T.setArch(UnknownArch);
1239 break;
1240
1241 case Triple::aarch64:
1242 case Triple::amdgcn:
1243 case Triple::amdil64:
1244 case Triple::amdil:
1245 case Triple::arm:
1246 case Triple::bpfel:
1247 case Triple::hexagon:
1248 case Triple::hsail64:
1249 case Triple::hsail:
1250 case Triple::kalimba:
1251 case Triple::le32:
1252 case Triple::le64:
1253 case Triple::mips64el:
1254 case Triple::mipsel:
1255 case Triple::msp430:
1256 case Triple::nvptx64:
1257 case Triple::nvptx:
1258 case Triple::ppc64le:
1259 case Triple::r600:
1260 case Triple::shave:
1261 case Triple::sparcel:
1262 case Triple::spir64:
1263 case Triple::spir:
1264 case Triple::thumb:
1265 case Triple::wasm32:
1266 case Triple::wasm64:
1267 case Triple::x86:
1268 case Triple::x86_64:
1269 case Triple::xcore:
1270 // Already little endian.
1271 break;
1272
1273 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1274 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1275 case Triple::mips64: T.setArch(Triple::mips64el); break;
1276 case Triple::mips: T.setArch(Triple::mipsel); break;
1277 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1278 case Triple::sparc: T.setArch(Triple::sparcel); break;
1279 }
1280 return T;
1281 }
1282
11671283 const char *Triple::getARMCPUForArch(StringRef MArch) const {
11681284 if (MArch.empty())
11691285 MArch = getArchName();
552552 EXPECT_EQ(Triple::wasm64, T.get64BitArchVariant().getArch());
553553 }
554554
555 TEST(TripleTest, EndianArchVariants) {
556 Triple T;
557 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
558 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
559
560 T.setArch(Triple::UnknownArch);
561 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
562 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
563
564 T.setArch(Triple::aarch64_be);
565 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
566 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
567
568 T.setArch(Triple::aarch64);
569 EXPECT_EQ(Triple::aarch64_be, T.getBigEndianArchVariant().getArch());
570 EXPECT_EQ(Triple::aarch64, T.getLittleEndianArchVariant().getArch());
571
572 T.setArch(Triple::armeb);
573 EXPECT_EQ(Triple::armeb, T.getBigEndianArchVariant().getArch());
574 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
575
576 T.setArch(Triple::arm);
577 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
578 EXPECT_EQ(Triple::arm, T.getLittleEndianArchVariant().getArch());
579
580 T.setArch(Triple::bpfeb);
581 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
582 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
583
584 T.setArch(Triple::bpfel);
585 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());
586 EXPECT_EQ(Triple::bpfel, T.getLittleEndianArchVariant().getArch());
587
588 T.setArch(Triple::mips64);
589 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
590 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
591
592 T.setArch(Triple::mips64el);
593 EXPECT_EQ(Triple::mips64, T.getBigEndianArchVariant().getArch());
594 EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());
595
596 T.setArch(Triple::mips);
597 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
598 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
599
600 T.setArch(Triple::mipsel);
601 EXPECT_EQ(Triple::mips, T.getBigEndianArchVariant().getArch());
602 EXPECT_EQ(Triple::mipsel, T.getLittleEndianArchVariant().getArch());
603
604 T.setArch(Triple::ppc);
605 EXPECT_EQ(Triple::ppc, T.getBigEndianArchVariant().getArch());
606 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
607
608 T.setArch(Triple::ppc64);
609 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
610 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
611
612 T.setArch(Triple::ppc64le);
613 EXPECT_EQ(Triple::ppc64, T.getBigEndianArchVariant().getArch());
614 EXPECT_EQ(Triple::ppc64le, T.getLittleEndianArchVariant().getArch());
615
616 T.setArch(Triple::sparc);
617 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
618 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
619
620 T.setArch(Triple::sparcel);
621 EXPECT_EQ(Triple::sparc, T.getBigEndianArchVariant().getArch());
622 EXPECT_EQ(Triple::sparcel, T.getLittleEndianArchVariant().getArch());
623
624 T.setArch(Triple::thumb);
625 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
626 EXPECT_EQ(Triple::thumb, T.getLittleEndianArchVariant().getArch());
627
628 T.setArch(Triple::thumbeb);
629 EXPECT_EQ(Triple::thumbeb, T.getBigEndianArchVariant().getArch());
630 EXPECT_EQ(Triple::UnknownArch, T.getLittleEndianArchVariant().getArch());
631 }
632
555633 TEST(TripleTest, getOSVersion) {
556634 Triple T;
557635 unsigned Major, Minor, Micro;