131 changes: 131 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml

trigger:
- master

jobs:
- job: build_ubuntu
displayName: Linux Build
timeoutInMinutes: 0

pool:
vmImage: 'ubuntu-16.04'

steps:
- script: |
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo apt-add-repository -s "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main"
sudo apt-get update
sudo apt-get -y install cmake ccache ninja-build clang-9 lld-9 libllvm-9-ocaml-dev libllvm9 llvm-9 llvm-9-dev llvm-9-tools llvm-9-runtime
displayName: Install clang-9 and other dependencies
- script: |
mkdir build
cd build
CC=clang-9 CXX=clang++-9 CXXFLAGS="-msse -msse2" cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX="" -DLLVM_CCACHE_DIR=$HOME/.ccache -DLLVM_CCACHE_BUILD=ON -DLLVM_ENABLE_CXX1Y=ON -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_RUNTIME=OFF -DLLVM_BUILD_TOOLS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_TOOLS=OFF -DLLVM_INCLUDE_UTILS=OFF -DWITH_POLLY=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON
displayName: Configure LLVM
- script: |
cd build
ninja
displayName: Build LLVM
- script: |
cd build
DESTDIR=./dest ninja install
cd dest
tar -czf llvmlibs-linux.tar.gz lib include bin
sha256sum ./llvmlibs-linux.tar.gz | awk '{ print $1}' >> llvmlibs-linux.tar.gz.sha256
displayName: Package LLVM Libraries
- task: GitHubRelease@0
inputs:
gitHubConnection: RPCS3-Token
repositoryName: RPCS3/llvm
action: edit # Options: create, edit, delete
target: '$(Build.SourceVersion)' # Required when action == Create || Action == Edit
tagSource: auto # Required when action == Create# Options: auto, manual
#tagPattern: # Optional
tag: 'continuous-linux-master' # Required when action == Edit || Action == Delete || TagSource == Manual
title: 'Linux build' # Optional
#releaseNotesSource: 'file' # Optional. Options: file, input
#releaseNotesFile: # Optional
#releaseNotes: # Optional
assets: 'build/dest/llvmlibs-linux*' # Optional
assetUploadMode: delete # Optional. Options: delete, replace
#isDraft: false # Optional
#isPreRelease: true # Optional
#addChangeLog: true # Optional
#compareWith: 'lastFullRelease' # Required when addChangeLog == True. Options: lastFullRelease, lastRelease, lastReleaseByTag
#releaseTag: # Required when compareWith == LastReleaseByTag

- job: build_win32
displayName: Win32 Build
timeoutInMinutes: 0

pool:
vmImage: 'windows-2019'

steps:
- script: |
mkdir llvm_build
cd llvm_build
cmake -G "Visual Studio 16 2019" .. -DLLVM_TARGETS_TO_BUILD="X86" -DLLVM_DEFAULT_TARGET_TRIPLE:STRING=x86_64-pc-windows-msvc -DLLVM_HOST_TRIPLE:STRING=x86_64-pc-windows-msvc -DCMAKE_BUILD_TYPE=Release -Thost=x64 -DLLVM_BUILD_RUNTIME=OFF -DLLVM_BUILD_TOOLS=OFF -DLLVM_INCLUDE_DOCS=OFF -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_INCLUDE_BENCHMARKS=OFF -DLLVM_INCLUDE_UTILS=OFF -DWITH_POLLY=ON -DCMAKE_SYSTEM_VERSION=6.1 -DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=10.0
displayName: Configure LLVM
- script: |
cd llvm_build
cmake --build . --config Release -- /maxcpucount
displayName: Build LLVM
- script: |
mkdir llvm_out
cd llvm_out
mkdir build
cd build
mkdir llvm
cd llvm
mkdir cmake
mkdir include
mkdir tools
xcopy "..\..\..\cmake" ".\cmake" /E
xcopy "..\..\..\include" ".\include" /E
cd ..\
mkdir llvm_build
cd llvm_build
mkdir Release
mkdir include
mkdir lib
cd lib
mkdir cmake
cd ..\
xcopy "..\..\..\llvm_build\Release" ".\Release" /E
xcopy "..\..\..\llvm_build\include" ".\include" /E
xcopy "..\..\..\llvm_build\lib\cmake" ".\lib\cmake" /E
cd ..\
7z a -t7z -m0=lzma2 -mx=9 -aoa -r "llvmlibs.7z" *
displayName: Package LLVM Libraries
- task: GitHubRelease@0
inputs:
gitHubConnection: RPCS3-Token
repositoryName: RPCS3/llvm
action: edit # Options: create, edit, delete
target: '$(Build.SourceVersion)' # Required when action == Create || Action == Edit
tagSource: auto # Required when action == Create# Options: auto, manual
#tagPattern: # Optional
tag: 'continuous-master' # Required when action == Edit || Action == Delete || TagSource == Manual
title: 'Windows build' # Optional
#releaseNotesSource: 'file' # Optional. Options: file, input
#releaseNotesFile: # Optional
#releaseNotes: # Optional
assets: 'llvm_out/build/llvmlibs.7z' # Optional
assetUploadMode: delete # Optional. Options: delete, replace
#isDraft: false # Optional
#isPreRelease: true # Optional
#addChangeLog: true # Optional
#compareWith: 'lastFullRelease' # Required when addChangeLog == True. Options: lastFullRelease, lastRelease, lastReleaseByTag
#releaseTag: # Required when compareWith == LastReleaseByTag
3 changes: 3 additions & 0 deletions include/llvm/ADT/DenseMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1219,13 +1219,16 @@ class DenseMapIterator : DebugEpochBase::HandleBase {
"comparing incomparable iterators!");
return Ptr == RHS.Ptr;
}
#if __cpp_impl_three_way_comparison >= 201711
#else
bool operator!=(const ConstIterator &RHS) const {
assert((!Ptr || isHandleInSync()) && "handle not in sync!");
assert((!RHS.Ptr || RHS.isHandleInSync()) && "handle not in sync!");
assert(getEpochAddress() == RHS.getEpochAddress() &&
"comparing incomparable iterators!");
return Ptr != RHS.Ptr;
}
#endif

