blob: 805eeaf40d71a1d8055d20b296e6a95c025cf84c [file] [log] [blame]
Alexey Bataev9959db52014-05-06 10:08:46 +00001//===--- CGStmtOpenMP.cpp - Emit LLVM Code from Statements ----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This contains code to emit OpenMP nodes as LLVM code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CGOpenMPRuntime.h"
15#include "CodeGenFunction.h"
16#include "CodeGenModule.h"
17#include "clang/AST/Stmt.h"
18#include "clang/AST/StmtOpenMP.h"
19using namespace clang;
20using namespace CodeGen;
21
22//===----------------------------------------------------------------------===//
23// OpenMP Directive Emission
24//===----------------------------------------------------------------------===//
25
26void CodeGenFunction::EmitOMPParallelDirective(const OMPParallelDirective &S) {
27 const CapturedStmt *CS = cast<CapturedStmt>(S.getAssociatedStmt());
28 llvm::Value *CapturedStruct = GenerateCapturedStmtArgument(*CS);
29
30 llvm::Value *OutlinedFn;
31 {
32 CodeGenFunction CGF(CGM, true);
33 CGCapturedStmtInfo CGInfo(*CS, CS->getCapturedRegionKind());
34 CGF.CapturedStmtInfo = &CGInfo;
35 OutlinedFn = CGF.GenerateCapturedStmtFunction(
36 CS->getCapturedDecl(), CS->getCapturedRecordDecl(), CS->getLocStart());
37 }
38
39 // Build call __kmpc_fork_call(loc, 1, microtask, captured_struct/*context*/)
40 llvm::Value *Args[] = {
Alexey Bataev23b69422014-06-18 07:08:49 +000041 CGM.getOpenMPRuntime().EmitOpenMPUpdateLocation(*this, S.getLocStart()),
42 Builder.getInt32(1), // Number of arguments after 'microtask' argument
43 // (there is only one additional argument - 'context')
44 Builder.CreateBitCast(OutlinedFn,
45 CGM.getOpenMPRuntime().getKmpc_MicroPointerTy()),
46 EmitCastToVoidPtr(CapturedStruct)};
Alexey Bataev9959db52014-05-06 10:08:46 +000047 llvm::Constant *RTLFn = CGM.getOpenMPRuntime().CreateRuntimeFunction(
48 CGOpenMPRuntime::OMPRTL__kmpc_fork_call);
49 EmitRuntimeCall(RTLFn, Args);
50}
Alexander Musman515ad8c2014-05-22 08:54:05 +000051
52void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) {
53 const CapturedStmt *CS = cast<CapturedStmt>(S.getAssociatedStmt());
54 const Stmt *Body = CS->getCapturedStmt();
55 LoopStack.setParallel();
56 LoopStack.setVectorizerEnable(true);
57 for (auto C : S.clauses()) {
58 switch (C->getClauseKind()) {
59 case OMPC_safelen: {
60 RValue Len = EmitAnyExpr(cast<OMPSafelenClause>(C)->getSafelen(),
61 AggValueSlot::ignored(), true);
62 llvm::ConstantInt *Val = cast<llvm::ConstantInt>(Len.getScalarVal());
63 LoopStack.setVectorizerWidth(Val->getZExtValue());
64 // In presence of finite 'safelen', it may be unsafe to mark all
65 // the memory instructions parallel, because loop-carried
66 // dependences of 'safelen' iterations are possible.
67 LoopStack.setParallel(false);
68 break;
69 }
70 default:
71 // Not handled yet
72 ;
73 }
74 }
75 EmitStmt(Body);
76}
77
Alexey Bataevf29276e2014-06-18 04:14:57 +000078void CodeGenFunction::EmitOMPForDirective(const OMPForDirective &) {
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000079 llvm_unreachable("CodeGen for 'omp for' is not supported yet.");
Alexey Bataevf29276e2014-06-18 04:14:57 +000080}
Alexey Bataevd3f8dd22014-06-25 11:44:49 +000081
82void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &) {
83 llvm_unreachable("CodeGen for 'omp sections' is not supported yet.");
84}
85
Alexey Bataev1e0498a2014-06-26 08:21:58 +000086void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &) {
87 llvm_unreachable("CodeGen for 'omp section' is not supported yet.");
88}
89
Alexey Bataevd1e40fb2014-06-26 12:05:45 +000090void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &) {
91 llvm_unreachable("CodeGen for 'omp single' is not supported yet.");
92}
93