LLVM: lib/Target/Hexagon/HexagonGenExtract.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

21#include "llvm/IR/IntrinsicsHexagon.h"

28#include

29#include

30#include

31

32using namespace llvm;

33

36 " instructions"));

37

38

39

40

41

42

43

45 cl::desc("No extract instruction with offset 0"));

46

47namespace {

48

49 class HexagonGenExtract : public FunctionPass {

50 public:

51 static char ID;

52

54

55 StringRef getPassName() const override {

56 return "Hexagon generate \"extract\" instructions";

57 }

58

60

61 void getAnalysisUsage(AnalysisUsage &AU) const override {

62 AU.addRequired();

64 FunctionPass::getAnalysisUsage(AU);

65 }

66

67 private:

68 bool visitBlock(BasicBlock *B);

69 bool convert(Instruction *In);

70

71 unsigned ExtractCount = 0;

72 DominatorTree *DT;

73 };

74

75}

76

77char HexagonGenExtract::ID = 0;

78

80 "\"extract\" instructions", false, false)

84

85bool HexagonGenExtract::convert(Instruction *In) {

87

88 Value *BF = nullptr;

89 ConstantInt *CSL = nullptr, *CSR = nullptr, *CM = nullptr;

92 bool LogicalSR;

93

94

95 LogicalSR = true;

99

100 if (!Match) {

101

102 LogicalSR = false;

106 }

107 if (!Match) {

108

109 LogicalSR = true;

113 if (Match && NoSR0)

114 return false;

115 }

116 if (!Match) {

117

118 LogicalSR = true;

122 }

123 if (!Match) {

124

125 LogicalSR = false;

129 }

130 if (!Match) {

131 CM = nullptr;

132

133 LogicalSR = true;

136 }

137 if (!Match) {

138 CM = nullptr;

139

140 LogicalSR = false;

143 }

144 if (!Match)

145 return false;

146

148 if (!Ty->isIntegerTy())

149 return false;

151 if (BW != 32 && BW != 64)

152 return false;

153

154 uint32_t SR = CSR->getZExtValue();

156

157 if (!CM) {

158

159

160

161 if (!LogicalSR && (SR > SL))

162 return false;

164 CM = ConstantInt::get(Ctx, A);

165 }

166

167

168

169 APInt M = CM->getValue().lshr(SL);

171

172

173

174 uint32_t U = BW - std::max(SL, SR);

175

176

178 if (W == 0 || W == 1)

179 return false;

180

181

182

183

184

185 if (!LogicalSR) {

186

187

188

190 if (M.intersects(C) || !M.isMask(W))

191 return false;

192 } else {

193

194

195

196 if (!M.getLoBits(U).isMask(W))

197 return false;

198 }

199

201 Intrinsic::ID IntId = (BW == 32) ? Intrinsic::hexagon_S2_extractu

202 : Intrinsic::hexagon_S2_extractup;

205 if (SL != 0)

207 In->replaceAllUsesWith(NewIn);

208 return true;

209}

210

211bool HexagonGenExtract::visitBlock(BasicBlock *B) {

213

214

216 Changed |= visitBlock(DTN->getBlock());

217

218

221

223 while (true) {

224 if (HasCutoff && (ExtractCount >= Cutoff))

226 bool Last = (I == Begin);

228 NextI = std::prev(I);

230 bool Done = convert(In);

231 if (HasCutoff && Done)

232 ExtractCount++;

235 break;

236 I = NextI;

237 }

239}

240

241bool HexagonGenExtract::runOnFunction(Function &F) {

242 if (skipFunction(F))

243 return false;

244

245 DT = &getAnalysis().getDomTree();

247

248

249

251 Changed = visitBlock(Entry);

252

254}

255

257 return new HexagonGenExtract();

258}

This file implements a class to represent arbitrary precision integral constant values and operations...

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

This file contains the declarations for the subclasses of Constant, which represent the different fla...

static bool runOnFunction(Function &F, bool PostInlining)

This file defines the little GraphTraits template class that should be specialized by classes that...

This file provides various utilities for inspecting and working with the control flow graph in LLVM I...

#define INITIALIZE_PASS_DEPENDENCY(depName)

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

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

Class for arbitrary precision integers.

APInt shl(unsigned shiftAmt) const

Left-shift function.

static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)

Constructs an APInt value that has the top hiBitsSet bits set.

APInt lshr(unsigned shiftAmt) const

Logical right-shift function.

AnalysisUsage & addRequired()

AnalysisUsage & addPreserved()

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

LLVM Basic Block Representation.

InstListType::iterator iterator

Instruction iterators...

LLVM_ABI LLVMContext & getContext() const

Get the context in which this basic block lives.

This is the shared class of boolean and integer constants.

uint64_t getZExtValue() const

Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...

DomTreeNodeBase< NodeT > * getNode(const NodeT *BB) const

getNode - return the (Post)DominatorTree node for the specified basic block.

Legacy analysis pass which computes a DominatorTree.

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

LLVM_ABI CallInst * CreateIntrinsic(Intrinsic::ID ID, ArrayRef< Type * > Types, ArrayRef< Value * > Args, FMFSource FMFSource={}, const Twine &Name="")

Create a call to intrinsic ID with Args, mangled using Types.

ConstantInt * getInt32(uint32_t C)

Get a constant 32-bit value.

Value * CreateShl(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)

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

This is an important class for using LLVM in a threaded context.

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

static LLVM_ABI IntegerType * getInt32Ty(LLVMContext &C)

LLVM_ABI TypeSize getPrimitiveSizeInBits() const LLVM_READONLY

Return the basic size of this type if it is a primitive type.

LLVM Value Representation.

Type * getType() const

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

LLVM_ABI StringRef getName() const

Return a constant reference to the value's name.

unsigned ID

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

@ C

The default llvm calling convention, compatible with C.

@ BasicBlock

Various leaf nodes.

BinaryOp_match< LHS, RHS, Instruction::And > m_And(const LHS &L, const RHS &R)

BinaryOp_match< LHS, RHS, Instruction::AShr > m_AShr(const LHS &L, const RHS &R)

bool match(Val *V, const Pattern &P)

class_match< ConstantInt > m_ConstantInt()

Match an arbitrary ConstantInt and ignore it.

class_match< Value > m_Value()

Match an arbitrary value and ignore it.

BinaryOp_match< LHS, RHS, Instruction::LShr > m_LShr(const LHS &L, const RHS &R)

BinaryOp_match< LHS, RHS, Instruction::Shl > m_Shl(const LHS &L, const RHS &R)

initializer< Ty > init(const Ty &Val)

friend class Instruction

Iterator for Instructions in a `BasicBlock.

This is an optimization pass for GlobalISel generic memory operations.

FunctionPass * createHexagonGenExtract()

Definition HexagonGenExtract.cpp:256

iterator_range< typename GraphTraits< GraphType >::ChildIteratorType > children(const typename GraphTraits< GraphType >::NodeRef &G)

static NodeRef getEntryNode(Function *F)