forked from cosmonaut/wraith-lang
add optimization transforms
parent
c2b4cd4b4a
commit
a75b7a0818
19
compiler.c
19
compiler.c
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue