Skip to content

Commit e9cf054

Browse files
committed
fix
1 parent e3c1b7c commit e9cf054

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ static void addOpDecorateReqs(const MachineInstr &MI, unsigned DecIndex,
920920
} else if (Dec == SPIRV::Decoration::FPMaxErrorDecorationINTEL) {
921921
Reqs.addRequirements(SPIRV::Capability::FPMaxErrorINTEL);
922922
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_fp_max_error);
923-
}else if (Dec == SPIRV::Decoration::MathOpDSPModeINTEL) {
923+
} else if (Dec == SPIRV::Decoration::MathOpDSPModeINTEL) {
924924
Reqs.addExtension(SPIRV::Extension::Extension::SPV_INTEL_fpga_dsp_control);
925925
}
926926
}
@@ -1977,6 +1977,7 @@ static void handleMIFlagDecoration(MachineInstr &I, const SPIRVSubtarget &ST,
19771977
Register DstReg = I.getOperand(0).getReg();
19781978
buildOpDecorate(DstReg, I, TII, SPIRV::Decoration::FPFastMathMode, {FMFlags});
19791979
}
1980+
19801981
static std::vector<uint32_t>
19811982
getMetaDataValues(std::vector<llvm::MDNode *> &MetaDataList) {
19821983
std::vector<uint32_t> res;
@@ -1998,23 +1999,9 @@ getMetaDataValues(std::vector<llvm::MDNode *> &MetaDataList) {
19981999
static void handleFunctionDecoration(llvm::Module::const_iterator F,
19992000
const SPIRVInstrInfo &TII,
20002001
MachineModuleInfo *MMI,
2001-
const SPIRVSubtarget &ST) {
2002-
2003-
MachineFunction *MF = MMI->getMachineFunction(*F);
2004-
Register Des = Register();
2005-
MachineInstr *curr = nullptr;
2006-
2007-
for (auto &MBB : *MF) {
2008-
for (auto &MI : MBB) {
2009-
if (MI.getOpcode() == SPIRV::OpFunction) {
2010-
if (MI.getNumOperands() > 0 && MI.getOperand(0).isReg()) {
2011-
Des = MI.getOperand(0).getReg();
2012-
curr = &MI;
2013-
}
2014-
}
2015-
}
2016-
}
2017-
2002+
const SPIRVSubtarget &ST, MachineInstr &MI) {
2003+
Register Des = MI.getOperand(0).getReg();
2004+
MachineInstr *curr = &MI;
20182005
// dsp controll
20192006
if (llvm::MDNode *Node = F->getMetadata("prefer_dsp")) {
20202007
std::vector<llvm::MDNode *> MetaDataList;
@@ -2024,25 +2011,29 @@ static void handleFunctionDecoration(llvm::Module::const_iterator F,
20242011
if (ST.canUseExtension(
20252012
SPIRV::Extension::Extension::SPV_INTEL_fpga_dsp_control)) {
20262013
std::vector<uint32_t> params = getMetaDataValues(MetaDataList);
2027-
params.push_back(0);
2014+
if (params.size() == 1)
2015+
params.push_back(0);
20282016
buildOpDecorate(Des, *curr, TII, SPIRV::Decoration::MathOpDSPModeINTEL,
20292017
params);
20302018
}
20312019
}
20322020
}
20332021

2034-
// Walk all functions and add decorations related to MI flags.
2022+
// Walk all functions and add decorations related to MI flags and function metadata.
20352023
static void addDecorations(const Module &M, const SPIRVInstrInfo &TII,
20362024
MachineModuleInfo *MMI, const SPIRVSubtarget &ST,
20372025
SPIRV::ModuleAnalysisInfo &MAI) {
20382026
for (auto F = M.begin(), E = M.end(); F != E; ++F) {
20392027
MachineFunction *MF = MMI->getMachineFunction(*F);
20402028
if (!MF)
20412029
continue;
2042-
for (auto &MBB : *MF)
2043-
for (auto &MI : MBB)
2030+
for (auto &MBB : *MF) {
2031+
for (auto &MI : MBB) {
2032+
if (MI.getOpcode() == SPIRV::OpFunction)
2033+
handleFunctionDecoration(F, TII, MMI, ST, MI);
20442034
handleMIFlagDecoration(MI, ST, TII, MAI.Reqs);
2045-
handleFunctionDecoration(F, TII, MMI, ST);
2035+
}
2036+
}
20462037
}
20472038
}
20482039

0 commit comments

Comments
 (0)