diff options
Diffstat (limited to 'contrib/llvm/lib/IR/Function.cpp')
-rw-r--r-- | contrib/llvm/lib/IR/Function.cpp | 96 |
1 files changed, 71 insertions, 25 deletions
diff --git a/contrib/llvm/lib/IR/Function.cpp b/contrib/llvm/lib/IR/Function.cpp index e1223d0..05419aa 100644 --- a/contrib/llvm/lib/IR/Function.cpp +++ b/contrib/llvm/lib/IR/Function.cpp @@ -26,10 +26,6 @@ #include "llvm/IR/MDBuilder.h" #include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" -#include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/RWMutex.h" -#include "llvm/Support/StringPool.h" -#include "llvm/Support/Threading.h" using namespace llvm; // Explicit instantiations of SymbolTableListTraits since some of the methods @@ -262,7 +258,10 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name, assert(FunctionType::isValidReturnType(getReturnType()) && "invalid return type"); setGlobalObjectSubClassData(0); - SymTab = new ValueSymbolTable(); + + // We only need a symbol table for a function if the context keeps value names + if (!getContext().shouldDiscardValueNames()) + SymTab = make_unique<ValueSymbolTable>(); // If the function has arguments, mark them as lazily built. if (Ty->getNumParams()) @@ -271,6 +270,7 @@ Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name, if (ParentModule) ParentModule->getFunctionList().push_back(this); + HasLLVMReservedName = getName().startswith("llvm."); // Ensure intrinsics have the right parameter attributes. // Note, the IntID field will have been set in Value::setName if this function // name is a valid intrinsic ID. @@ -283,7 +283,6 @@ Function::~Function() { // Delete all of the method arguments and unlink from symbol table... ArgumentList.clear(); - delete SymTab; // Remove the function from the on-the-side GC table. clearGC(); @@ -332,10 +331,6 @@ bool Function::arg_empty() const { return getFunctionType()->getNumParams() == 0; } -void Function::setParent(Module *parent) { - Parent = parent; -} - // dropAllReferences() - This function causes all the subinstructions to "let // go" of all references that they are maintaining. This allows one to // 'delete' a whole class at a time, even though there may be circular @@ -488,9 +483,7 @@ static ArrayRef<const char *> findTargetSubtable(StringRef Name) { /// \brief This does the actual lookup of an intrinsic ID which /// matches the given function name. -static Intrinsic::ID lookupIntrinsicID(const ValueName *ValName) { - StringRef Name = ValName->getKey(); - +Intrinsic::ID Function::lookupIntrinsicID(StringRef Name) { ArrayRef<const char *> NameTable = findTargetSubtable(Name); int Idx = Intrinsic::lookupLLVMIntrinsicByName(NameTable, Name); if (Idx == -1) @@ -508,12 +501,14 @@ static Intrinsic::ID lookupIntrinsicID(const ValueName *ValName) { } void Function::recalculateIntrinsicID() { - const ValueName *ValName = this->getValueName(); - if (!ValName || !isIntrinsic()) { + StringRef Name = getName(); + if (!Name.startswith("llvm.")) { + HasLLVMReservedName = false; IntID = Intrinsic::not_intrinsic; return; } - IntID = lookupIntrinsicID(ValName); + HasLLVMReservedName = true; + IntID = lookupIntrinsicID(Name); } /// Returns a stable mangling for the type specified for use in the name @@ -557,6 +552,13 @@ static std::string getMangledTypeStr(Type* Ty) { return Result; } +StringRef Intrinsic::getName(ID id) { + assert(id < num_intrinsics && "Invalid intrinsic ID!"); + assert(!isOverloaded(id) && + "This version of getName does not support overloading"); + return IntrinsicNameTable[id]; +} + std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) { assert(id < num_intrinsics && "Invalid intrinsic ID!"); std::string Result(IntrinsicNameTable[id]); @@ -608,10 +610,11 @@ enum IIT_Info { IIT_HALF_VEC_ARG = 30, IIT_SAME_VEC_WIDTH_ARG = 31, IIT_PTR_TO_ARG = 32, - IIT_VEC_OF_PTRS_TO_ELT = 33, - IIT_I128 = 34, - IIT_V512 = 35, - IIT_V1024 = 36 + IIT_PTR_TO_ELT = 33, + IIT_VEC_OF_PTRS_TO_ELT = 34, + IIT_I128 = 35, + IIT_V512 = 36, + IIT_V1024 = 37 }; @@ -745,6 +748,11 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos, ArgInfo)); return; } + case IIT_PTR_TO_ELT: { + unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); + OutputTable.push_back(IITDescriptor::get(IITDescriptor::PtrToElt, ArgInfo)); + return; + } case IIT_VEC_OF_PTRS_TO_ELT: { unsigned ArgInfo = (NextElt == Infos.size() ? 0 : Infos[NextElt++]); OutputTable.push_back(IITDescriptor::get(IITDescriptor::VecOfPtrsToElt, @@ -754,9 +762,9 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef<unsigned char> Infos, case IIT_EMPTYSTRUCT: OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct, 0)); return; - case IIT_STRUCT5: ++StructElts; // FALL THROUGH. - case IIT_STRUCT4: ++StructElts; // FALL THROUGH. - case IIT_STRUCT3: ++StructElts; // FALL THROUGH. + case IIT_STRUCT5: ++StructElts; LLVM_FALLTHROUGH; + case IIT_STRUCT4: ++StructElts; LLVM_FALLTHROUGH; + case IIT_STRUCT3: ++StructElts; LLVM_FALLTHROUGH; case IIT_STRUCT2: { OutputTable.push_back(IITDescriptor::get(IITDescriptor::Struct,StructElts)); @@ -871,6 +879,14 @@ static Type *DecodeFixedType(ArrayRef<Intrinsic::IITDescriptor> &Infos, Type *Ty = Tys[D.getArgumentNumber()]; return PointerType::getUnqual(Ty); } + case IITDescriptor::PtrToElt: { + Type *Ty = Tys[D.getArgumentNumber()]; + VectorType *VTy = dyn_cast<VectorType>(Ty); + if (!VTy) + llvm_unreachable("Expected an argument of Vector Type"); + Type *EltTy = VTy->getVectorElementType(); + return PointerType::getUnqual(EltTy); + } case IITDescriptor::VecOfPtrsToElt: { Type *Ty = Tys[D.getArgumentNumber()]; VectorType *VTy = dyn_cast<VectorType>(Ty); @@ -1049,7 +1065,7 @@ bool Intrinsic::matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> if (D.getArgumentNumber() >= ArgTys.size()) return true; VectorType * ReferenceType = - dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]); + dyn_cast<VectorType>(ArgTys[D.getArgumentNumber()]); VectorType *ThisArgType = dyn_cast<VectorType>(Ty); if (!ThisArgType || !ReferenceType || (ReferenceType->getVectorNumElements() != @@ -1065,6 +1081,16 @@ bool Intrinsic::matchIntrinsicType(Type *Ty, ArrayRef<Intrinsic::IITDescriptor> PointerType *ThisArgType = dyn_cast<PointerType>(Ty); return (!ThisArgType || ThisArgType->getElementType() != ReferenceType); } + case IITDescriptor::PtrToElt: { + if (D.getArgumentNumber() >= ArgTys.size()) + return true; + VectorType * ReferenceType = + dyn_cast<VectorType> (ArgTys[D.getArgumentNumber()]); + PointerType *ThisArgType = dyn_cast<PointerType>(Ty); + + return (!ThisArgType || !ReferenceType || + ThisArgType->getElementType() != ReferenceType->getElementType()); + } case IITDescriptor::VecOfPtrsToElt: { if (D.getArgumentNumber() >= ArgTys.size()) return true; @@ -1264,7 +1290,27 @@ Optional<uint64_t> Function::getEntryCount() const { if (MDString *MDS = dyn_cast<MDString>(MD->getOperand(0))) if (MDS->getString().equals("function_entry_count")) { ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(1)); - return CI->getValue().getZExtValue(); + uint64_t Count = CI->getValue().getZExtValue(); + if (Count == 0) + return None; + return Count; } return None; } + +void Function::setSectionPrefix(StringRef Prefix) { + MDBuilder MDB(getContext()); + setMetadata(LLVMContext::MD_section_prefix, + MDB.createFunctionSectionPrefix(Prefix)); +} + +Optional<StringRef> Function::getSectionPrefix() const { + if (MDNode *MD = getMetadata(LLVMContext::MD_section_prefix)) { + assert(dyn_cast<MDString>(MD->getOperand(0)) + ->getString() + .equals("function_section_prefix") && + "Metadata not match"); + return dyn_cast<MDString>(MD->getOperand(1))->getString(); + } + return None; +} |