//===- NeonEmitter.cpp - Generate arm_neon.h for use with clang -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This tablegen backend is responsible for emitting arm_neon.h, which includes
// a declaration and definition of each function specified by the ARM NEON
// compiler interface. See ARM document DUI0348B.
//
// Each NEON instruction is implemented in terms of 1 or more functions which
// are suffixed with the element type of the input vectors. Functions may be
// implemented in terms of generic vector operations such as +, *, -, etc. or
// by calling a __builtin_-prefixed function which will be handled by clang's
// CodeGen library.
//
// Additional validation code can be generated by this file when runHeader() is
// called, rather than the normal run() entry point.
//
//===----------------------------------------------------------------------===//
#include "NeonEmitter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include <string>
using namespace llvm;
/// ParseTypes - break down a string such as "fQf" into a vector of StringRefs,
/// which each StringRef representing a single type declared in the string.
/// for "fQf" we would end up with 2 StringRefs, "f", and "Qf", representing
/// 2xfloat and 4xfloat respectively.
static void ParseTypes(Record *r, std::string &s,
SmallVectorImpl<StringRef> &TV) {
const char *data = s.data();
int len = 0;
for (unsigned i = 0, e = s.size(); i != e; ++i, ++len) {
if (data[len] == 'P' || data[len] == 'Q' || data[len] == 'U')
continue;
switch (data[len]) {
case 'c':
case 's':
case 'i':
case 'l':
case 'h':
case 'f':
break;
default:
throw TGError(r->getLoc(),
"Unexpected letter: " + std::string(data + len, 1));
break;
}
TV.push_back(StringRef(data, len + 1));
data += len + 1;
len = -1;
}
}
/// Widen - Convert a type code into the next wider type. char -> short,
/// short -> int, etc.
static char Widen(const char t) {
switch (t) {
case 'c':
return 's';
case 's':
return 'i';
case 'i':
return 'l';
default: throw "unhandled type in widen!";
}
return '\0';
}
/// Narrow - Convert a type code into the next smaller type. short -> char,
/// float -> half float, etc.
static char Narrow(const char t) {
switch (t) {
case 's':
return 'c';
case 'i':
return 's';
case 'l':
return 'i';
case 'f':
return 'h';
default: throw "unhandled type in widen!";
}
return '\0';
}
/// For a particular StringRef, return the base type code, and whether it has
/// the quad-vector, polynomial, or unsigned modifiers set.
static char ClassifyType(StringRef ty, bool &quad