66mlir::LogicalResult
linkFiles(std::vector<std::string> Files,
67 LLVMContext &Context, Linker &L,
unsigned Flags,
68 bool DisableDITypeMap,
bool NoVerify,
69 bool Internalize,
bool Verbose) {
71 unsigned ApplicableFlags = Flags & Linker::Flags::OverrideFromSrc;
73 bool InternalizeLinkedSymbols =
false;
74 for (
const auto &File : Files) {
75 std::unique_ptr<MemoryBuffer> Buffer = MemoryBuffer::getMemBufferCopy(File);
77 std::unique_ptr<Module> maybeModule =
78 loadFile(std::move(Buffer), Context, Verbose);
80 WithColor::error() <<
" loading file '" << File <<
"'\n";
81 return mlir::failure();
87 if (DisableDITypeMap && !NoVerify && verifyModule(*maybeModule, &errs())) {
88 WithColor::error() <<
"input module is broken!\n";
89 return mlir::failure();
93 errs() <<
"Linking in '" << File <<
"'\n";
96 if (InternalizeLinkedSymbols)
98 std::move(maybeModule), ApplicableFlags,
99 [](Module &M,
const StringSet<> &GVS) {
100 internalizeModule(M, [&GVS](
const GlobalValue &GV) {
101 return !GV.hasName() || (GVS.count(GV.getName()) == 0);
105 Err = L.linkInModule(std::move(maybeModule), ApplicableFlags);
108 errs() <<
"couldn't link.\n";
109 return mlir::failure();
113 InternalizeLinkedSymbols = Internalize;
116 ApplicableFlags = Flags;
119 return mlir::success();
124 std::vector<std::string> Files,
bool DisableDITypeMap,
125 bool NoVerify,
bool Internalize,
bool OnlyNeeded,
126 bool PreserveAssemblyUseListOrder,
bool Verbose) {
129 if (!DisableDITypeMap)
130 Context.enableDebugTypeODRUniquing();
132 auto Composite = std::make_unique<Module>(
"aie-llvm-link", Context);
133 Linker L(*Composite);
135 unsigned Flags = Linker::Flags::None;
137 Flags |= Linker::Flags::LinkOnlyNeeded;
140 if (failed(
linkFiles(Files, Context, L, Flags, DisableDITypeMap, NoVerify,
141 Internalize, Verbose)))
142 return mlir::failure();
144 Composite->print(output,
nullptr, PreserveAssemblyUseListOrder);
145 return mlir::success();
mlir::LogicalResult linkFiles(std::vector< std::string > Files, LLVMContext &Context, Linker &L, unsigned Flags, bool DisableDITypeMap, bool NoVerify, bool Internalize, bool Verbose)
mlir::LogicalResult AIELLVMLink(llvm::raw_ostream &output, std::vector< std::string > Files, bool DisableDITypeMap=false, bool NoVerify=false, bool Internalize=false, bool OnlyNeeded=false, bool PreserveAssemblyUseListOrder=false, bool Verbose=false)