Skip to content
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

LLVM 11 rebase #5

Open
wants to merge 14 commits into
base: upstream-llvm11-snapshot
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions Makefile.isp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.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"
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 += -DLLVM_BINUTILS_INCDIR=/usr/include
COMMON_CMAKE_FLAGS += -DBUILD_SHARED_LIBS=True
COMMON_CMAKE_FLAGS += -DLLVM_OPTIMIZED_TABLEGEN=True
COMMON_CMAKE_FLAGS += -DLLVM_BUILD_TESTS=True
COMMON_CMAKE_FLAGS += -DDEFAULT_SYSROOT=$(ISP_PREFIX)/riscv64-unknown-elf

Choose a reason for hiding this comment

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

Can these changes be squashed into a previous commit?

COMMON_CMAKE_FLAGS += -DLLVM_DEFAULT_TARGET_TRIPLE="riscv64-unknown-elf"
COMMON_CMAKE_FLAGS += -DLLVM_TARGETS_TO_BUILD="RISCV"

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
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
29 changes: 25 additions & 4 deletions llvm/include/llvm/MC/MCInst.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,41 @@ class MCInst {
// These flags could be used to pass some info from one target subcomponent
// to another, for example, from disassembler to asm printer. The values of
// the flags have any sense on target level only (e.g. prefixes on x86).
unsigned Flags = 0;
enum : unsigned { NumFlagsBits = 31 };
mutable uint32_t Flags : NumFlagsBits;

SMLoc Loc;
SmallVector<MCOperand, 8> Operands;

public:
/// Get the (implementation defined) symbol flags.
uint32_t getFlags() const { return Flags; }

/// Set the (implementation defined) symbol flags.
void setFlags(uint32_t Value) const {
assert(Value < (1U << NumFlagsBits) && "Out of range flags");
Flags = Value;
}

/// Modify the flags via a mask
void modifyFlags(uint32_t Value, uint32_t Mask) const {
assert(Value < (1U << NumFlagsBits) && "Out of range flags");
Flags = (Flags & ~Mask) | Value;
}

void setFlag(uint32_t Value) const {
modifyFlags(Value, 0);
}

bool getFlag(uint32_t Flag) const {
return Flags & Flag;
}

MCInst() = default;

void setOpcode(unsigned Op) { Opcode = Op; }
unsigned getOpcode() const { return Opcode; }

void setFlags(unsigned F) { Flags = F; }
unsigned getFlags() const { return Flags; }

void setLoc(SMLoc loc) { Loc = loc; }
SMLoc getLoc() const { return Loc; }

Expand Down
7 changes: 7 additions & 0 deletions llvm/include/llvm/MC/MCObjectFileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ class MCObjectFileInfo {
/// Remarks section.
MCSection *RemarksSection = nullptr;

// ISP Metadata Section
MCSection *ISPMetadataSection;

/// EH frame section.
///
/// It is initialized on demand so it can be overwritten (with uniquing).
Expand Down Expand Up @@ -401,6 +404,10 @@ class MCObjectFileInfo {
return EHFrameSection;
}

MCSection *getISPMetadataSection() const {
return ISPMetadataSection;
}

enum Environment { IsMachO, IsELF, IsCOFF, IsWasm, IsXCOFF };
Environment getObjectFileType() const { return Env; }

Expand Down
2 changes: 2 additions & 0 deletions llvm/include/llvm/MC/MCObjectStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ class MCObjectStreamer : public MCStreamer {
void EmitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
void ChangeSection(MCSection *Section, const MCExpr *Subsection) override;
void EmitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
void EmitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment) override;

/// Emit an instruction to a special fragment, because this instruction
/// can change its size during relaxation.
Expand Down
10 changes: 10 additions & 0 deletions llvm/include/llvm/MC/MCStreamer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef LLVM_MC_MCSTREAMER_H
#define LLVM_MC_MCSTREAMER_H

#include "llvm/MC/SSITHMetadata.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/Optional.h"
Expand Down Expand Up @@ -102,6 +103,11 @@ class MCTargetStreamer {
virtual void emitLabel(MCSymbol *Symbol);
// Allow a target to add behavior to the emitAssignment of MCStreamer.
virtual void emitAssignment(MCSymbol *Symbol, const MCExpr *Value);
// Allow a target to add behavior to the EmitInstruction of MCStreamer
virtual void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI);
// Allow a target to add behavior or the EmitCommonSymbol of MCStreamer
virtual void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size,
unsigned ByteAlignment);

virtual void prettyPrintAsm(MCInstPrinter &InstPrinter, uint64_t Address,
const MCInst &Inst, const MCSubtargetInfo &STI,
Expand Down Expand Up @@ -613,6 +619,10 @@ class MCStreamer {
uint64_t Size = 0, unsigned ByteAlignment = 0,
SMLoc Loc = SMLoc()) = 0;

/// SSITH metadata write - only defined by MCELFStreamer
virtual void EmitSSITHMetadataEntry(SmallVector<MCFixup, 4> &Fixups,
uint8_t MD_type, uint8_t tag) {}

/// Emit a thread local bss (.tbss) symbol.
///
/// \param Section - The thread local common section.
Expand Down
12 changes: 10 additions & 2 deletions llvm/include/llvm/MC/MCSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MCSymbol {

/// The Flags field is used by object file implementations to store
/// additional per symbol information which is not easily classified.
enum : unsigned { NumFlagsBits = 16 };
enum : unsigned { NumFlagsBits = 31 };
mutable uint32_t Flags : NumFlagsBits;

/// Index field, for use by the object file implementation.
Expand Down Expand Up @@ -406,7 +406,6 @@ class MCSymbol {
/// dump - Print the value to stderr.
void dump() const;

protected:
/// Get the (implementation defined) symbol flags.
uint32_t getFlags() const { return Flags; }

Expand All @@ -421,6 +420,15 @@ class MCSymbol {
assert(Value < (1U << NumFlagsBits) && "Out of range flags");
Flags = (Flags & ~Mask) | Value;
}

void setFlag(uint32_t Value) const {
modifyFlags(Value, 0);
}

bool getFlag(uint32_t Flag) const {
return Flags & Flag;
}

};

inline raw_ostream &operator<<(raw_ostream &OS, const MCSymbol &Sym) {
Expand Down
Loading