aboutsummaryrefslogtreecommitdiff
path: root/utils/TableGen/NeonEmitter.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:49:41 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:49:41 +0000
commit45b533945f0851ec234ca846e1af5ee1e4df0b6e (patch)
tree0a5b74c0b9ca73aded34df95c91fcaf3815230d8 /utils/TableGen/NeonEmitter.cpp
parent7e86edd64bfae4e324224452e4ea879b3371a4bd (diff)
downloadsrc-45b533945f0851ec234ca846e1af5ee1e4df0b6e.tar.gz
src-45b533945f0851ec234ca846e1af5ee1e4df0b6e.zip
Vendor import of clang trunk r256633:vendor/clang/clang-trunk-r256633
Notes
Notes: svn path=/vendor/clang/dist/; revision=292920 svn path=/vendor/clang/clang-trunk-r256633/; revision=292923; tag=vendor/clang/clang-trunk-r256633
Diffstat (limited to 'utils/TableGen/NeonEmitter.cpp')
-rw-r--r--utils/TableGen/NeonEmitter.cpp83
1 files changed, 41 insertions, 42 deletions
diff --git a/utils/TableGen/NeonEmitter.cpp b/utils/TableGen/NeonEmitter.cpp
index 7644ae2c04da..6e7bc9057fd7 100644
--- a/utils/TableGen/NeonEmitter.cpp
+++ b/utils/TableGen/NeonEmitter.cpp
@@ -36,6 +36,7 @@
#include "llvm/TableGen/SetTheory.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <algorithm>
+#include <deque>
#include <map>
#include <sstream>
#include <string>
@@ -393,7 +394,7 @@ public:
/// Return true if the prototype has a scalar argument.
/// This does not return true for the "splat" code ('a').
- bool protoHasScalar();
+ bool protoHasScalar() const;
/// Return the index that parameter PIndex will sit at
/// in a generated function call. This is often just PIndex,
@@ -431,9 +432,9 @@ public:
/// Return the name, mangled with type information.
/// If ForceClassS is true, use ClassS (u32/s32) instead
/// of the intrinsic's own type class.
- std::string getMangledName(bool ForceClassS = false);
+ std::string getMangledName(bool ForceClassS = false) const;
/// Return the type code for a builtin function call.
- std::string getInstTypeCode(Type T, ClassKind CK);
+ std::string getInstTypeCode(Type T, ClassKind CK) const;
/// Return the type string for a BUILTIN() macro in Builtins.def.
std::string getBuiltinTypeStr();
@@ -444,7 +445,7 @@ public:
void indexBody();
private:
- std::string mangleName(std::string Name, ClassKind CK);
+ std::string mangleName(std::string Name, ClassKind CK) const;
void initVariables();
std::string replaceParamsIn(std::string S);
@@ -494,7 +495,7 @@ private:
class NeonEmitter {
RecordKeeper &Records;
DenseMap<Record *, ClassKind> ClassMap;
- std::map<std::string, std::vector<Intrinsic *>> IntrinsicMap;
+ std::map<std::string, std::deque<Intrinsic>> IntrinsicMap;
unsigned UniqueNumber;
void createIntrinsic(Record *R, SmallVectorImpl<Intrinsic *> &Out);
@@ -507,7 +508,7 @@ class NeonEmitter {
public:
/// Called by Intrinsic - this attempts to get an intrinsic that takes
/// the given types as arguments.
- Intrinsic *getIntrinsic(StringRef Name, ArrayRef<Type> Types);
+ Intrinsic &getIntrinsic(StringRef Name, ArrayRef<Type> Types);
/// Called by Intrinsic - returns a globally-unique number.
unsigned getUniqueNumber() { return UniqueNumber++; }
@@ -836,10 +837,6 @@ void Type::applyModifier(char Mod) {
Float = true;
break;
case 'f':
- // Special case - if we're half-precision, a floating
- // point argument needs to be 128-bits (double size).
- if (isHalf())
- Bitwidth = 128;
Float = true;
ElementBitwidth = 32;
break;
@@ -954,7 +951,7 @@ void Type::applyModifier(char Mod) {
// Intrinsic implementation
//===----------------------------------------------------------------------===//
-std::string Intrinsic::getInstTypeCode(Type T, ClassKind CK) {
+std::string Intrinsic::getInstTypeCode(Type T, ClassKind CK) const {
char typeCode = '\0';
bool printNumber = true;
@@ -992,6 +989,10 @@ std::string Intrinsic::getInstTypeCode(Type T, ClassKind CK) {
return S;
}
+static bool isFloatingPointProtoModifier(char Mod) {
+ return Mod == 'F' || Mod == 'f';
+}
+
std::string Intrinsic::getBuiltinTypeStr() {
ClassKind LocalCK = getClassKind(true);
std::string S;
@@ -1013,7 +1014,7 @@ std::string Intrinsic::getBuiltinTypeStr() {
if (!RetT.isScalar() && !RetT.isSigned())
RetT.makeSigned();
- bool ForcedVectorFloatingType = Proto[0] == 'F' || Proto[0] == 'f';
+ bool ForcedVectorFloatingType = isFloatingPointProtoModifier(Proto[0]);
if (LocalCK == ClassB && !RetT.isScalar() && !ForcedVectorFloatingType)
// Cast to vector of 8-bit elements.
RetT.makeInteger(8, true);
@@ -1026,7 +1027,7 @@ std::string Intrinsic::getBuiltinTypeStr() {
if (T.isPoly())
T.makeInteger(T.getElementSizeInBits(), false);
- bool ForcedFloatingType = Proto[I + 1] == 'F' || Proto[I + 1] == 'f';
+ bool ForcedFloatingType = isFloatingPointProtoModifier(Proto[I + 1]);
if (LocalCK == ClassB && !T.isScalar() && !ForcedFloatingType)
T.makeInteger(8, true);
// Halves always get converted to 8-bit elements.
@@ -1049,7 +1050,7 @@ std::string Intrinsic::getBuiltinTypeStr() {
return S;
}
-std::string Intrinsic::getMangledName(bool ForceClassS) {
+std::string Intrinsic::getMangledName(bool ForceClassS) const {
// Check if the prototype has a scalar operand with the type of the vector
// elements. If not, bitcasting the args will take care of arg checking.
// The actual signedness etc. will be taken care of with special enums.
@@ -1060,12 +1061,12 @@ std::string Intrinsic::getMangledName(bool ForceClassS) {
return mangleName(Name, ForceClassS ? ClassS : LocalCK);
}
-std::string Intrinsic::mangleName(std::string Name, ClassKind LocalCK) {
+std::string Intrinsic::mangleName(std::string Name, ClassKind LocalCK) const {
std::string typeCode = getInstTypeCode(BaseType, LocalCK);
std::string S = Name;
- if (Name == "vcvt_f32_f16" || Name == "vcvt_f32_f64" ||
- Name == "vcvt_f64_f32")
+ if (Name == "vcvt_f16_f32" || Name == "vcvt_f32_f16" ||
+ Name == "vcvt_f32_f64" || Name == "vcvt_f64_f32")
return Name;
if (typeCode.size() > 0) {
@@ -1278,7 +1279,7 @@ void Intrinsic::emitShadowedArgs() {
// We don't check 'a' in this function, because for builtin function the
// argument matching to 'a' uses a vector type splatted from a scalar type.
-bool Intrinsic::protoHasScalar() {
+bool Intrinsic::protoHasScalar() const {
return (Proto.find('s') != std::string::npos ||
Proto.find('z') != std::string::npos ||
Proto.find('r') != std::string::npos ||
@@ -1363,7 +1364,7 @@ void Intrinsic::emitBodyAsBuiltinCall() {
// Extra constant integer to hold type class enum for this function, e.g. s8
if (getClassKind(true) == ClassB) {
Type ThisTy = getReturnType();
- if (Proto[0] == 'v' || Proto[0] == 'f' || Proto[0] == 'F')
+ if (Proto[0] == 'v' || isFloatingPointProtoModifier(Proto[0]))
ThisTy = getParamType(0);
if (ThisTy.isPointer())
ThisTy = getParamType(1);
@@ -1491,15 +1492,14 @@ std::pair<Type, std::string> Intrinsic::DagEmitter::emitDagCall(DagInit *DI) {
N = SI->getAsUnquotedString();
else
N = emitDagArg(DI->getArg(0), "").second;
- Intrinsic *Callee = Intr.Emitter.getIntrinsic(N, Types);
- assert(Callee && "getIntrinsic should not return us nullptr!");
+ Intrinsic &Callee = Intr.Emitter.getIntrinsic(N, Types);
// Make sure the callee is known as an early def.
- Callee->setNeededEarly();
- Intr.Dependencies.insert(Callee);
+ Callee.setNeededEarly();
+ Intr.Dependencies.insert(&Callee);
// Now create the call itself.
- std::string S = CallPrefix.str() + Callee->getMangledName(true) + "(";
+ std::string S = CallPrefix.str() + Callee.getMangledName(true) + "(";
for (unsigned I = 0; I < DI->getNumArgs() - 1; ++I) {
if (I != 0)
S += ", ";
@@ -1507,7 +1507,7 @@ std::pair<Type, std::string> Intrinsic::DagEmitter::emitDagCall(DagInit *DI) {
}
S += ")";
- return std::make_pair(Callee->getReturnType(), S);
+ return std::make_pair(Callee.getReturnType(), S);
}
std::pair<Type, std::string> Intrinsic::DagEmitter::emitDagCast(DagInit *DI,
@@ -1855,11 +1855,11 @@ void Intrinsic::indexBody() {
// NeonEmitter implementation
//===----------------------------------------------------------------------===//
-Intrinsic *NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types) {
+Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types) {
// First, look up the name in the intrinsic map.
assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
("Intrinsic '" + Name + "' not found!").str());
- std::vector<Intrinsic *> &V = IntrinsicMap[Name.str()];
+ auto &V = IntrinsicMap.find(Name.str())->second;
std::vector<Intrinsic *> GoodVec;
// Create a string to print if we end up failing.
@@ -1874,35 +1874,35 @@ Intrinsic *NeonEmitter::getIntrinsic(StringRef Name, ArrayRef<Type> Types) {
// Now, look through each intrinsic implementation and see if the types are
// compatible.
- for (auto *I : V) {
- ErrMsg += " - " + I->getReturnType().str() + " " + I->getMangledName();
+ for (auto &I : V) {
+ ErrMsg += " - " + I.getReturnType().str() + " " + I.getMangledName();
ErrMsg += "(";
- for (unsigned A = 0; A < I->getNumParams(); ++A) {
+ for (unsigned A = 0; A < I.getNumParams(); ++A) {
if (A != 0)
ErrMsg += ", ";
- ErrMsg += I->getParamType(A).str();
+ ErrMsg += I.getParamType(A).str();
}
ErrMsg += ")\n";
- if (I->getNumParams() != Types.size())
+ if (I.getNumParams() != Types.size())
continue;
bool Good = true;
for (unsigned Arg = 0; Arg < Types.size(); ++Arg) {
- if (I->getParamType(Arg) != Types[Arg]) {
+ if (I.getParamType(Arg) != Types[Arg]) {
Good = false;
break;
}
}
if (Good)
- GoodVec.push_back(I);
+ GoodVec.push_back(&I);
}
assert_with_loc(GoodVec.size() > 0,
"No compatible intrinsic found - " + ErrMsg);
assert_with_loc(GoodVec.size() == 1, "Multiple overloads found - " + ErrMsg);
- return GoodVec.front();
+ return *GoodVec.front();
}
void NeonEmitter::createIntrinsic(Record *R,
@@ -1947,13 +1947,12 @@ void NeonEmitter::createIntrinsic(Record *R,
std::sort(NewTypeSpecs.begin(), NewTypeSpecs.end());
NewTypeSpecs.erase(std::unique(NewTypeSpecs.begin(), NewTypeSpecs.end()),
NewTypeSpecs.end());
+ auto &Entry = IntrinsicMap[Name];
for (auto &I : NewTypeSpecs) {
- Intrinsic *IT = new Intrinsic(R, Name, Proto, I.first, I.second, CK, Body,
- *this, Guard, IsUnavailable, BigEndianSafe);
-
- IntrinsicMap[Name].push_back(IT);
- Out.push_back(IT);
+ Entry.emplace_back(R, Name, Proto, I.first, I.second, CK, Body, *this,
+ Guard, IsUnavailable, BigEndianSafe);
+ Out.push_back(&Entry.back());
}
CurrentRecord = nullptr;
@@ -2023,8 +2022,8 @@ void NeonEmitter::genOverloadTypeCheckCode(raw_ostream &OS,
uint64_t Mask = 0ULL;
Type Ty = Def->getReturnType();
- if (Def->getProto()[0] == 'v' || Def->getProto()[0] == 'f' ||
- Def->getProto()[0] == 'F')
+ if (Def->getProto()[0] == 'v' ||
+ isFloatingPointProtoModifier(Def->getProto()[0]))
Ty = Def->getParamType(0);
if (Ty.isPointer())
Ty = Def->getParamType(1);