[SPIR-V] Use MapVector for per function maps (#239349) Iterating a DenseMap keyed by Function pointers made the order of FPFastMathDefault execution modes and their constants may vary between runs with SPV_KHR_float_controls2
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp index 836d60b..a0b0bca 100644 --- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -19,6 +19,7 @@ #include "SPIRVUtils.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" +#include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" @@ -197,7 +198,7 @@ SmallPtrSet<Value *, 0> Named; // map of function declarations to <pointer arg index => element type> - DenseMap<Function *, SmallVector<std::pair<unsigned, Type *>>> FDeclPtrTys; + MapVector<Function *, SmallVector<std::pair<unsigned, Type *>>> FDeclPtrTys; // a register of Instructions that don't have a complete type definition bool CanTodoType = true; @@ -3189,7 +3190,7 @@ static SPIRV::FPFastMathDefaultInfoVector &getOrCreateFPFastMathDefaultInfoVec( const Module &M, - DenseMap<Function *, SPIRV::FPFastMathDefaultInfoVector> + MapVector<Function *, SPIRV::FPFastMathDefaultInfoVector> &FPFastMathDefaultInfoMap, Function *F) { auto it = FPFastMathDefaultInfoMap.find(F); @@ -3263,7 +3264,7 @@ // type. The first element is the smallest bit width, and the last element // is the largest bit width, therefore, we will have {half, float, double} // in the order of their bit widths. - DenseMap<Function *, SPIRV::FPFastMathDefaultInfoVector> + MapVector<Function *, SPIRV::FPFastMathDefaultInfoVector> FPFastMathDefaultInfoMap; for (unsigned i = 0; i < Node->getNumOperands(); i++) {
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h index 8fd9052..a9150e0 100644 --- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h +++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.h
@@ -18,6 +18,7 @@ #include "SPIRVGlobalRegistry.h" #include "SPIRVUtils.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/MapVector.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/IR/PassManager.h" @@ -131,7 +132,7 @@ using RegisterAliasMapTy = std::map<const MachineFunction *, LocalToGlobalRegTable>; using FPFastMathDefaultInfoMapTy = - DenseMap<const Function *, FPFastMathDefaultInfoVector>; + MapVector<const Function *, FPFastMathDefaultInfoVector>; // The struct contains results of the module analysis and methods // to access them.