Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Enable LLVM loop vectorizer #3929

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Config/llvm-config.h"
#ifdef DEBUG
#include "llvm/Support/CommandLine.h"
#endif
#include <setjmp.h>

#include <string>
Expand Down Expand Up @@ -105,6 +108,7 @@ static LLVMContext &jl_LLVMContext = getGlobalContext();
static IRBuilder<> builder(getGlobalContext());
static bool nested_compile=false;
static Module *jl_Module;
static TargetMachine *jl_TargetMachine;
static ExecutionEngine *jl_ExecutionEngine;
static DIBuilder *dbuilder;
static std::map<int, std::string> argNumberStrings;
Expand Down Expand Up @@ -3088,11 +3092,12 @@ static void init_julia_llvm_env(Module *m)
T_void = Type::getVoidTy(jl_LLVMContext);

// add needed base definitions to our LLVM environment
StructType *valueSt = StructType::create(getGlobalContext(), "jl_value_t");
/*StructType *valueSt = StructType::create(getGlobalContext(), "jl_value_t");
Type *valueStructElts[1] = { PointerType::getUnqual(valueSt) };
ArrayRef<Type*> vselts(valueStructElts);
valueSt->setBody(vselts);
jl_value_llvmt = valueSt;
jl_value_llvmt = valueSt;*/
jl_value_llvmt = PointerType::getUnqual(T_int8);

jl_pvalue_llvmt = PointerType::get(jl_value_llvmt, 0);
jl_ppvalue_llvmt = PointerType::get(jl_pvalue_llvmt, 0);
Expand Down Expand Up @@ -3340,9 +3345,13 @@ static void init_julia_llvm_env(Module *m)

// set up optimization passes
FPM = new FunctionPassManager(jl_Module);
#ifndef LLVM32
#ifdef LLVM32
FPM->add(new DataLayout(*jl_ExecutionEngine->getDataLayout()));
#else
FPM->add(new TargetData(*jl_ExecutionEngine->getTargetData()));
#endif
jl_TargetMachine->addAnalysisPasses(*FPM);

// list of passes from vmkit
FPM->add(createCFGSimplificationPass()); // Clean up disgusting code
FPM->add(createPromoteMemoryToRegisterPass());// Kill useless allocas
Expand Down Expand Up @@ -3372,6 +3381,7 @@ static void init_julia_llvm_env(Module *m)
//FPM->add(createLoopDeletionPass()); // Delete dead loops
FPM->add(createLoopUnrollPass()); // Unroll small loops
//FPM->add(createLoopStrengthReducePass()); // (jwb added)
FPM->add(createLoopVectorizePass()); // Vectorize loops

FPM->add(createInstructionCombiningPass()); // Clean up after the unroller
FPM->add(createGVNPass()); // Remove redundancies
Expand All @@ -3394,7 +3404,9 @@ static void init_julia_llvm_env(Module *m)

extern "C" void jl_init_codegen(void)
{

#ifdef DEBUG
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
#endif
InitializeNativeTarget();
jl_Module = new Module("julia", jl_LLVMContext);

Expand Down Expand Up @@ -3423,10 +3435,11 @@ extern "C" void jl_init_codegen(void)
#ifdef __APPLE__
options.JITExceptionHandling = 1;
#endif
jl_ExecutionEngine = EngineBuilder(jl_Module)
.setEngineKind(EngineKind::JIT)
.setTargetOptions(options)
.create();
EngineBuilder eb(jl_Module);
eb.setEngineKind(EngineKind::JIT)
.setTargetOptions(options);
jl_TargetMachine = eb.selectTarget();
jl_ExecutionEngine = eb.create();
#endif // LLVM VERSION

dbuilder = new DIBuilder(*jl_Module);
Expand Down
2 changes: 1 addition & 1 deletion src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ static Value *emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs,
Value *typemin;
switch (f) {
HANDLE(neg_int,1) return builder.CreateSub(ConstantInt::get(t, 0), JL_INT(x));
HANDLE(add_int,2) return builder.CreateAdd(JL_INT(x), JL_INT(y));
HANDLE(add_int,2) return builder.CreateAdd(JL_INT(x), JL_INT(y), "", false, true);
HANDLE(sub_int,2) return builder.CreateSub(JL_INT(x), JL_INT(y));
HANDLE(mul_int,2) return builder.CreateMul(JL_INT(x), JL_INT(y));
HANDLE(sdiv_int,2)
Expand Down