Skip to content

Commit

Permalink
Remove typed pointers from example
Browse files Browse the repository at this point in the history
Upstream llvm now asserts when trying to enable typed pointers.

llvm-dialects needs to keep support for typed pointers for some time,
but it also needs to compile with upstream llvm.

We could add a CMake flag or make the test code dependent on the llvm
version, but in practice, llvm-dialects examples are only tested here.
  • Loading branch information
Flakebi committed Jul 21, 2023
1 parent b5c7de3 commit c47dec2
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 35 deletions.
24 changes: 1 addition & 23 deletions example/ExampleMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ cl::opt<Action> g_action(
cl::list<std::string> g_inputs(cl::Positional, cl::ZeroOrMore,
cl::desc("Input file(s) (\"-\" for stdin)"));

cl::opt<bool> g_typedPointers("typed-pointers", cl::init(false),
cl::desc("Disable opaque pointers"));

cl::opt<bool> g_rpot("rpot", cl::init(false),
cl::desc("Visit functions in reverse post-order"));

Expand Down Expand Up @@ -135,23 +132,6 @@ std::unique_ptr<Module> createModuleExample(LLVMContext &context) {
return module;
}

/// A smaller example that does not need pointers and works with typed pointers.
std::unique_ptr<Module> createModuleExampleTypedPtrs(LLVMContext &context) {
auto module = std::make_unique<Module>("example", context);
Builder b{context};

Function *fn = Function::Create(FunctionType::get(b.getVoidTy(), false),
GlobalValue::ExternalLinkage, "example-typed", *module);

BasicBlock *bb = BasicBlock::Create(context, "entry", fn);
b.SetInsertPoint(bb);

useUnnamedStructTypes(b);

b.CreateRetVoid();
return module;
}

struct VisitorInnermost {
int counter = 0;
};
Expand Down Expand Up @@ -241,12 +221,10 @@ int main(int argc, char **argv) {
llvm::cl::ParseCommandLineOptions(argc, argv);

LLVMContext context;
if (g_typedPointers)
context.setOpaquePointers(false);
auto dialectContext = DialectContext::make<xd::ExampleDialect>(context);

if (g_action == Action::Build) {
auto module = g_typedPointers ? createModuleExampleTypedPtrs(context) : createModuleExample(context);
auto module = createModuleExample(context);
module->print(llvm::outs(), nullptr, false);
} else {
if (g_inputs.size() != 1) {
Expand Down
12 changes: 0 additions & 12 deletions test/example/test-builder.test
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --tool llvm-dialects-example --include-generated-funcs
; NOTE: stdin isn't used by the example program, but the redirect makes the UTC tool happy.
; RUN: llvm-dialects-example - | FileCheck --check-prefixes=CHECK %s
; RUN: llvm-dialects-example -typed-pointers | FileCheck --check-prefixes=TYPED %s

; CHECK-LABEL: @example(
; CHECK-NEXT: entry:
Expand Down Expand Up @@ -34,14 +33,3 @@
; CHECK-NEXT: call void (...) @xd.write([[TMP2]] [[TMP17]])
; CHECK-NEXT: ret void
;
;
; TYPED-LABEL: @example-typed(
; TYPED-NEXT: entry:
; TYPED-NEXT: [[TMP0:%.*]] = call [[TMP0]] @xd.read.s_s()
; TYPED-NEXT: [[TMP1:%.*]] = call [[TMP1]] @xd.read.s_s_0()
; TYPED-NEXT: [[TMP2:%.*]] = call [[TMP2]] @xd.read.s_s_1()
; TYPED-NEXT: call void (...) @xd.write([[TMP0]] [[TMP0]])
; TYPED-NEXT: call void (...) @xd.write([[TMP1]] [[TMP1]])
; TYPED-NEXT: call void (...) @xd.write([[TMP2]] [[TMP2]])
; TYPED-NEXT: ret void
;

0 comments on commit c47dec2

Please sign in to comment.