LLVM: lib/Target/AMDGPU/AMDGPURemoveIncompatibleFunctions.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

23

24#define DEBUG_TYPE "amdgpu-remove-incompatible-functions"

25

26using namespace llvm;

27

28namespace llvm {

31}

32

33namespace {

34

36

37class AMDGPURemoveIncompatibleFunctions {

38public:

39 AMDGPURemoveIncompatibleFunctions(const TargetMachine *TM = nullptr)

40 : TM(TM) {

41 assert(TM && "No TargetMachine!");

42 }

43

44 bool checkFunction(Function &F);

45

47 assert(TM->getTargetTriple().isAMDGCN());

48

50 for (Function &F : M) {

51 if (checkFunction(F))

53 }

54

55 for (Function *F : FnsToDelete) {

57 F->eraseFromParent();

58 }

59 return !FnsToDelete.empty();

60 }

61

62private:

63 const TargetMachine *TM = nullptr;

64};

65

66class AMDGPURemoveIncompatibleFunctionsLegacy : public ModulePass {

67public:

68 static char ID;

69

70 AMDGPURemoveIncompatibleFunctionsLegacy(const TargetMachine *TM)

71 : ModulePass(ID), TM(TM) {}

72

73 bool runOnModule(Module &M) override {

74 AMDGPURemoveIncompatibleFunctions Pass(TM);

75 return Pass.run(M);

76 }

77

78 StringRef getPassName() const override {

79 return "AMDGPU Remove Incompatible Functions";

80 }

81

82 void getAnalysisUsage(AnalysisUsage &AU) const override {}

83

84private:

85 const TargetMachine *TM = nullptr;

86};

87

88StringRef getFeatureName(unsigned Feature) {

90 if (Feature == KV.Value)

91 return KV.Key;

92

94}

95

100 return &KV;

101

102 return nullptr;

103}

104

105constexpr unsigned FeaturesToCheck[] = {AMDGPU::FeatureGFX11Insts,

106 AMDGPU::FeatureGFX10Insts,

107 AMDGPU::FeatureGFX9Insts,

108 AMDGPU::FeatureGFX8Insts,

109 AMDGPU::FeatureDPP,

110 AMDGPU::Feature16BitInsts,

111 AMDGPU::FeatureDot1Insts,

112 AMDGPU::FeatureDot2Insts,

113 AMDGPU::FeatureDot3Insts,

114 AMDGPU::FeatureDot4Insts,

115 AMDGPU::FeatureDot5Insts,

116 AMDGPU::FeatureDot6Insts,

117 AMDGPU::FeatureDot7Insts,

118 AMDGPU::FeatureDot8Insts,

119 AMDGPU::FeatureExtendedImageInsts,

120 AMDGPU::FeatureSMemRealTime,

121 AMDGPU::FeatureSMemTimeInst,

122 AMDGPU::FeatureGWS};

123

127 if (Features.test(FE.Value) && FE.Implies.any())

128 Result |= expandImpliedFeatures(FE.Implies.getAsBitset());

129 }

131}

132

133void reportFunctionRemoved(Function &F, unsigned Feature) {

135 ORE.emit([&]() {

136

137

138

139

141 << "removing function '" << F.getName() << "': +"

142 << getFeatureName(Feature)

143 << " is not supported on the current target";

144 });

145}

146}

147

151 AMDGPURemoveIncompatibleFunctions Impl(TM);

152 if (Impl.run(M))

155}

156

157bool AMDGPURemoveIncompatibleFunctions::checkFunction(Function &F) {

158 if (F.isDeclaration())

159 return false;

160

162 static_cast<const GCNSubtarget *>(TM->getSubtargetImpl(F));

163

164

165

166 StringRef GPUName = ST->getCPU();

168 return false;

169

170

171

173 if (!GPUInfo)

174 return false;

175

176

177

178

179

180

182 expandImpliedFeatures(GPUInfo->Implies.getAsBitset());

183

184

185

186

187

188

189 for (unsigned Feature : FeaturesToCheck) {

190 if (ST->hasFeature(Feature) && !GPUFeatureBits.test(Feature)) {

191 reportFunctionRemoved(F, Feature);

192 return true;

193 }

194 }

195

196

197

198

199

200 if (ST->supportsWave32() && ST->hasFeature(AMDGPU::FeatureWavefrontSize32)) {

201 reportFunctionRemoved(F, AMDGPU::FeatureWavefrontSize32);

202 return true;

203 }

204

205 if (ST->supportsWave64() && ST->hasFeature(AMDGPU::FeatureWavefrontSize64)) {

206 reportFunctionRemoved(F, AMDGPU::FeatureWavefrontSize64);

207 return true;

208 }

209 return false;

210}

211

213 "AMDGPU Remove Incompatible Functions", false, false)

214

215char AMDGPURemoveIncompatibleFunctionsLegacy::ID = 0;

216

219 return new AMDGPURemoveIncompatibleFunctionsLegacy(TM);

220}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

AMD GCN specific subclass of TargetSubtarget.

Module.h This file contains the declarations for the Module class.

print mir2vec MIR2Vec Vocabulary Printer Pass

Machine Check Debug Module

ModuleAnalysisManager MAM

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)

PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)

Definition AMDGPURemoveIncompatibleFunctions.cpp:149

static LLVM_ABI ConstantPointerNull * get(PointerType *T)

Static factory methods - Return objects of the specified value.

Container class for subtarget features.

constexpr bool test(unsigned I) const

ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...

A Module instance is used to store all the information related to an LLVM module.

A set of analyses that are preserved following a run of a transformation pass.

static PreservedAnalyses none()

Convenience factory function for the empty preserved set.

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

void push_back(const T &Elt)

StringRef - Represent a constant reference to a string, i.e.

bool starts_with(StringRef Prefix) const

Check if this string starts with the given Prefix.

constexpr bool empty() const

empty - Check if the string is empty.

Primary interface to the complete machine description for the target machine.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

PointerTypeMap run(const Module &M)

Compute the PointerTypeMap for the module M.

This is an optimization pass for GlobalISel generic memory operations.

const SubtargetFeatureKV AMDGPUFeatureKV[AMDGPU::NumSubtargetFeatures - 1]

class LLVM_GSL_OWNER SmallVector

Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...

ModulePass * createAMDGPURemoveIncompatibleFunctionsPass(const TargetMachine *)

AnalysisManager< Module > ModuleAnalysisManager

Convenience typedef for the Module analysis manager.

Used to provide key value pairs for feature and CPU bit flags.

Used to provide key value pairs for feature and CPU bit flags.