Skip to content

Instantly share code, notes, and snippets.

@RadhikaG
Created January 26, 2017 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save RadhikaG/605c1c34247e4992676967598413aa91 to your computer and use it in GitHub Desktop.
Save RadhikaG/605c1c34247e4992676967598413aa91 to your computer and use it in GitHub Desktop.
#include "X86.h"
#include "X86InstrInfo.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/Target/TargetRegisterInfo.h"
using namespace llvm;
#define X86_MACHINEINSTR_PRINTER_PASS_NAME "Dummy X86 machineinstr printer pass"
namespace {
class X86MachineInstrPrinter : public MachineFunctionPass {
public:
static char ID;
X86MachineInstrPrinter() : MachineFunctionPass(ID) {
initializeX86MachineInstrPrinterPass(*PassRegistry::getPassRegistry());
}
bool runOnMachineFunction(MachineFunction &MF) override;
StringRef getPassName() const override { return X86_MACHINEINSTR_PRINTER_PASS_NAME; }
};
char X86MachineInstrPrinter::ID = 0;
bool X86MachineInstrPrinter::runOnMachineFunction(MachineFunction &MF) {
for (auto &MBB : MF) {
outs() << "Contents of MachineBasicBlock:\n";
outs() << MBB << "\n";
const BasicBlock *BB = MBB.getBasicBlock();
outs() << "Contents of BasicBlock corresponding to MachineBasicBlock:\n";
outs() << BB << "\n";
}
return false;
}
} // end of anonymous namespace
INITIALIZE_PASS(X86MachineInstrPrinter, "x86-machineinstr-printer",
X86_MACHINEINSTR_PRINTER_PASS_NAME,
true, // is CFG only?
true // is analysis?
)
namespace llvm {
FunctionPass *createX86MachineInstrPrinterPass() { return new X86MachineInstrPrinter(); }
}
@uzleo
Copy link

uzleo commented Mar 3, 2020

createX86MachineInstrPrinterPass should be createX86MachineInstrPrinter at end, no?

@uzleo
Copy link

uzleo commented Mar 3, 2020

also the header "llvm/Target/TargetRegisterInfo.h" seemed to move to "llvm/CodeGen/TargetRegisterInfo.h"

@prasantadh
Copy link

thanks @RadhikaG for the post! helped a lot.

also wish that I had seen @uzleo comments sooner!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment