Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/llvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on: [push]

jobs:
build_llvm:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macOS-latest
steps:
- name: Setup Windows
if: startsWith(matrix.os, 'windows')
uses: tstellar/actions/setup-windows@master
with:
arch: amd64
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Install Ninja
uses: tstellar/actions/install-ninja@master
with:
os: ${{ runner.os }}
- name: Test LLVM / dynamic
if: startsWith(matrix.os, 'windows') == false
uses: tstellar/actions/build-test-llvm-project@master
with:
cmake_args: -G Ninja -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_args }} -DLLVM_ENABLE_PROJECTS='polly;clang' -DPOLLY_ENABLE_GPGPU_CODEGEN=OFF -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_POLLY_LINK_INTO_TOOLS=OFF -DLLVM_BUILD_EXAMPLES=ON
os: ${{ runner.os }}
- name: Test LLVM / static
uses: tstellar/actions/build-test-llvm-project@master
with:
cmake_args: -G Ninja -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_args }} -DLLVM_ENABLE_PROJECTS='polly;clang' -DPOLLY_ENABLE_GPGPU_CODEGEN=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_POLLY_LINK_INTO_TOOLS=ON -DLLVM_BUILD_EXAMPLES=ON
os: ${{ runner.os }}
36 changes: 22 additions & 14 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -847,32 +847,40 @@ macro(add_llvm_executable name)
llvm_codesign(${name} ENTITLEMENTS ${ARG_ENTITLEMENTS} BUNDLE_PATH ${ARG_BUNDLE_PATH})
endmacro(add_llvm_executable name)

# add_llvm_pass_plugin(name)
# add_llvm_pass_plugin(name [NO_MODULE] ...)
# Add ${name} as an llvm plugin.
# If option LLVM_${name_upper}_LINK_INTO_TOOLS is set to ON, the plugin is registered statically.
# Otherwise a pluggable shared library is registered.
#
# If NO_MODULE is specified, when option LLVM_${name_upper}_LINK_INTO_TOOLS is set to OFF,
# only an object library is built, and no module is built. This is specific to the Polly use case.
function(add_llvm_pass_plugin name)
cmake_parse_arguments(ARG
"NO_MODULE" "" ""
${ARGN})

string(TOUPPER ${name} name_upper)

option(LLVM_${name_upper}_LINK_INTO_TOOLS "Statically link ${name} into tools (if available)" OFF)

# process_llvm_pass_plugins takes care of the actual linking, just create an
# object library as of now
add_llvm_library(${name} OBJECT ${ARGN})

if(LLVM_${name_upper}_LINK_INTO_TOOLS)
target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS)
set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS)
if (TARGET intrinsics_gen)
add_dependencies(obj.${name} intrinsics_gen)
endif()
endif()

message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
if(LLVM_${name_upper}_LINK_INTO_TOOLS)
list(REMOVE_ITEM ARG_UNPARSED_ARGUMENTS BUILDTREE_ONLY)
# process_llvm_pass_plugins takes care of the actual linking, just create an
# object library as of now
add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
target_compile_definitions(${name} PRIVATE LLVM_${name_upper}_LINK_INTO_TOOLS)
set_property(TARGET ${name} APPEND PROPERTY COMPILE_DEFINITIONS LLVM_LINK_INTO_TOOLS)
if (TARGET intrinsics_gen)
add_dependencies(obj.${name} intrinsics_gen)
endif()
message(STATUS "Registering ${name} as a pass plugin (static build: ${LLVM_${name_upper}_LINK_INTO_TOOLS})")
set_property(GLOBAL APPEND PROPERTY LLVM_COMPILE_EXTENSIONS ${name})
elseif(NOT ARG_NO_MODULE)
add_llvm_library(${name} MODULE ${ARG_UNPARSED_ARGUMENTS})
else()
add_llvm_library(${name} OBJECT ${ARG_UNPARSED_ARGUMENTS})
endif()

endfunction(add_llvm_pass_plugin)

# Generate X Macro file for extension handling. It provides a
Expand Down
30 changes: 10 additions & 20 deletions llvm/examples/Bye/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
add_llvm_pass_plugin(Bye
Bye.cpp
DEPENDS
intrinsics_gen
BUILDTREE_ONLY
)

