Skip to content

Commit

Permalink
Extend GenXIntrinsics interface
Browse files Browse the repository at this point in the history
Add some functions to get LSC special argument indices.
Add function to get encoded LSCVectorSize.
  • Loading branch information
BruceGliff committed Mar 30, 2022
1 parent 99ac111 commit c97396d
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 74 deletions.
160 changes: 160 additions & 0 deletions GenXIntrinsics/include/llvm/GenXIntrinsics/GenXIntrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,166 @@ inline bool isLSC2D(const Function *F) {
return isLSC2D(getGenXIntrinsicID(F));
}


// Dependency from visa_igc_common_header.
// Converts vector size into LSC-appropriate code.
inline LSCVectorSize getLSCVectorSize(unsigned N) {
switch (N) {
case 0:
return LSCVectorSize::N0;
case 1:
return LSCVectorSize::N1;
case 2:
return LSCVectorSize::N2;
case 3:
return LSCVectorSize::N3;
case 4:
return LSCVectorSize::N4;
case 8:
return LSCVectorSize::N8;
case 16:
return LSCVectorSize::N16;
case 32:
return LSCVectorSize::N32;
case 64:
return LSCVectorSize::N64;
}
llvm_unreachable("Unknown vector size");
}
// Gets encoded vector size for LSC instruction.
inline uint8_t getEncodedLSCVectorSize(unsigned N) {
return static_cast<uint8_t>(getLSCVectorSize(N));
}

// Functions in this namespace return argument index for LSC instruction.
namespace LSCArgIdx {
constexpr int Invalid = -1;
// Returns VectorSize index.
inline int getLSCVectorSize(LSCCategory Cat) {
switch (Cat) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::Atomic:
return 7;
case LSCCategory::LegacyAtomic:
return 8;
case LSCCategory::Prefetch2D:
case LSCCategory::Load2D:
case LSCCategory::Store2D:
case LSCCategory::Fence:
case LSCCategory::NotLSC:
default:
llvm_unreachable("no such argument");
return Invalid;
}
}
// Returns VectorSize index.
inline int getLSCVectorSize(unsigned IID) {
return LSCArgIdx::getLSCVectorSize(getLSCCategory(IID));
}

// Returns DataSize index.
inline int getLSCDataSize(LSCCategory Cat) {
switch (Cat) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::LegacyAtomic:
case LSCCategory::Atomic:
return 6;
case LSCCategory::Load2D:
case LSCCategory::Prefetch2D:
case LSCCategory::Store2D:
return 3;
case LSCCategory::Fence:
case LSCCategory::NotLSC:
default:
llvm_unreachable("no such argument");
return Invalid;
}
}
// Returns DataSize index.
inline int getLSCDataSize(unsigned IID) {
return LSCArgIdx::getLSCDataSize(getLSCCategory(IID));
}

// Returns immediate offset index.
inline int getLSCImmOffset(LSCCategory Cat) {
switch (Cat) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::LegacyAtomic:
case LSCCategory::Atomic:
return 5;
case LSCCategory::Prefetch2D:
case LSCCategory::Load2D:
case LSCCategory::Store2D:
case LSCCategory::Fence:
case LSCCategory::NotLSC:
default:
llvm_unreachable("no such argument");
return Invalid;
}
}
// Returns immediate offset index.
inline int getLSCImmOffset(unsigned IID) {
return LSCArgIdx::getLSCImmOffset(getLSCCategory(IID));
}

// Returns data order index.
inline int getLSCDataOrder(LSCCategory Cat) {
switch (Cat) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::Atomic:
return 8;
case LSCCategory::LegacyAtomic:
return 7;
case LSCCategory::Load2D:
case LSCCategory::Prefetch2D:
case LSCCategory::Store2D:
return 4;
case LSCCategory::Fence:
case LSCCategory::NotLSC:
default:
llvm_unreachable("no such argument");
return Invalid;
}
}
// Returns data order index.
inline int getLSCDataOrder(unsigned IID) {
return LSCArgIdx::getLSCDataOrder(getLSCCategory(IID));
}

// Returns width index.
inline int getLSCWidth(LSCCategory Cat) {
switch (Cat) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::Fence:
case LSCCategory::LegacyAtomic:
case LSCCategory::Atomic:
case LSCCategory::Prefetch2D:
return 0;
case LSCCategory::Load2D:
case LSCCategory::Store2D:
case LSCCategory::NotLSC:
default:
llvm_unreachable("no such argument");
return Invalid;
}
}
// Returns width index.
inline int getLSCWidth(unsigned IID) {
return LSCArgIdx::getLSCWidth(getLSCCategory(IID));
}

} // namespace LSCArgIdx

