Skip to content

Commit 673cfcd

Browse files
committed
Revert "[Linker] Propagate nobuiltin attributes when linking known libcalls (#89431)"
This apparently breaks AMDGPU offloading for unknown reasons. Reverting for now. This reverts commit aa16de6.
1 parent 139e0aa commit 673cfcd

File tree

5 files changed

+5
-156
lines changed

5 files changed

+5
-156
lines changed

llvm/include/llvm/Linker/IRMover.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/DenseSet.h"
1414
#include "llvm/ADT/FunctionExtras.h"
15-
#include "llvm/ADT/StringSet.h"
16-
#include "llvm/IR/GlobalValue.h"
17-
#include "llvm/Support/StringSaver.h"
18-
#include "llvm/TargetParser/Triple.h"
1915
#include <functional>
2016

2117
namespace llvm {
2218
class Error;
19+
class GlobalValue;
2320
class Metadata;
2421
class Module;
2522
class StructType;
@@ -63,33 +60,6 @@ class IRMover {
6360
bool hasType(StructType *Ty);
6461
};
6562

66-
/// Utility for handling linking of known libcall functions. If a merged
67-
/// module contains a recognized library call we can no longer perform any
68-
/// libcall related transformations.
69-
class LibcallHandler {
70-
bool HasLibcalls = false;
71-
72-
StringSet<> Libcalls;
73-
StringSet<> Triples;
74-
75-
BumpPtrAllocator Alloc;
76-
StringSaver Saver;
77-
78-
public:
79-
LibcallHandler() : Saver(Alloc) {}
80-
81-
void updateLibcalls(const Triple &TheTriple);
82-
83-
bool checkLibcalls(GlobalValue &GV) {
84-
if (HasLibcalls)
85-
return false;
86-
return HasLibcalls = isa<Function>(&GV) && !GV.isDeclaration() &&
87-
Libcalls.count(GV.getName());
88-
}
89-
90-
bool hasLibcalls() const { return HasLibcalls; }
91-
};
92-
9363
IRMover(Module &M);
9464

9565
typedef std::function<void(GlobalValue &)> ValueAdder;
@@ -114,7 +84,6 @@ class IRMover {
11484
Module &Composite;
11585
IdentifiedStructTypeSet IdentifiedStructTypes;
11686
MDMapT SharedMDs; ///< A Metadata map to use for all calls to \a move().
117-
LibcallHandler Libcalls;
11887
};
11988

12089
} // End llvm namespace

llvm/lib/Linker/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ add_llvm_component_library(LLVMLinker
99
intrinsics_gen
1010

1111
LINK_COMPONENTS
12-
Analysis
1312
Core
1413
Object
1514
Support

llvm/lib/Linker/IRMover.cpp

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "llvm/ADT/SetVector.h"
1313
#include "llvm/ADT/SmallPtrSet.h"
1414
#include "llvm/ADT/SmallString.h"
15-
#include "llvm/Analysis/TargetLibraryInfo.h"
1615
#include "llvm/IR/AutoUpgrade.h"
1716
#include "llvm/IR/Constants.h"
1817
#include "llvm/IR/DebugInfoMetadata.h"
@@ -400,9 +399,6 @@ class IRLinker {
400399
/// A metadata map that's shared between IRLinker instances.
401400
MDMapT &SharedMDs;
402401

403-
/// A list of libcalls that the current target may call.
404-
IRMover::LibcallHandler &Libcalls;
405-
406402
/// Mapping of values from what they used to be in Src, to what they are now
407403
/// in DstM. ValueToValueMapTy is a ValueMap, which involves some overhead
408404
/// due to the use of Value handles which the Linker doesn't actually need,
@@ -544,12 +540,10 @@ class IRLinker {
544540
IRLinker(Module &DstM, MDMapT &SharedMDs,
545541
IRMover::IdentifiedStructTypeSet &Set, std::unique_ptr<Module> SrcM,
546542
ArrayRef<GlobalValue *> ValuesToLink,
547-
IRMover::LibcallHandler &Libcalls, IRMover::LazyCallback AddLazyFor,
548-
bool IsPerformingImport)
543+
IRMover::LazyCallback AddLazyFor, bool IsPerformingImport)
549544
: DstM(DstM), SrcM(std::move(SrcM)), AddLazyFor(std::move(AddLazyFor)),
550545
TypeMap(Set), GValMaterializer(*this), LValMaterializer(*this),
551-
SharedMDs(SharedMDs), Libcalls(Libcalls),
552-
IsPerformingImport(IsPerformingImport),
546+
SharedMDs(SharedMDs), IsPerformingImport(IsPerformingImport),
553547
Mapper(ValueMap, RF_ReuseAndMutateDistinctMDs | RF_IgnoreMissingLocals,
554548
&TypeMap, &GValMaterializer),
555549
IndirectSymbolMCID(Mapper.registerAlternateMappingContext(
@@ -567,13 +561,6 @@ class IRLinker {
567561
};
568562
}
569563

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-
577564
/// The LLVM SymbolTable class autorenames globals that conflict in the symbol
578565
/// table. This is good for all clients except for us. Go through the trouble
579566
/// to force this back.
@@ -1618,26 +1605,14 @@ Error IRLinker::run() {
16181605

16191606
DstM.setTargetTriple(SrcTriple.merge(DstTriple));
16201607

1621-
// Update the target triple's libcall information if it was changed.
1622-
Libcalls.updateLibcalls(Triple(DstM.getTargetTriple()));
1623-
16241608
// Loop over all of the linked values to compute type mappings.
16251609
computeTypeMapping();
16261610

1627-
bool AddsLibcalls = false;
16281611
std::reverse(Worklist.begin(), Worklist.end());
16291612
while (!Worklist.empty()) {
16301613
GlobalValue *GV = Worklist.back();
16311614
Worklist.pop_back();
16321615

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-
16411616
// Already mapped.
16421617
if (ValueMap.find(GV) != ValueMap.end() ||
16431618
IndirectSymbolValueMap.find(GV) != IndirectSymbolValueMap.end())
@@ -1700,13 +1675,6 @@ Error IRLinker::run() {
17001675
}
17011676
}
17021677

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-
17101678
// Merge the module flags into the DstM module.
17111679
return linkModuleFlagsMetadata();
17121680
}
@@ -1789,22 +1757,6 @@ bool IRMover::IdentifiedStructTypeSet::hasType(StructType *Ty) {
17891757
return I == NonOpaqueStructTypes.end() ? false : *I == Ty;
17901758
}
17911759

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-
18081760
IRMover::IRMover(Module &M) : Composite(M) {
18091761
TypeFinder StructTypes;
18101762
StructTypes.run(M, /* OnlyNamed */ false);
@@ -1820,25 +1772,14 @@ IRMover::IRMover(Module &M) : Composite(M) {
18201772
for (const auto *MD : StructTypes.getVisitedMetadata()) {
18211773
SharedMDs[MD].reset(const_cast<MDNode *>(MD));
18221774
}
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);
18341775
}
18351776

18361777
Error IRMover::move(std::unique_ptr<Module> Src,
18371778
ArrayRef<GlobalValue *> ValuesToLink,
18381779
LazyCallback AddLazyFor, bool IsPerformingImport) {
18391780
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);
18421783
Error E = TheIRLinker.run();
18431784
Composite.dropTriviallyDeadConstantArrays();
18441785
return E;

llvm/test/Linker/Inputs/strlen.ll

Lines changed: 0 additions & 21 deletions
This file was deleted.

llvm/test/Linker/libcalls.ll

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)