Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 68c521d

Browse files
committed
[AMDGPU] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292623 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0e0a424 commit 68c521d

11 files changed

+300
-200
lines changed

lib/Target/AMDGPU/AMDGPUAsmPrinter.h

Lines changed: 38 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,92 +15,75 @@
1515
#ifndef LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
1616
#define LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H
1717

18-
#include "AMDGPUMCInstLower.h"
19-
18+
#include "llvm/ADT/StringRef.h"
2019
#include "llvm/CodeGen/AsmPrinter.h"
20+
#include <cstddef>
21+
#include <cstdint>
22+
#include <limits>
23+
#include <memory>
24+
#include <string>
2125
#include <vector>
2226

2327
namespace llvm {
28+
2429
class MCOperand;
2530

2631
class AMDGPUAsmPrinter final : public AsmPrinter {
2732
private:
2833
struct SIProgramInfo {
29-
SIProgramInfo() :
30-
VGPRBlocks(0),
31-
SGPRBlocks(0),
32-
Priority(0),
33-
FloatMode(0),
34-
Priv(0),
35-
DX10Clamp(0),
36-
DebugMode(0),
37-
IEEEMode(0),
38-
ScratchSize(0),
39-
ComputePGMRSrc1(0),
40-
LDSBlocks(0),
41-
ScratchBlocks(0),
42-
ComputePGMRSrc2(0),
43-
NumVGPR(0),
44-
NumSGPR(0),
45-
FlatUsed(false),
46-
NumSGPRsForWavesPerEU(0),
47-
NumVGPRsForWavesPerEU(0),
48-
ReservedVGPRFirst(0),
49-
ReservedVGPRCount(0),
50-
DebuggerWavefrontPrivateSegmentOffsetSGPR((uint16_t)-1),
51-
DebuggerPrivateSegmentBufferSGPR((uint16_t)-1),
52-
VCCUsed(false),
53-
CodeLen(0) {}
54-
5534
// Fields set in PGM_RSRC1 pm4 packet.
56-
uint32_t VGPRBlocks;
57-
uint32_t SGPRBlocks;
58-
uint32_t Priority;
59-
uint32_t FloatMode;
60-
uint32_t Priv;
61-
uint32_t DX10Clamp;
62-
uint32_t DebugMode;
63-
uint32_t IEEEMode;
64-
uint32_t ScratchSize;
65-
66-
uint64_t ComputePGMRSrc1;
35+
uint32_t VGPRBlocks = 0;
36+
uint32_t SGPRBlocks = 0;
37+
uint32_t Priority = 0;
38+
uint32_t FloatMode = 0;
39+
uint32_t Priv = 0;
40+
uint32_t DX10Clamp = 0;
41+
uint32_t DebugMode = 0;
42+
uint32_t IEEEMode = 0;
43+
uint32_t ScratchSize = 0;
44+
45+
uint64_t ComputePGMRSrc1 = 0;
6746

6847
// Fields set in PGM_RSRC2 pm4 packet.
69-
uint32_t LDSBlocks;
70-
uint32_t ScratchBlocks;
48+
uint32_t LDSBlocks = 0;
49+
uint32_t ScratchBlocks = 0;
7150

72-
uint64_t ComputePGMRSrc2;
51+
uint64_t ComputePGMRSrc2 = 0;
7352

74-
uint32_t NumVGPR;
75-
uint32_t NumSGPR;
53+
uint32_t NumVGPR = 0;
54+
uint32_t NumSGPR = 0;
7655
uint32_t LDSSize;
77-
bool FlatUsed;
56+
bool FlatUsed = false;
7857

7958
// Number of SGPRs that meets number of waves per execution unit request.
80-
uint32_t NumSGPRsForWavesPerEU;
59+
uint32_t NumSGPRsForWavesPerEU = 0;
8160

8261
// Number of VGPRs that meets number of waves per execution unit request.
83-
uint32_t NumVGPRsForWavesPerEU;
62+
uint32_t NumVGPRsForWavesPerEU = 0;
8463

8564
// If ReservedVGPRCount is 0 then must be 0. Otherwise, this is the first
8665
// fixed VGPR number reserved.
87-
uint16_t ReservedVGPRFirst;
66+
uint16_t ReservedVGPRFirst = 0;
8867

8968
// The number of consecutive VGPRs reserved.
90-
uint16_t ReservedVGPRCount;
69+
uint16_t ReservedVGPRCount = 0;
9170

9271
// Fixed SGPR number used to hold wave scratch offset for entire kernel
9372
// execution, or uint16_t(-1) if the register is not used or not known.
94-
uint16_t DebuggerWavefrontPrivateSegmentOffsetSGPR;
73+
uint16_t DebuggerWavefrontPrivateSegmentOffsetSGPR =
74+
std::numeric_limits<uint16_t>::max();
9575

9676
// Fixed SGPR number of the first 4 SGPRs used to hold scratch V# for entire
9777
// kernel execution, or uint16_t(-1) if the register is not used or not
9878
// known.
99-
uint16_t DebuggerPrivateSegmentBufferSGPR;
79+
uint16_t DebuggerPrivateSegmentBufferSGPR =
80+
std::numeric_limits<uint16_t>::max();
10081

10182
// Bonus information for debugging.
102-
bool VCCUsed;
103-
uint64_t CodeLen;
83+
bool VCCUsed = false;
84+
uint64_t CodeLen = 0;
85+
86+
SIProgramInfo() = default;
10487
};
10588

10689
void getSIProgramInfo(SIProgramInfo &Out, const MachineFunction &MF) const;
@@ -155,6 +138,6 @@ class AMDGPUAsmPrinter final : public AsmPrinter {
155138
size_t DisasmLineMaxLen;
156139
};
157140

158-
} // End anonymous llvm
141+
} // end namespace llvm
159142

