Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit e576a61

Browse files
committed
Initial parallel CPU
1 parent 17dbbcc commit e576a61

File tree

3 files changed

+17
-47
lines changed

3 files changed

+17
-47
lines changed

src/core/polyhedral/codegen_llvm.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/STLExtras.h"
2222
#include "llvm/ADT/SmallVector.h"
2323
#include "llvm/Analysis/TargetTransformInfo.h"
24+
#include "llvm/Config/llvm-config.h"
2425
#include "llvm/ExecutionEngine/ExecutionEngine.h"
2526
#include "llvm/IR/IRBuilder.h"
2627
#include "llvm/IR/LegacyPassManager.h"
@@ -42,6 +43,10 @@
4243
#include "tc/core/polyhedral/scop.h"
4344
#include "tc/core/scope_guard.h"
4445

46+
#ifndef LLVM_VERSION_MAJOR
47+
#error LLVM_VERSION_MAJOR not set
48+
#endif
49+
4550
using namespace Halide;
4651

4752
namespace tc {
@@ -303,8 +308,8 @@ class CodeGen_TC : public Halide::Internal::CodeGen_X86 {
303308
Halide::Internal::debug(3) << "Optimizing module\n";
304309

305310
if (Halide::Internal::debug::debug_level() >= 3) {
306-
#if LLVM_VERSION >= 50
307-
module->print(dbgs(), nullptr, false, true);
311+
#if LLVM_VERSION_MAJOR >= 5
312+
module->print(llvm::dbgs(), nullptr, false, true);
308313
#else
309314
module->dump();
310315
#endif
@@ -338,16 +343,16 @@ class CodeGen_TC : public Halide::Internal::CodeGen_X86 {
338343

339344
llvm::PassManagerBuilder b;
340345
b.OptLevel = 3;
341-
b.tapirTarget = new llvm::tapir::CilkABI();
342-
#if LLVM_VERSION >= 50
346+
b.tapirTarget = new llvm::CilkABI();
347+
#if LLVM_VERSION_MAJOR >= 5
343348
b.Inliner = llvm::createFunctionInliningPass(b.OptLevel, 0, false);
344349
#else
345350
b.Inliner = llvm::createFunctionInliningPass(b.OptLevel, 0);
346351
#endif
347352
b.LoopVectorize = true;
348353
b.SLPVectorize = true;
349354

350-
#if LLVM_VERSION >= 50
355+
#if LLVM_VERSION_MAJOR >= 5
351356
if (TM) {
352357
TM->adjustPassManager(b);
353358
}
@@ -366,8 +371,8 @@ class CodeGen_TC : public Halide::Internal::CodeGen_X86 {
366371

367372
Halide::Internal::debug(3) << "After LLVM optimizations:\n";
368373
if (Halide::Internal::debug::debug_level() >= 2) {
369-
#if LLVM_VERSION >= 50
370-
module->print(dbgs(), nullptr, false, true);
374+
#if LLVM_VERSION_MAJOR >= 5
375+
module->print(llvm::dbgs(), nullptr, false, true);
371376
#else
372377
module->dump();
373378
#endif
@@ -530,7 +535,8 @@ class LLVMCodegen {
530535
llvm::BasicBlock::Create(llvmCtx, "loop_latch", function);
531536
auto* loopExitBB = llvm::BasicBlock::Create(llvmCtx, "loop_exit", function);
532537

533-
bool parallel = true;
538+
//TODO: integrate query ISL as to whether the relevant loop ought be parallelized
539+
bool parallel = false;
534540

535541
llvm::Value* SyncRegion = nullptr;
536542
if (parallel) {

src/core/polyhedral/llvm_jit.cc

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Jit::Jit()
3737
objectLayer_([]() { return std::make_shared<SectionMemoryManager>(); }),
3838
compileLayer_(objectLayer_, orc::SimpleCompiler(*TM_)) {
3939
sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
40+
std::string err;
41+
sys::DynamicLibrary::LoadLibraryPermanently("cilkrts", &err);
4042
}
4143

4244
void Jit::codegenScop(
@@ -82,42 +84,4 @@ JITTargetAddress Jit::getSymbolAddress(const std::string Name) {
8284
return *res;
8385
}
8486

85-
DEFINE_bool(llvm_no_opt, false, "Disable LLVM optimizations");
86-
DEFINE_bool(llvm_debug_passes, false, "Print pass debug info");
87-
DEFINE_bool(llvm_dump_optimized_ir, false, "Print optimized IR");
88-
89-
std::shared_ptr<Module> Jit::optimizeModule(std::shared_ptr<Module> M) {
90-
if (FLAGS_llvm_no_opt) {
91-
return M;
92-
}
93-
94-
PassBuilder PB(TM_.get());
95-
AAManager AA;
96-
CHECK(PB.parseAAPipeline(AA, "default"))
97-
<< "Unable to parse AA pipeline description.";
98-
LoopAnalysisManager LAM(FLAGS_llvm_debug_passes);
99-
FunctionAnalysisManager FAM(FLAGS_llvm_debug_passes);
100-
CGSCCAnalysisManager CGAM(FLAGS_llvm_debug_passes);
101-
ModuleAnalysisManager MAM(FLAGS_llvm_debug_passes);
102-
FAM.registerPass([&] { return std::move(AA); });
103-
PB.registerModuleAnalyses(MAM);
104-
PB.registerCGSCCAnalyses(CGAM);
105-
PB.registerFunctionAnalyses(FAM);
106-
PB.registerLoopAnalyses(LAM);
107-
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
108-
109-
ModulePassManager MPM(FLAGS_llvm_debug_passes);
110-
MPM.addPass(VerifierPass());
111-
CHECK(PB.parsePassPipeline(MPM, "default<O3>", true, FLAGS_llvm_debug_passes))
112-
<< "Unable to parse pass pipline description.";
113-
MPM.addPass(VerifierPass());
114-
115-
MPM.run(*M, MAM);
116-
117-
if (FLAGS_llvm_dump_optimized_ir) {
118-
// M->dump(); // does not link
119-
M->print(llvm::errs(), nullptr);
120-
}
121-
122-
return M;
12387
}

test/test_mapper_llvm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ TEST(LLVMCodegen, MultiStmt) {
6868
{
6969
O1(i, j) +=! A(i, j, rk, rl) * B(i, j)
7070
O2(i, j) = C(i, j) * D(i, j)
71-
O3(i, j) = O1(i, j) + O2(i, j)
71+
O3(i, j) = O1(i, j) + O2(i, j)
7272
}
7373
)TC";
7474

0 commit comments

Comments
 (0)