Skip to content

Commit c268488

Browse files
committed
Merge 97965 from mainline.
Update the OCaml Kaleidoscope tutorial. llvm-svn: 98311
1 parent 859d416 commit c268488

File tree

5 files changed

+58
-65
lines changed

5 files changed

+58
-65
lines changed

llvm/docs/tutorial/OCamlLangImpl3.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
let the_module = create_module (global_context ()) "my cool jit"
9999
let builder = builder (global_context ())
100100
let named_values:(string, llvalue) Hashtbl.t = Hashtbl.create 10
101+
let double_type = double_type context
101102
</pre>
102103
</div>
103104

@@ -389,7 +390,7 @@
389390
<div class="doc_code">
390391
<pre>
391392
(* Create a new basic block to start insertion into. *)
392-
let bb = append_block "entry" the_function in
393+
let bb = append_block context "entry" the_function in
393394
position_at_end bb builder;
394395

395396
try
@@ -903,6 +904,7 @@
903904
let the_module = create_module context "my cool jit"
904905
let builder = builder context
905906
let named_values:(string, llvalue) Hashtbl.t = Hashtbl.create 10
907+
let double_type = double_type context
906908

907909
let rec codegen_expr = function
908910
| Ast.Number n -&gt; const_float double_type n
@@ -974,7 +976,7 @@
974976
let the_function = codegen_proto proto in
975977

976978
(* Create a new basic block to start insertion into. *)
977-
let bb = append_block "entry" the_function in
979+
let bb = append_block context "entry" the_function in
978980
position_at_end bb builder;
979981

980982
try

llvm/docs/tutorial/OCamlLangImpl4.html

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,8 @@
186186
<div class="doc_code">
187187
<pre>
188188
(* Create the JIT. *)
189-
let the_module_provider = ModuleProvider.create Codegen.the_module in
190-
let the_execution_engine = ExecutionEngine.create the_module_provider in
191-
let the_fpm = PassManager.create_function the_module_provider in
189+
let the_execution_engine = ExecutionEngine.create Codegen.the_module in
190+
let the_fpm = PassManager.create_function Codegen.the_module in
192191

193192
(* Set up the optimizer pipeline. Start with registering info about how the
194193
* target lays out data structures. *)
@@ -213,18 +212,11 @@
213212
</pre>
214213
</div>
215214

216-
<p>This code defines two values, an <tt>Llvm.llmoduleprovider</tt> and a
217-
<tt>Llvm.PassManager.t</tt>. The former is basically a wrapper around our
218-
<tt>Llvm.llmodule</tt> that the <tt>Llvm.PassManager.t</tt> requires. It
219-
provides certain flexibility that we're not going to take advantage of here,
220-
so I won't dive into any details about it.</p>
221-
222215
<p>The meat of the matter here, is the definition of "<tt>the_fpm</tt>". It
223-
requires a pointer to the <tt>the_module</tt> (through the
224-
<tt>the_module_provider</tt>) to construct itself. Once it is set up, we use a
225-
series of "add" calls to add a bunch of LLVM passes. The first pass is
226-
basically boilerplate, it adds a pass so that later optimizations know how the
227-
data structures in the program are laid out. The
216+
requires a pointer to the <tt>the_module</tt> to construct itself. Once it is
217+
set up, we use a series of "add" calls to add a bunch of LLVM passes. The
218+
first pass is basically boilerplate, it adds a pass so that later optimizations
219+
know how the data structures in the program are laid out. The
228220
"<tt>the_execution_engine</tt>" variable is related to the JIT, which we will
229221
get to in the next section.</p>
230222

@@ -320,8 +312,7 @@
320312
let main () =
321313
...
322314
<b>(* Create the JIT. *)
323-
let the_module_provider = ModuleProvider.create Codegen.the_module in
324-
let the_execution_engine = ExecutionEngine.create the_module_provider in</b>
315+
let the_execution_engine = ExecutionEngine.create Codegen.the_module in</b>
325316
...
326317
</pre>
327318
</div>
@@ -351,7 +342,7 @@
351342
the_execution_engine in
352343

