summaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2007-08-04 01:51:18 +0000
committerChandler Carruth <chandlerc@gmail.com>2007-08-04 01:51:18 +0000
commit6994040a952e5fb27605eb3cf29ed86c4e59cf62 (patch)
treef1b3c2c54513244bf35e148ed628aa7c11923582 /utils
parent5dd75b4ca7e582f44da2f50362e8ab4c59972b5f (diff)
downloadllvm-6994040a952e5fb27605eb3cf29ed86c4e59cf62.tar.gz
llvm-6994040a952e5fb27605eb3cf29ed86c4e59cf62.tar.bz2
llvm-6994040a952e5fb27605eb3cf29ed86c4e59cf62.tar.xz
This is the patch to provide clean intrinsic function overloading support in LLVM. It cleans up the intrinsic definitions and generally smooths the process for more complicated intrinsic writing. It will be used by the upcoming atomic intrinsics as well as vector and float intrinsics in the future.
This also changes the syntax for llvm.bswap, llvm.part.set, llvm.part.select, and llvm.ct* intrinsics. They are automatically upgraded by both the LLVM ASM reader and the bitcode reader. The test cases have been updated, with special tests added to ensure the automatic upgrading is supported. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40807 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils')
-rw-r--r--utils/TableGen/CodeGenIntrinsics.h4
-rw-r--r--utils/TableGen/CodeGenTarget.cpp5
-rw-r--r--utils/TableGen/IntrinsicEmitter.cpp101
-rw-r--r--utils/TableGen/RegisterInfoEmitter.cpp2
4 files changed, 61 insertions, 51 deletions
diff --git a/utils/TableGen/CodeGenIntrinsics.h b/utils/TableGen/CodeGenIntrinsics.h
index 57f85ad422..8b2ead443f 100644
--- a/utils/TableGen/CodeGenIntrinsics.h
+++ b/utils/TableGen/CodeGenIntrinsics.h
@@ -30,10 +30,6 @@ namespace llvm {
std::string GCCBuiltinName;// Name of the corresponding GCC builtin, or "".
std::string TargetPrefix; // Target prefix, e.g. "ppc" for t-s intrinsics.
- /// ArgTypes - The type primitive enum value for the return value and all
- /// of the arguments. These are things like Type::IntegerTyID.
- std::vector<std::string> ArgTypes;
-
/// ArgVTs - The MVT::ValueType for each argument type. Note that this list
/// is only populated when in the context of a target .td file. When
/// building Intrinsics.td, this isn't available, because we don't know the
diff --git a/utils/TableGen/CodeGenTarget.cpp b/utils/TableGen/CodeGenTarget.cpp
index 21136c4645..78b850b43c 100644
--- a/utils/TableGen/CodeGenTarget.cpp
+++ b/utils/TableGen/CodeGenTarget.cpp
@@ -97,7 +97,7 @@ std::string llvm::getEnumName(MVT::ValueType T) {
case MVT::v2f64: return "MVT::v2f64";
case MVT::v3i32: return "MVT::v3i32";
case MVT::v3f32: return "MVT::v3f32";
- case MVT::iPTR: return "TLI.getPointerTy()";
+ case MVT::iPTR: return "MVT::iPTR";
default: assert(0 && "ILLEGAL VALUE TYPE!"); return "";
}
}
@@ -651,13 +651,12 @@ CodeGenIntrinsic::CodeGenIntrinsic(Record *R, CodeGenTarget *CGT) {
for (unsigned i = 0, e = TypeList->getSize(); i != e; ++i) {
Record *TyEl = TypeList->getElementAsRecord(i);
assert(TyEl->isSubClassOf("LLVMType") && "Expected a type!");
- ArgTypes.push_back(TyEl->getValueAsString("TypeVal"));
MVT::ValueType VT = getValueType(TyEl->getValueAsDef("VT"));
isOverloaded |= VT == MVT::iAny;
ArgVTs.push_back(VT);
ArgTypeDefs.push_back(TyEl);
}
- if (ArgTypes.size() == 0)
+ if (ArgVTs.size() == 0)
throw "Intrinsic '"+DefName+"' needs at least a type for the ret value!";
diff --git a/utils/TableGen/IntrinsicEmitter.cpp b/utils/TableGen/IntrinsicEmitter.cpp
index 3c11227785..ebc0c32692 100644
--- a/utils/TableGen/IntrinsicEmitter.cpp
+++ b/utils/TableGen/IntrinsicEmitter.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "CodeGenTarget.h"
#include "IntrinsicEmitter.h"
#include "Record.h"
#include "llvm/ADT/StringExtras.h"
@@ -94,12 +95,14 @@ EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
// For overloaded intrinsics, only the prefix needs to match
if (Ints[I->second].isOverloaded)
- OS << " if (Len >= " << I->first.size()
- << " && !memcmp(Name, \"" << I->first << "\", " << I->first.size()
- << ")) return Intrinsic::" << Ints[I->second].EnumName << ";\n";
+ OS << " if (Len > " << I->first.size()
+ << " && !memcmp(Name, \"" << I->first << ".\", "
+ << (I->first.size() + 1) << ")) return Intrinsic::"
+ << Ints[I->second].EnumName << ";\n";
else
OS << " if (Len == " << I->first.size()
- << " && !memcmp(Name, \"" << I->first << "\", Len)) return Intrinsic::"
+ << " && !memcmp(Name, \"" << I->first << "\", "
+ << I->first.size() << ")) return Intrinsic::"
<< Ints[I->second].EnumName << ";\n";
}
OS << " }\n";
@@ -117,50 +120,55 @@ EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
OS << "#endif\n\n";
}
-static bool EmitTypeVerify(std::ostream &OS, Record *ArgType) {
- if (ArgType->getValueAsString("TypeVal") == "...") return true;
-
- OS << "(int)" << ArgType->getValueAsString("TypeVal") << ", ";
- // If this is an integer type, check the width is correct.
- if (ArgType->isSubClassOf("LLVMIntegerType"))
- OS << ArgType->getValueAsInt("Width") << ", ";
-
- // If this is a vector type, check that the subtype and size are correct.
- else if (ArgType->isSubClassOf("LLVMVectorType")) {
- EmitTypeVerify(OS, ArgType->getValueAsDef("ElTy"));
- OS << ArgType->getValueAsInt("NumElts") << ", ";
+static void EmitTypeForValueType(std::ostream &OS, MVT::ValueType VT) {
+ if (MVT::isInteger(VT)) {
+ unsigned BitWidth = MVT::getSizeInBits(VT);
+ OS << "IntegerType::get(" << BitWidth << ")";
+ } else if (VT == MVT::Other) {
+ // MVT::OtherVT is used to mean the empty struct type here.
+ OS << "StructType::get(std::vector<const Type *>())";
+ } else if (VT == MVT::f32) {
+ OS << "Type::FloatTy";
+ } else if (VT == MVT::f64) {
+ OS << "Type::DoubleTy";
+ } else if (VT == MVT::isVoid) {
+ OS << "Type::VoidTy";
+ } else {
+ assert(false && "Unsupported ValueType!");
}
-
- return false;
}
static void EmitTypeGenerate(std::ostream &OS, Record *ArgType,
unsigned &ArgNo) {
- if (ArgType->isSubClassOf("LLVMIntegerType")) {
- unsigned BitWidth = ArgType->getValueAsInt("Width");
+ MVT::ValueType VT = getValueType(ArgType->getValueAsDef("VT"));
+
+ if (ArgType->isSubClassOf("LLVMMatchType")) {
+ unsigned Number = ArgType->getValueAsInt("Number");
+ assert(Number < ArgNo && "Invalid matching number!");
+ OS << "Tys[" << Number << "]";
+ } else if (VT == MVT::iAny) {
// NOTE: The ArgNo variable here is not the absolute argument number, it is
// the index of the "arbitrary" type in the Tys array passed to the
// Intrinsic::getDeclaration function. Consequently, we only want to
- // increment it when we actually hit an arbitrary integer type which is
- // identified by BitWidth == 0. Getting this wrong leads to very subtle
- // bugs!
- if (BitWidth == 0)
- OS << "Tys[" << ArgNo++ << "]";
- else
- OS << "IntegerType::get(" << BitWidth << ")";
- } else if (ArgType->isSubClassOf("LLVMVectorType")) {
+ // increment it when we actually hit an overloaded type. Getting this wrong
+ // leads to very subtle bugs!
+ OS << "Tys[" << ArgNo++ << "]";
+ } else if (MVT::isVector(VT)) {
OS << "VectorType::get(";
- EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
- OS << ", " << ArgType->getValueAsInt("NumElts") << ")";
- } else if (ArgType->isSubClassOf("LLVMPointerType")) {
+ EmitTypeForValueType(OS, MVT::getVectorElementType(VT));
+ OS << ", " << MVT::getVectorNumElements(VT) << ")";
+ } else if (VT == MVT::iPTR) {
OS << "PointerType::get(";
EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
OS << ")";
- } else if (ArgType->isSubClassOf("LLVMEmptyStructType")) {
- OS << "StructType::get(std::vector<const Type *>())";
+ } else if (VT == MVT::isVoid) {
+ if (ArgNo == 0)
+ OS << "Type::VoidTy";
+ else
+ // MVT::isVoid is used to mean varargs here.
+ OS << "...";
} else {
- OS << "Type::getPrimitiveType(";
- OS << ArgType->getValueAsString("TypeVal") << ")";
+ EmitTypeForValueType(OS, VT);
}
}
@@ -209,18 +217,24 @@ void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
}
const std::vector<Record*> &ArgTypes = I->first;
- OS << " VerifyIntrinsicPrototype(ID, IF, ";
- bool VarArg = false;
+ OS << " VerifyIntrinsicPrototype(ID, IF, " << ArgTypes.size() << ", ";
for (unsigned j = 0; j != ArgTypes.size(); ++j) {
- VarArg = EmitTypeVerify(OS, ArgTypes[j]);
- if (VarArg) {
- if ((j+1) != ArgTypes.size())
+ Record *ArgType = ArgTypes[j];
+ if (ArgType->isSubClassOf("LLVMMatchType")) {
+ unsigned Number = ArgType->getValueAsInt("Number");
+ assert(Number < j && "Invalid matching number!");
+ OS << "~" << Number;
+ } else {
+ MVT::ValueType VT = getValueType(ArgType->getValueAsDef("VT"));
+ OS << getEnumName(VT);
+ if (VT == MVT::isVoid && j != 0 && j != ArgTypes.size()-1)
throw "Var arg type not last argument";
- break;
}
+ if (j != ArgTypes.size()-1)
+ OS << ", ";
}
- OS << (VarArg ? "-2);\n" : "-1);\n");
+ OS << ");\n";
OS << " break;\n";
}
OS << " }\n";
@@ -255,7 +269,8 @@ void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
const std::vector<Record*> &ArgTypes = I->first;
unsigned N = ArgTypes.size();
- if (ArgTypes[N-1]->getValueAsString("TypeVal") == "...") {
+ if (N > 1 &&
+ getValueType(ArgTypes[N-1]->getValueAsDef("VT")) == MVT::isVoid) {
OS << " IsVarArg = true;\n";
--N;
}
diff --git a/utils/TableGen/RegisterInfoEmitter.cpp b/utils/TableGen/RegisterInfoEmitter.cpp
index a8690041bf..06c575da3a 100644
--- a/utils/TableGen/RegisterInfoEmitter.cpp
+++ b/utils/TableGen/RegisterInfoEmitter.cpp
@@ -209,7 +209,7 @@ void RegisterInfoEmitter::run(std::ostream &OS) {
<< " static const MVT::ValueType " << Name
<< "[] = {\n ";
for (unsigned i = 0, e = RC.VTs.size(); i != e; ++i)
- OS << getName(RC.VTs[i]) << ", ";
+ OS << getEnumName(RC.VTs[i]) << ", ";
OS << "MVT::Other\n };\n\n";
}
OS << "} // end anonymous namespace\n\n";