2017-09-27 23:26:01 +00:00
|
|
|
//===- MILexer.h - Lexer for machine instructions ---------------*- C++ -*-===//
|
2015-06-22 20:37:46 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file declares the function that lexes the machine instruction source
|
|
|
|
// string.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|
|
|
|
|
2015-06-23 23:42:28 +00:00
|
|
|
#include "llvm/ADT/APSInt.h"
|
2015-06-22 20:37:46 +00:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2017-06-06 11:49:48 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-09-27 23:26:01 +00:00
|
|
|
#include <string>
|
2015-06-22 20:37:46 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
class Twine;
|
|
|
|
|
|
|
|
/// A token produced by the machine instruction lexer.
|
|
|
|
struct MIToken {
|
|
|
|
enum TokenKind {
|
|
|
|
// Markers
|
|
|
|
Eof,
|
|
|
|
Error,
|
2015-08-13 23:10:16 +00:00
|
|
|
Newline,
|
2015-06-22 20:37:46 +00:00
|
|
|
|
2015-06-23 16:35:26 +00:00
|
|
|
// Tokens with no info.
|
|
|
|
comma,
|
|
|
|
equal,
|
2015-06-24 17:34:58 +00:00
|
|
|
underscore,
|
2015-07-13 23:24:34 +00:00
|
|
|
colon,
|
2015-08-03 23:08:19 +00:00
|
|
|
coloncolon,
|
2016-07-26 21:49:34 +00:00
|
|
|
dot,
|
2015-07-22 17:58:46 +00:00
|
|
|
exclaim,
|
2015-07-28 17:28:03 +00:00
|
|
|
lparen,
|
|
|
|
rparen,
|
2015-08-14 18:57:24 +00:00
|
|
|
lbrace,
|
|
|
|
rbrace,
|
2015-08-05 22:26:15 +00:00
|
|
|
plus,
|
|
|
|
minus,
|
2016-03-08 02:00:43 +00:00
|
|
|
less,
|
|
|
|
greater,
|
2015-06-23 16:35:26 +00:00
|
|
|
|
2015-07-06 23:07:26 +00:00
|
|
|
// Keywords
|
|
|
|
kw_implicit,
|
|
|
|
kw_implicit_define,
|
2015-08-19 18:55:47 +00:00
|
|
|
kw_def,
|
2015-07-07 20:34:53 +00:00
|
|
|
kw_dead,
|
[CodeGen] Split out the notions of MI invariance and MI dereferenceability.
Summary:
An IR load can be invariant, dereferenceable, neither, or both. But
currently, MI's notion of invariance is IR-invariant &&
IR-dereferenceable.
This patch splits up the notions of invariance and dereferenceability at
the MI level. It's NFC, so adds some probably-unnecessary
"is-dereferenceable" checks, which we can remove later if desired.
Reviewers: chandlerc, tstellarAMD
Subscribers: jholewinski, arsenm, nemanjai, llvm-commits
Differential Revision: https://reviews.llvm.org/D23371
llvm-svn: 281151
2016-09-11 01:38:58 +00:00
|
|
|
kw_dereferenceable,
|
2015-07-08 21:23:34 +00:00
|
|
|
kw_killed,
|
2015-07-08 23:58:31 +00:00
|
|
|
kw_undef,
|
2015-08-14 19:07:07 +00:00
|
|
|
kw_internal,
|
2015-08-05 17:49:03 +00:00
|
|
|
kw_early_clobber,
|
2015-08-05 17:41:17 +00:00
|
|
|
kw_debug_use,
|
2017-12-12 17:53:59 +00:00
|
|
|
kw_renamable,
|
2015-08-19 19:05:34 +00:00
|
|
|
kw_tied_def,
|
2015-07-17 00:24:15 +00:00
|
|
|
kw_frame_setup,
|
2018-01-09 11:33:22 +00:00
|
|
|
kw_frame_destroy,
|
2018-05-03 00:07:56 +00:00
|
|
|
kw_nnan,
|
|
|
|
kw_ninf,
|
|
|
|
kw_nsz,
|
|
|
|
kw_arcp,
|
|
|
|
kw_contract,
|
|
|
|
kw_afn,
|
|
|
|
kw_reassoc,
|
2015-07-22 21:15:11 +00:00
|
|
|
kw_debug_location,
|
2015-08-14 21:55:58 +00:00
|
|
|
kw_cfi_same_value,
|
2015-07-23 23:09:07 +00:00
|
|
|
kw_cfi_offset,
|
2017-12-15 15:17:18 +00:00
|
|
|
kw_cfi_rel_offset,
|
2015-07-27 20:39:03 +00:00
|
|
|
kw_cfi_def_cfa_register,
|
2015-07-21 22:28:27 +00:00
|
|
|
kw_cfi_def_cfa_offset,
|
2017-12-15 15:17:18 +00:00
|
|
|
kw_cfi_adjust_cfa_offset,
|
|
|
|
kw_cfi_escape,
|
2015-07-29 18:57:23 +00:00
|
|
|
kw_cfi_def_cfa,
|
2017-12-15 15:17:18 +00:00
|
|
|
kw_cfi_register,
|
|
|
|
kw_cfi_remember_state,
|
2017-11-02 12:00:58 +00:00
|
|
|
kw_cfi_restore,
|
2017-12-15 15:17:18 +00:00
|
|
|
kw_cfi_restore_state,
|
|
|
|
kw_cfi_undefined,
|
|
|
|
kw_cfi_window_save,
|
2015-07-28 17:28:03 +00:00
|
|
|
kw_blockaddress,
|
2016-07-29 20:32:59 +00:00
|
|
|
kw_intrinsic,
|
2015-07-28 23:02:45 +00:00
|
|
|
kw_target_index,
|
2015-07-31 20:49:21 +00:00
|
|
|
kw_half,
|
|
|
|
kw_float,
|
|
|
|
kw_double,
|
|
|
|
kw_x86_fp80,
|
|
|
|
kw_fp128,
|
|
|
|
kw_ppc_fp128,
|
2015-08-06 00:44:07 +00:00
|
|
|
kw_target_flags,
|
2015-08-04 00:24:45 +00:00
|
|
|
kw_volatile,
|
2015-08-06 16:49:30 +00:00
|
|
|
kw_non_temporal,
|
2015-08-06 16:55:53 +00:00
|
|
|
kw_invariant,
|
2015-08-07 20:48:30 +00:00
|
|
|
kw_align,
|
2018-01-26 11:47:28 +00:00
|
|
|
kw_addrspace,
|
2015-08-12 20:44:16 +00:00
|
|
|
kw_stack,
|
2015-08-12 21:00:22 +00:00
|
|
|
kw_got,
|
2015-08-12 21:11:08 +00:00
|
|
|
kw_jump_table,
|
2015-08-12 20:33:26 +00:00
|
|
|
kw_constant_pool,
|
2015-08-20 00:12:57 +00:00
|
|
|
kw_call_entry,
|
2015-08-10 23:24:42 +00:00
|
|
|
kw_liveout,
|
2015-08-13 23:10:16 +00:00
|
|
|
kw_address_taken,
|
|
|
|
kw_landing_pad,
|
|
|
|
kw_liveins,
|
|
|
|
kw_successors,
|
2016-08-17 20:25:25 +00:00
|
|
|
kw_floatpred,
|
|
|
|
kw_intpred,
|
2015-07-06 23:07:26 +00:00
|
|
|
|
2015-08-17 22:05:15 +00:00
|
|
|
// Named metadata keywords
|
|
|
|
md_tbaa,
|
2015-08-17 22:06:40 +00:00
|
|
|
md_alias_scope,
|
2015-08-17 22:08:02 +00:00
|
|
|
md_noalias,
|
2015-08-17 22:09:52 +00:00
|
|
|
md_range,
|
2017-08-23 20:31:27 +00:00
|
|
|
md_diexpr,
|
2015-08-17 22:05:15 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
// Identifier tokens
|
2015-06-23 16:35:26 +00:00
|
|
|
Identifier,
|
2015-06-23 23:42:28 +00:00
|
|
|
NamedRegister,
|
2018-03-30 18:15:54 +00:00
|
|
|
NamedVirtualRegister,
|
2015-08-13 23:10:16 +00:00
|
|
|
MachineBasicBlockLabel,
|
2015-06-26 16:46:11 +00:00
|
|
|
MachineBasicBlock,
|
2015-07-16 23:37:45 +00:00
|
|
|
StackObject,
|
|
|
|
FixedStackObject,
|
2015-06-26 22:56:48 +00:00
|
|
|
NamedGlobalValue,
|
|
|
|
GlobalValue,
|
2015-07-21 16:59:53 +00:00
|
|
|
ExternalSymbol,
|
2015-06-23 23:42:28 +00:00
|
|
|
|
|
|
|
// Other tokens
|
2015-07-10 22:51:20 +00:00
|
|
|
IntegerLiteral,
|
2015-07-31 20:49:21 +00:00
|
|
|
FloatingPointLiteral,
|
2016-10-12 21:06:45 +00:00
|
|
|
HexLiteral,
|
2015-07-15 23:38:35 +00:00
|
|
|
VirtualRegister,
|
2015-07-20 20:51:18 +00:00
|
|
|
ConstantPoolItem,
|
2015-07-27 22:42:41 +00:00
|
|
|
JumpTableIndex,
|
2015-07-28 17:28:03 +00:00
|
|
|
NamedIRBlock,
|
2015-07-27 22:42:41 +00:00
|
|
|
IRBlock,
|
2015-08-03 23:08:19 +00:00
|
|
|
NamedIRValue,
|
2015-08-21 21:54:12 +00:00
|
|
|
IRValue,
|
2016-03-28 18:18:46 +00:00
|
|
|
QuotedIRValue, // `<constant value>`
|
2017-07-11 22:23:00 +00:00
|
|
|
SubRegisterIndex,
|
|
|
|
StringConstant
|
2015-06-22 20:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2017-09-27 23:26:01 +00:00
|
|
|
TokenKind Kind = Error;
|
2015-06-22 20:37:46 +00:00
|
|
|
StringRef Range;
|
2015-08-06 23:17:42 +00:00
|
|
|
StringRef StringValue;
|
|
|
|
std::string StringValueStorage;
|
2015-06-23 23:42:28 +00:00
|
|
|
APSInt IntVal;
|
2015-06-22 20:37:46 +00:00
|
|
|
|
|
|
|
public:
|
2017-09-27 23:26:01 +00:00
|
|
|
MIToken() = default;
|
2015-08-05 17:35:55 +00:00
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
MIToken &reset(TokenKind Kind, StringRef Range);
|
2015-06-22 20:37:46 +00:00
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
MIToken &setStringValue(StringRef StrVal);
|
|
|
|
MIToken &setOwnedStringValue(std::string StrVal);
|
|
|
|
MIToken &setIntegerValue(APSInt IntVal);
|
2015-06-23 23:42:28 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
TokenKind kind() const { return Kind; }
|
|
|
|
|
|
|
|
bool isError() const { return Kind == Error; }
|
|
|
|
|
2015-08-13 23:10:16 +00:00
|
|
|
bool isNewlineOrEOF() const { return Kind == Newline || Kind == Eof; }
|
|
|
|
|
|
|
|
bool isErrorOrEOF() const { return Kind == Error || Kind == Eof; }
|
|
|
|
|
2015-06-24 17:34:58 +00:00
|
|
|
bool isRegister() const {
|
2015-07-10 22:51:20 +00:00
|
|
|
return Kind == NamedRegister || Kind == underscore ||
|
2018-03-30 18:15:54 +00:00
|
|
|
Kind == NamedVirtualRegister || Kind == VirtualRegister;
|
2015-06-24 17:34:58 +00:00
|
|
|
}
|
2015-06-23 16:35:26 +00:00
|
|
|
|
2015-07-06 23:07:26 +00:00
|
|
|
bool isRegisterFlag() const {
|
2015-07-08 21:23:34 +00:00
|
|
|
return Kind == kw_implicit || Kind == kw_implicit_define ||
|
2015-08-19 18:55:47 +00:00
|
|
|
Kind == kw_def || Kind == kw_dead || Kind == kw_killed ||
|
|
|
|
Kind == kw_undef || Kind == kw_internal ||
|
2017-12-12 17:53:59 +00:00
|
|
|
Kind == kw_early_clobber || Kind == kw_debug_use ||
|
|
|
|
Kind == kw_renamable;
|
2015-07-06 23:07:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 16:49:30 +00:00
|
|
|
bool isMemoryOperandFlag() const {
|
2015-08-06 16:55:53 +00:00
|
|
|
return Kind == kw_volatile || Kind == kw_non_temporal ||
|
2017-07-13 02:28:54 +00:00
|
|
|
Kind == kw_dereferenceable || Kind == kw_invariant ||
|
|
|
|
Kind == StringConstant;
|
2015-08-06 16:49:30 +00:00
|
|
|
}
|
2015-08-04 00:24:45 +00:00
|
|
|
|
2015-06-22 20:37:46 +00:00
|
|
|
bool is(TokenKind K) const { return Kind == K; }
|
|
|
|
|
|
|
|
bool isNot(TokenKind K) const { return Kind != K; }
|
|
|
|
|
|
|
|
StringRef::iterator location() const { return Range.begin(); }
|
|
|
|
|
2015-08-06 23:17:42 +00:00
|
|
|
StringRef range() const { return Range; }
|
2015-07-20 20:31:01 +00:00
|
|
|
|
2015-08-05 17:35:55 +00:00
|
|
|
/// Return the token's string value.
|
2015-08-06 23:17:42 +00:00
|
|
|
StringRef stringValue() const { return StringValue; }
|
2015-07-20 20:31:01 +00:00
|
|
|
|
2015-06-23 23:42:28 +00:00
|
|
|
const APSInt &integerValue() const { return IntVal; }
|
2015-06-26 16:46:11 +00:00
|
|
|
|
|
|
|
bool hasIntegerValue() const {
|
2015-06-26 22:56:48 +00:00
|
|
|
return Kind == IntegerLiteral || Kind == MachineBasicBlock ||
|
2015-08-13 23:10:16 +00:00
|
|
|
Kind == MachineBasicBlockLabel || Kind == StackObject ||
|
|
|
|
Kind == FixedStackObject || Kind == GlobalValue ||
|
|
|
|
Kind == VirtualRegister || Kind == ConstantPoolItem ||
|
2015-08-19 23:31:05 +00:00
|
|
|
Kind == JumpTableIndex || Kind == IRBlock || Kind == IRValue;
|
2015-06-26 16:46:11 +00:00
|
|
|
}
|
2015-06-22 20:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Consume a single machine instruction token in the given source and return
|
|
|
|
/// the remaining source string.
|
|
|
|
StringRef lexMIToken(
|
|
|
|
StringRef Source, MIToken &Token,
|
|
|
|
function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback);
|
|
|
|
|
|
|
|
} // end namespace llvm
|
|
|
|
|
2017-09-27 23:26:01 +00:00
|
|
|
#endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H
|