inline unsigned getLSCNumVectorElements(LSCVectorSize VS) {
switch (VS) {
case LSCVectorSize::N0:
Expand Down
95 changes: 21 additions & 74 deletions GenXIntrinsics/lib/GenXIntrinsics/GenXIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,93 +688,40 @@ std::string GenXIntrinsic::getAnyName(unsigned id, ArrayRef<Type *> Tys) {
GenXIntrinsic::LSCVectorSize GenXIntrinsic::getLSCVectorSize(
const Instruction *I) {
assert(isLSC(I));
switch (getLSCCategory(I)) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::Atomic:
return static_cast<LSCVectorSize>(
cast<ConstantInt>(I->getOperand(7))->getZExtValue());
case LSCCategory::LegacyAtomic:
return static_cast<LSCVectorSize>(
cast<ConstantInt>(I->getOperand(8))->getZExtValue());
case LSCCategory::Fence:
case LSCCategory::Load2D:
case LSCCategory::Prefetch2D:
case LSCCategory::Store2D:
case LSCCategory::NotLSC:
return LSCVectorSize::N0;
}
llvm_unreachable("Unknown LSC category");
const int VectorSizeIdx = LSCArgIdx::getLSCVectorSize(getLSCCategory(I));
if (VectorSizeIdx == LSCArgIdx::Invalid)
return LSCVectorSize::N0;
return static_cast<LSCVectorSize>(
cast<ConstantInt>(I->getOperand(VectorSizeIdx))->getZExtValue());
}

GenXIntrinsic::LSCDataSize GenXIntrinsic::getLSCDataSize(
const Instruction *I) {
assert(isLSC(I));
switch (getLSCCategory(I)) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::LegacyAtomic:
case LSCCategory::Atomic:
return static_cast<LSCDataSize>(
cast<ConstantInt>(I->getOperand(6))->getZExtValue());
case LSCCategory::Load2D:
case LSCCategory::Prefetch2D:
case LSCCategory::Store2D:
return static_cast<LSCDataSize>(
cast<ConstantInt>(I->getOperand(3))->getZExtValue());
case LSCCategory::Fence:
case LSCCategory::NotLSC:
return LSCDataSize::Invalid;
}
llvm_unreachable("Unknown LSC category");
const int DataSizeIdx = LSCArgIdx::getLSCDataSize(getLSCCategory(I));
if (DataSizeIdx == LSCArgIdx::Invalid)
return LSCDataSize::Invalid;
return static_cast<LSCDataSize>(
cast<ConstantInt>(I->getOperand(DataSizeIdx))->getZExtValue());
}

GenXIntrinsic::LSCDataOrder GenXIntrinsic::getLSCDataOrder(
const Instruction *I) {
assert(isLSC(I));
switch (getLSCCategory(I)) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::Atomic:
return static_cast<LSCDataOrder>(
cast<ConstantInt>(I->getOperand(8))->getZExtValue());
case LSCCategory::LegacyAtomic:
return static_cast<LSCDataOrder>(
cast<ConstantInt>(I->getOperand(7))->getZExtValue());
case LSCCategory::Load2D:
case LSCCategory::Prefetch2D:
case LSCCategory::Store2D:
return static_cast<LSCDataOrder>(
cast<ConstantInt>(I->getOperand(4))->getZExtValue());
case LSCCategory::Fence:
case LSCCategory::NotLSC:
return LSCDataOrder::Invalid;
}
llvm_unreachable("Unknown LSC category");
const int DataOrderIdx = LSCArgIdx::getLSCDataOrder(getLSCCategory(I));
if (DataOrderIdx == LSCArgIdx::Invalid)
return LSCDataOrder::Invalid;
return static_cast<LSCDataOrder>(
cast<ConstantInt>(I->getOperand(DataOrderIdx))->getZExtValue());
}

unsigned GenXIntrinsic::getLSCWidth(const Instruction *I) {
assert(isLSC(I));
switch(getLSCCategory(I)) {
case LSCCategory::Load:
case LSCCategory::Prefetch:
case LSCCategory::Store:
case LSCCategory::Fence:
case LSCCategory::LegacyAtomic:
case LSCCategory::Atomic: {
case LSCCategory::Prefetch2D:
if (auto VT = dyn_cast<VectorType>(I->getOperand(0)->getType()))
return VCINTR::VectorType::getNumElements(VT);
return 1;
}
case LSCCategory::Load2D:
case LSCCategory::Store2D:
case LSCCategory::NotLSC:
return 1;
}
llvm_unreachable("Unknown LSC category");
const int WidthIdx = LSCArgIdx::getLSCWidth(getLSCCategory(I));
if (WidthIdx == LSCArgIdx::Invalid)
return 1;
if (auto VT = dyn_cast<VectorType>(I->getOperand(WidthIdx)->getType()))
return VCINTR::VectorType::getNumElements(VT);
return 1;
}

0 comments on commit c97396d

Please sign in to comment.