Skip to content

[MLIR][LLVM] Move the LLVM inliner interface into a separate file. #11

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

Open
wants to merge 28 commits into
base: byval
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56d94a9
[mlir][llvm] Add experimental alias scope decl intrinsic.
gysit Mar 22, 2023
eb78886
[lldb] Add test for unavailable registers
DavidSpickett Mar 13, 2023
b7165fd
[llvm][ARM] Fix bounds check after use in ARMAsmParser
DavidSpickett Mar 22, 2023
ee2cd60
[dataflow] Log flow condition to the correct stream.
sam-mccall Mar 21, 2023
a578883
[IR] Rename dropUndefImplying to dropUBImplying (NFC)
nikic Mar 22, 2023
1a9d495
[GVN] Regenerate test checks (NFC)
nikic Mar 22, 2023
d25e022
[MLIR][Affine] Fix assumption on int type in memref elt size method
bondhugula Mar 22, 2023
c962690
[LoopPredication] Add a test demonstrating bug.
Mar 22, 2023
ea929a0
[LV] Set inbounds flag using CreateGEP in vectorizeInterleaveGroup(NFC).
fhahn Mar 22, 2023
e2f6ebe
[tests] precommit tests for D145846
vfdff Mar 22, 2023
7949a2a
[InstCombine] enhance icmp with sub folds
vfdff Mar 22, 2023
c8117eb
[mlir] Add a pattern to fold tensor.cast into scf.forall.
pifon2a Mar 22, 2023
255ba1c
[mlir][AffineMap] NFC - Refactor getProjectedMap and split into proje…
nicolasvasilache Mar 22, 2023
f0111f2
[libc][Bazel] Bazel fix for 494734b06d62b
Mar 22, 2023
256c672
[ConstraintElim] Add tests with GEP constant expressions.
fhahn Mar 22, 2023
3a3ad9f
[SimplifyCFG][LICM] Add metadata speculation tests (NFC)
nikic Mar 22, 2023
acf6a32
[flang] add -flang-experimental-hlfir flag to flang-new
tblah Mar 14, 2023
893ce57
docs: add some documentation on Windows SDK search
compnerd Mar 15, 2023
ee5617d
[Dexter] Add timeout options
SLTozer Mar 1, 2023
d6ad4f0
[MemProf] Context disambiguation cloning pass [patch 1a/3]
teresajohnson Dec 29, 2022
d4eb996
[gn build] Port d6ad4f01c3da
llvmgnsyncbot Mar 22, 2023
a17b71d
[NFC] Add DebugVariableAggregate class
OCHyams Mar 22, 2023
f225272
[Assignment Tracking] Fix mem2reg misidentifying unlinked stores
OCHyams Mar 22, 2023
e4ceb5a
[X86] Create extra prolog/epilog for stack realignment
LuoYuanke Mar 22, 2023
e7618a6
[GVN] Fix change reporting when removing assume (PR61574)
nikic Mar 22, 2023
a2033ff
[gn build] Port e4ceb5a7bb9b
llvmgnsyncbot Mar 22, 2023
ed114b6
[MLIR][LLVM] Copy byval attributes during inlining.
definelicht Mar 22, 2023
76f2608
[MLIR][LLVM] Move the LLVM inliner interface into a separate file.
definelicht Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions clang/docs/UsersManual.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4487,3 +4487,126 @@ If the user is using the static CRT (``/MT``), then different runtimes are used
to produce DLLs and EXEs. To link a DLL, pass
``clang_rt.asan_dll_thunk-x86_64.lib``. To link an EXE, pass
``-wholearchive:clang_rt.asan-x86_64.lib``.

Windows System Headers and Library Lookup
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang-cl uses a set of different approaches to locate the right system libraries
to link against when building code. The Windows environment uses libraries from
three distinct sources:

1. Windows SDK
2. UCRT (Universal C Runtime)
3. Visual C++ Tools (VCRuntime)

The Windows SDK provides the import libraries and headers required to build
programs against the Windows system packages. Underlying the Windows SDK is the
UCRT, the universal C runtime.

This difference is best illustrated by the various headers that one would find
in the different categories. The WinSDK would contain headers such as
`WinSock2.h` which is part of the Windows API surface, providing the Windows
socketing interfaces for networking. UCRT provides the C library headers,
including e.g. `stdio.h`. Finally, the Visual C++ tools provides the underlying
Visual C++ Runtime headers such as `stdint.h` or `crtdefs.h`.

There are various controls that allow the user control over where clang-cl will
locate these headers. The default behaviour for the Windows SDK and UCRT is as
follows:

1. Consult the command line.

Anything the user specifies is always given precedence. The following
extensions are part of the clang-cl toolset:

- `/winsysroot:`

