LLVM: lib/TargetParser/TargetDataLayout.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

13#include

14using namespace llvm;

15

17 if (T.isOSBinFormatGOFF())

18 return "-m:l";

19 if (T.isOSBinFormatMachO())

20 return "-m:o";

21 if ((T.isOSWindows() || T.isUEFI()) && T.isOSBinFormatCOFF())

22 return T.getArch() == Triple::x86 ? "-m:x" : "-m:w";

23 if (T.isOSBinFormatXCOFF())

24 return "-m:a";

25 return "-m:e";

26}

27

30 std::string Ret;

31

32 if (TT.isLittleEndian())

33

34 Ret += "e";

35 else

36

37 Ret += "E";

38

40

41

42 Ret += "-p:32:32";

43

44

45

46 Ret += "-Fi8";

47

48

50 Ret += "-i64:64";

51

52

53

55 Ret += "-f64:32:64";

56

57

58

60 Ret += "-v64:32:64-v128:32:128";

62 Ret += "-v128:64:128";

63

64

65

66 Ret += "-a:0:32";

67

68

69 Ret += "-n32";

70

71

73 Ret += "-S128";

75 Ret += "-S64";

76 else

77 Ret += "-S32";

78

79 return Ret;

80}

81

82

84 if (TT.isOSBinFormatMachO()) {

86 return "e-m:o-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-"

87 "n32:64-S128-Fn32";

88 return "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-n32:64-S128-"

89 "Fn32";

90 }

91 if (TT.isOSBinFormatCOFF())

92 return "e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-i64:64-i128:"

93 "128-n32:64-S128-Fn32";

94 std::string Endian = TT.isLittleEndian() ? "e" : "E";

95 std::string Ptr32 = TT.getEnvironment() == Triple::GNUILP32 ? "-p:32:32" : "";

96 return Endian + "-m:e" + Ptr32 +

97 "-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-"

98 "n32:64-S128-Fn32";

99}

100

101

104 return "E-m:e-p:64:64-i64:64-i128:128-n32:64-S128";

105 else

106 return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128";

107}

108

110

111

112

113

114 return "e-m:e-S32-p:32:32-i32:32:32-i64:32:32-f32:32:32-f64:32:32-v64:32:32"

115 "-v128:32:32-a:0:32-Fi32-n32";

116}

117

119 if (TT.isLoongArch64())

120 return "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128";

121 assert(TT.isLoongArch32() && "only LA32 and LA64 are currently supported");

122 return "e-m:e-p:32:32-i64:64-n32-S128";

123}

124

126 std::string Ret = "";

127

128 Ret += "E";

129

130

131 Ret += "-m:e";

132

133

134

135

136

137 Ret += "-p:32:16:32";

138

139

140

141 Ret += "-i8:8:8-i16:16:16-i32:16:32";

142

143

144

145

146 Ret += "-n8:16:32";

147

148 Ret += "-a:0:16-S16";

149

150 return Ret;

151}

152

153namespace {

154enum class MipsABI { Unknown, O32, N32, N64 };

155}

156

157

158

159

160

163 return MipsABI::O32;

165 return MipsABI::N32;

167 return MipsABI::N64;

168 if (TT.isABIN32())

169 return MipsABI::N32;

170 assert(ABIName.empty() && "Unknown ABI option for MIPS");

171

172 if (TT.isMIPS64())

173 return MipsABI::N64;

174 return MipsABI::O32;

175}

176

178 std::string Ret;

179 MipsABI ABI = getMipsABI(TT, ABIName);

180

181

182 if (TT.isLittleEndian())

183 Ret += "e";

184 else

185 Ret += "E";

186

187 if (ABI == MipsABI::O32)

188 Ret += "-m:m";

189 else

190 Ret += "-m:e";

191

192

193 if (ABI != MipsABI::N64)

194 Ret += "-p:32:32";

195

196

197

198 Ret += "-i8:8:32-i16:16:32-i64:64";

199

200

201

202

203 if (ABI == MipsABI::N64 || ABI == MipsABI::N32)

204 Ret += "-i128:128-n32:64-S128";

205 else

206 Ret += "-n32-S64";

207

208 return Ret;

209}

210

213 std::string Ret;

214

215

216 if (T.isLittleEndian())

217 Ret = "e";

218 else

219 Ret = "E";

220

222

223

224

226 Ret += "-p:32:32";

227

228

229

230

232 (T.isPPC64ELFv2ABI() && ABIName != "elfv2"))) {

233 Ret += "-Fi64";

234 } else if (T.isOSAIX()) {

235 Ret += is64Bit ? "-Fi64" : "-Fi32";

236 } else {

237 Ret += "-Fn32";

238 }

239

240

