81 std::unique_ptr<Module>
parse();
139 : SM(), Filename(Filename), Context(Context) {
178 reinterpret_cast<MIRParserImpl *
>(Context)->reportDiagnostic(Diag);
186 if (!
In.setCurrentDocument()) {
190 return llvm::make_unique<Module>(Filename, Context);
193 std::unique_ptr<Module> M;
194 bool NoLLVMIR =
false;
197 if (
const auto *BSN =
198 dyn_cast_or_null<yaml::BlockScalarNode>(
In.getCurrentNode())) {
207 if (!
In.setCurrentDocument())
211 M = llvm::make_unique<Module>(Filename, Context);
220 }
while (
In.setCurrentDocument());
227 auto MF = llvm::make_unique<yaml::MachineFunction>();
231 auto FunctionName = MF->Name;
232 if (Functions.find(FunctionName) != Functions.end())
233 return error(
Twine(
"redefinition of machine function '") + FunctionName +
235 Functions.insert(std::make_pair(FunctionName, std::move(MF)));
237 createDummyFunction(FunctionName, M);
239 return error(
Twine(
"function '") + FunctionName +
240 "' isn't defined in the provided LLVM IR");
253 auto It = Functions.find(MF.
getName());
254 if (It == Functions.end())
255 return error(
Twine(
"no machine function information for function '") +
256 MF.
getName() +
"' in the MIR file");
274 if (!Name.
Value.empty()) {
275 BB = dyn_cast_or_null<BasicBlock>(
280 "' is not defined in the function '" + MF.
getName() +
286 PFS.
MBBSlots.insert(std::make_pair(YamlMBB.ID, MBB)).second;
288 return error(
Twine(
"redefinition of machine basic block with id #") +
294 "' requires at least one machine basic block in its body");
316 for (
const auto &MBBSource : YamlMBB.
Successors) {
320 return error(Error, MBBSource.SourceRange);
325 for (
const auto &LiveInSource : YamlMBB.
LiveIns) {
329 return error(Error, LiveInSource.SourceRange);
336 return error(Error, MISource.SourceRange);
346 assert(RegInfo.
isSSA());
356 const auto *RC = getRegClass(MF, VReg.Class.Value);
358 return error(VReg.Class.SourceRange.Start,
359 Twine(
"use of undefined register class '") +
360 VReg.Class.Value +
"'");
364 VirtualRegisterSlots.
insert(std::make_pair(VReg.ID, Reg));
392 Object.IsImmutable, Object.IsAliased);
408 Object.Size, Object.Alignment,
419 assert(SourceRange.
isValid() &&
"Invalid source range");
422 *Loc.getPointer() ==
'\'';
425 Loc = Loc.getFromPointer(Loc.getPointer() + Error.
getColumnNo() +
440 unsigned Line = LineAndColumn.first + Error.
getLineNo() - 1;
449 if (L.line_number() == Line) {
465 if (!Names2RegClasses.empty())
470 Names2RegClasses.insert(
477 initNames2RegClasses(MF);
478 auto RegClassInfo = Names2RegClasses.find(Name);
479 if (RegClassInfo == Names2RegClasses.end())
481 return RegClassInfo->getValue();
485 : Impl(std::move(Impl)) {}
492 return Impl->initializeMachineFunction(MF);
499 if (std::error_code EC = FileOrErr.getError()) {
501 "Could not open input file: " + EC.message());
507 std::unique_ptr<MIRParser>
510 auto Filename = Contents->getBufferIdentifier();
511 return llvm::make_unique<MIRParser>(
512 llvm::make_unique<MIRParserImpl>(std::move(Contents), Filename, Context));
void setHasStackMap(bool s=true)
void setFrameAddressIsTaken(bool T)
Represents a range in source code.
std::vector< FlowStringValue > Successors
const char * getPointer() const
A Module instance is used to store all the information related to an LLVM module. ...
void setIsLandingPad(bool V=true)
setIsLandingPad - Indicates the block is a landing pad.
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. ...
bool parseMachineInstr(MachineInstr *&MI, SourceMgr &SM, MachineFunction &MF, StringRef Src, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots, SMDiagnostic &Error)
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
DiagnosticSeverity
Defines the different supported severity of a diagnostic.
std::unique_ptr< MIRParser > createMIRParser(std::unique_ptr< MemoryBuffer > Contents, LLVMContext &Context)
This function is another interface to the MIR serialization format parser.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Diagnostic information for machine IR parser.
void addLiveIn(unsigned Reg)
Adds the specified register as a live in.
A forward iterator which reads text lines from a buffer.
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
bool initializeMachineFunction(MachineFunction &MF)
Initialize the machine function to the state that's described in the MIR file.
std::enable_if< has_ScalarEnumerationTraits< T >::value, void >::type yamlize(IO &io, T &Val, bool)
void setAlignment(unsigned Align)
setAlignment - Set alignment of the basic block.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
unsigned getMainFileID() const
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.
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.
const TargetRegisterClass * getRegClass(unsigned i) const
getRegClass - Returns the register class associated with the enumeration value.
StringRef getLineContents() const
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...
MIRParserImpl(std::unique_ptr< MemoryBuffer > Contents, StringRef Filename, LLVMContext &Context)
DenseMap< unsigned, unsigned > VirtualRegisterSlots
std::vector< VirtualRegisterDefinition > VirtualRegisters
void setHasMustTailInVarArgFunc(bool B)
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool TracksSubRegLiveness
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)
FunctionType::get - This static method is the primary way of constructing a FunctionType.
const char * getRegClassName(const TargetRegisterClass *Class) const
getRegClassName - Returns the name of the register class.
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.
instr_iterator insert(instr_iterator I, MachineInstr *M)
Insert MI into the instruction list before I, possibly inside a bundle.
ValueSymbolTable & getValueSymbolTable()
getSymbolTable() - Return the symbol table...
void setHasOpaqueSPAdjustment(bool B)
MachineBasicBlock * CreateMachineBasicBlock(const BasicBlock *bb=nullptr)
CreateMachineBasicBlock - Allocate a new MachineBasicBlock.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
std::vector< FlowStringValue > LiveIns
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
LLVM Basic Block Representation.
This is an important class for using LLVM in a threaded context.
UnreachableInst - This function has undefined behavior.
void setStackSize(uint64_t Size)
Set the size of the stack.
bool tracksLiveness() const
tracksLiveness - Returns true when tracking register liveness accurately.
static Type * getVoidTy(LLVMContext &C)
void setHasVAStart(bool B)
unsigned MaxCallFrameSize
std::vector< MachineStackObject > StackObjects
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
void setHasInlineAsm(bool B)
Set a flag that indicates that the function contains inline assembly.
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)
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 initializeMachineBasicBlock(MachineFunction &MF, MachineBasicBlock &MBB, const yaml::MachineBasicBlock &YamlMBB, const PerFunctionMIParsingState &PFS)
Initialize the machine basic block using it's YAML representation.
SourceMgr::DiagKind getKind() const
Module.h This file contains the declarations for the Module class.
MachineFrameInfo FrameInfo
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
MachineFrameInfo * getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
void setAdjustsStack(bool V)
std::vector< MachineBasicBlock > BasicBlocks
bool HasOpaqueSPAdjustment
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
bool parseMBBReference(MachineBasicBlock *&MBB, SourceMgr &SM, MachineFunction &MF, StringRef Src, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots, SMDiagnostic &Error)
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...
void setHasAddressTaken()
setHasAddressTaken - Set this block to reflect that it potentially is the target of an indirect branc...
bool parseNamedRegisterReference(unsigned &Reg, SourceMgr &SM, MachineFunction &MF, StringRef Src, const PerFunctionMIParsingState &PFS, const SlotMapping &IRSlots, SMDiagnostic &Error)
This struct contains the mapping from the slot numbers to unnamed metadata nodes and global values...
bool error(const Twine &Message)
Report an error with the given message at unknown location.
static SMLoc getFromPointer(const char *Ptr)
std::vector< StringValue > Instructions
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
bool initializeFrameInfo(MachineFrameInfo &MFI, const yaml::MachineFunction &YamlMF)
Representation of each machine instruction.
void ensureMaxAlignment(unsigned Align)
Make sure the function is at least Align bytes aligned.
const MemoryBuffer * getMemoryBuffer(unsigned i) const
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.
bool IsReturnAddressTaken
void setMaxCallFrameSize(unsigned S)
DenseMap< unsigned, MachineBasicBlock * > MBBSlots
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset)
Create a spill slot at a fixed location on the stack.
void enableSubRegLiveness(bool Enable=true)
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...
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
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...
std::vector< FixedMachineStackObject > FixedStackObjects
void insert(iterator MBBI, MachineBasicBlock *MBB)
const ARM::ArchExtKind Kind
void setReturnAddressIsTaken(bool s)
bool initializeRegisterInfo(const MachineFunction &MF, MachineRegisterInfo &RegInfo, const yaml::MachineFunction &YamlMF, DenseMap< unsigned, unsigned > &VirtualRegisterSlots)
void setAlignment(unsigned A)
setAlignment - Set the alignment (log2, not bytes) of the function.
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.
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.
Represents a location in source code.
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.
void addSuccessor(MachineBasicBlock *succ, uint32_t weight=0)
addSuccessor - Add succ as a successor of this MachineBasicBlock.
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
LLVMContext & getContext() const
Get the global data context.
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...