Skip to content
Merged
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
8 changes: 0 additions & 8 deletions llvm/lib/IR/Intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,14 +740,6 @@ Intrinsic::ID Intrinsic::lookupIntrinsicID(StringRef Name) {
#include "llvm/IR/IntrinsicImpl.inc"
#undef GET_INTRINSIC_ATTRIBUTES

AttributeSet Intrinsic::getFnAttributes(LLVMContext &C, ID id) {
if (id == 0)
return AttributeSet();
uint16_t PackedID = IntrinsicsToAttributesMap[id - 1];
uint8_t FnAttrID = PackedID >> 8;
return getIntrinsicFnAttributeSet(C, FnAttrID);
}

Function *Intrinsic::getOrInsertDeclaration(Module *M, ID id,
ArrayRef<Type *> Tys) {
// There can never be multiple globals with the same name of different types,
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/TableGen/intrinsic-attrs.td
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ def int_deref_ptr_ret : Intrinsic<[llvm_ptr_ty], [], [Dereferenceable<RetIndex,
// CHECK-NEXT: });

// CHECK: static constexpr uint16_t IntrinsicsToAttributesMap[] = {
// CHECK: 0 << 8 | 0, // llvm.deref.ptr.ret
// CHECK: 1 << 8 | 1, // llvm.random.gen
// CHECK: 0 << 2 | 0, // llvm.deref.ptr.ret
// CHECK: 1 << 2 | 1, // llvm.random.gen
// CHECK: }; // IntrinsicsToAttributesMap

// CHECK: static constexpr ArgNoAttrIDPair ArgAttrIdTable[] = {
Expand Down
41 changes: 27 additions & 14 deletions llvm/utils/TableGen/Basic/IntrinsicEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,21 +629,24 @@ static constexpr uint16_t IntrinsicsToAttributesMap[] = {)";
UniqAttributes.try_emplace(&Int, ID);
}

constexpr uint16_t NoFunctionAttrsID = 255;
if (UniqAttributes.size() > 256)
PrintFatalError("Too many unique argument attributes for table!");
// Note, ID 255 is used to indicate no function attributes.
if (UniqFnAttributes.size() > 255)
PrintFatalError("Too many unique function attributes for table!");

// Assign a 16-bit packed ID for each intrinsic. The lower 8-bits will be its
// "argument attribute ID" (index in UniqAttributes) and upper 8 bits will be
const uint8_t UniqAttributesBitSize = Log2_32_Ceil(UniqAttributes.size() + 1);
Copy link
Contributor

@jurahul jurahul Sep 14, 2025

Choose a reason for hiding this comment

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

@elvinw-intel why is the +1 needed here? Assuming UniqAttributes.size() == 256, we should be able to use 8 bits, but it seems here it will use 9 bits.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@elvinw-intel why is the +1 needed here? Assuming UniqAttributes.size() == 256, we should be able to use 8 bits, but it seems here it will use 9 bits.

yes that is incorrect and need to be fixed - I can add the fix in follow up or create a new draft.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. A separate PR may be preferable to not mix two things in one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#158714 to adjust both bit calculations

// 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
// "argument attribute ID" (index in UniqAttributes) and upper bits will be
// its "function attribute ID" (index in UniqFnAttributes).
for (const CodeGenIntrinsic &Int : Ints) {
uint16_t FnAttrIndex =
hasFnAttributes(Int) ? UniqFnAttributes[&Int] : NoFunctionAttrsID;
OS << formatv("\n {} << 8 | {}, // {}", FnAttrIndex,
UniqAttributes[&Int], Int.Name);
OS << formatv("\n {} << {} | {}, // {}", FnAttrIndex,
UniqAttributesBitSize, UniqAttributes[&Int], Int.Name);
}

OS << R"(
Expand Down Expand Up @@ -749,8 +752,8 @@ AttributeList Intrinsic::getAttributes(LLVMContext &C, ID id,
return AttributeList();

uint16_t PackedID = IntrinsicsToAttributesMap[id - 1];
uint8_t FnAttrID = PackedID >> 8;
uint8_t ArgAttrID = PackedID & 0xFF;
uint16_t FnAttrID = PackedID >> ({});
uint16_t ArgAttrID = PackedID & ({});
using PairTy = std::pair<unsigned, AttributeSet>;
alignas(PairTy) char ASStorage[sizeof(PairTy) * {}];
PairTy *AS = reinterpret_cast<PairTy *>(ASStorage);
Expand All @@ -772,10 +775,20 @@ AttributeList Intrinsic::getAttributes(LLVMContext &C, ID id,
}
return AttributeList::get(C, ArrayRef(AS, NumAttrs));
}

AttributeSet Intrinsic::getFnAttributes(LLVMContext &C, ID id) {
if (id == 0)
return AttributeSet();
uint16_t PackedID = IntrinsicsToAttributesMap[id - 1];
uint16_t FnAttrID = PackedID >> ({});
return getIntrinsicFnAttributeSet(C, FnAttrID);
}
#endif // GET_INTRINSIC_ATTRIBUTES

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

void IntrinsicEmitter::EmitIntrinsicToBuiltinMap(
Expand Down