Skip to content

Commit 5d6c920

Browse files
committed
Conversion of 'sycl.constructor(%0, %1) {type = @range}' (#51)
This PR adds support for converting the `sycl.constructor(%0, %1) {type = @range}` operation (representing construction of a sycl::range<n> object) to a call to the appropriate `sycl::range<n>` constructor. Signed-off-by: Tiotto, Ettore <[email protected]>
1 parent 7b3ac03 commit 5d6c920

File tree

4 files changed

+408
-128
lines changed

4 files changed

+408
-128
lines changed

mlir-sycl/include/mlir/Conversion/SYCLToLLVM/SYCLFuncRegistry.h

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class SYCLFuncRegistry;
3030
/// needs to be created in SYCLFuncRegistry constructor.
3131
class SYCLFuncDescriptor {
3232
friend class SYCLFuncRegistry;
33+
friend llvm::raw_ostream &operator<<(llvm::raw_ostream &, const SYCLFuncDescriptor &);
3334

3435
public:
3536
/// Enumerates SYCL functions.
@@ -44,26 +45,51 @@ class SYCLFuncDescriptor {
4445
Id1CtorSizeT, // sycl::id<1>::id<1>(std::enable_if<(1)==(1), unsigned long>::type)
4546
Id2CtorSizeT, // sycl::id<2>::id<2>(std::enable_if<(2)==(2), unsigned long>::type)
4647
Id3CtorSizeT, // sycl::id<3>::id<3>(std::enable_if<(3)==(3), unsigned long>::type)
47-
Id1CtorRange, // sycl::id<1>::id<1>(std::enable_if<(1)==(1), unsigned long>::type, unsigned long)
48-
Id2CtorRange, // sycl::id<2>::id<2>(std::enable_if<(2)==(2), unsigned long>::type, unsigned long)
49-
Id3CtorRange, // sycl::id<3>::id<3>(std::enable_if<(3)==(3), unsigned long>::type, unsigned long)
50-
Id1CtorItem, // sycl::id<1>::id<1>(std::enable_if<(1)==(1), unsigned long>::type, unsigned long, unsigned long)
51-
Id2CtorItem, // sycl::id<2>::id<2>(std::enable_if<(2)==(2), unsigned long>::type, unsigned long, unsigned long)
52-
Id3CtorItem, // sycl::id<3>::id<3>(std::enable_if<(3)==(3), unsigned long>::type, unsigned long, unsigned long)
48+
Id1Ctor2SizeT, // sycl::id<1>::id<1>(std::enable_if<(1)==(1), unsigned long>::type, unsigned long)
49+
Id2Ctor2SizeT, // sycl::id<2>::id<2>(std::enable_if<(2)==(2), unsigned long>::type, unsigned long)
50+
Id3Ctor2SizeT, // sycl::id<3>::id<3>(std::enable_if<(3)==(3), unsigned long>::type, unsigned long)
51+
Id1Ctor3SizeT, // sycl::id<1>::id<1>(std::enable_if<(1)==(1), unsigned long>::type, unsigned long, unsigned long)
52+
Id2Ctor3SizeT, // sycl::id<2>::id<2>(std::enable_if<(2)==(2), unsigned long>::type, unsigned long, unsigned long)
53+
Id3Ctor3SizeT, // sycl::id<3>::id<3>(std::enable_if<(3)==(3), unsigned long>::type, unsigned long, unsigned long)
5354
Id1CopyCtor, // sycl::id<1>::id(sycl::id<1> const&)
5455
Id2CopyCtor, // sycl::id<2>::id(sycl::id<2> const&)
5556
Id3CopyCtor, // sycl::id<3>::id(sycl::id<3> const&)
5657

57-
// Member functions for ..TODO..
58+
// Member functions for the sycl::Range<n> class.
59+
Range1CtorDefault, // sycl::Range<1>::range()
60+
Range2CtorDefault, // sycl::range<2>::range()
61+
Range3CtorDefault, // sycl::range<3>::range()
62+
Range1CtorSizeT, // sycl::range<1>::range<1>(std::enable_if<(1)==(1), unsigned long>::type)
63+
Range2CtorSizeT, // sycl::range<2>::range<2>(std::enable_if<(2)==(2), unsigned long>::type)
64+
Range3CtorSizeT, // sycl::range<3>::range<3>(std::enable_if<(3)==(3), unsigned long>::type)
65+
Range1Ctor2SizeT, // sycl::range<1>::range<1>(std::enable_if<(1)==(1), unsigned long>::type, unsigned long)
66+
Range2Ctor2SizeT, // sycl::range<2>::range<2>(std::enable_if<(2)==(2), unsigned long>::type, unsigned long)
67+
Range3Ctor2SizeT, // sycl::range<3>::range<3>(std::enable_if<(3)==(3), unsigned long>::type, unsigned long)
68+
Range1Ctor3SizeT, // sycl::range<1>::range<1>(std::enable_if<(1)==(1), unsigned long>::type, unsigned long, unsigned long)
69+
Range2Ctor3SizeT, // sycl::range<2>::range<2>(std::enable_if<(2)==(2), unsigned long>::type, unsigned long, unsigned long)
70+
Range3Ctor3SizeT, // sycl::range<3>::range<3>(std::enable_if<(3)==(3), unsigned long>::type, unsigned long, unsigned long)
71+
Range1CopyCtor, // sycl::range<1>::range(sycl::range<1> const&)
72+
Range2CopyCtor, // sycl::range<2>::range(sycl::range<2> const&)
73+
Range3CopyCtor, // sycl::range<3>::range(sycl::range<3> const&)
5874
};
5975
// clang-format on
6076

6177
/// Enumerates the kind of FuncId.
6278
enum class FuncIdKind {
6379
Unknown,
64-
IdCtor, // any sycl::id<n> constructors
80+
IdCtor, // any sycl::id<n> constructors.
81+
RangeCtor // any sycl::range<n> constructors.
6582
};
6683

84+
/// Returns the funcIdKind given a \p funcId.
85+
static FuncIdKind getFuncIdKind(FuncId funcId);
86+
87+
/// Retuns a descriptive name for the given \p funcIdKind.
88+
static std::string funcIdKindToName(FuncIdKind funcIdKind);
89+
90+
/// Retuns the FuncIdKind given a descriptive \p name.
91+
static FuncIdKind nameToFuncIdKind(Twine name);
92+
6793
// Call the SYCL constructor identified by \p id with the given \p args.
6894
static Value call(FuncId id, ValueRange args,
6995
const SYCLFuncRegistry &registry, OpBuilder &b,
@@ -73,8 +99,11 @@ class SYCLFuncDescriptor {
7399
/// Private constructor: only available to 'SYCLFuncRegistry'.
74100
SYCLFuncDescriptor(FuncId id, StringRef name, Type outputTy,
75101
ArrayRef<Type> argTys)
76-
: id(id), name(name), outputTy(outputTy),
77-
argTys(argTys.begin(), argTys.end()) {}
102+
: funcId(id), funcIdKind(getFuncIdKind(id)), name(name),
103+
outputTy(outputTy), argTys(argTys.begin(), argTys.end()) {
104+
assert(funcId != FuncId::Unknown && "Illegal function id");
105+
assert(funcIdKind != FuncIdKind::Unknown && "Illegal function id kind");
106+
}
78107

79108
/// Inject the declaration for this function into the module.
80109
void declareFunction(ModuleOp &module, OpBuilder &b);
@@ -83,13 +112,22 @@ class SYCLFuncDescriptor {
83112
static bool isIdCtor(FuncId funcId);
84113

85114
private:
86-
FuncId id; // unique identifier for a SYCL function
115+
FuncId funcId = FuncId::Unknown; // SYCL function identifier
116+
FuncIdKind funcIdKind = FuncIdKind::Unknown; // SYCL function kind
87117
StringRef name; // SYCL function name
88118
Type outputTy; // SYCL function output type
89119
SmallVector<Type, 4> argTys; // SYCL function arguments types
90-
FlatSymbolRefAttr funcRef; // Reference to the SYCL function declaration
120+
FlatSymbolRefAttr funcRef; // Reference to the SYCL function
91121
};
92122

123+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
124+
const SYCLFuncDescriptor &desc) {
125+
os << "funcId=" << (int)desc.funcId
126+
<< ", funcIdKind=" << SYCLFuncDescriptor::funcIdKindToName(desc.funcIdKind)
127+
<< ", name='" << desc.name.str() << "')";
128+
return os;
129+
}
130+
93131
/// \class SYCLFuncRegistry
94132
/// Singleton class representing the set of SYCL functions callable from the
95133
/// compiler.

0 commit comments

Comments
 (0)