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

Threaded code generation with mr::Builder #23

Open
MaikKlein opened this issue Aug 21, 2017 · 1 comment
Open

Threaded code generation with mr::Builder #23

MaikKlein opened this issue Aug 21, 2017 · 1 comment

Comments

@MaikKlein
Copy link

I currently want to multi-thread my code generation, but Builder is inherently mutable. The simple solution would be to just wrap it in a mutex, but that would kill the performance.

One solution that I am thinking of is to create a separate builder object for every node that I traverse, then I would return the builder object and merge them together in the correct order.

The only problem that I see are the ids. If I would want to split the builder object into many small builder objects I would need to keep track of the correct IDs.

#[derive(Default)]
pub struct Builder {
    module: mr::Module,
    next_id: Arc<AtomicUsize>, // <= from u32 to Arc<AtomicUsize>,
    function: Option<mr::Function>,
    basic_block: Option<mr::BasicBlock>,
}

One solution would be to use an Arc<AtomicUsize>, this could also made generic.

And and append function to merge them together. builder.append(other_builder);

What are your thoughts?

@antiagainst
Copy link
Collaborator

The above sounds good to me. Please feel free to modify and send pull requests! :)

Just keep it as Arc<AtomicUsize> would be fine for me. Let's change it to a more generic solution when demanded.

Nit: append() sounds more like attaching at the end of the builder; we actually want merge().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants