From 2f3c9c3e2fe161765bab7c590cfd3d945d7a54ea Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 13 Aug 2019 21:33:33 -0700 Subject: [PATCH] Mark memory.size VM intrinsics as not modifying state, and throw.trap/breakpoint as functions which do not return. --- lib/llvm-backend/src/intrinsics.rs | 37 ++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/llvm-backend/src/intrinsics.rs b/lib/llvm-backend/src/intrinsics.rs index 461c54d5d64..46b65a22719 100644 --- a/lib/llvm-backend/src/intrinsics.rs +++ b/lib/llvm-backend/src/intrinsics.rs @@ -1,4 +1,5 @@ use inkwell::{ + attributes::{Attribute, AttributeLoc}, builder::Builder, context::Context, module::Module, @@ -310,7 +311,7 @@ impl Intrinsics { i32_ty.fn_type(&[ctx_ptr_ty.as_basic_type_enum(), i32_ty_basic], false); let ret_i1_take_i1_i1 = i1_ty.fn_type(&[i1_ty_basic, i1_ty_basic], false); - Self { + let intrinsics = Self { ctlz_i32: module.add_function("llvm.ctlz.i32", ret_i32_take_i32_i1, None), ctlz_i64: module.add_function("llvm.ctlz.i64", ret_i64_take_i64_i1, None), @@ -531,7 +532,39 @@ impl Intrinsics { None, ), ctx_ptr_ty, - } + }; + + let readonly = + context.create_enum_attribute(Attribute::get_named_enum_kind_id("readonly"), 0); + intrinsics + .memory_size_dynamic_local + .add_attribute(AttributeLoc::Function, readonly); + intrinsics + .memory_size_static_local + .add_attribute(AttributeLoc::Function, readonly); + intrinsics + .memory_size_shared_local + .add_attribute(AttributeLoc::Function, readonly); + intrinsics + .memory_size_dynamic_import + .add_attribute(AttributeLoc::Function, readonly); + intrinsics + .memory_size_static_import + .add_attribute(AttributeLoc::Function, readonly); + intrinsics + .memory_size_shared_import + .add_attribute(AttributeLoc::Function, readonly); + + let noreturn = + context.create_enum_attribute(Attribute::get_named_enum_kind_id("noreturn"), 0); + intrinsics + .throw_trap + .add_attribute(AttributeLoc::Function, noreturn); + intrinsics + .throw_breakpoint + .add_attribute(AttributeLoc::Function, noreturn); + + intrinsics } }