63 bool NoLLVMIR =
false;
66 bool NoMIRDocuments =
false;
121 std::vector<CalleeSavedInfo> &CSIInfo,
179 In(SM.getMemoryBuffer(
180 SM.AddNewSourceBuffer(std::move(Contents),
SMLoc()))->getBuffer(),
226 NoMIRDocuments =
true;
227 return llvm::make_unique<Module>(Filename, Context);
230 std::unique_ptr<Module> M;
233 if (
const auto *BSN =
244 NoMIRDocuments =
true;
247 M = llvm::make_unique<Module>(Filename, Context);
292 return error(
Twine(
"function '") + FunctionName +
293 "' isn't defined in the provided LLVM IR");
297 return error(
Twine(
"redefinition of machine function '") + FunctionName +
322 bool HasInlineAsm =
false;
327 if (
MI.isInlineAsm())
333 MF.setHasInlineAsm(HasInlineAsm);
349 initNames2RegClasses(MF);
350 initNames2RegBanks(MF);
415 computeFunctionProperties(MF);
434 return error(VReg.ID.SourceRange.Start,
435 Twine(
"redefinition of virtual register '%") +
436 Twine(VReg.ID.Value) +
"'");
442 const auto *RC = getRegClass(MF, VReg.Class.Value);
447 const RegisterBank *RegBank = getRegBank(MF, VReg.Class.Value);
450 VReg.Class.SourceRange.Start,
451 Twine(
"use of undefined register class or register bank '") +
452 VReg.Class.Value +
"'");
458 if (!VReg.PreferredRegister.Value.empty()) {
460 return error(VReg.Class.SourceRange.Start,
461 Twine(
"preferred register can only be set for normal vregs"));
464 VReg.PreferredRegister.Value, Error))
465 return error(Error, VReg.PreferredRegister.SourceRange);
470 for (
const auto &LiveIn : YamlMF.
LiveIns) {
473 return error(Error, LiveIn.Register.SourceRange);
475 if (!LiveIn.VirtualRegister.Value.empty()) {
479 return error(Error, LiveIn.VirtualRegister.SourceRange);
492 return error(Error, RegSource.SourceRange);
512 error(
Twine(
"Cannot determine class/bank of virtual register ") +
569 if (parseMBBReference(PFS, MBB, YamlMFI.
SavePoint))
580 std::vector<CalleeSavedInfo> CSIInfo;
586 Object.IsImmutable, Object.IsAliased);
593 return error(Object.ID.SourceRange.Start,
594 Twine(
"redefinition of fixed stack object '%fixed-stack.") +
595 Twine(Object.ID.Value) +
"'");
606 if (!Name.
Value.empty()) {
607 Alloca = dyn_cast_or_null<AllocaInst>(
611 "alloca instruction named '" + Name.
Value +
612 "' isn't defined in the function '" + F.
getName() +
619 Object.Size, Object.Alignment,
624 return error(Object.ID.SourceRange.Start,
625 Twine(
"redefinition of stack object '%stack.") +
626 Twine(Object.ID.Value) +
"'");
630 if (Object.LocalOffset)
636 if (!CSIInfo.empty())
652 std::vector<CalleeSavedInfo> &CSIInfo,
654 if (RegisterSource.
Value.empty())
665 template <
typename T>
674 "expected a reference to a '" + TypeString +
683 assert(FrameIdx >= 0 &&
"Expected a stack object frame index");
684 MDNode *Var =
nullptr, *Expr =
nullptr, *Loc =
nullptr;
685 if (parseMDNode(PFS, Var, Object.
DebugVar) ||
686 parseMDNode(PFS, Expr, Object.
DebugExpr) ||
687 parseMDNode(PFS, Loc, Object.
DebugLoc))
689 if (!Var && !Expr && !Loc)
704 if (Source.
Value.empty())
718 for (
const auto &YamlConstant : YamlMF.
Constants) {
722 return error(Error, YamlConstant.Value.SourceRange);
724 YamlConstant.Alignment
725 ? YamlConstant.Alignment
726 : M.getDataLayout().getPrefTypeAlignment(Value->
getType());
728 if (!ConstantPoolSlots.
insert(std::make_pair(YamlConstant.ID.Value, Index))
730 return error(YamlConstant.ID.SourceRange.Start,
731 Twine(
"redefinition of constant pool item '%const.") +
732 Twine(YamlConstant.ID.Value) +
"'");
740 for (
const auto &Entry : YamlJTI.
Entries) {
741 std::vector<MachineBasicBlock *> Blocks;
742 for (
const auto &MBBSource : Entry.Blocks) {
744 if (parseMBBReference(PFS, MBB, MBBSource.Value))
751 return error(Entry.ID.SourceRange.Start,
752 Twine(
"redefinition of jump table entry '%jump-table.") +
753 Twine(Entry.ID.Value) +
"'");
772 *Loc.getPointer() ==
'\'';
775 Loc = Loc.getFromPointer(Loc.getPointer() + Error.
getColumnNo() +
790 unsigned Line = LineAndColumn.first + Error.
getLineNo() - 1;
799 if (
L.line_number() == Line) {
815 if (!Names2RegClasses.
empty())
826 if (!Names2RegBanks.
empty())
836 std::make_pair(
StringRef(RegBank.getName()).lower(), &RegBank));
842 auto RegClassInfo = Names2RegClasses.
find(Name);
843 if (RegClassInfo == Names2RegClasses.
end())
845 return RegClassInfo->getValue();
850 auto RegBankInfo = Names2RegBanks.
find(Name);
851 if (RegBankInfo == Names2RegBanks.
end())
853 return RegBankInfo->getValue();
857 : Impl(std::move(Impl)) {}
862 return Impl->parseIRModule();
866 return Impl->parseMachineFunctions(M, MMI);
873 if (std::error_code EC = FileOrErr.getError()) {
875 "Could not open input file: " + EC.message());
881 std::unique_ptr<MIRParser>
884 auto Filename = Contents->getBufferIdentifier();
890 "Can't read MIR with a Context that discards named Values")));
893 return llvm::make_unique<MIRParser>(
894 llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename,
Context));
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
void push_back(const T &Elt)
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)
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.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
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. ...
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.
union llvm::VRegInfo::@284 D
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
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
Diagnostic information for machine IR parser.
bool parseMachineFunction(Module &M, MachineModuleInfo &MMI)
Parse the machine function in the current YAML document.
iterator find(StringRef Key)
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
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...
static Function * createDummyFunction(StringRef Name, Module &M)
Create an empty function with the given name.
std::unique_ptr< Module > parseIRModule()
Try to parse the optional LLVM module and the machine functions in the MIR file.
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...
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.
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 parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
Parses MachineFunctions in the MIR file and add them to the given MachineModuleInfo MMI...
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)
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)
bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI)
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.
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
~0u means: not computed yet.
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
void setCalleeSavedRegs(ArrayRef< MCPhysReg > CSRs)
Sets the updated Callee Saved Registers list.
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
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
MachineFunction & getOrCreateMachineFunction(const Function &F)
Returns the MachineFunction constructed for the IR function F.
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.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
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...
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.
MachineFunction * getMachineFunction(const Function &F) const
Returns the MachineFunction associated to IR function F if there is one, otherwise nullptr...
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)
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, int64_t FileSize=-1, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
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.
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.
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.
std::unique_ptr< Module > parseIRModule()
Parses the optional LLVM IR module in the MIR file.
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).
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.
bool initializeMachineFunction(const yaml::MachineFunction &YamlMF, MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
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.
This class contains meta information specific to a module.
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...