-
Notifications
You must be signed in to change notification settings - Fork 14.3k
llvm-reduce: Reduce global variable code model #133865
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
@llvm/pr-subscribers-llvm-ir Author: Matt Arsenault (arsenm) ChangesThe current API doesn't have a way to unset it. The query returns Full diff: https://github.com/llvm/llvm-project/pull/133865.diff 4 Files Affected:
diff --git a/llvm/include/llvm/IR/GlobalVariable.h b/llvm/include/llvm/IR/GlobalVariable.h
index 83e484816d7d4..5ea5d3b11cd9a 100644
--- a/llvm/include/llvm/IR/GlobalVariable.h
+++ b/llvm/include/llvm/IR/GlobalVariable.h
@@ -289,6 +289,10 @@ class GlobalVariable : public GlobalObject, public ilist_node<GlobalVariable> {
///
void setCodeModel(CodeModel::Model CM);
+ /// Remove the code model for this global.
+ ///
+ void clearCodeModel();
+
// Methods for support type inquiry through isa, cast, and dyn_cast:
static bool classof(const Value *V) {
return V->getValueID() == Value::GlobalVariableVal;
diff --git a/llvm/lib/IR/Globals.cpp b/llvm/lib/IR/Globals.cpp
index 8ca44719a3f94..401f8ac58bce8 100644
--- a/llvm/lib/IR/Globals.cpp
+++ b/llvm/lib/IR/Globals.cpp
@@ -557,6 +557,15 @@ void GlobalVariable::setCodeModel(CodeModel::Model CM) {
assert(getCodeModel() == CM && "Code model representation error!");
}
+void GlobalVariable::clearCodeModel() {
+ unsigned CodeModelData = 0;
+ unsigned OldData = getGlobalValueSubClassData();
+ unsigned NewData = (OldData & ~(CodeModelMask << CodeModelShift)) |
+ (CodeModelData << CodeModelShift);
+ setGlobalValueSubClassData(NewData);
+ assert(getCodeModel() == std::nullopt && "Code model representation error!");
+}
+
//===----------------------------------------------------------------------===//
// GlobalAlias Implementation
//===----------------------------------------------------------------------===//
diff --git a/llvm/test/tools/llvm-reduce/reduce-code-model.ll b/llvm/test/tools/llvm-reduce/reduce-code-model.ll
new file mode 100644
index 0000000000000..898f5995d9826
--- /dev/null
+++ b/llvm/test/tools/llvm-reduce/reduce-code-model.ll
@@ -0,0 +1,18 @@
+; RUN: llvm-reduce -abort-on-invalid-reduction --delta-passes=global-values --test FileCheck --test-arg --check-prefix=INTERESTING --test-arg %s --test-arg --input-file %s -o %t.0
+; RUN: FileCheck --implicit-check-not=define --check-prefix=RESULT %s < %t.0
+
+; INTERESTING: @code_model_large_keep = global i32 0, code_model "large", align 4
+; INTERESTING @code_model_large_drop = global i32 0
+
+; RESULT: @code_model_large_keep = global i32 0, code_model "large", align 4{{$}}
+; RESULT: @code_model_large_drop = global i32 0, align 4{{$}}
+@code_model_large_keep = global i32 0, code_model "large", align 4
+@code_model_large_drop = global i32 0, code_model "large", align 4
+
+; INTERESTING: @code_model_tiny_keep = global i32 0, code_model "tiny", align 4
+; INTERESTING @code_model_tiny_drop = global i32 0
+
+; RESULT: @code_model_tiny_keep = global i32 0, code_model "tiny", align 4{{$}}
+; RESULT: @code_model_tiny_drop = global i32 0, align 4{{$}}
+@code_model_tiny_keep = global i32 0, code_model "tiny", align 4
+@code_model_tiny_drop = global i32 0, code_model "tiny", align 4
diff --git a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
index e56876c38032e..659bf8dd23eff 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceGlobalValues.cpp
@@ -70,7 +70,8 @@ void llvm::reduceGlobalValuesDeltaPass(Oracle &O, ReducerWorkItem &Program) {
if (GVar->isExternallyInitialized() && !O.shouldKeep())
GVar->setExternallyInitialized(false);
- // TODO: Reduce code model
+ if (GVar->getCodeModel() && !O.shouldKeep())
+ GVar->clearCodeModel();
}
}
}
|
Also discovered #133864 adding this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
ca1e66b
to
1aeed13
Compare
The current API doesn't have a way to unset it. The query returns an optional, but the set doesn't. Alternatively I could switch the set to also use optional.
0336fe4
to
3bf571b
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/7996 Here is the relevant piece of the build log for the reference
|
The current API doesn't have a way to unset it. The query returns an optional, but the set doesn't. Alternatively I could switch the set to also use optional.
The current API doesn't have a way to unset it. The query returns
an optional, but the set doesn't. Alternatively I could switch the
set to also use optional.