Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 1 | //===-- LLParser.h - Parser Class -------------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the parser class for .ll files. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 00e08fc | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 14 | #ifndef LLVM_LIB_ASMPARSER_LLPARSER_H |
| 15 | #define LLVM_LIB_ASMPARSER_LLPARSER_H |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 16 | |
| 17 | #include "LLLexer.h" |
George Burgess IV | 274105b | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/Optional.h" |
Chandler Carruth | a1514e2 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringMap.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Attributes.h" |
| 21 | #include "llvm/IR/Instructions.h" |
| 22 | #include "llvm/IR/Module.h" |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 23 | #include "llvm/IR/ModuleSummaryIndex.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 24 | #include "llvm/IR/Operator.h" |
| 25 | #include "llvm/IR/Type.h" |
Chandler Carruth | eb3d76d | 2014-03-04 11:17:44 +0000 | [diff] [blame] | 26 | #include "llvm/IR/ValueHandle.h" |
Chris Lattner | e80250e | 2009-12-29 21:43:58 +0000 | [diff] [blame] | 27 | #include <map> |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 28 | |
| 29 | namespace llvm { |
| 30 | class Module; |
| 31 | class OpaqueType; |
| 32 | class Function; |
| 33 | class Value; |
| 34 | class BasicBlock; |
| 35 | class Instruction; |
| 36 | class Constant; |
| 37 | class GlobalValue; |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 38 | class Comdat; |
Nick Lewycky | 21cc446 | 2009-04-04 07:22:01 +0000 | [diff] [blame] | 39 | class MDString; |
| 40 | class MDNode; |
Alex Lorenz | d31dc69 | 2015-06-23 17:10:10 +0000 | [diff] [blame] | 41 | struct SlotMapping; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 42 | class StructType; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 44 | /// ValID - Represents a reference of a definition of some sort with no type. |
| 45 | /// There are several cases where we have to parse the value but where the |
| 46 | /// type can depend on later context. This may either be a numeric reference |
| 47 | /// or a symbolic (%var) reference. This is just a discriminated union. |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 48 | struct ValID { |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 49 | enum { |
David Majnemer | 83fc12a | 2015-11-11 21:57:16 +0000 | [diff] [blame] | 50 | t_LocalID, t_GlobalID, // ID in UIntVal. |
| 51 | t_LocalName, t_GlobalName, // Name in StrVal. |
| 52 | t_APSInt, t_APFloat, // Value in APSIntVal/APFloatVal. |
| 53 | t_Null, t_Undef, t_Zero, t_None, // No value. |
| 54 | t_EmptyArray, // No value: [] |
| 55 | t_Constant, // Value in ConstantVal. |
| 56 | t_InlineAsm, // Value in FTy/StrVal/StrVal2/UIntVal. |
| 57 | t_ConstantStruct, // Value in ConstantStructElts. |
| 58 | t_PackedConstantStruct // Value in ConstantStructElts. |
David Blaikie | afb5379 | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 59 | } Kind = t_LocalID; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 61 | LLLexer::LocTy Loc; |
| 62 | unsigned UIntVal; |
Karl Schimpf | e2dfa01 | 2015-09-03 16:18:32 +0000 | [diff] [blame] | 63 | FunctionType *FTy = nullptr; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 64 | std::string StrVal, StrVal2; |
| 65 | APSInt APSIntVal; |
David Blaikie | afb5379 | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 66 | APFloat APFloatVal{0.0}; |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 67 | Constant *ConstantVal; |
David Blaikie | afb5379 | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 68 | std::unique_ptr<Constant *[]> ConstantStructElts; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 69 | |
David Blaikie | afb5379 | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 70 | ValID() = default; |
David Blaikie | 5b8c55e | 2015-08-03 20:30:53 +0000 | [diff] [blame] | 71 | ValID(const ValID &RHS) |
David Blaikie | afb5379 | 2015-08-03 20:08:41 +0000 | [diff] [blame] | 72 | : Kind(RHS.Kind), Loc(RHS.Loc), UIntVal(RHS.UIntVal), FTy(RHS.FTy), |
David Blaikie | 5b8c55e | 2015-08-03 20:30:53 +0000 | [diff] [blame] | 73 | StrVal(RHS.StrVal), StrVal2(RHS.StrVal2), APSIntVal(RHS.APSIntVal), |
| 74 | APFloatVal(RHS.APFloatVal), ConstantVal(RHS.ConstantVal) { |
| 75 | assert(!RHS.ConstantStructElts); |
| 76 | } |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 78 | bool operator<(const ValID &RHS) const { |
| 79 | if (Kind == t_LocalID || Kind == t_GlobalID) |
| 80 | return UIntVal < RHS.UIntVal; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 81 | assert((Kind == t_LocalName || Kind == t_GlobalName || |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 82 | Kind == t_ConstantStruct || Kind == t_PackedConstantStruct) && |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 83 | "Ordering not defined for this ValID kind yet"); |
| 84 | return StrVal < RHS.StrVal; |
| 85 | } |
| 86 | }; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 87 | |
Benjamin Kramer | 55c06ae | 2013-09-11 18:05:11 +0000 | [diff] [blame] | 88 | class LLParser { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 89 | public: |
| 90 | typedef LLLexer::LocTy LocTy; |
| 91 | private: |
Chris Lattner | 4ba9d9b | 2010-04-07 04:08:57 +0000 | [diff] [blame] | 92 | LLVMContext &Context; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 93 | LLLexer Lex; |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 94 | // Module being parsed, null if we are only parsing summary index. |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 95 | Module *M; |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 96 | // Summary index being parsed, null if we are only parsing Module. |
| 97 | ModuleSummaryIndex *Index; |
Alex Lorenz | d31dc69 | 2015-06-23 17:10:10 +0000 | [diff] [blame] | 98 | SlotMapping *Slots; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 99 | |
Chris Lattner | 449c310 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 100 | // Instruction metadata resolution. Each instruction can have a list of |
| 101 | // MDRef info associated with them. |
Dan Gohman | 41d6ab4 | 2010-08-24 14:31:06 +0000 | [diff] [blame] | 102 | // |
| 103 | // The simpler approach of just creating temporary MDNodes and then calling |
| 104 | // RAUW on them when the definition is processed doesn't work because some |
| 105 | // instruction metadata kinds, such as dbg, get stored in the IR in an |
| 106 | // "optimized" format which doesn't participate in the normal value use |
| 107 | // lists. This means that RAUW doesn't work, even on temporary MDNodes |
| 108 | // which otherwise support RAUW. Instead, we defer resolving MDNode |
| 109 | // references until the definitions have been processed. |
Chris Lattner | 449c310 | 2010-04-01 05:14:45 +0000 | [diff] [blame] | 110 | struct MDRef { |
| 111 | SMLoc Loc; |
| 112 | unsigned MDKind, MDSlot; |
| 113 | }; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 114 | |
Manman Ren | 804f034 | 2013-09-28 00:22:27 +0000 | [diff] [blame] | 115 | SmallVector<Instruction*, 64> InstsWithTBAATag; |
| 116 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 117 | // Type resolution handling data structures. The location is set when we |
| 118 | // have processed a use of the type but not a definition yet. |
| 119 | StringMap<std::pair<Type*, LocTy> > NamedTypes; |
David Majnemer | 4762c0b | 2015-02-11 07:43:56 +0000 | [diff] [blame] | 120 | std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 121 | |
David Majnemer | 4762c0b | 2015-02-11 07:43:56 +0000 | [diff] [blame] | 122 | std::map<unsigned, TrackingMDNodeRef> NumberedMetadata; |
Duncan P. N. Exon Smith | f9eaea7 | 2015-01-19 21:30:18 +0000 | [diff] [blame] | 123 | std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 124 | |
| 125 | // Global Value reference information. |
| 126 | std::map<std::string, std::pair<GlobalValue*, LocTy> > ForwardRefVals; |
| 127 | std::map<unsigned, std::pair<GlobalValue*, LocTy> > ForwardRefValIDs; |
| 128 | std::vector<GlobalValue*> NumberedVals; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 129 | |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 130 | // Comdat forward reference information. |
| 131 | std::map<std::string, LocTy> ForwardRefComdats; |
| 132 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 133 | // References to blockaddress. The key is the function ValID, the value is |
| 134 | // a list of references to blocks in that function. |
Duncan P. N. Exon Smith | 1658978 | 2014-08-19 00:13:19 +0000 | [diff] [blame] | 135 | std::map<ValID, std::map<ValID, GlobalValue *>> ForwardRefBlockAddresses; |
| 136 | class PerFunctionState; |
| 137 | /// Reference to per-function state to allow basic blocks to be |
| 138 | /// forward-referenced by blockaddress instructions within the same |
| 139 | /// function. |
| 140 | PerFunctionState *BlockAddressPFS; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 141 | |
Bill Wendling | 95ce4c2 | 2013-02-06 06:52:58 +0000 | [diff] [blame] | 142 | // Attribute builder reference information. |
Bill Wendling | baad55c | 2013-02-08 06:32:06 +0000 | [diff] [blame] | 143 | std::map<Value*, std::vector<unsigned> > ForwardRefAttrGroups; |
| 144 | std::map<unsigned, AttrBuilder> NumberedAttrBuilders; |
Bill Wendling | 95ce4c2 | 2013-02-06 06:52:58 +0000 | [diff] [blame] | 145 | |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 146 | // Summary global value reference information. |
| 147 | std::map<unsigned, std::vector<std::pair<ValueInfo *, LocTy>>> |
| 148 | ForwardRefValueInfos; |
| 149 | std::map<unsigned, std::vector<std::pair<AliasSummary *, LocTy>>> |
| 150 | ForwardRefAliasees; |
| 151 | std::vector<ValueInfo> NumberedValueInfos; |
| 152 | |
| 153 | // Summary type id reference information. |
| 154 | std::map<unsigned, std::vector<std::pair<GlobalValue::GUID *, LocTy>>> |
| 155 | ForwardRefTypeIds; |
| 156 | |
| 157 | // Map of module ID to path. |
| 158 | std::map<unsigned, StringRef> ModuleIdMap; |
| 159 | |
Adrian Prantl | 733fe2f | 2017-10-02 18:31:29 +0000 | [diff] [blame] | 160 | /// Only the llvm-as tool may set this to false to bypass |
| 161 | /// UpgradeDebuginfo so it can generate broken bitcode. |
| 162 | bool UpgradeDebugInfo; |
| 163 | |
Yaxun Liu | 7c2d049 | 2018-01-30 22:32:39 +0000 | [diff] [blame] | 164 | /// DataLayout string to override that in LLVM assembly. |
| 165 | StringRef DataLayoutStr; |
| 166 | |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 167 | std::string SourceFileName; |
| 168 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 169 | public: |
Alex Lorenz | d31dc69 | 2015-06-23 17:10:10 +0000 | [diff] [blame] | 170 | LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M, |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 171 | ModuleSummaryIndex *Index, LLVMContext &Context, |
Yaxun Liu | 7c2d049 | 2018-01-30 22:32:39 +0000 | [diff] [blame] | 172 | SlotMapping *Slots = nullptr, bool UpgradeDebugInfo = true, |
| 173 | StringRef DataLayoutString = "") |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 174 | : Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index), |
Adrian Prantl | 733fe2f | 2017-10-02 18:31:29 +0000 | [diff] [blame] | 175 | Slots(Slots), BlockAddressPFS(nullptr), |
Yaxun Liu | 7c2d049 | 2018-01-30 22:32:39 +0000 | [diff] [blame] | 176 | UpgradeDebugInfo(UpgradeDebugInfo), DataLayoutStr(DataLayoutString) { |
| 177 | if (!DataLayoutStr.empty()) |
| 178 | M->setDataLayout(DataLayoutStr); |
| 179 | } |
Chris Lattner | ad7d1e2 | 2009-01-04 20:44:11 +0000 | [diff] [blame] | 180 | bool Run(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 181 | |
Alex Lorenz | 0e99876 | 2015-08-21 21:32:39 +0000 | [diff] [blame] | 182 | bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots); |
Alex Lorenz | 4b50ecb | 2015-07-17 22:07:03 +0000 | [diff] [blame] | 183 | |
Quentin Colombet | cbd4dbb | 2016-03-08 00:37:07 +0000 | [diff] [blame] | 184 | bool parseTypeAtBeginning(Type *&Ty, unsigned &Read, |
| 185 | const SlotMapping *Slots); |
Quentin Colombet | 2ba0323 | 2016-03-07 22:09:05 +0000 | [diff] [blame] | 186 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 187 | LLVMContext &getContext() { return Context; } |
Owen Anderson | b43eae7 | 2009-07-02 17:04:01 +0000 | [diff] [blame] | 188 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 189 | private: |
| 190 | |
Benjamin Kramer | d1e1703 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 191 | bool Error(LocTy L, const Twine &Msg) const { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 192 | return Lex.Error(L, Msg); |
| 193 | } |
Benjamin Kramer | d1e1703 | 2010-09-27 17:42:11 +0000 | [diff] [blame] | 194 | bool TokError(const Twine &Msg) const { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 195 | return Error(Lex.getLoc(), Msg); |
| 196 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 197 | |
Alex Lorenz | 0e99876 | 2015-08-21 21:32:39 +0000 | [diff] [blame] | 198 | /// Restore the internal name and slot mappings using the mappings that |
| 199 | /// were created at an earlier parsing stage. |
| 200 | void restoreParsingState(const SlotMapping *Slots); |
| 201 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 202 | /// GetGlobalVal - Get a value with the specified name or ID, creating a |
| 203 | /// forward reference record if needed. This can return null if the value |
| 204 | /// exists but does not have the right type. |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 205 | GlobalValue *GetGlobalVal(const std::string &N, Type *Ty, LocTy Loc, |
| 206 | bool IsCall); |
| 207 | GlobalValue *GetGlobalVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 208 | |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 209 | /// Get a Comdat with the specified name, creating a forward reference |
| 210 | /// record if needed. |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 211 | Comdat *getComdat(const std::string &Name, LocTy Loc); |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 212 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 213 | // Helper Routines. |
| 214 | bool ParseToken(lltok::Kind T, const char *ErrMsg); |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 215 | bool EatIfPresent(lltok::Kind T) { |
| 216 | if (Lex.getKind() != T) return false; |
| 217 | Lex.Lex(); |
| 218 | return true; |
| 219 | } |
Michael Ilseman | 15c13d3 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 220 | |
| 221 | FastMathFlags EatFastMathFlagsIfPresent() { |
| 222 | FastMathFlags FMF; |
| 223 | while (true) |
| 224 | switch (Lex.getKind()) { |
Sanjay Patel | 00e900a | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 225 | case lltok::kw_fast: FMF.setFast(); Lex.Lex(); continue; |
Michael Ilseman | 1638b83 | 2012-12-09 21:12:04 +0000 | [diff] [blame] | 226 | case lltok::kw_nnan: FMF.setNoNaNs(); Lex.Lex(); continue; |
| 227 | case lltok::kw_ninf: FMF.setNoInfs(); Lex.Lex(); continue; |
| 228 | case lltok::kw_nsz: FMF.setNoSignedZeros(); Lex.Lex(); continue; |
| 229 | case lltok::kw_arcp: FMF.setAllowReciprocal(); Lex.Lex(); continue; |
Adam Nemet | 5c57c11 | 2017-03-28 20:11:52 +0000 | [diff] [blame] | 230 | case lltok::kw_contract: |
| 231 | FMF.setAllowContract(true); |
| 232 | Lex.Lex(); |
| 233 | continue; |
Sanjay Patel | 00e900a | 2017-11-06 16:27:15 +0000 | [diff] [blame] | 234 | case lltok::kw_reassoc: FMF.setAllowReassoc(); Lex.Lex(); continue; |
| 235 | case lltok::kw_afn: FMF.setApproxFunc(); Lex.Lex(); continue; |
Michael Ilseman | 15c13d3 | 2012-11-27 00:42:44 +0000 | [diff] [blame] | 236 | default: return FMF; |
| 237 | } |
| 238 | return FMF; |
| 239 | } |
| 240 | |
Craig Topper | 695aa80 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 241 | bool ParseOptionalToken(lltok::Kind T, bool &Present, |
| 242 | LocTy *Loc = nullptr) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 243 | if (Lex.getKind() != T) { |
| 244 | Present = false; |
| 245 | } else { |
Rafael Espindola | d72479c | 2011-01-13 01:30:30 +0000 | [diff] [blame] | 246 | if (Loc) |
| 247 | *Loc = Lex.getLoc(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 248 | Lex.Lex(); |
| 249 | Present = true; |
| 250 | } |
| 251 | return false; |
| 252 | } |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 253 | bool ParseStringConstant(std::string &Result); |
| 254 | bool ParseUInt32(unsigned &Val); |
| 255 | bool ParseUInt32(unsigned &Val, LocTy &Loc) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 256 | Loc = Lex.getLoc(); |
Chris Lattner | 3ed88ef | 2009-01-02 08:05:26 +0000 | [diff] [blame] | 257 | return ParseUInt32(Val); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 258 | } |
Hal Finkel | 11af4b4 | 2014-07-18 15:51:28 +0000 | [diff] [blame] | 259 | bool ParseUInt64(uint64_t &Val); |
| 260 | bool ParseUInt64(uint64_t &Val, LocTy &Loc) { |
| 261 | Loc = Lex.getLoc(); |
| 262 | return ParseUInt64(Val); |
| 263 | } |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 264 | bool ParseFlag(unsigned &Val); |
Hans Wennborg | ce718ff | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 265 | |
Artur Pilipenko | 9987cb6 | 2015-08-03 14:31:49 +0000 | [diff] [blame] | 266 | bool ParseStringAttribute(AttrBuilder &B); |
| 267 | |
Hans Wennborg | ce718ff | 2012-06-23 11:37:03 +0000 | [diff] [blame] | 268 | bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM); |
| 269 | bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM); |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 270 | bool ParseOptionalUnnamedAddr(GlobalVariable::UnnamedAddr &UnnamedAddr); |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 271 | bool ParseOptionalAddrSpace(unsigned &AddrSpace, unsigned DefaultAS = 0); |
| 272 | bool ParseOptionalProgramAddrSpace(unsigned &AddrSpace) { |
| 273 | return ParseOptionalAddrSpace( |
| 274 | AddrSpace, M->getDataLayout().getProgramAddressSpace()); |
| 275 | }; |
Bill Wendling | e01b81b | 2012-12-04 23:40:58 +0000 | [diff] [blame] | 276 | bool ParseOptionalParamAttrs(AttrBuilder &B); |
| 277 | bool ParseOptionalReturnAttrs(AttrBuilder &B); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 278 | bool ParseOptionalLinkage(unsigned &Res, bool &HasLinkage, |
Sean Fertile | 509132b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 279 | unsigned &Visibility, unsigned &DLLStorageClass, |
| 280 | bool &DSOLocal); |
| 281 | void ParseOptionalDSOLocal(bool &DSOLocal); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 282 | void ParseOptionalVisibility(unsigned &Res); |
| 283 | void ParseOptionalDLLStorageClass(unsigned &Res); |
Alexey Samsonov | 5e4558e | 2014-09-10 18:00:17 +0000 | [diff] [blame] | 284 | bool ParseOptionalCallingConv(unsigned &CC); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 285 | bool ParseOptionalAlignment(unsigned &Alignment); |
Sanjoy Das | 5ff5907 | 2015-04-16 20:29:50 +0000 | [diff] [blame] | 286 | bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes); |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 287 | bool ParseScopeAndOrdering(bool isAtomic, SyncScope::ID &SSID, |
Eli Friedman | 47f3513 | 2011-07-25 23:16:38 +0000 | [diff] [blame] | 288 | AtomicOrdering &Ordering); |
Konstantin Zhuravlyov | 8f85685 | 2017-07-11 22:23:00 +0000 | [diff] [blame] | 289 | bool ParseScope(SyncScope::ID &SSID); |
Tim Northover | ca396e3 | 2014-03-11 10:48:52 +0000 | [diff] [blame] | 290 | bool ParseOrdering(AtomicOrdering &Ordering); |
Charles Davis | 1e063d1 | 2010-02-12 00:31:15 +0000 | [diff] [blame] | 291 | bool ParseOptionalStackAlignment(unsigned &Alignment); |
Chris Lattner | c3a6c5c | 2009-12-30 05:44:30 +0000 | [diff] [blame] | 292 | bool ParseOptionalCommaAlign(unsigned &Alignment, bool &AteExtraComma); |
Matt Arsenault | e0b3c33 | 2017-04-10 22:27:50 +0000 | [diff] [blame] | 293 | bool ParseOptionalCommaAddrSpace(unsigned &AddrSpace, LocTy &Loc, |
| 294 | bool &AteExtraComma); |
Reid Kleckner | 3cbfa16 | 2014-01-17 23:58:17 +0000 | [diff] [blame] | 295 | bool ParseOptionalCommaInAlloca(bool &IsInAlloca); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 296 | bool parseAllocSizeArguments(unsigned &BaseSizeArg, |
George Burgess IV | 274105b | 2016-04-12 01:05:35 +0000 | [diff] [blame] | 297 | Optional<unsigned> &HowManyArg); |
| 298 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices, |
| 299 | bool &AteExtraComma); |
Chris Lattner | 628c13a | 2009-12-30 05:14:00 +0000 | [diff] [blame] | 300 | bool ParseIndexList(SmallVectorImpl<unsigned> &Indices) { |
| 301 | bool AteExtraComma; |
| 302 | if (ParseIndexList(Indices, AteExtraComma)) return true; |
| 303 | if (AteExtraComma) |
| 304 | return TokError("expected index"); |
| 305 | return false; |
| 306 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 307 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 308 | // Top-Level Entities |
| 309 | bool ParseTopLevelEntities(); |
| 310 | bool ValidateEndOfModule(); |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 311 | bool ValidateEndOfIndex(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 312 | bool ParseTargetDefinition(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 313 | bool ParseModuleAsm(); |
Teresa Johnson | 2dec5fc | 2016-03-30 18:15:08 +0000 | [diff] [blame] | 314 | bool ParseSourceFileName(); |
Bill Wendling | 3defc0b | 2012-11-28 08:41:48 +0000 | [diff] [blame] | 315 | bool ParseDepLibs(); // FIXME: Remove in 4.0. |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 316 | bool ParseUnnamedType(); |
| 317 | bool ParseNamedType(); |
| 318 | bool ParseDeclare(); |
| 319 | bool ParseDefine(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 320 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 321 | bool ParseGlobalType(bool &IsConstant); |
Dan Gohman | 3845e50 | 2009-08-12 23:32:33 +0000 | [diff] [blame] | 322 | bool ParseUnnamedGlobal(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 323 | bool ParseNamedGlobal(); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 324 | bool ParseGlobal(const std::string &Name, LocTy NameLoc, unsigned Linkage, |
Nico Rieck | 38f68c5 | 2014-01-14 15:22:47 +0000 | [diff] [blame] | 325 | bool HasLinkage, unsigned Visibility, |
Sean Fertile | 509132b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 326 | unsigned DLLStorageClass, bool DSOLocal, |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 327 | GlobalVariable::ThreadLocalMode TLM, |
| 328 | GlobalVariable::UnnamedAddr UnnamedAddr); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 329 | bool parseIndirectSymbol(const std::string &Name, LocTy NameLoc, |
| 330 | unsigned L, unsigned Visibility, |
Sean Fertile | 509132b | 2017-10-26 15:00:26 +0000 | [diff] [blame] | 331 | unsigned DLLStorageClass, bool DSOLocal, |
Dmitry Polukhin | 51a06a2 | 2016-04-05 08:47:51 +0000 | [diff] [blame] | 332 | GlobalVariable::ThreadLocalMode TLM, |
Peter Collingbourne | 63b34cd | 2016-06-14 21:01:22 +0000 | [diff] [blame] | 333 | GlobalVariable::UnnamedAddr UnnamedAddr); |
David Majnemer | c8a1169 | 2014-06-27 18:19:56 +0000 | [diff] [blame] | 334 | bool parseComdat(); |
Devang Patel | 923078c | 2009-07-01 19:21:12 +0000 | [diff] [blame] | 335 | bool ParseStandaloneMetadata(); |
Devang Patel | eff2ab6 | 2009-07-29 00:34:02 +0000 | [diff] [blame] | 336 | bool ParseNamedMetadata(); |
Chris Lattner | 442ffa1 | 2009-12-29 21:53:55 +0000 | [diff] [blame] | 337 | bool ParseMDString(MDString *&Result); |
Chris Lattner | 4a72efc | 2009-12-30 04:15:23 +0000 | [diff] [blame] | 338 | bool ParseMDNodeID(MDNode *&Result); |
Bill Wendling | 95ce4c2 | 2013-02-06 06:52:58 +0000 | [diff] [blame] | 339 | bool ParseUnnamedAttrGrp(); |
Bill Wendling | baad55c | 2013-02-08 06:32:06 +0000 | [diff] [blame] | 340 | bool ParseFnAttributeValuePairs(AttrBuilder &B, |
| 341 | std::vector<unsigned> &FwdRefAttrGrps, |
Michael Gottesman | 2253a2f | 2013-06-27 00:25:01 +0000 | [diff] [blame] | 342 | bool inAttrGrp, LocTy &BuiltinLoc); |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 343 | |
| 344 | // Module Summary Index Parsing. |
Teresa Johnson | a9a2147 | 2018-05-26 02:34:13 +0000 | [diff] [blame] | 345 | bool SkipModuleSummaryEntry(); |
| 346 | bool ParseSummaryEntry(); |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 347 | bool ParseModuleEntry(unsigned ID); |
| 348 | bool ParseModuleReference(StringRef &ModulePath); |
| 349 | bool ParseGVReference(ValueInfo &VI, unsigned &GVId); |
| 350 | bool ParseGVEntry(unsigned ID); |
| 351 | bool ParseFunctionSummary(std::string Name, GlobalValue::GUID, unsigned ID); |
| 352 | bool ParseVariableSummary(std::string Name, GlobalValue::GUID, unsigned ID); |
| 353 | bool ParseAliasSummary(std::string Name, GlobalValue::GUID, unsigned ID); |
| 354 | bool ParseGVFlags(GlobalValueSummary::GVFlags &GVFlags); |
Eugene Leviant | ae9f773 | 2018-11-23 10:54:51 +0000 | [diff] [blame] | 355 | bool ParseGVarFlags(GlobalVarSummary::GVarFlags &GVarFlags); |
Teresa Johnson | c6dda90 | 2018-06-26 13:56:49 +0000 | [diff] [blame] | 356 | bool ParseOptionalFFlags(FunctionSummary::FFlags &FFlags); |
| 357 | bool ParseOptionalCalls(std::vector<FunctionSummary::EdgeTy> &Calls); |
| 358 | bool ParseHotness(CalleeInfo::HotnessType &Hotness); |
| 359 | bool ParseOptionalTypeIdInfo(FunctionSummary::TypeIdInfo &TypeIdInfo); |
| 360 | bool ParseTypeTests(std::vector<GlobalValue::GUID> &TypeTests); |
| 361 | bool ParseVFuncIdList(lltok::Kind Kind, |
| 362 | std::vector<FunctionSummary::VFuncId> &VFuncIdList); |
| 363 | bool ParseConstVCallList( |
| 364 | lltok::Kind Kind, |
| 365 | std::vector<FunctionSummary::ConstVCall> &ConstVCallList); |
| 366 | using IdToIndexMapType = |
| 367 | std::map<unsigned, std::vector<std::pair<unsigned, LocTy>>>; |
| 368 | bool ParseConstVCall(FunctionSummary::ConstVCall &ConstVCall, |
| 369 | IdToIndexMapType &IdToIndexMap, unsigned Index); |
| 370 | bool ParseVFuncId(FunctionSummary::VFuncId &VFuncId, |
| 371 | IdToIndexMapType &IdToIndexMap, unsigned Index); |
| 372 | bool ParseOptionalRefs(std::vector<ValueInfo> &Refs); |
| 373 | bool ParseTypeIdEntry(unsigned ID); |
| 374 | bool ParseTypeIdSummary(TypeIdSummary &TIS); |
| 375 | bool ParseTypeTestResolution(TypeTestResolution &TTRes); |
| 376 | bool ParseOptionalWpdResolutions( |
| 377 | std::map<uint64_t, WholeProgramDevirtResolution> &WPDResMap); |
| 378 | bool ParseWpdRes(WholeProgramDevirtResolution &WPDRes); |
| 379 | bool ParseOptionalResByArg( |
| 380 | std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> |
| 381 | &ResByArg); |
| 382 | bool ParseArgs(std::vector<uint64_t> &Args); |
| 383 | void AddGlobalValueToIndex(std::string Name, GlobalValue::GUID, |
| 384 | GlobalValue::LinkageTypes Linkage, unsigned ID, |
| 385 | std::unique_ptr<GlobalValueSummary> Summary); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 386 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 387 | // Type Parsing. |
Duncan P. N. Exon Smith | 1ef70ff | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 388 | bool ParseType(Type *&Result, const Twine &Msg, bool AllowVoid = false); |
| 389 | bool ParseType(Type *&Result, bool AllowVoid = false) { |
| 390 | return ParseType(Result, "expected type", AllowVoid); |
| 391 | } |
| 392 | bool ParseType(Type *&Result, const Twine &Msg, LocTy &Loc, |
| 393 | bool AllowVoid = false) { |
| 394 | Loc = Lex.getLoc(); |
| 395 | return ParseType(Result, Msg, AllowVoid); |
| 396 | } |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 397 | bool ParseType(Type *&Result, LocTy &Loc, bool AllowVoid = false) { |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 398 | Loc = Lex.getLoc(); |
Chris Lattner | a9a9e07 | 2009-03-09 04:49:14 +0000 | [diff] [blame] | 399 | return ParseType(Result, AllowVoid); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 400 | } |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 401 | bool ParseAnonStructType(Type *&Result, bool Packed); |
| 402 | bool ParseStructBody(SmallVectorImpl<Type*> &Body); |
| 403 | bool ParseStructDefinition(SMLoc TypeLoc, StringRef Name, |
| 404 | std::pair<Type*, LocTy> &Entry, |
| 405 | Type *&ResultTy); |
| 406 | |
| 407 | bool ParseArrayVectorType(Type *&Result, bool isVector); |
| 408 | bool ParseFunctionType(Type *&Result); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 409 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 410 | // Function Semantic Analysis. |
| 411 | class PerFunctionState { |
| 412 | LLParser &P; |
| 413 | Function &F; |
| 414 | std::map<std::string, std::pair<Value*, LocTy> > ForwardRefVals; |
| 415 | std::map<unsigned, std::pair<Value*, LocTy> > ForwardRefValIDs; |
| 416 | std::vector<Value*> NumberedVals; |
Michael Ilseman | 407a616 | 2012-11-15 22:34:00 +0000 | [diff] [blame] | 417 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 418 | /// FunctionNumber - If this is an unnamed function, this is the slot |
| 419 | /// number of it, otherwise it is -1. |
| 420 | int FunctionNumber; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 421 | public: |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 422 | PerFunctionState(LLParser &p, Function &f, int functionNumber); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 423 | ~PerFunctionState(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 424 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 425 | Function &getFunction() const { return F; } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 426 | |
Chris Lattner | 09d9ef4 | 2009-10-28 03:39:23 +0000 | [diff] [blame] | 427 | bool FinishFunction(); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 428 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 429 | /// GetVal - Get a value with the specified name or ID, creating a |
| 430 | /// forward reference record if needed. This can return null if the value |
| 431 | /// exists but does not have the right type. |
Alexander Richardson | b0b9884 | 2018-02-27 11:15:11 +0000 | [diff] [blame] | 432 | Value *GetVal(const std::string &Name, Type *Ty, LocTy Loc, bool IsCall); |
| 433 | Value *GetVal(unsigned ID, Type *Ty, LocTy Loc, bool IsCall); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 434 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 435 | /// SetInstName - After an instruction is parsed and inserted into its |
| 436 | /// basic block, this installs its name. |
| 437 | bool SetInstName(int NameID, const std::string &NameStr, LocTy NameLoc, |
| 438 | Instruction *Inst); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 439 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 440 | /// GetBB - Get a basic block with the specified name or ID, creating a |
| 441 | /// forward reference record if needed. This can return null if the value |
| 442 | /// is not a BasicBlock. |
| 443 | BasicBlock *GetBB(const std::string &Name, LocTy Loc); |
| 444 | BasicBlock *GetBB(unsigned ID, LocTy Loc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 445 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 446 | /// DefineBB - Define the specified basic block, which is either named or |
| 447 | /// unnamed. If there is an error, this returns null otherwise it returns |
| 448 | /// the block being defined. |
| 449 | BasicBlock *DefineBB(const std::string &Name, LocTy Loc); |
Duncan P. N. Exon Smith | 1658978 | 2014-08-19 00:13:19 +0000 | [diff] [blame] | 450 | |
| 451 | bool resolveForwardRefBlockAddresses(); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 452 | }; |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 453 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 454 | bool ConvertValIDToValue(Type *Ty, ValID &ID, Value *&V, |
Alexander Richardson | b0b9884 | 2018-02-27 11:15:11 +0000 | [diff] [blame] | 455 | PerFunctionState *PFS, bool IsCall); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 456 | |
Alexander Richardson | 47ff67b | 2018-08-23 09:25:17 +0000 | [diff] [blame] | 457 | Value *checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty, |
| 458 | Value *Val, bool IsCall); |
| 459 | |
Alex Lorenz | 4b50ecb | 2015-07-17 22:07:03 +0000 | [diff] [blame] | 460 | bool parseConstantValue(Type *Ty, Constant *&C); |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 461 | bool ParseValue(Type *Ty, Value *&V, PerFunctionState *PFS); |
| 462 | bool ParseValue(Type *Ty, Value *&V, PerFunctionState &PFS) { |
| 463 | return ParseValue(Ty, V, &PFS); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 464 | } |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 465 | |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 466 | bool ParseValue(Type *Ty, Value *&V, LocTy &Loc, |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 467 | PerFunctionState &PFS) { |
| 468 | Loc = Lex.getLoc(); |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 469 | return ParseValue(Ty, V, &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 470 | } |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 471 | |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 472 | bool ParseTypeAndValue(Value *&V, PerFunctionState *PFS); |
| 473 | bool ParseTypeAndValue(Value *&V, PerFunctionState &PFS) { |
| 474 | return ParseTypeAndValue(V, &PFS); |
| 475 | } |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 476 | bool ParseTypeAndValue(Value *&V, LocTy &Loc, PerFunctionState &PFS) { |
| 477 | Loc = Lex.getLoc(); |
| 478 | return ParseTypeAndValue(V, PFS); |
| 479 | } |
Chris Lattner | f9be95f | 2009-10-27 19:13:16 +0000 | [diff] [blame] | 480 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, LocTy &Loc, |
| 481 | PerFunctionState &PFS); |
| 482 | bool ParseTypeAndBasicBlock(BasicBlock *&BB, PerFunctionState &PFS) { |
| 483 | LocTy Loc; |
| 484 | return ParseTypeAndBasicBlock(BB, Loc, PFS); |
| 485 | } |
Victor Hernandez | 1971556 | 2009-12-03 23:40:58 +0000 | [diff] [blame] | 486 | |
Chris Lattner | fdfeb69 | 2010-02-12 20:49:41 +0000 | [diff] [blame] | 487 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 488 | struct ParamInfo { |
| 489 | LocTy Loc; |
| 490 | Value *V; |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 491 | AttributeSet Attrs; |
| 492 | ParamInfo(LocTy loc, Value *v, AttributeSet attrs) |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 493 | : Loc(loc), V(v), Attrs(attrs) {} |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 494 | }; |
| 495 | bool ParseParameterList(SmallVectorImpl<ParamInfo> &ArgList, |
Reid Kleckner | 44b3a0b | 2014-08-26 00:33:28 +0000 | [diff] [blame] | 496 | PerFunctionState &PFS, |
| 497 | bool IsMustTailCall = false, |
| 498 | bool InVarArgsFunc = false); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 499 | |
Sanjoy Das | f70eb72 | 2015-09-24 23:34:52 +0000 | [diff] [blame] | 500 | bool |
| 501 | ParseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList, |
| 502 | PerFunctionState &PFS); |
| 503 | |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 504 | bool ParseExceptionArgs(SmallVectorImpl<Value *> &Args, |
| 505 | PerFunctionState &PFS); |
| 506 | |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 507 | // Constant Parsing. |
Craig Topper | 695aa80 | 2014-04-16 04:21:27 +0000 | [diff] [blame] | 508 | bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 509 | bool ParseGlobalValue(Type *Ty, Constant *&C); |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 510 | bool ParseGlobalTypeAndValue(Constant *&V); |
Peter Collingbourne | ca668e1 | 2016-11-10 22:34:55 +0000 | [diff] [blame] | 511 | bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts, |
| 512 | Optional<unsigned> *InRangeOp = nullptr); |
Rafael Espindola | f907a26 | 2015-01-06 22:55:16 +0000 | [diff] [blame] | 513 | bool parseOptionalComdat(StringRef GlobalName, Comdat *&C); |
Duncan P. N. Exon Smith | 1ef70ff | 2014-12-15 19:07:53 +0000 | [diff] [blame] | 514 | bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS); |
Duncan P. N. Exon Smith | ed356a9 | 2015-02-13 01:26:47 +0000 | [diff] [blame] | 515 | bool ParseValueAsMetadata(Metadata *&MD, const Twine &TypeMsg, |
| 516 | PerFunctionState *PFS); |
Duncan P. N. Exon Smith | dad20b2 | 2014-12-09 18:38:53 +0000 | [diff] [blame] | 517 | bool ParseMetadata(Metadata *&MD, PerFunctionState *PFS); |
Duncan P. N. Exon Smith | 9e8d3bc | 2015-01-12 21:23:11 +0000 | [diff] [blame] | 518 | bool ParseMDTuple(MDNode *&MD, bool IsDistinct = false); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 519 | bool ParseMDNode(MDNode *&N); |
| 520 | bool ParseMDNodeTail(MDNode *&N); |
| 521 | bool ParseMDNodeVector(SmallVectorImpl<Metadata *> &Elts); |
Duncan P. N. Exon Smith | eb71378 | 2015-04-24 21:21:57 +0000 | [diff] [blame] | 522 | bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD); |
Duncan P. N. Exon Smith | 233c2e7 | 2015-04-24 21:29:36 +0000 | [diff] [blame] | 523 | bool ParseInstructionMetadata(Instruction &Inst); |
Peter Collingbourne | 6aef9f9 | 2016-05-31 23:01:54 +0000 | [diff] [blame] | 524 | bool ParseGlobalObjectMetadataAttachment(GlobalObject &GO); |
Duncan P. N. Exon Smith | ae32114 | 2015-04-24 22:04:41 +0000 | [diff] [blame] | 525 | bool ParseOptionalFunctionMetadata(Function &F); |
Victor Hernandez | bf170d4 | 2010-01-05 22:22:14 +0000 | [diff] [blame] | 526 | |
Duncan P. N. Exon Smith | 89aee38 | 2015-02-04 22:05:21 +0000 | [diff] [blame] | 527 | template <class FieldTy> |
| 528 | bool ParseMDField(LocTy Loc, StringRef Name, FieldTy &Result); |
Duncan P. N. Exon Smith | cb96a31 | 2015-01-20 02:42:29 +0000 | [diff] [blame] | 529 | template <class FieldTy> bool ParseMDField(StringRef Name, FieldTy &Result); |
Duncan P. N. Exon Smith | 5d2d1f2 | 2015-01-19 23:32:36 +0000 | [diff] [blame] | 530 | template <class ParserTy> |
Duncan P. N. Exon Smith | 3a18dcb | 2015-01-19 23:39:32 +0000 | [diff] [blame] | 531 | bool ParseMDFieldsImplBody(ParserTy parseField); |
| 532 | template <class ParserTy> |
Duncan P. N. Exon Smith | 5d2d1f2 | 2015-01-19 23:32:36 +0000 | [diff] [blame] | 533 | bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc); |
Duncan P. N. Exon Smith | 3b0fe4e | 2015-01-13 21:10:44 +0000 | [diff] [blame] | 534 | bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false); |
Duncan P. N. Exon Smith | f4293bc | 2015-02-10 01:08:16 +0000 | [diff] [blame] | 535 | |
| 536 | #define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \ |
| 537 | bool Parse##CLASS(MDNode *&Result, bool IsDistinct); |
| 538 | #include "llvm/IR/Metadata.def" |
Duncan P. N. Exon Smith | 3b0fe4e | 2015-01-13 21:10:44 +0000 | [diff] [blame] | 539 | |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 540 | // Function Parsing. |
| 541 | struct ArgInfo { |
| 542 | LocTy Loc; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 543 | Type *Ty; |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 544 | AttributeSet Attrs; |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 545 | std::string Name; |
Reid Kleckner | 0609040 | 2017-04-12 00:38:00 +0000 | [diff] [blame] | 546 | ArgInfo(LocTy L, Type *ty, AttributeSet Attr, const std::string &N) |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 547 | : Loc(L), Ty(ty), Attrs(Attr), Name(N) {} |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 548 | }; |
Chris Lattner | 1afcace | 2011-07-09 17:41:24 +0000 | [diff] [blame] | 549 | bool ParseArgumentList(SmallVectorImpl<ArgInfo> &ArgList, bool &isVarArg); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 550 | bool ParseFunctionHeader(Function *&Fn, bool isDefine); |
| 551 | bool ParseFunctionBody(Function &Fn); |
| 552 | bool ParseBasicBlock(PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 553 | |
Reid Kleckner | 710c1a4 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 554 | enum TailCallType { TCT_None, TCT_Tail, TCT_MustTail }; |
| 555 | |
Chris Lattner | f1bc7ce | 2009-12-30 05:23:43 +0000 | [diff] [blame] | 556 | // Instruction Parsing. Each instruction parsing routine can return with a |
| 557 | // normal result, an error result, or return having eaten an extra comma. |
| 558 | enum InstResult { InstNormal = 0, InstError = 1, InstExtraComma = 2 }; |
| 559 | int ParseInstruction(Instruction *&Inst, BasicBlock *BB, |
| 560 | PerFunctionState &PFS); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 561 | bool ParseCmpPredicate(unsigned &P, unsigned Opc); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 562 | |
Chris Lattner | 437544f | 2011-06-17 06:49:41 +0000 | [diff] [blame] | 563 | bool ParseRet(Instruction *&Inst, BasicBlock *BB, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 564 | bool ParseBr(Instruction *&Inst, PerFunctionState &PFS); |
| 565 | bool ParseSwitch(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | ab21db7 | 2009-10-28 00:19:10 +0000 | [diff] [blame] | 566 | bool ParseIndirectBr(Instruction *&Inst, PerFunctionState &PFS); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 567 | bool ParseInvoke(Instruction *&Inst, PerFunctionState &PFS); |
Bill Wendling | dccc03b | 2011-07-31 06:30:59 +0000 | [diff] [blame] | 568 | bool ParseResume(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 569 | bool ParseCleanupRet(Instruction *&Inst, PerFunctionState &PFS); |
| 570 | bool ParseCatchRet(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 8cec2f2 | 2015-12-12 05:38:55 +0000 | [diff] [blame] | 571 | bool ParseCatchSwitch(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 572 | bool ParseCatchPad(Instruction *&Inst, PerFunctionState &PFS); |
David Majnemer | 4a45f08 | 2015-07-31 17:58:14 +0000 | [diff] [blame] | 573 | bool ParseCleanupPad(Instruction *&Inst, PerFunctionState &PFS); |
Misha Brukman | 9ea4034 | 2009-01-02 22:46:48 +0000 | [diff] [blame] | 574 | |
Cameron McInally | ca8cb68 | 2018-11-13 18:15:47 +0000 | [diff] [blame] | 575 | bool ParseUnaryOp(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc, |
| 576 | unsigned OperandType); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 577 | bool ParseArithmetic(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc, |
Chris Lattner | e914b59 | 2009-01-05 08:24:46 +0000 | [diff] [blame] | 578 | unsigned OperandType); |
Fangrui Song | f831f82 | 2018-07-12 02:03:53 +0000 | [diff] [blame] | 579 | bool ParseLogical(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); |
| 580 | bool ParseCompare(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); |
| 581 | bool ParseCast(Instruction *&Inst, PerFunctionState &PFS, unsigned Opc); |
| 582 | bool ParseSelect(Instruction *&Inst, PerFunctionState &PFS); |
| 583 | bool ParseVA_Arg(Instruction *&Inst, PerFunctionState &PFS); |
| 584 | bool ParseExtractElement(Instruction *&Inst, PerFunctionState &PFS); |
| 585 | bool ParseInsertElement(Instruction *&Inst, PerFunctionState &PFS); |
| 586 | bool ParseShuffleVector(Instruction *&Inst, PerFunctionState &PFS); |
| 587 | int ParsePHI(Instruction *&Inst, PerFunctionState &PFS); |
| 588 | bool ParseLandingPad(Instruction *&Inst, PerFunctionState &PFS); |
| 589 | bool ParseCall(Instruction *&Inst, PerFunctionState &PFS, |
| 590 | CallInst::TailCallKind TCK); |
| 591 | int ParseAlloc(Instruction *&Inst, PerFunctionState &PFS); |
| 592 | int ParseLoad(Instruction *&Inst, PerFunctionState &PFS); |
| 593 | int ParseStore(Instruction *&Inst, PerFunctionState &PFS); |
| 594 | int ParseCmpXchg(Instruction *&Inst, PerFunctionState &PFS); |
| 595 | int ParseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS); |
| 596 | int ParseFence(Instruction *&Inst, PerFunctionState &PFS); |
| 597 | int ParseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS); |
| 598 | int ParseExtractValue(Instruction *&Inst, PerFunctionState &PFS); |
| 599 | int ParseInsertValue(Instruction *&Inst, PerFunctionState &PFS); |
Duncan P. N. Exon Smith | 7838818 | 2014-08-19 21:30:15 +0000 | [diff] [blame] | 600 | |
| 601 | // Use-list order directives. |
| 602 | bool ParseUseListOrder(PerFunctionState *PFS = nullptr); |
| 603 | bool ParseUseListOrderBB(); |
| 604 | bool ParseUseListOrderIndexes(SmallVectorImpl<unsigned> &Indexes); |
| 605 | bool sortUseListOrder(Value *V, ArrayRef<unsigned> Indexes, SMLoc Loc); |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 606 | }; |
Alexander Kornienko | cd52a7a | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 607 | } // End llvm namespace |
Chris Lattner | df98617 | 2009-01-02 07:01:27 +0000 | [diff] [blame] | 608 | |
| 609 | #endif |