inline DenseMapIterator& operator++() { // Preincrement
assert(isHandleInSync() && "invalid iterator access!");
Expand Down
165 changes: 1 addition & 164 deletions lib/ExecutionEngine/GDBRegistrationListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,16 @@
using namespace llvm;
using namespace llvm::object;

// This must be kept in sync with gdb/gdb/jit.h .
extern "C" {

typedef enum {
JIT_NOACTION = 0,
JIT_REGISTER_FN,
JIT_UNREGISTER_FN
} jit_actions_t;

struct jit_code_entry {
struct jit_code_entry *next_entry;
struct jit_code_entry *prev_entry;
const char *symfile_addr;
uint64_t symfile_size;
};

struct jit_descriptor {
uint32_t version;
// This should be jit_actions_t, but we want to be specific about the
// bit-width.
uint32_t action_flag;
struct jit_code_entry *relevant_entry;
struct jit_code_entry *first_entry;
};

// We put information about the JITed function in this global, which the
// debugger reads. Make sure to specify the version statically, because the
// debugger checks the version before we can set it during runtime.
struct jit_descriptor __jit_debug_descriptor = { 1, 0, nullptr, nullptr };

// Debuggers puts a breakpoint in this function.
LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code() {
// The noinline and the asm prevent calls to this function from being
// optimized out.
#if !defined(_MSC_VER)
asm volatile("":::"memory");
#endif
}

}

namespace {

struct RegisteredObjectInfo {
RegisteredObjectInfo() {}

RegisteredObjectInfo(std::size_t Size, jit_code_entry *Entry,
OwningBinary<ObjectFile> Obj)
: Size(Size), Entry(Entry), Obj(std::move(Obj)) {}

std::size_t Size;
jit_code_entry *Entry;
OwningBinary<ObjectFile> Obj;
};

// Buffer for an in-memory object file in executable memory
typedef llvm::DenseMap<JITEventListener::ObjectKey, RegisteredObjectInfo>
RegisteredObjectBufferMap;

/// Global access point for the JIT debugging interface designed for use with a
/// singleton toolbox. Handles thread-safe registration and deregistration of
/// object files that are in executable memory managed by the client of this
/// class.
class GDBJITRegistrationListener : public JITEventListener {
/// A map of in-memory object files that have been registered with the
/// JIT interface.
RegisteredObjectBufferMap ObjectBufferMap;

public:
/// Instantiates the JIT service.
GDBJITRegistrationListener() : ObjectBufferMap() {}
GDBJITRegistrationListener() {}

/// Unregisters each object that was previously registered and releases all
/// internal resources.
Expand All @@ -105,119 +44,17 @@ class GDBJITRegistrationListener : public JITEventListener {
/// frees associated resources.
/// Returns true if @p Object was found in ObjectBufferMap.
void notifyFreeingObject(ObjectKey K) override;

private:
/// Deregister the debug info for the given object file from the debugger
/// and delete any temporary copies. This private method does not remove
/// the function from Map so that it can be called while iterating over Map.
void deregisterObjectInternal(RegisteredObjectBufferMap::iterator I);
};

/// Lock used to serialize all jit registration events, since they
/// modify global variables.
ManagedStatic<sys::Mutex> JITDebugLock;

/// Do the registration.
void NotifyDebugger(jit_code_entry* JITCodeEntry) {
__jit_debug_descriptor.action_flag = JIT_REGISTER_FN;

// Insert this entry at the head of the list.
JITCodeEntry->prev_entry = nullptr;
jit_code_entry* NextEntry = __jit_debug_descriptor.first_entry;
JITCodeEntry->next_entry = NextEntry;
if (NextEntry) {
NextEntry->prev_entry = JITCodeEntry;
}
__jit_debug_descriptor.first_entry = JITCodeEntry;
__jit_debug_descriptor.relevant_entry = JITCodeEntry;
__jit_debug_register_code();
}

GDBJITRegistrationListener::~GDBJITRegistrationListener() {
// Free all registered object files.
std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
for (RegisteredObjectBufferMap::iterator I = ObjectBufferMap.begin(),
E = ObjectBufferMap.end();
I != E; ++I) {
// Call the private method that doesn't update the map so our iterator
// doesn't break.
deregisterObjectInternal(I);
}
ObjectBufferMap.clear();
}

void GDBJITRegistrationListener::notifyObjectLoaded(
ObjectKey K, const ObjectFile &Obj,
const RuntimeDyld::LoadedObjectInfo &L) {

OwningBinary<ObjectFile> DebugObj = L.getObjectForDebug(Obj);

// Bail out if debug objects aren't supported.
if (!DebugObj.getBinary())
return;

const char *Buffer = DebugObj.getBinary()->getMemoryBufferRef().getBufferStart();
size_t Size = DebugObj.getBinary()->getMemoryBufferRef().getBufferSize();

std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
assert(ObjectBufferMap.find(K) == ObjectBufferMap.end() &&
"Second attempt to perform debug registration.");
jit_code_entry* JITCodeEntry = new jit_code_entry();

if (!JITCodeEntry) {
llvm::report_fatal_error(
"Allocation failed when registering a JIT entry!\n");
} else {
JITCodeEntry->symfile_addr = Buffer;
JITCodeEntry->symfile_size = Size;

ObjectBufferMap[K] =
RegisteredObjectInfo(Size, JITCodeEntry, std::move(DebugObj));
NotifyDebugger(JITCodeEntry);
}
}

void GDBJITRegistrationListener::notifyFreeingObject(ObjectKey K) {
std::lock_guard<llvm::sys::Mutex> locked(*JITDebugLock);
RegisteredObjectBufferMap::iterator I = ObjectBufferMap.find(K);

if (I != ObjectBufferMap.end()) {
deregisterObjectInternal(I);
ObjectBufferMap.erase(I);
}
}

void GDBJITRegistrationListener::deregisterObjectInternal(
RegisteredObjectBufferMap::iterator I) {

jit_code_entry*& JITCodeEntry = I->second.Entry;

// Do the unregistration.
{
__jit_debug_descriptor.action_flag = JIT_UNREGISTER_FN;

// Remove the jit_code_entry from the linked list.
jit_code_entry* PrevEntry = JITCodeEntry->prev_entry;
jit_code_entry* NextEntry = JITCodeEntry->next_entry;

if (NextEntry) {
NextEntry->prev_entry = PrevEntry;
}
if (PrevEntry) {
PrevEntry->next_entry = NextEntry;
}
else {
assert(__jit_debug_descriptor.first_entry == JITCodeEntry);
__jit_debug_descriptor.first_entry = NextEntry;
}

// Tell the debugger which entry we removed, and unregister the code.
__jit_debug_descriptor.relevant_entry = JITCodeEntry;
__jit_debug_register_code();
}

delete JITCodeEntry;
JITCodeEntry = nullptr;
}

llvm::ManagedStatic<GDBJITRegistrationListener> GDBRegListener;
Expand Down
4 changes: 0 additions & 4 deletions lib/ExecutionEngine/MCJIT/MCJIT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,12 @@ JITSymbol MCJIT::findSymbol(const std::string &Name,
uint64_t MCJIT::getGlobalValueAddress(const std::string &Name) {
std::lock_guard<sys::Mutex> locked(lock);
uint64_t Result = getSymbolAddress(Name, false);
if (Result != 0)
finalizeLoadedModules();
return Result;
}

uint64_t MCJIT::getFunctionAddress(const std::string &Name) {
std::lock_guard<sys::Mutex> locked(lock);
uint64_t Result = getSymbolAddress(Name, true);
if (Result != 0)
finalizeLoadedModules();
return Result;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/ExecutionEngine/RuntimeDyld/RuntimeDyldImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <map>
#include <system_error>
#include <unordered_map>
#include <deque>

using namespace llvm;
using namespace llvm::object;
Expand Down Expand Up @@ -251,7 +252,7 @@ class RuntimeDyldImpl {

// A list of all sections emitted by the dynamic linker. These sections are
// referenced in the code by means of their index in this list - SectionID.
typedef SmallVector<SectionEntry, 64> SectionList;
typedef std::deque<SectionEntry> SectionList;
SectionList Sections;

typedef unsigned SID; // Type for SectionIDs
Expand Down
1 change: 1 addition & 0 deletions lib/Target/X86/X86.td
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ def ProcessorFeatures {
FeatureINVPCID,
FeatureLZCNT,
FeatureMOVBE,
FeatureRTM,
FeatureFastVariableShuffle];
list<SubtargetFeature> HSWSpecificFeatures = [FeaturePOPCNTFalseDeps,
FeatureLZCNTFalseDeps];
Expand Down
Loading