Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

Commit

Permalink
Remove debugging stuff from build_llvm_ir
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Mar 6, 2017
1 parent cd25082 commit be68c96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ experimental_tools: make_builddir \
$(BUILDDIR)/loop_info: $(SRC_LLVM_DIR)/experimental/loop_info.cpp
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $^ $(LLVM_LDFLAGS) -o $@

# build_llvm_ir needs -rdynamic so that it can dlsym symbols from its own
# binary in the JIT.
$(BUILDDIR)/build_llvm_ir: $(SRC_LLVM_DIR)/experimental/build_llvm_ir.cpp
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $^ -rdynamic $(LLVM_LDFLAGS) -o $@

Expand Down
23 changes: 5 additions & 18 deletions src_llvm/experimental/build_llvm_ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ class SimpleOrcJIT {
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
CompileLayer(ObjectLayer, orc::SimpleCompiler(*TM)) {
std::string s;
bool b = llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &s);
errs() << "$$ LoadLibraryPermanently returned " << b
<< "; error string=" << s << "\n";
if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &s)) {
errs() << "ERROR: LoadLibraryPermanently returned false"
<< "; error string=" << s << "\n";
}
}

TargetMachine &getTargetMachine() { return *TM; }
Expand All @@ -57,15 +58,11 @@ class SimpleOrcJIT {
// JIT.
auto Resolver = orc::createLambdaResolver(
[&](const std::string &Name) {
errs() << "$$ resolving " << Name << "\n";
if (auto Sym = findMangledSymbol(Name))
return Sym;
return JITSymbol(nullptr);
},
[](const std::string &S) {
errs() << "$$ external resolving " << S << "\n";
return nullptr;
});
[](const std::string &S) { return nullptr; });
auto H = CompileLayer.addModuleSet(singletonSet(std::move(M)),
make_unique<SectionMemoryManager>(),
std::move(Resolver));
Expand All @@ -82,7 +79,6 @@ class SimpleOrcJIT {
}

JITSymbol findSymbol(const std::string Name) {
errs() << "$$ findSymbol: " << Name << "\n";
return findMangledSymbol(mangle(Name));
}

Expand All @@ -96,7 +92,6 @@ class SimpleOrcJIT {
}

JITSymbol findMangledSymbol(const std::string &Name) {
errs() << "$$ findMangledSymbol: " << Name << "\n";
const bool ExportedSymbolsOnly = true;

// Search modules in reverse order: from last added to first added.
Expand All @@ -107,7 +102,6 @@ class SimpleOrcJIT {
return Sym;

// If we can't find the symbol in the JIT, try looking in the host process.
errs() << "$$ finding " << Name << " in host process\n";
if (auto SymAddr = RTDyldMemoryManager::getSymbolAddressInProcess(Name))
return JITSymbol(SymAddr, JITSymbolFlags::Exported);

Expand Down Expand Up @@ -168,7 +162,6 @@ int main(int argc, char **argv) {
LLVMContext Context;
std::unique_ptr<Module> Mod = make_unique<Module>("my module", Context);

printd(101.24);
std::string funcname = "foo";

FunctionType *FT =
Expand All @@ -185,12 +178,6 @@ int main(int argc, char **argv) {

SimpleOrcJIT JIT;
Mod->setDataLayout(JIT.getTargetMachine().createDataLayout());
void* s = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("printd");
if (s != nullptr) {
errs() << "$$ " << s << "\n";
} else {
errs() << "$$ SearchForAddressOfSymbol unable to find printd\n";
}

PassManagerBuilder Builder;
Builder.OptLevel = 3;
Expand Down

0 comments on commit be68c96

Please sign in to comment.