[PATCH] D68233: [FPEnv] [WIP] Verify strictfp attribute correctness

Kevin P. Neal via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 30 10:20:30 PDT 2019


kpn created this revision.
kpn added reviewers: craig.topper, andrew.w.kaylor, cameron.mcinally, arsenm, spatel, uweigand, kbarton.
Herald added subscribers: llvm-commits, hiraditya, wdng.
Herald added a project: LLVM.

The strictfp attribute is now defined to require that function definitions be marked strictfp if they contain a strictfp call or a strictfp constrained intrinsic. This patch verifies that all function calls agree with their contained function about the strictfp attribute. It also enforces the attribute if a constrained fp intrinsic is used in a function.

It does _not_ require that all FP instructions in a function be strict if any of this is. That's a later patch.

Note that this patch _cannot_ yet go in the tree because quite a few tests break with this check in place. I'm working on fixing or getting those fixed, and having this patch visible is part of that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68233

Files:
  llvm/lib/IR/Verifier.cpp


Index: llvm/lib/IR/Verifier.cpp
===================================================================
--- llvm/lib/IR/Verifier.cpp
+++ llvm/lib/IR/Verifier.cpp
@@ -277,6 +277,10 @@
   /// already.
   bool SawFrameEscape;
 
+  /// Whether or not we've seen constrained floating-point intrinsics
+  /// in a function.
+  bool HasConstrainedFP;
+
   /// Whether the current function has a DISubprogram attached to it.
   bool HasDebugInfo = false;
 
@@ -347,9 +351,11 @@
     }
 
     Broken = false;
+    HasConstrainedFP = false;
     // FIXME: We strip const here because the inst visitor strips const.
     visit(const_cast<Function &>(F));
     verifySiblingFuncletUnwinds();
+    verifyFunctionConstrainedFP(F);
     InstsInThisBlock.clear();
     DebugFnArgs.clear();
     LandingPadResultTy = nullptr;
@@ -493,6 +499,7 @@
   void visitCatchSwitchInst(CatchSwitchInst &CatchSwitch);
   void visitCleanupReturnInst(CleanupReturnInst &CRI);
 
+  void verifyFunctionConstrainedFP(const Function &F);
   void verifySwiftErrorCall(CallBase &Call, const Value *SwiftErrorVal);
   void verifySwiftErrorValue(const Value *SwiftErrorVal);
   void verifyMustTailCall(CallInst &CI);
@@ -2369,6 +2376,17 @@
     }
 }
 
+
+void Verifier::verifyFunctionConstrainedFP(const Function &F) {
+  if (HasConstrainedFP) {
+    AttributeList Attrs = F.getAttributes();
+    AttributeSet FnAttrs = Attrs.getFnAttributes();
+    Assert (FnAttrs.hasAttribute(Attribute::StrictFP),
+            "Constrained floating point requires function attribute strictfp!",
+            &F);
+  }
+}
+
 // verifyBasicBlock - Verify that a basic block is well formed...
 //
 void Verifier::visitBasicBlock(BasicBlock &BB) {
@@ -2862,6 +2880,16 @@
   // Verify call attributes.
   verifyFunctionAttrs(FTy, Attrs, &Call, IsIntrinsic);
 
+  // Verify strictfp attributes match.
+  Function *ContainingF = Call.getFunction();
+  AttributeSet CFnAttrs = ContainingF->getAttributes().getFnAttributes();
+  AttributeSet CallAttrs = Attrs.getFnAttributes();
+  Assert (CFnAttrs.hasAttribute(Attribute::StrictFP) ==
+          CallAttrs.hasAttribute(Attribute::StrictFP),
+            "Functions and their contained calls must match "
+            "in use of attribute strictfp!",
+            ContainingF, &Call);
+
   // Conservatively check the inalloca argument.
   // We have a bug if we can find that there is an underlying alloca without
   // inalloca.
@@ -4745,6 +4773,7 @@
   unsigned NumOperands = FPI.getNumArgOperands();
   bool HasExceptionMD = false;
   bool HasRoundingMD = false;
+  HasConstrainedFP = true;
   switch (FPI.getIntrinsicID()) {
   case Intrinsic::experimental_constrained_sqrt:
   case Intrinsic::experimental_constrained_sin:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68233.222455.patch
Type: text/x-patch
Size: 2714 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/49a0ff16/attachment.bin>


More information about the llvm-commits mailing list