@@ -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+
19801981static std::vector<uint32_t >
19811982getMetaDataValues (std::vector<llvm::MDNode *> &MetaDataList) {
19821983 std::vector<uint32_t > res;
@@ -1998,23 +1999,10 @@ getMetaDataValues(std::vector<llvm::MDNode *> &MetaDataList) {
19981999static 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,
2003+ MachineInstr &MI) {
2004+ Register Des = MI.getOperand (0 ).getReg ();
2005+ MachineInstr *curr = &MI;
20182006 // dsp controll
20192007 if (llvm::MDNode *Node = F->getMetadata (" prefer_dsp" )) {
20202008 std::vector<llvm::MDNode *> MetaDataList;
@@ -2024,25 +2012,29 @@ static void handleFunctionDecoration(llvm::Module::const_iterator F,
20242012 if (ST.canUseExtension (
20252013 SPIRV::Extension::Extension::SPV_INTEL_fpga_dsp_control)) {
20262014 std::vector<uint32_t > params = getMetaDataValues (MetaDataList);
2027- params.push_back (0 );
2015+ if (params.size () == 1 )
2016+ params.push_back (0 );
20282017 buildOpDecorate (Des, *curr, TII, SPIRV::Decoration::MathOpDSPModeINTEL,
20292018 params);
20302019 }
20312020 }
20322021}
20332022
2034- // Walk all functions and add decorations related to MI flags.
2023+ // Walk all functions and add decorations related to MI flags and function metadata .
20352024static void addDecorations (const Module &M, const SPIRVInstrInfo &TII,
20362025 MachineModuleInfo *MMI, const SPIRVSubtarget &ST,
20372026 SPIRV::ModuleAnalysisInfo &MAI) {
20382027 for (auto F = M.begin (), E = M.end (); F != E; ++F) {
20392028 MachineFunction *MF = MMI->getMachineFunction (*F);
20402029 if (!MF)
20412030 continue ;
2042- for (auto &MBB : *MF)
2043- for (auto &MI : MBB)
2031+ for (auto &MBB : *MF) {
2032+ for (auto &MI : MBB) {
2033+ if (MI.getOpcode () == SPIRV::OpFunction)
2034+ handleFunctionDecoration (F, TII, MMI, ST, MI);
20442035 handleMIFlagDecoration (MI, ST, TII, MAI.Reqs );
2045- handleFunctionDecoration (F, TII, MMI, ST);
2036+ }
2037+ }
20462038 }
20472039}
20482040
0 commit comments