From 67c32a98315f785a9ec9d531c1f571a0196c7463 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 18 Jan 2015 16:17:27 +0000 Subject: Vendor import of llvm RELEASE_360/rc1 tag r226102 (effectively, 3.6.0 RC1): https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_360/rc1@226102 --- lib/AsmParser/LLParser.h | 104 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 76 insertions(+), 28 deletions(-) (limited to 'lib/AsmParser/LLParser.h') diff --git a/lib/AsmParser/LLParser.h b/lib/AsmParser/LLParser.h index 7203bb245d0f9..220562d66fc7b 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" @@ -52,8 +52,6 @@ namespace llvm { 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_ConstantStruct, // Value in ConstantStructElts. t_PackedConstantStruct // Value in ConstantStructElts. } Kind; @@ -64,8 +62,6 @@ namespace llvm { APSInt APSIntVal; APFloat APFloatVal; Constant *ConstantVal; - MDNode *MDNodeVal; - MDString *MDStringVal; Constant **ConstantStructElts; ValID() : Kind(t_LocalID), APFloatVal(0.0) {} @@ -84,6 +80,31 @@ namespace llvm { } }; + /// Structure to represent an optional metadata field. + template struct MDFieldImpl { + typedef MDFieldImpl ImplTy; + FieldTy Val; + bool Seen; + + void assign(FieldTy Val) { + Seen = true; + this->Val = Val; + } + + explicit MDFieldImpl(FieldTy Default) : Val(Default), Seen(false) {} + }; + template struct MDUnsignedField : public MDFieldImpl { + typedef typename MDUnsignedField::ImplTy ImplTy; + NumTy Max; + + MDUnsignedField(NumTy Default = 0, + NumTy Max = std::numeric_limits::max()) + : ImplTy(Default), Max(Max) {} + }; + struct MDField : public MDFieldImpl { + MDField() : ImplTy(nullptr) {} + }; + class LLParser { public: typedef LLLexer::LocTy LocTy; @@ -106,7 +127,6 @@ namespace llvm { SMLoc Loc; unsigned MDKind, MDSlot; }; - DenseMap > ForwardRefInstMetadata; SmallVector InstsWithTBAATag; @@ -115,8 +135,8 @@ namespace llvm { StringMap > NamedTypes; std::vector > NumberedTypes; - std::vector > NumberedMetadata; - std::map, LocTy> > ForwardRefMDNodes; + std::vector NumberedMetadata; + std::map> ForwardRefMDNodes; // Global Value reference information. std::map > ForwardRefVals; @@ -128,17 +148,21 @@ namespace llvm { // 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) + : Context(m->getContext()), Lex(F, SM, Err, m->getContext()), M(m), + BlockAddressPFS(nullptr) {} bool Run(); LLVMContext &getContext() { return Context; } @@ -222,7 +246,7 @@ namespace llvm { } bool ParseOptionalVisibility(unsigned &Visibility); bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass); - bool ParseOptionalCallingConv(CallingConv::ID &CC); + bool ParseOptionalCallingConv(unsigned &CC); bool ParseOptionalAlignment(unsigned &Alignment); bool ParseOptionalDereferenceableBytes(uint64_t &Bytes); bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope, @@ -258,22 +282,29 @@ namespace llvm { bool HasLinkage, unsigned Visibility, unsigned DLLStorageClass, GlobalVariable::ThreadLocalMode TLM, bool UnnamedAddr); - bool ParseAlias(const std::string &Name, LocTy Loc, unsigned Visibility, - unsigned DLLStorageClass, + 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); @@ -327,6 +358,8 @@ 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, @@ -366,19 +399,32 @@ namespace llvm { : Loc(loc), V(v), Attrs(attrs) {} }; bool ParseParameterList(SmallVectorImpl &ArgList, - PerFunctionState &PFS); + PerFunctionState &PFS, + bool IsMustTailCall = false, + bool InVarArgsFunc = false); // Constant Parsing. bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr); bool ParseGlobalValue(Type *Ty, Constant *&V); bool ParseGlobalTypeAndValue(Constant *&V); - bool ParseGlobalValueVector(SmallVectorImpl &Elts); - bool parseOptionalComdat(Comdat *&C); - bool ParseMetadataListValue(ValID &ID, PerFunctionState *PFS); - bool ParseMetadataValue(ValID &ID, PerFunctionState *PFS); - bool ParseMDNodeVector(SmallVectorImpl &, PerFunctionState *PFS); + bool ParseGlobalValueVector(SmallVectorImpl &Elts); + bool parseOptionalComdat(StringRef GlobalName, Comdat *&C); + bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS); + bool ParseValueAsMetadata(Metadata *&MD, 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 ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS); + bool ParseMDField(LocTy Loc, StringRef Name, + MDUnsignedField &Result); + bool ParseMDField(LocTy Loc, StringRef Name, MDField &Result); + template bool ParseMDFieldsImpl(ParserTy parseField); + bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false); + bool ParseMDLocation(MDNode *&Result, bool IsDistinct); + // Function Parsing. struct ArgInfo { LocTy Loc; @@ -433,9 +479,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 -- cgit v1.2.3