241

242 Ret += "-i64:64";

243

244

246 Ret += "-i128:128-n32:64";

247 else

248 Ret += "-n32";

249

250

251

252

253 if (is64Bit && (T.isOSAIX() || T.isOSLinux()))

254 Ret += "-S128-v256:256:256-v512:512:512";

255

256 return Ret;

257}

258

261

262 return "e-m:e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128"

263 "-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-G1";

264 }

265

266

267

268

269

270

271

272 return "e-m:e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32"

273 "-p7:160:256:256:32-p8:128:128:128:48-p9:192:256:256:32-i64:64-"

274 "v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-"

275 "v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8:9";

276}

277

279 std::string Ret;

280

281 if (TT.isLittleEndian())

282 Ret += "e";

283 else

284 Ret += "E";

285

286 Ret += "-m:e";

287

288

289 if (TT.isRISCV64()) {

290 Ret += "-p:64:64-i64:64-i128:128";

291 Ret += "-n32:64";

292 } else {

293 assert(TT.isRISCV32() && "only RV32 and RV64 are currently supported");

294 Ret += "-p:32:32-i64:64";

295 Ret += "-n32";

296 }

297

298

300 if (ABI == "ilp32e")

301 Ret += "-S32";

302 else if (ABI == "lp64e")

303 Ret += "-S64";

304 else

305 Ret += "-S128";

306

307 return Ret;

308}

309

311 const bool Is64Bit = T.isSPARC64();

312

313

314 std::string Ret = T.getArch() == Triple::sparcel ? "e" : "E";

315 Ret += "-m:e";

316

317

318 if (!Is64Bit)

319 Ret += "-p:32:32";

320

321

322 Ret += "-i64:64";

323

324

325

326 Ret += "-i128:128";

327

328

329

330 if (Is64Bit)

331 Ret += "-n32:64";

332 else

333 Ret += "-f128:64-n32";

334

335 if (Is64Bit)

336 Ret += "-S128";

337 else

338 Ret += "-S64";

339

340 return Ret;

341}

342

344 std::string Ret;

345

346

347 Ret += "E";

348

349

351

352

353 if (TT.isOSzOS()) {

354

355 Ret += "-p1:32:32";

356 }

357

358

359

360

361 Ret += "-i1:8:16-i8:8:16";

362

363

364 Ret += "-i64:64";

365

366

367 Ret += "-f128:64";

368

369

370

371 Ret += "-v128:64";

372

373

374 Ret += "-a:8:16";

375

376

377 Ret += "-n32:64";

378

379 return Ret;

380}

381

383 bool Is64Bit = TT.isX86_64();

384

385

386 std::string Ret = "e";

387

389

390 if (!Is64Bit || TT.isX32())

391 Ret += "-p:32:32";

392

393

394 Ret += "-p270:32:32-p271:32:32-p272:64:64";

395

396

397

398

399 if (Is64Bit || TT.isOSWindows())

400 Ret += "-i64:64-i128:128";

401 else if (TT.isOSIAMCU())

402 Ret += "-i64:32-f64:32";

403 else

404 Ret += "-i128:128-f64:32:64";

405

406

407 if (TT.isOSIAMCU())

408 ;

409 else if (Is64Bit || TT.isOSDarwin() || TT.isWindowsMSVCEnvironment())

410 Ret += "-f80:128";

411 else

412 Ret += "-f80:32";

413

414 if (TT.isOSIAMCU())

415 Ret += "-f128:32";

416

417

418 if (Is64Bit)

419 Ret += "-n8:16:32:64";

420 else

421 Ret += "-n8:16:32";

422

423

424 if ((!Is64Bit && TT.isOSWindows()) || TT.isOSIAMCU())

425 Ret += "-a:0:32-S32";

426 else

427 Ret += "-S128";

428

429 return Ret;

430}

431

434 std::string Ret = "e";

435

436

437

438

439 if (!Is64Bit)

440 Ret += "-p:32:32-p6:32:32-p7:32:32";

441 else if (ABIName == "shortptr")

442 Ret += "-p3:32:32-p4:32:32-p5:32:32-p6:32:32-p7:32:32";

443 else

444 Ret += "-p6:32:32";

445

446 Ret += "-i64:64-i128:128-i256:256-v16:16-v32:32-n16:32:64";

447

448 return Ret;

449}

450

452 const auto Arch = TT.getArch();

453

454

455

456

457

459 return "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"

460 "v256:256-v512:512-v1024:1024-n8:16:32:64-G1";

462 return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"

463 "v512:512-v1024:1024-n8:16:32:64-G10";

466 return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"

467 "v512:512-v1024:1024-n32:64-S32-G1-P4-A0";

469 return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"

