Operator.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/Operator.h - Operator utility subclass -------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines various classes for working with Instructions and
  15. // ConstantExprs.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_OPERATOR_H
  19. #define LLVM_IR_OPERATOR_H
  20. #include "llvm/ADT/None.h"
  21. #include "llvm/ADT/Optional.h"
  22. #include "llvm/IR/Constants.h"
  23. #include "llvm/IR/Instruction.h"
  24. #include "llvm/IR/Type.h"
  25. #include "llvm/IR/Value.h"
  26. #include "llvm/Support/Casting.h"
  27. #include <cstddef>
  28. namespace llvm {
  29. /// This is a utility class that provides an abstraction for the common
  30. /// functionality between Instructions and ConstantExprs.
  31. class Operator : public User {
  32. public:
  33. // The Operator class is intended to be used as a utility, and is never itself
  34. // instantiated.
  35. Operator() = delete;
  36. ~Operator() = delete;
  37. void *operator new(size_t s) = delete;
  38. /// Return the opcode for this Instruction or ConstantExpr.
  39. unsigned getOpcode() const {
  40. if (const Instruction *I = dyn_cast<Instruction>(this))
  41. return I->getOpcode();
  42. return cast<ConstantExpr>(this)->getOpcode();
  43. }
  44. /// If V is an Instruction or ConstantExpr, return its opcode.
  45. /// Otherwise return UserOp1.
  46. static unsigned getOpcode(const Value *V) {
  47. if (const Instruction *I = dyn_cast<Instruction>(V))
  48. return I->getOpcode();
  49. if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
  50. return CE->getOpcode();
  51. return Instruction::UserOp1;
  52. }
  53. static bool classof(const Instruction *) { return true; }
  54. static bool classof(const ConstantExpr *) { return true; }
  55. static bool classof(const Value *V) {
  56. return isa<Instruction>(V) || isa<ConstantExpr>(V);
  57. }
  58. };
  59. /// Utility class for integer operators which may exhibit overflow - Add, Sub,
  60. /// Mul, and Shl. It does not include SDiv, despite that operator having the
  61. /// potential for overflow.
  62. class OverflowingBinaryOperator : public Operator {
  63. public:
  64. enum {
  65. AnyWrap = 0,
  66. NoUnsignedWrap = (1 << 0),
  67. NoSignedWrap = (1 << 1)
  68. };
  69. private:
  70. friend class Instruction;
  71. friend class ConstantExpr;
  72. void setHasNoUnsignedWrap(bool B) {
  73. SubclassOptionalData =
  74. (SubclassOptionalData & ~NoUnsignedWrap) | (B * NoUnsignedWrap);
  75. }
  76. void setHasNoSignedWrap(bool B) {
  77. SubclassOptionalData =
  78. (SubclassOptionalData & ~NoSignedWrap) | (B * NoSignedWrap);
  79. }
  80. public:
  81. /// Test whether this operation is known to never
  82. /// undergo unsigned overflow, aka the nuw property.
  83. bool hasNoUnsignedWrap() const {
  84. return SubclassOptionalData & NoUnsignedWrap;
  85. }
  86. /// Test whether this operation is known to never
  87. /// undergo signed overflow, aka the nsw property.
  88. bool hasNoSignedWrap() const {
  89. return (SubclassOptionalData & NoSignedWrap) != 0;
  90. }
  91. static bool classof(const Instruction *I) {
  92. return I->getOpcode() == Instruction::Add ||
  93. I->getOpcode() == Instruction::Sub ||
  94. I->getOpcode() == Instruction::Mul ||
  95. I->getOpcode() == Instruction::Shl;
  96. }
  97. static bool classof(const ConstantExpr *CE) {
  98. return CE->getOpcode() == Instruction::Add ||
  99. CE->getOpcode() == Instruction::Sub ||
  100. CE->getOpcode() == Instruction::Mul ||
  101. CE->getOpcode() == Instruction::Shl;
  102. }
  103. static bool classof(const Value *V) {
  104. return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
  105. (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
  106. }
  107. };
  108. /// A udiv or sdiv instruction, which can be marked as "exact",
  109. /// indicating that no bits are destroyed.
  110. class PossiblyExactOperator : public Operator {
  111. public:
  112. enum {
  113. IsExact = (1 << 0)
  114. };
  115. private:
  116. friend class Instruction;
  117. friend class ConstantExpr;
  118. void setIsExact(bool B) {
  119. SubclassOptionalData = (SubclassOptionalData & ~IsExact) | (B * IsExact);
  120. }
  121. public:
  122. /// Test whether this division is known to be exact, with zero remainder.
  123. bool isExact() const {
  124. return SubclassOptionalData & IsExact;
  125. }
  126. static bool isPossiblyExactOpcode(unsigned OpC) {
  127. return OpC == Instruction::SDiv ||
  128. OpC == Instruction::UDiv ||
  129. OpC == Instruction::AShr ||
  130. OpC == Instruction::LShr;
  131. }
  132. static bool classof(const ConstantExpr *CE) {
  133. return isPossiblyExactOpcode(CE->getOpcode());
  134. }
  135. static bool classof(const Instruction *I) {
  136. return isPossiblyExactOpcode(I->getOpcode());
  137. }
  138. static bool classof(const Value *V) {
  139. return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
  140. (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
  141. }
  142. };
  143. /// Convenience struct for specifying and reasoning about fast-math flags.
  144. class FastMathFlags {
  145. private:
  146. friend class FPMathOperator;
  147. unsigned Flags = 0;
  148. FastMathFlags(unsigned F) {
  149. // If all 7 bits are set, turn this into -1. If the number of bits grows,
  150. // this must be updated. This is intended to provide some forward binary
  151. // compatibility insurance for the meaning of 'fast' in case bits are added.
  152. if (F == 0x7F) Flags = ~0U;
  153. else Flags = F;
  154. }
  155. public:
  156. // This is how the bits are used in Value::SubclassOptionalData so they
  157. // should fit there too.
  158. // WARNING: We're out of space. SubclassOptionalData only has 7 bits. New
  159. // functionality will require a change in how this information is stored.
  160. enum {
  161. AllowReassoc = (1 << 0),
  162. NoNaNs = (1 << 1),
  163. NoInfs = (1 << 2),
  164. NoSignedZeros = (1 << 3),
  165. AllowReciprocal = (1 << 4),
  166. AllowContract = (1 << 5),
  167. ApproxFunc = (1 << 6)
  168. };
  169. FastMathFlags() = default;
  170. static FastMathFlags getFast() {
  171. FastMathFlags FMF;
  172. FMF.setFast();
  173. return FMF;
  174. }
  175. bool any() const { return Flags != 0; }
  176. bool none() const { return Flags == 0; }
  177. bool all() const { return Flags == ~0U; }
  178. void clear() { Flags = 0; }
  179. void set() { Flags = ~0U; }
  180. /// Flag queries
  181. bool allowReassoc() const { return 0 != (Flags & AllowReassoc); }
  182. bool noNaNs() const { return 0 != (Flags & NoNaNs); }
  183. bool noInfs() const { return 0 != (Flags & NoInfs); }
  184. bool noSignedZeros() const { return 0 != (Flags & NoSignedZeros); }
  185. bool allowReciprocal() const { return 0 != (Flags & AllowReciprocal); }
  186. bool allowContract() const { return 0 != (Flags & AllowContract); }
  187. bool approxFunc() const { return 0 != (Flags & ApproxFunc); }
  188. /// 'Fast' means all bits are set.
  189. bool isFast() const { return all(); }
  190. /// Flag setters
  191. void setAllowReassoc(bool B = true) {
  192. Flags = (Flags & ~AllowReassoc) | B * AllowReassoc;
  193. }
  194. void setNoNaNs(bool B = true) {
  195. Flags = (Flags & ~NoNaNs) | B * NoNaNs;
  196. }
  197. void setNoInfs(bool B = true) {
  198. Flags = (Flags & ~NoInfs) | B * NoInfs;
  199. }
  200. void setNoSignedZeros(bool B = true) {
  201. Flags = (Flags & ~NoSignedZeros) | B * NoSignedZeros;
  202. }
  203. void setAllowReciprocal(bool B = true) {
  204. Flags = (Flags & ~AllowReciprocal) | B * AllowReciprocal;
  205. }
  206. void setAllowContract(bool B = true) {
  207. Flags = (Flags & ~AllowContract) | B * AllowContract;
  208. }
  209. void setApproxFunc(bool B = true) {
  210. Flags = (Flags & ~ApproxFunc) | B * ApproxFunc;
  211. }
  212. void setFast(bool B = true) { B ? set() : clear(); }
  213. void operator&=(const FastMathFlags &OtherFlags) {
  214. Flags &= OtherFlags.Flags;
  215. }
  216. };
  217. /// Utility class for floating point operations which can have
  218. /// information about relaxed accuracy requirements attached to them.
  219. class FPMathOperator : public Operator {
  220. private:
  221. friend class Instruction;
  222. /// 'Fast' means all bits are set.
  223. void setFast(bool B) {
  224. setHasAllowReassoc(B);
  225. setHasNoNaNs(B);
  226. setHasNoInfs(B);
  227. setHasNoSignedZeros(B);
  228. setHasAllowReciprocal(B);
  229. setHasAllowContract(B);
  230. setHasApproxFunc(B);
  231. }
  232. void setHasAllowReassoc(bool B) {
  233. SubclassOptionalData =
  234. (SubclassOptionalData & ~FastMathFlags::AllowReassoc) |
  235. (B * FastMathFlags::AllowReassoc);
  236. }
  237. void setHasNoNaNs(bool B) {
  238. SubclassOptionalData =
  239. (SubclassOptionalData & ~FastMathFlags::NoNaNs) |
  240. (B * FastMathFlags::NoNaNs);
  241. }
  242. void setHasNoInfs(bool B) {
  243. SubclassOptionalData =
  244. (SubclassOptionalData & ~FastMathFlags::NoInfs) |
  245. (B * FastMathFlags::NoInfs);
  246. }
  247. void setHasNoSignedZeros(bool B) {
  248. SubclassOptionalData =
  249. (SubclassOptionalData & ~FastMathFlags::NoSignedZeros) |
  250. (B * FastMathFlags::NoSignedZeros);
  251. }
  252. void setHasAllowReciprocal(bool B) {
  253. SubclassOptionalData =
  254. (SubclassOptionalData & ~FastMathFlags::AllowReciprocal) |
  255. (B * FastMathFlags::AllowReciprocal);
  256. }
  257. void setHasAllowContract(bool B) {
  258. SubclassOptionalData =
  259. (SubclassOptionalData & ~FastMathFlags::AllowContract) |
  260. (B * FastMathFlags::AllowContract);
  261. }
  262. void setHasApproxFunc(bool B) {
  263. SubclassOptionalData =
  264. (SubclassOptionalData & ~FastMathFlags::ApproxFunc) |
  265. (B * FastMathFlags::ApproxFunc);
  266. }
  267. /// Convenience function for setting multiple fast-math flags.
  268. /// FMF is a mask of the bits to set.
  269. void setFastMathFlags(FastMathFlags FMF) {
  270. SubclassOptionalData |= FMF.Flags;
  271. }
  272. /// Convenience function for copying all fast-math flags.
  273. /// All values in FMF are transferred to this operator.
  274. void copyFastMathFlags(FastMathFlags FMF) {
  275. SubclassOptionalData = FMF.Flags;
  276. }
  277. public:
  278. /// Test if this operation allows all non-strict floating-point transforms.
  279. bool isFast() const {
  280. return ((SubclassOptionalData & FastMathFlags::AllowReassoc) != 0 &&
  281. (SubclassOptionalData & FastMathFlags::NoNaNs) != 0 &&
  282. (SubclassOptionalData & FastMathFlags::NoInfs) != 0 &&
  283. (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0 &&
  284. (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0 &&
  285. (SubclassOptionalData & FastMathFlags::AllowContract) != 0 &&
  286. (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0);
  287. }
  288. /// Test if this operation may be simplified with reassociative transforms.
  289. bool hasAllowReassoc() const {
  290. return (SubclassOptionalData & FastMathFlags::AllowReassoc) != 0;
  291. }
  292. /// Test if this operation's arguments and results are assumed not-NaN.
  293. bool hasNoNaNs() const {
  294. return (SubclassOptionalData & FastMathFlags::NoNaNs) != 0;
  295. }
  296. /// Test if this operation's arguments and results are assumed not-infinite.
  297. bool hasNoInfs() const {
  298. return (SubclassOptionalData & FastMathFlags::NoInfs) != 0;
  299. }
  300. /// Test if this operation can ignore the sign of zero.
  301. bool hasNoSignedZeros() const {
  302. return (SubclassOptionalData & FastMathFlags::NoSignedZeros) != 0;
  303. }
  304. /// Test if this operation can use reciprocal multiply instead of division.
  305. bool hasAllowReciprocal() const {
  306. return (SubclassOptionalData & FastMathFlags::AllowReciprocal) != 0;
  307. }
  308. /// Test if this operation can be floating-point contracted (FMA).
  309. bool hasAllowContract() const {
  310. return (SubclassOptionalData & FastMathFlags::AllowContract) != 0;
  311. }
  312. /// Test if this operation allows approximations of math library functions or
  313. /// intrinsics.
  314. bool hasApproxFunc() const {
  315. return (SubclassOptionalData & FastMathFlags::ApproxFunc) != 0;
  316. }
  317. /// Convenience function for getting all the fast-math flags
  318. FastMathFlags getFastMathFlags() const {
  319. return FastMathFlags(SubclassOptionalData);
  320. }
  321. /// Get the maximum error permitted by this operation in ULPs. An accuracy of
  322. /// 0.0 means that the operation should be performed with the default
  323. /// precision.
  324. float getFPAccuracy() const;
  325. static bool classof(const Value *V) {
  326. unsigned Opcode;
  327. if (auto *I = dyn_cast<Instruction>(V))
  328. Opcode = I->getOpcode();
  329. else if (auto *CE = dyn_cast<ConstantExpr>(V))
  330. Opcode = CE->getOpcode();
  331. else
  332. return false;
  333. switch (Opcode) {
  334. case Instruction::FNeg:
  335. case Instruction::FAdd:
  336. case Instruction::FSub:
  337. case Instruction::FMul:
  338. case Instruction::FDiv:
  339. case Instruction::FRem:
  340. // FIXME: To clean up and correct the semantics of fast-math-flags, FCmp
  341. // should not be treated as a math op, but the other opcodes should.
  342. // This would make things consistent with Select/PHI (FP value type
  343. // determines whether they are math ops and, therefore, capable of
  344. // having fast-math-flags).
  345. case Instruction::FCmp:
  346. return true;
  347. case Instruction::PHI:
  348. case Instruction::Select:
  349. case Instruction::Call: {
  350. Type *Ty = V->getType();
  351. while (ArrayType *ArrTy = dyn_cast<ArrayType>(Ty))
  352. Ty = ArrTy->getElementType();
  353. return Ty->isFPOrFPVectorTy();
  354. }
  355. default:
  356. return false;
  357. }
  358. }
  359. };
  360. /// A helper template for defining operators for individual opcodes.
  361. template<typename SuperClass, unsigned Opc>
  362. class ConcreteOperator : public SuperClass {
  363. public:
  364. static bool classof(const Instruction *I) {
  365. return I->getOpcode() == Opc;
  366. }
  367. static bool classof(const ConstantExpr *CE) {
  368. return CE->getOpcode() == Opc;
  369. }
  370. static bool classof(const Value *V) {
  371. return (isa<Instruction>(V) && classof(cast<Instruction>(V))) ||
  372. (isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)));
  373. }
  374. };
  375. class AddOperator
  376. : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Add> {
  377. };
  378. class SubOperator
  379. : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Sub> {
  380. };
  381. class MulOperator
  382. : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Mul> {
  383. };
  384. class ShlOperator
  385. : public ConcreteOperator<OverflowingBinaryOperator, Instruction::Shl> {
  386. };
  387. class SDivOperator
  388. : public ConcreteOperator<PossiblyExactOperator, Instruction::SDiv> {
  389. };
  390. class UDivOperator
  391. : public ConcreteOperator<PossiblyExactOperator, Instruction::UDiv> {
  392. };
  393. class AShrOperator
  394. : public ConcreteOperator<PossiblyExactOperator, Instruction::AShr> {
  395. };
  396. class LShrOperator
  397. : public ConcreteOperator<PossiblyExactOperator, Instruction::LShr> {
  398. };
  399. class ZExtOperator : public ConcreteOperator<Operator, Instruction::ZExt> {};
  400. class GEPOperator
  401. : public ConcreteOperator<Operator, Instruction::GetElementPtr> {
  402. friend class GetElementPtrInst;
  403. friend class ConstantExpr;
  404. enum {
  405. IsInBounds = (1 << 0),
  406. // InRangeIndex: bits 1-6
  407. };
  408. void setIsInBounds(bool B) {
  409. SubclassOptionalData =
  410. (SubclassOptionalData & ~IsInBounds) | (B * IsInBounds);
  411. }
  412. public:
  413. /// Test whether this is an inbounds GEP, as defined by LangRef.html.
  414. bool isInBounds() const {
  415. return SubclassOptionalData & IsInBounds;
  416. }
  417. /// Returns the offset of the index with an inrange attachment, or None if
  418. /// none.
  419. Optional<unsigned> getInRangeIndex() const {
  420. if (SubclassOptionalData >> 1 == 0) return None;
  421. return (SubclassOptionalData >> 1) - 1;
  422. }
  423. inline op_iterator idx_begin() { return op_begin()+1; }
  424. inline const_op_iterator idx_begin() const { return op_begin()+1; }
  425. inline op_iterator idx_end() { return op_end(); }
  426. inline const_op_iterator idx_end() const { return op_end(); }
  427. Value *getPointerOperand() {
  428. return getOperand(0);
  429. }
  430. const Value *getPointerOperand() const {
  431. return getOperand(0);
  432. }
  433. static unsigned getPointerOperandIndex() {
  434. return 0U; // get index for modifying correct operand
  435. }
  436. /// Method to return the pointer operand as a PointerType.
  437. Type *getPointerOperandType() const {
  438. return getPointerOperand()->getType();
  439. }
  440. Type *getSourceElementType() const;
  441. Type *getResultElementType() const;
  442. /// Method to return the address space of the pointer operand.
  443. unsigned getPointerAddressSpace() const {
  444. return getPointerOperandType()->getPointerAddressSpace();
  445. }
  446. unsigned getNumIndices() const { // Note: always non-negative
  447. return getNumOperands() - 1;
  448. }
  449. bool hasIndices() const {
  450. return getNumOperands() > 1;
  451. }
  452. /// Return true if all of the indices of this GEP are zeros.
  453. /// If so, the result pointer and the first operand have the same
  454. /// value, just potentially different types.
  455. bool hasAllZeroIndices() const {
  456. for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
  457. if (ConstantInt *C = dyn_cast<ConstantInt>(I))
  458. if (C->isZero())
  459. continue;
  460. return false;
  461. }
  462. return true;
  463. }
  464. /// Return true if all of the indices of this GEP are constant integers.
  465. /// If so, the result pointer and the first operand have
  466. /// a constant offset between them.
  467. bool hasAllConstantIndices() const {
  468. for (const_op_iterator I = idx_begin(), E = idx_end(); I != E; ++I) {
  469. if (!isa<ConstantInt>(I))
  470. return false;
  471. }
  472. return true;
  473. }
  474. unsigned countNonConstantIndices() const {
  475. return count_if(make_range(idx_begin(), idx_end()), [](const Use& use) {
  476. return !isa<ConstantInt>(*use);
  477. });
  478. }
  479. /// Compute the maximum alignment that this GEP is garranteed to preserve.
  480. Align getMaxPreservedAlignment(const DataLayout &DL) const;
  481. /// Accumulate the constant address offset of this GEP if possible.
  482. ///
  483. /// This routine accepts an APInt into which it will try to accumulate the
  484. /// constant offset of this GEP.
  485. ///
  486. /// If \p ExternalAnalysis is provided it will be used to calculate a offset
  487. /// when a operand of GEP is not constant.
  488. /// For example, for a value \p ExternalAnalysis might try to calculate a
  489. /// lower bound. If \p ExternalAnalysis is successful, it should return true.
  490. ///
  491. /// If the \p ExternalAnalysis returns false or the value returned by \p
  492. /// ExternalAnalysis results in a overflow/underflow, this routine returns
  493. /// false and the value of the offset APInt is undefined (it is *not*
  494. /// preserved!).
  495. ///
  496. /// The APInt passed into this routine must be at exactly as wide as the
  497. /// IntPtr type for the address space of the base GEP pointer.
  498. bool accumulateConstantOffset(
  499. const DataLayout &DL, APInt &Offset,
  500. function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr) const;
  501. static bool accumulateConstantOffset(
  502. Type *SourceType, ArrayRef<const Value *> Index, const DataLayout &DL,
  503. APInt &Offset,
  504. function_ref<bool(Value &, APInt &)> ExternalAnalysis = nullptr);
  505. };
  506. class PtrToIntOperator
  507. : public ConcreteOperator<Operator, Instruction::PtrToInt> {
  508. friend class PtrToInt;
  509. friend class ConstantExpr;
  510. public:
  511. Value *getPointerOperand() {
  512. return getOperand(0);
  513. }
  514. const Value *getPointerOperand() const {
  515. return getOperand(0);
  516. }
  517. static unsigned getPointerOperandIndex() {
  518. return 0U; // get index for modifying correct operand
  519. }
  520. /// Method to return the pointer operand as a PointerType.
  521. Type *getPointerOperandType() const {
  522. return getPointerOperand()->getType();
  523. }
  524. /// Method to return the address space of the pointer operand.
  525. unsigned getPointerAddressSpace() const {
  526. return cast<PointerType>(getPointerOperandType())->getAddressSpace();
  527. }
  528. };
  529. class BitCastOperator
  530. : public ConcreteOperator<Operator, Instruction::BitCast> {
  531. friend class BitCastInst;
  532. friend class ConstantExpr;
  533. public:
  534. Type *getSrcTy() const {
  535. return getOperand(0)->getType();
  536. }
  537. Type *getDestTy() const {
  538. return getType();
  539. }
  540. };
  541. class AddrSpaceCastOperator
  542. : public ConcreteOperator<Operator, Instruction::AddrSpaceCast> {
  543. friend class AddrSpaceCastInst;
  544. friend class ConstantExpr;
  545. public:
  546. Value *getPointerOperand() { return getOperand(0); }
  547. const Value *getPointerOperand() const { return getOperand(0); }
  548. unsigned getSrcAddressSpace() const {
  549. return getPointerOperand()->getType()->getPointerAddressSpace();
  550. }
  551. unsigned getDestAddressSpace() const {
  552. return getType()->getPointerAddressSpace();
  553. }
  554. };
  555. } // end namespace llvm
  556. #endif // LLVM_IR_OPERATOR_H
  557. #ifdef __GNUC__
  558. #pragma GCC diagnostic pop
  559. #endif