Bug Summary

File:lib/CodeGen/StackProtector.cpp
Warning:line 211, column 36
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 StackProtector.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~svn326246/build-llvm/lib/CodeGen -I /build/llvm-toolchain-snapshot-7~svn326246/lib/CodeGen -I /build/llvm-toolchain-snapshot-7~svn326246/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn326246/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~svn326246/build-llvm/lib/CodeGen -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-02-28-041547-14988-1 -x c++ /build/llvm-toolchain-snapshot-7~svn326246/lib/CodeGen/StackProtector.cpp

/build/llvm-toolchain-snapshot-7~svn326246/lib/CodeGen/StackProtector.cpp

1//===- StackProtector.cpp - Stack Protector Insertion ---------------------===//
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 pass inserts stack protectors into functions which need them. A variable
11// with a random value in it is stored onto the stack before the local variables
12// are allocated. Upon exiting the block, the stored value is checked. If it's
13// changed, then there was some sort of violation and the program aborts.
14//
15//===----------------------------------------------------------------------===//
16
17#include "llvm/CodeGen/StackProtector.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/Statistic.h"
20#include "llvm/Analysis/BranchProbabilityInfo.h"
21#include "llvm/Analysis/EHPersonalities.h"
22#include "llvm/Analysis/OptimizationRemarkEmitter.h"
23#include "llvm/CodeGen/Passes.h"
24#include "llvm/CodeGen/TargetLowering.h"
25#include "llvm/CodeGen/TargetPassConfig.h"
26#include "llvm/CodeGen/TargetSubtargetInfo.h"
27#include "llvm/IR/Attributes.h"
28#include "llvm/IR/BasicBlock.h"
29#include "llvm/IR/Constants.h"
30#include "llvm/IR/DataLayout.h"
31#include "llvm/IR/DebugInfo.h"
32#include "llvm/IR/DebugLoc.h"
33#include "llvm/IR/DerivedTypes.h"
34#include "llvm/IR/Dominators.h"
35#include "llvm/IR/Function.h"
36#include "llvm/IR/IRBuilder.h"
37#include "llvm/IR/Instruction.h"
38#include "llvm/IR/Instructions.h"
39#include "llvm/IR/Intrinsics.h"
40#include "llvm/IR/MDBuilder.h"
41#include "llvm/IR/Module.h"
42#include "llvm/IR/Type.h"
43#include "llvm/IR/User.h"
44#include "llvm/Pass.h"
45#include "llvm/Support/Casting.h"
46#include "llvm/Support/CommandLine.h"
47#include "llvm/Target/TargetMachine.h"
48#include "llvm/Target/TargetOptions.h"
49#include <utility>
50
51using namespace llvm;
52
53#define DEBUG_TYPE"stack-protector" "stack-protector"
54
55STATISTIC(NumFunProtected, "Number of functions protected")static llvm::Statistic NumFunProtected = {"stack-protector", "NumFunProtected"
, "Number of functions protected", {0}, {false}}
;
56STATISTIC(NumAddrTaken, "Number of local variables that have their address"static llvm::Statistic NumAddrTaken = {"stack-protector", "NumAddrTaken"
, "Number of local variables that have their address" " taken."
, {0}, {false}}
57 " taken.")static llvm::Statistic NumAddrTaken = {"stack-protector", "NumAddrTaken"
, "Number of local variables that have their address" " taken."
, {0}, {false}}
;
58
59static cl::opt<bool> EnableSelectionDAGSP("enable-selectiondag-sp",
60 cl::init(true), cl::Hidden);
61
62char StackProtector::ID = 0;
63
64INITIALIZE_PASS_BEGIN(StackProtector, DEBUG_TYPE,static void *initializeStackProtectorPassOnce(PassRegistry &
Registry) {
65 "Insert stack protectors", false, true)static void *initializeStackProtectorPassOnce(PassRegistry &
Registry) {
66INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)initializeTargetPassConfigPass(Registry);
67INITIALIZE_PASS_END(StackProtector, DEBUG_TYPE,PassInfo *PI = new PassInfo( "Insert stack protectors", "stack-protector"
, &StackProtector::ID, PassInfo::NormalCtor_t(callDefaultCtor
<StackProtector>), false, true); Registry.registerPass(
*PI, true); return PI; } static llvm::once_flag InitializeStackProtectorPassFlag
; void llvm::initializeStackProtectorPass(PassRegistry &Registry
) { llvm::call_once(InitializeStackProtectorPassFlag, initializeStackProtectorPassOnce
, std::ref(Registry)); }
68 "Insert stack protectors", false, true)PassInfo *PI = new PassInfo( "Insert stack protectors", "stack-protector"
, &StackProtector::ID, PassInfo::NormalCtor_t(callDefaultCtor
<StackProtector>), false, true); Registry.registerPass(
*PI, true); return PI; } static llvm::once_flag InitializeStackProtectorPassFlag
; void llvm::initializeStackProtectorPass(PassRegistry &Registry
) { llvm::call_once(InitializeStackProtectorPassFlag, initializeStackProtectorPassOnce
, std::ref(Registry)); }
69
70FunctionPass *llvm::createStackProtectorPass() { return new StackProtector(); }
71
72StackProtector::SSPLayoutKind
73StackProtector::getSSPLayout(const AllocaInst *AI) const {
74 return AI ? Layout.lookup(AI) : SSPLK_None;
75}
76
77void StackProtector::adjustForColoring(const AllocaInst *From,
78 const AllocaInst *To) {
79 // When coloring replaces one alloca with another, transfer the SSPLayoutKind
80 // tag from the remapped to the target alloca. The remapped alloca should
81 // have a size smaller than or equal to the replacement alloca.
82 SSPLayoutMap::iterator I = Layout.find(From);
83 if (I != Layout.end()) {
84 SSPLayoutKind Kind = I->second;
85 Layout.erase(I);
86
87 // Transfer the tag, but make sure that SSPLK_AddrOf does not overwrite
88 // SSPLK_SmallArray or SSPLK_LargeArray, and make sure that
89 // SSPLK_SmallArray does not overwrite SSPLK_LargeArray.
90 I = Layout.find(To);
91 if (I == Layout.end())
92 Layout.insert(std::make_pair(To, Kind));
93 else if (I->second != SSPLK_LargeArray && Kind != SSPLK_AddrOf)
94 I->second = Kind;
95 }
96}
97
98void StackProtector::getAnalysisUsage(AnalysisUsage &AU) const {
99 AU.addRequired<TargetPassConfig>();
100 AU.addPreserved<DominatorTreeWrapperPass>();
101}
102
103bool StackProtector::runOnFunction(Function &Fn) {
104 F = &Fn;
105 M = F->getParent();
106 DominatorTreeWrapperPass *DTWP =
107 getAnalysisIfAvailable<DominatorTreeWrapperPass>();
108 DT = DTWP ? &DTWP->getDomTree() : nullptr;
1
Assuming 'DTWP' is null
2
'?' condition is false
109 TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
110 Trip = TM->getTargetTriple();
111 TLI = TM->getSubtargetImpl(Fn)->getTargetLowering();
112 HasPrologue = false;
113 HasIRCheck = false;
114
115 Attribute Attr = Fn.getFnAttribute("stack-protector-buffer-size");
116 if (Attr.isStringAttribute() &&
3
Assuming the condition is false
4
Taking false branch
117 Attr.getValueAsString().getAsInteger(10, SSPBufferSize))
118 return false; // Invalid integer string
119
120 if (!RequiresStackProtector())
5
Assuming the condition is false
6
Taking false branch
121 return false;
122
123 // TODO(etienneb): Functions with funclets are not correctly supported now.
124 // Do nothing if this is funclet-based personality.
125 if (Fn.hasPersonalityFn()) {
7
Assuming the condition is false
8
Taking false branch
126 EHPersonality Personality = classifyEHPersonality(Fn.getPersonalityFn());
127 if (isFuncletEHPersonality(Personality))
128 return false;
129 }
130
131 ++NumFunProtected;
132 return InsertStackProtectors();
9
Calling 'StackProtector::InsertStackProtectors'
133}
134
135/// \param [out] IsLarge is set to true if a protectable array is found and
136/// it is "large" ( >= ssp-buffer-size). In the case of a structure with
137/// multiple arrays, this gets set if any of them is large.
138bool StackProtector::ContainsProtectableArray(Type *Ty, bool &IsLarge,
139 bool Strong,
140 bool InStruct) const {
141 if (!Ty)
142 return false;
143 if (ArrayType *AT = dyn_cast<ArrayType>(Ty)) {
144 if (!AT->getElementType()->isIntegerTy(8)) {
145 // If we're on a non-Darwin platform or we're inside of a structure, don't
146 // add stack protectors unless the array is a character array.
147 // However, in strong mode any array, regardless of type and size,
148 // triggers a protector.
149 if (!Strong && (InStruct || !Trip.isOSDarwin()))
150 return false;
151 }
152
153 // If an array has more than SSPBufferSize bytes of allocated space, then we
154 // emit stack protectors.
155 if (SSPBufferSize <= M->getDataLayout().getTypeAllocSize(AT)) {
156 IsLarge = true;
157 return true;
158 }
159
160 if (Strong)
161 // Require a protector for all arrays in strong mode
162 return true;
163 }
164
165 const StructType *ST = dyn_cast<StructType>(Ty);
166 if (!ST)
167 return false;
168
169 bool NeedsProtector = false;
170 for (StructType::element_iterator I = ST->element_begin(),
171 E = ST->element_end();
172 I != E; ++I)
173 if (ContainsProtectableArray(*I, IsLarge, Strong, true)) {
174 // If the element is a protectable array and is large (>= SSPBufferSize)
175 // then we are done. If the protectable array is not large, then
176 // keep looking in case a subsequent element is a large array.
177 if (IsLarge)
178 return true;
179 NeedsProtector = true;
180 }
181
182 return NeedsProtector;
183}
184
185bool StackProtector::HasAddressTaken(const Instruction *AI) {
186 for (const User *U : AI->users()) {
187 if (const StoreInst *SI = dyn_cast<StoreInst>(U)) {
188 if (AI == SI->getValueOperand())
189 return true;
190 } else if (const PtrToIntInst *SI = dyn_cast<PtrToIntInst>(U)) {
191 if (AI == SI->getOperand(0))
192 return true;
193 } else if (isa<CallInst>(U)) {
194 return true;
195 } else if (isa<InvokeInst>(U)) {
196 return true;
197 } else if (const SelectInst *SI = dyn_cast<SelectInst>(U)) {
198 if (HasAddressTaken(SI))
199 return true;
200 } else if (const PHINode *PN = dyn_cast<PHINode>(U)) {
201 // Keep track of what PHI nodes we have already visited to ensure
202 // they are only visited once.
203 if (VisitedPHIs.insert(PN).second)
204 if (HasAddressTaken(PN))
205 return true;
206 } else if (const GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(U)) {
207 if (HasAddressTaken(GEP))
208 return true;
209 } else if (const BitCastInst *BI = dyn_cast<BitCastInst>(U)) {
210 if (HasAddressTaken(BI))
211 return true;
212 }
213 }
214 return false;
215}
216
217/// \brief Check whether or not this function needs a stack protector based
218/// upon the stack protector level.
219///
220/// We use two heuristics: a standard (ssp) and strong (sspstrong).
221/// The standard heuristic which will add a guard variable to functions that
222/// call alloca with a either a variable size or a size >= SSPBufferSize,
223/// functions with character buffers larger than SSPBufferSize, and functions
224/// with aggregates containing character buffers larger than SSPBufferSize. The
225/// strong heuristic will add a guard variables to functions that call alloca
226/// regardless of size, functions with any buffer regardless of type and size,
227/// functions with aggregates that contain any buffer regardless of type and
228/// size, and functions that contain stack-based variables that have had their
229/// address taken.
230bool StackProtector::RequiresStackProtector() {
231 bool Strong = false;
232 bool NeedsProtector = false;
233 for (const BasicBlock &BB : *F)
234 for (const Instruction &I : BB)
235 if (const CallInst *CI = dyn_cast<CallInst>(&I))
236 if (CI->getCalledFunction() ==
237 Intrinsic::getDeclaration(F->getParent(),
238 Intrinsic::stackprotector))
239 HasPrologue = true;
240
241 if (F->hasFnAttribute(Attribute::SafeStack))
242 return false;
243
244 // We are constructing the OptimizationRemarkEmitter on the fly rather than
245 // using the analysis pass to avoid building DominatorTree and LoopInfo which
246 // are not available this late in the IR pipeline.
247 OptimizationRemarkEmitter ORE(F);
248
249 if (F->hasFnAttribute(Attribute::StackProtectReq)) {
250 ORE.emit([&]() {
251 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorRequested", F)
252 << "Stack protection applied to function "
253 << ore::NV("Function", F)
254 << " due to a function attribute or command-line switch";
255 });
256 NeedsProtector = true;
257 Strong = true; // Use the same heuristic as strong to determine SSPLayout
258 } else if (F->hasFnAttribute(Attribute::StackProtectStrong))
259 Strong = true;
260 else if (HasPrologue)
261 NeedsProtector = true;
262 else if (!F->hasFnAttribute(Attribute::StackProtect))
263 return false;
264
265 for (const BasicBlock &BB : *F) {
266 for (const Instruction &I : BB) {
267 if (const AllocaInst *AI = dyn_cast<AllocaInst>(&I)) {
268 if (AI->isArrayAllocation()) {
269 auto RemarkBuilder = [&]() {
270 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorAllocaOrArray",
271 &I)
272 << "Stack protection applied to function "
273 << ore::NV("Function", F)
274 << " due to a call to alloca or use of a variable length "
275 "array";
276 };
277 if (const auto *CI = dyn_cast<ConstantInt>(AI->getArraySize())) {
278 if (CI->getLimitedValue(SSPBufferSize) >= SSPBufferSize) {
279 // A call to alloca with size >= SSPBufferSize requires
280 // stack protectors.
281 Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
282 ORE.emit(RemarkBuilder);
283 NeedsProtector = true;
284 } else if (Strong) {
285 // Require protectors for all alloca calls in strong mode.
286 Layout.insert(std::make_pair(AI, SSPLK_SmallArray));
287 ORE.emit(RemarkBuilder);
288 NeedsProtector = true;
289 }
290 } else {
291 // A call to alloca with a variable size requires protectors.
292 Layout.insert(std::make_pair(AI, SSPLK_LargeArray));
293 ORE.emit(RemarkBuilder);
294 NeedsProtector = true;
295 }
296 continue;
297 }
298
299 bool IsLarge = false;
300 if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) {
301 Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray
302 : SSPLK_SmallArray));
303 ORE.emit([&]() {
304 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorBuffer", &I)
305 << "Stack protection applied to function "
306 << ore::NV("Function", F)
307 << " due to a stack allocated buffer or struct containing a "
308 "buffer";
309 });
310 NeedsProtector = true;
311 continue;
312 }
313
314 if (Strong && HasAddressTaken(AI)) {
315 ++NumAddrTaken;
316 Layout.insert(std::make_pair(AI, SSPLK_AddrOf));
317 ORE.emit([&]() {
318 return OptimizationRemark(DEBUG_TYPE"stack-protector", "StackProtectorAddressTaken",
319 &I)
320 << "Stack protection applied to function "
321 << ore::NV("Function", F)
322 << " due to the address of a local variable being taken";
323 });
324 NeedsProtector = true;
325 }
326 }
327 }
328 }
329
330 return NeedsProtector;
331}
332
333/// Create a stack guard loading and populate whether SelectionDAG SSP is
334/// supported.
335static Value *getStackGuard(const TargetLoweringBase *TLI, Module *M,
336 IRBuilder<> &B,
337 bool *SupportsSelectionDAGSP = nullptr) {
338 if (Value *Guard = TLI->getIRStackGuard(B))
339 return B.CreateLoad(Guard, true, "StackGuard");
340
341 // Use SelectionDAG SSP handling, since there isn't an IR guard.
342 //
343 // This is more or less weird, since we optionally output whether we
344 // should perform a SelectionDAG SP here. The reason is that it's strictly
345 // defined as !TLI->getIRStackGuard(B), where getIRStackGuard is also
346 // mutating. There is no way to get this bit without mutating the IR, so
347 // getting this bit has to happen in this right time.
348 //
349 // We could have define a new function TLI::supportsSelectionDAGSP(), but that
350 // will put more burden on the backends' overriding work, especially when it
351 // actually conveys the same information getIRStackGuard() already gives.
352 if (SupportsSelectionDAGSP)
353 *SupportsSelectionDAGSP = true;
354 TLI->insertSSPDeclarations(*M);
355 return B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard));
356}
357
358/// Insert code into the entry block that stores the stack guard
359/// variable onto the stack:
360///
361/// entry:
362/// StackGuardSlot = alloca i8*
363/// StackGuard = <stack guard>
364/// call void @llvm.stackprotector(StackGuard, StackGuardSlot)
365///
366/// Returns true if the platform/triple supports the stackprotectorcreate pseudo
367/// node.
368static bool CreatePrologue(Function *F, Module *M, ReturnInst *RI,
369 const TargetLoweringBase *TLI, AllocaInst *&AI) {
370 bool SupportsSelectionDAGSP = false;
371 IRBuilder<> B(&F->getEntryBlock().front());
372 PointerType *PtrTy = Type::getInt8PtrTy(RI->getContext());
373 AI = B.CreateAlloca(PtrTy, nullptr, "StackGuardSlot");
374
375 Value *GuardSlot = getStackGuard(TLI, M, B, &SupportsSelectionDAGSP);
376 B.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackprotector),
377 {GuardSlot, AI});
378 return SupportsSelectionDAGSP;
379}
380
381/// InsertStackProtectors - Insert code into the prologue and epilogue of the
382/// function.
383///
384/// - The prologue code loads and stores the stack guard onto the stack.
385/// - The epilogue checks the value stored in the prologue against the original
386/// value. It calls __stack_chk_fail if they differ.
387bool StackProtector::InsertStackProtectors() {
388 // If the target wants to XOR the frame pointer into the guard value, it's
389 // impossible to emit the check in IR, so the target *must* support stack
390 // protection in SDAG.
391 bool SupportsSelectionDAGSP =
392 TLI->useStackGuardXorFP() ||
10
Assuming the condition is false
393 (EnableSelectionDAGSP && !TM->Options.EnableFastISel);
11
Assuming the condition is false
394 AllocaInst *AI = nullptr; // Place on stack that stores the stack guard.
12
'AI' initialized to a null pointer value
395
396 for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
13
Loop condition is true. Entering loop body
397 BasicBlock *BB = &*I++;
398 ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator());
399 if (!RI)
14
Assuming 'RI' is non-null
15
Taking false branch
400 continue;
401
402 // Generate prologue instrumentation if not already generated.
403 if (!HasPrologue) {
16
Assuming the condition is false
17
Taking false branch
404 HasPrologue = true;
405 SupportsSelectionDAGSP &= CreatePrologue(F, M, RI, TLI, AI);
406 }
407
408 // SelectionDAG based code generation. Nothing else needs to be done here.
409 // The epilogue instrumentation is postponed to SelectionDAG.
410 if (SupportsSelectionDAGSP)
18
Taking false branch
411 break;
412
413 // Set HasIRCheck to true, so that SelectionDAG will not generate its own
414 // version. SelectionDAG called 'shouldEmitSDCheck' to check whether
415 // instrumentation has already been generated.
416 HasIRCheck = true;
417
418 // Generate epilogue instrumentation. The epilogue intrumentation can be
419 // function-based or inlined depending on which mechanism the target is
420 // providing.
421 if (Value* GuardCheck = TLI->getSSPStackGuardCheck(*M)) {
19
Assuming 'GuardCheck' is non-null
20
Taking true branch
422 // Generate the function-based epilogue instrumentation.
423 // The target provides a guard check function, generate a call to it.
424 IRBuilder<> B(RI);
425 LoadInst *Guard = B.CreateLoad(AI, true, "Guard");
21
Passing null pointer value via 1st parameter 'Ptr'
22
Calling 'IRBuilder::CreateLoad'
426 CallInst *Call = B.CreateCall(GuardCheck, {Guard});
427 llvm::Function *Function = cast<llvm::Function>(GuardCheck);
428 Call->setAttributes(Function->getAttributes());
429 Call->setCallingConv(Function->getCallingConv());
430 } else {
431 // Generate the epilogue with inline instrumentation.
432 // If we do not support SelectionDAG based tail calls, generate IR level
433 // tail calls.
434 //
435 // For each block with a return instruction, convert this:
436 //
437 // return:
438 // ...
439 // ret ...
440 //
441 // into this:
442 //
443 // return:
444 // ...
445 // %1 = <stack guard>
446 // %2 = load StackGuardSlot
447 // %3 = cmp i1 %1, %2
448 // br i1 %3, label %SP_return, label %CallStackCheckFailBlk
449 //
450 // SP_return:
451 // ret ...
452 //
453 // CallStackCheckFailBlk:
454 // call void @__stack_chk_fail()
455 // unreachable
456
457 // Create the FailBB. We duplicate the BB every time since the MI tail
458 // merge pass will merge together all of the various BB into one including
459 // fail BB generated by the stack protector pseudo instruction.
460 BasicBlock *FailBB = CreateFailBB();
461
462 // Split the basic block before the return instruction.
463 BasicBlock *NewBB = BB->splitBasicBlock(RI->getIterator(), "SP_return");
464
465 // Update the dominator tree if we need to.
466 if (DT && DT->isReachableFromEntry(BB)) {
467 DT->addNewBlock(NewBB, BB);
468 DT->addNewBlock(FailBB, BB);
469 }
470
471 // Remove default branch instruction to the new BB.
472 BB->getTerminator()->eraseFromParent();
473
474 // Move the newly created basic block to the point right after the old
475 // basic block so that it's in the "fall through" position.
476 NewBB->moveAfter(BB);
477
478 // Generate the stack protector instructions in the old basic block.
479 IRBuilder<> B(BB);
480 Value *Guard = getStackGuard(TLI, M, B);
481 LoadInst *LI2 = B.CreateLoad(AI, true);
482 Value *Cmp = B.CreateICmpEQ(Guard, LI2);
483 auto SuccessProb =
484 BranchProbabilityInfo::getBranchProbStackProtector(true);
485 auto FailureProb =
486 BranchProbabilityInfo::getBranchProbStackProtector(false);
487 MDNode *Weights = MDBuilder(F->getContext())
488 .createBranchWeights(SuccessProb.getNumerator(),
489 FailureProb.getNumerator());
490 B.CreateCondBr(Cmp, NewBB, FailBB, Weights);
491 }
492 }
493
494 // Return if we didn't modify any basic blocks. i.e., there are no return
495 // statements in the function.
496 return HasPrologue;
497}
498
499/// CreateFailBB - Create a basic block to jump to when the stack protector
500/// check fails.
501BasicBlock *StackProtector::CreateFailBB() {
502 LLVMContext &Context = F->getContext();
503 BasicBlock *FailBB = BasicBlock::Create(Context, "CallStackCheckFailBlk", F);
504 IRBuilder<> B(FailBB);
505 B.SetCurrentDebugLocation(DebugLoc::get(0, 0, F->getSubprogram()));
506 if (Trip.isOSOpenBSD()) {
507 Constant *StackChkFail =
508 M->getOrInsertFunction("__stack_smash_handler",
509 Type::getVoidTy(Context),
510 Type::getInt8PtrTy(Context));
511
512 B.CreateCall(StackChkFail, B.CreateGlobalStringPtr(F->getName(), "SSH"));
513 } else {
514 Constant *StackChkFail =
515 M->getOrInsertFunction("__stack_chk_fail", Type::getVoidTy(Context));
516
517 B.CreateCall(StackChkFail, {});
518 }
519 B.CreateUnreachable();
520 return FailBB;
521}
522
523bool StackProtector::shouldEmitSDCheck(const BasicBlock &BB) const {
524 return HasPrologue && !HasIRCheck && dyn_cast<ReturnInst>(BB.getTerminator());
525}

/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h

