Skip to content

Commit df82f6b

Browse files
committed
Policy support ported from split LLVM repo
1 parent c1106c9 commit df82f6b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+894
-102
lines changed

Makefile.isp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.PHONY: all
2+
.PHONY: debug
3+
.PHONY: release
4+
.PHONY: install
5+
.PHONY: clean
6+
7+
export ISP_PREFIX ?= $(HOME)/.local/isp/
8+
9+
ifeq "$(shell isp-support/check_ninja_version)" "System ninja is new enough"
10+
NINJA := ninja
11+
else
12+
NINJA := $(HOME)/.local/bin/ninja
13+
endif
14+
15+
BUILD_TYPE ?= debug
16+
17+
COMMON_CMAKE_FLAGS += -G "Ninja"
18+
COMMON_CMAKE_FLAGS += -DLLVM_ENABLE_PROJECTS="clang"
19+
COMMON_CMAKE_FLAGS += -DCMAKE_MAKE_PROGRAM=$(NINJA)
20+
COMMON_CMAKE_FLAGS += -DCMAKE_INSTALL_PREFIX=$(ISP_PREFIX)
21+
COMMON_CMAKE_FLAGS += -DCMAKE_C_COMPILER=clang
22+
COMMON_CMAKE_FLAGS += -DCMAKE_CXX_COMPILER=clang++
23+
COMMON_CMAKE_FLAGS += -DLLVM_BINUTILS_INCDIR=/usr/include
24+
COMMON_CMAKE_FLAGS += -DBUILD_SHARED_LIBS=True
25+
COMMON_CMAKE_FLAGS += -DLLVM_OPTIMIZED_TABLEGEN=True
26+
COMMON_CMAKE_FLAGS += -DLLVM_BUILD_TESTS=True
27+
COMMON_CMAKE_FLAGS += -DDEFAULT_SYSROOT=$(ISP_PREFIX)riscv32-unknown-elf
28+
COMMON_CMAKE_FLAGS += -DLLVM_DEFAULT_TARGET_TRIPLE="riscv32-unknown-elf"
29+
COMMON_CMAKE_FLAGS += -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="RISCV"
30+
COMMON_CMAKE_FLAGS += -DLLVM_TARGETS_TO_BUILD=""
31+
32+
DEBUG_CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Debug
33+
DEBUG_CMAKE_FLAGS += -DLLVM_ENABLE_ASSERTIONS=ON
34+
DEBUG_CMAKE_FLAGS += -DCMAKE_C_FLAGS=-fstandalone-debug
35+
DEBUG_CMAKE_FLAGS += -DCMAKE_CXX_FLAGS=-fstandalone-debug
36+
37+
RELEASE_CMAKE_FLAGS := -DCMAKE_BUILD_TYPE=Release
38+
39+
debug-build/build.ninja: CMAKE_FLAGS := $(COMMON_CMAKE_FLAGS) $(DEBUG_CMAKE_FLAGS)
40+
41+
release-build/build.ninja: CMAKE_FLAGS := $(COMMON_CMAKE_FLAGS) $(RELEASE_CMAKE_FLAGS)
42+
43+
all: $(BUILD_TYPE)
44+
45+
$(BUILD_TYPE): $(BUILD_TYPE)-build/build.ninja
46+
$(NINJA) -C $(BUILD_TYPE)-build
47+
48+
$(BUILD_TYPE)-build/build.ninja:
49+
$(RM) -r $(BUILD_TYPE)-build
50+
mkdir -p $(BUILD_TYPE)-build
51+
cd $(BUILD_TYPE)-build; cmake $(CMAKE_FLAGS) ../llvm
52+
53+
install: $(BUILD_TYPE)-install
54+
55+
debug-install release-install: %-install: $*
56+
$(NINJA) -C $*-build install
57+
58+
clean:
59+
$(RM) -r debug-build
60+
$(RM) -r release-build

isp-support/README

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Best results obtained by using the gold linker. Your ld is likely a symlink,
2+
point it at ld.gold
3+
4+
Be sure to clone recursively
5+
6+
To build the llvm riscv cross compiler first make sure that you have a riscv
7+
toolchain installed. I worked with the instructions here for a clean riscv
8+
toolchain:
9+
10+
https://github.com/lowRISC/riscv-llvm
11+
12+
Then run the configure script. I *strongly* recommend you let it install the
13+
same version of cmake and ninja that I was using (the latest release as of May
14+
22, 2018). It will also ask you for the base path to the riscv toolchain. This
15+
will enable the cross compiler to actually work, and is where the cross compiler
16+
will get installed.
17+
18+
./configure.sh
19+
20+
After that, you can build either the debug or release version. I have been
21+
working with the debug version during development, and strongly recommend it.
22+
The release version is currently *untested* and *unsupported*.
23+
24+
cd debug-build
25+
ninja
26+
ninja install

