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

feat(EVM-emulator): add support for propagating LLVM options #858

Merged
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
1 change: 1 addition & 0 deletions system-contracts/contracts/EvmEmulator.yul.llvm.options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'-eravm-jump-table-density-threshold=10 -tail-dup-size=4 -eravm-enable-split-loop-phi-live-ranges -tail-merge-only-bbs-without-succ'
16 changes: 15 additions & 1 deletion system-contracts/scripts/compile-yul.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// hardhat import should be the first import in the file
import { existsSync } from "fs";
import type { CompilerPaths } from "./utils";
import { spawn, compilerLocation, prepareCompilerPaths, needsRecompilation, setCompilationTime } from "./utils";
import * as fs from "fs";
Expand All @@ -11,11 +12,24 @@ const CONTRACTS_DIR = "contracts-preprocessed";
const BOOTLOADER_DIR = "bootloader";
const TIMESTAMP_FILE_YUL = "last_compilation_yul.timestamp";
const TIMESTAMP_FILE_BOOTLOADER = "last_compilation_bootloader.timestamp";
const LLVM_OPTIONS_FILE_EXTENSION = ".llvm.options";

export async function compileYul(paths: CompilerPaths, file: string) {
const zksolcLocation = await compilerLocation(COMPILER_VERSION, IS_COMPILER_PRE_RELEASE);

const filePath = `${paths.absolutePathSources}/${file}`;
const llvmOptionsFilePath = `${filePath}${LLVM_OPTIONS_FILE_EXTENSION}`;
let llvmOptions = "";
if (existsSync(llvmOptionsFilePath)) {
const llvmOptionsFileContent = (await fs.promises.readFile(llvmOptionsFilePath)).toString();
if (!llvmOptionsFileContent.startsWith("'") || !llvmOptionsFileContent.endsWith("'")) {
throw new Error(`Content in ${llvmOptionsFilePath} must start and end with a single quote.`);
}
llvmOptions = `--llvm-options=${llvmOptionsFileContent}`;
}

await spawn(
`${zksolcLocation} ${paths.absolutePathSources}/${file} --optimization 3 --enable-eravm-extensions --yul --bin --overwrite -o ${paths.absolutePathArtifacts}`
`${zksolcLocation} ${paths.absolutePathSources}/${file} --optimization 3 ${llvmOptions} --enable-eravm-extensions --yul --bin --overwrite -o ${paths.absolutePathArtifacts}`
);
}

Expand Down
6 changes: 5 additions & 1 deletion system-contracts/scripts/preprocess-system-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, mkdirSync, writeFileSync } from "fs";
import { copyFileSync, existsSync, mkdirSync, writeFileSync } from "fs";
import path from "path";
import { renderFile } from "template-file";
import { glob } from "fast-glob";
Expand All @@ -8,6 +8,7 @@ import { needsRecompilation, deleteDir, setCompilationTime, isFolderEmpty } from
const CONTRACTS_DIR = "contracts";
const OUTPUT_DIR = "contracts-preprocessed";
const TIMESTAMP_FILE = "last_compilation_preprocessing.timestamp"; // File to store the last compilation time
const LLVM_OPTIONS_FILE_EXTENSION = ".llvm.options";

const params = {
SYSTEM_CONTRACTS_OFFSET: "0x8000",
Expand Down Expand Up @@ -44,6 +45,9 @@ async function preprocess(testMode: boolean) {
mkdirSync(directory, { recursive: true });
}
writeFileSync(fileName, preprocessed);
if (existsSync(contract + LLVM_OPTIONS_FILE_EXTENSION)) {
copyFileSync(contract + LLVM_OPTIONS_FILE_EXTENSION, fileName + LLVM_OPTIONS_FILE_EXTENSION);
}
}

console.log("System Contracts preprocessing done!");
Expand Down
Loading