Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
brainfucker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Taddeüs Kroes
brainfucker
Commits
4ad2e109
Commit
4ad2e109
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Added a small optimization example
parent
d1d5c13d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+57
-1
57 additions, 1 deletion
README.md
with
57 additions
and
1 deletion
README.md
+
57
−
1
View file @
4ad2e109
...
...
@@ -7,6 +7,7 @@ purpose of practicing OCaml LLVM bindings and seeing how well LLVM optimizes
arrays. Brainfuck commands are transformed to LLVM IR, which is generated in
such a way that it is easy to optimize for LLVM's
`opt`
utility.
Building and usage
==================
...
...
@@ -15,7 +16,7 @@ Building the `bf` compiler (Debian dependencies):
$ sudo apt-get install ocaml llvm-3.4 libllvm-3.4-ocaml-dev
$ make
Building a
b
rainfuck program (plain and optimized):
Building a
B
rainfuck program (plain and optimized):
$ make hello hello-opt # compile file "hello.b" to binaries
$ ./hello
...
...
@@ -35,3 +36,58 @@ Examining generated LLVM:
...
$ echo ++++++++++++. | ./bf | opt -O3 -S
...
Optimization example
--------------------
The
`text.py`
utility genrates single-cell Brainfuck code for a given text:
$ ./text.py Hello World!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
+++++++++++++++++++++++++++++.
+++++++.
.
+++.
-------------------------------------------------------------------------------.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++.
++++++++++++++++++++++++.
+++.
------.
--------.
-------------------------------------------------------------------.
-----------------------.
The LLVM optimization engine is able to completely optimize away array accesses
(in the absence of loops):
$ ./text.py Hello World! | ./bf | opt -O3 -S
; ModuleID = '<stdin>'
target datalayout = "e"
; Function Attrs: nounwind
declare i32 @putchar(i8) #0
declare void @exit(i32)
define void @_start() {
entry:
%0 = tail call i32 @putchar(i8 72)
%1 = tail call i32 @putchar(i8 101)
%2 = tail call i32 @putchar(i8 108)
%3 = tail call i32 @putchar(i8 108)
%4 = tail call i32 @putchar(i8 111)
%5 = tail call i32 @putchar(i8 32)
%6 = tail call i32 @putchar(i8 87)
%7 = tail call i32 @putchar(i8 111)
%8 = tail call i32 @putchar(i8 114)
%9 = tail call i32 @putchar(i8 108)
%10 = tail call i32 @putchar(i8 100)
%11 = tail call i32 @putchar(i8 33)
%12 = tail call i32 @putchar(i8 10)
tail call void @exit(i32 0)
ret void
}
attributes #0 = { nounwind }
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment