Skip to content

Commit 97347d7

Browse files
dwoodwor-intelKornevNikita
authored andcommitted
Member initialization and code cleanup
This is a collection of small fixes to make the code more static analyzer-friendly: * Added initialization to some previously-uninitialized fields to make sure they have sensible "null" values even when the full constructor isn't called. * Removed the CU member from SPIRVToLLVMDbgTran since its only use was effectively as a local variable in SPIRVToLLVMDbgTran::transCompileUnit and so it didn't need to be a member variable. * Removed the unnecessary initialize method from LLVMParallelAccessIndices in SPIRVWriter and moved initialization logic to the constructor. Original commit: KhronosGroup/SPIRV-LLVM-Translator@4a7804b
1 parent fccd293 commit 97347d7

File tree

9 files changed

+15
-18
lines changed

9 files changed

+15
-18
lines changed

llvm-spirv/lib/SPIRV/LLVMToSPIRVDbgTran.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class LLVMToSPIRVDbgTran {
154154
DebugInfoFinder DIF;
155155
SPIRVType *VoidT;
156156
SPIRVEntry *DebugInfoNone;
157-
SPIRVExtInst *SPIRVCU;
157+
SPIRVExtInst *SPIRVCU = nullptr;
158158
std::vector<const DbgVariableIntrinsic *> DbgDeclareIntrinsics;
159159
std::vector<const DbgVariableIntrinsic *> DbgValueIntrinsics;
160160
}; // class LLVMToSPIRVDbgTran

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ SPIRVToLLVMDbgTran::transCompileUnit(const SPIRVExtInst *DebugInst) {
129129
M->addModuleFlag(llvm::Module::Max, "Dwarf Version", Ops[DWARFVersionIdx]);
130130
unsigned SourceLang = convertSPIRVSourceLangToDWARF(Ops[LanguageIdx]);
131131
auto Producer = findModuleProducer();
132-
CU = Builder.createCompileUnit(SourceLang, getFile(Ops[SourceIdx]), Producer,
133-
false, "", 0);
134-
return CU;
132+
return Builder.createCompileUnit(SourceLang, getFile(Ops[SourceIdx]),
133+
Producer, false, "", 0);
135134
}
136135

