Skip to content
Merged
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
117 changes: 71 additions & 46 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2059,36 +2059,42 @@ void addFuncPointerCallArgumentAttributes(CallInst *CI,

#define ONE_STRING_DECORATION_CASE(NAME, NAMESPACE) \
case NAMESPACE::Decoration##NAME: { \
assert(NumOperands == 2 && #NAME " requires exactly 1 extra operand"); \
ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule, \
#NAME " requires exactly 1 extra operand"); \
auto *StrDecoEO = dyn_cast<MDString>(DecoMD->getOperand(1)); \
assert(StrDecoEO &&#NAME " requires extra operand to be a string"); \
ErrLog.checkError(StrDecoEO, SPIRVEC_InvalidLlvmModule, \
#NAME " requires extra operand to be a string"); \
Target->addDecorate( \
new SPIRVDecorate##NAME##Attr(Target, StrDecoEO->getString().str())); \
break; \
}

#define ONE_INT_DECORATION_CASE(NAME, NAMESPACE, TYPE) \
case NAMESPACE::Decoration##NAME: { \
assert(NumOperands == 2 && #NAME " requires exactly 1 extra operand"); \
ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule, \
#NAME " requires exactly 1 extra operand"); \
auto *IntDecoEO = \
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1)); \
assert(IntDecoEO &&#NAME " requires extra operand to be an integer"); \
ErrLog.checkError(IntDecoEO, SPIRVEC_InvalidLlvmModule, \
#NAME " requires extra operand to be an integer"); \
Target->addDecorate(new SPIRVDecorate##NAME( \
Target, static_cast<TYPE>(IntDecoEO->getZExtValue()))); \
break; \
}

#define TWO_INT_DECORATION_CASE(NAME, NAMESPACE, TYPE1, TYPE2) \
case NAMESPACE::Decoration##NAME: { \
assert(NumOperands == 3 && #NAME " requires exactly 2 extra operand"); \
ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule, \
#NAME " requires exactly 2 extra operands"); \
auto *IntDecoEO1 = \
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1)); \
assert(IntDecoEO1 &&#NAME \
" requires first extra operand to be an integer"); \
ErrLog.checkError(IntDecoEO1, SPIRVEC_InvalidLlvmModule, \
#NAME " requires first extra operand to be an integer"); \
auto *IntDecoEO2 = \
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(2)); \
assert(IntDecoEO2 &&#NAME \
" requires second extra operand to be an integer"); \
ErrLog.checkError(IntDecoEO2, SPIRVEC_InvalidLlvmModule, \
#NAME \
" requires second extra operand to be an integer"); \
Target->addDecorate(new SPIRVDecorate##NAME( \
Target, static_cast<TYPE1>(IntDecoEO1->getZExtValue()), \
static_cast<TYPE2>(IntDecoEO2->getZExtValue()))); \
Expand All @@ -2109,16 +2115,20 @@ void checkIsGlobalVar(SPIRVEntry *E, Decoration Dec) {
}

static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
SPIRVErrorLog &ErrLog = Target->getErrorLog();

auto *ArgDecoMD = dyn_cast<MDNode>(MD);
assert(ArgDecoMD && "Decoration list must be a metadata node");
for (unsigned I = 0, E = ArgDecoMD->getNumOperands(); I != E; ++I) {
auto *DecoMD = dyn_cast<MDNode>(ArgDecoMD->getOperand(I));
assert(DecoMD && "Decoration does not name metadata");
assert(DecoMD->getNumOperands() > 0 &&
"Decoration metadata must have at least one operand");
ErrLog.checkError(DecoMD, SPIRVEC_InvalidLlvmModule,
"Decoration does not name metadata");
ErrLog.checkError(DecoMD->getNumOperands() > 0, SPIRVEC_InvalidLlvmModule,
"Decoration metadata must have at least one operand");
auto *DecoKindConst =
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(0));
assert(DecoKindConst && "First operand of decoration must be the kind");
ErrLog.checkError(DecoKindConst, SPIRVEC_InvalidLlvmModule,
"First operand of decoration must be the kind");
auto DecoKind = static_cast<Decoration>(DecoKindConst->getZExtValue());

const size_t NumOperands = DecoMD->getNumOperands();
Expand All @@ -2145,25 +2155,31 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
break;
}
case DecorationMergeINTEL: {
assert(NumOperands == 3 && "MergeINTEL requires exactly 3 extra operand");
ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
"MergeINTEL requires exactly 3 extra operands");
auto *Name = dyn_cast<MDString>(DecoMD->getOperand(1));
assert(Name && "MergeINTEL requires first extra operand to be a string");
ErrLog.checkError(
Name, SPIRVEC_InvalidLlvmModule,
"MergeINTEL requires first extra operand to be a string");
auto *Direction = dyn_cast<MDString>(DecoMD->getOperand(2));
assert(Direction &&
"MergeINTEL requires second extra operand to be a string");
ErrLog.checkError(
Direction, SPIRVEC_InvalidLlvmModule,
"MergeINTEL requires second extra operand to be a string");
Target->addDecorate(new SPIRVDecorateMergeINTELAttr(
Target, Name->getString().str(), Direction->getString().str()));
break;
}
case DecorationLinkageAttributes: {
assert(NumOperands == 3 &&
"LinkageAttributes requires exactly 3 extra operand");
ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
"LinkageAttributes requires exactly 3 extra operands");
auto *Name = dyn_cast<MDString>(DecoMD->getOperand(1));
assert(Name &&
"LinkageAttributes requires first extra operand to be a string");
ErrLog.checkError(
Name, SPIRVEC_InvalidLlvmModule,
"LinkageAttributes requires first extra operand to be a string");
auto *Type = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(2));
assert(Type &&
"LinkageAttributes requires second extra operand to be an int");
ErrLog.checkError(
Type, SPIRVEC_InvalidLlvmModule,
"LinkageAttributes requires second extra operand to be an int");
auto TypeKind = static_cast<SPIRVLinkageTypeKind>(Type->getZExtValue());
Target->addDecorate(new SPIRVDecorateLinkageAttr(
Target, Name->getString().str(), TypeKind));
Expand All @@ -2172,44 +2188,49 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {
case spv::internal::DecorationHostAccessINTEL: {
checkIsGlobalVar(Target, DecoKind);

assert(NumOperands == 3 && "HostAccessINTEL requires 2 extra operands "
"after the decoration kind number");
ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
"HostAccessINTEL requires exactly 2 extra operands "
"after the decoration kind number");
auto *AccessMode =
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
assert(AccessMode &&
"HostAccessINTEL requires first extra operand to be an int");
ErrLog.checkError(
AccessMode, SPIRVEC_InvalidLlvmModule,
"HostAccessINTEL requires first extra operand to be an int");
auto *Name = dyn_cast<MDString>(DecoMD->getOperand(2));
assert(Name &&
"HostAccessINTEL requires second extra operand to be a string");
ErrLog.checkError(
Name, SPIRVEC_InvalidLlvmModule,
"HostAccessINTEL requires second extra operand to be a string");

Target->addDecorate(new SPIRVDecorateHostAccessINTEL(
Target, AccessMode->getZExtValue(), Name->getString().str()));
break;
}
case spv::internal::DecorationInitModeINTEL: {
checkIsGlobalVar(Target, DecoKind);
assert(static_cast<SPIRVVariable *>(Target)->getInitializer() &&
"InitModeINTEL only be applied to a global (module scope) "
"variable which has an Initializer operand");
ErrLog.checkError(static_cast<SPIRVVariable *>(Target)->getInitializer(),
SPIRVEC_InvalidLlvmModule,
"InitModeINTEL only be applied to a global (module "
"scope) variable which has an Initializer operand");

assert(NumOperands == 2 &&
"InitModeINTEL requires exactly 1 extra operand");
ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule,
"InitModeINTEL requires exactly 1 extra operand");
auto *Trigger = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
assert(Trigger &&
"InitModeINTEL requires extra operand to be an integer");
ErrLog.checkError(
Trigger, SPIRVEC_InvalidLlvmModule,
"InitModeINTEL requires extra operand to be an integer");

