Skip to content

Commit 4a7804b

Browse files
dwoodwor-intelsvenvh
authored andcommitted
[NFC] 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.
1 parent 441aa40 commit 4a7804b

File tree

9 files changed

+15
-18
lines changed

9 files changed

+15
-18
lines changed

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

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) {

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;

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ SPIRVType *LLVMToSPIRVBase::transScavengedType(Value *V) {
730730
SPIRVType *RT = transType(F->getReturnType());
731731
std::vector<SPIRVType *> PT;
732732
for (Argument &Arg : F->args()) {
733+
assert(OCLTypeToSPIRVPtr);
733734
Type *Ty = OCLTypeToSPIRVPtr->getAdaptedArgumentType(F, Arg.getArgNo());
734735
if (!Ty) {
735736
Ty = Arg.getType();
@@ -1329,9 +1330,8 @@ class LLVMParallelAccessIndices {
13291330
public:
13301331
LLVMParallelAccessIndices(
13311332
MDNode *Node, LLVMToSPIRVBase::LLVMToSPIRVMetadataMap &IndexGroupArrayMap)
1332-
: Node(Node), IndexGroupArrayMap(IndexGroupArrayMap) {}
1333+
: Node(Node), IndexGroupArrayMap(IndexGroupArrayMap) {
13331334

1334-
void initialize() {
13351335
assert(isValid() &&
13361336
"LLVMParallelAccessIndices initialized from an invalid MDNode");
13371337

@@ -1465,7 +1465,6 @@ LLVMToSPIRVBase::getLoopControl(const BranchInst *Branch,
14651465
} else if (S == "llvm.loop.parallel_access_indices") {
14661466
// Intel FPGA IVDep loop attribute
14671467
LLVMParallelAccessIndices IVDep(Node, IndexGroupArrayMap);
1468-
IVDep.initialize();
14691468
// Store IVDep-specific parameters into an intermediate
14701469
// container to address the case when there're multiple
14711470
// IVDep metadata nodes and this condition gets entered multiple

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

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

lib/SPIRV/libSPIRV/SPIRVEntry.h

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

537537
_SPIRV_DCL_ENCDEC
538538
protected:
539-
SPIRVExecutionModelKind ExecModel;
539+
SPIRVExecutionModelKind ExecModel = ExecutionModelMax;
540540
std::string Name;
541541

542542
private:

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 {

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)