if (LLVM_LINK_LLVM_DYLIB)
target_link_libraries(Bye PUBLIC LLVM)
else()
target_link_libraries(Bye
PUBLIC
LLVMSupport
LLVMCore
LLVMipo
LLVMPasses
)
if(LLVM_BYE_LINK_INTO_TOOLS)
message(WARNING "Setting LLVM_BYE_LINK_INTO_TOOLS=ON only makes sense for testing purpose")
endif()

if( LLVM_BUILD_EXAMPLES )
install(TARGETS ${name} RUNTIME DESTINATION examples)
endif()
add_llvm_pass_plugin(Bye
Bye.cpp
DEPENDS
intrinsics_gen
BUILDTREE_ONLY
)

install(TARGETS ${name} RUNTIME DESTINATION examples)
set_target_properties(${name} PROPERTIES FOLDER "Examples")
4 changes: 4 additions & 0 deletions llvm/include/llvm/Support/DynamicLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ namespace sys {
/// Add searchable symbol/value pair.
static void AddSymbol(StringRef symbolName, void *symbolValue);

/// Ensure the underlying library registry is properly constructed.
/// This is only useful to force ManagedStatic registration ordering.
static void ensureConstructed();

class HandleSet;
};

Expand Down
5 changes: 5 additions & 0 deletions llvm/lib/Support/DynamicLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ void DynamicLibrary::AddSymbol(StringRef SymbolName, void *SymbolValue) {
(*ExplicitSymbols)[SymbolName] = SymbolValue;
}

void DynamicLibrary::ensureConstructed() {
(void)*OpenedHandles;
}


DynamicLibrary DynamicLibrary::getPermanentLibrary(const char *FileName,
std::string *Err) {
// Force OpenedHandles to be added into the ManagedStatic list before any
Expand Down
9 changes: 9 additions & 0 deletions llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
#include "llvm/Transforms/IPO.h"
Expand Down Expand Up @@ -194,12 +195,20 @@ static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
/// Since GlobalExtensions is a managed static, calling 'empty()' will trigger
/// the construction of the object.
static bool GlobalExtensionsNotEmpty() {
// Dynamic library static registry **must** be initialized before global
// extension registry, because global extension may reference functions from
// dynamically opened libraries. Failing to ensure that order (randomly)
// triggers a segfault upon destruction, if the dynamically loaded library is
// closed before the global extensions are destroyed.
sys::DynamicLibrary::ensureConstructed();
return GlobalExtensions.isConstructed() && !GlobalExtensions->empty();
}

void PassManagerBuilder::addGlobalExtension(
PassManagerBuilder::ExtensionPointTy Ty,
PassManagerBuilder::ExtensionFn Fn) {
// See comment in GlobalExtensionsNotEmpty
sys::DynamicLibrary::ensureConstructed();
GlobalExtensions->push_back(std::make_pair(Ty, std::move(Fn)));
}

Expand Down
5 changes: 1 addition & 4 deletions llvm/test/Feature/load_extension.ll
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
; This is currently failing on multiple platforms. Disable while investigation occurs.
; XFAIL: *

; RUN: opt %s %loadbye -goodbye -wave-goodbye -disable-output 2>&1 | FileCheck %s
; REQUIRES: plugins, examples
; REQUIRES: plugins
; CHECK: Bye

@junk = global i32 0
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ def get_asan_rtlib():
if config.build_examples:
config.available_features.add('examples')

if config.linked_bye_extension and config.build_examples:
if config.linked_bye_extension:
config.substitutions.append(('%llvmcheckext', 'CHECK-EXT'))
config.substitutions.append(('%loadbye', ''))
else:
config.substitutions.append(('%llvmcheckext', 'CHECK-NOEXT'))
config.substitutions.append(('%loadbye',
'-load={}/libBye{}'.format(config.llvm_shlib_dir,
'-load={}/Bye{}'.format(config.llvm_shlib_dir,
config.llvm_shlib_ext)))

# Static libraries are not built if BUILD_SHARED_LIBS is ON.
Expand Down
1 change: 1 addition & 0 deletions polly/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ endif ()
# Use an object-library to add the same files to multiple libs without requiring
# the sources them to be recompiled for each of them.
add_llvm_pass_plugin(Polly
NO_MODULE
Analysis/DependenceInfo.cpp
Analysis/PolyhedralInfo.cpp
Analysis/ScopDetection.cpp
Expand Down