Skip to content

Commit c2c263a

Browse files
Refined migration behavior
1 parent 0e95b2d commit c2c263a

File tree

17 files changed

+260
-65
lines changed

17 files changed

+260
-65
lines changed

clang/include/clang/DPCT/DPCTOptions.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,10 @@ DPCT_ENUM_OPTION(
814814
"Experimental extension that allows to use non standard SYCL "
815815
"builtin functions.\n",
816816
false),
817+
DPCT_OPTION_ENUM_VALUE(
818+
"prefetch", int(ExperimentalFeatures::Exp_Prefetch),
819+
"Experimental extension that allows use of SYCL prefetch APIs.\n",
820+
false),
817821
DPCT_OPTION_ENUM_VALUE(
818822
"all", int(ExperimentalFeatures::Exp_All),
819823
"Enable all experimental extensions listed in this option.\n",

clang/lib/DPCT/AnalysisInfo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,6 +1347,9 @@ class DpctGlobalInfo {
13471347
return getUsingExperimental<
13481348
ExperimentalFeatures::Exp_NonStandardSYCLBuiltins>();
13491349
}
1350+
static bool useExtPrefetch() {
1351+
return getUsingExperimental<ExperimentalFeatures::Exp_Prefetch>();
1352+
}
13501353
static bool useNoQueueDevice() {
13511354
return getHelperFuncPreference(HelperFuncPreference::NoQueueDevice);
13521355
}

clang/lib/DPCT/CommandOption/ValidateArguments.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ enum class ExperimentalFeatures : unsigned int {
100100
Exp_InOrderQueueEvents,
101101
Exp_ExperimentalFeaturesEnumSize,
102102
Exp_NonStandardSYCLBuiltins,
103+
Exp_Prefetch,
103104
Exp_All
104105
};
105106
enum class HelperFuncPreference : unsigned int { NoQueueDevice = 0 };

clang/lib/DPCT/DPCT.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,8 @@ int runDPCT(int argc, const char **argv) {
977977
Experimentals.addValue(ExperimentalFeatures::Exp_BindlessImages);
978978
else if (Option.ends_with("graph"))
979979
Experimentals.addValue(ExperimentalFeatures::Exp_Graph);
980+
else if (Option.ends_with("prefetch"))
981+
Experimentals.addValue(ExperimentalFeatures::Exp_Prefetch);
980982
} else if (Option == "--no-dry-pattern") {
981983
NoDRYPattern.setValue(true);
982984
}

clang/lib/DPCT/RulesAsm/AsmMigration.cpp

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,6 @@ bool SYCLGenBase::emitBuiltinType(const InlineAsmBuiltinType *T) {
536536
case InlineAsmBuiltinType::u16x2: OS() << MapNames::getClNamespace() + "ushort2"; break;
537537
case InlineAsmBuiltinType::bf16: OS() << MapNames::getClNamespace() + "ext::oneapi::bfloat16"; break;
538538
case InlineAsmBuiltinType::f16x2: OS() << MapNames::getClNamespace() + "half2"; break;
539-
case InlineAsmBuiltinType::voidType: OS() << "void"; break;
540539
case InlineAsmBuiltinType::e4m3:
541540
case InlineAsmBuiltinType::e5m2:
542541
case InlineAsmBuiltinType::tf32:
@@ -591,7 +590,7 @@ bool SYCLGenBase::emitVariableDeclaration(const InlineAsmVarDecl *D) {
591590
bool SYCLGenBase::emitAddressExpr(const InlineAsmAddressExpr *Dst) {
592591
// Address expression only support ld/st & atom instructions.
593592
if (!CurrInst || !CurrInst->is(asmtok::op_st, asmtok::op_ld, asmtok::op_atom,
594-
asmtok::op_prefetch))
593+
asmtok::op_prefetch, asmtok::op_prefetchu))
595594
return SYCLGenError();
596595
std::string Type;
597596
if (tryEmitType(Type, CurrInst->getType(0)))
@@ -619,7 +618,8 @@ bool SYCLGenBase::emitAddressExpr(const InlineAsmAddressExpr *Dst) {
619618
std::string Reg;
620619
if (tryEmitStmt(Reg, Dst->getSymbol()))
621620
return SYCLGenSuccess();
622-
if (CurrInst->is(asmtok::op_prefetch) || CanSuppressCast(Dst->getSymbol()))
621+
if (CurrInst->is(asmtok::op_prefetch, asmtok::op_prefetchu) ||
622+
CanSuppressCast(Dst->getSymbol()))
623623
OS() << llvm::formatv("{0}", Reg);
624624
else
625625
OS() << llvm::formatv("(({0} *)(uintptr_t){1})", Type, Reg);
@@ -1284,12 +1284,15 @@ class SYCLGen : public SYCLGenBase {
12841284
}
12851285

12861286
bool handle_prefetch(const InlineAsmInstruction *Inst) override {
1287-
if (Inst->getNumInputOperands() != 1)
1287+
if (!DpctGlobalInfo::useExtPrefetch() || Inst->getNumInputOperands() != 1)
12881288
return SYCLGenError();
12891289

12901290
AsmStateSpace SS = Inst->getStateSpace();
1291-
if (SS != AsmStateSpace::S_global && SS != AsmStateSpace::none)
1292-
return SYCLGenError();
1291+
if (SS != AsmStateSpace::S_global && SS != AsmStateSpace::none) {
1292+
report(Diagnostics::API_NOT_MIGRATED, /*UseTextBegin=*/true,
1293+
GAS->getAsmString()->getString());
1294+
return SYCLGenSuccess();
1295+
}
12931296

12941297
if (!(Inst->hasAttr(InstAttr::L1) || Inst->hasAttr(InstAttr::L2)))
12951298
return SYCLGenError();
@@ -1299,8 +1302,18 @@ class SYCLGen : public SYCLGenBase {
12991302
PrefetchHint = "L1";
13001303
else if (Inst->hasAttr(InstAttr::L2))
13011304
PrefetchHint = "L2";
1302-
else
1303-
return SYCLGenError();
1305+
1306+
std::string evictionHint = "";
1307+
if (Inst->hasAttr(InstAttr::evict_last))
1308+
evictionHint = "evict_last";
1309+
else if (Inst->hasAttr(InstAttr::evict_normal))
1310+
evictionHint = "evict_normal";
1311+
1312+
if (!evictionHint.empty()) {
1313+
report(Diagnostics::API_NOT_MIGRATED, /*UseTextBegin=*/true,
1314+
GAS->getAsmString()->getString());
1315+
return SYCLGenSuccess();
1316+
}
13041317

13051318
llvm::SaveAndRestore<const InlineAsmInstruction *> Store(CurrInst);
13061319
CurrInst = Inst;
@@ -1320,6 +1333,15 @@ class SYCLGen : public SYCLGenBase {
13201333
return SYCLGenSuccess();
13211334
}
13221335

1336+
bool handle_prefetchu(const InlineAsmInstruction *Inst) override {
1337+
if (!DpctGlobalInfo::useExtPrefetch())
1338+
return SYCLGenError();
1339+
1340+
report(Diagnostics::API_NOT_MIGRATED, /*UseTextBegin=*/true,
1341+
GAS->getAsmString()->getString());
1342+
return SYCLGenSuccess();
1343+
}
1344+
13231345
StringRef GetWiderTypeAsString(const InlineAsmBuiltinType *Type) const {
13241346
switch (Type->getKind()) {
13251347
case InlineAsmBuiltinType::s16:

clang/lib/DPCT/RulesAsm/Parser/AsmLexer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ bool InlineAsmLexer::lexTokenInternal(InlineAsmToken &Result) {
265265
Char = getChar(CurPtr);
266266
if (Char == ':') {
267267
CurPtr++;
268+
Char = getChar(CurPtr);
269+
if (isIdentifierStart(Char) || isDigit(Char)) {
270+
Result.setFlag(InlineAsmToken::StartOfColonColon);
271+
return lexIdentifierContinue(Result, CurPtr);
272+
}
268273
Kind = asmtok::coloncolon;
269274
} else {
270275
Kind = asmtok::colon;

clang/lib/DPCT/RulesAsm/Parser/AsmNodes.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ class InlineAsmBuiltinType : public InlineAsmType {
8383
enum TypeKind {
8484
#define BUILTIN_TYPE(X, Y) X,
8585
#include "AsmTokenKinds.def"
86-
voidType,
8786
NUM_TYPES
8887
};
8988

@@ -223,7 +222,9 @@ class InlineAsmVarDecl : public InlineAsmNamedDecl {
223222
: InlineAsmNamedDecl(VariableDeclClass, Name), StateSpace(SS),
224223
Type(Type) {}
225224

226-
AsmStateSpace getStorageClass() const { return StateSpace; }
225+
AsmStateSpace getStorageClass() const {
226+
return StateSpace;
227+
}
227228

228229
void setInlineAsmOp(const Expr *Val) { InlineAsmOp = Val; }
229230
const Expr *getInlineAsmOp() const { return InlineAsmOp; }
@@ -389,12 +390,7 @@ class InlineAsmInstruction : public InlineAsmStmt {
389390
return InstructionClass <= S->getStmtClass();
390391
}
391392
AsmStateSpace getStateSpace() const {
392-
AsmStateSpace SS = AsmStateSpace::none;
393-
394-
if (StateSpace.has_value()) {
395-
return StateSpace.value();
396-
}
397-
return SS;
393+
return StateSpace.value_or(AsmStateSpace::none);
398394
}
399395
};
400396

clang/lib/DPCT/RulesAsm/Parser/AsmParser.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ InlineAsmStmtResult InlineAsmParser::ParseInstruction() {
335335
SmallVector<InlineAsmExpr *, 4> Ops;
336336
std::optional<AsmStateSpace> StateSpace;
337337

338-
while (Tok.startOfDot()) {
338+
while (Tok.startOfDot() || Tok.startOfColonColon()) {
339339
switch (Tok.getIdentifier()->getFlags()) {
340340
case InlineAsmIdentifierInfo::BuiltinType:
341341
Types.push_back(Context.getBuiltinTypeFromTokenKind(Tok.getKind()));
@@ -356,6 +356,11 @@ InlineAsmStmtResult InlineAsmParser::ParseInstruction() {
356356
ConsumeToken(); // consume instruction attribute
357357
}
358358

359+
if (Tok.getKind() == asmtok::coloncolon) {
360+
Attrs.push_back(ConvertToInstAttr(Tok.getKind()));
361+
ConsumeToken();
362+
}
363+
359364
InlineAsmExprResult Pred, Out;
360365
if ((Out = ParseExpression()).isInvalid())
361366
return AsmStmtError();
@@ -378,10 +383,11 @@ InlineAsmStmtResult InlineAsmParser::ParseInstruction() {
378383
Out = nullptr;
379384
}
380385
// prefetch{.state}.{level} [%0] has only one input operand and no type.
381-
if (Opcode->getTokenID() == asmtok::op_prefetch) {
386+
if (Opcode->getTokenID() == asmtok::op_prefetch ||
387+
Opcode->getTokenID() == asmtok::op_prefetchu) {
382388
Ops.push_back(Out.get());
383389
Out = nullptr;
384-
Types.push_back(Context.getBuiltinType(InlineAsmBuiltinType::voidType));
390+
Types.push_back(Context.getBuiltinType(InlineAsmBuiltinType::byte));
385391
}
386392

387393
return ::new (Context) InlineAsmInstruction(Opcode, StateSpace, Attrs, Types,

clang/lib/DPCT/RulesAsm/Parser/AsmToken.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ class InlineAsmToken {
2727

2828
public:
2929
enum TokenFlags {
30-
NeedsCleaning = 0x01, // This identifier contains special characters.
31-
Placeholder = 0x02, // This identifier is an inline asm placeholder.
32-
StartOfDot = 0x04, // This identifier is an dot identifier.
30+
NeedsCleaning = 0x01, // This identifier contains special characters.
31+
Placeholder = 0x02, // This identifier is an inline asm placeholder.
32+
StartOfDot = 0x04, // This identifier is a dot identifier.
33+
StartOfColonColon = 0x08, // This identifier is a coloncolon identifier.
3334
};
3435

3536
asmtok::TokenKind getKind() const { return Kind; }
@@ -112,8 +113,11 @@ class InlineAsmToken {
112113
/// Return true if this token is an inline asm placeholder.
113114
bool isPlaceholder() const { return getFlag(Placeholder); }
114115

115-
/// Return true if this token is an dot identifier.
116+
/// Return true if this token is a dot identifier.
116117
bool startOfDot() const { return getFlag(StartOfDot); }
118+
119+
/// Return true if this token is a coloncolon identifier.
120+
bool startOfColonColon() const { return getFlag(StartOfColonColon); }
117121
};
118122

119123
} // namespace clang::dpct

clang/lib/DPCT/RulesAsm/Parser/AsmTokenKinds.def

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#endif
1313

1414
#ifndef PUNCTUATOR
15-
#define PUNCTUATOR(X, Y) TOK(X)
15+
#define PUNCTUATOR(X,Y) TOK(X)
1616
#endif
1717

1818
#ifndef KEYWORD
@@ -406,6 +406,10 @@ MODIFIER(sc, ".sc")
406406
MODIFIER(gl, ".gl")
407407
MODIFIER(L1, ".L1")
408408
MODIFIER(L2, ".L2")
409+
MODIFIER(tensormap, ".tensormap")
410+
MODIFIER(evict_last, "::evict_last")
411+
MODIFIER(evict_normal, "::evict_normal")
412+
409413

410414
#undef LINKAGE
411415
#undef TARGET

0 commit comments

Comments
 (0)