Skip to content

Commit 3846d84

Browse files
authored
Hexagon: Move RuntimeLibcall setting out of TargetLowering (#142543)
RuntimeLibcalls needs to be correct in non-codegen contexts, so should not be configured in TargetLowering. Hexagon has this exotic, overly general sounding fast math flag which appear to be untested. I've renamed and moved it but this should probably be deleted and move to a combine based on fast math flags.
1 parent d5a1f49 commit 3846d84

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "llvm/IR/RuntimeLibcalls.h"
10+
#include "llvm/Support/CommandLine.h"
1011

1112
using namespace llvm;
1213
using namespace RTLIB;
1314

15+
static cl::opt<bool>
16+
HexagonEnableFastMathRuntimeCalls("hexagon-fast-math", cl::Hidden,
17+
cl::desc("Enable Fast Math processing"));
18+
1419
/// Set default libcall names. If a target wants to opt-out of a libcall it
1520
/// should be placed here.
1621
void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
@@ -302,4 +307,42 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT) {
302307
for (auto &E : RTLibCallCommon)
303308
setLibcallName(E.Code, E.Name);
304309
}
310+
311+
if (TT.getArch() == Triple::ArchType::hexagon) {
312+
setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3");
313+
setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3");
314+
setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3");
315+
setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3");
316+
setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3");
317+
setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3");
318+
setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3");
319+
setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3");
320+
321+
const bool FastMath = HexagonEnableFastMathRuntimeCalls;
322+
// This is the only fast library function for sqrtd.
323+
if (FastMath)
324+
setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2");
325+
326+
// Prefix is: nothing for "slow-math",
327+
// "fast2_" for V5+ fast-math double-precision
328+
// (actually, keep fast-math and fast-math2 separate for now)
329+
if (FastMath) {
330+
setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3");
331+
setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3");
332+
setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3");
333+
setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3");
334+
setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3");
335+
} else {
336+
setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3");
337+
setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3");
338+
setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3");
339+
setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3");
340+
setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3");
341+
}
342+
343+
if (FastMath)
344+
setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf");
345+
else
346+
setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf");
347+
}
305348
}

llvm/lib/Target/Hexagon/HexagonISelLowering.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ static cl::opt<bool>
7373
EnableHexSDNodeSched("enable-hexagon-sdnode-sched", cl::Hidden,
7474
cl::desc("Enable Hexagon SDNode scheduling"));
7575

76-
static cl::opt<bool> EnableFastMath("ffast-math", cl::Hidden,
77-
cl::desc("Enable Fast Math processing"));
78-
7976
static cl::opt<int> MinimumJumpTables("minimum-jump-tables", cl::Hidden,
8077
cl::init(5),
8178
cl::desc("Set minimum jump tables"));
@@ -1850,46 +1847,6 @@ HexagonTargetLowering::HexagonTargetLowering(const TargetMachine &TM,
18501847
initializeHVXLowering();
18511848

18521849
computeRegisterProperties(&HRI);
1853-
1854-
//
1855-
// Library calls for unsupported operations
1856-
//
1857-
bool FastMath = EnableFastMath;
1858-
1859-
setLibcallName(RTLIB::SDIV_I32, "__hexagon_divsi3");
1860-
setLibcallName(RTLIB::SDIV_I64, "__hexagon_divdi3");
1861-
setLibcallName(RTLIB::UDIV_I32, "__hexagon_udivsi3");
1862-
setLibcallName(RTLIB::UDIV_I64, "__hexagon_udivdi3");
1863-
setLibcallName(RTLIB::SREM_I32, "__hexagon_modsi3");
1864-
setLibcallName(RTLIB::SREM_I64, "__hexagon_moddi3");
1865-
setLibcallName(RTLIB::UREM_I32, "__hexagon_umodsi3");
1866-
setLibcallName(RTLIB::UREM_I64, "__hexagon_umoddi3");
1867-
1868-
// This is the only fast library function for sqrtd.
1869-
if (FastMath)
1870-
setLibcallName(RTLIB::SQRT_F64, "__hexagon_fast2_sqrtdf2");
1871-
1872-
// Prefix is: nothing for "slow-math",
1873-
// "fast2_" for V5+ fast-math double-precision
1874-
// (actually, keep fast-math and fast-math2 separate for now)
1875-
if (FastMath) {
1876-
setLibcallName(RTLIB::ADD_F64, "__hexagon_fast_adddf3");
1877-
setLibcallName(RTLIB::SUB_F64, "__hexagon_fast_subdf3");
1878-
setLibcallName(RTLIB::MUL_F64, "__hexagon_fast_muldf3");
1879-
setLibcallName(RTLIB::DIV_F64, "__hexagon_fast_divdf3");
1880-
setLibcallName(RTLIB::DIV_F32, "__hexagon_fast_divsf3");
1881-
} else {
1882-
setLibcallName(RTLIB::ADD_F64, "__hexagon_adddf3");
1883-
setLibcallName(RTLIB::SUB_F64, "__hexagon_subdf3");
1884-
setLibcallName(RTLIB::MUL_F64, "__hexagon_muldf3");
1885-
setLibcallName(RTLIB::DIV_F64, "__hexagon_divdf3");
1886-
setLibcallName(RTLIB::DIV_F32, "__hexagon_divsf3");
1887-
}
1888-
1889-
if (FastMath)
1890-
setLibcallName(RTLIB::SQRT_F32, "__hexagon_fast2_sqrtf");
1891-
else
1892-
setLibcallName(RTLIB::SQRT_F32, "__hexagon_sqrtf");
18931850
}
18941851

18951852
const char* HexagonTargetLowering::getTargetNodeName(unsigned Opcode) const {

0 commit comments

Comments
 (0)