Skip to content

Commit 859b278

Browse files
MabezDevandreisfr
authored andcommitted
[Object] Init subtarget info with cpu and target feature in initializeRecordStreamer.
The initializeRecordStreamer function previously initialize subtarget info with empty CPU and target features strings. This may cause an error during asm parsing, becasue asm code may use instructions available only for specific target fetures. So, add CPU and target features initialization from parsed functions description.
1 parent 05d11d8 commit 859b278

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

llvm/lib/Object/ModuleSymbolTable.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,27 @@ initializeRecordStreamer(const Module &M,
9090
if (!MAI)
9191
return;
9292

93+
// Extract the target CPU and features from function attributes in the module
94+
// so that the asm parser is initialized with the correct subtarget features.
95+
// Without this, backends that gate instructions on subtarget features (e.g.
96+
// Xtensa's "entry" requiring HasWindowed, or RISC-V multiply instructions)
97+
// would reject valid inline assembly when the default CPU lacks those
98+
// features.
99+
StringRef CPU;
100+
StringRef FS;
101+
for (const Function &F : M) {
102+
if (F.isDeclaration())
103+
continue;
104+
if (const Attribute &A = F.getFnAttribute("target-cpu"); A.isValid())
105+
CPU = A.getValueAsString();
106+
if (const Attribute &A = F.getFnAttribute("target-features"); A.isValid())
107+
FS = A.getValueAsString();
108+
if (!CPU.empty() && !FS.empty())
109+
break;
110+
}
111+
93112
std::unique_ptr<MCSubtargetInfo> STI(
94-
T->createMCSubtargetInfo(TT.str(), "", ""));
113+
T->createMCSubtargetInfo(TT.str(), CPU, FS));
95114
if (!STI)
96115
return;
97116

0 commit comments

Comments
 (0)