@@ -57,6 +57,28 @@ ConstantInt *CrossDSOCFI::extractNumericTypeId(MDNode *MD) {
57
57
return C;
58
58
}
59
59
60
+ void setDefaultSubtargetFeatures (const Triple &Triple,
61
+ const StringRef TargetABI, Function *F) {
62
+ if (Triple.isRISCV64 ()) {
63
+ if (TargetABI.contains (" lp64d" ))
64
+ F->addFnAttr (" target-features" , " +d" );
65
+ else if (TargetABI.contains (" lp64f" ))
66
+ F->addFnAttr (" target-features" , " +f" );
67
+ else if (TargetABI.contains (" lp64q" ))
68
+ F->addFnAttr (" target-features" , " +q" );
69
+ } else if (Triple.isRISCV32 () && TargetABI.contains (" ilp32f" )) {
70
+ F->addFnAttr (" target-features" , " +f" );
71
+ }
72
+ }
73
+
74
+ StringRef getTargetABIFromMD (const Module &M) {
75
+ StringRef TargetABI = " " ;
76
+ if (auto *TargetABIMD =
77
+ dyn_cast_or_null<MDString>(M.getModuleFlag (" target-abi" )))
78
+ TargetABI = TargetABIMD->getString ();
79
+ return TargetABI;
80
+ }
81
+
60
82
// / buildCFICheck - emits __cfi_check for the current module.
61
83
void CrossDSOCFI::buildCFICheck (Module &M) {
62
84
// FIXME: verify that __cfi_check ends up near the end of the code section,
@@ -96,6 +118,14 @@ void CrossDSOCFI::buildCFICheck(Module &M) {
96
118
if (T.isARM () || T.isThumb ())
97
119
F->addFnAttr (" target-features" , " +thumb-mode" );
98
120
121
+ StringRef DefaultTargetFeatures = Ctx.getDefaultTargetFeatures ();
122
+ if (DefaultTargetFeatures.empty ()) {
123
+ auto TargetABI = getTargetABIFromMD (M);
124
+ setDefaultSubtargetFeatures (T, TargetABI, F);
125
+ } else {
126
+ F->addFnAttr (" target-features" , DefaultTargetFeatures);
127
+ }
128
+
99
129
auto args = F->arg_begin ();
100
130
Value &CallSiteTypeId = *(args++);
101
131
CallSiteTypeId.setName (" CallSiteTypeId" );
0 commit comments