Skip to content
Merged
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/IntrinsicsSPIRV.td
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ let TargetPrefix = "spv" in {
def int_spv_selection_merge : Intrinsic<[], [llvm_vararg_ty]>;
def int_spv_cmpxchg : Intrinsic<[llvm_i32_ty], [llvm_any_ty, llvm_vararg_ty]>;
def int_spv_unreachable : Intrinsic<[], []>;
def int_spv_alloca : Intrinsic<[llvm_any_ty], []>;
def int_spv_alloca_array : Intrinsic<[llvm_any_ty], [llvm_anyint_ty]>;
def int_spv_alloca : Intrinsic<[llvm_any_ty], [llvm_i8_ty], [ImmArg<ArgIndex<0>>]>;
def int_spv_alloca_array : Intrinsic<[llvm_any_ty], [llvm_anyint_ty, llvm_i8_ty], [ImmArg<ArgIndex<1>>]>;
def int_spv_undef : Intrinsic<[llvm_i32_ty], []>;
def int_spv_inline_asm : Intrinsic<[], [llvm_metadata_ty, llvm_metadata_ty, llvm_vararg_ty]>;

Expand Down
28 changes: 16 additions & 12 deletions llvm/lib/Target/SPIRV/MCTargetDesc/SPIRVBaseInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,15 @@ getSymbolicOperandMnemonic(SPIRV::OperandCategory::OperandCategory Category,
const SPIRV::SymbolicOperand *EnumValueInCategory =
SPIRV::lookupSymbolicOperandByCategory(Category);

auto TableEnd = ArrayRef(SPIRV::SymbolicOperands).end();
while (EnumValueInCategory && EnumValueInCategory->Category == Category) {
if ((EnumValueInCategory->Value != 0) &&
(Value & EnumValueInCategory->Value)) {
Name += Separator + EnumValueInCategory->Mnemonic.str();
Separator = "|";
}
++EnumValueInCategory;
if (++EnumValueInCategory == TableEnd)
break;
}

return Name;
Expand Down Expand Up @@ -115,15 +117,16 @@ getSymbolicOperandMaxVersion(SPIRV::OperandCategory::OperandCategory Category,
CapabilityList
getSymbolicOperandCapabilities(SPIRV::OperandCategory::OperandCategory Category,
uint32_t Value) {
CapabilityList Capabilities;
const SPIRV::CapabilityEntry *Capability =
SPIRV::lookupCapabilityByCategoryAndValue(Category, Value);

CapabilityList Capabilities;
auto TableEnd = ArrayRef(SPIRV::CapabilityEntries).end();
while (Capability && Capability->Category == Category &&
Capability->Value == Value) {
Capabilities.push_back(
static_cast<SPIRV::Capability::Capability>(Capability->ReqCapability));
++Capability;
if (++Capability == TableEnd)
break;
}

return Capabilities;
Expand All @@ -136,16 +139,15 @@ getCapabilitiesEnabledByExtension(SPIRV::Extension::Extension Extension) {
Extension, SPIRV::OperandCategory::CapabilityOperand);

CapabilityList Capabilities;
auto TableEnd = ArrayRef(SPIRV::ExtensionEntries).end();
while (Entry &&
Entry->Category == SPIRV::OperandCategory::CapabilityOperand) {
// Some capabilities' codes might go not in order.
if (Entry->ReqExtension != Extension) {
++Entry;
continue;
}
Capabilities.push_back(
static_cast<SPIRV::Capability::Capability>(Entry->Value));
++Entry;
if (Entry->ReqExtension == Extension)
Capabilities.push_back(
static_cast<SPIRV::Capability::Capability>(Entry->Value));
if (++Entry == TableEnd)
break;
}

return Capabilities;
Expand All @@ -158,11 +160,13 @@ getSymbolicOperandExtensions(SPIRV::OperandCategory::OperandCategory Category,
SPIRV::lookupExtensionByCategoryAndValue(Category, Value);

ExtensionList Extensions;
auto TableEnd = ArrayRef(SPIRV::ExtensionEntries).end();
while (Extension && Extension->Category == Category &&
Extension->Value == Value) {
Extensions.push_back(
static_cast<SPIRV::Extension::Extension>(Extension->ReqExtension));
++Extension;
if (++Extension == TableEnd)
break;
}

return Extensions;
Expand Down
34 changes: 24 additions & 10 deletions llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,16 +2664,7 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
return false;
}

Type *parseBuiltinCallArgumentBaseType(const StringRef DemangledCall,
unsigned ArgIdx, LLVMContext &Ctx) {
SmallVector<StringRef, 10> BuiltinArgsTypeStrs;
StringRef BuiltinArgs =
DemangledCall.slice(DemangledCall.find('(') + 1, DemangledCall.find(')'));
BuiltinArgs.split(BuiltinArgsTypeStrs, ',', -1, false);
if (ArgIdx >= BuiltinArgsTypeStrs.size())
return nullptr;
StringRef TypeStr = BuiltinArgsTypeStrs[ArgIdx].trim();

Type *parseBuiltinCallArgumentType(StringRef TypeStr, LLVMContext &Ctx) {
// Parse strings representing OpenCL builtin types.
if (hasBuiltinTypePrefix(TypeStr)) {
// OpenCL builtin types in demangled call strings have the following format:
Expand Down Expand Up @@ -2717,6 +2708,29 @@ Type *parseBuiltinCallArgumentBaseType(const StringRef DemangledCall,
return BaseType;
}

bool parseBuiltinTypeStr(SmallVector<StringRef, 10> &BuiltinArgsTypeStrs,
const StringRef DemangledCall, LLVMContext &Ctx) {
auto Pos1 = DemangledCall.find('(');
if (Pos1 == StringRef::npos)
return false;
auto Pos2 = DemangledCall.find(')');
if (Pos2 == StringRef::npos || Pos1 > Pos2)
return false;
DemangledCall.slice(Pos1 + 1, Pos2)
.split(BuiltinArgsTypeStrs, ',', -1, false);
return true;
}

Type *parseBuiltinCallArgumentBaseType(const StringRef DemangledCall,
unsigned ArgIdx, LLVMContext &Ctx) {
SmallVector<StringRef, 10> BuiltinArgsTypeStrs;
parseBuiltinTypeStr(BuiltinArgsTypeStrs, DemangledCall, Ctx);
if (ArgIdx >= BuiltinArgsTypeStrs.size())
return nullptr;
StringRef TypeStr = BuiltinArgsTypeStrs[ArgIdx].trim();
return parseBuiltinCallArgumentType(TypeStr, Ctx);
}

struct BuiltinType {
StringRef Name;
uint32_t Opcode;
Expand Down
3 changes: 3 additions & 0 deletions llvm/lib/Target/SPIRV/SPIRVBuiltins.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ mapBuiltinToOpcode(const StringRef DemangledCall,
/// \p ArgIdx is the index of the argument to parse.
Type *parseBuiltinCallArgumentBaseType(const StringRef DemangledCall,
unsigned ArgIdx, LLVMContext &Ctx);
bool parseBuiltinTypeStr(SmallVector<StringRef, 10> &BuiltinArgsTypeStrs,
const StringRef DemangledCall, LLVMContext &Ctx);
Type *parseBuiltinCallArgumentType(StringRef TypeStr, LLVMContext &Ctx);

/// Translates a string representing a SPIR-V or OpenCL builtin type to a
/// TargetExtType that can be further lowered with lowerBuiltinType().
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ bool SPIRVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,

if (Arg.hasName())
buildOpName(VRegs[i][0], Arg.getName(), MIRBuilder);
if (isPointerTy(Arg.getType())) {
if (isPointerTyOrWrapper(Arg.getType())) {
auto DerefBytes = static_cast<unsigned>(Arg.getDereferenceableBytes());
if (DerefBytes != 0)
buildOpDecorate(VRegs[i][0], MIRBuilder,
Expand Down
Loading
Loading