OverflowInstAnalysis.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- OverflowInstAnalysis.h - Utils to fold overflow insts ----*- 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 holds routines to help analyse overflow instructions
  15. // and fold them into constants or other overflow instructions
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_ANALYSIS_OVERFLOWINSTANALYSIS_H
  19. #define LLVM_ANALYSIS_OVERFLOWINSTANALYSIS_H
  20. #include "llvm/IR/InstrTypes.h"
  21. namespace llvm {
  22. class Value;
  23. class Use;
  24. /// Match one of the patterns up to the select/logic op:
  25. /// %Op0 = icmp ne i4 %X, 0
  26. /// %Agg = call { i4, i1 } @llvm.[us]mul.with.overflow.i4(i4 %X, i4 %Y)
  27. /// %Op1 = extractvalue { i4, i1 } %Agg, 1
  28. /// %ret = select i1 %Op0, i1 %Op1, i1 false / %ret = and i1 %Op0, %Op1
  29. ///
  30. /// %Op0 = icmp eq i4 %X, 0
  31. /// %Agg = call { i4, i1 } @llvm.[us]mul.with.overflow.i4(i4 %X, i4 %Y)
  32. /// %NotOp1 = extractvalue { i4, i1 } %Agg, 1
  33. /// %Op1 = xor i1 %NotOp1, true
  34. /// %ret = select i1 %Op0, i1 true, i1 %Op1 / %ret = or i1 %Op0, %Op1
  35. ///
  36. /// Callers are expected to align that with the operands of the select/logic.
  37. /// IsAnd is set to true if the Op0 and Op1 are used as the first pattern.
  38. /// If Op0 and Op1 match one of the patterns above, return true and fill Y's
  39. /// use.
  40. bool isCheckForZeroAndMulWithOverflow(Value *Op0, Value *Op1, bool IsAnd,
  41. Use *&Y);
  42. bool isCheckForZeroAndMulWithOverflow(Value *Op0, Value *Op1, bool IsAnd);
  43. } // end namespace llvm
  44. #endif
  45. #ifdef __GNUC__
  46. #pragma GCC diagnostic pop
  47. #endif