88 std::unique_ptr<Module>
parse();
115 std::vector<CalleeSavedInfo> &CSIInfo,
171 : SM(), Filename(Filename), Context(Context) {
218 if (!
In.setCurrentDocument()) {
222 return llvm::make_unique<Module>(Filename, Context);
225 std::unique_ptr<Module> M;
226 bool NoLLVMIR =
false;
229 if (
const auto *BSN =
230 dyn_cast_or_null<yaml::BlockScalarNode>(
In.getCurrentNode())) {
239 if (!
In.setCurrentDocument())
243 M = llvm::make_unique<Module>(Filename, Context);
252 }
while (
In.setCurrentDocument());
259 auto MF = llvm::make_unique<yaml::MachineFunction>();
264 auto FunctionName = MF->Name;
265 if (Functions.find(FunctionName) != Functions.end())
266 return error(
Twine(
"redefinition of machine function '") + FunctionName +
268 Functions.insert(std::make_pair(FunctionName, std::move(MF)));
270 createDummyFunction(FunctionName, M);
272 return error(
Twine(
"function '") + FunctionName +
273 "' isn't defined in the provided LLVM IR");
299 bool HasInlineAsm =
false;
304 if (
MI.isInlineAsm())
310 MF.setHasInlineAsm(HasInlineAsm);
323 auto It = Functions.find(MF.
getName());
324 if (It == Functions.end())
325 return error(
Twine(
"no machine function information for function '") +
326 MF.
getName() +
"' in the MIR file");
367 "' requires at least one machine basic block in its body");
395 computeFunctionProperties(MF);
414 return error(VReg.ID.SourceRange.Start,
415 Twine(
"redefinition of virtual register '%") +
416 Twine(VReg.ID.Value) +
"'");
422 const auto *RC = getRegClass(MF, VReg.Class.Value);
427 const RegisterBank *RegBank = getRegBank(MF, VReg.Class.Value);
430 VReg.Class.SourceRange.Start,
431 Twine(
"use of undefined register class or register bank '") +
432 VReg.Class.Value +
"'");
438 if (!VReg.PreferredRegister.Value.empty()) {
440 return error(VReg.Class.SourceRange.Start,
441 Twine(
"preferred register can only be set for normal vregs"));
444 VReg.PreferredRegister.Value, Error))
445 return error(Error, VReg.PreferredRegister.SourceRange);
450 for (
const auto &LiveIn : YamlMF.
LiveIns) {
453 return error(Error, LiveIn.Register.SourceRange);
455 if (!LiveIn.VirtualRegister.Value.empty()) {
459 return error(Error, LiveIn.VirtualRegister.SourceRange);
472 return error(Error, RegSource.SourceRange);
473 CalleeSavedRegisterMask[
Reg] =
true;
490 error(
Twine(
"Cannot determine class/bank of virtual register ") +
548 if (parseMBBReference(PFS, MBB, YamlMFI.
SavePoint))
559 std::vector<CalleeSavedInfo> CSIInfo;
565 Object.IsImmutable, Object.IsAliased);
572 return error(Object.ID.SourceRange.Start,
573 Twine(
"redefinition of fixed stack object '%fixed-stack.") +
574 Twine(Object.ID.Value) +
"'");
585 if (!Name.
Value.empty()) {
586 Alloca = dyn_cast_or_null<AllocaInst>(
590 "alloca instruction named '" + Name.
Value +
591 "' isn't defined in the function '" + F.
getName() +
598 Object.Size, Object.Alignment,
603 return error(Object.ID.SourceRange.Start,
604 Twine(
"redefinition of stack object '%stack.") +
605 Twine(Object.ID.Value) +
"'");
609 if (Object.LocalOffset)
615 if (!CSIInfo.empty())
631 std::vector<CalleeSavedInfo> &CSIInfo,
633 if (RegisterSource.
Value.empty())
644 template <
typename T>
653 "expected a reference to a '" + TypeString +
662 assert(FrameIdx >= 0 &&
"Expected a stack object frame index");
663 MDNode *Var =
nullptr, *Expr =
nullptr, *Loc =
nullptr;
664 if (parseMDNode(PFS, Var, Object.
DebugVar) ||
665 parseMDNode(PFS, Expr, Object.
DebugExpr) ||
666 parseMDNode(PFS, Loc, Object.
DebugLoc))
668 if (!Var && !Expr && !Loc)
683 if (Source.
Value.empty())
697 for (
const auto &YamlConstant : YamlMF.
Constants) {
701 return error(Error, YamlConstant.Value.SourceRange);
703 YamlConstant.Alignment
704 ? YamlConstant.Alignment
707 if (!ConstantPoolSlots.
insert(std::make_pair(YamlConstant.ID.Value, Index))
709 return error(YamlConstant.ID.SourceRange.Start,
710 Twine(
"redefinition of constant pool item '%const.") +
711 Twine(YamlConstant.ID.Value) +
"'");
719 for (
const auto &Entry : YamlJTI.
Entries) {
720 std::vector<MachineBasicBlock *> Blocks;
721 for (
const auto &MBBSource : Entry.Blocks) {
723 if (parseMBBReference(PFS, MBB, MBBSource.Value))
730 return error(Entry.ID.SourceRange.Start,
731 Twine(
"redefinition of jump table entry '%jump-table.") +
732 Twine(Entry.ID.Value) +
"'");
751 *Loc.getPointer() ==
'\'';
754 Loc = Loc.getFromPointer(Loc.getPointer() + Error.
getColumnNo() +
769 unsigned Line = LineAndColumn.first + Error.
getLineNo() - 1;
778 if (
L.line_number() == Line) {
794 if (!Names2RegClasses.empty())
799 Names2RegClasses.insert(
805 if (!Names2RegBanks.empty())
814 Names2RegBanks.insert(
815 std::make_pair(
StringRef(RegBank.getName()).lower(), &RegBank));
821 initNames2RegClasses(MF);
822 auto RegClassInfo = Names2RegClasses.find(Name);
823 if (RegClassInfo == Names2RegClasses.end())
825 return RegClassInfo->getValue();
830 initNames2RegBanks(MF);
831 auto RegBankInfo = Names2RegBanks.find(Name);
832 if (RegBankInfo == Names2RegBanks.end())
834 return RegBankInfo->getValue();
838 : Impl(std::move(Impl)) {}
845 return Impl->initializeMachineFunction(MF);
852 if (std::error_code EC = FileOrErr.getError()) {
854 "Could not open input file: " + EC.message());
860 std::unique_ptr<MIRParser>
863 auto Filename = Contents->getBufferIdentifier();
869 "Can't read MIR with a Context that discards named Values")));
872 return llvm::make_unique<MIRParser>(
873 llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename,
Context));
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
The MachineConstantPool class keeps track of constants referenced by a function which must be spilled...
void setSavePoint(MachineBasicBlock *NewSave)
bool parseMachineBasicBlockDefinitions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine basic block definitions, and skip the machine instructions.
bool verify(Pass *p=nullptr, const char *Banner=nullptr, bool AbortOnError=true) const
Run the current MachineFunction through the machine code verifier, useful for debugger use...
void setRestorePoint(MachineBasicBlock *NewRestore)
size_type size() const
size - Returns the number of bits in this bitvector.
void setVariableDbgInfo(const DILocalVariable *Var, const DIExpression *Expr, unsigned Slot, const DILocation *Loc)
Collect information used to emit debugging information of a variable.
DenseMap< unsigned, unsigned > JumpTableSlots
void mapLocalFrameObject(int ObjectIndex, int64_t Offset)
Map a frame index into the local object block.
const char * getPointer() const
void setCalleeSavedInfoValid(bool v)
DenseMap< unsigned, unsigned > ConstantPoolSlots
MachineFunctionProperties & reset(Property P)
Constant * parseConstantValue(StringRef Asm, SMDiagnostic &Err, const Module &M, const SlotMapping *Slots=nullptr)
Parse a type and a constant value in the given string.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
union llvm::VRegInfo::@253 D
std::pair< unsigned, unsigned > getLineAndColumn(SMLoc Loc, unsigned BufferID=0) const
Find the line and column number for the specified location in the specified file. ...
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
std::unique_ptr< MIRParser > createMIRParser(std::unique_ptr< MemoryBuffer > Contents, LLVMContext &Context)
This function is another interface to the MIR serialization format parser.
bool shouldDiscardValueNames() const
Return true if the Context runtime configuration is set to discard all value names.
Optional< std::vector< FlowStringValue > > CalleeSavedRegisters
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
const BitVector & getUsedPhysRegsMask() const
Diagnostic information for machine IR parser.
DenseMap< unsigned, int > StackObjectSlots
A forward iterator which reads text lines from a buffer.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
DenseMap< unsigned, VRegInfo * > VRegInfos
void setRegBank(unsigned Reg, const RegisterBank &RegBank)
Set the register bank to RegBank for Reg.
bool parseMBBReference(PerFunctionMIParsingState &PFS, MachineBasicBlock *&MBB, StringRef Src, SMDiagnostic &Error)
const TargetRegisterClass * RC
bool initializeMachineFunction(MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
StringRef getName() const
Return a constant reference to the value's name.
MachineJumpTableInfo * getOrCreateJumpTableInfo(unsigned JTEntryKind)
getOrCreateJumpTableInfo - Get the JumpTableInfo for this function, if it does already exist...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
unsigned getMainFileID() const
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
Holds all the information related to register banks.
std::string str() const
Return the twine contents as a std::string.
void setHasPatchPoint(bool s=true)
unsigned getNumRegClasses() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
std::unique_ptr< Module > parse()
Try to parse the optional LLVM module and the machine functions in the MIR file.
virtual const RegisterBankInfo * getRegBankInfo() const
If the information for the register banks is available, return it.
const TargetRegisterClass * getRegClass(unsigned i) const
Returns the register class associated with the enumeration value.
void setUsedPhysRegMask(BitVector &Mask)
StringRef getLineContents() const
const MachineFunctionProperties & getProperties() const
Get the function properties.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
void freezeReservedRegs(const MachineFunction &)
freezeReservedRegs - Called by the register allocator to freeze the set of reserved registers before ...
Reg
All possible values of the reg field in the ModR/M byte.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
bool parseStackObjectsDebugInfo(PerFunctionMIParsingState &PFS, const yaml::MachineStackObject &Object, int FrameIdx)
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool Immutable=false)
Create a spill slot at a fixed location on the stack.
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context)
DenseMap< unsigned, int > FixedStackObjectSlots
std::vector< VirtualRegisterDefinition > VirtualRegisters
unsigned createJumpTableIndex(const std::vector< MachineBasicBlock * > &DestBBs)
createJumpTableIndex - Create a new jump table.
bool setupRegisterInfo(const PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
void setHasMustTailInVarArgFunc(bool B)
bool HasMustTailInVarArgFunc
StringRef getMessage() const
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
bool parseCalleeSavedRegister(PerFunctionMIParsingState &PFS, std::vector< CalleeSavedInfo > &CSIInfo, const yaml::StringValue &RegisterSource, int FrameIdx)
static void handleYAMLDiag(const SMDiagnostic &Diag, void *Context)
std::unique_ptr< Module > parseAssembly(MemoryBufferRef F, SMDiagnostic &Err, LLVMContext &Context, SlotMapping *Slots=nullptr)
parseAssemblyFile and parseAssemblyString are wrappers around this function.
bool parseVirtualRegisterReference(PerFunctionMIParsingState &PFS, VRegInfo *&Info, StringRef Src, SMDiagnostic &Error)
void setStackProtectorIndex(int I)
void setHasOpaqueSPAdjustment(bool B)
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
VRegInfo & getVRegInfo(unsigned VReg)
bool parseStackObjectReference(PerFunctionMIParsingState &PFS, int &FI, StringRef Src, SMDiagnostic &Error)
unsigned const MachineRegisterInfo * MRI
Serializable representation of stack object from the MachineFrameInfo class.
bool parseRegisterInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
static bool isSSA(const MachineFunction &MF)
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
This function has undefined behavior.
This is an important base class in LLVM.
void setStackSize(uint64_t Size)
Set the size of the stack.
MachineJumpTable JumpTableInfo
Constant pool.
bool initializeJumpTableInfo(PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI)
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
bool parseNamedRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
static Type * getVoidTy(LLVMContext &C)
void setHasVAStart(bool B)
static bool typecheckMDNode(T *&Result, MDNode *Node, const yaml::StringValue &Source, StringRef TypeString, MIRParserImpl &Parser)
Verify that given node is of a certain type. Return true on error.
unsigned MaxCallFrameSize
StringValue StackProtector
std::vector< MachineStackObject > StackObjects
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
ArrayRef< SMFixIt > getFixIts() const
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool Immutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
void reportDiagnostic(const SMDiagnostic &Diag)
MachineConstantPool * getConstantPool()
getConstantPool - Return the constant pool object for the current function.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
Serializable representation of MachineFrameInfo.
ArrayRef< std::pair< unsigned, unsigned > > getRanges() const
std::unique_ptr< Module > parseLLVMModule()
Parse the optional LLVM IR module that's embedded in the MIR file.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This class implements the parsing of LLVM IR that's embedded inside a MIR file.
bool parseMachineInstructions(PerFunctionMIParsingState &PFS, StringRef Src, SMDiagnostic &Error)
Parse the machine instructions.
SourceMgr::DiagKind getKind() const
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
enum llvm::VRegInfo::uint8_t Kind
MachineOperand class - Representation of each machine instruction operand.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
MachineFrameInfo FrameInfo
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
void setAdjustsStack(bool V)
This class implements the register bank concept.
ValueSymbolTable * getValueSymbolTable()
getSymbolTable() - Return the symbol table if any, otherwise nullptr.
bool HasOpaqueSPAdjustment
The CalleeSavedInfo class tracks the information need to locate where a callee saved register is in t...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool initializeMachineFunction(MachineFunction &MF) override
Initialize the machine function to the state that's described in the MIR file.
A wrapper around std::string which contains a source range that's being set during parsing...
This struct contains the mappings from the slot numbers to unnamed metadata nodes, global values and types.
bool parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error)
bool error(const Twine &Message)
Report an error with the given message at unknown location.
static SMLoc getFromPointer(const char *Ptr)
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
bool Explicit
VReg was explicitly specified in the .mir file.
Representation of each machine instruction.
void setCalleeSavedInfo(const std::vector< CalleeSavedInfo > &CSI)
Used by prolog/epilog inserter to set the function's callee saved information.
std::vector< MachineFunctionLiveIn > LiveIns
bool hasOneDef(unsigned RegNo) const
Return true if there is exactly one operand defining the specified register.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
bool initializeFrameInfo(PerFunctionMIParsingState &PFS, const yaml::MachineFunction &YamlMF)
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true, bool IsVolatileSize=false)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful, otherwise returning null.
std::vector< Entry > Entries
void push_back(MachineInstr *MI)
bool IsReturnAddressTaken
void setMaxCallFrameSize(unsigned S)
unsigned getNumRegBanks() const
Get the total number of register banks.
void addPhysRegsUsedFromRegMask(const uint32_t *RegMask)
addPhysRegsUsedFromRegMask - Mark any registers not in RegMask as used.
std::vector< MachineConstantPoolValue > Constants
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
MIRParser(std::unique_ptr< MIRParserImpl > Impl)
void setExposesReturnsTwice(bool B)
setCallsSetJmp - Set a flag that indicates if there's a call to a "returns twice" function...
std::enable_if< has_ScalarEnumerationTraits< T >::value, void >::type yamlize(IO &io, T &Val, bool, EmptyContext &Ctx)
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
void setSimpleHint(unsigned VReg, unsigned PrefReg)
Specify the preferred register allocation hint for the specified virtual register.
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS, const AllocaInst *Alloca=nullptr)
Create a new statically sized stack object, returning a nonnegative identifier to represent it...
bool initializeConstantPool(PerFunctionMIParsingState &PFS, MachineConstantPool &ConstantPool, const yaml::MachineFunction &YamlMF)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< FixedMachineStackObject > FixedStackObjects
void setReturnAddressIsTaken(bool s)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.
void setAlignment(unsigned A)
setAlignment - Set the alignment (log2, not bytes) of the function.
bool def_empty(unsigned RegNo) const
def_empty - Return true if there are no instructions defining the specified register (it may be live-...
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool parseMachineFunction(yaml::Input &In, Module &M, bool NoLLVMIR)
Parse the machine function in the current YAML document.
void setObjectOffset(int ObjectIdx, int64_t SPOffset)
Set the stack frame offset of the specified object.
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
StringRef - Represent a constant reference to a string, i.e.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
Return an SMDiagnostic at the specified location with the specified string.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
const RegisterBank * RegBank
MachineJumpTableInfo::JTEntryKind Kind
Represents a location in source code.
bool parseRegisterReference(PerFunctionMIParsingState &PFS, unsigned &Reg, StringRef Src, SMDiagnostic &Error)
std::unique_ptr< MIRParser > createMIRParserFromFile(StringRef Filename, SMDiagnostic &Error, LLVMContext &Context)
This function is the main interface to the MIR serialization format parser.
int CreateVariableSizedObject(unsigned Alignment, const AllocaInst *Alloca)
Notify the MachineFrameInfo object that a variable sized object has been created. ...
void setObjectAlignment(int ObjectIdx, unsigned Align)
setObjectAlignment - Change the alignment of the specified stack object.
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
getConstantPoolIndex - Create a new entry in the constant pool or return an existing one...
Properties which a MachineFunction may have at a given point in time.
LLVMContext & getContext() const
Get the global data context.
an instruction to allocate memory on the stack
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...