[PATCH] Add the option to build/test compiler-rt as a standalone project with just-built Clang.

Alexey Samsonov samsonov at google.com
Mon Feb 24 05:50:39 PST 2014


Hi brad.king, chapuni,

This change allows to build compiler-rt libraries and run compiler-rt
testsuite with just-built Clang (in the same way as it's done with Makefile build).

http://llvm-reviews.chandlerc.com/D2868

Files:
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGExprAgg.cpp
  lib/CodeGen/CGCleanup.cpp
  runtime/CMakeLists.txt

Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -28,6 +28,7 @@
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/MDBuilder.h"
 #include "llvm/Support/ConvertUTF.h"
+#include "llvm/Support/Debug.h"
 
 using namespace clang;
 using namespace CodeGen;
@@ -3052,6 +3053,7 @@
   AggValueSlot Slot = CreateAggTemp(E->getType(), "temp.lvalue");
   Slot.setExternallyDestructed();
   EmitAggExpr(E->getSubExpr(), Slot);
+  // llvm::dbgs() << "Binding Temporary to LValue!\n";
   EmitCXXTemporary(E->getTemporary(), E->getType(), Slot.getAddr());
   return MakeAddrLValue(Slot.getAddr(), E->getType());
 }
Index: lib/CodeGen/CGExprAgg.cpp
===================================================================
--- lib/CodeGen/CGExprAgg.cpp
+++ lib/CodeGen/CGExprAgg.cpp
@@ -22,6 +22,7 @@
 #include "llvm/IR/Function.h"
 #include "llvm/IR/GlobalVariable.h"
 #include "llvm/IR/Intrinsics.h"
+#include "llvm/Support/Debug.h"
 using namespace clang;
 using namespace CodeGen;
 
@@ -954,8 +955,10 @@
   Visit(E->getSubExpr());
 
   // Push that destructor we promised.
-  if (!wasExternallyDestructed)
+  if (!wasExternallyDestructed) {
+    //llvm::dbgs() << "VisitCXXBindTemporaryExpr!\n";
     CGF.EmitCXXTemporary(E->getTemporary(), E->getType(), Dest.getAddr());
+  }
 }
 
 void
Index: lib/CodeGen/CGCleanup.cpp
===================================================================
--- lib/CodeGen/CGCleanup.cpp
+++ lib/CodeGen/CGCleanup.cpp
@@ -19,6 +19,7 @@
 
 #include "CGCleanup.h"
 #include "CodeGenFunction.h"
+#include "llvm/Support/Debug.h"
 
 using namespace clang;
 using namespace CodeGen;
@@ -1141,6 +1142,7 @@
 void CodeGenFunction::EmitCXXTemporary(const CXXTemporary *Temporary,
                                        QualType TempType,
                                        llvm::Value *Ptr) {
+  // llvm::dbgs() << "-- Emitting CXX temporary! --\n";
   pushDestroy(NormalAndEHCleanup, Ptr, TempType, destroyCXXObject,
               /*useEHCleanup*/ true);
 }
Index: runtime/CMakeLists.txt
===================================================================
--- runtime/CMakeLists.txt
+++ runtime/CMakeLists.txt
@@ -1,12 +1,58 @@
 # TODO: Set the install directory.
 
+include(ExternalProject)
+
 set(known_subdirs
-  "compiler-rt"
   "libcxx"
   )
 
 foreach (dir ${known_subdirs})
   if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${dir}/CMakeLists.txt)
     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${dir})
   endif()
 endforeach()
+
+set(COMPILER_RT_SRC_ROOT ${LLVM_MAIN_SRC_DIR}/projects/compiler-rt)
+if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
+  # Add compiler-rt as an external project.
+  set(COMPILER_RT_PREFIX ${CMAKE_BINARY_DIR}/projects/compiler-rt)
+  
+  ExternalProject_Add(compiler-rt
+    PREFIX ${COMPILER_RT_PREFIX}
+    SOURCE_DIR ${COMPILER_RT_SRC_ROOT}
+    CMAKE_ARGS -DCMAKE_C_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+               -DCMAKE_CXX_COMPILER=${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++
+               -DCMAKE_BUILD_TYPE=Release
+               -DLLVM_CONFIG_PATH=${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-config
+               -DCOMPILER_RT_OUTPUT_DIR=${LLVM_LIBRARY_OUTPUT_INTDIR}/clang/${CLANG_VERSION}
+               -DCOMPILER_RT_INSTALL_PATH=lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}
+               -DCOMPILER_RT_INCLUDE_TESTS=${LLVM_INCLUDE_TESTS}
+               -DCOMPILER_RT_ENABLE_WERROR=${LLVM_ENABLE_WERROR}
+    INSTALL_COMMAND ""
+    )
+  # Due to a bug, DEPENDS in ExternalProject_Add doesn't work in some CMake versions.
+  add_dependencies(compiler-rt llvm-config clang clang++)
+
+  # Add a custom step to re-configure compiler-rt on each rebuild.
+  ExternalProject_Add_Step(compiler-rt force-reconfigure
+    DEPENDERS configure
+    ALWAYS 1
+    )
+
+  ExternalProject_Add_Step(compiler-rt clobber
+    COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
+    COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
+    COMMENT "Clobberring compier-rt build directory..."
+    DEPENDERS configure
+    DEPENDS ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang
+  )
+
+  ExternalProject_Get_Property(compiler-rt BINARY_DIR)
+  add_custom_target(check-compiler-rt
+          COMMAND ${CMAKE_BUILD_TOOL} check-all
+          DEPENDS compiler-rt
+          WORKING_DIRECTORY ${BINARY_DIR})
+  # Add binaries that compiler-rt tests depend on.
+  add_dependencies(check-compiler-rt FileCheck count
+                                     not llvm-nm llvm-symbolizer)
+endif()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2868.1.patch
Type: text/x-patch
Size: 4564 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140224/45a9d63d/attachment.bin>


More information about the cfe-commits mailing list