Skip to content

Commit e62480b

Browse files
committed
Use TargetMachine
1 parent c109081 commit e62480b

File tree

7 files changed

+28
-22
lines changed

7 files changed

+28
-22
lines changed

llvm/include/llvm/CodeGen/TargetInstrInfo.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,15 +2184,6 @@ class LLVM_ABI TargetInstrInfo : public MCInstrInfo {
21842184
MachineBasicBlock::iterator &MIT,
21852185
unsigned Flags) const;
21862186

2187-
/// Remove all Linker Optimization Hints (LOH) associated with instructions in
2188-
/// \p MIs and \return the number of hints removed. This is useful in
2189-
/// transformations that cause these hints to be illegal, like in the machine
2190-
/// outliner.
2191-
virtual size_t clearLinkerOptimizationHints(
2192-
const SmallPtrSetImpl<MachineInstr *> &MIs) const {
2193-
return 0;
2194-
}
2195-
21962187
/// Optional target hook that returns true if \p MBB is safe to outline from,
21972188
/// and returns any target-specific information in \p Flags.
21982189
virtual bool isMBBSafeToOutlineFrom(MachineBasicBlock &MBB,

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ using ModulePassManager = PassManager<Module>;
3737

3838
class Function;
3939
class GlobalValue;
40+
class MachineInstr;
4041
class MachineModuleInfoWrapperPass;
4142
struct MachineSchedContext;
4243
class Mangler;
@@ -518,6 +519,15 @@ class TargetMachine {
518519

519520
// MachineRegisterInfo callback function
520521
virtual void registerMachineRegisterInfoCallback(MachineFunction &MF) const {}
522+
523+
/// Remove all Linker Optimization Hints (LOH) associated with instructions in
524+
/// \p MIs and \return the number of hints removed. This is useful in
525+
/// transformations that cause these hints to be illegal, like in the machine
526+
/// outliner.
527+
virtual size_t clearLinkerOptimizationHints(
528+
const SmallPtrSetImpl<MachineInstr *> &MIs) const {
529+
return 0;
530+
}
521531
};
522532

523533
} // end namespace llvm

llvm/lib/CodeGen/MachineOutliner.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
6868
#include "llvm/CodeGen/Passes.h"
6969
#include "llvm/CodeGen/TargetInstrInfo.h"
70+
#include "llvm/CodeGen/TargetPassConfig.h"
7071
#include "llvm/CodeGen/TargetSubtargetInfo.h"
7172
#include "llvm/IR/DIBuilder.h"
7273
#include "llvm/IR/IRBuilder.h"
@@ -77,6 +78,7 @@
7778
#include "llvm/Support/Debug.h"
7879
#include "llvm/Support/SuffixTree.h"
7980
#include "llvm/Support/raw_ostream.h"
81+
#include "llvm/Target/TargetMachine.h"
8082
#include "llvm/Transforms/Utils/ModuleUtils.h"
8183
#include <tuple>
8284
#include <vector>
@@ -427,6 +429,7 @@ struct MachineOutliner : public ModulePass {
427429
static char ID;
428430

429431
MachineModuleInfo *MMI = nullptr;
432+
const TargetMachine *TM = nullptr;
430433

431434
/// Set to true if the outliner should consider functions with
432435
/// linkonceodr linkage.
@@ -462,6 +465,7 @@ struct MachineOutliner : public ModulePass {
462465

463466
void getAnalysisUsage(AnalysisUsage &AU) const override {
464467
AU.addRequired<MachineModuleInfoWrapperPass>();
468+
AU.addRequired<TargetPassConfig>();
465469
AU.addPreserved<MachineModuleInfoWrapperPass>();
466470
AU.addUsedIfAvailable<ImmutableModuleSummaryIndexWrapperPass>();
467471
AU.setPreservesAll();
@@ -1081,10 +1085,9 @@ bool MachineOutliner::outline(
10811085
// the outlined function.
10821086
SmallPtrSet<MachineInstr *, 2> MIs;
10831087
for (Candidate &C : OF->Candidates) {
1084-
const TargetInstrInfo &TII = *C.getMF()->getSubtarget().getInstrInfo();
10851088
for (MachineInstr &MI : C)
10861089
MIs.insert(&MI);
1087-
NumRemovedLOHs += TII.clearLinkerOptimizationHints(MIs);
1090+
NumRemovedLOHs += TM->clearLinkerOptimizationHints(MIs);
10881091
MIs.clear();
10891092
}
10901093

@@ -1399,6 +1402,7 @@ bool MachineOutliner::runOnModule(Module &M) {
13991402
initializeOutlinerMode(M);
14001403

14011404
MMI = &getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
1405+
TM = &getAnalysis<TargetPassConfig>().getTM<TargetMachine>();
14021406

14031407
// Number to append to the current outlined function.
14041408
unsigned OutlinedFunctionNum = 0;

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9641,15 +9641,6 @@ AArch64InstrInfo::getOutlinableRanges(MachineBasicBlock &MBB,
96419641
return Ranges;
96429642
}
96439643

9644-
size_t AArch64InstrInfo::clearLinkerOptimizationHints(
9645-
const SmallPtrSetImpl<MachineInstr *> &MIs) const {
9646-
if (MIs.empty())
9647-
return 0;
9648-
auto *MI = *MIs.begin();
9649-
auto *FuncInfo = MI->getMF()->getInfo<AArch64FunctionInfo>();
9650-
return FuncInfo->clearLinkerOptimizationHints(MIs);
9651-
}
9652-
96539644
outliner::InstrType
96549645
AArch64InstrInfo::getOutliningTypeImpl(const MachineModuleInfo &MMI,
96559646
MachineBasicBlock::iterator &MIT,

llvm/lib/Target/AArch64/AArch64InstrInfo.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,6 @@ class AArch64InstrInfo final : public AArch64GenInstrInfo {
493493
outliner::InstrType getOutliningTypeImpl(const MachineModuleInfo &MMI,
494494
MachineBasicBlock::iterator &MIT,
495495
unsigned Flags) const override;
496-
size_t clearLinkerOptimizationHints(
497-
const SmallPtrSetImpl<MachineInstr *> &MIs) const override;
498496
SmallVector<
499497
std::pair<MachineBasicBlock::iterator, MachineBasicBlock::iterator>>
500498
getOutlinableRanges(MachineBasicBlock &MBB, unsigned &Flags) const override;

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,15 @@ AArch64TargetMachine::createPostMachineScheduler(MachineSchedContext *C) const {
509509
return DAG;
510510
}
511511

512+
size_t AArch64TargetMachine::clearLinkerOptimizationHints(
513+
const SmallPtrSetImpl<MachineInstr *> &MIs) const {
514+
if (MIs.empty())
515+
return 0;
516+
auto *MI = *MIs.begin();
517+
auto *FuncInfo = MI->getMF()->getInfo<AArch64FunctionInfo>();
518+
return FuncInfo->clearLinkerOptimizationHints(MIs);
519+
}
520+
512521
void AArch64leTargetMachine::anchor() { }
513522

514523
AArch64leTargetMachine::AArch64leTargetMachine(

llvm/lib/Target/AArch64/AArch64TargetMachine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class AArch64TargetMachine : public CodeGenTargetMachineImpl {
7676
ScheduleDAGInstrs *
7777
createPostMachineScheduler(MachineSchedContext *C) const override;
7878

79+
size_t clearLinkerOptimizationHints(
80+
const SmallPtrSetImpl<MachineInstr *> &MIs) const override;
81+
7982
private:
8083
bool isLittle;
8184
};

0 commit comments

Comments
 (0)