Skip to content

Commit e933413

Browse files
committed
[CIR] Upstream cir.call with scalar arguments
1 parent 001cc34 commit e933413

File tree

17 files changed

+577
-48
lines changed

17 files changed

+577
-48
lines changed

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

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

217217
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee,
218-
mlir::Type returnType) {
219-
auto op = create<cir::CallOp>(loc, callee, returnType);
220-
return op;
218+
mlir::Type returnType, mlir::ValueRange operands) {
219+
return create<cir::CallOp>(loc, callee, returnType, operands);
221220
}
222221

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

228228
//===--------------------------------------------------------------------===//

clang/include/clang/CIR/Dialect/IR/CIRDialect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
3232
#include "clang/CIR/Interfaces/CIRLoopOpInterface.h"
3333
#include "clang/CIR/Interfaces/CIROpInterfaces.h"
34+
#include "clang/CIR/MissingFeatures.h"
3435

3536
namespace mlir {
3637
namespace OpTrait {

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

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,13 @@ def FuncOp : CIR_Op<"func", [
17691769
return getFunctionType().getReturnTypes();
17701770
}
17711771

1772+
// TODO(cir): this should be an operand attribute, but for now we just hard-
1773+
// wire this as a function. Will later add a $no_proto argument to this op.
1774+
bool getNoProto() {
1775+
assert(!cir::MissingFeatures::opFuncNoProto());
1776+
return false;
1777+
}
1778+
17721779
//===------------------------------------------------------------------===//
17731780
// SymbolOpInterface Methods
17741781
//===------------------------------------------------------------------===//
@@ -1789,6 +1796,41 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
17891796
!listconcat(extra_traits,
17901797
[DeclareOpInterfaceMethods<CIRCallOpInterface>,
17911798
DeclareOpInterfaceMethods<SymbolUserOpInterface>])> {
1799+
let extraClassDeclaration = [{
1800+
/// Get the argument operands to the called function.
1801+
mlir::OperandRange getArgOperands() {
1802+
return {arg_operand_begin(), arg_operand_end()};
1803+
}
1804+
1805+
mlir::MutableOperandRange getArgOperandsMutable() {
1806+
llvm_unreachable("NYI");
1807+
}
1808+
1809+
/// Return the callee of this operation
1810+
mlir::CallInterfaceCallable getCallableForCallee() {
1811+
return (*this)->getAttrOfType<mlir::SymbolRefAttr>("callee");
1812+
}
1813+
1814+
/// Set the callee for this operation.
1815+
void setCalleeFromCallable(::mlir::CallInterfaceCallable callee) {
1816+
(*this)->setAttr(getCalleeAttrName(),
1817+
mlir::cast<mlir::SymbolRefAttr>(callee));
1818+
}
1819+
1820+
mlir::ArrayAttr getArgAttrsAttr() { return {}; }
1821+
::mlir::ArrayAttr getResAttrsAttr() { return {}; }
1822+
1823+
void setResAttrsAttr(::mlir::ArrayAttr attrs) {}
1824+
void setArgAttrsAttr(::mlir::ArrayAttr attrs) {}
1825+
1826+
::mlir::Attribute removeArgAttrsAttr() { return {}; }
1827+
::mlir::Attribute removeResAttrsAttr() { return {}; }
1828+
1829+
void setArg(unsigned index, mlir::Value value) {
1830+
setOperand(index, value);
1831+
}
1832+
}];
1833+
17921834
let hasCustomAssemblyFormat = 1;
17931835
let skipDefaultBuilders = 1;
17941836
let hasVerifier = 0;
@@ -1798,7 +1840,8 @@ class CIR_CallOpBase<string mnemonic, list<Trait> extra_traits = []>
17981840
// the upstreaming process moves on. The verifiers is also missing for now,
17991841
// will add in the future.
18001842

1801-
dag commonArgs = (ins FlatSymbolRefAttr:$callee);
1843+
dag commonArgs = (ins FlatSymbolRefAttr:$callee,
1844+
Variadic<CIR_AnyType>:$args);
18021845
}
18031846

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

18211864
let builders = [OpBuilder<(ins "mlir::SymbolRefAttr":$callee,
1822-
"mlir::Type":$resType), [{
1865+
"mlir::Type":$resType,
1866+
"mlir::ValueRange":$operands), [{
1867+
$_state.addOperands(operands);
18231868
$_state.addAttribute("callee", callee);
18241869
if (resType && !isa<VoidType>(resType))
18251870
$_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: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,18 @@ struct MissingFeatures {
7272
static bool opFuncDsolocal() { return false; }
7373
static bool opFuncLinkage() { return false; }
7474
static bool opFuncVisibility() { return false; }
75+
static bool opFuncNoProto() { return false; }
7576

7677
// CallOp handling
7778
static bool opCallBuiltinFunc() { return false; }
7879
static bool opCallPseudoDtor() { return false; }
79-
static bool opCallArgs() { return false; }
80+
static bool opCallAggregateArgs() { return false; }
81+
static bool opCallPaddingArgs() { return false; }
82+
static bool opCallABIExtendArg() { return false; }
83+
static bool opCallABIIndirectArg() { return false; }
84+
static bool opCallWidenArg() { return false; }
85+
static bool opCallBitcastArg() { return false; }
86+
static bool opCallImplicitObjectSizeArgs() { return false; }
8087
static bool opCallReturn() { return false; }
8188
static bool opCallArgEvaluationOrder() { return false; }
8289
static bool opCallCallConv() { return false; }
@@ -90,6 +97,11 @@ struct MissingFeatures {
9097
static bool opCallAttrs() { return false; }
9198
static bool opCallSurroundingTry() { return false; }
9299
static bool opCallASTAttr() { return false; }
100+
static bool opCallVariadic() { return false; }
101+
static bool opCallObjCMethod() { return false; }
102+
static bool opCallExtParameterInfo() { return false; }
103+
static bool opCallCIRGenFuncInfoParamInfo() { return false; }
104+
static bool opCallCIRGenFuncInfoExtParamInfo() { return false; }
93105

94106
// ScopeOp handling
95107
static bool opScopeCleanupRegion() { return false; }
@@ -156,6 +168,7 @@ struct MissingFeatures {
156168
static bool emitCheckedInBoundsGEP() { return false; }
157169
static bool preservedAccessIndexRegion() { return false; }
158170
static bool bitfields() { return false; }
171+
static bool msabi() { return false; }
159172
static bool typeChecks() { return false; }
160173
static bool lambdaFieldToName() { return false; }
161174
static bool targetSpecificCXXABI() { return false; }

0 commit comments

Comments
 (0)