Skip to content

get llvm libcall optimizations working #9541

Closed

Description

@thestinger

It doesn't like that our libc signatures don't quite match, and we also currently have to mark all of the wrappers as inline(never) to prevent fixed_stack_segment from being too aggressively bubbled up.

Specifically, I really want dead-store-elimination working on unique pointers like it does with runtimeless Rust:

#[no_std];
#[allow(ctypes, cstack)];

extern {
    fn malloc(size: uint) -> *mut u8;
    fn free(ptr: *mut u8);
    fn abort() -> !;
}

#[lang = "exchange_malloc"]
#[inline(always)]
unsafe fn exchange_malloc(size: uint) -> *mut u8 {
    let ptr = malloc(size);
    if ptr == 0 as *mut u8 {
        abort()
    }
    ptr
}

#[lang = "exchange_free"]
#[inline(always)]
unsafe fn exchange_free(ptr: *mut u8) {
    free(ptr)
}

#[start]
fn main(_: int, _: **u8) -> int {
    let mut _a = ~5;
    0
}

LLVM eliminates the allocation here.

Activity

  1. thestinger commented on Oct 3, 2013

    @thestinger
    ContributorAuthor

    This is also going to prevent the upcoming escape analysis implementation in LLVM from working.

  2. thestinger commented on Jan 20, 2014

    @thestinger
    ContributorAuthor

    This is fixed for malloc and free, at least.

  3. added 4 commits that reference this issue on Nov 21, 2022
  4. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-slowIssue: Problems and improvements with respect to performance of generated code.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions