12
12
#include " llvm/ADT/SetVector.h"
13
13
#include " llvm/ADT/SmallPtrSet.h"
14
14
#include " llvm/ADT/SmallString.h"
15
- #include " llvm/Analysis/TargetLibraryInfo.h"
16
15
#include " llvm/IR/AutoUpgrade.h"
17
16
#include " llvm/IR/Constants.h"
18
17
#include " llvm/IR/DebugInfoMetadata.h"
@@ -400,9 +399,6 @@ class IRLinker {
400
399
// / A metadata map that's shared between IRLinker instances.
401
400
MDMapT &SharedMDs;
402
401
403
- // / A list of libcalls that the current target may call.
404
- IRMover::LibcallHandler &Libcalls;
405
-
406
402
// / Mapping of values from what they used to be in Src, to what they are now
407
403
// / in DstM. ValueToValueMapTy is a ValueMap, which involves some overhead
408
404
// / due to the use of Value handles which the Linker doesn't actually need,
@@ -544,12 +540,10 @@ class IRLinker {
544
540
IRLinker (Module &DstM, MDMapT &SharedMDs,
545
541
IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM,
546
542
ArrayRef<GlobalValue *> ValuesToLink,
547
- IRMover::LibcallHandler &Libcalls, IRMover::LazyCallback AddLazyFor,
548
- bool IsPerformingImport)
543
+ IRMover::LazyCallback AddLazyFor, bool IsPerformingImport)
549
544
: DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
550
545
TypeMap (Set), GValMaterializer(*this ), LValMaterializer(*this ),
551
- SharedMDs(SharedMDs), Libcalls(Libcalls),
552
- IsPerformingImport(IsPerformingImport),
546
+ SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
553
547
Mapper(ValueMap, RF_ReuseAndMutateDistinctMDs | RF_IgnoreMissingLocals,
554
548
&TypeMap, &GValMaterializer),
555
549
IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
@@ -567,13 +561,6 @@ class IRLinker {
567
561
};
568
562
}
569
563
570
- static void addNoBuiltinAttributes (Function &F) {
571
- F.setAttributes (
572
- F.getAttributes ().addFnAttribute (F.getContext (), " no-builtins" ));
573
- F.setAttributes (
574
- F.getAttributes ().addFnAttribute (F.getContext (), Attribute::NoBuiltin));
575
- }
576
-
577
564
// / The LLVM SymbolTable class autorenames globals that conflict in the symbol
578
565
// / table. This is good for all clients except for us. Go through the trouble
579
566
// / to force this back.
@@ -1618,26 +1605,14 @@ Error IRLinker::run() {
1618
1605
1619
1606
DstM.setTargetTriple (SrcTriple.merge (DstTriple));
1620
1607
1621
- // Update the target triple's libcall information if it was changed.
1622
- Libcalls.updateLibcalls (Triple (DstM.getTargetTriple ()));
1623
-
1624
1608
// Loop over all of the linked values to compute type mappings.
1625
1609
computeTypeMapping ();
1626
1610
1627
- bool AddsLibcalls = false ;
1628
1611
std::reverse (Worklist.begin (), Worklist.end ());
1629
1612
while (!Worklist.empty ()) {
1630
1613
GlobalValue *GV = Worklist.back ();
1631
1614
Worklist.pop_back ();
1632
1615
1633
- // If the module already contains libcall functions we need every function
1634
- // linked in to have `nobuiltin` attributes. Otherwise check if this is a
1635
- // libcall definition.
1636
- if (Function *F = dyn_cast<Function>(GV); F && Libcalls.hasLibcalls ())
1637
- addNoBuiltinAttributes (*F);
1638
- else
1639
- AddsLibcalls = Libcalls.checkLibcalls (*GV);
1640
-
1641
1616
// Already mapped.
1642
1617
if (ValueMap.find (GV) != ValueMap.end () ||
1643
1618
IndirectSymbolValueMap.find (GV) != IndirectSymbolValueMap.end ())
@@ -1700,13 +1675,6 @@ Error IRLinker::run() {
1700
1675
}
1701
1676
}
1702
1677
1703
- // If we have imported a recognized libcall function we can no longer make any
1704
- // reasonable optimizations based off of its semantics. Add the 'nobuiltin'
1705
- // attribute to every function to suppress libcall detection.
1706
- if (AddsLibcalls)
1707
- for (Function &F : DstM.functions ())
1708
- addNoBuiltinAttributes (F);
1709
-
1710
1678
// Merge the module flags into the DstM module.
1711
1679
return linkModuleFlagsMetadata ();
1712
1680
}
@@ -1789,22 +1757,6 @@ bool IRMover::IdentifiedStructTypeSet::hasType(StructType *Ty) {
1789
1757
return I == NonOpaqueStructTypes.end () ? false : *I == Ty;
1790
1758
}
1791
1759
1792
- void IRMover::LibcallHandler::updateLibcalls (const Triple &TheTriple) {
1793
- if (Triples.count (TheTriple.getTriple ()))
1794
- return ;
1795
- Triples.insert (Saver.save (TheTriple.getTriple ()));
1796
-
1797
- // Collect the names of runtime functions that the target may want to call.
1798
- TargetLibraryInfoImpl TLII (TheTriple);
1799
- TargetLibraryInfo TLI (TLII);
1800
- for (unsigned I = 0 , E = static_cast <unsigned >(LibFunc::NumLibFuncs); I != E;
1801
- ++I) {
1802
- LibFunc F = static_cast <LibFunc>(I);
1803
- if (TLI.has (F))
1804
- Libcalls.insert (TLI.getName (F));
1805
- }
1806
- }
1807
-
1808
1760
IRMover::IRMover (Module &M) : Composite(M) {
1809
1761
TypeFinder StructTypes;
1810
1762
StructTypes.run (M, /* OnlyNamed */ false );
@@ -1820,25 +1772,14 @@ IRMover::IRMover(Module &M) : Composite(M) {
1820
1772
for (const auto *MD : StructTypes.getVisitedMetadata ()) {
1821
1773
SharedMDs[MD].reset (const_cast <MDNode *>(MD));
1822
1774
}
1823
-
1824
- // Check the composite module for any already present libcalls. If we define
1825
- // these then it is important to mark any imported functions as 'nobuiltin'.
1826
- Libcalls.updateLibcalls (Triple (Composite.getTargetTriple ()));
1827
- for (Function &F : Composite.functions ())
1828
- if (Libcalls.checkLibcalls (F))
1829
- break ;
1830
-
1831
- if (Libcalls.hasLibcalls ())
1832
- for (Function &F : Composite.functions ())
1833
- addNoBuiltinAttributes (F);
1834
1775
}
1835
1776
1836
1777
Error IRMover::move (std::unique_ptr<Module> Src,
1837
1778
ArrayRef<GlobalValue *> ValuesToLink,
1838
1779
LazyCallback AddLazyFor, bool IsPerformingImport) {
1839
1780
IRLinker TheIRLinker (Composite, SharedMDs, IdentifiedStructTypes,
1840
- std::move (Src), ValuesToLink, Libcalls ,
1841
- std::move (AddLazyFor), IsPerformingImport);
1781
+ std::move (Src), ValuesToLink, std::move (AddLazyFor) ,
1782
+ IsPerformingImport);
1842
1783
Error E = TheIRLinker.run ();
1843
1784
Composite.dropTriviallyDeadConstantArrays ();
1844
1785
return E;
0 commit comments