isp-support/check_ninja_version

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
version=`ninja --version`;
4+
check="1.8.2";
5+
winner=`echo -e "${version}\n${check}" | sort -nr | head -1`;
6+
if [[ "${winner}" = "${version}" ]]; then
7+
echo "System ninja is new enough"
8+
exit 0
9+
else
10+
echo "System ninja is too old"
11+
exit 1
12+
fi

isp-support/install-dependencies

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
apt-get update
6+
7+
apt-get install -y \
8+
binutils-dev \
9+
build-essential \
10+
clang \
11+
cmake \
12+
unzip \
13+
wget \
14+
zlib1g-dev
15+
16+
ninja_check() {
17+
md5sum --quiet -c <<< "540b5a37ac9d822b07179ec1771855ae $HOME/.local/bin/ninja"
18+
}
19+
20+
if [ -f $HOME/.local/bin/ninja ]; then
21+
ninja_check
22+
else
23+
wget https://github.com/ninja-build/ninja/releases/download/v1.8.2/ninja-linux.zip
24+
unzip -o ninja-linux.zip
25+
mkdir -p $HOME/.local/bin
26+
mv ninja $HOME/.local/bin
27+
rm ninja-linux.zip
28+
ninja_check
29+
fi

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,12 @@ class AsmPrinter : public MachineFunctionPass {
410410
llvm_unreachable("EmitInstruction not implemented");
411411
}
412412

413+
//SSITH Placeholder, only used by RISCV currently
414+
virtual void EmitSSITHMetadataInst(MCSymbol *Sym, const MCSubtargetInfo &STI,
415+
uint8_t tag){}
416+
virtual void EmitSSITHMetadataFnRange(MCSymbol *begin, MCSymbol *end,
417+
const MCSubtargetInfo &STI) {}
418+
413419
/// Return the symbol for the specified constant pool entry.
414420
virtual MCSymbol *GetCPISymbol(unsigned CPID) const;
415421

llvm/include/llvm/CodeGen/MachineInstr.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,16 @@ class MachineInstr
102102
// no unsigned wrap.
103103
NoSWrap = 1 << 12, // Instruction supports binary operator
104104
// no signed wrap.
105-
IsExact = 1 << 13 // Instruction supports division is
106-
// known to be exact.
105+
IsExact = 1 << 13, // Instruction supports division is
106+
//SSITH
107+
FnProlog = 1 << 14, // Instruction is part of the compiler generated
108+
// prolog
109+
FnEpilog = 1 << 15, // Instruction is part of the compiler generated
110+
// epilog
111+
FPtrStore = 1 << 16, // Instruction writes a function pointer to memory
112+
FPtrCreate = 1 << 17 // Instruction creates a function pointer
107113
};
114+
//SSITH NOTE: Flags is only 16 bits long, getting close to the max here
108115

109116
private:
110117
const MCInstrDesc *MCID; // Instruction descriptor.
@@ -116,7 +123,7 @@ class MachineInstr
116123
using OperandCapacity = ArrayRecycler<MachineOperand>::Capacity;
117124
OperandCapacity CapOperands; // Capacity of the Operands array.
118125

119-
uint16_t Flags = 0; // Various bits of additional
126+
uint32_t Flags = 0; // Various bits of additional
120127
// information about machine
121128
// instruction.
122129

@@ -286,7 +293,7 @@ class MachineInstr
286293
}
287294

