Bug Summary

File:lib/Transforms/Scalar/GuardWidening.cpp
Warning:line 463, column 9
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name GuardWidening.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/lib/Transforms/Scalar -I /build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar -I /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn326551/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn326551/build-llvm/lib/Transforms/Scalar -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-03-02-155150-1477-1 -x c++ /build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp

/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp

1//===- GuardWidening.cpp - ---- Guard widening ----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the guard widening pass. The semantics of the
11// @llvm.experimental.guard intrinsic lets LLVM transform it so that it fails
12// more often that it did before the transform. This optimization is called
13// "widening" and can be used hoist and common runtime checks in situations like
14// these:
15//
16// %cmp0 = 7 u< Length
17// call @llvm.experimental.guard(i1 %cmp0) [ "deopt"(...) ]
18// call @unknown_side_effects()
19// %cmp1 = 9 u< Length
20// call @llvm.experimental.guard(i1 %cmp1) [ "deopt"(...) ]
21// ...
22//
23// =>
24//
25// %cmp0 = 9 u< Length
26// call @llvm.experimental.guard(i1 %cmp0) [ "deopt"(...) ]
27// call @unknown_side_effects()
28// ...
29//
30// If %cmp0 is false, @llvm.experimental.guard will "deoptimize" back to a
31// generic implementation of the same function, which will have the correct
32// semantics from that point onward. It is always _legal_ to deoptimize (so
33// replacing %cmp0 with false is "correct"), though it may not always be
34// profitable to do so.
35//
36// NB! This pass is a work in progress. It hasn't been tuned to be "production
37// ready" yet. It is known to have quadriatic running time and will not scale
38// to large numbers of guards
39//
40//===----------------------------------------------------------------------===//
41
42#include "llvm/Transforms/Scalar/GuardWidening.h"
43#include "llvm/ADT/DenseMap.h"
44#include "llvm/ADT/DepthFirstIterator.h"
45#include "llvm/Analysis/LoopInfo.h"
46#include "llvm/Analysis/PostDominators.h"
47#include "llvm/Analysis/ValueTracking.h"
48#include "llvm/IR/ConstantRange.h"
49#include "llvm/IR/Dominators.h"
50#include "llvm/IR/IntrinsicInst.h"
51#include "llvm/IR/PatternMatch.h"
52#include "llvm/Pass.h"
53#include "llvm/Support/Debug.h"
54#include "llvm/Support/KnownBits.h"
55#include "llvm/Transforms/Scalar.h"
56
57using namespace llvm;
58
59#define DEBUG_TYPE"guard-widening" "guard-widening"
60
61namespace {
62
63class GuardWideningImpl {
64 DominatorTree &DT;
65 PostDominatorTree &PDT;
66 LoopInfo &LI;
67
68 /// The set of guards whose conditions have been widened into dominating
69 /// guards.
70 SmallVector<IntrinsicInst *, 16> EliminatedGuards;
71
72 /// The set of guards which have been widened to include conditions to other
73 /// guards.
74 DenseSet<IntrinsicInst *> WidenedGuards;
75
76 /// Try to eliminate guard \p Guard by widening it into an earlier dominating
77 /// guard. \p DFSI is the DFS iterator on the dominator tree that is
78 /// currently visiting the block containing \p Guard, and \p GuardsPerBlock
79 /// maps BasicBlocks to the set of guards seen in that block.
80 bool eliminateGuardViaWidening(
81 IntrinsicInst *Guard, const df_iterator<DomTreeNode *> &DFSI,
82 const DenseMap<BasicBlock *, SmallVector<IntrinsicInst *, 8>> &
83 GuardsPerBlock);
84
85 /// Used to keep track of which widening potential is more effective.
86 enum WideningScore {
87 /// Don't widen.
88 WS_IllegalOrNegative,
89
90 /// Widening is performance neutral as far as the cycles spent in check
91 /// conditions goes (but can still help, e.g., code layout, having less
92 /// deopt state).
93 WS_Neutral,
94
95 /// Widening is profitable.
96 WS_Positive,
97
98 /// Widening is very profitable. Not significantly different from \c
99 /// WS_Positive, except by the order.
100 WS_VeryPositive
101 };
102
103 static StringRef scoreTypeToString(WideningScore WS);
104
105 /// Compute the score for widening the condition in \p DominatedGuard
106 /// (contained in \p DominatedGuardLoop) into \p DominatingGuard (contained in
107 /// \p DominatingGuardLoop).
108 WideningScore computeWideningScore(IntrinsicInst *DominatedGuard,
109 Loop *DominatedGuardLoop,
110 IntrinsicInst *DominatingGuard,
111 Loop *DominatingGuardLoop);
112
113 /// Helper to check if \p V can be hoisted to \p InsertPos.
114 bool isAvailableAt(Value *V, Instruction *InsertPos) {
115 SmallPtrSet<Instruction *, 8> Visited;
116 return isAvailableAt(V, InsertPos, Visited);
117 }
118
119 bool isAvailableAt(Value *V, Instruction *InsertPos,
120 SmallPtrSetImpl<Instruction *> &Visited);
121
122 /// Helper to hoist \p V to \p InsertPos. Guaranteed to succeed if \c
123 /// isAvailableAt returned true.
124 void makeAvailableAt(Value *V, Instruction *InsertPos);
125
126 /// Common helper used by \c widenGuard and \c isWideningCondProfitable. Try
127 /// to generate an expression computing the logical AND of \p Cond0 and \p
128 /// Cond1. Return true if the expression computing the AND is only as
129 /// expensive as computing one of the two. If \p InsertPt is true then
130 /// actually generate the resulting expression, make it available at \p
131 /// InsertPt and return it in \p Result (else no change to the IR is made).
132 bool widenCondCommon(Value *Cond0, Value *Cond1, Instruction *InsertPt,
133 Value *&Result);
134
135 /// Represents a range check of the form \c Base + \c Offset u< \c Length,
136 /// with the constraint that \c Length is not negative. \c CheckInst is the
137 /// pre-existing instruction in the IR that computes the result of this range
138 /// check.
139 class RangeCheck {
140 Value *Base;
141 ConstantInt *Offset;
142 Value *Length;
143 ICmpInst *CheckInst;
144
145 public:
146 explicit RangeCheck(Value *Base, ConstantInt *Offset, Value *Length,
147 ICmpInst *CheckInst)
148 : Base(Base), Offset(Offset), Length(Length), CheckInst(CheckInst) {}
149
150 void setBase(Value *NewBase) { Base = NewBase; }
151 void setOffset(ConstantInt *NewOffset) { Offset = NewOffset; }
152
153 Value *getBase() const { return Base; }
154 ConstantInt *getOffset() const { return Offset; }
155 const APInt &getOffsetValue() const { return getOffset()->getValue(); }
156 Value *getLength() const { return Length; };
157 ICmpInst *getCheckInst() const { return CheckInst; }
158
159 void print(raw_ostream &OS, bool PrintTypes = false) {
160 OS << "Base: ";
161 Base->printAsOperand(OS, PrintTypes);
162 OS << " Offset: ";
163 Offset->printAsOperand(OS, PrintTypes);
164 OS << " Length: ";
165 Length->printAsOperand(OS, PrintTypes);
166 }
167
168 LLVM_DUMP_METHOD__attribute__((noinline)) __attribute__((__used__)) void dump() {
169 print(dbgs());
170 dbgs() << "\n";
171 }
172 };
173
174 /// Parse \p CheckCond into a conjunction (logical-and) of range checks; and
175 /// append them to \p Checks. Returns true on success, may clobber \c Checks
176 /// on failure.
177 bool parseRangeChecks(Value *CheckCond, SmallVectorImpl<RangeCheck> &Checks) {
178 SmallPtrSet<Value *, 8> Visited;
179 return parseRangeChecks(CheckCond, Checks, Visited);
53
Calling 'GuardWideningImpl::parseRangeChecks'
56
Returning from 'GuardWideningImpl::parseRangeChecks'
59
Calling 'GuardWideningImpl::parseRangeChecks'
62
Returning from 'GuardWideningImpl::parseRangeChecks'
180 }
181
182 bool parseRangeChecks(Value *CheckCond, SmallVectorImpl<RangeCheck> &Checks,
183 SmallPtrSetImpl<Value *> &Visited);
184
185 /// Combine the checks in \p Checks into a smaller set of checks and append
186 /// them into \p CombinedChecks. Return true on success (i.e. all of checks
187 /// in \p Checks were combined into \p CombinedChecks). Clobbers \p Checks
188 /// and \p CombinedChecks on success and on failure.
189 bool combineRangeChecks(SmallVectorImpl<RangeCheck> &Checks,
190 SmallVectorImpl<RangeCheck> &CombinedChecks);
191
192 /// Can we compute the logical AND of \p Cond0 and \p Cond1 for the price of
193 /// computing only one of the two expressions?
194 bool isWideningCondProfitable(Value *Cond0, Value *Cond1) {
195 Value *ResultUnused;
196 return widenCondCommon(Cond0, Cond1, /*InsertPt=*/nullptr, ResultUnused);
197 }
198
199 /// Widen \p ToWiden to fail if \p NewCondition is false (in addition to
200 /// whatever it is already checking).
201 void widenGuard(IntrinsicInst *ToWiden, Value *NewCondition) {
202 Value *Result;
203 widenCondCommon(ToWiden->getArgOperand(0), NewCondition, ToWiden, Result);
1
Passing value via 4th parameter 'Result'
2
Calling 'GuardWideningImpl::widenCondCommon'
204 ToWiden->setArgOperand(0, Result);
205 }
206
207public:
208 explicit GuardWideningImpl(DominatorTree &DT, PostDominatorTree &PDT,
209 LoopInfo &LI)
210 : DT(DT), PDT(PDT), LI(LI) {}
211
212 /// The entry point for this pass.
213 bool run();
214};
215
216struct GuardWideningLegacyPass : public FunctionPass {
217 static char ID;
218 GuardWideningPass Impl;
219
220 GuardWideningLegacyPass() : FunctionPass(ID) {
221 initializeGuardWideningLegacyPassPass(*PassRegistry::getPassRegistry());
222 }
223
224 bool runOnFunction(Function &F) override {
225 if (skipFunction(F))
226 return false;
227 return GuardWideningImpl(
228 getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
229 getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree(),
230 getAnalysis<LoopInfoWrapperPass>().getLoopInfo()).run();
231 }
232
233 void getAnalysisUsage(AnalysisUsage &AU) const override {
234 AU.setPreservesCFG();
235 AU.addRequired<DominatorTreeWrapperPass>();
236 AU.addRequired<PostDominatorTreeWrapperPass>();
237 AU.addRequired<LoopInfoWrapperPass>();
238 }
239};
240
241}
242
243bool GuardWideningImpl::run() {
244 using namespace llvm::PatternMatch;
245
246 DenseMap<BasicBlock *, SmallVector<IntrinsicInst *, 8>> GuardsInBlock;
247 bool Changed = false;
248
249 for (auto DFI = df_begin(DT.getRootNode()), DFE = df_end(DT.getRootNode());
250 DFI != DFE; ++DFI) {
251 auto *BB = (*DFI)->getBlock();
252 auto &CurrentList = GuardsInBlock[BB];
253
254 for (auto &I : *BB)
255 if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>()))
256 CurrentList.push_back(cast<IntrinsicInst>(&I));
257
258 for (auto *II : CurrentList)
259 Changed |= eliminateGuardViaWidening(II, DFI, GuardsInBlock);
260 }
261
262 for (auto *II : EliminatedGuards)
263 if (!WidenedGuards.count(II))
264 II->eraseFromParent();
265
266 return Changed;
267}
268
269bool GuardWideningImpl::eliminateGuardViaWidening(
270 IntrinsicInst *GuardInst, const df_iterator<DomTreeNode *> &DFSI,
271 const DenseMap<BasicBlock *, SmallVector<IntrinsicInst *, 8>> &
272 GuardsInBlock) {
273 IntrinsicInst *BestSoFar = nullptr;
274 auto BestScoreSoFar = WS_IllegalOrNegative;
275 auto *GuardInstLoop = LI.getLoopFor(GuardInst->getParent());
276
277 // In the set of dominating guards, find the one we can merge GuardInst with
278 // for the most profit.
279 for (unsigned i = 0, e = DFSI.getPathLength(); i != e; ++i) {
280 auto *CurBB = DFSI.getPath(i)->getBlock();
281 auto *CurLoop = LI.getLoopFor(CurBB);
282 assert(GuardsInBlock.count(CurBB) && "Must have been populated by now!")(static_cast <bool> (GuardsInBlock.count(CurBB) &&
"Must have been populated by now!") ? void (0) : __assert_fail
("GuardsInBlock.count(CurBB) && \"Must have been populated by now!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 282, __extension__ __PRETTY_FUNCTION__))
;
283 const auto &GuardsInCurBB = GuardsInBlock.find(CurBB)->second;
284
285 auto I = GuardsInCurBB.begin();
286 auto E = GuardsInCurBB.end();
287
288#ifndef NDEBUG
289 {
290 unsigned Index = 0;
291 for (auto &I : *CurBB) {
292 if (Index == GuardsInCurBB.size())
293 break;
294 if (GuardsInCurBB[Index] == &I)
295 Index++;
296 }
297 assert(Index == GuardsInCurBB.size() &&(static_cast <bool> (Index == GuardsInCurBB.size() &&
"Guards expected to be in order!") ? void (0) : __assert_fail
("Index == GuardsInCurBB.size() && \"Guards expected to be in order!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 298, __extension__ __PRETTY_FUNCTION__))
298 "Guards expected to be in order!")(static_cast <bool> (Index == GuardsInCurBB.size() &&
"Guards expected to be in order!") ? void (0) : __assert_fail
("Index == GuardsInCurBB.size() && \"Guards expected to be in order!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 298, __extension__ __PRETTY_FUNCTION__))
;
299 }
300#endif
301
302 assert((i == (e - 1)) == (GuardInst->getParent() == CurBB) && "Bad DFS?")(static_cast <bool> ((i == (e - 1)) == (GuardInst->getParent
() == CurBB) && "Bad DFS?") ? void (0) : __assert_fail
("(i == (e - 1)) == (GuardInst->getParent() == CurBB) && \"Bad DFS?\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 302, __extension__ __PRETTY_FUNCTION__))
;
303
304 if (i == (e - 1)) {
305 // Corner case: make sure we're only looking at guards strictly dominating
306 // GuardInst when visiting GuardInst->getParent().
307 auto NewEnd = std::find(I, E, GuardInst);
308 assert(NewEnd != E && "GuardInst not in its own block?")(static_cast <bool> (NewEnd != E && "GuardInst not in its own block?"
) ? void (0) : __assert_fail ("NewEnd != E && \"GuardInst not in its own block?\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 308, __extension__ __PRETTY_FUNCTION__))
;
309 E = NewEnd;
310 }
311
312 for (auto *Candidate : make_range(I, E)) {
313 auto Score =
314 computeWideningScore(GuardInst, GuardInstLoop, Candidate, CurLoop);
315 DEBUG(dbgs() << "Score between " << *GuardInst->getArgOperand(0)do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("guard-widening")) { dbgs() << "Score between " <<
*GuardInst->getArgOperand(0) << " and " << *Candidate
->getArgOperand(0) << " is " << scoreTypeToString
(Score) << "\n"; } } while (false)
316 << " and " << *Candidate->getArgOperand(0) << " is "do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("guard-widening")) { dbgs() << "Score between " <<
*GuardInst->getArgOperand(0) << " and " << *Candidate
->getArgOperand(0) << " is " << scoreTypeToString
(Score) << "\n"; } } while (false)
317 << scoreTypeToString(Score) << "\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("guard-widening")) { dbgs() << "Score between " <<
*GuardInst->getArgOperand(0) << " and " << *Candidate
->getArgOperand(0) << " is " << scoreTypeToString
(Score) << "\n"; } } while (false)
;
318 if (Score > BestScoreSoFar) {
319 BestScoreSoFar = Score;
320 BestSoFar = Candidate;
321 }
322 }
323 }
324
325 if (BestScoreSoFar == WS_IllegalOrNegative) {
326 DEBUG(dbgs() << "Did not eliminate guard " << *GuardInst << "\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("guard-widening")) { dbgs() << "Did not eliminate guard "
<< *GuardInst << "\n"; } } while (false)
;
327 return false;
328 }
329
330 assert(BestSoFar != GuardInst && "Should have never visited same guard!")(static_cast <bool> (BestSoFar != GuardInst && "Should have never visited same guard!"
) ? void (0) : __assert_fail ("BestSoFar != GuardInst && \"Should have never visited same guard!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 330, __extension__ __PRETTY_FUNCTION__))
;
331 assert(DT.dominates(BestSoFar, GuardInst) && "Should be!")(static_cast <bool> (DT.dominates(BestSoFar, GuardInst)
&& "Should be!") ? void (0) : __assert_fail ("DT.dominates(BestSoFar, GuardInst) && \"Should be!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 331, __extension__ __PRETTY_FUNCTION__))
;
332
333 DEBUG(dbgs() << "Widening " << *GuardInst << " into " << *BestSoFardo { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("guard-widening")) { dbgs() << "Widening " << *GuardInst
<< " into " << *BestSoFar << " with score "
<< scoreTypeToString(BestScoreSoFar) << "\n"; } }
while (false)
334 << " with score " << scoreTypeToString(BestScoreSoFar) << "\n")do { if (::llvm::DebugFlag && ::llvm::isCurrentDebugType
("guard-widening")) { dbgs() << "Widening " << *GuardInst
<< " into " << *BestSoFar << " with score "
<< scoreTypeToString(BestScoreSoFar) << "\n"; } }
while (false)
;
335 widenGuard(BestSoFar, GuardInst->getArgOperand(0));
336 GuardInst->setArgOperand(0, ConstantInt::getTrue(GuardInst->getContext()));
337 EliminatedGuards.push_back(GuardInst);
338 WidenedGuards.insert(BestSoFar);
339 return true;
340}
341
342GuardWideningImpl::WideningScore GuardWideningImpl::computeWideningScore(
343 IntrinsicInst *DominatedGuard, Loop *DominatedGuardLoop,
344 IntrinsicInst *DominatingGuard, Loop *DominatingGuardLoop) {
345 bool HoistingOutOfLoop = false;
346
347 if (DominatingGuardLoop != DominatedGuardLoop) {
348 if (DominatingGuardLoop &&
349 !DominatingGuardLoop->contains(DominatedGuardLoop))
350 return WS_IllegalOrNegative;
351
352 HoistingOutOfLoop = true;
353 }
354
355 if (!isAvailableAt(DominatedGuard->getArgOperand(0), DominatingGuard))
356 return WS_IllegalOrNegative;
357
358 bool HoistingOutOfIf =
359 !PDT.dominates(DominatedGuard->getParent(), DominatingGuard->getParent());
360
361 if (isWideningCondProfitable(DominatedGuard->getArgOperand(0),
362 DominatingGuard->getArgOperand(0)))
363 return HoistingOutOfLoop ? WS_VeryPositive : WS_Positive;
364
365 if (HoistingOutOfLoop)
366 return WS_Positive;
367
368 return HoistingOutOfIf ? WS_IllegalOrNegative : WS_Neutral;
369}
370
371bool GuardWideningImpl::isAvailableAt(Value *V, Instruction *Loc,
372 SmallPtrSetImpl<Instruction *> &Visited) {
373 auto *Inst = dyn_cast<Instruction>(V);
374 if (!Inst || DT.dominates(Inst, Loc) || Visited.count(Inst))
375 return true;
376
377 if (!isSafeToSpeculativelyExecute(Inst, Loc, &DT) ||
378 Inst->mayReadFromMemory())
379 return false;
380
381 Visited.insert(Inst);
382
383 // We only want to go _up_ the dominance chain when recursing.
384 assert(!isa<PHINode>(Loc) &&(static_cast <bool> (!isa<PHINode>(Loc) &&
"PHIs should return false for isSafeToSpeculativelyExecute")
? void (0) : __assert_fail ("!isa<PHINode>(Loc) && \"PHIs should return false for isSafeToSpeculativelyExecute\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 385, __extension__ __PRETTY_FUNCTION__))
385 "PHIs should return false for isSafeToSpeculativelyExecute")(static_cast <bool> (!isa<PHINode>(Loc) &&
"PHIs should return false for isSafeToSpeculativelyExecute")
? void (0) : __assert_fail ("!isa<PHINode>(Loc) && \"PHIs should return false for isSafeToSpeculativelyExecute\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 385, __extension__ __PRETTY_FUNCTION__))
;
386 assert(DT.isReachableFromEntry(Inst->getParent()) &&(static_cast <bool> (DT.isReachableFromEntry(Inst->getParent
()) && "We did a DFS from the block entry!") ? void (
0) : __assert_fail ("DT.isReachableFromEntry(Inst->getParent()) && \"We did a DFS from the block entry!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 387, __extension__ __PRETTY_FUNCTION__))
387 "We did a DFS from the block entry!")(static_cast <bool> (DT.isReachableFromEntry(Inst->getParent
()) && "We did a DFS from the block entry!") ? void (
0) : __assert_fail ("DT.isReachableFromEntry(Inst->getParent()) && \"We did a DFS from the block entry!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 387, __extension__ __PRETTY_FUNCTION__))
;
388 return all_of(Inst->operands(),
389 [&](Value *Op) { return isAvailableAt(Op, Loc, Visited); });
390}
391
392void GuardWideningImpl::makeAvailableAt(Value *V, Instruction *Loc) {
393 auto *Inst = dyn_cast<Instruction>(V);
394 if (!Inst || DT.dominates(Inst, Loc))
395 return;
396
397 assert(isSafeToSpeculativelyExecute(Inst, Loc, &DT) &&(static_cast <bool> (isSafeToSpeculativelyExecute(Inst,
Loc, &DT) && !Inst->mayReadFromMemory() &&
"Should've checked with isAvailableAt!") ? void (0) : __assert_fail
("isSafeToSpeculativelyExecute(Inst, Loc, &DT) && !Inst->mayReadFromMemory() && \"Should've checked with isAvailableAt!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 398, __extension__ __PRETTY_FUNCTION__))
398 !Inst->mayReadFromMemory() && "Should've checked with isAvailableAt!")(static_cast <bool> (isSafeToSpeculativelyExecute(Inst,
Loc, &DT) && !Inst->mayReadFromMemory() &&
"Should've checked with isAvailableAt!") ? void (0) : __assert_fail
("isSafeToSpeculativelyExecute(Inst, Loc, &DT) && !Inst->mayReadFromMemory() && \"Should've checked with isAvailableAt!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 398, __extension__ __PRETTY_FUNCTION__))
;
399
400 for (Value *Op : Inst->operands())
401 makeAvailableAt(Op, Loc);
402
403 Inst->moveBefore(Loc);
404}
405
406bool GuardWideningImpl::widenCondCommon(Value *Cond0, Value *Cond1,
407 Instruction *InsertPt, Value *&Result) {
408 using namespace llvm::PatternMatch;
409
410 {
411 // L >u C0 && L >u C1 -> L >u max(C0, C1)
412 ConstantInt *RHS0, *RHS1;
413 Value *LHS;
414 ICmpInst::Predicate Pred0, Pred1;
415 if (match(Cond0, m_ICmp(Pred0, m_Value(LHS), m_ConstantInt(RHS0))) &&
3
Calling 'm_Value'
6
Returning from 'm_Value'
7
Calling 'm_ConstantInt'
10
Returning from 'm_ConstantInt'
11
Calling 'm_ICmp'
14
Returning from 'm_ICmp'
15
Calling 'match'
50
Returning from 'match'
51
Taking false branch
416 match(Cond1, m_ICmp(Pred1, m_Specific(LHS), m_ConstantInt(RHS1)))) {
417
418 ConstantRange CR0 =
419 ConstantRange::makeExactICmpRegion(Pred0, RHS0->getValue());
420 ConstantRange CR1 =
421 ConstantRange::makeExactICmpRegion(Pred1, RHS1->getValue());
422
423 // SubsetIntersect is a subset of the actual mathematical intersection of
424 // CR0 and CR1, while SupersetIntersect is a superset of the actual
425 // mathematical intersection. If these two ConstantRanges are equal, then
426 // we know we were able to represent the actual mathematical intersection
427 // of CR0 and CR1, and can use the same to generate an icmp instruction.
428 //
429 // Given what we're doing here and the semantics of guards, it would
430 // actually be correct to just use SubsetIntersect, but that may be too
431 // aggressive in cases we care about.
432 auto SubsetIntersect = CR0.inverse().unionWith(CR1.inverse()).inverse();
433 auto SupersetIntersect = CR0.intersectWith(CR1);
434
435 APInt NewRHSAP;
436 CmpInst::Predicate Pred;
437 if (SubsetIntersect == SupersetIntersect &&
438 SubsetIntersect.getEquivalentICmp(Pred, NewRHSAP)) {
439 if (InsertPt) {
440 ConstantInt *NewRHS = ConstantInt::get(Cond0->getContext(), NewRHSAP);
441 Result = new ICmpInst(InsertPt, Pred, LHS, NewRHS, "wide.chk");
442 }
443 return true;
444 }
445 }
446 }
447
448 {
449 SmallVector<GuardWideningImpl::RangeCheck, 4> Checks, CombinedChecks;
450 if (parseRangeChecks(Cond0, Checks) && parseRangeChecks(Cond1, Checks) &&
52
Calling 'GuardWideningImpl::parseRangeChecks'
57
Returning from 'GuardWideningImpl::parseRangeChecks'
58
Calling 'GuardWideningImpl::parseRangeChecks'
63
Returning from 'GuardWideningImpl::parseRangeChecks'
71
Taking true branch
451 combineRangeChecks(Checks, CombinedChecks)) {
64
Calling 'GuardWideningImpl::combineRangeChecks'
70
Returning from 'GuardWideningImpl::combineRangeChecks'
452 if (InsertPt) {
72
Taking true branch
453 Result = nullptr;
73
Null pointer value stored to 'Result'
454 for (auto &RC : CombinedChecks) {
74
Assuming '__begin3' is equal to '__end3'
455 makeAvailableAt(RC.getCheckInst(), InsertPt);
456 if (Result)
457 Result = BinaryOperator::CreateAnd(RC.getCheckInst(), Result, "",
458 InsertPt);
459 else
460 Result = RC.getCheckInst();
461 }
462
463 Result->setName("wide.chk");
75
Calling constructor for 'Twine'
101
Returning from constructor for 'Twine'
102
Called C++ object pointer is null
464 }
465 return true;
466 }
467 }
468
469 // Base case -- just logical-and the two conditions together.
470
471 if (InsertPt) {
472 makeAvailableAt(Cond0, InsertPt);
473 makeAvailableAt(Cond1, InsertPt);
474
475 Result = BinaryOperator::CreateAnd(Cond0, Cond1, "wide.chk", InsertPt);
476 }
477
478 // We were not able to compute Cond0 AND Cond1 for the price of one.
479 return false;
480}
481
482bool GuardWideningImpl::parseRangeChecks(
483 Value *CheckCond, SmallVectorImpl<GuardWideningImpl::RangeCheck> &Checks,
484 SmallPtrSetImpl<Value *> &Visited) {
485 if (!Visited.insert(CheckCond).second)
54
Assuming the condition is true
55
Taking true branch
60
Assuming the condition is true
61
Taking true branch
486 return true;
487
488 using namespace llvm::PatternMatch;
489
490 {
491 Value *AndLHS, *AndRHS;
492 if (match(CheckCond, m_And(m_Value(AndLHS), m_Value(AndRHS))))
493 return parseRangeChecks(AndLHS, Checks) &&
494 parseRangeChecks(AndRHS, Checks);
495 }
496
497 auto *IC = dyn_cast<ICmpInst>(CheckCond);
498 if (!IC || !IC->getOperand(0)->getType()->isIntegerTy() ||
499 (IC->getPredicate() != ICmpInst::ICMP_ULT &&
500 IC->getPredicate() != ICmpInst::ICMP_UGT))
501 return false;
502
503 Value *CmpLHS = IC->getOperand(0), *CmpRHS = IC->getOperand(1);
504 if (IC->getPredicate() == ICmpInst::ICMP_UGT)
505 std::swap(CmpLHS, CmpRHS);
506
507 auto &DL = IC->getModule()->getDataLayout();
508
509 GuardWideningImpl::RangeCheck Check(
510 CmpLHS, cast<ConstantInt>(ConstantInt::getNullValue(CmpRHS->getType())),
511 CmpRHS, IC);
512
513 if (!isKnownNonNegative(Check.getLength(), DL))
514 return false;
515
516 // What we have in \c Check now is a correct interpretation of \p CheckCond.
517 // Try to see if we can move some constant offsets into the \c Offset field.
518
519 bool Changed;
520 auto &Ctx = CheckCond->getContext();
521
522 do {
523 Value *OpLHS;
524 ConstantInt *OpRHS;
525 Changed = false;
526
527#ifndef NDEBUG
528 auto *BaseInst = dyn_cast<Instruction>(Check.getBase());
529 assert((!BaseInst || DT.isReachableFromEntry(BaseInst->getParent())) &&(static_cast <bool> ((!BaseInst || DT.isReachableFromEntry
(BaseInst->getParent())) && "Unreachable instruction?"
) ? void (0) : __assert_fail ("(!BaseInst || DT.isReachableFromEntry(BaseInst->getParent())) && \"Unreachable instruction?\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 530, __extension__ __PRETTY_FUNCTION__))
530 "Unreachable instruction?")(static_cast <bool> ((!BaseInst || DT.isReachableFromEntry
(BaseInst->getParent())) && "Unreachable instruction?"
) ? void (0) : __assert_fail ("(!BaseInst || DT.isReachableFromEntry(BaseInst->getParent())) && \"Unreachable instruction?\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 530, __extension__ __PRETTY_FUNCTION__))
;
531#endif
532
533 if (match(Check.getBase(), m_Add(m_Value(OpLHS), m_ConstantInt(OpRHS)))) {
534 Check.setBase(OpLHS);
535 APInt NewOffset = Check.getOffsetValue() + OpRHS->getValue();
536 Check.setOffset(ConstantInt::get(Ctx, NewOffset));
537 Changed = true;
538 } else if (match(Check.getBase(),
539 m_Or(m_Value(OpLHS), m_ConstantInt(OpRHS)))) {
540 KnownBits Known = computeKnownBits(OpLHS, DL);
541 if ((OpRHS->getValue() & Known.Zero) == OpRHS->getValue()) {
542 Check.setBase(OpLHS);
543 APInt NewOffset = Check.getOffsetValue() + OpRHS->getValue();
544 Check.setOffset(ConstantInt::get(Ctx, NewOffset));
545 Changed = true;
546 }
547 }
548 } while (Changed);
549
550 Checks.push_back(Check);
551 return true;
552}
553
554bool GuardWideningImpl::combineRangeChecks(
555 SmallVectorImpl<GuardWideningImpl::RangeCheck> &Checks,
556 SmallVectorImpl<GuardWideningImpl::RangeCheck> &RangeChecksOut) {
557 unsigned OldCount = Checks.size();
558 while (!Checks.empty()) {
65
Calling 'SmallVectorBase::empty'
67
Returning from 'SmallVectorBase::empty'
68
Loop condition is false. Execution continues on line 650
559 // Pick all of the range checks with a specific base and length, and try to
560 // merge them.
561 Value *CurrentBase = Checks.front().getBase();
562 Value *CurrentLength = Checks.front().getLength();
563
564 SmallVector<GuardWideningImpl::RangeCheck, 3> CurrentChecks;
565
566 auto IsCurrentCheck = [&](GuardWideningImpl::RangeCheck &RC) {
567 return RC.getBase() == CurrentBase && RC.getLength() == CurrentLength;
568 };
569
570 copy_if(Checks, std::back_inserter(CurrentChecks), IsCurrentCheck);
571 Checks.erase(remove_if(Checks, IsCurrentCheck), Checks.end());
572
573 assert(CurrentChecks.size() != 0 && "We know we have at least one!")(static_cast <bool> (CurrentChecks.size() != 0 &&
"We know we have at least one!") ? void (0) : __assert_fail (
"CurrentChecks.size() != 0 && \"We know we have at least one!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 573, __extension__ __PRETTY_FUNCTION__))
;
574
575 if (CurrentChecks.size() < 3) {
576 RangeChecksOut.insert(RangeChecksOut.end(), CurrentChecks.begin(),
577 CurrentChecks.end());
578 continue;
579 }
580
581 // CurrentChecks.size() will typically be 3 here, but so far there has been
582 // no need to hard-code that fact.
583
584 std::sort(CurrentChecks.begin(), CurrentChecks.end(),
585 [&](const GuardWideningImpl::RangeCheck &LHS,
586 const GuardWideningImpl::RangeCheck &RHS) {
587 return LHS.getOffsetValue().slt(RHS.getOffsetValue());
588 });
589
590 // Note: std::sort should not invalidate the ChecksStart iterator.
591
592 ConstantInt *MinOffset = CurrentChecks.front().getOffset(),
593 *MaxOffset = CurrentChecks.back().getOffset();
594
595 unsigned BitWidth = MaxOffset->getValue().getBitWidth();
596 if ((MaxOffset->getValue() - MinOffset->getValue())
597 .ugt(APInt::getSignedMinValue(BitWidth)))
598 return false;
599
600 APInt MaxDiff = MaxOffset->getValue() - MinOffset->getValue();
601 const APInt &HighOffset = MaxOffset->getValue();
602 auto OffsetOK = [&](const GuardWideningImpl::RangeCheck &RC) {
603 return (HighOffset - RC.getOffsetValue()).ult(MaxDiff);
604 };
605
606 if (MaxDiff.isMinValue() ||
607 !std::all_of(std::next(CurrentChecks.begin()), CurrentChecks.end(),
608 OffsetOK))
609 return false;
610
611 // We have a series of f+1 checks as:
612 //
613 // I+k_0 u< L ... Chk_0
614 // I+k_1 u< L ... Chk_1
615 // ...
616 // I+k_f u< L ... Chk_f
617 //
618 // with forall i in [0,f]: k_f-k_i u< k_f-k_0 ... Precond_0
619 // k_f-k_0 u< INT_MIN+k_f ... Precond_1
620 // k_f != k_0 ... Precond_2
621 //
622 // Claim:
623 // Chk_0 AND Chk_f implies all the other checks
624 //
625 // Informal proof sketch:
626 //
627 // We will show that the integer range [I+k_0,I+k_f] does not unsigned-wrap
628 // (i.e. going from I+k_0 to I+k_f does not cross the -1,0 boundary) and
629 // thus I+k_f is the greatest unsigned value in that range.
630 //
631 // This combined with Ckh_(f+1) shows that everything in that range is u< L.
632 // Via Precond_0 we know that all of the indices in Chk_0 through Chk_(f+1)
633 // lie in [I+k_0,I+k_f], this proving our claim.
634 //
635 // To see that [I+k_0,I+k_f] is not a wrapping range, note that there are
636 // two possibilities: I+k_0 u< I+k_f or I+k_0 >u I+k_f (they can't be equal
637 // since k_0 != k_f). In the former case, [I+k_0,I+k_f] is not a wrapping
638 // range by definition, and the latter case is impossible:
639 //
640 // 0-----I+k_f---I+k_0----L---INT_MAX,INT_MIN------------------(-1)
641 // xxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
642 //
643 // For Chk_0 to succeed, we'd have to have k_f-k_0 (the range highlighted
644 // with 'x' above) to be at least >u INT_MIN.
645
646 RangeChecksOut.emplace_back(CurrentChecks.front());
647 RangeChecksOut.emplace_back(CurrentChecks.back());
648 }
649
650 assert(RangeChecksOut.size() <= OldCount && "We pessimized!")(static_cast <bool> (RangeChecksOut.size() <= OldCount
&& "We pessimized!") ? void (0) : __assert_fail ("RangeChecksOut.size() <= OldCount && \"We pessimized!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 650, __extension__ __PRETTY_FUNCTION__))
;
69
Within the expansion of the macro 'assert':
651 return RangeChecksOut.size() != OldCount;
652}
653
654PreservedAnalyses GuardWideningPass::run(Function &F,
655 FunctionAnalysisManager &AM) {
656 auto &DT = AM.getResult<DominatorTreeAnalysis>(F);
657 auto &LI = AM.getResult<LoopAnalysis>(F);
658 auto &PDT = AM.getResult<PostDominatorTreeAnalysis>(F);
659 if (!GuardWideningImpl(DT, PDT, LI).run())
660 return PreservedAnalyses::all();
661
662 PreservedAnalyses PA;
663 PA.preserveSet<CFGAnalyses>();
664 return PA;
665}
666
667#ifndef NDEBUG
668StringRef GuardWideningImpl::scoreTypeToString(WideningScore WS) {
669 switch (WS) {
670 case WS_IllegalOrNegative:
671 return "IllegalOrNegative";
672 case WS_Neutral:
673 return "Neutral";
674 case WS_Positive:
675 return "Positive";
676 case WS_VeryPositive:
677 return "VeryPositive";
678 }
679
680 llvm_unreachable("Fully covered switch above!")::llvm::llvm_unreachable_internal("Fully covered switch above!"
, "/build/llvm-toolchain-snapshot-7~svn326551/lib/Transforms/Scalar/GuardWidening.cpp"
, 680)
;
681}
682#endif
683
684char GuardWideningLegacyPass::ID = 0;
685
686INITIALIZE_PASS_BEGIN(GuardWideningLegacyPass, "guard-widening", "Widen guards",static void *initializeGuardWideningLegacyPassPassOnce(PassRegistry
&Registry) {
687 false, false)static void *initializeGuardWideningLegacyPassPassOnce(PassRegistry
&Registry) {
688INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)initializeDominatorTreeWrapperPassPass(Registry);
689INITIALIZE_PASS_DEPENDENCY(PostDominatorTreeWrapperPass)initializePostDominatorTreeWrapperPassPass(Registry);
690INITIALIZE_PASS_DEPENDENCY(LoopInfoWrapperPass)initializeLoopInfoWrapperPassPass(Registry);
691INITIALIZE_PASS_END(GuardWideningLegacyPass, "guard-widening", "Widen guards",PassInfo *PI = new PassInfo( "Widen guards", "guard-widening"
, &GuardWideningLegacyPass::ID, PassInfo::NormalCtor_t(callDefaultCtor
<GuardWideningLegacyPass>), false, false); Registry.registerPass
(*PI, true); return PI; } static llvm::once_flag InitializeGuardWideningLegacyPassPassFlag
; void llvm::initializeGuardWideningLegacyPassPass(PassRegistry
&Registry) { llvm::call_once(InitializeGuardWideningLegacyPassPassFlag
, initializeGuardWideningLegacyPassPassOnce, std::ref(Registry
)); }
692 false, false)PassInfo *PI = new PassInfo( "Widen guards", "guard-widening"
, &GuardWideningLegacyPass::ID, PassInfo::NormalCtor_t(callDefaultCtor
<GuardWideningLegacyPass>), false, false); Registry.registerPass
(*PI, true); return PI; } static llvm::once_flag InitializeGuardWideningLegacyPassPassFlag
; void llvm::initializeGuardWideningLegacyPassPass(PassRegistry
&Registry) { llvm::call_once(InitializeGuardWideningLegacyPassPassFlag
, initializeGuardWideningLegacyPassPassOnce, std::ref(Registry
)); }
693
694FunctionPass *llvm::createGuardWideningPass() {
695 return new GuardWideningLegacyPass();
696}

/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/PatternMatch.h

1//===- PatternMatch.h - Match on the LLVM IR --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file provides a simple and efficient mechanism for performing general
11// tree-based pattern matches on the LLVM IR. The power of these routines is
12// that it allows you to write concise patterns that are expressive and easy to
13// understand. The other major advantage of this is that it allows you to
14// trivially capture/bind elements in the pattern to variables. For example,
15// you can do something like this:
16//
17// Value *Exp = ...
18// Value *X, *Y; ConstantInt *C1, *C2; // (X & C1) | (Y & C2)
19// if (match(Exp, m_Or(m_And(m_Value(X), m_ConstantInt(C1)),
20// m_And(m_Value(Y), m_ConstantInt(C2))))) {
21// ... Pattern is matched and variables are bound ...
22// }
23//
24// This is primarily useful to things like the instruction combiner, but can
25// also be useful for static analysis tools or code generators.
26//
27//===----------------------------------------------------------------------===//
28
29#ifndef LLVM_IR_PATTERNMATCH_H
30#define LLVM_IR_PATTERNMATCH_H
31
32#include "llvm/ADT/APFloat.h"
33#include "llvm/ADT/APInt.h"
34#include "llvm/IR/CallSite.h"
35#include "llvm/IR/Constant.h"
36#include "llvm/IR/Constants.h"
37#include "llvm/IR/InstrTypes.h"
38#include "llvm/IR/Instruction.h"
39#include "llvm/IR/Instructions.h"
40#include "llvm/IR/Intrinsics.h"
41#include "llvm/IR/Operator.h"
42#include "llvm/IR/Value.h"
43#include "llvm/Support/Casting.h"
44#include <cstdint>
45
46namespace llvm {
47namespace PatternMatch {
48
49template <typename Val, typename Pattern> bool match(Val *V, const Pattern &P) {
50 return const_cast<Pattern &>(P).match(V);
16
Calling 'CmpClass_match::match'
49
Returning from 'CmpClass_match::match'
51}
52
53template <typename SubPattern_t> struct OneUse_match {
54 SubPattern_t SubPattern;
55
56 OneUse_match(const SubPattern_t &SP) : SubPattern(SP) {}
57
58 template <typename OpTy> bool match(OpTy *V) {
59 return V->hasOneUse() && SubPattern.match(V);
60 }
61};
62
63template <typename T> inline OneUse_match<T> m_OneUse(const T &SubPattern) {
64 return SubPattern;
65}
66
67template <typename Class> struct class_match {
68 template <typename ITy> bool match(ITy *V) { return isa<Class>(V); }
69};
70
71/// Match an arbitrary value and ignore it.
72inline class_match<Value> m_Value() { return class_match<Value>(); }
73
74/// Match an arbitrary binary operation and ignore it.
75inline class_match<BinaryOperator> m_BinOp() {
76 return class_match<BinaryOperator>();
77}
78
79/// Matches any compare instruction and ignore it.
80inline class_match<CmpInst> m_Cmp() { return class_match<CmpInst>(); }
81
82/// Match an arbitrary ConstantInt and ignore it.
83inline class_match<ConstantInt> m_ConstantInt() {
84 return class_match<ConstantInt>();
85}
86
87/// Match an arbitrary undef constant.
88inline class_match<UndefValue> m_Undef() { return class_match<UndefValue>(); }
89
90/// Match an arbitrary Constant and ignore it.
91inline class_match<Constant> m_Constant() { return class_match<Constant>(); }
92
93/// Matching combinators
94template <typename LTy, typename RTy> struct match_combine_or {
95 LTy L;
96 RTy R;
97
98 match_combine_or(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
99
100 template <typename ITy> bool match(ITy *V) {
101 if (L.match(V))
102 return true;
103 if (R.match(V))
104 return true;
105 return false;
106 }
107};
108
109template <typename LTy, typename RTy> struct match_combine_and {
110 LTy L;
111 RTy R;
112
113 match_combine_and(const LTy &Left, const RTy &Right) : L(Left), R(Right) {}
114
115 template <typename ITy> bool match(ITy *V) {
116 if (L.match(V))
117 if (R.match(V))
118 return true;
119 return false;
120 }
121};
122
123/// Combine two pattern matchers matching L || R
124template <typename LTy, typename RTy>
125inline match_combine_or<LTy, RTy> m_CombineOr(const LTy &L, const RTy &R) {
126 return match_combine_or<LTy, RTy>(L, R);
127}
128
129/// Combine two pattern matchers matching L && R
130template <typename LTy, typename RTy>
131inline match_combine_and<LTy, RTy> m_CombineAnd(const LTy &L, const RTy &R) {
132 return match_combine_and<LTy, RTy>(L, R);
133}
134
135struct match_zero {
136 template <typename ITy> bool match(ITy *V) {
137 if (const auto *C = dyn_cast<Constant>(V))
138 return C->isNullValue();
139 return false;
140 }
141};
142
143/// Match an arbitrary zero/null constant. This includes
144/// zero_initializer for vectors and ConstantPointerNull for pointers.
145inline match_zero m_Zero() { return match_zero(); }
146
147struct match_neg_zero {
148 template <typename ITy> bool match(ITy *V) {
149 if (const auto *C = dyn_cast<Constant>(V))
150 return C->isNegativeZeroValue();
151 return false;
152 }
153};
154
155/// Match an arbitrary zero/null constant. This includes
156/// zero_initializer for vectors and ConstantPointerNull for pointers. For
157/// floating point constants, this will match negative zero but not positive
158/// zero
159inline match_neg_zero m_NegZero() { return match_neg_zero(); }
160
161struct match_any_zero {
162 template <typename ITy> bool match(ITy *V) {
163 if (const auto *C = dyn_cast<Constant>(V))
164 return C->isZeroValue();
165 return false;
166 }
167};
168
169/// Match an arbitrary zero/null constant. This includes
170/// zero_initializer for vectors and ConstantPointerNull for pointers. For
171/// floating point constants, this will match negative zero and positive zero
172inline match_any_zero m_AnyZero() { return match_any_zero(); }
173
174struct match_nan {
175 template <typename ITy> bool match(ITy *V) {
176 if (const auto *C = dyn_cast<ConstantFP>(V))
177 return C->isNaN();
178 return false;
179 }
180};
181
182/// Match an arbitrary NaN constant. This includes quiet and signalling nans.
183inline match_nan m_NaN() { return match_nan(); }
184
185struct apint_match {
186 const APInt *&Res;
187
188 apint_match(const APInt *&R) : Res(R) {}
189
190 template <typename ITy> bool match(ITy *V) {
191 if (auto *CI = dyn_cast<ConstantInt>(V)) {
192 Res = &CI->getValue();
193 return true;
194 }
195 if (V->getType()->isVectorTy())
196 if (const auto *C = dyn_cast<Constant>(V))
197 if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue())) {
198 Res = &CI->getValue();
199 return true;
200 }
201 return false;
202 }
203};
204// Either constexpr if or renaming ConstantFP::getValueAPF to
205// ConstantFP::getValue is needed to do it via single template
206// function for both apint/apfloat.
207struct apfloat_match {
208 const APFloat *&Res;
209 apfloat_match(const APFloat *&R) : Res(R) {}
210 template <typename ITy> bool match(ITy *V) {
211 if (auto *CI = dyn_cast<ConstantFP>(V)) {
212 Res = &CI->getValueAPF();
213 return true;
214 }
215 if (V->getType()->isVectorTy())
216 if (const auto *C = dyn_cast<Constant>(V))
217 if (auto *CI = dyn_cast_or_null<ConstantFP>(C->getSplatValue())) {
218 Res = &CI->getValueAPF();
219 return true;
220 }
221 return false;
222 }
223};
224
225/// Match a ConstantInt or splatted ConstantVector, binding the
226/// specified pointer to the contained APInt.
227inline apint_match m_APInt(const APInt *&Res) { return Res; }
228
229/// Match a ConstantFP or splatted ConstantVector, binding the
230/// specified pointer to the contained APFloat.
231inline apfloat_match m_APFloat(const APFloat *&Res) { return Res; }
232
233template <int64_t Val> struct constantint_match {
234 template <typename ITy> bool match(ITy *V) {
235 if (const auto *CI = dyn_cast<ConstantInt>(V)) {
236 const APInt &CIV = CI->getValue();
237 if (Val >= 0)
238 return CIV == static_cast<uint64_t>(Val);
239 // If Val is negative, and CI is shorter than it, truncate to the right
240 // number of bits. If it is larger, then we have to sign extend. Just
241 // compare their negated values.
242 return -CIV == -Val;
243 }
244 return false;
245 }
246};
247
248/// Match a ConstantInt with a specific value.
249template <int64_t Val> inline constantint_match<Val> m_ConstantInt() {
250 return constantint_match<Val>();
251}
252
253/// This helper class is used to match scalar and vector constants that satisfy
254/// a specified predicate. For vector constants, undefined elements are ignored.
255template <typename Predicate> struct cst_pred_ty : public Predicate {
256 template <typename ITy> bool match(ITy *V) {
257 if (const auto *CI = dyn_cast<ConstantInt>(V))
258 return this->isValue(CI->getValue());
259 if (V->getType()->isVectorTy()) {
260 if (const auto *C = dyn_cast<Constant>(V)) {
261 if (const auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
262 return this->isValue(CI->getValue());
263
264 // Non-splat vector constant: check each element for a match.
265 unsigned NumElts = V->getType()->getVectorNumElements();
266 assert(NumElts != 0 && "Constant vector with no elements?")(static_cast <bool> (NumElts != 0 && "Constant vector with no elements?"
) ? void (0) : __assert_fail ("NumElts != 0 && \"Constant vector with no elements?\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/PatternMatch.h"
, 266, __extension__ __PRETTY_FUNCTION__))
;
267 for (unsigned i = 0; i != NumElts; ++i) {
268 Constant *Elt = C->getAggregateElement(i);
269 if (!Elt)
270 return false;
271 if (isa<UndefValue>(Elt))
272 continue;
273 auto *CI = dyn_cast<ConstantInt>(Elt);
274 if (!CI || !this->isValue(CI->getValue()))
275 return false;
276 }
277 return true;
278 }
279 }
280 return false;
281 }
282};
283
284/// This helper class is used to match scalar and vector constants that
285/// satisfy a specified predicate, and bind them to an APInt.
286template <typename Predicate> struct api_pred_ty : public Predicate {
287 const APInt *&Res;
288
289 api_pred_ty(const APInt *&R) : Res(R) {}
290
291 template <typename ITy> bool match(ITy *V) {
292 if (const auto *CI = dyn_cast<ConstantInt>(V))
293 if (this->isValue(CI->getValue())) {
294 Res = &CI->getValue();
295 return true;
296 }
297 if (V->getType()->isVectorTy())
298 if (const auto *C = dyn_cast<Constant>(V))
299 if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
300 if (this->isValue(CI->getValue())) {
301 Res = &CI->getValue();
302 return true;
303 }
304
305 return false;
306 }
307};
308
309///////////////////////////////////////////////////////////////////////////////
310//
311// Encapsulate constant value queries for use in templated predicate matchers.
312// This allows checking if constants match using compound predicates and works
313// with vector constants, possibly with relaxed constraints. For example, ignore
314// undef values.
315//
316///////////////////////////////////////////////////////////////////////////////
317
318struct is_all_ones {
319 bool isValue(const APInt &C) { return C.isAllOnesValue(); }
320};
321/// Match an integer or vector with all bits set.
322inline cst_pred_ty<is_all_ones> m_AllOnes() {
323 return cst_pred_ty<is_all_ones>();
324}
325
326struct is_maxsignedvalue {
327 bool isValue(const APInt &C) { return C.isMaxSignedValue(); }
328};
329/// Match an integer or vector with values having all bits except for the high
330/// bit set (0x7f...).
331inline cst_pred_ty<is_maxsignedvalue> m_MaxSignedValue() {
332 return cst_pred_ty<is_maxsignedvalue>();
333}
334inline api_pred_ty<is_maxsignedvalue> m_MaxSignedValue(const APInt *&V) {
335 return V;
336}
337
338struct is_negative {
339 bool isValue(const APInt &C) { return C.isNegative(); }
340};
341/// Match an integer or vector of negative values.
342inline cst_pred_ty<is_negative> m_Negative() {
343 return cst_pred_ty<is_negative>();
344}
345inline api_pred_ty<is_negative> m_Negative(const APInt *&V) {
346 return V;
347}
348
349struct is_nonnegative {
350 bool isValue(const APInt &C) { return C.isNonNegative(); }
351};
352/// Match an integer or vector of nonnegative values.
353inline cst_pred_ty<is_nonnegative> m_NonNegative() {
354 return cst_pred_ty<is_nonnegative>();
355}
356inline api_pred_ty<is_nonnegative> m_NonNegative(const APInt *&V) {
357 return V;
358}
359
360struct is_one {
361 bool isValue(const APInt &C) { return C.isOneValue(); }
362};
363/// Match an integer 1 or a vector with all elements equal to 1.
364inline cst_pred_ty<is_one> m_One() {
365 return cst_pred_ty<is_one>();
366}
367
368struct is_power2 {
369 bool isValue(const APInt &C) { return C.isPowerOf2(); }
370};
371/// Match an integer or vector power-of-2.
372inline cst_pred_ty<is_power2> m_Power2() {
373 return cst_pred_ty<is_power2>();
374}
375inline api_pred_ty<is_power2> m_Power2(const APInt *&V) {
376 return V;
377}
378
379struct is_power2_or_zero {
380 bool isValue(const APInt &C) { return !C || C.isPowerOf2(); }
381};
382/// Match an integer or vector of 0 or power-of-2 values.
383inline cst_pred_ty<is_power2_or_zero> m_Power2OrZero() {
384 return cst_pred_ty<is_power2_or_zero>();
385}
386inline api_pred_ty<is_power2_or_zero> m_Power2OrZero(const APInt *&V) {
387 return V;
388}
389
390struct is_sign_mask {
391 bool isValue(const APInt &C) { return C.isSignMask(); }
392};
393/// Match an integer or vector with only the sign bit(s) set.
394inline cst_pred_ty<is_sign_mask> m_SignMask() {
395 return cst_pred_ty<is_sign_mask>();
396}
397
398///////////////////////////////////////////////////////////////////////////////
399
400template <typename Class> struct bind_ty {
401 Class *&VR;
402
403 bind_ty(Class *&V) : VR(V) {}
404
405 template <typename ITy> bool match(ITy *V) {
406 if (auto *CV = dyn_cast<Class>(V)) {
407 VR = CV;
408 return true;
409 }
410 return false;
411 }
412};
413
414/// Match a value, capturing it if we match.
415inline bind_ty<Value> m_Value(Value *&V) { return V; }
4
Calling constructor for 'bind_ty'
5
Returning from constructor for 'bind_ty'
416inline bind_ty<const Value> m_Value(const Value *&V) { return V; }
417
418/// Match an instruction, capturing it if we match.
419inline bind_ty<Instruction> m_Instruction(Instruction *&I) { return I; }
420/// Match a binary operator, capturing it if we match.
421inline bind_ty<BinaryOperator> m_BinOp(BinaryOperator *&I) { return I; }
422
423/// Match a ConstantInt, capturing the value if we match.
424inline bind_ty<ConstantInt> m_ConstantInt(ConstantInt *&CI) { return CI; }
8
Calling constructor for 'bind_ty'
9
Returning from constructor for 'bind_ty'
425
426/// Match a Constant, capturing the value if we match.
427inline bind_ty<Constant> m_Constant(Constant *&C) { return C; }
428
429/// Match a ConstantFP, capturing the value if we match.
430inline bind_ty<ConstantFP> m_ConstantFP(ConstantFP *&C) { return C; }
431
432/// Match a specified Value*.
433struct specificval_ty {
434 const Value *Val;
435
436 specificval_ty(const Value *V) : Val(V) {}
437
438 template <typename ITy> bool match(ITy *V) { return V == Val; }
439};
440
441/// Match if we have a specific specified value.
442inline specificval_ty m_Specific(const Value *V) { return V; }
443
444/// Match a specified floating point value or vector of all elements of
445/// that value.
446struct specific_fpval {
447 double Val;
448
449 specific_fpval(double V) : Val(V) {}
450
451 template <typename ITy> bool match(ITy *V) {
452 if (const auto *CFP = dyn_cast<ConstantFP>(V))
453 return CFP->isExactlyValue(Val);
454 if (V->getType()->isVectorTy())
455 if (const auto *C = dyn_cast<Constant>(V))
456 if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
457 return CFP->isExactlyValue(Val);
458 return false;
459 }
460};
461
462/// Match a specific floating point value or vector with all elements
463/// equal to the value.
464inline specific_fpval m_SpecificFP(double V) { return specific_fpval(V); }
465
466/// Match a float 1.0 or vector with all elements equal to 1.0.
467inline specific_fpval m_FPOne() { return m_SpecificFP(1.0); }
468
469struct bind_const_intval_ty {
470 uint64_t &VR;
471
472 bind_const_intval_ty(uint64_t &V) : VR(V) {}
473
474 template <typename ITy> bool match(ITy *V) {
475 if (const auto *CV = dyn_cast<ConstantInt>(V))
476 if (CV->getValue().ule(UINT64_MAX(18446744073709551615UL))) {
477 VR = CV->getZExtValue();
478 return true;
479 }
480 return false;
481 }
482};
483
484/// Match a specified integer value or vector of all elements of that
485// value.
486struct specific_intval {
487 uint64_t Val;
488
489 specific_intval(uint64_t V) : Val(V) {}
490
491 template <typename ITy> bool match(ITy *V) {
492 const auto *CI = dyn_cast<ConstantInt>(V);
493 if (!CI && V->getType()->isVectorTy())
494 if (const auto *C = dyn_cast<Constant>(V))
495 CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue());
496
497 return CI && CI->getValue() == Val;
498 }
499};
500
501/// Match a specific integer value or vector with all elements equal to
502/// the value.
503inline specific_intval m_SpecificInt(uint64_t V) { return specific_intval(V); }
504
505/// Match a ConstantInt and bind to its value. This does not match
506/// ConstantInts wider than 64-bits.
507inline bind_const_intval_ty m_ConstantInt(uint64_t &V) { return V; }
508
509//===----------------------------------------------------------------------===//
510// Matcher for any binary operator.
511//
512template <typename LHS_t, typename RHS_t, bool Commutable = false>
513struct AnyBinaryOp_match {
514 LHS_t L;
515 RHS_t R;
516
517 AnyBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
518
519 template <typename OpTy> bool match(OpTy *V) {
520 if (auto *I = dyn_cast<BinaryOperator>(V))
521 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
522 (Commutable && R.match(I->getOperand(0)) &&
523 L.match(I->getOperand(1)));
524 return false;
525 }
526};
527
528template <typename LHS, typename RHS>
529inline AnyBinaryOp_match<LHS, RHS> m_BinOp(const LHS &L, const RHS &R) {
530 return AnyBinaryOp_match<LHS, RHS>(L, R);
531}
532
533//===----------------------------------------------------------------------===//
534// Matchers for specific binary operators.
535//
536
537template <typename LHS_t, typename RHS_t, unsigned Opcode,
538 bool Commutable = false>
539struct BinaryOp_match {
540 LHS_t L;
541 RHS_t R;
542
543 BinaryOp_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
544
545 template <typename OpTy> bool match(OpTy *V) {
546 if (V->getValueID() == Value::InstructionVal + Opcode) {
547 auto *I = cast<BinaryOperator>(V);
548 return (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
549 (Commutable && R.match(I->getOperand(0)) &&
550 L.match(I->getOperand(1)));
551 }
552 if (auto *CE = dyn_cast<ConstantExpr>(V))
553 return CE->getOpcode() == Opcode &&
554 ((L.match(CE->getOperand(0)) && R.match(CE->getOperand(1))) ||
555 (Commutable && R.match(CE->getOperand(0)) &&
556 L.match(CE->getOperand(1))));
557 return false;
558 }
559};
560
561template <typename LHS, typename RHS>
562inline BinaryOp_match<LHS, RHS, Instruction::Add> m_Add(const LHS &L,
563 const RHS &R) {
564 return BinaryOp_match<LHS, RHS, Instruction::Add>(L, R);
565}
566
567template <typename LHS, typename RHS>
568inline BinaryOp_match<LHS, RHS, Instruction::FAdd> m_FAdd(const LHS &L,
569 const RHS &R) {
570 return BinaryOp_match<LHS, RHS, Instruction::FAdd>(L, R);
571}
572
573template <typename LHS, typename RHS>
574inline BinaryOp_match<LHS, RHS, Instruction::Sub> m_Sub(const LHS &L,
575 const RHS &R) {
576 return BinaryOp_match<LHS, RHS, Instruction::Sub>(L, R);
577}
578
579template <typename LHS, typename RHS>
580inline BinaryOp_match<LHS, RHS, Instruction::FSub> m_FSub(const LHS &L,
581 const RHS &R) {
582 return BinaryOp_match<LHS, RHS, Instruction::FSub>(L, R);
583}
584
585template <typename LHS, typename RHS>
586inline BinaryOp_match<LHS, RHS, Instruction::Mul> m_Mul(const LHS &L,
587 const RHS &R) {
588 return BinaryOp_match<LHS, RHS, Instruction::Mul>(L, R);
589}
590
591template <typename LHS, typename RHS>
592inline BinaryOp_match<LHS, RHS, Instruction::FMul> m_FMul(const LHS &L,
593 const RHS &R) {
594 return BinaryOp_match<LHS, RHS, Instruction::FMul>(L, R);
595}
596
597template <typename LHS, typename RHS>
598inline BinaryOp_match<LHS, RHS, Instruction::UDiv> m_UDiv(const LHS &L,
599 const RHS &R) {
600 return BinaryOp_match<LHS, RHS, Instruction::UDiv>(L, R);
601}
602
603template <typename LHS, typename RHS>
604inline BinaryOp_match<LHS, RHS, Instruction::SDiv> m_SDiv(const LHS &L,
605 const RHS &R) {
606 return BinaryOp_match<LHS, RHS, Instruction::SDiv>(L, R);
607}
608
609template <typename LHS, typename RHS>
610inline BinaryOp_match<LHS, RHS, Instruction::FDiv> m_FDiv(const LHS &L,
611 const RHS &R) {
612 return BinaryOp_match<LHS, RHS, Instruction::FDiv>(L, R);
613}
614
615template <typename LHS, typename RHS>
616inline BinaryOp_match<LHS, RHS, Instruction::URem> m_URem(const LHS &L,
617 const RHS &R) {
618 return BinaryOp_match<LHS, RHS, Instruction::URem>(L, R);
619}
620
621template <typename LHS, typename RHS>
622inline BinaryOp_match<LHS, RHS, Instruction::SRem> m_SRem(const LHS &L,
623 const RHS &R) {
624 return BinaryOp_match<LHS, RHS, Instruction::SRem>(L, R);
625}
626
627template <typename LHS, typename RHS>
628inline BinaryOp_match<LHS, RHS, Instruction::FRem> m_FRem(const LHS &L,
629 const RHS &R) {
630 return BinaryOp_match<LHS, RHS, Instruction::FRem>(L, R);
631}
632
633template <typename LHS, typename RHS>
634inline BinaryOp_match<LHS, RHS, Instruction::And> m_And(const LHS &L,
635 const RHS &R) {
636 return BinaryOp_match<LHS, RHS, Instruction::And>(L, R);
637}
638
639template <typename LHS, typename RHS>
640inline BinaryOp_match<LHS, RHS, Instruction::Or> m_Or(const LHS &L,
641 const RHS &R) {
642 return BinaryOp_match<LHS, RHS, Instruction::Or>(L, R);
643}
644
645template <typename LHS, typename RHS>
646inline BinaryOp_match<LHS, RHS, Instruction::Xor> m_Xor(const LHS &L,
647 const RHS &R) {
648 return BinaryOp_match<LHS, RHS, Instruction::Xor>(L, R);
649}
650
651template <typename LHS, typename RHS>
652inline BinaryOp_match<LHS, RHS, Instruction::Shl> m_Shl(const LHS &L,
653 const RHS &R) {
654 return BinaryOp_match<LHS, RHS, Instruction::Shl>(L, R);
655}
656
657template <typename LHS, typename RHS>
658inline BinaryOp_match<LHS, RHS, Instruction::LShr> m_LShr(const LHS &L,
659 const RHS &R) {
660 return BinaryOp_match<LHS, RHS, Instruction::LShr>(L, R);
661}
662
663template <typename LHS, typename RHS>
664inline BinaryOp_match<LHS, RHS, Instruction::AShr> m_AShr(const LHS &L,
665 const RHS &R) {
666 return BinaryOp_match<LHS, RHS, Instruction::AShr>(L, R);
667}
668
669template <typename LHS_t, typename RHS_t, unsigned Opcode,
670 unsigned WrapFlags = 0>
671struct OverflowingBinaryOp_match {
672 LHS_t L;
673 RHS_t R;
674
675 OverflowingBinaryOp_match(const LHS_t &LHS, const RHS_t &RHS)
676 : L(LHS), R(RHS) {}
677
678 template <typename OpTy> bool match(OpTy *V) {
679 if (auto *Op = dyn_cast<OverflowingBinaryOperator>(V)) {
680 if (Op->getOpcode() != Opcode)
681 return false;
682 if (WrapFlags & OverflowingBinaryOperator::NoUnsignedWrap &&
683 !Op->hasNoUnsignedWrap())
684 return false;
685 if (WrapFlags & OverflowingBinaryOperator::NoSignedWrap &&
686 !Op->hasNoSignedWrap())
687 return false;
688 return L.match(Op->getOperand(0)) && R.match(Op->getOperand(1));
689 }
690 return false;
691 }
692};
693
694template <typename LHS, typename RHS>
695inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
696 OverflowingBinaryOperator::NoSignedWrap>
697m_NSWAdd(const LHS &L, const RHS &R) {
698 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
699 OverflowingBinaryOperator::NoSignedWrap>(
700 L, R);
701}
702template <typename LHS, typename RHS>
703inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
704 OverflowingBinaryOperator::NoSignedWrap>
705m_NSWSub(const LHS &L, const RHS &R) {
706 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
707 OverflowingBinaryOperator::NoSignedWrap>(
708 L, R);
709}
710template <typename LHS, typename RHS>
711inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
712 OverflowingBinaryOperator::NoSignedWrap>
713m_NSWMul(const LHS &L, const RHS &R) {
714 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
715 OverflowingBinaryOperator::NoSignedWrap>(
716 L, R);
717}
718template <typename LHS, typename RHS>
719inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
720 OverflowingBinaryOperator::NoSignedWrap>
721m_NSWShl(const LHS &L, const RHS &R) {
722 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
723 OverflowingBinaryOperator::NoSignedWrap>(
724 L, R);
725}
726
727template <typename LHS, typename RHS>
728inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
729 OverflowingBinaryOperator::NoUnsignedWrap>
730m_NUWAdd(const LHS &L, const RHS &R) {
731 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Add,
732 OverflowingBinaryOperator::NoUnsignedWrap>(
733 L, R);
734}
735template <typename LHS, typename RHS>
736inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
737 OverflowingBinaryOperator::NoUnsignedWrap>
738m_NUWSub(const LHS &L, const RHS &R) {
739 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Sub,
740 OverflowingBinaryOperator::NoUnsignedWrap>(
741 L, R);
742}
743template <typename LHS, typename RHS>
744inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
745 OverflowingBinaryOperator::NoUnsignedWrap>
746m_NUWMul(const LHS &L, const RHS &R) {
747 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Mul,
748 OverflowingBinaryOperator::NoUnsignedWrap>(
749 L, R);
750}
751template <typename LHS, typename RHS>
752inline OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
753 OverflowingBinaryOperator::NoUnsignedWrap>
754m_NUWShl(const LHS &L, const RHS &R) {
755 return OverflowingBinaryOp_match<LHS, RHS, Instruction::Shl,
756 OverflowingBinaryOperator::NoUnsignedWrap>(
757 L, R);
758}
759
760//===----------------------------------------------------------------------===//
761// Class that matches a group of binary opcodes.
762//
763template <typename LHS_t, typename RHS_t, typename Predicate>
764struct BinOpPred_match : Predicate {
765 LHS_t L;
766 RHS_t R;
767
768 BinOpPred_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
769
770 template <typename OpTy> bool match(OpTy *V) {
771 if (auto *I = dyn_cast<Instruction>(V))
772 return this->isOpType(I->getOpcode()) && L.match(I->getOperand(0)) &&
773 R.match(I->getOperand(1));
774 if (auto *CE = dyn_cast<ConstantExpr>(V))
775 return this->isOpType(CE->getOpcode()) && L.match(CE->getOperand(0)) &&
776 R.match(CE->getOperand(1));
777 return false;
778 }
779};
780
781struct is_shift_op {
782 bool isOpType(unsigned Opcode) { return Instruction::isShift(Opcode); }
783};
784
785struct is_right_shift_op {
786 bool isOpType(unsigned Opcode) {
787 return Opcode == Instruction::LShr || Opcode == Instruction::AShr;
788 }
789};
790
791struct is_logical_shift_op {
792 bool isOpType(unsigned Opcode) {
793 return Opcode == Instruction::LShr || Opcode == Instruction::Shl;
794 }
795};
796
797struct is_bitwiselogic_op {
798 bool isOpType(unsigned Opcode) {
799 return Instruction::isBitwiseLogicOp(Opcode);
800 }
801};
802
803struct is_idiv_op {
804 bool isOpType(unsigned Opcode) {
805 return Opcode == Instruction::SDiv || Opcode == Instruction::UDiv;
806 }
807};
808
809/// Matches shift operations.
810template <typename LHS, typename RHS>
811inline BinOpPred_match<LHS, RHS, is_shift_op> m_Shift(const LHS &L,
812 const RHS &R) {
813 return BinOpPred_match<LHS, RHS, is_shift_op>(L, R);
814}
815
816/// Matches logical shift operations.
817template <typename LHS, typename RHS>
818inline BinOpPred_match<LHS, RHS, is_right_shift_op> m_Shr(const LHS &L,
819 const RHS &R) {
820 return BinOpPred_match<LHS, RHS, is_right_shift_op>(L, R);
821}
822
823/// Matches logical shift operations.
824template <typename LHS, typename RHS>
825inline BinOpPred_match<LHS, RHS, is_logical_shift_op>
826m_LogicalShift(const LHS &L, const RHS &R) {
827 return BinOpPred_match<LHS, RHS, is_logical_shift_op>(L, R);
828}
829
830/// Matches bitwise logic operations.
831template <typename LHS, typename RHS>
832inline BinOpPred_match<LHS, RHS, is_bitwiselogic_op>
833m_BitwiseLogic(const LHS &L, const RHS &R) {
834 return BinOpPred_match<LHS, RHS, is_bitwiselogic_op>(L, R);
835}
836
837/// Matches integer division operations.
838template <typename LHS, typename RHS>
839inline BinOpPred_match<LHS, RHS, is_idiv_op> m_IDiv(const LHS &L,
840 const RHS &R) {
841 return BinOpPred_match<LHS, RHS, is_idiv_op>(L, R);
842}
843
844//===----------------------------------------------------------------------===//
845// Class that matches exact binary ops.
846//
847template <typename SubPattern_t> struct Exact_match {
848 SubPattern_t SubPattern;
849
850 Exact_match(const SubPattern_t &SP) : SubPattern(SP) {}
851
852 template <typename OpTy> bool match(OpTy *V) {
853 if (auto *PEO = dyn_cast<PossiblyExactOperator>(V))
854 return PEO->isExact() && SubPattern.match(V);
855 return false;
856 }
857};
858
859template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
860 return SubPattern;
861}
862
863//===----------------------------------------------------------------------===//
864// Matchers for CmpInst classes
865//
866
867template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
868 bool Commutable = false>
869struct CmpClass_match {
870 PredicateTy &Predicate;
871 LHS_t L;
872 RHS_t R;
873
874 CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
875 : Predicate(Pred), L(LHS), R(RHS) {}
876
877 template <typename OpTy> bool match(OpTy *V) {
878 if (auto *I = dyn_cast<Class>(V))
17
Calling 'dyn_cast'
47
Returning from 'dyn_cast'
48
Taking false branch
879 if ((L.match(I->getOperand(0)) && R.match(I->getOperand(1))) ||
880 (Commutable && R.match(I->getOperand(0)) &&
881 L.match(I->getOperand(1)))) {
882 Predicate = I->getPredicate();
883 return true;
884 }
885 return false;
886 }
887};
888
889template <typename LHS, typename RHS>
890inline CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>
891m_Cmp(CmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
892 return CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>(Pred, L, R);
893}
894
895template <typename LHS, typename RHS>
896inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>
897m_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
898 return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(Pred, L, R);
12
Calling constructor for 'CmpClass_match'
13
Returning from constructor for 'CmpClass_match'
899}
900
901template <typename LHS, typename RHS>
902inline CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>
903m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
904 return CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>(Pred, L, R);
905}
906
907//===----------------------------------------------------------------------===//
908// Matchers for SelectInst classes
909//
910
911template <typename Cond_t, typename LHS_t, typename RHS_t>
912struct SelectClass_match {
913 Cond_t C;
914 LHS_t L;
915 RHS_t R;
916
917 SelectClass_match(const Cond_t &Cond, const LHS_t &LHS, const RHS_t &RHS)
918 : C(Cond), L(LHS), R(RHS) {}
919
920 template <typename OpTy> bool match(OpTy *V) {
921 if (auto *I = dyn_cast<SelectInst>(V))
922 return C.match(I->getOperand(0)) && L.match(I->getOperand(1)) &&
923 R.match(I->getOperand(2));
924 return false;
925 }
926};
927
928template <typename Cond, typename LHS, typename RHS>
929inline SelectClass_match<Cond, LHS, RHS> m_Select(const Cond &C, const LHS &L,
930 const RHS &R) {
931 return SelectClass_match<Cond, LHS, RHS>(C, L, R);
932}
933
934/// This matches a select of two constants, e.g.:
935/// m_SelectCst<-1, 0>(m_Value(V))
936template <int64_t L, int64_t R, typename Cond>
937inline SelectClass_match<Cond, constantint_match<L>, constantint_match<R>>
938m_SelectCst(const Cond &C) {
939 return m_Select(C, m_ConstantInt<L>(), m_ConstantInt<R>());
940}
941
942//===----------------------------------------------------------------------===//
943// Matchers for CastInst classes
944//
945
946template <typename Op_t, unsigned Opcode> struct CastClass_match {
947 Op_t Op;
948
949 CastClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
950
951 template <typename OpTy> bool match(OpTy *V) {
952 if (auto *O = dyn_cast<Operator>(V))
953 return O->getOpcode() == Opcode && Op.match(O->getOperand(0));
954 return false;
955 }
956};
957
958/// Matches BitCast.
959template <typename OpTy>
960inline CastClass_match<OpTy, Instruction::BitCast> m_BitCast(const OpTy &Op) {
961 return CastClass_match<OpTy, Instruction::BitCast>(Op);
962}
963
964/// Matches PtrToInt.
965template <typename OpTy>
966inline CastClass_match<OpTy, Instruction::PtrToInt> m_PtrToInt(const OpTy &Op) {
967 return CastClass_match<OpTy, Instruction::PtrToInt>(Op);
968}
969
970/// Matches Trunc.
971template <typename OpTy>
972inline CastClass_match<OpTy, Instruction::Trunc> m_Trunc(const OpTy &Op) {
973 return CastClass_match<OpTy, Instruction::Trunc>(Op);
974}
975
976/// Matches SExt.
977template <typename OpTy>
978inline CastClass_match<OpTy, Instruction::SExt> m_SExt(const OpTy &Op) {
979 return CastClass_match<OpTy, Instruction::SExt>(Op);
980}
981
982/// Matches ZExt.
983template <typename OpTy>
984inline CastClass_match<OpTy, Instruction::ZExt> m_ZExt(const OpTy &Op) {
985 return CastClass_match<OpTy, Instruction::ZExt>(Op);
986}
987
988template <typename OpTy>
989inline match_combine_or<CastClass_match<OpTy, Instruction::ZExt>,
990 CastClass_match<OpTy, Instruction::SExt>>
991m_ZExtOrSExt(const OpTy &Op) {
992 return m_CombineOr(m_ZExt(Op), m_SExt(Op));
993}
994
995/// Matches UIToFP.
996template <typename OpTy>
997inline CastClass_match<OpTy, Instruction::UIToFP> m_UIToFP(const OpTy &Op) {
998 return CastClass_match<OpTy, Instruction::UIToFP>(Op);
999}
1000
1001/// Matches SIToFP.
1002template <typename OpTy>
1003inline CastClass_match<OpTy, Instruction::SIToFP> m_SIToFP(const OpTy &Op) {
1004 return CastClass_match<OpTy, Instruction::SIToFP>(Op);
1005}
1006
1007/// Matches FPTrunc
1008template <typename OpTy>
1009inline CastClass_match<OpTy, Instruction::FPTrunc> m_FPTrunc(const OpTy &Op) {
1010 return CastClass_match<OpTy, Instruction::FPTrunc>(Op);
1011}
1012
1013/// Matches FPExt
1014template <typename OpTy>
1015inline CastClass_match<OpTy, Instruction::FPExt> m_FPExt(const OpTy &Op) {
1016 return CastClass_match<OpTy, Instruction::FPExt>(Op);
1017}
1018
1019//===----------------------------------------------------------------------===//
1020// Matcher for LoadInst classes
1021//
1022
1023template <typename Op_t> struct LoadClass_match {
1024 Op_t Op;
1025
1026 LoadClass_match(const Op_t &OpMatch) : Op(OpMatch) {}
1027
1028 template <typename OpTy> bool match(OpTy *V) {
1029 if (auto *LI = dyn_cast<LoadInst>(V))
1030 return Op.match(LI->getPointerOperand());
1031 return false;
1032 }
1033};
1034
1035/// Matches LoadInst.
1036template <typename OpTy> inline LoadClass_match<OpTy> m_Load(const OpTy &Op) {
1037 return LoadClass_match<OpTy>(Op);
1038}
1039//===----------------------------------------------------------------------===//
1040// Matchers for unary operators
1041//
1042
1043template <typename LHS_t> struct not_match {
1044 LHS_t L;
1045
1046 not_match(const LHS_t &LHS) : L(LHS) {}
1047
1048 template <typename OpTy> bool match(OpTy *V) {
1049 if (auto *O = dyn_cast<Operator>(V))
1050 if (O->getOpcode() == Instruction::Xor) {
1051 if (isAllOnes(O->getOperand(1)))
1052 return L.match(O->getOperand(0));
1053 if (isAllOnes(O->getOperand(0)))
1054 return L.match(O->getOperand(1));
1055 }
1056 return false;
1057 }
1058
1059private:
1060 bool isAllOnes(Value *V) {
1061 return isa<Constant>(V) && cast<Constant>(V)->isAllOnesValue();
1062 }
1063};
1064
1065template <typename LHS> inline not_match<LHS> m_Not(const LHS &L) { return L; }
1066
1067template <typename LHS_t> struct neg_match {
1068 LHS_t L;
1069
1070 neg_match(const LHS_t &LHS) : L(LHS) {}
1071
1072 template <typename OpTy> bool match(OpTy *V) {
1073 if (auto *O = dyn_cast<Operator>(V))
1074 if (O->getOpcode() == Instruction::Sub)
1075 return matchIfNeg(O->getOperand(0), O->getOperand(1));
1076 return false;
1077 }
1078
1079private:
1080 bool matchIfNeg(Value *LHS, Value *RHS) {
1081 return ((isa<ConstantInt>(LHS) && cast<ConstantInt>(LHS)->isZero()) ||
1082 isa<ConstantAggregateZero>(LHS)) &&
1083 L.match(RHS);
1084 }
1085};
1086
1087/// Match an integer negate.
1088template <typename LHS> inline neg_match<LHS> m_Neg(const LHS &L) { return L; }
1089
1090template <typename LHS_t> struct fneg_match {
1091 LHS_t L;
1092
1093 fneg_match(const LHS_t &LHS) : L(LHS) {}
1094
1095 template <typename OpTy> bool match(OpTy *V) {
1096 if (auto *O = dyn_cast<Operator>(V))
1097 if (O->getOpcode() == Instruction::FSub)
1098 return matchIfFNeg(O->getOperand(0), O->getOperand(1));
1099 return false;
1100 }
1101
1102private:
1103 bool matchIfFNeg(Value *LHS, Value *RHS) {
1104 if (const auto *C = dyn_cast<Constant>(LHS))
1105 return C->isNegativeZeroValue() && L.match(RHS);
1106 return false;
1107 }
1108};
1109
1110/// Match a floating point negate.
1111template <typename LHS> inline fneg_match<LHS> m_FNeg(const LHS &L) {
1112 return L;
1113}
1114
1115//===----------------------------------------------------------------------===//
1116// Matchers for control flow.
1117//
1118
1119struct br_match {
1120 BasicBlock *&Succ;
1121
1122 br_match(BasicBlock *&Succ) : Succ(Succ) {}
1123
1124 template <typename OpTy> bool match(OpTy *V) {
1125 if (auto *BI = dyn_cast<BranchInst>(V))
1126 if (BI->isUnconditional()) {
1127 Succ = BI->getSuccessor(0);
1128 return true;
1129 }
1130 return false;
1131 }
1132};
1133
1134inline br_match m_UnconditionalBr(BasicBlock *&Succ) { return br_match(Succ); }
1135
1136template <typename Cond_t> struct brc_match {
1137 Cond_t Cond;
1138 BasicBlock *&T, *&F;
1139
1140 brc_match(const Cond_t &C, BasicBlock *&t, BasicBlock *&f)
1141 : Cond(C), T(t), F(f) {}
1142
1143 template <typename OpTy> bool match(OpTy *V) {
1144 if (auto *BI = dyn_cast<BranchInst>(V))
1145 if (BI->isConditional() && Cond.match(BI->getCondition())) {
1146 T = BI->getSuccessor(0);
1147 F = BI->getSuccessor(1);
1148 return true;
1149 }
1150 return false;
1151 }
1152};
1153
1154template <typename Cond_t>
1155inline brc_match<Cond_t> m_Br(const Cond_t &C, BasicBlock *&T, BasicBlock *&F) {
1156 return brc_match<Cond_t>(C, T, F);
1157}
1158
1159//===----------------------------------------------------------------------===//
1160// Matchers for max/min idioms, eg: "select (sgt x, y), x, y" -> smax(x,y).
1161//
1162
1163template <typename CmpInst_t, typename LHS_t, typename RHS_t, typename Pred_t,
1164 bool Commutable = false>
1165struct MaxMin_match {
1166 LHS_t L;
1167 RHS_t R;
1168
1169 MaxMin_match(const LHS_t &LHS, const RHS_t &RHS) : L(LHS), R(RHS) {}
1170
1171 template <typename OpTy> bool match(OpTy *V) {
1172 // Look for "(x pred y) ? x : y" or "(x pred y) ? y : x".
1173 auto *SI = dyn_cast<SelectInst>(V);
1174 if (!SI)
1175 return false;
1176 auto *Cmp = dyn_cast<CmpInst_t>(SI->getCondition());
1177 if (!Cmp)
1178 return false;
1179 // At this point we have a select conditioned on a comparison. Check that
1180 // it is the values returned by the select that are being compared.
1181 Value *TrueVal = SI->getTrueValue();
1182 Value *FalseVal = SI->getFalseValue();
1183 Value *LHS = Cmp->getOperand(0);
1184 Value *RHS = Cmp->getOperand(1);
1185 if ((TrueVal != LHS || FalseVal != RHS) &&
1186 (TrueVal != RHS || FalseVal != LHS))
1187 return false;
1188 typename CmpInst_t::Predicate Pred =
1189 LHS == TrueVal ? Cmp->getPredicate() : Cmp->getInversePredicate();
1190 // Does "(x pred y) ? x : y" represent the desired max/min operation?
1191 if (!Pred_t::match(Pred))
1192 return false;
1193 // It does! Bind the operands.
1194 return (L.match(LHS) && R.match(RHS)) ||
1195 (Commutable && R.match(LHS) && L.match(RHS));
1196 }
1197};
1198
1199/// Helper class for identifying signed max predicates.
1200struct smax_pred_ty {
1201 static bool match(ICmpInst::Predicate Pred) {
1202 return Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_SGE;
1203 }
1204};
1205
1206/// Helper class for identifying signed min predicates.
1207struct smin_pred_ty {
1208 static bool match(ICmpInst::Predicate Pred) {
1209 return Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_SLE;
1210 }
1211};
1212
1213/// Helper class for identifying unsigned max predicates.
1214struct umax_pred_ty {
1215 static bool match(ICmpInst::Predicate Pred) {
1216 return Pred == CmpInst::ICMP_UGT || Pred == CmpInst::ICMP_UGE;
1217 }
1218};
1219
1220/// Helper class for identifying unsigned min predicates.
1221struct umin_pred_ty {
1222 static bool match(ICmpInst::Predicate Pred) {
1223 return Pred == CmpInst::ICMP_ULT || Pred == CmpInst::ICMP_ULE;
1224 }
1225};
1226
1227/// Helper class for identifying ordered max predicates.
1228struct ofmax_pred_ty {
1229 static bool match(FCmpInst::Predicate Pred) {
1230 return Pred == CmpInst::FCMP_OGT || Pred == CmpInst::FCMP_OGE;
1231 }
1232};
1233
1234/// Helper class for identifying ordered min predicates.
1235struct ofmin_pred_ty {
1236 static bool match(FCmpInst::Predicate Pred) {
1237 return Pred == CmpInst::FCMP_OLT || Pred == CmpInst::FCMP_OLE;
1238 }
1239};
1240
1241/// Helper class for identifying unordered max predicates.
1242struct ufmax_pred_ty {
1243 static bool match(FCmpInst::Predicate Pred) {
1244 return Pred == CmpInst::FCMP_UGT || Pred == CmpInst::FCMP_UGE;
1245 }
1246};
1247
1248/// Helper class for identifying unordered min predicates.
1249struct ufmin_pred_ty {
1250 static bool match(FCmpInst::Predicate Pred) {
1251 return Pred == CmpInst::FCMP_ULT || Pred == CmpInst::FCMP_ULE;
1252 }
1253};
1254
1255template <typename LHS, typename RHS>
1256inline MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty> m_SMax(const LHS &L,
1257 const RHS &R) {
1258 return MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty>(L, R);
1259}
1260
1261template <typename LHS, typename RHS>
1262inline MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty> m_SMin(const LHS &L,
1263 const RHS &R) {
1264 return MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty>(L, R);
1265}
1266
1267template <typename LHS, typename RHS>
1268inline MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty> m_UMax(const LHS &L,
1269 const RHS &R) {
1270 return MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty>(L, R);
1271}
1272
1273template <typename LHS, typename RHS>
1274inline MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty> m_UMin(const LHS &L,
1275 const RHS &R) {
1276 return MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty>(L, R);
1277}
1278
1279/// Match an 'ordered' floating point maximum function.
1280/// Floating point has one special value 'NaN'. Therefore, there is no total
1281/// order. However, if we can ignore the 'NaN' value (for example, because of a
1282/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
1283/// semantics. In the presence of 'NaN' we have to preserve the original
1284/// select(fcmp(ogt/ge, L, R), L, R) semantics matched by this predicate.
1285///
1286/// max(L, R) iff L and R are not NaN
1287/// m_OrdFMax(L, R) = R iff L or R are NaN
1288template <typename LHS, typename RHS>
1289inline MaxMin_match<FCmpInst, LHS, RHS, ofmax_pred_ty> m_OrdFMax(const LHS &L,
1290 const RHS &R) {
1291 return MaxMin_match<FCmpInst, LHS, RHS, ofmax_pred_ty>(L, R);
1292}
1293
1294/// Match an 'ordered' floating point minimum function.
1295/// Floating point has one special value 'NaN'. Therefore, there is no total
1296/// order. However, if we can ignore the 'NaN' value (for example, because of a
1297/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
1298/// semantics. In the presence of 'NaN' we have to preserve the original
1299/// select(fcmp(olt/le, L, R), L, R) semantics matched by this predicate.
1300///
1301/// min(L, R) iff L and R are not NaN
1302/// m_OrdFMin(L, R) = R iff L or R are NaN
1303template <typename LHS, typename RHS>
1304inline MaxMin_match<FCmpInst, LHS, RHS, ofmin_pred_ty> m_OrdFMin(const LHS &L,
1305 const RHS &R) {
1306 return MaxMin_match<FCmpInst, LHS, RHS, ofmin_pred_ty>(L, R);
1307}
1308
1309/// Match an 'unordered' floating point maximum function.
1310/// Floating point has one special value 'NaN'. Therefore, there is no total
1311/// order. However, if we can ignore the 'NaN' value (for example, because of a
1312/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'maximum'
1313/// semantics. In the presence of 'NaN' we have to preserve the original
1314/// select(fcmp(ugt/ge, L, R), L, R) semantics matched by this predicate.
1315///
1316/// max(L, R) iff L and R are not NaN
1317/// m_UnordFMax(L, R) = L iff L or R are NaN
1318template <typename LHS, typename RHS>
1319inline MaxMin_match<FCmpInst, LHS, RHS, ufmax_pred_ty>
1320m_UnordFMax(const LHS &L, const RHS &R) {
1321 return MaxMin_match<FCmpInst, LHS, RHS, ufmax_pred_ty>(L, R);
1322}
1323
1324/// Match an 'unordered' floating point minimum function.
1325/// Floating point has one special value 'NaN'. Therefore, there is no total
1326/// order. However, if we can ignore the 'NaN' value (for example, because of a
1327/// 'no-nans-float-math' flag) a combination of a fcmp and select has 'minimum'
1328/// semantics. In the presence of 'NaN' we have to preserve the original
1329/// select(fcmp(ult/le, L, R), L, R) semantics matched by this predicate.
1330///
1331/// min(L, R) iff L and R are not NaN
1332/// m_UnordFMin(L, R) = L iff L or R are NaN
1333template <typename LHS, typename RHS>
1334inline MaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>
1335m_UnordFMin(const LHS &L, const RHS &R) {
1336 return MaxMin_match<FCmpInst, LHS, RHS, ufmin_pred_ty>(L, R);
1337}
1338
1339//===----------------------------------------------------------------------===//
1340// Matchers for overflow check patterns: e.g. (a + b) u< a
1341//
1342
1343template <typename LHS_t, typename RHS_t, typename Sum_t>
1344struct UAddWithOverflow_match {
1345 LHS_t L;
1346 RHS_t R;
1347 Sum_t S;
1348
1349 UAddWithOverflow_match(const LHS_t &L, const RHS_t &R, const Sum_t &S)
1350 : L(L), R(R), S(S) {}
1351
1352 template <typename OpTy> bool match(OpTy *V) {
1353 Value *ICmpLHS, *ICmpRHS;
1354 ICmpInst::Predicate Pred;
1355 if (!m_ICmp(Pred, m_Value(ICmpLHS), m_Value(ICmpRHS)).match(V))
1356 return false;
1357
1358 Value *AddLHS, *AddRHS;
1359 auto AddExpr = m_Add(m_Value(AddLHS), m_Value(AddRHS));
1360
1361 // (a + b) u< a, (a + b) u< b
1362 if (Pred == ICmpInst::ICMP_ULT)
1363 if (AddExpr.match(ICmpLHS) && (ICmpRHS == AddLHS || ICmpRHS == AddRHS))
1364 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpLHS);
1365
1366 // a >u (a + b), b >u (a + b)
1367 if (Pred == ICmpInst::ICMP_UGT)
1368 if (AddExpr.match(ICmpRHS) && (ICmpLHS == AddLHS || ICmpLHS == AddRHS))
1369 return L.match(AddLHS) && R.match(AddRHS) && S.match(ICmpRHS);
1370
1371 return false;
1372 }
1373};
1374
1375/// Match an icmp instruction checking for unsigned overflow on addition.
1376///
1377/// S is matched to the addition whose result is being checked for overflow, and
1378/// L and R are matched to the LHS and RHS of S.
1379template <typename LHS_t, typename RHS_t, typename Sum_t>
1380UAddWithOverflow_match<LHS_t, RHS_t, Sum_t>
1381m_UAddWithOverflow(const LHS_t &L, const RHS_t &R, const Sum_t &S) {
1382 return UAddWithOverflow_match<LHS_t, RHS_t, Sum_t>(L, R, S);
1383}
1384
1385template <typename Opnd_t> struct Argument_match {
1386 unsigned OpI;
1387 Opnd_t Val;
1388
1389 Argument_match(unsigned OpIdx, const Opnd_t &V) : OpI(OpIdx), Val(V) {}
1390
1391 template <typename OpTy> bool match(OpTy *V) {
1392 CallSite CS(V);
1393 return CS.isCall() && Val.match(CS.getArgument(OpI));
1394 }
1395};
1396
1397/// Match an argument.
1398template <unsigned OpI, typename Opnd_t>
1399inline Argument_match<Opnd_t> m_Argument(const Opnd_t &Op) {
1400 return Argument_match<Opnd_t>(OpI, Op);
1401}
1402
1403/// Intrinsic matchers.
1404struct IntrinsicID_match {
1405 unsigned ID;
1406
1407 IntrinsicID_match(Intrinsic::ID IntrID) : ID(IntrID) {}
1408
1409 template <typename OpTy> bool match(OpTy *V) {
1410 if (const auto *CI = dyn_cast<CallInst>(V))
1411 if (const auto *F = CI->getCalledFunction())
1412 return F->getIntrinsicID() == ID;
1413 return false;
1414 }
1415};
1416
1417/// Intrinsic matches are combinations of ID matchers, and argument
1418/// matchers. Higher arity matcher are defined recursively in terms of and-ing
1419/// them with lower arity matchers. Here's some convenient typedefs for up to
1420/// several arguments, and more can be added as needed
1421template <typename T0 = void, typename T1 = void, typename T2 = void,
1422 typename T3 = void, typename T4 = void, typename T5 = void,
1423 typename T6 = void, typename T7 = void, typename T8 = void,
1424 typename T9 = void, typename T10 = void>
1425struct m_Intrinsic_Ty;
1426template <typename T0> struct m_Intrinsic_Ty<T0> {
1427 using Ty = match_combine_and<IntrinsicID_match, Argument_match<T0>>;
1428};
1429template <typename T0, typename T1> struct m_Intrinsic_Ty<T0, T1> {
1430 using Ty =
1431 match_combine_and<typename m_Intrinsic_Ty<T0>::Ty, Argument_match<T1>>;
1432};
1433template <typename T0, typename T1, typename T2>
1434struct m_Intrinsic_Ty<T0, T1, T2> {
1435 using Ty =
1436 match_combine_and<typename m_Intrinsic_Ty<T0, T1>::Ty,
1437 Argument_match<T2>>;
1438};
1439template <typename T0, typename T1, typename T2, typename T3>
1440struct m_Intrinsic_Ty<T0, T1, T2, T3> {
1441 using Ty =
1442 match_combine_and<typename m_Intrinsic_Ty<T0, T1, T2>::Ty,
1443 Argument_match<T3>>;
1444};
1445
1446/// Match intrinsic calls like this:
1447/// m_Intrinsic<Intrinsic::fabs>(m_Value(X))
1448template <Intrinsic::ID IntrID> inline IntrinsicID_match m_Intrinsic() {
1449 return IntrinsicID_match(IntrID);
1450}
1451
1452template <Intrinsic::ID IntrID, typename T0>
1453inline typename m_Intrinsic_Ty<T0>::Ty m_Intrinsic(const T0 &Op0) {
1454 return m_CombineAnd(m_Intrinsic<IntrID>(), m_Argument<0>(Op0));
1455}
1456
1457template <Intrinsic::ID IntrID, typename T0, typename T1>
1458inline typename m_Intrinsic_Ty<T0, T1>::Ty m_Intrinsic(const T0 &Op0,
1459 const T1 &Op1) {
1460 return m_CombineAnd(m_Intrinsic<IntrID>(Op0), m_Argument<1>(Op1));
1461}
1462
1463template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2>
1464inline typename m_Intrinsic_Ty<T0, T1, T2>::Ty
1465m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2) {
1466 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1), m_Argument<2>(Op2));
1467}
1468
1469template <Intrinsic::ID IntrID, typename T0, typename T1, typename T2,
1470 typename T3>
1471inline typename m_Intrinsic_Ty<T0, T1, T2, T3>::Ty
1472m_Intrinsic(const T0 &Op0, const T1 &Op1, const T2 &Op2, const T3 &Op3) {
1473 return m_CombineAnd(m_Intrinsic<IntrID>(Op0, Op1, Op2), m_Argument<3>(Op3));
1474}
1475
1476// Helper intrinsic matching specializations.
1477template <typename Opnd0>
1478inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BitReverse(const Opnd0 &Op0) {
1479 return m_Intrinsic<Intrinsic::bitreverse>(Op0);
1480}
1481
1482template <typename Opnd0>
1483inline typename m_Intrinsic_Ty<Opnd0>::Ty m_BSwap(const Opnd0 &Op0) {
1484 return m_Intrinsic<Intrinsic::bswap>(Op0);
1485}
1486
1487template <typename Opnd0, typename Opnd1>
1488inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMin(const Opnd0 &Op0,
1489 const Opnd1 &Op1) {
1490 return m_Intrinsic<Intrinsic::minnum>(Op0, Op1);
1491}
1492
1493template <typename Opnd0, typename Opnd1>
1494inline typename m_Intrinsic_Ty<Opnd0, Opnd1>::Ty m_FMax(const Opnd0 &Op0,
1495 const Opnd1 &Op1) {
1496 return m_Intrinsic<Intrinsic::maxnum>(Op0, Op1);
1497}
1498
1499template <typename Opnd_t> struct Signum_match {
1500 Opnd_t Val;
1501 Signum_match(const Opnd_t &V) : Val(V) {}
1502
1503 template <typename OpTy> bool match(OpTy *V) {
1504 unsigned TypeSize = V->getType()->getScalarSizeInBits();
1505 if (TypeSize == 0)
1506 return false;
1507
1508 unsigned ShiftWidth = TypeSize - 1;
1509 Value *OpL = nullptr, *OpR = nullptr;
1510
1511 // This is the representation of signum we match:
1512 //
1513 // signum(x) == (x >> 63) | (-x >>u 63)
1514 //
1515 // An i1 value is its own signum, so it's correct to match
1516 //
1517 // signum(x) == (x >> 0) | (-x >>u 0)
1518 //
1519 // for i1 values.
1520
1521 auto LHS = m_AShr(m_Value(OpL), m_SpecificInt(ShiftWidth));
1522 auto RHS = m_LShr(m_Neg(m_Value(OpR)), m_SpecificInt(ShiftWidth));
1523 auto Signum = m_Or(LHS, RHS);
1524
1525 return Signum.match(V) && OpL == OpR && Val.match(OpL);
1526 }
1527};
1528
1529/// Matches a signum pattern.
1530///
1531/// signum(x) =
1532/// x > 0 -> 1
1533/// x == 0 -> 0
1534/// x < 0 -> -1
1535template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
1536 return Signum_match<Val_t>(V);
1537}
1538
1539//===----------------------------------------------------------------------===//
1540// Matchers for two-operands operators with the operators in either order
1541//
1542
1543/// Matches a BinaryOperator with LHS and RHS in either order.
1544template <typename LHS, typename RHS>
1545inline AnyBinaryOp_match<LHS, RHS, true> m_c_BinOp(const LHS &L, const RHS &R) {
1546 return AnyBinaryOp_match<LHS, RHS, true>(L, R);
1547}
1548
1549/// Matches an ICmp with a predicate over LHS and RHS in either order.
1550/// Does not swap the predicate.
1551template <typename LHS, typename RHS>
1552inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>
1553m_c_ICmp(ICmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
1554 return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate, true>(Pred, L,
1555 R);
1556}
1557
1558/// Matches a Add with LHS and RHS in either order.
1559template <typename LHS, typename RHS>
1560inline BinaryOp_match<LHS, RHS, Instruction::Add, true> m_c_Add(const LHS &L,
1561 const RHS &R) {
1562 return BinaryOp_match<LHS, RHS, Instruction::Add, true>(L, R);
1563}
1564
1565/// Matches a Mul with LHS and RHS in either order.
1566template <typename LHS, typename RHS>
1567inline BinaryOp_match<LHS, RHS, Instruction::Mul, true> m_c_Mul(const LHS &L,
1568 const RHS &R) {
1569 return BinaryOp_match<LHS, RHS, Instruction::Mul, true>(L, R);
1570}
1571
1572/// Matches an And with LHS and RHS in either order.
1573template <typename LHS, typename RHS>
1574inline BinaryOp_match<LHS, RHS, Instruction::And, true> m_c_And(const LHS &L,
1575 const RHS &R) {
1576 return BinaryOp_match<LHS, RHS, Instruction::And, true>(L, R);
1577}
1578
1579/// Matches an Or with LHS and RHS in either order.
1580template <typename LHS, typename RHS>
1581inline BinaryOp_match<LHS, RHS, Instruction::Or, true> m_c_Or(const LHS &L,
1582 const RHS &R) {
1583 return BinaryOp_match<LHS, RHS, Instruction::Or, true>(L, R);
1584}
1585
1586/// Matches an Xor with LHS and RHS in either order.
1587template <typename LHS, typename RHS>
1588inline BinaryOp_match<LHS, RHS, Instruction::Xor, true> m_c_Xor(const LHS &L,
1589 const RHS &R) {
1590 return BinaryOp_match<LHS, RHS, Instruction::Xor, true>(L, R);
1591}
1592
1593/// Matches an SMin with LHS and RHS in either order.
1594template <typename LHS, typename RHS>
1595inline MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>
1596m_c_SMin(const LHS &L, const RHS &R) {
1597 return MaxMin_match<ICmpInst, LHS, RHS, smin_pred_ty, true>(L, R);
1598}
1599/// Matches an SMax with LHS and RHS in either order.
1600template <typename LHS, typename RHS>
1601inline MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true>
1602m_c_SMax(const LHS &L, const RHS &R) {
1603 return MaxMin_match<ICmpInst, LHS, RHS, smax_pred_ty, true>(L, R);
1604}
1605/// Matches a UMin with LHS and RHS in either order.
1606template <typename LHS, typename RHS>
1607inline MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true>
1608m_c_UMin(const LHS &L, const RHS &R) {
1609 return MaxMin_match<ICmpInst, LHS, RHS, umin_pred_ty, true>(L, R);
1610}
1611/// Matches a UMax with LHS and RHS in either order.
1612template <typename LHS, typename RHS>
1613inline MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true>
1614m_c_UMax(const LHS &L, const RHS &R) {
1615 return MaxMin_match<ICmpInst, LHS, RHS, umax_pred_ty, true>(L, R);
1616}
1617
1618/// Matches FAdd with LHS and RHS in either order.
1619template <typename LHS, typename RHS>
1620inline BinaryOp_match<LHS, RHS, Instruction::FAdd, true>
1621m_c_FAdd(const LHS &L, const RHS &R) {
1622 return BinaryOp_match<LHS, RHS, Instruction::FAdd, true>(L, R);
1623}
1624
1625/// Matches FMul with LHS and RHS in either order.
1626template <typename LHS, typename RHS>
1627inline BinaryOp_match<LHS, RHS, Instruction::FMul, true>
1628m_c_FMul(const LHS &L, const RHS &R) {
1629 return BinaryOp_match<LHS, RHS, Instruction::FMul, true>(L, R);
1630}
1631
1632} // end namespace PatternMatch
1633} // end namespace llvm
1634
1635#endif // LLVM_IR_PATTERNMATCH_H

/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h

1//===- llvm/Support/Casting.h - Allow flexible, checked, casts --*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the isa<X>(), cast<X>(), dyn_cast<X>(), cast_or_null<X>(),
11// and dyn_cast_or_null<X>() templates.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_SUPPORT_CASTING_H
16#define LLVM_SUPPORT_CASTING_H
17
18#include "llvm/Support/Compiler.h"
19#include "llvm/Support/type_traits.h"
20#include <cassert>
21#include <memory>
22#include <type_traits>
23
24namespace llvm {
25
26//===----------------------------------------------------------------------===//
27// isa<x> Support Templates
28//===----------------------------------------------------------------------===//
29
30// Define a template that can be specialized by smart pointers to reflect the
31// fact that they are automatically dereferenced, and are not involved with the
32// template selection process... the default implementation is a noop.
33//
34template<typename From> struct simplify_type {
35 using SimpleType = From; // The real type this represents...
36
37 // An accessor to get the real value...
38 static SimpleType &getSimplifiedValue(From &Val) { return Val; }
39};
40
41template<typename From> struct simplify_type<const From> {
42 using NonConstSimpleType = typename simplify_type<From>::SimpleType;
43 using SimpleType =
44 typename add_const_past_pointer<NonConstSimpleType>::type;
45 using RetType =
46 typename add_lvalue_reference_if_not_pointer<SimpleType>::type;
47
48 static RetType getSimplifiedValue(const From& Val) {
49 return simplify_type<From>::getSimplifiedValue(const_cast<From&>(Val));
21
Calling 'simplify_type::getSimplifiedValue'
22
Returning from 'simplify_type::getSimplifiedValue'
32
Calling 'simplify_type::getSimplifiedValue'
33
Returning from 'simplify_type::getSimplifiedValue'
50 }
51};
52
53// The core of the implementation of isa<X> is here; To and From should be
54// the names of classes. This template can be specialized to customize the
55// implementation of isa<> without rewriting it from scratch.
56template <typename To, typename From, typename Enabler = void>
57struct isa_impl {
58 static inline bool doit(const From &Val) {
59 return To::classof(&Val);
28
Calling 'ICmpInst::classof'
40
Returning from 'ICmpInst::classof'
60 }
61};
62
63/// \brief Always allow upcasts, and perform no dynamic check for them.
64template <typename To, typename From>
65struct isa_impl<
66 To, From, typename std::enable_if<std::is_base_of<To, From>::value>::type> {
67 static inline bool doit(const From &) { return true; }
68};
69
70template <typename To, typename From> struct isa_impl_cl {
71 static inline bool doit(const From &Val) {
72 return isa_impl<To, From>::doit(Val);
73 }
74};
75
76template <typename To, typename From> struct isa_impl_cl<To, const From> {
77 static inline bool doit(const From &Val) {
78 return isa_impl<To, From>::doit(Val);
79 }
80};
81
82template <typename To, typename From>
83struct isa_impl_cl<To, const std::unique_ptr<From>> {
84 static inline bool doit(const std::unique_ptr<From> &Val) {
85 assert(Val && "isa<> used on a null pointer")(static_cast <bool> (Val && "isa<> used on a null pointer"
) ? void (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 85, __extension__ __PRETTY_FUNCTION__))
;
86 return isa_impl_cl<To, From>::doit(*Val);
87 }
88};
89
90template <typename To, typename From> struct isa_impl_cl<To, From*> {
91 static inline bool doit(const From *Val) {
92 assert(Val && "isa<> used on a null pointer")(static_cast <bool> (Val && "isa<> used on a null pointer"
) ? void (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 92, __extension__ __PRETTY_FUNCTION__))
;
93 return isa_impl<To, From>::doit(*Val);
94 }
95};
96
97template <typename To, typename From> struct isa_impl_cl<To, From*const> {
98 static inline bool doit(const From *Val) {
99 assert(Val && "isa<> used on a null pointer")(static_cast <bool> (Val && "isa<> used on a null pointer"
) ? void (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 99, __extension__ __PRETTY_FUNCTION__))
;
100 return isa_impl<To, From>::doit(*Val);
101 }
102};
103
104template <typename To, typename From> struct isa_impl_cl<To, const From*> {
105 static inline bool doit(const From *Val) {
106 assert(Val && "isa<> used on a null pointer")(static_cast <bool> (Val && "isa<> used on a null pointer"
) ? void (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 106, __extension__ __PRETTY_FUNCTION__))
;
26
Within the expansion of the macro 'assert':
107 return isa_impl<To, From>::doit(*Val);
27
Calling 'isa_impl::doit'
41
Returning from 'isa_impl::doit'
108 }
109};
110
111template <typename To, typename From> struct isa_impl_cl<To, const From*const> {
112 static inline bool doit(const From *Val) {
113 assert(Val && "isa<> used on a null pointer")(static_cast <bool> (Val && "isa<> used on a null pointer"
) ? void (0) : __assert_fail ("Val && \"isa<> used on a null pointer\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 113, __extension__ __PRETTY_FUNCTION__))
;
114 return isa_impl<To, From>::doit(*Val);
115 }
116};
117
118template<typename To, typename From, typename SimpleFrom>
119struct isa_impl_wrap {
120 // When From != SimplifiedType, we can simplify the type some more by using
121 // the simplify_type template.
122 static bool doit(const From &Val) {
123 return isa_impl_wrap<To, SimpleFrom,
24
Calling 'isa_impl_wrap::doit'
35
Calling 'isa_impl_wrap::doit'
36
Returning from 'isa_impl_wrap::doit'
43
Returning from 'isa_impl_wrap::doit'
124 typename simplify_type<SimpleFrom>::SimpleType>::doit(
125 simplify_type<const From>::getSimplifiedValue(Val));
20
Calling 'simplify_type::getSimplifiedValue'
23
Returning from 'simplify_type::getSimplifiedValue'
31
Calling 'simplify_type::getSimplifiedValue'
34
Returning from 'simplify_type::getSimplifiedValue'
126 }
127};
128
129template<typename To, typename FromTy>
130struct isa_impl_wrap<To, FromTy, FromTy> {
131 // When From == SimpleType, we are as simple as we are going to get.
132 static bool doit(const FromTy &Val) {
133 return isa_impl_cl<To,FromTy>::doit(Val);
25
Calling 'isa_impl_cl::doit'
42
Returning from 'isa_impl_cl::doit'
134 }
135};
136
137// isa<X> - Return true if the parameter to the template is an instance of the
138// template type argument. Used like this:
139//
140// if (isa<Type>(myVal)) { ... }
141//
142template <class X, class Y> LLVM_NODISCARD[[clang::warn_unused_result]] inline bool isa(const Y &Val) {
143 return isa_impl_wrap<X, const Y,
19
Calling 'isa_impl_wrap::doit'
30
Calling 'isa_impl_wrap::doit'
37
Returning from 'isa_impl_wrap::doit'
44
Returning from 'isa_impl_wrap::doit'
144 typename simplify_type<const Y>::SimpleType>::doit(Val);
145}
146
147//===----------------------------------------------------------------------===//
148// cast<x> Support Templates
149//===----------------------------------------------------------------------===//
150
151template<class To, class From> struct cast_retty;
152
153// Calculate what type the 'cast' function should return, based on a requested
154// type of To and a source type of From.
155template<class To, class From> struct cast_retty_impl {
156 using ret_type = To &; // Normal case, return Ty&
157};
158template<class To, class From> struct cast_retty_impl<To, const From> {
159 using ret_type = const To &; // Normal case, return Ty&
160};
161
162template<class To, class From> struct cast_retty_impl<To, From*> {
163 using ret_type = To *; // Pointer arg case, return Ty*
164};
165
166template<class To, class From> struct cast_retty_impl<To, const From*> {
167 using ret_type = const To *; // Constant pointer arg case, return const Ty*
168};
169
170template<class To, class From> struct cast_retty_impl<To, const From*const> {
171 using ret_type = const To *; // Constant pointer arg case, return const Ty*
172};
173
174template <class To, class From>
175struct cast_retty_impl<To, std::unique_ptr<From>> {
176private:
177 using PointerType = typename cast_retty_impl<To, From *>::ret_type;
178 using ResultType = typename std::remove_pointer<PointerType>::type;
179
180public:
181 using ret_type = std::unique_ptr<ResultType>;
182};
183
184template<class To, class From, class SimpleFrom>
185struct cast_retty_wrap {
186 // When the simplified type and the from type are not the same, use the type
187 // simplifier to reduce the type, then reuse cast_retty_impl to get the
188 // resultant type.
189 using ret_type = typename cast_retty<To, SimpleFrom>::ret_type;
190};
191
192template<class To, class FromTy>
193struct cast_retty_wrap<To, FromTy, FromTy> {
194 // When the simplified type is equal to the from type, use it directly.
195 using ret_type = typename cast_retty_impl<To,FromTy>::ret_type;
196};
197
198template<class To, class From>
199struct cast_retty {
200 using ret_type = typename cast_retty_wrap<
201 To, From, typename simplify_type<From>::SimpleType>::ret_type;
202};
203
204// Ensure the non-simple values are converted using the simplify_type template
205// that may be specialized by smart pointers...
206//
207template<class To, class From, class SimpleFrom> struct cast_convert_val {
208 // This is not a simple type, use the template to simplify it...
209 static typename cast_retty<To, From>::ret_type doit(From &Val) {
210 return cast_convert_val<To, SimpleFrom,
211 typename simplify_type<SimpleFrom>::SimpleType>::doit(
212 simplify_type<From>::getSimplifiedValue(Val));
213 }
214};
215
216template<class To, class FromTy> struct cast_convert_val<To,FromTy,FromTy> {
217 // This _is_ a simple type, just cast it.
218 static typename cast_retty<To, FromTy>::ret_type doit(const FromTy &Val) {
219 typename cast_retty<To, FromTy>::ret_type Res2
220 = (typename cast_retty<To, FromTy>::ret_type)const_cast<FromTy&>(Val);
221 return Res2;
222 }
223};
224
225template <class X> struct is_simple_type {
226 static const bool value =
227 std::is_same<X, typename simplify_type<X>::SimpleType>::value;
228};
229
230// cast<X> - Return the argument parameter cast to the specified type. This
231// casting operator asserts that the type is correct, so it does not return null
232// on failure. It does not allow a null argument (use cast_or_null for that).
233// It is typically used like this:
234//
235// cast<Instruction>(myVal)->getParent()
236//
237template <class X, class Y>
238inline typename std::enable_if<!is_simple_type<Y>::value,
239 typename cast_retty<X, const Y>::ret_type>::type
240cast(const Y &Val) {
241 assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
) ? void (0) : __assert_fail ("isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 241, __extension__ __PRETTY_FUNCTION__))
;
242 return cast_convert_val<
243 X, const Y, typename simplify_type<const Y>::SimpleType>::doit(Val);
244}
245
246template <class X, class Y>
247inline typename cast_retty<X, Y>::ret_type cast(Y &Val) {
248 assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
) ? void (0) : __assert_fail ("isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 248, __extension__ __PRETTY_FUNCTION__))
;
249 return cast_convert_val<X, Y,
250 typename simplify_type<Y>::SimpleType>::doit(Val);
251}
252
253template <class X, class Y>
254inline typename cast_retty<X, Y *>::ret_type cast(Y *Val) {
255 assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"
) ? void (0) : __assert_fail ("isa<X>(Val) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 255, __extension__ __PRETTY_FUNCTION__))
;
256 return cast_convert_val<X, Y*,
257 typename simplify_type<Y*>::SimpleType>::doit(Val);
258}
259
260template <class X, class Y>
261inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
262cast(std::unique_ptr<Y> &&Val) {
263 assert(isa<X>(Val.get()) && "cast<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val.get()) &&
"cast<Ty>() argument of incompatible type!") ? void (0
) : __assert_fail ("isa<X>(Val.get()) && \"cast<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 263, __extension__ __PRETTY_FUNCTION__))
;
264 using ret_type = typename cast_retty<X, std::unique_ptr<Y>>::ret_type;
265 return ret_type(
266 cast_convert_val<X, Y *, typename simplify_type<Y *>::SimpleType>::doit(
267 Val.release()));
268}
269
270// cast_or_null<X> - Functionally identical to cast, except that a null value is
271// accepted.
272//
273template <class X, class Y>
274LLVM_NODISCARD[[clang::warn_unused_result]] inline
275 typename std::enable_if<!is_simple_type<Y>::value,
276 typename cast_retty<X, const Y>::ret_type>::type
277 cast_or_null(const Y &Val) {
278 if (!Val)
279 return nullptr;
280 assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"
) ? void (0) : __assert_fail ("isa<X>(Val) && \"cast_or_null<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 280, __extension__ __PRETTY_FUNCTION__))
;
281 return cast<X>(Val);
282}
283
284template <class X, class Y>
285LLVM_NODISCARD[[clang::warn_unused_result]] inline
286 typename std::enable_if<!is_simple_type<Y>::value,
287 typename cast_retty<X, Y>::ret_type>::type
288 cast_or_null(Y &Val) {
289 if (!Val)
290 return nullptr;
291 assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"
) ? void (0) : __assert_fail ("isa<X>(Val) && \"cast_or_null<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 291, __extension__ __PRETTY_FUNCTION__))
;
292 return cast<X>(Val);
293}
294
295template <class X, class Y>
296LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y *>::ret_type
297cast_or_null(Y *Val) {
298 if (!Val) return nullptr;
299 assert(isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!")(static_cast <bool> (isa<X>(Val) && "cast_or_null<Ty>() argument of incompatible type!"
) ? void (0) : __assert_fail ("isa<X>(Val) && \"cast_or_null<Ty>() argument of incompatible type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/Support/Casting.h"
, 299, __extension__ __PRETTY_FUNCTION__))
;
300 return cast<X>(Val);
301}
302
303template <class X, class Y>
304inline typename cast_retty<X, std::unique_ptr<Y>>::ret_type
305cast_or_null(std::unique_ptr<Y> &&Val) {
306 if (!Val)
307 return nullptr;
308 return cast<X>(std::move(Val));
309}
310
311// dyn_cast<X> - Return the argument parameter cast to the specified type. This
312// casting operator returns null if the argument is of the wrong type, so it can
313// be used to test for a type as well as cast if successful. This should be
314// used in the context of an if statement like this:
315//
316// if (const Instruction *I = dyn_cast<Instruction>(myVal)) { ... }
317//
318
319template <class X, class Y>
320LLVM_NODISCARD[[clang::warn_unused_result]] inline
321 typename std::enable_if<!is_simple_type<Y>::value,
322 typename cast_retty<X, const Y>::ret_type>::type
323 dyn_cast(const Y &Val) {
324 return isa<X>(Val) ? cast<X>(Val) : nullptr;
325}
326
327template <class X, class Y>
328LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y>::ret_type dyn_cast(Y &Val) {
329 return isa<X>(Val) ? cast<X>(Val) : nullptr;
330}
331
332template <class X, class Y>
333LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y *>::ret_type dyn_cast(Y *Val) {
334 return isa<X>(Val) ? cast<X>(Val) : nullptr;
18
Calling 'isa'
45
Returning from 'isa'
46
'?' condition is false
335}
336
337// dyn_cast_or_null<X> - Functionally identical to dyn_cast, except that a null
338// value is accepted.
339//
340template <class X, class Y>
341LLVM_NODISCARD[[clang::warn_unused_result]] inline
342 typename std::enable_if<!is_simple_type<Y>::value,
343 typename cast_retty<X, const Y>::ret_type>::type
344 dyn_cast_or_null(const Y &Val) {
345 return (Val && isa<X>(Val)) ? cast<X>(Val) : nullptr;
346}
347
348template <class X, class Y>
349LLVM_NODISCARD[[clang::warn_unused_result]] inline
350 typename std::enable_if<!is_simple_type<Y>::value,
351 typename cast_retty<X, Y>::ret_type>::type
352 dyn_cast_or_null(Y &Val) {
353 return (Val && isa<X>(Val)) ? cast<X>(Val) : nullptr;
354}
355
356template <class X, class Y>
357LLVM_NODISCARD[[clang::warn_unused_result]] inline typename cast_retty<X, Y *>::ret_type
358dyn_cast_or_null(Y *Val) {
359 return (Val && isa<X>(Val)) ? cast<X>(Val) : nullptr;
360}
361
362// unique_dyn_cast<X> - Given a unique_ptr<Y>, try to return a unique_ptr<X>,
363// taking ownership of the input pointer iff isa<X>(Val) is true. If the
364// cast is successful, From refers to nullptr on exit and the casted value
365// is returned. If the cast is unsuccessful, the function returns nullptr
366// and From is unchanged.
367template <class X, class Y>
368LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast(std::unique_ptr<Y> &Val)
369 -> decltype(cast<X>(Val)) {
370 if (!isa<X>(Val))
371 return nullptr;
372 return cast<X>(std::move(Val));
373}
374
375template <class X, class Y>
376LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast(std::unique_ptr<Y> &&Val)
377 -> decltype(cast<X>(Val)) {
378 return unique_dyn_cast<X, Y>(Val);
379}
380
381// dyn_cast_or_null<X> - Functionally identical to unique_dyn_cast, except that
382// a null value is accepted.
383template <class X, class Y>
384LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &Val)
385 -> decltype(cast<X>(Val)) {
386 if (!Val)
387 return nullptr;
388 return unique_dyn_cast<X, Y>(Val);
389}
390
391template <class X, class Y>
392LLVM_NODISCARD[[clang::warn_unused_result]] inline auto unique_dyn_cast_or_null(std::unique_ptr<Y> &&Val)
393 -> decltype(cast<X>(Val)) {
394 return unique_dyn_cast_or_null<X, Y>(Val);
395}
396
397} // end namespace llvm
398
399#endif // LLVM_SUPPORT_CASTING_H

/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h

1//===- llvm/Instructions.h - Instruction subclass definitions ---*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file exposes the class definitions of all of the subclasses of the
11// Instruction class. This is meant to be an easy way to get access to all
12// instruction subclasses.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_IR_INSTRUCTIONS_H
17#define LLVM_IR_INSTRUCTIONS_H
18
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/None.h"
21#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/SmallVector.h"
23#include "llvm/ADT/StringRef.h"
24#include "llvm/ADT/Twine.h"
25#include "llvm/ADT/iterator.h"
26#include "llvm/ADT/iterator_range.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/BasicBlock.h"
29#include "llvm/IR/CallingConv.h"
30#include "llvm/IR/Constant.h"
31#include "llvm/IR/DerivedTypes.h"
32#include "llvm/IR/Function.h"
33#include "llvm/IR/InstrTypes.h"
34#include "llvm/IR/Instruction.h"
35#include "llvm/IR/OperandTraits.h"
36#include "llvm/IR/Type.h"
37#include "llvm/IR/Use.h"
38#include "llvm/IR/User.h"
39#include "llvm/IR/Value.h"
40#include "llvm/Support/AtomicOrdering.h"
41#include "llvm/Support/Casting.h"
42#include "llvm/Support/ErrorHandling.h"
43#include <cassert>
44#include <cstddef>
45#include <cstdint>
46#include <iterator>
47
48namespace llvm {
49
50class APInt;
51class ConstantInt;
52class DataLayout;
53class LLVMContext;
54
55//===----------------------------------------------------------------------===//
56// AllocaInst Class
57//===----------------------------------------------------------------------===//
58
59/// an instruction to allocate memory on the stack
60class AllocaInst : public UnaryInstruction {
61 Type *AllocatedType;
62
63protected:
64 // Note: Instruction needs to be a friend here to call cloneImpl.
65 friend class Instruction;
66
67 AllocaInst *cloneImpl() const;
68
69public:
70 explicit AllocaInst(Type *Ty, unsigned AddrSpace,
71 Value *ArraySize = nullptr,
72 const Twine &Name = "",
73 Instruction *InsertBefore = nullptr);
74 AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,
75 const Twine &Name, BasicBlock *InsertAtEnd);
76
77 AllocaInst(Type *Ty, unsigned AddrSpace,
78 const Twine &Name, Instruction *InsertBefore = nullptr);
79 AllocaInst(Type *Ty, unsigned AddrSpace,
80 const Twine &Name, BasicBlock *InsertAtEnd);
81
82 AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, unsigned Align,
83 const Twine &Name = "", Instruction *InsertBefore = nullptr);
84 AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, unsigned Align,
85 const Twine &Name, BasicBlock *InsertAtEnd);
86
87 /// Return true if there is an allocation size parameter to the allocation
88 /// instruction that is not 1.
89 bool isArrayAllocation() const;
90
91 /// Get the number of elements allocated. For a simple allocation of a single
92 /// element, this will return a constant 1 value.
93 const Value *getArraySize() const { return getOperand(0); }
94 Value *getArraySize() { return getOperand(0); }
95
96 /// Overload to return most specific pointer type.
97 PointerType *getType() const {
98 return cast<PointerType>(Instruction::getType());
99 }
100
101 /// Return the type that is being allocated by the instruction.
102 Type *getAllocatedType() const { return AllocatedType; }
103 /// for use only in special circumstances that need to generically
104 /// transform a whole instruction (eg: IR linking and vectorization).
105 void setAllocatedType(Type *Ty) { AllocatedType = Ty; }
106
107 /// Return the alignment of the memory that is being allocated by the
108 /// instruction.
109 unsigned getAlignment() const {
110 return (1u << (getSubclassDataFromInstruction() & 31)) >> 1;
111 }
112 void setAlignment(unsigned Align);
113
114 /// Return true if this alloca is in the entry block of the function and is a
115 /// constant size. If so, the code generator will fold it into the
116 /// prolog/epilog code, so it is basically free.
117 bool isStaticAlloca() const;
118
119 /// Return true if this alloca is used as an inalloca argument to a call. Such
120 /// allocas are never considered static even if they are in the entry block.
121 bool isUsedWithInAlloca() const {
122 return getSubclassDataFromInstruction() & 32;
123 }
124
125 /// Specify whether this alloca is used to represent the arguments to a call.
126 void setUsedWithInAlloca(bool V) {
127 setInstructionSubclassData((getSubclassDataFromInstruction() & ~32) |
128 (V ? 32 : 0));
129 }
130
131 /// Return true if this alloca is used as a swifterror argument to a call.
132 bool isSwiftError() const {
133 return getSubclassDataFromInstruction() & 64;
134 }
135
136 /// Specify whether this alloca is used to represent a swifterror.
137 void setSwiftError(bool V) {
138 setInstructionSubclassData((getSubclassDataFromInstruction() & ~64) |
139 (V ? 64 : 0));
140 }
141
142 // Methods for support type inquiry through isa, cast, and dyn_cast:
143 static bool classof(const Instruction *I) {
144 return (I->getOpcode() == Instruction::Alloca);
145 }
146 static bool classof(const Value *V) {
147 return isa<Instruction>(V) && classof(cast<Instruction>(V));
148 }
149
150private:
151 // Shadow Instruction::setInstructionSubclassData with a private forwarding
152 // method so that subclasses cannot accidentally use it.
153 void setInstructionSubclassData(unsigned short D) {
154 Instruction::setInstructionSubclassData(D);
155 }
156};
157
158//===----------------------------------------------------------------------===//
159// LoadInst Class
160//===----------------------------------------------------------------------===//
161
162/// An instruction for reading from memory. This uses the SubclassData field in
163/// Value to store whether or not the load is volatile.
164class LoadInst : public UnaryInstruction {
165 void AssertOK();
166
167protected:
168 // Note: Instruction needs to be a friend here to call cloneImpl.
169 friend class Instruction;
170
171 LoadInst *cloneImpl() const;
172
173public:
174 LoadInst(Value *Ptr, const Twine &NameStr, Instruction *InsertBefore);
175 LoadInst(Value *Ptr, const Twine &NameStr, BasicBlock *InsertAtEnd);
176 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile = false,
177 Instruction *InsertBefore = nullptr);
178 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile = false,
179 Instruction *InsertBefore = nullptr)
180 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
181 NameStr, isVolatile, InsertBefore) {}
182 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
183 BasicBlock *InsertAtEnd);
184 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
185 Instruction *InsertBefore = nullptr)
186 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
187 NameStr, isVolatile, Align, InsertBefore) {}
188 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
189 unsigned Align, Instruction *InsertBefore = nullptr);
190 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
191 unsigned Align, BasicBlock *InsertAtEnd);
192 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile, unsigned Align,
193 AtomicOrdering Order, SyncScope::ID SSID = SyncScope::System,
194 Instruction *InsertBefore = nullptr)
195 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
196 NameStr, isVolatile, Align, Order, SSID, InsertBefore) {}
197 LoadInst(Type *Ty, Value *Ptr, const Twine &NameStr, bool isVolatile,
198 unsigned Align, AtomicOrdering Order,
199 SyncScope::ID SSID = SyncScope::System,
200 Instruction *InsertBefore = nullptr);
201 LoadInst(Value *Ptr, const Twine &NameStr, bool isVolatile,
202 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
203 BasicBlock *InsertAtEnd);
204 LoadInst(Value *Ptr, const char *NameStr, Instruction *InsertBefore);
205 LoadInst(Value *Ptr, const char *NameStr, BasicBlock *InsertAtEnd);
206 LoadInst(Type *Ty, Value *Ptr, const char *NameStr = nullptr,
207 bool isVolatile = false, Instruction *InsertBefore = nullptr);
208 explicit LoadInst(Value *Ptr, const char *NameStr = nullptr,
209 bool isVolatile = false,
210 Instruction *InsertBefore = nullptr)
211 : LoadInst(cast<PointerType>(Ptr->getType())->getElementType(), Ptr,
212 NameStr, isVolatile, InsertBefore) {}
213 LoadInst(Value *Ptr, const char *NameStr, bool isVolatile,
214 BasicBlock *InsertAtEnd);
215
216 /// Return true if this is a load from a volatile memory location.
217 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
218
219 /// Specify whether this is a volatile load or not.
220 void setVolatile(bool V) {
221 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
222 (V ? 1 : 0));
223 }
224
225 /// Return the alignment of the access that is being performed.
226 unsigned getAlignment() const {
227 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
228 }
229
230 void setAlignment(unsigned Align);
231
232 /// Returns the ordering constraint of this load instruction.
233 AtomicOrdering getOrdering() const {
234 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
235 }
236
237 /// Sets the ordering constraint of this load instruction. May not be Release
238 /// or AcquireRelease.
239 void setOrdering(AtomicOrdering Ordering) {
240 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
241 ((unsigned)Ordering << 7));
242 }
243
244 /// Returns the synchronization scope ID of this load instruction.
245 SyncScope::ID getSyncScopeID() const {
246 return SSID;
247 }
248
249 /// Sets the synchronization scope ID of this load instruction.
250 void setSyncScopeID(SyncScope::ID SSID) {
251 this->SSID = SSID;
252 }
253
254 /// Sets the ordering constraint and the synchronization scope ID of this load
255 /// instruction.
256 void setAtomic(AtomicOrdering Ordering,
257 SyncScope::ID SSID = SyncScope::System) {
258 setOrdering(Ordering);
259 setSyncScopeID(SSID);
260 }
261
262 bool isSimple() const { return !isAtomic() && !isVolatile(); }
263
264 bool isUnordered() const {
265 return (getOrdering() == AtomicOrdering::NotAtomic ||
266 getOrdering() == AtomicOrdering::Unordered) &&
267 !isVolatile();
268 }
269
270 Value *getPointerOperand() { return getOperand(0); }
271 const Value *getPointerOperand() const { return getOperand(0); }
272 static unsigned getPointerOperandIndex() { return 0U; }
273 Type *getPointerOperandType() const { return getPointerOperand()->getType(); }
274
275 /// Returns the address space of the pointer operand.
276 unsigned getPointerAddressSpace() const {
277 return getPointerOperandType()->getPointerAddressSpace();
278 }
279
280 // Methods for support type inquiry through isa, cast, and dyn_cast:
281 static bool classof(const Instruction *I) {
282 return I->getOpcode() == Instruction::Load;
283 }
284 static bool classof(const Value *V) {
285 return isa<Instruction>(V) && classof(cast<Instruction>(V));
286 }
287
288private:
289 // Shadow Instruction::setInstructionSubclassData with a private forwarding
290 // method so that subclasses cannot accidentally use it.
291 void setInstructionSubclassData(unsigned short D) {
292 Instruction::setInstructionSubclassData(D);
293 }
294
295 /// The synchronization scope ID of this load instruction. Not quite enough
296 /// room in SubClassData for everything, so synchronization scope ID gets its
297 /// own field.
298 SyncScope::ID SSID;
299};
300
301//===----------------------------------------------------------------------===//
302// StoreInst Class
303//===----------------------------------------------------------------------===//
304
305/// An instruction for storing to memory.
306class StoreInst : public Instruction {
307 void AssertOK();
308
309protected:
310 // Note: Instruction needs to be a friend here to call cloneImpl.
311 friend class Instruction;
312
313 StoreInst *cloneImpl() const;
314
315public:
316 StoreInst(Value *Val, Value *Ptr, Instruction *InsertBefore);
317 StoreInst(Value *Val, Value *Ptr, BasicBlock *InsertAtEnd);
318 StoreInst(Value *Val, Value *Ptr, bool isVolatile = false,
319 Instruction *InsertBefore = nullptr);
320 StoreInst(Value *Val, Value *Ptr, bool isVolatile, BasicBlock *InsertAtEnd);
321 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
322 unsigned Align, Instruction *InsertBefore = nullptr);
323 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
324 unsigned Align, BasicBlock *InsertAtEnd);
325 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
326 unsigned Align, AtomicOrdering Order,
327 SyncScope::ID SSID = SyncScope::System,
328 Instruction *InsertBefore = nullptr);
329 StoreInst(Value *Val, Value *Ptr, bool isVolatile,
330 unsigned Align, AtomicOrdering Order, SyncScope::ID SSID,
331 BasicBlock *InsertAtEnd);
332
333 // allocate space for exactly two operands
334 void *operator new(size_t s) {
335 return User::operator new(s, 2);
336 }
337
338 /// Return true if this is a store to a volatile memory location.
339 bool isVolatile() const { return getSubclassDataFromInstruction() & 1; }
340
341 /// Specify whether this is a volatile store or not.
342 void setVolatile(bool V) {
343 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
344 (V ? 1 : 0));
345 }
346
347 /// Transparently provide more efficient getOperand methods.
348 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
349
350 /// Return the alignment of the access that is being performed
351 unsigned getAlignment() const {
352 return (1 << ((getSubclassDataFromInstruction() >> 1) & 31)) >> 1;
353 }
354
355 void setAlignment(unsigned Align);
356
357 /// Returns the ordering constraint of this store instruction.
358 AtomicOrdering getOrdering() const {
359 return AtomicOrdering((getSubclassDataFromInstruction() >> 7) & 7);
360 }
361
362 /// Sets the ordering constraint of this store instruction. May not be
363 /// Acquire or AcquireRelease.
364 void setOrdering(AtomicOrdering Ordering) {
365 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 7)) |
366 ((unsigned)Ordering << 7));
367 }
368
369 /// Returns the synchronization scope ID of this store instruction.
370 SyncScope::ID getSyncScopeID() const {
371 return SSID;
372 }
373
374 /// Sets the synchronization scope ID of this store instruction.
375 void setSyncScopeID(SyncScope::ID SSID) {
376 this->SSID = SSID;
377 }
378
379 /// Sets the ordering constraint and the synchronization scope ID of this
380 /// store instruction.
381 void setAtomic(AtomicOrdering Ordering,
382 SyncScope::ID SSID = SyncScope::System) {
383 setOrdering(Ordering);
384 setSyncScopeID(SSID);
385 }
386
387 bool isSimple() const { return !isAtomic() && !isVolatile(); }
388
389 bool isUnordered() const {
390 return (getOrdering() == AtomicOrdering::NotAtomic ||
391 getOrdering() == AtomicOrdering::Unordered) &&
392 !isVolatile();
393 }
394
395 Value *getValueOperand() { return getOperand(0); }
396 const Value *getValueOperand() const { return getOperand(0); }
397
398 Value *getPointerOperand() { return getOperand(1); }
399 const Value *getPointerOperand() const { return getOperand(1); }
400 static unsigned getPointerOperandIndex() { return 1U; }
401 Type *getPointerOperandType() const { return getPointerOperand()->getType(); }
402
403 /// Returns the address space of the pointer operand.
404 unsigned getPointerAddressSpace() const {
405 return getPointerOperandType()->getPointerAddressSpace();
406 }
407
408 // Methods for support type inquiry through isa, cast, and dyn_cast:
409 static bool classof(const Instruction *I) {
410 return I->getOpcode() == Instruction::Store;
411 }
412 static bool classof(const Value *V) {
413 return isa<Instruction>(V) && classof(cast<Instruction>(V));
414 }
415
416private:
417 // Shadow Instruction::setInstructionSubclassData with a private forwarding
418 // method so that subclasses cannot accidentally use it.
419 void setInstructionSubclassData(unsigned short D) {
420 Instruction::setInstructionSubclassData(D);
421 }
422
423 /// The synchronization scope ID of this store instruction. Not quite enough
424 /// room in SubClassData for everything, so synchronization scope ID gets its
425 /// own field.
426 SyncScope::ID SSID;
427};
428
429template <>
430struct OperandTraits<StoreInst> : public FixedNumOperandTraits<StoreInst, 2> {
431};
432
433DEFINE_TRANSPARENT_OPERAND_ACCESSORS(StoreInst, Value)StoreInst::op_iterator StoreInst::op_begin() { return OperandTraits
<StoreInst>::op_begin(this); } StoreInst::const_op_iterator
StoreInst::op_begin() const { return OperandTraits<StoreInst
>::op_begin(const_cast<StoreInst*>(this)); } StoreInst
::op_iterator StoreInst::op_end() { return OperandTraits<StoreInst
>::op_end(this); } StoreInst::const_op_iterator StoreInst::
op_end() const { return OperandTraits<StoreInst>::op_end
(const_cast<StoreInst*>(this)); } Value *StoreInst::getOperand
(unsigned i_nocapture) const { (static_cast <bool> (i_nocapture
< OperandTraits<StoreInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<StoreInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 433, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<StoreInst>::op_begin(const_cast
<StoreInst*>(this))[i_nocapture].get()); } void StoreInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<StoreInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<StoreInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 433, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
StoreInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned StoreInst::getNumOperands() const { return OperandTraits
<StoreInst>::operands(this); } template <int Idx_nocapture
> Use &StoreInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
StoreInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
434
435//===----------------------------------------------------------------------===//
436// FenceInst Class
437//===----------------------------------------------------------------------===//
438
439/// An instruction for ordering other memory operations.
440class FenceInst : public Instruction {
441 void Init(AtomicOrdering Ordering, SyncScope::ID SSID);
442
443protected:
444 // Note: Instruction needs to be a friend here to call cloneImpl.
445 friend class Instruction;
446
447 FenceInst *cloneImpl() const;
448
449public:
450 // Ordering may only be Acquire, Release, AcquireRelease, or
451 // SequentiallyConsistent.
452 FenceInst(LLVMContext &C, AtomicOrdering Ordering,
453 SyncScope::ID SSID = SyncScope::System,
454 Instruction *InsertBefore = nullptr);
455 FenceInst(LLVMContext &C, AtomicOrdering Ordering, SyncScope::ID SSID,
456 BasicBlock *InsertAtEnd);
457
458 // allocate space for exactly zero operands
459 void *operator new(size_t s) {
460 return User::operator new(s, 0);
461 }
462
463 /// Returns the ordering constraint of this fence instruction.
464 AtomicOrdering getOrdering() const {
465 return AtomicOrdering(getSubclassDataFromInstruction() >> 1);
466 }
467
468 /// Sets the ordering constraint of this fence instruction. May only be
469 /// Acquire, Release, AcquireRelease, or SequentiallyConsistent.
470 void setOrdering(AtomicOrdering Ordering) {
471 setInstructionSubclassData((getSubclassDataFromInstruction() & 1) |
472 ((unsigned)Ordering << 1));
473 }
474
475 /// Returns the synchronization scope ID of this fence instruction.
476 SyncScope::ID getSyncScopeID() const {
477 return SSID;
478 }
479
480 /// Sets the synchronization scope ID of this fence instruction.
481 void setSyncScopeID(SyncScope::ID SSID) {
482 this->SSID = SSID;
483 }
484
485 // Methods for support type inquiry through isa, cast, and dyn_cast:
486 static bool classof(const Instruction *I) {
487 return I->getOpcode() == Instruction::Fence;
488 }
489 static bool classof(const Value *V) {
490 return isa<Instruction>(V) && classof(cast<Instruction>(V));
491 }
492
493private:
494 // Shadow Instruction::setInstructionSubclassData with a private forwarding
495 // method so that subclasses cannot accidentally use it.
496 void setInstructionSubclassData(unsigned short D) {
497 Instruction::setInstructionSubclassData(D);
498 }
499
500 /// The synchronization scope ID of this fence instruction. Not quite enough
501 /// room in SubClassData for everything, so synchronization scope ID gets its
502 /// own field.
503 SyncScope::ID SSID;
504};
505
506//===----------------------------------------------------------------------===//
507// AtomicCmpXchgInst Class
508//===----------------------------------------------------------------------===//
509
510/// an instruction that atomically checks whether a
511/// specified value is in a memory location, and, if it is, stores a new value
512/// there. Returns the value that was loaded.
513///
514class AtomicCmpXchgInst : public Instruction {
515 void Init(Value *Ptr, Value *Cmp, Value *NewVal,
516 AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
517 SyncScope::ID SSID);
518
519protected:
520 // Note: Instruction needs to be a friend here to call cloneImpl.
521 friend class Instruction;
522
523 AtomicCmpXchgInst *cloneImpl() const;
524
525public:
526 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
527 AtomicOrdering SuccessOrdering,
528 AtomicOrdering FailureOrdering,
529 SyncScope::ID SSID, Instruction *InsertBefore = nullptr);
530 AtomicCmpXchgInst(Value *Ptr, Value *Cmp, Value *NewVal,
531 AtomicOrdering SuccessOrdering,
532 AtomicOrdering FailureOrdering,
533 SyncScope::ID SSID, BasicBlock *InsertAtEnd);
534
535 // allocate space for exactly three operands
536 void *operator new(size_t s) {
537 return User::operator new(s, 3);
538 }
539
540 /// Return true if this is a cmpxchg from a volatile memory
541 /// location.
542 ///
543 bool isVolatile() const {
544 return getSubclassDataFromInstruction() & 1;
545 }
546
547 /// Specify whether this is a volatile cmpxchg.
548 ///
549 void setVolatile(bool V) {
550 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
551 (unsigned)V);
552 }
553
554 /// Return true if this cmpxchg may spuriously fail.
555 bool isWeak() const {
556 return getSubclassDataFromInstruction() & 0x100;
557 }
558
559 void setWeak(bool IsWeak) {
560 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x100) |
561 (IsWeak << 8));
562 }
563
564 /// Transparently provide more efficient getOperand methods.
565 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
566
567 /// Returns the success ordering constraint of this cmpxchg instruction.
568 AtomicOrdering getSuccessOrdering() const {
569 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
570 }
571
572 /// Sets the success ordering constraint of this cmpxchg instruction.
573 void setSuccessOrdering(AtomicOrdering Ordering) {
574 assert(Ordering != AtomicOrdering::NotAtomic &&(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 575, __extension__ __PRETTY_FUNCTION__))
575 "CmpXchg instructions can only be atomic.")(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 575, __extension__ __PRETTY_FUNCTION__))
;
576 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0x1c) |
577 ((unsigned)Ordering << 2));
578 }
579
580 /// Returns the failure ordering constraint of this cmpxchg instruction.
581 AtomicOrdering getFailureOrdering() const {
582 return AtomicOrdering((getSubclassDataFromInstruction() >> 5) & 7);
583 }
584
585 /// Sets the failure ordering constraint of this cmpxchg instruction.
586 void setFailureOrdering(AtomicOrdering Ordering) {
587 assert(Ordering != AtomicOrdering::NotAtomic &&(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 588, __extension__ __PRETTY_FUNCTION__))
588 "CmpXchg instructions can only be atomic.")(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "CmpXchg instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"CmpXchg instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 588, __extension__ __PRETTY_FUNCTION__))
;
589 setInstructionSubclassData((getSubclassDataFromInstruction() & ~0xe0) |
590 ((unsigned)Ordering << 5));
591 }
592
593 /// Returns the synchronization scope ID of this cmpxchg instruction.
594 SyncScope::ID getSyncScopeID() const {
595 return SSID;
596 }
597
598 /// Sets the synchronization scope ID of this cmpxchg instruction.
599 void setSyncScopeID(SyncScope::ID SSID) {
600 this->SSID = SSID;
601 }
602
603 Value *getPointerOperand() { return getOperand(0); }
604 const Value *getPointerOperand() const { return getOperand(0); }
605 static unsigned getPointerOperandIndex() { return 0U; }
606
607 Value *getCompareOperand() { return getOperand(1); }
608 const Value *getCompareOperand() const { return getOperand(1); }
609
610 Value *getNewValOperand() { return getOperand(2); }
611 const Value *getNewValOperand() const { return getOperand(2); }
612
613 /// Returns the address space of the pointer operand.
614 unsigned getPointerAddressSpace() const {
615 return getPointerOperand()->getType()->getPointerAddressSpace();
616 }
617
618 /// Returns the strongest permitted ordering on failure, given the
619 /// desired ordering on success.
620 ///
621 /// If the comparison in a cmpxchg operation fails, there is no atomic store
622 /// so release semantics cannot be provided. So this function drops explicit
623 /// Release requests from the AtomicOrdering. A SequentiallyConsistent
624 /// operation would remain SequentiallyConsistent.
625 static AtomicOrdering
626 getStrongestFailureOrdering(AtomicOrdering SuccessOrdering) {
627 switch (SuccessOrdering) {
628 default:
629 llvm_unreachable("invalid cmpxchg success ordering")::llvm::llvm_unreachable_internal("invalid cmpxchg success ordering"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 629)
;
630 case AtomicOrdering::Release:
631 case AtomicOrdering::Monotonic:
632 return AtomicOrdering::Monotonic;
633 case AtomicOrdering::AcquireRelease:
634 case AtomicOrdering::Acquire:
635 return AtomicOrdering::Acquire;
636 case AtomicOrdering::SequentiallyConsistent:
637 return AtomicOrdering::SequentiallyConsistent;
638 }
639 }
640
641 // Methods for support type inquiry through isa, cast, and dyn_cast:
642 static bool classof(const Instruction *I) {
643 return I->getOpcode() == Instruction::AtomicCmpXchg;
644 }
645 static bool classof(const Value *V) {
646 return isa<Instruction>(V) && classof(cast<Instruction>(V));
647 }
648
649private:
650 // Shadow Instruction::setInstructionSubclassData with a private forwarding
651 // method so that subclasses cannot accidentally use it.
652 void setInstructionSubclassData(unsigned short D) {
653 Instruction::setInstructionSubclassData(D);
654 }
655
656 /// The synchronization scope ID of this cmpxchg instruction. Not quite
657 /// enough room in SubClassData for everything, so synchronization scope ID
658 /// gets its own field.
659 SyncScope::ID SSID;
660};
661
662template <>
663struct OperandTraits<AtomicCmpXchgInst> :
664 public FixedNumOperandTraits<AtomicCmpXchgInst, 3> {
665};
666
667DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicCmpXchgInst, Value)AtomicCmpXchgInst::op_iterator AtomicCmpXchgInst::op_begin() {
return OperandTraits<AtomicCmpXchgInst>::op_begin(this
); } AtomicCmpXchgInst::const_op_iterator AtomicCmpXchgInst::
op_begin() const { return OperandTraits<AtomicCmpXchgInst>
::op_begin(const_cast<AtomicCmpXchgInst*>(this)); } AtomicCmpXchgInst
::op_iterator AtomicCmpXchgInst::op_end() { return OperandTraits
<AtomicCmpXchgInst>::op_end(this); } AtomicCmpXchgInst::
const_op_iterator AtomicCmpXchgInst::op_end() const { return OperandTraits
<AtomicCmpXchgInst>::op_end(const_cast<AtomicCmpXchgInst
*>(this)); } Value *AtomicCmpXchgInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<AtomicCmpXchgInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicCmpXchgInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 667, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<AtomicCmpXchgInst>::op_begin
(const_cast<AtomicCmpXchgInst*>(this))[i_nocapture].get
()); } void AtomicCmpXchgInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<AtomicCmpXchgInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicCmpXchgInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 667, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
AtomicCmpXchgInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned AtomicCmpXchgInst::getNumOperands() const { return
OperandTraits<AtomicCmpXchgInst>::operands(this); } template
<int Idx_nocapture> Use &AtomicCmpXchgInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &AtomicCmpXchgInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
668
669//===----------------------------------------------------------------------===//
670// AtomicRMWInst Class
671//===----------------------------------------------------------------------===//
672
673/// an instruction that atomically reads a memory location,
674/// combines it with another value, and then stores the result back. Returns
675/// the old value.
676///
677class AtomicRMWInst : public Instruction {
678protected:
679 // Note: Instruction needs to be a friend here to call cloneImpl.
680 friend class Instruction;
681
682 AtomicRMWInst *cloneImpl() const;
683
684public:
685 /// This enumeration lists the possible modifications atomicrmw can make. In
686 /// the descriptions, 'p' is the pointer to the instruction's memory location,
687 /// 'old' is the initial value of *p, and 'v' is the other value passed to the
688 /// instruction. These instructions always return 'old'.
689 enum BinOp {
690 /// *p = v
691 Xchg,
692 /// *p = old + v
693 Add,
694 /// *p = old - v
695 Sub,
696 /// *p = old & v
697 And,
698 /// *p = ~(old & v)
699 Nand,
700 /// *p = old | v
701 Or,
702 /// *p = old ^ v
703 Xor,
704 /// *p = old >signed v ? old : v
705 Max,
706 /// *p = old <signed v ? old : v
707 Min,
708 /// *p = old >unsigned v ? old : v
709 UMax,
710 /// *p = old <unsigned v ? old : v
711 UMin,
712
713 FIRST_BINOP = Xchg,
714 LAST_BINOP = UMin,
715 BAD_BINOP
716 };
717
718 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
719 AtomicOrdering Ordering, SyncScope::ID SSID,
720 Instruction *InsertBefore = nullptr);
721 AtomicRMWInst(BinOp Operation, Value *Ptr, Value *Val,
722 AtomicOrdering Ordering, SyncScope::ID SSID,
723 BasicBlock *InsertAtEnd);
724
725 // allocate space for exactly two operands
726 void *operator new(size_t s) {
727 return User::operator new(s, 2);
728 }
729
730 BinOp getOperation() const {
731 return static_cast<BinOp>(getSubclassDataFromInstruction() >> 5);
732 }
733
734 void setOperation(BinOp Operation) {
735 unsigned short SubclassData = getSubclassDataFromInstruction();
736 setInstructionSubclassData((SubclassData & 31) |
737 (Operation << 5));
738 }
739
740 /// Return true if this is a RMW on a volatile memory location.
741 ///
742 bool isVolatile() const {
743 return getSubclassDataFromInstruction() & 1;
744 }
745
746 /// Specify whether this is a volatile RMW or not.
747 ///
748 void setVolatile(bool V) {
749 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
750 (unsigned)V);
751 }
752
753 /// Transparently provide more efficient getOperand methods.
754 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
755
756 /// Returns the ordering constraint of this rmw instruction.
757 AtomicOrdering getOrdering() const {
758 return AtomicOrdering((getSubclassDataFromInstruction() >> 2) & 7);
759 }
760
761 /// Sets the ordering constraint of this rmw instruction.
762 void setOrdering(AtomicOrdering Ordering) {
763 assert(Ordering != AtomicOrdering::NotAtomic &&(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "atomicrmw instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"atomicrmw instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 764, __extension__ __PRETTY_FUNCTION__))
764 "atomicrmw instructions can only be atomic.")(static_cast <bool> (Ordering != AtomicOrdering::NotAtomic
&& "atomicrmw instructions can only be atomic.") ? void
(0) : __assert_fail ("Ordering != AtomicOrdering::NotAtomic && \"atomicrmw instructions can only be atomic.\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 764, __extension__ __PRETTY_FUNCTION__))
;
765 setInstructionSubclassData((getSubclassDataFromInstruction() & ~(7 << 2)) |
766 ((unsigned)Ordering << 2));
767 }
768
769 /// Returns the synchronization scope ID of this rmw instruction.
770 SyncScope::ID getSyncScopeID() const {
771 return SSID;
772 }
773
774 /// Sets the synchronization scope ID of this rmw instruction.
775 void setSyncScopeID(SyncScope::ID SSID) {
776 this->SSID = SSID;
777 }
778
779 Value *getPointerOperand() { return getOperand(0); }
780 const Value *getPointerOperand() const { return getOperand(0); }
781 static unsigned getPointerOperandIndex() { return 0U; }
782
783 Value *getValOperand() { return getOperand(1); }
784 const Value *getValOperand() const { return getOperand(1); }
785
786 /// Returns the address space of the pointer operand.
787 unsigned getPointerAddressSpace() const {
788 return getPointerOperand()->getType()->getPointerAddressSpace();
789 }
790
791 // Methods for support type inquiry through isa, cast, and dyn_cast:
792 static bool classof(const Instruction *I) {
793 return I->getOpcode() == Instruction::AtomicRMW;
794 }
795 static bool classof(const Value *V) {
796 return isa<Instruction>(V) && classof(cast<Instruction>(V));
797 }
798
799private:
800 void Init(BinOp Operation, Value *Ptr, Value *Val,
801 AtomicOrdering Ordering, SyncScope::ID SSID);
802
803 // Shadow Instruction::setInstructionSubclassData with a private forwarding
804 // method so that subclasses cannot accidentally use it.
805 void setInstructionSubclassData(unsigned short D) {
806 Instruction::setInstructionSubclassData(D);
807 }
808
809 /// The synchronization scope ID of this rmw instruction. Not quite enough
810 /// room in SubClassData for everything, so synchronization scope ID gets its
811 /// own field.
812 SyncScope::ID SSID;
813};
814
815template <>
816struct OperandTraits<AtomicRMWInst>
817 : public FixedNumOperandTraits<AtomicRMWInst,2> {
818};
819
820DEFINE_TRANSPARENT_OPERAND_ACCESSORS(AtomicRMWInst, Value)AtomicRMWInst::op_iterator AtomicRMWInst::op_begin() { return
OperandTraits<AtomicRMWInst>::op_begin(this); } AtomicRMWInst
::const_op_iterator AtomicRMWInst::op_begin() const { return OperandTraits
<AtomicRMWInst>::op_begin(const_cast<AtomicRMWInst*>
(this)); } AtomicRMWInst::op_iterator AtomicRMWInst::op_end()
{ return OperandTraits<AtomicRMWInst>::op_end(this); }
AtomicRMWInst::const_op_iterator AtomicRMWInst::op_end() const
{ return OperandTraits<AtomicRMWInst>::op_end(const_cast
<AtomicRMWInst*>(this)); } Value *AtomicRMWInst::getOperand
(unsigned i_nocapture) const { (static_cast <bool> (i_nocapture
< OperandTraits<AtomicRMWInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicRMWInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 820, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<AtomicRMWInst>::op_begin(const_cast
<AtomicRMWInst*>(this))[i_nocapture].get()); } void AtomicRMWInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<AtomicRMWInst
>::operands(this) && "setOperand() out of range!")
? void (0) : __assert_fail ("i_nocapture < OperandTraits<AtomicRMWInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 820, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
AtomicRMWInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned AtomicRMWInst::getNumOperands() const { return OperandTraits
<AtomicRMWInst>::operands(this); } template <int Idx_nocapture
> Use &AtomicRMWInst::Op() { return this->OpFrom<
Idx_nocapture>(this); } template <int Idx_nocapture>
const Use &AtomicRMWInst::Op() const { return this->OpFrom
<Idx_nocapture>(this); }
821
822//===----------------------------------------------------------------------===//
823// GetElementPtrInst Class
824//===----------------------------------------------------------------------===//
825
826// checkGEPType - Simple wrapper function to give a better assertion failure
827// message on bad indexes for a gep instruction.
828//
829inline Type *checkGEPType(Type *Ty) {
830 assert(Ty && "Invalid GetElementPtrInst indices for type!")(static_cast <bool> (Ty && "Invalid GetElementPtrInst indices for type!"
) ? void (0) : __assert_fail ("Ty && \"Invalid GetElementPtrInst indices for type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 830, __extension__ __PRETTY_FUNCTION__))
;
831 return Ty;
832}
833
834/// an instruction for type-safe pointer arithmetic to
835/// access elements of arrays and structs
836///
837class GetElementPtrInst : public Instruction {
838 Type *SourceElementType;
839 Type *ResultElementType;
840
841 GetElementPtrInst(const GetElementPtrInst &GEPI);
842
843 /// Constructors - Create a getelementptr instruction with a base pointer an
844 /// list of indices. The first ctor can optionally insert before an existing
845 /// instruction, the second appends the new instruction to the specified
846 /// BasicBlock.
847 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
848 ArrayRef<Value *> IdxList, unsigned Values,
849 const Twine &NameStr, Instruction *InsertBefore);
850 inline GetElementPtrInst(Type *PointeeType, Value *Ptr,
851 ArrayRef<Value *> IdxList, unsigned Values,
852 const Twine &NameStr, BasicBlock *InsertAtEnd);
853
854 void init(Value *Ptr, ArrayRef<Value *> IdxList, const Twine &NameStr);
855
856protected:
857 // Note: Instruction needs to be a friend here to call cloneImpl.
858 friend class Instruction;
859
860 GetElementPtrInst *cloneImpl() const;
861
862public:
863 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
864 ArrayRef<Value *> IdxList,
865 const Twine &NameStr = "",
866 Instruction *InsertBefore = nullptr) {
867 unsigned Values = 1 + unsigned(IdxList.size());
868 if (!PointeeType)
869 PointeeType =
870 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
871 else
872 assert((static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 874, __extension__ __PRETTY_FUNCTION__))
873 PointeeType ==(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 874, __extension__ __PRETTY_FUNCTION__))
874 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType())(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 874, __extension__ __PRETTY_FUNCTION__))
;
875 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
876 NameStr, InsertBefore);
877 }
878
879 static GetElementPtrInst *Create(Type *PointeeType, Value *Ptr,
880 ArrayRef<Value *> IdxList,
881 const Twine &NameStr,
882 BasicBlock *InsertAtEnd) {
883 unsigned Values = 1 + unsigned(IdxList.size());
884 if (!PointeeType)
885 PointeeType =
886 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
887 else
888 assert((static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 890, __extension__ __PRETTY_FUNCTION__))
889 PointeeType ==(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 890, __extension__ __PRETTY_FUNCTION__))
890 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType())(static_cast <bool> (PointeeType == cast<PointerType
>(Ptr->getType()->getScalarType())->getElementType
()) ? void (0) : __assert_fail ("PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 890, __extension__ __PRETTY_FUNCTION__))
;
891 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
892 NameStr, InsertAtEnd);
893 }
894
895 /// Create an "inbounds" getelementptr. See the documentation for the
896 /// "inbounds" flag in LangRef.html for details.
897 static GetElementPtrInst *CreateInBounds(Value *Ptr,
898 ArrayRef<Value *> IdxList,
899 const Twine &NameStr = "",
900 Instruction *InsertBefore = nullptr){
901 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertBefore);
902 }
903
904 static GetElementPtrInst *
905 CreateInBounds(Type *PointeeType, Value *Ptr, ArrayRef<Value *> IdxList,
906 const Twine &NameStr = "",
907 Instruction *InsertBefore = nullptr) {
908 GetElementPtrInst *GEP =
909 Create(PointeeType, Ptr, IdxList, NameStr, InsertBefore);
910 GEP->setIsInBounds(true);
911 return GEP;
912 }
913
914 static GetElementPtrInst *CreateInBounds(Value *Ptr,
915 ArrayRef<Value *> IdxList,
916 const Twine &NameStr,
917 BasicBlock *InsertAtEnd) {
918 return CreateInBounds(nullptr, Ptr, IdxList, NameStr, InsertAtEnd);
919 }
920
921 static GetElementPtrInst *CreateInBounds(Type *PointeeType, Value *Ptr,
922 ArrayRef<Value *> IdxList,
923 const Twine &NameStr,
924 BasicBlock *InsertAtEnd) {
925 GetElementPtrInst *GEP =
926 Create(PointeeType, Ptr, IdxList, NameStr, InsertAtEnd);
927 GEP->setIsInBounds(true);
928 return GEP;
929 }
930
931 /// Transparently provide more efficient getOperand methods.
932 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
933
934 Type *getSourceElementType() const { return SourceElementType; }
935
936 void setSourceElementType(Type *Ty) { SourceElementType = Ty; }
937 void setResultElementType(Type *Ty) { ResultElementType = Ty; }
938
939 Type *getResultElementType() const {
940 assert(ResultElementType ==(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 941, __extension__ __PRETTY_FUNCTION__))
941 cast<PointerType>(getType()->getScalarType())->getElementType())(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 941, __extension__ __PRETTY_FUNCTION__))
;
942 return ResultElementType;
943 }
944
945 /// Returns the address space of this instruction's pointer type.
946 unsigned getAddressSpace() const {
947 // Note that this is always the same as the pointer operand's address space
948 // and that is cheaper to compute, so cheat here.
949 return getPointerAddressSpace();
950 }
951
952 /// Returns the type of the element that would be loaded with
953 /// a load instruction with the specified parameters.
954 ///
955 /// Null is returned if the indices are invalid for the specified
956 /// pointer type.
957 ///
958 static Type *getIndexedType(Type *Ty, ArrayRef<Value *> IdxList);
959 static Type *getIndexedType(Type *Ty, ArrayRef<Constant *> IdxList);
960 static Type *getIndexedType(Type *Ty, ArrayRef<uint64_t> IdxList);
961
962 inline op_iterator idx_begin() { return op_begin()+1; }
963 inline const_op_iterator idx_begin() const { return op_begin()+1; }
964 inline op_iterator idx_end() { return op_end(); }
965 inline const_op_iterator idx_end() const { return op_end(); }
966
967 inline iterator_range<op_iterator> indices() {
968 return make_range(idx_begin(), idx_end());
969 }
970
971 inline iterator_range<const_op_iterator> indices() const {
972 return make_range(idx_begin(), idx_end());
973 }
974
975 Value *getPointerOperand() {
976 return getOperand(0);
977 }
978 const Value *getPointerOperand() const {
979 return getOperand(0);
980 }
981 static unsigned getPointerOperandIndex() {
982 return 0U; // get index for modifying correct operand.
983 }
984
985 /// Method to return the pointer operand as a
986 /// PointerType.
987 Type *getPointerOperandType() const {
988 return getPointerOperand()->getType();
989 }
990
991 /// Returns the address space of the pointer operand.
992 unsigned getPointerAddressSpace() const {
993 return getPointerOperandType()->getPointerAddressSpace();
994 }
995
996 /// Returns the pointer type returned by the GEP
997 /// instruction, which may be a vector of pointers.
998 static Type *getGEPReturnType(Value *Ptr, ArrayRef<Value *> IdxList) {
999 return getGEPReturnType(
1000 cast<PointerType>(Ptr->getType()->getScalarType())->getElementType(),
1001 Ptr, IdxList);
1002 }
1003 static Type *getGEPReturnType(Type *ElTy, Value *Ptr,
1004 ArrayRef<Value *> IdxList) {
1005 Type *PtrTy = PointerType::get(checkGEPType(getIndexedType(ElTy, IdxList)),
1006 Ptr->getType()->getPointerAddressSpace());
1007 // Vector GEP
1008 if (Ptr->getType()->isVectorTy()) {
1009 unsigned NumElem = Ptr->getType()->getVectorNumElements();
1010 return VectorType::get(PtrTy, NumElem);
1011 }
1012 for (Value *Index : IdxList)
1013 if (Index->getType()->isVectorTy()) {
1014 unsigned NumElem = Index->getType()->getVectorNumElements();
1015 return VectorType::get(PtrTy, NumElem);
1016 }
1017 // Scalar GEP
1018 return PtrTy;
1019 }
1020
1021 unsigned getNumIndices() const { // Note: always non-negative
1022 return getNumOperands() - 1;
1023 }
1024
1025 bool hasIndices() const {
1026 return getNumOperands() > 1;
1027 }
1028
1029 /// Return true if all of the indices of this GEP are
1030 /// zeros. If so, the result pointer and the first operand have the same
1031 /// value, just potentially different types.
1032 bool hasAllZeroIndices() const;
1033
1034 /// Return true if all of the indices of this GEP are
1035 /// constant integers. If so, the result pointer and the first operand have
1036 /// a constant offset between them.
1037 bool hasAllConstantIndices() const;
1038
1039 /// Set or clear the inbounds flag on this GEP instruction.
1040 /// See LangRef.html for the meaning of inbounds on a getelementptr.
1041 void setIsInBounds(bool b = true);
1042
1043 /// Determine whether the GEP has the inbounds flag.
1044 bool isInBounds() const;
1045
1046 /// Accumulate the constant address offset of this GEP if possible.
1047 ///
1048 /// This routine accepts an APInt into which it will accumulate the constant
1049 /// offset of this GEP if the GEP is in fact constant. If the GEP is not
1050 /// all-constant, it returns false and the value of the offset APInt is
1051 /// undefined (it is *not* preserved!). The APInt passed into this routine
1052 /// must be at least as wide as the IntPtr type for the address space of
1053 /// the base GEP pointer.
1054 bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const;
1055
1056 // Methods for support type inquiry through isa, cast, and dyn_cast:
1057 static bool classof(const Instruction *I) {
1058 return (I->getOpcode() == Instruction::GetElementPtr);
1059 }
1060 static bool classof(const Value *V) {
1061 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1062 }
1063};
1064
1065template <>
1066struct OperandTraits<GetElementPtrInst> :
1067 public VariadicOperandTraits<GetElementPtrInst, 1> {
1068};
1069
1070GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1071 ArrayRef<Value *> IdxList, unsigned Values,
1072 const Twine &NameStr,
1073 Instruction *InsertBefore)
1074 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1075 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1076 Values, InsertBefore),
1077 SourceElementType(PointeeType),
1078 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1079 assert(ResultElementType ==(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1080, __extension__ __PRETTY_FUNCTION__))
1080 cast<PointerType>(getType()->getScalarType())->getElementType())(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1080, __extension__ __PRETTY_FUNCTION__))
;
1081 init(Ptr, IdxList, NameStr);
1082}
1083
1084GetElementPtrInst::GetElementPtrInst(Type *PointeeType, Value *Ptr,
1085 ArrayRef<Value *> IdxList, unsigned Values,
1086 const Twine &NameStr,
1087 BasicBlock *InsertAtEnd)
1088 : Instruction(getGEPReturnType(PointeeType, Ptr, IdxList), GetElementPtr,
1089 OperandTraits<GetElementPtrInst>::op_end(this) - Values,
1090 Values, InsertAtEnd),
1091 SourceElementType(PointeeType),
1092 ResultElementType(getIndexedType(PointeeType, IdxList)) {
1093 assert(ResultElementType ==(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1094, __extension__ __PRETTY_FUNCTION__))
1094 cast<PointerType>(getType()->getScalarType())->getElementType())(static_cast <bool> (ResultElementType == cast<PointerType
>(getType()->getScalarType())->getElementType()) ? void
(0) : __assert_fail ("ResultElementType == cast<PointerType>(getType()->getScalarType())->getElementType()"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1094, __extension__ __PRETTY_FUNCTION__))
;
1095 init(Ptr, IdxList, NameStr);
1096}
1097
1098DEFINE_TRANSPARENT_OPERAND_ACCESSORS(GetElementPtrInst, Value)GetElementPtrInst::op_iterator GetElementPtrInst::op_begin() {
return OperandTraits<GetElementPtrInst>::op_begin(this
); } GetElementPtrInst::const_op_iterator GetElementPtrInst::
op_begin() const { return OperandTraits<GetElementPtrInst>
::op_begin(const_cast<GetElementPtrInst*>(this)); } GetElementPtrInst
::op_iterator GetElementPtrInst::op_end() { return OperandTraits
<GetElementPtrInst>::op_end(this); } GetElementPtrInst::
const_op_iterator GetElementPtrInst::op_end() const { return OperandTraits
<GetElementPtrInst>::op_end(const_cast<GetElementPtrInst
*>(this)); } Value *GetElementPtrInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<GetElementPtrInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<GetElementPtrInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1098, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<GetElementPtrInst>::op_begin
(const_cast<GetElementPtrInst*>(this))[i_nocapture].get
()); } void GetElementPtrInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<GetElementPtrInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<GetElementPtrInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1098, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
GetElementPtrInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned GetElementPtrInst::getNumOperands() const { return
OperandTraits<GetElementPtrInst>::operands(this); } template
<int Idx_nocapture> Use &GetElementPtrInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &GetElementPtrInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
1099
1100//===----------------------------------------------------------------------===//
1101// ICmpInst Class
1102//===----------------------------------------------------------------------===//
1103
1104/// This instruction compares its operands according to the predicate given
1105/// to the constructor. It only operates on integers or pointers. The operands
1106/// must be identical types.
1107/// Represent an integer comparison operator.
1108class ICmpInst: public CmpInst {
1109 void AssertOK() {
1110 assert(isIntPredicate() &&(static_cast <bool> (isIntPredicate() && "Invalid ICmp predicate value"
) ? void (0) : __assert_fail ("isIntPredicate() && \"Invalid ICmp predicate value\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1111, __extension__ __PRETTY_FUNCTION__))
1111 "Invalid ICmp predicate value")(static_cast <bool> (isIntPredicate() && "Invalid ICmp predicate value"
) ? void (0) : __assert_fail ("isIntPredicate() && \"Invalid ICmp predicate value\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1111, __extension__ __PRETTY_FUNCTION__))
;
1112 assert(getOperand(0)->getType() == getOperand(1)->getType() &&(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to ICmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to ICmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1113, __extension__ __PRETTY_FUNCTION__))
1113 "Both operands to ICmp instruction are not of the same type!")(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to ICmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to ICmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1113, __extension__ __PRETTY_FUNCTION__))
;
1114 // Check that the operands are the right type
1115 assert((getOperand(0)->getType()->isIntOrIntVectorTy() ||(static_cast <bool> ((getOperand(0)->getType()->isIntOrIntVectorTy
() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
"Invalid operand types for ICmp instruction") ? void (0) : __assert_fail
("(getOperand(0)->getType()->isIntOrIntVectorTy() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) && \"Invalid operand types for ICmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1117, __extension__ __PRETTY_FUNCTION__))
1116 getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&(static_cast <bool> ((getOperand(0)->getType()->isIntOrIntVectorTy
() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
"Invalid operand types for ICmp instruction") ? void (0) : __assert_fail
("(getOperand(0)->getType()->isIntOrIntVectorTy() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) && \"Invalid operand types for ICmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1117, __extension__ __PRETTY_FUNCTION__))
1117 "Invalid operand types for ICmp instruction")(static_cast <bool> ((getOperand(0)->getType()->isIntOrIntVectorTy
() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) &&
"Invalid operand types for ICmp instruction") ? void (0) : __assert_fail
("(getOperand(0)->getType()->isIntOrIntVectorTy() || getOperand(0)->getType()->isPtrOrPtrVectorTy()) && \"Invalid operand types for ICmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1117, __extension__ __PRETTY_FUNCTION__))
;
1118 }
1119
1120protected:
1121 // Note: Instruction needs to be a friend here to call cloneImpl.
1122 friend class Instruction;
1123
1124 /// Clone an identical ICmpInst
1125 ICmpInst *cloneImpl() const;
1126
1127public:
1128 /// Constructor with insert-before-instruction semantics.
1129 ICmpInst(
1130 Instruction *InsertBefore, ///< Where to insert
1131 Predicate pred, ///< The predicate to use for the comparison
1132 Value *LHS, ///< The left-hand-side of the expression
1133 Value *RHS, ///< The right-hand-side of the expression
1134 const Twine &NameStr = "" ///< Name of the instruction
1135 ) : CmpInst(makeCmpResultType(LHS->getType()),
1136 Instruction::ICmp, pred, LHS, RHS, NameStr,
1137 InsertBefore) {
1138#ifndef NDEBUG
1139 AssertOK();
1140#endif
1141 }
1142
1143 /// Constructor with insert-at-end semantics.
1144 ICmpInst(
1145 BasicBlock &InsertAtEnd, ///< Block to insert into.
1146 Predicate pred, ///< The predicate to use for the comparison
1147 Value *LHS, ///< The left-hand-side of the expression
1148 Value *RHS, ///< The right-hand-side of the expression
1149 const Twine &NameStr = "" ///< Name of the instruction
1150 ) : CmpInst(makeCmpResultType(LHS->getType()),
1151 Instruction::ICmp, pred, LHS, RHS, NameStr,
1152 &InsertAtEnd) {
1153#ifndef NDEBUG
1154 AssertOK();
1155#endif
1156 }
1157
1158 /// Constructor with no-insertion semantics
1159 ICmpInst(
1160 Predicate pred, ///< The predicate to use for the comparison
1161 Value *LHS, ///< The left-hand-side of the expression
1162 Value *RHS, ///< The right-hand-side of the expression
1163 const Twine &NameStr = "" ///< Name of the instruction
1164 ) : CmpInst(makeCmpResultType(LHS->getType()),
1165 Instruction::ICmp, pred, LHS, RHS, NameStr) {
1166#ifndef NDEBUG
1167 AssertOK();
1168#endif
1169 }
1170
1171 /// For example, EQ->EQ, SLE->SLE, UGT->SGT, etc.
1172 /// @returns the predicate that would be the result if the operand were
1173 /// regarded as signed.
1174 /// Return the signed version of the predicate
1175 Predicate getSignedPredicate() const {
1176 return getSignedPredicate(getPredicate());
1177 }
1178
1179 /// This is a static version that you can use without an instruction.
1180 /// Return the signed version of the predicate.
1181 static Predicate getSignedPredicate(Predicate pred);
1182
1183 /// For example, EQ->EQ, SLE->ULE, UGT->UGT, etc.
1184 /// @returns the predicate that would be the result if the operand were
1185 /// regarded as unsigned.
1186 /// Return the unsigned version of the predicate
1187 Predicate getUnsignedPredicate() const {
1188 return getUnsignedPredicate(getPredicate());
1189 }
1190
1191 /// This is a static version that you can use without an instruction.
1192 /// Return the unsigned version of the predicate.
1193 static Predicate getUnsignedPredicate(Predicate pred);
1194
1195 /// Return true if this predicate is either EQ or NE. This also
1196 /// tests for commutativity.
1197 static bool isEquality(Predicate P) {
1198 return P == ICMP_EQ || P == ICMP_NE;
1199 }
1200
1201 /// Return true if this predicate is either EQ or NE. This also
1202 /// tests for commutativity.
1203 bool isEquality() const {
1204 return isEquality(getPredicate());
1205 }
1206
1207 /// @returns true if the predicate of this ICmpInst is commutative
1208 /// Determine if this relation is commutative.
1209 bool isCommutative() const { return isEquality(); }
1210
1211 /// Return true if the predicate is relational (not EQ or NE).
1212 ///
1213 bool isRelational() const {
1214 return !isEquality();
1215 }
1216
1217 /// Return true if the predicate is relational (not EQ or NE).
1218 ///
1219 static bool isRelational(Predicate P) {
1220 return !isEquality(P);
1221 }
1222
1223 /// Exchange the two operands to this instruction in such a way that it does
1224 /// not modify the semantics of the instruction. The predicate value may be
1225 /// changed to retain the same result if the predicate is order dependent
1226 /// (e.g. ult).
1227 /// Swap operands and adjust predicate.
1228 void swapOperands() {
1229 setPredicate(getSwappedPredicate());
1230 Op<0>().swap(Op<1>());
1231 }
1232
1233 // Methods for support type inquiry through isa, cast, and dyn_cast:
1234 static bool classof(const Instruction *I) {
1235 return I->getOpcode() == Instruction::ICmp;
1236 }
1237 static bool classof(const Value *V) {
1238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
29
Calling 'isa'
38
Returning from 'isa'
39
Assuming the condition is false
1239 }
1240};
1241
1242//===----------------------------------------------------------------------===//
1243// FCmpInst Class
1244//===----------------------------------------------------------------------===//
1245
1246/// This instruction compares its operands according to the predicate given
1247/// to the constructor. It only operates on floating point values or packed
1248/// vectors of floating point values. The operands must be identical types.
1249/// Represents a floating point comparison operator.
1250class FCmpInst: public CmpInst {
1251 void AssertOK() {
1252 assert(isFPPredicate() && "Invalid FCmp predicate value")(static_cast <bool> (isFPPredicate() && "Invalid FCmp predicate value"
) ? void (0) : __assert_fail ("isFPPredicate() && \"Invalid FCmp predicate value\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1252, __extension__ __PRETTY_FUNCTION__))
;
1253 assert(getOperand(0)->getType() == getOperand(1)->getType() &&(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to FCmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to FCmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1254, __extension__ __PRETTY_FUNCTION__))
1254 "Both operands to FCmp instruction are not of the same type!")(static_cast <bool> (getOperand(0)->getType() == getOperand
(1)->getType() && "Both operands to FCmp instruction are not of the same type!"
) ? void (0) : __assert_fail ("getOperand(0)->getType() == getOperand(1)->getType() && \"Both operands to FCmp instruction are not of the same type!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1254, __extension__ __PRETTY_FUNCTION__))
;
1255 // Check that the operands are the right type
1256 assert(getOperand(0)->getType()->isFPOrFPVectorTy() &&(static_cast <bool> (getOperand(0)->getType()->isFPOrFPVectorTy
() && "Invalid operand types for FCmp instruction") ?
void (0) : __assert_fail ("getOperand(0)->getType()->isFPOrFPVectorTy() && \"Invalid operand types for FCmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1257, __extension__ __PRETTY_FUNCTION__))
1257 "Invalid operand types for FCmp instruction")(static_cast <bool> (getOperand(0)->getType()->isFPOrFPVectorTy
() && "Invalid operand types for FCmp instruction") ?
void (0) : __assert_fail ("getOperand(0)->getType()->isFPOrFPVectorTy() && \"Invalid operand types for FCmp instruction\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1257, __extension__ __PRETTY_FUNCTION__))
;
1258 }
1259
1260protected:
1261 // Note: Instruction needs to be a friend here to call cloneImpl.
1262 friend class Instruction;
1263
1264 /// Clone an identical FCmpInst
1265 FCmpInst *cloneImpl() const;
1266
1267public:
1268 /// Constructor with insert-before-instruction semantics.
1269 FCmpInst(
1270 Instruction *InsertBefore, ///< Where to insert
1271 Predicate pred, ///< The predicate to use for the comparison
1272 Value *LHS, ///< The left-hand-side of the expression
1273 Value *RHS, ///< The right-hand-side of the expression
1274 const Twine &NameStr = "" ///< Name of the instruction
1275 ) : CmpInst(makeCmpResultType(LHS->getType()),
1276 Instruction::FCmp, pred, LHS, RHS, NameStr,
1277 InsertBefore) {
1278 AssertOK();
1279 }
1280
1281 /// Constructor with insert-at-end semantics.
1282 FCmpInst(
1283 BasicBlock &InsertAtEnd, ///< Block to insert into.
1284 Predicate pred, ///< The predicate to use for the comparison
1285 Value *LHS, ///< The left-hand-side of the expression
1286 Value *RHS, ///< The right-hand-side of the expression
1287 const Twine &NameStr = "" ///< Name of the instruction
1288 ) : CmpInst(makeCmpResultType(LHS->getType()),
1289 Instruction::FCmp, pred, LHS, RHS, NameStr,
1290 &InsertAtEnd) {
1291 AssertOK();
1292 }
1293
1294 /// Constructor with no-insertion semantics
1295 FCmpInst(
1296 Predicate pred, ///< The predicate to use for the comparison
1297 Value *LHS, ///< The left-hand-side of the expression
1298 Value *RHS, ///< The right-hand-side of the expression
1299 const Twine &NameStr = "" ///< Name of the instruction
1300 ) : CmpInst(makeCmpResultType(LHS->getType()),
1301 Instruction::FCmp, pred, LHS, RHS, NameStr) {
1302 AssertOK();
1303 }
1304
1305 /// @returns true if the predicate of this instruction is EQ or NE.
1306 /// Determine if this is an equality predicate.
1307 static bool isEquality(Predicate Pred) {
1308 return Pred == FCMP_OEQ || Pred == FCMP_ONE || Pred == FCMP_UEQ ||
1309 Pred == FCMP_UNE;
1310 }
1311
1312 /// @returns true if the predicate of this instruction is EQ or NE.
1313 /// Determine if this is an equality predicate.
1314 bool isEquality() const { return isEquality(getPredicate()); }
1315
1316 /// @returns true if the predicate of this instruction is commutative.
1317 /// Determine if this is a commutative predicate.
1318 bool isCommutative() const {
1319 return isEquality() ||
1320 getPredicate() == FCMP_FALSE ||
1321 getPredicate() == FCMP_TRUE ||
1322 getPredicate() == FCMP_ORD ||
1323 getPredicate() == FCMP_UNO;
1324 }
1325
1326 /// @returns true if the predicate is relational (not EQ or NE).
1327 /// Determine if this a relational predicate.
1328 bool isRelational() const { return !isEquality(); }
1329
1330 /// Exchange the two operands to this instruction in such a way that it does
1331 /// not modify the semantics of the instruction. The predicate value may be
1332 /// changed to retain the same result if the predicate is order dependent
1333 /// (e.g. ult).
1334 /// Swap operands and adjust predicate.
1335 void swapOperands() {
1336 setPredicate(getSwappedPredicate());
1337 Op<0>().swap(Op<1>());
1338 }
1339
1340 /// Methods for support type inquiry through isa, cast, and dyn_cast:
1341 static bool classof(const Instruction *I) {
1342 return I->getOpcode() == Instruction::FCmp;
1343 }
1344 static bool classof(const Value *V) {
1345 return isa<Instruction>(V) && classof(cast<Instruction>(V));
1346 }
1347};
1348
1349class CallInst;
1350class InvokeInst;
1351
1352template <class T> struct CallBaseParent { using type = Instruction; };
1353
1354template <> struct CallBaseParent<InvokeInst> { using type = TerminatorInst; };
1355
1356//===----------------------------------------------------------------------===//
1357/// Base class for all callable instructions (InvokeInst and CallInst)
1358/// Holds everything related to calling a function, abstracting from the base
1359/// type @p BaseInstTy and the concrete instruction @p InstTy
1360///
1361template <class InstTy>
1362class CallBase : public CallBaseParent<InstTy>::type,
1363 public OperandBundleUser<InstTy, User::op_iterator> {
1364protected:
1365 AttributeList Attrs; ///< parameter attributes for callable
1366 FunctionType *FTy;
1367 using BaseInstTy = typename CallBaseParent<InstTy>::type;
1368
1369 template <class... ArgsTy>
1370 CallBase(AttributeList const &A, FunctionType *FT, ArgsTy &&... Args)
1371 : BaseInstTy(std::forward<ArgsTy>(Args)...), Attrs(A), FTy(FT) {}
1372 bool hasDescriptor() const { return Value::HasDescriptor; }
1373
1374 using BaseInstTy::BaseInstTy;
1375
1376 using OperandBundleUser<InstTy,
1377 User::op_iterator>::isFnAttrDisallowedByOpBundle;
1378 using OperandBundleUser<InstTy, User::op_iterator>::getNumTotalBundleOperands;
1379 using OperandBundleUser<InstTy, User::op_iterator>::bundleOperandHasAttr;
1380 using Instruction::getSubclassDataFromInstruction;
1381 using Instruction::setInstructionSubclassData;
1382
1383public:
1384 using Instruction::getContext;
1385 using OperandBundleUser<InstTy, User::op_iterator>::hasOperandBundles;
1386 using OperandBundleUser<InstTy,
1387 User::op_iterator>::getBundleOperandsStartIndex;
1388
1389 static bool classof(const Instruction *I) {
1390 llvm_unreachable(::llvm::llvm_unreachable_internal("CallBase is not meant to be used as part of the classof hierarchy"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1391)
1391 "CallBase is not meant to be used as part of the classof hierarchy")::llvm::llvm_unreachable_internal("CallBase is not meant to be used as part of the classof hierarchy"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1391)
;
1392 }
1393
1394public:
1395 /// Return the parameter attributes for this call.
1396 ///
1397 AttributeList getAttributes() const { return Attrs; }
1398
1399 /// Set the parameter attributes for this call.
1400 ///
1401 void setAttributes(AttributeList A) { Attrs = A; }
1402
1403 FunctionType *getFunctionType() const { return FTy; }
1404
1405 void mutateFunctionType(FunctionType *FTy) {
1406 Value::mutateType(FTy->getReturnType());
1407 this->FTy = FTy;
1408 }
1409
1410 /// Return the number of call arguments.
1411 ///
1412 unsigned getNumArgOperands() const {
1413 return getNumOperands() - getNumTotalBundleOperands() - InstTy::ArgOffset;
1414 }
1415
1416 /// getArgOperand/setArgOperand - Return/set the i-th call argument.
1417 ///
1418 Value *getArgOperand(unsigned i) const {
1419 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1419, __extension__ __PRETTY_FUNCTION__))
;
1420 return getOperand(i);
1421 }
1422 void setArgOperand(unsigned i, Value *v) {
1423 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1423, __extension__ __PRETTY_FUNCTION__))
;
1424 setOperand(i, v);
1425 }
1426
1427 /// Return the iterator pointing to the beginning of the argument list.
1428 User::op_iterator arg_begin() { return op_begin(); }
1429
1430 /// Return the iterator pointing to the end of the argument list.
1431 User::op_iterator arg_end() {
1432 // [ call args ], [ operand bundles ], callee
1433 return op_end() - getNumTotalBundleOperands() - InstTy::ArgOffset;
1434 }
1435
1436 /// Iteration adapter for range-for loops.
1437 iterator_range<User::op_iterator> arg_operands() {
1438 return make_range(arg_begin(), arg_end());
1439 }
1440
1441 /// Return the iterator pointing to the beginning of the argument list.
1442 User::const_op_iterator arg_begin() const { return op_begin(); }
1443
1444 /// Return the iterator pointing to the end of the argument list.
1445 User::const_op_iterator arg_end() const {
1446 // [ call args ], [ operand bundles ], callee
1447 return op_end() - getNumTotalBundleOperands() - InstTy::ArgOffset;
1448 }
1449
1450 /// Iteration adapter for range-for loops.
1451 iterator_range<User::const_op_iterator> arg_operands() const {
1452 return make_range(arg_begin(), arg_end());
1453 }
1454
1455 /// Wrappers for getting the \c Use of a call argument.
1456 const Use &getArgOperandUse(unsigned i) const {
1457 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1457, __extension__ __PRETTY_FUNCTION__))
;
1458 return User::getOperandUse(i);
1459 }
1460 Use &getArgOperandUse(unsigned i) {
1461 assert(i < getNumArgOperands() && "Out of bounds!")(static_cast <bool> (i < getNumArgOperands() &&
"Out of bounds!") ? void (0) : __assert_fail ("i < getNumArgOperands() && \"Out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1461, __extension__ __PRETTY_FUNCTION__))
;
1462 return User::getOperandUse(i);
1463 }
1464
1465 /// If one of the arguments has the 'returned' attribute, return its
1466 /// operand value. Otherwise, return nullptr.
1467 Value *getReturnedArgOperand() const {
1468 unsigned Index;
1469
1470 if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index) && Index)
1471 return getArgOperand(Index - AttributeList::FirstArgIndex);
1472 if (const Function *F = getCalledFunction())
1473 if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index) &&
1474 Index)
1475 return getArgOperand(Index - AttributeList::FirstArgIndex);
1476
1477 return nullptr;
1478 }
1479
1480 User::op_iterator op_begin() {
1481 return OperandTraits<CallBase>::op_begin(this);
1482 }
1483
1484 User::const_op_iterator op_begin() const {
1485 return OperandTraits<CallBase>::op_begin(const_cast<CallBase *>(this));
1486 }
1487
1488 User::op_iterator op_end() { return OperandTraits<CallBase>::op_end(this); }
1489
1490 User::const_op_iterator op_end() const {
1491 return OperandTraits<CallBase>::op_end(const_cast<CallBase *>(this));
1492 }
1493
1494 Value *getOperand(unsigned i_nocapture) const {
1495 assert(i_nocapture < OperandTraits<CallBase>::operands(this) &&(static_cast <bool> (i_nocapture < OperandTraits<
CallBase>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CallBase>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1496, __extension__ __PRETTY_FUNCTION__))
1496 "getOperand() out of range!")(static_cast <bool> (i_nocapture < OperandTraits<
CallBase>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CallBase>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1496, __extension__ __PRETTY_FUNCTION__))
;
1497 return cast_or_null<Value>(OperandTraits<CallBase>::op_begin(
1498 const_cast<CallBase *>(this))[i_nocapture]
1499 .get());
1500 }
1501
1502 void setOperand(unsigned i_nocapture, Value *Val_nocapture) {
1503 assert(i_nocapture < OperandTraits<CallBase>::operands(this) &&(static_cast <bool> (i_nocapture < OperandTraits<
CallBase>::operands(this) && "setOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CallBase>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1504, __extension__ __PRETTY_FUNCTION__))
1504 "setOperand() out of range!")(static_cast <bool> (i_nocapture < OperandTraits<
CallBase>::operands(this) && "setOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CallBase>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1504, __extension__ __PRETTY_FUNCTION__))
;
1505 OperandTraits<CallBase>::op_begin(this)[i_nocapture] = Val_nocapture;
1506 }
1507
1508 unsigned getNumOperands() const {
1509 return OperandTraits<CallBase>::operands(this);
1510 }
1511 template <int Idx_nocapture> Use &Op() {
1512 return User::OpFrom<Idx_nocapture>(this);
1513 }
1514 template <int Idx_nocapture> const Use &Op() const {
1515 return User::OpFrom<Idx_nocapture>(this);
1516 }
1517
1518 /// Return the function called, or null if this is an
1519 /// indirect function invocation.
1520 ///
1521 Function *getCalledFunction() const {
1522 return dyn_cast<Function>(Op<-InstTy::ArgOffset>());
1523 }
1524
1525 /// Determine whether this call has the given attribute.
1526 bool hasFnAttr(Attribute::AttrKind Kind) const {
1527 assert(Kind != Attribute::NoBuiltin &&(static_cast <bool> (Kind != Attribute::NoBuiltin &&
"Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin"
) ? void (0) : __assert_fail ("Kind != Attribute::NoBuiltin && \"Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1528, __extension__ __PRETTY_FUNCTION__))
1528 "Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin")(static_cast <bool> (Kind != Attribute::NoBuiltin &&
"Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin"
) ? void (0) : __assert_fail ("Kind != Attribute::NoBuiltin && \"Use CallBase::isNoBuiltin() to check for Attribute::NoBuiltin\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1528, __extension__ __PRETTY_FUNCTION__))
;
1529 return hasFnAttrImpl(Kind);
1530 }
1531
1532 /// Determine whether this call has the given attribute.
1533 bool hasFnAttr(StringRef Kind) const { return hasFnAttrImpl(Kind); }
1534
1535 /// getCallingConv/setCallingConv - Get or set the calling convention of this
1536 /// function call.
1537 CallingConv::ID getCallingConv() const {
1538 return static_cast<CallingConv::ID>(getSubclassDataFromInstruction() >> 2);
1539 }
1540 void setCallingConv(CallingConv::ID CC) {
1541 auto ID = static_cast<unsigned>(CC);
1542 assert(!(ID & ~CallingConv::MaxID) && "Unsupported calling convention")(static_cast <bool> (!(ID & ~CallingConv::MaxID) &&
"Unsupported calling convention") ? void (0) : __assert_fail
("!(ID & ~CallingConv::MaxID) && \"Unsupported calling convention\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1542, __extension__ __PRETTY_FUNCTION__))
;
1543 setInstructionSubclassData((getSubclassDataFromInstruction() & 3) |
1544 (ID << 2));
1545 }
1546
1547
1548 /// adds the attribute to the list of attributes.
1549 void addAttribute(unsigned i, Attribute::AttrKind Kind) {
1550 AttributeList PAL = getAttributes();
1551 PAL = PAL.addAttribute(getContext(), i, Kind);
1552 setAttributes(PAL);
1553 }
1554
1555 /// adds the attribute to the list of attributes.
1556 void addAttribute(unsigned i, Attribute Attr) {
1557 AttributeList PAL = getAttributes();
1558 PAL = PAL.addAttribute(getContext(), i, Attr);
1559 setAttributes(PAL);
1560 }
1561
1562 /// Adds the attribute to the indicated argument
1563 void addParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1564 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1564, __extension__ __PRETTY_FUNCTION__))
;
1565 AttributeList PAL = getAttributes();
1566 PAL = PAL.addParamAttribute(getContext(), ArgNo, Kind);
1567 setAttributes(PAL);
1568 }
1569
1570 /// Adds the attribute to the indicated argument
1571 void addParamAttr(unsigned ArgNo, Attribute Attr) {
1572 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1572, __extension__ __PRETTY_FUNCTION__))
;
1573 AttributeList PAL = getAttributes();
1574 PAL = PAL.addParamAttribute(getContext(), ArgNo, Attr);
1575 setAttributes(PAL);
1576 }
1577
1578 /// removes the attribute from the list of attributes.
1579 void removeAttribute(unsigned i, Attribute::AttrKind Kind) {
1580 AttributeList PAL = getAttributes();
1581 PAL = PAL.removeAttribute(getContext(), i, Kind);
1582 setAttributes(PAL);
1583 }
1584
1585 /// removes the attribute from the list of attributes.
1586 void removeAttribute(unsigned i, StringRef Kind) {
1587 AttributeList PAL = getAttributes();
1588 PAL = PAL.removeAttribute(getContext(), i, Kind);
1589 setAttributes(PAL);
1590 }
1591
1592 /// Removes the attribute from the given argument
1593 void removeParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) {
1594 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1594, __extension__ __PRETTY_FUNCTION__))
;
1595 AttributeList PAL = getAttributes();
1596 PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
1597 setAttributes(PAL);
1598 }
1599
1600 /// Removes the attribute from the given argument
1601 void removeParamAttr(unsigned ArgNo, StringRef Kind) {
1602 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1602, __extension__ __PRETTY_FUNCTION__))
;
1603 AttributeList PAL = getAttributes();
1604 PAL = PAL.removeParamAttribute(getContext(), ArgNo, Kind);
1605 setAttributes(PAL);
1606 }
1607
1608 /// adds the dereferenceable attribute to the list of attributes.
1609 void addDereferenceableAttr(unsigned i, uint64_t Bytes) {
1610 AttributeList PAL = getAttributes();
1611 PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
1612 setAttributes(PAL);
1613 }
1614
1615 /// adds the dereferenceable_or_null attribute to the list of
1616 /// attributes.
1617 void addDereferenceableOrNullAttr(unsigned i, uint64_t Bytes) {
1618 AttributeList PAL = getAttributes();
1619 PAL = PAL.addDereferenceableOrNullAttr(getContext(), i, Bytes);
1620 setAttributes(PAL);
1621 }
1622
1623 /// Determine whether the return value has the given attribute.
1624 bool hasRetAttr(Attribute::AttrKind Kind) const {
1625 if (Attrs.hasAttribute(AttributeList::ReturnIndex, Kind))
1626 return true;
1627
1628 // Look at the callee, if available.
1629 if (const Function *F = getCalledFunction())
1630 return F->getAttributes().hasAttribute(AttributeList::ReturnIndex, Kind);
1631 return false;
1632 }
1633
1634 /// Determine whether the argument or parameter has the given attribute.
1635 bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1636 assert(ArgNo < getNumArgOperands() && "Param index out of bounds!")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Param index out of bounds!") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Param index out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1636, __extension__ __PRETTY_FUNCTION__))
;
1637
1638 if (Attrs.hasParamAttribute(ArgNo, Kind))
1639 return true;
1640 if (const Function *F = getCalledFunction())
1641 return F->getAttributes().hasParamAttribute(ArgNo, Kind);
1642 return false;
1643 }
1644
1645 /// Get the attribute of a given kind at a position.
1646 Attribute getAttribute(unsigned i, Attribute::AttrKind Kind) const {
1647 return getAttributes().getAttribute(i, Kind);
1648 }
1649
1650 /// Get the attribute of a given kind at a position.
1651 Attribute getAttribute(unsigned i, StringRef Kind) const {
1652 return getAttributes().getAttribute(i, Kind);
1653 }
1654
1655 /// Get the attribute of a given kind from a given arg
1656 Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
1657 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1657, __extension__ __PRETTY_FUNCTION__))
;
1658 return getAttributes().getParamAttr(ArgNo, Kind);
1659 }
1660
1661 /// Get the attribute of a given kind from a given arg
1662 Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
1663 assert(ArgNo < getNumArgOperands() && "Out of bounds")(static_cast <bool> (ArgNo < getNumArgOperands() &&
"Out of bounds") ? void (0) : __assert_fail ("ArgNo < getNumArgOperands() && \"Out of bounds\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1663, __extension__ __PRETTY_FUNCTION__))
;
1664 return getAttributes().getParamAttr(ArgNo, Kind);
1665 }
1666 /// Return true if the data operand at index \p i has the attribute \p
1667 /// A.
1668 ///
1669 /// Data operands include call arguments and values used in operand bundles,
1670 /// but does not include the callee operand. This routine dispatches to the
1671 /// underlying AttributeList or the OperandBundleUser as appropriate.
1672 ///
1673 /// The index \p i is interpreted as
1674 ///
1675 /// \p i == Attribute::ReturnIndex -> the return value
1676 /// \p i in [1, arg_size + 1) -> argument number (\p i - 1)
1677 /// \p i in [arg_size + 1, data_operand_size + 1) -> bundle operand at index
1678 /// (\p i - 1) in the operand list.
1679 bool dataOperandHasImpliedAttr(unsigned i, Attribute::AttrKind Kind) const {
1680 // There are getNumOperands() - (InstTy::ArgOffset - 1) data operands.
1681 // The last operand is the callee.
1682 assert(i < (getNumOperands() - InstTy::ArgOffset + 1) &&(static_cast <bool> (i < (getNumOperands() - InstTy::
ArgOffset + 1) && "Data operand index out of bounds!"
) ? void (0) : __assert_fail ("i < (getNumOperands() - InstTy::ArgOffset + 1) && \"Data operand index out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1683, __extension__ __PRETTY_FUNCTION__))
1683 "Data operand index out of bounds!")(static_cast <bool> (i < (getNumOperands() - InstTy::
ArgOffset + 1) && "Data operand index out of bounds!"
) ? void (0) : __assert_fail ("i < (getNumOperands() - InstTy::ArgOffset + 1) && \"Data operand index out of bounds!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1683, __extension__ __PRETTY_FUNCTION__))
;
1684
1685 // The attribute A can either be directly specified, if the operand in
1686 // question is a call argument; or be indirectly implied by the kind of its
1687 // containing operand bundle, if the operand is a bundle operand.
1688
1689 if (i == AttributeList::ReturnIndex)
1690 return hasRetAttr(Kind);
1691
1692 // FIXME: Avoid these i - 1 calculations and update the API to use
1693 // zero-based indices.
1694 if (i < (getNumArgOperands() + 1))
1695 return paramHasAttr(i - 1, Kind);
1696
1697 assert(hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) &&(static_cast <bool> (hasOperandBundles() && i >=
(getBundleOperandsStartIndex() + 1) && "Must be either a call argument or an operand bundle!"
) ? void (0) : __assert_fail ("hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) && \"Must be either a call argument or an operand bundle!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1698, __extension__ __PRETTY_FUNCTION__))
1698 "Must be either a call argument or an operand bundle!")(static_cast <bool> (hasOperandBundles() && i >=
(getBundleOperandsStartIndex() + 1) && "Must be either a call argument or an operand bundle!"
) ? void (0) : __assert_fail ("hasOperandBundles() && i >= (getBundleOperandsStartIndex() + 1) && \"Must be either a call argument or an operand bundle!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1698, __extension__ __PRETTY_FUNCTION__))
;
1699 return bundleOperandHasAttr(i - 1, Kind);
1700 }
1701
1702 /// Extract the alignment of the return value.
1703 unsigned getRetAlignment() const { return Attrs.getRetAlignment(); }
1704
1705 /// Extract the alignment for a call or parameter (0=unknown).
1706 unsigned getParamAlignment(unsigned ArgNo) const {
1707 return Attrs.getParamAlignment(ArgNo);
1708 }
1709
1710 /// Extract the number of dereferenceable bytes for a call or
1711 /// parameter (0=unknown).
1712 uint64_t getDereferenceableBytes(unsigned i) const {
1713 return Attrs.getDereferenceableBytes(i);
1714 }
1715
1716 /// Extract the number of dereferenceable_or_null bytes for a call or
1717 /// parameter (0=unknown).
1718 uint64_t getDereferenceableOrNullBytes(unsigned i) const {
1719 return Attrs.getDereferenceableOrNullBytes(i);
1720 }
1721
1722 /// @brief Determine if the return value is marked with NoAlias attribute.
1723 bool returnDoesNotAlias() const {
1724 return Attrs.hasAttribute(AttributeList::ReturnIndex, Attribute::NoAlias);
1725 }
1726
1727 /// Return true if the call should not be treated as a call to a
1728 /// builtin.
1729 bool isNoBuiltin() const {
1730 return hasFnAttrImpl(Attribute::NoBuiltin) &&
1731 !hasFnAttrImpl(Attribute::Builtin);
1732 }
1733
1734 /// Determine if the call requires strict floating point semantics.
1735 bool isStrictFP() const { return hasFnAttr(Attribute::StrictFP); }
1736
1737 /// Return true if the call should not be inlined.
1738 bool isNoInline() const { return hasFnAttr(Attribute::NoInline); }
1739 void setIsNoInline() {
1740 addAttribute(AttributeList::FunctionIndex, Attribute::NoInline);
1741 }
1742 /// Determine if the call does not access memory.
1743 bool doesNotAccessMemory() const {
1744 return hasFnAttr(Attribute::ReadNone);
1745 }
1746 void setDoesNotAccessMemory() {
1747 addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
1748 }
1749
1750 /// Determine if the call does not access or only reads memory.
1751 bool onlyReadsMemory() const {
1752 return doesNotAccessMemory() || hasFnAttr(Attribute::ReadOnly);
1753 }
1754 void setOnlyReadsMemory() {
1755 addAttribute(AttributeList::FunctionIndex, Attribute::ReadOnly);
1756 }
1757
1758 /// Determine if the call does not access or only writes memory.
1759 bool doesNotReadMemory() const {
1760 return doesNotAccessMemory() || hasFnAttr(Attribute::WriteOnly);
1761 }
1762 void setDoesNotReadMemory() {
1763 addAttribute(AttributeList::FunctionIndex, Attribute::WriteOnly);
1764 }
1765
1766 /// @brief Determine if the call can access memmory only using pointers based
1767 /// on its arguments.
1768 bool onlyAccessesArgMemory() const {
1769 return hasFnAttr(Attribute::ArgMemOnly);
1770 }
1771 void setOnlyAccessesArgMemory() {
1772 addAttribute(AttributeList::FunctionIndex, Attribute::ArgMemOnly);
1773 }
1774
1775 /// @brief Determine if the function may only access memory that is
1776 /// inaccessible from the IR.
1777 bool onlyAccessesInaccessibleMemory() const {
1778 return hasFnAttr(Attribute::InaccessibleMemOnly);
1779 }
1780 void setOnlyAccessesInaccessibleMemory() {
1781 addAttribute(AttributeList::FunctionIndex, Attribute::InaccessibleMemOnly);
1782 }
1783
1784 /// @brief Determine if the function may only access memory that is
1785 /// either inaccessible from the IR or pointed to by its arguments.
1786 bool onlyAccessesInaccessibleMemOrArgMem() const {
1787 return hasFnAttr(Attribute::InaccessibleMemOrArgMemOnly);
1788 }
1789 void setOnlyAccessesInaccessibleMemOrArgMem() {
1790 addAttribute(AttributeList::FunctionIndex, Attribute::InaccessibleMemOrArgMemOnly);
1791 }
1792 /// Determine if the call cannot return.
1793 bool doesNotReturn() const { return hasFnAttr(Attribute::NoReturn); }
1794 void setDoesNotReturn() {
1795 addAttribute(AttributeList::FunctionIndex, Attribute::NoReturn);
1796 }
1797
1798 /// Determine if the call cannot unwind.
1799 bool doesNotThrow() const { return hasFnAttr(Attribute::NoUnwind); }
1800 void setDoesNotThrow() {
1801 addAttribute(AttributeList::FunctionIndex, Attribute::NoUnwind);
1802 }
1803
1804 /// Determine if the invoke cannot be duplicated.
1805 bool cannotDuplicate() const {return hasFnAttr(Attribute::NoDuplicate); }
1806 void setCannotDuplicate() {
1807 addAttribute(AttributeList::FunctionIndex, Attribute::NoDuplicate);
1808 }
1809
1810 /// Determine if the invoke is convergent
1811 bool isConvergent() const { return hasFnAttr(Attribute::Convergent); }
1812 void setConvergent() {
1813 addAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
1814 }
1815 void setNotConvergent() {
1816 removeAttribute(AttributeList::FunctionIndex, Attribute::Convergent);
1817 }
1818
1819 /// Determine if the call returns a structure through first
1820 /// pointer argument.
1821 bool hasStructRetAttr() const {
1822 if (getNumArgOperands() == 0)
1823 return false;
1824
1825 // Be friendly and also check the callee.
1826 return paramHasAttr(0, Attribute::StructRet);
1827 }
1828
1829 /// Determine if any call argument is an aggregate passed by value.
1830 bool hasByValArgument() const {
1831 return Attrs.hasAttrSomewhere(Attribute::ByVal);
1832 }
1833 /// Get a pointer to the function that is invoked by this
1834 /// instruction.
1835 const Value *getCalledValue() const { return Op<-InstTy::ArgOffset>(); }
1836 Value *getCalledValue() { return Op<-InstTy::ArgOffset>(); }
1837
1838 /// Set the function called.
1839 void setCalledFunction(Value* Fn) {
1840 setCalledFunction(
1841 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
1842 Fn);
1843 }
1844 void setCalledFunction(FunctionType *FTy, Value *Fn) {
1845 this->FTy = FTy;
1846 assert(FTy == cast<FunctionType>((static_cast <bool> (FTy == cast<FunctionType>( cast
<PointerType>(Fn->getType())->getElementType())) ?
void (0) : __assert_fail ("FTy == cast<FunctionType>( cast<PointerType>(Fn->getType())->getElementType())"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1847, __extension__ __PRETTY_FUNCTION__))
1847 cast<PointerType>(Fn->getType())->getElementType()))(static_cast <bool> (FTy == cast<FunctionType>( cast
<PointerType>(Fn->getType())->getElementType())) ?
void (0) : __assert_fail ("FTy == cast<FunctionType>( cast<PointerType>(Fn->getType())->getElementType())"
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 1847, __extension__ __PRETTY_FUNCTION__))
;
1848 Op<-InstTy::ArgOffset>() = Fn;
1849 }
1850
1851protected:
1852 template <typename AttrKind> bool hasFnAttrImpl(AttrKind Kind) const {
1853 if (Attrs.hasAttribute(AttributeList::FunctionIndex, Kind))
1854 return true;
1855
1856 // Operand bundles override attributes on the called function, but don't
1857 // override attributes directly present on the call instruction.
1858 if (isFnAttrDisallowedByOpBundle(Kind))
1859 return false;
1860
1861 if (const Function *F = getCalledFunction())
1862 return F->getAttributes().hasAttribute(AttributeList::FunctionIndex,
1863 Kind);
1864 return false;
1865 }
1866};
1867
1868//===----------------------------------------------------------------------===//
1869/// This class represents a function call, abstracting a target
1870/// machine's calling convention. This class uses low bit of the SubClassData
1871/// field to indicate whether or not this is a tail call. The rest of the bits
1872/// hold the calling convention of the call.
1873///
1874class CallInst : public CallBase<CallInst> {
1875 friend class OperandBundleUser<CallInst, User::op_iterator>;
1876
1877 CallInst(const CallInst &CI);
1878
1879 /// Construct a CallInst given a range of arguments.
1880 /// Construct a CallInst from a range of arguments
1881 inline CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1882 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1883 Instruction *InsertBefore);
1884
1885 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1886 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1887 Instruction *InsertBefore)
1888 : CallInst(cast<FunctionType>(
1889 cast<PointerType>(Func->getType())->getElementType()),
1890 Func, Args, Bundles, NameStr, InsertBefore) {}
1891
1892 inline CallInst(Value *Func, ArrayRef<Value *> Args, const Twine &NameStr,
1893 Instruction *InsertBefore)
1894 : CallInst(Func, Args, None, NameStr, InsertBefore) {}
1895
1896 /// Construct a CallInst given a range of arguments.
1897 /// Construct a CallInst from a range of arguments
1898 inline CallInst(Value *Func, ArrayRef<Value *> Args,
1899 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
1900 BasicBlock *InsertAtEnd);
1901
1902 explicit CallInst(Value *F, const Twine &NameStr, Instruction *InsertBefore);
1903
1904 CallInst(Value *F, const Twine &NameStr, BasicBlock *InsertAtEnd);
1905
1906 void init(Value *Func, ArrayRef<Value *> Args,
1907 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr) {
1908 init(cast<FunctionType>(
1909 cast<PointerType>(Func->getType())->getElementType()),
1910 Func, Args, Bundles, NameStr);
1911 }
1912 void init(FunctionType *FTy, Value *Func, ArrayRef<Value *> Args,
1913 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
1914 void init(Value *Func, const Twine &NameStr);
1915
1916protected:
1917 // Note: Instruction needs to be a friend here to call cloneImpl.
1918 friend class Instruction;
1919
1920 CallInst *cloneImpl() const;
1921
1922public:
1923 static constexpr int ArgOffset = 1;
1924
1925 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1926 ArrayRef<OperandBundleDef> Bundles = None,
1927 const Twine &NameStr = "",
1928 Instruction *InsertBefore = nullptr) {
1929 return Create(cast<FunctionType>(
1930 cast<PointerType>(Func->getType())->getElementType()),
1931 Func, Args, Bundles, NameStr, InsertBefore);
1932 }
1933
1934 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1935 const Twine &NameStr,
1936 Instruction *InsertBefore = nullptr) {
1937 return Create(cast<FunctionType>(
1938 cast<PointerType>(Func->getType())->getElementType()),
1939 Func, Args, None, NameStr, InsertBefore);
1940 }
1941
1942 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1943 const Twine &NameStr,
1944 Instruction *InsertBefore = nullptr) {
1945 return new (unsigned(Args.size() + 1))
1946 CallInst(Ty, Func, Args, None, NameStr, InsertBefore);
1947 }
1948
1949 static CallInst *Create(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
1950 ArrayRef<OperandBundleDef> Bundles = None,
1951 const Twine &NameStr = "",
1952 Instruction *InsertBefore = nullptr) {
1953 const unsigned TotalOps =
1954 unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1955 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1956
1957 return new (TotalOps, DescriptorBytes)
1958 CallInst(Ty, Func, Args, Bundles, NameStr, InsertBefore);
1959 }
1960
1961 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1962 ArrayRef<OperandBundleDef> Bundles,
1963 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1964 const unsigned TotalOps =
1965 unsigned(Args.size()) + CountBundleInputs(Bundles) + 1;
1966 const unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
1967
1968 return new (TotalOps, DescriptorBytes)
1969 CallInst(Func, Args, Bundles, NameStr, InsertAtEnd);
1970 }
1971
1972 static CallInst *Create(Value *Func, ArrayRef<Value *> Args,
1973 const Twine &NameStr, BasicBlock *InsertAtEnd) {
1974 return new (unsigned(Args.size() + 1))
1975 CallInst(Func, Args, None, NameStr, InsertAtEnd);
1976 }
1977
1978 static CallInst *Create(Value *F, const Twine &NameStr = "",
1979 Instruction *InsertBefore = nullptr) {
1980 return new (1) CallInst(F, NameStr, InsertBefore);
1981 }
1982
1983 static CallInst *Create(Value *F, const Twine &NameStr,
1984 BasicBlock *InsertAtEnd) {
1985 return new (1) CallInst(F, NameStr, InsertAtEnd);
1986 }
1987
1988 /// Create a clone of \p CI with a different set of operand bundles and
1989 /// insert it before \p InsertPt.
1990 ///
1991 /// The returned call instruction is identical \p CI in every way except that
1992 /// the operand bundles for the new instruction are set to the operand bundles
1993 /// in \p Bundles.
1994 static CallInst *Create(CallInst *CI, ArrayRef<OperandBundleDef> Bundles,
1995 Instruction *InsertPt = nullptr);
1996
1997 /// Generate the IR for a call to malloc:
1998 /// 1. Compute the malloc call's argument as the specified type's size,
1999 /// possibly multiplied by the array size if the array size is not
2000 /// constant 1.
2001 /// 2. Call malloc with that argument.
2002 /// 3. Bitcast the result of the malloc call to the specified type.
2003 static Instruction *CreateMalloc(Instruction *InsertBefore, Type *IntPtrTy,
2004 Type *AllocTy, Value *AllocSize,
2005 Value *ArraySize = nullptr,
2006 Function *MallocF = nullptr,
2007 const Twine &Name = "");
2008 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, Type *IntPtrTy,
2009 Type *AllocTy, Value *AllocSize,
2010 Value *ArraySize = nullptr,
2011 Function *MallocF = nullptr,
2012 const Twine &Name = "");
2013 static Instruction *CreateMalloc(Instruction *InsertBefore, Type *IntPtrTy,
2014 Type *AllocTy, Value *AllocSize,
2015 Value *ArraySize = nullptr,
2016 ArrayRef<OperandBundleDef> Bundles = None,
2017 Function *MallocF = nullptr,
2018 const Twine &Name = "");
2019 static Instruction *CreateMalloc(BasicBlock *InsertAtEnd, Type *IntPtrTy,
2020 Type *AllocTy, Value *AllocSize,
2021 Value *ArraySize = nullptr,
2022 ArrayRef<OperandBundleDef> Bundles = None,
2023 Function *MallocF = nullptr,
2024 const Twine &Name = "");
2025 /// Generate the IR for a call to the builtin free function.
2026 static Instruction *CreateFree(Value *Source, Instruction *InsertBefore);
2027 static Instruction *CreateFree(Value *Source, BasicBlock *InsertAtEnd);
2028 static Instruction *CreateFree(Value *Source,
2029 ArrayRef<OperandBundleDef> Bundles,
2030 Instruction *InsertBefore);
2031 static Instruction *CreateFree(Value *Source,
2032 ArrayRef<OperandBundleDef> Bundles,
2033 BasicBlock *InsertAtEnd);
2034
2035 // Note that 'musttail' implies 'tail'.
2036 enum TailCallKind {
2037 TCK_None = 0,
2038 TCK_Tail = 1,
2039 TCK_MustTail = 2,
2040 TCK_NoTail = 3
2041 };
2042 TailCallKind getTailCallKind() const {
2043 return TailCallKind(getSubclassDataFromInstruction() & 3);
2044 }
2045
2046 bool isTailCall() const {
2047 unsigned Kind = getSubclassDataFromInstruction() & 3;
2048 return Kind == TCK_Tail || Kind == TCK_MustTail;
2049 }
2050
2051 bool isMustTailCall() const {
2052 return (getSubclassDataFromInstruction() & 3) == TCK_MustTail;
2053 }
2054
2055 bool isNoTailCall() const {
2056 return (getSubclassDataFromInstruction() & 3) == TCK_NoTail;
2057 }
2058
2059 void setTailCall(bool isTC = true) {
2060 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
2061 unsigned(isTC ? TCK_Tail : TCK_None));
2062 }
2063
2064 void setTailCallKind(TailCallKind TCK) {
2065 setInstructionSubclassData((getSubclassDataFromInstruction() & ~3) |
2066 unsigned(TCK));
2067 }
2068
2069 /// Return true if the call can return twice
2070 bool canReturnTwice() const { return hasFnAttr(Attribute::ReturnsTwice); }
2071 void setCanReturnTwice() {
2072 addAttribute(AttributeList::FunctionIndex, Attribute::ReturnsTwice);
2073 }
2074
2075 /// Check if this call is an inline asm statement.
2076 bool isInlineAsm() const { return isa<InlineAsm>(Op<-1>()); }
2077
2078 // Methods for support type inquiry through isa, cast, and dyn_cast:
2079 static bool classof(const Instruction *I) {
2080 return I->getOpcode() == Instruction::Call;
2081 }
2082 static bool classof(const Value *V) {
2083 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2084 }
2085
2086private:
2087 // Shadow Instruction::setInstructionSubclassData with a private forwarding
2088 // method so that subclasses cannot accidentally use it.
2089 void setInstructionSubclassData(unsigned short D) {
2090 Instruction::setInstructionSubclassData(D);
2091 }
2092};
2093
2094template <>
2095struct OperandTraits<CallBase<CallInst>>
2096 : public VariadicOperandTraits<CallBase<CallInst>, 1> {};
2097
2098CallInst::CallInst(Value *Func, ArrayRef<Value *> Args,
2099 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
2100 BasicBlock *InsertAtEnd)
2101 : CallBase<CallInst>(
2102 cast<FunctionType>(
2103 cast<PointerType>(Func->getType())->getElementType())
2104 ->getReturnType(),
2105 Instruction::Call,
2106 OperandTraits<CallBase<CallInst>>::op_end(this) -
2107 (Args.size() + CountBundleInputs(Bundles) + 1),
2108 unsigned(Args.size() + CountBundleInputs(Bundles) + 1), InsertAtEnd) {
2109 init(Func, Args, Bundles, NameStr);
2110}
2111
2112CallInst::CallInst(FunctionType *Ty, Value *Func, ArrayRef<Value *> Args,
2113 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr,
2114 Instruction *InsertBefore)
2115 : CallBase<CallInst>(Ty->getReturnType(), Instruction::Call,
2116 OperandTraits<CallBase<CallInst>>::op_end(this) -
2117 (Args.size() + CountBundleInputs(Bundles) + 1),
2118 unsigned(Args.size() + CountBundleInputs(Bundles) + 1),
2119 InsertBefore) {
2120 init(Ty, Func, Args, Bundles, NameStr);
2121}
2122
2123//===----------------------------------------------------------------------===//
2124// SelectInst Class
2125//===----------------------------------------------------------------------===//
2126
2127/// This class represents the LLVM 'select' instruction.
2128///
2129class SelectInst : public Instruction {
2130 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
2131 Instruction *InsertBefore)
2132 : Instruction(S1->getType(), Instruction::Select,
2133 &Op<0>(), 3, InsertBefore) {
2134 init(C, S1, S2);
2135 setName(NameStr);
2136 }
2137
2138 SelectInst(Value *C, Value *S1, Value *S2, const Twine &NameStr,
2139 BasicBlock *InsertAtEnd)
2140 : Instruction(S1->getType(), Instruction::Select,
2141 &Op<0>(), 3, InsertAtEnd) {
2142 init(C, S1, S2);
2143 setName(NameStr);
2144 }
2145
2146 void init(Value *C, Value *S1, Value *S2) {
2147 assert(!areInvalidOperands(C, S1, S2) && "Invalid operands for select")(static_cast <bool> (!areInvalidOperands(C, S1, S2) &&
"Invalid operands for select") ? void (0) : __assert_fail ("!areInvalidOperands(C, S1, S2) && \"Invalid operands for select\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2147, __extension__ __PRETTY_FUNCTION__))
;
2148 Op<0>() = C;
2149 Op<1>() = S1;
2150 Op<2>() = S2;
2151 }
2152
2153protected:
2154 // Note: Instruction needs to be a friend here to call cloneImpl.
2155 friend class Instruction;
2156
2157 SelectInst *cloneImpl() const;
2158
2159public:
2160 static SelectInst *Create(Value *C, Value *S1, Value *S2,
2161 const Twine &NameStr = "",
2162 Instruction *InsertBefore = nullptr,
2163 Instruction *MDFrom = nullptr) {
2164 SelectInst *Sel = new(3) SelectInst(C, S1, S2, NameStr, InsertBefore);
2165 if (MDFrom)
2166 Sel->copyMetadata(*MDFrom);
2167 return Sel;
2168 }
2169
2170 static SelectInst *Create(Value *C, Value *S1, Value *S2,
2171 const Twine &NameStr,
2172 BasicBlock *InsertAtEnd) {
2173 return new(3) SelectInst(C, S1, S2, NameStr, InsertAtEnd);
2174 }
2175
2176 const Value *getCondition() const { return Op<0>(); }
2177 const Value *getTrueValue() const { return Op<1>(); }
2178 const Value *getFalseValue() const { return Op<2>(); }
2179 Value *getCondition() { return Op<0>(); }
2180 Value *getTrueValue() { return Op<1>(); }
2181 Value *getFalseValue() { return Op<2>(); }
2182
2183 void setCondition(Value *V) { Op<0>() = V; }
2184 void setTrueValue(Value *V) { Op<1>() = V; }
2185 void setFalseValue(Value *V) { Op<2>() = V; }
2186
2187 /// Return a string if the specified operands are invalid
2188 /// for a select operation, otherwise return null.
2189 static const char *areInvalidOperands(Value *Cond, Value *True, Value *False);
2190
2191 /// Transparently provide more efficient getOperand methods.
2192 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2193
2194 OtherOps getOpcode() const {
2195 return static_cast<OtherOps>(Instruction::getOpcode());
2196 }
2197
2198 // Methods for support type inquiry through isa, cast, and dyn_cast:
2199 static bool classof(const Instruction *I) {
2200 return I->getOpcode() == Instruction::Select;
2201 }
2202 static bool classof(const Value *V) {
2203 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2204 }
2205};
2206
2207template <>
2208struct OperandTraits<SelectInst> : public FixedNumOperandTraits<SelectInst, 3> {
2209};
2210
2211DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SelectInst, Value)SelectInst::op_iterator SelectInst::op_begin() { return OperandTraits
<SelectInst>::op_begin(this); } SelectInst::const_op_iterator
SelectInst::op_begin() const { return OperandTraits<SelectInst
>::op_begin(const_cast<SelectInst*>(this)); } SelectInst
::op_iterator SelectInst::op_end() { return OperandTraits<
SelectInst>::op_end(this); } SelectInst::const_op_iterator
SelectInst::op_end() const { return OperandTraits<SelectInst
>::op_end(const_cast<SelectInst*>(this)); } Value *SelectInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<SelectInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<SelectInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2211, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<SelectInst>::op_begin(const_cast
<SelectInst*>(this))[i_nocapture].get()); } void SelectInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<SelectInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<SelectInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2211, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
SelectInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned SelectInst::getNumOperands() const { return OperandTraits
<SelectInst>::operands(this); } template <int Idx_nocapture
> Use &SelectInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
SelectInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
2212
2213//===----------------------------------------------------------------------===//
2214// VAArgInst Class
2215//===----------------------------------------------------------------------===//
2216
2217/// This class represents the va_arg llvm instruction, which returns
2218/// an argument of the specified type given a va_list and increments that list
2219///
2220class VAArgInst : public UnaryInstruction {
2221protected:
2222 // Note: Instruction needs to be a friend here to call cloneImpl.
2223 friend class Instruction;
2224
2225 VAArgInst *cloneImpl() const;
2226
2227public:
2228 VAArgInst(Value *List, Type *Ty, const Twine &NameStr = "",
2229 Instruction *InsertBefore = nullptr)
2230 : UnaryInstruction(Ty, VAArg, List, InsertBefore) {
2231 setName(NameStr);
2232 }
2233
2234 VAArgInst(Value *List, Type *Ty, const Twine &NameStr,
2235 BasicBlock *InsertAtEnd)
2236 : UnaryInstruction(Ty, VAArg, List, InsertAtEnd) {
2237 setName(NameStr);
2238 }
2239
2240 Value *getPointerOperand() { return getOperand(0); }
2241 const Value *getPointerOperand() const { return getOperand(0); }
2242 static unsigned getPointerOperandIndex() { return 0U; }
2243
2244 // Methods for support type inquiry through isa, cast, and dyn_cast:
2245 static bool classof(const Instruction *I) {
2246 return I->getOpcode() == VAArg;
2247 }
2248 static bool classof(const Value *V) {
2249 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2250 }
2251};
2252
2253//===----------------------------------------------------------------------===//
2254// ExtractElementInst Class
2255//===----------------------------------------------------------------------===//
2256
2257/// This instruction extracts a single (scalar)
2258/// element from a VectorType value
2259///
2260class ExtractElementInst : public Instruction {
2261 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr = "",
2262 Instruction *InsertBefore = nullptr);
2263 ExtractElementInst(Value *Vec, Value *Idx, const Twine &NameStr,
2264 BasicBlock *InsertAtEnd);
2265
2266protected:
2267 // Note: Instruction needs to be a friend here to call cloneImpl.
2268 friend class Instruction;
2269
2270 ExtractElementInst *cloneImpl() const;
2271
2272public:
2273 static ExtractElementInst *Create(Value *Vec, Value *Idx,
2274 const Twine &NameStr = "",
2275 Instruction *InsertBefore = nullptr) {
2276 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertBefore);
2277 }
2278
2279 static ExtractElementInst *Create(Value *Vec, Value *Idx,
2280 const Twine &NameStr,
2281 BasicBlock *InsertAtEnd) {
2282 return new(2) ExtractElementInst(Vec, Idx, NameStr, InsertAtEnd);
2283 }
2284
2285 /// Return true if an extractelement instruction can be
2286 /// formed with the specified operands.
2287 static bool isValidOperands(const Value *Vec, const Value *Idx);
2288
2289 Value *getVectorOperand() { return Op<0>(); }
2290 Value *getIndexOperand() { return Op<1>(); }
2291 const Value *getVectorOperand() const { return Op<0>(); }
2292 const Value *getIndexOperand() const { return Op<1>(); }
2293
2294 VectorType *getVectorOperandType() const {
2295 return cast<VectorType>(getVectorOperand()->getType());
2296 }
2297
2298 /// Transparently provide more efficient getOperand methods.
2299 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2300
2301 // Methods for support type inquiry through isa, cast, and dyn_cast:
2302 static bool classof(const Instruction *I) {
2303 return I->getOpcode() == Instruction::ExtractElement;
2304 }
2305 static bool classof(const Value *V) {
2306 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2307 }
2308};
2309
2310template <>
2311struct OperandTraits<ExtractElementInst> :
2312 public FixedNumOperandTraits<ExtractElementInst, 2> {
2313};
2314
2315DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ExtractElementInst, Value)ExtractElementInst::op_iterator ExtractElementInst::op_begin(
) { return OperandTraits<ExtractElementInst>::op_begin(
this); } ExtractElementInst::const_op_iterator ExtractElementInst
::op_begin() const { return OperandTraits<ExtractElementInst
>::op_begin(const_cast<ExtractElementInst*>(this)); }
ExtractElementInst::op_iterator ExtractElementInst::op_end()
{ return OperandTraits<ExtractElementInst>::op_end(this
); } ExtractElementInst::const_op_iterator ExtractElementInst
::op_end() const { return OperandTraits<ExtractElementInst
>::op_end(const_cast<ExtractElementInst*>(this)); } Value
*ExtractElementInst::getOperand(unsigned i_nocapture) const {
(static_cast <bool> (i_nocapture < OperandTraits<
ExtractElementInst>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<ExtractElementInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2315, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ExtractElementInst>::op_begin
(const_cast<ExtractElementInst*>(this))[i_nocapture].get
()); } void ExtractElementInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<ExtractElementInst>::operands(this)
&& "setOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<ExtractElementInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2315, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ExtractElementInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned ExtractElementInst::getNumOperands() const { return
OperandTraits<ExtractElementInst>::operands(this); } template
<int Idx_nocapture> Use &ExtractElementInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &ExtractElementInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
2316
2317//===----------------------------------------------------------------------===//
2318// InsertElementInst Class
2319//===----------------------------------------------------------------------===//
2320
2321/// This instruction inserts a single (scalar)
2322/// element into a VectorType value
2323///
2324class InsertElementInst : public Instruction {
2325 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx,
2326 const Twine &NameStr = "",
2327 Instruction *InsertBefore = nullptr);
2328 InsertElementInst(Value *Vec, Value *NewElt, Value *Idx, const Twine &NameStr,
2329 BasicBlock *InsertAtEnd);
2330
2331protected:
2332 // Note: Instruction needs to be a friend here to call cloneImpl.
2333 friend class Instruction;
2334
2335 InsertElementInst *cloneImpl() const;
2336
2337public:
2338 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2339 const Twine &NameStr = "",
2340 Instruction *InsertBefore = nullptr) {
2341 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertBefore);
2342 }
2343
2344 static InsertElementInst *Create(Value *Vec, Value *NewElt, Value *Idx,
2345 const Twine &NameStr,
2346 BasicBlock *InsertAtEnd) {
2347 return new(3) InsertElementInst(Vec, NewElt, Idx, NameStr, InsertAtEnd);
2348 }
2349
2350 /// Return true if an insertelement instruction can be
2351 /// formed with the specified operands.
2352 static bool isValidOperands(const Value *Vec, const Value *NewElt,
2353 const Value *Idx);
2354
2355 /// Overload to return most specific vector type.
2356 ///
2357 VectorType *getType() const {
2358 return cast<VectorType>(Instruction::getType());
2359 }
2360
2361 /// Transparently provide more efficient getOperand methods.
2362 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2363
2364 // Methods for support type inquiry through isa, cast, and dyn_cast:
2365 static bool classof(const Instruction *I) {
2366 return I->getOpcode() == Instruction::InsertElement;
2367 }
2368 static bool classof(const Value *V) {
2369 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2370 }
2371};
2372
2373template <>
2374struct OperandTraits<InsertElementInst> :
2375 public FixedNumOperandTraits<InsertElementInst, 3> {
2376};
2377
2378DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertElementInst, Value)InsertElementInst::op_iterator InsertElementInst::op_begin() {
return OperandTraits<InsertElementInst>::op_begin(this
); } InsertElementInst::const_op_iterator InsertElementInst::
op_begin() const { return OperandTraits<InsertElementInst>
::op_begin(const_cast<InsertElementInst*>(this)); } InsertElementInst
::op_iterator InsertElementInst::op_end() { return OperandTraits
<InsertElementInst>::op_end(this); } InsertElementInst::
const_op_iterator InsertElementInst::op_end() const { return OperandTraits
<InsertElementInst>::op_end(const_cast<InsertElementInst
*>(this)); } Value *InsertElementInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<InsertElementInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<InsertElementInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2378, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<InsertElementInst>::op_begin
(const_cast<InsertElementInst*>(this))[i_nocapture].get
()); } void InsertElementInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<InsertElementInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<InsertElementInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2378, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
InsertElementInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned InsertElementInst::getNumOperands() const { return
OperandTraits<InsertElementInst>::operands(this); } template
<int Idx_nocapture> Use &InsertElementInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &InsertElementInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
2379
2380//===----------------------------------------------------------------------===//
2381// ShuffleVectorInst Class
2382//===----------------------------------------------------------------------===//
2383
2384/// This instruction constructs a fixed permutation of two
2385/// input vectors.
2386///
2387class ShuffleVectorInst : public Instruction {
2388protected:
2389 // Note: Instruction needs to be a friend here to call cloneImpl.
2390 friend class Instruction;
2391
2392 ShuffleVectorInst *cloneImpl() const;
2393
2394public:
2395 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
2396 const Twine &NameStr = "",
2397 Instruction *InsertBefor = nullptr);
2398 ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,
2399 const Twine &NameStr, BasicBlock *InsertAtEnd);
2400
2401 // allocate space for exactly three operands
2402 void *operator new(size_t s) {
2403 return User::operator new(s, 3);
2404 }
2405
2406 /// Return true if a shufflevector instruction can be
2407 /// formed with the specified operands.
2408 static bool isValidOperands(const Value *V1, const Value *V2,
2409 const Value *Mask);
2410
2411 /// Overload to return most specific vector type.
2412 ///
2413 VectorType *getType() const {
2414 return cast<VectorType>(Instruction::getType());
2415 }
2416
2417 /// Transparently provide more efficient getOperand methods.
2418 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2419
2420 Constant *getMask() const {
2421 return cast<Constant>(getOperand(2));
2422 }
2423
2424 /// Return the shuffle mask value for the specified element of the mask.
2425 /// Return -1 if the element is undef.
2426 static int getMaskValue(Constant *Mask, unsigned Elt);
2427
2428 /// Return the shuffle mask value of this instruction for the given element
2429 /// index. Return -1 if the element is undef.
2430 int getMaskValue(unsigned Elt) const {
2431 return getMaskValue(getMask(), Elt);
2432 }
2433
2434 /// Convert the input shuffle mask operand to a vector of integers. Undefined
2435 /// elements of the mask are returned as -1.
2436 static void getShuffleMask(Constant *Mask, SmallVectorImpl<int> &Result);
2437
2438 /// Return the mask for this instruction as a vector of integers. Undefined
2439 /// elements of the mask are returned as -1.
2440 void getShuffleMask(SmallVectorImpl<int> &Result) const {
2441 return getShuffleMask(getMask(), Result);
2442 }
2443
2444 SmallVector<int, 16> getShuffleMask() const {
2445 SmallVector<int, 16> Mask;
2446 getShuffleMask(Mask);
2447 return Mask;
2448 }
2449
2450 /// Change values in a shuffle permute mask assuming the two vector operands
2451 /// of length InVecNumElts have swapped position.
2452 static void commuteShuffleMask(MutableArrayRef<int> Mask,
2453 unsigned InVecNumElts) {
2454 for (int &Idx : Mask) {
2455 if (Idx == -1)
2456 continue;
2457 Idx = Idx < (int)InVecNumElts ? Idx + InVecNumElts : Idx - InVecNumElts;
2458 assert(Idx >= 0 && Idx < (int)InVecNumElts * 2 &&(static_cast <bool> (Idx >= 0 && Idx < (int
)InVecNumElts * 2 && "shufflevector mask index out of range"
) ? void (0) : __assert_fail ("Idx >= 0 && Idx < (int)InVecNumElts * 2 && \"shufflevector mask index out of range\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2459, __extension__ __PRETTY_FUNCTION__))
2459 "shufflevector mask index out of range")(static_cast <bool> (Idx >= 0 && Idx < (int
)InVecNumElts * 2 && "shufflevector mask index out of range"
) ? void (0) : __assert_fail ("Idx >= 0 && Idx < (int)InVecNumElts * 2 && \"shufflevector mask index out of range\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2459, __extension__ __PRETTY_FUNCTION__))
;
2460 }
2461 }
2462
2463 // Methods for support type inquiry through isa, cast, and dyn_cast:
2464 static bool classof(const Instruction *I) {
2465 return I->getOpcode() == Instruction::ShuffleVector;
2466 }
2467 static bool classof(const Value *V) {
2468 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2469 }
2470};
2471
2472template <>
2473struct OperandTraits<ShuffleVectorInst> :
2474 public FixedNumOperandTraits<ShuffleVectorInst, 3> {
2475};
2476
2477DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorInst, Value)ShuffleVectorInst::op_iterator ShuffleVectorInst::op_begin() {
return OperandTraits<ShuffleVectorInst>::op_begin(this
); } ShuffleVectorInst::const_op_iterator ShuffleVectorInst::
op_begin() const { return OperandTraits<ShuffleVectorInst>
::op_begin(const_cast<ShuffleVectorInst*>(this)); } ShuffleVectorInst
::op_iterator ShuffleVectorInst::op_end() { return OperandTraits
<ShuffleVectorInst>::op_end(this); } ShuffleVectorInst::
const_op_iterator ShuffleVectorInst::op_end() const { return OperandTraits
<ShuffleVectorInst>::op_end(const_cast<ShuffleVectorInst
*>(this)); } Value *ShuffleVectorInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<ShuffleVectorInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<ShuffleVectorInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2477, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ShuffleVectorInst>::op_begin
(const_cast<ShuffleVectorInst*>(this))[i_nocapture].get
()); } void ShuffleVectorInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<ShuffleVectorInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<ShuffleVectorInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2477, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ShuffleVectorInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned ShuffleVectorInst::getNumOperands() const { return
OperandTraits<ShuffleVectorInst>::operands(this); } template
<int Idx_nocapture> Use &ShuffleVectorInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &ShuffleVectorInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
2478
2479//===----------------------------------------------------------------------===//
2480// ExtractValueInst Class
2481//===----------------------------------------------------------------------===//
2482
2483/// This instruction extracts a struct member or array
2484/// element value from an aggregate value.
2485///
2486class ExtractValueInst : public UnaryInstruction {
2487 SmallVector<unsigned, 4> Indices;
2488
2489 ExtractValueInst(const ExtractValueInst &EVI);
2490
2491 /// Constructors - Create a extractvalue instruction with a base aggregate
2492 /// value and a list of indices. The first ctor can optionally insert before
2493 /// an existing instruction, the second appends the new instruction to the
2494 /// specified BasicBlock.
2495 inline ExtractValueInst(Value *Agg,
2496 ArrayRef<unsigned> Idxs,
2497 const Twine &NameStr,
2498 Instruction *InsertBefore);
2499 inline ExtractValueInst(Value *Agg,
2500 ArrayRef<unsigned> Idxs,
2501 const Twine &NameStr, BasicBlock *InsertAtEnd);
2502
2503 void init(ArrayRef<unsigned> Idxs, const Twine &NameStr);
2504
2505protected:
2506 // Note: Instruction needs to be a friend here to call cloneImpl.
2507 friend class Instruction;
2508
2509 ExtractValueInst *cloneImpl() const;
2510
2511public:
2512 static ExtractValueInst *Create(Value *Agg,
2513 ArrayRef<unsigned> Idxs,
2514 const Twine &NameStr = "",
2515 Instruction *InsertBefore = nullptr) {
2516 return new
2517 ExtractValueInst(Agg, Idxs, NameStr, InsertBefore);
2518 }
2519
2520 static ExtractValueInst *Create(Value *Agg,
2521 ArrayRef<unsigned> Idxs,
2522 const Twine &NameStr,
2523 BasicBlock *InsertAtEnd) {
2524 return new ExtractValueInst(Agg, Idxs, NameStr, InsertAtEnd);
2525 }
2526
2527 /// Returns the type of the element that would be extracted
2528 /// with an extractvalue instruction with the specified parameters.
2529 ///
2530 /// Null is returned if the indices are invalid for the specified type.
2531 static Type *getIndexedType(Type *Agg, ArrayRef<unsigned> Idxs);
2532
2533 using idx_iterator = const unsigned*;
2534
2535 inline idx_iterator idx_begin() const { return Indices.begin(); }
2536 inline idx_iterator idx_end() const { return Indices.end(); }
2537 inline iterator_range<idx_iterator> indices() const {
2538 return make_range(idx_begin(), idx_end());
2539 }
2540
2541 Value *getAggregateOperand() {
2542 return getOperand(0);
2543 }
2544 const Value *getAggregateOperand() const {
2545 return getOperand(0);
2546 }
2547 static unsigned getAggregateOperandIndex() {
2548 return 0U; // get index for modifying correct operand
2549 }
2550
2551 ArrayRef<unsigned> getIndices() const {
2552 return Indices;
2553 }
2554
2555 unsigned getNumIndices() const {
2556 return (unsigned)Indices.size();
2557 }
2558
2559 bool hasIndices() const {
2560 return true;
2561 }
2562
2563 // Methods for support type inquiry through isa, cast, and dyn_cast:
2564 static bool classof(const Instruction *I) {
2565 return I->getOpcode() == Instruction::ExtractValue;
2566 }
2567 static bool classof(const Value *V) {
2568 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2569 }
2570};
2571
2572ExtractValueInst::ExtractValueInst(Value *Agg,
2573 ArrayRef<unsigned> Idxs,
2574 const Twine &NameStr,
2575 Instruction *InsertBefore)
2576 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2577 ExtractValue, Agg, InsertBefore) {
2578 init(Idxs, NameStr);
2579}
2580
2581ExtractValueInst::ExtractValueInst(Value *Agg,
2582 ArrayRef<unsigned> Idxs,
2583 const Twine &NameStr,
2584 BasicBlock *InsertAtEnd)
2585 : UnaryInstruction(checkGEPType(getIndexedType(Agg->getType(), Idxs)),
2586 ExtractValue, Agg, InsertAtEnd) {
2587 init(Idxs, NameStr);
2588}
2589
2590//===----------------------------------------------------------------------===//
2591// InsertValueInst Class
2592//===----------------------------------------------------------------------===//
2593
2594/// This instruction inserts a struct field of array element
2595/// value into an aggregate value.
2596///
2597class InsertValueInst : public Instruction {
2598 SmallVector<unsigned, 4> Indices;
2599
2600 InsertValueInst(const InsertValueInst &IVI);
2601
2602 /// Constructors - Create a insertvalue instruction with a base aggregate
2603 /// value, a value to insert, and a list of indices. The first ctor can
2604 /// optionally insert before an existing instruction, the second appends
2605 /// the new instruction to the specified BasicBlock.
2606 inline InsertValueInst(Value *Agg, Value *Val,
2607 ArrayRef<unsigned> Idxs,
2608 const Twine &NameStr,
2609 Instruction *InsertBefore);
2610 inline InsertValueInst(Value *Agg, Value *Val,
2611 ArrayRef<unsigned> Idxs,
2612 const Twine &NameStr, BasicBlock *InsertAtEnd);
2613
2614 /// Constructors - These two constructors are convenience methods because one
2615 /// and two index insertvalue instructions are so common.
2616 InsertValueInst(Value *Agg, Value *Val, unsigned Idx,
2617 const Twine &NameStr = "",
2618 Instruction *InsertBefore = nullptr);
2619 InsertValueInst(Value *Agg, Value *Val, unsigned Idx, const Twine &NameStr,
2620 BasicBlock *InsertAtEnd);
2621
2622 void init(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,
2623 const Twine &NameStr);
2624
2625protected:
2626 // Note: Instruction needs to be a friend here to call cloneImpl.
2627 friend class Instruction;
2628
2629 InsertValueInst *cloneImpl() const;
2630
2631public:
2632 // allocate space for exactly two operands
2633 void *operator new(size_t s) {
2634 return User::operator new(s, 2);
2635 }
2636
2637 static InsertValueInst *Create(Value *Agg, Value *Val,
2638 ArrayRef<unsigned> Idxs,
2639 const Twine &NameStr = "",
2640 Instruction *InsertBefore = nullptr) {
2641 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertBefore);
2642 }
2643
2644 static InsertValueInst *Create(Value *Agg, Value *Val,
2645 ArrayRef<unsigned> Idxs,
2646 const Twine &NameStr,
2647 BasicBlock *InsertAtEnd) {
2648 return new InsertValueInst(Agg, Val, Idxs, NameStr, InsertAtEnd);
2649 }
2650
2651 /// Transparently provide more efficient getOperand methods.
2652 DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value)public: inline Value *getOperand(unsigned) const; inline void
setOperand(unsigned, Value*); inline op_iterator op_begin();
inline const_op_iterator op_begin() const; inline op_iterator
op_end(); inline const_op_iterator op_end() const; protected
: template <int> inline Use &Op(); template <int
> inline const Use &Op() const; public: inline unsigned
getNumOperands() const
;
2653
2654 using idx_iterator = const unsigned*;
2655
2656 inline idx_iterator idx_begin() const { return Indices.begin(); }
2657 inline idx_iterator idx_end() const { return Indices.end(); }
2658 inline iterator_range<idx_iterator> indices() const {
2659 return make_range(idx_begin(), idx_end());
2660 }
2661
2662 Value *getAggregateOperand() {
2663 return getOperand(0);
2664 }
2665 const Value *getAggregateOperand() const {
2666 return getOperand(0);
2667 }
2668 static unsigned getAggregateOperandIndex() {
2669 return 0U; // get index for modifying correct operand
2670 }
2671
2672 Value *getInsertedValueOperand() {
2673 return getOperand(1);
2674 }
2675 const Value *getInsertedValueOperand() const {
2676 return getOperand(1);
2677 }
2678 static unsigned getInsertedValueOperandIndex() {
2679 return 1U; // get index for modifying correct operand
2680 }
2681
2682 ArrayRef<unsigned> getIndices() const {
2683 return Indices;
2684 }
2685
2686 unsigned getNumIndices() const {
2687 return (unsigned)Indices.size();
2688 }
2689
2690 bool hasIndices() const {
2691 return true;
2692 }
2693
2694 // Methods for support type inquiry through isa, cast, and dyn_cast:
2695 static bool classof(const Instruction *I) {
2696 return I->getOpcode() == Instruction::InsertValue;
2697 }
2698 static bool classof(const Value *V) {
2699 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2700 }
2701};
2702
2703template <>
2704struct OperandTraits<InsertValueInst> :
2705 public FixedNumOperandTraits<InsertValueInst, 2> {
2706};
2707
2708InsertValueInst::InsertValueInst(Value *Agg,
2709 Value *Val,
2710 ArrayRef<unsigned> Idxs,
2711 const Twine &NameStr,
2712 Instruction *InsertBefore)
2713 : Instruction(Agg->getType(), InsertValue,
2714 OperandTraits<InsertValueInst>::op_begin(this),
2715 2, InsertBefore) {
2716 init(Agg, Val, Idxs, NameStr);
2717}
2718
2719InsertValueInst::InsertValueInst(Value *Agg,
2720 Value *Val,
2721 ArrayRef<unsigned> Idxs,
2722 const Twine &NameStr,
2723 BasicBlock *InsertAtEnd)
2724 : Instruction(Agg->getType(), InsertValue,
2725 OperandTraits<InsertValueInst>::op_begin(this),
2726 2, InsertAtEnd) {
2727 init(Agg, Val, Idxs, NameStr);
2728}
2729
2730DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueInst, Value)InsertValueInst::op_iterator InsertValueInst::op_begin() { return
OperandTraits<InsertValueInst>::op_begin(this); } InsertValueInst
::const_op_iterator InsertValueInst::op_begin() const { return
OperandTraits<InsertValueInst>::op_begin(const_cast<
InsertValueInst*>(this)); } InsertValueInst::op_iterator InsertValueInst
::op_end() { return OperandTraits<InsertValueInst>::op_end
(this); } InsertValueInst::const_op_iterator InsertValueInst::
op_end() const { return OperandTraits<InsertValueInst>::
op_end(const_cast<InsertValueInst*>(this)); } Value *InsertValueInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<InsertValueInst>::
operands(this) && "getOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<InsertValueInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2730, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<InsertValueInst>::op_begin
(const_cast<InsertValueInst*>(this))[i_nocapture].get()
); } void InsertValueInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<InsertValueInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<InsertValueInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326551/include/llvm/IR/Instructions.h"
, 2730, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
InsertValueInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned InsertValueInst::getNumOperands() const { return
OperandTraits<InsertValueInst>::operands(this); } template
<int Idx_nocapture> Use &InsertValueInst::Op() { return
this->OpFro