|
| 1 | +//===--- CIRGenCall.cpp - Encapsulate calling convention details ----------===// |
| 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 | +// These classes wrap the information about a call or function definition used |
| 10 | +// to handle ABI compliancy. |
| 11 | +// |
| 12 | +//===----------------------------------------------------------------------===// |
| 13 | + |
| 14 | +#include "CIRGenCall.h" |
| 15 | +#include "CIRGenFunction.h" |
| 16 | +#include "clang/CIR/MissingFeatures.h" |
| 17 | + |
| 18 | +using namespace clang; |
| 19 | +using namespace clang::CIRGen; |
| 20 | + |
| 21 | +CIRGenFunctionInfo *CIRGenFunctionInfo::create() { |
| 22 | + // For now we just create an empty CIRGenFunctionInfo. |
| 23 | + CIRGenFunctionInfo *fi = new CIRGenFunctionInfo(); |
| 24 | + return fi; |
| 25 | +} |
| 26 | + |
| 27 | +CIRGenCallee CIRGenCallee::prepareConcreteCallee(CIRGenFunction &cgf) const { |
| 28 | + assert(!cir::MissingFeatures::opCallVirtual()); |
| 29 | + return *this; |
| 30 | +} |
| 31 | + |
| 32 | +static const CIRGenFunctionInfo &arrangeFreeFunctionLikeCall(CIRGenTypes &cgt) { |
| 33 | + assert(!cir::MissingFeatures::opCallArgs()); |
| 34 | + return cgt.arrangeCIRFunctionInfo(); |
| 35 | +} |
| 36 | + |
| 37 | +const CIRGenFunctionInfo &CIRGenTypes::arrangeFreeFunctionCall() { |
| 38 | + return arrangeFreeFunctionLikeCall(*this); |
| 39 | +} |
| 40 | + |
| 41 | +static cir::CIRCallOpInterface emitCallLikeOp(CIRGenFunction &cgf, |
| 42 | + mlir::Location callLoc, |
| 43 | + cir::FuncOp directFuncOp) { |
| 44 | + CIRGenBuilderTy &builder = cgf.getBuilder(); |
| 45 | + |
| 46 | + assert(!cir::MissingFeatures::opCallSurroundingTry()); |
| 47 | + assert(!cir::MissingFeatures::invokeOp()); |
| 48 | + |
| 49 | + assert(builder.getInsertionBlock() && "expected valid basic block"); |
| 50 | + assert(!cir::MissingFeatures::opCallIndirect()); |
| 51 | + |
| 52 | + return builder.createCallOp(callLoc, directFuncOp); |
| 53 | +} |
| 54 | + |
| 55 | +RValue CIRGenFunction::emitCall(const CIRGenFunctionInfo &funcInfo, |
| 56 | + const CIRGenCallee &callee, |
| 57 | + cir::CIRCallOpInterface *callOp, |
| 58 | + mlir::Location loc) { |
| 59 | + assert(!cir::MissingFeatures::opCallArgs()); |
| 60 | + assert(!cir::MissingFeatures::emitLifetimeMarkers()); |
| 61 | + |
| 62 | + const CIRGenCallee &concreteCallee = callee.prepareConcreteCallee(*this); |
| 63 | + mlir::Operation *calleePtr = concreteCallee.getFunctionPointer(); |
| 64 | + |
| 65 | + assert(!cir::MissingFeatures::opCallInAlloca()); |
| 66 | + |
| 67 | + mlir::NamedAttrList attrs; |
| 68 | + StringRef funcName; |
| 69 | + if (auto calleeFuncOp = dyn_cast<cir::FuncOp>(calleePtr)) |
| 70 | + funcName = calleeFuncOp.getName(); |
| 71 | + |
| 72 | + assert(!cir::MissingFeatures::opCallCallConv()); |
| 73 | + assert(!cir::MissingFeatures::opCallSideEffect()); |
| 74 | + assert(!cir::MissingFeatures::opCallAttrs()); |
| 75 | + |
| 76 | + assert(!cir::MissingFeatures::invokeOp()); |
| 77 | + |
| 78 | + auto directFuncOp = dyn_cast<cir::FuncOp>(calleePtr); |
| 79 | + assert(!cir::MissingFeatures::opCallIndirect()); |
| 80 | + assert(!cir::MissingFeatures::opCallAttrs()); |
| 81 | + |
| 82 | + cir::CIRCallOpInterface theCall = emitCallLikeOp(*this, loc, directFuncOp); |
| 83 | + |
| 84 | + if (callOp) |
| 85 | + *callOp = theCall; |
| 86 | + |
| 87 | + assert(!cir::MissingFeatures::opCallMustTail()); |
| 88 | + assert(!cir::MissingFeatures::opCallReturn()); |
| 89 | + |
| 90 | + // For now we just return nothing because we don't have support for return |
| 91 | + // values yet. |
| 92 | + RValue ret = RValue::get(nullptr); |
| 93 | + |
| 94 | + return ret; |
| 95 | +} |
0 commit comments