Skip to content

Commit 557cae2

Browse files
committed
[CIR] Upstream cir.call with scalar arguments
1 parent afc030d commit 557cae2

File tree

16 files changed

+588
-46
lines changed

16 files changed

+588
-46
lines changed

clang/include/clang/CIR/Dialect/Builder/CIRBaseBuilder.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,15 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
214214
//===--------------------------------------------------------------------===//
215215

216216
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
217-
mlir::Type returnType) {
218-
auto op = create<cir::CallOp>(loc, callee, returnType);
217+
mlir::Type returnType, mlir::ValueRange operands) {
218+
auto op = create<cir::CallOp>(loc, callee, returnType, operands);
219219
return op;
220220
}
221221

222-
cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee) {
222+
cir::CallOp createCallOp(mlir::Location loc, cir::FuncOp callee,
223+
mlir::ValueRange operands) {
223224
return createCallOp(loc, mlir::SymbolRefAttr::get(callee),
224-
callee.getFunctionType().getReturnType());
225+
callee.getFunctionType().getReturnType(), operands);
225226
}
226227

227228
//===--------------------------------------------------------------------===//

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,6 +1496,10 @@ def FuncOp : CIR_Op<"func", [
14961496
return getFunctionType().getReturnTypes();
14971497
}
14981498

1499+
// TODO(cir): this should be an operand attribute, but for now we just hard-
1500+
// wire this as a function. Will later add a $no_proto argument to this op.
1501+
bool getNoProto() { return false; }
1502+
14991503
//===------------------------------------------------------------------===//
15001504
// SymbolOpInterface Methods
15011505
//===------------------------------------------------------------------===//
@@ -1516,6 +1520,41 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
15161520
!listconcat(extra_traits,
15171521
[DeclareOpInterfaceMethods<CIRCallOpInterface>,
15181522
DeclareOpInterfaceMethods<SymbolUserOpInterface>])> {
1523+
let extraClassDeclaration = [{
1524+
/// Get the argument operands to the called function.
1525+
mlir::OperandRange getArgOperands() {
1526+
return {arg_operand_begin(), arg_operand_end()};
1527+
}
1528+
1529+
mlir::MutableOperandRange getArgOperandsMutable() {
1530+
llvm_unreachable("NYI");
1531+
}
1532+
1533+
/// Return the callee of this operation
1534+
mlir::CallInterfaceCallable getCallableForCallee() {
1535+
return (*this)->getAttrOfType<mlir::SymbolRefAttr>("callee");
1536+
}
1537+
1538+
/// Set the callee for this operation.
1539+
void setCalleeFromCallable(::mlir::CallInterfaceCallable callee) {
1540+
(*this)->setAttr(getCalleeAttrName(),
1541+
mlir::cast<mlir::SymbolRefAttr>(callee));
1542+
}
1543+
1544+
::mlir::ArrayAttr getArgAttrsAttr() { return {}; }
1545+
::mlir::ArrayAttr getResAttrsAttr() { return {}; }
1546+
1547+
void setResAttrsAttr(::mlir::ArrayAttr attrs) {}
1548+
void setArgAttrsAttr(::mlir::ArrayAttr attrs) {}
1549+
1550+
::mlir::Attribute removeArgAttrsAttr() { return {}; }
1551+
::mlir::Attribute removeResAttrsAttr() { return {}; }
1552+
1553+
void setArg(unsigned index, mlir::Value value) {
1554+
setOperand(index, value);
1555+
}
1556+
}];
1557+
15191558
let hasCustomAssemblyFormat = 1;
15201559
let skipDefaultBuilders = 1;
15211560
let hasVerifier = 0;
@@ -1525,7 +1564,8 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
15251564
// the upstreaming process moves on. The verifiers is also missing for now,
15261565
// will add in the future.
15271566

1528-
dag commonArgs = (ins FlatSymbolRefAttr:$callee);
1567+
dag commonArgs = (ins FlatSymbolRefAttr:$callee,
1568+
Variadic<CIR_AnyType>:$args);
15291569
}
15301570

