LLVM: lib/CodeGen/ReplaceWithVeclib.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

31

32using namespace llvm;

33

34#define DEBUG_TYPE "replace-with-veclib"

35

37 "Number of calls to intrinsics that have been replaced.");

38

40 "Number of vector library function declarations added.");

41

43 "Number of functions added to `llvm.compiler.used`");

44

45

46

47

50 Function *ScalarFunc = nullptr) {

52 if (!TLIFunc) {

53 TLIFunc =

55 if (ScalarFunc)

57

59 << TLIName << "` of type `" << *(TLIFunc->getType())

60 << "` to module.\n");

61

62 ++NumTLIFuncDeclAdded;

63

64

67 << "` to `@llvm.compiler.used`.\n");

68 ++NumFuncUsedAdded;

69 }

70 return TLIFunc;

71}

72

73

74

79 if (auto OptMaskpos = Info.getParamIndexForOptionalMask()) {

80 auto *MaskTy =

82 Args.insert(Args.begin() + OptMaskpos.value(),

84 }

85

86

88 II->getOperandBundlesAsDefs(OpBundles);

89

91 II->replaceAllUsesWith(Replacement);

92

94 Replacement->copyFastMathFlags(II);

95}

96

97

98

99

102 assert(II != nullptr && "Intrinsic cannot be null");

104 Type *RetTy = II->getType();

106

107

110

111

116

117

118

121 auto *ArgTy = Arg.value()->getType();

123 nullptr);

126 if (IsOloadTy)

129 auto *ScalarArgTy = VectorArgTy->getElementType();

130 ScalarArgTypes.push_back(ScalarArgTy);

131 if (IsOloadTy)

133

134

135 if (EC.isZero())

136 EC = VectorArgTy->getElementCount();

137 else if (EC != VectorArgTy->getElementCount())

138 return false;

139 } else

140

141 return false;

142 }

143

144

145

146 std::string ScalarName =

150

151

152

153

156 if (!VD && !(VD = TLI.getVectorMappingInfo(ScalarName, EC, true)))

157 return false;

158

160 << "` and vector width " << EC << " to: `"

162

163

164

166 FunctionType::get(ScalarRetTy, ScalarArgTypes, false);

169 if (!OptInfo)

170 return false;

171

172

173

174

175

176 for (auto &VFParam : OptInfo->Shape.Parameters) {

178 continue;

179

180

181

182 assert(VFParam.ParamPos < II->arg_size() && "ParamPos has invalid range");

183 Type *OrigTy = II->getArgOperand(VFParam.ParamPos)->getType();

186 << ". Wrong type at index " << VFParam.ParamPos << ": "

187 << *OrigTy << "\n");

188 return false;

189 }

190 }

191

193 if (!VectorFTy)

194 return false;

195

198 II->getCalledFunction());

201 << "` with call to `" << TLIFunc->getName() << "`.\n");

202 ++NumCallsReplaced;

203 return true;

204}

205

209

212 continue;

213 if (II->getType()->isVectorTy() && II->getType()->isVoidTy())

214 continue;

215

218 }

219 }

220

221 for (auto *I : ReplacedCalls)

222 I->eraseFromParent();

223 return !ReplacedCalls.empty();

224}

225

226

227

228

234 LLVM_DEBUG(dbgs() << "Intrinsic calls replaced with vector libraries: "

235 << NumCallsReplaced << "\n");

236

244 return PA;

245 }

246

247

249}

250

251

252

253

259

269

270

271

272

274

276 "Replace intrinsics with calls to vector library", false,

277 false)

280 "Replace intrinsics with calls to vector library", false,

282

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

Expand Atomic instructions

Analysis containing CSE Info

static bool runImpl(Function &F, const TargetLowering &TLI, const LibcallLoweringInfo &Libcalls, AssumptionCache *AC)

This is the interface for a simple mod/ref and alias analysis over globals.

uint64_t IntrinsicInst * II

#define INITIALIZE_PASS_DEPENDENCY(depName)

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

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

Function * getTLIFunction(Module *M, FunctionType *VectorFTy, const StringRef TLIName, Function *ScalarFunc=nullptr)

Returns a vector Function that it adds to the Module M.

Definition ReplaceWithVeclib.cpp:48

static bool replaceWithCallToVeclib(const TargetLibraryInfo &TLI, IntrinsicInst *II)

Returns true when successfully replaced II, which is a call to a vectorized intrinsic,...

Definition ReplaceWithVeclib.cpp:100

static void replaceWithTLIFunction(IntrinsicInst *II, VFInfo &Info, Function *TLIVecFunc)

Replace the intrinsic call II to TLIVecFunc, which is the corresponding function from the vector libr...

Definition ReplaceWithVeclib.cpp:75

static bool runImpl(const TargetLibraryInfo &TLI, Function &F)

Definition ReplaceWithVeclib.cpp:206

This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...

#define STATISTIC(VARNAME, DESC)

A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.

PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)

