@@ -45,11 +45,10 @@ unsigned IDELinearConstantAnalysis::CurrGenConstantId = 0; // NOLINT
4545unsigned IDELinearConstantAnalysis::CurrLCAIDId = 0 ; // NOLINT
4646unsigned IDELinearConstantAnalysis::CurrBinaryId = 0 ; // NOLINT
4747
48- const IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::TOP =
49- std::numeric_limits<IDELinearConstantAnalysis::l_t >::min();
48+ const IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::TOP = Top{};
5049
5150const IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::BOTTOM =
52- std::numeric_limits<IDELinearConstantAnalysis:: l_t >::max() ;
51+ Bottom{} ;
5352
5453IDELinearConstantAnalysis::IDELinearConstantAnalysis (
5554 const ProjectIRDB *IRDB, const LLVMTypeHierarchy *TH,
@@ -470,8 +469,7 @@ IDELinearConstantAnalysis::LCAEdgeFunctionComposer::joinWith(
470469 return std::make_shared<AllBottom<l_t >>(BOTTOM);
471470}
472471
473- IDELinearConstantAnalysis::GenConstant::GenConstant (
474- IDELinearConstantAnalysis::l_t IntConst)
472+ IDELinearConstantAnalysis::GenConstant::GenConstant (int64_t IntConst)
475473 : GenConstantId(++CurrGenConstantId), IntConst(IntConst) {}
476474
477475IDELinearConstantAnalysis::l_t
@@ -502,7 +500,7 @@ IDELinearConstantAnalysis::GenConstant::composeWith(
502500 return std::make_shared<AllBottom<l_t >>(BOTTOM);
503501 }
504502
505- return std::make_shared<GenConstant>(Res);
503+ return std::make_shared<GenConstant>(std::get< int64_t >( Res) );
506504}
507505
508506std::shared_ptr<EdgeFunction<IDELinearConstantAnalysis::l_t >>
@@ -583,11 +581,6 @@ IDELinearConstantAnalysis::BinOp::computeTarget(l_t Source) {
583581 << " Curr Node : " << llvmIRToString (CurrNode));
584582 LOG_IF_ENABLE (BOOST_LOG_SEV (lg::get (), DEBUG) << ' ' );
585583
586- llvm::errs () << " BinOp::computeTarget(" << Source << " ) with Op: " << Op
587- << " , Lop: " << llvmIRToShortString (Lop)
588- << " , Rop: " << llvmIRToShortString (Rop)
589- << " , at CurrNode: " << llvmIRToString (CurrNode) << ' \n ' ;
590-
591584 if (LLVMZeroValue::isLLVMZeroValue (CurrNode) &&
592585 llvm::isa<llvm::ConstantInt>(Lop) && llvm::isa<llvm::ConstantInt>(Rop)) {
593586 const auto *Lic = llvm::cast<llvm::ConstantInt>(Lop);
@@ -667,30 +660,28 @@ void IDELinearConstantAnalysis::BinOp::print(std::ostream &OS,
667660}
668661
669662char IDELinearConstantAnalysis::opToChar (const unsigned Op) {
670- char OpAsChar;
671663 switch (Op) {
672664 case llvm::Instruction::Add:
673- OpAsChar = ' +' ;
674- break ;
665+ return ' +' ;
675666 case llvm::Instruction::Sub:
676- OpAsChar = ' -' ;
677- break ;
667+ return ' -' ;
678668 case llvm::Instruction::Mul:
679- OpAsChar = ' *' ;
680- break ;
669+ return ' *' ;
681670 case llvm::Instruction::UDiv:
682671 case llvm::Instruction::SDiv:
683- OpAsChar = ' /' ;
684- break ;
672+ return ' /' ;
685673 case llvm::Instruction::URem:
686674 case llvm::Instruction::SRem:
687- OpAsChar = ' %' ;
688- break ;
675+ return ' %' ;
676+ case llvm::Instruction::And:
677+ return ' &' ;
678+ case llvm::Instruction::Or:
679+ return ' |' ;
680+ case llvm::Instruction::Xor:
681+ return ' ^' ;
689682 default :
690- OpAsChar = ' ' ;
691- break ;
683+ return ' ' ;
692684 }
693- return OpAsChar;
694685}
695686
696687bool IDELinearConstantAnalysis::isEntryPoint (
@@ -699,66 +690,72 @@ bool IDELinearConstantAnalysis::isEntryPoint(
699690}
700691
701692IDELinearConstantAnalysis::l_t
702- IDELinearConstantAnalysis::executeBinOperation (const unsigned Op, l_t Lop,
703- l_t Rop) {
693+ IDELinearConstantAnalysis::executeBinOperation (const unsigned Op, l_t LVal,
694+ l_t RVal) {
695+
696+ auto *LopPtr = std::get_if<int64_t >(&LVal);
697+ auto *RopPtr = std::get_if<int64_t >(&RVal);
704698
705- if (Lop == BOTTOM || Rop == BOTTOM ) {
699+ if (!LopPtr || !RopPtr ) {
706700 return BOTTOM;
707701 }
708702
703+ auto Lop = *LopPtr;
704+ auto Rop = *RopPtr;
705+
709706 // default initialize with BOTTOM (all information)
710- l_t Res = BOTTOM ;
707+ int64_t Res;
711708 switch (Op) {
712709 case llvm::Instruction::Add:
713710 if (llvm::AddOverflow (Lop, Rop, Res)) {
714- Res = BOTTOM;
711+ return BOTTOM;
715712 }
716- break ;
713+ return Res ;
717714
718715 case llvm::Instruction::Sub:
719716 if (llvm::SubOverflow (Lop, Rop, Res)) {
720- Res = BOTTOM;
717+ return BOTTOM;
721718 }
722- break ;
719+ return Res ;
723720
724721 case llvm::Instruction::Mul:
725722 if (llvm::MulOverflow (Lop, Rop, Res)) {
726- Res = BOTTOM;
723+ return BOTTOM;
727724 }
728- break ;
725+ return Res ;
729726
730727 case llvm::Instruction::UDiv:
731728 case llvm::Instruction::SDiv:
732- // / MIN is TOP, so already handled
733-
734- // if (Lop == std::numeric_limits<IDELinearConstantAnalysis::l_t>::min() &&
735- // Rop == -1) { // Would produce and overflow, as the complement of min
736- // is
737- // // not representable in a signed type.
738- // return BOTTOM;
739- // }
740- if (Rop == 0 ) { // Division by zero is UB, so we return TOP
729+ if (Lop == std::numeric_limits<int64_t >::min () &&
730+ Rop == -1 ) { // Would produce and overflow, as the complement of min is
731+ // not representable in a signed type.
732+ return TOP;
733+ }
734+ if (Rop == 0 ) { // Division by zero is UB, so we return Bot
741735 return BOTTOM;
742736 }
743- Res = Lop / Rop;
744- break ;
737+ return Lop / Rop;
745738
746739 case llvm::Instruction::URem:
747740 case llvm::Instruction::SRem:
748- if (Rop == 0 ) { // Division by zero is UB, so we return TOP
741+ if (Rop == 0 ) { // Division by zero is UB, so we return Bot
749742 return BOTTOM;
750743 }
751- Res = Lop % Rop;
752- break ;
753-
744+ return Lop % Rop;
745+
746+ case llvm::Instruction::And:
747+ return Lop & Rop;
748+ case llvm::Instruction::Or:
749+ return Lop | Rop;
750+ case llvm::Instruction::Xor:
751+ return Lop ^ Rop;
754752 default :
755753 LOG_IF_ENABLE (BOOST_LOG_SEV (lg::get (), DEBUG)
756754 << " Operation not supported by "
757755 " IDELinearConstantAnalysis::"
758756 " executeBinOperation()" );
759- break ;
757+ return BOTTOM ;
760758 }
761- return Res;
762759}
763760
764761void IDELinearConstantAnalysis::printNode (std::ostream &OS, n_t Stmt) const {
@@ -776,13 +773,7 @@ void IDELinearConstantAnalysis::printFunction(std::ostream &OS,
776773}
777774
778775void IDELinearConstantAnalysis::printEdgeFact (std::ostream &OS, l_t L) const {
779- if (L == BOTTOM) {
780- OS << " Bottom" ;
781- } else if (L == TOP) {
782- OS << " Top" ;
783- } else {
784- OS << L;
785- }
776+ OS << L;
786777}
787778
788779void IDELinearConstantAnalysis::emitTextReport (
0 commit comments