diff options
author | Tanya Lattner <tonic@nondot.org> | 2012-07-11 23:02:10 +0000 |
---|---|---|
committer | Tanya Lattner <tonic@nondot.org> | 2012-07-11 23:02:10 +0000 |
commit | 7445ada9c8b9d3f2a72d137be229dcdeac954f61 (patch) | |
tree | efd921098c51b299d2db0426cdbf2e6c47a223d6 /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | 9690a41e185166b3186d0accd3c223edc61fe371 (diff) | |
download | bcm5719-llvm-7445ada9c8b9d3f2a72d137be229dcdeac954f61.tar.gz bcm5719-llvm-7445ada9c8b9d3f2a72d137be229dcdeac954f61.zip |
Add OpenCL metadata for kernel arg names. This output is controlled via a flag as noted in the OpenCL Spec.
Includes a test case.
llvm-svn: 160092
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index c40b42193f9..954db7f8c05 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -252,6 +252,33 @@ void CodeGenFunction::EmitMCountInstrumentation() { Builder.CreateCall(MCountFn); } +// OpenCL v1.2 s5.6.4.6 allows the compiler to store kernel argument +// information in the program executable. The argument information stored +// includes the argument name, its type, the address and access qualifiers used. +// FIXME: Add type, address, and access qualifiers. +static void GenOpenCLArgMetadata(const FunctionDecl *FD, llvm::Function *Fn, + CodeGenModule &CGM,llvm::LLVMContext &Context, + llvm::SmallVector <llvm::Value*, 5> &kernelMDArgs) { + + // Create MDNodes that represents the kernel arg metadata. + // Each MDNode is a list in the form of "key", N number of values which is + // the same number of values as their are kernel arguments. + + // MDNode for the kernel argument names. + SmallVector<llvm::Value*, 8> argNames; + argNames.push_back(llvm::MDString::get(Context, "kernel_arg_name")); + + for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) { + const ParmVarDecl *parm = FD->getParamDecl(i); + + // Get argument name. + argNames.push_back(llvm::MDString::get(Context, parm->getName())); + + } + // Add MDNode to the list of all metadata. + kernelMDArgs.push_back(llvm::MDNode::get(Context, argNames)); +} + void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, llvm::Function *Fn) { @@ -263,6 +290,9 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD, llvm::SmallVector <llvm::Value*, 5> kernelMDArgs; kernelMDArgs.push_back(Fn); + if (CGM.getCodeGenOpts().EmitOpenCLArgMetadata) + GenOpenCLArgMetadata(FD, Fn, CGM, Context, kernelMDArgs); + if (FD->hasAttr<WorkGroupSizeHintAttr>()) { llvm::SmallVector <llvm::Value*, 5> attrMDArgs; attrMDArgs.push_back(llvm::MDString::get(Context, "work_group_size_hint")); |