Get the result of an analysis pass for a given IR unit.

Represent the analysis usage information of a pass.

AnalysisUsage & addRequired()

AnalysisUsage & addPreserved()

Add the specified Pass class to the set of analyses preserved by this pass.

LLVM_ABI void setPreservesCFG()

This function should be called by the pass, iff they do not:

Represents analyses that only rely on functions' control flow.

static LLVM_ABI Constant * getAllOnesValue(Type *Ty)

An analysis that produces DemandedBits for a function.

static constexpr ElementCount getFixed(ScalarTy MinVal)

FunctionPass class - This class is used to implement most global optimizations.

static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)

This static method is the primary way of constructing a FunctionType.

static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)

const Function & getFunction() const

void copyAttributesFrom(const Function *Src)

copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...

PointerType * getType() const

Global values are always pointers.

@ ExternalLinkage

Externally visible function.

Legacy wrapper pass to provide the GlobalsAAResult object.

CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)

This provides a uniform API for creating instructions and inserting them into a basic block: either a...

A wrapper class for inspecting calls to intrinsic functions.

This analysis provides dependence information for the memory accesses of a loop.

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

AnalysisType & getAnalysis() const

getAnalysis() - This function is used by subclasses to get to the analysis information ...

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

static PreservedAnalyses all()

Construct a special preserved set that preserves all passes.

PreservedAnalyses & preserveSet()

Mark an analysis set as preserved.

PreservedAnalyses & preserve()

Mark an analysis as preserved.

Analysis pass that exposes the ScalarEvolution for a function.

void push_back(const T &Elt)

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

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

std::string str() const

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

Analysis pass providing the TargetLibraryInfo.

Provides information about what library functions are available for the current target.

const VecDesc * getVectorMappingInfo(StringRef F, const ElementCount &VF, bool Masked) const

The instances of the Type class are immutable: once they are created, they are never changed.

bool isVectorTy() const

True if this is an instance of VectorType.

Type * getScalarType() const

If this is a vector type, return the element type, otherwise return 'this'.

static LLVM_ABI IntegerType * getInt1Ty(LLVMContext &C)

bool isVoidTy() const

Return true if this is 'void'.

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

Provides info so a possible vectorization of a function can be computed.

LLVM_ABI std::string getVectorFunctionABIVariantString() const

Returns a vector function ABI variant string on the form: ZGV(<...

StringRef getVectorFnName() const

static LLVM_ABI VectorType * get(Type *ElementType, ElementCount EC)

This static method is the primary way to construct an VectorType.

LLVM_ABI StringRef getName(ID id)

Return the LLVM name for an intrinsic, such as "llvm.ppc.altivec.lvx".

LLVM_ABI bool isOverloaded(ID id)

Returns true if the intrinsic can be overloaded.

LLVM_ABI std::optional< VFInfo > tryDemangleForVFABI(StringRef MangledName, const FunctionType *FTy)

Function to construct a VFInfo out of a mangled names in the following format:

LLVM_ABI FunctionType * createFunctionType(const VFInfo &Info, const FunctionType *ScalarFTy)

Constructs a FunctionType by applying vector function information to the type of a matching scalar fu...

This is an optimization pass for GlobalISel generic memory operations.

auto enumerate(FirstRange &&First, RestRanges &&...Rest)

Given two or more input ranges, returns a new range whose values are tuples (A, B,...

decltype(auto) dyn_cast(const From &Val)

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

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

bool isa(const From &Val)

isa - Return true if the parameter to the template is an instance of one of the template type argu...

IRBuilder(LLVMContext &, FolderTy, InserterTy, MDNode *, ArrayRef< OperandBundleDef >) -> IRBuilder< FolderTy, InserterTy >

LLVM_ABI void appendToCompilerUsed(Module &M, ArrayRef< GlobalValue * > Values)

Adds global values to the llvm.compiler.used list.

LLVM_ABI bool isVectorIntrinsicWithScalarOpAtArg(Intrinsic::ID ID, unsigned ScalarOpdIdx, const TargetTransformInfo *TTI)

Identifies if the vector form of the intrinsic has a scalar operand.

LLVM_ABI FunctionPass * createReplaceWithVeclibLegacyPass()

Definition ReplaceWithVeclib.cpp:283

AnalysisManager< Function > FunctionAnalysisManager

Convenience typedef for the Function analysis manager.

LLVM_ABI bool isVectorIntrinsicWithOverloadTypeAtArg(Intrinsic::ID ID, int OpdIdx, const TargetTransformInfo *TTI)

Identifies if the vector form of the intrinsic is overloaded on the type of the operand at index OpdI...

void getAnalysisUsage(AnalysisUsage &AU) const override

getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...

Definition ReplaceWithVeclib.cpp:260

bool runOnFunction(Function &F) override

runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.

Definition ReplaceWithVeclib.cpp:254

LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)

Definition ReplaceWithVeclib.cpp:229

Holds the VFShape for a specific scalar to vector function mapping.