/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/IR/Instruction.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- llvm/Instruction.h - Instruction class definition -------*- 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 contains the declaration of the Instruction class, which is the |
11 | | // base class for all of the LLVM instructions. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_IR_INSTRUCTION_H |
16 | | #define LLVM_IR_INSTRUCTION_H |
17 | | |
18 | | #include "llvm/ADT/ArrayRef.h" |
19 | | #include "llvm/ADT/None.h" |
20 | | #include "llvm/ADT/StringRef.h" |
21 | | #include "llvm/ADT/ilist_node.h" |
22 | | #include "llvm/IR/DebugLoc.h" |
23 | | #include "llvm/IR/SymbolTableListTraits.h" |
24 | | #include "llvm/IR/User.h" |
25 | | #include "llvm/IR/Value.h" |
26 | | #include "llvm/Support/Casting.h" |
27 | | #include <algorithm> |
28 | | #include <cassert> |
29 | | #include <cstdint> |
30 | | #include <utility> |
31 | | |
32 | | namespace llvm { |
33 | | |
34 | | class BasicBlock; |
35 | | class FastMathFlags; |
36 | | class MDNode; |
37 | | struct AAMDNodes; |
38 | | |
39 | | template <> struct ilist_alloc_traits<Instruction> { |
40 | | static inline void deleteNode(Instruction *V); |
41 | | }; |
42 | | |
43 | | class Instruction : public User, |
44 | | public ilist_node_with_parent<Instruction, BasicBlock> { |
45 | | BasicBlock *Parent; |
46 | | DebugLoc DbgLoc; // 'dbg' Metadata cache. |
47 | | |
48 | | enum { |
49 | | /// This is a bit stored in the SubClassData field which indicates whether |
50 | | /// this instruction has metadata attached to it or not. |
51 | | HasMetadataBit = 1 << 15 |
52 | | }; |
53 | | |
54 | | protected: |
55 | | ~Instruction(); // Use deleteValue() to delete a generic Instruction. |
56 | | |
57 | | public: |
58 | | Instruction(const Instruction &) = delete; |
59 | | Instruction &operator=(const Instruction &) = delete; |
60 | | |
61 | | /// Specialize the methods defined in Value, as we know that an instruction |
62 | | /// can only be used by other instructions. |
63 | 81.9M | Instruction *user_back() { return cast<Instruction>(*user_begin());} |
64 | 3.25k | const Instruction *user_back() const { return cast<Instruction>(*user_begin());} |
65 | | |
66 | 1.43G | inline const BasicBlock *getParent() const { return Parent; } |
67 | 2.03G | inline BasicBlock *getParent() { return Parent; } |
68 | | |
69 | | /// Return the module owning the function this instruction belongs to |
70 | | /// or nullptr it the function does not have a module. |
71 | | /// |
72 | | /// Note: this is undefined behavior if the instruction does not have a |
73 | | /// parent, or the parent basic block does not have a parent function. |
74 | | const Module *getModule() const; |
75 | 184M | Module *getModule() { |
76 | 184M | return const_cast<Module *>( |
77 | 184M | static_cast<const Instruction *>(this)->getModule()); |
78 | 184M | } |
79 | | |
80 | | /// Return the function this instruction belongs to. |
81 | | /// |
82 | | /// Note: it is undefined behavior to call this on an instruction not |
83 | | /// currently inserted into a function. |
84 | | const Function *getFunction() const; |
85 | 30.3M | Function *getFunction() { |
86 | 30.3M | return const_cast<Function *>( |
87 | 30.3M | static_cast<const Instruction *>(this)->getFunction()); |
88 | 30.3M | } |
89 | | |
90 | | /// This method unlinks 'this' from the containing basic block, but does not |
91 | | /// delete it. |
92 | | void removeFromParent(); |
93 | | |
94 | | /// This method unlinks 'this' from the containing basic block and deletes it. |
95 | | /// |
96 | | /// \returns an iterator pointing to the element after the erased one |
97 | | SymbolTableList<Instruction>::iterator eraseFromParent(); |
98 | | |
99 | | /// Insert an unlinked instruction into a basic block immediately before |
100 | | /// the specified instruction. |
101 | | void insertBefore(Instruction *InsertPos); |
102 | | |
103 | | /// Insert an unlinked instruction into a basic block immediately after the |
104 | | /// specified instruction. |
105 | | void insertAfter(Instruction *InsertPos); |
106 | | |
107 | | /// Unlink this instruction from its current basic block and insert it into |
108 | | /// the basic block that MovePos lives in, right before MovePos. |
109 | | void moveBefore(Instruction *MovePos); |
110 | | |
111 | | /// Unlink this instruction and insert into BB before I. |
112 | | /// |
113 | | /// \pre I is a valid iterator into BB. |
114 | | void moveBefore(BasicBlock &BB, SymbolTableList<Instruction>::iterator I); |
115 | | |
116 | | /// Unlink this instruction from its current basic block and insert it into |
117 | | /// the basic block that MovePos lives in, right after MovePos. |
118 | | void moveAfter(Instruction *MovePos); |
119 | | |
120 | | //===--------------------------------------------------------------------===// |
121 | | // Subclass classification. |
122 | | //===--------------------------------------------------------------------===// |
123 | | |
124 | | /// Returns a member of one of the enums like Instruction::Add. |
125 | 33.0G | unsigned getOpcode() const { return getValueID() - InstructionVal; } |
126 | | |
127 | 1.61M | const char *getOpcodeName() const { return getOpcodeName(getOpcode()); } |
128 | 4.39G | bool isTerminator() const { return isTerminator(getOpcode()); } |
129 | 772M | bool isBinaryOp() const { return isBinaryOp(getOpcode()); } |
130 | 43.1k | bool isShift() { return isShift(getOpcode()); } |
131 | 463M | bool isCast() const { return isCast(getOpcode()); } |
132 | 1.71M | bool isFuncletPad() const { return isFuncletPad(getOpcode()); } |
133 | | |
134 | | static const char* getOpcodeName(unsigned OpCode); |
135 | | |
136 | 4.39G | static inline bool isTerminator(unsigned OpCode) { |
137 | 4.39G | return OpCode >= TermOpsBegin && OpCode < TermOpsEnd; |
138 | 4.39G | } |
139 | | |
140 | 806M | static inline bool isBinaryOp(unsigned Opcode) { |
141 | 779M | return Opcode >= BinaryOpsBegin && Opcode < BinaryOpsEnd; |
142 | 806M | } |
143 | | |
144 | | /// Determine if the Opcode is one of the shift instructions. |
145 | 43.4k | static inline bool isShift(unsigned Opcode) { |
146 | 30.8k | return Opcode >= Shl && Opcode <= AShr; |
147 | 43.4k | } |
148 | | |
149 | | /// Return true if this is a logical shift left or a logical shift right. |
150 | 1.38M | inline bool isLogicalShift() const { |
151 | 1.12M | return getOpcode() == Shl || getOpcode() == LShr; |
152 | 1.38M | } |
153 | | |
154 | | /// Return true if this is an arithmetic shift right. |
155 | 2.09k | inline bool isArithmeticShift() const { |
156 | 2.09k | return getOpcode() == AShr; |
157 | 2.09k | } |
158 | | |
159 | | /// Determine if the Opcode is and/or/xor. |
160 | 86.7k | static inline bool isBitwiseLogicOp(unsigned Opcode) { |
161 | 86.7k | return Opcode == And || Opcode == Or79.8k || Opcode == Xor77.2k ; |
162 | 86.7k | } |
163 | | |
164 | | /// Return true if this is and/or/xor. |
165 | 86.2k | inline bool isBitwiseLogicOp() const { |
166 | 86.2k | return isBitwiseLogicOp(getOpcode()); |
167 | 86.2k | } |
168 | | |
169 | | /// Determine if the OpCode is one of the CastInst instructions. |
170 | 500M | static inline bool isCast(unsigned OpCode) { |
171 | 180M | return OpCode >= CastOpsBegin && OpCode < CastOpsEnd; |
172 | 500M | } |
173 | | |
174 | | /// Determine if the OpCode is one of the FuncletPadInst instructions. |
175 | 1.71M | static inline bool isFuncletPad(unsigned OpCode) { |
176 | 210k | return OpCode >= FuncletPadOpsBegin && OpCode < FuncletPadOpsEnd; |
177 | 1.71M | } |
178 | | |
179 | | //===--------------------------------------------------------------------===// |
180 | | // Metadata manipulation. |
181 | | //===--------------------------------------------------------------------===// |
182 | | |
183 | | /// Return true if this instruction has any metadata attached to it. |
184 | 727M | bool hasMetadata() const { return DbgLoc || 727M hasMetadataHashEntry()715M ; } |
185 | | |
186 | | /// Return true if this instruction has metadata attached to it other than a |
187 | | /// debug location. |
188 | 7.98M | bool hasMetadataOtherThanDebugLoc() const { |
189 | 7.98M | return hasMetadataHashEntry(); |
190 | 7.98M | } |
191 | | |
192 | | /// Get the metadata of given kind attached to this Instruction. |
193 | | /// If the metadata is not found then return null. |
194 | 699M | MDNode *getMetadata(unsigned KindID) const { |
195 | 699M | if (!hasMetadata()699M ) return nullptr312M ; |
196 | 386M | return getMetadataImpl(KindID); |
197 | 699M | } |
198 | | |
199 | | /// Get the metadata of given kind attached to this Instruction. |
200 | | /// If the metadata is not found then return null. |
201 | 71.9k | MDNode *getMetadata(StringRef Kind) const { |
202 | 71.9k | if (!hasMetadata()71.9k ) return nullptr62.2k ; |
203 | 9.66k | return getMetadataImpl(Kind); |
204 | 71.9k | } |
205 | | |
206 | | /// Get all metadata attached to this Instruction. The first element of each |
207 | | /// pair returned is the KindID, the second element is the metadata value. |
208 | | /// This list is returned sorted by the KindID. |
209 | | void |
210 | 7.20M | getAllMetadata(SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const { |
211 | 7.20M | if (hasMetadata()) |
212 | 1.07M | getAllMetadataImpl(MDs); |
213 | 7.20M | } |
214 | | |
215 | | /// This does the same thing as getAllMetadata, except that it filters out the |
216 | | /// debug location. |
217 | | void getAllMetadataOtherThanDebugLoc( |
218 | 7.70M | SmallVectorImpl<std::pair<unsigned, MDNode *>> &MDs) const { |
219 | 7.70M | if (hasMetadataOtherThanDebugLoc()) |
220 | 2.39M | getAllMetadataOtherThanDebugLocImpl(MDs); |
221 | 7.70M | } |
222 | | |
223 | | /// Fills the AAMDNodes structure with AA metadata from this instruction. |
224 | | /// When Merge is true, the existing AA metadata is merged with that from this |
225 | | /// instruction providing the most-general result. |
226 | | void getAAMetadata(AAMDNodes &N, bool Merge = false) const; |
227 | | |
228 | | /// Set the metadata of the specified kind to the specified node. This updates |
229 | | /// or replaces metadata if already present, or removes it if Node is null. |
230 | | void setMetadata(unsigned KindID, MDNode *Node); |
231 | | void setMetadata(StringRef Kind, MDNode *Node); |
232 | | |
233 | | /// Copy metadata from \p SrcInst to this instruction. \p WL, if not empty, |
234 | | /// specifies the list of meta data that needs to be copied. If \p WL is |
235 | | /// empty, all meta data will be copied. |
236 | | void copyMetadata(const Instruction &SrcInst, |
237 | | ArrayRef<unsigned> WL = ArrayRef<unsigned>()); |
238 | | |
239 | | /// If the instruction has "branch_weights" MD_prof metadata and the MDNode |
240 | | /// has three operands (including name string), swap the order of the |
241 | | /// metadata. |
242 | | void swapProfMetadata(); |
243 | | |
244 | | /// Drop all unknown metadata except for debug locations. |
245 | | /// @{ |
246 | | /// Passes are required to drop metadata they don't understand. This is a |
247 | | /// convenience method for passes to do so. |
248 | | void dropUnknownNonDebugMetadata(ArrayRef<unsigned> KnownIDs); |
249 | 85.7k | void dropUnknownNonDebugMetadata() { |
250 | 85.7k | return dropUnknownNonDebugMetadata(None); |
251 | 85.7k | } |
252 | 0 | void dropUnknownNonDebugMetadata(unsigned ID1) { |
253 | 0 | return dropUnknownNonDebugMetadata(makeArrayRef(ID1)); |
254 | 0 | } |
255 | 0 | void dropUnknownNonDebugMetadata(unsigned ID1, unsigned ID2) { |
256 | 0 | unsigned IDs[] = {ID1, ID2}; |
257 | 0 | return dropUnknownNonDebugMetadata(IDs); |
258 | 0 | } |
259 | | /// @} |
260 | | |
261 | | /// Sets the metadata on this instruction from the AAMDNodes structure. |
262 | | void setAAMetadata(const AAMDNodes &N); |
263 | | |
264 | | /// Retrieve the raw weight values of a conditional branch or select. |
265 | | /// Returns true on success with profile weights filled in. |
266 | | /// Returns false if no metadata or invalid metadata was found. |
267 | | bool extractProfMetadata(uint64_t &TrueVal, uint64_t &FalseVal) const; |
268 | | |
269 | | /// Retrieve total raw weight values of a branch. |
270 | | /// Returns true on success with profile total weights filled in. |
271 | | /// Returns false if no metadata was found. |
272 | | bool extractProfTotalWeight(uint64_t &TotalVal) const; |
273 | | |
274 | | /// Updates branch_weights metadata by scaling it by \p S / \p T. |
275 | | void updateProfWeight(uint64_t S, uint64_t T); |
276 | | |
277 | | /// Sets the branch_weights metadata to \p W for CallInst. |
278 | | void setProfWeight(uint64_t W); |
279 | | |
280 | | /// Set the debug location information for this instruction. |
281 | 5.78M | void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); } |
282 | | |
283 | | /// Return the debug location for this node as a DebugLoc. |
284 | 755M | const DebugLoc &getDebugLoc() const { return DbgLoc; } |
285 | | |
286 | | /// Set or clear the nsw flag on this instruction, which must be an operator |
287 | | /// which supports this flag. See LangRef.html for the meaning of this flag. |
288 | | void setHasNoUnsignedWrap(bool b = true); |
289 | | |
290 | | /// Set or clear the nsw flag on this instruction, which must be an operator |
291 | | /// which supports this flag. See LangRef.html for the meaning of this flag. |
292 | | void setHasNoSignedWrap(bool b = true); |
293 | | |
294 | | /// Set or clear the exact flag on this instruction, which must be an operator |
295 | | /// which supports this flag. See LangRef.html for the meaning of this flag. |
296 | | void setIsExact(bool b = true); |
297 | | |
298 | | /// Determine whether the no unsigned wrap flag is set. |
299 | | bool hasNoUnsignedWrap() const; |
300 | | |
301 | | /// Determine whether the no signed wrap flag is set. |
302 | | bool hasNoSignedWrap() const; |
303 | | |
304 | | /// Drops flags that may cause this instruction to evaluate to poison despite |
305 | | /// having non-poison inputs. |
306 | | void dropPoisonGeneratingFlags(); |
307 | | |
308 | | /// Determine whether the exact flag is set. |
309 | | bool isExact() const; |
310 | | |
311 | | /// Set or clear the unsafe-algebra flag on this instruction, which must be an |
312 | | /// operator which supports this flag. See LangRef.html for the meaning of |
313 | | /// this flag. |
314 | | void setHasUnsafeAlgebra(bool B); |
315 | | |
316 | | /// Set or clear the no-nans flag on this instruction, which must be an |
317 | | /// operator which supports this flag. See LangRef.html for the meaning of |
318 | | /// this flag. |
319 | | void setHasNoNaNs(bool B); |
320 | | |
321 | | /// Set or clear the no-infs flag on this instruction, which must be an |
322 | | /// operator which supports this flag. See LangRef.html for the meaning of |
323 | | /// this flag. |
324 | | void setHasNoInfs(bool B); |
325 | | |
326 | | /// Set or clear the no-signed-zeros flag on this instruction, which must be |
327 | | /// an operator which supports this flag. See LangRef.html for the meaning of |
328 | | /// this flag. |
329 | | void setHasNoSignedZeros(bool B); |
330 | | |
331 | | /// Set or clear the allow-reciprocal flag on this instruction, which must be |
332 | | /// an operator which supports this flag. See LangRef.html for the meaning of |
333 | | /// this flag. |
334 | | void setHasAllowReciprocal(bool B); |
335 | | |
336 | | /// Convenience function for setting multiple fast-math flags on this |
337 | | /// instruction, which must be an operator which supports these flags. See |
338 | | /// LangRef.html for the meaning of these flags. |
339 | | void setFastMathFlags(FastMathFlags FMF); |
340 | | |
341 | | /// Convenience function for transferring all fast-math flag values to this |
342 | | /// instruction, which must be an operator which supports these flags. See |
343 | | /// LangRef.html for the meaning of these flags. |
344 | | void copyFastMathFlags(FastMathFlags FMF); |
345 | | |
346 | | /// Determine whether the unsafe-algebra flag is set. |
347 | | bool hasUnsafeAlgebra() const; |
348 | | |
349 | | /// Determine whether the no-NaNs flag is set. |
350 | | bool hasNoNaNs() const; |
351 | | |
352 | | /// Determine whether the no-infs flag is set. |
353 | | bool hasNoInfs() const; |
354 | | |
355 | | /// Determine whether the no-signed-zeros flag is set. |
356 | | bool hasNoSignedZeros() const; |
357 | | |
358 | | /// Determine whether the allow-reciprocal flag is set. |
359 | | bool hasAllowReciprocal() const; |
360 | | |
361 | | /// Determine whether the allow-contract flag is set. |
362 | | bool hasAllowContract() const; |
363 | | |
364 | | /// Convenience function for getting all the fast-math flags, which must be an |
365 | | /// operator which supports these flags. See LangRef.html for the meaning of |
366 | | /// these flags. |
367 | | FastMathFlags getFastMathFlags() const; |
368 | | |
369 | | /// Copy I's fast-math flags |
370 | | void copyFastMathFlags(const Instruction *I); |
371 | | |
372 | | /// Convenience method to copy supported exact, fast-math, and (optionally) |
373 | | /// wrapping flags from V to this instruction. |
374 | | void copyIRFlags(const Value *V, bool IncludeWrapFlags = true); |
375 | | |
376 | | /// Logical 'and' of any supported wrapping, exact, and fast-math flags of |
377 | | /// V and this instruction. |
378 | | void andIRFlags(const Value *V); |
379 | | |
380 | | private: |
381 | | /// Return true if we have an entry in the on-the-side metadata hash. |
382 | 1.15G | bool hasMetadataHashEntry() const { |
383 | 1.15G | return (getSubclassDataFromValue() & HasMetadataBit) != 0; |
384 | 1.15G | } |
385 | | |
386 | | // These are all implemented in Metadata.cpp. |
387 | | MDNode *getMetadataImpl(unsigned KindID) const; |
388 | | MDNode *getMetadataImpl(StringRef Kind) const; |
389 | | void |
390 | | getAllMetadataImpl(SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const; |
391 | | void getAllMetadataOtherThanDebugLocImpl( |
392 | | SmallVectorImpl<std::pair<unsigned, MDNode *>> &) const; |
393 | | /// Clear all hashtable-based metadata from this instruction. |
394 | | void clearMetadataHashEntries(); |
395 | | |
396 | | public: |
397 | | //===--------------------------------------------------------------------===// |
398 | | // Predicates and helper methods. |
399 | | //===--------------------------------------------------------------------===// |
400 | | |
401 | | /// Return true if the instruction is associative: |
402 | | /// |
403 | | /// Associative operators satisfy: x op (y op z) === (x op y) op z |
404 | | /// |
405 | | /// In LLVM, the Add, Mul, And, Or, and Xor operators are associative. |
406 | | /// |
407 | | bool isAssociative() const LLVM_READONLY; |
408 | 32.1M | static bool isAssociative(unsigned Opcode) { |
409 | 32.1M | return Opcode == And || Opcode == Or27.2M || Opcode == Xor25.0M || |
410 | 32.1M | Opcode == Add24.3M || Opcode == Mul6.37M ; |
411 | 32.1M | } |
412 | | |
413 | | /// Return true if the instruction is commutative: |
414 | | /// |
415 | | /// Commutative operators satisfy: (x op y) === (y op x) |
416 | | /// |
417 | | /// In LLVM, these are the commutative operators, plus SetEQ and SetNE, when |
418 | | /// applied to any type. |
419 | | /// |
420 | 59.9M | bool isCommutative() const { return isCommutative(getOpcode()); } |
421 | 116M | static bool isCommutative(unsigned Opcode) { |
422 | 116M | switch (Opcode) { |
423 | 96.6M | case Add: 96.6M case FAdd: |
424 | 96.6M | case Mul: 96.6M case FMul: |
425 | 96.6M | case And: 96.6M case Or: 96.6M case Xor: |
426 | 96.6M | return true; |
427 | 19.8M | default: |
428 | 19.8M | return false; |
429 | 116M | } |
430 | 116M | } |
431 | | |
432 | | /// Return true if the instruction is idempotent: |
433 | | /// |
434 | | /// Idempotent operators satisfy: x op x === x |
435 | | /// |
436 | | /// In LLVM, the And and Or operators are idempotent. |
437 | | /// |
438 | 0 | bool isIdempotent() const { return isIdempotent(getOpcode()); } |
439 | 8.57k | static bool isIdempotent(unsigned Opcode) { |
440 | 8.56k | return Opcode == And || Opcode == Or; |
441 | 8.57k | } |
442 | | |
443 | | /// Return true if the instruction is nilpotent: |
444 | | /// |
445 | | /// Nilpotent operators satisfy: x op x === Id, |
446 | | /// |
447 | | /// where Id is the identity for the operator, i.e. a constant such that |
448 | | /// x op Id === x and Id op x === x for all x. |
449 | | /// |
450 | | /// In LLVM, the Xor operator is nilpotent. |
451 | | /// |
452 | 0 | bool isNilpotent() const { return isNilpotent(getOpcode()); } |
453 | 8.56k | static bool isNilpotent(unsigned Opcode) { |
454 | 8.56k | return Opcode == Xor; |
455 | 8.56k | } |
456 | | |
457 | | /// Return true if this instruction may modify memory. |
458 | | bool mayWriteToMemory() const; |
459 | | |
460 | | /// Return true if this instruction may read memory. |
461 | | bool mayReadFromMemory() const; |
462 | | |
463 | | /// Return true if this instruction may read or write memory. |
464 | 54.2M | bool mayReadOrWriteMemory() const { |
465 | 42.9M | return mayReadFromMemory() || mayWriteToMemory(); |
466 | 54.2M | } |
467 | | |
468 | | /// Return true if this instruction has an AtomicOrdering of unordered or |
469 | | /// higher. |
470 | | bool isAtomic() const; |
471 | | |
472 | | /// Return true if this atomic instruction loads from memory. |
473 | | bool hasAtomicLoad() const; |
474 | | |
475 | | /// Return true if this atomic instruction stores to memory. |
476 | | bool hasAtomicStore() const; |
477 | | |
478 | | /// Return true if this instruction may throw an exception. |
479 | | bool mayThrow() const; |
480 | | |
481 | | /// Return true if this instruction behaves like a memory fence: it can load |
482 | | /// or store to memory location without being given a memory location. |
483 | 923k | bool isFenceLike() const { |
484 | 923k | switch (getOpcode()) { |
485 | 923k | default: |
486 | 923k | return false; |
487 | 923k | // This list should be kept in sync with the list in mayWriteToMemory for |
488 | 923k | // all opcodes which don't have a memory location. |
489 | 1 | case Instruction::Fence: |
490 | 1 | case Instruction::CatchPad: |
491 | 1 | case Instruction::CatchRet: |
492 | 1 | case Instruction::Call: |
493 | 1 | case Instruction::Invoke: |
494 | 1 | return true; |
495 | 923k | } |
496 | 923k | } |
497 | | |
498 | | /// Return true if the instruction may have side effects. |
499 | | /// |
500 | | /// Note that this does not consider malloc and alloca to have side |
501 | | /// effects because the newly allocated memory is completely invisible to |
502 | | /// instructions which don't use the returned value. For cases where this |
503 | | /// matters, isSafeToSpeculativelyExecute may be more appropriate. |
504 | 189M | bool mayHaveSideEffects() const { return mayWriteToMemory() || 189M mayThrow()97.2M ; } |
505 | | |
506 | | /// Return true if the instruction is a variety of EH-block. |
507 | 202M | bool isEHPad() const { |
508 | 202M | switch (getOpcode()) { |
509 | 174k | case Instruction::CatchSwitch: |
510 | 174k | case Instruction::CatchPad: |
511 | 174k | case Instruction::CleanupPad: |
512 | 174k | case Instruction::LandingPad: |
513 | 174k | return true; |
514 | 202M | default: |
515 | 202M | return false; |
516 | 202M | } |
517 | 202M | } |
518 | | |
519 | | /// Create a copy of 'this' instruction that is identical in all ways except |
520 | | /// the following: |
521 | | /// * The instruction has no parent |
522 | | /// * The instruction has no name |
523 | | /// |
524 | | Instruction *clone() const; |
525 | | |
526 | | /// Return true if the specified instruction is exactly identical to the |
527 | | /// current one. This means that all operands match and any extra information |
528 | | /// (e.g. load is volatile) agree. |
529 | | bool isIdenticalTo(const Instruction *I) const; |
530 | | |
531 | | /// This is like isIdenticalTo, except that it ignores the |
532 | | /// SubclassOptionalData flags, which may specify conditions under which the |
533 | | /// instruction's result is undefined. |
534 | | bool isIdenticalToWhenDefined(const Instruction *I) const; |
535 | | |
536 | | /// When checking for operation equivalence (using isSameOperationAs) it is |
537 | | /// sometimes useful to ignore certain attributes. |
538 | | enum OperationEquivalenceFlags { |
539 | | /// Check for equivalence ignoring load/store alignment. |
540 | | CompareIgnoringAlignment = 1<<0, |
541 | | /// Check for equivalence treating a type and a vector of that type |
542 | | /// as equivalent. |
543 | | CompareUsingScalarTypes = 1<<1 |
544 | | }; |
545 | | |
546 | | /// This function determines if the specified instruction executes the same |
547 | | /// operation as the current one. This means that the opcodes, type, operand |
548 | | /// types and any other factors affecting the operation must be the same. This |
549 | | /// is similar to isIdenticalTo except the operands themselves don't have to |
550 | | /// be identical. |
551 | | /// @returns true if the specified instruction is the same operation as |
552 | | /// the current one. |
553 | | /// @brief Determine if one instruction is the same operation as another. |
554 | | bool isSameOperationAs(const Instruction *I, unsigned flags = 0) const; |
555 | | |
556 | | /// Return true if there are any uses of this instruction in blocks other than |
557 | | /// the specified block. Note that PHI nodes are considered to evaluate their |
558 | | /// operands in the corresponding predecessor block. |
559 | | bool isUsedOutsideOfBlock(const BasicBlock *BB) const; |
560 | | |
561 | | |
562 | | /// Methods for support type inquiry through isa, cast, and dyn_cast: |
563 | 3.08G | static bool classof(const Value *V) { |
564 | 3.08G | return V->getValueID() >= Value::InstructionVal; |
565 | 3.08G | } |
566 | | |
567 | | //---------------------------------------------------------------------- |
568 | | // Exported enumerations. |
569 | | // |
570 | | enum TermOps { // These terminate basic blocks |
571 | | #define FIRST_TERM_INST(N) TermOpsBegin = N, |
572 | | #define HANDLE_TERM_INST(N, OPC, CLASS) OPC = N, |
573 | | #define LAST_TERM_INST(N) TermOpsEnd = N+1 |
574 | | #include "llvm/IR/Instruction.def" |
575 | | }; |
576 | | |
577 | | enum BinaryOps { |
578 | | #define FIRST_BINARY_INST(N) BinaryOpsBegin = N, |
579 | | #define HANDLE_BINARY_INST(N, OPC, CLASS) OPC = N, |
580 | | #define LAST_BINARY_INST(N) BinaryOpsEnd = N+1 |
581 | | #include "llvm/IR/Instruction.def" |
582 | | }; |
583 | | |
584 | | enum MemoryOps { |
585 | | #define FIRST_MEMORY_INST(N) MemoryOpsBegin = N, |
586 | | #define HANDLE_MEMORY_INST(N, OPC, CLASS) OPC = N, |
587 | | #define LAST_MEMORY_INST(N) MemoryOpsEnd = N+1 |
588 | | #include "llvm/IR/Instruction.def" |
589 | | }; |
590 | | |
591 | | enum CastOps { |
592 | | #define FIRST_CAST_INST(N) CastOpsBegin = N, |
593 | | #define HANDLE_CAST_INST(N, OPC, CLASS) OPC = N, |
594 | | #define LAST_CAST_INST(N) CastOpsEnd = N+1 |
595 | | #include "llvm/IR/Instruction.def" |
596 | | }; |
597 | | |
598 | | enum FuncletPadOps { |
599 | | #define FIRST_FUNCLETPAD_INST(N) FuncletPadOpsBegin = N, |
600 | | #define HANDLE_FUNCLETPAD_INST(N, OPC, CLASS) OPC = N, |
601 | | #define LAST_FUNCLETPAD_INST(N) FuncletPadOpsEnd = N+1 |
602 | | #include "llvm/IR/Instruction.def" |
603 | | }; |
604 | | |
605 | | enum OtherOps { |
606 | | #define FIRST_OTHER_INST(N) OtherOpsBegin = N, |
607 | | #define HANDLE_OTHER_INST(N, OPC, CLASS) OPC = N, |
608 | | #define LAST_OTHER_INST(N) OtherOpsEnd = N+1 |
609 | | #include "llvm/IR/Instruction.def" |
610 | | }; |
611 | | |
612 | | private: |
613 | | friend class SymbolTableListTraits<Instruction>; |
614 | | |
615 | | // Shadow Value::setValueSubclassData with a private forwarding method so that |
616 | | // subclasses cannot accidentally use it. |
617 | 69.8M | void setValueSubclassData(unsigned short D) { |
618 | 69.8M | Value::setValueSubclassData(D); |
619 | 69.8M | } |
620 | | |
621 | 2.95G | unsigned short getSubclassDataFromValue() const { |
622 | 2.95G | return Value::getSubclassDataFromValue(); |
623 | 2.95G | } |
624 | | |
625 | 10.2M | void setHasMetadataHashEntry(bool V) { |
626 | 10.2M | setValueSubclassData((getSubclassDataFromValue() & ~HasMetadataBit) | |
627 | 10.2M | (V ? HasMetadataBit6.90M : 03.38M )); |
628 | 10.2M | } |
629 | | |
630 | | void setParent(BasicBlock *P); |
631 | | |
632 | | protected: |
633 | | // Instruction subclasses can stick up to 15 bits of stuff into the |
634 | | // SubclassData field of instruction with these members. |
635 | | |
636 | | // Verify that only the low 15 bits are used. |
637 | 59.6M | void setInstructionSubclassData(unsigned short D) { |
638 | 59.6M | assert((D & HasMetadataBit) == 0 && "Out of range value put into field"); |
639 | 59.6M | setValueSubclassData((getSubclassDataFromValue() & HasMetadataBit) | D); |
640 | 59.6M | } |
641 | | |
642 | 1.72G | unsigned getSubclassDataFromInstruction() const { |
643 | 1.72G | return getSubclassDataFromValue() & ~HasMetadataBit; |
644 | 1.72G | } |
645 | | |
646 | | Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, |
647 | | Instruction *InsertBefore = nullptr); |
648 | | Instruction(Type *Ty, unsigned iType, Use *Ops, unsigned NumOps, |
649 | | BasicBlock *InsertAtEnd); |
650 | | |
651 | | private: |
652 | | /// Create a copy of this instruction. |
653 | | Instruction *cloneImpl() const; |
654 | | }; |
655 | | |
656 | 34.8M | inline void ilist_alloc_traits<Instruction>::deleteNode(Instruction *V) { |
657 | 34.8M | V->deleteValue(); |
658 | 34.8M | } |
659 | | |
660 | | } // end namespace llvm |
661 | | |
662 | | #endif // LLVM_IR_INSTRUCTION_H |