Skip to content

Commit f727f4d

Browse files
jcranmer-intelsvenvh
authored andcommitted
Remove more getPointerElementType queries.
Most of this tranche of calls were being used to disambiguate between different built-ins that share the same or similar names. The exception is the change in visitCallSPIRVPipeBuiltin, which is a convoluted way of adding a cast to i8 addrspace(4)* if not already i8 addrspace(4)*, so it is instead rewritten to check if a cast needs to be added without querying getPointerElementType.
1 parent 55d1de8 commit f727f4d

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

lib/SPIRV/OCLToSPIRV.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,10 +1743,11 @@ static const char *getSubgroupAVCIntelOpKind(StringRef Name) {
17431743
.StartsWith(kOCLSubgroupsAVCIntel::SICPrefix, "sic");
17441744
}
17451745

1746-
static const char *getSubgroupAVCIntelTyKind(Type *Ty) {
1747-
auto *STy = cast<StructType>(cast<PointerType>(Ty)->getPointerElementType());
1748-
auto TName = STy->getName();
1749-
return TName.endswith("_payload_t") ? "payload" : "result";
1746+
static const char *getSubgroupAVCIntelTyKind(StringRef MangledName) {
1747+
// We're looking for the type name of the last parameter, which will be at the
1748+
// very end of the mangled name. Since we only care about the ending of the
1749+
// name, we don't need to be any more clever than this.
1750+
return MangledName.endswith("_payload_t") ? "payload" : "result";
17501751
}
17511752

17521753
static Type *getSubgroupAVCIntelMCEType(Module *M, std::string &TName) {
@@ -1778,11 +1779,9 @@ void OCLToSPIRVBase::visitSubgroupAVCBuiltinCall(CallInst *CI,
17781779

17791780
// Update names for built-ins mapped on two or more SPIRV instructions
17801781
if (FName.find(Prefix + "ime_get_streamout_major_shape_") == 0) {
1781-
auto PTy = cast<PointerType>(CI->getArgOperand(0)->getType());
1782-
auto *STy = cast<StructType>(PTy->getPointerElementType());
1783-
assert(STy->hasName() && "Invalid Subgroup AVC Intel built-in call");
1784-
FName += (STy->getName().contains("single")) ? "_single_reference"
1785-
: "_dual_reference";
1782+
// _single_reference functions have 2 arguments, _dual_reference have 3
1783+
// arguments.
1784+
FName += (CI->arg_size() == 2) ? "_single_reference" : "_dual_reference";
17861785
} else if (FName.find(Prefix + "sic_configure_ipe") == 0) {
17871786
FName += (CI->arg_size() == 8) ? "_luma" : "_luma_chroma";
17881787
}
@@ -1818,8 +1817,8 @@ void OCLToSPIRVBase::visitSubgroupAVCWrapperBuiltinCall(
18181817
// Find 'to_mce' conversion function.
18191818
// The operand required conversion is always the last one.
18201819
const char *OpKind = getSubgroupAVCIntelOpKind(DemangledName);
1821-
const char *TyKind = getSubgroupAVCIntelTyKind(
1822-
CI->getArgOperand(CI->arg_size() - 1)->getType());
1820+
const char *TyKind =
1821+
getSubgroupAVCIntelTyKind(CI->getCalledFunction()->getName());
18231822
std::string MCETName =
18241823
std::string(kOCLSubgroupsAVCIntel::TypePrefix) + "mce_" + TyKind + "_t";
18251824
auto *MCETy =

lib/SPIRV/SPIRVToOCL.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,8 @@ void SPIRVToOCLBase::visitCallSPIRVPipeBuiltin(CallInst *CI, Op OC) {
580580
auto &P = Args[Args.size() - 3];
581581
auto T = P->getType();
582582
assert(isa<PointerType>(T));
583-
auto ET = T->getPointerElementType();
584-
if (!ET->isIntegerTy(8) ||
585-
T->getPointerAddressSpace() != SPIRAS_Generic) {
586-
auto NewTy = PointerType::getInt8PtrTy(*Ctx, SPIRAS_Generic);
583+
auto *NewTy = PointerType::getInt8PtrTy(*Ctx, SPIRAS_Generic);
584+
if (T != NewTy) {
587585
P = CastInst::CreatePointerBitCastOrAddrSpaceCast(P, NewTy, "", CI);
588586
}
589587
return DemangledName;
@@ -926,15 +924,17 @@ void SPIRVToOCLBase::visitCallSPIRVAvcINTELEvaluateBuiltIn(CallInst *CI,
926924
// reference image
927925
// 3. With single reference image - uses one OpVmeImageINTEL opcode for
928926
// reference image
929-
int NumImages = std::count_if(Args.begin(), Args.end(), [](Value *Arg) {
930-
if (auto *PT = dyn_cast<PointerType>(Arg->getType())) {
931-
if (auto *ST = dyn_cast<StructType>(PT->getPointerElementType())) {
932-
if (ST->getName().startswith("spirv.VmeImageINTEL"))
933-
return true;
934-
}
935-
}
936-
return false;
937-
});
927+
StringRef FnName = CI->getCalledFunction()->getName();
928+
int NumImages = 0;
929+
if (FnName.contains("SingleReference"))
930+
NumImages = 2;
931+
else if (FnName.contains("DualReference"))
932+
NumImages = 3;
933+
else if (FnName.contains("MultiReference"))
934+
NumImages = 1;
935+
else if (FnName.contains("EvaluateIpe"))
936+
NumImages = 1;
937+
938938
auto EraseVmeImageCall = [](CallInst *CI) {
939939
if (CI->hasOneUse()) {
940940
CI->replaceAllUsesWith(UndefValue::get(CI->getType()));

0 commit comments

Comments
 (0)