mirror of
https://github.com/AFLplusplus/AFLplusplus.git
synced 2025-06-11 09:41:35 +00:00
Merge pull request #1621 from devnexen/llvm_16_upd
LLVM plugin 16+ support proposal.
This commit is contained in:
commit
16f71bfa24
@ -48,6 +48,7 @@ LLVM_MINOR = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/.*\.//' | sed
|
||||
LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^[0-2]\.|^3.[0-7]\.' && echo 1 || echo 0 )
|
||||
LLVM_TOO_NEW = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[5-9]' && echo 1 || echo 0 )
|
||||
LLVM_NEW_API = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[0-9]' && echo 1 || echo 0 )
|
||||
LLVM_NEWER_API = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[6-9]' && echo 1 || echo 0 )
|
||||
LLVM_10_OK = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[1-9]|^10\.[1-9]|^10\.0.[1-9]' && echo 1 || echo 0 )
|
||||
LLVM_HAVE_LTO = $(shell $(LLVM_CONFIG) --version 2>/dev/null | grep -E -q '^1[1-9]' && echo 1 || echo 0 )
|
||||
LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir 2>/dev/null)
|
||||
@ -81,6 +82,11 @@ ifeq "$(LLVM_NEW_API)" "1"
|
||||
LLVM_TOO_OLD=0
|
||||
endif
|
||||
|
||||
ifeq "$(LLVM_NEWER_API)" "1"
|
||||
$(info [+] llvm_mode detected llvm 16+, enabling c++17)
|
||||
LLVM_STDCXX = c++17
|
||||
endif
|
||||
|
||||
ifeq "$(LLVM_TOO_OLD)" "1"
|
||||
$(info [!] llvm_mode detected an old version of llvm, upgrade to at least 9 or preferable 11!)
|
||||
$(shell sleep 1)
|
||||
|
@ -728,7 +728,11 @@ GlobalVariable *ModuleSanitizerCoverageAFL::CreateFunctionLocalArrayInSection(
|
||||
Array->setSection(getSectionName(Section));
|
||||
#if (LLVM_VERSION_MAJOR >= 11) || \
|
||||
(LLVM_VERSION_MAJOR == 10 && LLVM_VERSION_MINOR >= 1)
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
Array->setAlignment(Align(DL->getTypeStoreSize(Ty).getFixedValue()));
|
||||
#else
|
||||
Array->setAlignment(Align(DL->getTypeStoreSize(Ty).getFixedSize()));
|
||||
#endif
|
||||
#else
|
||||
Array->setAlignment(Align(4)); // cheating
|
||||
#endif
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <cmath>
|
||||
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
@ -35,6 +36,12 @@ typedef long double max_align_t;
|
||||
#if LLVM_VERSION_MAJOR >= 11
|
||||
#define MNAME M.getSourceFileName()
|
||||
#define FMNAME F.getParent()->getSourceFileName()
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
// None becomes deprecated
|
||||
// the standard std::nullopt_t is recommended instead
|
||||
// from C++17 and onwards.
|
||||
constexpr std::nullopt_t None = std::nullopt;
|
||||
#endif
|
||||
#else
|
||||
#define MNAME std::string("")
|
||||
#define FMNAME std::string("")
|
||||
|
@ -708,7 +708,11 @@ bool CompareTransform::transformCmps(Module &M, const bool processStrcmp,
|
||||
/* since the call is the first instruction of the bb it is safe to
|
||||
* replace it with a phi instruction */
|
||||
BasicBlock::iterator ii(callInst);
|
||||
#if LLVM_MAJOR >= 16
|
||||
ReplaceInstWithInst(callInst->getParent(), ii, PN);
|
||||
#else
|
||||
ReplaceInstWithInst(callInst->getParent()->getInstList(), ii, PN);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
@ -322,8 +322,12 @@ bool SplitComparesTransform::simplifyFPCompares(Module &M) {
|
||||
* block bb it is now at the position where the old FcmpInst was */
|
||||
Instruction *fcmp_np;
|
||||
fcmp_np = CmpInst::Create(Instruction::FCmp, new_pred, op0, op1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
fcmp_np->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
#else
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
fcmp_np);
|
||||
#endif
|
||||
|
||||
/* create a new basic block which holds the new EQ fcmp */
|
||||
Instruction *fcmp_eq;
|
||||
@ -331,7 +335,11 @@ bool SplitComparesTransform::simplifyFPCompares(Module &M) {
|
||||
BasicBlock *middle_bb =
|
||||
BasicBlock::Create(C, "injected", end_bb->getParent(), end_bb);
|
||||
fcmp_eq = CmpInst::Create(Instruction::FCmp, CmpInst::FCMP_OEQ, op0, op1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
fcmp_eq->insertInto(middle_bb, middle_bb->end());
|
||||
#else
|
||||
middle_bb->getInstList().push_back(fcmp_eq);
|
||||
#endif
|
||||
/* add an unconditional branch to the end of middle_bb with destination
|
||||
* end_bb */
|
||||
BranchInst::Create(end_bb, middle_bb);
|
||||
@ -352,7 +360,11 @@ bool SplitComparesTransform::simplifyFPCompares(Module &M) {
|
||||
PN->addIncoming(ConstantInt::get(Int1Ty, 1), bb);
|
||||
/* replace the old FcmpInst with our new and shiny PHI inst */
|
||||
BasicBlock::iterator ii(FcmpInst);
|
||||
#if LLVM_MAJOR >= 16
|
||||
ReplaceInstWithInst(FcmpInst->getParent(), ii, PN);
|
||||
#else
|
||||
ReplaceInstWithInst(FcmpInst->getParent()->getInstList(), ii, PN);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -409,7 +421,11 @@ bool SplitComparesTransform::simplifyOrEqualsCompare(CmpInst *IcmpInst,
|
||||
/* create the ICMP instruction with new_pred and add it to the old basic
|
||||
* block bb it is now at the position where the old IcmpInst was */
|
||||
CmpInst *icmp_np = CmpInst::Create(Instruction::ICmp, new_pred, op0, op1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_np->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
#else
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), icmp_np);
|
||||
#endif
|
||||
|
||||
/* create a new basic block which holds the new EQ icmp */
|
||||
CmpInst *icmp_eq;
|
||||
@ -417,7 +433,11 @@ bool SplitComparesTransform::simplifyOrEqualsCompare(CmpInst *IcmpInst,
|
||||
BasicBlock *middle_bb =
|
||||
BasicBlock::Create(C, "injected", end_bb->getParent(), end_bb);
|
||||
icmp_eq = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, op0, op1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_eq->insertInto(middle_bb, middle_bb->end());
|
||||
#else
|
||||
middle_bb->getInstList().push_back(icmp_eq);
|
||||
#endif
|
||||
/* add an unconditional branch to the end of middle_bb with destination
|
||||
* end_bb */
|
||||
BranchInst::Create(end_bb, middle_bb);
|
||||
@ -438,7 +458,11 @@ bool SplitComparesTransform::simplifyOrEqualsCompare(CmpInst *IcmpInst,
|
||||
PN->addIncoming(ConstantInt::get(Int1Ty, 1), bb);
|
||||
/* replace the old IcmpInst with our new and shiny PHI inst */
|
||||
BasicBlock::iterator ii(IcmpInst);
|
||||
#if LLVM_MAJOR >= 16
|
||||
ReplaceInstWithInst(IcmpInst->getParent(), ii, PN);
|
||||
#else
|
||||
ReplaceInstWithInst(IcmpInst->getParent()->getInstList(), ii, PN);
|
||||
#endif
|
||||
|
||||
worklist.push_back(icmp_np);
|
||||
worklist.push_back(icmp_eq);
|
||||
@ -518,7 +542,11 @@ bool SplitComparesTransform::simplifySignedCompare(CmpInst *IcmpInst, Module &M,
|
||||
|
||||
}
|
||||
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_inv_sig_cmp->insertInto(sign_bb, sign_bb->end());
|
||||
#else
|
||||
sign_bb->getInstList().push_back(icmp_inv_sig_cmp);
|
||||
#endif
|
||||
BranchInst::Create(end_bb, sign_bb);
|
||||
|
||||
/* create a new bb which is executed if signedness is equal */
|
||||
@ -528,7 +556,11 @@ bool SplitComparesTransform::simplifySignedCompare(CmpInst *IcmpInst, Module &M,
|
||||
/* we can do a normal unsigned compare now */
|
||||
icmp_usign_cmp = CmpInst::Create(Instruction::ICmp, new_pred, op0, op1);
|
||||
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_usign_cmp->insertInto(middle_bb, middle_bb->end());
|
||||
#else
|
||||
middle_bb->getInstList().push_back(icmp_usign_cmp);
|
||||
#endif
|
||||
BranchInst::Create(end_bb, middle_bb);
|
||||
|
||||
auto term = bb->getTerminator();
|
||||
@ -543,7 +575,11 @@ bool SplitComparesTransform::simplifySignedCompare(CmpInst *IcmpInst, Module &M,
|
||||
PN->addIncoming(icmp_inv_sig_cmp, sign_bb);
|
||||
|
||||
BasicBlock::iterator ii(IcmpInst);
|
||||
#if LLVM_MAJOR >= 16
|
||||
ReplaceInstWithInst(IcmpInst->getParent(), ii, PN);
|
||||
#else
|
||||
ReplaceInstWithInst(IcmpInst->getParent()->getInstList(), ii, PN);
|
||||
#endif
|
||||
|
||||
// save for later
|
||||
worklist.push_back(icmp_usign_cmp);
|
||||
@ -717,7 +753,11 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
|
||||
|
||||
}
|
||||
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_inv_cmp->insertInto(inv_cmp_bb, inv_cmp_bb->end());
|
||||
#else
|
||||
inv_cmp_bb->getInstList().push_back(icmp_inv_cmp);
|
||||
#endif
|
||||
worklist.push_back(icmp_inv_cmp);
|
||||
|
||||
auto term = bb->getTerminator();
|
||||
@ -728,12 +768,18 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
|
||||
BasicBlock *cmp_low_bb =
|
||||
BasicBlock::Create(C, "" /*"injected"*/, end_bb->getParent(), end_bb);
|
||||
op0_low = new TruncInst(op0, NewIntType);
|
||||
cmp_low_bb->getInstList().push_back(op0_low);
|
||||
op1_low = new TruncInst(op1, NewIntType);
|
||||
cmp_low_bb->getInstList().push_back(op1_low);
|
||||
|
||||
icmp_low = CmpInst::Create(Instruction::ICmp, pred, op0_low, op1_low);
|
||||
|
||||
#if LLVM_MAJOR >= 16
|
||||
op0_low->insertInto(cmp_low_bb, cmp_low_bb->end());
|
||||
op1_low->insertInto(cmp_low_bb, cmp_low_bb->end());
|
||||
icmp_low->insertInto(cmp_low_bb, cmp_low_bb->end());
|
||||
#else
|
||||
cmp_low_bb->getInstList().push_back(op0_low);
|
||||
cmp_low_bb->getInstList().push_back(op1_low);
|
||||
cmp_low_bb->getInstList().push_back(icmp_low);
|
||||
#endif
|
||||
BranchInst::Create(end_bb, cmp_low_bb);
|
||||
|
||||
BranchInst::Create(end_bb, cmp_low_bb, icmp_inv_cmp, inv_cmp_bb);
|
||||
@ -754,7 +800,11 @@ bool SplitComparesTransform::splitCompare(CmpInst *cmp_inst, Module &M,
|
||||
}
|
||||
|
||||
BasicBlock::iterator ii(cmp_inst);
|
||||
#if LLVM_MAJOR >= 16
|
||||
ReplaceInstWithInst(cmp_inst->getParent(), ii, PN);
|
||||
#else
|
||||
ReplaceInstWithInst(cmp_inst->getParent()->getInstList(), ii, PN);
|
||||
#endif
|
||||
|
||||
// We split the comparison into low and high. If this isn't our target
|
||||
// bitwidth we recursively split the low and high parts again until we have
|
||||
@ -999,13 +1049,21 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
Instruction *bpre_op0, *bpre_op1;
|
||||
bpre_op0 = CastInst::Create(Instruction::BitCast, op0,
|
||||
IntegerType::get(C, op_size));
|
||||
#if LLVM_MAJOR >= 16
|
||||
bpre_op0->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
#else
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
bpre_op0);
|
||||
#endif
|
||||
|
||||
bpre_op1 = CastInst::Create(Instruction::BitCast, op1,
|
||||
IntegerType::get(C, op_size));
|
||||
#if LLVM_MAJOR >= 16
|
||||
bpre_op1->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
#else
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
bpre_op1);
|
||||
#endif
|
||||
|
||||
/* Check if any operand is NaN.
|
||||
* If so, all comparisons except unequal (which yields true) yield false */
|
||||
@ -1025,34 +1083,42 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
Instruction *nan_op0, *nan_op1;
|
||||
nan_op0 = BinaryOperator::Create(Instruction::Shl, bpre_op0,
|
||||
ConstantInt::get(bpre_op0->getType(), 1));
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
nan_op0);
|
||||
|
||||
/* compare to NaN interval */
|
||||
Instruction *is_op0_nan =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0,
|
||||
ConstantInt::get(intType, NaN_lowend));
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
is_op0_nan);
|
||||
|
||||
/* Check op1 for NaN */
|
||||
/* Shift right 1 Bit, ignore sign bit */
|
||||
nan_op1 = BinaryOperator::Create(Instruction::Shl, bpre_op1,
|
||||
ConstantInt::get(bpre_op1->getType(), 1));
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
nan_op1);
|
||||
|
||||
/* compare to NaN interval */
|
||||
Instruction *is_op0_nan =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op0,
|
||||
ConstantInt::get(intType, NaN_lowend));
|
||||
/* compare to NaN interval */
|
||||
Instruction *is_op1_nan =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, nan_op1,
|
||||
ConstantInt::get(intType, NaN_lowend));
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
is_op1_nan);
|
||||
|
||||
/* combine checks */
|
||||
Instruction *is_nan =
|
||||
BinaryOperator::Create(Instruction::Or, is_op0_nan, is_op1_nan);
|
||||
#if LLVM_MAJOR >= 16
|
||||
nan_op0->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
is_op0_nan->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
nan_op1->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
is_op1_nan->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
is_nan->insertInto(bb, BasicBlock::iterator(bb->getTerminator()));
|
||||
#else
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
nan_op0);
|
||||
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
is_op0_nan);
|
||||
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
nan_op1);
|
||||
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()),
|
||||
is_op1_nan);
|
||||
|
||||
bb->getInstList().insert(BasicBlock::iterator(bb->getTerminator()), is_nan);
|
||||
#endif
|
||||
|
||||
/* the result of the comparison, when at least one op is NaN
|
||||
is true only for the "NOT EQUAL" predicates. */
|
||||
@ -1079,23 +1145,30 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
|
||||
isMzero_op0 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op0,
|
||||
ConstantInt::get(intType, MinusZero));
|
||||
isMzero_op1 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1,
|
||||
ConstantInt::get(intType, MinusZero));
|
||||
b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero),
|
||||
bpre_op0);
|
||||
b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero),
|
||||
bpre_op1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
isMzero_op0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
isMzero_op1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
b_op0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
b_op1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
#else
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op0);
|
||||
|
||||
isMzero_op1 = CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, bpre_op1,
|
||||
ConstantInt::get(intType, MinusZero));
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), isMzero_op1);
|
||||
|
||||
b_op0 = SelectInst::Create(isMzero_op0, ConstantInt::get(intType, PlusZero),
|
||||
bpre_op0);
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), b_op0);
|
||||
|
||||
b_op1 = SelectInst::Create(isMzero_op1, ConstantInt::get(intType, PlusZero),
|
||||
bpre_op1);
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), b_op1);
|
||||
#endif
|
||||
|
||||
/* isolate signs of value of floating point type */
|
||||
|
||||
@ -1106,26 +1179,34 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
s_s0 =
|
||||
BinaryOperator::Create(Instruction::LShr, b_op0,
|
||||
ConstantInt::get(b_op0->getType(), op_size - 1));
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
|
||||
t_s0 = new TruncInst(s_s0, Int1Ty);
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);
|
||||
|
||||
s_s1 =
|
||||
BinaryOperator::Create(Instruction::LShr, b_op1,
|
||||
ConstantInt::get(b_op1->getType(), op_size - 1));
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
|
||||
t_s0 = new TruncInst(s_s0, Int1Ty);
|
||||
t_s1 = new TruncInst(s_s1, Int1Ty);
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);
|
||||
|
||||
/* compare of the sign bits */
|
||||
icmp_sign_bit =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_s0, t_s1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
s_s0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
t_s0->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
s_s1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
t_s1->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
icmp_sign_bit->insertInto(nonan_bb, BasicBlock::iterator(nonan_bb->getTerminator()));
|
||||
#else
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), s_s0);
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), t_s0);
|
||||
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), s_s1);
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), t_s1);
|
||||
|
||||
nonan_bb->getInstList().insert(
|
||||
BasicBlock::iterator(nonan_bb->getTerminator()), icmp_sign_bit);
|
||||
#endif
|
||||
|
||||
/* create a new basic block which is executed if the signedness bits are
|
||||
* equal */
|
||||
@ -1157,17 +1238,28 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
s_e1 = BinaryOperator::Create(
|
||||
Instruction::LShr, b_op1,
|
||||
ConstantInt::get(b_op1->getType(), shiftR_exponent));
|
||||
#if LLVM_MAJOR >= 16
|
||||
s_e0->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
s_e1->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
#else
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()), s_e0);
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()), s_e1);
|
||||
#endif
|
||||
|
||||
t_e0 = new TruncInst(s_e0, IntExponentTy);
|
||||
t_e1 = new TruncInst(s_e1, IntExponentTy);
|
||||
#if LLVM_MAJOR >= 16
|
||||
t_e0->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
t_e1->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
#else
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()), t_e0);
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()), t_e1);
|
||||
#endif
|
||||
|
||||
|
||||
if (sizeInBits - precision < exTySizeBytes * 8) {
|
||||
|
||||
@ -1177,10 +1269,15 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
m_e1 = BinaryOperator::Create(
|
||||
Instruction::And, t_e1,
|
||||
ConstantInt::get(t_e1->getType(), mask_exponent));
|
||||
#if LLVM_MAJOR >= 16
|
||||
m_e0->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
m_e1->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
#else
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()), m_e0);
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()), m_e1);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
@ -1214,9 +1311,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
Instruction *icmp_exponent;
|
||||
icmp_exponents_equal =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, m_e0, m_e1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_exponents_equal->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
#else
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()),
|
||||
icmp_exponents_equal);
|
||||
#endif
|
||||
|
||||
// shortcut for unequal exponents
|
||||
signequal2_bb = signequal_bb->splitBasicBlock(
|
||||
@ -1230,9 +1331,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
|
||||
icmp_exponent =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_UGT, m_e0, m_e1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_exponent->insertInto(signequal2_bb, BasicBlock::iterator(signequal2_bb->getTerminator()));
|
||||
#else
|
||||
signequal2_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
||||
icmp_exponent);
|
||||
#endif
|
||||
icmp_exponent_result =
|
||||
BinaryOperator::Create(Instruction::Xor, icmp_exponent, t_s0);
|
||||
break;
|
||||
@ -1240,9 +1345,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
case CmpInst::FCMP_ULT:
|
||||
icmp_exponents_equal =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, m_e0, m_e1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_exponents_equal->insertInto(signequal_bb, BasicBlock::iterator(signequal_bb->getTerminator()));
|
||||
#else
|
||||
signequal_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal_bb->getTerminator()),
|
||||
icmp_exponents_equal);
|
||||
#endif
|
||||
|
||||
// shortcut for unequal exponents
|
||||
signequal2_bb = signequal_bb->splitBasicBlock(
|
||||
@ -1256,9 +1365,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
|
||||
icmp_exponent =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_ULT, m_e0, m_e1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_exponent->insertInto(signequal2_bb, BasicBlock::iterator(signequal2_bb->getTerminator()));
|
||||
#else
|
||||
signequal2_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
||||
icmp_exponent);
|
||||
#endif
|
||||
icmp_exponent_result =
|
||||
BinaryOperator::Create(Instruction::Xor, icmp_exponent, t_s0);
|
||||
break;
|
||||
@ -1267,9 +1380,13 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
|
||||
}
|
||||
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_exponent_result->insertInto(signequal2_bb, BasicBlock::iterator(signequal2_bb->getTerminator()));
|
||||
#else
|
||||
signequal2_bb->getInstList().insert(
|
||||
BasicBlock::iterator(signequal2_bb->getTerminator()),
|
||||
icmp_exponent_result);
|
||||
#endif
|
||||
|
||||
{
|
||||
|
||||
@ -1319,19 +1436,29 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
m_f1 = BinaryOperator::Create(
|
||||
Instruction::And, b_op1,
|
||||
ConstantInt::get(b_op1->getType(), mask_fraction));
|
||||
#if LLVM_MAJOR >= 16
|
||||
m_f0->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
||||
m_f1->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
||||
#else
|
||||
middle_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle_bb->getTerminator()), m_f0);
|
||||
middle_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle_bb->getTerminator()), m_f1);
|
||||
#endif
|
||||
|
||||
if (needTrunc) {
|
||||
|
||||
t_f0 = new TruncInst(m_f0, IntFractionTy);
|
||||
t_f1 = new TruncInst(m_f1, IntFractionTy);
|
||||
#if LLVM_MAJOR >= 16
|
||||
t_f0->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
||||
t_f1->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
||||
#else
|
||||
middle_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle_bb->getTerminator()), t_f0);
|
||||
middle_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle_bb->getTerminator()), t_f1);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
@ -1346,10 +1473,15 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
|
||||
t_f0 = new TruncInst(b_op0, IntFractionTy);
|
||||
t_f1 = new TruncInst(b_op1, IntFractionTy);
|
||||
#if LLVM_MAJOR >= 16
|
||||
t_f0->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
||||
t_f1->insertInto(middle_bb, BasicBlock::iterator(middle_bb->getTerminator()));
|
||||
#else
|
||||
middle_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle_bb->getTerminator()), t_f0);
|
||||
middle_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle_bb->getTerminator()), t_f1);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
@ -1370,18 +1502,26 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
case CmpInst::FCMP_OEQ:
|
||||
icmp_fraction_result =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_EQ, t_f0, t_f1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_fraction_result->insertInto(middle2_bb, BasicBlock::iterator(middle2_bb->getTerminator()));
|
||||
#else
|
||||
middle2_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle2_bb->getTerminator()),
|
||||
icmp_fraction_result);
|
||||
#endif
|
||||
|
||||
break;
|
||||
case CmpInst::FCMP_UNE:
|
||||
case CmpInst::FCMP_ONE:
|
||||
icmp_fraction_result =
|
||||
CmpInst::Create(Instruction::ICmp, CmpInst::ICMP_NE, t_f0, t_f1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_fraction_result->insertInto(middle2_bb, BasicBlock::iterator(middle2_bb->getTerminator()));
|
||||
#else
|
||||
middle2_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle2_bb->getTerminator()),
|
||||
icmp_fraction_result);
|
||||
#endif
|
||||
|
||||
break;
|
||||
case CmpInst::FCMP_OGT:
|
||||
@ -1402,21 +1542,31 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
if (FcmpInst->getPredicate() == CmpInst::FCMP_OGT ||
|
||||
FcmpInst->getPredicate() == CmpInst::FCMP_UGT) {
|
||||
|
||||
negative_bb->getInstList().push_back(
|
||||
icmp_fraction_result = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1));
|
||||
positive_bb->getInstList().push_back(
|
||||
icmp_fraction_result2 = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1));
|
||||
icmp_fraction_result = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1);
|
||||
icmp_fraction_result2 = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_fraction_result->insertInto(negative_bb, negative_bb->end());
|
||||
icmp_fraction_result2->insertInto(positive_bb, negative_bb->end());
|
||||
#else
|
||||
negative_bb->getInstList().push_back(icmp_fraction_result);
|
||||
positive_bb->getInstList().push_back(icmp_fraction_result2);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
negative_bb->getInstList().push_back(
|
||||
icmp_fraction_result = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1));
|
||||
positive_bb->getInstList().push_back(
|
||||
icmp_fraction_result2 = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1));
|
||||
icmp_fraction_result = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_UGT, t_f0, t_f1);
|
||||
icmp_fraction_result2 = CmpInst::Create(
|
||||
Instruction::ICmp, CmpInst::ICMP_ULT, t_f0, t_f1);
|
||||
#if LLVM_MAJOR >= 16
|
||||
icmp_fraction_result->insertInto(negative_bb, negative_bb->end());
|
||||
icmp_fraction_result2->insertInto(positive_bb, negative_bb->end());
|
||||
#else
|
||||
negative_bb->getInstList().push_back(icmp_fraction_result);
|
||||
positive_bb->getInstList().push_back(icmp_fraction_result2);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
@ -1430,8 +1580,12 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
PN2 = PHINode::Create(Int1Ty, 2, "");
|
||||
PN2->addIncoming(icmp_fraction_result, negative_bb);
|
||||
PN2->addIncoming(icmp_fraction_result2, positive_bb);
|
||||
#if LLVM_MAJOR >= 16
|
||||
PN2->insertInto(middle2_bb, BasicBlock::iterator(middle2_bb->getTerminator()));
|
||||
#else
|
||||
middle2_bb->getInstList().insert(
|
||||
BasicBlock::iterator(middle2_bb->getTerminator()), PN2);
|
||||
#endif
|
||||
|
||||
} break;
|
||||
|
||||
@ -1494,7 +1648,11 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) {
|
||||
}
|
||||
|
||||
BasicBlock::iterator ii(FcmpInst);
|
||||
#if LLVM_MAJOR >= 16
|
||||
ReplaceInstWithInst(FcmpInst->getParent(), ii, PN);
|
||||
#else
|
||||
ReplaceInstWithInst(FcmpInst->getParent()->getInstList(), ii, PN);
|
||||
#endif
|
||||
++count;
|
||||
|
||||
}
|
||||
|
@ -225,12 +225,20 @@ BasicBlock *SplitSwitchesTransform::switchConvert(
|
||||
BasicBlock *NewNode = BasicBlock::Create(Val->getContext(), "NodeBlock", F);
|
||||
Shift = BinaryOperator::Create(Instruction::LShr, Val,
|
||||
ConstantInt::get(ValType, smallestIndex * 8));
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
Shift->insertInto(NewNode, NewNode->end());
|
||||
#else
|
||||
NewNode->getInstList().push_back(Shift);
|
||||
#endif
|
||||
|
||||
if (ValTypeBitWidth > 8) {
|
||||
|
||||
Trunc = new TruncInst(Shift, ByteType);
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
Trunc->insertInto(NewNode, NewNode->end());
|
||||
#else
|
||||
NewNode->getInstList().push_back(Trunc);
|
||||
#endif
|
||||
|
||||
} else {
|
||||
|
||||
@ -253,7 +261,11 @@ BasicBlock *SplitSwitchesTransform::switchConvert(
|
||||
ICmpInst *Comp =
|
||||
new ICmpInst(ICmpInst::ICMP_EQ, Trunc, ConstantInt::get(ByteType, byte),
|
||||
"byteMatch");
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
Comp->insertInto(NewNode, NewNode->end());
|
||||
#else
|
||||
NewNode->getInstList().push_back(Comp);
|
||||
#endif
|
||||
|
||||
bytesChecked[smallestIndex] = true;
|
||||
bool allBytesAreChecked = true;
|
||||
@ -355,7 +367,11 @@ BasicBlock *SplitSwitchesTransform::switchConvert(
|
||||
ICmpInst *Comp =
|
||||
new ICmpInst(ICmpInst::ICMP_ULT, Trunc,
|
||||
ConstantInt::get(ByteType, pivot), "byteMatch");
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
Comp->insertInto(NewNode, NewNode->end());
|
||||
#else
|
||||
NewNode->getInstList().push_back(Comp);
|
||||
#endif
|
||||
BranchInst::Create(LBB, RBB, Comp, NewNode);
|
||||
|
||||
}
|
||||
@ -452,7 +468,11 @@ bool SplitSwitchesTransform::splitSwitches(Module &M) {
|
||||
BranchInst::Create(SwitchBlock, OrigBlock);
|
||||
|
||||
/* We are now done with the switch instruction, delete it. */
|
||||
#if LLVM_VERSION_MAJOR >= 16
|
||||
SI->eraseFromParent();
|
||||
#else
|
||||
CurBlock->getInstList().erase(SI);
|
||||
#endif
|
||||
|
||||
/* we have to update the phi nodes! */
|
||||
for (BasicBlock::iterator I = Default->begin(); I != Default->end(); ++I) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user