353344
print_string "Evaluated to ";
354-
print_float (GenericValue.as_float double_type result);
345+
print_float (GenericValue.as_float Codegen.double_type result);
355346
print_newline ();
356347
</pre>
357348
</div>
@@ -796,6 +787,7 @@
796787
let the_module = create_module context "my cool jit"
797788
let builder = builder context
798789
let named_values:(string, llvalue) Hashtbl.t = Hashtbl.create 10
790+
let double_type = double_type context
799791

800792
let rec codegen_expr = function
801793
| Ast.Number n -&gt; const_float double_type n
@@ -867,7 +859,7 @@
867859
let the_function = codegen_proto proto in
868860

869861
(* Create a new basic block to start insertion into. *)
870-
let bb = append_block "entry" the_function in
862+
let bb = append_block context "entry" the_function in
871863
position_at_end bb builder;
872864

873865
try
@@ -932,7 +924,7 @@
932924
the_execution_engine in
933925

934926
print_string "Evaluated to ";
935-
print_float (GenericValue.as_float double_type result);
927+
print_float (GenericValue.as_float Codegen.double_type result);
936928
print_newline ();
937929
with Stream.Error s | Codegen.Error s -&gt;
938930
(* Skip token for error recovery. *)
@@ -971,16 +963,15 @@
971963
let stream = Lexer.lex (Stream.of_channel stdin) in
972964

973965
(* Create the JIT. *)
974-
let the_module_provider = ModuleProvider.create Codegen.the_module in
975-
let the_execution_engine = ExecutionEngine.create the_module_provider in
976-
let the_fpm = PassManager.create_function the_module_provider in
966+
let the_execution_engine = ExecutionEngine.create Codegen.the_module in
967+
let the_fpm = PassManager.create_function Codegen.the_module in
977968

978969
(* Set up the optimizer pipeline. Start with registering info about how the
979970
* target lays out data structures. *)
980971
TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
981972

982973
(* Do simple "peephole" optimizations and bit-twiddling optzn. *)
983-
add_instruction_combining the_fpm;
974+
add_instruction_combination the_fpm;
984975

985976
(* reassociate expressions. *)
986977
add_reassociation the_fpm;

llvm/docs/tutorial/OCamlLangImpl5.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@
364364
let start_bb = insertion_block builder in
365365
let the_function = block_parent start_bb in
366366

367-
let then_bb = append_block "then" the_function in
367+
let then_bb = append_block context "then" the_function in
368368
position_at_end then_bb builder;
369369
</pre>
370370
</div>
@@ -417,7 +417,7 @@
417417
<div class="doc_code">
418418
<pre>
419419
(* Emit 'else' value. *)
420-
let else_bb = append_block "else" the_function in
420+
let else_bb = append_block context "else" the_function in
421421
position_at_end else_bb builder;
422422
let else_val = codegen_expr else_ in
423423

@@ -433,7 +433,7 @@
433433
<div class="doc_code">
434434
<pre>
435435
(* Emit merge block. *)
436-
let merge_bb = append_block "ifcont" the_function in
436+
let merge_bb = append_block context "ifcont" the_function in
437437
position_at_end merge_bb builder;
438438
let incoming = [(then_val, new_then_bb); (else_val, new_else_bb)] in
439439
let phi = build_phi incoming "iftmp" builder in
@@ -704,7 +704,7 @@
704704
* block. *)
705705
let preheader_bb = insertion_block builder in
706706
let the_function = block_parent preheader_bb in
707-
let loop_bb = append_block "loop" the_function in
707+
let loop_bb = append_block context "loop" the_function in
708708

709709
(* Insert an explicit fall through from the current block to the
710710
* loop_bb. *)
@@ -804,7 +804,7 @@
804804
<pre>
805805
(* Create the "after loop" block and insert it. *)
806806
let loop_end_bb = insertion_block builder in
807-
let after_bb = append_block "afterloop" the_function in
807+
let after_bb = append_block context "afterloop" the_function in
808808

809809
(* Insert the conditional branch into the end of loop_end_bb. *)
810810
ignore (build_cond_br end_cond loop_bb after_bb builder);
@@ -1204,6 +1204,7 @@
12041204
let the_module = create_module context "my cool jit"
12051205
let builder = builder context
12061206
let named_values:(string, llvalue) Hashtbl.t = Hashtbl.create 10
1207+
let double_type = double_type context
12071208

