Skip to content

Commit db20a7f

Browse files
authored
DAG: Fix constructing a temporary TargetTransformInfo instance (#168480)
1 parent 7f0dbf0 commit db20a7f

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

llvm/include/llvm/CodeGen/SelectionDAGISel.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ class SelectionDAGISel {
5858
AssumptionCache *AC = nullptr;
5959
GCFunctionInfo *GFI = nullptr;
6060
SSPLayoutInfo *SP = nullptr;
61-
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
62-
TargetTransformInfo *TTI = nullptr;
63-
#endif
61+
const TargetTransformInfo *TTI = nullptr;
6462
CodeGenOptLevel OptLevel;
6563
const TargetInstrInfo *TII;
6664
const TargetLowering *TLI;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,14 +1097,15 @@ RegsForValue::getRegsAndSizes() const {
10971097
}
10981098

10991099
void SelectionDAGBuilder::init(GCFunctionInfo *gfi, BatchAAResults *aa,
1100-
AssumptionCache *ac,
1101-
const TargetLibraryInfo *li) {
1100+
AssumptionCache *ac, const TargetLibraryInfo *li,
1101+
const TargetTransformInfo &TTI) {
11021102
BatchAA = aa;
11031103
AC = ac;
11041104
GFI = gfi;
11051105
LibInfo = li;
11061106
Context = DAG.getContext();
11071107
LPadToCallSiteMap.clear();
1108+
this->TTI = &TTI;
11081109
SL->init(DAG.getTargetLoweringInfo(), TM, DAG.getDataLayout());
11091110
AssignmentTrackingEnabled = isAssignmentTrackingEnabled(
11101111
*DAG.getMachineFunction().getFunction().getParent());
@@ -2589,10 +2590,6 @@ bool SelectionDAGBuilder::shouldKeepJumpConditionsTogether(
25892590
if (!LhsDeps.contains(RhsI))
25902591
RhsDeps.try_emplace(RhsI, false);
25912592

2592-
const auto &TLI = DAG.getTargetLoweringInfo();
2593-
const auto &TTI =
2594-
TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
2595-
25962593
InstructionCost CostOfIncluding = 0;
25972594
// See if this instruction will need to computed independently of whether RHS
25982595
// is.
@@ -2632,8 +2629,8 @@ bool SelectionDAGBuilder::shouldKeepJumpConditionsTogether(
26322629
// RHS condition. Use latency because we are essentially trying to calculate
26332630
// the cost of the dependency chain.
26342631
// Possible TODO: We could try to estimate ILP and make this more precise.
2635-
CostOfIncluding +=
2636-
TTI.getInstructionCost(InsPair.first, TargetTransformInfo::TCK_Latency);
2632+
CostOfIncluding += TTI->getInstructionCost(
2633+
InsPair.first, TargetTransformInfo::TCK_Latency);
26372634

26382635
if (CostOfIncluding > CostThresh)
26392636
return false;
@@ -4915,10 +4912,9 @@ void SelectionDAGBuilder::visitMaskedStore(const CallInst &I,
49154912
LocationSize::beforeOrAfterPointer(), Alignment, I.getAAMetadata());
49164913

49174914
const auto &TLI = DAG.getTargetLoweringInfo();
4918-
const auto &TTI =
4919-
TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
4915+
49204916
SDValue StoreNode =
4921-
!IsCompressing && TTI.hasConditionalLoadStoreForType(
4917+
!IsCompressing && TTI->hasConditionalLoadStoreForType(
49224918
I.getArgOperand(0)->getType(), /*IsStore=*/true)
49234919
? TLI.visitMaskedStore(DAG, sdl, getMemoryRoot(), MMO, Ptr, Src0,
49244920
Mask)
@@ -5073,14 +5069,14 @@ void SelectionDAGBuilder::visitMaskedLoad(const CallInst &I, bool IsExpanding) {
50735069
LocationSize::beforeOrAfterPointer(), Alignment, AAInfo, Ranges);
50745070

50755071
const auto &TLI = DAG.getTargetLoweringInfo();
5076-
const auto &TTI =
5077-
TLI.getTargetMachine().getTargetTransformInfo(*I.getFunction());
5072+
50785073
// The Load/Res may point to different values and both of them are output
50795074
// variables.
50805075
SDValue Load;
50815076
SDValue Res;
5082-
if (!IsExpanding && TTI.hasConditionalLoadStoreForType(Src0Operand->getType(),
5083-
/*IsStore=*/false))
5077+
if (!IsExpanding &&
5078+
TTI->hasConditionalLoadStoreForType(Src0Operand->getType(),
5079+
/*IsStore=*/false))
50845080
Res = TLI.visitMaskedLoad(DAG, sdl, InChain, MMO, Load, Ptr, Src0, Mask);
50855081
else
50865082
Res = Load =

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class SelectionDAGBuilder {
232232
BatchAAResults *BatchAA = nullptr;
233233
AssumptionCache *AC = nullptr;
234234
const TargetLibraryInfo *LibInfo = nullptr;
235+
const TargetTransformInfo *TTI = nullptr;
235236

236237
class SDAGSwitchLowering : public SwitchCG::SwitchLowering {
237238
public:
@@ -285,7 +286,7 @@ class SelectionDAGBuilder {
285286
FuncInfo(funcinfo), SwiftError(swifterror) {}
286287

287288
void init(GCFunctionInfo *gfi, BatchAAResults *BatchAA, AssumptionCache *AC,
288-
const TargetLibraryInfo *li);
289+
const TargetLibraryInfo *li, const TargetTransformInfo &TTI);
289290

290291
/// Clear out the current SelectionDAG and the associated state and prepare
291292
/// this SelectionDAGBuilder object to be used for a new block. This doesn't

llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,7 @@ void SelectionDAGISel::initializeAnalysisResults(
519519

520520
SP = &FAM.getResult<SSPLayoutAnalysis>(Fn);
521521

522-
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
523522
TTI = &FAM.getResult<TargetIRAnalysis>(Fn);
524-
#endif
525523
}
526524

527525
void SelectionDAGISel::initializeAnalysisResults(MachineFunctionPass &MFP) {
@@ -578,9 +576,7 @@ void SelectionDAGISel::initializeAnalysisResults(MachineFunctionPass &MFP) {
578576

579577
SP = &MFP.getAnalysis<StackProtector>().getLayoutInfo();
580578

581-
#if !defined(NDEBUG) && LLVM_ENABLE_ABI_BREAKING_CHECKS
582579
TTI = &MFP.getAnalysis<TargetTransformInfoWrapperPass>().getTTI(Fn);
583-
#endif
584580
}
585581

586582
bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
@@ -593,7 +589,7 @@ bool SelectionDAGISel::runOnMachineFunction(MachineFunction &mf) {
593589

594590
ISEL_DUMP(dbgs() << "\n\n\n=== " << FuncName << '\n');
595591

596-
SDB->init(GFI, getBatchAA(), AC, LibInfo);
592+
SDB->init(GFI, getBatchAA(), AC, LibInfo, *TTI);
597593

598594
MF->setHasInlineAsm(false);
599595

0 commit comments

Comments
 (0)