llvm.org GIT mirror llvm / 23b1498
[Triple] Reimplement isLittleEndian(). Now it works for arm too. Differential Revision: http://reviews.llvm.org/D21846 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274154 91177308-0d34-0410-b5e6-96231b3b80d8 Davide Italiano 3 years ago
2 changed file(s) with 34 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
12871287
12881288 Triple Triple::getBigEndianArchVariant() const {
12891289 Triple T(*this);
1290 // Already big endian.
1291 if (!isLittleEndian())
1292 return T;
12901293 switch (getArch()) {
12911294 case Triple::UnknownArch:
12921295 case Triple::amdgcn:
13191322 T.setArch(UnknownArch);
13201323 break;
13211324
1322 case Triple::aarch64_be:
1323 case Triple::armeb:
1324 case Triple::bpfeb:
1325 case Triple::lanai:
1326 case Triple::mips64:
1327 case Triple::mips:
1328 case Triple::ppc64:
1329 case Triple::ppc:
1330 case Triple::sparc:
1331 case Triple::sparcv9:
1332 case Triple::systemz:
1333 case Triple::tce:
1334 case Triple::thumbeb:
1335 // Already big endian.
1336 break;
1337
13381325 case Triple::aarch64: T.setArch(Triple::aarch64_be); break;
13391326 case Triple::bpfel: T.setArch(Triple::bpfeb); break;
13401327 case Triple::mips64el:T.setArch(Triple::mips64); break;
13411328 case Triple::mipsel: T.setArch(Triple::mips); break;
13421329 case Triple::ppc64le: T.setArch(Triple::ppc64); break;
13431330 case Triple::sparcel: T.setArch(Triple::sparc); break;
1331 default:
1332 llvm_unreachable("getBigEndianArchVariant: unknown triple.");
13441333 }
13451334 return T;
13461335 }
13471336
13481337 Triple Triple::getLittleEndianArchVariant() const {
13491338 Triple T(*this);
1339 if (isLittleEndian())
1340 return T;
1341
13501342 switch (getArch()) {
13511343 case Triple::UnknownArch:
13521344 case Triple::lanai:
13621354 T.setArch(UnknownArch);
13631355 break;
13641356
1357 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1358 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1359 case Triple::mips64: T.setArch(Triple::mips64el); break;
1360 case Triple::mips: T.setArch(Triple::mipsel); break;
1361 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1362 case Triple::sparc: T.setArch(Triple::sparcel); break;
1363 default:
1364 llvm_unreachable("getLittleEndianArchVariant: unknown triple.");
1365 }
1366 return T;
1367 }
1368
1369 bool Triple::isLittleEndian() const {
1370 switch (getArch()) {
13651371 case Triple::aarch64:
13661372 case Triple::amdgcn:
13671373 case Triple::amdil64:
13921398 case Triple::x86:
13931399 case Triple::x86_64:
13941400 case Triple::xcore:
1395 // Already little endian.
1396 break;
1397
1398 case Triple::aarch64_be: T.setArch(Triple::aarch64); break;
1399 case Triple::bpfeb: T.setArch(Triple::bpfel); break;
1400 case Triple::mips64: T.setArch(Triple::mips64el); break;
1401 case Triple::mips: T.setArch(Triple::mipsel); break;
1402 case Triple::ppc64: T.setArch(Triple::ppc64le); break;
1403 case Triple::sparc: T.setArch(Triple::sparcel); break;
1404 }
1405 return T;
1406 }
1407
1408 bool Triple::isLittleEndian() const {
1409 return *this == getLittleEndianArchVariant();
1401 return true;
1402 default:
1403 return false;
1404 }
14101405 }
14111406
14121407 StringRef Triple::getARMCPUForArch(StringRef MArch) const {
642642 T.setArch(Triple::arm);
643643 EXPECT_EQ(Triple::UnknownArch, T.getBigEndianArchVariant().getArch());
644644 EXPECT_EQ(Triple::arm, T.getLittleEndianArchVariant().getArch());
645 T = Triple("arm");
646 EXPECT_TRUE(T.isLittleEndian());
647 T = Triple("thumb");
648 EXPECT_TRUE(T.isLittleEndian());
649 T = Triple("armeb");
650 EXPECT_FALSE(T.isLittleEndian());
651 T = Triple("thumbeb");
652 EXPECT_FALSE(T.isLittleEndian());
645653
646654 T.setArch(Triple::bpfeb);
647655 EXPECT_EQ(Triple::bpfeb, T.getBigEndianArchVariant().getArch());