llvm-project/llvm/lib/AsmParser/LLToken.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

494 lines
7.9 KiB
C
Raw Normal View History

//===- LLToken.h - Token Codes for LLVM Assembly Files ----------*- C++ -*-===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// This file defines the enums for the .ll lexer.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_ASMPARSER_LLTOKEN_H
#define LLVM_LIB_ASMPARSER_LLTOKEN_H
namespace llvm {
namespace lltok {
enum Kind {
// Markers
Eof,
Error,
// Tokens with no info.
dotdotdot, // ...
equal,
comma, // = ,
star, // *
lsquare,
rsquare, // [ ]
lbrace,
rbrace, // { }
less,
greater, // < >
lparen,
rparen, // ( )
exclaim, // !
bar, // |
colon, // :
kw_vscale,
kw_x,
kw_true,
kw_false,
kw_declare,
kw_define,
kw_global,
kw_constant,
Represent runtime preemption in the IR. Currently we do not represent runtime preemption in the IR, which has several drawbacks: 1) The semantics of GlobalValues differ depending on the object file format you are targeting (as well as the relocation-model and -fPIE value). 2) We have no way of disabling inlining of run time interposable functions, since in the IR we only know if a function is link-time interposable. Because of this llvm cannot support elf-interposition semantics. 3) In LTO builds of executables we will have extra knowledge that a symbol resolved to a local definition and can't be preemptable, but have no way to propagate that knowledge through the compiler. This patch adds preemptability specifiers to the IR with the following meaning: dso_local --> means the compiler may assume the symbol will resolve to a definition within the current linkage unit and the symbol may be accessed directly even if the definition is not within this compilation unit. dso_preemptable --> means that the compiler must assume the GlobalValue may be replaced with a definition from outside the current linkage unit at runtime. To ease transitioning dso_preemptable is treated as a 'default' in that low-level codegen will still do the same checks it did previously to see if a symbol should be accessed indirectly. Eventually when IR producers emit the specifiers on all Globalvalues we can change dso_preemptable to mean 'always access indirectly', and remove the current logic. Differential Revision: https://reviews.llvm.org/D20217 llvm-svn: 316668
2017-10-26 23:00:26 +08:00
kw_dso_local,
kw_dso_preemptable,
kw_private,
kw_internal,
kw_linkonce,
kw_linkonce_odr,
kw_weak, // Used as a linkage, and a modifier for "cmpxchg".
kw_weak_odr,
kw_appending,
kw_dllimport,
kw_dllexport,
kw_common,
kw_available_externally,
kw_default,
kw_hidden,
kw_protected,
kw_unnamed_addr,
IR: Introduce local_unnamed_addr attribute. If a local_unnamed_addr attribute is attached to a global, the address is known to be insignificant within the module. It is distinct from the existing unnamed_addr attribute in that it only describes a local property of the module rather than a global property of the symbol. This attribute is intended to be used by the code generator and LTO to allow the linker to decide whether the global needs to be in the symbol table. It is possible to exclude a global from the symbol table if three things are true: - This attribute is present on every instance of the global (which means that the normal rule that the global must have a unique address can be broken without being observable by the program by performing comparisons against the global's address) - The global has linkonce_odr linkage (which means that each linkage unit must have its own copy of the global if it requires one, and the copy in each linkage unit must be the same) - It is a constant or a function (which means that the program cannot observe that the unique-address rule has been broken by writing to the global) Although this attribute could in principle be computed from the module contents, LTO clients (i.e. linkers) will normally need to be able to compute this property as part of symbol resolution, and it would be inefficient to materialize every module just to compute it. See: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html for earlier discussion. Part of the fix for PR27553. Differential Revision: http://reviews.llvm.org/D20348 llvm-svn: 272709
2016-06-15 05:01:22 +08:00
kw_local_unnamed_addr,
kw_externally_initialized,
kw_extern_weak,
kw_external,
kw_thread_local,
kw_localdynamic,
kw_initialexec,
kw_localexec,
kw_zeroinitializer,
kw_undef,
kw_poison,
kw_null,
kw_none,
kw_to,
kw_caller,
kw_within,
kw_from,
kw_tail,
kw_musttail,
kw_notail,
kw_target,
kw_triple,
kw_source_filename,
kw_unwind,
kw_deplibs, // FIXME: Remove in 4.0
kw_datalayout,
kw_volatile,
kw_atomic,
kw_unordered,
kw_monotonic,
kw_acquire,
kw_release,
kw_acq_rel,
kw_seq_cst,
kw_syncscope,
kw_nnan,
kw_ninf,
kw_nsz,
kw_arcp,
kw_contract,
[IR] redefine 'UnsafeAlgebra' / 'reassoc' fast-math-flags and add 'trans' fast-math-flag As discussed on llvm-dev: http://lists.llvm.org/pipermail/llvm-dev/2016-November/107104.html and again more recently: http://lists.llvm.org/pipermail/llvm-dev/2017-October/118118.html ...this is a step in cleaning up our fast-math-flags implementation in IR to better match the capabilities of both clang's user-visible flags and the backend's flags for SDNode. As proposed in the above threads, we're replacing the 'UnsafeAlgebra' bit (which had the 'umbrella' meaning that all flags are set) with a new bit that only applies to algebraic reassociation - 'AllowReassoc'. We're also adding a bit to allow approximations for library functions called 'ApproxFunc' (this was initially proposed as 'libm' or similar). ...and we're out of bits. 7 bits ought to be enough for anyone, right? :) FWIW, I did look at getting this out of SubclassOptionalData via SubclassData (spacious 16-bits), but that's apparently already used for other purposes. Also, I don't think we can just add a field to FPMathOperator because Operator is not intended to be instantiated. We'll defer movement of FMF to another day. We keep the 'fast' keyword. I thought about removing that, but seeing IR like this: %f.fast = fadd reassoc nnan ninf nsz arcp contract afn float %op1, %op2 ...made me think we want to keep the shortcut synonym. Finally, this change is binary incompatible with existing IR as seen in the compatibility tests. This statement: "Newer releases can ignore features from older releases, but they cannot miscompile them. For example, if nsw is ever replaced with something else, dropping it would be a valid way to upgrade the IR." ( http://llvm.org/docs/DeveloperPolicy.html#ir-backwards-compatibility ) ...provides the flexibility we want to make this change without requiring a new IR version. Ie, we're not loosening the FP strictness of existing IR. At worst, we will fail to optimize some previously 'fast' code because it's no longer recognized as 'fast'. This should get fixed as we audit/squash all of the uses of 'isFast()'. Note: an inter-dependent clang commit to use the new API name should closely follow commit. Differential Revision: https://reviews.llvm.org/D39304 llvm-svn: 317488
2017-11-07 00:27:15 +08:00
kw_reassoc,
kw_afn,
kw_fast,
kw_nuw,
kw_nsw,
kw_exact,
kw_inbounds,
kw_inrange,
kw_align,
kw_addrspace,
kw_section,
kw_partition,
kw_alias,
kw_ifunc,
kw_module,
kw_asm,
kw_sideeffect,
kw_alignstack,
kw_inteldialect,
kw_gc,
kw_prefix,
kw_prologue,
kw_c,
kw_cc,
kw_ccc,
kw_fastcc,
kw_coldcc,
kw_intel_ocl_bicc,
kw_cfguard_checkcc,
kw_x86_stdcallcc,
kw_x86_fastcallcc,
kw_x86_thiscallcc,
kw_x86_vectorcallcc,
kw_x86_regcallcc,
kw_arm_apcscc,
kw_arm_aapcscc,
kw_arm_aapcs_vfpcc,
kw_aarch64_vector_pcs,
kw_aarch64_sve_vector_pcs,
kw_msp430_intrcc,
kw_avr_intrcc,
kw_avr_signalcc,
kw_ptx_kernel,
kw_ptx_device,
kw_spir_kernel,
kw_spir_func,
kw_x86_64_sysvcc,
kw_win64cc,
kw_webkit_jscc,
kw_anyregcc,
kw_swiftcc,
kw_preserve_mostcc,
kw_preserve_allcc,
kw_ghccc,
kw_x86_intrcc,
kw_hhvmcc,
kw_hhvm_ccc,
kw_cxx_fast_tlscc,
kw_amdgpu_vs,
kw_amdgpu_ls,
kw_amdgpu_hs,
kw_amdgpu_es,
kw_amdgpu_gs,
kw_amdgpu_ps,
kw_amdgpu_cs,
kw_amdgpu_kernel,
kw_amdgpu_gfx,
kw_tailcc,
// Attributes:
kw_attributes,
kw_allocsize,
kw_alwaysinline,
kw_argmemonly,
kw_sanitize_address,
kw_sanitize_hwaddress,
kw_sanitize_memtag,
kw_builtin,
kw_byval,
kw_inalloca,
kw_cold,
kw_convergent,
kw_dereferenceable,
kw_dereferenceable_or_null,
kw_inaccessiblememonly,
kw_inaccessiblemem_or_argmemonly,
kw_inlinehint,
kw_inreg,
kw_jumptable,
kw_minsize,
kw_naked,
kw_nest,
kw_noalias,
kw_noundef,
kw_nobuiltin,
kw_nocallback,
kw_nocapture,
kw_noduplicate,
kw_nofree,
kw_noimplicitfloat,
kw_noinline,
kw_norecurse,
kw_nonlazybind,
kw_nomerge,
kw_nonnull,
kw_noprofile,
kw_noredzone,
kw_noreturn,
kw_nosync,
kw_nocf_check,
kw_nounwind,
kw_null_pointer_is_valid,
kw_optforfuzzing,
kw_optnone,
kw_optsize,
kw_preallocated,
kw_readnone,
kw_readonly,
kw_returned,
kw_returns_twice,
kw_signext,
kw_speculatable,
kw_ssp,
kw_sspreq,
kw_sspstrong,
kw_safestack,
kw_shadowcallstack,
kw_sret,
kw_sanitize_thread,
kw_sanitize_memory,
kw_speculative_load_hardening,
kw_strictfp,
kw_swifterror,
kw_swiftself,
kw_uwtable,
kw_vscale_range,
kw_willreturn,
kw_writeonly,
kw_zeroext,
kw_immarg,
IR: Define byref parameter attribute This allows tracking the in-memory type of a pointer argument to a function for ABI purposes. This is essentially a stripped down version of byval to remove some of the stack-copy implications in its definition. This includes the base IR changes, and some tests for places where it should be treated similarly to byval. Codegen support will be in a future patch. My original attempt at solving some of these problems was to repurpose byval with a different address space from the stack. However, it is technically permitted for the callee to introduce a write to the argument, although nothing does this in reality. There is also talk of removing and replacing the byval attribute, so a new attribute would need to take its place anyway. This is intended avoid some optimization issues with the current handling of aggregate arguments, as well as fixes inflexibilty in how frontends can specify the kernel ABI. The most honest representation of the amdgpu_kernel convention is to expose all kernel arguments as loads from constant memory. Today, these are raw, SSA Argument values and codegen is responsible for turning these into loads. Background: There currently isn't a satisfactory way to represent how arguments for the amdgpu_kernel calling convention are passed. In reality, arguments are passed in a single, flat, constant memory buffer implicitly passed to the function. It is also illegal to call this function in the IR, and this is only ever invoked by a driver of some kind. It does not make sense to have a stack passed parameter in this context as is implied by byval. It is never valid to write to the kernel arguments, as this would corrupt the inputs seen by other dispatches of the kernel. These argumets are also not in the same address space as the stack, so a copy is needed to an alloca. From a source C-like language, the kernel parameters are invisible. Semantically, a copy is always required from the constant argument memory to a mutable variable. The current clang calling convention lowering emits raw values, including aggregates into the function argument list, since using byval would not make sense. This has some unfortunate consequences for the optimizer. In the aggregate case, we end up with an aggregate store to alloca, which both SROA and instcombine turn into a store of each aggregate field. The optimizer never pieces this back together to see that this is really just a copy from constant memory, so we end up stuck with expensive stack usage. This also means the backend dictates the alignment of arguments, and arbitrarily picks the LLVM IR ABI type alignment. By allowing an explicit alignment, frontends can make better decisions. For example, there's real no advantage to an aligment higher than 4, so a frontend could choose to compact the argument layout. Similarly, there is a high penalty to using an alignment lower than 4, so a frontend could opt into more padding for small arguments. Another design consideration is when it is appropriate to expose the fact that these arguments are all really passed in adjacent memory. Currently we have a late IR optimization pass in codegen to rewrite the kernel argument values into explicit loads to enable vectorization. In most programs, unrelated argument loads can be merged together. However, exposing this property directly from the frontend has some disadvantages. We still need a way to track the original argument sizes and alignments to report to the driver. I find using some side-channel, metadata mechanism to track this unappealing. If the kernel arguments were exposed as a single buffer to begin with, alias analysis would be unaware that the padding bits betewen arguments are meaningless. Another family of problems is there are still some gaps in replacing all of the available parameter attributes with metadata equivalents once lowered to loads. The immediate plan is to start using this new attribute to handle all aggregate argumets for kernels. Long term, it makes sense to migrate all kernel arguments, including scalars, to be passed indirectly in the same manner. Additional context is in D79744.
2020-06-06 04:58:47 +08:00
kw_byref,
kw_mustprogress,
kw_type,
kw_opaque,
kw_comdat,
// Comdat types
kw_any,
kw_exactmatch,
kw_largest,
kw_noduplicates,
kw_samesize,
kw_eq,
kw_ne,
kw_slt,
kw_sgt,
kw_sle,
kw_sge,
kw_ult,
kw_ugt,
kw_ule,
kw_uge,
kw_oeq,
kw_one,
kw_olt,
kw_ogt,
kw_ole,
kw_oge,
kw_ord,
kw_uno,
kw_ueq,
kw_une,
// atomicrmw operations that aren't also instruction keywords.
kw_xchg,
kw_nand,
kw_max,
kw_min,
kw_umax,
kw_umin,
// Instruction Opcodes (Opcode in UIntVal).
kw_fneg,
kw_add,
kw_fadd,
kw_sub,
kw_fsub,
kw_mul,
kw_fmul,
kw_udiv,
kw_sdiv,
kw_fdiv,
kw_urem,
kw_srem,
kw_frem,
kw_shl,
kw_lshr,
kw_ashr,
kw_and,
kw_or,
kw_xor,
kw_icmp,
kw_fcmp,
kw_phi,
kw_call,
kw_trunc,
kw_zext,
kw_sext,
kw_fptrunc,
kw_fpext,
kw_uitofp,
kw_sitofp,
kw_fptoui,
kw_fptosi,
kw_inttoptr,
kw_ptrtoint,
kw_bitcast,
kw_addrspacecast,
kw_select,
kw_va_arg,
kw_landingpad,
kw_personality,
kw_cleanup,
kw_catch,
kw_filter,
kw_ret,
kw_br,
kw_switch,
kw_indirectbr,
kw_invoke,
kw_resume,
kw_unreachable,
kw_cleanupret,
kw_catchswitch,
kw_catchret,
kw_catchpad,
kw_cleanuppad,
kw_callbr,
kw_alloca,
kw_load,
kw_store,
kw_fence,
kw_cmpxchg,
kw_atomicrmw,
kw_getelementptr,
kw_extractelement,
kw_insertelement,
kw_shufflevector,
kw_extractvalue,
kw_insertvalue,
kw_blockaddress,
[llvm][IR] Add dso_local_equivalent Constant The `dso_local_equivalent` constant is a wrapper for functions that represents a value which is functionally equivalent to the global passed to this. That is, if this accepts a function, calling this constant should have the same effects as calling the function directly. This could be a direct reference to the function, the `@plt` modifier on X86/AArch64, a thunk, or anything that's equivalent to the resolved function as a call target. When lowered, the returned address must have a constant offset at link time from some other symbol defined within the same binary. The address of this value is also insignificant. The name is leveraged from `dso_local` where use of a function or variable is resolved to a symbol in the same linkage unit. In this patch: - Addition of `dso_local_equivalent` and handling it - Update Constant::needsRelocation() to strip constant inbound GEPs and take advantage of `dso_local_equivalent` for relative references This is useful for the [Relative VTables C++ ABI](https://reviews.llvm.org/D72959) which makes vtables readonly. This works by replacing the dynamic relocations for function pointers in them with static relocations that represent the offset between the vtable and virtual functions. If a function is externally defined, `dso_local_equivalent` can be used as a generic wrapper for the function to still allow for this static offset calculation to be done. See [RFC](http://lists.llvm.org/pipermail/llvm-dev/2020-August/144469.html) for more details. Differential Revision: https://reviews.llvm.org/D77248
2020-04-02 06:25:04 +08:00
kw_dso_local_equivalent,
kw_freeze,
// Metadata types.
kw_distinct,
// Use-list order directives.
kw_uselistorder,
kw_uselistorder_bb,
// Summary index keywords
kw_path,
kw_hash,
kw_gv,
kw_guid,
kw_name,
kw_summaries,
kw_flags,
kw_blockcount,
kw_linkage,
kw_visibility,
kw_notEligibleToImport,
kw_live,
kw_dsoLocal,
kw_canAutoHide,
kw_function,
kw_insts,
kw_funcFlags,
kw_readNone,
kw_readOnly,
kw_noRecurse,
kw_returnDoesNotAlias,
kw_noInline,
kw_alwaysInline,
kw_calls,
kw_callee,
kw_params,
kw_param,
kw_hotness,
kw_unknown,
kw_hot,
kw_critical,
kw_relbf,
kw_variable,
kw_vTableFuncs,
kw_virtFunc,
kw_aliasee,
kw_refs,
kw_typeIdInfo,
kw_typeTests,
kw_typeTestAssumeVCalls,
kw_typeCheckedLoadVCalls,
kw_typeTestAssumeConstVCalls,
kw_typeCheckedLoadConstVCalls,
kw_vFuncId,
kw_offset,
kw_args,
kw_typeid,
kw_typeidCompatibleVTable,
kw_summary,
kw_typeTestRes,
kw_kind,
kw_unsat,
kw_byteArray,
kw_inline,
kw_single,
kw_allOnes,
kw_sizeM1BitWidth,
kw_alignLog2,
kw_sizeM1,
kw_bitMask,
kw_inlineBits,
kw_vcall_visibility,
kw_wpdResolutions,
kw_wpdRes,
kw_indir,
kw_singleImpl,
kw_branchFunnel,
kw_singleImplName,
kw_resByArg,
kw_byArg,
kw_uniformRetVal,
kw_uniqueRetVal,
kw_virtualConstProp,
kw_info,
kw_byte,
kw_bit,
kw_varFlags,
// Unsigned Valued tokens (UIntVal).
LabelID, // 42:
GlobalID, // @42
LocalVarID, // %42
AttrGrpID, // #42
SummaryID, // ^42
// String valued tokens (StrVal).
LabelStr, // foo:
GlobalVar, // @foo @"foo"
ComdatVar, // $foo
LocalVar, // %foo %"foo"
MetadataVar, // !foo
StringConstant, // "foo"
DwarfTag, // DW_TAG_foo
DwarfAttEncoding, // DW_ATE_foo
DwarfVirtuality, // DW_VIRTUALITY_foo
DwarfLang, // DW_LANG_foo
DwarfCC, // DW_CC_foo
EmissionKind, // lineTablesOnly
NameTableKind, // GNU
DwarfOp, // DW_OP_foo
DIFlag, // DIFlagFoo
DISPFlag, // DISPFlagFoo
DwarfMacinfo, // DW_MACINFO_foo
ChecksumKind, // CSK_foo
// Type valued tokens (TyVal).
Type,
APFloat, // APFloatVal
APSInt // APSInt
};
} // end namespace lltok
} // end namespace llvm
#endif