class Comdat;
class MDString;
class MDNode;
+ struct SlotMapping;
class StructType;
/// ValID - Represents a reference of a definition of some sort with no type.
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_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;
- Constant **ConstantStructElts;
-
- ValID() : Kind(t_LocalID), APFloatVal(0.0) {}
- ~ValID() {
- if (Kind == t_ConstantStruct || Kind == t_PackedConstantStruct)
- delete [] ConstantStructElts;
+ std::unique_ptr<Constant *[]> 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 {
}
};
- /// Structure to represent an optional metadata field.
- template <class FieldTy> struct MDFieldImpl {
- typedef MDFieldImpl ImplTy;
- FieldTy Val;
- bool Seen;
-
- void assign(FieldTy Val) {
- Seen = true;
- this->Val = std::move(Val);
- }
-
- explicit MDFieldImpl(FieldTy Default)
- : Val(std::move(Default)), Seen(false) {}
- };
- struct MDUnsignedField : public MDFieldImpl<uint64_t> {
- uint64_t Max;
-
- MDUnsignedField(uint64_t Default = 0, uint64_t Max = UINT64_MAX)
- : ImplTy(Default), Max(Max) {}
- };
- struct DwarfTagField : public MDUnsignedField {
- DwarfTagField() : MDUnsignedField(0, ~0u >> 16) {}
- };
- struct MDField : public MDFieldImpl<Metadata *> {
- MDField() : ImplTy(nullptr) {}
- };
- struct MDStringField : public MDFieldImpl<std::string> {
- MDStringField() : ImplTy(std::string()) {}
- };
- struct MDFieldList : public MDFieldImpl<SmallVector<Metadata *, 4>> {
- MDFieldList() : ImplTy(SmallVector<Metadata *, 4>()) {}
- };
-
class LLParser {
public:
typedef LLLexer::LocTy LocTy;
LLVMContext &Context;
LLLexer Lex;
Module *M;
+ SlotMapping *Slots;
// Instruction metadata resolution. Each instruction can have a list of
// MDRef info associated with them.
unsigned MDKind, MDSlot;
};
+ /// 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<Instruction*, 64> 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<std::pair<Type*, LocTy> > NamedTypes;
- std::vector<std::pair<Type*, LocTy> > NumberedTypes;
+ std::map<unsigned, std::pair<Type*, LocTy> > NumberedTypes;
- std::vector<TrackingMDNodeRef> NumberedMetadata;
+ std::map<unsigned, TrackingMDNodeRef> NumberedMetadata;
std::map<unsigned, std::pair<TempMDTuple, LocTy>> ForwardRefMDNodes;
// Global Value reference information.
std::map<unsigned, AttrBuilder> NumberedAttrBuilders;
public:
- LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *m)
- : Context(m->getContext()), Lex(F, SM, Err, m->getContext()), M(m),
- BlockAddressPFS(nullptr) {}
+ 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:
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.
return ParseUInt64(Val);
}
+ bool ParseStringAttribute(AttrBuilder &B);
+
bool ParseTLSModel(GlobalVariable::ThreadLocalMode &TLM);
bool ParseOptionalThreadLocal(GlobalVariable::ThreadLocalMode &TLM);
bool parseOptionalUnnamedAddr(bool &UnnamedAddr) {
bool ParseOptionalDLLStorageClass(unsigned &DLLStorageClass);
bool ParseOptionalCallingConv(unsigned &CC);
bool ParseOptionalAlignment(unsigned &Alignment);
- bool ParseOptionalDereferenceableBytes(uint64_t &Bytes);
+ bool ParseOptionalDerefAttrBytes(lltok::Kind AttrKind, uint64_t &Bytes);
bool ParseScopeAndOrdering(bool isAtomic, SynchronizationScope &Scope,
AtomicOrdering &Ordering);
bool ParseOrdering(AtomicOrdering &Ordering);
/// 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.
};
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) {
bool IsMustTailCall = false,
bool InVarArgsFunc = false);
+ bool
+ ParseOptionalOperandBundles(SmallVectorImpl<OperandBundleDef> &BundleList,
+ PerFunctionState &PFS);
+
+ bool ParseExceptionArgs(SmallVectorImpl<Value *> &Args,
+ PerFunctionState &PFS);
+
// Constant Parsing.
bool ParseValID(ValID &ID, PerFunctionState *PFS = nullptr);
bool ParseGlobalValue(Type *Ty, Constant *&V);
bool ParseGlobalValueVector(SmallVectorImpl<Constant *> &Elts);
bool parseOptionalComdat(StringRef GlobalName, Comdat *&C);
bool ParseMetadataAsValue(Value *&V, PerFunctionState &PFS);
- bool ParseValueAsMetadata(Metadata *&MD, 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<Metadata *> &MDs);
- bool ParseInstructionMetadata(Instruction *Inst, PerFunctionState *PFS);
+ bool ParseMetadataAttachment(unsigned &Kind, MDNode *&MD);
+ bool ParseInstructionMetadata(Instruction &Inst);
+ bool ParseOptionalFunctionMetadata(Function &F);
- bool ParseMDField(LocTy Loc, StringRef Name, MDUnsignedField &Result);
- bool ParseMDField(LocTy Loc, StringRef Name, DwarfTagField &Result);
- bool ParseMDField(LocTy Loc, StringRef Name, MDField &Result);
- bool ParseMDField(LocTy Loc, StringRef Name, MDStringField &Result);
- bool ParseMDField(LocTy Loc, StringRef Name, MDFieldList &Result);
+ template <class FieldTy>
+ bool ParseMDField(LocTy Loc, StringRef Name, FieldTy &Result);
template <class FieldTy> bool ParseMDField(StringRef Name, FieldTy &Result);
template <class ParserTy>
bool ParseMDFieldsImplBody(ParserTy parseField);
template <class ParserTy>
bool ParseMDFieldsImpl(ParserTy parseField, LocTy &ClosingLoc);
bool ParseSpecializedMDNode(MDNode *&N, bool IsDistinct = false);
- bool ParseMDLocation(MDNode *&Result, bool IsDistinct);
- bool ParseGenericDebugNode(MDNode *&Result, bool IsDistinct);
+
+#define HANDLE_SPECIALIZED_MDNODE_LEAF(CLASS) \
+ bool Parse##CLASS(MDNode *&Result, bool IsDistinct);
+#include "llvm/IR/Metadata.def"
// Function Parsing.
struct ArgInfo {
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);