160-
#endif
143+
#endif // LLVM_LIB_TARGET_AMDGPU_AMDGPUASMPRINTER_H

lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,29 @@
1717
#include "AMDGPUIntrinsicInfo.h"
1818
#include "AMDGPUSubtarget.h"
1919
#include "AMDGPUTargetMachine.h"
20-
20+
#include "llvm/ADT/StringRef.h"
2121
#include "llvm/Analysis/DivergenceAnalysis.h"
2222
#include "llvm/CodeGen/Passes.h"
23+
#include "llvm/IR/Attributes.h"
24+
#include "llvm/IR/BasicBlock.h"
25+
#include "llvm/IR/Constants.h"
26+
#include "llvm/IR/DerivedTypes.h"
27+
#include "llvm/IR/Function.h"
28+
#include "llvm/IR/InstrTypes.h"
29+
#include "llvm/IR/Instruction.h"
30+
#include "llvm/IR/Instructions.h"
2331
#include "llvm/IR/InstVisitor.h"
32+
#include "llvm/IR/IntrinsicInst.h"
33+
#include "llvm/IR/Intrinsics.h"
2434
#include "llvm/IR/IRBuilder.h"
25-
#include "llvm/Support/Debug.h"
26-
#include "llvm/Support/raw_ostream.h"
35+
#include "llvm/IR/LLVMContext.h"
36+
#include "llvm/IR/Operator.h"
37+
#include "llvm/IR/Type.h"
38+
#include "llvm/IR/Value.h"
39+
#include "llvm/Pass.h"
40+
#include "llvm/Support/Casting.h"
41+
#include <cassert>
42+
#include <iterator>
2743

2844
#define DEBUG_TYPE "amdgpu-codegenprepare"
2945

@@ -34,10 +50,10 @@ namespace {
3450
class AMDGPUCodeGenPrepare : public FunctionPass,
3551
public InstVisitor<AMDGPUCodeGenPrepare, bool> {
3652
const GCNTargetMachine *TM;
37-
const SISubtarget *ST;
38-
DivergenceAnalysis *DA;
39-
Module *Mod;
40-
bool HasUnsafeFPMath;
53+
const SISubtarget *ST = nullptr;
54+
DivergenceAnalysis *DA = nullptr;
55+
Module *Mod = nullptr;
56+
bool HasUnsafeFPMath = false;
4157

4258
/// \brief Copies exact/nsw/nuw flags (if any) from binary operation \p I to
4359
/// binary operation \p V.
@@ -113,13 +129,9 @@ class AMDGPUCodeGenPrepare : public FunctionPass,
113129

114130
public:
115131
static char ID;
132+
116133
AMDGPUCodeGenPrepare(const TargetMachine *TM = nullptr) :
117-
FunctionPass(ID),
118-
TM(static_cast<const GCNTargetMachine *>(TM)),
119-
ST(nullptr),
120-
DA(nullptr),
121-
Mod(nullptr),
122-
HasUnsafeFPMath(false) { }
134+
FunctionPass(ID), TM(static_cast<const GCNTargetMachine *>(TM)) {}
123135

124136
bool visitFDiv(BinaryOperator &I);
125137

@@ -142,7 +154,7 @@ class AMDGPUCodeGenPrepare : public FunctionPass,
142154
}
143155
};
144156

145-
} // End anonymous namespace
157+
} // end anonymous namespace
146158

