Skip to content

Commit

Permalink
Replace add-, get-, has-, removeAttribute by related methods. (Khrono…
Browse files Browse the repository at this point in the history
  • Loading branch information
KornevNikita authored Sep 6, 2021
1 parent 6cef1d1 commit 6eb3848
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 36 deletions.
6 changes: 2 additions & 4 deletions lib/SPIRV/PreprocessMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ void PreprocessMetadataBase::preprocessVectorComputeMetadata(Module *M,
auto Attrs = F.getAttributes();
if (Attrs.hasFnAttr(kVCMetadata::VCFloatControl)) {
SPIRVWord Mode = 0;
Attrs
.getAttribute(AttributeList::FunctionIndex,
kVCMetadata::VCFloatControl)
Attrs.getFnAttr(kVCMetadata::VCFloatControl)
.getValueAsString()
.getAsInteger(0, Mode);
spv::ExecutionMode ExecRoundMode =
Expand All @@ -344,7 +342,7 @@ void PreprocessMetadataBase::preprocessVectorComputeMetadata(Module *M,
}
if (Attrs.hasFnAttr(kVCMetadata::VCSLMSize)) {
SPIRVWord SLMSize = 0;
Attrs.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCSLMSize)
Attrs.getFnAttr(kVCMetadata::VCSLMSize)
.getValueAsString()
.getAsInteger(0, SLMSize);
EM.addOp()
Expand Down
10 changes: 5 additions & 5 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3878,7 +3878,7 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {

auto SEVAttr = Attribute::get(*Context, kVCMetadata::VCSingleElementVector);
if (BF->hasDecorate(DecorationSingleElementVectorINTEL))
F->addAttribute(AttributeList::ReturnIndex, SEVAttr);
F->addAttributeAtIndex(AttributeList::ReturnIndex, SEVAttr);

for (Function::arg_iterator I = F->arg_begin(), E = F->arg_end(); I != E;
++I) {
Expand All @@ -3888,10 +3888,10 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
if (BA->hasDecorate(DecorationFuncParamIOKindINTEL, 0, &Kind)) {
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCArgumentIOKind,
std::to_string(Kind));
F->addAttribute(ArgNo + 1, Attr);
F->addParamAttr(ArgNo, Attr);
}
if (BA->hasDecorate(DecorationSingleElementVectorINTEL))
F->addAttribute(ArgNo + 1, SEVAttr);
F->addParamAttr(ArgNo, SEVAttr);
}

// Do not add float control if there is no any
Expand Down Expand Up @@ -3991,14 +3991,14 @@ bool SPIRVToLLVM::transVectorComputeMetadata(SPIRVFunction *BF) {
if (IsVCFloatControl) {
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCFloatControl,
std::to_string(FloatControl));
F->addAttribute(AttributeList::FunctionIndex, Attr);
F->addFnAttr(Attr);
}

if (auto EM = BF->getExecutionMode(ExecutionModeSharedLocalMemorySizeINTEL)) {
unsigned int SLMSize = EM->getLiterals()[0];
Attribute Attr = Attribute::get(*Context, kVCMetadata::VCSLMSize,
std::to_string(SLMSize));
F->addAttribute(AttributeList::FunctionIndex, Attr);
F->addFnAttr(Attr);
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions lib/SPIRV/SPIRVToOCL12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ void SPIRVToOCL12Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {

void SPIRVToOCL12Base::visitCallSPIRVControlBarrier(CallInst *CI) {
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
Attrs = Attrs.addAttribute(CI->getContext(), AttributeList::FunctionIndex,
Attribute::Convergent);
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
mutateCallInstOCL(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Expand Down
3 changes: 1 addition & 2 deletions lib/SPIRV/SPIRVToOCL20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ void SPIRVToOCL20Base::visitCallSPIRVMemoryBarrier(CallInst *CI) {

void SPIRVToOCL20Base::visitCallSPIRVControlBarrier(CallInst *CI) {
AttributeList Attrs = CI->getCalledFunction()->getAttributes();
Attrs = Attrs.addAttribute(CI->getContext(), AttributeList::FunctionIndex,
Attribute::Convergent);
Attrs = Attrs.addFnAttribute(CI->getContext(), Attribute::Convergent);
mutateCallInstOCL(
M, CI,
[=](CallInst *, std::vector<Value *> &Args) {
Expand Down
4 changes: 2 additions & 2 deletions lib/SPIRV/SPIRVUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ cl::opt<bool, true> EnableDbgOutput("spirv-debug",
bool isSupportedTriple(Triple T) { return T.isSPIR(); }

void addFnAttr(CallInst *Call, Attribute::AttrKind Attr) {
Call->addAttribute(AttributeList::FunctionIndex, Attr);
Call->addFnAttr(Attr);
}

void removeFnAttr(CallInst *Call, Attribute::AttrKind Attr) {
Call->removeAttribute(AttributeList::FunctionIndex, Attr);
Call->removeFnAttr(Attr);
}

Value *removeCast(Value *V) {
Expand Down
38 changes: 17 additions & 21 deletions lib/SPIRV/SPIRVWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,22 +652,21 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
BA->addAttr(FunctionParameterAttributeSret);
if (I->onlyReadsMemory())
BA->addAttr(FunctionParameterAttributeNoWrite);
if (Attrs.hasAttribute(ArgNo + 1, Attribute::ZExt))
if (Attrs.hasParamAttr(ArgNo, Attribute::ZExt))
BA->addAttr(FunctionParameterAttributeZext);
if (Attrs.hasAttribute(ArgNo + 1, Attribute::SExt))
if (Attrs.hasParamAttr(ArgNo, Attribute::SExt))
BA->addAttr(FunctionParameterAttributeSext);
if (Attrs.hasAttribute(ArgNo + 1, Attribute::Alignment)) {
SPIRVWord AlignmentBytes =
Attrs.getAttribute(ArgNo + 1, Attribute::Alignment)
.getAlignment()
.valueOrOne()
.value();
if (Attrs.hasParamAttr(ArgNo, Attribute::Alignment)) {
SPIRVWord AlignmentBytes = Attrs.getParamAttr(ArgNo, Attribute::Alignment)
.getAlignment()
.valueOrOne()
.value();
BA->setAlignment(AlignmentBytes);
}
if (BM->isAllowedToUseVersion(VersionNumber::SPIRV_1_1) &&
Attrs.hasAttribute(ArgNo + 1, Attribute::Dereferenceable))
Attrs.hasParamAttr(ArgNo, Attribute::Dereferenceable))
BA->addDecorate(DecorationMaxByteOffset,
Attrs.getAttribute(ArgNo + 1, Attribute::Dereferenceable)
Attrs.getParamAttr(ArgNo, Attribute::Dereferenceable)
.getDereferenceableBytes());
if (BufferLocation && I->getType()->isPointerTy()) {
// Order of integer numbers in MD node follows the order of function
Expand All @@ -692,9 +691,9 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
BA->addDecorate(internal::DecorationRuntimeAlignedINTEL, LocID);
}
}
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::ZExt))
if (Attrs.hasRetAttr(Attribute::ZExt))
BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeZext);
if (Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::SExt))
if (Attrs.hasRetAttr(Attribute::SExt))
BF->addDecorate(DecorationFuncParamAttr, FunctionParameterAttributeSext);
if (Attrs.hasFnAttr("referenced-indirectly")) {
assert(!isKernel(F) &&
Expand Down Expand Up @@ -734,14 +733,13 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {

if (Attrs.hasFnAttr(kVCMetadata::VCSIMTCall)) {
SPIRVWord SIMTMode = 0;
Attrs.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCSIMTCall)
Attrs.getFnAttr(kVCMetadata::VCSIMTCall)
.getValueAsString()
.getAsInteger(0, SIMTMode);
BF->addDecorate(DecorationSIMTCallINTEL, SIMTMode);
}

if (Attrs.hasAttribute(AttributeList::ReturnIndex,
kVCMetadata::VCSingleElementVector)) {
if (Attrs.hasRetAttr(kVCMetadata::VCSingleElementVector)) {
auto *RT = BF->getType();
(void)RT;
assert((RT->isTypeBool() || RT->isTypeFloat() || RT->isTypeInt() ||
Expand All @@ -754,14 +752,14 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {
++I) {
auto ArgNo = I->getArgNo();
SPIRVFunctionParameter *BA = BF->getArgument(ArgNo);
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCArgumentIOKind)) {
if (Attrs.hasParamAttr(ArgNo, kVCMetadata::VCArgumentIOKind)) {
SPIRVWord Kind = {};
Attrs.getAttribute(ArgNo + 1, kVCMetadata::VCArgumentIOKind)
Attrs.getParamAttr(ArgNo, kVCMetadata::VCArgumentIOKind)
.getValueAsString()
.getAsInteger(0, Kind);
BA->addDecorate(DecorationFuncParamIOKindINTEL, Kind);
}
if (Attrs.hasAttribute(ArgNo + 1, kVCMetadata::VCSingleElementVector)) {
if (Attrs.hasParamAttr(ArgNo, kVCMetadata::VCSingleElementVector)) {
auto *AT = BA->getType();
(void)AT;
assert((AT->isTypeBool() || AT->isTypeFloat() || AT->isTypeInt() ||
Expand All @@ -775,8 +773,7 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {
Attrs.hasFnAttr(kVCMetadata::VCFloatControl)) {

SPIRVWord Mode = 0;
Attrs
.getAttribute(AttributeList::FunctionIndex, kVCMetadata::VCFloatControl)
Attrs.getFnAttr(kVCMetadata::VCFloatControl)
.getValueAsString()
.getAsInteger(0, Mode);
VCFloatTypeSizeMap::foreach (
Expand Down Expand Up @@ -1399,7 +1396,6 @@ SPIRVEntry *addMemAliasingINTELInstructions(SPIRVModule *M,
return M->getOrAddAliasScopeListDeclINTELInst(ListId, AliasingListMD);
}


// Translate alias.scope/noalias metadata attached to store and load
// instructions.
void transAliasingMemAccess(SPIRVModule *BM, MDNode *AliasingListMD,
Expand Down

0 comments on commit 6eb3848

Please sign in to comment.