Mercurial > hg > CbC > CbC_llvm
comparison lib/Analysis/CmpInstAnalysis.cpp @ 147:c2174574ed3a
LLVM 10
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 14 Aug 2019 16:55:33 +0900 |
parents | 803732b1fca8 |
children |
comparison
equal
deleted
inserted
replaced
134:3a76565eade5 | 147:c2174574ed3a |
---|---|
1 //===- CmpInstAnalysis.cpp - Utils to help fold compares ---------------===// | 1 //===- CmpInstAnalysis.cpp - Utils to help fold compares ---------------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 // | 4 // See https://llvm.org/LICENSE.txt for license information. |
5 // This file is distributed under the University of Illinois Open Source | 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 // License. See LICENSE.TXT for details. | |
7 // | 6 // |
8 //===----------------------------------------------------------------------===// | 7 //===----------------------------------------------------------------------===// |
9 // | 8 // |
10 // This file holds routines to help analyse compare instructions | 9 // This file holds routines to help analyse compare instructions |
11 // and fold them into constants or other compare instructions | 10 // and fold them into constants or other compare instructions |
38 default: | 37 default: |
39 llvm_unreachable("Invalid ICmp predicate!"); | 38 llvm_unreachable("Invalid ICmp predicate!"); |
40 } | 39 } |
41 } | 40 } |
42 | 41 |
43 Value *llvm::getICmpValue(bool Sign, unsigned Code, Value *LHS, Value *RHS, | 42 Constant *llvm::getPredForICmpCode(unsigned Code, bool Sign, Type *OpTy, |
44 CmpInst::Predicate &NewICmpPred) { | 43 CmpInst::Predicate &Pred) { |
45 switch (Code) { | 44 switch (Code) { |
46 default: llvm_unreachable("Illegal ICmp code!"); | 45 default: llvm_unreachable("Illegal ICmp code!"); |
47 case 0: // False. | 46 case 0: // False. |
48 return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 0); | 47 return ConstantInt::get(CmpInst::makeCmpResultType(OpTy), 0); |
49 case 1: NewICmpPred = Sign ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; | 48 case 1: Pred = Sign ? ICmpInst::ICMP_SGT : ICmpInst::ICMP_UGT; break; |
50 case 2: NewICmpPred = ICmpInst::ICMP_EQ; break; | 49 case 2: Pred = ICmpInst::ICMP_EQ; break; |
51 case 3: NewICmpPred = Sign ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; | 50 case 3: Pred = Sign ? ICmpInst::ICMP_SGE : ICmpInst::ICMP_UGE; break; |
52 case 4: NewICmpPred = Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; | 51 case 4: Pred = Sign ? ICmpInst::ICMP_SLT : ICmpInst::ICMP_ULT; break; |
53 case 5: NewICmpPred = ICmpInst::ICMP_NE; break; | 52 case 5: Pred = ICmpInst::ICMP_NE; break; |
54 case 6: NewICmpPred = Sign ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; | 53 case 6: Pred = Sign ? ICmpInst::ICMP_SLE : ICmpInst::ICMP_ULE; break; |
55 case 7: // True. | 54 case 7: // True. |
56 return ConstantInt::get(CmpInst::makeCmpResultType(LHS->getType()), 1); | 55 return ConstantInt::get(CmpInst::makeCmpResultType(OpTy), 1); |
57 } | 56 } |
58 return nullptr; | 57 return nullptr; |
59 } | 58 } |
60 | 59 |
61 bool llvm::PredicatesFoldable(ICmpInst::Predicate p1, ICmpInst::Predicate p2) { | 60 bool llvm::predicatesFoldable(ICmpInst::Predicate P1, ICmpInst::Predicate P2) { |
62 return (CmpInst::isSigned(p1) == CmpInst::isSigned(p2)) || | 61 return (CmpInst::isSigned(P1) == CmpInst::isSigned(P2)) || |
63 (CmpInst::isSigned(p1) && ICmpInst::isEquality(p2)) || | 62 (CmpInst::isSigned(P1) && ICmpInst::isEquality(P2)) || |
64 (CmpInst::isSigned(p2) && ICmpInst::isEquality(p1)); | 63 (CmpInst::isSigned(P2) && ICmpInst::isEquality(P1)); |
65 } | 64 } |
66 | 65 |
67 bool llvm::decomposeBitTestICmp(Value *LHS, Value *RHS, | 66 bool llvm::decomposeBitTestICmp(Value *LHS, Value *RHS, |
68 CmpInst::Predicate &Pred, | 67 CmpInst::Predicate &Pred, |
69 Value *&X, APInt &Mask, bool LookThruTrunc) { | 68 Value *&X, APInt &Mask, bool LookThruTrunc) { |