147159
Value *AMDGPUCodeGenPrepare::copyFlags(
148160
const BinaryOperator &I, Value *V) const {

lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,49 @@
1414

1515
#include "AMDGPU.h"
1616
#include "AMDGPUSubtarget.h"
17+
#include "Utils/AMDGPUBaseInfo.h"
18+
#include "llvm/ADT/APInt.h"
19+
#include "llvm/ADT/None.h"
20+
#include "llvm/ADT/STLExtras.h"
21+
#include "llvm/ADT/StringRef.h"
22+
#include "llvm/ADT/Triple.h"
23+
#include "llvm/ADT/Twine.h"
1724
#include "llvm/Analysis/ValueTracking.h"
18-
#include "llvm/IR/IRBuilder.h"
25+
#include "llvm/IR/Attributes.h"
26+
#include "llvm/IR/BasicBlock.h"
27+
#include "llvm/IR/Constant.h"
28+
#include "llvm/IR/Constants.h"
29+
#include "llvm/IR/DataLayout.h"
30+
#include "llvm/IR/DerivedTypes.h"
31+
#include "llvm/IR/Function.h"
32+
#include "llvm/IR/GlobalValue.h"
33+
#include "llvm/IR/GlobalVariable.h"
34+
#include "llvm/IR/Instruction.h"
35+
#include "llvm/IR/Instructions.h"
1936
#include "llvm/IR/IntrinsicInst.h"
37+
#include "llvm/IR/Intrinsics.h"
38+
#include "llvm/IR/IRBuilder.h"
39+
#include "llvm/IR/LLVMContext.h"
2040
#include "llvm/IR/MDBuilder.h"
41+
#include "llvm/IR/Metadata.h"
42+
#include "llvm/IR/Module.h"
43+
#include "llvm/IR/Type.h"
44+
#include "llvm/IR/User.h"
45+
#include "llvm/IR/Value.h"
46+
#include "llvm/Pass.h"
47+
#include "llvm/Support/Casting.h"
2148
#include "llvm/Support/Debug.h"
49+
#include "llvm/Support/ErrorHandling.h"
50+
#include "llvm/Support/MathExtras.h"
2251
#include "llvm/Support/raw_ostream.h"
52+
#include "llvm/Target/TargetMachine.h"
53+
#include <algorithm>
54+
#include <cassert>
55+
#include <cstdint>
56+
#include <map>
57+
#include <tuple>
58+
#include <utility>
59+
#include <vector>
2360

2461
#define DEBUG_TYPE "amdgpu-promote-alloca"
2562

@@ -31,16 +68,16 @@ namespace {
3168
class AMDGPUPromoteAlloca : public FunctionPass {
3269
private:
3370
const TargetMachine *TM;
34-
Module *Mod;
35-
const DataLayout *DL;
36-
MDNode *MaxWorkGroupSizeRange;
71+
Module *Mod = nullptr;
72+
const DataLayout *DL = nullptr;
73+
MDNode *MaxWorkGroupSizeRange = nullptr;
3774

3875
// FIXME: This should be per-kernel.
39-
uint32_t LocalMemLimit;
40-
uint32_t CurrentLocalMemUsage;
76+
uint32_t LocalMemLimit = 0;
77+
uint32_t CurrentLocalMemUsage = 0;
4178

42-
bool IsAMDGCN;
43-
bool IsAMDHSA;
79+
bool IsAMDGCN = false;
80+
bool IsAMDHSA = false;
4481

4582
std::pair<Value *, Value *> getLocalSizeYZ(IRBuilder<> &Builder);
4683
Value *getWorkitemID(IRBuilder<> &Builder, unsigned N);
@@ -63,15 +100,7 @@ class AMDGPUPromoteAlloca : public FunctionPass {
63100
static char ID;
64101

65102
AMDGPUPromoteAlloca(const TargetMachine *TM_ = nullptr) :
66-
FunctionPass(ID),
67-
TM(TM_),
68-
Mod(nullptr),
69-
DL(nullptr),
70-
MaxWorkGroupSizeRange(nullptr),
71-
LocalMemLimit(0),
72-
CurrentLocalMemUsage(0),
73-
IsAMDGCN(false),
74-
IsAMDHSA(false) { }
103+
FunctionPass(ID), TM(TM_) {}
75104

76105
bool doInitialization(Module &M) override;
77106
bool runOnFunction(Function &F) override;
@@ -86,7 +115,7 @@ class AMDGPUPromoteAlloca : public FunctionPass {
86115
}
87116
};
88117

89-
} // End anonymous namespace
118+
} // end anonymous namespace
90119

91120
char AMDGPUPromoteAlloca::ID = 0;
92121

@@ -95,7 +124,6 @@ INITIALIZE_TM_PASS(AMDGPUPromoteAlloca, DEBUG_TYPE,
95124

96125
char &llvm::AMDGPUPromoteAllocaID = AMDGPUPromoteAlloca::ID;
97126

98-
99127
bool AMDGPUPromoteAlloca::doInitialization(Module &M) {
100128
if (!TM)
101129
return false;
@@ -298,7 +326,7 @@ AMDGPUPromoteAlloca::getLocalSizeYZ(IRBuilder<> &Builder) {
298326
Value *GEPZU = Builder.CreateConstInBoundsGEP1_64(CastDispatchPtr, 2);
299327
LoadInst *LoadZU = Builder.CreateAlignedLoad(GEPZU, 4);
300328

301-
MDNode *MD = llvm::MDNode::get(Mod->getContext(), None);
329+
MDNode *MD = MDNode::get(Mod->getContext(), None);
302330
LoadXY->setMetadata(LLVMContext::MD_invariant_load, MD);
303331
LoadZU->setMetadata(LLVMContext::MD_invariant_load, MD);
304332
LoadZU->setMetadata(LLVMContext::MD_range, MaxWorkGroupSizeRange);

0 commit comments

Comments
 (0)