|
| 1 | +//===---- CIRGenBuiltinX86.cpp - Emit CIR for X86 builtins ----------------===// |
| 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 to emit NVPTX Builtin calls. |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +#include "CIRGenCXXABI.h" |
| 14 | +#include "CIRGenCall.h" |
| 15 | +#include "CIRGenFunction.h" |
| 16 | +#include "CIRGenModule.h" |
| 17 | +#include "TargetInfo.h" |
| 18 | +#include "clang/CIR/MissingFeatures.h" |
| 19 | + |
| 20 | +#include "mlir/Dialect/Func/IR/FuncOps.h" |
| 21 | +#include "mlir/IR/Value.h" |
| 22 | +#include "clang/AST/GlobalDecl.h" |
| 23 | +#include "clang/Basic/Builtins.h" |
| 24 | +#include "clang/Basic/TargetBuiltins.h" |
| 25 | +#include "clang/CIR/Dialect/IR/CIRDialect.h" |
| 26 | +#include "clang/CIR/Dialect/IR/CIRTypes.h" |
| 27 | +#include "llvm/Support/ErrorHandling.h" |
| 28 | + |
| 29 | +using namespace clang; |
| 30 | +using namespace clang::CIRGen; |
| 31 | +using namespace cir; |
| 32 | + |
| 33 | +mlir::Value CIRGenFunction::emitNVPTXBuiltinExpr(unsigned builtinId, |
| 34 | + const CallExpr *expr) { |
| 35 | + auto getIntrinsic = [&](const char *name) { |
| 36 | + mlir::Type intTy = cir::IntType::get(&getMLIRContext(), 32, false); |
| 37 | + return builder |
| 38 | + .create<cir::LLVMIntrinsicCallOp>(getLoc(expr->getExprLoc()), |
| 39 | + builder.getStringAttr(name), intTy) |
| 40 | + .getResult(); |
| 41 | + }; |
| 42 | + switch (builtinId) { |
| 43 | + case NVPTX::BI__nvvm_read_ptx_sreg_tid_x: |
| 44 | + return getIntrinsic("nvvm.read.ptx.sreg.tid.x"); |
| 45 | + case NVPTX::BI__nvvm_read_ptx_sreg_tid_y: |
| 46 | + return getIntrinsic("nvvm.read.ptx.sreg.tid.y"); |
| 47 | + case NVPTX::BI__nvvm_read_ptx_sreg_tid_z: |
| 48 | + return getIntrinsic("nvvm.read.ptx.sreg.tid.z"); |
| 49 | + case NVPTX::BI__nvvm_read_ptx_sreg_tid_w: |
| 50 | + return getIntrinsic("nvvm.read.ptx.sreg.tid.w"); |
| 51 | + |
| 52 | + case NVPTX::BI__nvvm_read_ptx_sreg_ntid_x: |
| 53 | + return getIntrinsic("nvvm.read.ptx.sreg.ntid.x"); |
| 54 | + case NVPTX::BI__nvvm_read_ptx_sreg_ntid_y: |
| 55 | + return getIntrinsic("nvvm.read.ptx.sreg.ntid.y"); |
| 56 | + case NVPTX::BI__nvvm_read_ptx_sreg_ntid_z: |
| 57 | + return getIntrinsic("nvvm.read.ptx.sreg.ntid.z"); |
| 58 | + case NVPTX::BI__nvvm_read_ptx_sreg_ntid_w: |
| 59 | + return getIntrinsic("nvvm.read.ptx.sreg.ntid.w"); |
| 60 | + |
| 61 | + case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_x: |
| 62 | + return getIntrinsic("nvvm.read.ptx.sreg.ctaid.x"); |
| 63 | + case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_y: |
| 64 | + return getIntrinsic("nvvm.read.ptx.sreg.ctaid.y"); |
| 65 | + case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_z: |
| 66 | + return getIntrinsic("nvvm.read.ptx.sreg.ctaid.z"); |
| 67 | + case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_w: |
| 68 | + return getIntrinsic("nvvm.read.ptx.sreg.ctaid.w"); |
| 69 | + |
| 70 | + case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_x: |
| 71 | + return getIntrinsic("nvvm.read.ptx.sreg.nctaid.x"); |
| 72 | + case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_y: |
| 73 | + return getIntrinsic("nvvm.read.ptx.sreg.nctaid.y"); |
| 74 | + case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_z: |
| 75 | + return getIntrinsic("nvvm.read.ptx.sreg.nctaid.z"); |
| 76 | + case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_w: |
| 77 | + return getIntrinsic("nvvm.read.ptx.sreg.nctaid.w"); |
| 78 | + |
| 79 | + default: |
| 80 | + llvm_unreachable("NYI"); |
| 81 | + } |
| 82 | +} |
0 commit comments