LLVM: lib/Target/PowerPC/PPCLowerMASSVEntries.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

24

25#define DEBUG_TYPE "ppc-lower-massv-entries"

26

27using namespace llvm;

28

29namespace {

30

32#define TLI_DEFINE_MASSV_VECFUNCS

33#define TLI_DEFINE_VECFUNC(SCAL, VEC, VF, VABI_PREFIX) VEC,

34#include "llvm/Analysis/VecFuncs.def"

35#undef TLI_DEFINE_MASSV_VECFUNCS

36};

37

38class PPCLowerMASSVEntries : public ModulePass {

39public:

40 static char ID;

41

43

44 bool runOnModule(Module &M) override;

45

46 StringRef getPassName() const override { return "PPC Lower MASS Entries"; }

47

48 void getAnalysisUsage(AnalysisUsage &AU) const override {

50 }

51

52private:

53 static bool isMASSVFunc(StringRef Name);

55 static std::string createMASSVFuncName(Function &Func,

60};

61

62}

63

64

65

66bool PPCLowerMASSVEntries::isMASSVFunc(StringRef Name) {

68}

69

70

71

72

73

74

75StringRef PPCLowerMASSVEntries::getCPUSuffix(const PPCSubtarget *Subtarget) {

76

77 if (!Subtarget)

78 return "";

79

80 if (Subtarget->isAIXABI() && Subtarget->hasP10Vector())

81 return "_P10";

82 if (Subtarget->hasP9Vector())

83 return "_P9";

84 if (Subtarget->hasP8Vector())

85 return "_P8";

87 return "_P7";

88

90 "Mininum subtarget for -vector-library=MASSV option is Power8 on Linux "

91 "and Power7 on AIX when vectorization is not disabled.");

92}

93

94

95

96std::string

97PPCLowerMASSVEntries::createMASSVFuncName(Function &Func,

98 const PPCSubtarget *Subtarget) {

99 StringRef Suffix = getCPUSuffix(Subtarget);

100 auto GenericName = Func.getName().str();

101 std::string MASSVEntryName = GenericName + Suffix.str();

102 return MASSVEntryName;

103}

104

105

106

107bool PPCLowerMASSVEntries::handlePowSpecialCases(CallInst *CI, Function &Func,

109 if (Func.getName() != "__powf4" && Func.getName() != "__powd2")

110 return false;

111

114

115

117 return false;

118

119 if (!CFP->isExactlyValue(0.75) && !CFP->isExactlyValue(0.25))

120 return false;

121

123 return false;

124

127 return true;

128 }

129

130 return false;

131}

132

133

134

135

136bool PPCLowerMASSVEntries::lowerMASSVCall(CallInst *CI, Function &Func,

138 const PPCSubtarget *Subtarget) {

140 return false;

141

142

143 if (handlePowSpecialCases(CI, Func, M))

144 return true;

145

146 std::string MASSVEntryName = createMASSVFuncName(Func, Subtarget);

147 FunctionCallee FCache = M.getOrInsertFunction(

148 MASSVEntryName, Func.getFunctionType(), Func.getAttributes());

149

151

152 return true;

153}

154

155bool PPCLowerMASSVEntries::runOnModule(Module &M) {

157

158 auto *TPC = getAnalysisIfAvailable();

159 if (!TPC)

161

162 auto &TM = TPC->getTM();

163 const PPCSubtarget *Subtarget;

164

165 for (Function &Func : M) {

166 if (Func.isDeclaration())

167 continue;

168

169 if (!isMASSVFunc(Func.getName()))

170 continue;

171

172

173

174

176

177 for (auto *User : MASSVUsers) {

179 if (!CI)

180 continue;

181

182 Subtarget = &TM.getSubtarget(*CI->getParent()->getParent());

183 Changed |= lowerMASSVCall(CI, Func, M, Subtarget);

184 }

185 }

186

188}

189

190char PPCLowerMASSVEntries::ID = 0;

191

193

195 false)

196

198 return new PPCLowerMASSVEntries();

199}

static const Function * getParent(const Value *V)

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

Machine Check Debug Module

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

Target-Independent Code Generator Pass Configuration Options pass.

This pass exposes codegen information to IR-level passes.

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

Value * getArgOperand(unsigned i) const

void setCalledFunction(Function *Fn)

Sets the function called, including updating the function type.

This class represents a function call, abstracting a target machine's calling convention.

LLVM_ABI bool hasNoInfs() const LLVM_READONLY

Determine whether the no-infs flag is set.

LLVM_ABI bool hasNoSignedZeros() const LLVM_READONLY

Determine whether the no-signed-zeros flag is set.

LLVM_ABI bool hasApproxFunc() const LLVM_READONLY

Determine whether the approximate-math-functions flag is set.

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.

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

std::string str() const

str - Get the contents as an std::string.

Wrapper pass for TargetTransformInfo.

Type * getType() const

All values are typed, get the type of this value.

const ParentTy * getParent() const

unsigned ID

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

LLVM_ABI Function * getOrInsertDeclaration(Module *M, ID id, ArrayRef< Type * > Tys={})

Look up the Function declaration of the intrinsic id in the Module M.

NodeAddr< FuncNode * > Func

This is an optimization pass for GlobalISel generic memory operations.

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

auto dyn_cast_or_null(const Y &Val)

ModulePass * createPPCLowerMASSVEntriesPass()

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

class LLVM_GSL_OWNER SmallVector

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

char & PPCLowerMASSVEntriesID

Definition PPCLowerMASSVEntries.cpp:192

bool is_contained(R &&Range, const E &Element)

Returns true if Element is found in Range.