Add option to limit the maximal number of parallel threads.

Differential Revision: http://reviews.llvm.org/D5581

llvm-svn: 219004
This commit is contained in:
Johannes Doerfert 2014-10-03 19:11:10 +00:00
parent 12b355a2ce
commit 990cd4c2e2
2 changed files with 43 additions and 1 deletions

View File

@ -18,10 +18,16 @@
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Module.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Support/CommandLine.h"
using namespace llvm;
using namespace polly;
static cl::opt<int>
PollyNumThreads("polly-num-threads",
cl::desc("Number of threads to use (0 = auto)"), cl::Hidden,
cl::init(0));
// We generate a loop of either of the following structures:
//
// BeforeBB BeforeBB
@ -185,7 +191,7 @@ void ParallelLoopGenerator::createCallSpawnThreads(Value *SubFn,
F = Function::Create(Ty, Linkage, Name, M);
}
Value *NumberOfThreads = ConstantInt::get(LongType, 0);
Value *NumberOfThreads = ConstantInt::get(LongType, PollyNumThreads);
Value *Args[] = {SubFn, SubFnParam, NumberOfThreads, LB, UB, Stride};
Builder.CreateCall(F, Args);

View File

@ -0,0 +1,36 @@
; RUN: opt %loadPolly -polly-codegen -enable-polly-openmp -S < %s | FileCheck %s --check-prefix=AUTO
; RUN: opt %loadPolly -polly-codegen -enable-polly-openmp -polly-num-threads=1 -S < %s | FileCheck %s --check-prefix=ONE
; RUN: opt %loadPolly -polly-codegen -enable-polly-openmp -polly-num-threads=4 -S < %s | FileCheck %s --check-prefix=FOUR
;
; AUTO: call void @GOMP_parallel_loop_runtime_start(void (i8*)* @jd.polly.subfn, i8* %polly.par.userContext{{[0-9]*}}, i64 0, i64 0, i64 1024, i64 1)
; ONE: call void @GOMP_parallel_loop_runtime_start(void (i8*)* @jd.polly.subfn, i8* %polly.par.userContext{{[0-9]*}}, i64 1, i64 0, i64 1024, i64 1)
; FOUR: call void @GOMP_parallel_loop_runtime_start(void (i8*)* @jd.polly.subfn, i8* %polly.par.userContext{{[0-9]*}}, i64 4, i64 0, i64 1024, i64 1)
;
; void jd(int *A) {
; for (int i = 0; i < 1024; i++)
; A[i] = 0;
; }
;
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
define void @jd(i32* %A) {
entry:
br label %for.cond
for.cond: ; preds = %for.inc, %entry
%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
%exitcond = icmp ne i64 %indvars.iv, 1024
br i1 %exitcond, label %for.body, label %for.end
for.body: ; preds = %for.cond
%arrayidx = getelementptr inbounds i32* %A, i64 %indvars.iv
store i32 0, i32* %arrayidx, align 4
br label %for.inc
for.inc: ; preds = %for.body
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
br label %for.cond
for.end: ; preds = %for.cond
ret void
}