llvm.org GIT mirror llvm / ac844bf
[LinkModules] Change the way ModuleLinker merges triples. This commit makes the following changes: - Stop issuing a warning when the triples' string representations do not match exactly if the Triple objects generated from the strings compare equal. - On Apple platforms, choose the triple that has the larger minimum version number. rdar://problem/16743513 Differential Revision: http://reviews.llvm.org/D7591 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228999 91177308-0d34-0410-b5e6-96231b3b80d8 Akira Hatanaka 5 years ago
11 changed file(s) with 83 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
201201 Triple(const Twine &ArchStr, const Twine &VendorStr, const Twine &OSStr,
202202 const Twine &EnvironmentStr);
203203
204 bool operator==(const Triple &Other) const {
205 return Arch == Other.Arch && SubArch == Other.SubArch &&
206 Vendor == Other.Vendor && OS == Other.OS &&
207 Environment == Other.Environment &&
208 ObjectFormat == Other.ObjectFormat;
209 }
210
204211 /// @}
205212 /// @name Normalization
206213 /// @{
338345 return false;
339346 }
340347
348 bool isOSVersionLT(const Triple &Other) const {
349 unsigned RHS[3];
350 Other.getOSVersion(RHS[0], RHS[1], RHS[2]);
351 return isOSVersionLT(RHS[0], RHS[1], RHS[2]);
352 }
353
341354 /// isMacOSXVersionLT - Comparison function for checking OS X version
342355 /// compatibility, which handles supporting skewed version numbering schemes
343356 /// used by the "darwin" triples.
1717 #include "llvm/ADT/SetVector.h"
1818 #include "llvm/ADT/SmallString.h"
1919 #include "llvm/ADT/Statistic.h"
20 #include "llvm/ADT/Triple.h"
2021 #include "llvm/IR/Constants.h"
2122 #include "llvm/IR/DebugInfo.h"
2223 #include "llvm/IR/DiagnosticInfo.h"
14561457 return HasErr;
14571458 }
14581459
1460 // This function returns true if the triples match.
1461 static bool triplesMatch(const Triple &T0, const Triple &T1) {
1462 // If vendor is apple, ignore the version number.
1463 if (T0.getVendor() == Triple::Apple)
1464 return T0.getArch() == T1.getArch() &&
1465 T0.getSubArch() == T1.getSubArch() &&
1466 T0.getVendor() == T1.getVendor() &&
1467 T0.getOS() == T1.getOS();
1468
1469 return T0 == T1;
1470 }
1471
1472 // This function returns the merged triple.
1473 static std::string mergeTriples(const Triple &SrcTriple, const Triple &DstTriple) {
1474 // If vendor is apple, pick the triple with the larger version number.
1475 if (SrcTriple.getVendor() == Triple::Apple)
1476 if (DstTriple.isOSVersionLT(SrcTriple))
1477 return SrcTriple.str();
1478
1479 return DstTriple.str();
1480 }
1481
14591482 bool ModuleLinker::run() {
14601483 assert(DstM && "Null destination module");
14611484 assert(SrcM && "Null source module");
14641487 // doesn't have one already.
14651488 if (!DstM->getDataLayout() && SrcM->getDataLayout())
14661489 DstM->setDataLayout(SrcM->getDataLayout());
1467
1468 // Copy the target triple from the source to dest if the dest's is empty.
1469 if (DstM->getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1470 DstM->setTargetTriple(SrcM->getTargetTriple());
14711490
14721491 if (SrcM->getDataLayout() && DstM->getDataLayout() &&
14731492 *SrcM->getDataLayout() != *DstM->getDataLayout()) {
14771496 DstM->getModuleIdentifier() + "' is '" +
14781497 DstM->getDataLayoutStr() + "'\n");
14791498 }
1480 if (!SrcM->getTargetTriple().empty() &&
1481 DstM->getTargetTriple() != SrcM->getTargetTriple()) {
1499
1500 // Copy the target triple from the source to dest if the dest's is empty.
1501 if (DstM->getTargetTriple().empty() && !SrcM->getTargetTriple().empty())
1502 DstM->setTargetTriple(SrcM->getTargetTriple());
1503
1504 Triple SrcTriple(SrcM->getTargetTriple()), DstTriple(DstM->getTargetTriple());
1505
1506 if (!SrcM->getTargetTriple().empty() && !triplesMatch(SrcTriple, DstTriple))
14821507 emitWarning("Linking two modules of different target triples: " +
14831508 SrcM->getModuleIdentifier() + "' is '" +
14841509 SrcM->getTargetTriple() + "' whereas '" +
14851510 DstM->getModuleIdentifier() + "' is '" +
14861511 DstM->getTargetTriple() + "'\n");
1487 }
1512
1513 DstM->setTargetTriple(mergeTriples(SrcTriple, DstTriple));
14881514
14891515 // Append the module inline asm string.
14901516 if (!SrcM->getModuleInlineAsm().empty()) {
0 target triple = "x86_64-apple-macosx10.10.0"
0 target triple = "x86_64-apple-macosx10.8.0"
0 target triple = "i386-apple-macosx10.9.0"
0 target triple = "x86_64h-apple-macosx10.9.0"
None target triple = "e"
0 target triple = "x86_64-unknown-linux-gnu"
None target triple = "E"
0 target triple = "i386-unknown-linux-gnu"
0 target triple = "x86_64h-unknown-linux-gnu"
0 ; RUN: llvm-link %s %S/Inputs/apple-version/1.ll -S -o - 2>%t.err | FileCheck %s -check-prefix=CHECK1
1 ; RUN: cat %t.err | FileCheck --check-prefix=WARN1 --allow-empty %s
2 ; RUN: llvm-link %s %S/Inputs/apple-version/2.ll -S -o - 2>%t.err | FileCheck %s -check-prefix=CHECK2
3 ; RUN: cat %t.err | FileCheck --check-prefix=WARN2 --allow-empty %s
4 ; RUN: llvm-link %s %S/Inputs/apple-version/3.ll -S -o /dev/null 2>%t.err
5 ; RUN: cat %t.err | FileCheck --check-prefix=WARN3 %s
6 ; RUN: llvm-link %s %S/Inputs/apple-version/4.ll -S -o /dev/null 2>%t.err
7 ; RUN: cat %t.err | FileCheck --check-prefix=WARN4 --allow-empty %s
8
9 ; Check that the triple that has the larger version number is chosen and no
10 ; warnings are issued when the Triples differ only in version numbers.
11
12 ; CHECK1: target triple = "x86_64-apple-macosx10.10.0"
13 ; WARN1-NOT: WARNING
14 ; CHECK2: target triple = "x86_64-apple-macosx10.9.0"
15 ; WARN2-NOT: WARNING
16
17 ; i386 and x86_64 map to different ArchType enums.
18 ; WARN3: WARNING: Linking two modules of different target triples
19
20 ; x86_64h and x86_64 map to the same ArchType enum.
21 ; WARN4-NOT: WARNING
22
23 target triple = "x86_64-apple-macosx10.9.0"
77 ; RUN: llvm-link -suppress-warnings %s %S/Inputs/targettriple-b.ll -S -o - 2>%t.no-warn.err | FileCheck %s
88 ; RUN: (echo foo ;cat %t.no-warn.err) | FileCheck --check-prefix=WARN-A %s
99
10 target triple = "e"
10 target triple = "x86_64-unknown-linux-gnu"
1111
12 ; CHECK: target triple = "e"
12 ; CHECK: target triple = "x86_64-unknown-linux-gnu"
1313
1414 ; WARN-A-NOT: WARNING
1515
16 ; i386 and x86_64 map to different ArchType enums.
1617 ; WARN-B: WARNING: Linking two modules of different target triples:
18
19 ; x86_64h and x86_64 map to the same ArchType enum.
20 ; WARN-C-NOT: WARNING