The `/winsysroot:` is used as an equivalent to `-sysroot` on Unix
environments. It allows the control of an alternate location to be treated
as a system root. When specified, it will be used as the root where the
`Windows Kits` is located.

- `/winsdkversion:`
- `/winsdkdir:`

If `/winsysroot:` is not specified, the `/winsdkdir:` argument is consulted
as a location to identify where the Windows SDK is located. Contrary to
`/winsysroot:`, `/winsdkdir:` is expected to be the complete path rather
than a root to locate `Windows Kits`.

The `/winsdkversion:` flag allows the user to specify a version identifier
for the SDK to prefer. When this is specified, no additional validation is
performed and this version is preferred. If the version is not specified,
the highest detected version number will be used.

2. Consult the environment.

TODO: This is not yet implemented.

This will consult the environment variables:

- `WindowsSdkDir`
- `UCRTVersion`

3. Fallback to the registry.

If no arguments are used to indicate where the SDK is present, and the
compiler is running on Windows, the registry is consulted to locate the
installation.

The Visual C++ Toolset has a slightly more elaborate mechanism for detection.

1. Consult the command line.

- `/winsysroot:`

The `/winsysroot:` is used as an equivalent to `-sysroot` on Unix
environments. It allows the control of an alternate location to be treated
as a system root. When specified, it will be used as the root where the
`VC` directory is located.

- `/vctoolsdir:`
- `/vctoolsversion:`

If `/winsysroot:` is not specified, the `/vctoolsdir:` argument is consulted
as a location to identify where the Visual C++ Tools are located. If
`/vctoolsversion:` is specified, that version is preferred, otherwise, the
highest version detected is used.

2. Consult the environment.

- `/external:[VARIABLE]`

This specifies a user identified environment variable which is treated as
a path delimiter (`;`) separated list of paths to map into `-imsvc`
arguments which are treated as `-isystem`.

- `INCLUDE` and `EXTERNAL_INCLUDE`

The path delimiter (`;`) separated list of paths will be mapped to
`-imsvc` arguments which are treated as `-isystem`.

- `LIB` (indirectly)

The linker `link.exe` or `lld-link.exe` will honour the environment
variable `LIB` which is a path delimiter (`;`) set of paths to consult for
the import libraries to use when linking the final target.

The following environment variables will be consulted and used to form paths
to validate and load content from as appropriate:

- `VCToolsInstallDir`
- `VCINSTALLDIR`
- `Path`

3. Consult `ISetupConfiguration` [Windows Only]

Assuming that the toolchain is built with `USE_MSVC_SETUP_API` defined and
is running on Windows, the Visual Studio COM interface `ISetupConfiguration`
will be used to locate the installation of the MSVC toolset.

4. Fallback to the registry [DEPRECATED]

The registry information is used to help locate the installation as a final
fallback. This is only possible for pre-VS2017 installations and is
considered deprecated.
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ class DataflowAnalysisContext {
/// `Val2` imposed by the flow condition.
bool equivalentBoolValues(BoolValue &Val1, BoolValue &Val2);

LLVM_DUMP_METHOD void dumpFlowCondition(AtomicBoolValue &Token);
LLVM_DUMP_METHOD void dumpFlowCondition(AtomicBoolValue &Token,
llvm::raw_ostream &OS = llvm::dbgs());

/// Returns the `ControlFlowContext` registered for `F`, if any. Otherwise,
/// returns null.
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -5080,6 +5080,10 @@ def flang_experimental_exec : Flag<["-"], "flang-experimental-exec">,
Flags<[FlangOption, FlangOnlyOption, NoXarchOption, HelpHidden]>,
HelpText<"Enable support for generating executables (experimental)">;

def flang_experimental_hlfir : Flag<["-"], "flang-experimental-hlfir">,
Flags<[FlangOption, FC1Option, FlangOnlyOption, NoXarchOption, HelpHidden]>,
HelpText<"Use HLFIR lowering (experimental)">;

//===----------------------------------------------------------------------===//
// FLangOption + CoreOption + NoXarchOption
//===----------------------------------------------------------------------===//
Expand Down
5 changes: 3 additions & 2 deletions clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,16 @@ BoolValue &DataflowAnalysisContext::buildAndSubstituteFlowConditionWithCache(
return substituteBoolValue(*ConstraintsIt->second, SubstitutionsCache);
}

void DataflowAnalysisContext::dumpFlowCondition(AtomicBoolValue &Token) {
void DataflowAnalysisContext::dumpFlowCondition(AtomicBoolValue &Token,
llvm::raw_ostream &OS) {
llvm::DenseSet<BoolValue *> Constraints = {&Token};
llvm::DenseSet<AtomicBoolValue *> VisitedTokens;
addTransitiveFlowConditionConstraints(Token, Constraints, VisitedTokens);

llvm::DenseMap<const AtomicBoolValue *, std::string> AtomNames = {
{&getBoolLiteralValue(false), "False"},
{&getBoolLiteralValue(true), "True"}};
llvm::dbgs() << debugString(Constraints, AtomNames);
OS << debugString(Constraints, AtomNames);
}

const ControlFlowContext *
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ void Environment::dump(raw_ostream &OS) const {
}

OS << "FlowConditionToken:\n";
DACtx->dumpFlowCondition(*FlowConditionToken);
DACtx->dumpFlowCondition(*FlowConditionToken, OS);
}

void Environment::dump() const {
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/ToolChains/Flang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ void Flang::addOtherOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
if (stackArrays &&
!stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
CmdArgs.push_back("-fstack-arrays");

if (Args.hasArg(options::OPT_flang_experimental_hlfir))
CmdArgs.push_back("-flang-experimental-hlfir");
}

void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from dex.debugger.DebuggerControllers.DebuggerControllerBase import DebuggerControllerBase
from dex.debugger.DebuggerBase import DebuggerBase
from dex.utils.Exceptions import DebuggerException
from dex.utils.Timeout import Timeout


class BreakpointRange:
Expand Down Expand Up @@ -140,10 +141,26 @@ def _run_debugger_custom(self, cmdline):
time.sleep(self._pause_between_steps)

exit_desired = False
timed_out = False
total_timeout = Timeout(self.context.options.timeout_total)

while not self.debugger.is_finished:
while self.debugger.is_running:
pass

breakpoint_timeout = Timeout(self.context.options.timeout_breakpoint)
while self.debugger.is_running and not timed_out:
# Check to see whether we've timed out while we're waiting.
if total_timeout.timed_out():
self.context.logger.error('Debugger session has been '
f'running for {total_timeout.elapsed}s, timeout reached!')
timed_out = True
if breakpoint_timeout.timed_out():
self.context.logger.error(f'Debugger session has not '
f'hit a breakpoint for {breakpoint_timeout.elapsed}s, timeout '
'reached!')
timed_out = True

if timed_out:
break

step_info = self.debugger.get_step_info(self._watches, self._step_index)
if step_info.current_frame:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from dex.debugger.DebuggerControllers.DebuggerControllerBase import DebuggerControllerBase
from dex.debugger.DebuggerControllers.ControllerHelpers import in_source_file, update_step_watches
from dex.utils.Exceptions import DebuggerException, LoadDebuggerException
from dex.utils.Timeout import Timeout

class EarlyExitCondition(object):
def __init__(self, on_line, hit_count, expression, values):
Expand Down Expand Up @@ -81,12 +82,25 @@ def _run_debugger_custom(self, cmdline):
self.watches.update(command_obj.get_watches())
early_exit_conditions = self._get_early_exit_conditions()

timed_out = False
total_timeout = Timeout(self.context.options.timeout_total)
max_steps = self.context.options.max_steps
for _ in range(max_steps):
while self.debugger.is_running:
pass

if self.debugger.is_finished:
breakpoint_timeout = Timeout(self.context.options.timeout_breakpoint)
while self.debugger.is_running and not timed_out:
# Check to see whether we've timed out while we're waiting.
if total_timeout.timed_out():
self.context.logger.error('Debugger session has been '
f'running for {total_timeout.elapsed}s, timeout reached!')
timed_out = True
if breakpoint_timeout.timed_out():
self.context.logger.error(f'Debugger session has not '
f'hit a breakpoint for {breakpoint_timeout.elapsed}s, timeout '
'reached!')
timed_out = True

if timed_out or self.debugger.is_finished:
break

self.step_index += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,21 @@ def add_debugger_tool_arguments(parser, context, defaults):
default='',
help='command line arguments for the test program, in addition to any '
'provided by DexCommandLine')

parser.add_argument(
'--timeout-total',
metavar='<seconds>',
type=float,
default=0.0,
help='if >0, debugger session will automatically exit after '
'running for <timeout-total> seconds')
parser.add_argument(
'--timeout-breakpoint',
metavar='<seconds>',
type=float,
default=0.0,
help='if >0, debugger session will automatically exit after '
'waiting <timeout-breakpoint> seconds without hitting a '
'breakpoint')

def handle_debugger_tool_base_options(context, defaults): # noqa
options = context.options
Expand Down
31 changes: 31 additions & 0 deletions cross-project-tests/debuginfo-tests/dexter/dex/utils/Timeout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# DExTer : Debugging Experience Tester
# ~~~~~~ ~ ~~ ~ ~~
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""Utility class to check for timeouts. Timer starts when the object is initialized,
and can be checked by calling timed_out(). Passing a timeout value of 0.0 or less
means a timeout will never be triggered, i.e. timed_out() will always return False.
"""

import time

class Timeout(object):

def __init__(self, duration: float):
self.start = self.now
self.duration = duration

def timed_out(self):
if self.duration <= 0.0:
return False
return self.elapsed > self.duration

@property
def elapsed(self):
return self.now - self.start

@property
def now(self):
return time.time()
23 changes: 20 additions & 3 deletions flang/include/flang/Tools/CLOptions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
#include "mlir/Transforms/Passes.h"
#include "flang/Optimizer/CodeGen/CodeGen.h"
#include "flang/Optimizer/HLFIR/Passes.h"
#include "flang/Optimizer/Transforms/Passes.h"
#include "llvm/Passes/OptimizationLevel.h"
#include "llvm/Support/CommandLine.h"
Expand Down Expand Up @@ -72,7 +73,8 @@ DisableOption(BoxedProcedureRewrite, "boxed-procedure-rewrite",
"rewrite boxed procedures");
#endif

DisableOption(ExternalNameConversion, "external-name-interop", "convert names with external convention");
DisableOption(ExternalNameConversion, "external-name-interop",
"convert names with external convention");

/// Generic for adding a pass to the pass manager if it is not disabled.
template <typename F>
Expand Down Expand Up @@ -211,15 +213,28 @@ inline void createDefaultFIROptimizerPassPipeline(mlir::PassManager &pm,
pm.addPass(mlir::createCSEPass());
}

/// Create a pass pipeline for lowering from HLFIR to FIR
///
/// \param pm - MLIR pass manager that will hold the pipeline definition
/// \param optLevel - optimization level used for creating FIR optimization
/// passes pipeline
inline void createHLFIRToFIRPassPipeline(
mlir::PassManager &pm, llvm::OptimizationLevel optLevel = defaultOptLevel) {
if (optLevel.isOptimizingForSpeed())
pm.addPass(mlir::createCanonicalizerPass());
pm.addPass(hlfir::createLowerHLFIRIntrinsicsPass());
pm.addPass(hlfir::createBufferizeHLFIRPass());
pm.addPass(hlfir::createConvertHLFIRtoFIRPass());
}

#if !defined(FLANG_EXCLUDE_CODEGEN)
inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
llvm::OptimizationLevel optLevel = defaultOptLevel,
bool underscoring = true) {
fir::addBoxedProcedurePass(pm);
pm.addNestedPass<mlir::func::FuncOp>(
fir::createAbstractResultOnFuncOptPass());
pm.addNestedPass<fir::GlobalOp>(
fir::createAbstractResultOnGlobalOptPass());
pm.addNestedPass<fir::GlobalOp>(fir::createAbstractResultOnGlobalOptPass());
fir::addCodeGenRewritePass(pm);
fir::addTargetRewritePass(pm);
fir::addExternalNameConversionPass(pm, underscoring);
Expand All @@ -234,6 +249,8 @@ inline void createDefaultFIRCodeGenPassPipeline(mlir::PassManager &pm,
inline void createMLIRToLLVMPassPipeline(mlir::PassManager &pm,
llvm::OptimizationLevel optLevel = defaultOptLevel,
bool stackArrays = false, bool underscoring = true) {
fir::createHLFIRToFIRPassPipeline(pm, optLevel);

// Add default optimizer pass pipeline.
fir::createDefaultFIROptimizerPassPipeline(pm, optLevel, stackArrays);

Expand Down
5 changes: 5 additions & 0 deletions flang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ bool CompilerInvocation::createFromArgs(
success = false;
}

// -flang-experimental-hlfir
if (args.hasArg(clang::driver::options::OPT_flang_experimental_hlfir)) {
res.loweringOpts.setLowerToHighLevelFIR(true);
}

success &= parseFrontendArgs(res.getFrontendOpts(), args, diags);
parseTargetArgs(res.getTargetOpts(), args);
parsePreprocessorArgs(res.getPreprocessorOpts(), args);
Expand Down
2 changes: 2 additions & 0 deletions flang/test/Driver/driver-help-hidden.f90
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
! CHECK-NEXT: Specify where to find the compiled intrinsic modules
! CHECK-NEXT: -flang-experimental-exec
! CHECK-NEXT: Enable support for generating executables (experimental)
! CHECK-NEXT: -flang-experimental-hlfir
! CHECK-NEXT: Use HLFIR lowering (experimental)
! CHECK-NEXT: -flarge-sizes Use INTEGER(KIND=8) for the result type in size-related intrinsics
! CHECK-NEXT: -flogical-abbreviations Enable logical abbreviations
! CHECK-NEXT: -flto=<value> Set LTO mode
Expand Down
Loading