Skip to content

LLVM 11 rebase #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: upstream-llvm11-snapshot
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ autoconf/autom4te.cache
.vs
# clangd index
.clangd

#==============================================================================#
# Build Directories
#==============================================================================#
*-build
57 changes: 57 additions & 0 deletions Makefile.isp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.PHONY: all
.PHONY: debug
.PHONY: release
.PHONY: install
.PHONY: clean

export ISP_PREFIX ?= $(HOME)/.local/isp/

ifeq "$(shell isp-support/check_ninja_version)" "System ninja is new enough"
NINJA := ninja
else
NINJA := $(HOME)/.local/bin/ninja
endif

BUILD_TYPE ?= debug

COMMON_CMAKE_FLAGS += -G "Ninja"
COMMON_CMAKE_FLAGS += -DLLVM_ENABLE_PROJECTS="clang;lld;llvm"
COMMON_CMAKE_FLAGS += -DCMAKE_MAKE_PROGRAM=$(NINJA)
COMMON_CMAKE_FLAGS += -DCMAKE_INSTALL_PREFIX=$(ISP_PREFIX)
COMMON_CMAKE_FLAGS += -DCMAKE_C_COMPILER=clang
COMMON_CMAKE_FLAGS += -DCMAKE_CXX_COMPILER=clang++
COMMON_CMAKE_FLAGS += -DBUILD_SHARED_LIBS=True
COMMON_CMAKE_FLAGS += -DLLVM_OPTIMIZED_TABLEGEN=True
COMMON_CMAKE_FLAGS += -DLLVM_BUILD_TESTS=True
COMMON_CMAKE_FLAGS += -DLLVM_TARGETS_TO_BUILD="RISCV"
COMMON_CMAKE_FLAGS += -DCLANG_DEFAULT_RTLIB=compiler-rt

DEBUG_CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Debug
DEBUG_CMAKE_FLAGS += -DLLVM_ENABLE_ASSERTIONS=ON
DEBUG_CMAKE_FLAGS += -DCMAKE_C_FLAGS=-fstandalone-debug
DEBUG_CMAKE_FLAGS += -DCMAKE_CXX_FLAGS=-fstandalone-debug

RELEASE_CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Release

debug-build/build.ninja: CMAKE_FLAGS := $(COMMON_CMAKE_FLAGS) $(DEBUG_CMAKE_FLAGS)

release-build/build.ninja: CMAKE_FLAGS := $(COMMON_CMAKE_FLAGS) $(RELEASE_CMAKE_FLAGS)

all: $(BUILD_TYPE)

$(BUILD_TYPE): $(BUILD_TYPE)-build/build.ninja
$(NINJA) -C $(BUILD_TYPE)-build

$(BUILD_TYPE)-build/build.ninja:
$(RM) -r $(BUILD_TYPE)-build
mkdir -p $(BUILD_TYPE)-build
cd $(BUILD_TYPE)-build; cmake $(CMAKE_FLAGS) ../llvm

install: $(BUILD_TYPE)-install

debug-install release-install: %-install: $*
$(NINJA) -C $*-build install

clean:
$(RM) -r debug-build
$(RM) -r release-build
2 changes: 1 addition & 1 deletion clang/lib/Driver/ToolChains/RISCVToolchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void RISCV::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("elf32lriscv");
}

std::string Linker = getToolChain().GetProgramPath(getShortName());
std::string Linker = getToolChain().GetLinkerPath();

bool WantCRTs =
!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/riscv32-toolchain.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// A basic clang -cc1 command-line, and simple environment check.
// REQUIRES: platform-linker

// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 2>&1 | FileCheck -check-prefix=CC1 %s
// CC1: clang{{.*}} "-cc1" "-triple" "riscv32"

// Test interaction with -fuse-ld=lld, if lld is available.
// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 2>&1 | FileCheck -check-prefix=LLD %s
// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}

// In the below tests, --rtlib=platform is used so that the driver ignores
// the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib

Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/riscv64-toolchain.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
// A basic clang -cc1 command-line, and simple environment check.
// REQUIRES: platform-linker