12081209
let rec codegen_expr = function
12091210
| Ast.Number n -&gt; const_float double_type n
@@ -1250,7 +1251,7 @@
12501251
let start_bb = insertion_block builder in
12511252
let the_function = block_parent start_bb in
12521253

1253-
let then_bb = append_block "then" the_function in
1254+
let then_bb = append_block context "then" the_function in
12541255

12551256
(* Emit 'then' value. *)
12561257
position_at_end then_bb builder;
@@ -1262,7 +1263,7 @@
12621263
let new_then_bb = insertion_block builder in
12631264

12641265
(* Emit 'else' value. *)
1265-
let else_bb = append_block "else" the_function in
1266+
let else_bb = append_block context "else" the_function in
12661267
position_at_end else_bb builder;
12671268
let else_val = codegen_expr else_ in
12681269

@@ -1271,7 +1272,7 @@
12711272
let new_else_bb = insertion_block builder in
12721273

12731274
(* Emit merge block. *)
1274-
let merge_bb = append_block "ifcont" the_function in
1275+
let merge_bb = append_block context "ifcont" the_function in
12751276
position_at_end merge_bb builder;
12761277
let incoming = [(then_val, new_then_bb); (else_val, new_else_bb)] in
12771278
let phi = build_phi incoming "iftmp" builder in
@@ -1297,7 +1298,7 @@
12971298
* block. *)
12981299
let preheader_bb = insertion_block builder in
12991300
let the_function = block_parent preheader_bb in
1300-
let loop_bb = append_block "loop" the_function in
1301+
let loop_bb = append_block context "loop" the_function in
13011302

13021303
(* Insert an explicit fall through from the current block to the
13031304
* loop_bb. *)
@@ -1341,7 +1342,7 @@
13411342

13421343
(* Create the "after loop" block and insert it. *)
13431344
let loop_end_bb = insertion_block builder in
1344-
let after_bb = append_block "afterloop" the_function in
1345+
let after_bb = append_block context "afterloop" the_function in
13451346

13461347
(* Insert the conditional branch into the end of loop_end_bb. *)
13471348
ignore (build_cond_br end_cond loop_bb after_bb builder);
@@ -1397,7 +1398,7 @@
13971398
let the_function = codegen_proto proto in
13981399

13991400
(* Create a new basic block to start insertion into. *)
1400-
let bb = append_block "entry" the_function in
1401+
let bb = append_block context "entry" the_function in
14011402
position_at_end bb builder;
14021403

14031404
try
@@ -1462,7 +1463,7 @@
14621463
the_execution_engine in
14631464

14641465
print_string "Evaluated to ";
1465-
print_float (GenericValue.as_float double_type result);
1466+
print_float (GenericValue.as_float Codegen.double_type result);
14661467
print_newline ();
14671468
with Stream.Error s | Codegen.Error s -&gt;
14681469
(* Skip token for error recovery. *)
@@ -1501,16 +1502,15 @@
15011502
let stream = Lexer.lex (Stream.of_channel stdin) in
15021503

15031504
(* Create the JIT. *)
1504-
let the_module_provider = ModuleProvider.create Codegen.the_module in
1505-
let the_execution_engine = ExecutionEngine.create the_module_provider in
1506-
let the_fpm = PassManager.create_function the_module_provider in
1505+
let the_execution_engine = ExecutionEngine.create Codegen.the_module in
1506+
let the_fpm = PassManager.create_function Codegen.the_module in
15071507

15081508
(* Set up the optimizer pipeline. Start with registering info about how the
15091509
* target lays out data structures. *)
15101510
TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
15111511

15121512
(* Do simple "peephole" optimizations and bit-twiddling optzn. *)
1513-
add_instruction_combining the_fpm;
1513+
add_instruction_combination the_fpm;
15141514

15151515
(* reassociate expressions. *)
15161516
add_reassociation the_fpm;

llvm/docs/tutorial/OCamlLangImpl6.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@
300300
end;</b>
301301

