diff options
author | Zhigang Gong <zhigang.gong@intel.com> | 2015-02-27 11:35:01 +0800 |
---|---|---|
committer | Zhigang Gong <zhigang.gong@intel.com> | 2015-02-27 14:50:34 +0800 |
commit | 0c5077b91259e157f81232985ccc5f7884767d65 (patch) | |
tree | 57f9067bc9c4cc5525de0fdc594733621639c170 /backend | |
parent | 2240eb4210ef66bdddc1195845ed86a3a3cdb69b (diff) |
GBE: remove constant expression handling code in gen writer pass.
All the constant expressions should be expanded in prior to
gen writer pass.
Signed-off-by: Zhigang Gong <zhigang.gong@intel.com>
Reviewed-by: "Song, Ruiling" <ruiling.song@intel.com>
Diffstat (limited to 'backend')
-rw-r--r-- | backend/src/llvm/llvm_gen_backend.cpp | 214 |
1 files changed, 1 insertions, 213 deletions
diff --git a/backend/src/llvm/llvm_gen_backend.cpp b/backend/src/llvm/llvm_gen_backend.cpp index 87d85b97..7e8bb651 100644 --- a/backend/src/llvm/llvm_gen_backend.cpp +++ b/backend/src/llvm/llvm_gen_backend.cpp @@ -570,8 +570,6 @@ namespace gbe INLINE void newRegister(Value *value, Value *key = NULL, bool uniform = false); /*! get the register for a llvm::Constant */ ir::Register getConstantRegister(Constant *c, uint32_t index = 0); - /*! get constant pointer */ - ir::Register getConstantPointerRegister(ConstantExpr *ce, uint32_t index = 0); /*! Return a valid register from an operand (can use LOADI to make one) */ INLINE ir::Register getRegister(Value *value, uint32_t index = 0); /*! Create a new immediate from a constant */ @@ -1042,150 +1040,7 @@ namespace gbe ir::ImmediateIndex GenWriter::processConstantImmIndex(Constant *CPV, int32_t index) { if (dyn_cast<ConstantExpr>(CPV) == NULL) return processConstantImmIndexImpl(CPV, index); - - if (dyn_cast<ConstantExpr>(CPV)) { - ConstantExpr *ce = dyn_cast<ConstantExpr>(CPV); - - if (!isScalarType(ce->getType())) { - VectorType *vecType = cast<VectorType>(ce->getType()); - GBE_ASSERT(ce->getOpcode() == Instruction::BitCast); - GBE_ASSERT(isScalarType(vecType->getElementType())); - ir::Type elemType = getType(ctx, vecType->getElementType()); - - const ir::ImmediateIndex immIndex = processConstantImmIndex(ce->getOperand(0), -1); - const ir::Immediate imm = ctx.getImmediate(immIndex); - GBE_ASSERT(vecType->getNumElements() == imm.getElemNum() && - getTypeByteSize(unit, vecType->getElementType()) == imm.getTypeSize()); - return ctx.processImm(ir::IMM_BITCAST, immIndex, elemType); - } - ir::Type type = getType(ctx, ce->getType()); - switch (ce->getOpcode()) { - default: - ce->dump(); - GBE_ASSERT(0 && "unsupported ce opcode.\n"); - case Instruction::FPTrunc: - case Instruction::Trunc: - { - const ir::ImmediateIndex immIndex = processConstantImmIndex(ce->getOperand(0), -1); - return ctx.processImm(ir::IMM_TRUNC, immIndex, type); - } - case Instruction::BitCast: - { - const ir::ImmediateIndex immIndex = processConstantImmIndex(ce->getOperand(0), -1); - if (type == ir::TYPE_LARGE_INT) - return immIndex; - return ctx.processImm(ir::IMM_BITCAST, immIndex, type); - } - case Instruction::FPToUI: - case Instruction::FPToSI: - case Instruction::SIToFP: - case Instruction::UIToFP: - case Instruction::SExt: - case Instruction::ZExt: - case Instruction::FPExt: - { - const ir::ImmediateIndex immIndex = processConstantImmIndex(ce->getOperand(0), -1); - switch (ce->getOpcode()) { - default: - GBE_ASSERT(0); - case Instruction::FPToUI: return ctx.processImm(ir::IMM_FPTOUI, immIndex, type); - case Instruction::FPToSI: return ctx.processImm(ir::IMM_FPTOSI, immIndex, type); - case Instruction::SIToFP: return ctx.processImm(ir::IMM_SITOFP, immIndex, type); - case Instruction::UIToFP: return ctx.processImm(ir::IMM_UITOFP, immIndex, type); - case Instruction::SExt: return ctx.processImm(ir::IMM_SEXT, immIndex, type); - case Instruction::ZExt: return ctx.processImm(ir::IMM_ZEXT, immIndex, type); - case Instruction::FPExt: return ctx.processImm(ir::IMM_FPEXT, immIndex, type); - } - } - - case Instruction::ExtractElement: - case Instruction::FCmp: - case Instruction::ICmp: - case Instruction::FAdd: - case Instruction::Add: - case Instruction::Sub: - case Instruction::FSub: - case Instruction::Mul: - case Instruction::FMul: - case Instruction::SDiv: - case Instruction::UDiv: - case Instruction::FDiv: - case Instruction::SRem: - case Instruction::FRem: - case Instruction::Shl: - case Instruction::AShr: - case Instruction::LShr: - case Instruction::And: - case Instruction::Or: - case Instruction::Xor: { - const ir::ImmediateIndex lhs = processConstantImmIndex(ce->getOperand(0), -1); - const ir::ImmediateIndex rhs = processConstantImmIndex(ce->getOperand(1), -1); - switch (ce->getOpcode()) { - default: - //ce->dump(); - GBE_ASSERTM(0, "Unsupported constant expression.\n"); - - case Instruction::ExtractElement: - return ctx.processImm(ir::IMM_EXTRACT, lhs, rhs, type); - case Instruction::Add: - case Instruction::FAdd: - return ctx.processImm(ir::IMM_ADD, lhs, rhs, type); - case Instruction::FSub: - case Instruction::Sub: - return ctx.processImm(ir::IMM_SUB, lhs, rhs, type); - case Instruction::Mul: - case Instruction::FMul: - return ctx.processImm(ir::IMM_MUL, lhs, rhs, type); - case Instruction::SDiv: - case Instruction::FDiv: - return ctx.processImm(ir::IMM_DIV, lhs, rhs, type); - case Instruction::SRem: - case Instruction::FRem: - return ctx.processImm(ir::IMM_REM, lhs, rhs, type); - case Instruction::Shl: - return ctx.processImm(ir::IMM_SHL, lhs, rhs, type); - case Instruction::AShr: - return ctx.processImm(ir::IMM_ASHR, lhs, rhs, type); - case Instruction::LShr: - return ctx.processImm(ir::IMM_LSHR, lhs, rhs, type); - case Instruction::And: - return ctx.processImm(ir::IMM_AND, lhs, rhs, type); - case Instruction::Or: - return ctx.processImm(ir::IMM_OR, lhs, rhs, type); - case Instruction::Xor: - return ctx.processImm(ir::IMM_XOR, lhs, rhs, type); - case Instruction::FCmp: - case Instruction::ICmp: - switch (ce->getPredicate()) { - default: - NOT_SUPPORTED; - case ICmpInst::ICMP_EQ: - case ICmpInst::FCMP_OEQ: return ctx.processImm(ir::IMM_OEQ, lhs, rhs, type); - case ICmpInst::ICMP_NE: - case ICmpInst::FCMP_ONE: return ctx.processImm(ir::IMM_ONE, lhs, rhs, type); - case ICmpInst::ICMP_ULE: - case ICmpInst::ICMP_SLE: - case ICmpInst::FCMP_OLE: return ctx.processImm(ir::IMM_OLE, lhs, rhs, type); - case ICmpInst::ICMP_UGE: - case ICmpInst::ICMP_SGE: - case ICmpInst::FCMP_OGE: return ctx.processImm(ir::IMM_OGE, lhs, rhs, type); - case ICmpInst::ICMP_ULT: - case ICmpInst::ICMP_SLT: - case ICmpInst::FCMP_OLT: return ctx.processImm(ir::IMM_OLT, lhs, rhs, type); - case ICmpInst::ICMP_UGT: - case ICmpInst::ICMP_SGT: - case ICmpInst::FCMP_OGT: return ctx.processImm(ir::IMM_OGT, lhs, rhs, type); - case ICmpInst::FCMP_ORD: return ctx.processImm(ir::IMM_ORD, lhs, rhs, type); - case ICmpInst::FCMP_TRUE: - Value *cv = ConstantInt::get(ce->getType(), 1); - return ctx.newImmediate(cv); - } - break; - } - break; - } - } - } + CPV->dump(); GBE_ASSERT(0 && "unsupported constant.\n"); return ctx.newImmediate((uint32_t)0); } @@ -1229,64 +1084,6 @@ namespace gbe }; } - ir::Register GenWriter::getConstantPointerRegister(ConstantExpr *expr, uint32_t elemID) { - Value* val = expr->getOperand(0); - - if (expr->isCast()) { - ir::Register pointer_reg; - if(isa<ConstantExpr>(val)) { - // try to get the real pointer register, for case like: - // store i64 ptrtoint (i8 addrspace(3)* getelementptr inbounds ... - // in which ptrtoint and getelementptr are ConstantExpr. - pointer_reg = getConstantPointerRegister(dyn_cast<ConstantExpr>(val), elemID); - } else { - pointer_reg = regTranslator.getScalar(val, elemID); - } - // if ptrToInt request another type other than 32bit, convert as requested - ir::Type dstType = getType(ctx, expr->getType()); - ir::Type srcType = getType(ctx, val->getType()); - if(srcType != dstType && dstType != ir::TYPE_S32) { - ir::Register tmp = ctx.reg(getFamily(dstType)); - ctx.CVT(dstType, srcType, tmp, pointer_reg); - return tmp; - } - return pointer_reg; - } - else if (expr->getOpcode() == Instruction::GetElementPtr) { - uint32_t constantOffset = 0; - - Value *pointer = val; - CompositeType* CompTy = cast<CompositeType>(pointer->getType()); - for(uint32_t op=1; op<expr->getNumOperands(); ++op) { - int32_t TypeIndex; - ConstantInt* ConstOP = dyn_cast<ConstantInt>(expr->getOperand(op)); - if (ConstOP == NULL) - goto error; - TypeIndex = ConstOP->getZExtValue(); - GBE_ASSERT(TypeIndex >= 0); - constantOffset += getGEPConstOffset(unit, CompTy, TypeIndex); - CompTy = dyn_cast<CompositeType>(CompTy->getTypeAtIndex(TypeIndex)); - } - - ir::Register pointer_reg; - if(isa<ConstantExpr>(pointer)) - pointer_reg = getConstantPointerRegister(dyn_cast<ConstantExpr>(pointer), elemID); - else - pointer_reg = regTranslator.getScalar(pointer, elemID); - - ir::Register offset_reg = ctx.reg(ir::RegisterFamily::FAMILY_DWORD); - ctx.LOADI(ir::Type::TYPE_S32, offset_reg, ctx.newIntegerImmediate(constantOffset, ir::Type::TYPE_S32)); - ir::Register reg = ctx.reg(ir::RegisterFamily::FAMILY_DWORD); - ctx.ADD(ir::Type::TYPE_S32, reg, pointer_reg, offset_reg); - return reg; - } - -error: - expr->dump(); - GBE_ASSERT(0 && "Unsupported constant expression"); - return regTranslator.getScalar(val, elemID); - } - ir::Register GenWriter::getConstantRegister(Constant *c, uint32_t elemID) { GBE_ASSERT(c != NULL); if(isa<GlobalValue>(c)) { @@ -1309,15 +1106,6 @@ error: return reg; } - if(isa<ConstantExpr>(c)) { - // Check whether this is a constant drived from a pointer. - Constant *itC = c; - while(isa<ConstantExpr>(itC)) - itC = dyn_cast<ConstantExpr>(itC)->getOperand(0); - if (itC->getType()->isPointerTy()) - return getConstantPointerRegister(dyn_cast<ConstantExpr>(c), elemID); - } - const ir::ImmediateIndex immIndex = this->newImmediate(c, elemID); const ir::Immediate imm = ctx.getImmediate(immIndex); const ir::Register reg = ctx.reg(getFamily(imm.getType())); |