Skip to content

Commit

Permalink
port to clang-6 (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfoco authored and vgvassilev committed Nov 17, 2019
1 parent 620cd19 commit 8834289
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 30 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
cmake_minimum_required(VERSION 3.4.3)
find_package(Subversion)

find_package(LLVM 5.0 REQUIRED CONFIG PATHS ${CLAD_PATH_TO_LLVM_BUILD} NO_DEFAULT_PATH)
find_package(LLVM 6.0 REQUIRED CONFIG PATHS ${CLAD_PATH_TO_LLVM_BUILD} NO_DEFAULT_PATH)

# We cannot use find_package(Clang) or include(ClangConfig) because we require
# a specific version (currently 5.0) and ClangConfig.cmake tries to do
# a specific version (currently 6.0) and ClangConfig.cmake tries to do
# find_package(LLVM REQUIRED CONFIG...) which in certain cases resolves to the
# wrong LLVM version.
# FIXME: That may be a bug in ClangConfig.cmake.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Note: Clad provides custom derivatives for some mathematical functions from `<cm
Note: *the concept of custom_derivatives will be reviewed soon, we intend to provide a different interface and avoid function name-based specifications and by-name lookups*.
## How to install
At the moment, only LLVM/Clang 5.0.x is supported.
At the moment, only LLVM/Clang 6.0.x is supported.
## How Clad works
Clad is a plugin for the Clang compiler. It relies on the Clang to build the AST ([Clang AST](https://clang.llvm.org/docs/IntroductionToTheClangAST.html)) of user's source code. Then, [CladPlugin](https://github.com/vgvassilev/clad/blob/a264195f00792feeebe63ac7a8ab815c02d20eee/tools/ClangPlugin.h#L48), implemented as `clang::ASTConsumer` analyzes the AST to find differentiation requests for clad and process those requests by building Clang AST for derivative functions. The whole clad's operation sequence is the following:
Expand All @@ -140,11 +140,11 @@ Clad is a plugin for the Clang compiler. It relies on the Clang to build the AST
* Finally, derivative's AST is [passed](https://github.com/vgvassilev/clad/blob/a264195f00792feeebe63ac7a8ab815c02d20eee/tools/ClangPlugin.cpp#L145) for further processing by Clang compiler (LLVM IR generation, optimizations, machine code generation, etc.).
### Building from source (example was tested on Ubuntu 18.04 LTS, tests are disabled)
```
sudo apt install clang-5.0 llvm-5.0 clang-5.0-dev llvm-5.0-dev libllvm5.0 llvm-5.0-runtime
sudo apt install clang-6.0 llvm-6.0 clang-6.0-dev llvm-6.0-dev libllvm6.0 llvm-6.0-runtime
sudo -H pip install lit
git clone https://github.com/vgvassilev/clad.git clad
mkdir build_dir inst; cd build_dir
cmake ../clad -DLLVM_DIR=/usr/lib/llvm-5.0/lib/cmake/llvm/ -DCMAKE_INSTALL_PREFIX=../inst
cmake ../clad -DLLVM_DIR=/usr/lib/llvm-6.0/lib/cmake/llvm/ -DCMAKE_INSTALL_PREFIX=../inst
make && make install
```
### Building from source LLVM, Clang and clad (development environment)
Expand Down
11 changes: 5 additions & 6 deletions cmake-variants.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
}
},
"clangVersion": {
"default": "clang5",
"default": "clang6",
"choices": {
"clang6": {
"short": "Clang 5.0",
"long": "Use Clang 5.0",
"short": "Clang 6.0",
"long": "Use Clang 6.0",
"settings": {
"CMAKE_C_COMPILER": "/usr/bin/clang-5.0",
"CMAKE_CXX_COMPILER": "/usr/bin/clang++-5.0",
"LLVM_DIR": "/usr/lib/llvm-5.0/lib/cmake/llvm/"
"CMAKE_CXX_COMPILER": "/usr/bin/clang++-6.0",
"LLVM_DIR": "/usr/lib/llvm-6.0/lib/cmake/llvm/"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ described first.

External Dependencies
---------------------
* clang-5.0
* clang-6.0

Forward Mode & Reverse Mode
---------------------------
Expand Down
6 changes: 2 additions & 4 deletions include/clad/Differentiator/DerivativeBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,8 @@ namespace clad {
template <typename Range>
clang::CompoundStmt* MakeCompoundStmt(const Range & Stmts) {
auto Stmts_ref = llvm::makeArrayRef(Stmts.data(), Stmts.size());
return new (m_Context) clang::CompoundStmt(m_Context,
Stmts_ref,
noLoc,
noLoc);
return clang::CompoundStmt::Create(m_Context, Stmts_ref,
noLoc, noLoc);
}

/// Get the latest block of code (i.e. place for statements output).
Expand Down
16 changes: 7 additions & 9 deletions lib/Differentiator/DerivativeBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ namespace clad {
// From Sema::ActOnStartNamespaceDef:
if (II) {
LookupResult R(m_Sema, II, noLoc, Sema::LookupOrdinaryName,
Sema::ForRedeclaration);
Sema::ForVisibleRedeclaration);
m_Sema.LookupQualifiedName(R, m_Sema.CurContext->getRedeclContext());
NamedDecl* FoundDecl =
R.isSingleResult() ? R.getRepresentativeDecl() : nullptr;
Expand Down Expand Up @@ -620,10 +620,8 @@ namespace clad {

auto StmtsRef = llvm::makeArrayRef(CompStmtSave.data(),
CompStmtSave.size());
CompoundStmt* CS = new (m_Context) clang::CompoundStmt(m_Context,
StmtsRef,
noLoc,
noLoc);
CompoundStmt* CS = clang::CompoundStmt::Create(m_Context, StmtsRef,
noLoc, noLoc);
hessianFD->setBody(CS);
endScope(); // Function body scope
m_Sema.PopFunctionScopeInfo();
Expand Down Expand Up @@ -863,7 +861,7 @@ namespace clad {
return Result;
DeclarationName CladName = &m_Context.Idents.get("clad");
LookupResult CladR(m_Sema, CladName, noLoc, Sema::LookupNamespaceName,
Sema::ForRedeclaration);
Sema::ForVisibleRedeclaration);
m_Sema.LookupQualifiedName(CladR, m_Context.getTranslationUnitDecl());
assert(!CladR.empty() && "cannot find clad namespace");
Result = cast<NamespaceDecl>(CladR.getFoundDecl());
Expand All @@ -879,7 +877,7 @@ namespace clad {
CSS.Extend(m_Context, CladNS, noLoc, noLoc);
DeclarationName TapeName = &m_Context.Idents.get("tape");
LookupResult TapeR(m_Sema, TapeName, noLoc, Sema::LookupUsingDeclName,
Sema::ForRedeclaration);
Sema::ForVisibleRedeclaration);
m_Sema.LookupQualifiedName(TapeR, CladNS, CSS);
assert(!TapeR.empty() && isa<TemplateDecl>(TapeR.getFoundDecl()) &&
"cannot find clad::tape");
Expand Down Expand Up @@ -1120,7 +1118,7 @@ namespace clad {
Intro.Range.setEnd(E->getLocEnd());
AttributeFactory AttrFactory;
DeclSpec DS(AttrFactory);
Declarator D(DS, Declarator::LambdaExprContext);
Declarator D(DS, DeclaratorContext::LambdaExprContext);
S.PushLambdaScope();
V.beginScope(Scope::BlockScope | Scope::FnScope | Scope::DeclScope);
S.ActOnStartOfLambdaDefinition(Intro, D, V.getCurrentScope());
Expand Down Expand Up @@ -1393,7 +1391,7 @@ namespace clad {
// Find the builtin derivatives namespace
DeclarationName Name = &C.Idents.get("custom_derivatives");
LookupResult R(S, Name, SourceLocation(), Sema::LookupNamespaceName,
Sema::ForRedeclaration);
Sema::ForVisibleRedeclaration);
S.LookupQualifiedName(R, C.getTranslationUnitDecl(),
/*allowBuiltinCreation*/ false);
assert(!R.empty() && "Cannot find builtin derivatives!");
Expand Down
5 changes: 3 additions & 2 deletions lib/Differentiator/StmtClone.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
//--------------------------------------------------------------------*- C++ -*-
// clad - the C++ Clang-based Automatic Differentiator
// author: Vassil Vassilev <vvasilev-at-cern.ch>
Expand Down Expand Up @@ -279,8 +280,8 @@ Stmt* StmtClone::VisitCompoundStmt(CompoundStmt *Node) {

llvm::ArrayRef<Stmt*> stmtsRef = llvm::makeArrayRef(clonedBody.data(),
clonedBody.size());
return new (Ctx) CompoundStmt(Ctx, stmtsRef, Node->getLBracLoc(),
Node->getLBracLoc());
return CompoundStmt::Create(Ctx, stmtsRef, Node->getLBracLoc(),
Node->getLBracLoc());
}

VarDecl* StmtClone::CloneDeclOrNull(VarDecl* Node) {
Expand Down
4 changes: 2 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if(CLAD_BUILT_STANDALONE)
# cmake will fall back to LLVM-config (asking llvm-config --obj-root) and this
# will return a build folder. This information will force lit to look for
# utils such as FileCheck in /usr/local/... instead of the true location in
# /usr/lib/llvm-5.0/
# /usr/lib/llvm-6.0/
set(LLVM_BINARY_DIR ${LLVM_INSTALL_PREFIX})
set(LLVM_TOOLS_DIR ${LLVM_INSTALL_PREFIX})
set(LLVM_LIBS_DIR ${LLVM_INSTALL_PREFIX}/lib/)
Expand Down Expand Up @@ -54,7 +54,7 @@ if(NOT LLVM_MAIN_SRC_DIR)
endif()
add_lit_testsuite(check-clad "Running the Clad regression tests"
${CMAKE_CURRENT_BINARY_DIR}
#LIT ${LIT_COMMAND}
LIT ${LIT_COMMAND}
PARAMS ${CLAD_TEST_PARAMS}
DEPENDS ${CLAD_TEST_DEPS}
ARGS ${CLAD_TEST_EXTRA_ARGS} --verbose --succinct
Expand Down
2 changes: 1 addition & 1 deletion tools/ClangPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace clad {
DeclarationName Name = &C.Idents.get("clad");
Sema &SemaR = m_CI.getSema();
LookupResult R(SemaR, Name, SourceLocation(), Sema::LookupNamespaceName,
Sema::ForRedeclaration);
Sema::ForVisibleRedeclaration);
SemaR.LookupQualifiedName(R, C.getTranslationUnitDecl(),
/*allowBuiltinCreation*/ false);
m_HasRuntime = !R.empty();
Expand Down

0 comments on commit 8834289

Please sign in to comment.