Target->addDecorate(
new SPIRVDecorateInitModeINTEL(Target, Trigger->getZExtValue()));
break;
}
case spv::internal::DecorationImplementInCSRINTEL: {
checkIsGlobalVar(Target, DecoKind);

assert(NumOperands == 2 &&
"ImplementInCSRINTEL requires exactly 1 extra operand");
ErrLog.checkError(NumOperands == 2, SPIRVEC_InvalidLlvmModule,
"ImplementInCSRINTEL requires exactly 1 extra operand");
auto *Value = mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
assert(Value &&
"ImplementInCSRINTEL requires extra operand to be an integer");
ErrLog.checkError(
Value, SPIRVEC_InvalidLlvmModule,
"ImplementInCSRINTEL requires extra operand to be an integer");

Target->addDecorate(
new SPIRVDecorateImplementInCSRINTEL(Target, Value->getZExtValue()));
Expand All @@ -2223,8 +2244,9 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {

auto *DecoValEO1 =
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(1));
assert(DecoValEO1 &&
"First extra operand in default decoration case must be integer.");
ErrLog.checkError(
DecoValEO1, SPIRVEC_InvalidLlvmModule,
"First extra operand in default decoration case must be integer.");
if (NumOperands == 2) {
Target->addDecorate(
new SPIRVDecorate(DecoKind, Target, DecoValEO1->getZExtValue()));
Expand All @@ -2233,9 +2255,12 @@ static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target) {

auto *DecoValEO2 =
mdconst::dyn_extract<ConstantInt>(DecoMD->getOperand(2));
assert(DecoValEO2 &&
"First extra operand in default decoration case must be integer.");
assert(NumOperands == 3 && "At most 2 extra operands expected.");
ErrLog.checkError(
DecoValEO2, SPIRVEC_InvalidLlvmModule,
"Second extra operand in default decoration case must be integer.");

ErrLog.checkError(NumOperands == 3, SPIRVEC_InvalidLlvmModule,
"At most 2 extra operands expected.");
Target->addDecorate(new SPIRVDecorate(DecoKind, Target,
DecoValEO1->getZExtValue(),
DecoValEO2->getZExtValue()));
Expand Down