15311571
def CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
@@ -1546,7 +1586,9 @@ def CallOp : CIR_CallOpBase<"call", [NoRegionArguments]> {
15461586
let arguments = commonArgs;
15471587

15481588
let builders = [OpBuilder<(ins "mlir::SymbolRefAttr":$callee,
1549-
"mlir::Type":$resType), [{
1589+
"mlir::Type":$resType,
1590+
"mlir::ValueRange":$operands), [{
1591+
$_state.addOperands(operands);
15501592
$_state.addAttribute("callee", callee);
15511593
if (resType && !isa<VoidType>(resType))
15521594
$_state.addTypes(resType);

clang/include/clang/CIR/Interfaces/CIROpInterfaces.td

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,24 @@ let cppNamespace = "::cir" in {
2121
// The CIRCallOpInterface must be used instead of CallOpInterface when looking
2222
// at arguments and other bits of CallOp. This creates a level of abstraction
2323
// that's useful for handling indirect calls and other details.
24-
def CIRCallOpInterface : OpInterface<"CIRCallOpInterface", []> {
24+
def CIRCallOpInterface : OpInterface<"CIRCallOpInterface", [CallOpInterface]> {
2525
// Currently we don't have any methods defined in CIRCallOpInterface. We'll
2626
// add more methods as the upstreaming proceeds.
27+
let methods = [
28+
InterfaceMethod<"", "mlir::Operation::operand_iterator",
29+
"arg_operand_begin", (ins)>,
30+
InterfaceMethod<"", "mlir::Operation::operand_iterator",
31+
"arg_operand_end", (ins)>,
32+
InterfaceMethod<
33+
"Return the operand at index 'i', accounts for indirect call or "
34+
"exception info",
35+
"mlir::Value", "getArgOperand",
36+
(ins "unsigned":$i)>,
37+
InterfaceMethod<
38+
"Return the number of operands, accounts for indirect call or "
39+
"exception info",
40+
"unsigned", "getNumArgOperands", (ins)>,
41+
];
2742
}
2843

2944
def CIRGlobalValueInterface

clang/include/clang/CIR/MissingFeatures.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ struct MissingFeatures {
7676
// CallOp handling
7777
static bool opCallBuiltinFunc() { return false; }
7878
static bool opCallPseudoDtor() { return false; }
79-
static bool opCallArgs() { return false; }
79+
static bool opCallAggregateArgs() { return false; }
80+
static bool opCallPaddingArgs() { return false; }
81+
static bool opCallABIExtendArg() { return false; }
82+
static bool opCallABIIndirectArg() { return false; }
83+
static bool opCallWidenArg() { return false; }
84+
static bool opCallBitcastArg() { return false; }
85+
static bool opCallImplicitObjectSizeArgs() { return false; }
8086
static bool opCallReturn() { return false; }
8187
static bool opCallArgEvaluationOrder() { return false; }
8288
static bool opCallCallConv() { return false; }
@@ -90,6 +96,9 @@ struct MissingFeatures {
9096
static bool opCallAttrs() { return false; }
9197
static bool opCallSurroundingTry() { return false; }
9298
static bool opCallASTAttr() { return false; }
99+
static bool opCallVariadic() { return false; }
100+
static bool opCallObjCMethod() { return false; }
101+
static bool opCallExtParameterInfo() { return false; }
93102

94103
// ScopeOp handling
95104
static bool opScopeCleanupRegion() { return false; }
@@ -157,6 +166,7 @@ struct MissingFeatures {
157166
static bool emitCheckedInBoundsGEP() { return false; }
158167
static bool preservedAccessIndexRegion() { return false; }
159168
static bool bitfields() { return false; }
169+
static bool msabi() { return false; }
160170
static bool typeChecks() { return false; }
161171
static bool lambdaFieldToName() { return false; }
162172

0 commit comments

Comments
 (0)