diff options
Diffstat (limited to 'llvm_mode')
-rw-r--r-- | llvm_mode/Makefile | 8 | ||||
-rw-r--r-- | llvm_mode/split-compares-pass.so.cc | 35 |
2 files changed, 23 insertions, 20 deletions
diff --git a/llvm_mode/Makefile b/llvm_mode/Makefile index 7f2cc870..55bfab59 100644 --- a/llvm_mode/Makefile +++ b/llvm_mode/Makefile @@ -35,10 +35,10 @@ else LLVM_CONFIG ?= llvm-config endif -LLVMVER = $(shell $(LLVM_CONFIG) --version) -LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version | egrep -q '^[12]|^3\.0|^1[0-9]' && echo 1 || echo 0 ) -LLVM_MAJOR = $(shell $(LLVM_CONFIG) --version | sed 's/\..*//') -LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir) +LLVMVER = $(shell $(LLVM_CONFIG) --version 2>/dev/null) +LLVM_UNSUPPORTED = $(shell $(LLVM_CONFIG) --version 2>/dev/null | egrep -q '^[12]|^3\.0|^1[0-9]' && echo 1 || echo 0 ) +LLVM_MAJOR = $(shell $(LLVM_CONFIG) --version 2>/dev/null | sed 's/\..*//') +LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir 2>/dev/null) ifeq "$(LLVM_UNSUPPORTED)" "1" $(warn llvm_mode only supports versions 3.8.0 up to 9) diff --git a/llvm_mode/split-compares-pass.so.cc b/llvm_mode/split-compares-pass.so.cc index 0595c682..87e28f30 100644 --- a/llvm_mode/split-compares-pass.so.cc +++ b/llvm_mode/split-compares-pass.so.cc @@ -499,11 +499,10 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) { auto op0 = FcmpInst->getOperand(0); auto op1 = FcmpInst->getOperand(1); - unsigned op0_size, op1_size; - op0_size = op0->getType()->getPrimitiveSizeInBits(); - op1_size = op1->getType()->getPrimitiveSizeInBits(); + unsigned op_size; + op_size = op0->getType()->getPrimitiveSizeInBits(); - if (op0_size != op1_size) { continue; } + if (op_size != op1->getType()->getPrimitiveSizeInBits()) { continue; } const unsigned int sizeInBits = op0->getType()->getPrimitiveSizeInBits(); const unsigned int precision = @@ -511,34 +510,40 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) { ? 24 : sizeInBits == 64 ? 53 - : sizeInBits == 128 ? 113 : sizeInBits == 16 ? 11 : 65; + : sizeInBits == 128 ? 113 : sizeInBits == 16 ? 11 + /* sizeInBits == 80 */ : 65; const unsigned shiftR_exponent = precision - 1; const unsigned long long mask_fraction = - ((1 << (precision - 2))) | ((1 << (precision - 2)) - 1); + (1ULL << (shiftR_exponent - 1)) | ((1ULL << (shiftR_exponent - 1)) - 1); const unsigned long long mask_exponent = - (1 << (sizeInBits - precision)) - 1; + (1ULL << (sizeInBits - precision)) - 1; // round up sizes to the next power of two // this should help with integer compare splitting size_t exTySizeBytes = ((sizeInBits - precision + 7) >> 3); - size_t frTySizeBytes = ((precision - 1 + 7) >> 3); + size_t frTySizeBytes = ((precision - 1ULL + 7) >> 3); IntegerType *IntExponentTy = IntegerType::get(C, nextPowerOfTwo(exTySizeBytes) << 3); IntegerType *IntFractionTy = IntegerType::get(C, nextPowerOfTwo(frTySizeBytes) << 3); +// errs() << "Fractions: IntFractionTy size " << +// IntFractionTy->getPrimitiveSizeInBits() << ", op_size " << op_size << +// ", mask " << mask_fraction << +// ", precision " << precision << "\n"; + BasicBlock *end_bb = bb->splitBasicBlock(BasicBlock::iterator(FcmpInst)); /* create the integers from floats directly */ Instruction *b_op0, *b_op1; b_op0 = CastInst::Create(Instruction::BitCast, op0, - IntegerType::get(C, op0_size)); + IntegerType::get(C, op_size)); bb->getInstList().insert(bb->getTerminator()->getIterator(), b_op0); b_op1 = CastInst::Create(Instruction::BitCast, op1, - IntegerType::get(C, op1_size)); + IntegerType::get(C, op_size)); bb->getInstList().insert(bb->getTerminator()->getIterator(), b_op1); /* isolate signs of value of floating point type */ @@ -549,14 +554,14 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) { s_s0 = BinaryOperator::Create( Instruction::LShr, b_op0, - ConstantInt::get(b_op0->getType(), op0_size - 1)); + ConstantInt::get(b_op0->getType(), op_size - 1)); bb->getInstList().insert(bb->getTerminator()->getIterator(), s_s0); t_s0 = new TruncInst(s_s0, Int1Ty); bb->getInstList().insert(bb->getTerminator()->getIterator(), t_s0); s_s1 = BinaryOperator::Create( Instruction::LShr, b_op1, - ConstantInt::get(b_op1->getType(), op1_size - 1)); + ConstantInt::get(b_op1->getType(), op_size - 1)); bb->getInstList().insert(bb->getTerminator()->getIterator(), s_s1); t_s1 = new TruncInst(s_s1, Int1Ty); bb->getInstList().insert(bb->getTerminator()->getIterator(), t_s1); @@ -675,10 +680,8 @@ size_t SplitComparesTransform::splitFPCompares(Module &M) { /* isolate the mantissa aka fraction */ Instruction *t_f0, *t_f1; - bool needTrunc = IntFractionTy->getPrimitiveSizeInBits() < op0_size; - // errs() << "Fractions: IntFractionTy size " << - // IntFractionTy->getPrimitiveSizeInBits() << ", op0_size " << op0_size << ", - // needTrunc " << needTrunc << "\n"; + bool needTrunc = IntFractionTy->getPrimitiveSizeInBits() < op_size; + if (precision - 1 < frTySizeBytes * 8) { Instruction *m_f0, *m_f1; |