Skip to content

Commit 3bee3df

Browse files
committed
[SYCL] Revert all improvements, just fix a bug
1 parent 6b578a6 commit 3bee3df

File tree

4 files changed

+23
-44
lines changed

4 files changed

+23
-44
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,6 @@ class IdentifierArgument<string name, bit opt = 0> : Argument<name, opt>;
174174
class IntArgument<string name, bit opt = 0> : Argument<name, opt>;
175175
class StringArgument<string name, bit opt = 0> : Argument<name, opt>;
176176
class ExprArgument<string name, bit opt = 0> : Argument<name, opt>;
177-
class IntegerExprArgument<string name, int undef = 0, bit opt = 0>
178-
: ExprArgument<name, opt> {
179-
int UndefValue = undef;
180-
}
181177
class DeclArgument<DeclNode kind, string name, bit opt = 0, bit fake = 0>
182178
: Argument<name, opt, fake> {
183179
DeclNode Kind = kind;
@@ -1293,7 +1289,7 @@ def LoopUnrollHint : InheritableAttr {
12931289

12941290
def IntelReqdSubGroupSize: InheritableAttr {
12951291
let Spellings = [GNU<"intel_reqd_sub_group_size">, CXX11<"cl", "intel_reqd_sub_group_size">];
1296-
let Args = [IntegerExprArgument<"SubGroupSize", /* UndefValue = */ 0>];
1292+
let Args = [ExprArgument<"SubGroupSize">];
12971293
let Subjects = SubjectList<[Function, CXXMethod], ErrorDiag>;
12981294
let Documentation = [IntelReqdSubGroupSizeDocs];
12991295
let LangOpts = [OpenCL, SYCLIsDevice, SYCLIsHost];

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,16 @@ void CodeGenFunction::EmitOpenCLKernelMetadata(const FunctionDecl *FD,
565565
Fn->setMetadata("reqd_work_group_size", llvm::MDNode::get(Context, AttrMDArgs));
566566
}
567567

568-
if (IntelReqdSubGroupSizeAttr *A = FD->getAttr<IntelReqdSubGroupSizeAttr>()) {
568+
if (const IntelReqdSubGroupSizeAttr *A =
569+
FD->getAttr<IntelReqdSubGroupSizeAttr>()) {
570+
llvm::APSInt ArgVal(32);
569571
llvm::LLVMContext &Context = getLLVMContext();
570-
llvm::Metadata *AttrMDArgs[] = {llvm::ConstantAsMetadata::get(
571-
Builder.getInt32(A->getSubGroupSizeEvaluated(FD->getASTContext())))};
572+
bool IsValid = A->getSubGroupSize()->isIntegerConstantExpr(
573+
ArgVal, FD->getASTContext());
574+
assert(IsValid && "Not an integer constant expression");
575+
(void)IsValid;
576+
llvm::Metadata *AttrMDArgs[] = {
577+
llvm::ConstantAsMetadata::get(Builder.getInt32(ArgVal.getSExtValue()))};
572578
Fn->setMetadata("intel_reqd_sub_group_size",
573579
llvm::MDNode::get(Context, AttrMDArgs));
574580
}

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,15 @@ static void reportConflictingAttrs(Sema &S, FunctionDecl *F, const Attr *A1,
308308
F->setInvalidDecl();
309309
}
310310

311+
/// Returns the signed constant integer value represetned by given expression
312+
static int getIntExprValue(const Expr *E, ASTContext &Ctx) {
313+
llvm::APSInt Val(32);
314+
bool IsValid = E->isIntegerConstantExpr(Val, Ctx);
315+
assert(IsValid && "expression must be constant integer");
316+
(void)IsValid;
317+
return Val.getSExtValue();
318+
}
319+
311320
class MarkDeviceFunction : public RecursiveASTVisitor<MarkDeviceFunction> {
312321
public:
313322
MarkDeviceFunction(Sema &S)
@@ -1688,16 +1697,16 @@ void Sema::MarkDevice(void) {
16881697
KernelBody ? KernelBody->getAttr<SYCLSimdAttr>() : nullptr;
16891698
if (auto *Existing =
16901699
SYCLKernel->getAttr<IntelReqdSubGroupSizeAttr>()) {
1691-
if (Existing->getSubGroupSizeEvaluated(getASTContext()) !=
1692-
Attr->getSubGroupSizeEvaluated(getASTContext())) {
1700+
if (getIntExprValue(Existing->getSubGroupSize(), getASTContext()) !=
1701+
getIntExprValue(Attr->getSubGroupSize(), getASTContext())) {
16931702
Diag(SYCLKernel->getLocation(),
16941703
diag::err_conflicting_sycl_kernel_attributes);
16951704
Diag(Existing->getLocation(), diag::note_conflicting_attribute);
16961705
Diag(Attr->getLocation(), diag::note_conflicting_attribute);
16971706
SYCLKernel->setInvalidDecl();
16981707
}
1699-
} else if (KBSimdAttr &&
1700-
(Attr->getSubGroupSizeEvaluated(getASTContext()) != 1)) {
1708+
} else if (KBSimdAttr && (getIntExprValue(Attr->getSubGroupSize(),
1709+
getASTContext()) != 1)) {
17011710
reportConflictingAttrs(*this, KernelBody, KBSimdAttr, Attr);
17021711
} else {
17031712
SYCLKernel->addAttr(A);

clang/utils/TableGen/ClangAttrEmitter.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,36 +1161,6 @@ namespace {
11611161
void writeHasChildren(raw_ostream &OS) const override { OS << "true"; }
11621162
};
11631163

1164-
class IntegerExprArgument : public ExprArgument {
1165-
private:
1166-
int UndefValue;
1167-
1168-
public:
1169-
IntegerExprArgument(const Record &Arg, StringRef Attr)
1170-
: ExprArgument(Arg, Attr), UndefValue(Arg.getValueAsInt("UndefValue")) {
1171-
}
1172-
1173-
void writeAccessors(raw_ostream &OS) const override {
1174-
OS << " " << getType() << " get" << getUpperName() << "() const {\n";
1175-
OS << " return " << getLowerName() << ";\n";
1176-
OS << " }\n";
1177-
OS << "private:\n";
1178-
OS << " int " << getLowerName() << "Value = " << UndefValue << ";\n";
1179-
OS << "public:\n";
1180-
OS << " int get" << getUpperName() << "Evaluated(ASTContext &Ctx) {\n";
1181-
OS << " if (" << getLowerName() << "Value != " << UndefValue << ")\n";
1182-
OS << " return " << getLowerName() << "Value;\n";
1183-
OS << " llvm::APSInt Val(32);\n";
1184-
OS << " bool Succeedded = " << getLowerName()
1185-
<< "->isIntegerConstantExpr(Val, Ctx);\n";
1186-
OS << " assert(Succeedded && \"expression must be constant "
1187-
"integer\");\n";
1188-
OS << " " << getLowerName() << "Value = Val.getSExtValue();\n";
1189-
OS << " return " << getLowerName() << "Value;\n";
1190-
OS << " }";
1191-
}
1192-
};
1193-
11941164
class VariadicExprArgument : public VariadicArgument {
11951165
public:
11961166
VariadicExprArgument(const Record &Arg, StringRef Attr)
@@ -1329,8 +1299,6 @@ createArgument(const Record &Arg, StringRef Attr,
13291299
Ptr = std::make_unique<EnumArgument>(Arg, Attr);
13301300
else if (ArgName == "ExprArgument")
13311301
Ptr = std::make_unique<ExprArgument>(Arg, Attr);
1332-
else if (ArgName == "IntegerExprArgument")
1333-
Ptr = std::make_unique<IntegerExprArgument>(Arg, Attr);
13341302
else if (ArgName == "DeclArgument")
13351303
Ptr = std::make_unique<SimpleArgument>(
13361304
Arg, Attr, (Arg.getValueAsDef("Kind")->getName() + "Decl *").str());

0 commit comments

Comments
 (0)