Index: lib/CodeGen/TargetInfo.cpp =================================================================== --- lib/CodeGen/TargetInfo.cpp +++ lib/CodeGen/TargetInfo.cpp @@ -6836,6 +6836,8 @@ } +static void appendOCLVerMD (CodeGen::CodeGenModule &CGM); + void AMDGPUTargetCodeGenInfo::setTargetAttributes( const Decl *D, llvm::GlobalValue *GV, @@ -6857,6 +6859,8 @@ if (NumSGPR != 0) F->addFnAttr("amdgpu_num_sgpr", llvm::utostr(NumSGPR)); } + + appendOCLVerMD(M); } @@ -7530,6 +7534,13 @@ llvm::NamedMDNode *SPIRVerMD = M.getOrInsertNamedMetadata("opencl.spir.version"); SPIRVerMD->addOperand(llvm::MDNode::get(Ctx, SPIRVerElts)); + appendOCLVerMD(CGM); +} + +static void appendOCLVerMD (CodeGen::CodeGenModule &CGM) { + llvm::LLVMContext &Ctx = CGM.getModule().getContext(); + llvm::Type *Int32Ty = llvm::Type::getInt32Ty(Ctx); + llvm::Module &M = CGM.getModule(); // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the // opencl.ocl.version named metadata node. llvm::Metadata *OCLVerElts[] = { Index: test/CodeGenOpenCL/spir_version.cl =================================================================== --- test/CodeGenOpenCL/spir_version.cl +++ test/CodeGenOpenCL/spir_version.cl @@ -1,18 +1,31 @@ -// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CL10 -// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CL12 -// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CL20 -// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CL10 -// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CL12 -// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CL20 +// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SPIR-CL10 +// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CHECK-SPIR-CL12 +// RUN: %clang_cc1 %s -triple "spir-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL20 +// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-SPIR-CL10 +// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CHECK-SPIR-CL12 +// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-SPIR-CL20 + +// RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - | FileCheck %s --check-prefix=CHECK-AMDGCN-CL10 +// RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL1.2 | FileCheck %s --check-prefix=CHECK-AMDGCN-CL12 +// RUN: %clang_cc1 %s -triple "amdgcn--amdhsa" -emit-llvm -o - -cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-AMDGCN-CL20 + kernel void foo() {} -// CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]} -// CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]} -// CL10: [[SPIR]] = !{i32 2, i32 0} -// CL10: [[OCL]] = !{i32 1, i32 0} -// CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]} -// CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]} -// CL12: [[SPIR]] = !{i32 2, i32 0} -// CL12: [[OCL]] = !{i32 1, i32 2} -// CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]} -// CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]} -// CL20: [[SPIR]] = !{i32 2, i32 0} + +// CHECK-SPIR-CL10: !opencl.spir.version = !{[[SPIR:![0-9]+]]} +// CHECK-SPIR-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK-SPIR-CL10: [[SPIR]] = !{i32 2, i32 0} +// CHECK-SPIR-CL10: [[OCL]] = !{i32 1, i32 0} +// CHECK-SPIR-CL12: !opencl.spir.version = !{[[SPIR:![0-9]+]]} +// CHECK-SPIR-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK-SPIR-CL12: [[SPIR]] = !{i32 2, i32 0} +// CHECK-SPIR-CL12: [[OCL]] = !{i32 1, i32 2} +// CHECK-SPIR-CL20: !opencl.spir.version = !{[[SPIR:![0-9]+]]} +// CHECK-SPIR-CL20: !opencl.ocl.version = !{[[SPIR:![0-9]+]]} +// CHECK-SPIR-CL20: [[SPIR]] = !{i32 2, i32 0} + +// CHECK-AMDGCN-CL10: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK-AMDGCN-CL10: [[OCL]] = !{i32 1, i32 0} +// CHECK-AMDGCN-CL12: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK-AMDGCN-CL12: [[OCL]] = !{i32 1, i32 2} +// CHECK-AMDGCN-CL20: !opencl.ocl.version = !{[[OCL:![0-9]+]]} +// CHECK-AMDGCN-CL20: [[OCL]] = !{i32 2, i32 0} \ No newline at end of file