add optimization transforms

generics
cosmonaut 2021-04-21 22:48:55 -07:00
parent c2b4cd4b4a
commit a75b7a0818
1 changed files with 19 additions and 0 deletions

View File

@ -5,6 +5,10 @@
#include <llvm-c/Core.h> #include <llvm-c/Core.h>
#include <llvm-c/Analysis.h> #include <llvm-c/Analysis.h>
#include <llvm-c/BitWriter.h> #include <llvm-c/BitWriter.h>
#include <llvm-c/Transforms/PassManagerBuilder.h>
#include <llvm-c/Transforms/InstCombine.h>
#include <llvm-c/Transforms/Scalar.h>
#include <llvm-c/Transforms/Utils.h>
#include "y.tab.h" #include "y.tab.h"
#include "ast.h" #include "ast.h"
@ -643,9 +647,24 @@ int main(int argc, char *argv[])
LLVMVerifyModule(module, LLVMAbortProcessAction, &error); LLVMVerifyModule(module, LLVMAbortProcessAction, &error);
LLVMDisposeMessage(error); LLVMDisposeMessage(error);
LLVMPassManagerRef passManager = LLVMCreatePassManager();
LLVMAddInstructionCombiningPass(passManager);
LLVMAddCFGSimplificationPass(passManager);
LLVMAddReassociatePass(passManager);
LLVMAddPromoteMemoryToRegisterPass(passManager);
LLVMPassManagerBuilderRef passManagerBuilder = LLVMPassManagerBuilderCreate();
LLVMPassManagerBuilderSetOptLevel(passManagerBuilder, 3);
LLVMPassManagerBuilderPopulateModulePassManager(passManagerBuilder, passManager);
LLVMRunPassManager(passManager, module);
if (LLVMWriteBitcodeToFile(module, "test.bc") != 0) { if (LLVMWriteBitcodeToFile(module, "test.bc") != 0) {
fprintf(stderr, "error writing bitcode to file\n"); fprintf(stderr, "error writing bitcode to file\n");
} }
LLVMPassManagerBuilderDispose(passManagerBuilder);
LLVMDisposePassManager(passManager);
LLVMDisposeModule(module);
return 0; return 0;
} }