// RUN: %clang %s -### -no-canonical-prefixes -target riscv64 2>&1 | FileCheck -check-prefix=CC1 %s
// CC1: clang{{.*}} "-cc1" "-triple" "riscv64"

// Test interaction with -fuse-ld=lld, if lld is available.
// RUN: %clang %s -### -no-canonical-prefixes -target riscv32 -fuse-ld=lld 2>&1 | FileCheck -check-prefix=LLD %s
// LLD: {{(error: invalid linker name in argument '-fuse-ld=lld')|(ld.lld)}}

// In the below tests, --rtlib=platform is used so that the driver ignores
// the configure-time CLANG_DEFAULT_RTLIB option when choosing the runtime lib

Expand Down
3 changes: 3 additions & 0 deletions clang/test/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ except KeyError:
import lit.llvm
lit.llvm.initialize(lit_config, config)

if not "@CLANG_DEFAULT_LINKER@":
config.available_features('platform-linker')

# Let the main config do the real work.
lit_config.load_config(config, "@CLANG_SOURCE_DIR@/test/lit.cfg.py")
2 changes: 2 additions & 0 deletions compiler-rt/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ clang_darwin
multi_arch
*.sw?
*.pyc
build32
build64
63 changes: 63 additions & 0 deletions compiler-rt/Makefile.isp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.PHONY: all
.PHONY: install
.PHONY: clean
.PHONY: rv32 rv64

NINJA := ninja

COMMON_FLAGS += -G "Ninja"
COMMON_FLAGS += -DCMAKE_C_COMPILER=$(ISP_PREFIX)/bin/clang
COMMON_FLAGS += -DCMAKE_CXX_COMPILER=$(ISP_PREFIX)/bin/clang++
COMMON_FLAGS += -DCMAKE_AR=$(ISP_PREFIX)/bin/llvm-ar
COMMON_FLAGS += -DCMAKE_NM=$(ISP_PREFIX)/bin/llvm-nm
COMMON_FLAGS += -DCMAKE_RANLIB=$(ISP_PREFIX)/bin/llvm-ranlib
COMMON_FLAGS += -DCMAKE_INSTALL_PREFIX=$(ISP_PREFIX)
COMMON_FLAGS += -DCMAKE_VERBOSE_MAKEFILE=ON
COMMON_FLAGS += -DCMAKE_EXE_LINKER_FLAGS="-fuse-ld=lld"
COMMON_FLAGS += -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY
COMMON_FLAGS += -DCOMPILER_RT_OS_DIR=baremetal -DCOMPILER_RT_BAREMETAL_BUILD=ON
COMMON_FLAGS += -DCOMPILER_RT_BUILD_SANITIZERS=OFF -DCOMPILER_RT_BUILD_XRAY=OFF
COMMON_FLAGS += -DCOMPILER_RT_BUILD_LIBFUZZER=OFF -DCOMPILER_RT_BUILD_PROFILE=OFF

RV32_TARGET_FLAGS += --target=riscv32-unknown-elf -march=rv32ima -mabi=ilp32
RV32_TARGET_FLAGS += -mno-relax
RV32_FLAGS += -DCMAKE_C_FLAGS=$(RV32_TARGET_FLAGS)
RV32_FLAGS += -DCMAKE_CXX_FLAGS=$(RV32_TARGET_FLAGS)
RV32_FLAGS += -DCMAKE_ASM_FLAGS=$(RV32_TARGET_FLAGS)
RV32_FLAGS += -DCOMPILER_RT_DEFAULT_TARGET_ARCH=riscv32
RV32_FLAGS += -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=riscv32-unknown-elf
RV32_FLAGS += -DCMAKE_SYSROOT=$(ISP_PREFIX)/clang_sysroot/riscv32-unknown-elf

RV64_TARGET_FLAGS += --target=riscv64-unknown-elf -march=rv64imafd -mabi=lp64d
RV64_TARGET_FLAGS += -mno-relax -mcmodel=medany
RV64_FLAGS += -DCMAKE_C_FLAGS=$(RV64_TARGET_FLAGS)
RV64_FLAGS += -DCMAKE_CXX_FLAGS=$(RV64_TARGET_FLAGS)
RV64_FLAGS += -DCMAKE_ASM_FLAGS=$(RV64_TARGET_FLAGS)
RV64_FLAGS += -DCOMPILER_RT_DEFAULT_TARGET_ARCH=riscv64
RV64_FLAGS += -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE=riscv64-unknown-elf
RV64_FLAGS += -DCMAKE_SYSROOT=$(ISP_PREFIX)/clang_sysroot/riscv64-unknown-elf