302302
(* Create a new basic block to start insertion into. *)
303-
let bb = append_block "entry" the_function in
303+
let bb = append_block context "entry" the_function in
304304
position_at_end bb builder;
305305
...
306306
</pre>
@@ -1177,6 +1177,7 @@
11771177
let the_module = create_module context "my cool jit"
11781178
let builder = builder context
11791179
let named_values:(string, llvalue) Hashtbl.t = Hashtbl.create 10
1180+
let double_type = double_type context
11801181

11811182
let rec codegen_expr = function
11821183
| Ast.Number n -&gt; const_float double_type n
@@ -1241,7 +1242,7 @@
12411242
let start_bb = insertion_block builder in
12421243
let the_function = block_parent start_bb in
12431244

1244-
let then_bb = append_block "then" the_function in
1245+
let then_bb = append_block context "then" the_function in
12451246

12461247
(* Emit 'then' value. *)
12471248
position_at_end then_bb builder;
@@ -1253,7 +1254,7 @@
12531254
let new_then_bb = insertion_block builder in
12541255

12551256
(* Emit 'else' value. *)
1256-
let else_bb = append_block "else" the_function in
1257+
let else_bb = append_block context "else" the_function in
12571258
position_at_end else_bb builder;
12581259
let else_val = codegen_expr else_ in
12591260

@@ -1262,7 +1263,7 @@
12621263
let new_else_bb = insertion_block builder in
12631264

12641265
(* Emit merge block. *)
1265-
let merge_bb = append_block "ifcont" the_function in
1266+
let merge_bb = append_block context "ifcont" the_function in
12661267
position_at_end merge_bb builder;
12671268
let incoming = [(then_val, new_then_bb); (else_val, new_else_bb)] in
12681269
let phi = build_phi incoming "iftmp" builder in
@@ -1288,7 +1289,7 @@
12881289
* block. *)
12891290
let preheader_bb = insertion_block builder in
12901291
let the_function = block_parent preheader_bb in
1291-
let loop_bb = append_block "loop" the_function in
1292+
let loop_bb = append_block context "loop" the_function in
12921293

12931294
(* Insert an explicit fall through from the current block to the
12941295
* loop_bb. *)
@@ -1332,7 +1333,7 @@
13321333

13331334
(* Create the "after loop" block and insert it. *)
13341335
let loop_end_bb = insertion_block builder in
1335-
let after_bb = append_block "afterloop" the_function in
1336+
let after_bb = append_block context "afterloop" the_function in
13361337

13371338
(* Insert the conditional branch into the end of loop_end_bb. *)
13381339
ignore (build_cond_br end_cond loop_bb after_bb builder);
@@ -1396,7 +1397,7 @@
13961397
end;
13971398

13981399
(* Create a new basic block to start insertion into. *)
1399-
let bb = append_block "entry" the_function in
1400+
let bb = append_block context "entry" the_function in
14001401
position_at_end bb builder;
14011402

14021403
try
@@ -1461,7 +1462,7 @@
14611462
the_execution_engine in
14621463

14631464
print_string "Evaluated to ";
1464-
print_float (GenericValue.as_float double_type result);
1465+
print_float (GenericValue.as_float Codegen.double_type result);
14651466
print_newline ();
14661467
with Stream.Error s | Codegen.Error s -&gt;
14671468
(* Skip token for error recovery. *)
@@ -1500,16 +1501,15 @@
15001501
let stream = Lexer.lex (Stream.of_channel stdin) in
15011502

15021503
(* Create the JIT. *)
1503-
let the_module_provider = ModuleProvider.create Codegen.the_module in
1504-
let the_execution_engine = ExecutionEngine.create the_module_provider in
1505-
let the_fpm = PassManager.create_function the_module_provider in
1504+
let the_execution_engine = ExecutionEngine.create Codegen.the_module in
1505+
let the_fpm = PassManager.create_function Codegen.the_module in
15061506

15071507
(* Set up the optimizer pipeline. Start with registering info about how the
15081508
* target lays out data structures. *)
15091509
TargetData.add (ExecutionEngine.target_data the_execution_engine) the_fpm;
15101510

15111511
(* Do simple "peephole" optimizations and bit-twiddling optzn. *)
1512-
add_instruction_combining the_fpm;
1512+
add_instruction_combination the_fpm;
15131513

15141514
(* reassociate expressions. *)
15151515
add_reassociation the_fpm;

0 commit comments

Comments
 (0)