[Bitcode] Move x86_intrcc upgrade to bitcode reader
authorNikita Popov <npopov@redhat.com>
Fri, 4 Mar 2022 09:30:50 +0000 (10:30 +0100)
committerNikita Popov <npopov@redhat.com>
Fri, 4 Mar 2022 09:30:50 +0000 (10:30 +0100)
This upgrade requires access the legacy pointer element type, so
it needs to happen inside the bitcode reader.

llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/IR/AutoUpgrade.cpp
llvm/test/Bitcode/x86_intr-upgrade.test

index debb530..cba5680 100644 (file)
@@ -3601,6 +3601,16 @@ Error BitcodeReader::parseFunctionRecord(ArrayRef<uint64_t> Record) {
     }
   }
 
+  if (Func->getCallingConv() == CallingConv::X86_INTR &&
+      !Func->arg_empty() && !Func->hasParamAttribute(0, Attribute::ByVal)) {
+    unsigned ParamTypeID = getContainedTypeID(FTyID, 1);
+    Type *ByValTy = getPtrElementTypeByID(ParamTypeID);
+    if (!ByValTy)
+      return error("Missing param element type for x86_intrcc upgrade");
+    Attribute NewAttr = Attribute::getWithByValType(Context, ByValTy);
+    Func->addParamAttr(0, NewAttr);
+  }
+
   MaybeAlign Alignment;
   if (Error Err = parseAlignmentValue(Record[5], Alignment))
     return Err;
index 6803fdb..da01227 100644 (file)
@@ -4496,13 +4496,6 @@ void llvm::UpgradeFunctionAttributes(Function &F) {
     SFPV.visit(F);
   }
 
-  if (F.getCallingConv() == CallingConv::X86_INTR &&
-      !F.arg_empty() && !F.hasParamAttribute(0, Attribute::ByVal)) {
-    Type *ByValTy = F.getArg(0)->getType()->getPointerElementType();
-    Attribute NewAttr = Attribute::getWithByValType(F.getContext(), ByValTy);
-    F.addParamAttr(0, NewAttr);
-  }
-
   // Remove all incompatibile attributes from function.
   F.removeRetAttrs(AttributeFuncs::typeIncompatible(F.getReturnType()));
   for (auto &Arg : F.args())
index 30940be..1e96ce8 100644 (file)
@@ -1,4 +1,5 @@
-RUN: llvm-dis %p/Inputs/x86_intrcc_upgrade.bc -o - | FileCheck %s
+RUN: llvm-dis %p/Inputs/x86_intrcc_upgrade.bc -opaque-pointers=0 -o - | FileCheck %s
+RUN: llvm-dis %p/Inputs/x86_intrcc_upgrade.bc -opaque-pointers=1 -o - | FileCheck %s --check-prefix=OPAQUE
 
 Make sure we upgrade x86_intrcc to a byval with explicit type
 
@@ -9,3 +10,11 @@ CHECK: define x86_intrcc void @non_byval_ptr_struct(%struct* byval(%struct) %0)
 CHECK: declare x86_intrcc void @no_args_decl()
 CHECK: declare x86_intrcc void @non_byval_ptr_arg0_decl(i32* byval(i32))
 CHECK: declare x86_intrcc void @non_byval_ptr_struct_decl(%struct* byval(%struct))
+
+OPAQUE: define x86_intrcc void @no_args() {
+OPAQUE: define x86_intrcc void @non_byval_ptr_arg0(ptr byval(i32) %0)
+OPAQUE: define x86_intrcc void @non_byval_ptr_struct(ptr byval(%struct) %0)
+
+OPAQUE: declare x86_intrcc void @no_args_decl()
+OPAQUE: declare x86_intrcc void @non_byval_ptr_arg0_decl(ptr byval(i32))
+OPAQUE: declare x86_intrcc void @non_byval_ptr_struct_decl(ptr byval(%struct))