diff options
author | Nate Begeman <natebegeman@mac.com> | 2009-02-04 19:47:21 +0000 |
---|---|---|
committer | Nate Begeman <natebegeman@mac.com> | 2009-02-04 19:47:21 +0000 |
commit | 6ae3aa83d0383dd86f5e54db3d4930a4e6fe0712 (patch) | |
tree | a230ae492d7e6949201c1d2ad0b901da5a0cad4c /llvm/lib | |
parent | 022923a22a616a97685af71862a7a9833af23b65 (diff) | |
download | bcm5719-llvm-6ae3aa83d0383dd86f5e54db3d4930a4e6fe0712.tar.gz bcm5719-llvm-6ae3aa83d0383dd86f5e54db3d4930a4e6fe0712.zip |
New feature: add support for target intrinsics being defined in the
target directories themselves. This also means that VMCore no longer
needs to know about every target's list of intrinsics. Future work
will include converting the PowerPC target to this interface as an
example implementation.
llvm-svn: 63765
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp | 9 | ||||
-rw-r--r-- | llvm/lib/Target/TargetIntrinsicInfo.cpp | 22 | ||||
-rw-r--r-- | llvm/lib/VMCore/AutoUpgrade.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/VMCore/Function.cpp | 12 | ||||
-rw-r--r-- | llvm/lib/VMCore/Module.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/VMCore/Verifier.cpp | 3 |
7 files changed, 59 insertions, 17 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 943f1d00256..60e863c53ed 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -2949,15 +2949,6 @@ bool LLParser::ParseCall(Instruction *&Inst, PerFunctionState &PFS, Value *Callee; if (ConvertValIDToValue(PFTy, CalleeID, Callee, PFS)) return true; - // Check for call to invalid intrinsic to avoid crashing later. - if (Function *F = dyn_cast<Function>(Callee)) { - if (F->hasName() && F->getNameLen() >= 5 && - !strncmp(F->getValueName()->getKeyData(), "llvm.", 5) && - !F->getIntrinsicID(true)) - return Error(CallLoc, "Call to invalid LLVM intrinsic function '" + - F->getNameStr() + "'"); - } - // FIXME: In LLVM 3.0, stop accepting zext, sext and inreg as optional // function attributes. unsigned ObsoleteFuncAttrs = Attribute::ZExt|Attribute::SExt|Attribute::InReg; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp index c3cff2037e4..1b1d70baab8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp @@ -43,6 +43,7 @@ #include "llvm/Target/TargetData.h" #include "llvm/Target/TargetFrameInfo.h" #include "llvm/Target/TargetInstrInfo.h" +#include "llvm/Target/TargetIntrinsicInfo.h" #include "llvm/Target/TargetLowering.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" @@ -4426,6 +4427,14 @@ void SelectionDAGLowering::visitCall(CallInst &I) { const char *RenameFn = 0; if (Function *F = I.getCalledFunction()) { if (F->isDeclaration()) { + const TargetIntrinsicInfo *II = TLI.getTargetMachine().getIntrinsicInfo(); + if (II) { + if (unsigned IID = II->getIntrinsicID(F)) { + RenameFn = visitIntrinsicCall(I, IID); + if (!RenameFn) + return; + } + } if (unsigned IID = F->getIntrinsicID()) { RenameFn = visitIntrinsicCall(I, IID); if (!RenameFn) diff --git a/llvm/lib/Target/TargetIntrinsicInfo.cpp b/llvm/lib/Target/TargetIntrinsicInfo.cpp new file mode 100644 index 00000000000..d8da08e4f1d --- /dev/null +++ b/llvm/lib/Target/TargetIntrinsicInfo.cpp @@ -0,0 +1,22 @@ +//===-- TargetIntrinsicInfo.cpp - Target Instruction Information ----------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the TargetIntrinsicInfo class. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Target/TargetIntrinsicInfo.h" +using namespace llvm; + +TargetIntrinsicInfo::TargetIntrinsicInfo(const char **desc, unsigned count) + : Intrinsics(desc), NumIntrinsics(count) { +} + +TargetIntrinsicInfo::~TargetIntrinsicInfo() { +} diff --git a/llvm/lib/VMCore/AutoUpgrade.cpp b/llvm/lib/VMCore/AutoUpgrade.cpp index abad7af79be..dd366071b76 100644 --- a/llvm/lib/VMCore/AutoUpgrade.cpp +++ b/llvm/lib/VMCore/AutoUpgrade.cpp @@ -217,7 +217,7 @@ bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) { // Upgrade intrinsic attributes. This does not change the function. if (NewFn) F = NewFn; - if (unsigned id = F->getIntrinsicID(true)) + if (unsigned id = F->getIntrinsicID()) F->setAttributes(Intrinsic::getAttributes((Intrinsic::ID)id)); return Upgraded; } diff --git a/llvm/lib/VMCore/Function.cpp b/llvm/lib/VMCore/Function.cpp index bda2eff4c99..bc3b611820c 100644 --- a/llvm/lib/VMCore/Function.cpp +++ b/llvm/lib/VMCore/Function.cpp @@ -175,7 +175,7 @@ Function::Function(const FunctionType *Ty, LinkageTypes Linkage, ParentModule->getFunctionList().push_back(this); // Ensure intrinsics have the right parameter attributes. - if (unsigned IID = getIntrinsicID(true)) + if (unsigned IID = getIntrinsicID()) setAttributes(Intrinsic::getAttributes(Intrinsic::ID(IID))); } @@ -304,7 +304,7 @@ void Function::copyAttributesFrom(const GlobalValue *Src) { /// particular intrinsic functions which correspond to this value are defined in /// llvm/Intrinsics.h. /// -unsigned Function::getIntrinsicID(bool noAssert) const { +unsigned Function::getIntrinsicID() const { const ValueName *ValName = this->getValueName(); if (!ValName) return 0; @@ -315,12 +315,9 @@ unsigned Function::getIntrinsicID(bool noAssert) const { || Name[2] != 'v' || Name[3] != 'm') return 0; // All intrinsics start with 'llvm.' - assert((Len != 5 || noAssert) && "'llvm.' is an invalid intrinsic name!"); - #define GET_FUNCTION_RECOGNIZER #include "llvm/Intrinsics.gen" #undef GET_FUNCTION_RECOGNIZER - assert(noAssert && "Invalid LLVM intrinsic name"); return 0; } @@ -373,4 +370,9 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys, getType(id, Tys, numTys))); } +// This defines the "Intrinsic::getIntrinsicForGCCBuiltin()" method. +#define GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN +#include "llvm/Intrinsics.gen" +#undef GET_LLVM_INTRINSIC_FOR_GCC_BUILTIN + // vim: sw=2 ai diff --git a/llvm/lib/VMCore/Module.cpp b/llvm/lib/VMCore/Module.cpp index ef94796b242..896245d69e6 100644 --- a/llvm/lib/VMCore/Module.cpp +++ b/llvm/lib/VMCore/Module.cpp @@ -171,6 +171,25 @@ Constant *Module::getOrInsertFunction(const std::string &Name, return F; } +Constant *Module::getOrInsertTargetIntrinsic(const std::string &Name, + const FunctionType *Ty, + AttrListPtr AttributeList) { + ValueSymbolTable &SymTab = getValueSymbolTable(); + + // See if we have a definition for the specified function already. + GlobalValue *F = dyn_cast_or_null<GlobalValue>(SymTab.lookup(Name)); + if (F == 0) { + // Nope, add it + Function *New = Function::Create(Ty, GlobalVariable::ExternalLinkage, Name); + New->setAttributes(AttributeList); + FunctionList.push_back(New); + return New; // Return the new prototype. + } + + // Otherwise, we just found the existing function or a prototype. + return F; +} + Constant *Module::getOrInsertFunction(const std::string &Name, const FunctionType *Ty) { AttrListPtr AttributeList = AttrListPtr::get((AttributeWithIndex *)0, 0); diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index 62d2930ae07..99a5b92e5ff 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -1004,10 +1004,9 @@ void Verifier::VerifyCallSite(CallSite CS) { void Verifier::visitCallInst(CallInst &CI) { VerifyCallSite(&CI); - if (Function *F = CI.getCalledFunction()) { + if (Function *F = CI.getCalledFunction()) if (Intrinsic::ID ID = (Intrinsic::ID)F->getIntrinsicID()) visitIntrinsicFunctionCall(ID, CI); - } } void Verifier::visitInvokeInst(InvokeInst &II) { |