joaoleal / CppADCodeGen

Source Code Generation for Automatic Differentiation using Operator Overloading
Other
162 stars 36 forks source link

Add support for LLVM 10 #60

Closed acxz closed 3 years ago

acxz commented 3 years ago

Resolves #59

joaoleal commented 3 years ago

Hello,

There are some additional changes still needed for clang 10.0 support. We need to replace the following in llvm_base_model_library_processor_impl.hpp:

        CompilerInvocation::setLangDefaults(*invocation->getLangOpts(), InputKind::C,
                                            llvm::Triple(invocation->TargetOpts->Triple),
                                            invocation->getPreprocessorOpts(),
                                            LangStandard::lang_unspecified);

with:

        CompilerInvocation::setLangDefaults(*invocation->getLangOpts(),
#if LLVM_VERSION_MAJOR >= 10
                                            InputKind(clang::Language::C),
#else
                                            InputKind::C,
#endif
                                            llvm::Triple(invocation->TargetOpts->Triple),
                                            invocation->getPreprocessorOpts(),
                                            LangStandard::lang_unspecified);

The following line needs to be added to llvm10_0.hpp:

#include  <clang/Basic/Builtins.h>

There is still another issue that I have not been able to solve. I have some local changes which allow me to compile but I still don't know what are the differences with your PR. I'm having issues during the linking step:

[100%] Linking CXX executable llvm_link_clang /usr/bin/ld: /usr/lib/llvm-10/lib/libclangCodeGen.a(BackendUtil.cpp.o): na função "(anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete >)": (.text._ZN12_GLOBAL__N_118EmitAssemblyHelper30EmitAssemblyWithNewPassManagerEN5clang13BackendActionESt10unique_ptrIN4llvm17raw_pwrite_streamESt14default_deleteIS5_EE+0x1f15): referência não definida para "getPollyPluginInfo()" collect2: error: ld returned 1 exit status make[3]: [test/cppad/cg/model/llvm/CMakeFiles/llvm_link_clang.dir/build.make:108: test/cppad/cg/model/llvm/llvm_link_clang] Error 1 make[2]: [CMakeFiles/Makefile2:3814: test/cppad/cg/model/llvm/CMakeFiles/llvm_link_clang.dir/all] Error 2 make[1]: [CMakeFiles/Makefile2:3821: test/cppad/cg/model/llvm/CMakeFiles/llvm_link_clang.dir/rule] Error 2 make: [Makefile:1475: llvm_link_clang] Error 2

joaoleal commented 3 years ago

Another change is required. Replace in llvm_base_model_library_processor_impl.hpp:

ArrayRef<const char*> args {"-Wall", "-x", "c", "string-input"}; // -Wall or -v flag is required to avoid an error inside createInvocationFromCommandLine()

with:

std::vector<const char*> args {"-Wall", "-x", "c", "string-input"}; // -Wall or -v flag is required to avoid an error inside createInvocationFromCommandLine()

Also, I think llvm-10 needs to compile with C++14. There this is still the issue with the linking. Similar problem here and here.

acxz commented 3 years ago

Ah yeah I was able to figure out the InputKind issue, but yes still getting linking issues. I can go ahead and close this PR and let you take it up. Don't think I have knowledge the completely implement this.

joaoleal commented 3 years ago

I was able to get it to link and run successfully. I'm attaching a patch with my changes if you would like to implement it in this PR: llvm-10.zip

acxz commented 3 years ago

Sweet! Yeah I can put your patch on top of this PR. I'll give it a go later today.

acxz commented 3 years ago

@joaoleal sorry for taking some time, a couple busy days.

I had to convert your patch to a patch I could use with the git apply command (apparently idea patches dont work off the bat).