Skip to content

Commit

Permalink
[globalisel][tablegen] Move <Target>InstructionSelector declarations …
Browse files Browse the repository at this point in the history
…to anonymous namespaces

Summary: This resolves the issue of tablegen-erated includes in the headers for non-GlobalISel builds in a simpler way than before.

Reviewers: qcolombet, ab

Reviewed By: ab

Subscribers: igorb, ab, mgorny, dberris, rovka, llvm-commits, kristof.beyls

Differential Revision: https://reviews.llvm.org/D30998

llvm-svn: 299637
  • Loading branch information
dsandersllvm committed Apr 6, 2017
1 parent 7ee2275 commit 0b5293f
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 153 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Target/AArch64/AArch64.h
Expand Up @@ -22,8 +22,11 @@

namespace llvm {

class AArch64RegisterBankInfo;
class AArch64Subtarget;
class AArch64TargetMachine;
class FunctionPass;
class InstructionSelector;
class MachineFunctionPass;

FunctionPass *createAArch64DeadRegisterDefinitions();
Expand All @@ -45,6 +48,9 @@ FunctionPass *createAArch64A53Fix835769();
FunctionPass *createAArch64CleanupLocalDynamicTLSPass();

FunctionPass *createAArch64CollectLOHPass();
InstructionSelector *
createAArch64InstructionSelector(const AArch64TargetMachine &,
AArch64Subtarget &, AArch64RegisterBankInfo &);

void initializeAArch64A53Fix835769Pass(PassRegistry&);
void initializeAArch64A57FPLoadBalancingPass(PassRegistry&);
Expand Down
53 changes: 52 additions & 1 deletion llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
Expand Up @@ -12,18 +12,19 @@
/// \todo This should be generated by TableGen.
//===----------------------------------------------------------------------===//

#include "AArch64InstructionSelector.h"
#include "AArch64InstrInfo.h"
#include "AArch64MachineFunctionInfo.h"
#include "AArch64RegisterBankInfo.h"
#include "AArch64RegisterInfo.h"
#include "AArch64Subtarget.h"
#include "AArch64TargetMachine.h"
#include "MCTargetDesc/AArch64AddressingModes.h"
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Debug.h"
Expand All @@ -37,6 +38,47 @@ using namespace llvm;
#error "You shouldn't build this"
#endif

namespace {

class AArch64InstructionSelector : public InstructionSelector {
public:
AArch64InstructionSelector(const AArch64TargetMachine &TM,
const AArch64Subtarget &STI,
const AArch64RegisterBankInfo &RBI);

bool select(MachineInstr &I) const override;

private:
/// tblgen-erated 'select' implementation, used as the initial selector for
/// the patterns that don't require complex C++.
bool selectImpl(MachineInstr &I) const;

bool selectVaStartAAPCS(MachineInstr &I, MachineFunction &MF,
MachineRegisterInfo &MRI) const;
bool selectVaStartDarwin(MachineInstr &I, MachineFunction &MF,
MachineRegisterInfo &MRI) const;

bool selectCompareBranch(MachineInstr &I, MachineFunction &MF,
MachineRegisterInfo &MRI) const;

bool selectArithImmed(MachineOperand &Root, MachineOperand &Result1,
MachineOperand &Result2) const;

const AArch64TargetMachine &TM;
const AArch64Subtarget &STI;
const AArch64InstrInfo &TII;
const AArch64RegisterInfo &TRI;
const AArch64RegisterBankInfo &RBI;

// We declare the temporaries used by selectImpl() in the class to minimize the
// cost of constructing placeholder values.
#define GET_GLOBALISEL_TEMPORARIES_DECL
#include "AArch64GenGlobalISel.inc"
#undef GET_GLOBALISEL_TEMPORARIES_DECL
};

} // end anonymous namespace

#define GET_GLOBALISEL_IMPL
#include "AArch64GenGlobalISel.inc"
#undef GET_GLOBALISEL_IMPL
Expand Down Expand Up @@ -1315,3 +1357,12 @@ bool AArch64InstructionSelector::selectArithImmed(
Result2.clearParent();
return true;
}

namespace llvm {
InstructionSelector *
createAArch64InstructionSelector(const AArch64TargetMachine &TM,
AArch64Subtarget &Subtarget,
AArch64RegisterBankInfo &RBI) {
return new AArch64InstructionSelector(TM, Subtarget, RBI);
}
}
74 changes: 0 additions & 74 deletions llvm/lib/Target/AArch64/AArch64InstructionSelector.h

This file was deleted.

4 changes: 2 additions & 2 deletions llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
Expand Up @@ -12,7 +12,6 @@

#include "AArch64.h"
#include "AArch64CallLowering.h"
#include "AArch64InstructionSelector.h"
#include "AArch64LegalizerInfo.h"
#include "AArch64MacroFusion.h"
#ifdef LLVM_BUILD_GLOBAL_ISEL
Expand Down Expand Up @@ -286,7 +285,8 @@ AArch64TargetMachine::getSubtargetImpl(const Function &F) const {
// FIXME: At this point, we can't rely on Subtarget having RBI.
// It's awkward to mix passing RBI and the Subtarget; should we pass
// TII/TRI as well?
GISel->InstSelector.reset(new AArch64InstructionSelector(*this, *I, *RBI));
GISel->InstSelector.reset(
createAArch64InstructionSelector(*this, *I, *RBI));

GISel->RegBankInfo.reset(RBI);
#endif
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/AArch64/AArch64TargetMachine.h
Expand Up @@ -21,6 +21,8 @@

namespace llvm {

class AArch64RegisterBankInfo;

class AArch64TargetMachine : public LLVMTargetMachine {
protected:
std::unique_ptr<TargetLoweringObjectFile> TLOF;
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/X86/X86.h
Expand Up @@ -21,7 +21,10 @@ namespace llvm {

class FunctionPass;
class ImmutablePass;
class InstructionSelector;
class PassRegistry;
class X86RegisterBankInfo;
class X86Subtarget;
class X86TargetMachine;

/// This pass converts a legalized DAG into a X86-specific DAG, ready for
Expand Down Expand Up @@ -92,6 +95,9 @@ void initializeFixupBWInstPassPass(PassRegistry &);
/// encoding when possible in order to reduce code size.
FunctionPass *createX86EvexToVexInsts();

InstructionSelector *createX86InstructionSelector(X86Subtarget &,
X86RegisterBankInfo &);

void initializeEvexToVexInstPassPass(PassRegistry &);

} // End llvm namespace
Expand Down
50 changes: 49 additions & 1 deletion llvm/lib/Target/X86/X86InstructionSelector.cpp
Expand Up @@ -12,7 +12,6 @@
/// \todo This should be generated by TableGen.
//===----------------------------------------------------------------------===//

#include "X86InstructionSelector.h"
#include "X86InstrBuilder.h"
#include "X86InstrInfo.h"
#include "X86RegisterBankInfo.h"
Expand All @@ -23,7 +22,9 @@
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
#include "llvm/IR/Type.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
Expand All @@ -36,6 +37,47 @@ using namespace llvm;
#error "You shouldn't build this"
#endif

namespace {

class X86InstructionSelector : public InstructionSelector {
public:
X86InstructionSelector(const X86Subtarget &STI,
const X86RegisterBankInfo &RBI);

bool select(MachineInstr &I) const override;

private:
/// tblgen-erated 'select' implementation, used as the initial selector for
/// the patterns that don't require complex C++.
bool selectImpl(MachineInstr &I) const;

// TODO: remove after selectImpl support pattern with a predicate.
unsigned getFAddOp(LLT &Ty, const RegisterBank &RB) const;
unsigned getFSubOp(LLT &Ty, const RegisterBank &RB) const;
unsigned getAddOp(LLT &Ty, const RegisterBank &RB) const;
unsigned getSubOp(LLT &Ty, const RegisterBank &RB) const;
unsigned getLoadStoreOp(LLT &Ty, const RegisterBank &RB, unsigned Opc,
uint64_t Alignment) const;

bool selectBinaryOp(MachineInstr &I, MachineRegisterInfo &MRI,
MachineFunction &MF) const;
bool selectLoadStoreOp(MachineInstr &I, MachineRegisterInfo &MRI,
MachineFunction &MF) const;
bool selectFrameIndex(MachineInstr &I, MachineRegisterInfo &MRI,
MachineFunction &MF) const;

const X86Subtarget &STI;
const X86InstrInfo &TII;
const X86RegisterInfo &TRI;
const X86RegisterBankInfo &RBI;

#define GET_GLOBALISEL_TEMPORARIES_DECL
#include "X86GenGlobalISel.inc"
#undef GET_GLOBALISEL_TEMPORARIES_DECL
};

} // end anonymous namespace

#define GET_GLOBALISEL_IMPL
#include "X86GenGlobalISel.inc"
#undef GET_GLOBALISEL_IMPL
Expand Down Expand Up @@ -415,3 +457,9 @@ bool X86InstructionSelector::selectFrameIndex(MachineInstr &I,

return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
}

InstructionSelector *
llvm::createX86InstructionSelector(X86Subtarget &Subtarget,
X86RegisterBankInfo &RBI) {
return new X86InstructionSelector(Subtarget, RBI);
}
72 changes: 0 additions & 72 deletions llvm/lib/Target/X86/X86InstructionSelector.h

This file was deleted.

4 changes: 1 addition & 3 deletions llvm/lib/Target/X86/X86TargetMachine.cpp
Expand Up @@ -15,7 +15,6 @@
#include "X86.h"
#include "X86CallLowering.h"
#include "X86LegalizerInfo.h"
#include "X86InstructionSelector.h"
#ifdef LLVM_BUILD_GLOBAL_ISEL
#include "X86RegisterBankInfo.h"
#endif
Expand Down Expand Up @@ -287,8 +286,7 @@ X86TargetMachine::getSubtargetImpl(const Function &F) const {

auto *RBI = new X86RegisterBankInfo(*I->getRegisterInfo());
GISel->RegBankInfo.reset(RBI);
GISel->InstSelector.reset(new X86InstructionSelector(*I, *RBI));

GISel->InstSelector.reset(createX86InstructionSelector(*I, *RBI));
#endif
I->setGISelAccessor(*GISel);
}
Expand Down

0 comments on commit 0b5293f

Please sign in to comment.