Skip to content

Commit

Permalink
Use references now that it is natural to do so.
Browse files Browse the repository at this point in the history
The linker never takes ownership of a module or changes which module it
is refering to, making it natural to use references.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254449 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
espindola committed Dec 1, 2015
1 parent b0b27c5 commit 76c60c3
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 107 deletions.
14 changes: 7 additions & 7 deletions include/llvm/Linker/Linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ class Linker {
InternalizeLinkedSymbols = (1 << 2)
};

Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
Linker(Module *M);
Linker(Module &M, DiagnosticHandlerFunction DiagnosticHandler);
Linker(Module &M);

Module *getModule() const { return Composite; }
Module &getModule() const { return Composite; }

/// \brief Link \p Src into the composite. The source is destroyed.
/// Passing OverrideSymbols as true will have symbols from Src
Expand All @@ -80,19 +80,19 @@ class Linker {
/// is passed. If a \p FuncToImport is provided, only that single
/// function is imported from the source module.
/// Returns true on error.
bool linkInModule(Module *Src, unsigned Flags = Flags::None,
bool linkInModule(Module &Src, unsigned Flags = Flags::None,
const FunctionInfoIndex *Index = nullptr,
Function *FuncToImport = nullptr);

static bool LinkModules(Module *Dest, Module *Src,
static bool linkModules(Module &Dest, Module &Src,
DiagnosticHandlerFunction DiagnosticHandler,
unsigned Flags = Flags::None);

static bool LinkModules(Module *Dest, Module *Src,
static bool linkModules(Module &Dest, Module &Src,
unsigned Flags = Flags::None);

private:
Module *Composite;
Module &Composite;

IdentifiedStructTypeSet IdentifiedStructTypes;

Expand Down
8 changes: 4 additions & 4 deletions lib/LTO/LTOCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ const char* LTOCodeGenerator::getVersionString() {
LTOCodeGenerator::LTOCodeGenerator()
: Context(getGlobalContext()),
MergedModule(new Module("ld-temp.o", Context)),
IRLinker(new Linker(MergedModule.get())) {
IRLinker(new Linker(*MergedModule)) {
initializeLTOPasses();
}

LTOCodeGenerator::LTOCodeGenerator(std::unique_ptr<LLVMContext> Context)
: OwnedContext(std::move(Context)), Context(*OwnedContext),
MergedModule(new Module("ld-temp.o", *OwnedContext)),
IRLinker(new Linker(MergedModule.get())) {
IRLinker(new Linker(*MergedModule)) {
initializeLTOPasses();
}

Expand Down Expand Up @@ -114,7 +114,7 @@ bool LTOCodeGenerator::addModule(LTOModule *Mod) {
assert(&Mod->getModule().getContext() == &Context &&
"Expected module in same context");

bool ret = IRLinker->linkInModule(&Mod->getModule());
bool ret = IRLinker->linkInModule(Mod->getModule());

const std::vector<const char *> &undefs = Mod->getAsmUndefinedRefs();
for (int i = 0, e = undefs.size(); i != e; ++i)
Expand All @@ -130,7 +130,7 @@ void LTOCodeGenerator::setModule(std::unique_ptr<LTOModule> Mod) {
AsmUndefinedRefs.clear();

MergedModule = Mod->takeModule();
IRLinker = make_unique<Linker>(MergedModule.get());
IRLinker = make_unique<Linker>(*MergedModule);

const std::vector<const char*> &Undefs = Mod->getAsmUndefinedRefs();
for (int I = 0, E = Undefs.size(); I != E; ++I)
Expand Down
Loading

0 comments on commit 76c60c3

Please sign in to comment.