Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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
2 changes: 1 addition & 1 deletion llvm/test/TableGen/intrinsic-attrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def int_deref_ptr_ret : Intrinsic<[llvm_ptr_ty], [], [Dereferenceable<RetIndex,
// CHECK-NEXT: Attribute::get(C, Attribute::NoUnwind),
// CHECK-NEXT: });

// CHECK: static constexpr uint16_t IntrinsicsToAttributesMap[] = {
// CHECK: static constexpr uint8_t IntrinsicsToAttributesMap[] = {
// CHECK: 0 << 2 | 0, // llvm.deref.ptr.ret
// CHECK: 1 << 2 | 1, // llvm.random.gen
// CHECK: }; // IntrinsicsToAttributesMap
Expand Down
43 changes: 25 additions & 18 deletions llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,7 @@ static AttributeSet getIntrinsicFnAttributeSet(LLVMContext &C, unsigned ID) {
}
OS << R"(
}
} // getIntrinsicFnAttributeSet

static constexpr uint16_t IntrinsicsToAttributesMap[] = {)";
} // getIntrinsicFnAttributeSet)";

// Compute unique argument attributes.
std::map<const CodeGenIntrinsic *, unsigned, AttributeComparator>
Expand All @@ -633,17 +631,25 @@ static constexpr uint16_t IntrinsicsToAttributesMap[] = {)";
// Note, ID `-1` is used to indicate no function attributes.
const uint8_t UniqFnAttributesBitSize =
Log2_32_Ceil(UniqFnAttributes.size() + 2);
const uint16_t NoFunctionAttrsID =
maskTrailingOnes<uint16_t>(UniqFnAttributesBitSize);
if (UniqAttributesBitSize + UniqFnAttributesBitSize > 16)
PrintFatalError(
"More than 16 bits are used for IntrinsicsToAttributesMap's entry!");

// Assign a 16-bit packed ID for each intrinsic. The lower bits will be its
const uint32_t NoFunctionAttrsID =
maskTrailingOnes<uint32_t>(UniqFnAttributesBitSize);
uint8_t AttributesMapDataBitSize =
PowerOf2Ceil(UniqAttributesBitSize + UniqFnAttributesBitSize);
if (AttributesMapDataBitSize < 8)
AttributesMapDataBitSize = 8;
else if (AttributesMapDataBitSize > 64)
PrintFatalError("Packed ID of IntrinsicsToAttributesMap exceeds 64b!");
else if (AttributesMapDataBitSize > 16)
PrintWarning("Packed ID of IntrinsicsToAttributesMap exceeds 16b, "
"this may cause performance drop!");

// Assign a packed ID for each intrinsic. The lower bits will be its
// "argument attribute ID" (index in UniqAttributes) and upper bits will be
// its "function attribute ID" (index in UniqFnAttributes).
OS << formatv("\nstatic constexpr uint{}_t IntrinsicsToAttributesMap[] = {{",
AttributesMapDataBitSize);
for (const CodeGenIntrinsic &Int : Ints) {
uint16_t FnAttrIndex =
uint32_t FnAttrIndex =
hasFnAttributes(Int) ? UniqFnAttributes[&Int] : NoFunctionAttrsID;
OS << formatv("\n {} << {} | {}, // {}", FnAttrIndex,
UniqAttributesBitSize, UniqAttributes[&Int], Int.Name);
Expand Down Expand Up @@ -751,9 +757,9 @@ AttributeList Intrinsic::getAttributes(LLVMContext &C, ID id,
if (id == 0)
return AttributeList();

uint16_t PackedID = IntrinsicsToAttributesMap[id - 1];
uint16_t FnAttrID = PackedID >> ({});
uint16_t ArgAttrID = PackedID & ({});
uint{}_t PackedID = IntrinsicsToAttributesMap[id - 1];
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format string uint{}_t is used without the bit size parameter. This should be uint{}_t with the AttributesMapDataBitSize parameter passed to formatv to properly substitute the bit size.

Copilot uses AI. Check for mistakes.

uint32_t FnAttrID = PackedID >> ({});
uint32_t ArgAttrID = PackedID & ({});
using PairTy = std::pair<unsigned, AttributeSet>;
alignas(PairTy) char ASStorage[sizeof(PairTy) * {}];
PairTy *AS = reinterpret_cast<PairTy *>(ASStorage);
Expand All @@ -779,16 +785,17 @@ AttributeList Intrinsic::getAttributes(LLVMContext &C, ID id,
AttributeSet Intrinsic::getFnAttributes(LLVMContext &C, ID id) {
if (id == 0)
return AttributeSet();
uint16_t PackedID = IntrinsicsToAttributesMap[id - 1];
uint16_t FnAttrID = PackedID >> ({});
uint{}_t PackedID = IntrinsicsToAttributesMap[id - 1];
Copy link
Preview

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format string uint{}_t is used without the bit size parameter. This should be uint{}_t with the AttributesMapDataBitSize parameter passed to formatv to properly substitute the bit size.

Copilot uses AI. Check for mistakes.

uint32_t FnAttrID = PackedID >> ({});
return getIntrinsicFnAttributeSet(C, FnAttrID);
}
#endif // GET_INTRINSIC_ATTRIBUTES

)",
UniqAttributesBitSize,
AttributesMapDataBitSize, UniqAttributesBitSize,
maskTrailingOnes<uint16_t>(UniqAttributesBitSize), MaxNumAttrs,
NoFunctionAttrsID, UniqAttributesBitSize);
NoFunctionAttrsID, AttributesMapDataBitSize,
UniqAttributesBitSize);
}

void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
Expand Down
Loading