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

Merge latest changes #58

Merged
merged 89 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
3a99a67
experiments with RV32P
PhilippvK Feb 21, 2024
3d7af8b
move to llvm 18
PhilippvK Feb 21, 2024
a202492
add legalizer info to settings (WIP)
PhilippvK Feb 21, 2024
2a124c8
fix patterngen mattr
PhilippvK Feb 21, 2024
852cc05
implement automatic lookup up llvm version
PhilippvK Feb 21, 2024
26ac012
minor fix
PhilippvK Feb 21, 2024
c87f0aa
filter_model: fix and implement missing major opcodes
PhilippvK Feb 21, 2024
5f89324
add insert markers patch for llvm 18
PhilippvK Feb 21, 2024
67d273e
add examples/cfg/riscv.yml
PhilippvK Feb 21, 2024
d9dd74b
add insert markers patch for llvm 18
PhilippvK Feb 21, 2024
77bdd33
refactor pattern-gen flow (setup)
PhilippvK Feb 21, 2024
54638b8
riscv_isa_info: llvm18 fix
PhilippvK Feb 21, 2024
0ecbf08
insert_markers_llvm18: fix typo
PhilippvK Feb 21, 2024
b32330b
add backend if legalizer settings
PhilippvK Feb 21, 2024
0c67a66
update cdsl2llvm dependency branch
PhilippvK Feb 21, 2024
eee3148
RV32P.core_desc: split sunpkd8xy into multiple instrs
PhilippvK Feb 26, 2024
b4bb65a
RV32P.core_desc: add GPR32Pair register alias (unused)
PhilippvK Feb 26, 2024
55f32b8
RV32P.core_desc: try new zpfsoperand mechanic (for better register pa…
PhilippvK Feb 26, 2024
fb0c2f5
filter.yml: update
PhilippvK Feb 26, 2024
222143c
riscv.yml: update legalizer settings
PhilippvK Feb 26, 2024
d0c9095
demo.py: load test files
PhilippvK Feb 26, 2024
a303895
demo.py: fix
PhilippvK Feb 26, 2024
78ec345
llvmir writer fix
PhilippvK Feb 26, 2024
6444449
riscv_gisel_legalizer: fix
PhilippvK Feb 26, 2024
c3ef953
flow: support user-provided test files (#50)
PhilippvK Feb 26, 2024
808541e
flow: detect duplicate patches
PhilippvK Feb 26, 2024
845a3d0
flow: gmir fix
PhilippvK Feb 26, 2024
1d91ee8
flow: refactor generate (skip/only)
PhilippvK Feb 26, 2024
af97dc7
flow: support user-provided test files (#50)
PhilippvK Feb 26, 2024
a301924
default settings: fix typos
PhilippvK Feb 26, 2024
1bb8c79
cdsl2llvm fix
PhilippvK Feb 26, 2024
363ed15
examples: add missing files
PhilippvK Feb 26, 2024
d4f0384
update filter
PhilippvK Feb 26, 2024
05fd99f
demo: disable everything except test and nand
PhilippvK Feb 26, 2024
a34bf3c
migrate to new pass infra
PhilippvK Feb 26, 2024
6a02b0a
add missing assertion msgs
PhilippvK Feb 26, 2024
3643e2c
support assembly test files
PhilippvK Feb 26, 2024
503cf55
fix lint warning
PhilippvK Feb 26, 2024
46469f4
test stage: make FileCheck available
PhilippvK Feb 26, 2024
bd310a6
examples/cdsl/RV32P.core_desc update
PhilippvK Mar 1, 2024
b4f4e83
flow fix
PhilippvK Mar 1, 2024
3018fcc
update demo
PhilippvK Mar 1, 2024
380ca20
lint
PhilippvK Mar 1, 2024
47a441f
fix last patch stage being skipped
PhilippvK Mar 1, 2024
556c881
more linting
PhilippvK Mar 1, 2024
f32c80b
address pr comment
PhilippvK Mar 1, 2024
894d080
add missing test file
PhilippvK Mar 1, 2024
19dea0b
update cv_nand tests
PhilippvK Mar 1, 2024
c1727d2
fix after linting
PhilippvK Mar 1, 2024
5a760c5
add PassResult and PassManager
PhilippvK Mar 4, 2024
a3d4353
update pass function args (expect input model name
PhilippvK Mar 4, 2024
bf1a3a7
add metrics to settings
PhilippvK Mar 4, 2024
a9b89da
fix
PhilippvK Mar 4, 2024
c578332
pass settings to passes
PhilippvK Mar 4, 2024
0031a57
temp
PhilippvK Mar 4, 2024
41348cc
fix
PhilippvK Mar 4, 2024
dfa4b17
pass shell env to passes
PhilippvK Mar 4, 2024
162a424
move pass helper properties to settings
PhilippvK Mar 4, 2024
ae31473
move passes to seperate file
PhilippvK Mar 4, 2024
557bbfb
passes: add PassFormat (unused)
PhilippvK Mar 4, 2024
84418db
PassResult: add outputs field (unused)
PhilippvK Mar 4, 2024
b5be067
passes: add PassFormat (unused)
PhilippvK Mar 4, 2024
b28c17b
fixes
PhilippvK Mar 4, 2024
c6d0d43
try to split pattern gen step into formats and patterns
PhilippvK Mar 4, 2024
be629e7
fix Example.core_desc
PhilippvK Mar 4, 2024
5218135
update demo
PhilippvK Mar 4, 2024
d62b338
patterngen fix
PhilippvK Mar 4, 2024
b8430f0
update cdsl2llvm branch
PhilippvK Mar 4, 2024
2c1eff1
allow (per-model) pass skipping via settings
PhilippvK Mar 4, 2024
c593fa7
fixes for cleanup and export step
PhilippvK Mar 4, 2024
6d39cb7
more fixes
PhilippvK Mar 4, 2024
386a8ed
passes: implement multiprocessing depending on number of cpus
PhilippvK Mar 4, 2024
dc5ed75
settings: avoid duplicated list items when merging
PhilippvK Mar 4, 2024
67a5a9c
update xcorev cdsl submodule
PhilippvK Mar 4, 2024
86effd5
update demo
PhilippvK Mar 5, 2024
eb18cc0
generate instr info
PhilippvK Mar 5, 2024
d64ce00
support model specific overrides
PhilippvK Mar 5, 2024
b2fdfe2
ignore 2 xcvalu instrs whihc fail type infer during llvm-tblgen
PhilippvK Mar 5, 2024
9b2c885
generate instr info (fixes)
PhilippvK Mar 5, 2024
94ec993
generate instr info (fixes)
PhilippvK Mar 5, 2024
c84e476
lint
PhilippvK Mar 5, 2024
659f7d8
generate instr info (fixes)
PhilippvK Mar 5, 2024
c40dd95
add instr_info_notes
PhilippvK Mar 5, 2024
d114f5e
generate instr info (fixes)
PhilippvK Mar 5, 2024
1618895
update examples
PhilippvK Mar 5, 2024
0241f63
fix
PhilippvK Mar 5, 2024
6152ec1
cleanup
PhilippvK Mar 5, 2024
6b4f4cd
fix
PhilippvK Mar 5, 2024
01dab0b
lint
PhilippvK Mar 5, 2024
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
805 changes: 805 additions & 0 deletions examples/cdsl/RV32P.core_desc

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions examples/cfg/filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
filter:
sets:
# keep: [XCoreVAlu]
drop: [RISCVBase, RISCVEncoding, Zicsr, Zifencei, RVSMode, RVDebug, RV32I, RVNMode, XCoreVSimd]
# drop: [RISCVBase, RISCVEncoding, Zicsr, Zifencei, RVSMode, RVDebug, RV32I, RVNMode, XCoreVSimd]
drop: [RISCVBase, RISCVEncoding, Zicsr, Zifencei, RVSMode, RVDebug, RV32I, RVNMode]
# drop: [RISCVBase, RISCVEncoding, Zicsr, Zifencei, RVSMode, RVDebug, RV32I, RVNMode, RV32Zpsfoperand]
instructions:
# keep: [CV_ABS, CV_ADD_B]
keep: [CV_ABS, CV_ADD_B]
drop: [CV_CLIPU, CV_CLIPR, CV_CLIPUR]
opcodes:
keep: [custom-0, custom-1, custom-2 ,custom-3, 0b00000]
keep: [custom-0, custom-1, custom-2 ,custom-3, 0b00000, OP-P, OP]
encoding_sizes:
keep: [32]
4 changes: 3 additions & 1 deletion examples/cfg/patches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ patches:
# file: gitlab_ci.patch
# file: llvm/gitlab_ci.patch
# file: /absolute/path/to/gitlab_ci.patch
- name: insert_markers_llvm17
# - name: insert_markers_llvm17
- name: insert_markers_llvm18
# TODO: automatially select patch depending on llvm version
# generated patch (TODO: implement)
# - name: ???
# target: llvm
Expand Down
76 changes: 76 additions & 0 deletions examples/cfg/riscv.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
riscv:
xlen: 32
features:
- m
- fast-unaligned-access
legalization:
gisel:
ops:
# TODO: simd shift?
# TODO: rotate left/right?
- name: [G_SMAX, G_UMAX, G_SMIN, G_UMIN, G_ABS]
types: [s32]
onlyif: [HasVendorXCVAlu]
- name: [G_ADD, G_SUB, G_AND, G_OR, G_XOR, G_ASHR, G_LSHR, G_SHL]
types: [v4i8, v2i16]
onlyif: [HasVendorXCVSimd]
- name: G_INSERT_VECTOR_ELT
types: [v4i8, v2i16]
onlyif: [HasVendorXCVSimd]
# - name: [G_ADD]
# types: [v4i8, v2i16]
# onlyif: [HasExtmyextsimd]
# - name: [G_ADD]
# types: [s16, s32]
# onlyif: [HasExtmyextalu]
# - name: [G_ADD, G_SMAX]
# types: [v4i8, v2i16]
# onlyif: [HasExtRV32Zpn]
# - name: [G_SHL, G_SMIN, G_SUB]
# types: [v4i8]
# onlyif: [HasExtRV32Zpn]
# - name: [G_SMIN, G_SMAX] # TODO: CLZ, REV, CMIX
# types: [s32]
# onlyif: [HasExtRV32Zbpo]
# # TODO: RV32Zpsfoperand (register pairs)
# TODO: G_BITCAST
transform_info:
shouldFoldTerminatingConditionAfterLSR: true
prefersVectorizedAddressing: false
enableInterleavedAccessVectorization: true
enableMaskedInterleavedAccessVectorization: null
enableScalableVectorization: false
preferEpilogueVectorization: null
supportsScalableVectors: false
# getInliningThresholdMultiplier: ?
# getInliningCostBenefitAnalysisSavingsMultiplier: ?
# getInliningCostBenefitAnalysisProfitableMultiplier: ?
# getInlinerVectorBonusPercent: ?
# getFlatAddressSpace: ?
# getMinVectorRegisterBitWidth: ?
# getCacheLineSize: ?
# getPrefetchDistance: ?
# getMaxPrefetchIterationsAhead: ?
# getMaxMemIntrinsicInlineSizeThreshold: ?
# getAtomicMemIntrinsicMaxElementSize: ?
# getMaxNumArgs: ?
# getGISelRematGlobalCost: ?
# getMinTripCountTailFoldingThreshold: ?
# getMaxVScale: ?
# getVScaleForTuning: ?
# getPredictableBranchThreshold: ?
# isSingleThreaded: ?
# isNumRegsMajorCostOfLSR: ?
# canMacroFuseCmp: ?
# enableOrderedReductions: ?
# LSRWithInstrQueries: ?
# useAA: ?
# shouldBuildLookupTables: ?
# shouldBuildRelLookupTables: ?
# supportsEfficientVectorElementLoadStore: ?
# supportsTailCalls: ?
# enableSelectOptimize: ?
# isFPVectorizationPotentiallyUnsafe: ?
# isVScaleKnownToBeAPowerOfTwo: ?
# enableWritePrefetching: ?
5 changes: 5 additions & 0 deletions examples/cfg/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
test:
paths: []
# - MC/RISCV
# - CodeGen/RISCV
46 changes: 37 additions & 9 deletions examples/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,15 @@
seal5_flow.initialize(
clone=True,
clone_url="https://github.com/llvm/llvm-project.git",
clone_ref="llvmorg-17.0.6",
# clone_ref="llvmorg-17.0.6",
clone_ref="llvmorg-18.1.0-rc3",
force=True,
verbose=VERBOSE,
)

# Optional: clean existing settings/models for fresh run
seal5_flow.reset(settings=True, interactive=False)

# Clone Seal5 dependencies
# 1. M2-ISA-R (frontend only)
# 2. CDSL2LLVM (later)
# TODO: refresh refs
seal5_flow.setup(force=True, verbose=VERBOSE)

# Load CoreDSL inputs
cdsl_files = [
# XCOREV
Expand All @@ -66,6 +61,7 @@
EXAMPLES_DIR / "cdsl" / "rv_xcorev" / "XCoreVMem.core_desc",
EXAMPLES_DIR / "cdsl" / "rv_xcorev" / "XCoreVBranchImmediate.core_desc",
# RVP (will not work)
EXAMPLES_DIR / "cdsl" / "RV32P.core_desc",
# EXAMPLES_DIR / "cdsl" / "RVP.core_desc",
# S4E (untested) -> undefined XLEN
# EXAMPLES_DIR / "cdsl" / "rv_s4e" / "s4e-mac.core_desc",
Expand All @@ -78,6 +74,12 @@
]
seal5_flow.load(cdsl_files, verbose=VERBOSE, overwrite=True)

# Load test inputs
test_files = [
EXAMPLES_DIR / "tests" / "xcorev" / "cv_abs.test.c",
]
seal5_flow.load(test_files, verbose=VERBOSE, overwrite=True)

# Load YAML inputs
cfg_files = [
# XCOREV
Expand All @@ -94,25 +96,51 @@
EXAMPLES_DIR / "cfg" / "llvm.yml",
EXAMPLES_DIR / "cfg" / "filter.yml",
EXAMPLES_DIR / "cfg" / "patches.yml",
EXAMPLES_DIR / "cfg" / "riscv.yml",
EXAMPLES_DIR / "cfg" / "tests.yml",
EXAMPLES_DIR / "cfg" / "git.yml",
]
seal5_flow.load(cfg_files, verbose=VERBOSE, overwrite=False)

# Clone & install Seal5 dependencies
# 1. CDSL2LLVM (add PHASE_0 patches)
seal5_flow.setup(force=True, verbose=VERBOSE)

# Apply initial patches
seal5_flow.patch(verbose=VERBOSE, stages=[PatchStage.PHASE_0])

if not FAST:
# Build initial LLVM
seal5_flow.build(verbose=VERBOSE, config="release")
else:
pass
# Build PatternGen & llc
# seal5_flow.build(verbose=VERBOSE, config="release", target="pattern-gen")
# seal5_flow.build(verbose=VERBOSE, config="release", target="llc")

# Transform inputs
# 1. Create M2-ISA-R metamodel
# 2. Convert to Seal5 metamodel (including aliases, builtins,...)
# 3. Analyse/optimize instructions
seal5_flow.transform(verbose=VERBOSE)

# Generate patches
seal5_flow.generate(verbose=VERBOSE)
# Generate patches (except Patterns)
seal5_flow.generate(verbose=VERBOSE, skip=["pattern_gen"])

# Apply next patches
seal5_flow.patch(verbose=VERBOSE, stages=[PatchStage.PHASE_1, PatchStage.PHASE_2])

if not FAST:
# Build patch LLVM
seal5_flow.build(verbose=VERBOSE, config="release")
else:
# Rebuilt PatternGen & llc
seal5_flow.build(verbose=VERBOSE, config="release", target="pattern-gen")
seal5_flow.build(verbose=VERBOSE, config="release", target="llc")

# Generate remaining patches
seal5_flow.generate(verbose=VERBOSE, only=["pattern_gen"])


# Apply patches
seal5_flow.patch(verbose=VERBOSE)
Expand Down
9 changes: 9 additions & 0 deletions examples/tests/xcorev/cv_abs.test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang --target=riscv32 -march=rv32ixs4emac -c -o %t.o %s
// RUN: llvm-objdump --disassembler-options=numeric -d %t.o | FileCheck %s

int main() {
// CHECK: 0b 90 1a 01 cv.abs x1, x2
asm("cv.abs x1, x2");

return 0;
}
9 changes: 9 additions & 0 deletions examples/tests/xcorev/cv_mac.test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang --target=riscv32 -march=rv32ixs4emac -c -o %t.o %s
// RUN: llvm-objdump --disassembler-options=numeric -d %t.o | FileCheck %s

int main() {
// CHECK: 0b 90 1a 01 cv.mac x1, x2, x3
asm("cv.mac x1, x2, x3");

return 0;
}
7 changes: 6 additions & 1 deletion seal5/backends/llvmir/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ def main():
install_dir = pathlib.Path(install_dir)
try:
cdsl2llvm.run_pattern_gen(
install_dir / "llvm" / "build", input_file, output_file, skip_patterns=True, skip_formats=True
# install_dir / "llvm" / "build",
install_dir,
input_file,
output_file,
skip_patterns=True,
skip_formats=True
)
metrics["n_success"] += 1
except AssertionError:
Expand Down
26 changes: 22 additions & 4 deletions seal5/backends/patterngen/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,20 @@ def main():
# print("model", model)
artifacts = {}
artifacts[None] = [] # used for global artifacts
settings = model.get("settings", None)
if args.splitted:
# errs = []
model_includes = []
default_mattr = "+m,+fast-unaligned-access"
if settings:
riscv_settings = settings.riscv
if riscv_settings:
features = riscv_settings.features
if features is None:
pass
else:
default_mattr = ",".join([f"+{f}" for f in features])

assert out_path.is_dir(), "Expecting output directory when using --splitted"
for set_name, set_def in model["sets"].items():
artifacts[set_name] = []
Expand Down Expand Up @@ -125,19 +136,26 @@ def main():
output_file = set_dir / out_name
output_file_fmt = set_dir / out_name_fmt
install_dir = os.getenv("CDSL2LLVM_DIR", None)
ext = None
predicate = None
mattr = default_mattr
if ext_settings is not None:
ext = ext_settings.get_predicate(name=set_name)
predicate = ext_settings.get_predicate(name=set_name)
arch_ = ext_settings.get_arch(name=set_name)
mattr = ",".join([*mattr.split(","), f"+{arch_}"])

assert install_dir is not None
install_dir = pathlib.Path(install_dir)
try:
cdsl2llvm.run_pattern_gen(
install_dir / "llvm" / "build",
# install_dir / "llvm" / "build",
install_dir,
input_file,
output_file,
skip_patterns=False,
skip_formats=not args.formats,
ext=ext,
ext=predicate,
mattr=mattr,

)
if output_file.is_file():
metrics["n_success"] += 1
Expand Down
Empty file.
Loading
Loading