Skip to content

[TableGen] Warn on redundant intrinsic properties #141056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions llvm/test/TableGen/warn-default-property.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: llvm-tblgen -gen-intrinsic-impl -I %p/../../include %s -DTEST_INTRINSICS_SUPPRESS_DEFS -o /dev/null 2>&1 | FileCheck %s

include "llvm/IR/Intrinsics.td"

// CHECK: warning: property 'IntrWillReturn' is already enabled by default
// CHECK: warning: property 'IntrNoCallback' is already enabled by default
def int_foo : DefaultAttrsIntrinsic<[], [], [IntrWillReturn, IntrNoMem, IntrNoCallback]>;
25 changes: 12 additions & 13 deletions llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,19 +324,28 @@ CodeGenIntrinsic::CodeGenIntrinsic(const Record *R,
for (unsigned E = TypeList->size(); Idx < E; ++Idx)
IS.ParamTys.push_back(TypeList->getElementAsRecord(Idx));

// Apply default properties, unless they are disabled.
ArrayRef<const Record *> DefaultProperties(Ctx.DefaultProperties);
if (TheDef->getValueAsBit("DisableDefaultAttributes"))
DefaultProperties = {};
for (const Record *Property : DefaultProperties)
setProperty(Property);

// Parse the intrinsic properties.
const ListInit *PropList = R->getValueAsListInit("IntrProperties");
for (unsigned i = 0, e = PropList->size(); i != e; ++i) {
const Record *Property = PropList->getElementAsRecord(i);
assert(Property->isSubClassOf("IntrinsicProperty") &&
"Expected a property!");

if (is_contained(DefaultProperties, Property)) {
PrintWarning(TheDef->getLoc(), "property '" + Property->getName() +
"' is already enabled by default");
}

setProperty(Property);
}

// Set default properties to true.
setDefaultProperties(Ctx.DefaultProperties);

// Also record the SDPatternOperator Properties.
Properties = parseSDPatternOperatorProperties(R);

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

void CodeGenIntrinsic::setDefaultProperties(
ArrayRef<const Record *> DefaultProperties) {
// opt-out of using default attributes.
if (TheDef->getValueAsBit("DisableDefaultAttributes"))
return;

for (const Record *Rec : DefaultProperties)
setProperty(Rec);
}

void CodeGenIntrinsic::setProperty(const Record *R) {
if (R->getName() == "IntrNoMem")
ME = MemoryEffects::none();
Expand Down
4 changes: 0 additions & 4 deletions llvm/utils/TableGen/Basic/CodeGenIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ struct CodeGenIntrinsic {

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

/// Goes through all IntrProperties that have IsDefault value set and sets
/// the property.
void setDefaultProperties(ArrayRef<const Record *> DefaultProperties);

/// Helper function to set property \p Name to true.
void setProperty(const Record *R);

Expand Down