Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
brainfucker
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
brainfucker
Commits
ddb09a9d
Commit
ddb09a9d
authored
Jan 08, 2015
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extended optimization example
parent
4ad2e109
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
11 deletions
+48
-11
README.md
README.md
+48
-11
No files found.
README.md
View file @
ddb09a9d
...
@@ -58,18 +58,58 @@ The `text.py` utility genrates single-cell Brainfuck code for a given text:
...
@@ -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
The compiler generates very verbose code:
(in the absence of loops):
$ ./text.py Hello World! | ./bf | opt -O3 -S
$ ./text.py Hello World! | ./bf
; ModuleID = '<stdin>'
...
target datalayout = "e"
; Function Attrs: nounwind
define void @_start() {
declare i32 @putchar(i8) #0
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() {
define void @_start() {
entry:
entry:
%0 = tail call i32 @putchar(i8 72)
%0 = tail call i32 @putchar(i8 72)
...
@@ -88,6 +128,3 @@ The LLVM optimization engine is able to completely optimize away array accesses
...
@@ -88,6 +128,3 @@ The LLVM optimization engine is able to completely optimize away array accesses
tail call void @exit(i32 0)
tail call void @exit(i32 0)
ret void
ret void
}
}
attributes #0 = { nounwind }
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment