| 1 | //===- CIRGenAMDGPU.cpp - AMDGPU-specific logic for CIR generation --------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This contains code dealing with AMDGPU-specific logic of CIR generation. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "CIRGenModule.h" |
| 14 | |
| 15 | #include "clang/Basic/TargetOptions.h" |
| 16 | #include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 17 | #include "llvm/TargetParser/Triple.h" |
| 18 | |
| 19 | using namespace clang; |
| 20 | using namespace clang::CIRGen; |
| 21 | |
| 22 | void CIRGenModule::emitAMDGPUMetadata() { |
| 23 | // Emit code object version module flag. |
| 24 | if (target.getTargetOpts().CodeObjectVersion != |
| 25 | llvm::CodeObjectVersionKind::COV_None) { |
| 26 | getModule()->setAttr( |
| 27 | name: cir::CIRDialect::getAMDGPUCodeObjectVersionAttrName(), |
| 28 | value: builder.getI32IntegerAttr(value: target.getTargetOpts().CodeObjectVersion)); |
| 29 | } |
| 30 | |
| 31 | // Emit printf kind module flag for HIP. |
| 32 | if (langOpts.HIP) { |
| 33 | llvm::StringRef printfKind = |
| 34 | target.getTargetOpts().AMDGPUPrintfKindVal == |
| 35 | TargetOptions::AMDGPUPrintfKind::Hostcall |
| 36 | ? "hostcall" |
| 37 | : "buffered"; |
| 38 | getModule()->setAttr(name: cir::CIRDialect::getAMDGPUPrintfKindAttrName(), |
| 39 | value: builder.getStringAttr(bytes: printfKind)); |
| 40 | } |
| 41 | |
| 42 | // Emit xnack module flag. |
| 43 | if (target.getTargetOpts().AMDGPUXnackState != |
| 44 | TargetOptions::AMDGPUFeatureState::Any) { |
| 45 | getModule()->setAttr(name: cir::CIRDialect::getAMDGPUXnackAttrName(), |
| 46 | value: builder.getI32IntegerAttr( |
| 47 | value: target.getTargetOpts().AMDGPUXnackState == |
| 48 | TargetOptions::AMDGPUFeatureState::Enabled |
| 49 | ? 1 |
| 50 | : 0)); |
| 51 | } |
| 52 | |
| 53 | // Emit sramecc module flag. |
| 54 | if (target.getTargetOpts().AMDGPUSramEccState != |
| 55 | TargetOptions::AMDGPUFeatureState::Any) { |
| 56 | getModule()->setAttr(name: cir::CIRDialect::getAMDGPUSramEccAttrName(), |
| 57 | value: builder.getI32IntegerAttr( |
| 58 | value: target.getTargetOpts().AMDGPUSramEccState == |
| 59 | TargetOptions::AMDGPUFeatureState::Enabled |
| 60 | ? 1 |
| 61 | : 0)); |
| 62 | } |
| 63 | } |
| 64 |