GVNExpression.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. //===- GVNExpression.h - GVN Expression classes -----------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. /// \file
  10. ///
  11. /// The header file for the GVN pass that contains expression handling
  12. /// classes
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
  16. #define LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H
  17. #include "llvm/ADT/Hashing.h"
  18. #include "llvm/ADT/iterator_range.h"
  19. #include "llvm/Analysis/MemorySSA.h"
  20. #include "llvm/IR/Constant.h"
  21. #include "llvm/IR/Instructions.h"
  22. #include "llvm/IR/Value.h"
  23. #include "llvm/Support/Allocator.h"
  24. #include "llvm/Support/ArrayRecycler.h"
  25. #include "llvm/Support/Casting.h"
  26. #include "llvm/Support/Compiler.h"
  27. #include "llvm/Support/raw_ostream.h"
  28. #include <algorithm>
  29. #include <cassert>
  30. #include <iterator>
  31. #include <utility>
  32. namespace llvm {
  33. class BasicBlock;
  34. class Type;
  35. namespace GVNExpression {
  36. enum ExpressionType {
  37. ET_Base,
  38. ET_Constant,
  39. ET_Variable,
  40. ET_Dead,
  41. ET_Unknown,
  42. ET_BasicStart,
  43. ET_Basic,
  44. ET_AggregateValue,
  45. ET_Phi,
  46. ET_MemoryStart,
  47. ET_Call,
  48. ET_Load,
  49. ET_Store,
  50. ET_MemoryEnd,
  51. ET_BasicEnd
  52. };
  53. class Expression {
  54. private:
  55. ExpressionType EType;
  56. unsigned Opcode;
  57. mutable hash_code HashVal = 0;
  58. public:
  59. Expression(ExpressionType ET = ET_Base, unsigned O = ~2U)
  60. : EType(ET), Opcode(O) {}
  61. Expression(const Expression &) = delete;
  62. Expression &operator=(const Expression &) = delete;
  63. virtual ~Expression();
  64. static unsigned getEmptyKey() { return ~0U; }
  65. static unsigned getTombstoneKey() { return ~1U; }
  66. bool operator!=(const Expression &Other) const { return !(*this == Other); }
  67. bool operator==(const Expression &Other) const {
  68. if (getOpcode() != Other.getOpcode())
  69. return false;
  70. if (getOpcode() == getEmptyKey() || getOpcode() == getTombstoneKey())
  71. return true;
  72. // Compare the expression type for anything but load and store.
  73. // For load and store we set the opcode to zero to make them equal.
  74. if (getExpressionType() != ET_Load && getExpressionType() != ET_Store &&
  75. getExpressionType() != Other.getExpressionType())
  76. return false;
  77. return equals(Other);
  78. }
  79. hash_code getComputedHash() const {
  80. // It's theoretically possible for a thing to hash to zero. In that case,
  81. // we will just compute the hash a few extra times, which is no worse that
  82. // we did before, which was to compute it always.
  83. if (static_cast<unsigned>(HashVal) == 0)
  84. HashVal = getHashValue();
  85. return HashVal;
  86. }
  87. virtual bool equals(const Expression &Other) const { return true; }
  88. // Return true if the two expressions are exactly the same, including the
  89. // normally ignored fields.
  90. virtual bool exactlyEquals(const Expression &Other) const {
  91. return getExpressionType() == Other.getExpressionType() && equals(Other);
  92. }
  93. unsigned getOpcode() const { return Opcode; }
  94. void setOpcode(unsigned opcode) { Opcode = opcode; }
  95. ExpressionType getExpressionType() const { return EType; }
  96. // We deliberately leave the expression type out of the hash value.
  97. virtual hash_code getHashValue() const { return getOpcode(); }
  98. // Debugging support
  99. virtual void printInternal(raw_ostream &OS, bool PrintEType) const {
  100. if (PrintEType)
  101. OS << "etype = " << getExpressionType() << ",";
  102. OS << "opcode = " << getOpcode() << ", ";
  103. }
  104. void print(raw_ostream &OS) const {
  105. OS << "{ ";
  106. printInternal(OS, true);
  107. OS << "}";
  108. }
  109. LLVM_DUMP_METHOD void dump() const;
  110. };
  111. inline raw_ostream &operator<<(raw_ostream &OS, const Expression &E) {
  112. E.print(OS);
  113. return OS;
  114. }
  115. class BasicExpression : public Expression {
  116. private:
  117. using RecyclerType = ArrayRecycler<Value *>;
  118. using RecyclerCapacity = RecyclerType::Capacity;
  119. Value **Operands = nullptr;
  120. unsigned MaxOperands;
  121. unsigned NumOperands = 0;
  122. Type *ValueType = nullptr;
  123. public:
  124. BasicExpression(unsigned NumOperands)
  125. : BasicExpression(NumOperands, ET_Basic) {}
  126. BasicExpression(unsigned NumOperands, ExpressionType ET)
  127. : Expression(ET), MaxOperands(NumOperands) {}
  128. BasicExpression() = delete;
  129. BasicExpression(const BasicExpression &) = delete;
  130. BasicExpression &operator=(const BasicExpression &) = delete;
  131. ~BasicExpression() override;
  132. static bool classof(const Expression *EB) {
  133. ExpressionType ET = EB->getExpressionType();
  134. return ET > ET_BasicStart && ET < ET_BasicEnd;
  135. }
  136. /// Swap two operands. Used during GVN to put commutative operands in
  137. /// order.
  138. void swapOperands(unsigned First, unsigned Second) {
  139. std::swap(Operands[First], Operands[Second]);
  140. }
  141. Value *getOperand(unsigned N) const {
  142. assert(Operands && "Operands not allocated");
  143. assert(N < NumOperands && "Operand out of range");
  144. return Operands[N];
  145. }
  146. void setOperand(unsigned N, Value *V) {
  147. assert(Operands && "Operands not allocated before setting");
  148. assert(N < NumOperands && "Operand out of range");
  149. Operands[N] = V;
  150. }
  151. unsigned getNumOperands() const { return NumOperands; }
  152. using op_iterator = Value **;
  153. using const_op_iterator = Value *const *;
  154. op_iterator op_begin() { return Operands; }
  155. op_iterator op_end() { return Operands + NumOperands; }
  156. const_op_iterator op_begin() const { return Operands; }
  157. const_op_iterator op_end() const { return Operands + NumOperands; }
  158. iterator_range<op_iterator> operands() {
  159. return iterator_range<op_iterator>(op_begin(), op_end());
  160. }
  161. iterator_range<const_op_iterator> operands() const {
  162. return iterator_range<const_op_iterator>(op_begin(), op_end());
  163. }
  164. void op_push_back(Value *Arg) {
  165. assert(NumOperands < MaxOperands && "Tried to add too many operands");
  166. assert(Operands && "Operandss not allocated before pushing");
  167. Operands[NumOperands++] = Arg;
  168. }
  169. bool op_empty() const { return getNumOperands() == 0; }
  170. void allocateOperands(RecyclerType &Recycler, BumpPtrAllocator &Allocator) {
  171. assert(!Operands && "Operands already allocated");
  172. Operands = Recycler.allocate(RecyclerCapacity::get(MaxOperands), Allocator);
  173. }
  174. void deallocateOperands(RecyclerType &Recycler) {
  175. Recycler.deallocate(RecyclerCapacity::get(MaxOperands), Operands);
  176. }
  177. void setType(Type *T) { ValueType = T; }
  178. Type *getType() const { return ValueType; }
  179. bool equals(const Expression &Other) const override {
  180. if (getOpcode() != Other.getOpcode())
  181. return false;
  182. const auto &OE = cast<BasicExpression>(Other);
  183. return getType() == OE.getType() && NumOperands == OE.NumOperands &&
  184. std::equal(op_begin(), op_end(), OE.op_begin());
  185. }
  186. hash_code getHashValue() const override {
  187. return hash_combine(this->Expression::getHashValue(), ValueType,
  188. hash_combine_range(op_begin(), op_end()));
  189. }
  190. // Debugging support
  191. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  192. if (PrintEType)
  193. OS << "ExpressionTypeBasic, ";
  194. this->Expression::printInternal(OS, false);
  195. OS << "operands = {";
  196. for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
  197. OS << "[" << i << "] = ";
  198. Operands[i]->printAsOperand(OS);
  199. OS << " ";
  200. }
  201. OS << "} ";
  202. }
  203. };
  204. class op_inserter {
  205. private:
  206. using Container = BasicExpression;
  207. Container *BE;
  208. public:
  209. using iterator_category = std::output_iterator_tag;
  210. using value_type = void;
  211. using difference_type = void;
  212. using pointer = void;
  213. using reference = void;
  214. explicit op_inserter(BasicExpression &E) : BE(&E) {}
  215. explicit op_inserter(BasicExpression *E) : BE(E) {}
  216. op_inserter &operator=(Value *val) {
  217. BE->op_push_back(val);
  218. return *this;
  219. }
  220. op_inserter &operator*() { return *this; }
  221. op_inserter &operator++() { return *this; }
  222. op_inserter &operator++(int) { return *this; }
  223. };
  224. class MemoryExpression : public BasicExpression {
  225. private:
  226. const MemoryAccess *MemoryLeader;
  227. public:
  228. MemoryExpression(unsigned NumOperands, enum ExpressionType EType,
  229. const MemoryAccess *MemoryLeader)
  230. : BasicExpression(NumOperands, EType), MemoryLeader(MemoryLeader) {}
  231. MemoryExpression() = delete;
  232. MemoryExpression(const MemoryExpression &) = delete;
  233. MemoryExpression &operator=(const MemoryExpression &) = delete;
  234. static bool classof(const Expression *EB) {
  235. return EB->getExpressionType() > ET_MemoryStart &&
  236. EB->getExpressionType() < ET_MemoryEnd;
  237. }
  238. hash_code getHashValue() const override {
  239. return hash_combine(this->BasicExpression::getHashValue(), MemoryLeader);
  240. }
  241. bool equals(const Expression &Other) const override {
  242. if (!this->BasicExpression::equals(Other))
  243. return false;
  244. const MemoryExpression &OtherMCE = cast<MemoryExpression>(Other);
  245. return MemoryLeader == OtherMCE.MemoryLeader;
  246. }
  247. const MemoryAccess *getMemoryLeader() const { return MemoryLeader; }
  248. void setMemoryLeader(const MemoryAccess *ML) { MemoryLeader = ML; }
  249. };
  250. class CallExpression final : public MemoryExpression {
  251. private:
  252. CallInst *Call;
  253. public:
  254. CallExpression(unsigned NumOperands, CallInst *C,
  255. const MemoryAccess *MemoryLeader)
  256. : MemoryExpression(NumOperands, ET_Call, MemoryLeader), Call(C) {}
  257. CallExpression() = delete;
  258. CallExpression(const CallExpression &) = delete;
  259. CallExpression &operator=(const CallExpression &) = delete;
  260. ~CallExpression() override;
  261. static bool classof(const Expression *EB) {
  262. return EB->getExpressionType() == ET_Call;
  263. }
  264. // Debugging support
  265. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  266. if (PrintEType)
  267. OS << "ExpressionTypeCall, ";
  268. this->BasicExpression::printInternal(OS, false);
  269. OS << " represents call at ";
  270. Call->printAsOperand(OS);
  271. }
  272. };
  273. class LoadExpression final : public MemoryExpression {
  274. private:
  275. LoadInst *Load;
  276. public:
  277. LoadExpression(unsigned NumOperands, LoadInst *L,
  278. const MemoryAccess *MemoryLeader)
  279. : LoadExpression(ET_Load, NumOperands, L, MemoryLeader) {}
  280. LoadExpression(enum ExpressionType EType, unsigned NumOperands, LoadInst *L,
  281. const MemoryAccess *MemoryLeader)
  282. : MemoryExpression(NumOperands, EType, MemoryLeader), Load(L) {}
  283. LoadExpression() = delete;
  284. LoadExpression(const LoadExpression &) = delete;
  285. LoadExpression &operator=(const LoadExpression &) = delete;
  286. ~LoadExpression() override;
  287. static bool classof(const Expression *EB) {
  288. return EB->getExpressionType() == ET_Load;
  289. }
  290. LoadInst *getLoadInst() const { return Load; }
  291. void setLoadInst(LoadInst *L) { Load = L; }
  292. bool equals(const Expression &Other) const override;
  293. bool exactlyEquals(const Expression &Other) const override {
  294. return Expression::exactlyEquals(Other) &&
  295. cast<LoadExpression>(Other).getLoadInst() == getLoadInst();
  296. }
  297. // Debugging support
  298. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  299. if (PrintEType)
  300. OS << "ExpressionTypeLoad, ";
  301. this->BasicExpression::printInternal(OS, false);
  302. OS << " represents Load at ";
  303. Load->printAsOperand(OS);
  304. OS << " with MemoryLeader " << *getMemoryLeader();
  305. }
  306. };
  307. class StoreExpression final : public MemoryExpression {
  308. private:
  309. StoreInst *Store;
  310. Value *StoredValue;
  311. public:
  312. StoreExpression(unsigned NumOperands, StoreInst *S, Value *StoredValue,
  313. const MemoryAccess *MemoryLeader)
  314. : MemoryExpression(NumOperands, ET_Store, MemoryLeader), Store(S),
  315. StoredValue(StoredValue) {}
  316. StoreExpression() = delete;
  317. StoreExpression(const StoreExpression &) = delete;
  318. StoreExpression &operator=(const StoreExpression &) = delete;
  319. ~StoreExpression() override;
  320. static bool classof(const Expression *EB) {
  321. return EB->getExpressionType() == ET_Store;
  322. }
  323. StoreInst *getStoreInst() const { return Store; }
  324. Value *getStoredValue() const { return StoredValue; }
  325. bool equals(const Expression &Other) const override;
  326. bool exactlyEquals(const Expression &Other) const override {
  327. return Expression::exactlyEquals(Other) &&
  328. cast<StoreExpression>(Other).getStoreInst() == getStoreInst();
  329. }
  330. // Debugging support
  331. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  332. if (PrintEType)
  333. OS << "ExpressionTypeStore, ";
  334. this->BasicExpression::printInternal(OS, false);
  335. OS << " represents Store " << *Store;
  336. OS << " with StoredValue ";
  337. StoredValue->printAsOperand(OS);
  338. OS << " and MemoryLeader " << *getMemoryLeader();
  339. }
  340. };
  341. class AggregateValueExpression final : public BasicExpression {
  342. private:
  343. unsigned MaxIntOperands;
  344. unsigned NumIntOperands = 0;
  345. unsigned *IntOperands = nullptr;
  346. public:
  347. AggregateValueExpression(unsigned NumOperands, unsigned NumIntOperands)
  348. : BasicExpression(NumOperands, ET_AggregateValue),
  349. MaxIntOperands(NumIntOperands) {}
  350. AggregateValueExpression() = delete;
  351. AggregateValueExpression(const AggregateValueExpression &) = delete;
  352. AggregateValueExpression &
  353. operator=(const AggregateValueExpression &) = delete;
  354. ~AggregateValueExpression() override;
  355. static bool classof(const Expression *EB) {
  356. return EB->getExpressionType() == ET_AggregateValue;
  357. }
  358. using int_arg_iterator = unsigned *;
  359. using const_int_arg_iterator = const unsigned *;
  360. int_arg_iterator int_op_begin() { return IntOperands; }
  361. int_arg_iterator int_op_end() { return IntOperands + NumIntOperands; }
  362. const_int_arg_iterator int_op_begin() const { return IntOperands; }
  363. const_int_arg_iterator int_op_end() const {
  364. return IntOperands + NumIntOperands;
  365. }
  366. unsigned int_op_size() const { return NumIntOperands; }
  367. bool int_op_empty() const { return NumIntOperands == 0; }
  368. void int_op_push_back(unsigned IntOperand) {
  369. assert(NumIntOperands < MaxIntOperands &&
  370. "Tried to add too many int operands");
  371. assert(IntOperands && "Operands not allocated before pushing");
  372. IntOperands[NumIntOperands++] = IntOperand;
  373. }
  374. virtual void allocateIntOperands(BumpPtrAllocator &Allocator) {
  375. assert(!IntOperands && "Operands already allocated");
  376. IntOperands = Allocator.Allocate<unsigned>(MaxIntOperands);
  377. }
  378. bool equals(const Expression &Other) const override {
  379. if (!this->BasicExpression::equals(Other))
  380. return false;
  381. const AggregateValueExpression &OE = cast<AggregateValueExpression>(Other);
  382. return NumIntOperands == OE.NumIntOperands &&
  383. std::equal(int_op_begin(), int_op_end(), OE.int_op_begin());
  384. }
  385. hash_code getHashValue() const override {
  386. return hash_combine(this->BasicExpression::getHashValue(),
  387. hash_combine_range(int_op_begin(), int_op_end()));
  388. }
  389. // Debugging support
  390. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  391. if (PrintEType)
  392. OS << "ExpressionTypeAggregateValue, ";
  393. this->BasicExpression::printInternal(OS, false);
  394. OS << ", intoperands = {";
  395. for (unsigned i = 0, e = int_op_size(); i != e; ++i) {
  396. OS << "[" << i << "] = " << IntOperands[i] << " ";
  397. }
  398. OS << "}";
  399. }
  400. };
  401. class int_op_inserter {
  402. private:
  403. using Container = AggregateValueExpression;
  404. Container *AVE;
  405. public:
  406. using iterator_category = std::output_iterator_tag;
  407. using value_type = void;
  408. using difference_type = void;
  409. using pointer = void;
  410. using reference = void;
  411. explicit int_op_inserter(AggregateValueExpression &E) : AVE(&E) {}
  412. explicit int_op_inserter(AggregateValueExpression *E) : AVE(E) {}
  413. int_op_inserter &operator=(unsigned int val) {
  414. AVE->int_op_push_back(val);
  415. return *this;
  416. }
  417. int_op_inserter &operator*() { return *this; }
  418. int_op_inserter &operator++() { return *this; }
  419. int_op_inserter &operator++(int) { return *this; }
  420. };
  421. class PHIExpression final : public BasicExpression {
  422. private:
  423. BasicBlock *BB;
  424. public:
  425. PHIExpression(unsigned NumOperands, BasicBlock *B)
  426. : BasicExpression(NumOperands, ET_Phi), BB(B) {}
  427. PHIExpression() = delete;
  428. PHIExpression(const PHIExpression &) = delete;
  429. PHIExpression &operator=(const PHIExpression &) = delete;
  430. ~PHIExpression() override;
  431. static bool classof(const Expression *EB) {
  432. return EB->getExpressionType() == ET_Phi;
  433. }
  434. bool equals(const Expression &Other) const override {
  435. if (!this->BasicExpression::equals(Other))
  436. return false;
  437. const PHIExpression &OE = cast<PHIExpression>(Other);
  438. return BB == OE.BB;
  439. }
  440. hash_code getHashValue() const override {
  441. return hash_combine(this->BasicExpression::getHashValue(), BB);
  442. }
  443. // Debugging support
  444. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  445. if (PrintEType)
  446. OS << "ExpressionTypePhi, ";
  447. this->BasicExpression::printInternal(OS, false);
  448. OS << "bb = " << BB;
  449. }
  450. };
  451. class DeadExpression final : public Expression {
  452. public:
  453. DeadExpression() : Expression(ET_Dead) {}
  454. DeadExpression(const DeadExpression &) = delete;
  455. DeadExpression &operator=(const DeadExpression &) = delete;
  456. static bool classof(const Expression *E) {
  457. return E->getExpressionType() == ET_Dead;
  458. }
  459. };
  460. class VariableExpression final : public Expression {
  461. private:
  462. Value *VariableValue;
  463. public:
  464. VariableExpression(Value *V) : Expression(ET_Variable), VariableValue(V) {}
  465. VariableExpression() = delete;
  466. VariableExpression(const VariableExpression &) = delete;
  467. VariableExpression &operator=(const VariableExpression &) = delete;
  468. static bool classof(const Expression *EB) {
  469. return EB->getExpressionType() == ET_Variable;
  470. }
  471. Value *getVariableValue() const { return VariableValue; }
  472. void setVariableValue(Value *V) { VariableValue = V; }
  473. bool equals(const Expression &Other) const override {
  474. const VariableExpression &OC = cast<VariableExpression>(Other);
  475. return VariableValue == OC.VariableValue;
  476. }
  477. hash_code getHashValue() const override {
  478. return hash_combine(this->Expression::getHashValue(),
  479. VariableValue->getType(), VariableValue);
  480. }
  481. // Debugging support
  482. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  483. if (PrintEType)
  484. OS << "ExpressionTypeVariable, ";
  485. this->Expression::printInternal(OS, false);
  486. OS << " variable = " << *VariableValue;
  487. }
  488. };
  489. class ConstantExpression final : public Expression {
  490. private:
  491. Constant *ConstantValue = nullptr;
  492. public:
  493. ConstantExpression() : Expression(ET_Constant) {}
  494. ConstantExpression(Constant *constantValue)
  495. : Expression(ET_Constant), ConstantValue(constantValue) {}
  496. ConstantExpression(const ConstantExpression &) = delete;
  497. ConstantExpression &operator=(const ConstantExpression &) = delete;
  498. static bool classof(const Expression *EB) {
  499. return EB->getExpressionType() == ET_Constant;
  500. }
  501. Constant *getConstantValue() const { return ConstantValue; }
  502. void setConstantValue(Constant *V) { ConstantValue = V; }
  503. bool equals(const Expression &Other) const override {
  504. const ConstantExpression &OC = cast<ConstantExpression>(Other);
  505. return ConstantValue == OC.ConstantValue;
  506. }
  507. hash_code getHashValue() const override {
  508. return hash_combine(this->Expression::getHashValue(),
  509. ConstantValue->getType(), ConstantValue);
  510. }
  511. // Debugging support
  512. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  513. if (PrintEType)
  514. OS << "ExpressionTypeConstant, ";
  515. this->Expression::printInternal(OS, false);
  516. OS << " constant = " << *ConstantValue;
  517. }
  518. };
  519. class UnknownExpression final : public Expression {
  520. private:
  521. Instruction *Inst;
  522. public:
  523. UnknownExpression(Instruction *I) : Expression(ET_Unknown), Inst(I) {}
  524. UnknownExpression() = delete;
  525. UnknownExpression(const UnknownExpression &) = delete;
  526. UnknownExpression &operator=(const UnknownExpression &) = delete;
  527. static bool classof(const Expression *EB) {
  528. return EB->getExpressionType() == ET_Unknown;
  529. }
  530. Instruction *getInstruction() const { return Inst; }
  531. void setInstruction(Instruction *I) { Inst = I; }
  532. bool equals(const Expression &Other) const override {
  533. const auto &OU = cast<UnknownExpression>(Other);
  534. return Inst == OU.Inst;
  535. }
  536. hash_code getHashValue() const override {
  537. return hash_combine(this->Expression::getHashValue(), Inst);
  538. }
  539. // Debugging support
  540. void printInternal(raw_ostream &OS, bool PrintEType) const override {
  541. if (PrintEType)
  542. OS << "ExpressionTypeUnknown, ";
  543. this->Expression::printInternal(OS, false);
  544. OS << " inst = " << *Inst;
  545. }
  546. };
  547. } // end namespace GVNExpression
  548. } // end namespace llvm
  549. #endif // LLVM_TRANSFORMS_SCALAR_GVNEXPRESSION_H