RISCV relaxations (#408)

This PR enables RISC-V relaxations and changes to internal linkage for internal function and global symbols.

See also:
https://github.com/llvm/llvm-project/issues/167381#issuecomment-3513830043

Signed-off-by: xermicus <cyrill@parity.io>
This commit is contained in:
xermicus
2025-11-11 17:27:53 +01:00
committed by GitHub
parent 046455db06
commit 878ca91689
7 changed files with 16 additions and 13 deletions
+3
View File
@@ -6,6 +6,9 @@ This is a development pre-release.
Supported `polkadot-sdk` rev: `2509.0.0`
### Changed
- Instruct the LLVM backend and linker to `--relax` (may lead to smaller contract code size).
## v0.5.0
This is a development pre-release.
+8 -8
View File
@@ -1,10 +1,10 @@
{
"Baseline": 914,
"Computation": 2295,
"DivisionArithmetics": 14496,
"ERC20": 17482,
"Events": 1674,
"FibonacciIterative": 1490,
"Flipper": 2086,
"SHA1": 8158
"Baseline": 905,
"Computation": 2286,
"DivisionArithmetics": 14347,
"ERC20": 16929,
"Events": 1665,
"FibonacciIterative": 1447,
"Flipper": 2077,
"SHA1": 7721
}
+1 -1
View File
@@ -78,7 +78,7 @@ SECTIONS {
"--error-limit=0",
"--relocatable",
"--emit-relocs",
"--no-relax",
"--relax",
"--unique",
"--gc-sections",
self.linker_script_path.to_str().expect("should be utf8"),
@@ -35,7 +35,7 @@ impl<'ctx> Global<'ctx> {
.add_global(r#type, Some(address_space.into()), name);
let global = Self { r#type, value };
global.value.set_linkage(inkwell::module::Linkage::External);
global.value.set_linkage(inkwell::module::Linkage::Internal);
global
.value
.set_visibility(inkwell::GlobalVisibility::Default);
@@ -134,7 +134,7 @@ impl<'ctx> Context<'ctx> {
module
.get_function(import)
.unwrap_or_else(|| panic!("{import} import should be declared"))
.set_linkage(inkwell::module::Linkage::External);
.set_linkage(inkwell::module::Linkage::Internal);
}
}
@@ -29,7 +29,7 @@ impl TargetMachine {
/// LLVM target features.
pub const VM_FEATURES: &'static str =
"+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov";
"+e,+m,+a,+c,+zbb,+auipc-addi-fusion,+ld-add-fusion,+lui-addi-fusion,+xtheadcondmov,+relax";
/// A shortcut constructor.
/// A separate instance for every optimization level is created.
@@ -215,7 +215,7 @@ impl PolkaVMWriteLLVM for FunctionDefinition {
self.identifier.as_str(),
function_type,
self.result.len(),
Some(inkwell::module::Linkage::External),
Some(inkwell::module::Linkage::Internal),
Some((self.location.line, self.location.column)),
true,
)?;