SROA and GVN may introduce some integer type not support by backend.
Remove this type assert in GenWrite, and found these types, set the unit to
invalid. If unit is invalid, use optLevel 0, which not include SROA and GVN, and
try again.
Signed-off-by: Yang Rong <rong.r.yang@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
BVAR(OCL_OUTPUT_GEN_IR, false);
bool Program::buildFromLLVMFile(const char *fileName, std::string &error, int optLevel) {
- ir::Unit unit;
- if (llvmToGen(unit, fileName, optLevel) == false) {
+ ir::Unit *unit = new ir::Unit();
+ if (llvmToGen(*unit, fileName, optLevel) == false) {
error = std::string(fileName) + " not found";
return false;
}
- this->buildFromUnit(unit, error);
+ //If unit is not valid, maybe some thing don't support by backend, introduce by some passes
+ //use optLevel 0 to try again.
+ if(!unit->getValid()) {
+ delete unit; //clear unit
+ unit = new ir::Unit();
+ llvmToGen(*unit, fileName, 0); //suppose file exists and llvmToGen will not return false.
+ }
+ assert(unit->getValid());
+ this->buildFromUnit(*unit, error);
+ delete unit;
return true;
}
bb->append(*insnPtr);
#if GBE_DEBUG
std::string whyNot;
- GBE_ASSERTM(insnPtr->wellFormed(whyNot), whyNot.c_str());
+ if(getUnit().getValid())
+ GBE_ASSERTM(insnPtr->wellFormed(whyNot), whyNot.c_str());
#endif /* GBE_DEBUG */
// Close the current block if this is a branch
namespace gbe {
namespace ir {
- Unit::Unit(PointerSize pointerSize) : pointerSize(pointerSize) {}
+ Unit::Unit(PointerSize pointerSize) : pointerSize(pointerSize), valid(true) {}
Unit::~Unit(void) {
for (const auto &pair : functions) GBE_DELETE(pair.second);
}
ConstantSet& getConstantSet(void) { return constantSet; }
/*! Return the constant set */
const ConstantSet& getConstantSet(void) const { return constantSet; }
+ void setValid(bool value) { valid = value; }
+ bool getValid() { return valid; }
private:
friend class ContextInterface; //!< Can free modify the unit
hash_map<std::string, Function*> functions; //!< All the defined functions
ConstantSet constantSet; //!< All the constants defined in the unit
PointerSize pointerSize; //!< Size shared by all pointers
GBE_CLASS(Unit);
+ bool valid;
};
/*! Output the unit string in the given stream */
} /* namespace gbe */
#endif /* __GBE_IR_UNIT_HPP__ */
-
}
/*! LLVM IR Type to Gen IR type translation */
- static ir::Type getType(const ir::Context &ctx, const Type *type)
+ static ir::Type getType(ir::Context &ctx, const Type *type)
{
GBE_ASSERT(isScalarType(type));
if (type->isFloatTy() == true)
return ir::TYPE_S32;
if (type == Type::getInt64Ty(type->getContext()))
return ir::TYPE_S64;
- GBE_ASSERT(0);
+ ctx.getUnit().setValid(false);
return ir::TYPE_S64;
}
/*! LLVM IR Type to Gen IR unsigned type translation */
- static ir::Type getUnsignedType(const ir::Context &ctx, const Type *type)
+ static ir::Type getUnsignedType(ir::Context &ctx, const Type *type)
{
GBE_ASSERT(type->isIntegerTy() == true);
if (type == Type::getInt1Ty(type->getContext()))
return ir::TYPE_U32;
if (type == Type::getInt64Ty(type->getContext()))
return ir::TYPE_U64;
- GBE_ASSERT(0);
+ ctx.getUnit().setValid(false);
return ir::TYPE_U64;
}
/*! Type to register family translation */
- static ir::RegisterFamily getFamily(const ir::Context &ctx, const Type *type)
+ static ir::RegisterFamily getFamily(ir::Context &ctx, const Type *type)
{
GBE_ASSERT(isScalarType(type) == true);
if (type == Type::getInt1Ty(type->getContext()))
return ir::FAMILY_QWORD;
if (type->isPointerTy())
return ctx.getPointerFamily();
- GBE_ASSERT(0);
+ ctx.getUnit().setValid(false);
return ir::FAMILY_BOOL;
}
/*! Get number of element to process dealing either with a vector or a scalar
* value
*/
- static ir::Type getVectorInfo(const ir::Context &ctx, Type *llvmType, Value *value, uint32_t &elemNum, bool useUnsigned = false)
+ static ir::Type getVectorInfo(ir::Context &ctx, Type *llvmType, Value *value, uint32_t &elemNum, bool useUnsigned = false)
{
ir::Type type;
if (llvmType->isVectorTy() == true) {
const uint64_t u64 = CI->getZExtValue();
return doIt(u64);
} else {
- GBE_ASSERTM(false, "Unsupported integer size");
+ //GBE_ASSERTM(false, "Unsupported integer size");
+ doIt.invalid();
return doIt(uint64_t(0));
}
}
template <typename T> ir::ImmediateIndex operator() (const T &t) {
return ctx.newImmediate(t);
}
+ void invalid() {
+ ctx.getUnit().setValid(false);
+ }
ir::Context &ctx;
};
template <typename T> ir::Immediate operator() (const T &t) {
return ir::Immediate(t);
}
+ void invalid() {
+ ctx.getUnit().setValid(false);
+ }
ir::Context &ctx;
};
template <typename T> INLINE uint64_t operator() (const T &t) {
return uint64_t(t);
}
+ void invalid() {
+ ctx.getUnit().setValid(false);
+ }
ir::Context &ctx;
};
MPM.add(createFunctionAttrsPass()); // Set readonly/readnone attrs
//MPM.add(createScalarReplAggregatesPass(64, true, -1, -1, 64))
- //MPM.add(createSROAPass(/*RequiresDomTree*/ false));
+ if(optLevel > 0)
+ MPM.add(createSROAPass(/*RequiresDomTree*/ false));
MPM.add(createEarlyCSEPass()); // Catch trivial redundancies
MPM.add(createJumpThreadingPass()); // Thread jumps.
MPM.add(createCorrelatedValuePropagationPass()); // Propagate conditionals
MPM.add(createLoopDeletionPass()); // Delete dead loops
MPM.add(createLoopUnrollPass()); // Unroll small loops
if(optLevel > 0)
- MPM.add(createGVNPass(true)); // Remove redundancies
+ MPM.add(createGVNPass()); // Remove redundancies
MPM.add(createMemCpyOptPass()); // Remove memcpy / form memset
MPM.add(createSCCPPass()); // Constant prop with SCCP