github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions c,cpp,h --
clang/lib/Basic/Targets/WebAssembly.cpp clang/lib/Basic/Targets/WebAssembly.h
clang/lib/Driver/ToolChains/WebAssembly.cpp clang/test/Driver/wasm-features.c
clang/test/Driver/wasm-toolchain.c
clang/test/Preprocessor/wasm-target-features.c lld/wasm/Config.h
lld/wasm/Driver.cpp lld/wasm/Relocations.cpp lld/wasm/SyntheticSections.cpp
lld/wasm/Writer.cpp lld/wasm/WriterUtils.cpp lld/wasm/WriterUtils.h
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h
llvm/lib/Target/WebAssembly/WebAssemblyISelDAGToDAG.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
llvm/lib/Target/WebAssembly/WebAssemblySubtarget.cpp
llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Target/WebAssembly/WebAssemblyUtilities.cpp
llvm/lib/Target/WebAssembly/WebAssemblyUtilities.h --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Basic/Targets/WebAssembly.cpp
b/clang/lib/Basic/Targets/WebAssembly.cpp
index 785bec699..a8bc7c13f 100644
--- a/clang/lib/Basic/Targets/WebAssembly.cpp
+++ b/clang/lib/Basic/Targets/WebAssembly.cpp
@@ -418,11 +418,11 @@ WebAssemblyTargetInfo::getTargetBuiltins() const {
void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts,
const TargetInfo *Aux) {
TargetInfo::adjust(Diags, Opts, Aux);
- // If not using component model threading intrinsics, turn off POSIXThreads
- // and ThreadModel so that we don't predefine _REENTRANT or
__STDCPP_THREADS__
- // if we will eventually end up stripping atomics because they are
unsupported.
- if (!HasComponentModelThreadContext &&
- (!HasAtomics || !HasBulkMemory)) {
+ // If not using component model threading intrinsics, turn off POSIXThreads
+ // and ThreadModel so that we don't predefine _REENTRANT or
__STDCPP_THREADS__
+ // if we will eventually end up stripping atomics because they are
+ // unsupported.
+ if (!HasComponentModelThreadContext && (!HasAtomics || !HasBulkMemory)) {
Opts.POSIXThreads = false;
Opts.setThreadModel(LangOptions::ThreadModelKind::Single);
Opts.ThreadsafeStatics = false;
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 84b9b00bf..151d289d1 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -79,17 +79,19 @@ static bool WantsPthread(const llvm::Triple &Triple, const
ArgList &Args) {
return WantsPthread;
}
-static bool WantsComponentModelThreadContext(const llvm::Triple &Triple, const
ArgList &Args) {
+static bool WantsComponentModelThreadContext(const llvm::Triple &Triple,
+ const ArgList &Args) {
// If the target is WASIP3, then enable the
// component-model-thread-context feature by default, unless explicitly
// disabled.
return Triple.getOS() == llvm::Triple::WASIp3 &&
Args.hasFlag(options::OPT_mcomponent_model_thread_context,
- options::OPT_mno_component_model_thread_context, true);
+ options::OPT_mno_component_model_thread_context, true);
}
static bool WantsSharedMemory(const llvm::Triple &Triple, const ArgList &Args)
{
- return WantsPthread(Triple, Args) &&
!WantsComponentModelThreadContext(Triple, Args);
+ return WantsPthread(Triple, Args) &&
+ !WantsComponentModelThreadContext(Triple, Args);
}
void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h
index 2c4954e68..d3040949a 100644
--- a/lld/wasm/Config.h
+++ b/lld/wasm/Config.h
@@ -282,12 +282,15 @@ struct Ctx {
0>
whyExtractRecords;
- // Whether to use component model thread context intrinsics for the stack
pointer and TLS base.
+ // Whether to use component model thread context intrinsics for the stack
+ // pointer and TLS base.
bool componentModelThreadContext = false;
Ctx();
void reset();
- bool isMultithreaded() const { return componentModelThreadContext ||
arg.sharedMemory; }
+ bool isMultithreaded() const {
+ return componentModelThreadContext || arg.sharedMemory;
+ }
};
extern Ctx ctx;
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 22a2c5ba1..170fc9e51 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -966,8 +966,9 @@ static void createPostLTOSymbols() {
bool is64 = ctx.arg.is64.value_or(false);
- auto stack_pointer_name =
- ctx.componentModelThreadContext ? "__init_stack_pointer" :
"__stack_pointer";
+ auto stack_pointer_name = ctx.componentModelThreadContext
+ ? "__init_stack_pointer"
+ : "__stack_pointer";
if (ctx.isPic) {
ctx.sym.stackPointer =
createUndefinedGlobal(stack_pointer_name, ctx.arg.is64.value_or(false)
@@ -991,9 +992,11 @@ static void createPostLTOSymbols() {
if (ctx.isMultithreaded()) {
// TLS symbols are all hidden/dso-local
- auto tls_base_name = ctx.componentModelThreadContext ? "__init_tls_base" :
"__tls_base";
- ctx.sym.tlsBase = createGlobalVariable(tls_base_name,
!ctx.componentModelThreadContext,
- WASM_SYMBOL_VISIBILITY_HIDDEN);
+ auto tls_base_name =
+ ctx.componentModelThreadContext ? "__init_tls_base" : "__tls_base";
+ ctx.sym.tlsBase =
+ createGlobalVariable(tls_base_name, !ctx.componentModelThreadContext,
+ WASM_SYMBOL_VISIBILITY_HIDDEN);
ctx.sym.tlsSize = createGlobalVariable("__tls_size", false,
WASM_SYMBOL_VISIBILITY_HIDDEN);
ctx.sym.tlsAlign = createGlobalVariable("__tls_align", false,
@@ -1316,68 +1319,73 @@ static void determineThreadContextABI(ArrayRef<ObjFile
*> files) {
// A complication is that a user may attempt to link together object files
// compiled with different versions of LLVM, where one does not specifiy
// -component-model-thread-context when using the global thread context ABI.
- // They may also attempt to link object files with the global ABI compiled
with
- // older LLVM versions, but link them with a newer wasm-ld. To ensure the
correct behavior
- // in both of these cases, we treat the import of a __stack_pointer global
from the env module
- // as an indication that the global thread context ABI is being used.
+ // They may also attempt to link object files with the global ABI compiled
+ // with older LLVM versions, but link them with a newer wasm-ld. To ensure
the
+ // correct behavior in both of these cases, we treat the import of a
+ // __stack_pointer global from the env module as an indication that the
global
+ // thread context ABI is being used.
- enum class ThreadContextABI {
- Undetermined,
- ComponentModelBuiltins,
- Globals
- };
+ enum class ThreadContextABI { Undetermined, ComponentModelBuiltins, Globals
};
ThreadContextABI threadContextABI = ThreadContextABI::Undetermined;
for (ObjFile *obj : files) {
auto targetFeatures = obj->getWasmObj()->getTargetFeatures();
- auto threadContextFeature = llvm::find_if(targetFeatures,
- [](const auto &f) {
- return f.Name ==
"component-model-thread-context";
- });
+ auto threadContextFeature =
+ llvm::find_if(targetFeatures, [](const auto &f) {
+ return f.Name == "component-model-thread-context";
+ });
- bool usesComponentModelThreadContext = threadContextFeature !=
targetFeatures.end() &&
- threadContextFeature->Prefix ==
WASM_FEATURE_PREFIX_USED;
+ bool usesComponentModelThreadContext =
+ threadContextFeature != targetFeatures.end() &&
+ threadContextFeature->Prefix == WASM_FEATURE_PREFIX_USED;
if (threadContextFeature == targetFeatures.end()) {
- // If the feature is not explicitly used or disallowed, check for the
presence of a __stack_pointer
- // import in this specific file to determine if the global thread
context ABI is being used.
- bool hasStackPointerImport = llvm::any_of(obj->getSymbols(), [](const
auto &sym) {
- return sym && sym->getName() == "__stack_pointer" &&
- sym->kind() == Symbol::UndefinedGlobalKind &&
- sym->importModule && sym->importModule == "env";
- });
+ // If the feature is not explicitly used or disallowed, check for the
+ // presence of a __stack_pointer import in this specific file to
determine
+ // if the global thread context ABI is being used.
+ bool hasStackPointerImport =
+ llvm::any_of(obj->getSymbols(), [](const auto &sym) {
+ return sym && sym->getName() == "__stack_pointer" &&
+ sym->kind() == Symbol::UndefinedGlobalKind &&
+ sym->importModule && sym->importModule == "env";
+ });
if (!hasStackPointerImport) {
- // No __stack_pointer import, so this is probably an object file
compiled from assembly or
- // some other source that doesn't care about the thread context ABI.
As such, we let it pass.
+ // No __stack_pointer import, so this is probably an object file
+ // compiled from assembly or some other source that doesn't care about
+ // the thread context ABI. As such, we let it pass.
continue;
}
// Treat this as using the globals ABI
usesComponentModelThreadContext = false;
- }
+ }
if (usesComponentModelThreadContext) {
if (threadContextABI == ThreadContextABI::Undetermined) {
threadContextABI = ThreadContextABI::ComponentModelBuiltins;
} else if (threadContextABI != ThreadContextABI::ComponentModelBuiltins)
{
- error("thread context ABI mismatch: " + obj->getName() +
- " uses component-model-thread-context but other files disallow
it");
+ error(
+ "thread context ABI mismatch: " + obj->getName() +
+ " uses component-model-thread-context but other files disallow
it");
}
} else {
if (threadContextABI == ThreadContextABI::Undetermined) {
threadContextABI = ThreadContextABI::Globals;
} else if (threadContextABI != ThreadContextABI::Globals) {
- error("thread context ABI mismatch: " + obj->getName() +
- " disallows component-model-thread-context but other files use
it");
+ error(
+ "thread context ABI mismatch: " + obj->getName() +
+ " disallows component-model-thread-context but other files use
it");
}
}
}
-
+
// If the ABI is undetermined at this point, default to the globals ABI
- ctx.componentModelThreadContext = (threadContextABI ==
ThreadContextABI::ComponentModelBuiltins);
+ ctx.componentModelThreadContext =
+ (threadContextABI == ThreadContextABI::ComponentModelBuiltins);
if (ctx.arg.sharedMemory && ctx.componentModelThreadContext) {
- error("--shared-memory is currently incompatible with component model
thread context intrinsics");
+ error("--shared-memory is currently incompatible with component model "
+ "thread context intrinsics");
}
}
@@ -1555,9 +1563,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *>
argsArr) {
if (errorCount())
return;
- // Now that LTO is complete and all object files are available, determine
the
- // thread context ABI and create symbols (__stack_pointer, __tls_base, etc.)
based
- // on the determined ABI.
+ // Now that LTO is complete and all object files are available, determine the
+ // thread context ABI and create symbols (__stack_pointer, __tls_base, etc.)
+ // based on the determined ABI.
determineThreadContextABI(ctx.objectFiles);
createPostLTOSymbols();
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 119206017..a39fc7df7 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -651,10 +651,12 @@ void Writer::populateTargetFeatures() {
if (tlsUsed) {
if (!allowed.contains("bulk-memory")) {
- error("bulk-memory feature must be used in order to use thread-local
storage");
+ error("bulk-memory feature must be used in order to use thread-local "
+ "storage");
}
if (!ctx.componentModelThreadContext && !allowed.contains("atomics")) {
- error("atomics feature must be used in order to use thread-local
storage");
+ error(
+ "atomics feature must be used in order to use thread-local storage");
}
}
@@ -1632,8 +1634,10 @@ void Writer::createInitTLSFunction() {
writeUleb128(os, 0, "num locals");
if (tlsSeg) {
- // When using component model thread context intrinsics, we don't set
the TLS base
- //inside __init_tls; this should be done as part of the thread startup
stub.
+ // When using component model thread context intrinsics, we don't set the
+ // TLS base
+ // inside __init_tls; this should be done as part of the thread startup
+ // stub.
if (!ctx.componentModelThreadContext) {
writeU8(os, WASM_OPCODE_LOCAL_GET, "local.get");
writeUleb128(os, 0, "local index");
diff --git
a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
index 916a42664..bb643a956 100644
--- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
+++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
@@ -25,10 +25,12 @@ using namespace llvm;
static bool shouldQuoteName(StringRef Name) {
// Wasm export/import names and import module names can contain characters
// that are not allowed in identifiers, so we need to quote them.
- auto isValidStartChar = [](char C) { return isalpha(C) || C == '_' || C ==
'.'; };
+ auto isValidStartChar = [](char C) {
+ return isalpha(C) || C == '_' || C == '.';
+ };
auto isValidChar = [&](char C) { return isValidStartChar(C) || isdigit(C); };
- return !(Name.size() > 0 && isValidStartChar(Name.front())) ||
- llvm::any_of(Name, [&](char C) { return !isValidChar(C); });
+ return !(Name.size() > 0 && isValidStartChar(Name.front())) ||
+ llvm::any_of(Name, [&](char C) { return !isValidChar(C); });
}
WebAssemblyTargetStreamer::WebAssemblyTargetStreamer(MCStreamer &S)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
index eb176161d..7e314f9da 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
@@ -232,7 +232,8 @@ void WebAssemblyFrameLowering::writeBackSP(
MachineBasicBlock::iterator &InsertStore, const DebugLoc &DL) const {
const auto *TII = MF.getSubtarget<WebAssemblySubtarget>().getInstrInfo();
- if
(MF.getSubtarget<WebAssemblySubtarget>().hasComponentModelThreadContext()) {
+ if (MF.getSubtarget<WebAssemblySubtarget>()
+ .hasComponentModelThreadContext()) {
const char *ES = "__wasm_component_model_builtin_context_set_0";
auto *SPSymbol = MF.createExternalSymbolName(ES);
BuildMI(MBB, InsertStore, DL, TII->get(WebAssembly::CALL))
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h
b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h
index e567345e9..98133d48a 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.h
@@ -48,10 +48,9 @@ public:
bool needsPrologForEH(const MachineFunction &MF) const;
/// Write SP back to __stack_pointer global or context.set.
- void writeBackSP(unsigned SrcReg, MachineFunction &MF,
- MachineBasicBlock &MBB,
- MachineBasicBlock::iterator &InsertStore,
- const DebugLoc &DL) const;
+ void writeBackSP(unsigned SrcReg, MachineFunction &MF, MachineBasicBlock
&MBB,
+ MachineBasicBlock::iterator &InsertStore,
+ const DebugLoc &DL) const;
// Returns the index of the WebAssembly local to which the stack object
// FrameIndex in MF should be allocated, or std::nullopt.
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
index 24d5c1939..8180611a7 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp
@@ -405,8 +405,8 @@ bool
WebAssemblyLateEHPrepare::restoreStackPointer(MachineFunction &MF) {
WebAssembly::isCatch(InsertPos->getOpcode()) &&
"catch/catch_all should be present in every EH pad at this point");
++InsertPos; // Skip the catch instruction
- FrameLowering->writeBackSP(FrameLowering->getSPReg(MF), MF, MBB,
- InsertPos, MBB.begin()->getDebugLoc());
+ FrameLowering->writeBackSP(FrameLowering->getSPReg(MF), MF, MBB, InsertPos,
+ MBB.begin()->getDebugLoc());
}
return Changed;
}
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.cpp
b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.cpp
index 20bd0c3b1..662e01022 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.cpp
@@ -38,12 +38,12 @@
WebAssemblySubtarget::initializeSubtargetDependencies(StringRef CPU,
if (CPU.empty())
CPU = "generic";
- ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
-
+ ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);
+
// WASIP3 implies using the component model thread context intrinsics by
// default, unless explicitly disabled.
- if (!FS.contains("component-model-thread-context") &&
- !HasComponentModelThreadContext &&
+ if (!FS.contains("component-model-thread-context") &&
+ !HasComponentModelThreadContext &&
TargetTriple.getOS() == Triple::WASIp3) {
ToggleFeature(WebAssembly::FeatureComponentModelThreadContext);
HasComponentModelThreadContext = true;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
index 05009b388..4b82172e2 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblySubtarget.h
@@ -112,7 +112,9 @@ public:
bool hasBulkMemoryOpt() const { return HasBulkMemoryOpt; }
bool hasCallIndirectOverlong() const { return HasCallIndirectOverlong; }
bool hasCompactImports() const { return HasCompactImports; }
- bool hasComponentModelThreadContext() const { return
HasComponentModelThreadContext; }
+ bool hasComponentModelThreadContext() const {
+ return HasComponentModelThreadContext;
+ }
bool hasExceptionHandling() const { return HasExceptionHandling; }
bool hasExtendedConst() const { return HasExtendedConst; }
bool hasFP16() const { return HasFP16; }
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 3c620b4bd..f8d3b4a69 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -268,8 +268,8 @@ class CoalesceFeaturesAndStripAtomics final : public
ModulePass {
// function individually, since having multiple feature sets in one module
// currently does not make sense for WebAssembly. If atomics are not enabled,
// also strip atomic operations and thread local storage, unless the target
- // is using component model threading intrinsics which allow thread local
storage
- // without atomics, in which case only strip atomics.
+ // is using component model threading intrinsics which allow thread local
+ // storage without atomics, in which case only strip atomics.
static char ID;
WebAssemblyTargetMachine *WasmTM;
@@ -289,7 +289,7 @@ public:
bool StrippedTLS = false;
if (Features[WebAssembly::FeatureComponentModelThreadContext]) {
- // Using component model threading intrinsics allows TLS without
+ // Using component model threading intrinsics allows TLS without
// atomics, so don't strip TLS even if atomics are disabled.
if (!Features[WebAssembly::FeatureAtomics]) {
StrippedAtomics = stripAtomics(M);
@@ -432,7 +432,7 @@ private:
M.addModuleFlag(Module::ModFlagBehavior::Error,
"wasm-feature-shared-mem",
wasm::WASM_FEATURE_PREFIX_DISALLOWED);
}
-
+
// Mark component-model-thread-context as disallowed when not in use to
// prevent linking object files with incompatible threading ABIs.
if (!Features[WebAssembly::FeatureComponentModelThreadContext]) {
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.h
b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.h
index 5b4e9cff1..c7de7f997 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.h
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyUtilities.h
@@ -77,8 +77,8 @@ bool canLowerMultivalueReturn(const WebAssemblySubtarget
*Subtarget);
bool canLowerReturn(size_t ResultSize, const WebAssemblySubtarget *Subtarget);
// Get the TLS base value for the current target
-// If using component model threading intrinsics: calls
__wasm_component_model_builtin_context_get_1
-// Otherwise: global.get __tls_base
+// If using component model threading intrinsics: calls
+// __wasm_component_model_builtin_context_get_1 Otherwise: global.get
__tls_base
MachineSDNode *getTLSBase(SelectionDAG &DAG, const SDLoc &DL,
const WebAssemblySubtarget *Subtarget);
``````````
</details>
https://github.com/llvm/llvm-project/pull/175800
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits