Skip to content

[CIR] Upstream cir.call with scalar arguments #136810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
//===--------------------------------------------------------------------===//

cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
mlir::Type returnType) {
auto op = create<cir::CallOp>(loc, callee, returnType);
return op;
mlir::Type returnType, mlir::ValueRange operands) {
return create<cir::CallOp>(loc, callee, returnType, operands);
}

cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee) {
cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee,
mlir::ValueRange operands) {
return createCallOp(loc, mlir::SymbolRefAttr::get(callee),
callee.getFunctionType().getReturnType());
callee.getFunctionType().getReturnType(), operands);
}

//===--------------------------------------------------------------------===//
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/CIR/Dialect/IR/CIRDialect.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
#include "clang/CIR/MissingFeatures.h"

namespace mlir {
namespace OpTrait {
Expand Down
49 changes: 47 additions & 2 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,13 @@ def FuncOp : CIR_Op<"func", [
return getFunctionType().getReturnTypes();
}

// TODO(cir): this should be an operand attribute, but for now we just hard-
// wire this as a function. Will later add a $no_proto argument to this op.
bool getNoProto() {
assert(!cir::MissingFeatures::opFuncNoProto());
return false;
}

//===------------------------------------------------------------------===//
// SymbolOpInterface Methods
//===------------------------------------------------------------------===//
Expand All @@ -1789,6 +1796,41 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
!listconcat(extra_traits,
[DeclareOpInterfaceMethods<CIRCallOpInterface>,
DeclareOpInterfaceMethods<SymbolUserOpInterface>])> {
let extraClassDeclaration = [{
/// Get the argument operands to the called function.
mlir::OperandRange getArgOperands() {
return getArgs();
}

mlir::MutableOperandRange getArgOperandsMutable() {
return getArgsMutable();
}

/// Return the callee of this operation
mlir::CallInterfaceCallable getCallableForCallee() {
return (*this)->getAttrOfType<mlir::SymbolRefAttr>("callee");
}

/// Set the callee for this operation.
void setCalleeFromCallable(::mlir::CallInterfaceCallable callee) {
(*this)->setAttr(getCalleeAttrName(),
mlir::cast<mlir::SymbolRefAttr>(callee));
}

mlir::ArrayAttr getArgAttrsAttr() { return {}; }
::mlir::ArrayAttr getResAttrsAttr() { return {}; }

void setResAttrsAttr(::mlir::ArrayAttr attrs) {}
void setArgAttrsAttr(::mlir::ArrayAttr attrs) {}

::mlir::Attribute removeArgAttrsAttr() { return {}; }
::mlir::Attribute removeResAttrsAttr() { return {}; }

void setArg(unsigned index, mlir::Value value) {
setOperand(index, value);
}
}];

let hasCustomAssemblyFormat = 1;
let skipDefaultBuilders = 1;
let hasVerifier = 0;
Expand All @@ -1798,7 +1840,8 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
// the upstreaming process moves on. The verifiers is also missing for now,
// will add in the future.

dag commonArgs = (ins FlatSymbolRefAttr:$callee);
dag commonArgs = (ins FlatSymbolRefAttr:$callee,
Variadic<CIR_AnyType>:$args);
}

def CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
Expand All @@ -1819,7 +1862,9 @@ def CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
let arguments = commonArgs;

let builders = [OpBuilder<(ins "mlir::SymbolRefAttr":$callee,
"mlir::Type":$resType), [{
"mlir::Type":$resType,
"mlir::ValueRange":$operands), [{
$_state.addOperands(operands);
$_state.addAttribute("callee", callee);
if (resType && !isa<VoidType>(resType))
$_state.addTypes(resType);
Expand Down
13 changes: 12 additions & 1 deletion clang/include/clang/CIR/Interfaces/CIROpInterfaces.td
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,20 @@ let cppNamespace = "::cir" in {
// The CIRCallOpInterface must be used instead of CallOpInterface when looking
// at arguments and other bits of CallOp. This creates a level of abstraction
// that's useful for handling indirect calls and other details.
def CIRCallOpInterface : OpInterface<"CIRCallOpInterface", []> {
def CIRCallOpInterface : OpInterface<"CIRCallOpInterface", [CallOpInterface]> {
// Currently we don't have any methods defined in CIRCallOpInterface. We'll
// add more methods as the upstreaming proceeds.
let methods = [
InterfaceMethod<
"Return the operand at index 'i', accounts for indirect call or "
"exception info",
"mlir::Value", "getArgOperand",
(ins "unsigned":$i)>,
InterfaceMethod<
"Return the number of operands, accounts for indirect call or "
"exception info",
"unsigned", "getNumArgOperands", (ins)>,
];
}

def CIRGlobalValueInterface
Expand Down
15 changes: 14 additions & 1 deletion clang/include/clang/CIR/MissingFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,18 @@ struct MissingFeatures {
static bool opFuncDsolocal() { return false; }
static bool opFuncLinkage() { return false; }
static bool opFuncVisibility() { return false; }
static bool opFuncNoProto() { return false; }

// CallOp handling
static bool opCallBuiltinFunc() { return false; }
static bool opCallPseudoDtor() { return false; }
static bool opCallArgs() { return false; }
static bool opCallAggregateArgs() { return false; }
static bool opCallPaddingArgs() { return false; }
static bool opCallABIExtendArg() { return false; }
static bool opCallABIIndirectArg() { return false; }
static bool opCallWidenArg() { return false; }
static bool opCallBitcastArg() { return false; }
static bool opCallImplicitObjectSizeArgs() { return false; }
static bool opCallReturn() { return false; }
static bool opCallArgEvaluationOrder() { return false; }
static bool opCallCallConv() { return false; }
Expand All @@ -90,6 +97,11 @@ struct MissingFeatures {
static bool opCallAttrs() { return false; }
static bool opCallSurroundingTry() { return false; }
static bool opCallASTAttr() { return false; }
static bool opCallVariadic() { return false; }
static bool opCallObjCMethod() { return false; }
static bool opCallExtParameterInfo() { return false; }
static bool opCallCIRGenFuncInfoParamInfo() { return false; }
static bool opCallCIRGenFuncInfoExtParamInfo() { return false; }

// ScopeOp handling
static bool opScopeCleanupRegion() { return false; }
Expand Down Expand Up @@ -156,6 +168,7 @@ struct MissingFeatures {
static bool emitCheckedInBoundsGEP() { return false; }
static bool preservedAccessIndexRegion() { return false; }
static bool bitfields() { return false; }
static bool msabi() { return false; }
static bool typeChecks() { return false; }
static bool lambdaFieldToName() { return false; }
static bool targetSpecificCXXABI() { return false; }
Expand Down
Loading