1
1
#include " ../include/KaleidoscopeJIT.h"
2
2
#include " llvm/ADT/APFloat.h"
3
3
#include " llvm/ADT/STLExtras.h"
4
- #include " llvm/Analysis/AssumptionCache.h"
5
- #include " llvm/Analysis/BasicAliasAnalysis.h"
6
- #include " llvm/Analysis/MemoryDependenceAnalysis.h"
7
- #include " llvm/Analysis/MemorySSA.h"
8
- #include " llvm/Analysis/OptimizationRemarkEmitter.h"
9
- #include " llvm/Analysis/ProfileSummaryInfo.h"
10
- #include " llvm/Analysis/TargetTransformInfo.h"
11
4
#include " llvm/IR/BasicBlock.h"
12
5
#include " llvm/IR/Constants.h"
13
6
#include " llvm/IR/DerivedTypes.h"
14
7
#include " llvm/IR/Function.h"
15
8
#include " llvm/IR/IRBuilder.h"
16
9
#include " llvm/IR/LLVMContext.h"
10
+ #include " llvm/IR/LegacyPassManager.h"
17
11
#include " llvm/IR/Module.h"
18
- #include " llvm/IR/PassManager.h"
19
12
#include " llvm/IR/Type.h"
20
13
#include " llvm/IR/Verifier.h"
21
- #include " llvm/Passes/PassBuilder.h"
22
- #include " llvm/Passes/StandardInstrumentations.h"
23
14
#include " llvm/Support/TargetSelect.h"
24
15
#include " llvm/Target/TargetMachine.h"
25
16
#include " llvm/Transforms/InstCombine/InstCombine.h"
26
17
#include " llvm/Transforms/Scalar.h"
27
18
#include " llvm/Transforms/Scalar/GVN.h"
28
- #include " llvm/Transforms/Scalar/Reassociate.h"
29
- #include " llvm/Transforms/Scalar/SimplifyCFG.h"
30
19
#include < algorithm>
31
20
#include < cassert>
32
21
#include < cctype>
@@ -424,12 +413,8 @@ static std::unique_ptr<LLVMContext> TheContext;
424
413
static std::unique_ptr<Module> TheModule;
425
414
static std::unique_ptr<IRBuilder<>> Builder;
426
415
static std::map<std::string, Value *> NamedValues;
416
+ static std::unique_ptr<legacy::FunctionPassManager> TheFPM;
427
417
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
428
- static std::unique_ptr<FunctionPassManager> TheFPM;
429
- static std::unique_ptr<FunctionAnalysisManager> TheFAM;
430
- static std::unique_ptr<ModuleAnalysisManager> TheMAM;
431
- static std::unique_ptr<PassInstrumentationCallbacks> ThePIC;
432
- static std::unique_ptr<StandardInstrumentations> TheSI;
433
418
static std::map<std::string, std::unique_ptr<PrototypeAST>> FunctionProtos;
434
419
static ExitOnError ExitOnErr;
435
420
@@ -550,7 +535,7 @@ Function *FunctionAST::codegen() {
550
535
verifyFunction (*TheFunction);
551
536
552
537
// Run the optimizer on the function.
553
- TheFPM->run (*TheFunction, *TheFAM );
538
+ TheFPM->run (*TheFunction);
554
539
555
540
return TheFunction;
556
541
}
@@ -564,51 +549,28 @@ Function *FunctionAST::codegen() {
564
549
// Top-Level parsing and JIT Driver
565
550
// ===----------------------------------------------------------------------===//
566
551
567
- static void InitializeModuleAndManagers () {
552
+ static void InitializeModuleAndPassManager () {
568
553
// Open a new context and module.
569
554
TheContext = std::make_unique<LLVMContext>();
570
- TheModule = std::make_unique<Module>(" KaleidoscopeJIT " , *TheContext);
555
+ TheModule = std::make_unique<Module>(" my cool jit " , *TheContext);
571
556
TheModule->setDataLayout (TheJIT->getDataLayout ());
572
557
573
558
// Create a new builder for the module.
574
559
Builder = std::make_unique<IRBuilder<>>(*TheContext);
575
560
576
- // Create new pass and analysis managers.
577
- TheFPM = std::make_unique<FunctionPassManager>();
578
- TheFAM = std::make_unique<FunctionAnalysisManager>();
579
- TheMAM = std::make_unique<ModuleAnalysisManager>();
580
- ThePIC = std::make_unique<PassInstrumentationCallbacks>();
581
- TheSI = std::make_unique<StandardInstrumentations>(*TheContext,
582
- /* DebugLogging*/ true );
583
- TheSI->registerCallbacks (*ThePIC, TheMAM.get ());
561
+ // Create a new pass manager attached to it.
562
+ TheFPM = std::make_unique<legacy::FunctionPassManager>(TheModule.get ());
584
563
585
- // Add transform passes.
586
564
// Do simple "peephole" optimizations and bit-twiddling optzns.
587
- TheFPM->addPass ( InstCombinePass ());
565
+ TheFPM->add ( createInstructionCombiningPass ());
588
566
// Reassociate expressions.
589
- TheFPM->addPass ( ReassociatePass ());
567
+ TheFPM->add ( createReassociatePass ());
590
568
// Eliminate Common SubExpressions.
591
- TheFPM->addPass ( GVNPass ());
569
+ TheFPM->add ( createGVNPass ());
592
570
// Simplify the control flow graph (deleting unreachable blocks, etc).
593
- TheFPM->addPass (SimplifyCFGPass ());
594
-
595
- // Register analysis passes used in these transform passes.
596
- TheFAM->registerPass ([&] { return AAManager (); });
597
- TheFAM->registerPass ([&] { return AssumptionAnalysis (); });
598
- TheFAM->registerPass ([&] { return DominatorTreeAnalysis (); });
599
- TheFAM->registerPass ([&] { return LoopAnalysis (); });
600
- TheFAM->registerPass ([&] { return MemoryDependenceAnalysis (); });
601
- TheFAM->registerPass ([&] { return MemorySSAAnalysis (); });
602
- TheFAM->registerPass ([&] { return OptimizationRemarkEmitterAnalysis (); });
603
- TheFAM->registerPass ([&] {
604
- return OuterAnalysisManagerProxy<ModuleAnalysisManager, Function>(*TheMAM);
605
- });
606
- TheFAM->registerPass (
607
- [&] { return PassInstrumentationAnalysis (ThePIC.get ()); });
608
- TheFAM->registerPass ([&] { return TargetIRAnalysis (); });
609
- TheFAM->registerPass ([&] { return TargetLibraryAnalysis (); });
610
-
611
- TheMAM->registerPass ([&] { return ProfileSummaryAnalysis (); });
571
+ TheFPM->add (createCFGSimplificationPass ());
572
+
573
+ TheFPM->doInitialization ();
612
574
}
613
575
614
576
static void HandleDefinition () {
@@ -619,7 +581,7 @@ static void HandleDefinition() {
619
581
fprintf (stderr, " \n " );
620
582
ExitOnErr (TheJIT->addModule (
621
583
ThreadSafeModule (std::move (TheModule), std::move (TheContext))));
622
- InitializeModuleAndManagers ();
584
+ InitializeModuleAndPassManager ();
623
585
}
624
586
} else {
625
587
// Skip token for error recovery.
@@ -651,7 +613,7 @@ static void HandleTopLevelExpression() {
651
613
652
614
auto TSM = ThreadSafeModule (std::move (TheModule), std::move (TheContext));
653
615
ExitOnErr (TheJIT->addModule (std::move (TSM), RT));
654
- InitializeModuleAndManagers ();
616
+ InitializeModuleAndPassManager ();
655
617
656
618
// Search the JIT for the __anon_expr symbol.
657
619
auto ExprSymbol = ExitOnErr (TheJIT->lookup (" __anon_expr" ));
@@ -737,7 +699,7 @@ int main() {
737
699
738
700
TheJIT = ExitOnErr (KaleidoscopeJIT::Create ());
739
701
740
- InitializeModuleAndManagers ();
702
+ InitializeModuleAndPassManager ();
741
703
742
704
// Run the main "interpreter loop" now.
743
705
MainLoop ();
0 commit comments