all: rv32 rv64

rv32: build32/build.ninja
$(NINJA) -v -C build32

rv64: build64/build.ninja
$(NINJA) -v -C build64

build32/build.ninja:
mkdir -p build32
cd build32; cmake $(COMMON_FLAGS) $(RV32_FLAGS) ..

build64/build.ninja:
mkdir -p build64
cd build64; cmake $(COMMON_FLAGS) $(RV64_FLAGS) ..

install:
$(NINJA) -v -C build32 install
$(NINJA) -v -C build64 install
mkdir -p $(ISP_PREFIX)/lib/clang/11.0.0/lib
cp $(ISP_PREFIX)/lib/baremetal/* $(ISP_PREFIX)/lib/clang/11.0.0/lib

clean:
$(RM) -r build32 build64
5 changes: 5 additions & 0 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,12 @@ else ()
# double routines.
if("${arch}" STREQUAL "riscv32")
list(APPEND BUILTIN_CFLAGS -fforce-enable-int128)
list(APPEND BUILTIN_CFLAGS -march=rv32ima -mabi=ilp32)
endif()
if("${arch}" STREQUAL "riscv64")
list(APPEND BUILTIN_CFLAGS -march=rv64imafd -mabi=lp64d)
endif()
list(APPEND BUILTIN_CFLAGS -mno-relax)

add_compiler_rt_runtime(clang_rt.builtins
STATIC
Expand Down
26 changes: 26 additions & 0 deletions isp-support/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Best results obtained by using the gold linker. Your ld is likely a symlink,
point it at ld.gold

Be sure to clone recursively

To build the llvm riscv cross compiler first make sure that you have a riscv
toolchain installed. I worked with the instructions here for a clean riscv
toolchain:

https://github.com/lowRISC/riscv-llvm

Then run the configure script. I *strongly* recommend you let it install the
same version of cmake and ninja that I was using (the latest release as of May
22, 2018). It will also ask you for the base path to the riscv toolchain. This
will enable the cross compiler to actually work, and is where the cross compiler
will get installed.

./configure.sh

After that, you can build either the debug or release version. I have been
working with the debug version during development, and strongly recommend it.
The release version is currently *untested* and *unsupported*.

cd debug-build
ninja
ninja install
12 changes: 12 additions & 0 deletions isp-support/check_ninja_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

version=`ninja --version`;
check="1.8.2";
winner=`echo -e "${version}\n${check}" | sort -nr | head -1`;
if [[ "${winner}" = "${version}" ]]; then
echo "System ninja is new enough"
exit 0
else
echo "System ninja is too old"
exit 1
fi
29 changes: 29 additions & 0 deletions isp-support/install-dependencies
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

set -e

apt-get update

apt-get install -y \
binutils-dev \
build-essential \
clang \
cmake \
unzip \
wget \
zlib1g-dev

ninja_check() {
md5sum --quiet -c <<< "540b5a37ac9d822b07179ec1771855ae $HOME/.local/bin/ninja"
}

if [ -f $HOME/.local/bin/ninja ]; then
ninja_check
else
wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip
unzip -o ninja-linux.zip
mkdir -p $HOME/.local/bin
mv ninja $HOME/.local/bin
rm ninja-linux.zip
ninja_check
fi
32 changes: 23 additions & 9 deletions llvm/include/llvm/CodeGen/MachineInstr.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

namespace llvm {

typedef uint32_t MachineInstrFlags_t;
class AAResults;
template <typename T> class ArrayRef;
class DIExpression;
Expand Down Expand Up @@ -102,10 +103,23 @@ class MachineInstr
// no unsigned wrap.
NoSWrap = 1 << 12, // Instruction supports binary operator
// no signed wrap.
IsExact = 1 << 13, // Instruction supports division is
IsExact = 1 << 13, // Instruction supports division is
// known to be exact.
NoFPExcept = 1 << 14, // Instruction does not raise
// floatint-point exceptions.
FnProlog = 1 << 15, // Instruction is part of the compiler generated
// prolog
FnEpilog = 1 << 16, // Instruction is part of the compiler generated
// epilog
FPtrStore = 1 << 17, // Instruction writes a function pointer to memory
FPtrCreate = 1 << 18, // Instruction creates a function pointer
CallTarget = 1 << 19, // first instruction of a function
ReturnTarget = 1 << 20, // first instruction after a call
BranchTarget = 1 << 21, // a branch lands here.
IsCall = 1 << 22,
IsReturn = 1 << 23,
IsBranch = 1 << 24,
MaxFlagShift = 24
};

private:
Expand All @@ -118,7 +132,7 @@ class MachineInstr
using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
OperandCapacity CapOperands; // Capacity of the Operands array.

uint16_t Flags = 0; // Various bits of additional
MachineInstrFlags_t Flags = 0; // Various bits of additional
// information about machine
// instruction.

Expand Down Expand Up @@ -304,7 +318,7 @@ class MachineInstr
}

/// Return the MI flags bitvector.
uint16_t getFlags() const {
MachineInstrFlags_t getFlags() const {
return Flags;
}

Expand All @@ -315,18 +329,18 @@ class MachineInstr

/// Set a MI flag.
void setFlag(MIFlag Flag) {
Flags |= (uint16_t)Flag;
Flags |= (MachineInstrFlags_t)Flag;
}

void setFlags(unsigned flags) {
void setFlags(MachineInstrFlags_t flags) {
// Filter out the automatically maintained flags.
unsigned Mask = BundledPred | BundledSucc;
MachineInstrFlags_t Mask = BundledPred | BundledSucc;
Flags = (Flags & Mask) | (flags & ~Mask);
}

/// clearFlag - Clear a MI flag.
void clearFlag(MIFlag Flag) {
Flags &= ~((uint16_t)Flag);
Flags &= ~((MachineInstrFlags_t)Flag);
}

/// Return true if MI is in a bundle (but not the first MI in a bundle).
Expand Down Expand Up @@ -1632,9 +1646,9 @@ class MachineInstr
/// Return the MIFlags which represent both MachineInstrs. This
/// should be used when merging two MachineInstrs into one. This routine does
/// not modify the MIFlags of this MachineInstr.
uint16_t mergeFlagsWith(const MachineInstr& Other) const;
MachineInstrFlags_t mergeFlagsWith(const MachineInstr& Other) const;

static uint16_t copyFlagsFromInstruction(const Instruction &I);
static MachineInstrFlags_t copyFlagsFromInstruction(const Instruction &I);

/// Copy all flags to MachineInst MIFlags
void copyIRFlags(const Instruction &I);
Expand Down
6 changes: 4 additions & 2 deletions llvm/include/llvm/CodeGen/TargetInstrInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,8 @@ class TargetInstrInfo : public MCInstrInfo {
MachineBasicBlock::iterator MI,
Register SrcReg, bool isKill, int FrameIndex,
const TargetRegisterClass *RC,
const TargetRegisterInfo *TRI) const {
const TargetRegisterInfo *TRI,
unsigned flags = 0) const {
llvm_unreachable("Target didn't implement "
"TargetInstrInfo::storeRegToStackSlot!");
}
Expand All @@ -990,7 +991,8 @@ class TargetInstrInfo : public MCInstrInfo {
MachineBasicBlock::iterator MI,
Register DestReg, int FrameIndex,
const TargetRegisterClass *RC,
const TargetRegisterInfo *TRI) const {
const TargetRegisterInfo *TRI,
unsigned flags = 0) const {
llvm_unreachable("Target didn't implement "
"TargetInstrInfo::loadRegFromStackSlot!");
}
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(LLVM_TARGET_DEFINITIONS Attributes.td)
tablegen(LLVM Attributes.inc -gen-attrs)
add_public_tablegen_target(attributes_gen)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Squashed?


set(LLVM_TARGET_DEFINITIONS Intrinsics.td)
tablegen(LLVM IntrinsicImpl.inc -gen-intrinsic-impl)
Expand Down
Loading