Remove PointerType from target definition. Use abstract type MVT::iPTR to

represent pointer type.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28363 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Evan Cheng 2006-05-17 20:37:59 +00:00
parent eba0bf5aff
commit 2618d07765
4 changed files with 93 additions and 65 deletions

View File

@ -30,12 +30,7 @@ AsmWriterNum("asmwriternum", cl::init(0),
/// getValueType - Return the MCV::ValueType that the specified TableGen record
/// corresponds to.
MVT::ValueType llvm::getValueType(Record *Rec, const CodeGenTarget *CGT) {
MVT::ValueType VT = (MVT::ValueType)Rec->getValueAsInt("Value");
if (VT == MVT::iPTR) {
assert(CGT && "Use a pointer type in a place that isn't supported yet!");
VT = CGT->getPointerType();
}
return VT;
return (MVT::ValueType)Rec->getValueAsInt("Value");
}
std::string llvm::getName(MVT::ValueType T) {
@ -63,35 +58,37 @@ std::string llvm::getName(MVT::ValueType T) {
case MVT::v2f32: return "v2f32";
case MVT::v4f32: return "v4f32";
case MVT::v2f64: return "v2f64";
case MVT::iPTR: return "TLI.getPointetTy()";
default: assert(0 && "ILLEGAL VALUE TYPE!"); return "";
}
}
std::string llvm::getEnumName(MVT::ValueType T) {
switch (T) {
case MVT::Other: return "Other";
case MVT::i1: return "i1";
case MVT::i8: return "i8";
case MVT::i16: return "i16";
case MVT::i32: return "i32";
case MVT::i64: return "i64";
case MVT::i128: return "i128";
case MVT::f32: return "f32";
case MVT::f64: return "f64";
case MVT::f80: return "f80";
case MVT::f128: return "f128";
case MVT::Flag: return "Flag";
case MVT::isVoid:return "isVoid";
case MVT::v8i8: return "v8i8";
case MVT::v4i16: return "v4i16";
case MVT::v2i32: return "v2i32";
case MVT::v16i8: return "v16i8";
case MVT::v8i16: return "v8i16";
case MVT::v4i32: return "v4i32";
case MVT::v2i64: return "v2i64";
case MVT::v2f32: return "v2f32";
case MVT::v4f32: return "v4f32";
case MVT::v2f64: return "v2f64";
case MVT::Other: return "MVT::Other";
case MVT::i1: return "MVT::i1";
case MVT::i8: return "MVT::i8";
case MVT::i16: return "MVT::i16";
case MVT::i32: return "MVT::i32";
case MVT::i64: return "MVT::i64";
case MVT::i128: return "MVT::i128";
case MVT::f32: return "MVT::f32";
case MVT::f64: return "MVT::f64";
case MVT::f80: return "MVT::f80";
case MVT::f128: return "MVT::f128";
case MVT::Flag: return "MVT::Flag";
case MVT::isVoid:return "MVT::isVoid";
case MVT::v8i8: return "MVT::v8i8";
case MVT::v4i16: return "MVT::v4i16";
case MVT::v2i32: return "MVT::v2i32";
case MVT::v16i8: return "MVT::v16i8";
case MVT::v8i16: return "MVT::v8i16";
case MVT::v4i32: return "MVT::v4i32";
case MVT::v2i64: return "MVT::v2i64";
case MVT::v2f32: return "MVT::v2f32";
case MVT::v4f32: return "MVT::v4f32";
case MVT::v2f64: return "MVT::v2f64";
case MVT::iPTR: return "TLI.getPointetTy()";
default: assert(0 && "ILLEGAL VALUE TYPE!"); return "";
}
}
@ -104,7 +101,7 @@ std::ostream &llvm::operator<<(std::ostream &OS, MVT::ValueType T) {
/// getTarget - Return the current instance of the Target class.
///
CodeGenTarget::CodeGenTarget() : PointerType(MVT::Other) {
CodeGenTarget::CodeGenTarget() {
std::vector<Record*> Targets = Records.getAllDerivedDefinitions("Target");
if (Targets.size() == 0)
throw std::string("ERROR: No 'Target' subclasses defined!");
@ -114,7 +111,6 @@ CodeGenTarget::CodeGenTarget() : PointerType(MVT::Other) {
// Read in all of the CalleeSavedRegisters.
CalleeSavedRegisters =TargetRec->getValueAsListOfDefs("CalleeSavedRegisters");
PointerType = getValueType(TargetRec->getValueAsDef("PointerType"));
}

View File

@ -43,7 +43,6 @@ std::string getEnumName(MVT::ValueType T);
class CodeGenTarget {
Record *TargetRec;
std::vector<Record*> CalleeSavedRegisters;
MVT::ValueType PointerType;
mutable std::map<std::string, CodeGenInstruction> Instructions;
mutable std::vector<CodeGenRegister> Registers;
@ -63,8 +62,6 @@ public:
return CalleeSavedRegisters;
}
MVT::ValueType getPointerType() const { return PointerType; }
/// getInstructionSet - Return the InstructionSet object.
///
Record *getInstructionSet() const;

View File

@ -156,7 +156,7 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
return NodeToApply->UpdateNodeType(x.SDTCisVT_Info.VT, TP);
case SDTCisPtrTy: {
// Operand must be same as target pointer type.
return NodeToApply->UpdateNodeType(CGT.getPointerType(), TP);
return NodeToApply->UpdateNodeType(MVT::iPTR, TP);
}
case SDTCisInt: {
// If there is only one integer type supported, this must be it.
@ -346,6 +346,18 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
setTypes(ExtVTs);
return true;
}
if (getExtTypeNum(0) == MVT::iPTR) {
if (ExtVTs[0] == MVT::iPTR || ExtVTs[0] == MVT::isInt)
return false;
if (isExtIntegerInVTs(ExtVTs)) {
std::vector<unsigned char> FVTs = FilterEVTs(ExtVTs, MVT::isInteger);
if (FVTs.size()) {
setTypes(ExtVTs);
return true;
}
}
}
if (ExtVTs[0] == MVT::isInt && isExtIntegerInVTs(getExtTypes())) {
assert(hasTypeSet() && "should be handled above!");
@ -355,6 +367,16 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
setTypes(FVTs);
return true;
}
if (ExtVTs[0] == MVT::iPTR && isExtIntegerInVTs(getExtTypes())) {
//assert(hasTypeSet() && "should be handled above!");
std::vector<unsigned char> FVTs = FilterEVTs(getExtTypes(), MVT::isInteger);
if (getExtTypes() == FVTs)
return false;
if (FVTs.size()) {
setTypes(FVTs);
return true;
}
}
if (ExtVTs[0] == MVT::isFP && isExtFloatingPointInVTs(getExtTypes())) {
assert(hasTypeSet() && "should be handled above!");
std::vector<unsigned char> FVTs =
@ -374,7 +396,11 @@ bool TreePatternNode::UpdateNodeType(const std::vector<unsigned char> &ExtVTs,
(getExtTypeNum(0) == MVT::isFP && isExtFloatingPointInVTs(ExtVTs))) {
setTypes(ExtVTs);
return true;
}
}
if (getExtTypeNum(0) == MVT::isInt && ExtVTs[0] == MVT::iPTR) {
setTypes(ExtVTs);
return true;
}
if (isLeaf()) {
dump();
@ -402,6 +428,7 @@ void TreePatternNode::print(std::ostream &OS) const {
case MVT::isInt: OS << ":isInt"; break;
case MVT::isFP : OS << ":isFP"; break;
case MVT::isUnknown: ; /*OS << ":?";*/ break;
case MVT::iPTR: OS << ":iPTR"; break;
default: OS << ":" << getTypeNum(0); break;
}
@ -603,19 +630,22 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
// At some point, it may make sense for this tree pattern to have
// multiple types. Assert here that it does not, so we revisit this
// code when appropriate.
assert(getExtTypes().size() >= 1 && "TreePattern does not have a type!");
assert(getExtTypes().size() >= 1 && "TreePattern doesn't have a type!");
MVT::ValueType VT = getTypeNum(0);
for (unsigned i = 1, e = getExtTypes().size(); i != e; ++i)
assert(getTypeNum(i) == VT && "TreePattern has too many types!");
unsigned Size = MVT::getSizeInBits(getTypeNum(0));
// Make sure that the value is representable for this type.
if (Size < 32) {
int Val = (II->getValue() << (32-Size)) >> (32-Size);
if (Val != II->getValue())
TP.error("Sign-extended integer value '" + itostr(II->getValue()) +
"' is out of range for type 'MVT::" +
getEnumName(getTypeNum(0)) + "'!");
VT = getTypeNum(0);
if (VT != MVT::iPTR) {
unsigned Size = MVT::getSizeInBits(VT);
// Make sure that the value is representable for this type.
if (Size < 32) {
int Val = (II->getValue() << (32-Size)) >> (32-Size);
if (Val != II->getValue())
TP.error("Sign-extended integer value '" + itostr(II->getValue())+
"' is out of range for type '" +
getEnumName(getTypeNum(0)) + "'!");
}
}
}
@ -652,8 +682,7 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
utostr(getNumChildren()-1) + " operands!");
// Apply type info to the intrinsic ID.
MVT::ValueType PtrTy = ISE.getTargetInfo().getPointerType();
MadeChange |= getChild(0)->UpdateNodeType(PtrTy, TP);
MadeChange |= getChild(0)->UpdateNodeType(MVT::iPTR, TP);
for (unsigned i = 1, e = getNumChildren(); i != e; ++i) {
MVT::ValueType OpVT = Int.ArgVTs[i];
@ -1862,10 +1891,11 @@ static const ComplexPattern *NodeGetComplexPattern(TreePatternNode *N,
/// patterns before small ones. This is used to determine the size of a
/// pattern.
static unsigned getPatternSize(TreePatternNode *P, DAGISelEmitter &ISE) {
assert(isExtIntegerInVTs(P->getExtTypes()) ||
isExtFloatingPointInVTs(P->getExtTypes()) ||
P->getExtTypeNum(0) == MVT::isVoid ||
P->getExtTypeNum(0) == MVT::Flag &&
assert((isExtIntegerInVTs(P->getExtTypes()) ||
isExtFloatingPointInVTs(P->getExtTypes()) ||
P->getExtTypeNum(0) == MVT::isVoid ||
P->getExtTypeNum(0) == MVT::Flag ||
P->getExtTypeNum(0) == MVT::iPTR) &&
"Not a valid pattern node to size!");
unsigned Size = 2; // The node itself.
// If the root node is a ConstantSDNode, increases its size.
@ -2340,7 +2370,7 @@ public:
emitDecl("Tmp" + utostr(ResNo));
emitCode("Tmp" + utostr(ResNo) +
" = CurDAG->getTargetConstant(Tmp" + utostr(ResNo) +
"C, MVT::" + getEnumName(N->getTypeNum(0)) + ");");
"C, " + getEnumName(N->getTypeNum(0)) + ");");
} else if (!N->isLeaf() && N->getOperator()->getName() == "texternalsym"){
Record *Op = OperatorMap[N->getName()];
// Transform ExternalSymbol to TargetExternalSymbol
@ -2348,7 +2378,7 @@ public:
emitDecl("Tmp" + utostr(ResNo));
emitCode("Tmp" + utostr(ResNo) + " = CurDAG->getTarget"
"ExternalSymbol(cast<ExternalSymbolSDNode>(" +
Val + ")->getSymbol(), MVT::" +
Val + ")->getSymbol(), " +
getEnumName(N->getTypeNum(0)) + ");");
} else {
emitDecl("Tmp" + utostr(ResNo));
@ -2361,7 +2391,7 @@ public:
emitDecl("Tmp" + utostr(ResNo));
emitCode("Tmp" + utostr(ResNo) + " = CurDAG->getTarget"
"GlobalAddress(cast<GlobalAddressSDNode>(" + Val +
")->getGlobal(), MVT::" + getEnumName(N->getTypeNum(0)) +
")->getGlobal(), " + getEnumName(N->getTypeNum(0)) +
");");
} else {
emitDecl("Tmp" + utostr(ResNo));
@ -2420,7 +2450,7 @@ public:
if (DI->getDef()->isSubClassOf("Register")) {
emitDecl("Tmp" + utostr(ResNo));
emitCode("Tmp" + utostr(ResNo) + " = CurDAG->getRegister(" +
ISE.getQualifiedName(DI->getDef()) + ", MVT::" +
ISE.getQualifiedName(DI->getDef()) + ", " +
getEnumName(N->getTypeNum(0)) + ");");
return std::make_pair(1, ResNo);
}
@ -2430,7 +2460,7 @@ public:
emitDecl("Tmp" + utostr(ResNo));
emitCode("Tmp" + utostr(ResNo) +
" = CurDAG->getTargetConstant(" + itostr(II->getValue()) +
", MVT::" + getEnumName(N->getTypeNum(0)) + ");");
", " + getEnumName(N->getTypeNum(0)) + ");");
return std::make_pair(1, ResNo);
}
@ -2552,7 +2582,7 @@ public:
// Result types.
if (PatResults > 0) {
if (N->getTypeNum(0) != MVT::isVoid)
Code += ", MVT::" + getEnumName(N->getTypeNum(0));
Code += ", " + getEnumName(N->getTypeNum(0));
}
if (NodeHasChain)
Code += ", MVT::Other";
@ -2572,7 +2602,7 @@ public:
// Output order: results, chain, flags
// Result types.
if (PatResults > 0 && N->getTypeNum(0) != MVT::isVoid)
Code += ", MVT::" + getEnumName(N->getTypeNum(0));
Code += ", " + getEnumName(N->getTypeNum(0));
if (NodeHasChain)
Code += ", MVT::Other";
if (NodeHasOutFlag)
@ -2606,7 +2636,7 @@ public:
// Output order: results, chain, flags
// Result types.
if (NumResults > 0 && N->getTypeNum(0) != MVT::isVoid)
Code += ", MVT::" + getEnumName(N->getTypeNum(0));
Code += ", " + getEnumName(N->getTypeNum(0));
if (NodeHasChain)
Code += ", MVT::Other";
if (NodeHasOutFlag)
@ -2717,7 +2747,7 @@ public:
std::string Code = " Result = CurDAG->SelectNodeTo(N.Val, " +
II.Namespace + "::" + II.TheDef->getName();
if (N->getTypeNum(0) != MVT::isVoid)
Code += ", MVT::" + getEnumName(N->getTypeNum(0));
Code += ", " + getEnumName(N->getTypeNum(0));
if (NodeHasOutFlag)
Code += ", MVT::Flag";
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
@ -2730,7 +2760,7 @@ public:
Code = " ResNode = CurDAG->getTargetNode(" +
II.Namespace + "::" + II.TheDef->getName();
if (N->getTypeNum(0) != MVT::isVoid)
Code += ", MVT::" + getEnumName(N->getTypeNum(0));
Code += ", " + getEnumName(N->getTypeNum(0));
if (NodeHasOutFlag)
Code += ", MVT::Flag";
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
@ -2834,7 +2864,7 @@ private:
RootName + utostr(OpNo) + ");");
emitCode("ResNode = CurDAG->getCopyToReg(" + ChainName +
", CurDAG->getRegister(" + ISE.getQualifiedName(RR) +
", MVT::" + getEnumName(RVT) + "), " +
", " + getEnumName(RVT) + "), " +
RootName + utostr(OpNo) + ", InFlag).Val;");
emitCode(ChainName + " = SDOperand(ResNode, 0);");
emitCode("InFlag = SDOperand(ResNode, 1);");
@ -2882,7 +2912,7 @@ private:
ChainName = "Chain";
}
emitCode("ResNode = CurDAG->getCopyFromReg(" + ChainName + ", " +
ISE.getQualifiedName(RR) + ", MVT::" + getEnumName(RVT) +
ISE.getQualifiedName(RR) + ", " + getEnumName(RVT) +
", InFlag).Val;");
emitCode(ChainName + " = SDOperand(ResNode, 1);");
emitCode("InFlag = SDOperand(ResNode, 2);");

View File

@ -169,10 +169,15 @@ namespace llvm {
void setName(const std::string &N) { Name = N; }
bool isLeaf() const { return Val != 0; }
bool hasTypeSet() const { return Types[0] < MVT::LAST_VALUETYPE; }
bool hasTypeSet() const {
return (Types[0] < MVT::LAST_VALUETYPE) || (Types[0] == MVT::iPTR);
}
bool isTypeCompletelyUnknown() const {
return Types[0] == MVT::isUnknown;
}
bool isTypeDynamicallyResolved() const {
return Types[0] == MVT::iPTR;
}
MVT::ValueType getTypeNum(unsigned Num) const {
assert(hasTypeSet() && "Doesn't have a type yet!");
assert(Types.size() > Num && "Type num out of range!");
@ -247,7 +252,7 @@ namespace llvm {
/// ContainsUnresolvedType - Return true if this tree contains any
/// unresolved types.
bool ContainsUnresolvedType() const {
if (!hasTypeSet()) return true;
if (!hasTypeSet() && !isTypeDynamicallyResolved()) return true;
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
if (getChild(i)->ContainsUnresolvedType()) return true;
return false;