470 "v512:512-v1024:1024-n8:16:32:64-G1-P9-A0";

471 return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"

472 "v512:512-v1024:1024-n8:16:32:64-G1";

473}

474

476

477 return "E"

478 "-m:e"

479 "-p:32:32"

480 "-i64:64"

481 "-a:0:32"

482 "-n32"

483 "-S64";

484}

485

488 ? (TT.isOSEmscripten() ? "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-"

489 "i128:128-f128:64-n32:64-S128-ni:1:10:20"

490 : "e-m:e-p:64:64-p10:8:8-p20:8:8-i64:64-"

491 "i128:128-n32:64-S128-ni:1:10:20")

492 : (TT.isOSEmscripten() ? "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-"

493 "i128:128-f128:64-n32:64-S128-ni:1:10:20"

494 : "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-"

495 "i128:128-n32:64-S128-ni:1:10:20");

496}

497

499

500 std::string Ret = "e";

501

502

503 Ret += "-m:e";

504

505

506 Ret += "-i64:64";

507

508

509 Ret += "-n32:64";

510

511

512 Ret += "-S128";

513

514

515

516

517 Ret += "-v64:64:64";

518 Ret += "-v128:64:64";

519 Ret += "-v256:64:64";

520 Ret += "-v512:64:64";

521 Ret += "-v1024:64:64";

522 Ret += "-v2048:64:64";

523 Ret += "-v4096:64:64";

524 Ret += "-v8192:64:64";

525 Ret += "-v16384:64:64";

526

527 return Ret;

528}

529

542 return "e-m:e-p:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-"

543 "f32:32:32-i64:32-f64:32-a:0:32-n32";

545 return "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8:16-a:8";

552

553

554

555 return "e-m:e-p:32:32-i1:32-i8:8-i16:16-i32:32-i64:64-f16:16-"

556 "f32:32-f64:64-n8:16:32:64-v48:16:16-v96:32:32-v192:64:64";

558 return "e-m:e-p:32:32:32-a:0-n16:32-"

559 "i64:64:64-i32:32:32-i16:16:16-i1:8:8-f32:32:32-f64:64:64-"

560 "v32:32:32-v64:64:64-v512:512:512-v1024:1024:1024-v2048:2048:2048";

572 return "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-a:8-n8:16-S16";

599 return "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-n32";

616

625

626

627 return "";

628

630 return "";

631 }

633}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

static std::string computeX86DataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:382

static std::string computeNVPTXDataLayout(const Triple &T, StringRef ABIName)

Definition TargetDataLayout.cpp:432

static std::string computePowerDataLayout(const Triple &T, StringRef ABIName)

Definition TargetDataLayout.cpp:211

static std::string computeSystemZDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:343

static std::string computeAMDDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:259

static std::string computeMipsDataLayout(const Triple &TT, StringRef ABIName)

Definition TargetDataLayout.cpp:177

static std::string computeBPFDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:102

static std::string computeSPIRVDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:451

static std::string computeWebAssemblyDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:486

static StringRef getManglingComponent(const Triple &T)

Definition TargetDataLayout.cpp:16

static std::string computeCSKYDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:109

static std::string computeLanaiDataLayout()

Definition TargetDataLayout.cpp:475

static std::string computeM68kDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:125

static std::string computeARMDataLayout(const Triple &TT, StringRef ABIName)

Definition TargetDataLayout.cpp:28

static MipsABI getMipsABI(const Triple &TT, StringRef ABIName)

Definition TargetDataLayout.cpp:161

static std::string computeLoongArchDataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:118

static std::string computeVEDataLayout(const Triple &T)

Definition TargetDataLayout.cpp:498

static std::string computeSparcDataLayout(const Triple &T)

Definition TargetDataLayout.cpp:310

static std::string computeRISCVDataLayout(const Triple &TT, StringRef ABIName)

Definition TargetDataLayout.cpp:278

static std::string computeAArch64DataLayout(const Triple &TT)

Definition TargetDataLayout.cpp:83

static bool is64Bit(const char *name)

StringRef - Represent a constant reference to a string, i.e.

bool starts_with(StringRef Prefix) const

Check if this string starts with the given Prefix.

constexpr bool empty() const

empty - Check if the string is empty.

Triple - Helper class for working with autoconf configuration names.

LLVM_ABI std::string computeDataLayout(StringRef ABIName="") const

Compute the LLVM IR data layout string based on the triple.

Definition TargetDataLayout.cpp:530

ArchType getArch() const

Get the parsed architecture type of this triple.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

LLVM_ABI LLVM_READONLY ARMABI computeTargetABI(const Triple &TT, StringRef ABIName="")

This is an optimization pass for GlobalISel generic memory operations.