Skip to content

Commit

Permalink
GlobalISel: Add known bits to InstructionSelector
Browse files Browse the repository at this point in the history
AMDGPU uses this for some addressing mode selection patterns. The
analysis run itself doesn't do anything so it seems easier to just
always require this than adding a way to opt in.

llvm-svn: 370388
  • Loading branch information
arsenm committed Aug 29, 2019
1 parent e1327e6 commit caff0a8
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
7 changes: 6 additions & 1 deletion llvm/include/llvm/CodeGen/GlobalISel/InstructionSelector.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace llvm {

class APInt;
class APFloat;
class GISelKnownBits;
class MachineInstr;
class MachineInstrBuilder;
class MachineFunction;
Expand Down Expand Up @@ -381,11 +382,15 @@ class InstructionSelector {
virtual bool select(MachineInstr &I) = 0;

CodeGenCoverage *CoverageInfo = nullptr;
GISelKnownBits *KnownBits = nullptr;
MachineFunction *MF = nullptr;

/// Setup per-MF selector state.
virtual void setupMF(MachineFunction &mf, CodeGenCoverage &covinfo) {
virtual void setupMF(MachineFunction &mf,
GISelKnownBits &KB,
CodeGenCoverage &covinfo) {
CoverageInfo = &covinfo;
KnownBits = &KB;
MF = &mf;
}

Expand Down
6 changes: 5 additions & 1 deletion llvm/lib/CodeGen/GlobalISel/InstructionSelect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
#include "llvm/ADT/PostOrderIterator.h"
#include "llvm/ADT/Twine.h"
#include "llvm/CodeGen/GlobalISel/GISelKnownBits.h"
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
#include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
Expand Down Expand Up @@ -53,6 +54,8 @@ InstructionSelect::InstructionSelect() : MachineFunctionPass(ID) { }

void InstructionSelect::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired<TargetPassConfig>();
AU.addRequired<GISelKnownBitsAnalysis>();
AU.addPreserved<GISelKnownBitsAnalysis>();
getSelectionDAGFallbackAnalysisUsage(AU);
MachineFunctionPass::getAnalysisUsage(AU);
}
Expand All @@ -64,12 +67,13 @@ bool InstructionSelect::runOnMachineFunction(MachineFunction &MF) {
return false;

LLVM_DEBUG(dbgs() << "Selecting function: " << MF.getName() << '\n');
GISelKnownBits &KB = getAnalysis<GISelKnownBitsAnalysis>().get(MF);

const TargetPassConfig &TPC = getAnalysis<TargetPassConfig>();
InstructionSelector *ISel = MF.getSubtarget().getInstructionSelector();
CodeGenCoverage CoverageInfo;
assert(ISel && "Cannot work without InstructionSelector");
ISel->setupMF(MF, CoverageInfo);
ISel->setupMF(MF, KB, CoverageInfo);

// An optimization remark emitter. Used to report failures.
MachineOptimizationRemarkEmitter MORE(MF, /*MBFI=*/nullptr);
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ class AArch64InstructionSelector : public InstructionSelector {
bool select(MachineInstr &I) override;
static const char *getName() { return DEBUG_TYPE; }

void setupMF(MachineFunction &MF, CodeGenCoverage &CoverageInfo) override {
InstructionSelector::setupMF(MF, CoverageInfo);
void setupMF(MachineFunction &MF, GISelKnownBits &KB,
CodeGenCoverage &CoverageInfo) override {
InstructionSelector::setupMF(MF, KB, CoverageInfo);

// hasFnAttribute() is expensive to call on every BRCOND selection, so
// cache it here for each run of the selector.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
; VERIFY-NEXT: Verify generated machine code
; ENABLED-O0-NEXT: Localizer
; VERIFY-O0-NEXT: Verify generated machine code
; ENABLED-NEXT: Analysis for ComputingKnownBits
; ENABLED-NEXT: InstructionSelect
; VERIFY-NEXT: Verify generated machine code
; ENABLED-NEXT: ResetMachineFunction
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/AArch64/O0-pipeline.ll
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
; CHECK-NEXT: Legalizer
; CHECK-NEXT: RegBankSelect
; CHECK-NEXT: Localizer
; CHECK-NEXT: Analysis for ComputingKnownBits
; CHECK-NEXT: InstructionSelect
; CHECK-NEXT: ResetMachineFunction
; CHECK-NEXT: AArch64 Instruction Selection
Expand Down

0 comments on commit caff0a8

Please sign in to comment.