Skip to content

Commit e947db0

Browse files
committed
[TableGen] Warn on redundant intrinsic properties
Warn on explicit intrinsic properties that are already implied by the use of DefaultAttrsIntrinsic.
1 parent 4e186f2 commit e947db0

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: llvm-tblgen -gen-intrinsic-impl -I %p/../../include %s -DTEST_INTRINSICS_SUPPRESS_DEFS -o /dev/null 2>&1 | FileCheck %s
2+
3+
include "llvm/IR/Intrinsics.td"
4+
5+
// CHECK: warning: property 'IntrWillReturn' is already enabled by default
6+
// CHECK: warning: property 'IntrNoCallback' is already enabled by default
7+
def int_foo : DefaultAttrsIntrinsic<[], [], [IntrWillReturn, IntrNoMem, IntrNoCallback]>;

llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,19 +324,28 @@ CodeGenIntrinsic::CodeGenIntrinsic(const Record *R,
324324
for (unsigned E = TypeList->size(); Idx < E; ++Idx)
325325
IS.ParamTys.push_back(TypeList->getElementAsRecord(Idx));
326326

327+
// Apply default properties, unless they are disabled.
328+
ArrayRef<const Record *> DefaultProperties(Ctx.DefaultProperties);
329+
if (TheDef->getValueAsBit("DisableDefaultAttributes"))
330+
DefaultProperties = {};
331+
for (const Record *Property : DefaultProperties)
332+
setProperty(Property);
333+
327334
// Parse the intrinsic properties.
328335
const ListInit *PropList = R->getValueAsListInit("IntrProperties");
329336
for (unsigned i = 0, e = PropList->size(); i != e; ++i) {
330337
const Record *Property = PropList->getElementAsRecord(i);
331338
assert(Property->isSubClassOf("IntrinsicProperty") &&
332339
"Expected a property!");
333340

341+
if (is_contained(DefaultProperties, Property)) {
342+
PrintWarning(TheDef->getLoc(), "property '" + Property->getName() +
343+
"' is already enabled by default");
344+
}
345+
334346
setProperty(Property);
335347
}
336348

337-
// Set default properties to true.
338-
setDefaultProperties(Ctx.DefaultProperties);
339-
340349
// Also record the SDPatternOperator Properties.
341350
Properties = parseSDPatternOperatorProperties(R);
342351

@@ -345,16 +354,6 @@ CodeGenIntrinsic::CodeGenIntrinsic(const Record *R,
345354
llvm::sort(Attrs);
346355
}
347356

348-
void CodeGenIntrinsic::setDefaultProperties(
349-
ArrayRef<const Record *> DefaultProperties) {
350-
// opt-out of using default attributes.
351-
if (TheDef->getValueAsBit("DisableDefaultAttributes"))
352-
return;
353-
354-
for (const Record *Rec : DefaultProperties)
355-
setProperty(Rec);
356-
}
357-
358357
void CodeGenIntrinsic::setProperty(const Record *R) {
359358
if (R->getName() == "IntrNoMem")
360359
ME = MemoryEffects::none();

llvm/utils/TableGen/Basic/CodeGenIntrinsics.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,6 @@ struct CodeGenIntrinsic {
154154

155155
bool hasProperty(enum SDNP Prop) const { return Properties & (1 << Prop); }
156156

157-
/// Goes through all IntrProperties that have IsDefault value set and sets
158-
/// the property.
159-
void setDefaultProperties(ArrayRef<const Record *> DefaultProperties);
160-
161157
/// Helper function to set property \p Name to true.
162158
void setProperty(const Record *R);
163159

0 commit comments

Comments
 (0)