2006-03-03 02:32:46 +00:00
|
|
|
//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:37:13 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-03-03 02:32:46 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits information about intrinsic functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
#include "CodeGenIntrinsics.h"
|
2007-08-04 01:51:18 +00:00
|
|
|
#include "CodeGenTarget.h"
|
2012-05-17 15:55:41 +00:00
|
|
|
#include "SequenceToOffsetTable.h"
|
2012-06-11 15:37:55 +00:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2012-10-25 20:33:17 +00:00
|
|
|
#include "llvm/TableGen/Error.h"
|
2011-10-01 16:41:13 +00:00
|
|
|
#include "llvm/TableGen/Record.h"
|
2012-05-02 17:32:48 +00:00
|
|
|
#include "llvm/TableGen/StringMatcher.h"
|
2012-06-11 15:37:55 +00:00
|
|
|
#include "llvm/TableGen/TableGenBackend.h"
|
2006-03-15 02:51:05 +00:00
|
|
|
#include <algorithm>
|
2006-03-03 02:32:46 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
namespace {
|
|
|
|
class IntrinsicEmitter {
|
|
|
|
RecordKeeper &Records;
|
|
|
|
bool TargetOnly;
|
|
|
|
std::string TargetPrefix;
|
|
|
|
|
|
|
|
public:
|
|
|
|
IntrinsicEmitter(RecordKeeper &R, bool T)
|
|
|
|
: Records(R), TargetOnly(T) {}
|
|
|
|
|
|
|
|
void run(raw_ostream &OS);
|
|
|
|
|
|
|
|
void EmitPrefix(raw_ostream &OS);
|
|
|
|
|
|
|
|
void EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
|
|
|
|
void EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
|
|
|
|
raw_ostream &OS);
|
|
|
|
void EmitSuffix(raw_ostream &OS);
|
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
2006-03-03 02:32:46 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IntrinsicEmitter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-03 00:10:29 +00:00
|
|
|
void IntrinsicEmitter::run(raw_ostream &OS) {
|
2012-06-11 15:37:55 +00:00
|
|
|
emitSourceFileHeader("Intrinsic Function Source Fragment", OS);
|
|
|
|
|
2009-02-05 01:49:45 +00:00
|
|
|
std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
|
2012-06-11 15:37:55 +00:00
|
|
|
|
2009-02-05 01:49:45 +00:00
|
|
|
if (TargetOnly && !Ints.empty())
|
|
|
|
TargetPrefix = Ints[0].TargetPrefix;
|
2006-03-03 02:32:46 +00:00
|
|
|
|
2010-05-11 06:17:44 +00:00
|
|
|
EmitPrefix(OS);
|
|
|
|
|
2006-03-03 02:32:46 +00:00
|
|
|
// Emit the enum information.
|
|
|
|
EmitEnumInfo(Ints, OS);
|
2006-03-15 01:55:21 +00:00
|
|
|
|
|
|
|
// Emit the intrinsic ID -> name table.
|
|
|
|
EmitIntrinsicToNameTable(Ints, OS);
|
2009-02-24 23:17:49 +00:00
|
|
|
|
|
|
|
// Emit the intrinsic ID -> overload table.
|
|
|
|
EmitIntrinsicToOverloadTable(Ints, OS);
|
|
|
|
|
2006-03-09 20:34:19 +00:00
|
|
|
// Emit the function name recognizer.
|
|
|
|
EmitFnNameRecognizer(Ints, OS);
|
2006-03-15 01:55:21 +00:00
|
|
|
|
2007-02-07 20:38:26 +00:00
|
|
|
// Emit the intrinsic declaration generator.
|
|
|
|
EmitGenerator(Ints, OS);
|
|
|
|
|
2007-12-03 20:06:50 +00:00
|
|
|
// Emit the intrinsic parameter attributes.
|
|
|
|
EmitAttributes(Ints, OS);
|
2006-03-13 23:08:44 +00:00
|
|
|
|
2009-02-14 10:56:35 +00:00
|
|
|
// Emit intrinsic alias analysis mod/ref behavior.
|
|
|
|
EmitModRefBehavior(Ints, OS);
|
|
|
|
|
2006-03-15 01:33:26 +00:00
|
|
|
// Emit code to translate GCC builtins into LLVM intrinsics.
|
|
|
|
EmitIntrinsicToGCCBuiltinMap(Ints, OS);
|
2010-05-11 06:17:44 +00:00
|
|
|
|
|
|
|
EmitSuffix(OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) {
|
|
|
|
OS << "// VisualStudio defines setjmp as _setjmp\n"
|
2010-09-24 19:48:47 +00:00
|
|
|
"#if defined(_MSC_VER) && defined(setjmp) && \\\n"
|
|
|
|
" !defined(setjmp_undefined_for_msvc)\n"
|
2010-09-14 04:27:38 +00:00
|
|
|
"# pragma push_macro(\"setjmp\")\n"
|
|
|
|
"# undef setjmp\n"
|
2010-09-24 19:48:47 +00:00
|
|
|
"# define setjmp_undefined_for_msvc\n"
|
2010-05-11 06:17:44 +00:00
|
|
|
"#endif\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
|
2010-09-24 19:48:47 +00:00
|
|
|
OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n"
|
2010-05-11 06:17:44 +00:00
|
|
|
"// let's return it to _setjmp state\n"
|
2010-09-14 04:27:38 +00:00
|
|
|
"# pragma pop_macro(\"setjmp\")\n"
|
2010-09-24 19:48:47 +00:00
|
|
|
"# undef setjmp_undefined_for_msvc\n"
|
2010-05-11 06:17:44 +00:00
|
|
|
"#endif\n\n";
|
2006-03-03 02:32:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2006-03-09 20:34:19 +00:00
|
|
|
OS << "// Enum values for Intrinsics.h\n";
|
2006-03-03 02:32:46 +00:00
|
|
|
OS << "#ifdef GET_INTRINSIC_ENUM_VALUES\n";
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
OS << " " << Ints[i].EnumName;
|
|
|
|
OS << ((i != e-1) ? ", " : " ");
|
|
|
|
OS << std::string(40-Ints[i].EnumName.size(), ' ')
|
|
|
|
<< "// " << Ints[i].Name << "\n";
|
|
|
|
}
|
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
2006-03-09 20:34:19 +00:00
|
|
|
|
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2010-09-06 03:58:45 +00:00
|
|
|
// Build a 'first character of function name' -> intrinsic # mapping.
|
|
|
|
std::map<char, std::vector<unsigned> > IntMapping;
|
2006-03-09 20:34:19 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
2010-09-06 03:58:45 +00:00
|
|
|
IntMapping[Ints[i].Name[5]].push_back(i);
|
|
|
|
|
2006-03-09 20:34:19 +00:00
|
|
|
OS << "// Function name -> enum value recognizer code.\n";
|
|
|
|
OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
|
2010-09-06 03:58:45 +00:00
|
|
|
OS << " StringRef NameR(Name+6, Len-6); // Skip over 'llvm.'\n";
|
|
|
|
OS << " switch (Name[5]) { // Dispatch on first letter.\n";
|
|
|
|
OS << " default: break;\n";
|
|
|
|
// Emit the intrinsic matching stuff by first letter.
|
|
|
|
for (std::map<char, std::vector<unsigned> >::iterator I = IntMapping.begin(),
|
2006-03-09 20:34:19 +00:00
|
|
|
E = IntMapping.end(); I != E; ++I) {
|
2010-09-06 03:58:45 +00:00
|
|
|
OS << " case '" << I->first << "':\n";
|
|
|
|
std::vector<unsigned> &IntList = I->second;
|
|
|
|
|
|
|
|
// Emit all the overloaded intrinsics first, build a table of the
|
|
|
|
// non-overloaded ones.
|
|
|
|
std::vector<StringMatcher::StringPair> MatchTable;
|
2006-03-09 20:34:19 +00:00
|
|
|
|
2010-09-06 03:58:45 +00:00
|
|
|
for (unsigned i = 0, e = IntList.size(); i != e; ++i) {
|
|
|
|
unsigned IntNo = IntList[i];
|
|
|
|
std::string Result = "return " + TargetPrefix + "Intrinsic::" +
|
|
|
|
Ints[IntNo].EnumName + ";";
|
|
|
|
|
|
|
|
if (!Ints[IntNo].isOverloaded) {
|
|
|
|
MatchTable.push_back(std::make_pair(Ints[IntNo].Name.substr(6),Result));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For overloaded intrinsics, only the prefix needs to match
|
|
|
|
std::string TheStr = Ints[IntNo].Name.substr(6);
|
2010-09-06 01:44:44 +00:00
|
|
|
TheStr += '.'; // Require "bswap." instead of bswap.
|
2010-09-06 03:58:45 +00:00
|
|
|
OS << " if (NameR.startswith(\"" << TheStr << "\")) "
|
|
|
|
<< Result << '\n';
|
2010-09-06 01:44:44 +00:00
|
|
|
}
|
2010-09-06 03:58:45 +00:00
|
|
|
|
|
|
|
// Emit the matcher logic for the fixed length strings.
|
|
|
|
StringMatcher("NameR", MatchTable, OS).Emit(1);
|
|
|
|
OS << " break; // end of '" << I->first << "' case.\n";
|
2006-03-09 20:34:19 +00:00
|
|
|
}
|
2010-09-06 03:58:45 +00:00
|
|
|
|
2006-03-09 20:34:19 +00:00
|
|
|
OS << " }\n";
|
2006-03-09 22:05:04 +00:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2006-03-15 01:55:21 +00:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2006-03-15 01:55:21 +00:00
|
|
|
OS << "// Intrinsic ID to name table\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_NAME_TABLE\n";
|
|
|
|
OS << " // Note that entry #0 is the invalid intrinsic!\n";
|
2006-03-28 22:25:56 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
|
|
|
OS << " \"" << Ints[i].Name << "\",\n";
|
2006-03-15 01:55:21 +00:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2009-02-24 23:17:49 +00:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2012-03-01 02:16:57 +00:00
|
|
|
OS << "// Intrinsic ID to overload bitset\n";
|
2009-02-24 23:17:49 +00:00
|
|
|
OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
|
2012-03-01 02:16:57 +00:00
|
|
|
OS << "static const uint8_t OTable[] = {\n";
|
|
|
|
OS << " 0";
|
2009-02-24 23:17:49 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2012-03-01 02:16:57 +00:00
|
|
|
// Add one to the index so we emit a null bit for the invalid #0 intrinsic.
|
|
|
|
if ((i+1)%8 == 0)
|
|
|
|
OS << ",\n 0";
|
2009-02-24 23:17:49 +00:00
|
|
|
if (Ints[i].isOverloaded)
|
2012-03-01 02:16:57 +00:00
|
|
|
OS << " | (1<<" << (i+1)%8 << ')';
|
2009-02-24 23:17:49 +00:00
|
|
|
}
|
2012-03-01 02:16:57 +00:00
|
|
|
OS << "\n};\n\n";
|
|
|
|
// OTable contains a true bit at the position if the intrinsic is overloaded.
|
|
|
|
OS << "return (OTable[id/8] & (1 << (id%8))) != 0;\n";
|
2009-02-24 23:17:49 +00:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2012-05-16 06:34:44 +00:00
|
|
|
|
2012-05-27 18:28:35 +00:00
|
|
|
// NOTE: This must be kept in synch with the copy in lib/VMCore/Function.cpp!
|
2012-05-16 06:34:44 +00:00
|
|
|
enum IIT_Info {
|
2012-05-17 04:30:58 +00:00
|
|
|
// Common values should be encoded with 0-15.
|
2012-05-16 06:34:44 +00:00
|
|
|
IIT_Done = 0,
|
|
|
|
IIT_I1 = 1,
|
|
|
|
IIT_I8 = 2,
|
|
|
|
IIT_I16 = 3,
|
|
|
|
IIT_I32 = 4,
|
|
|
|
IIT_I64 = 5,
|
2013-01-11 01:45:05 +00:00
|
|
|
IIT_F16 = 6,
|
|
|
|
IIT_F32 = 7,
|
|
|
|
IIT_F64 = 8,
|
|
|
|
IIT_V2 = 9,
|
|
|
|
IIT_V4 = 10,
|
|
|
|
IIT_V8 = 11,
|
|
|
|
IIT_V16 = 12,
|
|
|
|
IIT_V32 = 13,
|
2012-05-17 05:03:24 +00:00
|
|
|
IIT_PTR = 14,
|
|
|
|
IIT_ARG = 15,
|
2013-01-11 01:45:05 +00:00
|
|
|
|
2012-05-17 04:30:58 +00:00
|
|
|
// Values from 16+ are only encodable with the inefficient encoding.
|
2013-01-11 01:45:05 +00:00
|
|
|
IIT_MMX = 16,
|
|
|
|
IIT_METADATA = 17,
|
|
|
|
IIT_EMPTYSTRUCT = 18,
|
|
|
|
IIT_STRUCT2 = 19,
|
|
|
|
IIT_STRUCT3 = 20,
|
|
|
|
IIT_STRUCT4 = 21,
|
|
|
|
IIT_STRUCT5 = 22,
|
|
|
|
IIT_EXTEND_VEC_ARG = 23,
|
|
|
|
IIT_TRUNC_VEC_ARG = 24,
|
|
|
|
IIT_ANYPTR = 25
|
2012-05-16 06:34:44 +00:00
|
|
|
};
|
|
|
|
|
2012-05-17 04:30:58 +00:00
|
|
|
|
2012-05-16 06:34:44 +00:00
|
|
|
static void EncodeFixedValueType(MVT::SimpleValueType VT,
|
2012-05-17 15:55:41 +00:00
|
|
|
std::vector<unsigned char> &Sig) {
|
2012-05-16 06:34:44 +00:00
|
|
|
if (EVT(VT).isInteger()) {
|
|
|
|
unsigned BitWidth = EVT(VT).getSizeInBits();
|
|
|
|
switch (BitWidth) {
|
2012-10-25 20:33:17 +00:00
|
|
|
default: PrintFatalError("unhandled integer type width in intrinsic!");
|
2012-05-16 06:34:44 +00:00
|
|
|
case 1: return Sig.push_back(IIT_I1);
|
|
|
|
case 8: return Sig.push_back(IIT_I8);
|
|
|
|
case 16: return Sig.push_back(IIT_I16);
|
|
|
|
case 32: return Sig.push_back(IIT_I32);
|
|
|
|
case 64: return Sig.push_back(IIT_I64);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-17 04:30:58 +00:00
|
|
|
switch (VT) {
|
2012-10-25 20:33:17 +00:00
|
|
|
default: PrintFatalError("unhandled MVT in intrinsic!");
|
2013-01-11 01:45:05 +00:00
|
|
|
case MVT::f16: return Sig.push_back(IIT_F16);
|
2012-05-17 04:30:58 +00:00
|
|
|
case MVT::f32: return Sig.push_back(IIT_F32);
|
|
|
|
case MVT::f64: return Sig.push_back(IIT_F64);
|
|
|
|
case MVT::Metadata: return Sig.push_back(IIT_METADATA);
|
|
|
|
case MVT::x86mmx: return Sig.push_back(IIT_MMX);
|
|
|
|
// MVT::OtherVT is used to mean the empty struct type here.
|
|
|
|
case MVT::Other: return Sig.push_back(IIT_EMPTYSTRUCT);
|
|
|
|
}
|
2012-05-16 06:34:44 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 04:00:03 +00:00
|
|
|
#ifdef _MSC_VER
|
2012-05-17 03:38:19 +00:00
|
|
|
#pragma optimize("",off) // MSVC 2010 optimizer can't deal with this function.
|
2012-05-17 04:00:03 +00:00
|
|
|
#endif
|
2012-05-16 06:34:44 +00:00
|
|
|
|
2012-05-27 16:39:08 +00:00
|
|
|
static void EncodeFixedType(Record *R, std::vector<unsigned char> &ArgCodes,
|
2012-05-17 15:55:41 +00:00
|
|
|
std::vector<unsigned char> &Sig) {
|
2012-05-16 06:34:44 +00:00
|
|
|
|
|
|
|
if (R->isSubClassOf("LLVMMatchType")) {
|
2012-05-17 04:30:58 +00:00
|
|
|
unsigned Number = R->getValueAsInt("Number");
|
2012-05-27 16:39:08 +00:00
|
|
|
assert(Number < ArgCodes.size() && "Invalid matching number!");
|
2012-05-17 04:30:58 +00:00
|
|
|
if (R->isSubClassOf("LLVMExtendedElementVectorType"))
|
2012-05-17 05:03:24 +00:00
|
|
|
Sig.push_back(IIT_EXTEND_VEC_ARG);
|
|
|
|
else if (R->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
Sig.push_back(IIT_TRUNC_VEC_ARG);
|
|
|
|
else
|
|
|
|
Sig.push_back(IIT_ARG);
|
2012-05-27 16:39:08 +00:00
|
|
|
return Sig.push_back((Number << 2) | ArgCodes[Number]);
|
2012-05-16 06:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MVT::SimpleValueType VT = getValueType(R->getValueAsDef("VT"));
|
2012-05-17 04:30:58 +00:00
|
|
|
|
2012-05-27 16:39:08 +00:00
|
|
|
unsigned Tmp = 0;
|
2012-05-26 23:03:52 +00:00
|
|
|
switch (VT) {
|
|
|
|
default: break;
|
2012-05-27 16:39:08 +00:00
|
|
|
case MVT::iPTRAny: ++Tmp; // FALL THROUGH.
|
|
|
|
case MVT::vAny: ++Tmp; // FALL THROUGH.
|
|
|
|
case MVT::fAny: ++Tmp; // FALL THROUGH.
|
|
|
|
case MVT::iAny: {
|
2012-05-26 23:03:52 +00:00
|
|
|
// If this is an "any" valuetype, then the type is the type of the next
|
|
|
|
// type in the list specified to getIntrinsic().
|
2012-05-17 04:30:58 +00:00
|
|
|
Sig.push_back(IIT_ARG);
|
2012-05-27 16:39:08 +00:00
|
|
|
|
|
|
|
// Figure out what arg # this is consuming, and remember what kind it was.
|
|
|
|
unsigned ArgNo = ArgCodes.size();
|
|
|
|
ArgCodes.push_back(Tmp);
|
|
|
|
|
|
|
|
// Encode what sort of argument it must be in the low 2 bits of the ArgNo.
|
|
|
|
return Sig.push_back((ArgNo << 2) | Tmp);
|
|
|
|
}
|
2012-05-26 23:03:52 +00:00
|
|
|
|
|
|
|
case MVT::iPTR: {
|
|
|
|
unsigned AddrSpace = 0;
|
|
|
|
if (R->isSubClassOf("LLVMQualPointerType")) {
|
|
|
|
AddrSpace = R->getValueAsInt("AddrSpace");
|
|
|
|
assert(AddrSpace < 256 && "Address space exceeds 255");
|
|
|
|
}
|
|
|
|
if (AddrSpace) {
|
|
|
|
Sig.push_back(IIT_ANYPTR);
|
|
|
|
Sig.push_back(AddrSpace);
|
|
|
|
} else {
|
|
|
|
Sig.push_back(IIT_PTR);
|
|
|
|
}
|
2012-05-27 16:39:08 +00:00
|
|
|
return EncodeFixedType(R->getValueAsDef("ElTy"), ArgCodes, Sig);
|
2012-05-26 23:03:52 +00:00
|
|
|
}
|
2012-05-16 06:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (EVT(VT).isVector()) {
|
|
|
|
EVT VVT = VT;
|
|
|
|
switch (VVT.getVectorNumElements()) {
|
2012-10-25 20:33:17 +00:00
|
|
|
default: PrintFatalError("unhandled vector type width in intrinsic!");
|
2012-05-16 06:34:44 +00:00
|
|
|
case 2: Sig.push_back(IIT_V2); break;
|
|
|
|
case 4: Sig.push_back(IIT_V4); break;
|
|
|
|
case 8: Sig.push_back(IIT_V8); break;
|
|
|
|
case 16: Sig.push_back(IIT_V16); break;
|
2012-05-17 04:30:58 +00:00
|
|
|
case 32: Sig.push_back(IIT_V32); break;
|
2012-05-16 06:34:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return EncodeFixedValueType(VVT.getVectorElementType().
|
|
|
|
getSimpleVT().SimpleTy, Sig);
|
|
|
|
}
|
2012-05-26 23:03:52 +00:00
|
|
|
|
2012-05-16 06:34:44 +00:00
|
|
|
EncodeFixedValueType(VT, Sig);
|
|
|
|
}
|
2012-05-17 04:00:03 +00:00
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
2012-05-17 03:38:19 +00:00
|
|
|
#pragma optimize("",on)
|
2012-05-17 04:00:03 +00:00
|
|
|
#endif
|
2012-05-16 06:34:44 +00:00
|
|
|
|
|
|
|
/// ComputeFixedEncoding - If we can encode the type signature for this
|
|
|
|
/// intrinsic into 32 bits, return it. If not, return ~0U.
|
2012-05-17 15:55:41 +00:00
|
|
|
static void ComputeFixedEncoding(const CodeGenIntrinsic &Int,
|
|
|
|
std::vector<unsigned char> &TypeSig) {
|
2012-05-27 16:39:08 +00:00
|
|
|
std::vector<unsigned char> ArgCodes;
|
2012-05-17 04:30:58 +00:00
|
|
|
|
2012-05-16 06:34:44 +00:00
|
|
|
if (Int.IS.RetVTs.empty())
|
|
|
|
TypeSig.push_back(IIT_Done);
|
|
|
|
else if (Int.IS.RetVTs.size() == 1 &&
|
|
|
|
Int.IS.RetVTs[0] == MVT::isVoid)
|
|
|
|
TypeSig.push_back(IIT_Done);
|
2012-05-17 05:03:24 +00:00
|
|
|
else {
|
|
|
|
switch (Int.IS.RetVTs.size()) {
|
2012-05-17 15:55:41 +00:00
|
|
|
case 1: break;
|
|
|
|
case 2: TypeSig.push_back(IIT_STRUCT2); break;
|
|
|
|
case 3: TypeSig.push_back(IIT_STRUCT3); break;
|
|
|
|
case 4: TypeSig.push_back(IIT_STRUCT4); break;
|
|
|
|
case 5: TypeSig.push_back(IIT_STRUCT5); break;
|
|
|
|
default: assert(0 && "Unhandled case in struct");
|
2012-05-17 05:03:24 +00:00
|
|
|
}
|
2012-05-17 15:55:41 +00:00
|
|
|
|
2012-05-17 05:03:24 +00:00
|
|
|
for (unsigned i = 0, e = Int.IS.RetVTs.size(); i != e; ++i)
|
2012-05-27 16:39:08 +00:00
|
|
|
EncodeFixedType(Int.IS.RetTypeDefs[i], ArgCodes, TypeSig);
|
2012-05-17 05:03:24 +00:00
|
|
|
}
|
2012-05-16 06:34:44 +00:00
|
|
|
|
|
|
|
for (unsigned i = 0, e = Int.IS.ParamTypeDefs.size(); i != e; ++i)
|
2012-05-27 16:39:08 +00:00
|
|
|
EncodeFixedType(Int.IS.ParamTypeDefs[i], ArgCodes, TypeSig);
|
2012-05-17 15:55:41 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
static void printIITEntry(raw_ostream &OS, unsigned char X) {
|
2012-05-17 15:55:41 +00:00
|
|
|
OS << (unsigned)X;
|
2012-05-16 06:34:44 +00:00
|
|
|
}
|
|
|
|
|
2007-02-07 20:38:26 +00:00
|
|
|
void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2012-05-16 06:34:44 +00:00
|
|
|
// If we can compute a 32-bit fixed encoding for this intrinsic, do so and
|
|
|
|
// capture it in this vector, otherwise store a ~0U.
|
|
|
|
std::vector<unsigned> FixedEncodings;
|
2007-02-07 20:38:26 +00:00
|
|
|
|
2012-05-17 15:55:41 +00:00
|
|
|
SequenceToOffsetTable<std::vector<unsigned char> > LongEncodingTable;
|
|
|
|
|
|
|
|
std::vector<unsigned char> TypeSig;
|
|
|
|
|
2007-02-07 20:38:26 +00:00
|
|
|
// Compute the unique argument type info.
|
2012-05-16 06:34:44 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2012-05-17 15:55:41 +00:00
|
|
|
// Get the signature for the intrinsic.
|
|
|
|
TypeSig.clear();
|
|
|
|
ComputeFixedEncoding(Ints[i], TypeSig);
|
|
|
|
|
|
|
|
// Check to see if we can encode it into a 32-bit word. We can only encode
|
|
|
|
// 8 nibbles into a 32-bit word.
|
|
|
|
if (TypeSig.size() <= 8) {
|
|
|
|
bool Failed = false;
|
|
|
|
unsigned Result = 0;
|
|
|
|
for (unsigned i = 0, e = TypeSig.size(); i != e; ++i) {
|
|
|
|
// If we had an unencodable argument, bail out.
|
|
|
|
if (TypeSig[i] > 15) {
|
|
|
|
Failed = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Result = (Result << 4) | TypeSig[e-i-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this could be encoded into a 31-bit word, return it.
|
|
|
|
if (!Failed && (Result >> 31) == 0) {
|
|
|
|
FixedEncodings.push_back(Result);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we're going to unique the sequence into the
|
|
|
|
// LongEncodingTable, and use its offset in the 32-bit table instead.
|
|
|
|
LongEncodingTable.add(TypeSig);
|
|
|
|
|
|
|
|
// This is a placehold that we'll replace after the table is laid out.
|
|
|
|
FixedEncodings.push_back(~0U);
|
2012-05-16 06:34:44 +00:00
|
|
|
}
|
|
|
|
|
2012-05-17 15:55:41 +00:00
|
|
|
LongEncodingTable.layout();
|
|
|
|
|
2012-05-27 18:28:35 +00:00
|
|
|
OS << "// Global intrinsic function declaration type table.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_GENERATOR_GLOBAL\n";
|
|
|
|
|
2012-05-16 06:34:44 +00:00
|
|
|
OS << "static const unsigned IIT_Table[] = {\n ";
|
|
|
|
|
|
|
|
for (unsigned i = 0, e = FixedEncodings.size(); i != e; ++i) {
|
|
|
|
if ((i & 7) == 7)
|
|
|
|
OS << "\n ";
|
2012-05-17 15:55:41 +00:00
|
|
|
|
|
|
|
// If the entry fit in the table, just emit it.
|
|
|
|
if (FixedEncodings[i] != ~0U) {
|
2012-05-16 06:34:44 +00:00
|
|
|
OS << "0x" << utohexstr(FixedEncodings[i]) << ", ";
|
2012-05-17 15:55:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-02-07 20:38:26 +00:00
|
|
|
|
2012-05-17 15:55:41 +00:00
|
|
|
TypeSig.clear();
|
|
|
|
ComputeFixedEncoding(Ints[i], TypeSig);
|
2008-11-13 09:08:33 +00:00
|
|
|
|
2007-02-07 20:38:26 +00:00
|
|
|
|
2012-05-17 15:55:41 +00:00
|
|
|
// Otherwise, emit the offset into the long encoding table. We emit it this
|
|
|
|
// way so that it is easier to read the offset in the .def file.
|
|
|
|
OS << "(1U<<31) | " << LongEncodingTable.get(TypeSig) << ", ";
|
2007-02-07 20:38:26 +00:00
|
|
|
}
|
2012-05-17 15:55:41 +00:00
|
|
|
|
|
|
|
OS << "0\n};\n\n";
|
|
|
|
|
|
|
|
// Emit the shared table of register lists.
|
|
|
|
OS << "static const unsigned char IIT_LongEncodingTable[] = {\n";
|
|
|
|
if (!LongEncodingTable.empty())
|
|
|
|
LongEncodingTable.emit(OS, printIITEntry);
|
|
|
|
OS << " 255\n};\n\n";
|
|
|
|
|
2012-05-23 12:34:56 +00:00
|
|
|
OS << "#endif\n\n"; // End of GET_INTRINSIC_GENERATOR_GLOBAL
|
2007-02-07 20:38:26 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
enum ModRefKind {
|
|
|
|
MRK_none,
|
|
|
|
MRK_readonly,
|
|
|
|
MRK_readnone
|
|
|
|
};
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
static ModRefKind getModRefKind(const CodeGenIntrinsic &intrinsic) {
|
|
|
|
switch (intrinsic.ModRef) {
|
|
|
|
case CodeGenIntrinsic::NoMem:
|
|
|
|
return MRK_readnone;
|
|
|
|
case CodeGenIntrinsic::ReadArgMem:
|
|
|
|
case CodeGenIntrinsic::ReadMem:
|
|
|
|
return MRK_readonly;
|
|
|
|
case CodeGenIntrinsic::ReadWriteArgMem:
|
|
|
|
case CodeGenIntrinsic::ReadWriteMem:
|
|
|
|
return MRK_none;
|
|
|
|
}
|
|
|
|
llvm_unreachable("bad mod-ref kind");
|
2011-05-28 06:31:34 +00:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:37:55 +00:00
|
|
|
namespace {
|
|
|
|
struct AttributeComparator {
|
|
|
|
bool operator()(const CodeGenIntrinsic *L, const CodeGenIntrinsic *R) const {
|
|
|
|
// Sort throwing intrinsics after non-throwing intrinsics.
|
|
|
|
if (L->canThrow != R->canThrow)
|
|
|
|
return R->canThrow;
|
|
|
|
|
|
|
|
if (L->isNoReturn != R->isNoReturn)
|
|
|
|
return R->isNoReturn;
|
|
|
|
|
|
|
|
// Try to order by readonly/readnone attribute.
|
|
|
|
ModRefKind LK = getModRefKind(*L);
|
|
|
|
ModRefKind RK = getModRefKind(*R);
|
|
|
|
if (LK != RK) return (LK > RK);
|
|
|
|
|
|
|
|
// Order by argument attributes.
|
|
|
|
// This is reliable because each side is already sorted internally.
|
|
|
|
return (L->ArgumentAttributes < R->ArgumentAttributes);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // End anonymous namespace
|
|
|
|
|
2009-01-12 01:18:58 +00:00
|
|
|
/// EmitAttributes - This emits the Intrinsic::getAttributes method.
|
2006-03-24 01:13:55 +00:00
|
|
|
void IntrinsicEmitter::
|
2009-07-03 00:10:29 +00:00
|
|
|
EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
|
2007-12-03 20:06:50 +00:00
|
|
|
OS << "// Add parameter attributes that are not common to all intrinsics.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
|
2009-02-05 01:49:45 +00:00
|
|
|
if (TargetOnly)
|
2012-12-07 23:16:57 +00:00
|
|
|
OS << "static AttributeSet getAttributes(LLVMContext &C, " << TargetPrefix
|
2011-05-28 06:31:34 +00:00
|
|
|
<< "Intrinsic::ID id) {\n";
|
2009-02-05 01:49:45 +00:00
|
|
|
else
|
2012-12-07 23:16:57 +00:00
|
|
|
OS << "AttributeSet Intrinsic::getAttributes(LLVMContext &C, ID id) {\n";
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2012-02-28 06:32:00 +00:00
|
|
|
// Compute the maximum number of attribute arguments and the map
|
|
|
|
typedef std::map<const CodeGenIntrinsic*, unsigned,
|
|
|
|
AttributeComparator> UniqAttrMapTy;
|
|
|
|
UniqAttrMapTy UniqAttributes;
|
2011-05-28 06:31:34 +00:00
|
|
|
unsigned maxArgAttrs = 0;
|
2012-02-28 06:32:00 +00:00
|
|
|
unsigned AttrNum = 0;
|
2006-03-09 22:37:52 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2011-05-28 06:31:34 +00:00
|
|
|
const CodeGenIntrinsic &intrinsic = Ints[i];
|
|
|
|
maxArgAttrs =
|
|
|
|
std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size()));
|
2012-02-28 06:32:00 +00:00
|
|
|
unsigned &N = UniqAttributes[&intrinsic];
|
|
|
|
if (N) continue;
|
|
|
|
assert(AttrNum < 256 && "Too many unique attributes for table!");
|
|
|
|
N = ++AttrNum;
|
2006-03-09 22:37:52 +00:00
|
|
|
}
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2013-01-27 03:25:05 +00:00
|
|
|
// Emit an array of AttributeSet. Most intrinsics will have at least one
|
|
|
|
// entry, for the function itself (index ~1), which is usually nounwind.
|
2012-02-28 06:32:00 +00:00
|
|
|
OS << " static const uint8_t IntrinsicsToAttributesMap[] = {\n";
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2012-02-28 06:32:00 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
const CodeGenIntrinsic &intrinsic = Ints[i];
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2012-02-28 06:32:00 +00:00
|
|
|
OS << " " << UniqAttributes[&intrinsic] << ", // "
|
|
|
|
<< intrinsic.Name << "\n";
|
|
|
|
}
|
|
|
|
OS << " };\n\n";
|
2009-01-12 01:27:55 +00:00
|
|
|
|
2013-01-27 03:25:05 +00:00
|
|
|
OS << " AttributeSet AS[" << maxArgAttrs+1 << "];\n";
|
2012-02-28 06:32:00 +00:00
|
|
|
OS << " unsigned NumAttrs = 0;\n";
|
2012-04-13 06:14:57 +00:00
|
|
|
OS << " if (id != 0) {\n";
|
2012-12-22 00:37:52 +00:00
|
|
|
OS << " SmallVector<Attribute::AttrKind, 8> AttrVec;\n";
|
2012-04-13 06:14:57 +00:00
|
|
|
OS << " switch(IntrinsicsToAttributesMap[id - ";
|
|
|
|
if (TargetOnly)
|
|
|
|
OS << "Intrinsic::num_intrinsics";
|
|
|
|
else
|
|
|
|
OS << "1";
|
|
|
|
OS << "]) {\n";
|
|
|
|
OS << " default: llvm_unreachable(\"Invalid attribute number\");\n";
|
2012-02-28 06:32:00 +00:00
|
|
|
for (UniqAttrMapTy::const_iterator I = UniqAttributes.begin(),
|
|
|
|
E = UniqAttributes.end(); I != E; ++I) {
|
2012-04-13 06:14:57 +00:00
|
|
|
OS << " case " << I->second << ":\n";
|
2009-01-12 01:27:55 +00:00
|
|
|
|
2012-02-28 06:32:00 +00:00
|
|
|
const CodeGenIntrinsic &intrinsic = *(I->first);
|
2011-05-28 06:31:34 +00:00
|
|
|
|
|
|
|
// Keep track of the number of attributes we're writing out.
|
|
|
|
unsigned numAttrs = 0;
|
2009-01-12 01:27:55 +00:00
|
|
|
|
2011-05-28 06:31:34 +00:00
|
|
|
// The argument attributes are alreadys sorted by argument index.
|
2012-10-10 06:13:42 +00:00
|
|
|
unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size();
|
|
|
|
if (ae) {
|
|
|
|
while (ai != ae) {
|
|
|
|
unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
|
2012-02-28 06:32:00 +00:00
|
|
|
|
2012-10-10 06:13:42 +00:00
|
|
|
OS << " AttrVec.clear();\n";
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2012-10-10 06:13:42 +00:00
|
|
|
do {
|
|
|
|
switch (intrinsic.ArgumentAttributes[ai].second) {
|
|
|
|
case CodeGenIntrinsic::NoCapture:
|
2012-12-19 07:18:57 +00:00
|
|
|
OS << " AttrVec.push_back(Attribute::NoCapture);\n";
|
2012-10-10 06:13:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-12 02:41:37 +00:00
|
|
|
|
2012-10-10 06:13:42 +00:00
|
|
|
++ai;
|
|
|
|
} while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
|
2011-05-28 06:31:34 +00:00
|
|
|
|
2013-01-27 03:25:05 +00:00
|
|
|
OS << " AS[" << numAttrs++ << "] = AttributeSet::get(C, "
|
2012-10-10 06:13:42 +00:00
|
|
|
<< argNo+1 << ", AttrVec);\n";
|
|
|
|
}
|
2011-05-28 06:31:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ModRefKind modRef = getModRefKind(intrinsic);
|
|
|
|
|
2012-05-27 23:20:41 +00:00
|
|
|
if (!intrinsic.canThrow || modRef || intrinsic.isNoReturn) {
|
2012-10-10 06:13:42 +00:00
|
|
|
OS << " AttrVec.clear();\n";
|
|
|
|
|
|
|
|
if (!intrinsic.canThrow)
|
2012-12-19 07:18:57 +00:00
|
|
|
OS << " AttrVec.push_back(Attribute::NoUnwind);\n";
|
2012-10-10 06:13:42 +00:00
|
|
|
if (intrinsic.isNoReturn)
|
2012-12-19 07:18:57 +00:00
|
|
|
OS << " AttrVec.push_back(Attribute::NoReturn);\n";
|
2012-05-27 23:20:41 +00:00
|
|
|
|
2011-05-28 06:31:34 +00:00
|
|
|
switch (modRef) {
|
|
|
|
case MRK_none: break;
|
2012-05-27 23:20:41 +00:00
|
|
|
case MRK_readonly:
|
2012-12-19 07:18:57 +00:00
|
|
|
OS << " AttrVec.push_back(Attribute::ReadOnly);\n";
|
2012-05-27 23:20:41 +00:00
|
|
|
break;
|
|
|
|
case MRK_readnone:
|
2012-12-19 07:18:57 +00:00
|
|
|
OS << " AttrVec.push_back(Attribute::ReadNone);\n";
|
2012-05-27 23:20:41 +00:00
|
|
|
break;
|
2009-01-12 02:41:37 +00:00
|
|
|
}
|
2013-01-27 03:25:05 +00:00
|
|
|
OS << " AS[" << numAttrs++ << "] = AttributeSet::get(C, "
|
2012-12-07 23:16:57 +00:00
|
|
|
<< "AttributeSet::FunctionIndex, AttrVec);\n";
|
2009-01-12 02:41:37 +00:00
|
|
|
}
|
2011-05-28 06:31:34 +00:00
|
|
|
|
|
|
|
if (numAttrs) {
|
2012-04-13 06:14:57 +00:00
|
|
|
OS << " NumAttrs = " << numAttrs << ";\n";
|
|
|
|
OS << " break;\n";
|
2011-05-28 06:31:34 +00:00
|
|
|
} else {
|
2012-12-07 23:16:57 +00:00
|
|
|
OS << " return AttributeSet();\n";
|
2011-05-28 06:31:34 +00:00
|
|
|
}
|
2009-01-12 01:27:55 +00:00
|
|
|
}
|
|
|
|
|
2012-04-13 06:14:57 +00:00
|
|
|
OS << " }\n";
|
2009-01-12 01:27:55 +00:00
|
|
|
OS << " }\n";
|
2013-01-27 03:25:05 +00:00
|
|
|
OS << " return AttributeSet::get(C, ArrayRef<AttributeSet>(AS, "
|
2012-05-28 01:47:44 +00:00
|
|
|
"NumAttrs));\n";
|
2009-01-12 01:18:58 +00:00
|
|
|
OS << "}\n";
|
2009-01-12 02:41:37 +00:00
|
|
|
OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
|
2006-03-09 22:37:52 +00:00
|
|
|
}
|
2006-03-13 23:08:44 +00:00
|
|
|
|
2009-02-14 10:56:35 +00:00
|
|
|
/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
|
|
|
|
void IntrinsicEmitter::
|
2009-07-03 00:10:29 +00:00
|
|
|
EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << "// Determine intrinsic alias analysis mod/ref behavior.\n"
|
|
|
|
<< "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n"
|
|
|
|
<< "assert(iid <= Intrinsic::" << Ints.back().EnumName << " && "
|
|
|
|
<< "\"Unknown intrinsic.\");\n\n";
|
|
|
|
|
|
|
|
OS << "static const uint8_t IntrinsicModRefBehavior[] = {\n"
|
|
|
|
<< " /* invalid */ UnknownModRefBehavior,\n";
|
2009-02-14 10:56:35 +00:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << " /* " << TargetPrefix << Ints[i].EnumName << " */ ";
|
2009-02-14 10:56:35 +00:00
|
|
|
switch (Ints[i].ModRef) {
|
|
|
|
case CodeGenIntrinsic::NoMem:
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << "DoesNotAccessMemory,\n";
|
2009-02-14 10:56:35 +00:00
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadArgMem:
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << "OnlyReadsArgumentPointees,\n";
|
2010-11-09 20:07:20 +00:00
|
|
|
break;
|
2009-02-14 10:56:35 +00:00
|
|
|
case CodeGenIntrinsic::ReadMem:
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << "OnlyReadsMemory,\n";
|
2009-02-14 10:56:35 +00:00
|
|
|
break;
|
2010-08-05 23:36:21 +00:00
|
|
|
case CodeGenIntrinsic::ReadWriteArgMem:
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << "OnlyAccessesArgumentPointees,\n";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadWriteMem:
|
|
|
|
OS << "UnknownModRefBehavior,\n";
|
2009-02-14 10:56:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 01:18:32 +00:00
|
|
|
OS << "};\n\n"
|
|
|
|
<< "return static_cast<ModRefBehavior>(IntrinsicModRefBehavior[iid]);\n"
|
|
|
|
<< "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
|
2009-02-14 10:56:35 +00:00
|
|
|
}
|
|
|
|
|
2008-01-04 04:38:35 +00:00
|
|
|
/// EmitTargetBuiltins - All of the builtins in the specified map are for the
|
|
|
|
/// same target, and we already checked it.
|
|
|
|
static void EmitTargetBuiltins(const std::map<std::string, std::string> &BIM,
|
2009-02-05 01:49:45 +00:00
|
|
|
const std::string &TargetPrefix,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2008-01-04 04:38:35 +00:00
|
|
|
|
2010-09-06 03:14:45 +00:00
|
|
|
std::vector<StringMatcher::StringPair> Results;
|
2008-01-04 04:38:35 +00:00
|
|
|
|
2010-09-06 03:14:45 +00:00
|
|
|
for (std::map<std::string, std::string>::const_iterator I = BIM.begin(),
|
|
|
|
E = BIM.end(); I != E; ++I) {
|
|
|
|
std::string ResultCode =
|
|
|
|
"return " + TargetPrefix + "Intrinsic::" + I->second + ";";
|
|
|
|
Results.push_back(StringMatcher::StringPair(I->first, ResultCode));
|
2008-01-04 04:38:35 +00:00
|
|
|
}
|
2010-09-06 03:14:45 +00:00
|
|
|
|
|
|
|
StringMatcher("BuiltinName", Results, OS).Emit();
|
2008-01-04 04:38:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-15 01:33:26 +00:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 00:10:29 +00:00
|
|
|
raw_ostream &OS) {
|
2008-01-02 21:24:22 +00:00
|
|
|
typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
|
2006-03-15 01:33:26 +00:00
|
|
|
BIMTy BuiltinMap;
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
if (!Ints[i].GCCBuiltinName.empty()) {
|
2008-01-02 21:24:22 +00:00
|
|
|
// Get the map for this target prefix.
|
|
|
|
std::map<std::string, std::string> &BIM =BuiltinMap[Ints[i].TargetPrefix];
|
|
|
|
|
|
|
|
if (!BIM.insert(std::make_pair(Ints[i].GCCBuiltinName,
|
|
|
|
Ints[i].EnumName)).second)
|
2012-10-25 20:33:17 +00:00
|
|
|
PrintFatalError("Intrinsic '" + Ints[i].TheDef->getName() +
|
|
|
|
"': duplicate GCC builtin name!");
|
2006-03-15 01:33:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OS << "// Get the LLVM intrinsic that corresponds to a GCC builtin.\n";
|
|
|
|
OS << "// This is used by the C front-end. The GCC builtin name is passed\n";
|
|
|
|
OS << "// in as BuiltinName, and a target prefix (e.g. 'ppc') is passed\n";
|
|
|
|
OS << "// in as TargetPrefix. The result is assigned to 'IntrinsicID'.\n";
|
|
|
|
OS << "#ifdef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN\n";
|
2009-02-05 01:49:45 +00:00
|
|
|
|
|
|
|
if (TargetOnly) {
|
|
|
|
OS << "static " << TargetPrefix << "Intrinsic::ID "
|
|
|
|
<< "getIntrinsicForGCCBuiltin(const char "
|
2010-09-06 03:14:45 +00:00
|
|
|
<< "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
|
2009-02-05 01:49:45 +00:00
|
|
|
} else {
|
|
|
|
OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
|
2010-09-06 03:14:45 +00:00
|
|
|
<< "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
|
2009-02-05 01:49:45 +00:00
|
|
|
}
|
|
|
|
|
2010-09-06 03:14:45 +00:00
|
|
|
OS << " StringRef BuiltinName(BuiltinNameStr);\n";
|
|
|
|
OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
|
2008-01-04 04:38:35 +00:00
|
|
|
|
2006-03-15 01:33:26 +00:00
|
|
|
// Note: this could emit significantly better code if we cared.
|
|
|
|
for (BIMTy::iterator I = BuiltinMap.begin(), E = BuiltinMap.end();I != E;++I){
|
2008-01-02 21:24:22 +00:00
|
|
|
OS << " ";
|
|
|
|
if (!I->first.empty())
|
2010-09-06 03:14:45 +00:00
|
|
|
OS << "if (TargetPrefix == \"" << I->first << "\") ";
|
2008-01-02 21:24:22 +00:00
|
|
|
else
|
|
|
|
OS << "/* Target Independent Builtins */ ";
|
|
|
|
OS << "{\n";
|
|
|
|
|
|
|
|
// Emit the comparisons for this target prefix.
|
2009-02-05 01:49:45 +00:00
|
|
|
EmitTargetBuiltins(I->second, TargetPrefix, OS);
|
2008-01-02 21:24:22 +00:00
|
|
|
OS << " }\n";
|
2006-03-15 01:33:26 +00:00
|
|
|
}
|
2010-09-06 03:14:45 +00:00
|
|
|
OS << " return ";
|
|
|
|
if (!TargetPrefix.empty())
|
|
|
|
OS << "(" << TargetPrefix << "Intrinsic::ID)";
|
|
|
|
OS << "Intrinsic::not_intrinsic;\n";
|
2009-02-05 01:49:45 +00:00
|
|
|
OS << "}\n";
|
2006-03-15 01:33:26 +00:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
2012-06-11 15:37:55 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
void EmitIntrinsics(RecordKeeper &RK, raw_ostream &OS, bool TargetOnly = false) {
|
|
|
|
IntrinsicEmitter(RK, TargetOnly).run(OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // End llvm namespace
|