137136
DIBasicType *SPIRVToLLVMDbgTran::transTypeBasic(const SPIRVExtInst *DebugInst) {

llvm-spirv/lib/SPIRV/SPIRVToLLVMDbgTran.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ class SPIRVToLLVMDbgTran {
152152
Module *M;
153153
DIBuilder Builder;
154154
SPIRVToLLVM *SPIRVReader;
155-
DICompileUnit *CU;
156155
bool Enable;
157156
std::unordered_map<std::string, DIFile *> FileMap;
158157
std::unordered_map<SPIRVId, DISubprogram *> FuncMap;

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,7 @@ SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
734734
SPIRVType *RT = transType(F->getReturnType());
735735
std::vector<SPIRVType *> PT;
736736
for (Argument &Arg : F->args()) {
737+
assert(OCLTypeToSPIRVPtr);
737738
Type *Ty = OCLTypeToSPIRVPtr->getAdaptedArgumentType(F, Arg.getArgNo());
738739
if (!Ty) {
739740
Ty = Arg.getType();
@@ -1347,9 +1348,8 @@ class LLVMParallelAccessIndices {
13471348
public:
13481349
LLVMParallelAccessIndices(
13491350
MDNode *Node, LLVMToSPIRVBase::LLVMToSPIRVMetadataMap &IndexGroupArrayMap)
1350-
: Node(Node), IndexGroupArrayMap(IndexGroupArrayMap) {}
1351+
: Node(Node), IndexGroupArrayMap(IndexGroupArrayMap) {
13511352

1352-
void initialize() {
13531353
assert(isValid() &&
13541354
"LLVMParallelAccessIndices initialized from an invalid MDNode");
13551355

@@ -1480,7 +1480,6 @@ LLVMToSPIRVBase::getLoopControl(const BranchInst *Branch,
14801480
} else if (S == "llvm.loop.parallel_access_indices") {
14811481
// Intel FPGA IVDep loop attribute
14821482
LLVMParallelAccessIndices IVDep(Node, IndexGroupArrayMap);
1483-
IVDep.initialize();
14841483
// Store IVDep-specific parameters into an intermediate
14851484
// container to address the case when there're multiple
14861485
// IVDep metadata nodes and this condition gets entered multiple

llvm-spirv/lib/SPIRV/SPIRVWriter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class LLVMToSPIRVBase : protected BuiltinCallHelper {
182182
SPIRVWord SrcLangVer;
183183
std::unique_ptr<LLVMToSPIRVDbgTran> DbgTran;
184184
std::unique_ptr<CallGraph> CG;
185-
OCLTypeToSPIRVBase *OCLTypeToSPIRVPtr;
185+
OCLTypeToSPIRVBase *OCLTypeToSPIRVPtr = nullptr;
186186
std::vector<llvm::Instruction *> UnboundInst;
187187
std::unique_ptr<SPIRVTypeScavenger> Scavenger;
188188

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVAsm.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ class SPIRVAsmINTEL : public SPIRVValue {
8989
assert(WordCount > FixedWC);
9090
assert(OpCode == OC);
9191
}
92-
SPIRVAsmTargetINTEL *Target;
93-
SPIRVTypeFunction *FunctionType;
92+
SPIRVAsmTargetINTEL *Target = nullptr;
93+
SPIRVTypeFunction *FunctionType = nullptr;
9494
std::string Instructions;
9595
std::string Constraints;
9696
};
@@ -134,7 +134,7 @@ class SPIRVAsmCallINTEL : public SPIRVInstruction {
134134
assert(getBasicBlock() && "Invalid BB");
135135
assert(getBasicBlock()->getModule() == Asm->getModule());
136136
}
137-
SPIRVAsmINTEL *Asm;
137+
SPIRVAsmINTEL *Asm = nullptr;
138138
std::vector<SPIRVWord> Args;
139139
};
140140

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVEntry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ class SPIRVEntryPoint : public SPIRVAnnotation<OpEntryPoint> {
535535

536536
_SPIRV_DCL_ENCDEC
537537
protected:
538-
SPIRVExecutionModelKind ExecModel;
538+
SPIRVExecutionModelKind ExecModel = ExecutionModelMax;
539539
std::string Name;
540540

541541
private:

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVInstruction.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ class SPIRVLoopMerge : public SPIRVInstruction {
10501050

10511051
SPIRVLoopMerge()
10521052
: SPIRVInstruction(OC), MergeBlock(SPIRVID_MAX),
1053-
LoopControl(SPIRVWORD_MAX) {
1053+
ContinueTarget(SPIRVID_MAX), LoopControl(SPIRVWORD_MAX) {
10541054
setHasNoId();
10551055
setHasNoType();
10561056
}
@@ -2214,8 +2214,8 @@ class SPIRVControlBarrier : public SPIRVInstruction {
22142214
SPIRVInstruction::validate();
22152215
}
22162216
SPIRVId ExecScope;
2217-
SPIRVId MemScope;
2218-
SPIRVId MemSema;
2217+
SPIRVId MemScope = SPIRVID_INVALID;
2218+
SPIRVId MemSema = SPIRVID_INVALID;
22192219
};
22202220

22212221
template <Op OC> class SPIRVLifetime : public SPIRVInstruction {

llvm-spirv/lib/SPIRV/libSPIRV/SPIRVType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class SPIRVTypeOpaqueGeneric : public SPIRVType {
777777
protected:
778778
_SPIRV_DEF_ENCDEC1(Id)
779779
void validate() const override { SPIRVEntry::validate(); }
780-
SPIRVId Opn;
780+
SPIRVId Opn = SPIRVID_INVALID;
781781
};
782782

783783
template <Op TheOpCode>
@@ -1009,7 +1009,7 @@ class SPIRVTypeSubgroupAvcINTEL : public SPIRVType {
10091009
protected:
10101010
_SPIRV_DEF_ENCDEC1(Id)
10111011
void validate() const override { SPIRVEntry::validate(); }
1012-
SPIRVId Opn;
1012+
SPIRVId Opn = SPIRVID_INVALID;
10131013
};
10141014

10151015
template <Op TheOpCode>

0 commit comments

Comments
 (0)