1//===---- llvm/IRBuilder.h - Builder for LLVM Instructions ------*- 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 IRBuilder class, which is used as a convenient way
11// to create LLVM instructions with a consistent and simplified interface.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_IRBUILDER_H
16#define LLVM_IR_IRBUILDER_H
17
18#include "llvm-c/Types.h"
19#include "llvm/ADT/ArrayRef.h"
20#include "llvm/ADT/None.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/ADT/Twine.h"
23#include "llvm/IR/BasicBlock.h"
24#include "llvm/IR/Constant.h"
25#include "llvm/IR/ConstantFolder.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/DataLayout.h"
28#include "llvm/IR/DebugLoc.h"
29#include "llvm/IR/DerivedTypes.h"
30#include "llvm/IR/Function.h"
31#include "llvm/IR/GlobalVariable.h"
32#include "llvm/IR/InstrTypes.h"
33#include "llvm/IR/Instruction.h"
34#include "llvm/IR/Instructions.h"
35#include "llvm/IR/Intrinsics.h"
36#include "llvm/IR/LLVMContext.h"
37#include "llvm/IR/Module.h"
38#include "llvm/IR/Operator.h"
39#include "llvm/IR/Type.h"
40#include "llvm/IR/Value.h"
41#include "llvm/IR/ValueHandle.h"
42#include "llvm/Support/AtomicOrdering.h"
43#include "llvm/Support/CBindingWrapping.h"
44#include "llvm/Support/Casting.h"
45#include <algorithm>
46#include <cassert>
47#include <cstddef>
48#include <cstdint>
49#include <functional>
50
51namespace llvm {
52
53class APInt;
54class MDNode;
55class Module;
56class Use;
57
58/// \brief This provides the default implementation of the IRBuilder
59/// 'InsertHelper' method that is called whenever an instruction is created by
60/// IRBuilder and needs to be inserted.
61///
62/// By default, this inserts the instruction at the insertion point.
63class IRBuilderDefaultInserter {
64protected:
65 void InsertHelper(Instruction *I, const Twine &Name,
66 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
67 if (BB) BB->getInstList().insert(InsertPt, I);
68 I->setName(Name);
69 }
70};
71
72/// Provides an 'InsertHelper' that calls a user-provided callback after
73/// performing the default insertion.
74class IRBuilderCallbackInserter : IRBuilderDefaultInserter {
75 std::function<void(Instruction *)> Callback;
76
77public:
78 IRBuilderCallbackInserter(std::function<void(Instruction *)> Callback)
79 : Callback(std::move(Callback)) {}
80
81protected:
82 void InsertHelper(Instruction *I, const Twine &Name,
83 BasicBlock *BB, BasicBlock::iterator InsertPt) const {
84 IRBuilderDefaultInserter::InsertHelper(I, Name, BB, InsertPt);
85 Callback(I);
86 }
87};
88
89/// \brief Common base class shared among various IRBuilders.
90class IRBuilderBase {
91 DebugLoc CurDbgLocation;
92
93protected:
94 BasicBlock *BB;
95 BasicBlock::iterator InsertPt;
96 LLVMContext &Context;
97
98 MDNode *DefaultFPMathTag;
99 FastMathFlags FMF;
100
101 ArrayRef<OperandBundleDef> DefaultOperandBundles;
102
103public:
104 IRBuilderBase(LLVMContext &context, MDNode *FPMathTag = nullptr,
105 ArrayRef<OperandBundleDef> OpBundles = None)
106 : Context(context), DefaultFPMathTag(FPMathTag),
107 DefaultOperandBundles(OpBundles) {
108 ClearInsertionPoint();
109 }
110
111 //===--------------------------------------------------------------------===//
112 // Builder configuration methods
113 //===--------------------------------------------------------------------===//
114
115 /// \brief Clear the insertion point: created instructions will not be
116 /// inserted into a block.
117 void ClearInsertionPoint() {
118 BB = nullptr;
119 InsertPt = BasicBlock::iterator();
120 }
121
122 BasicBlock *GetInsertBlock() const { return BB; }
123 BasicBlock::iterator GetInsertPoint() const { return InsertPt; }
124 LLVMContext &getContext() const { return Context; }
125
126 /// \brief This specifies that created instructions should be appended to the
127 /// end of the specified block.
128 void SetInsertPoint(BasicBlock *TheBB) {
129 BB = TheBB;
130 InsertPt = BB->end();
131 }
132
133 /// \brief This specifies that created instructions should be inserted before
134 /// the specified instruction.
135 void SetInsertPoint(Instruction *I) {
136 BB = I->getParent();
137 InsertPt = I->getIterator();
138 assert(InsertPt != BB->end() && "Can't read debug loc from end()")(static_cast <bool> (InsertPt != BB->end() &&
"Can't read debug loc from end()") ? void (0) : __assert_fail
("InsertPt != BB->end() && \"Can't read debug loc from end()\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 138, __extension__ __PRETTY_FUNCTION__))
;
139 SetCurrentDebugLocation(I->getDebugLoc());
140 }
141
142 /// \brief This specifies that created instructions should be inserted at the
143 /// specified point.
144 void SetInsertPoint(BasicBlock *TheBB, BasicBlock::iterator IP) {
145 BB = TheBB;
146 InsertPt = IP;
147 if (IP != TheBB->end())
148 SetCurrentDebugLocation(IP->getDebugLoc());
149 }
150
151 /// \brief Set location information used by debugging information.
152 void SetCurrentDebugLocation(DebugLoc L) { CurDbgLocation = std::move(L); }
153
154 /// \brief Get location information used by debugging information.
155 const DebugLoc &getCurrentDebugLocation() const { return CurDbgLocation; }
156
157 /// \brief If this builder has a current debug location, set it on the
158 /// specified instruction.
159 void SetInstDebugLocation(Instruction *I) const {
160 if (CurDbgLocation)
161 I->setDebugLoc(CurDbgLocation);
162 }
163
164 /// \brief Get the return type of the current function that we're emitting
165 /// into.
166 Type *getCurrentFunctionReturnType() const;
167
168 /// InsertPoint - A saved insertion point.
169 class InsertPoint {
170 BasicBlock *Block = nullptr;
171 BasicBlock::iterator Point;
172
173 public:
174 /// \brief Creates a new insertion point which doesn't point to anything.
175 InsertPoint() = default;
176
177 /// \brief Creates a new insertion point at the given location.
178 InsertPoint(BasicBlock *InsertBlock, BasicBlock::iterator InsertPoint)
179 : Block(InsertBlock), Point(InsertPoint) {}
180
181 /// \brief Returns true if this insert point is set.
182 bool isSet() const { return (Block != nullptr); }
183
184 BasicBlock *getBlock() const { return Block; }
185 BasicBlock::iterator getPoint() const { return Point; }
186 };
187
188 /// \brief Returns the current insert point.
189 InsertPoint saveIP() const {
190 return InsertPoint(GetInsertBlock(), GetInsertPoint());
191 }
192
193 /// \brief Returns the current insert point, clearing it in the process.
194 InsertPoint saveAndClearIP() {
195 InsertPoint IP(GetInsertBlock(), GetInsertPoint());
196 ClearInsertionPoint();
197 return IP;
198 }
199
200 /// \brief Sets the current insert point to a previously-saved location.
201 void restoreIP(InsertPoint IP) {
202 if (IP.isSet())
203 SetInsertPoint(IP.getBlock(), IP.getPoint());
204 else
205 ClearInsertionPoint();
206 }
207
208 /// \brief Get the floating point math metadata being used.
209 MDNode *getDefaultFPMathTag() const { return DefaultFPMathTag; }
210
211 /// \brief Get the flags to be applied to created floating point ops
212 FastMathFlags getFastMathFlags() const { return FMF; }
213
214 /// \brief Clear the fast-math flags.
215 void clearFastMathFlags() { FMF.clear(); }
216
217 /// \brief Set the floating point math metadata to be used.
218 void setDefaultFPMathTag(MDNode *FPMathTag) { DefaultFPMathTag = FPMathTag; }
219
220 /// \brief Set the fast-math flags to be used with generated fp-math operators
221 void setFastMathFlags(FastMathFlags NewFMF) { FMF = NewFMF; }
222
223 //===--------------------------------------------------------------------===//
224 // RAII helpers.
225 //===--------------------------------------------------------------------===//
226
227 // \brief RAII object that stores the current insertion point and restores it
228 // when the object is destroyed. This includes the debug location.
229 class InsertPointGuard {
230 IRBuilderBase &Builder;
231 AssertingVH<BasicBlock> Block;
232 BasicBlock::iterator Point;
233 DebugLoc DbgLoc;
234
235 public:
236 InsertPointGuard(IRBuilderBase &B)
237 : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
238 DbgLoc(B.getCurrentDebugLocation()) {}
239
240 InsertPointGuard(const InsertPointGuard &) = delete;
241 InsertPointGuard &operator=(const InsertPointGuard &) = delete;
242
243 ~InsertPointGuard() {
244 Builder.restoreIP(InsertPoint(Block, Point));
245 Builder.SetCurrentDebugLocation(DbgLoc);
246 }
247 };
248
249 // \brief RAII object that stores the current fast math settings and restores
250 // them when the object is destroyed.
251 class FastMathFlagGuard {
252 IRBuilderBase &Builder;
253 FastMathFlags FMF;
254 MDNode *FPMathTag;
255
256 public:
257 FastMathFlagGuard(IRBuilderBase &B)
258 : Builder(B), FMF(B.FMF), FPMathTag(B.DefaultFPMathTag) {}
259
260 FastMathFlagGuard(const FastMathFlagGuard &) = delete;
261 FastMathFlagGuard &operator=(const FastMathFlagGuard &) = delete;
262
263 ~FastMathFlagGuard() {
264 Builder.FMF = FMF;
265 Builder.DefaultFPMathTag = FPMathTag;
266 }
267 };
268
269 //===--------------------------------------------------------------------===//
270 // Miscellaneous creation methods.
271 //===--------------------------------------------------------------------===//
272
273 /// \brief Make a new global variable with initializer type i8*
274 ///
275 /// Make a new global variable with an initializer that has array of i8 type
276 /// filled in with the null terminated string value specified. The new global
277 /// variable will be marked mergable with any others of the same contents. If
278 /// Name is specified, it is the name of the global variable created.
279 GlobalVariable *CreateGlobalString(StringRef Str, const Twine &Name = "",
280 unsigned AddressSpace = 0);
281
282 /// \brief Get a constant value representing either true or false.
283 ConstantInt *getInt1(bool V) {
284 return ConstantInt::get(getInt1Ty(), V);
285 }
286
287 /// \brief Get the constant value for i1 true.
288 ConstantInt *getTrue() {
289 return ConstantInt::getTrue(Context);
290 }
291
292 /// \brief Get the constant value for i1 false.
293 ConstantInt *getFalse() {
294 return ConstantInt::getFalse(Context);
295 }
296
297 /// \brief Get a constant 8-bit value.
298 ConstantInt *getInt8(uint8_t C) {
299 return ConstantInt::get(getInt8Ty(), C);
300 }
301
302 /// \brief Get a constant 16-bit value.
303 ConstantInt *getInt16(uint16_t C) {
304 return ConstantInt::get(getInt16Ty(), C);
305 }
306
307 /// \brief Get a constant 32-bit value.
308 ConstantInt *getInt32(uint32_t C) {
309 return ConstantInt::get(getInt32Ty(), C);
310 }
311
312 /// \brief Get a constant 64-bit value.
313 ConstantInt *getInt64(uint64_t C) {
314 return ConstantInt::get(getInt64Ty(), C);
315 }
316
317 /// \brief Get a constant N-bit value, zero extended or truncated from
318 /// a 64-bit value.
319 ConstantInt *getIntN(unsigned N, uint64_t C) {
320 return ConstantInt::get(getIntNTy(N), C);
321 }
322
323 /// \brief Get a constant integer value.
324 ConstantInt *getInt(const APInt &AI) {
325 return ConstantInt::get(Context, AI);
326 }
327
328 //===--------------------------------------------------------------------===//
329 // Type creation methods
330 //===--------------------------------------------------------------------===//
331
332 /// \brief Fetch the type representing a single bit
333 IntegerType *getInt1Ty() {
334 return Type::getInt1Ty(Context);
335 }
336
337 /// \brief Fetch the type representing an 8-bit integer.
338 IntegerType *getInt8Ty() {
339 return Type::getInt8Ty(Context);
340 }
341
342 /// \brief Fetch the type representing a 16-bit integer.
343 IntegerType *getInt16Ty() {
344 return Type::getInt16Ty(Context);
345 }
346
347 /// \brief Fetch the type representing a 32-bit integer.
348 IntegerType *getInt32Ty() {
349 return Type::getInt32Ty(Context);
350 }
351
352 /// \brief Fetch the type representing a 64-bit integer.
353 IntegerType *getInt64Ty() {
354 return Type::getInt64Ty(Context);
355 }
356
357 /// \brief Fetch the type representing a 128-bit integer.
358 IntegerType *getInt128Ty() { return Type::getInt128Ty(Context); }
359
360 /// \brief Fetch the type representing an N-bit integer.
361 IntegerType *getIntNTy(unsigned N) {
362 return Type::getIntNTy(Context, N);
363 }
364
365 /// \brief Fetch the type representing a 16-bit floating point value.
366 Type *getHalfTy() {
367 return Type::getHalfTy(Context);
368 }
369
370 /// \brief Fetch the type representing a 32-bit floating point value.
371 Type *getFloatTy() {
372 return Type::getFloatTy(Context);
373 }
374
375 /// \brief Fetch the type representing a 64-bit floating point value.
376 Type *getDoubleTy() {
377 return Type::getDoubleTy(Context);
378 }
379
380 /// \brief Fetch the type representing void.
381 Type *getVoidTy() {
382 return Type::getVoidTy(Context);
383 }
384
385 /// \brief Fetch the type representing a pointer to an 8-bit integer value.
386 PointerType *getInt8PtrTy(unsigned AddrSpace = 0) {
387 return Type::getInt8PtrTy(Context, AddrSpace);
388 }
389
390 /// \brief Fetch the type representing a pointer to an integer value.
391 IntegerType *getIntPtrTy(const DataLayout &DL, unsigned AddrSpace = 0) {
392 return DL.getIntPtrType(Context, AddrSpace);
393 }
394
395 //===--------------------------------------------------------------------===//
396 // Intrinsic creation methods
397 //===--------------------------------------------------------------------===//
398
399 /// \brief Create and insert a memset to the specified pointer and the
400 /// specified value.
401 ///
402 /// If the pointer isn't an i8*, it will be converted. If a TBAA tag is
403 /// specified, it will be added to the instruction. Likewise with alias.scope
404 /// and noalias tags.
405 CallInst *CreateMemSet(Value *Ptr, Value *Val, uint64_t Size, unsigned Align,
406 bool isVolatile = false, MDNode *TBAATag = nullptr,
407 MDNode *ScopeTag = nullptr,
408 MDNode *NoAliasTag = nullptr) {
409 return CreateMemSet(Ptr, Val, getInt64(Size), Align, isVolatile,
410 TBAATag, ScopeTag, NoAliasTag);
411 }
412
413 CallInst *CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
414 bool isVolatile = false, MDNode *TBAATag = nullptr,
415 MDNode *ScopeTag = nullptr,
416 MDNode *NoAliasTag = nullptr);
417
418 /// \brief Create and insert a memcpy between the specified pointers.
419 ///
420 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
421 /// specified, it will be added to the instruction. Likewise with alias.scope
422 /// and noalias tags.
423 CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
424 unsigned SrcAlign, uint64_t Size,
425 bool isVolatile = false, MDNode *TBAATag = nullptr,
426 MDNode *TBAAStructTag = nullptr,
427 MDNode *ScopeTag = nullptr,
428 MDNode *NoAliasTag = nullptr) {
429 return CreateMemCpy(Dst, DstAlign, Src, SrcAlign, getInt64(Size),
430 isVolatile, TBAATag, TBAAStructTag, ScopeTag,
431 NoAliasTag);
432 }
433
434 CallInst *CreateMemCpy(Value *Dst, unsigned DstAlign, Value *Src,
435 unsigned SrcAlign, Value *Size,
436 bool isVolatile = false, MDNode *TBAATag = nullptr,
437 MDNode *TBAAStructTag = nullptr,
438 MDNode *ScopeTag = nullptr,
439 MDNode *NoAliasTag = nullptr);
440
441 // TODO: Old API. Remove this when no longer used.
442 CallInst *CreateMemCpy(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
443 bool isVolatile = false, MDNode *TBAATag = nullptr,
444 MDNode *TBAAStructTag = nullptr,
445 MDNode *ScopeTag = nullptr,
446 MDNode *NoAliasTag = nullptr) {
447 return CreateMemCpy(Dst, Align, Src, Align, getInt64(Size), isVolatile, TBAATag,
448 TBAAStructTag, ScopeTag, NoAliasTag);
449 }
450 // TODO: Old API. Remove this when no longer used.
451 CallInst *CreateMemCpy(Value *Dst, Value *Src, Value *Size, unsigned Align,
452 bool isVolatile = false, MDNode *TBAATag = nullptr,
453 MDNode *TBAAStructTag = nullptr,
454 MDNode *ScopeTag = nullptr,
455 MDNode *NoAliasTag = nullptr) {
456 return CreateMemCpy(Dst, Align, Src, Align, Size, isVolatile, TBAATag,
457 TBAAStructTag, ScopeTag, NoAliasTag);
458 }
459
460 /// \brief Create and insert an element unordered-atomic memcpy between the
461 /// specified pointers.
462 ///
463 /// DstAlign/SrcAlign are the alignments of the Dst/Src pointers, respectively.
464 ///
465 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
466 /// specified, it will be added to the instruction. Likewise with alias.scope
467 /// and noalias tags.
468 CallInst *CreateElementUnorderedAtomicMemCpy(
469 Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
470 uint64_t Size, uint32_t ElementSize, MDNode *TBAATag = nullptr,
471 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
472 MDNode *NoAliasTag = nullptr) {
473 return CreateElementUnorderedAtomicMemCpy(
474 Dst, DstAlign, Src, SrcAlign, getInt64(Size), ElementSize, TBAATag,
475 TBAAStructTag, ScopeTag, NoAliasTag);
476 }
477
478 CallInst *CreateElementUnorderedAtomicMemCpy(
479 Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign, Value *Size,
480 uint32_t ElementSize, MDNode *TBAATag = nullptr,
481 MDNode *TBAAStructTag = nullptr, MDNode *ScopeTag = nullptr,
482 MDNode *NoAliasTag = nullptr);
483
484 /// \brief Create and insert a memmove between the specified
485 /// pointers.
486 ///
487 /// If the pointers aren't i8*, they will be converted. If a TBAA tag is
488 /// specified, it will be added to the instruction. Likewise with alias.scope
489 /// and noalias tags.
490 CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
491 uint64_t Size, bool isVolatile = false,
492 MDNode *TBAATag = nullptr, MDNode *ScopeTag = nullptr,
493 MDNode *NoAliasTag = nullptr) {
494 return CreateMemMove(Dst, DstAlign, Src, SrcAlign, getInt64(Size), isVolatile,
495 TBAATag, ScopeTag, NoAliasTag);
496 }
497
498 CallInst *CreateMemMove(Value *Dst, unsigned DstAlign, Value *Src, unsigned SrcAlign,
499 Value *Size, bool isVolatile = false, MDNode *TBAATag = nullptr,
500 MDNode *ScopeTag = nullptr,
501 MDNode *NoAliasTag = nullptr);
502
503 // TODO: Old API. Remove this when no longer used.
504 CallInst *CreateMemMove(Value *Dst, Value *Src, uint64_t Size, unsigned Align,
505 bool isVolatile = false, MDNode *TBAATag = nullptr,
506 MDNode *ScopeTag = nullptr,
507 MDNode *NoAliasTag = nullptr) {
508 return CreateMemMove(Dst, Align, Src, Align, getInt64(Size), isVolatile,
509 TBAATag, ScopeTag, NoAliasTag);
510 }
511 // TODO: Old API. Remove this when no longer used.
512 CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
513 bool isVolatile = false, MDNode *TBAATag = nullptr,
514 MDNode *ScopeTag = nullptr,
515 MDNode *NoAliasTag = nullptr) {
516 return CreateMemMove(Dst, Align, Src, Align, Size, isVolatile, TBAATag,
517 ScopeTag, NoAliasTag);
518 }
519
520 /// \brief Create a vector fadd reduction intrinsic of the source vector.
521 /// The first parameter is a scalar accumulator value for ordered reductions.
522 CallInst *CreateFAddReduce(Value *Acc, Value *Src);
523
524 /// \brief Create a vector fmul reduction intrinsic of the source vector.
525 /// The first parameter is a scalar accumulator value for ordered reductions.
526 CallInst *CreateFMulReduce(Value *Acc, Value *Src);
527
528 /// \brief Create a vector int add reduction intrinsic of the source vector.
529 CallInst *CreateAddReduce(Value *Src);
530
531 /// \brief Create a vector int mul reduction intrinsic of the source vector.
532 CallInst *CreateMulReduce(Value *Src);
533
534 /// \brief Create a vector int AND reduction intrinsic of the source vector.
535 CallInst *CreateAndReduce(Value *Src);
536
537 /// \brief Create a vector int OR reduction intrinsic of the source vector.
538 CallInst *CreateOrReduce(Value *Src);
539
540 /// \brief Create a vector int XOR reduction intrinsic of the source vector.
541 CallInst *CreateXorReduce(Value *Src);
542
543 /// \brief Create a vector integer max reduction intrinsic of the source
544 /// vector.
545 CallInst *CreateIntMaxReduce(Value *Src, bool IsSigned = false);
546
547 /// \brief Create a vector integer min reduction intrinsic of the source
548 /// vector.
549 CallInst *CreateIntMinReduce(Value *Src, bool IsSigned = false);
550
551 /// \brief Create a vector float max reduction intrinsic of the source
552 /// vector.
553 CallInst *CreateFPMaxReduce(Value *Src, bool NoNaN = false);
554
555 /// \brief Create a vector float min reduction intrinsic of the source
556 /// vector.
557 CallInst *CreateFPMinReduce(Value *Src, bool NoNaN = false);
558
559 /// \brief Create a lifetime.start intrinsic.
560 ///
561 /// If the pointer isn't i8* it will be converted.
562 CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = nullptr);
563
564 /// \brief Create a lifetime.end intrinsic.
565 ///
566 /// If the pointer isn't i8* it will be converted.
567 CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = nullptr);
568
569 /// Create a call to invariant.start intrinsic.
570 ///
571 /// If the pointer isn't i8* it will be converted.
572 CallInst *CreateInvariantStart(Value *Ptr, ConstantInt *Size = nullptr);
573
574 /// \brief Create a call to Masked Load intrinsic
575 CallInst *CreateMaskedLoad(Value *Ptr, unsigned Align, Value *Mask,
576 Value *PassThru = nullptr, const Twine &Name = "");
577
578 /// \brief Create a call to Masked Store intrinsic
579 CallInst *CreateMaskedStore(Value *Val, Value *Ptr, unsigned Align,
580 Value *Mask);
581
582 /// \brief Create a call to Masked Gather intrinsic
583 CallInst *CreateMaskedGather(Value *Ptrs, unsigned Align,
584 Value *Mask = nullptr,
585 Value *PassThru = nullptr,
586 const Twine& Name = "");
587
588 /// \brief Create a call to Masked Scatter intrinsic
589 CallInst *CreateMaskedScatter(Value *Val, Value *Ptrs, unsigned Align,
590 Value *Mask = nullptr);
591
592 /// \brief Create an assume intrinsic call that allows the optimizer to
593 /// assume that the provided condition will be true.
594 CallInst *CreateAssumption(Value *Cond);
595
596 /// \brief Create a call to the experimental.gc.statepoint intrinsic to
597 /// start a new statepoint sequence.
598 CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
599 Value *ActualCallee,
600 ArrayRef<Value *> CallArgs,
601 ArrayRef<Value *> DeoptArgs,
602 ArrayRef<Value *> GCArgs,
603 const Twine &Name = "");
604
605 /// \brief Create a call to the experimental.gc.statepoint intrinsic to
606 /// start a new statepoint sequence.
607 CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
608 Value *ActualCallee, uint32_t Flags,
609 ArrayRef<Use> CallArgs,
610 ArrayRef<Use> TransitionArgs,
611 ArrayRef<Use> DeoptArgs,
612 ArrayRef<Value *> GCArgs,
613 const Twine &Name = "");
614
615 // \brief Conveninence function for the common case when CallArgs are filled
616 // in using makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be
617 // .get()'ed to get the Value pointer.
618 CallInst *CreateGCStatepointCall(uint64_t ID, uint32_t NumPatchBytes,
619 Value *ActualCallee, ArrayRef<Use> CallArgs,
620 ArrayRef<Value *> DeoptArgs,
621 ArrayRef<Value *> GCArgs,
622 const Twine &Name = "");
623
624 /// brief Create an invoke to the experimental.gc.statepoint intrinsic to
625 /// start a new statepoint sequence.
626 InvokeInst *
627 CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
628 Value *ActualInvokee, BasicBlock *NormalDest,
629 BasicBlock *UnwindDest, ArrayRef<Value *> InvokeArgs,
630 ArrayRef<Value *> DeoptArgs,
631 ArrayRef<Value *> GCArgs, const Twine &Name = "");
632
633 /// brief Create an invoke to the experimental.gc.statepoint intrinsic to
634 /// start a new statepoint sequence.
635 InvokeInst *CreateGCStatepointInvoke(
636 uint64_t ID, uint32_t NumPatchBytes, Value *ActualInvokee,
637 BasicBlock *NormalDest, BasicBlock *UnwindDest, uint32_t Flags,
638 ArrayRef<Use> InvokeArgs, ArrayRef<Use> TransitionArgs,
639 ArrayRef<Use> DeoptArgs, ArrayRef<Value *> GCArgs,
640 const Twine &Name = "");
641
642 // Conveninence function for the common case when CallArgs are filled in using
643 // makeArrayRef(CS.arg_begin(), CS.arg_end()); Use needs to be .get()'ed to
644 // get the Value *.
645 InvokeInst *
646 CreateGCStatepointInvoke(uint64_t ID, uint32_t NumPatchBytes,
647 Value *ActualInvokee, BasicBlock *NormalDest,
648 BasicBlock *UnwindDest, ArrayRef<Use> InvokeArgs,
649 ArrayRef<Value *> DeoptArgs,
650 ArrayRef<Value *> GCArgs, const Twine &Name = "");
651
652 /// \brief Create a call to the experimental.gc.result intrinsic to extract
653 /// the result from a call wrapped in a statepoint.
654 CallInst *CreateGCResult(Instruction *Statepoint,
655 Type *ResultType,
656 const Twine &Name = "");
657
658 /// \brief Create a call to the experimental.gc.relocate intrinsics to
659 /// project the relocated value of one pointer from the statepoint.
660 CallInst *CreateGCRelocate(Instruction *Statepoint,
661 int BaseOffset,
662 int DerivedOffset,
663 Type *ResultType,
664 const Twine &Name = "");
665
666 /// Create a call to intrinsic \p ID with 2 operands which is mangled on the
667 /// first type.
668 CallInst *CreateBinaryIntrinsic(Intrinsic::ID ID,
669 Value *LHS, Value *RHS,
670 const Twine &Name = "");
671
672 /// Create a call to intrinsic \p ID with 1 or more operands assuming the
673 /// intrinsic and all operands have the same type. If \p FMFSource is
674 /// provided, copy fast-math-flags from that instruction to the intrinsic.
675 CallInst *CreateIntrinsic(Intrinsic::ID ID, ArrayRef<Value *> Args,
676 Instruction *FMFSource = nullptr,
677 const Twine &Name = "");
678
679 /// Create call to the minnum intrinsic.
680 CallInst *CreateMinNum(Value *LHS, Value *RHS, const Twine &Name = "") {
681 return CreateBinaryIntrinsic(Intrinsic::minnum, LHS, RHS, Name);
682 }
683
684 /// Create call to the maxnum intrinsic.
685 CallInst *CreateMaxNum(Value *LHS, Value *RHS, const Twine &Name = "") {
686 return CreateBinaryIntrinsic(Intrinsic::maxnum, LHS, RHS, Name);
687 }
688
689private:
690 /// \brief Create a call to a masked intrinsic with given Id.
691 CallInst *CreateMaskedIntrinsic(Intrinsic::ID Id, ArrayRef<Value *> Ops,
692 ArrayRef<Type *> OverloadedTypes,
693 const Twine &Name = "");
694
695 Value *getCastedInt8PtrValue(Value *Ptr);
696};
697
698/// \brief This provides a uniform API for creating instructions and inserting
699/// them into a basic block: either at the end of a BasicBlock, or at a specific
700/// iterator location in a block.
701///
702/// Note that the builder does not expose the full generality of LLVM
703/// instructions. For access to extra instruction properties, use the mutators
704/// (e.g. setVolatile) on the instructions after they have been
705/// created. Convenience state exists to specify fast-math flags and fp-math
706/// tags.
707///
708/// The first template argument specifies a class to use for creating constants.
709/// This defaults to creating minimally folded constants. The second template
710/// argument allows clients to specify custom insertion hooks that are called on
711/// every newly created insertion.
712template <typename T = ConstantFolder,
713 typename Inserter = IRBuilderDefaultInserter>
714class IRBuilder : public IRBuilderBase, public Inserter {
715 T Folder;
716
717public:
718 IRBuilder(LLVMContext &C, const T &F, Inserter I = Inserter(),
719 MDNode *FPMathTag = nullptr,
720 ArrayRef<OperandBundleDef> OpBundles = None)
721 : IRBuilderBase(C, FPMathTag, OpBundles), Inserter(std::move(I)),
722 Folder(F) {}
723
724 explicit IRBuilder(LLVMContext &C, MDNode *FPMathTag = nullptr,
725 ArrayRef<OperandBundleDef> OpBundles = None)
726 : IRBuilderBase(C, FPMathTag, OpBundles), Folder() {}
727
728 explicit IRBuilder(BasicBlock *TheBB, const T &F, MDNode *FPMathTag = nullptr,
729 ArrayRef<OperandBundleDef> OpBundles = None)
730 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
731 SetInsertPoint(TheBB);
732 }
733
734 explicit IRBuilder(BasicBlock *TheBB, MDNode *FPMathTag = nullptr,
735 ArrayRef<OperandBundleDef> OpBundles = None)
736 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() {
737 SetInsertPoint(TheBB);
738 }
739
740 explicit IRBuilder(Instruction *IP, MDNode *FPMathTag = nullptr,
741 ArrayRef<OperandBundleDef> OpBundles = None)
742 : IRBuilderBase(IP->getContext(), FPMathTag, OpBundles), Folder() {
743 SetInsertPoint(IP);
744 }
745
746 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP, const T &F,
747 MDNode *FPMathTag = nullptr,
748 ArrayRef<OperandBundleDef> OpBundles = None)
749 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder(F) {
750 SetInsertPoint(TheBB, IP);
751 }
752
753 IRBuilder(BasicBlock *TheBB, BasicBlock::iterator IP,
754 MDNode *FPMathTag = nullptr,
755 ArrayRef<OperandBundleDef> OpBundles = None)
756 : IRBuilderBase(TheBB->getContext(), FPMathTag, OpBundles), Folder() {
757 SetInsertPoint(TheBB, IP);
758 }
759
760 /// \brief Get the constant folder being used.
761 const T &getFolder() { return Folder; }
762
763 /// \brief Insert and return the specified instruction.
764 template<typename InstTy>
765 InstTy *Insert(InstTy *I, const Twine &Name = "") const {
766 this->InsertHelper(I, Name, BB, InsertPt);
767 this->SetInstDebugLocation(I);
768 return I;
769 }
770
771 /// \brief No-op overload to handle constants.
772 Constant *Insert(Constant *C, const Twine& = "") const {
773 return C;
774 }
775
776 //===--------------------------------------------------------------------===//
777 // Instruction creation methods: Terminators
778 //===--------------------------------------------------------------------===//
779
780private:
781 /// \brief Helper to add branch weight and unpredictable metadata onto an
782 /// instruction.
783 /// \returns The annotated instruction.
784 template <typename InstTy>
785 InstTy *addBranchMetadata(InstTy *I, MDNode *Weights, MDNode *Unpredictable) {
786 if (Weights)
787 I->setMetadata(LLVMContext::MD_prof, Weights);
788 if (Unpredictable)
789 I->setMetadata(LLVMContext::MD_unpredictable, Unpredictable);
790 return I;
791 }
792
793public:
794 /// \brief Create a 'ret void' instruction.
795 ReturnInst *CreateRetVoid() {
796 return Insert(ReturnInst::Create(Context));
797 }
798
799 /// \brief Create a 'ret <val>' instruction.
800 ReturnInst *CreateRet(Value *V) {
801 return Insert(ReturnInst::Create(Context, V));
802 }
803
804 /// \brief Create a sequence of N insertvalue instructions,
805 /// with one Value from the retVals array each, that build a aggregate
806 /// return value one value at a time, and a ret instruction to return
807 /// the resulting aggregate value.
808 ///
809 /// This is a convenience function for code that uses aggregate return values
810 /// as a vehicle for having multiple return values.
811 ReturnInst *CreateAggregateRet(Value *const *retVals, unsigned N) {
812 Value *V = UndefValue::get(getCurrentFunctionReturnType());
813 for (unsigned i = 0; i != N; ++i)
814 V = CreateInsertValue(V, retVals[i], i, "mrv");
815 return Insert(ReturnInst::Create(Context, V));
816 }
817
818 /// \brief Create an unconditional 'br label X' instruction.
819 BranchInst *CreateBr(BasicBlock *Dest) {
820 return Insert(BranchInst::Create(Dest));
821 }
822
823 /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
824 /// instruction.
825 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
826 MDNode *BranchWeights = nullptr,
827 MDNode *Unpredictable = nullptr) {
828 return Insert(addBranchMetadata(BranchInst::Create(True, False, Cond),
829 BranchWeights, Unpredictable));
830 }
831
832 /// \brief Create a conditional 'br Cond, TrueDest, FalseDest'
833 /// instruction. Copy branch meta data if available.
834 BranchInst *CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False,
835 Instruction *MDSrc) {
836 BranchInst *Br = BranchInst::Create(True, False, Cond);
837 if (MDSrc) {
838 unsigned WL[4] = {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
839 LLVMContext::MD_make_implicit, LLVMContext::MD_dbg};
840 Br->copyMetadata(*MDSrc, makeArrayRef(&WL[0], 4));
841 }
842 return Insert(Br);
843 }
844
845 /// \brief Create a switch instruction with the specified value, default dest,
846 /// and with a hint for the number of cases that will be added (for efficient
847 /// allocation).
848 SwitchInst *CreateSwitch(Value *V, BasicBlock *Dest, unsigned NumCases = 10,
849 MDNode *BranchWeights = nullptr,
850 MDNode *Unpredictable = nullptr) {
851 return Insert(addBranchMetadata(SwitchInst::Create(V, Dest, NumCases),
852 BranchWeights, Unpredictable));
853 }
854
855 /// \brief Create an indirect branch instruction with the specified address
856 /// operand, with an optional hint for the number of destinations that will be
857 /// added (for efficient allocation).
858 IndirectBrInst *CreateIndirectBr(Value *Addr, unsigned NumDests = 10) {
859 return Insert(IndirectBrInst::Create(Addr, NumDests));
860 }
861
862 /// \brief Create an invoke instruction.
863 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
864 BasicBlock *UnwindDest,
865 ArrayRef<Value *> Args = None,
866 const Twine &Name = "") {
867 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args),
868 Name);
869 }
870 InvokeInst *CreateInvoke(Value *Callee, BasicBlock *NormalDest,
871 BasicBlock *UnwindDest, ArrayRef<Value *> Args,
872 ArrayRef<OperandBundleDef> OpBundles,
873 const Twine &Name = "") {
874 return Insert(InvokeInst::Create(Callee, NormalDest, UnwindDest, Args,
875 OpBundles), Name);
876 }
877
878 ResumeInst *CreateResume(Value *Exn) {
879 return Insert(ResumeInst::Create(Exn));
880 }
881
882 CleanupReturnInst *CreateCleanupRet(CleanupPadInst *CleanupPad,
883 BasicBlock *UnwindBB = nullptr) {
884 return Insert(CleanupReturnInst::Create(CleanupPad, UnwindBB));
885 }
886
887 CatchSwitchInst *CreateCatchSwitch(Value *ParentPad, BasicBlock *UnwindBB,
888 unsigned NumHandlers,
889 const Twine &Name = "") {
890 return Insert(CatchSwitchInst::Create(ParentPad, UnwindBB, NumHandlers),
891 Name);
892 }
893
894 CatchPadInst *CreateCatchPad(Value *ParentPad, ArrayRef<Value *> Args,
895 const Twine &Name = "") {
896 return Insert(CatchPadInst::Create(ParentPad, Args), Name);
897 }
898
899 CleanupPadInst *CreateCleanupPad(Value *ParentPad,
900 ArrayRef<Value *> Args = None,
901 const Twine &Name = "") {
902 return Insert(CleanupPadInst::Create(ParentPad, Args), Name);
903 }
904
905 CatchReturnInst *CreateCatchRet(CatchPadInst *CatchPad, BasicBlock *BB) {
906 return Insert(CatchReturnInst::Create(CatchPad, BB));
907 }
908
909 UnreachableInst *CreateUnreachable() {
910 return Insert(new UnreachableInst(Context));
911 }
912
913 //===--------------------------------------------------------------------===//
914 // Instruction creation methods: Binary Operators
915 //===--------------------------------------------------------------------===//
916private:
917 BinaryOperator *CreateInsertNUWNSWBinOp(BinaryOperator::BinaryOps Opc,
918 Value *LHS, Value *RHS,
919 const Twine &Name,
920 bool HasNUW, bool HasNSW) {
921 BinaryOperator *BO = Insert(BinaryOperator::Create(Opc, LHS, RHS), Name);
922 if (HasNUW) BO->setHasNoUnsignedWrap();
923 if (HasNSW) BO->setHasNoSignedWrap();
924 return BO;
925 }
926
927 Instruction *setFPAttrs(Instruction *I, MDNode *FPMD,
928 FastMathFlags FMF) const {
929 if (!FPMD)
930 FPMD = DefaultFPMathTag;
931 if (FPMD)
932 I->setMetadata(LLVMContext::MD_fpmath, FPMD);
933 I->setFastMathFlags(FMF);
934 return I;
935 }
936
937 Value *foldConstant(Instruction::BinaryOps Opc, Value *L,
938 Value *R, const Twine &Name = nullptr) const {
939 auto *LC = dyn_cast<Constant>(L);
940 auto *RC = dyn_cast<Constant>(R);
941 return (LC && RC) ? Insert(Folder.CreateBinOp(Opc, LC, RC), Name) : nullptr;
942 }
943
944public:
945 Value *CreateAdd(Value *LHS, Value *RHS, const Twine &Name = "",
946 bool HasNUW = false, bool HasNSW = false) {
947 if (Constant *LC = dyn_cast<Constant>(LHS))
948 if (Constant *RC = dyn_cast<Constant>(RHS))
949 return Insert(Folder.CreateAdd(LC, RC, HasNUW, HasNSW), Name);
950 return CreateInsertNUWNSWBinOp(Instruction::Add, LHS, RHS, Name,
951 HasNUW, HasNSW);
952 }
953 Value *CreateNSWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
954 return CreateAdd(LHS, RHS, Name, false, true);
955 }
956 Value *CreateNUWAdd(Value *LHS, Value *RHS, const Twine &Name = "") {
957 return CreateAdd(LHS, RHS, Name, true, false);
958 }
959 Value *CreateSub(Value *LHS, Value *RHS, const Twine &Name = "",
960 bool HasNUW = false, bool HasNSW = false) {
961 if (Constant *LC = dyn_cast<Constant>(LHS))
962 if (Constant *RC = dyn_cast<Constant>(RHS))
963 return Insert(Folder.CreateSub(LC, RC, HasNUW, HasNSW), Name);
964 return CreateInsertNUWNSWBinOp(Instruction::Sub, LHS, RHS, Name,
965 HasNUW, HasNSW);
966 }
967 Value *CreateNSWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
968 return CreateSub(LHS, RHS, Name, false, true);
969 }
970 Value *CreateNUWSub(Value *LHS, Value *RHS, const Twine &Name = "") {
971 return CreateSub(LHS, RHS, Name, true, false);
972 }
973 Value *CreateMul(Value *LHS, Value *RHS, const Twine &Name = "",
974 bool HasNUW = false, bool HasNSW = false) {
975 if (Constant *LC = dyn_cast<Constant>(LHS))
976 if (Constant *RC = dyn_cast<Constant>(RHS))
977 return Insert(Folder.CreateMul(LC, RC, HasNUW, HasNSW), Name);
978 return CreateInsertNUWNSWBinOp(Instruction::Mul, LHS, RHS, Name,
979 HasNUW, HasNSW);
980 }
981 Value *CreateNSWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
982 return CreateMul(LHS, RHS, Name, false, true);
983 }
984 Value *CreateNUWMul(Value *LHS, Value *RHS, const Twine &Name = "") {
985 return CreateMul(LHS, RHS, Name, true, false);
986 }
987 Value *CreateUDiv(Value *LHS, Value *RHS, const Twine &Name = "",
988 bool isExact = false) {
989 if (Constant *LC = dyn_cast<Constant>(LHS))
990 if (Constant *RC = dyn_cast<Constant>(RHS))
991 return Insert(Folder.CreateUDiv(LC, RC, isExact), Name);
992 if (!isExact)
993 return Insert(BinaryOperator::CreateUDiv(LHS, RHS), Name);
994 return Insert(BinaryOperator::CreateExactUDiv(LHS, RHS), Name);
995 }
996 Value *CreateExactUDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
997 return CreateUDiv(LHS, RHS, Name, true);
998 }
999 Value *CreateSDiv(Value *LHS, Value *RHS, const Twine &Name = "",
1000 bool isExact = false) {
1001 if (Constant *LC = dyn_cast<Constant>(LHS))
1002 if (Constant *RC = dyn_cast<Constant>(RHS))
1003 return Insert(Folder.CreateSDiv(LC, RC, isExact), Name);
1004 if (!isExact)
1005 return Insert(BinaryOperator::CreateSDiv(LHS, RHS), Name);
1006 return Insert(BinaryOperator::CreateExactSDiv(LHS, RHS), Name);
1007 }
1008 Value *CreateExactSDiv(Value *LHS, Value *RHS, const Twine &Name = "") {
1009 return CreateSDiv(LHS, RHS, Name, true);
1010 }
1011 Value *CreateURem(Value *LHS, Value *RHS, const Twine &Name = "") {
1012 if (Value *V = foldConstant(Instruction::URem, LHS, RHS, Name)) return V;
1013 return Insert(BinaryOperator::CreateURem(LHS, RHS), Name);
1014 }
1015 Value *CreateSRem(Value *LHS, Value *RHS, const Twine &Name = "") {
1016 if (Value *V = foldConstant(Instruction::SRem, LHS, RHS, Name)) return V;
1017 return Insert(BinaryOperator::CreateSRem(LHS, RHS), Name);
1018 }
1019 Value *CreateShl(Value *LHS, Value *RHS, const Twine &Name = "",
1020 bool HasNUW = false, bool HasNSW = false) {
1021 if (Constant *LC = dyn_cast<Constant>(LHS))
1022 if (Constant *RC = dyn_cast<Constant>(RHS))
1023 return Insert(Folder.CreateShl(LC, RC, HasNUW, HasNSW), Name);
1024 return CreateInsertNUWNSWBinOp(Instruction::Shl, LHS, RHS, Name,
1025 HasNUW, HasNSW);
1026 }
1027 Value *CreateShl(Value *LHS, const APInt &RHS, const Twine &Name = "",
1028 bool HasNUW = false, bool HasNSW = false) {
1029 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1030 HasNUW, HasNSW);
1031 }
1032 Value *CreateShl(Value *LHS, uint64_t RHS, const Twine &Name = "",
1033 bool HasNUW = false, bool HasNSW = false) {
1034 return CreateShl(LHS, ConstantInt::get(LHS->getType(), RHS), Name,
1035 HasNUW, HasNSW);
1036 }
1037
1038 Value *CreateLShr(Value *LHS, Value *RHS, const Twine &Name = "",
1039 bool isExact = false) {
1040 if (Constant *LC = dyn_cast<Constant>(LHS))
1041 if (Constant *RC = dyn_cast<Constant>(RHS))
1042 return Insert(Folder.CreateLShr(LC, RC, isExact), Name);
1043 if (!isExact)
1044 return Insert(BinaryOperator::CreateLShr(LHS, RHS), Name);
1045 return Insert(BinaryOperator::CreateExactLShr(LHS, RHS), Name);
1046 }
1047 Value *CreateLShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1048 bool isExact = false) {
1049 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1050 }
1051 Value *CreateLShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1052 bool isExact = false) {
1053 return CreateLShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1054 }
1055
1056 Value *CreateAShr(Value *LHS, Value *RHS, const Twine &Name = "",
1057 bool isExact = false) {
1058 if (Constant *LC = dyn_cast<Constant>(LHS))
1059 if (Constant *RC = dyn_cast<Constant>(RHS))
1060 return Insert(Folder.CreateAShr(LC, RC, isExact), Name);
1061 if (!isExact)
1062 return Insert(BinaryOperator::CreateAShr(LHS, RHS), Name);
1063 return Insert(BinaryOperator::CreateExactAShr(LHS, RHS), Name);
1064 }
1065 Value *CreateAShr(Value *LHS, const APInt &RHS, const Twine &Name = "",
1066 bool isExact = false) {
1067 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1068 }
1069 Value *CreateAShr(Value *LHS, uint64_t RHS, const Twine &Name = "",
1070 bool isExact = false) {
1071 return CreateAShr(LHS, ConstantInt::get(LHS->getType(), RHS), Name,isExact);
1072 }
1073
1074 Value *CreateAnd(Value *LHS, Value *RHS, const Twine &Name = "") {
1075 if (Constant *RC = dyn_cast<Constant>(RHS)) {
1076 if (isa<ConstantInt>(RC) && cast<ConstantInt>(RC)->isMinusOne())
1077 return LHS; // LHS & -1 -> LHS
1078 if (Constant *LC = dyn_cast<Constant>(LHS))
1079 return Insert(Folder.CreateAnd(LC, RC), Name);
1080 }
1081 return Insert(BinaryOperator::CreateAnd(LHS, RHS), Name);
1082 }
1083 Value *CreateAnd(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1084 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1085 }
1086 Value *CreateAnd(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1087 return CreateAnd(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1088 }
1089
1090 Value *CreateOr(Value *LHS, Value *RHS, const Twine &Name = "") {
1091 if (Constant *RC = dyn_cast<Constant>(RHS)) {
1092 if (RC->isNullValue())
1093 return LHS; // LHS | 0 -> LHS
1094 if (Constant *LC = dyn_cast<Constant>(LHS))
1095 return Insert(Folder.CreateOr(LC, RC), Name);
1096 }
1097 return Insert(BinaryOperator::CreateOr(LHS, RHS), Name);
1098 }
1099 Value *CreateOr(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1100 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1101 }
1102 Value *CreateOr(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1103 return CreateOr(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1104 }
1105
1106 Value *CreateXor(Value *LHS, Value *RHS, const Twine &Name = "") {
1107 if (Value *V = foldConstant(Instruction::Xor, LHS, RHS, Name)) return V;
1108 return Insert(BinaryOperator::CreateXor(LHS, RHS), Name);
1109 }
1110 Value *CreateXor(Value *LHS, const APInt &RHS, const Twine &Name = "") {
1111 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1112 }
1113 Value *CreateXor(Value *LHS, uint64_t RHS, const Twine &Name = "") {
1114 return CreateXor(LHS, ConstantInt::get(LHS->getType(), RHS), Name);
1115 }
1116 Value *CreateFAdd(Value *L, Value *R, const Twine &Name = "",
1117 MDNode *FPMD = nullptr) {
1118 if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V;
1119 Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), FPMD, FMF);
1120 return Insert(I, Name);
1121 }
1122 /// Copy fast-math-flags from an instruction rather than using the builder's
1123 /// default FMF.
1124 Value *CreateFAddFMF(Value *L, Value *R, Instruction *FMFSource,
1125 const Twine &Name = "") {
1126 if (Value *V = foldConstant(Instruction::FAdd, L, R, Name)) return V;
1127 Instruction *I = setFPAttrs(BinaryOperator::CreateFAdd(L, R), nullptr,
1128 FMFSource->getFastMathFlags());
1129 return Insert(I, Name);
1130 }
1131 Value *CreateFSub(Value *L, Value *R, const Twine &Name = "",
1132 MDNode *FPMD = nullptr) {
1133 if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V;
1134 Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), FPMD, FMF);
1135 return Insert(I, Name);
1136 }
1137 /// Copy fast-math-flags from an instruction rather than using the builder's
1138 /// default FMF.
1139 Value *CreateFSubFMF(Value *L, Value *R, Instruction *FMFSource,
1140 const Twine &Name = "") {
1141 if (Value *V = foldConstant(Instruction::FSub, L, R, Name)) return V;
1142 Instruction *I = setFPAttrs(BinaryOperator::CreateFSub(L, R), nullptr,
1143 FMFSource->getFastMathFlags());
1144 return Insert(I, Name);
1145 }
1146 Value *CreateFMul(Value *L, Value *R, const Twine &Name = "",
1147 MDNode *FPMD = nullptr) {
1148 if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V;
1149 Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), FPMD, FMF);
1150 return Insert(I, Name);
1151 }
1152 /// Copy fast-math-flags from an instruction rather than using the builder's
1153 /// default FMF.
1154 Value *CreateFMulFMF(Value *L, Value *R, Instruction *FMFSource,
1155 const Twine &Name = "") {
1156 if (Value *V = foldConstant(Instruction::FMul, L, R, Name)) return V;
1157 Instruction *I = setFPAttrs(BinaryOperator::CreateFMul(L, R), nullptr,
1158 FMFSource->getFastMathFlags());
1159 return Insert(I, Name);
1160 }
1161 Value *CreateFDiv(Value *L, Value *R, const Twine &Name = "",
1162 MDNode *FPMD = nullptr) {
1163 if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V;
1164 Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), FPMD, FMF);
1165 return Insert(I, Name);
1166 }
1167 /// Copy fast-math-flags from an instruction rather than using the builder's
1168 /// default FMF.
1169 Value *CreateFDivFMF(Value *L, Value *R, Instruction *FMFSource,
1170 const Twine &Name = "") {
1171 if (Value *V = foldConstant(Instruction::FDiv, L, R, Name)) return V;
1172 Instruction *I = setFPAttrs(BinaryOperator::CreateFDiv(L, R), nullptr,
1173 FMFSource->getFastMathFlags());
1174 return Insert(I, Name);
1175 }
1176 Value *CreateFRem(Value *L, Value *R, const Twine &Name = "",
1177 MDNode *FPMD = nullptr) {
1178 if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V;
1179 Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), FPMD, FMF);
1180 return Insert(I, Name);
1181 }
1182 /// Copy fast-math-flags from an instruction rather than using the builder's
1183 /// default FMF.
1184 Value *CreateFRemFMF(Value *L, Value *R, Instruction *FMFSource,
1185 const Twine &Name = "") {
1186 if (Value *V = foldConstant(Instruction::FRem, L, R, Name)) return V;
1187 Instruction *I = setFPAttrs(BinaryOperator::CreateFRem(L, R), nullptr,
1188 FMFSource->getFastMathFlags());
1189 return Insert(I, Name);
1190 }
1191
1192 Value *CreateBinOp(Instruction::BinaryOps Opc,
1193 Value *LHS, Value *RHS, const Twine &Name = "",
1194 MDNode *FPMathTag = nullptr) {
1195 if (Value *V = foldConstant(Opc, LHS, RHS, Name)) return V;
1196 Instruction *BinOp = BinaryOperator::Create(Opc, LHS, RHS);
1197 if (isa<FPMathOperator>(BinOp))
1198 BinOp = setFPAttrs(BinOp, FPMathTag, FMF);
1199 return Insert(BinOp, Name);
1200 }
1201
1202 Value *CreateNeg(Value *V, const Twine &Name = "",
1203 bool HasNUW = false, bool HasNSW = false) {
1204 if (Constant *VC = dyn_cast<Constant>(V))
1205 return Insert(Folder.CreateNeg(VC, HasNUW, HasNSW), Name);
1206 BinaryOperator *BO = Insert(BinaryOperator::CreateNeg(V), Name);
1207 if (HasNUW) BO->setHasNoUnsignedWrap();
1208 if (HasNSW) BO->setHasNoSignedWrap();
1209 return BO;
1210 }
1211 Value *CreateNSWNeg(Value *V, const Twine &Name = "") {
1212 return CreateNeg(V, Name, false, true);
1213 }
1214 Value *CreateNUWNeg(Value *V, const Twine &Name = "") {
1215 return CreateNeg(V, Name, true, false);
1216 }
1217 Value *CreateFNeg(Value *V, const Twine &Name = "",
1218 MDNode *FPMathTag = nullptr) {
1219 if (Constant *VC = dyn_cast<Constant>(V))
1220 return Insert(Folder.CreateFNeg(VC), Name);
1221 return Insert(setFPAttrs(BinaryOperator::CreateFNeg(V), FPMathTag, FMF),
1222 Name);
1223 }
1224 Value *CreateNot(Value *V, const Twine &Name = "") {
1225 if (Constant *VC = dyn_cast<Constant>(V))
1226 return Insert(Folder.CreateNot(VC), Name);
1227 return Insert(BinaryOperator::CreateNot(V), Name);
1228 }
1229
1230 //===--------------------------------------------------------------------===//
1231 // Instruction creation methods: Memory Instructions
1232 //===--------------------------------------------------------------------===//
1233
1234 AllocaInst *CreateAlloca(Type *Ty, unsigned AddrSpace,
1235 Value *ArraySize = nullptr, const Twine &Name = "") {
1236 return Insert(new AllocaInst(Ty, AddrSpace, ArraySize), Name);
1237 }
1238
1239 AllocaInst *CreateAlloca(Type *Ty, Value *ArraySize = nullptr,
1240 const Twine &Name = "") {
1241 const DataLayout &DL = BB->getParent()->getParent()->getDataLayout();
1242 return Insert(new AllocaInst(Ty, DL.getAllocaAddrSpace(), ArraySize), Name);
1243 }
1244 // \brief Provided to resolve 'CreateLoad(Ptr, "...")' correctly, instead of
1245 // converting the string to 'bool' for the isVolatile parameter.
1246 LoadInst *CreateLoad(Value *Ptr, const char *Name) {
1247 return Insert(new LoadInst(Ptr), Name);
1248 }
1249 LoadInst *CreateLoad(Value *Ptr, const Twine &Name = "") {
1250 return Insert(new LoadInst(Ptr), Name);
1251 }
1252 LoadInst *CreateLoad(Type *Ty, Value *Ptr, const Twine &Name = "") {
1253 return Insert(new LoadInst(Ty, Ptr), Name);
1254 }
1255 LoadInst *CreateLoad(Value *Ptr, bool isVolatile, const Twine &Name = "") {
1256 return Insert(new LoadInst(Ptr, nullptr, isVolatile), Name);
23
Passing null pointer value via 1st parameter 'Ptr'
24
Calling constructor for 'LoadInst'
1257 }
1258 StoreInst *CreateStore(Value *Val, Value *Ptr, bool isVolatile = false) {
1259 return Insert(new StoreInst(Val, Ptr, isVolatile));
1260 }
1261 // \brief Provided to resolve 'CreateAlignedLoad(Ptr, Align, "...")'
1262 // correctly, instead of converting the string to 'bool' for the isVolatile
1263 // parameter.
1264 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, const char *Name) {
1265 LoadInst *LI = CreateLoad(Ptr, Name);
1266 LI->setAlignment(Align);
1267 return LI;
1268 }
1269 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align,
1270 const Twine &Name = "") {
1271 LoadInst *LI = CreateLoad(Ptr, Name);
1272 LI->setAlignment(Align);
1273 return LI;
1274 }
1275 LoadInst *CreateAlignedLoad(Value *Ptr, unsigned Align, bool isVolatile,
1276 const Twine &Name = "") {
1277 LoadInst *LI = CreateLoad(Ptr, isVolatile, Name);
1278 LI->setAlignment(Align);
1279 return LI;
1280 }
1281 StoreInst *CreateAlignedStore(Value *Val, Value *Ptr, unsigned Align,
1282 bool isVolatile = false) {
1283 StoreInst *SI = CreateStore(Val, Ptr, isVolatile);
1284 SI->setAlignment(Align);
1285 return SI;
1286 }
1287 FenceInst *CreateFence(AtomicOrdering Ordering,
1288 SyncScope::ID SSID = SyncScope::System,
1289 const Twine &Name = "") {
1290 return Insert(new FenceInst(Context, Ordering, SSID), Name);
1291 }
1292 AtomicCmpXchgInst *
1293 CreateAtomicCmpXchg(Value *Ptr, Value *Cmp, Value *New,
1294 AtomicOrdering SuccessOrdering,
1295 AtomicOrdering FailureOrdering,
1296 SyncScope::ID SSID = SyncScope::System) {
1297 return Insert(new AtomicCmpXchgInst(Ptr, Cmp, New, SuccessOrdering,
1298 FailureOrdering, SSID));
1299 }
1300 AtomicRMWInst *CreateAtomicRMW(AtomicRMWInst::BinOp Op, Value *Ptr, Value *Val,
1301 AtomicOrdering Ordering,
1302 SyncScope::ID SSID = SyncScope::System) {
1303 return Insert(new AtomicRMWInst(Op, Ptr, Val, Ordering, SSID));
1304 }
1305 Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
1306 const Twine &Name = "") {
1307 return CreateGEP(nullptr, Ptr, IdxList, Name);
1308 }
1309 Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1310 const Twine &Name = "") {
1311 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1312 // Every index must be constant.
1313 size_t i, e;
1314 for (i = 0, e = IdxList.size(); i != e; ++i)
1315 if (!isa<Constant>(IdxList[i]))
1316 break;
1317 if (i == e)
1318 return Insert(Folder.CreateGetElementPtr(Ty, PC, IdxList), Name);
1319 }
1320 return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
1321 }
1322 Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
1323 const Twine &Name = "") {
1324 return CreateInBoundsGEP(nullptr, Ptr, IdxList, Name);
1325 }
1326 Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
1327 const Twine &Name = "") {
1328 if (Constant *PC = dyn_cast<Constant>(Ptr)) {
1329 // Every index must be constant.
1330 size_t i, e;
1331 for (i = 0, e = IdxList.size(); i != e; ++i)
1332 if (!isa<Constant>(IdxList[i]))
1333 break;
1334 if (i == e)
1335 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IdxList),
1336 Name);
1337 }
1338 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, IdxList), Name);
1339 }
1340 Value *CreateGEP(Value *Ptr, Value *Idx, const Twine &Name = "") {
1341 return CreateGEP(nullptr, Ptr, Idx, Name);
1342 }
1343 Value *CreateGEP(Type *Ty, Value *Ptr, Value *Idx, const Twine &Name = "") {
1344 if (Constant *PC = dyn_cast<Constant>(Ptr))
1345 if (Constant *IC = dyn_cast<Constant>(Idx))
1346 return Insert(Folder.CreateGetElementPtr(Ty, PC, IC), Name);
1347 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1348 }
1349 Value *CreateInBoundsGEP(Type *Ty, Value *Ptr, Value *Idx,
1350 const Twine &Name = "") {
1351 if (Constant *PC = dyn_cast<Constant>(Ptr))
1352 if (Constant *IC = dyn_cast<Constant>(Idx))
1353 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, IC), Name);
1354 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1355 }
1356 Value *CreateConstGEP1_32(Value *Ptr, unsigned Idx0, const Twine &Name = "") {
1357 return CreateConstGEP1_32(nullptr, Ptr, Idx0, Name);
1358 }
1359 Value *CreateConstGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1360 const Twine &Name = "") {
1361 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1362
1363 if (Constant *PC = dyn_cast<Constant>(Ptr))
1364 return Insert(Folder.CreateGetElementPtr(Ty, PC, Idx), Name);
1365
1366 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idx), Name);
1367 }
1368 Value *CreateConstInBoundsGEP1_32(Type *Ty, Value *Ptr, unsigned Idx0,
1369 const Twine &Name = "") {
1370 Value *Idx = ConstantInt::get(Type::getInt32Ty(Context), Idx0);
1371
1372 if (Constant *PC = dyn_cast<Constant>(Ptr))
1373 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idx), Name);
1374
1375 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idx), Name);
1376 }
1377 Value *CreateConstGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1,
1378 const Twine &Name = "") {
1379 Value *Idxs[] = {
1380 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1381 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1382 };
1383
1384 if (Constant *PC = dyn_cast<Constant>(Ptr))
1385 return Insert(Folder.CreateGetElementPtr(Ty, PC, Idxs), Name);
1386
1387 return Insert(GetElementPtrInst::Create(Ty, Ptr, Idxs), Name);
1388 }
1389 Value *CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0,
1390 unsigned Idx1, const Twine &Name = "") {
1391 Value *Idxs[] = {
1392 ConstantInt::get(Type::getInt32Ty(Context), Idx0),
1393 ConstantInt::get(Type::getInt32Ty(Context), Idx1)
1394 };
1395
1396 if (Constant *PC = dyn_cast<Constant>(Ptr))
1397 return Insert(Folder.CreateInBoundsGetElementPtr(Ty, PC, Idxs), Name);
1398
1399 return Insert(GetElementPtrInst::CreateInBounds(Ty, Ptr, Idxs), Name);
1400 }
1401 Value *CreateConstGEP1_64(Value *Ptr, uint64_t Idx0, const Twine &Name = "") {
1402 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1403
1404 if (Constant *PC = dyn_cast<Constant>(Ptr))
1405 return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idx), Name);
1406
1407 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idx), Name);
1408 }
1409 Value *CreateConstInBoundsGEP1_64(Value *Ptr, uint64_t Idx0,
1410 const Twine &Name = "") {
1411 Value *Idx = ConstantInt::get(Type::getInt64Ty(Context), Idx0);
1412
1413 if (Constant *PC = dyn_cast<Constant>(Ptr))
1414 return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idx), Name);
1415
1416 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idx), Name);
1417 }
1418 Value *CreateConstGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1419 const Twine &Name = "") {
1420 Value *Idxs[] = {
1421 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1422 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1423 };
1424
1425 if (Constant *PC = dyn_cast<Constant>(Ptr))
1426 return Insert(Folder.CreateGetElementPtr(nullptr, PC, Idxs), Name);
1427
1428 return Insert(GetElementPtrInst::Create(nullptr, Ptr, Idxs), Name);
1429 }
1430 Value *CreateConstInBoundsGEP2_64(Value *Ptr, uint64_t Idx0, uint64_t Idx1,
1431 const Twine &Name = "") {
1432 Value *Idxs[] = {
1433 ConstantInt::get(Type::getInt64Ty(Context), Idx0),
1434 ConstantInt::get(Type::getInt64Ty(Context), Idx1)
1435 };
1436
1437 if (Constant *PC = dyn_cast<Constant>(Ptr))
1438 return Insert(Folder.CreateInBoundsGetElementPtr(nullptr, PC, Idxs),
1439 Name);
1440
1441 return Insert(GetElementPtrInst::CreateInBounds(nullptr, Ptr, Idxs), Name);
1442 }
1443 Value *CreateStructGEP(Type *Ty, Value *Ptr, unsigned Idx,
1444 const Twine &Name = "") {
1445 return CreateConstInBoundsGEP2_32(Ty, Ptr, 0, Idx, Name);
1446 }
1447
1448 /// \brief Same as CreateGlobalString, but return a pointer with "i8*" type
1449 /// instead of a pointer to array of i8.
1450 Value *CreateGlobalStringPtr(StringRef Str, const Twine &Name = "",
1451 unsigned AddressSpace = 0) {
1452 GlobalVariable *gv = CreateGlobalString(Str, Name, AddressSpace);
1453 Value *zero = ConstantInt::get(Type::getInt32Ty(Context), 0);
1454 Value *Args[] = { zero, zero };
1455 return CreateInBoundsGEP(gv->getValueType(), gv, Args, Name);
1456 }
1457
1458 //===--------------------------------------------------------------------===//
1459 // Instruction creation methods: Cast/Conversion Operators
1460 //===--------------------------------------------------------------------===//
1461
1462 Value *CreateTrunc(Value *V, Type *DestTy, const Twine &Name = "") {
1463 return CreateCast(Instruction::Trunc, V, DestTy, Name);
1464 }
1465 Value *CreateZExt(Value *V, Type *DestTy, const Twine &Name = "") {
1466 return CreateCast(Instruction::ZExt, V, DestTy, Name);
1467 }
1468 Value *CreateSExt(Value *V, Type *DestTy, const Twine &Name = "") {
1469 return CreateCast(Instruction::SExt, V, DestTy, Name);
1470 }
1471 /// \brief Create a ZExt or Trunc from the integer value V to DestTy. Return
1472 /// the value untouched if the type of V is already DestTy.
1473 Value *CreateZExtOrTrunc(Value *V, Type *DestTy,
1474 const Twine &Name = "") {
1475 assert(V->getType()->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only zero extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1477, __extension__ __PRETTY_FUNCTION__))
1476 DestTy->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only zero extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1477, __extension__ __PRETTY_FUNCTION__))
1477 "Can only zero extend/truncate integers!")(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only zero extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only zero extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1477, __extension__ __PRETTY_FUNCTION__))
;
1478 Type *VTy = V->getType();
1479 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1480 return CreateZExt(V, DestTy, Name);
1481 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1482 return CreateTrunc(V, DestTy, Name);
1483 return V;
1484 }
1485 /// \brief Create a SExt or Trunc from the integer value V to DestTy. Return
1486 /// the value untouched if the type of V is already DestTy.
1487 Value *CreateSExtOrTrunc(Value *V, Type *DestTy,
1488 const Twine &Name = "") {
1489 assert(V->getType()->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only sign extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1491, __extension__ __PRETTY_FUNCTION__))
1490 DestTy->isIntOrIntVectorTy() &&(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only sign extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1491, __extension__ __PRETTY_FUNCTION__))
1491 "Can only sign extend/truncate integers!")(static_cast <bool> (V->getType()->isIntOrIntVectorTy
() && DestTy->isIntOrIntVectorTy() && "Can only sign extend/truncate integers!"
) ? void (0) : __assert_fail ("V->getType()->isIntOrIntVectorTy() && DestTy->isIntOrIntVectorTy() && \"Can only sign extend/truncate integers!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1491, __extension__ __PRETTY_FUNCTION__))
;
1492 Type *VTy = V->getType();
1493 if (VTy->getScalarSizeInBits() < DestTy->getScalarSizeInBits())
1494 return CreateSExt(V, DestTy, Name);
1495 if (VTy->getScalarSizeInBits() > DestTy->getScalarSizeInBits())
1496 return CreateTrunc(V, DestTy, Name);
1497 return V;
1498 }
1499 Value *CreateFPToUI(Value *V, Type *DestTy, const Twine &Name = ""){
1500 return CreateCast(Instruction::FPToUI, V, DestTy, Name);
1501 }
1502 Value *CreateFPToSI(Value *V, Type *DestTy, const Twine &Name = ""){
1503 return CreateCast(Instruction::FPToSI, V, DestTy, Name);
1504 }
1505 Value *CreateUIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1506 return CreateCast(Instruction::UIToFP, V, DestTy, Name);
1507 }
1508 Value *CreateSIToFP(Value *V, Type *DestTy, const Twine &Name = ""){
1509 return CreateCast(Instruction::SIToFP, V, DestTy, Name);
1510 }
1511 Value *CreateFPTrunc(Value *V, Type *DestTy,
1512 const Twine &Name = "") {
1513 return CreateCast(Instruction::FPTrunc, V, DestTy, Name);
1514 }
1515 Value *CreateFPExt(Value *V, Type *DestTy, const Twine &Name = "") {
1516 return CreateCast(Instruction::FPExt, V, DestTy, Name);
1517 }
1518 Value *CreatePtrToInt(Value *V, Type *DestTy,
1519 const Twine &Name = "") {
1520 return CreateCast(Instruction::PtrToInt, V, DestTy, Name);
1521 }
1522 Value *CreateIntToPtr(Value *V, Type *DestTy,
1523 const Twine &Name = "") {
1524 return CreateCast(Instruction::IntToPtr, V, DestTy, Name);
1525 }
1526 Value *CreateBitCast(Value *V, Type *DestTy,
1527 const Twine &Name = "") {
1528 return CreateCast(Instruction::BitCast, V, DestTy, Name);
1529 }
1530 Value *CreateAddrSpaceCast(Value *V, Type *DestTy,
1531 const Twine &Name = "") {
1532 return CreateCast(Instruction::AddrSpaceCast, V, DestTy, Name);
1533 }
1534 Value *CreateZExtOrBitCast(Value *V, Type *DestTy,
1535 const Twine &Name = "") {
1536 if (V->getType() == DestTy)
1537 return V;
1538 if (Constant *VC = dyn_cast<Constant>(V))
1539 return Insert(Folder.CreateZExtOrBitCast(VC, DestTy), Name);
1540 return Insert(CastInst::CreateZExtOrBitCast(V, DestTy), Name);
1541 }
1542 Value *CreateSExtOrBitCast(Value *V, Type *DestTy,
1543 const Twine &Name = "") {
1544 if (V->getType() == DestTy)
1545 return V;
1546 if (Constant *VC = dyn_cast<Constant>(V))
1547 return Insert(Folder.CreateSExtOrBitCast(VC, DestTy), Name);
1548 return Insert(CastInst::CreateSExtOrBitCast(V, DestTy), Name);
1549 }
1550 Value *CreateTruncOrBitCast(Value *V, Type *DestTy,
1551 const Twine &Name = "") {
1552 if (V->getType() == DestTy)
1553 return V;
1554 if (Constant *VC = dyn_cast<Constant>(V))
1555 return Insert(Folder.CreateTruncOrBitCast(VC, DestTy), Name);
1556 return Insert(CastInst::CreateTruncOrBitCast(V, DestTy), Name);
1557 }
1558 Value *CreateCast(Instruction::CastOps Op, Value *V, Type *DestTy,
1559 const Twine &Name = "") {
1560 if (V->getType() == DestTy)
1561 return V;
1562 if (Constant *VC = dyn_cast<Constant>(V))
1563 return Insert(Folder.CreateCast(Op, VC, DestTy), Name);
1564 return Insert(CastInst::Create(Op, V, DestTy), Name);
1565 }
1566 Value *CreatePointerCast(Value *V, Type *DestTy,
1567 const Twine &Name = "") {
1568 if (V->getType() == DestTy)
1569 return V;
1570 if (Constant *VC = dyn_cast<Constant>(V))
1571 return Insert(Folder.CreatePointerCast(VC, DestTy), Name);
1572 return Insert(CastInst::CreatePointerCast(V, DestTy), Name);
1573 }
1574
1575 Value *CreatePointerBitCastOrAddrSpaceCast(Value *V, Type *DestTy,
1576 const Twine &Name = "") {
1577 if (V->getType() == DestTy)
1578 return V;
1579
1580 if (Constant *VC = dyn_cast<Constant>(V)) {
1581 return Insert(Folder.CreatePointerBitCastOrAddrSpaceCast(VC, DestTy),
1582 Name);
1583 }
1584
1585 return Insert(CastInst::CreatePointerBitCastOrAddrSpaceCast(V, DestTy),
1586 Name);
1587 }
1588
1589 Value *CreateIntCast(Value *V, Type *DestTy, bool isSigned,
1590 const Twine &Name = "") {
1591 if (V->getType() == DestTy)
1592 return V;
1593 if (Constant *VC = dyn_cast<Constant>(V))
1594 return Insert(Folder.CreateIntCast(VC, DestTy, isSigned), Name);
1595 return Insert(CastInst::CreateIntegerCast(V, DestTy, isSigned), Name);
1596 }
1597
1598 Value *CreateBitOrPointerCast(Value *V, Type *DestTy,
1599 const Twine &Name = "") {
1600 if (V->getType() == DestTy)
1601 return V;
1602 if (V->getType()->isPtrOrPtrVectorTy() && DestTy->isIntOrIntVectorTy())
1603 return CreatePtrToInt(V, DestTy, Name);
1604 if (V->getType()->isIntOrIntVectorTy() && DestTy->isPtrOrPtrVectorTy())
1605 return CreateIntToPtr(V, DestTy, Name);
1606
1607 return CreateBitCast(V, DestTy, Name);
1608 }
1609
1610public:
1611 Value *CreateFPCast(Value *V, Type *DestTy, const Twine &Name = "") {
1612 if (V->getType() == DestTy)
1613 return V;
1614 if (Constant *VC = dyn_cast<Constant>(V))
1615 return Insert(Folder.CreateFPCast(VC, DestTy), Name);
1616 return Insert(CastInst::CreateFPCast(V, DestTy), Name);
1617 }
1618
1619 // \brief Provided to resolve 'CreateIntCast(Ptr, Ptr, "...")', giving a
1620 // compile time error, instead of converting the string to bool for the
1621 // isSigned parameter.
1622 Value *CreateIntCast(Value *, Type *, const char *) = delete;
1623
1624 //===--------------------------------------------------------------------===//
1625 // Instruction creation methods: Compare Instructions
1626 //===--------------------------------------------------------------------===//
1627
1628 Value *CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name = "") {
1629 return CreateICmp(ICmpInst::ICMP_EQ, LHS, RHS, Name);
1630 }
1631 Value *CreateICmpNE(Value *LHS, Value *RHS, const Twine &Name = "") {
1632 return CreateICmp(ICmpInst::ICMP_NE, LHS, RHS, Name);
1633 }
1634 Value *CreateICmpUGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1635 return CreateICmp(ICmpInst::ICMP_UGT, LHS, RHS, Name);
1636 }
1637 Value *CreateICmpUGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1638 return CreateICmp(ICmpInst::ICMP_UGE, LHS, RHS, Name);
1639 }
1640 Value *CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name = "") {
1641 return CreateICmp(ICmpInst::ICMP_ULT, LHS, RHS, Name);
1642 }
1643 Value *CreateICmpULE(Value *LHS, Value *RHS, const Twine &Name = "") {
1644 return CreateICmp(ICmpInst::ICMP_ULE, LHS, RHS, Name);
1645 }
1646 Value *CreateICmpSGT(Value *LHS, Value *RHS, const Twine &Name = "") {
1647 return CreateICmp(ICmpInst::ICMP_SGT, LHS, RHS, Name);
1648 }
1649 Value *CreateICmpSGE(Value *LHS, Value *RHS, const Twine &Name = "") {
1650 return CreateICmp(ICmpInst::ICMP_SGE, LHS, RHS, Name);
1651 }
1652 Value *CreateICmpSLT(Value *LHS, Value *RHS, const Twine &Name = "") {
1653 return CreateICmp(ICmpInst::ICMP_SLT, LHS, RHS, Name);
1654 }
1655 Value *CreateICmpSLE(Value *LHS, Value *RHS, const Twine &Name = "") {
1656 return CreateICmp(ICmpInst::ICMP_SLE, LHS, RHS, Name);
1657 }
1658
1659 Value *CreateFCmpOEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1660 MDNode *FPMathTag = nullptr) {
1661 return CreateFCmp(FCmpInst::FCMP_OEQ, LHS, RHS, Name, FPMathTag);
1662 }
1663 Value *CreateFCmpOGT(Value *LHS, Value *RHS, const Twine &Name = "",
1664 MDNode *FPMathTag = nullptr) {
1665 return CreateFCmp(FCmpInst::FCMP_OGT, LHS, RHS, Name, FPMathTag);
1666 }
1667 Value *CreateFCmpOGE(Value *LHS, Value *RHS, const Twine &Name = "",
1668 MDNode *FPMathTag = nullptr) {
1669 return CreateFCmp(FCmpInst::FCMP_OGE, LHS, RHS, Name, FPMathTag);
1670 }
1671 Value *CreateFCmpOLT(Value *LHS, Value *RHS, const Twine &Name = "",
1672 MDNode *FPMathTag = nullptr) {
1673 return CreateFCmp(FCmpInst::FCMP_OLT, LHS, RHS, Name, FPMathTag);
1674 }
1675 Value *CreateFCmpOLE(Value *LHS, Value *RHS, const Twine &Name = "",
1676 MDNode *FPMathTag = nullptr) {
1677 return CreateFCmp(FCmpInst::FCMP_OLE, LHS, RHS, Name, FPMathTag);
1678 }
1679 Value *CreateFCmpONE(Value *LHS, Value *RHS, const Twine &Name = "",
1680 MDNode *FPMathTag = nullptr) {
1681 return CreateFCmp(FCmpInst::FCMP_ONE, LHS, RHS, Name, FPMathTag);
1682 }
1683 Value *CreateFCmpORD(Value *LHS, Value *RHS, const Twine &Name = "",
1684 MDNode *FPMathTag = nullptr) {
1685 return CreateFCmp(FCmpInst::FCMP_ORD, LHS, RHS, Name, FPMathTag);
1686 }
1687 Value *CreateFCmpUNO(Value *LHS, Value *RHS, const Twine &Name = "",
1688 MDNode *FPMathTag = nullptr) {
1689 return CreateFCmp(FCmpInst::FCMP_UNO, LHS, RHS, Name, FPMathTag);
1690 }
1691 Value *CreateFCmpUEQ(Value *LHS, Value *RHS, const Twine &Name = "",
1692 MDNode *FPMathTag = nullptr) {
1693 return CreateFCmp(FCmpInst::FCMP_UEQ, LHS, RHS, Name, FPMathTag);
1694 }
1695 Value *CreateFCmpUGT(Value *LHS, Value *RHS, const Twine &Name = "",
1696 MDNode *FPMathTag = nullptr) {
1697 return CreateFCmp(FCmpInst::FCMP_UGT, LHS, RHS, Name, FPMathTag);
1698 }
1699 Value *CreateFCmpUGE(Value *LHS, Value *RHS, const Twine &Name = "",
1700 MDNode *FPMathTag = nullptr) {
1701 return CreateFCmp(FCmpInst::FCMP_UGE, LHS, RHS, Name, FPMathTag);
1702 }
1703 Value *CreateFCmpULT(Value *LHS, Value *RHS, const Twine &Name = "",
1704 MDNode *FPMathTag = nullptr) {
1705 return CreateFCmp(FCmpInst::FCMP_ULT, LHS, RHS, Name, FPMathTag);
1706 }
1707 Value *CreateFCmpULE(Value *LHS, Value *RHS, const Twine &Name = "",
1708 MDNode *FPMathTag = nullptr) {
1709 return CreateFCmp(FCmpInst::FCMP_ULE, LHS, RHS, Name, FPMathTag);
1710 }
1711 Value *CreateFCmpUNE(Value *LHS, Value *RHS, const Twine &Name = "",
1712 MDNode *FPMathTag = nullptr) {
1713 return CreateFCmp(FCmpInst::FCMP_UNE, LHS, RHS, Name, FPMathTag);
1714 }
1715
1716 Value *CreateICmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
1717 const Twine &Name = "") {
1718 if (Constant *LC = dyn_cast<Constant>(LHS))
1719 if (Constant *RC = dyn_cast<Constant>(RHS))
1720 return Insert(Folder.CreateICmp(P, LC, RC), Name);
1721 return Insert(new ICmpInst(P, LHS, RHS), Name);
1722 }
1723 Value *CreateFCmp(CmpInst::Predicate P, Value *LHS, Value *RHS,
1724 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1725 if (Constant *LC = dyn_cast<Constant>(LHS))
1726 if (Constant *RC = dyn_cast<Constant>(RHS))
1727 return Insert(Folder.CreateFCmp(P, LC, RC), Name);
1728 return Insert(setFPAttrs(new FCmpInst(P, LHS, RHS), FPMathTag, FMF), Name);
1729 }
1730
1731 //===--------------------------------------------------------------------===//
1732 // Instruction creation methods: Other Instructions
1733 //===--------------------------------------------------------------------===//
1734
1735 PHINode *CreatePHI(Type *Ty, unsigned NumReservedValues,
1736 const Twine &Name = "") {
1737 return Insert(PHINode::Create(Ty, NumReservedValues), Name);
1738 }
1739
1740 CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args = None,
1741 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1742 PointerType *PTy = cast<PointerType>(Callee->getType());
1743 FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
1744 return CreateCall(FTy, Callee, Args, Name, FPMathTag);
1745 }
1746
1747 CallInst *CreateCall(FunctionType *FTy, Value *Callee,
1748 ArrayRef<Value *> Args, const Twine &Name = "",
1749 MDNode *FPMathTag = nullptr) {
1750 CallInst *CI = CallInst::Create(FTy, Callee, Args, DefaultOperandBundles);
1751 if (isa<FPMathOperator>(CI))
1752 CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));
1753 return Insert(CI, Name);
1754 }
1755
1756 CallInst *CreateCall(Value *Callee, ArrayRef<Value *> Args,
1757 ArrayRef<OperandBundleDef> OpBundles,
1758 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1759 CallInst *CI = CallInst::Create(Callee, Args, OpBundles);
1760 if (isa<FPMathOperator>(CI))
1761 CI = cast<CallInst>(setFPAttrs(CI, FPMathTag, FMF));
1762 return Insert(CI, Name);
1763 }
1764
1765 CallInst *CreateCall(Function *Callee, ArrayRef<Value *> Args,
1766 const Twine &Name = "", MDNode *FPMathTag = nullptr) {
1767 return CreateCall(Callee->getFunctionType(), Callee, Args, Name, FPMathTag);
1768 }
1769
1770 Value *CreateSelect(Value *C, Value *True, Value *False,
1771 const Twine &Name = "", Instruction *MDFrom = nullptr) {
1772 if (Constant *CC = dyn_cast<Constant>(C))
1773 if (Constant *TC = dyn_cast<Constant>(True))
1774 if (Constant *FC = dyn_cast<Constant>(False))
1775 return Insert(Folder.CreateSelect(CC, TC, FC), Name);
1776
1777 SelectInst *Sel = SelectInst::Create(C, True, False);
1778 if (MDFrom) {
1779 MDNode *Prof = MDFrom->getMetadata(LLVMContext::MD_prof);
1780 MDNode *Unpred = MDFrom->getMetadata(LLVMContext::MD_unpredictable);
1781 Sel = addBranchMetadata(Sel, Prof, Unpred);
1782 }
1783 return Insert(Sel, Name);
1784 }
1785
1786 VAArgInst *CreateVAArg(Value *List, Type *Ty, const Twine &Name = "") {
1787 return Insert(new VAArgInst(List, Ty), Name);
1788 }
1789
1790 Value *CreateExtractElement(Value *Vec, Value *Idx,
1791 const Twine &Name = "") {
1792 if (Constant *VC = dyn_cast<Constant>(Vec))
1793 if (Constant *IC = dyn_cast<Constant>(Idx))
1794 return Insert(Folder.CreateExtractElement(VC, IC), Name);
1795 return Insert(ExtractElementInst::Create(Vec, Idx), Name);
1796 }
1797
1798 Value *CreateExtractElement(Value *Vec, uint64_t Idx,
1799 const Twine &Name = "") {
1800 return CreateExtractElement(Vec, getInt64(Idx), Name);
1801 }
1802
1803 Value *CreateInsertElement(Value *Vec, Value *NewElt, Value *Idx,
1804 const Twine &Name = "") {
1805 if (Constant *VC = dyn_cast<Constant>(Vec))
1806 if (Constant *NC = dyn_cast<Constant>(NewElt))
1807 if (Constant *IC = dyn_cast<Constant>(Idx))
1808 return Insert(Folder.CreateInsertElement(VC, NC, IC), Name);
1809 return Insert(InsertElementInst::Create(Vec, NewElt, Idx), Name);
1810 }
1811
1812 Value *CreateInsertElement(Value *Vec, Value *NewElt, uint64_t Idx,
1813 const Twine &Name = "") {
1814 return CreateInsertElement(Vec, NewElt, getInt64(Idx), Name);
1815 }
1816
1817 Value *CreateShuffleVector(Value *V1, Value *V2, Value *Mask,
1818 const Twine &Name = "") {
1819 if (Constant *V1C = dyn_cast<Constant>(V1))
1820 if (Constant *V2C = dyn_cast<Constant>(V2))
1821 if (Constant *MC = dyn_cast<Constant>(Mask))
1822 return Insert(Folder.CreateShuffleVector(V1C, V2C, MC), Name);
1823 return Insert(new ShuffleVectorInst(V1, V2, Mask), Name);
1824 }
1825
1826 Value *CreateShuffleVector(Value *V1, Value *V2, ArrayRef<uint32_t> IntMask,
1827 const Twine &Name = "") {
1828 Value *Mask = ConstantDataVector::get(Context, IntMask);
1829 return CreateShuffleVector(V1, V2, Mask, Name);
1830 }
1831
1832 Value *CreateExtractValue(Value *Agg,
1833 ArrayRef<unsigned> Idxs,
1834 const Twine &Name = "") {
1835 if (Constant *AggC = dyn_cast<Constant>(Agg))
1836 return Insert(Folder.CreateExtractValue(AggC, Idxs), Name);
1837 return Insert(ExtractValueInst::Create(Agg, Idxs), Name);
1838 }
1839
1840 Value *CreateInsertValue(Value *Agg, Value *Val,
1841 ArrayRef<unsigned> Idxs,
1842 const Twine &Name = "") {
1843 if (Constant *AggC = dyn_cast<Constant>(Agg))
1844 if (Constant *ValC = dyn_cast<Constant>(Val))
1845 return Insert(Folder.CreateInsertValue(AggC, ValC, Idxs), Name);
1846 return Insert(InsertValueInst::Create(Agg, Val, Idxs), Name);
1847 }
1848
1849 LandingPadInst *CreateLandingPad(Type *Ty, unsigned NumClauses,
1850 const Twine &Name = "") {
1851 return Insert(LandingPadInst::Create(Ty, NumClauses), Name);
1852 }
1853
1854 //===--------------------------------------------------------------------===//
1855 // Utility creation methods
1856 //===--------------------------------------------------------------------===//
1857
1858 /// \brief Return an i1 value testing if \p Arg is null.
1859 Value *CreateIsNull(Value *Arg, const Twine &Name = "") {
1860 return CreateICmpEQ(Arg, Constant::getNullValue(Arg->getType()),
1861 Name);
1862 }
1863
1864 /// \brief Return an i1 value testing if \p Arg is not null.
1865 Value *CreateIsNotNull(Value *Arg, const Twine &Name = "") {
1866 return CreateICmpNE(Arg, Constant::getNullValue(Arg->getType()),
1867 Name);
1868 }
1869
1870 /// \brief Return the i64 difference between two pointer values, dividing out
1871 /// the size of the pointed-to objects.
1872 ///
1873 /// This is intended to implement C-style pointer subtraction. As such, the
1874 /// pointers must be appropriately aligned for their element types and
1875 /// pointing into the same object.
1876 Value *CreatePtrDiff(Value *LHS, Value *RHS, const Twine &Name = "") {
1877 assert(LHS->getType() == RHS->getType() &&(static_cast <bool> (LHS->getType() == RHS->getType
() && "Pointer subtraction operand types must match!"
) ? void (0) : __assert_fail ("LHS->getType() == RHS->getType() && \"Pointer subtraction operand types must match!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1878, __extension__ __PRETTY_FUNCTION__))
1878 "Pointer subtraction operand types must match!")(static_cast <bool> (LHS->getType() == RHS->getType
() && "Pointer subtraction operand types must match!"
) ? void (0) : __assert_fail ("LHS->getType() == RHS->getType() && \"Pointer subtraction operand types must match!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1878, __extension__ __PRETTY_FUNCTION__))
;
1879 PointerType *ArgType = cast<PointerType>(LHS->getType());
1880 Value *LHS_int = CreatePtrToInt(LHS, Type::getInt64Ty(Context));
1881 Value *RHS_int = CreatePtrToInt(RHS, Type::getInt64Ty(Context));
1882 Value *Difference = CreateSub(LHS_int, RHS_int);
1883 return CreateExactSDiv(Difference,
1884 ConstantExpr::getSizeOf(ArgType->getElementType()),
1885 Name);
1886 }
1887
1888 /// \brief Create an invariant.group.barrier intrinsic call, that stops
1889 /// optimizer to propagate equality using invariant.group metadata.
1890 /// If Ptr type is different from pointer to i8, it's casted to pointer to i8
1891 /// in the same address space before call and casted back to Ptr type after
1892 /// call.
1893 Value *CreateInvariantGroupBarrier(Value *Ptr) {
1894 assert(isa<PointerType>(Ptr->getType()) &&(static_cast <bool> (isa<PointerType>(Ptr->getType
()) && "invariant.group.barrier only applies to pointers."
) ? void (0) : __assert_fail ("isa<PointerType>(Ptr->getType()) && \"invariant.group.barrier only applies to pointers.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1895, __extension__ __PRETTY_FUNCTION__))
1895 "invariant.group.barrier only applies to pointers.")(static_cast <bool> (isa<PointerType>(Ptr->getType
()) && "invariant.group.barrier only applies to pointers."
) ? void (0) : __assert_fail ("isa<PointerType>(Ptr->getType()) && \"invariant.group.barrier only applies to pointers.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1895, __extension__ __PRETTY_FUNCTION__))
;
1896 auto *PtrType = Ptr->getType();
1897 auto *Int8PtrTy = getInt8PtrTy(PtrType->getPointerAddressSpace());
1898 if (PtrType != Int8PtrTy)
1899 Ptr = CreateBitCast(Ptr, Int8PtrTy);
1900 Module *M = BB->getParent()->getParent();
1901 Function *FnInvariantGroupBarrier = Intrinsic::getDeclaration(
1902 M, Intrinsic::invariant_group_barrier, {Int8PtrTy});
1903
1904 assert(FnInvariantGroupBarrier->getReturnType() == Int8PtrTy &&(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1907, __extension__ __PRETTY_FUNCTION__))
1905 FnInvariantGroupBarrier->getFunctionType()->getParamType(0) ==(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1907, __extension__ __PRETTY_FUNCTION__))
1906 Int8PtrTy &&(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1907, __extension__ __PRETTY_FUNCTION__))
1907 "InvariantGroupBarrier should take and return the same type")(static_cast <bool> (FnInvariantGroupBarrier->getReturnType
() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType
()->getParamType(0) == Int8PtrTy && "InvariantGroupBarrier should take and return the same type"
) ? void (0) : __assert_fail ("FnInvariantGroupBarrier->getReturnType() == Int8PtrTy && FnInvariantGroupBarrier->getFunctionType()->getParamType(0) == Int8PtrTy && \"InvariantGroupBarrier should take and return the same type\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1907, __extension__ __PRETTY_FUNCTION__))
;
1908
1909 CallInst *Fn = CreateCall(FnInvariantGroupBarrier, {Ptr});
1910
1911 if (PtrType != Int8PtrTy)
1912 return CreateBitCast(Fn, PtrType);
1913 return Fn;
1914 }
1915
1916 /// \brief Return a vector value that contains \arg V broadcasted to \p
1917 /// NumElts elements.
1918 Value *CreateVectorSplat(unsigned NumElts, Value *V, const Twine &Name = "") {
1919 assert(NumElts > 0 && "Cannot splat to an empty vector!")(static_cast <bool> (NumElts > 0 && "Cannot splat to an empty vector!"
) ? void (0) : __assert_fail ("NumElts > 0 && \"Cannot splat to an empty vector!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1919, __extension__ __PRETTY_FUNCTION__))
;
1920
1921 // First insert it into an undef vector so we can shuffle it.
1922 Type *I32Ty = getInt32Ty();
1923 Value *Undef = UndefValue::get(VectorType::get(V->getType(), NumElts));
1924 V = CreateInsertElement(Undef, V, ConstantInt::get(I32Ty, 0),
1925 Name + ".splatinsert");
1926
1927 // Shuffle the value across the desired number of elements.
1928 Value *Zeros = ConstantAggregateZero::get(VectorType::get(I32Ty, NumElts));
1929 return CreateShuffleVector(V, Undef, Zeros, Name + ".splat");
1930 }
1931
1932 /// \brief Return a value that has been extracted from a larger integer type.
1933 Value *CreateExtractInteger(const DataLayout &DL, Value *From,
1934 IntegerType *ExtractedTy, uint64_t Offset,
1935 const Twine &Name) {
1936 IntegerType *IntTy = cast<IntegerType>(From->getType());
1937 assert(DL.getTypeStoreSize(ExtractedTy) + Offset <=(static_cast <bool> (DL.getTypeStoreSize(ExtractedTy) +
Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"
) ? void (0) : __assert_fail ("DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && \"Element extends past full value\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1939, __extension__ __PRETTY_FUNCTION__))
1938 DL.getTypeStoreSize(IntTy) &&(static_cast <bool> (DL.getTypeStoreSize(ExtractedTy) +
Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"
) ? void (0) : __assert_fail ("DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && \"Element extends past full value\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1939, __extension__ __PRETTY_FUNCTION__))
1939 "Element extends past full value")(static_cast <bool> (DL.getTypeStoreSize(ExtractedTy) +
Offset <= DL.getTypeStoreSize(IntTy) && "Element extends past full value"
) ? void (0) : __assert_fail ("DL.getTypeStoreSize(ExtractedTy) + Offset <= DL.getTypeStoreSize(IntTy) && \"Element extends past full value\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1939, __extension__ __PRETTY_FUNCTION__))
;
1940 uint64_t ShAmt = 8 * Offset;
1941 Value *V = From;
1942 if (DL.isBigEndian())
1943 ShAmt = 8 * (DL.getTypeStoreSize(IntTy) -
1944 DL.getTypeStoreSize(ExtractedTy) - Offset);
1945 if (ShAmt) {
1946 V = CreateLShr(V, ShAmt, Name + ".shift");
1947 }
1948 assert(ExtractedTy->getBitWidth() <= IntTy->getBitWidth() &&(static_cast <bool> (ExtractedTy->getBitWidth() <=
IntTy->getBitWidth() && "Cannot extract to a larger integer!"
) ? void (0) : __assert_fail ("ExtractedTy->getBitWidth() <= IntTy->getBitWidth() && \"Cannot extract to a larger integer!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1949, __extension__ __PRETTY_FUNCTION__))
1949 "Cannot extract to a larger integer!")(static_cast <bool> (ExtractedTy->getBitWidth() <=
IntTy->getBitWidth() && "Cannot extract to a larger integer!"
) ? void (0) : __assert_fail ("ExtractedTy->getBitWidth() <= IntTy->getBitWidth() && \"Cannot extract to a larger integer!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1949, __extension__ __PRETTY_FUNCTION__))
;
1950 if (ExtractedTy != IntTy) {
1951 V = CreateTrunc(V, ExtractedTy, Name + ".trunc");
1952 }
1953 return V;
1954 }
1955
1956private:
1957 /// \brief Helper function that creates an assume intrinsic call that
1958 /// represents an alignment assumption on the provided Ptr, Mask, Type
1959 /// and Offset.
1960 CallInst *CreateAlignmentAssumptionHelper(const DataLayout &DL,
1961 Value *PtrValue, Value *Mask,
1962 Type *IntPtrTy,
1963 Value *OffsetValue) {
1964 Value *PtrIntValue = CreatePtrToInt(PtrValue, IntPtrTy, "ptrint");
1965
1966 if (OffsetValue) {
1967 bool IsOffsetZero = false;
1968 if (ConstantInt *CI = dyn_cast<ConstantInt>(OffsetValue))
1969 IsOffsetZero = CI->isZero();
1970
1971 if (!IsOffsetZero) {
1972 if (OffsetValue->getType() != IntPtrTy)
1973 OffsetValue = CreateIntCast(OffsetValue, IntPtrTy, /*isSigned*/ true,
1974 "offsetcast");
1975 PtrIntValue = CreateSub(PtrIntValue, OffsetValue, "offsetptr");
1976 }
1977 }
1978
1979 Value *Zero = ConstantInt::get(IntPtrTy, 0);
1980 Value *MaskedPtr = CreateAnd(PtrIntValue, Mask, "maskedptr");
1981 Value *InvCond = CreateICmpEQ(MaskedPtr, Zero, "maskcond");
1982 return CreateAssumption(InvCond);
1983 }
1984
1985public:
1986 /// \brief Create an assume intrinsic call that represents an alignment
1987 /// assumption on the provided pointer.
1988 ///
1989 /// An optional offset can be provided, and if it is provided, the offset
1990 /// must be subtracted from the provided pointer to get the pointer with the
1991 /// specified alignment.
1992 CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
1993 unsigned Alignment,
1994 Value *OffsetValue = nullptr) {
1995 assert(isa<PointerType>(PtrValue->getType()) &&(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1996, __extension__ __PRETTY_FUNCTION__))
1996 "trying to create an alignment assumption on a non-pointer?")(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 1996, __extension__ __PRETTY_FUNCTION__))
;
1997 PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
1998 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
1999
2000 Value *Mask = ConstantInt::get(IntPtrTy, Alignment > 0 ? Alignment - 1 : 0);
2001 return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
2002 OffsetValue);
2003 }
2004 //
2005 /// \brief Create an assume intrinsic call that represents an alignment
2006 /// assumption on the provided pointer.
2007 ///
2008 /// An optional offset can be provided, and if it is provided, the offset
2009 /// must be subtracted from the provided pointer to get the pointer with the
2010 /// specified alignment.
2011 ///
2012 /// This overload handles the condition where the Alignment is dependent
2013 /// on an existing value rather than a static value.
2014 CallInst *CreateAlignmentAssumption(const DataLayout &DL, Value *PtrValue,
2015 Value *Alignment,
2016 Value *OffsetValue = nullptr) {
2017 assert(isa<PointerType>(PtrValue->getType()) &&(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 2018, __extension__ __PRETTY_FUNCTION__))
2018 "trying to create an alignment assumption on a non-pointer?")(static_cast <bool> (isa<PointerType>(PtrValue->
getType()) && "trying to create an alignment assumption on a non-pointer?"
) ? void (0) : __assert_fail ("isa<PointerType>(PtrValue->getType()) && \"trying to create an alignment assumption on a non-pointer?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/IRBuilder.h"
, 2018, __extension__ __PRETTY_FUNCTION__))
;
2019 PointerType *PtrTy = cast<PointerType>(PtrValue->getType());
2020 Type *IntPtrTy = getIntPtrTy(DL, PtrTy->getAddressSpace());
2021
2022 if (Alignment->getType() != IntPtrTy)
2023 Alignment = CreateIntCast(Alignment, IntPtrTy, /*isSigned*/ true,
2024 "alignmentcast");
2025 Value *IsPositive =
2026 CreateICmp(CmpInst::ICMP_SGT, Alignment,
2027 ConstantInt::get(Alignment->getType(), 0), "ispositive");
2028 Value *PositiveMask =
2029 CreateSub(Alignment, ConstantInt::get(IntPtrTy, 1), "positivemask");
2030 Value *Mask = CreateSelect(IsPositive, PositiveMask,
2031 ConstantInt::get(IntPtrTy, 0), "mask");
2032
2033 return CreateAlignmentAssumptionHelper(DL, PtrValue, Mask, IntPtrTy,
2034 OffsetValue);
2035 }
2036};
2037
2038// Create wrappers for C Binding types (see CBindingWrapping.h).
2039DEFINE_SIMPLE_CONVERSION_FUNCTIONS(IRBuilder<>, LLVMBuilderRef)inline IRBuilder<> *unwrap(LLVMBuilderRef P) { return reinterpret_cast
<IRBuilder<>*>(P); } inline LLVMBuilderRef wrap(const
IRBuilder<> *P) { return reinterpret_cast<LLVMBuilderRef
>(const_cast<IRBuilder<>*>(P)); }
2040
2041} // end namespace llvm
2042
2043#endif // LLVM_IR_IRBUILDER_H

/build/llvm-toolchain-snapshot-7~svn326246/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,
25
Called C++ object pointer is null
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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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));
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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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~svn326246/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->OpFrom<Idx_nocapture>(this); } template <int
Idx_nocapture> const Use &InsertValueInst::Op() const
{ return this->OpFrom<Idx_nocapture>(this); }
2731
2732//===----------------------------------------------------------------------===//
2733// PHINode Class
2734//===----------------------------------------------------------------------===//
2735
2736// PHINode - The PHINode class is used to represent the magical mystical PHI
2737// node, that can not exist in nature, but can be synthesized in a computer
2738// scientist's overactive imagination.
2739//
2740class PHINode : public Instruction {
2741 /// The number of operands actually allocated. NumOperands is
2742 /// the number actually in use.
2743 unsigned ReservedSpace;
2744
2745 PHINode(const PHINode &PN);
2746
2747 explicit PHINode(Type *Ty, unsigned NumReservedValues,
2748 const Twine &NameStr = "",
2749 Instruction *InsertBefore = nullptr)
2750 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertBefore),
2751 ReservedSpace(NumReservedValues) {
2752 setName(NameStr);
2753 allocHungoffUses(ReservedSpace);
2754 }
2755
2756 PHINode(Type *Ty, unsigned NumReservedValues, const Twine &NameStr,
2757 BasicBlock *InsertAtEnd)
2758 : Instruction(Ty, Instruction::PHI, nullptr, 0, InsertAtEnd),
2759 ReservedSpace(NumReservedValues) {
2760 setName(NameStr);
2761 allocHungoffUses(ReservedSpace);
2762 }
2763
2764protected:
2765 // Note: Instruction needs to be a friend here to call cloneImpl.
2766 friend class Instruction;
2767
2768 PHINode *cloneImpl() const;
2769
2770 // allocHungoffUses - this is more complicated than the generic
2771 // User::allocHungoffUses, because we have to allocate Uses for the incoming
2772 // values and pointers to the incoming blocks, all in one allocation.
2773 void allocHungoffUses(unsigned N) {
2774 User::allocHungoffUses(N, /* IsPhi */ true);
2775 }
2776
2777public:
2778 /// Constructors - NumReservedValues is a hint for the number of incoming
2779 /// edges that this phi node will have (use 0 if you really have no idea).
2780 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2781 const Twine &NameStr = "",
2782 Instruction *InsertBefore = nullptr) {
2783 return new PHINode(Ty, NumReservedValues, NameStr, InsertBefore);
2784 }
2785
2786 static PHINode *Create(Type *Ty, unsigned NumReservedValues,
2787 const Twine &NameStr, BasicBlock *InsertAtEnd) {
2788 return new PHINode(Ty, NumReservedValues, NameStr, InsertAtEnd);
2789 }
2790
2791 /// Provide fast operand accessors
2792 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
;
2793
2794 // Block iterator interface. This provides access to the list of incoming
2795 // basic blocks, which parallels the list of incoming values.
2796
2797 using block_iterator = BasicBlock **;
2798 using const_block_iterator = BasicBlock * const *;
2799
2800 block_iterator block_begin() {
2801 Use::UserRef *ref =
2802 reinterpret_cast<Use::UserRef*>(op_begin() + ReservedSpace);
2803 return reinterpret_cast<block_iterator>(ref + 1);
2804 }
2805
2806 const_block_iterator block_begin() const {
2807 const Use::UserRef *ref =
2808 reinterpret_cast<const Use::UserRef*>(op_begin() + ReservedSpace);
2809 return reinterpret_cast<const_block_iterator>(ref + 1);
2810 }
2811
2812 block_iterator block_end() {
2813 return block_begin() + getNumOperands();
2814 }
2815
2816 const_block_iterator block_end() const {
2817 return block_begin() + getNumOperands();
2818 }
2819
2820 iterator_range<block_iterator> blocks() {
2821 return make_range(block_begin(), block_end());
2822 }
2823
2824 iterator_range<const_block_iterator> blocks() const {
2825 return make_range(block_begin(), block_end());
2826 }
2827
2828 op_range incoming_values() { return operands(); }
2829
2830 const_op_range incoming_values() const { return operands(); }
2831
2832 /// Return the number of incoming edges
2833 ///
2834 unsigned getNumIncomingValues() const { return getNumOperands(); }
2835
2836 /// Return incoming value number x
2837 ///
2838 Value *getIncomingValue(unsigned i) const {
2839 return getOperand(i);
2840 }
2841 void setIncomingValue(unsigned i, Value *V) {
2842 assert(V && "PHI node got a null value!")(static_cast <bool> (V && "PHI node got a null value!"
) ? void (0) : __assert_fail ("V && \"PHI node got a null value!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2842, __extension__ __PRETTY_FUNCTION__))
;
2843 assert(getType() == V->getType() &&(static_cast <bool> (getType() == V->getType() &&
"All operands to PHI node must be the same type as the PHI node!"
) ? void (0) : __assert_fail ("getType() == V->getType() && \"All operands to PHI node must be the same type as the PHI node!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2844, __extension__ __PRETTY_FUNCTION__))
2844 "All operands to PHI node must be the same type as the PHI node!")(static_cast <bool> (getType() == V->getType() &&
"All operands to PHI node must be the same type as the PHI node!"
) ? void (0) : __assert_fail ("getType() == V->getType() && \"All operands to PHI node must be the same type as the PHI node!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2844, __extension__ __PRETTY_FUNCTION__))
;
2845 setOperand(i, V);
2846 }
2847
2848 static unsigned getOperandNumForIncomingValue(unsigned i) {
2849 return i;
2850 }
2851
2852 static unsigned getIncomingValueNumForOperand(unsigned i) {
2853 return i;
2854 }
2855
2856 /// Return incoming basic block number @p i.
2857 ///
2858 BasicBlock *getIncomingBlock(unsigned i) const {
2859 return block_begin()[i];
2860 }
2861
2862 /// Return incoming basic block corresponding
2863 /// to an operand of the PHI.
2864 ///
2865 BasicBlock *getIncomingBlock(const Use &U) const {
2866 assert(this == U.getUser() && "Iterator doesn't point to PHI's Uses?")(static_cast <bool> (this == U.getUser() && "Iterator doesn't point to PHI's Uses?"
) ? void (0) : __assert_fail ("this == U.getUser() && \"Iterator doesn't point to PHI's Uses?\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2866, __extension__ __PRETTY_FUNCTION__))
;
2867 return getIncomingBlock(unsigned(&U - op_begin()));
2868 }
2869
2870 /// Return incoming basic block corresponding
2871 /// to value use iterator.
2872 ///
2873 BasicBlock *getIncomingBlock(Value::const_user_iterator I) const {
2874 return getIncomingBlock(I.getUse());
2875 }
2876
2877 void setIncomingBlock(unsigned i, BasicBlock *BB) {
2878 assert(BB && "PHI node got a null basic block!")(static_cast <bool> (BB && "PHI node got a null basic block!"
) ? void (0) : __assert_fail ("BB && \"PHI node got a null basic block!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2878, __extension__ __PRETTY_FUNCTION__))
;
2879 block_begin()[i] = BB;
2880 }
2881
2882 /// Add an incoming value to the end of the PHI list
2883 ///
2884 void addIncoming(Value *V, BasicBlock *BB) {
2885 if (getNumOperands() == ReservedSpace)
2886 growOperands(); // Get more space!
2887 // Initialize some new operands.
2888 setNumHungOffUseOperands(getNumOperands() + 1);
2889 setIncomingValue(getNumOperands() - 1, V);
2890 setIncomingBlock(getNumOperands() - 1, BB);
2891 }
2892
2893 /// Remove an incoming value. This is useful if a
2894 /// predecessor basic block is deleted. The value removed is returned.
2895 ///
2896 /// If the last incoming value for a PHI node is removed (and DeletePHIIfEmpty
2897 /// is true), the PHI node is destroyed and any uses of it are replaced with
2898 /// dummy values. The only time there should be zero incoming values to a PHI
2899 /// node is when the block is dead, so this strategy is sound.
2900 ///
2901 Value *removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty = true);
2902
2903 Value *removeIncomingValue(const BasicBlock *BB, bool DeletePHIIfEmpty=true) {
2904 int Idx = getBasicBlockIndex(BB);
2905 assert(Idx >= 0 && "Invalid basic block argument to remove!")(static_cast <bool> (Idx >= 0 && "Invalid basic block argument to remove!"
) ? void (0) : __assert_fail ("Idx >= 0 && \"Invalid basic block argument to remove!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2905, __extension__ __PRETTY_FUNCTION__))
;
2906 return removeIncomingValue(Idx, DeletePHIIfEmpty);
2907 }
2908
2909 /// Return the first index of the specified basic
2910 /// block in the value list for this PHI. Returns -1 if no instance.
2911 ///
2912 int getBasicBlockIndex(const BasicBlock *BB) const {
2913 for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
2914 if (block_begin()[i] == BB)
2915 return i;
2916 return -1;
2917 }
2918
2919 Value *getIncomingValueForBlock(const BasicBlock *BB) const {
2920 int Idx = getBasicBlockIndex(BB);
2921 assert(Idx >= 0 && "Invalid basic block argument!")(static_cast <bool> (Idx >= 0 && "Invalid basic block argument!"
) ? void (0) : __assert_fail ("Idx >= 0 && \"Invalid basic block argument!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2921, __extension__ __PRETTY_FUNCTION__))
;
2922 return getIncomingValue(Idx);
2923 }
2924
2925 /// If the specified PHI node always merges together the
2926 /// same value, return the value, otherwise return null.
2927 Value *hasConstantValue() const;
2928
2929 /// Whether the specified PHI node always merges
2930 /// together the same value, assuming undefs are equal to a unique
2931 /// non-undef value.
2932 bool hasConstantOrUndefValue() const;
2933
2934 /// Methods for support type inquiry through isa, cast, and dyn_cast:
2935 static bool classof(const Instruction *I) {
2936 return I->getOpcode() == Instruction::PHI;
2937 }
2938 static bool classof(const Value *V) {
2939 return isa<Instruction>(V) && classof(cast<Instruction>(V));
2940 }
2941
2942private:
2943 void growOperands();
2944};
2945
2946template <>
2947struct OperandTraits<PHINode> : public HungoffOperandTraits<2> {
2948};
2949
2950DEFINE_TRANSPARENT_OPERAND_ACCESSORS(PHINode, Value)PHINode::op_iterator PHINode::op_begin() { return OperandTraits
<PHINode>::op_begin(this); } PHINode::const_op_iterator
PHINode::op_begin() const { return OperandTraits<PHINode>
::op_begin(const_cast<PHINode*>(this)); } PHINode::op_iterator
PHINode::op_end() { return OperandTraits<PHINode>::op_end
(this); } PHINode::const_op_iterator PHINode::op_end() const {
return OperandTraits<PHINode>::op_end(const_cast<PHINode
*>(this)); } Value *PHINode::getOperand(unsigned i_nocapture
) const { (static_cast <bool> (i_nocapture < OperandTraits
<PHINode>::operands(this) && "getOperand() out of range!"
) ? void (0) : __assert_fail ("i_nocapture < OperandTraits<PHINode>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2950, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<PHINode>::op_begin(const_cast
<PHINode*>(this))[i_nocapture].get()); } void PHINode::
setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<PHINode>::
operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<PHINode>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 2950, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
PHINode>::op_begin(this)[i_nocapture] = Val_nocapture; } unsigned
PHINode::getNumOperands() const { return OperandTraits<PHINode
>::operands(this); } template <int Idx_nocapture> Use
&PHINode::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
PHINode::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
2951
2952//===----------------------------------------------------------------------===//
2953// LandingPadInst Class
2954//===----------------------------------------------------------------------===//
2955
2956//===---------------------------------------------------------------------------
2957/// The landingpad instruction holds all of the information
2958/// necessary to generate correct exception handling. The landingpad instruction
2959/// cannot be moved from the top of a landing pad block, which itself is
2960/// accessible only from the 'unwind' edge of an invoke. This uses the
2961/// SubclassData field in Value to store whether or not the landingpad is a
2962/// cleanup.
2963///
2964class LandingPadInst : public Instruction {
2965 /// The number of operands actually allocated. NumOperands is
2966 /// the number actually in use.
2967 unsigned ReservedSpace;
2968
2969 LandingPadInst(const LandingPadInst &LP);
2970
2971public:
2972 enum ClauseType { Catch, Filter };
2973
2974private:
2975 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2976 const Twine &NameStr, Instruction *InsertBefore);
2977 explicit LandingPadInst(Type *RetTy, unsigned NumReservedValues,
2978 const Twine &NameStr, BasicBlock *InsertAtEnd);
2979
2980 // Allocate space for exactly zero operands.
2981 void *operator new(size_t s) {
2982 return User::operator new(s);
2983 }
2984
2985 void growOperands(unsigned Size);
2986 void init(unsigned NumReservedValues, const Twine &NameStr);
2987
2988protected:
2989 // Note: Instruction needs to be a friend here to call cloneImpl.
2990 friend class Instruction;
2991
2992 LandingPadInst *cloneImpl() const;
2993
2994public:
2995 /// Constructors - NumReservedClauses is a hint for the number of incoming
2996 /// clauses that this landingpad will have (use 0 if you really have no idea).
2997 static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
2998 const Twine &NameStr = "",
2999 Instruction *InsertBefore = nullptr);
3000 static LandingPadInst *Create(Type *RetTy, unsigned NumReservedClauses,
3001 const Twine &NameStr, BasicBlock *InsertAtEnd);
3002
3003 /// Provide fast operand accessors
3004 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
;
3005
3006 /// Return 'true' if this landingpad instruction is a
3007 /// cleanup. I.e., it should be run when unwinding even if its landing pad
3008 /// doesn't catch the exception.
3009 bool isCleanup() const { return getSubclassDataFromInstruction() & 1; }
3010
3011 /// Indicate that this landingpad instruction is a cleanup.
3012 void setCleanup(bool V) {
3013 setInstructionSubclassData((getSubclassDataFromInstruction() & ~1) |
3014 (V ? 1 : 0));
3015 }
3016
3017 /// Add a catch or filter clause to the landing pad.
3018 void addClause(Constant *ClauseVal);
3019
3020 /// Get the value of the clause at index Idx. Use isCatch/isFilter to
3021 /// determine what type of clause this is.
3022 Constant *getClause(unsigned Idx) const {
3023 return cast<Constant>(getOperandList()[Idx]);
3024 }
3025
3026 /// Return 'true' if the clause and index Idx is a catch clause.
3027 bool isCatch(unsigned Idx) const {
3028 return !isa<ArrayType>(getOperandList()[Idx]->getType());
3029 }
3030
3031 /// Return 'true' if the clause and index Idx is a filter clause.
3032 bool isFilter(unsigned Idx) const {
3033 return isa<ArrayType>(getOperandList()[Idx]->getType());
3034 }
3035
3036 /// Get the number of clauses for this landing pad.
3037 unsigned getNumClauses() const { return getNumOperands(); }
3038
3039 /// Grow the size of the operand list to accommodate the new
3040 /// number of clauses.
3041 void reserveClauses(unsigned Size) { growOperands(Size); }
3042
3043 // Methods for support type inquiry through isa, cast, and dyn_cast:
3044 static bool classof(const Instruction *I) {
3045 return I->getOpcode() == Instruction::LandingPad;
3046 }
3047 static bool classof(const Value *V) {
3048 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3049 }
3050};
3051
3052template <>
3053struct OperandTraits<LandingPadInst> : public HungoffOperandTraits<1> {
3054};
3055
3056DEFINE_TRANSPARENT_OPERAND_ACCESSORS(LandingPadInst, Value)LandingPadInst::op_iterator LandingPadInst::op_begin() { return
OperandTraits<LandingPadInst>::op_begin(this); } LandingPadInst
::const_op_iterator LandingPadInst::op_begin() const { return
OperandTraits<LandingPadInst>::op_begin(const_cast<
LandingPadInst*>(this)); } LandingPadInst::op_iterator LandingPadInst
::op_end() { return OperandTraits<LandingPadInst>::op_end
(this); } LandingPadInst::const_op_iterator LandingPadInst::op_end
() const { return OperandTraits<LandingPadInst>::op_end
(const_cast<LandingPadInst*>(this)); } Value *LandingPadInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<LandingPadInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<LandingPadInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3056, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<LandingPadInst>::op_begin(
const_cast<LandingPadInst*>(this))[i_nocapture].get());
} void LandingPadInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<LandingPadInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<LandingPadInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3056, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
LandingPadInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned LandingPadInst::getNumOperands() const { return OperandTraits
<LandingPadInst>::operands(this); } template <int Idx_nocapture
> Use &LandingPadInst::Op() { return this->OpFrom<
Idx_nocapture>(this); } template <int Idx_nocapture>
const Use &LandingPadInst::Op() const { return this->
OpFrom<Idx_nocapture>(this); }
3057
3058//===----------------------------------------------------------------------===//
3059// ReturnInst Class
3060//===----------------------------------------------------------------------===//
3061
3062//===---------------------------------------------------------------------------
3063/// Return a value (possibly void), from a function. Execution
3064/// does not continue in this function any longer.
3065///
3066class ReturnInst : public TerminatorInst {
3067 ReturnInst(const ReturnInst &RI);
3068
3069private:
3070 // ReturnInst constructors:
3071 // ReturnInst() - 'ret void' instruction
3072 // ReturnInst( null) - 'ret void' instruction
3073 // ReturnInst(Value* X) - 'ret X' instruction
3074 // ReturnInst( null, Inst *I) - 'ret void' instruction, insert before I
3075 // ReturnInst(Value* X, Inst *I) - 'ret X' instruction, insert before I
3076 // ReturnInst( null, BB *B) - 'ret void' instruction, insert @ end of B
3077 // ReturnInst(Value* X, BB *B) - 'ret X' instruction, insert @ end of B
3078 //
3079 // NOTE: If the Value* passed is of type void then the constructor behaves as
3080 // if it was passed NULL.
3081 explicit ReturnInst(LLVMContext &C, Value *retVal = nullptr,
3082 Instruction *InsertBefore = nullptr);
3083 ReturnInst(LLVMContext &C, Value *retVal, BasicBlock *InsertAtEnd);
3084 explicit ReturnInst(LLVMContext &C, BasicBlock *InsertAtEnd);
3085
3086protected:
3087 // Note: Instruction needs to be a friend here to call cloneImpl.
3088 friend class Instruction;
3089
3090 ReturnInst *cloneImpl() const;
3091
3092public:
3093 static ReturnInst* Create(LLVMContext &C, Value *retVal = nullptr,
3094 Instruction *InsertBefore = nullptr) {
3095 return new(!!retVal) ReturnInst(C, retVal, InsertBefore);
3096 }
3097
3098 static ReturnInst* Create(LLVMContext &C, Value *retVal,
3099 BasicBlock *InsertAtEnd) {
3100 return new(!!retVal) ReturnInst(C, retVal, InsertAtEnd);
3101 }
3102
3103 static ReturnInst* Create(LLVMContext &C, BasicBlock *InsertAtEnd) {
3104 return new(0) ReturnInst(C, InsertAtEnd);
3105 }
3106
3107 /// Provide fast operand accessors
3108 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
;
3109
3110 /// Convenience accessor. Returns null if there is no return value.
3111 Value *getReturnValue() const {
3112 return getNumOperands() != 0 ? getOperand(0) : nullptr;
3113 }
3114
3115 unsigned getNumSuccessors() const { return 0; }
3116
3117 // Methods for support type inquiry through isa, cast, and dyn_cast:
3118 static bool classof(const Instruction *I) {
3119 return (I->getOpcode() == Instruction::Ret);
3120 }
3121 static bool classof(const Value *V) {
3122 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3123 }
3124
3125private:
3126 friend TerminatorInst;
3127
3128 BasicBlock *getSuccessor(unsigned idx) const {
3129 llvm_unreachable("ReturnInst has no successors!")::llvm::llvm_unreachable_internal("ReturnInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3129)
;
3130 }
3131
3132 void setSuccessor(unsigned idx, BasicBlock *B) {
3133 llvm_unreachable("ReturnInst has no successors!")::llvm::llvm_unreachable_internal("ReturnInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3133)
;
3134 }
3135};
3136
3137template <>
3138struct OperandTraits<ReturnInst> : public VariadicOperandTraits<ReturnInst> {
3139};
3140
3141DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ReturnInst, Value)ReturnInst::op_iterator ReturnInst::op_begin() { return OperandTraits
<ReturnInst>::op_begin(this); } ReturnInst::const_op_iterator
ReturnInst::op_begin() const { return OperandTraits<ReturnInst
>::op_begin(const_cast<ReturnInst*>(this)); } ReturnInst
::op_iterator ReturnInst::op_end() { return OperandTraits<
ReturnInst>::op_end(this); } ReturnInst::const_op_iterator
ReturnInst::op_end() const { return OperandTraits<ReturnInst
>::op_end(const_cast<ReturnInst*>(this)); } Value *ReturnInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<ReturnInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<ReturnInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3141, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ReturnInst>::op_begin(const_cast
<ReturnInst*>(this))[i_nocapture].get()); } void ReturnInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<ReturnInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<ReturnInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3141, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ReturnInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned ReturnInst::getNumOperands() const { return OperandTraits
<ReturnInst>::operands(this); } template <int Idx_nocapture
> Use &ReturnInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
ReturnInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
3142
3143//===----------------------------------------------------------------------===//
3144// BranchInst Class
3145//===----------------------------------------------------------------------===//
3146
3147//===---------------------------------------------------------------------------
3148/// Conditional or Unconditional Branch instruction.
3149///
3150class BranchInst : public TerminatorInst {
3151 /// Ops list - Branches are strange. The operands are ordered:
3152 /// [Cond, FalseDest,] TrueDest. This makes some accessors faster because
3153 /// they don't have to check for cond/uncond branchness. These are mostly
3154 /// accessed relative from op_end().
3155 BranchInst(const BranchInst &BI);
3156 // BranchInst constructors (where {B, T, F} are blocks, and C is a condition):
3157 // BranchInst(BB *B) - 'br B'
3158 // BranchInst(BB* T, BB *F, Value *C) - 'br C, T, F'
3159 // BranchInst(BB* B, Inst *I) - 'br B' insert before I
3160 // BranchInst(BB* T, BB *F, Value *C, Inst *I) - 'br C, T, F', insert before I
3161 // BranchInst(BB* B, BB *I) - 'br B' insert at end
3162 // BranchInst(BB* T, BB *F, Value *C, BB *I) - 'br C, T, F', insert at end
3163 explicit BranchInst(BasicBlock *IfTrue, Instruction *InsertBefore = nullptr);
3164 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
3165 Instruction *InsertBefore = nullptr);
3166 BranchInst(BasicBlock *IfTrue, BasicBlock *InsertAtEnd);
3167 BranchInst(BasicBlock *IfTrue, BasicBlock *IfFalse, Value *Cond,
3168 BasicBlock *InsertAtEnd);
3169
3170 void AssertOK();
3171
3172protected:
3173 // Note: Instruction needs to be a friend here to call cloneImpl.
3174 friend class Instruction;
3175
3176 BranchInst *cloneImpl() const;
3177
3178public:
3179 static BranchInst *Create(BasicBlock *IfTrue,
3180 Instruction *InsertBefore = nullptr) {
3181 return new(1) BranchInst(IfTrue, InsertBefore);
3182 }
3183
3184 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
3185 Value *Cond, Instruction *InsertBefore = nullptr) {
3186 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertBefore);
3187 }
3188
3189 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *InsertAtEnd) {
3190 return new(1) BranchInst(IfTrue, InsertAtEnd);
3191 }
3192
3193 static BranchInst *Create(BasicBlock *IfTrue, BasicBlock *IfFalse,
3194 Value *Cond, BasicBlock *InsertAtEnd) {
3195 return new(3) BranchInst(IfTrue, IfFalse, Cond, InsertAtEnd);
3196 }
3197
3198 /// Transparently provide more efficient getOperand methods.
3199 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
;
3200
3201 bool isUnconditional() const { return getNumOperands() == 1; }
3202 bool isConditional() const { return getNumOperands() == 3; }
3203
3204 Value *getCondition() const {
3205 assert(isConditional() && "Cannot get condition of an uncond branch!")(static_cast <bool> (isConditional() && "Cannot get condition of an uncond branch!"
) ? void (0) : __assert_fail ("isConditional() && \"Cannot get condition of an uncond branch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3205, __extension__ __PRETTY_FUNCTION__))
;
3206 return Op<-3>();
3207 }
3208
3209 void setCondition(Value *V) {
3210 assert(isConditional() && "Cannot set condition of unconditional branch!")(static_cast <bool> (isConditional() && "Cannot set condition of unconditional branch!"
) ? void (0) : __assert_fail ("isConditional() && \"Cannot set condition of unconditional branch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3210, __extension__ __PRETTY_FUNCTION__))
;
3211 Op<-3>() = V;
3212 }
3213
3214 unsigned getNumSuccessors() const { return 1+isConditional(); }
3215
3216 BasicBlock *getSuccessor(unsigned i) const {
3217 assert(i < getNumSuccessors() && "Successor # out of range for Branch!")(static_cast <bool> (i < getNumSuccessors() &&
"Successor # out of range for Branch!") ? void (0) : __assert_fail
("i < getNumSuccessors() && \"Successor # out of range for Branch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3217, __extension__ __PRETTY_FUNCTION__))
;
3218 return cast_or_null<BasicBlock>((&Op<-1>() - i)->get());
3219 }
3220
3221 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3222 assert(idx < getNumSuccessors() && "Successor # out of range for Branch!")(static_cast <bool> (idx < getNumSuccessors() &&
"Successor # out of range for Branch!") ? void (0) : __assert_fail
("idx < getNumSuccessors() && \"Successor # out of range for Branch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3222, __extension__ __PRETTY_FUNCTION__))
;
3223 *(&Op<-1>() - idx) = NewSucc;
3224 }
3225
3226 /// Swap the successors of this branch instruction.
3227 ///
3228 /// Swaps the successors of the branch instruction. This also swaps any
3229 /// branch weight metadata associated with the instruction so that it
3230 /// continues to map correctly to each operand.
3231 void swapSuccessors();
3232
3233 // Methods for support type inquiry through isa, cast, and dyn_cast:
3234 static bool classof(const Instruction *I) {
3235 return (I->getOpcode() == Instruction::Br);
3236 }
3237 static bool classof(const Value *V) {
3238 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3239 }
3240};
3241
3242template <>
3243struct OperandTraits<BranchInst> : public VariadicOperandTraits<BranchInst, 1> {
3244};
3245
3246DEFINE_TRANSPARENT_OPERAND_ACCESSORS(BranchInst, Value)BranchInst::op_iterator BranchInst::op_begin() { return OperandTraits
<BranchInst>::op_begin(this); } BranchInst::const_op_iterator
BranchInst::op_begin() const { return OperandTraits<BranchInst
>::op_begin(const_cast<BranchInst*>(this)); } BranchInst
::op_iterator BranchInst::op_end() { return OperandTraits<
BranchInst>::op_end(this); } BranchInst::const_op_iterator
BranchInst::op_end() const { return OperandTraits<BranchInst
>::op_end(const_cast<BranchInst*>(this)); } Value *BranchInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<BranchInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<BranchInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3246, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<BranchInst>::op_begin(const_cast
<BranchInst*>(this))[i_nocapture].get()); } void BranchInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<BranchInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<BranchInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3246, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
BranchInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned BranchInst::getNumOperands() const { return OperandTraits
<BranchInst>::operands(this); } template <int Idx_nocapture
> Use &BranchInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
BranchInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
3247
3248//===----------------------------------------------------------------------===//
3249// SwitchInst Class
3250//===----------------------------------------------------------------------===//
3251
3252//===---------------------------------------------------------------------------
3253/// Multiway switch
3254///
3255class SwitchInst : public TerminatorInst {
3256 unsigned ReservedSpace;
3257
3258 // Operand[0] = Value to switch on
3259 // Operand[1] = Default basic block destination
3260 // Operand[2n ] = Value to match
3261 // Operand[2n+1] = BasicBlock to go to on match
3262 SwitchInst(const SwitchInst &SI);
3263
3264 /// Create a new switch instruction, specifying a value to switch on and a
3265 /// default destination. The number of additional cases can be specified here
3266 /// to make memory allocation more efficient. This constructor can also
3267 /// auto-insert before another instruction.
3268 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3269 Instruction *InsertBefore);
3270
3271 /// Create a new switch instruction, specifying a value to switch on and a
3272 /// default destination. The number of additional cases can be specified here
3273 /// to make memory allocation more efficient. This constructor also
3274 /// auto-inserts at the end of the specified BasicBlock.
3275 SwitchInst(Value *Value, BasicBlock *Default, unsigned NumCases,
3276 BasicBlock *InsertAtEnd);
3277
3278 // allocate space for exactly zero operands
3279 void *operator new(size_t s) {
3280 return User::operator new(s);
3281 }
3282
3283 void init(Value *Value, BasicBlock *Default, unsigned NumReserved);
3284 void growOperands();
3285
3286protected:
3287 // Note: Instruction needs to be a friend here to call cloneImpl.
3288 friend class Instruction;
3289
3290 SwitchInst *cloneImpl() const;
3291
3292public:
3293 // -2
3294 static const unsigned DefaultPseudoIndex = static_cast<unsigned>(~0L-1);
3295
3296 template <typename CaseHandleT> class CaseIteratorImpl;
3297
3298 /// A handle to a particular switch case. It exposes a convenient interface
3299 /// to both the case value and the successor block.
3300 ///
3301 /// We define this as a template and instantiate it to form both a const and
3302 /// non-const handle.
3303 template <typename SwitchInstT, typename ConstantIntT, typename BasicBlockT>
3304 class CaseHandleImpl {
3305 // Directly befriend both const and non-const iterators.
3306 friend class SwitchInst::CaseIteratorImpl<
3307 CaseHandleImpl<SwitchInstT, ConstantIntT, BasicBlockT>>;
3308
3309 protected:
3310 // Expose the switch type we're parameterized with to the iterator.
3311 using SwitchInstType = SwitchInstT;
3312
3313 SwitchInstT *SI;
3314 ptrdiff_t Index;
3315
3316 CaseHandleImpl() = default;
3317 CaseHandleImpl(SwitchInstT *SI, ptrdiff_t Index) : SI(SI), Index(Index) {}
3318
3319 public:
3320 /// Resolves case value for current case.
3321 ConstantIntT *getCaseValue() const {
3322 assert((unsigned)Index < SI->getNumCases() &&(static_cast <bool> ((unsigned)Index < SI->getNumCases
() && "Index out the number of cases.") ? void (0) : __assert_fail
("(unsigned)Index < SI->getNumCases() && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3323, __extension__ __PRETTY_FUNCTION__))
3323 "Index out the number of cases.")(static_cast <bool> ((unsigned)Index < SI->getNumCases
() && "Index out the number of cases.") ? void (0) : __assert_fail
("(unsigned)Index < SI->getNumCases() && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3323, __extension__ __PRETTY_FUNCTION__))
;
3324 return reinterpret_cast<ConstantIntT *>(SI->getOperand(2 + Index * 2));
3325 }
3326
3327 /// Resolves successor for current case.
3328 BasicBlockT *getCaseSuccessor() const {
3329 assert(((unsigned)Index < SI->getNumCases() ||(static_cast <bool> (((unsigned)Index < SI->getNumCases
() || (unsigned)Index == DefaultPseudoIndex) && "Index out the number of cases."
) ? void (0) : __assert_fail ("((unsigned)Index < SI->getNumCases() || (unsigned)Index == DefaultPseudoIndex) && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3331, __extension__ __PRETTY_FUNCTION__))
3330 (unsigned)Index == DefaultPseudoIndex) &&(static_cast <bool> (((unsigned)Index < SI->getNumCases
() || (unsigned)Index == DefaultPseudoIndex) && "Index out the number of cases."
) ? void (0) : __assert_fail ("((unsigned)Index < SI->getNumCases() || (unsigned)Index == DefaultPseudoIndex) && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3331, __extension__ __PRETTY_FUNCTION__))
3331 "Index out the number of cases.")(static_cast <bool> (((unsigned)Index < SI->getNumCases
() || (unsigned)Index == DefaultPseudoIndex) && "Index out the number of cases."
) ? void (0) : __assert_fail ("((unsigned)Index < SI->getNumCases() || (unsigned)Index == DefaultPseudoIndex) && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3331, __extension__ __PRETTY_FUNCTION__))
;
3332 return SI->getSuccessor(getSuccessorIndex());
3333 }
3334
3335 /// Returns number of current case.
3336 unsigned getCaseIndex() const { return Index; }
3337
3338 /// Returns TerminatorInst's successor index for current case successor.
3339 unsigned getSuccessorIndex() const {
3340 assert(((unsigned)Index == DefaultPseudoIndex ||(static_cast <bool> (((unsigned)Index == DefaultPseudoIndex
|| (unsigned)Index < SI->getNumCases()) && "Index out the number of cases."
) ? void (0) : __assert_fail ("((unsigned)Index == DefaultPseudoIndex || (unsigned)Index < SI->getNumCases()) && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3342, __extension__ __PRETTY_FUNCTION__))
3341 (unsigned)Index < SI->getNumCases()) &&(static_cast <bool> (((unsigned)Index == DefaultPseudoIndex
|| (unsigned)Index < SI->getNumCases()) && "Index out the number of cases."
) ? void (0) : __assert_fail ("((unsigned)Index == DefaultPseudoIndex || (unsigned)Index < SI->getNumCases()) && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3342, __extension__ __PRETTY_FUNCTION__))
3342 "Index out the number of cases.")(static_cast <bool> (((unsigned)Index == DefaultPseudoIndex
|| (unsigned)Index < SI->getNumCases()) && "Index out the number of cases."
) ? void (0) : __assert_fail ("((unsigned)Index == DefaultPseudoIndex || (unsigned)Index < SI->getNumCases()) && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3342, __extension__ __PRETTY_FUNCTION__))
;
3343 return (unsigned)Index != DefaultPseudoIndex ? Index + 1 : 0;
3344 }
3345
3346 bool operator==(const CaseHandleImpl &RHS) const {
3347 assert(SI == RHS.SI && "Incompatible operators.")(static_cast <bool> (SI == RHS.SI && "Incompatible operators."
) ? void (0) : __assert_fail ("SI == RHS.SI && \"Incompatible operators.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3347, __extension__ __PRETTY_FUNCTION__))
;
3348 return Index == RHS.Index;
3349 }
3350 };
3351
3352 using ConstCaseHandle =
3353 CaseHandleImpl<const SwitchInst, const ConstantInt, const BasicBlock>;
3354
3355 class CaseHandle
3356 : public CaseHandleImpl<SwitchInst, ConstantInt, BasicBlock> {
3357 friend class SwitchInst::CaseIteratorImpl<CaseHandle>;
3358
3359 public:
3360 CaseHandle(SwitchInst *SI, ptrdiff_t Index) : CaseHandleImpl(SI, Index) {}
3361
3362 /// Sets the new value for current case.
3363 void setValue(ConstantInt *V) {
3364 assert((unsigned)Index < SI->getNumCases() &&(static_cast <bool> ((unsigned)Index < SI->getNumCases
() && "Index out the number of cases.") ? void (0) : __assert_fail
("(unsigned)Index < SI->getNumCases() && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3365, __extension__ __PRETTY_FUNCTION__))
3365 "Index out the number of cases.")(static_cast <bool> ((unsigned)Index < SI->getNumCases
() && "Index out the number of cases.") ? void (0) : __assert_fail
("(unsigned)Index < SI->getNumCases() && \"Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3365, __extension__ __PRETTY_FUNCTION__))
;
3366 SI->setOperand(2 + Index*2, reinterpret_cast<Value*>(V));
3367 }
3368
3369 /// Sets the new successor for current case.
3370 void setSuccessor(BasicBlock *S) {
3371 SI->setSuccessor(getSuccessorIndex(), S);
3372 }
3373 };
3374
3375 template <typename CaseHandleT>
3376 class CaseIteratorImpl
3377 : public iterator_facade_base<CaseIteratorImpl<CaseHandleT>,
3378 std::random_access_iterator_tag,
3379 CaseHandleT> {
3380 using SwitchInstT = typename CaseHandleT::SwitchInstType;
3381
3382 CaseHandleT Case;
3383
3384 public:
3385 /// Default constructed iterator is in an invalid state until assigned to
3386 /// a case for a particular switch.
3387 CaseIteratorImpl() = default;
3388
3389 /// Initializes case iterator for given SwitchInst and for given
3390 /// case number.
3391 CaseIteratorImpl(SwitchInstT *SI, unsigned CaseNum) : Case(SI, CaseNum) {}
3392
3393 /// Initializes case iterator for given SwitchInst and for given
3394 /// TerminatorInst's successor index.
3395 static CaseIteratorImpl fromSuccessorIndex(SwitchInstT *SI,
3396 unsigned SuccessorIndex) {
3397 assert(SuccessorIndex < SI->getNumSuccessors() &&(static_cast <bool> (SuccessorIndex < SI->getNumSuccessors
() && "Successor index # out of range!") ? void (0) :
__assert_fail ("SuccessorIndex < SI->getNumSuccessors() && \"Successor index # out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3398, __extension__ __PRETTY_FUNCTION__))
3398 "Successor index # out of range!")(static_cast <bool> (SuccessorIndex < SI->getNumSuccessors
() && "Successor index # out of range!") ? void (0) :
__assert_fail ("SuccessorIndex < SI->getNumSuccessors() && \"Successor index # out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3398, __extension__ __PRETTY_FUNCTION__))
;
3399 return SuccessorIndex != 0 ? CaseIteratorImpl(SI, SuccessorIndex - 1)
3400 : CaseIteratorImpl(SI, DefaultPseudoIndex);
3401 }
3402
3403 /// Support converting to the const variant. This will be a no-op for const
3404 /// variant.
3405 operator CaseIteratorImpl<ConstCaseHandle>() const {
3406 return CaseIteratorImpl<ConstCaseHandle>(Case.SI, Case.Index);
3407 }
3408
3409 CaseIteratorImpl &operator+=(ptrdiff_t N) {
3410 // Check index correctness after addition.
3411 // Note: Index == getNumCases() means end().
3412 assert(Case.Index + N >= 0 &&(static_cast <bool> (Case.Index + N >= 0 && (
unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&
"Case.Index out the number of cases.") ? void (0) : __assert_fail
("Case.Index + N >= 0 && (unsigned)(Case.Index + N) <= Case.SI->getNumCases() && \"Case.Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3414, __extension__ __PRETTY_FUNCTION__))
3413 (unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&(static_cast <bool> (Case.Index + N >= 0 && (
unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&
"Case.Index out the number of cases.") ? void (0) : __assert_fail
("Case.Index + N >= 0 && (unsigned)(Case.Index + N) <= Case.SI->getNumCases() && \"Case.Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3414, __extension__ __PRETTY_FUNCTION__))
3414 "Case.Index out the number of cases.")(static_cast <bool> (Case.Index + N >= 0 && (
unsigned)(Case.Index + N) <= Case.SI->getNumCases() &&
"Case.Index out the number of cases.") ? void (0) : __assert_fail
("Case.Index + N >= 0 && (unsigned)(Case.Index + N) <= Case.SI->getNumCases() && \"Case.Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3414, __extension__ __PRETTY_FUNCTION__))
;
3415 Case.Index += N;
3416 return *this;
3417 }
3418 CaseIteratorImpl &operator-=(ptrdiff_t N) {
3419 // Check index correctness after subtraction.
3420 // Note: Case.Index == getNumCases() means end().
3421 assert(Case.Index - N >= 0 &&(static_cast <bool> (Case.Index - N >= 0 && (
unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&
"Case.Index out the number of cases.") ? void (0) : __assert_fail
("Case.Index - N >= 0 && (unsigned)(Case.Index - N) <= Case.SI->getNumCases() && \"Case.Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3423, __extension__ __PRETTY_FUNCTION__))
3422 (unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&(static_cast <bool> (Case.Index - N >= 0 && (
unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&
"Case.Index out the number of cases.") ? void (0) : __assert_fail
("Case.Index - N >= 0 && (unsigned)(Case.Index - N) <= Case.SI->getNumCases() && \"Case.Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3423, __extension__ __PRETTY_FUNCTION__))
3423 "Case.Index out the number of cases.")(static_cast <bool> (Case.Index - N >= 0 && (
unsigned)(Case.Index - N) <= Case.SI->getNumCases() &&
"Case.Index out the number of cases.") ? void (0) : __assert_fail
("Case.Index - N >= 0 && (unsigned)(Case.Index - N) <= Case.SI->getNumCases() && \"Case.Index out the number of cases.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3423, __extension__ __PRETTY_FUNCTION__))
;
3424 Case.Index -= N;
3425 return *this;
3426 }
3427 ptrdiff_t operator-(const CaseIteratorImpl &RHS) const {
3428 assert(Case.SI == RHS.Case.SI && "Incompatible operators.")(static_cast <bool> (Case.SI == RHS.Case.SI && "Incompatible operators."
) ? void (0) : __assert_fail ("Case.SI == RHS.Case.SI && \"Incompatible operators.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3428, __extension__ __PRETTY_FUNCTION__))
;
3429 return Case.Index - RHS.Case.Index;
3430 }
3431 bool operator==(const CaseIteratorImpl &RHS) const {
3432 return Case == RHS.Case;
3433 }
3434 bool operator<(const CaseIteratorImpl &RHS) const {
3435 assert(Case.SI == RHS.Case.SI && "Incompatible operators.")(static_cast <bool> (Case.SI == RHS.Case.SI && "Incompatible operators."
) ? void (0) : __assert_fail ("Case.SI == RHS.Case.SI && \"Incompatible operators.\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3435, __extension__ __PRETTY_FUNCTION__))
;
3436 return Case.Index < RHS.Case.Index;
3437 }
3438 CaseHandleT &operator*() { return Case; }
3439 const CaseHandleT &operator*() const { return Case; }
3440 };
3441
3442 using CaseIt = CaseIteratorImpl<CaseHandle>;
3443 using ConstCaseIt = CaseIteratorImpl<ConstCaseHandle>;
3444
3445 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3446 unsigned NumCases,
3447 Instruction *InsertBefore = nullptr) {
3448 return new SwitchInst(Value, Default, NumCases, InsertBefore);
3449 }
3450
3451 static SwitchInst *Create(Value *Value, BasicBlock *Default,
3452 unsigned NumCases, BasicBlock *InsertAtEnd) {
3453 return new SwitchInst(Value, Default, NumCases, InsertAtEnd);
3454 }
3455
3456 /// Provide fast operand accessors
3457 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
;
3458
3459 // Accessor Methods for Switch stmt
3460 Value *getCondition() const { return getOperand(0); }
3461 void setCondition(Value *V) { setOperand(0, V); }
3462
3463 BasicBlock *getDefaultDest() const {
3464 return cast<BasicBlock>(getOperand(1));
3465 }
3466
3467 void setDefaultDest(BasicBlock *DefaultCase) {
3468 setOperand(1, reinterpret_cast<Value*>(DefaultCase));
3469 }
3470
3471 /// Return the number of 'cases' in this switch instruction, excluding the
3472 /// default case.
3473 unsigned getNumCases() const {
3474 return getNumOperands()/2 - 1;
3475 }
3476
3477 /// Returns a read/write iterator that points to the first case in the
3478 /// SwitchInst.
3479 CaseIt case_begin() {
3480 return CaseIt(this, 0);
3481 }
3482
3483 /// Returns a read-only iterator that points to the first case in the
3484 /// SwitchInst.
3485 ConstCaseIt case_begin() const {
3486 return ConstCaseIt(this, 0);
3487 }
3488
3489 /// Returns a read/write iterator that points one past the last in the
3490 /// SwitchInst.
3491 CaseIt case_end() {
3492 return CaseIt(this, getNumCases());
3493 }
3494
3495 /// Returns a read-only iterator that points one past the last in the
3496 /// SwitchInst.
3497 ConstCaseIt case_end() const {
3498 return ConstCaseIt(this, getNumCases());
3499 }
3500
3501 /// Iteration adapter for range-for loops.
3502 iterator_range<CaseIt> cases() {
3503 return make_range(case_begin(), case_end());
3504 }
3505
3506 /// Constant iteration adapter for range-for loops.
3507 iterator_range<ConstCaseIt> cases() const {
3508 return make_range(case_begin(), case_end());
3509 }
3510
3511 /// Returns an iterator that points to the default case.
3512 /// Note: this iterator allows to resolve successor only. Attempt
3513 /// to resolve case value causes an assertion.
3514 /// Also note, that increment and decrement also causes an assertion and
3515 /// makes iterator invalid.
3516 CaseIt case_default() {
3517 return CaseIt(this, DefaultPseudoIndex);
3518 }
3519 ConstCaseIt case_default() const {
3520 return ConstCaseIt(this, DefaultPseudoIndex);
3521 }
3522
3523 /// Search all of the case values for the specified constant. If it is
3524 /// explicitly handled, return the case iterator of it, otherwise return
3525 /// default case iterator to indicate that it is handled by the default
3526 /// handler.
3527 CaseIt findCaseValue(const ConstantInt *C) {
3528 CaseIt I = llvm::find_if(
3529 cases(), [C](CaseHandle &Case) { return Case.getCaseValue() == C; });
3530 if (I != case_end())
3531 return I;
3532
3533 return case_default();
3534 }
3535 ConstCaseIt findCaseValue(const ConstantInt *C) const {
3536 ConstCaseIt I = llvm::find_if(cases(), [C](ConstCaseHandle &Case) {
3537 return Case.getCaseValue() == C;
3538 });
3539 if (I != case_end())
3540 return I;
3541
3542 return case_default();
3543 }
3544
3545 /// Finds the unique case value for a given successor. Returns null if the
3546 /// successor is not found, not unique, or is the default case.
3547 ConstantInt *findCaseDest(BasicBlock *BB) {
3548 if (BB == getDefaultDest())
3549 return nullptr;
3550
3551 ConstantInt *CI = nullptr;
3552 for (auto Case : cases()) {
3553 if (Case.getCaseSuccessor() != BB)
3554 continue;
3555
3556 if (CI)
3557 return nullptr; // Multiple cases lead to BB.
3558
3559 CI = Case.getCaseValue();
3560 }
3561
3562 return CI;
3563 }
3564
3565 /// Add an entry to the switch instruction.
3566 /// Note:
3567 /// This action invalidates case_end(). Old case_end() iterator will
3568 /// point to the added case.
3569 void addCase(ConstantInt *OnVal, BasicBlock *Dest);
3570
3571 /// This method removes the specified case and its successor from the switch
3572 /// instruction. Note that this operation may reorder the remaining cases at
3573 /// index idx and above.
3574 /// Note:
3575 /// This action invalidates iterators for all cases following the one removed,
3576 /// including the case_end() iterator. It returns an iterator for the next
3577 /// case.
3578 CaseIt removeCase(CaseIt I);
3579
3580 unsigned getNumSuccessors() const { return getNumOperands()/2; }
3581 BasicBlock *getSuccessor(unsigned idx) const {
3582 assert(idx < getNumSuccessors() &&"Successor idx out of range for switch!")(static_cast <bool> (idx < getNumSuccessors() &&
"Successor idx out of range for switch!") ? void (0) : __assert_fail
("idx < getNumSuccessors() &&\"Successor idx out of range for switch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3582, __extension__ __PRETTY_FUNCTION__))
;
3583 return cast<BasicBlock>(getOperand(idx*2+1));
3584 }
3585 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3586 assert(idx < getNumSuccessors() && "Successor # out of range for switch!")(static_cast <bool> (idx < getNumSuccessors() &&
"Successor # out of range for switch!") ? void (0) : __assert_fail
("idx < getNumSuccessors() && \"Successor # out of range for switch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3586, __extension__ __PRETTY_FUNCTION__))
;
3587 setOperand(idx * 2 + 1, NewSucc);
3588 }
3589
3590 // Methods for support type inquiry through isa, cast, and dyn_cast:
3591 static bool classof(const Instruction *I) {
3592 return I->getOpcode() == Instruction::Switch;
3593 }
3594 static bool classof(const Value *V) {
3595 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3596 }
3597};
3598
3599template <>
3600struct OperandTraits<SwitchInst> : public HungoffOperandTraits<2> {
3601};
3602
3603DEFINE_TRANSPARENT_OPERAND_ACCESSORS(SwitchInst, Value)SwitchInst::op_iterator SwitchInst::op_begin() { return OperandTraits
<SwitchInst>::op_begin(this); } SwitchInst::const_op_iterator
SwitchInst::op_begin() const { return OperandTraits<SwitchInst
>::op_begin(const_cast<SwitchInst*>(this)); } SwitchInst
::op_iterator SwitchInst::op_end() { return OperandTraits<
SwitchInst>::op_end(this); } SwitchInst::const_op_iterator
SwitchInst::op_end() const { return OperandTraits<SwitchInst
>::op_end(const_cast<SwitchInst*>(this)); } Value *SwitchInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<SwitchInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<SwitchInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3603, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<SwitchInst>::op_begin(const_cast
<SwitchInst*>(this))[i_nocapture].get()); } void SwitchInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<SwitchInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<SwitchInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3603, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
SwitchInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned SwitchInst::getNumOperands() const { return OperandTraits
<SwitchInst>::operands(this); } template <int Idx_nocapture
> Use &SwitchInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
SwitchInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
3604
3605//===----------------------------------------------------------------------===//
3606// IndirectBrInst Class
3607//===----------------------------------------------------------------------===//
3608
3609//===---------------------------------------------------------------------------
3610/// Indirect Branch Instruction.
3611///
3612class IndirectBrInst : public TerminatorInst {
3613 unsigned ReservedSpace;
3614
3615 // Operand[0] = Address to jump to
3616 // Operand[n+1] = n-th destination
3617 IndirectBrInst(const IndirectBrInst &IBI);
3618
3619 /// Create a new indirectbr instruction, specifying an
3620 /// Address to jump to. The number of expected destinations can be specified
3621 /// here to make memory allocation more efficient. This constructor can also
3622 /// autoinsert before another instruction.
3623 IndirectBrInst(Value *Address, unsigned NumDests, Instruction *InsertBefore);
3624
3625 /// Create a new indirectbr instruction, specifying an
3626 /// Address to jump to. The number of expected destinations can be specified
3627 /// here to make memory allocation more efficient. This constructor also
3628 /// autoinserts at the end of the specified BasicBlock.
3629 IndirectBrInst(Value *Address, unsigned NumDests, BasicBlock *InsertAtEnd);
3630
3631 // allocate space for exactly zero operands
3632 void *operator new(size_t s) {
3633 return User::operator new(s);
3634 }
3635
3636 void init(Value *Address, unsigned NumDests);
3637 void growOperands();
3638
3639protected:
3640 // Note: Instruction needs to be a friend here to call cloneImpl.
3641 friend class Instruction;
3642
3643 IndirectBrInst *cloneImpl() const;
3644
3645public:
3646 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3647 Instruction *InsertBefore = nullptr) {
3648 return new IndirectBrInst(Address, NumDests, InsertBefore);
3649 }
3650
3651 static IndirectBrInst *Create(Value *Address, unsigned NumDests,
3652 BasicBlock *InsertAtEnd) {
3653 return new IndirectBrInst(Address, NumDests, InsertAtEnd);
3654 }
3655
3656 /// Provide fast operand accessors.
3657 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
;
3658
3659 // Accessor Methods for IndirectBrInst instruction.
3660 Value *getAddress() { return getOperand(0); }
3661 const Value *getAddress() const { return getOperand(0); }
3662 void setAddress(Value *V) { setOperand(0, V); }
3663
3664 /// return the number of possible destinations in this
3665 /// indirectbr instruction.
3666 unsigned getNumDestinations() const { return getNumOperands()-1; }
3667
3668 /// Return the specified destination.
3669 BasicBlock *getDestination(unsigned i) { return getSuccessor(i); }
3670 const BasicBlock *getDestination(unsigned i) const { return getSuccessor(i); }
3671
3672 /// Add a destination.
3673 ///
3674 void addDestination(BasicBlock *Dest);
3675
3676 /// This method removes the specified successor from the
3677 /// indirectbr instruction.
3678 void removeDestination(unsigned i);
3679
3680 unsigned getNumSuccessors() const { return getNumOperands()-1; }
3681 BasicBlock *getSuccessor(unsigned i) const {
3682 return cast<BasicBlock>(getOperand(i+1));
3683 }
3684 void setSuccessor(unsigned i, BasicBlock *NewSucc) {
3685 setOperand(i + 1, NewSucc);
3686 }
3687
3688 // Methods for support type inquiry through isa, cast, and dyn_cast:
3689 static bool classof(const Instruction *I) {
3690 return I->getOpcode() == Instruction::IndirectBr;
3691 }
3692 static bool classof(const Value *V) {
3693 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3694 }
3695};
3696
3697template <>
3698struct OperandTraits<IndirectBrInst> : public HungoffOperandTraits<1> {
3699};
3700
3701DEFINE_TRANSPARENT_OPERAND_ACCESSORS(IndirectBrInst, Value)IndirectBrInst::op_iterator IndirectBrInst::op_begin() { return
OperandTraits<IndirectBrInst>::op_begin(this); } IndirectBrInst
::const_op_iterator IndirectBrInst::op_begin() const { return
OperandTraits<IndirectBrInst>::op_begin(const_cast<
IndirectBrInst*>(this)); } IndirectBrInst::op_iterator IndirectBrInst
::op_end() { return OperandTraits<IndirectBrInst>::op_end
(this); } IndirectBrInst::const_op_iterator IndirectBrInst::op_end
() const { return OperandTraits<IndirectBrInst>::op_end
(const_cast<IndirectBrInst*>(this)); } Value *IndirectBrInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<IndirectBrInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<IndirectBrInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3701, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<IndirectBrInst>::op_begin(
const_cast<IndirectBrInst*>(this))[i_nocapture].get());
} void IndirectBrInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<IndirectBrInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<IndirectBrInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3701, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
IndirectBrInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned IndirectBrInst::getNumOperands() const { return OperandTraits
<IndirectBrInst>::operands(this); } template <int Idx_nocapture
> Use &IndirectBrInst::Op() { return this->OpFrom<
Idx_nocapture>(this); } template <int Idx_nocapture>
const Use &IndirectBrInst::Op() const { return this->
OpFrom<Idx_nocapture>(this); }
3702
3703//===----------------------------------------------------------------------===//
3704// InvokeInst Class
3705//===----------------------------------------------------------------------===//
3706
3707/// Invoke instruction. The SubclassData field is used to hold the
3708/// calling convention of the call.
3709///
3710class InvokeInst : public CallBase<InvokeInst> {
3711 friend class OperandBundleUser<InvokeInst, User::op_iterator>;
3712
3713 InvokeInst(const InvokeInst &BI);
3714
3715 /// Construct an InvokeInst given a range of arguments.
3716 ///
3717 /// Construct an InvokeInst from a range of arguments
3718 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3719 ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3720 unsigned Values, const Twine &NameStr,
3721 Instruction *InsertBefore)
3722 : InvokeInst(cast<FunctionType>(
3723 cast<PointerType>(Func->getType())->getElementType()),
3724 Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
3725 InsertBefore) {}
3726
3727 inline InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3728 BasicBlock *IfException, ArrayRef<Value *> Args,
3729 ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3730 const Twine &NameStr, Instruction *InsertBefore);
3731 /// Construct an InvokeInst given a range of arguments.
3732 ///
3733 /// Construct an InvokeInst from a range of arguments
3734 inline InvokeInst(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3735 ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3736 unsigned Values, const Twine &NameStr,
3737 BasicBlock *InsertAtEnd);
3738
3739
3740 void init(Value *Func, BasicBlock *IfNormal, BasicBlock *IfException,
3741 ArrayRef<Value *> Args, ArrayRef<OperandBundleDef> Bundles,
3742 const Twine &NameStr) {
3743 init(cast<FunctionType>(
3744 cast<PointerType>(Func->getType())->getElementType()),
3745 Func, IfNormal, IfException, Args, Bundles, NameStr);
3746 }
3747
3748 void init(FunctionType *FTy, Value *Func, BasicBlock *IfNormal,
3749 BasicBlock *IfException, ArrayRef<Value *> Args,
3750 ArrayRef<OperandBundleDef> Bundles, const Twine &NameStr);
3751
3752protected:
3753 // Note: Instruction needs to be a friend here to call cloneImpl.
3754 friend class Instruction;
3755
3756 InvokeInst *cloneImpl() const;
3757
3758public:
3759 static constexpr int ArgOffset = 3;
3760 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3761 BasicBlock *IfException, ArrayRef<Value *> Args,
3762 const Twine &NameStr,
3763 Instruction *InsertBefore = nullptr) {
3764 return Create(cast<FunctionType>(
3765 cast<PointerType>(Func->getType())->getElementType()),
3766 Func, IfNormal, IfException, Args, None, NameStr,
3767 InsertBefore);
3768 }
3769
3770 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3771 BasicBlock *IfException, ArrayRef<Value *> Args,
3772 ArrayRef<OperandBundleDef> Bundles = None,
3773 const Twine &NameStr = "",
3774 Instruction *InsertBefore = nullptr) {
3775 return Create(cast<FunctionType>(
3776 cast<PointerType>(Func->getType())->getElementType()),
3777 Func, IfNormal, IfException, Args, Bundles, NameStr,
3778 InsertBefore);
3779 }
3780
3781 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3782 BasicBlock *IfException, ArrayRef<Value *> Args,
3783 const Twine &NameStr,
3784 Instruction *InsertBefore = nullptr) {
3785 unsigned Values = unsigned(Args.size()) + 3;
3786 return new (Values) InvokeInst(Ty, Func, IfNormal, IfException, Args, None,
3787 Values, NameStr, InsertBefore);
3788 }
3789
3790 static InvokeInst *Create(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3791 BasicBlock *IfException, ArrayRef<Value *> Args,
3792 ArrayRef<OperandBundleDef> Bundles = None,
3793 const Twine &NameStr = "",
3794 Instruction *InsertBefore = nullptr) {
3795 unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
3796 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3797
3798 return new (Values, DescriptorBytes)
3799 InvokeInst(Ty, Func, IfNormal, IfException, Args, Bundles, Values,
3800 NameStr, InsertBefore);
3801 }
3802
3803 static InvokeInst *Create(Value *Func,
3804 BasicBlock *IfNormal, BasicBlock *IfException,
3805 ArrayRef<Value *> Args, const Twine &NameStr,
3806 BasicBlock *InsertAtEnd) {
3807 unsigned Values = unsigned(Args.size()) + 3;
3808 return new (Values) InvokeInst(Func, IfNormal, IfException, Args, None,
3809 Values, NameStr, InsertAtEnd);
3810 }
3811
3812 static InvokeInst *Create(Value *Func, BasicBlock *IfNormal,
3813 BasicBlock *IfException, ArrayRef<Value *> Args,
3814 ArrayRef<OperandBundleDef> Bundles,
3815 const Twine &NameStr, BasicBlock *InsertAtEnd) {
3816 unsigned Values = unsigned(Args.size()) + CountBundleInputs(Bundles) + 3;
3817 unsigned DescriptorBytes = Bundles.size() * sizeof(BundleOpInfo);
3818
3819 return new (Values, DescriptorBytes)
3820 InvokeInst(Func, IfNormal, IfException, Args, Bundles, Values, NameStr,
3821 InsertAtEnd);
3822 }
3823
3824 /// Create a clone of \p II with a different set of operand bundles and
3825 /// insert it before \p InsertPt.
3826 ///
3827 /// The returned invoke instruction is identical to \p II in every way except
3828 /// that the operand bundles for the new instruction are set to the operand
3829 /// bundles in \p Bundles.
3830 static InvokeInst *Create(InvokeInst *II, ArrayRef<OperandBundleDef> Bundles,
3831 Instruction *InsertPt = nullptr);
3832
3833
3834
3835 /// Return the function called, or null if this is an
3836 /// indirect function invocation.
3837 ///
3838 Function *getCalledFunction() const {
3839 return dyn_cast<Function>(Op<-3>());
3840 }
3841
3842 /// Get a pointer to the function that is invoked by this
3843 /// instruction
3844 const Value *getCalledValue() const { return Op<-3>(); }
3845 Value *getCalledValue() { return Op<-3>(); }
3846
3847 /// Set the function called.
3848 void setCalledFunction(Value* Fn) {
3849 setCalledFunction(
3850 cast<FunctionType>(cast<PointerType>(Fn->getType())->getElementType()),
3851 Fn);
3852 }
3853 void setCalledFunction(FunctionType *FTy, Value *Fn) {
3854 this->FTy = FTy;
3855 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~svn326246/include/llvm/IR/Instructions.h"
, 3856, __extension__ __PRETTY_FUNCTION__))
3856 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~svn326246/include/llvm/IR/Instructions.h"
, 3856, __extension__ __PRETTY_FUNCTION__))
;
3857 Op<-3>() = Fn;
3858 }
3859
3860 // get*Dest - Return the destination basic blocks...
3861 BasicBlock *getNormalDest() const {
3862 return cast<BasicBlock>(Op<-2>());
3863 }
3864 BasicBlock *getUnwindDest() const {
3865 return cast<BasicBlock>(Op<-1>());
3866 }
3867 void setNormalDest(BasicBlock *B) {
3868 Op<-2>() = reinterpret_cast<Value*>(B);
3869 }
3870 void setUnwindDest(BasicBlock *B) {
3871 Op<-1>() = reinterpret_cast<Value*>(B);
3872 }
3873
3874 /// Get the landingpad instruction from the landing pad
3875 /// block (the unwind destination).
3876 LandingPadInst *getLandingPadInst() const;
3877
3878 BasicBlock *getSuccessor(unsigned i) const {
3879 assert(i < 2 && "Successor # out of range for invoke!")(static_cast <bool> (i < 2 && "Successor # out of range for invoke!"
) ? void (0) : __assert_fail ("i < 2 && \"Successor # out of range for invoke!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3879, __extension__ __PRETTY_FUNCTION__))
;
3880 return i == 0 ? getNormalDest() : getUnwindDest();
3881 }
3882
3883 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3884 assert(idx < 2 && "Successor # out of range for invoke!")(static_cast <bool> (idx < 2 && "Successor # out of range for invoke!"
) ? void (0) : __assert_fail ("idx < 2 && \"Successor # out of range for invoke!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3884, __extension__ __PRETTY_FUNCTION__))
;
3885 *(&Op<-2>() + idx) = reinterpret_cast<Value*>(NewSucc);
3886 }
3887
3888 unsigned getNumSuccessors() const { return 2; }
3889
3890 // Methods for support type inquiry through isa, cast, and dyn_cast:
3891 static bool classof(const Instruction *I) {
3892 return (I->getOpcode() == Instruction::Invoke);
3893 }
3894 static bool classof(const Value *V) {
3895 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3896 }
3897
3898private:
3899
3900 // Shadow Instruction::setInstructionSubclassData with a private forwarding
3901 // method so that subclasses cannot accidentally use it.
3902 void setInstructionSubclassData(unsigned short D) {
3903 Instruction::setInstructionSubclassData(D);
3904 }
3905};
3906
3907template <>
3908struct OperandTraits<CallBase<InvokeInst>>
3909 : public VariadicOperandTraits<CallBase<InvokeInst>, 3> {};
3910
3911InvokeInst::InvokeInst(FunctionType *Ty, Value *Func, BasicBlock *IfNormal,
3912 BasicBlock *IfException, ArrayRef<Value *> Args,
3913 ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3914 const Twine &NameStr, Instruction *InsertBefore)
3915 : CallBase<InvokeInst>(Ty->getReturnType(), Instruction::Invoke,
3916 OperandTraits<CallBase<InvokeInst>>::op_end(this) -
3917 Values,
3918 Values, InsertBefore) {
3919 init(Ty, Func, IfNormal, IfException, Args, Bundles, NameStr);
3920}
3921
3922InvokeInst::InvokeInst(Value *Func, BasicBlock *IfNormal,
3923 BasicBlock *IfException, ArrayRef<Value *> Args,
3924 ArrayRef<OperandBundleDef> Bundles, unsigned Values,
3925 const Twine &NameStr, BasicBlock *InsertAtEnd)
3926 : CallBase<InvokeInst>(
3927 cast<FunctionType>(
3928 cast<PointerType>(Func->getType())->getElementType())
3929 ->getReturnType(),
3930 Instruction::Invoke,
3931 OperandTraits<CallBase<InvokeInst>>::op_end(this) - Values, Values,
3932 InsertAtEnd) {
3933 init(Func, IfNormal, IfException, Args, Bundles, NameStr);
3934}
3935
3936
3937//===----------------------------------------------------------------------===//
3938// ResumeInst Class
3939//===----------------------------------------------------------------------===//
3940
3941//===---------------------------------------------------------------------------
3942/// Resume the propagation of an exception.
3943///
3944class ResumeInst : public TerminatorInst {
3945 ResumeInst(const ResumeInst &RI);
3946
3947 explicit ResumeInst(Value *Exn, Instruction *InsertBefore=nullptr);
3948 ResumeInst(Value *Exn, BasicBlock *InsertAtEnd);
3949
3950protected:
3951 // Note: Instruction needs to be a friend here to call cloneImpl.
3952 friend class Instruction;
3953
3954 ResumeInst *cloneImpl() const;
3955
3956public:
3957 static ResumeInst *Create(Value *Exn, Instruction *InsertBefore = nullptr) {
3958 return new(1) ResumeInst(Exn, InsertBefore);
3959 }
3960
3961 static ResumeInst *Create(Value *Exn, BasicBlock *InsertAtEnd) {
3962 return new(1) ResumeInst(Exn, InsertAtEnd);
3963 }
3964
3965 /// Provide fast operand accessors
3966 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
;
3967
3968 /// Convenience accessor.
3969 Value *getValue() const { return Op<0>(); }
3970
3971 unsigned getNumSuccessors() const { return 0; }
3972
3973 // Methods for support type inquiry through isa, cast, and dyn_cast:
3974 static bool classof(const Instruction *I) {
3975 return I->getOpcode() == Instruction::Resume;
3976 }
3977 static bool classof(const Value *V) {
3978 return isa<Instruction>(V) && classof(cast<Instruction>(V));
3979 }
3980
3981private:
3982 friend TerminatorInst;
3983
3984 BasicBlock *getSuccessor(unsigned idx) const {
3985 llvm_unreachable("ResumeInst has no successors!")::llvm::llvm_unreachable_internal("ResumeInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3985)
;
3986 }
3987
3988 void setSuccessor(unsigned idx, BasicBlock *NewSucc) {
3989 llvm_unreachable("ResumeInst has no successors!")::llvm::llvm_unreachable_internal("ResumeInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3989)
;
3990 }
3991};
3992
3993template <>
3994struct OperandTraits<ResumeInst> :
3995 public FixedNumOperandTraits<ResumeInst, 1> {
3996};
3997
3998DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ResumeInst, Value)ResumeInst::op_iterator ResumeInst::op_begin() { return OperandTraits
<ResumeInst>::op_begin(this); } ResumeInst::const_op_iterator
ResumeInst::op_begin() const { return OperandTraits<ResumeInst
>::op_begin(const_cast<ResumeInst*>(this)); } ResumeInst
::op_iterator ResumeInst::op_end() { return OperandTraits<
ResumeInst>::op_end(this); } ResumeInst::const_op_iterator
ResumeInst::op_end() const { return OperandTraits<ResumeInst
>::op_end(const_cast<ResumeInst*>(this)); } Value *ResumeInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<ResumeInst>::operands
(this) && "getOperand() out of range!") ? void (0) : __assert_fail
("i_nocapture < OperandTraits<ResumeInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3998, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<ResumeInst>::op_begin(const_cast
<ResumeInst*>(this))[i_nocapture].get()); } void ResumeInst
::setOperand(unsigned i_nocapture, Value *Val_nocapture) { (static_cast
<bool> (i_nocapture < OperandTraits<ResumeInst>
::operands(this) && "setOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<ResumeInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 3998, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
ResumeInst>::op_begin(this)[i_nocapture] = Val_nocapture; }
unsigned ResumeInst::getNumOperands() const { return OperandTraits
<ResumeInst>::operands(this); } template <int Idx_nocapture
> Use &ResumeInst::Op() { return this->OpFrom<Idx_nocapture
>(this); } template <int Idx_nocapture> const Use &
ResumeInst::Op() const { return this->OpFrom<Idx_nocapture
>(this); }
3999
4000//===----------------------------------------------------------------------===//
4001// CatchSwitchInst Class
4002//===----------------------------------------------------------------------===//
4003class CatchSwitchInst : public TerminatorInst {
4004 /// The number of operands actually allocated. NumOperands is
4005 /// the number actually in use.
4006 unsigned ReservedSpace;
4007
4008 // Operand[0] = Outer scope
4009 // Operand[1] = Unwind block destination
4010 // Operand[n] = BasicBlock to go to on match
4011 CatchSwitchInst(const CatchSwitchInst &CSI);
4012
4013 /// Create a new switch instruction, specifying a
4014 /// default destination. The number of additional handlers can be specified
4015 /// here to make memory allocation more efficient.
4016 /// This constructor can also autoinsert before another instruction.
4017 CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4018 unsigned NumHandlers, const Twine &NameStr,
4019 Instruction *InsertBefore);
4020
4021 /// Create a new switch instruction, specifying a
4022 /// default destination. The number of additional handlers can be specified
4023 /// here to make memory allocation more efficient.
4024 /// This constructor also autoinserts at the end of the specified BasicBlock.
4025 CatchSwitchInst(Value *ParentPad, BasicBlock *UnwindDest,
4026 unsigned NumHandlers, const Twine &NameStr,
4027 BasicBlock *InsertAtEnd);
4028
4029 // allocate space for exactly zero operands
4030 void *operator new(size_t s) { return User::operator new(s); }
4031
4032 void init(Value *ParentPad, BasicBlock *UnwindDest, unsigned NumReserved);
4033 void growOperands(unsigned Size);
4034
4035protected:
4036 // Note: Instruction needs to be a friend here to call cloneImpl.
4037 friend class Instruction;
4038
4039 CatchSwitchInst *cloneImpl() const;
4040
4041public:
4042 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4043 unsigned NumHandlers,
4044 const Twine &NameStr = "",
4045 Instruction *InsertBefore = nullptr) {
4046 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4047 InsertBefore);
4048 }
4049
4050 static CatchSwitchInst *Create(Value *ParentPad, BasicBlock *UnwindDest,
4051 unsigned NumHandlers, const Twine &NameStr,
4052 BasicBlock *InsertAtEnd) {
4053 return new CatchSwitchInst(ParentPad, UnwindDest, NumHandlers, NameStr,
4054 InsertAtEnd);
4055 }
4056
4057 /// Provide fast operand accessors
4058 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
;
4059
4060 // Accessor Methods for CatchSwitch stmt
4061 Value *getParentPad() const { return getOperand(0); }
4062 void setParentPad(Value *ParentPad) { setOperand(0, ParentPad); }
4063
4064 // Accessor Methods for CatchSwitch stmt
4065 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4066 bool unwindsToCaller() const { return !hasUnwindDest(); }
4067 BasicBlock *getUnwindDest() const {
4068 if (hasUnwindDest())
4069 return cast<BasicBlock>(getOperand(1));
4070 return nullptr;
4071 }
4072 void setUnwindDest(BasicBlock *UnwindDest) {
4073 assert(UnwindDest)(static_cast <bool> (UnwindDest) ? void (0) : __assert_fail
("UnwindDest", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4073, __extension__ __PRETTY_FUNCTION__))
;
4074 assert(hasUnwindDest())(static_cast <bool> (hasUnwindDest()) ? void (0) : __assert_fail
("hasUnwindDest()", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4074, __extension__ __PRETTY_FUNCTION__))
;
4075 setOperand(1, UnwindDest);
4076 }
4077
4078 /// return the number of 'handlers' in this catchswitch
4079 /// instruction, except the default handler
4080 unsigned getNumHandlers() const {
4081 if (hasUnwindDest())
4082 return getNumOperands() - 2;
4083 return getNumOperands() - 1;
4084 }
4085
4086private:
4087 static BasicBlock *handler_helper(Value *V) { return cast<BasicBlock>(V); }
4088 static const BasicBlock *handler_helper(const Value *V) {
4089 return cast<BasicBlock>(V);
4090 }
4091
4092public:
4093 using DerefFnTy = BasicBlock *(*)(Value *);
4094 using handler_iterator = mapped_iterator<op_iterator, DerefFnTy>;
4095 using handler_range = iterator_range<handler_iterator>;
4096 using ConstDerefFnTy = const BasicBlock *(*)(const Value *);
4097 using const_handler_iterator =
4098 mapped_iterator<const_op_iterator, ConstDerefFnTy>;
4099 using const_handler_range = iterator_range<const_handler_iterator>;
4100
4101 /// Returns an iterator that points to the first handler in CatchSwitchInst.
4102 handler_iterator handler_begin() {
4103 op_iterator It = op_begin() + 1;
4104 if (hasUnwindDest())
4105 ++It;
4106 return handler_iterator(It, DerefFnTy(handler_helper));
4107 }
4108
4109 /// Returns an iterator that points to the first handler in the
4110 /// CatchSwitchInst.
4111 const_handler_iterator handler_begin() const {
4112 const_op_iterator It = op_begin() + 1;
4113 if (hasUnwindDest())
4114 ++It;
4115 return const_handler_iterator(It, ConstDerefFnTy(handler_helper));
4116 }
4117
4118 /// Returns a read-only iterator that points one past the last
4119 /// handler in the CatchSwitchInst.
4120 handler_iterator handler_end() {
4121 return handler_iterator(op_end(), DerefFnTy(handler_helper));
4122 }
4123
4124 /// Returns an iterator that points one past the last handler in the
4125 /// CatchSwitchInst.
4126 const_handler_iterator handler_end() const {
4127 return const_handler_iterator(op_end(), ConstDerefFnTy(handler_helper));
4128 }
4129
4130 /// iteration adapter for range-for loops.
4131 handler_range handlers() {
4132 return make_range(handler_begin(), handler_end());
4133 }
4134
4135 /// iteration adapter for range-for loops.
4136 const_handler_range handlers() const {
4137 return make_range(handler_begin(), handler_end());
4138 }
4139
4140 /// Add an entry to the switch instruction...
4141 /// Note:
4142 /// This action invalidates handler_end(). Old handler_end() iterator will
4143 /// point to the added handler.
4144 void addHandler(BasicBlock *Dest);
4145
4146 void removeHandler(handler_iterator HI);
4147
4148 unsigned getNumSuccessors() const { return getNumOperands() - 1; }
4149 BasicBlock *getSuccessor(unsigned Idx) const {
4150 assert(Idx < getNumSuccessors() &&(static_cast <bool> (Idx < getNumSuccessors() &&
"Successor # out of range for catchswitch!") ? void (0) : __assert_fail
("Idx < getNumSuccessors() && \"Successor # out of range for catchswitch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4151, __extension__ __PRETTY_FUNCTION__))
4151 "Successor # out of range for catchswitch!")(static_cast <bool> (Idx < getNumSuccessors() &&
"Successor # out of range for catchswitch!") ? void (0) : __assert_fail
("Idx < getNumSuccessors() && \"Successor # out of range for catchswitch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4151, __extension__ __PRETTY_FUNCTION__))
;
4152 return cast<BasicBlock>(getOperand(Idx + 1));
4153 }
4154 void setSuccessor(unsigned Idx, BasicBlock *NewSucc) {
4155 assert(Idx < getNumSuccessors() &&(static_cast <bool> (Idx < getNumSuccessors() &&
"Successor # out of range for catchswitch!") ? void (0) : __assert_fail
("Idx < getNumSuccessors() && \"Successor # out of range for catchswitch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4156, __extension__ __PRETTY_FUNCTION__))
4156 "Successor # out of range for catchswitch!")(static_cast <bool> (Idx < getNumSuccessors() &&
"Successor # out of range for catchswitch!") ? void (0) : __assert_fail
("Idx < getNumSuccessors() && \"Successor # out of range for catchswitch!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4156, __extension__ __PRETTY_FUNCTION__))
;
4157 setOperand(Idx + 1, NewSucc);
4158 }
4159
4160 // Methods for support type inquiry through isa, cast, and dyn_cast:
4161 static bool classof(const Instruction *I) {
4162 return I->getOpcode() == Instruction::CatchSwitch;
4163 }
4164 static bool classof(const Value *V) {
4165 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4166 }
4167};
4168
4169template <>
4170struct OperandTraits<CatchSwitchInst> : public HungoffOperandTraits<2> {};
4171
4172DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchSwitchInst, Value)CatchSwitchInst::op_iterator CatchSwitchInst::op_begin() { return
OperandTraits<CatchSwitchInst>::op_begin(this); } CatchSwitchInst
::const_op_iterator CatchSwitchInst::op_begin() const { return
OperandTraits<CatchSwitchInst>::op_begin(const_cast<
CatchSwitchInst*>(this)); } CatchSwitchInst::op_iterator CatchSwitchInst
::op_end() { return OperandTraits<CatchSwitchInst>::op_end
(this); } CatchSwitchInst::const_op_iterator CatchSwitchInst::
op_end() const { return OperandTraits<CatchSwitchInst>::
op_end(const_cast<CatchSwitchInst*>(this)); } Value *CatchSwitchInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<CatchSwitchInst>::
operands(this) && "getOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<CatchSwitchInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4172, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<CatchSwitchInst>::op_begin
(const_cast<CatchSwitchInst*>(this))[i_nocapture].get()
); } void CatchSwitchInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<CatchSwitchInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CatchSwitchInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4172, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
CatchSwitchInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned CatchSwitchInst::getNumOperands() const { return
OperandTraits<CatchSwitchInst>::operands(this); } template
<int Idx_nocapture> Use &CatchSwitchInst::Op() { return
this->OpFrom<Idx_nocapture>(this); } template <int
Idx_nocapture> const Use &CatchSwitchInst::Op() const
{ return this->OpFrom<Idx_nocapture>(this); }
4173
4174//===----------------------------------------------------------------------===//
4175// CleanupPadInst Class
4176//===----------------------------------------------------------------------===//
4177class CleanupPadInst : public FuncletPadInst {
4178private:
4179 explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4180 unsigned Values, const Twine &NameStr,
4181 Instruction *InsertBefore)
4182 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4183 NameStr, InsertBefore) {}
4184 explicit CleanupPadInst(Value *ParentPad, ArrayRef<Value *> Args,
4185 unsigned Values, const Twine &NameStr,
4186 BasicBlock *InsertAtEnd)
4187 : FuncletPadInst(Instruction::CleanupPad, ParentPad, Args, Values,
4188 NameStr, InsertAtEnd) {}
4189
4190public:
4191 static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args = None,
4192 const Twine &NameStr = "",
4193 Instruction *InsertBefore = nullptr) {
4194 unsigned Values = 1 + Args.size();
4195 return new (Values)
4196 CleanupPadInst(ParentPad, Args, Values, NameStr, InsertBefore);
4197 }
4198
4199 static CleanupPadInst *Create(Value *ParentPad, ArrayRef<Value *> Args,
4200 const Twine &NameStr, BasicBlock *InsertAtEnd) {
4201 unsigned Values = 1 + Args.size();
4202 return new (Values)
4203 CleanupPadInst(ParentPad, Args, Values, NameStr, InsertAtEnd);
4204 }
4205
4206 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4207 static bool classof(const Instruction *I) {
4208 return I->getOpcode() == Instruction::CleanupPad;
4209 }
4210 static bool classof(const Value *V) {
4211 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4212 }
4213};
4214
4215//===----------------------------------------------------------------------===//
4216// CatchPadInst Class
4217//===----------------------------------------------------------------------===//
4218class CatchPadInst : public FuncletPadInst {
4219private:
4220 explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4221 unsigned Values, const Twine &NameStr,
4222 Instruction *InsertBefore)
4223 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4224 NameStr, InsertBefore) {}
4225 explicit CatchPadInst(Value *CatchSwitch, ArrayRef<Value *> Args,
4226 unsigned Values, const Twine &NameStr,
4227 BasicBlock *InsertAtEnd)
4228 : FuncletPadInst(Instruction::CatchPad, CatchSwitch, Args, Values,
4229 NameStr, InsertAtEnd) {}
4230
4231public:
4232 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4233 const Twine &NameStr = "",
4234 Instruction *InsertBefore = nullptr) {
4235 unsigned Values = 1 + Args.size();
4236 return new (Values)
4237 CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertBefore);
4238 }
4239
4240 static CatchPadInst *Create(Value *CatchSwitch, ArrayRef<Value *> Args,
4241 const Twine &NameStr, BasicBlock *InsertAtEnd) {
4242 unsigned Values = 1 + Args.size();
4243 return new (Values)
4244 CatchPadInst(CatchSwitch, Args, Values, NameStr, InsertAtEnd);
4245 }
4246
4247 /// Convenience accessors
4248 CatchSwitchInst *getCatchSwitch() const {
4249 return cast<CatchSwitchInst>(Op<-1>());
4250 }
4251 void setCatchSwitch(Value *CatchSwitch) {
4252 assert(CatchSwitch)(static_cast <bool> (CatchSwitch) ? void (0) : __assert_fail
("CatchSwitch", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4252, __extension__ __PRETTY_FUNCTION__))
;
4253 Op<-1>() = CatchSwitch;
4254 }
4255
4256 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4257 static bool classof(const Instruction *I) {
4258 return I->getOpcode() == Instruction::CatchPad;
4259 }
4260 static bool classof(const Value *V) {
4261 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4262 }
4263};
4264
4265//===----------------------------------------------------------------------===//
4266// CatchReturnInst Class
4267//===----------------------------------------------------------------------===//
4268
4269class CatchReturnInst : public TerminatorInst {
4270 CatchReturnInst(const CatchReturnInst &RI);
4271 CatchReturnInst(Value *CatchPad, BasicBlock *BB, Instruction *InsertBefore);
4272 CatchReturnInst(Value *CatchPad, BasicBlock *BB, BasicBlock *InsertAtEnd);
4273
4274 void init(Value *CatchPad, BasicBlock *BB);
4275
4276protected:
4277 // Note: Instruction needs to be a friend here to call cloneImpl.
4278 friend class Instruction;
4279
4280 CatchReturnInst *cloneImpl() const;
4281
4282public:
4283 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4284 Instruction *InsertBefore = nullptr) {
4285 assert(CatchPad)(static_cast <bool> (CatchPad) ? void (0) : __assert_fail
("CatchPad", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4285, __extension__ __PRETTY_FUNCTION__))
;
4286 assert(BB)(static_cast <bool> (BB) ? void (0) : __assert_fail ("BB"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4286, __extension__ __PRETTY_FUNCTION__))
;
4287 return new (2) CatchReturnInst(CatchPad, BB, InsertBefore);
4288 }
4289
4290 static CatchReturnInst *Create(Value *CatchPad, BasicBlock *BB,
4291 BasicBlock *InsertAtEnd) {
4292 assert(CatchPad)(static_cast <bool> (CatchPad) ? void (0) : __assert_fail
("CatchPad", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4292, __extension__ __PRETTY_FUNCTION__))
;
4293 assert(BB)(static_cast <bool> (BB) ? void (0) : __assert_fail ("BB"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4293, __extension__ __PRETTY_FUNCTION__))
;
4294 return new (2) CatchReturnInst(CatchPad, BB, InsertAtEnd);
4295 }
4296
4297 /// Provide fast operand accessors
4298 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
;
4299
4300 /// Convenience accessors.
4301 CatchPadInst *getCatchPad() const { return cast<CatchPadInst>(Op<0>()); }
4302 void setCatchPad(CatchPadInst *CatchPad) {
4303 assert(CatchPad)(static_cast <bool> (CatchPad) ? void (0) : __assert_fail
("CatchPad", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4303, __extension__ __PRETTY_FUNCTION__))
;
4304 Op<0>() = CatchPad;
4305 }
4306
4307 BasicBlock *getSuccessor() const { return cast<BasicBlock>(Op<1>()); }
4308 void setSuccessor(BasicBlock *NewSucc) {
4309 assert(NewSucc)(static_cast <bool> (NewSucc) ? void (0) : __assert_fail
("NewSucc", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4309, __extension__ __PRETTY_FUNCTION__))
;
4310 Op<1>() = NewSucc;
4311 }
4312 unsigned getNumSuccessors() const { return 1; }
4313
4314 /// Get the parentPad of this catchret's catchpad's catchswitch.
4315 /// The successor block is implicitly a member of this funclet.
4316 Value *getCatchSwitchParentPad() const {
4317 return getCatchPad()->getCatchSwitch()->getParentPad();
4318 }
4319
4320 // Methods for support type inquiry through isa, cast, and dyn_cast:
4321 static bool classof(const Instruction *I) {
4322 return (I->getOpcode() == Instruction::CatchRet);
4323 }
4324 static bool classof(const Value *V) {
4325 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4326 }
4327
4328private:
4329 friend TerminatorInst;
4330
4331 BasicBlock *getSuccessor(unsigned Idx) const {
4332 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!")(static_cast <bool> (Idx < getNumSuccessors() &&
"Successor # out of range for catchret!") ? void (0) : __assert_fail
("Idx < getNumSuccessors() && \"Successor # out of range for catchret!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4332, __extension__ __PRETTY_FUNCTION__))
;
4333 return getSuccessor();
4334 }
4335
4336 void setSuccessor(unsigned Idx, BasicBlock *B) {
4337 assert(Idx < getNumSuccessors() && "Successor # out of range for catchret!")(static_cast <bool> (Idx < getNumSuccessors() &&
"Successor # out of range for catchret!") ? void (0) : __assert_fail
("Idx < getNumSuccessors() && \"Successor # out of range for catchret!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4337, __extension__ __PRETTY_FUNCTION__))
;
4338 setSuccessor(B);
4339 }
4340};
4341
4342template <>
4343struct OperandTraits<CatchReturnInst>
4344 : public FixedNumOperandTraits<CatchReturnInst, 2> {};
4345
4346DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CatchReturnInst, Value)CatchReturnInst::op_iterator CatchReturnInst::op_begin() { return
OperandTraits<CatchReturnInst>::op_begin(this); } CatchReturnInst
::const_op_iterator CatchReturnInst::op_begin() const { return
OperandTraits<CatchReturnInst>::op_begin(const_cast<
CatchReturnInst*>(this)); } CatchReturnInst::op_iterator CatchReturnInst
::op_end() { return OperandTraits<CatchReturnInst>::op_end
(this); } CatchReturnInst::const_op_iterator CatchReturnInst::
op_end() const { return OperandTraits<CatchReturnInst>::
op_end(const_cast<CatchReturnInst*>(this)); } Value *CatchReturnInst
::getOperand(unsigned i_nocapture) const { (static_cast <bool
> (i_nocapture < OperandTraits<CatchReturnInst>::
operands(this) && "getOperand() out of range!") ? void
(0) : __assert_fail ("i_nocapture < OperandTraits<CatchReturnInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4346, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<CatchReturnInst>::op_begin
(const_cast<CatchReturnInst*>(this))[i_nocapture].get()
); } void CatchReturnInst::setOperand(unsigned i_nocapture, Value
*Val_nocapture) { (static_cast <bool> (i_nocapture <
OperandTraits<CatchReturnInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CatchReturnInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4346, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
CatchReturnInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned CatchReturnInst::getNumOperands() const { return
OperandTraits<CatchReturnInst>::operands(this); } template
<int Idx_nocapture> Use &CatchReturnInst::Op() { return
this->OpFrom<Idx_nocapture>(this); } template <int
Idx_nocapture> const Use &CatchReturnInst::Op() const
{ return this->OpFrom<Idx_nocapture>(this); }
4347
4348//===----------------------------------------------------------------------===//
4349// CleanupReturnInst Class
4350//===----------------------------------------------------------------------===//
4351
4352class CleanupReturnInst : public TerminatorInst {
4353private:
4354 CleanupReturnInst(const CleanupReturnInst &RI);
4355 CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
4356 Instruction *InsertBefore = nullptr);
4357 CleanupReturnInst(Value *CleanupPad, BasicBlock *UnwindBB, unsigned Values,
4358 BasicBlock *InsertAtEnd);
4359
4360 void init(Value *CleanupPad, BasicBlock *UnwindBB);
4361
4362protected:
4363 // Note: Instruction needs to be a friend here to call cloneImpl.
4364 friend class Instruction;
4365
4366 CleanupReturnInst *cloneImpl() const;
4367
4368public:
4369 static CleanupReturnInst *Create(Value *CleanupPad,
4370 BasicBlock *UnwindBB = nullptr,
4371 Instruction *InsertBefore = nullptr) {
4372 assert(CleanupPad)(static_cast <bool> (CleanupPad) ? void (0) : __assert_fail
("CleanupPad", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4372, __extension__ __PRETTY_FUNCTION__))
;
4373 unsigned Values = 1;
4374 if (UnwindBB)
4375 ++Values;
4376 return new (Values)
4377 CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertBefore);
4378 }
4379
4380 static CleanupReturnInst *Create(Value *CleanupPad, BasicBlock *UnwindBB,
4381 BasicBlock *InsertAtEnd) {
4382 assert(CleanupPad)(static_cast <bool> (CleanupPad) ? void (0) : __assert_fail
("CleanupPad", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4382, __extension__ __PRETTY_FUNCTION__))
;
4383 unsigned Values = 1;
4384 if (UnwindBB)
4385 ++Values;
4386 return new (Values)
4387 CleanupReturnInst(CleanupPad, UnwindBB, Values, InsertAtEnd);
4388 }
4389
4390 /// Provide fast operand accessors
4391 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
;
4392
4393 bool hasUnwindDest() const { return getSubclassDataFromInstruction() & 1; }
4394 bool unwindsToCaller() const { return !hasUnwindDest(); }
4395
4396 /// Convenience accessor.
4397 CleanupPadInst *getCleanupPad() const {
4398 return cast<CleanupPadInst>(Op<0>());
4399 }
4400 void setCleanupPad(CleanupPadInst *CleanupPad) {
4401 assert(CleanupPad)(static_cast <bool> (CleanupPad) ? void (0) : __assert_fail
("CleanupPad", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4401, __extension__ __PRETTY_FUNCTION__))
;
4402 Op<0>() = CleanupPad;
4403 }
4404
4405 unsigned getNumSuccessors() const { return hasUnwindDest() ? 1 : 0; }
4406
4407 BasicBlock *getUnwindDest() const {
4408 return hasUnwindDest() ? cast<BasicBlock>(Op<1>()) : nullptr;
4409 }
4410 void setUnwindDest(BasicBlock *NewDest) {
4411 assert(NewDest)(static_cast <bool> (NewDest) ? void (0) : __assert_fail
("NewDest", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4411, __extension__ __PRETTY_FUNCTION__))
;
4412 assert(hasUnwindDest())(static_cast <bool> (hasUnwindDest()) ? void (0) : __assert_fail
("hasUnwindDest()", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4412, __extension__ __PRETTY_FUNCTION__))
;
4413 Op<1>() = NewDest;
4414 }
4415
4416 // Methods for support type inquiry through isa, cast, and dyn_cast:
4417 static bool classof(const Instruction *I) {
4418 return (I->getOpcode() == Instruction::CleanupRet);
4419 }
4420 static bool classof(const Value *V) {
4421 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4422 }
4423
4424private:
4425 friend TerminatorInst;
4426
4427 BasicBlock *getSuccessor(unsigned Idx) const {
4428 assert(Idx == 0)(static_cast <bool> (Idx == 0) ? void (0) : __assert_fail
("Idx == 0", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4428, __extension__ __PRETTY_FUNCTION__))
;
4429 return getUnwindDest();
4430 }
4431
4432 void setSuccessor(unsigned Idx, BasicBlock *B) {
4433 assert(Idx == 0)(static_cast <bool> (Idx == 0) ? void (0) : __assert_fail
("Idx == 0", "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4433, __extension__ __PRETTY_FUNCTION__))
;
4434 setUnwindDest(B);
4435 }
4436
4437 // Shadow Instruction::setInstructionSubclassData with a private forwarding
4438 // method so that subclasses cannot accidentally use it.
4439 void setInstructionSubclassData(unsigned short D) {
4440 Instruction::setInstructionSubclassData(D);
4441 }
4442};
4443
4444template <>
4445struct OperandTraits<CleanupReturnInst>
4446 : public VariadicOperandTraits<CleanupReturnInst, /*MINARITY=*/1> {};
4447
4448DEFINE_TRANSPARENT_OPERAND_ACCESSORS(CleanupReturnInst, Value)CleanupReturnInst::op_iterator CleanupReturnInst::op_begin() {
return OperandTraits<CleanupReturnInst>::op_begin(this
); } CleanupReturnInst::const_op_iterator CleanupReturnInst::
op_begin() const { return OperandTraits<CleanupReturnInst>
::op_begin(const_cast<CleanupReturnInst*>(this)); } CleanupReturnInst
::op_iterator CleanupReturnInst::op_end() { return OperandTraits
<CleanupReturnInst>::op_end(this); } CleanupReturnInst::
const_op_iterator CleanupReturnInst::op_end() const { return OperandTraits
<CleanupReturnInst>::op_end(const_cast<CleanupReturnInst
*>(this)); } Value *CleanupReturnInst::getOperand(unsigned
i_nocapture) const { (static_cast <bool> (i_nocapture <
OperandTraits<CleanupReturnInst>::operands(this) &&
"getOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CleanupReturnInst>::operands(this) && \"getOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4448, __extension__ __PRETTY_FUNCTION__)); return cast_or_null
<Value>( OperandTraits<CleanupReturnInst>::op_begin
(const_cast<CleanupReturnInst*>(this))[i_nocapture].get
()); } void CleanupReturnInst::setOperand(unsigned i_nocapture
, Value *Val_nocapture) { (static_cast <bool> (i_nocapture
< OperandTraits<CleanupReturnInst>::operands(this) &&
"setOperand() out of range!") ? void (0) : __assert_fail ("i_nocapture < OperandTraits<CleanupReturnInst>::operands(this) && \"setOperand() out of range!\""
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4448, __extension__ __PRETTY_FUNCTION__)); OperandTraits<
CleanupReturnInst>::op_begin(this)[i_nocapture] = Val_nocapture
; } unsigned CleanupReturnInst::getNumOperands() const { return
OperandTraits<CleanupReturnInst>::operands(this); } template
<int Idx_nocapture> Use &CleanupReturnInst::Op() {
return this->OpFrom<Idx_nocapture>(this); } template
<int Idx_nocapture> const Use &CleanupReturnInst::
Op() const { return this->OpFrom<Idx_nocapture>(this
); }
4449
4450//===----------------------------------------------------------------------===//
4451// UnreachableInst Class
4452//===----------------------------------------------------------------------===//
4453
4454//===---------------------------------------------------------------------------
4455/// This function has undefined behavior. In particular, the
4456/// presence of this instruction indicates some higher level knowledge that the
4457/// end of the block cannot be reached.
4458///
4459class UnreachableInst : public TerminatorInst {
4460protected:
4461 // Note: Instruction needs to be a friend here to call cloneImpl.
4462 friend class Instruction;
4463
4464 UnreachableInst *cloneImpl() const;
4465
4466public:
4467 explicit UnreachableInst(LLVMContext &C, Instruction *InsertBefore = nullptr);
4468 explicit UnreachableInst(LLVMContext &C, BasicBlock *InsertAtEnd);
4469
4470 // allocate space for exactly zero operands
4471 void *operator new(size_t s) {
4472 return User::operator new(s, 0);
4473 }
4474
4475 unsigned getNumSuccessors() const { return 0; }
4476
4477 // Methods for support type inquiry through isa, cast, and dyn_cast:
4478 static bool classof(const Instruction *I) {
4479 return I->getOpcode() == Instruction::Unreachable;
4480 }
4481 static bool classof(const Value *V) {
4482 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4483 }
4484
4485private:
4486 friend TerminatorInst;
4487
4488 BasicBlock *getSuccessor(unsigned idx) const {
4489 llvm_unreachable("UnreachableInst has no successors!")::llvm::llvm_unreachable_internal("UnreachableInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4489)
;
4490 }
4491
4492 void setSuccessor(unsigned idx, BasicBlock *B) {
4493 llvm_unreachable("UnreachableInst has no successors!")::llvm::llvm_unreachable_internal("UnreachableInst has no successors!"
, "/build/llvm-toolchain-snapshot-7~svn326246/include/llvm/IR/Instructions.h"
, 4493)
;
4494 }
4495};
4496
4497//===----------------------------------------------------------------------===//
4498// TruncInst Class
4499//===----------------------------------------------------------------------===//
4500
4501/// This class represents a truncation of integer types.
4502class TruncInst : public CastInst {
4503protected:
4504 // Note: Instruction needs to be a friend here to call cloneImpl.
4505 friend class Instruction;
4506
4507 /// Clone an identical TruncInst
4508 TruncInst *cloneImpl() const;
4509
4510public:
4511 /// Constructor with insert-before-instruction semantics
4512 TruncInst(
4513 Value *S, ///< The value to be truncated
4514 Type *Ty, ///< The (smaller) type to truncate to
4515 const Twine &NameStr = "", ///< A name for the new instruction
4516 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4517 );
4518
4519 /// Constructor with insert-at-end-of-block semantics
4520 TruncInst(
4521 Value *S, ///< The value to be truncated
4522 Type *Ty, ///< The (smaller) type to truncate to
4523 const Twine &NameStr, ///< A name for the new instruction
4524 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4525 );
4526
4527 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4528 static bool classof(const Instruction *I) {
4529 return I->getOpcode() == Trunc;
4530 }
4531 static bool classof(const Value *V) {
4532 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4533 }
4534};
4535
4536//===----------------------------------------------------------------------===//
4537// ZExtInst Class
4538//===----------------------------------------------------------------------===//
4539
4540/// This class represents zero extension of integer types.
4541class ZExtInst : public CastInst {
4542protected:
4543 // Note: Instruction needs to be a friend here to call cloneImpl.
4544 friend class Instruction;
4545
4546 /// Clone an identical ZExtInst
4547 ZExtInst *cloneImpl() const;
4548
4549public:
4550 /// Constructor with insert-before-instruction semantics
4551 ZExtInst(
4552 Value *S, ///< The value to be zero extended
4553 Type *Ty, ///< The type to zero extend to
4554 const Twine &NameStr = "", ///< A name for the new instruction
4555 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4556 );
4557
4558 /// Constructor with insert-at-end semantics.
4559 ZExtInst(
4560 Value *S, ///< The value to be zero extended
4561 Type *Ty, ///< The type to zero extend to
4562 const Twine &NameStr, ///< A name for the new instruction
4563 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4564 );
4565
4566 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4567 static bool classof(const Instruction *I) {
4568 return I->getOpcode() == ZExt;
4569 }
4570 static bool classof(const Value *V) {
4571 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4572 }
4573};
4574
4575//===----------------------------------------------------------------------===//
4576// SExtInst Class
4577//===----------------------------------------------------------------------===//
4578
4579/// This class represents a sign extension of integer types.
4580class SExtInst : public CastInst {
4581protected:
4582 // Note: Instruction needs to be a friend here to call cloneImpl.
4583 friend class Instruction;
4584
4585 /// Clone an identical SExtInst
4586 SExtInst *cloneImpl() const;
4587
4588public:
4589 /// Constructor with insert-before-instruction semantics
4590 SExtInst(
4591 Value *S, ///< The value to be sign extended
4592 Type *Ty, ///< The type to sign extend to
4593 const Twine &NameStr = "", ///< A name for the new instruction
4594 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4595 );
4596
4597 /// Constructor with insert-at-end-of-block semantics
4598 SExtInst(
4599 Value *S, ///< The value to be sign extended
4600 Type *Ty, ///< The type to sign extend to
4601 const Twine &NameStr, ///< A name for the new instruction
4602 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4603 );
4604
4605 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4606 static bool classof(const Instruction *I) {
4607 return I->getOpcode() == SExt;
4608 }
4609 static bool classof(const Value *V) {
4610 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4611 }
4612};
4613
4614//===----------------------------------------------------------------------===//
4615// FPTruncInst Class
4616//===----------------------------------------------------------------------===//
4617
4618/// This class represents a truncation of floating point types.
4619class FPTruncInst : public CastInst {
4620protected:
4621 // Note: Instruction needs to be a friend here to call cloneImpl.
4622 friend class Instruction;
4623
4624 /// Clone an identical FPTruncInst
4625 FPTruncInst *cloneImpl() const;
4626
4627public:
4628 /// Constructor with insert-before-instruction semantics
4629 FPTruncInst(
4630 Value *S, ///< The value to be truncated
4631 Type *Ty, ///< The type to truncate to
4632 const Twine &NameStr = "", ///< A name for the new instruction
4633 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4634 );
4635
4636 /// Constructor with insert-before-instruction semantics
4637 FPTruncInst(
4638 Value *S, ///< The value to be truncated
4639 Type *Ty, ///< The type to truncate to
4640 const Twine &NameStr, ///< A name for the new instruction
4641 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4642 );
4643
4644 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4645 static bool classof(const Instruction *I) {
4646 return I->getOpcode() == FPTrunc;
4647 }
4648 static bool classof(const Value *V) {
4649 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4650 }
4651};
4652
4653//===----------------------------------------------------------------------===//
4654// FPExtInst Class
4655//===----------------------------------------------------------------------===//
4656
4657/// This class represents an extension of floating point types.
4658class FPExtInst : public CastInst {
4659protected:
4660 // Note: Instruction needs to be a friend here to call cloneImpl.
4661 friend class Instruction;
4662
4663 /// Clone an identical FPExtInst
4664 FPExtInst *cloneImpl() const;
4665
4666public:
4667 /// Constructor with insert-before-instruction semantics
4668 FPExtInst(
4669 Value *S, ///< The value to be extended
4670 Type *Ty, ///< The type to extend to
4671 const Twine &NameStr = "", ///< A name for the new instruction
4672 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4673 );
4674
4675 /// Constructor with insert-at-end-of-block semantics
4676 FPExtInst(
4677 Value *S, ///< The value to be extended
4678 Type *Ty, ///< The type to extend to
4679 const Twine &NameStr, ///< A name for the new instruction
4680 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4681 );
4682
4683 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4684 static bool classof(const Instruction *I) {
4685 return I->getOpcode() == FPExt;
4686 }
4687 static bool classof(const Value *V) {
4688 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4689 }
4690};
4691
4692//===----------------------------------------------------------------------===//
4693// UIToFPInst Class
4694//===----------------------------------------------------------------------===//
4695
4696/// This class represents a cast unsigned integer to floating point.
4697class UIToFPInst : public CastInst {
4698protected:
4699 // Note: Instruction needs to be a friend here to call cloneImpl.
4700 friend class Instruction;
4701
4702 /// Clone an identical UIToFPInst
4703 UIToFPInst *cloneImpl() const;
4704
4705public:
4706 /// Constructor with insert-before-instruction semantics
4707 UIToFPInst(
4708 Value *S, ///< The value to be converted
4709 Type *Ty, ///< The type to convert to
4710 const Twine &NameStr = "", ///< A name for the new instruction
4711 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4712 );
4713
4714 /// Constructor with insert-at-end-of-block semantics
4715 UIToFPInst(
4716 Value *S, ///< The value to be converted
4717 Type *Ty, ///< The type to convert to
4718 const Twine &NameStr, ///< A name for the new instruction
4719 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4720 );
4721
4722 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4723 static bool classof(const Instruction *I) {
4724 return I->getOpcode() == UIToFP;
4725 }
4726 static bool classof(const Value *V) {
4727 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4728 }
4729};
4730
4731//===----------------------------------------------------------------------===//
4732// SIToFPInst Class
4733//===----------------------------------------------------------------------===//
4734
4735/// This class represents a cast from signed integer to floating point.
4736class SIToFPInst : public CastInst {
4737protected:
4738 // Note: Instruction needs to be a friend here to call cloneImpl.
4739 friend class Instruction;
4740
4741 /// Clone an identical SIToFPInst
4742 SIToFPInst *cloneImpl() const;
4743
4744public:
4745 /// Constructor with insert-before-instruction semantics
4746 SIToFPInst(
4747 Value *S, ///< The value to be converted
4748 Type *Ty, ///< The type to convert to
4749 const Twine &NameStr = "", ///< A name for the new instruction
4750 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4751 );
4752
4753 /// Constructor with insert-at-end-of-block semantics
4754 SIToFPInst(
4755 Value *S, ///< The value to be converted
4756 Type *Ty, ///< The type to convert to
4757 const Twine &NameStr, ///< A name for the new instruction
4758 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4759 );
4760
4761 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4762 static bool classof(const Instruction *I) {
4763 return I->getOpcode() == SIToFP;
4764 }
4765 static bool classof(const Value *V) {
4766 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4767 }
4768};
4769
4770//===----------------------------------------------------------------------===//
4771// FPToUIInst Class
4772//===----------------------------------------------------------------------===//
4773
4774/// This class represents a cast from floating point to unsigned integer
4775class FPToUIInst : public CastInst {
4776protected:
4777 // Note: Instruction needs to be a friend here to call cloneImpl.
4778 friend class Instruction;
4779
4780 /// Clone an identical FPToUIInst
4781 FPToUIInst *cloneImpl() const;
4782
4783public:
4784 /// Constructor with insert-before-instruction semantics
4785 FPToUIInst(
4786 Value *S, ///< The value to be converted
4787 Type *Ty, ///< The type to convert to
4788 const Twine &NameStr = "", ///< A name for the new instruction
4789 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4790 );
4791
4792 /// Constructor with insert-at-end-of-block semantics
4793 FPToUIInst(
4794 Value *S, ///< The value to be converted
4795 Type *Ty, ///< The type to convert to
4796 const Twine &NameStr, ///< A name for the new instruction
4797 BasicBlock *InsertAtEnd ///< Where to insert the new instruction
4798 );
4799
4800 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4801 static bool classof(const Instruction *I) {
4802 return I->getOpcode() == FPToUI;
4803 }
4804 static bool classof(const Value *V) {
4805 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4806 }
4807};
4808
4809//===----------------------------------------------------------------------===//
4810// FPToSIInst Class
4811//===----------------------------------------------------------------------===//
4812
4813/// This class represents a cast from floating point to signed integer.
4814class FPToSIInst : public CastInst {
4815protected:
4816 // Note: Instruction needs to be a friend here to call cloneImpl.
4817 friend class Instruction;
4818
4819 /// Clone an identical FPToSIInst
4820 FPToSIInst *cloneImpl() const;
4821
4822public:
4823 /// Constructor with insert-before-instruction semantics
4824 FPToSIInst(
4825 Value *S, ///< The value to be converted
4826 Type *Ty, ///< The type to convert to
4827 const Twine &NameStr = "", ///< A name for the new instruction
4828 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4829 );
4830
4831 /// Constructor with insert-at-end-of-block semantics
4832 FPToSIInst(
4833 Value *S, ///< The value to be converted
4834 Type *Ty, ///< The type to convert to
4835 const Twine &NameStr, ///< A name for the new instruction
4836 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4837 );
4838
4839 /// Methods for support type inquiry through isa, cast, and dyn_cast:
4840 static bool classof(const Instruction *I) {
4841 return I->getOpcode() == FPToSI;
4842 }
4843 static bool classof(const Value *V) {
4844 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4845 }
4846};
4847
4848//===----------------------------------------------------------------------===//
4849// IntToPtrInst Class
4850//===----------------------------------------------------------------------===//
4851
4852/// This class represents a cast from an integer to a pointer.
4853class IntToPtrInst : public CastInst {
4854public:
4855 // Note: Instruction needs to be a friend here to call cloneImpl.
4856 friend class Instruction;
4857
4858 /// Constructor with insert-before-instruction semantics
4859 IntToPtrInst(
4860 Value *S, ///< The value to be converted
4861 Type *Ty, ///< The type to convert to
4862 const Twine &NameStr = "", ///< A name for the new instruction
4863 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4864 );
4865
4866 /// Constructor with insert-at-end-of-block semantics
4867 IntToPtrInst(
4868 Value *S, ///< The value to be converted
4869 Type *Ty, ///< The type to convert to
4870 const Twine &NameStr, ///< A name for the new instruction
4871 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4872 );
4873
4874 /// Clone an identical IntToPtrInst.
4875 IntToPtrInst *cloneImpl() const;
4876
4877 /// Returns the address space of this instruction's pointer type.
4878 unsigned getAddressSpace() const {
4879 return getType()->getPointerAddressSpace();
4880 }
4881
4882 // Methods for support type inquiry through isa, cast, and dyn_cast:
4883 static bool classof(const Instruction *I) {
4884 return I->getOpcode() == IntToPtr;
4885 }
4886 static bool classof(const Value *V) {
4887 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4888 }
4889};
4890
4891//===----------------------------------------------------------------------===//
4892// PtrToIntInst Class
4893//===----------------------------------------------------------------------===//
4894
4895/// This class represents a cast from a pointer to an integer.
4896class PtrToIntInst : public CastInst {
4897protected:
4898 // Note: Instruction needs to be a friend here to call cloneImpl.
4899 friend class Instruction;
4900
4901 /// Clone an identical PtrToIntInst.
4902 PtrToIntInst *cloneImpl() const;
4903
4904public:
4905 /// Constructor with insert-before-instruction semantics
4906 PtrToIntInst(
4907 Value *S, ///< The value to be converted
4908 Type *Ty, ///< The type to convert to
4909 const Twine &NameStr = "", ///< A name for the new instruction
4910 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4911 );
4912
4913 /// Constructor with insert-at-end-of-block semantics
4914 PtrToIntInst(
4915 Value *S, ///< The value to be converted
4916 Type *Ty, ///< The type to convert to
4917 const Twine &NameStr, ///< A name for the new instruction
4918 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4919 );
4920
4921 /// Gets the pointer operand.
4922 Value *getPointerOperand() { return getOperand(0); }
4923 /// Gets the pointer operand.
4924 const Value *getPointerOperand() const { return getOperand(0); }
4925 /// Gets the operand index of the pointer operand.
4926 static unsigned getPointerOperandIndex() { return 0U; }
4927
4928 /// Returns the address space of the pointer operand.
4929 unsigned getPointerAddressSpace() const {
4930 return getPointerOperand()->getType()->getPointerAddressSpace();
4931 }
4932
4933 // Methods for support type inquiry through isa, cast, and dyn_cast:
4934 static bool classof(const Instruction *I) {
4935 return I->getOpcode() == PtrToInt;
4936 }
4937 static bool classof(const Value *V) {
4938 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4939 }
4940};
4941
4942//===----------------------------------------------------------------------===//
4943// BitCastInst Class
4944//===----------------------------------------------------------------------===//
4945
4946/// This class represents a no-op cast from one type to another.
4947class BitCastInst : public CastInst {
4948protected:
4949 // Note: Instruction needs to be a friend here to call cloneImpl.
4950 friend class Instruction;
4951
4952 /// Clone an identical BitCastInst.
4953 BitCastInst *cloneImpl() const;
4954
4955public:
4956 /// Constructor with insert-before-instruction semantics
4957 BitCastInst(
4958 Value *S, ///< The value to be casted
4959 Type *Ty, ///< The type to casted to
4960 const Twine &NameStr = "", ///< A name for the new instruction
4961 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
4962 );
4963
4964 /// Constructor with insert-at-end-of-block semantics
4965 BitCastInst(
4966 Value *S, ///< The value to be casted
4967 Type *Ty, ///< The type to casted to
4968 const Twine &NameStr, ///< A name for the new instruction
4969 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
4970 );
4971
4972 // Methods for support type inquiry through isa, cast, and dyn_cast:
4973 static bool classof(const Instruction *I) {
4974 return I->getOpcode() == BitCast;
4975 }
4976 static bool classof(const Value *V) {
4977 return isa<Instruction>(V) && classof(cast<Instruction>(V));
4978 }
4979};
4980
4981//===----------------------------------------------------------------------===//
4982// AddrSpaceCastInst Class
4983//===----------------------------------------------------------------------===//
4984
4985/// This class represents a conversion between pointers from one address space
4986/// to another.
4987class AddrSpaceCastInst : public CastInst {
4988protected:
4989 // Note: Instruction needs to be a friend here to call cloneImpl.
4990 friend class Instruction;
4991
4992 /// Clone an identical AddrSpaceCastInst.
4993 AddrSpaceCastInst *cloneImpl() const;
4994
4995public:
4996 /// Constructor with insert-before-instruction semantics
4997 AddrSpaceCastInst(
4998 Value *S, ///< The value to be casted
4999 Type *Ty, ///< The type to casted to
5000 const Twine &NameStr = "", ///< A name for the new instruction
5001 Instruction *InsertBefore = nullptr ///< Where to insert the new instruction
5002 );
5003
5004 /// Constructor with insert-at-end-of-block semantics
5005 AddrSpaceCastInst(
5006 Value *S, ///< The value to be casted
5007 Type *Ty, ///< The type to casted to
5008 const Twine &NameStr, ///< A name for the new instruction
5009 BasicBlock *InsertAtEnd ///< The block to insert the instruction into
5010 );
5011
5012 // Methods for support type inquiry through isa, cast, and dyn_cast:
5013 static bool classof(const Instruction *I) {
5014 return I->getOpcode() == AddrSpaceCast;
5015 }
5016 static bool classof(const Value *V) {
5017 return isa<Instruction>(V) && classof(cast<Instruction>(V));
5018 }
5019
5020 /// Gets the pointer operand.
5021 Value *getPointerOperand() {
5022 return getOperand(0);
5023 }
5024
5025 /// Gets the pointer operand.
5026 const Value *getPointerOperand() const {
5027 return getOperand(0);
5028 }
5029
5030 /// Gets the operand index of the pointer operand.
5031 static unsigned getPointerOperandIndex() {
5032 return 0U;
5033 }
5034
5035 /// Returns the address space of the pointer operand.
5036 unsigned getSrcAddressSpace() const {
5037 return getPointerOperand()->getType()->getPointerAddressSpace();
5038 }
5039
5040 /// Returns the address space of the result.
5041 unsigned getDestAddressSpace() const {
5042 return getType()->getPointerAddressSpace();
5043 }
5044};
5045
5046} // end namespace llvm
5047
5048#endif // LLVM_IR_INSTRUCTIONS_H