288295
/// Return the MI flags bitvector.
289-
uint16_t getFlags() const {
296+
uint32_t getFlags() const {
290297
return Flags;
291298
}
292299

@@ -297,7 +304,7 @@ class MachineInstr
297304

298305
/// Set a MI flag.
299306
void setFlag(MIFlag Flag) {
300-
Flags |= (uint16_t)Flag;
307+
Flags |= (uint32_t)Flag;
301308
}
302309

303310
void setFlags(unsigned flags) {
@@ -308,7 +315,7 @@ class MachineInstr
308315

309316
/// clearFlag - Clear a MI flag.
310317
void clearFlag(MIFlag Flag) {
311-
Flags &= ~((uint16_t)Flag);
318+
Flags &= ~((uint32_t)Flag);
312319
}
313320

314321
/// Return true if MI is in a bundle (but not the first MI in a bundle).
@@ -1551,7 +1558,7 @@ class MachineInstr
15511558
/// Return the MIFlags which represent both MachineInstrs. This
15521559
/// should be used when merging two MachineInstrs into one. This routine does
15531560
/// not modify the MIFlags of this MachineInstr.
1554-
uint16_t mergeFlagsWith(const MachineInstr& Other) const;
1561+
uint32_t mergeFlagsWith(const MachineInstr& Other) const;
15551562

15561563
static uint16_t copyFlagsFromInstruction(const Instruction &I);
15571564

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ struct SDNodeFlags {
367367
bool AllowContract : 1;
368368
bool ApproximateFuncs : 1;
369369
bool AllowReassociation : 1;
370+
bool FPtrCreate : 1;
371+
bool FPtrStore : 1;
370372

371373
public:
372374
/// Default constructor turns off all optimization flags.
@@ -375,7 +377,7 @@ struct SDNodeFlags {
375377
Exact(false), NoNaNs(false), NoInfs(false),
376378
NoSignedZeros(false), AllowReciprocal(false), VectorReduction(false),
377379
AllowContract(false), ApproximateFuncs(false),
378-
AllowReassociation(false) {}
380+
AllowReassociation(false), FPtrCreate(false), FPtrStore(false) {}
379381

380382
/// Propagate the fast-math-flags from an IR FPMathOperator.
381383
void copyFMF(const FPMathOperator &FPMO) {
@@ -438,6 +440,14 @@ struct SDNodeFlags {
438440
setDefined();
439441
AllowReassociation = b;
440442
}
443+
void setFPtrCreate(bool b) {
444+
setDefined();
445+
FPtrCreate = b;
446+
}
447+
void setFPtrStore(bool b) {
448+
setDefined();
449+
FPtrStore = b;
450+
}
441451

442452
// These are accessors for each flag.
443453
bool hasNoUnsignedWrap() const { return NoUnsignedWrap; }
@@ -451,6 +461,8 @@ struct SDNodeFlags {
451461
bool hasAllowContract() const { return AllowContract; }
452462
bool hasApproximateFuncs() const { return ApproximateFuncs; }
453463
bool hasAllowReassociation() const { return AllowReassociation; }
464+
bool hasFPtrCreate() const { return FPtrCreate; }
465+
bool hasFPtrStore() const { return FPtrStore; }
454466

455467
bool isFast() const {
456468
return NoSignedZeros && AllowReciprocal && NoNaNs && NoInfs &&
@@ -473,6 +485,8 @@ struct SDNodeFlags {
473485
AllowContract &= Flags.AllowContract;
474486
ApproximateFuncs &= Flags.ApproximateFuncs;
475487
AllowReassociation &= Flags.AllowReassociation;
488+
FPtrCreate &= Flags.FPtrCreate;
489+
FPtrStore &= Flags.FPtrStore;
476490
}
477491
};
478492

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,8 @@ class TargetInstrInfo : public MCInstrInfo {
887887
MachineBasicBlock::iterator MI,
888888
unsigned SrcReg, bool isKill, int FrameIndex,
889889
const TargetRegisterClass *RC,
890-
const TargetRegisterInfo *TRI) const {
890+
const TargetRegisterInfo *TRI,
891+
unsigned flags = 0) const {
891892
llvm_unreachable("Target didn't implement "
892893
"TargetInstrInfo::storeRegToStackSlot!");
893894
}
@@ -899,7 +900,8 @@ class TargetInstrInfo : public MCInstrInfo {
899900
MachineBasicBlock::iterator MI,
900901
unsigned DestReg, int FrameIndex,
901902
const TargetRegisterClass *RC,
902-
const TargetRegisterInfo *TRI) const {
903+
const TargetRegisterInfo *TRI,
904+
unsigned flags = 0) const {
903905
llvm_unreachable("Target didn't implement "
904906
"TargetInstrInfo::loadRegFromStackSlot!");
905907
}

llvm/include/llvm/MC/MCELFStreamer.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ class MCELFStreamer : public MCObjectStreamer {
8282
bool isBundleLocked() const;
8383
void EmitInstToFragment(const MCInst &Inst, const MCSubtargetInfo &) override;
8484
void EmitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override;
85-
85+
86+
//SSITH
87+
void EmitSSITHMetadataHeader(const MCSubtargetInfo &STI) override;
88+
void EmitSSITHMetadataEntry(SmallVector<MCFixup, 4> &Fixups,
89+
const MCSubtargetInfo &STI,
90+
uint8_t MD_type, uint8_t tag) override;
91+
char *SSITHpopLastInstruction(int nbytes) override;
92+
void SSITHpushInstruction(char *inst, int nbytes) override;
93+
8694
void fixSymbolsInTLSFixups(const MCExpr *expr);
8795
void finalizeCGProfileEntry(const MCSymbolRefExpr *&S);
8896
void finalizeCGProfile();

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,14 @@ class MCStreamer {
583583
uint64_t Size = 0, unsigned ByteAlignment = 0,
584584
SMLoc Loc = SMLoc()) = 0;
585585

586+
/// SSITH metadata write - only defined by MCELFStreamer
587+
virtual void EmitSSITHMetadataHeader(const MCSubtargetInfo &STI) {}
588+
virtual void EmitSSITHMetadataEntry(SmallVector<MCFixup, 4> &Fixups,
589+
const MCSubtargetInfo &STI,
590+
uint8_t MD_type, uint8_t tag) {}
591+
virtual char *SSITHpopLastInstruction(int nbytes) { return nullptr; }
592+
virtual void SSITHpushInstruction(char *inst, int nbytes) {}
593+
586594
/// Emit a thread local bss (.tbss) symbol.
587595
///
588596
/// \param Section - The thread local common section.

0 commit comments

Comments
 (0)