Mercurial > hg > CbC > CbC_llvm
comparison clang/lib/CodeGen/CGOpenCLRuntime.cpp @ 252:1f2b6ac9f198 llvm-original
LLVM16-1
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 18 Aug 2023 09:04:13 +0900 |
parents | c4bab56944e8 |
children |
comparison
equal
deleted
inserted
replaced
237:c80f45b162ad | 252:1f2b6ac9f198 |
---|---|
29 const VarDecl &D) { | 29 const VarDecl &D) { |
30 return CGF.EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); | 30 return CGF.EmitStaticVarDecl(D, llvm::GlobalValue::InternalLinkage); |
31 } | 31 } |
32 | 32 |
33 llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { | 33 llvm::Type *CGOpenCLRuntime::convertOpenCLSpecificType(const Type *T) { |
34 assert(T->isOpenCLSpecificType() && | 34 assert(T->isOpenCLSpecificType() && "Not an OpenCL specific type!"); |
35 "Not an OpenCL specific type!"); | 35 |
36 // Check if the target has a specific translation for this type first. | |
37 if (llvm::Type *TransTy = CGM.getTargetCodeGenInfo().getOpenCLType(CGM, T)) | |
38 return TransTy; | |
36 | 39 |
37 switch (cast<BuiltinType>(T)->getKind()) { | 40 switch (cast<BuiltinType>(T)->getKind()) { |
38 default: | 41 default: |
39 llvm_unreachable("Unexpected opencl builtin type!"); | 42 llvm_unreachable("Unexpected opencl builtin type!"); |
40 return nullptr; | 43 return nullptr; |
73 CachedTys[Name] = PTy; | 76 CachedTys[Name] = PTy; |
74 return PTy; | 77 return PTy; |
75 } | 78 } |
76 | 79 |
77 llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { | 80 llvm::Type *CGOpenCLRuntime::getPipeType(const PipeType *T) { |
81 if (llvm::Type *PipeTy = CGM.getTargetCodeGenInfo().getOpenCLType(CGM, T)) | |
82 return PipeTy; | |
83 | |
78 if (T->isReadOnly()) | 84 if (T->isReadOnly()) |
79 return getPipeType(T, "opencl.pipe_ro_t", PipeROTy); | 85 return getPipeType(T, "opencl.pipe_ro_t", PipeROTy); |
80 else | 86 else |
81 return getPipeType(T, "opencl.pipe_wo_t", PipeWOTy); | 87 return getPipeType(T, "opencl.pipe_wo_t", PipeWOTy); |
82 } | 88 } |
89 CGM.getContext().getTargetAddressSpace( | 95 CGM.getContext().getTargetAddressSpace( |
90 CGM.getContext().getOpenCLTypeAddrSpace(T))); | 96 CGM.getContext().getOpenCLTypeAddrSpace(T))); |
91 return PipeTy; | 97 return PipeTy; |
92 } | 98 } |
93 | 99 |
94 llvm::PointerType *CGOpenCLRuntime::getSamplerType(const Type *T) { | 100 llvm::Type *CGOpenCLRuntime::getSamplerType(const Type *T) { |
95 if (!SamplerTy) | 101 if (SamplerTy) |
96 SamplerTy = llvm::PointerType::get(llvm::StructType::create( | 102 return SamplerTy; |
97 CGM.getLLVMContext(), "opencl.sampler_t"), | 103 |
98 CGM.getContext().getTargetAddressSpace( | 104 if (llvm::Type *TransTy = CGM.getTargetCodeGenInfo().getOpenCLType( |
99 CGM.getContext().getOpenCLTypeAddrSpace(T))); | 105 CGM, CGM.getContext().OCLSamplerTy.getTypePtr())) |
106 SamplerTy = TransTy; | |
107 else | |
108 SamplerTy = llvm::PointerType::get( | |
109 llvm::StructType::create(CGM.getLLVMContext(), "opencl.sampler_t"), | |
110 CGM.getContext().getTargetAddressSpace( | |
111 CGM.getContext().getOpenCLTypeAddrSpace(T))); | |
100 return SamplerTy; | 112 return SamplerTy; |
101 } | 113 } |
102 | 114 |
103 llvm::Value *CGOpenCLRuntime::getPipeElemSize(const Expr *PipeArg) { | 115 llvm::Value *CGOpenCLRuntime::getPipeElemSize(const Expr *PipeArg) { |
104 const PipeType *PipeTy = PipeArg->getType()->castAs<PipeType>(); | 116 const PipeType *PipeTy = PipeArg->getType()->castAs<PipeType>(); |
120 return llvm::ConstantInt::get(Int32Ty, TypeSize, false); | 132 return llvm::ConstantInt::get(Int32Ty, TypeSize, false); |
121 } | 133 } |
122 | 134 |
123 llvm::PointerType *CGOpenCLRuntime::getGenericVoidPointerType() { | 135 llvm::PointerType *CGOpenCLRuntime::getGenericVoidPointerType() { |
124 assert(CGM.getLangOpts().OpenCL); | 136 assert(CGM.getLangOpts().OpenCL); |
125 return llvm::IntegerType::getInt8PtrTy( | 137 return llvm::PointerType::get( |
126 CGM.getLLVMContext(), | 138 CGM.getLLVMContext(), |
127 CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic)); | 139 CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic)); |
128 } | 140 } |
129 | 141 |
130 // Get the block literal from an expression derived from the block expression. | 142 // Get the block literal from an expression derived from the block expression. |
147 /// Record emitted llvm invoke function and llvm block literal for the | 159 /// Record emitted llvm invoke function and llvm block literal for the |
148 /// corresponding block expression. | 160 /// corresponding block expression. |
149 void CGOpenCLRuntime::recordBlockInfo(const BlockExpr *E, | 161 void CGOpenCLRuntime::recordBlockInfo(const BlockExpr *E, |
150 llvm::Function *InvokeF, | 162 llvm::Function *InvokeF, |
151 llvm::Value *Block, llvm::Type *BlockTy) { | 163 llvm::Value *Block, llvm::Type *BlockTy) { |
152 assert(EnqueuedBlockMap.find(E) == EnqueuedBlockMap.end() && | 164 assert(!EnqueuedBlockMap.contains(E) && "Block expression emitted twice"); |
153 "Block expression emitted twice"); | |
154 assert(isa<llvm::Function>(InvokeF) && "Invalid invoke function"); | 165 assert(isa<llvm::Function>(InvokeF) && "Invalid invoke function"); |
155 assert(Block->getType()->isPointerTy() && "Invalid block literal type"); | 166 assert(Block->getType()->isPointerTy() && "Invalid block literal type"); |
156 EnqueuedBlockMap[E].InvokeFunc = InvokeF; | 167 EnqueuedBlockMap[E].InvokeFunc = InvokeF; |
157 EnqueuedBlockMap[E].BlockArg = Block; | 168 EnqueuedBlockMap[E].BlockArg = Block; |
158 EnqueuedBlockMap[E].BlockTy = BlockTy; | 169 EnqueuedBlockMap[E].BlockTy = BlockTy; |
159 EnqueuedBlockMap[E].Kernel = nullptr; | 170 EnqueuedBlockMap[E].KernelHandle = nullptr; |
160 } | 171 } |
161 | 172 |
162 llvm::Function *CGOpenCLRuntime::getInvokeFunction(const Expr *E) { | 173 llvm::Function *CGOpenCLRuntime::getInvokeFunction(const Expr *E) { |
163 return EnqueuedBlockMap[getBlockExpr(E)].InvokeFunc; | 174 return EnqueuedBlockMap[getBlockExpr(E)].InvokeFunc; |
164 } | 175 } |
169 | 180 |
170 // The block literal may be assigned to a const variable. Chasing down | 181 // The block literal may be assigned to a const variable. Chasing down |
171 // to get the block literal. | 182 // to get the block literal. |
172 const BlockExpr *Block = getBlockExpr(E); | 183 const BlockExpr *Block = getBlockExpr(E); |
173 | 184 |
174 assert(EnqueuedBlockMap.find(Block) != EnqueuedBlockMap.end() && | 185 assert(EnqueuedBlockMap.contains(Block) && "Block expression not emitted"); |
175 "Block expression not emitted"); | |
176 | 186 |
177 // Do not emit the block wrapper again if it has been emitted. | 187 // Do not emit the block wrapper again if it has been emitted. |
178 if (EnqueuedBlockMap[Block].Kernel) { | 188 if (EnqueuedBlockMap[Block].KernelHandle) { |
179 return EnqueuedBlockMap[Block]; | 189 return EnqueuedBlockMap[Block]; |
180 } | 190 } |
181 | 191 |
182 auto *F = CGF.getTargetHooks().createEnqueuedBlockKernel( | 192 auto *F = CGF.getTargetHooks().createEnqueuedBlockKernel( |
183 CGF, EnqueuedBlockMap[Block].InvokeFunc, EnqueuedBlockMap[Block].BlockTy); | 193 CGF, EnqueuedBlockMap[Block].InvokeFunc, EnqueuedBlockMap[Block].BlockTy); |
184 | 194 |
185 // The common part of the post-processing of the kernel goes here. | 195 // The common part of the post-processing of the kernel goes here. |
186 F->addFnAttr(llvm::Attribute::NoUnwind); | 196 EnqueuedBlockMap[Block].KernelHandle = F; |
187 F->setCallingConv( | |
188 CGF.getTypes().ClangCallConvToLLVMCallConv(CallingConv::CC_OpenCLKernel)); | |
189 EnqueuedBlockMap[Block].Kernel = F; | |
190 return EnqueuedBlockMap[Block]; | 197 return EnqueuedBlockMap[Block]; |
191 } | 198 } |