LLVM: lib/Analysis/InstructionPrecedenceTracking.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
25
26using namespace llvm;
27
28#define DEBUG_TYPE "ipt"
29STATISTIC(NumInstScanned, "Number of insts scanned while updating ibt");
30
31#ifndef NDEBUG
33 "ipt-expensive-asserts",
34 cl::desc("Perform expensive assert validation on every query to Instruction"
35 " Precedence Tracking"),
37#endif
38
41#ifndef NDEBUG
42
43
45 validateAll();
46 else
47 validate(BB);
48#endif
49
50 if (!FirstSpecialInsts.contains(BB)) {
51 fill(BB);
52 assert(FirstSpecialInsts.contains(BB) && "Must be!");
53 }
54 return FirstSpecialInsts[BB];
55}
56
60}
61
66 return MaybeFirstSpecial && MaybeFirstSpecial->comesBefore(Insn);
67}
68
69void InstructionPrecedenceTracking::fill(const BasicBlock *BB) {
70 FirstSpecialInsts.erase(BB);
71 for (const auto &I : *BB) {
72 NumInstScanned++;
74 FirstSpecialInsts[BB] = &I;
75 return;
76 }
77 }
78
79
80 FirstSpecialInsts[BB] = nullptr;
81}
82
83#ifndef NDEBUG
84void InstructionPrecedenceTracking::validate(const BasicBlock *BB) const {
85 auto It = FirstSpecialInsts.find(BB);
86
87 if (It == FirstSpecialInsts.end())
88 return;
89
93 "Cached first special instruction is wrong!");
94 return;
95 }
96
97 assert(It->second == nullptr &&
98 "Block is marked as having special instructions but in fact it has "
99 "none!");
100}
101
102void InstructionPrecedenceTracking::validateAll() const {
103
104 for (const auto &It : FirstSpecialInsts)
105 validate(It.first);
106}
107#endif
108
112 FirstSpecialInsts.erase(BB);
113}
114
117 assert(BB && "must be called before instruction is actually removed");
118 auto It = FirstSpecialInsts.find(BB);
119 if (It != FirstSpecialInsts.end() && It->second == Inst)
120 FirstSpecialInsts.erase(It);
121}
122
124 for (const auto *U : Inst->users()) {
125 if (const auto *UI = dyn_cast(U))
127 }
128}
129
131 FirstSpecialInsts.clear();
132#ifndef NDEBUG
133
134 validateAll();
135#endif
136}
137
140
141
142
143
144
146}
147
150 using namespace PatternMatch;
151 if (match(Insn, m_IntrinsicIntrinsic::experimental\_widenable\_condition()))
152 return false;
153 return Insn->mayWriteToMemory();
154}
SmallVector< AArch64_IMM::ImmInsnModel, 4 > Insn
static cl::opt< bool > ExpensiveAsserts("ipt-expensive-asserts", cl::desc("Perform expensive assert validation on every query to Instruction" " Precedence Tracking"), cl::init(false), cl::Hidden)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
LLVM Basic Block Representation.
bool isSpecialInstruction(const Instruction *Insn) const override
A predicate that defines whether or not the instruction Insn is considered special and needs to be tr...
void clear()
Invalidates all information from this tracking.
void removeUsersOf(const Instruction *Inst)
Notifies this tracking that we are going to replace all uses of Inst.
void insertInstructionTo(const Instruction *Inst, const BasicBlock *BB)
Notifies this tracking that we are going to insert a new instruction Inst to the basic block BB.
void removeInstruction(const Instruction *Inst)
Notifies this tracking that we are going to remove the instruction Inst It makes all necessary update...
const Instruction * getFirstSpecialInstruction(const BasicBlock *BB)
Returns the topmost special instruction from the block BB.
virtual bool isSpecialInstruction(const Instruction *Insn) const =0
A predicate that defines whether or not the instruction Insn is considered special and needs to be tr...
bool hasSpecialInstructions(const BasicBlock *BB)
Returns true iff at least one instruction from the basic block BB is special.
bool isPreceededBySpecialInstruction(const Instruction *Insn)
Returns true iff the first special instruction of Insn's block exists and dominates Insn.
bool comesBefore(const Instruction *Other) const
Given an instruction Other in the same basic block as this instruction, return true if this instructi...
bool isSpecialInstruction(const Instruction *Insn) const override
A predicate that defines whether or not the instruction Insn is considered special and needs to be tr...
iterator_range< user_iterator > users()
const ParentTy * getParent() const
bool match(Val *V, const Pattern &P)
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
bool isGuaranteedToTransferExecutionToSuccessor(const Instruction *I)
Return true if this function can prove that the instruction I will always transfer execution to one o...