X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAsmParser%2FLLParser.h;h=24ff8e750237a86e768fd070676cc46259c25a21;hb=59991f96f9c522f456d9cb6d2eda4a226806d7ff;hp=d8de77908cc93335335b1967e600b5cf6fd99745;hpb=73dee180c836270644dfa7d90f9c5ba877567999;p=oota-llvm.git diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index d8de77908cc..24ff8e75023 100644 --- a/lib/AsmParser/LLParser.h +++ b/lib/AsmParser/LLParser.h @@ -11,8 +11,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_ASMPARSER_LLPARSER_H -#define LLVM_ASMPARSER_LLPARSER_H +#ifndef LLVM_LIB_ASMPARSER_LLPARSER_H +#define LLVM_LIB_ASMPARSER_LLPARSER_H #include "LLLexer.h" #include "llvm/ADT/DenseMap.h" @@ -22,7 +22,7 @@ #include "llvm/IR/Module.h" #include "llvm/IR/Operator.h" #include "llvm/IR/Type.h" -#include "llvm/Support/ValueHandle.h" +#include "llvm/IR/ValueHandle.h" #include namespace llvm { @@ -34,8 +34,10 @@ namespace llvm { class Instruction; class Constant; class GlobalValue; + class Comdat; class MDString; class MDNode; + struct SlotMapping; class StructType; /// ValID - Represents a reference of a definition of some sort with no type. @@ -50,27 +52,26 @@ namespace llvm { t_Null, t_Undef, t_Zero, // No value. t_EmptyArray, // No value: [] t_Constant, // Value in ConstantVal. - t_InlineAsm, // Value in StrVal/StrVal2/UIntVal. - t_MDNode, // Value in MDNodeVal. - t_MDString, // Value in MDStringVal. + t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal. t_ConstantStruct, // Value in ConstantStructElts. t_PackedConstantStruct // Value in ConstantStructElts. - } Kind; + } Kind = t_LocalID; LLLexer::LocTy Loc; unsigned UIntVal; + FunctionType *FTy = nullptr; std::string StrVal, StrVal2; APSInt APSIntVal; - APFloat APFloatVal; + APFloat APFloatVal{0.0}; Constant *ConstantVal; - MDNode *MDNodeVal; - MDString *MDStringVal; - Constant **ConstantStructElts; - - ValID() : Kind(t_LocalID), APFloatVal(0.0) {} - ~ValID() { - if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) - delete [] ConstantStructElts; + std::unique_ptr ConstantStructElts; + + ValID() = default; + ValID(const ValID &RHS) + : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy), + StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal), + APFloatVal(RHS.APFloatVal), ConstantVal(RHS.ConstantVal) { + assert(!RHS.ConstantStructElts); } bool operator<(const ValID &RHS) const { @@ -90,6 +91,7 @@ namespace llvm { LLVMContext &Context; LLLexer Lex; Module *M; + SlotMapping *Slots; // Instruction metadata resolution. Each instruction can have a list of // MDRef info associated with them. @@ -105,32 +107,55 @@ namespace llvm { SMLoc Loc; unsigned MDKind, MDSlot; }; - DenseMap > ForwardRefInstMetadata; + + /// Indicates which operator an operand allows (for the few operands that + /// may only reference a certain operator). + enum OperatorConstraint { + OC_None = 0, // No constraint + OC_CatchPad, // Must be CatchPadInst + OC_CleanupPad // Must be CleanupPadInst + }; + + SmallVector InstsWithTBAATag; // Type resolution handling data structures. The location is set when we // have processed a use of the type but not a definition yet. StringMap > NamedTypes; - std::vector > NumberedTypes; + std::map > NumberedTypes; - std::vector > NumberedMetadata; - std::map, LocTy> > ForwardRefMDNodes; + std::map NumberedMetadata; + std::map> ForwardRefMDNodes; // Global Value reference information. std::map > ForwardRefVals; std::map > ForwardRefValIDs; std::vector NumberedVals; + // Comdat forward reference information. + std::map ForwardRefComdats; + // References to blockaddress. The key is the function ValID, the value is // a list of references to blocks in that function. - std::map > > - ForwardRefBlockAddresses; + std::map> ForwardRefBlockAddresses; + class PerFunctionState; + /// Reference to per-function state to allow basic blocks to be + /// forward-referenced by blockaddress instructions within the same + /// function. + PerFunctionState *BlockAddressPFS; + + // Attribute builder reference information. + std::map > ForwardRefAttrGroups; + std::map NumberedAttrBuilders; public: - LLParser(MemoryBuffer *F, SourceMgr &SM, SMDiagnostic &Err, Module *m) : - Context(m->getContext()), Lex(F, SM, Err, m->getContext()), - M(m) {} + LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, + SlotMapping *Slots = nullptr) + : Context(M->getContext()), Lex(F, SM, Err, M->getContext()), M(M), + Slots(Slots), BlockAddressPFS(nullptr) {} bool Run(); + bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots); + LLVMContext &getContext() { return Context; } private: @@ -142,12 +167,20 @@ namespace llvm { return Error(Lex.getLoc(), Msg); } + /// Restore the internal name and slot mappings using the mappings that + /// were created at an earlier parsing stage. + void restoreParsingState(const SlotMapping *Slots); + /// GetGlobalVal - Get a value with the specified name or ID, creating a /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc); GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc); + /// Get a Comdat with the specified name, creating a forward reference + /// record if needed. + Comdat *getComdat(const std::string &N, LocTy Loc); + // Helper Routines. bool ParseToken(lltok::Kind T, const char *ErrMsg); bool EatIfPresent(lltok::Kind T) { @@ -170,7 +203,8 @@ namespace llvm { return FMF; } - bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) { + bool ParseOptionalToken(lltok::Kind T, bool &Present, + LocTy *Loc = nullptr) { if (Lex.getKind() != T) { Present = false; } else { @@ -187,11 +221,20 @@ namespace llvm { Loc = Lex.getLoc(); return ParseUInt32(Val); } + bool ParseUInt64(uint64_t &Val); + bool ParseUInt64(uint64_t &Val, LocTy &Loc) { + Loc = Lex.getLoc(); + return ParseUInt64(Val); + } + + bool ParseStringAttribute(AttrBuilder &B); bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM); bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM); + bool parseOptionalUnnamedAddr(bool &UnnamedAddr) { + return ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr); + } bool ParseOptionalAddrSpace(unsigned &AddrSpace); - bool ParseOptionalFuncAttrs(AttrBuilder &B); bool ParseOptionalParamAttrs(AttrBuilder &B); bool ParseOptionalReturnAttrs(AttrBuilder &B); bool ParseOptionalLinkage(unsigned &Linkage, bool &HasLinkage); @@ -199,12 +242,16 @@ namespace llvm { bool HasLinkage; return ParseOptionalLinkage(Linkage, HasLinkage); } bool ParseOptionalVisibility(unsigned &Visibility); - bool ParseOptionalCallingConv(CallingConv::ID &CC); + bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass); + bool ParseOptionalCallingConv(unsigned &CC); bool ParseOptionalAlignment(unsigned &Alignment); + bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes); bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope, AtomicOrdering &Ordering); + bool ParseOrdering(AtomicOrdering &Ordering); bool ParseOptionalStackAlignment(unsigned &Alignment); bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); + bool ParseOptionalCommaInAlloca(bool &IsInAlloca); bool ParseIndexList(SmallVectorImpl &Indices,bool &AteExtraComma); bool ParseIndexList(SmallVectorImpl &Indices) { bool AteExtraComma; @@ -229,16 +276,32 @@ namespace llvm { bool ParseUnnamedGlobal(); bool ParseNamedGlobal(); bool ParseGlobal(const std::string &Name, LocTy Loc, unsigned Linkage, - bool HasLinkage, unsigned Visibility); - bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility); + bool HasLinkage, unsigned Visibility, + unsigned DLLStorageClass, + GlobalVariable::ThreadLocalMode TLM, bool UnnamedAddr); + bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Linkage, + unsigned Visibility, unsigned DLLStorageClass, + GlobalVariable::ThreadLocalMode TLM, bool UnnamedAddr); + bool parseComdat(); bool ParseStandaloneMetadata(); bool ParseNamedMetadata(); bool ParseMDString(MDString *&Result); bool ParseMDNodeID(MDNode *&Result); - bool ParseMDNodeID(MDNode *&Result, unsigned &SlotNo); + bool ParseUnnamedAttrGrp(); + bool ParseFnAttributeValuePairs(AttrBuilder &B, + std::vector &FwdRefAttrGrps, + bool inAttrGrp, LocTy &BuiltinLoc); // Type Parsing. - bool ParseType(Type *&Result, bool AllowVoid = false); + bool ParseType(Type *&Result, const Twine &Msg, bool AllowVoid = false); + bool ParseType(Type *&Result, bool AllowVoid = false) { + return ParseType(Result, "expected type", AllowVoid); + } + bool ParseType(Type *&Result, const Twine &Msg, LocTy &Loc, + bool AllowVoid = false) { + Loc = Lex.getLoc(); + return ParseType(Result, Msg, AllowVoid); + } bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) { Loc = Lex.getLoc(); return ParseType(Result, AllowVoid); @@ -274,8 +337,10 @@ namespace llvm { /// GetVal - Get a value with the specified name or ID, creating a /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. - Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc); - Value *GetVal(unsigned ID, Type *Ty, LocTy Loc); + Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc, + OperatorConstraint OC = OC_None); + Value *GetVal(unsigned ID, Type *Ty, LocTy Loc, + OperatorConstraint OC = OC_None); /// SetInstName - After an instruction is parsed and inserted into its /// basic block, this installs its name. @@ -292,14 +357,20 @@ namespace llvm { /// unnamed. If there is an error, this returns null otherwise it returns /// the block being defined. BasicBlock *DefineBB(const std::string &Name, LocTy Loc); + + bool resolveForwardRefBlockAddresses(); }; bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V, - PerFunctionState *PFS); - - bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS); - bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) { - return ParseValue(Ty, V, &PFS); + PerFunctionState *PFS, + OperatorConstraint OC = OC_None); + + bool parseConstantValue(Type *Ty, Constant *&C); + bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS, + OperatorConstraint OC = OC_None); + bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS, + OperatorConstraint OC = OC_None) { + return ParseValue(Ty, V, &PFS, OC); } bool ParseValue(Type *Ty, Value *&V, LocTy &Loc, PerFunctionState &PFS) { @@ -331,17 +402,47 @@ namespace llvm { : Loc(loc), V(v), Attrs(attrs) {} }; bool ParseParameterList(SmallVectorImpl &ArgList, + PerFunctionState &PFS, + bool IsMustTailCall = false, + bool InVarArgsFunc = false); + + bool + ParseOptionalOperandBundles(SmallVectorImpl &BundleList, + PerFunctionState &PFS); + + bool ParseExceptionArgs(SmallVectorImpl &Args, PerFunctionState &PFS); // Constant Parsing. - bool ParseValID(ValID &ID, PerFunctionState *PFS = NULL); + bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr); bool ParseGlobalValue(Type *Ty, Constant *&V); bool ParseGlobalTypeAndValue(Constant *&V); - bool ParseGlobalValueVector(SmallVectorImpl &Elts); - bool ParseMetadataListValue(ValID &ID, PerFunctionState *PFS); - bool ParseMetadataValue(ValID &ID, PerFunctionState *PFS); - bool ParseMDNodeVector(SmallVectorImpl &, PerFunctionState *PFS); - bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS); + bool ParseGlobalValueVector(SmallVectorImpl &Elts); + bool parseOptionalComdat(StringRef GlobalName, Comdat *&C); + bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS); + bool ParseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg, + PerFunctionState *PFS); + bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS); + bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false); + bool ParseMDNode(MDNode *&MD); + bool ParseMDNodeTail(MDNode *&MD); + bool ParseMDNodeVector(SmallVectorImpl &MDs); + bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD); + bool ParseInstructionMetadata(Instruction &Inst); + bool ParseOptionalFunctionMetadata(Function &F); + + template + bool ParseMDField(LocTy Loc, StringRef Name, FieldTy &Result); + template bool ParseMDField(StringRef Name, FieldTy &Result); + template + bool ParseMDFieldsImplBody(ParserTy parseField); + template + bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc); + bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false); + +#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ + bool Parse##CLASS(MDNode *&Result, bool IsDistinct); +#include "llvm/IR/Metadata.def" // Function Parsing. struct ArgInfo { @@ -357,6 +458,8 @@ namespace llvm { bool ParseFunctionBody(Function &Fn); bool ParseBasicBlock(PerFunctionState &PFS); + enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail }; + // Instruction Parsing. Each instruction parsing routine can return with a // normal result, an error result, or return having eaten an extra comma. enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; @@ -370,6 +473,13 @@ namespace llvm { bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); bool ParseResume(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS); + bool ParseTerminatePad(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCatchEndPad(Instruction *&Inst, PerFunctionState &PFS); + bool ParseCleanupEndPad(Instruction *&Inst, PerFunctionState &PFS); bool ParseArithmetic(Instruction *&I, PerFunctionState &PFS, unsigned Opc, unsigned OperandType); @@ -383,7 +493,8 @@ namespace llvm { bool ParseShuffleVector(Instruction *&I, PerFunctionState &PFS); int ParsePHI(Instruction *&I, PerFunctionState &PFS); bool ParseLandingPad(Instruction *&I, PerFunctionState &PFS); - bool ParseCall(Instruction *&I, PerFunctionState &PFS, bool isTail); + bool ParseCall(Instruction *&I, PerFunctionState &PFS, + CallInst::TailCallKind IsTail); int ParseAlloc(Instruction *&I, PerFunctionState &PFS); int ParseLoad(Instruction *&I, PerFunctionState &PFS); int ParseStore(Instruction *&I, PerFunctionState &PFS); @@ -394,9 +505,11 @@ namespace llvm { int ParseExtractValue(Instruction *&I, PerFunctionState &PFS); int ParseInsertValue(Instruction *&I, PerFunctionState &PFS); - bool ResolveForwardRefBlockAddresses(Function *TheFn, - std::vector > &Refs, - PerFunctionState *PFS); + // Use-list order directives. + bool ParseUseListOrder(PerFunctionState *PFS = nullptr); + bool ParseUseListOrderBB(); + bool ParseUseListOrderIndexes(SmallVectorImpl &Indexes); + bool sortUseListOrder(Value *V, ArrayRef Indexes, SMLoc Loc); }; } // End llvm namespace