Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1 | //===--- 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" |
| 19 | using namespace clang; |
| 20 | using namespace CodeGen; |
| 21 | |
| 22 | //===----------------------------------------------------------------------===// |
| 23 | // OpenMP Directive Emission |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | |
| 26 | void 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; |
Alexey Bataev | aca7fcf | 2014-06-30 02:55:54 +0000 | [diff] [blame] | 35 | OutlinedFn = CGF.GenerateCapturedStmtFunction(*CS); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | // Build call __kmpc_fork_call(loc, 1, microtask, captured_struct/*context*/) |
| 39 | llvm::Value *Args[] = { |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 40 | CGM.getOpenMPRuntime().EmitOpenMPUpdateLocation(*this, S.getLocStart()), |
| 41 | Builder.getInt32(1), // Number of arguments after 'microtask' argument |
| 42 | // (there is only one additional argument - 'context') |
| 43 | Builder.CreateBitCast(OutlinedFn, |
| 44 | CGM.getOpenMPRuntime().getKmpc_MicroPointerTy()), |
| 45 | EmitCastToVoidPtr(CapturedStruct)}; |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 46 | llvm::Constant *RTLFn = CGM.getOpenMPRuntime().CreateRuntimeFunction( |
| 47 | CGOpenMPRuntime::OMPRTL__kmpc_fork_call); |
| 48 | EmitRuntimeCall(RTLFn, Args); |
| 49 | } |
Alexander Musman | 515ad8c | 2014-05-22 08:54:05 +0000 | [diff] [blame] | 50 | |
| 51 | void CodeGenFunction::EmitOMPSimdDirective(const OMPSimdDirective &S) { |
| 52 | const CapturedStmt *CS = cast<CapturedStmt>(S.getAssociatedStmt()); |
| 53 | const Stmt *Body = CS->getCapturedStmt(); |
| 54 | LoopStack.setParallel(); |
| 55 | LoopStack.setVectorizerEnable(true); |
| 56 | for (auto C : S.clauses()) { |
| 57 | switch (C->getClauseKind()) { |
| 58 | case OMPC_safelen: { |
| 59 | RValue Len = EmitAnyExpr(cast<OMPSafelenClause>(C)->getSafelen(), |
| 60 | AggValueSlot::ignored(), true); |
| 61 | llvm::ConstantInt *Val = cast<llvm::ConstantInt>(Len.getScalarVal()); |
| 62 | LoopStack.setVectorizerWidth(Val->getZExtValue()); |
| 63 | // In presence of finite 'safelen', it may be unsafe to mark all |
| 64 | // the memory instructions parallel, because loop-carried |
| 65 | // dependences of 'safelen' iterations are possible. |
| 66 | LoopStack.setParallel(false); |
| 67 | break; |
| 68 | } |
| 69 | default: |
| 70 | // Not handled yet |
| 71 | ; |
| 72 | } |
| 73 | } |
| 74 | EmitStmt(Body); |
| 75 | } |
| 76 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 77 | void CodeGenFunction::EmitOMPForDirective(const OMPForDirective &) { |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 78 | llvm_unreachable("CodeGen for 'omp for' is not supported yet."); |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 79 | } |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 80 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 81 | void CodeGenFunction::EmitOMPForSimdDirective(const OMPForSimdDirective &) { |
| 82 | llvm_unreachable("CodeGen for 'omp for simd' is not supported yet."); |
| 83 | } |
| 84 | |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 85 | void CodeGenFunction::EmitOMPSectionsDirective(const OMPSectionsDirective &) { |
| 86 | llvm_unreachable("CodeGen for 'omp sections' is not supported yet."); |
| 87 | } |
| 88 | |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 89 | void CodeGenFunction::EmitOMPSectionDirective(const OMPSectionDirective &) { |
| 90 | llvm_unreachable("CodeGen for 'omp section' is not supported yet."); |
| 91 | } |
| 92 | |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 93 | void CodeGenFunction::EmitOMPSingleDirective(const OMPSingleDirective &) { |
| 94 | llvm_unreachable("CodeGen for 'omp single' is not supported yet."); |
| 95 | } |
| 96 | |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 97 | void CodeGenFunction::EmitOMPMasterDirective(const OMPMasterDirective &) { |
| 98 | llvm_unreachable("CodeGen for 'omp master' is not supported yet."); |
| 99 | } |
| 100 | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 101 | void CodeGenFunction::EmitOMPCriticalDirective(const OMPCriticalDirective &) { |
| 102 | llvm_unreachable("CodeGen for 'omp critical' is not supported yet."); |
| 103 | } |
| 104 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 105 | void |
| 106 | CodeGenFunction::EmitOMPParallelForDirective(const OMPParallelForDirective &) { |
| 107 | llvm_unreachable("CodeGen for 'omp parallel for' is not supported yet."); |
| 108 | } |
| 109 | |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 110 | void CodeGenFunction::EmitOMPParallelSectionsDirective( |
| 111 | const OMPParallelSectionsDirective &) { |
| 112 | llvm_unreachable("CodeGen for 'omp parallel sections' is not supported yet."); |
| 113 | } |
| 114 | |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 115 | void CodeGenFunction::EmitOMPTaskDirective(const OMPTaskDirective &) { |
| 116 | llvm_unreachable("CodeGen for 'omp task' is not supported yet."); |
| 117 | } |
| 118 | |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 119 | void CodeGenFunction::EmitOMPTaskyieldDirective(const OMPTaskyieldDirective &) { |
| 120 | llvm_unreachable("CodeGen for 'omp taskyield' is not supported yet."); |
| 121 | } |
| 122 | |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 123 | void CodeGenFunction::EmitOMPBarrierDirective(const OMPBarrierDirective &) { |
| 124 | llvm_unreachable("CodeGen for 'omp barrier' is not supported yet."); |
| 125 | } |
| 126 | |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 127 | void CodeGenFunction::EmitOMPTaskwaitDirective(const OMPTaskwaitDirective &) { |
| 128 | llvm_unreachable("CodeGen for 'omp taskwait' is not supported yet."); |
| 129 | } |
| 130 | |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 131 | void CodeGenFunction::EmitOMPFlushDirective(const OMPFlushDirective &) { |
| 132 | llvm_unreachable("CodeGen for 'omp flush' is not supported yet."); |
| 133 | } |
| 134 | |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 135 | void CodeGenFunction::EmitOMPOrderedDirective(const OMPOrderedDirective &) { |
| 136 | llvm_unreachable("CodeGen for 'omp ordered' is not supported yet."); |
| 137 | } |
| 138 | |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 139 | void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective &) { |
| 140 | llvm_unreachable("CodeGen for 'omp atomic' is not supported yet."); |
| 141 | } |
| 142 | |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame^] | 143 | void CodeGenFunction::EmitOMPTargetDirective(const OMPTargetDirective &) { |
| 144 | llvm_unreachable("CodeGen for 'omp target' is not supported yet."); |
| 145 | } |
| 146 | |