[PATCH] D84054: [lld][ELF] Add LOG2CEIL builtin ldscript function

Isaac Richter via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 26 10:25:12 PDT 2020


irichter updated this revision to Diff 280736.
irichter edited the summary of this revision.
irichter added a comment.

Now using `llvm::Log2_64_Ceil`; also, tests are somewhat less arbitrary (middle values are now near 2^16 and 2^32, maximum is tested at `UINT64_MAX`.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84054/new/

https://reviews.llvm.org/D84054

Files:
  lld/ELF/ScriptParser.cpp
  lld/test/ELF/linkerscript/operators.test


Index: lld/test/ELF/linkerscript/operators.test
===================================================================
--- lld/test/ELF/linkerscript/operators.test
+++ lld/test/ELF/linkerscript/operators.test
@@ -38,6 +38,16 @@
   minus_abs = _end - _start;
   max = MAX(11, 22);
   min = MIN(11, 22);
+  log2ceil0 = LOG2CEIL(0);
+  log2ceil1 = LOG2CEIL(1);
+  log2ceil2 = LOG2CEIL(2);
+  log2ceil3 = LOG2CEIL(3);
+  log2ceil4 = LOG2CEIL(4);
+  log2ceil10000 = LOG2CEIL(0x10000);
+  log2ceil10001 = LOG2CEIL(0x10001);
+  log2ceil100000000 = LOG2CEIL(0x100000000);
+  log2ceil100000001 = LOG2CEIL(0x100000001);
+  log2ceilmax = LOG2CEIL(0xffffffffffffffff);
   logicaland1 = 0 && 0;
   logicaland2 = 0 && 1;
   logicaland3 = 1 && 0;
@@ -78,6 +88,16 @@
 # CHECK-NEXT: 0000000000fff0 A minus_abs
 # CHECK-NEXT: 00000000000016 A max
 # CHECK-NEXT: 0000000000000b A min
+# CHECK-NEXT: 0000000000000000 A log2ceil0
+# CHECK-NEXT: 0000000000000000 A log2ceil1
+# CHECK-NEXT: 0000000000000001 A log2ceil2
+# CHECK-NEXT: 0000000000000002 A log2ceil3
+# CHECK-NEXT: 0000000000000002 A log2ceil4
+# CHECK-NEXT: 0000000000000010 A log2ceil10000
+# CHECK-NEXT: 0000000000000011 A log2ceil10001
+# CHECK-NEXT: 0000000000000020 A log2ceil100000000
+# CHECK-NEXT: 0000000000000021 A log2ceil100000001
+# CHECK-NEXT: 0000000000000040 A log2ceilmax
 # CHECK-NEXT: 00000000000000 A logicaland1
 # CHECK-NEXT: 00000000000000 A logicaland2
 # CHECK-NEXT: 00000000000000 A logicaland3
Index: lld/ELF/ScriptParser.cpp
===================================================================
--- lld/ELF/ScriptParser.cpp
+++ lld/ELF/ScriptParser.cpp
@@ -29,6 +29,7 @@
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/ScopedPrinter.h"
 #include <cassert>
@@ -1329,6 +1330,16 @@
       return cmd->getLMA();
     };
   }
+  if (tok == "LOG2CEIL") {
+    expect("(");
+    Expr a = readExpr();
+    expect(")");
+    return [=] {
+      // LOG2CEIL(0) is defined to be 0
+      return llvm::Log2_64_Ceil(
+          std::max(a().getValue(), static_cast<uint64_t>(1)));
+    };
+  }
   if (tok == "MAX" || tok == "MIN") {
     expect("(");
     Expr a = readExpr();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84054.280736.patch
Type: text/x-patch
Size: 2289 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200726/291a31c1/attachment.bin>


More information about the llvm-commits mailing list