2006-03-03 10:32:46 +08:00
|
|
|
//===- IntrinsicEmitter.cpp - Generate intrinsic information --------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-30 04:37:13 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2006-03-03 10:32:46 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This tablegen backend emits information about intrinsic functions.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
#include "CodeGenTarget.h"
|
2006-03-03 10:32:46 +08:00
|
|
|
#include "IntrinsicEmitter.h"
|
2010-09-06 11:14:45 +08:00
|
|
|
#include "StringMatcher.h"
|
2011-10-02 00:41:13 +08:00
|
|
|
#include "llvm/TableGen/Record.h"
|
2006-03-14 06:38:57 +08:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2006-03-15 10:51:05 +08:00
|
|
|
#include <algorithm>
|
2006-03-03 10:32:46 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// IntrinsicEmitter Implementation
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
void IntrinsicEmitter::run(raw_ostream &OS) {
|
2006-03-03 10:32:46 +08:00
|
|
|
EmitSourceFileHeader("Intrinsic Function Source Fragment", OS);
|
|
|
|
|
2009-02-05 09:49:45 +08:00
|
|
|
std::vector<CodeGenIntrinsic> Ints = LoadIntrinsics(Records, TargetOnly);
|
|
|
|
|
|
|
|
if (TargetOnly && !Ints.empty())
|
|
|
|
TargetPrefix = Ints[0].TargetPrefix;
|
2006-03-03 10:32:46 +08:00
|
|
|
|
2010-05-11 14:17:44 +08:00
|
|
|
EmitPrefix(OS);
|
|
|
|
|
2006-03-03 10:32:46 +08:00
|
|
|
// Emit the enum information.
|
|
|
|
EmitEnumInfo(Ints, OS);
|
2006-03-15 09:55:21 +08:00
|
|
|
|
|
|
|
// Emit the intrinsic ID -> name table.
|
|
|
|
EmitIntrinsicToNameTable(Ints, OS);
|
2009-02-25 07:17:49 +08:00
|
|
|
|
|
|
|
// Emit the intrinsic ID -> overload table.
|
|
|
|
EmitIntrinsicToOverloadTable(Ints, OS);
|
|
|
|
|
2006-03-10 04:34:19 +08:00
|
|
|
// Emit the function name recognizer.
|
|
|
|
EmitFnNameRecognizer(Ints, OS);
|
2006-03-15 09:55:21 +08:00
|
|
|
|
2006-03-10 06:05:04 +08:00
|
|
|
// Emit the intrinsic verifier.
|
|
|
|
EmitVerifier(Ints, OS);
|
2006-03-10 06:30:49 +08:00
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
// Emit the intrinsic declaration generator.
|
|
|
|
EmitGenerator(Ints, OS);
|
|
|
|
|
2007-12-04 04:06:50 +08:00
|
|
|
// Emit the intrinsic parameter attributes.
|
|
|
|
EmitAttributes(Ints, OS);
|
2006-03-14 07:08:44 +08:00
|
|
|
|
2009-02-14 18:56:35 +08:00
|
|
|
// Emit intrinsic alias analysis mod/ref behavior.
|
|
|
|
EmitModRefBehavior(Ints, OS);
|
|
|
|
|
2006-03-14 07:08:44 +08:00
|
|
|
// Emit a list of intrinsics with corresponding GCC builtins.
|
|
|
|
EmitGCCBuiltinList(Ints, OS);
|
2006-03-15 09:33:26 +08:00
|
|
|
|
|
|
|
// Emit code to translate GCC builtins into LLVM intrinsics.
|
|
|
|
EmitIntrinsicToGCCBuiltinMap(Ints, OS);
|
2010-05-11 14:17:44 +08:00
|
|
|
|
|
|
|
EmitSuffix(OS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitPrefix(raw_ostream &OS) {
|
|
|
|
OS << "// VisualStudio defines setjmp as _setjmp\n"
|
2010-09-25 03:48:47 +08:00
|
|
|
"#if defined(_MSC_VER) && defined(setjmp) && \\\n"
|
|
|
|
" !defined(setjmp_undefined_for_msvc)\n"
|
2010-09-14 12:27:38 +08:00
|
|
|
"# pragma push_macro(\"setjmp\")\n"
|
|
|
|
"# undef setjmp\n"
|
2010-09-25 03:48:47 +08:00
|
|
|
"# define setjmp_undefined_for_msvc\n"
|
2010-05-11 14:17:44 +08:00
|
|
|
"#endif\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitSuffix(raw_ostream &OS) {
|
2010-09-25 03:48:47 +08:00
|
|
|
OS << "#if defined(_MSC_VER) && defined(setjmp_undefined_for_msvc)\n"
|
2010-05-11 14:17:44 +08:00
|
|
|
"// let's return it to _setjmp state\n"
|
2010-09-14 12:27:38 +08:00
|
|
|
"# pragma pop_macro(\"setjmp\")\n"
|
2010-09-25 03:48:47 +08:00
|
|
|
"# undef setjmp_undefined_for_msvc\n"
|
2010-05-11 14:17:44 +08:00
|
|
|
"#endif\n\n";
|
2006-03-03 10:32:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void IntrinsicEmitter::EmitEnumInfo(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2006-03-10 04:34:19 +08:00
|
|
|
OS << "// Enum values for Intrinsics.h\n";
|
2006-03-03 10:32:46 +08: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-10 04:34:19 +08:00
|
|
|
|
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitFnNameRecognizer(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2010-09-06 11:58:45 +08:00
|
|
|
// Build a 'first character of function name' -> intrinsic # mapping.
|
|
|
|
std::map<char, std::vector<unsigned> > IntMapping;
|
2006-03-10 04:34:19 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
2010-09-06 11:58:45 +08:00
|
|
|
IntMapping[Ints[i].Name[5]].push_back(i);
|
|
|
|
|
2006-03-10 04:34:19 +08:00
|
|
|
OS << "// Function name -> enum value recognizer code.\n";
|
|
|
|
OS << "#ifdef GET_FUNCTION_RECOGNIZER\n";
|
2010-09-06 11:58:45 +08: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-10 04:34:19 +08:00
|
|
|
E = IntMapping.end(); I != E; ++I) {
|
2010-09-06 11:58:45 +08: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-10 04:34:19 +08:00
|
|
|
|
2010-09-06 11:58:45 +08: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 09:44:44 +08:00
|
|
|
TheStr += '.'; // Require "bswap." instead of bswap.
|
2010-09-06 11:58:45 +08:00
|
|
|
OS << " if (NameR.startswith(\"" << TheStr << "\")) "
|
|
|
|
<< Result << '\n';
|
2010-09-06 09:44:44 +08:00
|
|
|
}
|
2010-09-06 11:58:45 +08: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-10 04:34:19 +08:00
|
|
|
}
|
2010-09-06 11:58:45 +08:00
|
|
|
|
2006-03-10 04:34:19 +08:00
|
|
|
OS << " }\n";
|
2006-03-10 06:05:04 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2006-03-15 09:55:21 +08:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToNameTable(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2006-03-15 09:55:21 +08: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-29 06:25:56 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
|
|
|
OS << " \"" << Ints[i].Name << "\",\n";
|
2006-03-15 09:55:21 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2009-02-25 07:17:49 +08:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToOverloadTable(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2009-02-25 07:17:49 +08:00
|
|
|
OS << "// Intrinsic ID to overload table\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_OVERLOAD_TABLE\n";
|
|
|
|
OS << " // Note that entry #0 is the invalid intrinsic!\n";
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
OS << " ";
|
|
|
|
if (Ints[i].isOverloaded)
|
|
|
|
OS << "true";
|
|
|
|
else
|
|
|
|
OS << "false";
|
|
|
|
OS << ",\n";
|
|
|
|
}
|
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
static void EmitTypeForValueType(raw_ostream &OS, MVT::SimpleValueType VT) {
|
2009-08-11 06:56:29 +08:00
|
|
|
if (EVT(VT).isInteger()) {
|
|
|
|
unsigned BitWidth = EVT(VT).getSizeInBits();
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "IntegerType::get(Context, " << BitWidth << ")";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::Other) {
|
|
|
|
// MVT::OtherVT is used to mean the empty struct type here.
|
2009-08-06 07:16:16 +08:00
|
|
|
OS << "StructType::get(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::f32) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getFloatTy(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::f64) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getDoubleTy(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::f80) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getX86_FP80Ty(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::f128) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getFP128Ty(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::ppcf128) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getPPC_FP128Ty(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::isVoid) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getVoidTy(Context)";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::Metadata) {
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getMetadataTy(Context)";
|
2010-09-11 08:16:46 +08:00
|
|
|
} else if (VT == MVT::x86mmx) {
|
|
|
|
OS << "Type::getX86_MMXTy(Context)";
|
2007-08-04 09:51:18 +08:00
|
|
|
} else {
|
|
|
|
assert(false && "Unsupported ValueType!");
|
2006-03-14 06:38:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
|
2008-11-13 17:08:33 +08:00
|
|
|
unsigned &ArgNo);
|
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
static void EmitTypeGenerate(raw_ostream &OS,
|
2008-11-13 17:08:33 +08:00
|
|
|
const std::vector<Record*> &ArgTypes,
|
|
|
|
unsigned &ArgNo) {
|
2010-03-23 04:56:36 +08:00
|
|
|
if (ArgTypes.empty())
|
|
|
|
return EmitTypeForValueType(OS, MVT::isVoid);
|
|
|
|
|
|
|
|
if (ArgTypes.size() == 1)
|
|
|
|
return EmitTypeGenerate(OS, ArgTypes.front(), ArgNo);
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2011-06-19 06:48:56 +08:00
|
|
|
OS << "StructType::get(";
|
2008-11-13 17:08:33 +08:00
|
|
|
|
|
|
|
for (std::vector<Record*>::const_iterator
|
2008-11-13 18:18:35 +08:00
|
|
|
I = ArgTypes.begin(), E = ArgTypes.end(); I != E; ++I) {
|
2008-11-13 17:08:33 +08:00
|
|
|
EmitTypeGenerate(OS, *I, ArgNo);
|
2008-11-13 18:18:35 +08:00
|
|
|
OS << ", ";
|
|
|
|
}
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2008-11-13 18:18:35 +08:00
|
|
|
OS << " NULL)";
|
2008-11-13 17:08:33 +08:00
|
|
|
}
|
|
|
|
|
2009-07-03 08:10:29 +08:00
|
|
|
static void EmitTypeGenerate(raw_ostream &OS, const Record *ArgType,
|
2007-05-23 03:30:31 +08:00
|
|
|
unsigned &ArgNo) {
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
|
2007-08-04 09:51:18 +08:00
|
|
|
|
|
|
|
if (ArgType->isSubClassOf("LLVMMatchType")) {
|
|
|
|
unsigned Number = ArgType->getValueAsInt("Number");
|
|
|
|
assert(Number < ArgNo && "Invalid matching number!");
|
2009-01-07 08:09:01 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
|
|
|
|
OS << "VectorType::getExtendedElementVectorType"
|
|
|
|
<< "(dyn_cast<VectorType>(Tys[" << Number << "]))";
|
|
|
|
else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
OS << "VectorType::getTruncatedElementVectorType"
|
|
|
|
<< "(dyn_cast<VectorType>(Tys[" << Number << "]))";
|
|
|
|
else
|
|
|
|
OS << "Tys[" << Number << "]";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::iAny || VT == MVT::fAny || VT == MVT::vAny) {
|
2007-05-23 03:30:31 +08:00
|
|
|
// 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
|
2007-08-04 09:51:18 +08:00
|
|
|
// increment it when we actually hit an overloaded type. Getting this wrong
|
|
|
|
// leads to very subtle bugs!
|
|
|
|
OS << "Tys[" << ArgNo++ << "]";
|
2009-08-11 06:56:29 +08:00
|
|
|
} else if (EVT(VT).isVector()) {
|
|
|
|
EVT VVT = VT;
|
2007-02-15 10:26:10 +08:00
|
|
|
OS << "VectorType::get(";
|
2009-08-12 04:47:22 +08:00
|
|
|
EmitTypeForValueType(OS, VVT.getVectorElementType().getSimpleVT().SimpleTy);
|
2008-06-06 20:08:01 +08:00
|
|
|
OS << ", " << VVT.getVectorNumElements() << ")";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::iPTR) {
|
2007-12-17 09:12:55 +08:00
|
|
|
OS << "PointerType::getUnqual(";
|
2007-04-01 15:20:02 +08:00
|
|
|
EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << ")";
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::iPTRAny) {
|
2008-07-30 12:36:53 +08:00
|
|
|
// Make sure the user has passed us an argument type to overload. If not,
|
|
|
|
// treat it as an ordinary (not overloaded) intrinsic.
|
2011-07-15 01:45:39 +08:00
|
|
|
OS << "(" << ArgNo << " < Tys.size()) ? Tys[" << ArgNo
|
2008-07-30 12:36:53 +08:00
|
|
|
<< "] : PointerType::getUnqual(";
|
|
|
|
EmitTypeGenerate(OS, ArgType->getValueAsDef("ElTy"), ArgNo);
|
|
|
|
OS << ")";
|
|
|
|
++ArgNo;
|
2009-08-12 04:47:22 +08:00
|
|
|
} else if (VT == MVT::isVoid) {
|
2007-08-04 09:51:18 +08:00
|
|
|
if (ArgNo == 0)
|
2009-08-14 05:58:54 +08:00
|
|
|
OS << "Type::getVoidTy(Context)";
|
2007-08-04 09:51:18 +08:00
|
|
|
else
|
2009-08-12 04:47:22 +08:00
|
|
|
// MVT::isVoid is used to mean varargs here.
|
2007-08-04 09:51:18 +08:00
|
|
|
OS << "...";
|
2007-02-08 04:38:26 +08:00
|
|
|
} else {
|
2007-08-04 09:51:18 +08:00
|
|
|
EmitTypeForValueType(OS, VT);
|
2007-02-08 04:38:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-27 00:17:51 +08:00
|
|
|
/// RecordListComparator - Provide a deterministic comparator for lists of
|
2006-03-31 12:24:58 +08:00
|
|
|
/// records.
|
|
|
|
namespace {
|
2008-11-13 17:08:33 +08:00
|
|
|
typedef std::pair<std::vector<Record*>, std::vector<Record*> > RecPair;
|
2006-03-31 12:24:58 +08:00
|
|
|
struct RecordListComparator {
|
2008-11-13 17:08:33 +08:00
|
|
|
bool operator()(const RecPair &LHS,
|
|
|
|
const RecPair &RHS) const {
|
2006-03-31 12:24:58 +08:00
|
|
|
unsigned i = 0;
|
2008-11-13 17:08:33 +08:00
|
|
|
const std::vector<Record*> *LHSVec = &LHS.first;
|
|
|
|
const std::vector<Record*> *RHSVec = &RHS.first;
|
|
|
|
unsigned RHSSize = RHSVec->size();
|
|
|
|
unsigned LHSSize = LHSVec->size();
|
|
|
|
|
2010-03-23 04:56:36 +08:00
|
|
|
for (; i != LHSSize; ++i) {
|
2008-11-13 17:08:33 +08:00
|
|
|
if (i == RHSSize) return false; // RHS is shorter than LHS.
|
|
|
|
if ((*LHSVec)[i] != (*RHSVec)[i])
|
|
|
|
return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
|
2010-03-23 04:56:36 +08:00
|
|
|
}
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2008-11-13 20:03:00 +08:00
|
|
|
if (i != RHSSize) return true;
|
2008-11-13 17:08:33 +08:00
|
|
|
|
|
|
|
i = 0;
|
|
|
|
LHSVec = &LHS.second;
|
|
|
|
RHSVec = &RHS.second;
|
|
|
|
RHSSize = RHSVec->size();
|
|
|
|
LHSSize = LHSVec->size();
|
|
|
|
|
|
|
|
for (i = 0; i != LHSSize; ++i) {
|
|
|
|
if (i == RHSSize) return false; // RHS is shorter than LHS.
|
|
|
|
if ((*LHSVec)[i] != (*RHSVec)[i])
|
|
|
|
return (*LHSVec)[i]->getName() < (*RHSVec)[i]->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
return i != RHSSize;
|
2006-03-31 12:24:58 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2006-03-10 06:05:04 +08:00
|
|
|
void IntrinsicEmitter::EmitVerifier(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2006-03-10 06:05:04 +08:00
|
|
|
OS << "// Verifier::visitIntrinsicFunctionCall code.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_VERIFIER\n";
|
|
|
|
OS << " switch (ID) {\n";
|
|
|
|
OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
|
2006-03-31 12:24:58 +08:00
|
|
|
|
|
|
|
// This checking can emit a lot of very common code. To reduce the amount of
|
|
|
|
// code that we emit, batch up cases that have identical types. This avoids
|
|
|
|
// problems where GCC can run out of memory compiling Verifier.cpp.
|
2008-11-13 17:08:33 +08:00
|
|
|
typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
|
2006-03-31 12:24:58 +08:00
|
|
|
MapTy UniqueArgInfos;
|
|
|
|
|
|
|
|
// Compute the unique argument type info.
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
2008-11-13 17:08:33 +08:00
|
|
|
UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
|
|
|
|
Ints[i].IS.ParamTypeDefs)].push_back(i);
|
2006-03-31 12:24:58 +08:00
|
|
|
|
|
|
|
// Loop through the array, emitting one comparison for each batch.
|
|
|
|
for (MapTy::iterator I = UniqueArgInfos.begin(),
|
|
|
|
E = UniqueArgInfos.end(); I != E; ++I) {
|
2008-11-13 17:08:33 +08:00
|
|
|
for (unsigned i = 0, e = I->second.size(); i != e; ++i)
|
2006-03-31 12:24:58 +08:00
|
|
|
OS << " case Intrinsic::" << Ints[I->second[i]].EnumName << ":\t\t// "
|
|
|
|
<< Ints[I->second[i]].Name << "\n";
|
2006-03-31 12:48:26 +08:00
|
|
|
|
2008-11-13 17:08:33 +08:00
|
|
|
const RecPair &ArgTypes = I->first;
|
|
|
|
const std::vector<Record*> &RetTys = ArgTypes.first;
|
|
|
|
const std::vector<Record*> &ParamTys = ArgTypes.second;
|
2009-07-30 00:35:59 +08:00
|
|
|
std::vector<unsigned> OverloadedTypeIndices;
|
2008-11-13 17:08:33 +08:00
|
|
|
|
|
|
|
OS << " VerifyIntrinsicPrototype(ID, IF, " << RetTys.size() << ", "
|
|
|
|
<< ParamTys.size();
|
|
|
|
|
|
|
|
// Emit return types.
|
|
|
|
for (unsigned j = 0, je = RetTys.size(); j != je; ++j) {
|
|
|
|
Record *ArgType = RetTys[j];
|
|
|
|
OS << ", ";
|
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMMatchType")) {
|
|
|
|
unsigned Number = ArgType->getValueAsInt("Number");
|
2009-07-30 00:35:59 +08:00
|
|
|
assert(Number < OverloadedTypeIndices.size() &&
|
|
|
|
"Invalid matching number!");
|
|
|
|
Number = OverloadedTypeIndices[Number];
|
2009-01-07 08:09:01 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
|
|
|
|
OS << "~(ExtendedElementVectorType | " << Number << ")";
|
|
|
|
else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
OS << "~(TruncatedElementVectorType | " << Number << ")";
|
|
|
|
else
|
|
|
|
OS << "~" << Number;
|
2007-08-04 09:51:18 +08:00
|
|
|
} else {
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
|
2007-08-04 09:51:18 +08:00
|
|
|
OS << getEnumName(VT);
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2009-08-11 09:14:02 +08:00
|
|
|
if (EVT(VT).isOverloaded())
|
2009-07-30 00:35:59 +08:00
|
|
|
OverloadedTypeIndices.push_back(j);
|
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
if (VT == MVT::isVoid && j != 0 && j != je - 1)
|
2008-11-13 17:08:33 +08:00
|
|
|
throw "Var arg type not last argument";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the parameter types.
|
|
|
|
for (unsigned j = 0, je = ParamTys.size(); j != je; ++j) {
|
|
|
|
Record *ArgType = ParamTys[j];
|
|
|
|
OS << ", ";
|
|
|
|
|
|
|
|
if (ArgType->isSubClassOf("LLVMMatchType")) {
|
|
|
|
unsigned Number = ArgType->getValueAsInt("Number");
|
2009-07-30 00:35:59 +08:00
|
|
|
assert(Number < OverloadedTypeIndices.size() &&
|
|
|
|
"Invalid matching number!");
|
|
|
|
Number = OverloadedTypeIndices[Number];
|
2009-01-07 08:09:01 +08:00
|
|
|
if (ArgType->isSubClassOf("LLVMExtendedElementVectorType"))
|
|
|
|
OS << "~(ExtendedElementVectorType | " << Number << ")";
|
|
|
|
else if (ArgType->isSubClassOf("LLVMTruncatedElementVectorType"))
|
|
|
|
OS << "~(TruncatedElementVectorType | " << Number << ")";
|
|
|
|
else
|
|
|
|
OS << "~" << Number;
|
2008-11-13 17:08:33 +08:00
|
|
|
} else {
|
2009-08-12 04:47:22 +08:00
|
|
|
MVT::SimpleValueType VT = getValueType(ArgType->getValueAsDef("VT"));
|
2008-11-13 17:08:33 +08:00
|
|
|
OS << getEnumName(VT);
|
|
|
|
|
2009-08-11 09:14:02 +08:00
|
|
|
if (EVT(VT).isOverloaded())
|
2009-07-30 00:35:59 +08:00
|
|
|
OverloadedTypeIndices.push_back(j + RetTys.size());
|
|
|
|
|
2009-08-12 04:47:22 +08:00
|
|
|
if (VT == MVT::isVoid && j != 0 && j != je - 1)
|
2007-02-07 02:30:58 +08:00
|
|
|
throw "Var arg type not last argument";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
OS << ");\n";
|
2006-03-10 06:05:04 +08:00
|
|
|
OS << " break;\n";
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "#endif\n\n";
|
2006-03-10 04:34:19 +08:00
|
|
|
}
|
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
void IntrinsicEmitter::EmitGenerator(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << "// Code for generating Intrinsic function declarations.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_GENERATOR\n";
|
|
|
|
OS << " switch (id) {\n";
|
|
|
|
OS << " default: assert(0 && \"Invalid intrinsic!\");\n";
|
|
|
|
|
|
|
|
// Similar to GET_INTRINSIC_VERIFIER, batch up cases that have identical
|
|
|
|
// types.
|
2008-11-13 17:08:33 +08:00
|
|
|
typedef std::map<RecPair, std::vector<unsigned>, RecordListComparator> MapTy;
|
2007-02-08 04:38:26 +08:00
|
|
|
MapTy UniqueArgInfos;
|
|
|
|
|
|
|
|
// Compute the unique argument type info.
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i)
|
2008-11-13 17:08:33 +08:00
|
|
|
UniqueArgInfos[make_pair(Ints[i].IS.RetTypeDefs,
|
|
|
|
Ints[i].IS.ParamTypeDefs)].push_back(i);
|
2007-02-08 04:38:26 +08:00
|
|
|
|
|
|
|
// Loop through the array, emitting one generator for each batch.
|
2009-02-05 09:49:45 +08:00
|
|
|
std::string IntrinsicStr = TargetPrefix + "Intrinsic::";
|
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
for (MapTy::iterator I = UniqueArgInfos.begin(),
|
|
|
|
E = UniqueArgInfos.end(); I != E; ++I) {
|
2008-11-13 17:08:33 +08:00
|
|
|
for (unsigned i = 0, e = I->second.size(); i != e; ++i)
|
2009-02-05 09:49:45 +08:00
|
|
|
OS << " case " << IntrinsicStr << Ints[I->second[i]].EnumName
|
|
|
|
<< ":\t\t// " << Ints[I->second[i]].Name << "\n";
|
2007-02-08 04:38:26 +08:00
|
|
|
|
2008-11-13 17:08:33 +08:00
|
|
|
const RecPair &ArgTypes = I->first;
|
|
|
|
const std::vector<Record*> &RetTys = ArgTypes.first;
|
|
|
|
const std::vector<Record*> &ParamTys = ArgTypes.second;
|
|
|
|
|
|
|
|
unsigned N = ParamTys.size();
|
2007-02-08 04:38:26 +08:00
|
|
|
|
2007-08-04 09:51:18 +08:00
|
|
|
if (N > 1 &&
|
2009-08-12 04:47:22 +08:00
|
|
|
getValueType(ParamTys[N - 1]->getValueAsDef("VT")) == MVT::isVoid) {
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << " IsVarArg = true;\n";
|
|
|
|
--N;
|
|
|
|
}
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2007-05-23 03:30:31 +08:00
|
|
|
unsigned ArgNo = 0;
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << " ResultTy = ";
|
2008-11-13 17:08:33 +08:00
|
|
|
EmitTypeGenerate(OS, RetTys, ArgNo);
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << ";\n";
|
|
|
|
|
2008-11-13 17:08:33 +08:00
|
|
|
for (unsigned j = 0; j != N; ++j) {
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << " ArgTys.push_back(";
|
2008-11-13 17:08:33 +08:00
|
|
|
EmitTypeGenerate(OS, ParamTys[j], ArgNo);
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << ");\n";
|
|
|
|
}
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << " break;\n";
|
|
|
|
}
|
2008-11-13 17:08:33 +08:00
|
|
|
|
2007-02-08 04:38:26 +08:00
|
|
|
OS << " }\n";
|
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
namespace {
|
|
|
|
enum ModRefKind {
|
|
|
|
MRK_none,
|
|
|
|
MRK_readonly,
|
|
|
|
MRK_readnone
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
assert(0 && "bad mod-ref kind");
|
|
|
|
return MRK_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2009-01-12 09:18:58 +08:00
|
|
|
/// EmitAttributes - This emits the Intrinsic::getAttributes method.
|
2006-03-24 09:13:55 +08:00
|
|
|
void IntrinsicEmitter::
|
2009-07-03 08:10:29 +08:00
|
|
|
EmitAttributes(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS) {
|
2007-12-04 04:06:50 +08:00
|
|
|
OS << "// Add parameter attributes that are not common to all intrinsics.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_ATTRIBUTES\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
if (TargetOnly)
|
|
|
|
OS << "static AttrListPtr getAttributes(" << TargetPrefix
|
2011-05-28 14:31:34 +08:00
|
|
|
<< "Intrinsic::ID id) {\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
else
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << "AttrListPtr Intrinsic::getAttributes(ID id) {\n";
|
|
|
|
|
|
|
|
// Compute the maximum number of attribute arguments.
|
|
|
|
std::vector<const CodeGenIntrinsic*> sortedIntrinsics(Ints.size());
|
|
|
|
unsigned maxArgAttrs = 0;
|
2006-03-10 06:37:52 +08:00
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2011-05-28 14:31:34 +08:00
|
|
|
const CodeGenIntrinsic &intrinsic = Ints[i];
|
|
|
|
sortedIntrinsics[i] = &intrinsic;
|
|
|
|
maxArgAttrs =
|
|
|
|
std::max(maxArgAttrs, unsigned(intrinsic.ArgumentAttributes.size()));
|
2006-03-10 06:37:52 +08:00
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
// Emit an array of AttributeWithIndex. Most intrinsics will have
|
|
|
|
// at least one entry, for the function itself (index ~1), which is
|
|
|
|
// usually nounwind.
|
|
|
|
OS << " AttributeWithIndex AWI[" << maxArgAttrs+1 << "];\n";
|
2009-01-12 10:41:37 +08:00
|
|
|
OS << " unsigned NumAttrs = 0;\n";
|
2009-01-12 09:27:55 +08:00
|
|
|
OS << " switch (id) {\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << " default: break;\n";
|
|
|
|
|
|
|
|
AttributeComparator precedes;
|
|
|
|
|
|
|
|
std::stable_sort(sortedIntrinsics.begin(), sortedIntrinsics.end(), precedes);
|
2009-01-12 09:27:55 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
for (unsigned i = 0, e = sortedIntrinsics.size(); i != e; ++i) {
|
|
|
|
const CodeGenIntrinsic &intrinsic = *sortedIntrinsics[i];
|
|
|
|
OS << " case " << TargetPrefix << "Intrinsic::"
|
|
|
|
<< intrinsic.EnumName << ":\n";
|
2009-01-12 09:27:55 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
// Fill out the case if this is the last case for this range of
|
|
|
|
// intrinsics.
|
|
|
|
if (i + 1 != e && !precedes(&intrinsic, sortedIntrinsics[i + 1]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Keep track of the number of attributes we're writing out.
|
|
|
|
unsigned numAttrs = 0;
|
2009-01-12 09:27:55 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
// The argument attributes are alreadys sorted by argument index.
|
|
|
|
for (unsigned ai = 0, ae = intrinsic.ArgumentAttributes.size(); ai != ae;) {
|
|
|
|
unsigned argNo = intrinsic.ArgumentAttributes[ai].first;
|
2009-01-12 10:41:37 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get("
|
|
|
|
<< argNo+1 << ", ";
|
|
|
|
|
|
|
|
bool moreThanOne = false;
|
2009-01-12 10:41:37 +08:00
|
|
|
|
2011-05-28 14:31:34 +08:00
|
|
|
do {
|
|
|
|
if (moreThanOne) OS << '|';
|
|
|
|
|
|
|
|
switch (intrinsic.ArgumentAttributes[ai].second) {
|
2009-01-12 10:41:37 +08:00
|
|
|
case CodeGenIntrinsic::NoCapture:
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << "Attribute::NoCapture";
|
2009-01-12 10:41:37 +08:00
|
|
|
break;
|
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
++ai;
|
|
|
|
moreThanOne = true;
|
|
|
|
} while (ai != ae && intrinsic.ArgumentAttributes[ai].first == argNo);
|
|
|
|
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
ModRefKind modRef = getModRefKind(intrinsic);
|
|
|
|
|
|
|
|
if (!intrinsic.canThrow || modRef) {
|
|
|
|
OS << " AWI[" << numAttrs++ << "] = AttributeWithIndex::get(~0, ";
|
|
|
|
if (!intrinsic.canThrow) {
|
|
|
|
OS << "Attribute::NoUnwind";
|
|
|
|
if (modRef) OS << '|';
|
|
|
|
}
|
|
|
|
switch (modRef) {
|
|
|
|
case MRK_none: break;
|
|
|
|
case MRK_readonly: OS << "Attribute::ReadOnly"; break;
|
|
|
|
case MRK_readnone: OS << "Attribute::ReadNone"; break;
|
2009-01-12 10:41:37 +08:00
|
|
|
}
|
|
|
|
OS << ");\n";
|
|
|
|
}
|
2011-05-28 14:31:34 +08:00
|
|
|
|
|
|
|
if (numAttrs) {
|
|
|
|
OS << " NumAttrs = " << numAttrs << ";\n";
|
|
|
|
OS << " break;\n";
|
|
|
|
} else {
|
|
|
|
OS << " return AttrListPtr();\n";
|
|
|
|
}
|
2009-01-12 09:27:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
OS << " }\n";
|
2011-05-28 14:31:34 +08:00
|
|
|
OS << " return AttrListPtr::get(AWI, NumAttrs);\n";
|
2009-01-12 09:18:58 +08:00
|
|
|
OS << "}\n";
|
2009-01-12 10:41:37 +08:00
|
|
|
OS << "#endif // GET_INTRINSIC_ATTRIBUTES\n\n";
|
2006-03-10 06:37:52 +08:00
|
|
|
}
|
2006-03-14 07:08:44 +08:00
|
|
|
|
2009-02-14 18:56:35 +08:00
|
|
|
/// EmitModRefBehavior - Determine intrinsic alias analysis mod/ref behavior.
|
|
|
|
void IntrinsicEmitter::
|
2009-07-03 08:10:29 +08:00
|
|
|
EmitModRefBehavior(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
|
2009-02-14 18:56:35 +08:00
|
|
|
OS << "// Determine intrinsic alias analysis mod/ref behavior.\n";
|
|
|
|
OS << "#ifdef GET_INTRINSIC_MODREF_BEHAVIOR\n";
|
2010-01-06 16:45:52 +08:00
|
|
|
OS << "switch (iid) {\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
OS << "default:\n return UnknownModRefBehavior;\n";
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
2010-08-06 07:36:21 +08:00
|
|
|
if (Ints[i].ModRef == CodeGenIntrinsic::ReadWriteMem)
|
2009-02-14 18:56:35 +08:00
|
|
|
continue;
|
|
|
|
OS << "case " << TargetPrefix << "Intrinsic::" << Ints[i].EnumName
|
|
|
|
<< ":\n";
|
|
|
|
switch (Ints[i].ModRef) {
|
|
|
|
default:
|
|
|
|
assert(false && "Unknown Mod/Ref type!");
|
|
|
|
case CodeGenIntrinsic::NoMem:
|
|
|
|
OS << " return DoesNotAccessMemory;\n";
|
|
|
|
break;
|
|
|
|
case CodeGenIntrinsic::ReadArgMem:
|
2010-11-11 02:30:00 +08:00
|
|
|
OS << " return OnlyReadsArgumentPointees;\n";
|
2010-11-10 04:07:20 +08:00
|
|
|
break;
|
2009-02-14 18:56:35 +08:00
|
|
|
case CodeGenIntrinsic::ReadMem:
|
|
|
|
OS << " return OnlyReadsMemory;\n";
|
|
|
|
break;
|
2010-08-06 07:36:21 +08:00
|
|
|
case CodeGenIntrinsic::ReadWriteArgMem:
|
2010-11-11 02:30:00 +08:00
|
|
|
OS << " return OnlyAccessesArgumentPointees;\n";
|
2009-02-14 18:56:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << "}\n";
|
|
|
|
OS << "#endif // GET_INTRINSIC_MODREF_BEHAVIOR\n\n";
|
|
|
|
}
|
|
|
|
|
2006-03-14 07:08:44 +08:00
|
|
|
void IntrinsicEmitter::
|
2009-07-03 08:10:29 +08:00
|
|
|
EmitGCCBuiltinList(const std::vector<CodeGenIntrinsic> &Ints, raw_ostream &OS){
|
2006-03-14 07:08:44 +08:00
|
|
|
OS << "// Get the GCC builtin that corresponds to an LLVM intrinsic.\n";
|
|
|
|
OS << "#ifdef GET_GCC_BUILTIN_NAME\n";
|
|
|
|
OS << " switch (F->getIntrinsicID()) {\n";
|
|
|
|
OS << " default: BuiltinName = \"\"; break;\n";
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
if (!Ints[i].GCCBuiltinName.empty()) {
|
|
|
|
OS << " case Intrinsic::" << Ints[i].EnumName << ": BuiltinName = \""
|
|
|
|
<< Ints[i].GCCBuiltinName << "\"; break;\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OS << " }\n";
|
|
|
|
OS << "#endif\n\n";
|
2006-03-14 13:59:52 +08:00
|
|
|
}
|
2006-03-15 09:33:26 +08:00
|
|
|
|
2008-01-04 12:38:35 +08: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 09:49:45 +08:00
|
|
|
const std::string &TargetPrefix,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2008-01-04 12:38:35 +08:00
|
|
|
|
2010-09-06 11:14:45 +08:00
|
|
|
std::vector<StringMatcher::StringPair> Results;
|
2008-01-04 12:38:35 +08:00
|
|
|
|
2010-09-06 11:14:45 +08: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 12:38:35 +08:00
|
|
|
}
|
2010-09-06 11:14:45 +08:00
|
|
|
|
|
|
|
StringMatcher("BuiltinName", Results, OS).Emit();
|
2008-01-04 12:38:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-15 09:33:26 +08:00
|
|
|
void IntrinsicEmitter::
|
|
|
|
EmitIntrinsicToGCCBuiltinMap(const std::vector<CodeGenIntrinsic> &Ints,
|
2009-07-03 08:10:29 +08:00
|
|
|
raw_ostream &OS) {
|
2008-01-03 05:24:22 +08:00
|
|
|
typedef std::map<std::string, std::map<std::string, std::string> > BIMTy;
|
2006-03-15 09:33:26 +08:00
|
|
|
BIMTy BuiltinMap;
|
|
|
|
for (unsigned i = 0, e = Ints.size(); i != e; ++i) {
|
|
|
|
if (!Ints[i].GCCBuiltinName.empty()) {
|
2008-01-03 05:24:22 +08: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)
|
2006-03-15 09:33:26 +08:00
|
|
|
throw "Intrinsic '" + Ints[i].TheDef->getName() +
|
|
|
|
"': duplicate GCC builtin name!";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 09:49:45 +08:00
|
|
|
|
|
|
|
if (TargetOnly) {
|
|
|
|
OS << "static " << TargetPrefix << "Intrinsic::ID "
|
|
|
|
<< "getIntrinsicForGCCBuiltin(const char "
|
2010-09-06 11:14:45 +08:00
|
|
|
<< "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
} else {
|
|
|
|
OS << "Intrinsic::ID Intrinsic::getIntrinsicForGCCBuiltin(const char "
|
2010-09-06 11:14:45 +08:00
|
|
|
<< "*TargetPrefixStr, const char *BuiltinNameStr) {\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
}
|
|
|
|
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << " StringRef BuiltinName(BuiltinNameStr);\n";
|
|
|
|
OS << " StringRef TargetPrefix(TargetPrefixStr);\n\n";
|
2008-01-04 12:38:35 +08:00
|
|
|
|
2006-03-15 09:33:26 +08: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-03 05:24:22 +08:00
|
|
|
OS << " ";
|
|
|
|
if (!I->first.empty())
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << "if (TargetPrefix == \"" << I->first << "\") ";
|
2008-01-03 05:24:22 +08:00
|
|
|
else
|
|
|
|
OS << "/* Target Independent Builtins */ ";
|
|
|
|
OS << "{\n";
|
|
|
|
|
|
|
|
// Emit the comparisons for this target prefix.
|
2009-02-05 09:49:45 +08:00
|
|
|
EmitTargetBuiltins(I->second, TargetPrefix, OS);
|
2008-01-03 05:24:22 +08:00
|
|
|
OS << " }\n";
|
2006-03-15 09:33:26 +08:00
|
|
|
}
|
2010-09-06 11:14:45 +08:00
|
|
|
OS << " return ";
|
|
|
|
if (!TargetPrefix.empty())
|
|
|
|
OS << "(" << TargetPrefix << "Intrinsic::ID)";
|
|
|
|
OS << "Intrinsic::not_intrinsic;\n";
|
2009-02-05 09:49:45 +08:00
|
|
|
OS << "}\n";
|
2006-03-15 09:33:26 +08:00
|
|
|
OS << "#endif\n\n";
|
|
|
|
}
|