39#define DEBUG_TYPE "asm-printer"
47 std::unique_ptr<MCStreamer> Streamer)
50 StringRef getPassName()
const override {
return "Lanai Assembly Printer"; }
56 bool isBlockOnlyReachableByFallthrough(
68void LanaiAsmPrinter::printOperand(
const MachineInstr *
MI,
int OpNum,
70 const MachineOperand &MO =
MI->getOperand(OpNum);
100 O << MAI.getInternalSymbolPrefix() <<
"JTI" << getFunctionNumber() <<
'_'
105 O << MAI.getInternalSymbolPrefix() <<
"CPI" << getFunctionNumber() <<
'_'
115bool LanaiAsmPrinter::PrintAsmOperand(
const MachineInstr *
MI,
unsigned OpNo,
116 const char *ExtraCode, raw_ostream &O) {
118 if (ExtraCode && ExtraCode[0]) {
122 switch (ExtraCode[0]) {
127 const MachineOperand &FlagsOP =
MI->getOperand(OpNo - 1);
128 if (!FlagsOP.
isImm())
131 const unsigned NumVals =
Flags.getNumOperandRegisters();
134 unsigned RegOp = OpNo + 1;
135 if (RegOp >=
MI->getNumOperands())
137 const MachineOperand &MO =
MI->getOperand(RegOp);
153void LanaiAsmPrinter::emitCallInstruction(
const MachineInstr *
MI) {
154 assert((
MI->getOpcode() == Lanai::CALL ||
MI->getOpcode() == Lanai::CALLR) &&
155 "Unsupported call function");
157 LanaiMCInstLower MCInstLowering(OutContext, *
this);
158 MCSubtargetInfo STI = getSubtargetInfo();
162 OutStreamer->emitInstruction(MCInstBuilder(Lanai::ADD_I_LO)
170 OutStreamer->emitInstruction(MCInstBuilder(Lanai::SW_RI)
178 if (
MI->getOpcode() == Lanai::CALL) {
180 MCInstLowering.Lower(
MI, TmpInst);
182 OutStreamer->emitInstruction(TmpInst, STI);
184 OutStreamer->emitInstruction(MCInstBuilder(Lanai::ADD_R)
186 .addReg(
MI->getOperand(0).getReg())
193void LanaiAsmPrinter::customEmitInstruction(
const MachineInstr *
MI) {
194 LanaiMCInstLower MCInstLowering(OutContext, *
this);
195 MCSubtargetInfo STI = getSubtargetInfo();
197 MCInstLowering.Lower(
MI, TmpInst);
198 OutStreamer->emitInstruction(TmpInst, STI);
201void LanaiAsmPrinter::emitInstruction(
const MachineInstr *
MI) {
202 Lanai_MC::verifyInstructionPredicates(
MI->getOpcode(),
203 getSubtargetInfo().getFeatureBits());
210 emitCallInstruction(&*
I);
214 customEmitInstruction(&*
I);
215 }
while ((++
I !=
E) &&
I->isInsideBundle());
222bool LanaiAsmPrinter::isBlockOnlyReachableByFallthrough(
223 const MachineBasicBlock *
MBB)
const {
240 while (
I != Pred->
begin() && !(--
I)->isTerminator()) {
243 return !
I->isBarrier();
246char LanaiAsmPrinter::ID = 0;
253LLVMInitializeLanaiAsmPrinter() {
259 LanaiAsmPrinter &
AsmPrinter =
static_cast<LanaiAsmPrinter &
>(
269 LanaiAsmPrinter &
AsmPrinter =
static_cast<LanaiAsmPrinter &
>(
280 LanaiAsmPrinter &
AsmPrinter =
static_cast<LanaiAsmPrinter &
>(
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static const Function * getParent(const Value *V)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_EXTERNAL_VISIBILITY
This header defines various interfaces for pass management in LLVM.
This file declares the MachineConstantPool class which is an abstract constant pool to keep track of ...
Promote Memory to Register
ModuleAnalysisManager MAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
static bool printOperand(raw_ostream &OS, const SelectionDAG *G, const SDValue Value)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class is intended to be used as a driving class for all asm writers.
virtual bool isBlockOnlyReachableByFallthrough(const MachineBasicBlock *MBB) const
Return true if the basic block has exactly one predecessor and the control transfer mechanism between...
bool doInitialization(Module &M) override
Set up the AsmPrinter when we are working on a new module.
bool doFinalization(Module &M) override
Shut down the asmprinter.
bool runOnMachineFunction(MachineFunction &MF) override
Emit the specified function out to the OutStreamer.
virtual bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, const char *ExtraCode, raw_ostream &OS)
Print the specified operand of MI, an INLINEASM instruction, using the specified assembler variant.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MFAM)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
static const char * getRegisterName(MCRegister Reg)
void setOpcode(unsigned Op)
StringRef getName() const
getName - Get the symbol name.
MachineInstrBundleIterator< const MachineInstr > const_iterator
LLVM_ABI MCSymbol * getSymbol() const
Return the MCSymbol for this basic block.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
pred_iterator pred_begin()
Instructions::const_iterator const_instr_iterator
Function & getFunction()
Return the LLVM function that this machine code represents.
Representation of each machine instruction.
const GlobalValue * getGlobal() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
const BlockAddress * getBlockAddress() const
MachineOperandType getType() const
getType - Returns the MachineOperandType for this operand.
const char * getSymbolName() const
Register getReg() const
getReg - Returns the register number.
@ MO_Immediate
Immediate operand.
@ MO_ConstantPoolIndex
Address of indexed Constant in Constant Pool.
@ MO_GlobalAddress
Address of a global value.
@ MO_BlockAddress
Address of a basic block.
@ MO_MachineBasicBlock
MachineBasicBlock reference.
@ MO_Register
Register operand.
@ MO_ExternalSymbol
Name of external global symbol.
@ MO_JumpTableIndex
Address of indexed Jump Table for switch.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Represent a constant reference to a string, i.e.
Primary interface to the complete machine description for the target machine.
This class implements an extremely fast bulk output stream that can only output to a stream.
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
static unsigned makePreOp(unsigned AluOp)
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
Target & getTheLanaiTarget()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI void setupModuleAsmPrinter(Module &M, ModuleAnalysisManager &MAM, AsmPrinter &AsmPrinter)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI void setupMachineFunctionAsmPrinter(MachineFunctionAnalysisManager &MFAM, MachineFunction &MF, AsmPrinter &AsmPrinter)
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
RegisterAsmPrinter - Helper template for registering a target specific assembly printer,...