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
ddb09a9d
Commit
ddb09a9d
authored
10 years ago
by
Taddeüs Kroes
Browse files
Options
Downloads
Patches
Plain Diff
Extended optimization example
parent
4ad2e109
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
+48
-11
48 additions, 11 deletions
README.md
with
48 additions
and
11 deletions
README.md
+
48
−
11
View file @
ddb09a9d
...
...
@@ -58,18 +58,58 @@ The `text.py` utility genrates single-cell Brainfuck code for a given text:
-------------------------------------------------------------------.
-----------------------.
The LLVM optimization engine is able to completely optimize away array accesses
(in the absence of loops):
The compiler generates very verbose code:
$ ./text.py Hello World! | ./bf | opt -O3 -S
; ModuleID = '<stdin>'
target datalayout = "e"
$ ./text.py Hello World! | ./bf
...
; Function Attrs: nounwind
declare i32 @putchar(i8) #0
define void @_start() {
entry:
; initialization
%mem = alloca [30000 x i8]
%idx = alloca i32
%0 = bitcast [30000 x i8]* %mem to i8*
call void @llvm.memset.p0i8.i32(i8* %0, i8 0, i32 30000, i32 0, i1 false)
store i32 0, i32* %idx
; command: +
%1 = load i32* %idx
%2 = getelementptr inbounds [30000 x i8]* %mem, i32 0, i32 %1
%3 = load i8* %2
%4 = add i8 %3, 1
%5 = load i32* %idx
%6 = getelementptr inbounds [30000 x i8]* %mem, i32 0, i32 %5
store i8 %4, i8* %6
; command: +
%7 = load i32* %idx
%8 = getelementptr inbounds [30000 x i8]* %mem, i32 0, i32 %7
%9 = load i8* %8
%10 = add i8 %9, 1
%11 = load i32* %idx
%12 = getelementptr inbounds [30000 x i8]* %mem, i32 0, i32 %11
store i8 %10, i8* %12
...
; command: .
%433 = load i32* %idx
%434 = getelementptr inbounds [30000 x i8]* %mem, i32 0, i32 %433
%435 = load i8* %434
%436 = call i32 @putchar(i8 %435)
...
call void @exit(i32 0)
ret void
}
declare void @exit(i32)
The LLVM optimization engine is able to completely optimize away array accesses
using constant propagation/folding. In the absence of loops, this effectively
evaluates the whole program at compile time:
$ ./text.py Hello World! | ./bf | opt -O3 -S
...
define void @_start() {
entry:
%0 = tail call i32 @putchar(i8 72)
...
...
@@ -88,6 +128,3 @@ The LLVM optimization engine is able to completely optimize away array accesses
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