X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=lib%2FIR%2FFunction.cpp;h=cfb40b19c733123bc703da49442a235854fdce7f;hp=bc57dee0af0a40ff3b04b42f2bff02b4d71ac492;hb=fdf52d35570d49dc00730511e32218aecd828926;hpb=cc714e214298cfbf11de65b46de31900d51422cf diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp index bc57dee0af0..cfb40b19c73 100644 --- a/lib/IR/Function.cpp +++ b/lib/IR/Function.cpp @@ -35,8 +35,8 @@ using namespace llvm; // Explicit instantiations of SymbolTableListTraits since some of the methods // are not in the public header file... -template class llvm::SymbolTableListTraits; -template class llvm::SymbolTableListTraits; +template class llvm::SymbolTableListTraits; +template class llvm::SymbolTableListTraits; //===----------------------------------------------------------------------===// // Argument Implementation @@ -235,11 +235,11 @@ Type *Function::getReturnType() const { } void Function::removeFromParent() { - getParent()->getFunctionList().remove(this); + getParent()->getFunctionList().remove(getIterator()); } void Function::eraseFromParent() { - getParent()->getFunctionList().erase(this); + getParent()->getFunctionList().erase(getIterator()); } //===----------------------------------------------------------------------===// @@ -248,7 +248,7 @@ void Function::eraseFromParent() { Function::Function(FunctionType *Ty, LinkageTypes Linkage, const Twine &name, Module *ParentModule) - : GlobalObject(PointerType::getUnqual(Ty), Value::FunctionVal, + : GlobalObject(Ty, Value::FunctionVal, OperandTraits::op_begin(this), 0, Linkage, name), Ty(Ty) { assert(FunctionType::isValidReturnType(getReturnType()) && @@ -279,9 +279,6 @@ Function::~Function() { // Remove the function from the on-the-side GC table. clearGC(); - - // FIXME: needed by operator delete - setFunctionNumOperands(1); } void Function::BuildLazyArguments() const { @@ -328,14 +325,15 @@ void Function::dropAllReferences() { while (!BasicBlocks.empty()) BasicBlocks.begin()->eraseFromParent(); - // Prefix and prologue data are stored in a side table. - setPrefixData(nullptr); - setPrologueData(nullptr); + // Drop uses of any optional data (real or placeholder). + if (getNumOperands()) { + User::dropAllReferences(); + setNumHungOffUseOperands(0); + setValueSubclassData(getSubclassDataFromValue() & ~0xe); + } // Metadata is stored in a side-table. clearMetadata(); - - setPersonalityFn(nullptr); } void Function::addAttribute(unsigned i, Attribute::AttrKind attr) { @@ -411,30 +409,26 @@ void Function::clearGC() { } } -/// copyAttributesFrom - copy all additional attributes (those not needed to -/// create a Function) from the Function Src to this one. +/// Copy all additional attributes (those not needed to create a Function) from +/// the Function Src to this one. void Function::copyAttributesFrom(const GlobalValue *Src) { - assert(isa(Src) && "Expected a Function!"); GlobalObject::copyAttributesFrom(Src); - const Function *SrcF = cast(Src); + const Function *SrcF = dyn_cast(Src); + if (!SrcF) + return; + setCallingConv(SrcF->getCallingConv()); setAttributes(SrcF->getAttributes()); if (SrcF->hasGC()) setGC(SrcF->getGC()); else clearGC(); + if (SrcF->hasPersonalityFn()) + setPersonalityFn(SrcF->getPersonalityFn()); if (SrcF->hasPrefixData()) setPrefixData(SrcF->getPrefixData()); - else - setPrefixData(nullptr); if (SrcF->hasPrologueData()) setPrologueData(SrcF->getPrologueData()); - else - setPrologueData(nullptr); - if (SrcF->hasPersonalityFn()) - setPersonalityFn(SrcF->getPersonalityFn()); - else - setPersonalityFn(nullptr); } /// \brief This does the actual lookup of an intrinsic ID which @@ -492,7 +486,10 @@ static std::string getMangledTypeStr(Type* Ty) { Result += "vararg"; // Ensure nested function types are distinguishable. Result += "f"; - } else if (Ty) + } else if (isa(Ty)) + Result += "v" + utostr(Ty->getVectorNumElements()) + + getMangledTypeStr(Ty->getVectorElementType()); + else if (Ty) Result += EVT::getEVT(Ty).getEVTString(); return Result; } @@ -541,22 +538,25 @@ enum IIT_Info { // Values from 16+ are only encodable with the inefficient encoding. IIT_V64 = 16, IIT_MMX = 17, - IIT_METADATA = 18, - IIT_EMPTYSTRUCT = 19, - IIT_STRUCT2 = 20, - IIT_STRUCT3 = 21, - IIT_STRUCT4 = 22, - IIT_STRUCT5 = 23, - IIT_EXTEND_ARG = 24, - IIT_TRUNC_ARG = 25, - IIT_ANYPTR = 26, - IIT_V1 = 27, - IIT_VARARG = 28, - IIT_HALF_VEC_ARG = 29, - IIT_SAME_VEC_WIDTH_ARG = 30, - IIT_PTR_TO_ARG = 31, - IIT_VEC_OF_PTRS_TO_ELT = 32, - IIT_I128 = 33 + IIT_TOKEN = 18, + IIT_METADATA = 19, + IIT_EMPTYSTRUCT = 20, + IIT_STRUCT2 = 21, + IIT_STRUCT3 = 22, + IIT_STRUCT4 = 23, + IIT_STRUCT5 = 24, + IIT_EXTEND_ARG = 25, + IIT_TRUNC_ARG = 26, + IIT_ANYPTR = 27, + IIT_V1 = 28, + IIT_VARARG = 29, + 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 }; @@ -576,6 +576,9 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef Infos, case IIT_MMX: OutputTable.push_back(IITDescriptor::get(IITDescriptor::MMX, 0)); return; + case IIT_TOKEN: + OutputTable.push_back(IITDescriptor::get(IITDescriptor::Token, 0)); + return; case IIT_METADATA: OutputTable.push_back(IITDescriptor::get(IITDescriptor::Metadata, 0)); return; @@ -634,6 +637,14 @@ static void DecodeIITType(unsigned &NextElt, ArrayRef Infos, OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 64)); DecodeIITType(NextElt, Infos, OutputTable); return; + case IIT_V512: + OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 512)); + DecodeIITType(NextElt, Infos, OutputTable); + return; + case IIT_V1024: + OutputTable.push_back(IITDescriptor::get(IITDescriptor::Vector, 1024)); + DecodeIITType(NextElt, Infos, OutputTable); + return; case IIT_PTR: OutputTable.push_back(IITDescriptor::get(IITDescriptor::Pointer, 0)); DecodeIITType(NextElt, Infos, OutputTable); @@ -751,6 +762,7 @@ static Type *DecodeFixedType(ArrayRef &Infos, case IITDescriptor::Void: return Type::getVoidTy(Context); case IITDescriptor::VarArg: return Type::getVoidTy(Context); case IITDescriptor::MMX: return Type::getX86_MMXTy(Context); + case IITDescriptor::Token: return Type::getTokenTy(Context); case IITDescriptor::Metadata: return Type::getMetadataTy(Context); case IITDescriptor::Half: return Type::getHalfTy(Context); case IITDescriptor::Float: return Type::getFloatTy(Context); @@ -846,6 +858,18 @@ bool Intrinsic::isOverloaded(ID id) { #undef GET_INTRINSIC_OVERLOAD_TABLE } +bool Intrinsic::isLeaf(ID id) { + switch (id) { + default: + return true; + + case Intrinsic::experimental_gc_statepoint: + case Intrinsic::experimental_patchpoint_void: + case Intrinsic::experimental_patchpoint_i64: + return false; + } +} + /// This defines the "Intrinsic::getAttributes(ID id)" method. #define GET_INTRINSIC_ATTRIBUTES #include "llvm/IR/Intrinsics.gen" @@ -912,62 +936,68 @@ bool Function::callsFunctionThatReturnsTwice() const { return false; } +Constant *Function::getPersonalityFn() const { + assert(hasPersonalityFn() && getNumOperands()); + return cast(Op<0>()); +} + +void Function::setPersonalityFn(Constant *Fn) { + setHungoffOperand<0>(Fn); + setValueSubclassDataBit(3, Fn != nullptr); +} + Constant *Function::getPrefixData() const { - assert(hasPrefixData()); - const LLVMContextImpl::PrefixDataMapTy &PDMap = - getContext().pImpl->PrefixDataMap; - assert(PDMap.find(this) != PDMap.end()); - return cast(PDMap.find(this)->second->getReturnValue()); + assert(hasPrefixData() && getNumOperands()); + return cast(Op<1>()); } void Function::setPrefixData(Constant *PrefixData) { - if (!PrefixData && !hasPrefixData()) - return; - - unsigned SCData = getSubclassDataFromValue(); - LLVMContextImpl::PrefixDataMapTy &PDMap = getContext().pImpl->PrefixDataMap; - ReturnInst *&PDHolder = PDMap[this]; - if (PrefixData) { - if (PDHolder) - PDHolder->setOperand(0, PrefixData); - else - PDHolder = ReturnInst::Create(getContext(), PrefixData); - SCData |= (1<<1); - } else { - delete PDHolder; - PDMap.erase(this); - SCData &= ~(1<<1); - } - setValueSubclassData(SCData); + setHungoffOperand<1>(PrefixData); + setValueSubclassDataBit(1, PrefixData != nullptr); } Constant *Function::getPrologueData() const { - assert(hasPrologueData()); - const LLVMContextImpl::PrologueDataMapTy &SOMap = - getContext().pImpl->PrologueDataMap; - assert(SOMap.find(this) != SOMap.end()); - return cast(SOMap.find(this)->second->getReturnValue()); + assert(hasPrologueData() && getNumOperands()); + return cast(Op<2>()); } void Function::setPrologueData(Constant *PrologueData) { - if (!PrologueData && !hasPrologueData()) - return; - - unsigned PDData = getSubclassDataFromValue(); - LLVMContextImpl::PrologueDataMapTy &PDMap = getContext().pImpl->PrologueDataMap; - ReturnInst *&PDHolder = PDMap[this]; - if (PrologueData) { - if (PDHolder) - PDHolder->setOperand(0, PrologueData); - else - PDHolder = ReturnInst::Create(getContext(), PrologueData); - PDData |= (1<<2); - } else { - delete PDHolder; - PDMap.erase(this); - PDData &= ~(1<<2); + setHungoffOperand<2>(PrologueData); + setValueSubclassDataBit(2, PrologueData != nullptr); +} + +void Function::allocHungoffUselist() { + // If we've already allocated a uselist, stop here. + if (getNumOperands()) + return; + + allocHungoffUses(3, /*IsPhi=*/ false); + setNumHungOffUseOperands(3); + + // Initialize the uselist with placeholder operands to allow traversal. + auto *CPN = ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0)); + Op<0>().set(CPN); + Op<1>().set(CPN); + Op<2>().set(CPN); +} + +template +void Function::setHungoffOperand(Constant *C) { + if (C) { + allocHungoffUselist(); + Op().set(C); + } else if (getNumOperands()) { + Op().set( + ConstantPointerNull::get(Type::getInt1PtrTy(getContext(), 0))); } - setValueSubclassData(PDData); +} + +void Function::setValueSubclassDataBit(unsigned Bit, bool On) { + assert(Bit < 16 && "SubclassData contains only 16 bits"); + if (On) + setValueSubclassData(getSubclassDataFromValue() | (1 << Bit)); + else + setValueSubclassData(getSubclassDataFromValue() & ~(1 << Bit)); } void Function::setEntryCount(uint64_t Count) { @@ -985,22 +1015,3 @@ Optional Function::getEntryCount() const { } return None; } - -void Function::setPersonalityFn(Constant *C) { - if (!C) { - if (hasPersonalityFn()) { - // Note, the num operands is used to compute the offset of the operand, so - // the order here matters. Clearing the operand then clearing the num - // operands ensures we have the correct offset to the operand. - Op<0>().set(nullptr); - setFunctionNumOperands(0); - } - } else { - // Note, the num operands is used to compute the offset of the operand, so - // the order here matters. We need to set num operands to 1 first so that - // we get the correct offset to the first operand when we set it. - if (!hasPersonalityFn()) - setFunctionNumOperands(1); - Op<0>().set(C); - } -}