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