Skip to content

Commit c87e0e8

Browse files
authored
[DirectX] Move triple/DL compat to bitcode writer (llvm#163587)
Move our handling of setting up a compatible triple for DXIL to the bitcode writer itself, and do the same for the datalayout. This avoids us needing to temporarily change the triple just to change it back, and it also allows us to make the datalayout truly compatible, including the `i8:32` alignment that isn't accepted by modern LLVM's DataLayout.
1 parent 72c6e4b commit c87e0e8

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,12 +1165,15 @@ void DXILBitcodeWriter::writeValueSymbolTableForwardDecl() {}
11651165
/// Returns the bit offset to backpatch with the location of the real VST.
11661166
void DXILBitcodeWriter::writeModuleInfo() {
11671167
// Emit various pieces of data attached to a module.
1168-
if (!M.getTargetTriple().empty())
1169-
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE,
1170-
M.getTargetTriple().str(), 0 /*TODO*/);
1171-
const std::string &DL = M.getDataLayoutStr();
1172-
if (!DL.empty())
1173-
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
1168+
1169+
// We need to hardcode a triple and datalayout that's compatible with the
1170+
// historical DXIL triple and datalayout from DXC.
1171+
StringRef Triple = "dxil-ms-dx";
1172+
StringRef DL = "e-m:e-p:32:32-i1:8-i8:8-i16:32-i32:32-i64:64-"
1173+
"f16:32-f32:32-f64:64-n8:16:32:64";
1174+
writeStringRecord(Stream, bitc::MODULE_CODE_TRIPLE, Triple, 0 /*TODO*/);
1175+
writeStringRecord(Stream, bitc::MODULE_CODE_DATALAYOUT, DL, 0 /*TODO*/);
1176+
11741177
if (!M.getModuleInlineAsm().empty())
11751178
writeStringRecord(Stream, bitc::MODULE_CODE_ASM, M.getModuleInlineAsm(),
11761179
0 /*TODO*/);

llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,6 @@ class EmbedDXILPass : public llvm::ModulePass {
149149
std::string Data;
150150
llvm::raw_string_ostream OS(Data);
151151

152-
Triple OriginalTriple = M.getTargetTriple();
153-
// Set to DXIL triple when write to bitcode.
154-
// Only the output bitcode need to be DXIL triple.
155-
M.setTargetTriple(Triple("dxil-ms-dx"));
156-
157152
// Perform late legalization of lifetime intrinsics that would otherwise
158153
// fail the Module Verifier if performed in an earlier pass
159154
legalizeLifetimeIntrinsics(M);
@@ -165,9 +160,6 @@ class EmbedDXILPass : public llvm::ModulePass {
165160
// not-so-legal legalizations
166161
removeLifetimeIntrinsics(M);
167162

168-
// Recover triple.
169-
M.setTargetTriple(OriginalTriple);
170-
171163
Constant *ModuleConstant =
172164
ConstantDataArray::get(M.getContext(), arrayRefFromStringRef(Data));
173165
auto *GV = new llvm::GlobalVariable(M, ModuleConstant->getType(), true,

0 commit comments

Comments
 (0)