Skip to content

PP extension #3

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

Draft
wants to merge 196 commits into
base: kpdev42/llvmorg-15.0.4-release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
b44da82
Add test case and initial parsing
kpdev Apr 24, 2021
e435a87
Add initial pp_fields insertion
kpdev May 9, 2021
13d6f48
Add pointer to specialization
kpdev Aug 14, 2021
fc75737
[PP-EXT] Adopt for LLVM v15.0.4
kpdev Jan 31, 2023
08b6727
[PP-EXT] Change approach to specialization implementation
kpdev Feb 14, 2023
1a92e31
[PP-EXT] Add ast dump to a test file
kpdev Feb 21, 2023
4529c96
[PP-EXT] Add gen struct to variants. And replace [] to <>
kpdev Feb 28, 2023
424d5bb
[PP-EXT] Add specialization struct to variant
kpdev Feb 28, 2023
d8e7ddf
[PP-EXT] Add parsing of specialized object
kpdev Mar 14, 2023
ae08106
[PP-EXT] Add functions to a test file
kpdev Mar 16, 2023
7950be7
[PP-EXT] Add support for generalization fields access
kpdev Mar 17, 2023
8b6443b
[PP-EXT] Add support for variant's fields access
kpdev Mar 27, 2023
e899b51
[PP-EXT] Add support for variant access by value (with <>)
kpdev Apr 4, 2023
9eb1adf
[PP-EXT] Add support for extended variant creation
kpdev Apr 5, 2023
d466206
[PP-EXT] Add support for nested fields access (<a><b>)
kpdev Apr 11, 2023
ab65c50
[PP-EXT] Add runtime test
kpdev Apr 11, 2023
b4d85d1
[PP-EXT] Add tests for ctors
kpdev Apr 26, 2023
2d5dd47
[PP-EXT] Add ctors to init array
kpdev May 9, 2023
f006ad6
[PP-EXT] Init generalizations tags
kpdev May 16, 2023
08102b3
[PP-EXT] Add objects initialization
kpdev Jun 5, 2023
7cf55d4
[PP-EXT][Refactoring] Replace lambdas with methods
kpdev Jun 11, 2023
4619916
[PP-EXT] Add support for generalization extension
kpdev Jun 12, 2023
f1feb67
[PP-EXT] Use semi as a delimiter instead of comma
kpdev Jun 13, 2023
88a7f89
[PP-EXT] Add test case for multi-files build
kpdev Jun 13, 2023
a1d5f8a
[PP-EXT] Add support for multi module implementation
kpdev Jun 18, 2023
20f8ce0
[PP-EXT] Add support for empty generalization
kpdev Jun 18, 2023
2254c1c
[PP-EXT] Use keyword 'struct' in veriables definitions
kpdev Jun 18, 2023
531e4ad
[PP-EXT] Add checking tags to multi-modules test case
kpdev Jun 18, 2023
2aa496c
[PP-EXT] Add support for multi-modules tags generation
kpdev Jul 9, 2023
1ed6fee
[PP-EXT] Add check to tag initializers
kpdev Jul 14, 2023
b0673c4
[PP-EXT] Add support for define and call multimethods
kpdev Jul 25, 2023
1fb050b
[PP-EXT] Refactoring multimethods args parsing
kpdev Aug 13, 2023
d0e2925
[PP-EXT] Mangle multimethods names
kpdev Aug 25, 2023
e7366ad
[PP_EXT] Cleanup test
kpdev Aug 25, 2023
020e5aa
[PP-EXT] Implement typedef support
kpdev Sep 17, 2023
336d144
[PP-EXT] Replace default parameters and return type with ones from MMs
kpdev Sep 18, 2023
3b0385a
[PP-EXT] Generate pointer for an array of MM handlers
kpdev Sep 20, 2023
97c4588
[PP_EXT] Add runtime check for type tag value
kpdev Nov 25, 2023
778435b
[PP-EXT] Introduce LLVM IR level PP-extension handler
kpdev Dec 17, 2023
7dc27a2
[PP-EXT] Add default handlers for multimethods
kpdev Dec 19, 2023
0912840
[PP-EXT] Add allocation for 1D multimethods
kpdev Jan 3, 2024
704e902
[PP-EXT] Add support for allocation N-dimention arrays of multimethod…
kpdev Jan 3, 2024
a5ef7df
[PP-EXT] Fix builtin type support
kpdev Jan 4, 2024
e4f790a
[PP-EXT] Add default init for allocated handlers array
kpdev Jan 4, 2024
3255ed5
[PP-EXT] Add body for dispatch function
kpdev Jan 12, 2024
af5e5ef
[PP-EXT] Add generation of debug output to stdout
kpdev Jan 14, 2024
3476f11
[PP-EXT] Add debug logs. Fix default handler invokation
kpdev Jan 16, 2024
10108be
[PP-EXT] Move HandlePPExtensionMethods to the proper place
kpdev Jan 17, 2024
b426120
[PP-EXT] Support basic monomethods
kpdev Jan 19, 2024
4b2c1b9
[PP-EXT] Fix main test
kpdev Jan 21, 2024
c6de611
[PP-EXT] Add support for multisource monomethod specialization
kpdev Jan 25, 2024
73c78cb
[PP-EXT] Replace <...> with @
kpdev Jan 27, 2024
52cb721
[PP-EXT] Add cmake-based projects to examples
kpdev Jan 27, 2024
52f83d9
[PP-EXT] Add period before @ character
kpdev Jan 27, 2024
b192cb7
[PP-EXT] Add support for additional param in monomethods
kpdev Feb 2, 2024
c0e91dc
[PP-EXT] Implement access to the tail part
kpdev Feb 3, 2024
fc5288b
[PP-EXT] Fix '<' symbol handling
kpdev Feb 3, 2024
cd5800b
[PP-EXT] Update test
kpdev Feb 3, 2024
f8dcc13
[PP-EXT] Fix 00-ppp-type-c demo example
kpdev Feb 5, 2024
183407d
[PP-EXT] Enhance getting whole variant from generalization
kpdev Feb 6, 2024
0127918
[PP-EXT] Handle cast case
kpdev Feb 8, 2024
97537be
[PP-EXT] Change pthread test to make it buildable
kpdev Feb 8, 2024
0a94174
[PP-EXT] Fix pthread test case
kpdev Feb 8, 2024
bbd1f04
[PP-EXT] Use empty initializeded generalizaton in pthread test
kpdev Feb 8, 2024
ad6d1e0
[PP-EXT] Tmp fix for names lookup
kpdev Feb 10, 2024
122f0e3
[PP-EXT] Adapt test for new syntax
kpdev Feb 10, 2024
b744f76
[PP-EXT] Add new version of 00-ppp-type-c test
kpdev Feb 10, 2024
a35f20b
[PP-EXT] Adapt test for using compiler-generated create_spec
kpdev Feb 17, 2024
78975ba
[PP-EXT] Add evolution example (initial state)
kpdev Feb 17, 2024
9ed0914
[PP-EXT] Add create_spec implementation
kpdev Feb 20, 2024
d639be3
[PP-EXT][Test] Remove build files
kpdev Feb 20, 2024
6c5f2e2
[PP-EXT][Test] Make evolution/00-start work
kpdev Feb 21, 2024
fd8acf3
[PP-EXT][Test] Make evolution/01-new-spec work
kpdev Feb 21, 2024
2f1c03d
[PP-EXT] Fix return types and values in generated mm handlers
kpdev Feb 21, 2024
006cd0e
[PP-EXT][Test] Make evolution/0-new-func work
kpdev Feb 21, 2024
3359a2b
[PP-EXT] Add support for typedefs in generalization extension
kpdev Feb 23, 2024
59aea06
[PP-EXT][Test] Add initial version of 03-new-field
kpdev Feb 24, 2024
f31f3ff
[PP-EXT] Add support for typedefs in multimethods
kpdev Feb 26, 2024
a7ace2d
[PP-EXT][Test] Add evolution/04-rectangles-only-out test
kpdev Feb 28, 2024
686cf31
[PP-EXT][Test] Make 03-ppp-type-dyn-decorator-c build and run
kpdev Mar 1, 2024
af6c8b9
[PP-EXT] Add chained decorator support
kpdev Mar 17, 2024
628fbb8
[PP-EXT] Add support for chained access for variant fields
kpdev Mar 23, 2024
86d117a
[PP-EXT][Test] Add script to run all existing pp-ext tests
kpdev Mar 23, 2024
2b6bc03
[PP-EXT][Test] Set proper CMAKE_C_COMPILER in check_all script
kpdev Mar 23, 2024
91bb995
[PP-EXT][Refactoring] Extract functional for creating new decorated type
kpdev Mar 24, 2024
df45f23
[PP-EXT] Support create_spec for decorated types
kpdev Mar 24, 2024
ca3217a
[PP-EXT][Test] Add 03-ppp-type-gen-decorator-c test
kpdev Mar 24, 2024
82cd4fe
[PP-EXT] Set type tags in create_spec for decorated types
kpdev Apr 6, 2024
ab390ff
[PP-EXT][Test] Support 03-new-field/ppp/03-ppp-type-gen-decorator-c
kpdev Apr 6, 2024
383919b
[PP-EXT][Test] Fix 03-ppp-type-gen-decorator-c/CMakeLists.txt
kpdev Apr 6, 2024
8a4a9a8
[PP-EXT][Test] Add 05-multimethod test
kpdev Apr 6, 2024
005bf87
[PP-EXT][Test] Add 06-multimethod-new-spec test
kpdev Apr 6, 2024
15627eb
[PP-EXT] Fix fields access through head and tail
kpdev Apr 6, 2024
0d6c5c2
[PP-EXT][Test] Fix 03-ppp-type-gen-decorator-c test
kpdev Apr 6, 2024
d0189c7
[PP-EXT][Test] Fix MMRecorder and add 04-ppp-type-rect-only-out-c to …
kpdev Apr 6, 2024
562ae1a
[PP-EXT][Refactoring] Prepare TryParsePPExt for tags introduction
kpdev Apr 13, 2024
515158e
[PP-EXT] Add basic support for tagged structs
kpdev Apr 13, 2024
9ea91a8
[PP-EXT][Test] Add test for tagged monomethod
kpdev Apr 13, 2024
e842ced
[PP-EXT][Test] Add more complex test for tagged struct & monomethods
kpdev Apr 13, 2024
02347e1
[PP-EXT] Add void type support, and comma-divided specializations
kpdev Apr 13, 2024
77caa7a
[PP-EXT][Test] Add 00-start/ppp/00-ppp-tag-c
kpdev Apr 21, 2024
94e98b3
[PP-EXT] Add support for extending tagged generalizations
kpdev Apr 21, 2024
d91202e
[PP-EXT][Test] Add 00-start/ppp/00-ppp-tag-c/ to check_all.py
kpdev Apr 21, 2024
714ddd4
[PP-EXT][Test] Add initial version 01-new-spec/ppp/01-ppp-tag-c
kpdev Apr 21, 2024
99ddca9
[PP-EXT][Test] Add 01-new-spec/ppp/01-ppp-tag-c to check_all.py
kpdev Apr 21, 2024
3be2c6d
[PP-EXT][Test] Add initial version of 02-new-func/ppp/02-ppp-tag-c
kpdev Apr 21, 2024
1c33b8c
[PP-EXT] Add 02-new-func/ppp/02-ppp-tag-c to check_all.py
kpdev Apr 21, 2024
50c4502
[PP-EXT][Test] Add initial version of 03-new-field/ppp/03-ppp-tag-dyn…
kpdev Apr 21, 2024
a6f773c
[PP-EXT][Test] Add 03-new-field/ppp/03-ppp-tag-dyn-decorator-c to che…
kpdev Apr 21, 2024
ba60f3b
[PP-EXT][Test] Add initial version of 03-new-field/ppp/03-ppp-tag-gen…
kpdev Apr 21, 2024
1b1c867
[PP-EXT][Test] Add init version of 04-ppp-tag-rect-only-out-c
kpdev Apr 21, 2024
f8b8109
[PP-EXT][Test] Add 04-ppp-tag-rect-only-out-c to check_all.py
kpdev Apr 21, 2024
cee88f1
[PP-EXT][Test] Add 04-ppp-type-is-rect-only-out-c to check_all.py
kpdev Apr 21, 2024
d60d73a
[PP-EXT][Test] Add init version of 04-ppp-tag-is-rect-only-out-c test
kpdev Apr 21, 2024
07c7b00
[PP-EXT][Test] Add 04-ppp-tag-is-rect-only-out-c to check_all.py
kpdev Apr 21, 2024
b9ff6aa
[PP-EXT][Test][Refactoring] Remove unused legacy cmake projects
kpdev Apr 28, 2024
6f65f22
[PP-EXT][Test] Add init version of patterns/abstract-factory
kpdev Apr 28, 2024
87e6089
[PP-EXT][Test] Add init version of patterns/factory-method
kpdev Apr 28, 2024
6471d74
[PP-EXT][Test] Add initial version of patterns/builder
kpdev Apr 28, 2024
7ae3558
[PP-EXT][Test] Clean build and bin dirs after tests
kpdev Apr 28, 2024
09fc569
[PP-EXT] Support create_spec for tagged generalization
kpdev Apr 28, 2024
a3f0f95
[PP-EXT] Init type tags in create_spec for tagged generalizations
kpdev Apr 30, 2024
084605d
[PP-EXT][Test] Add 03-ppp-tag-gen-decorator-c to check_all.py
kpdev May 1, 2024
775a212
[PP-EXT] Add support for 2D MM
kpdev May 1, 2024
343245d
[PP-EXT][Test] Add 05-multimethod/ppp/05-ppp-type-c to check_all.py
kpdev May 1, 2024
aebea03
[PP-EXT][Test] Add 06-multimethod-new-spec/ppp/06-ppp-type-c to check…
kpdev May 4, 2024
4d0c6ce
[PP-EXT][Test] Add pp-mm-tag.c to check_all.py
kpdev May 4, 2024
8d006a8
[PP-EXT][Test] Add 05-multimethod/ppp/05-ppp-tag-c to check_all.py
kpdev May 5, 2024
572f688
[PP-EXT][Test] Add 06-multimethod-new-spec/ppp/06-ppp-tag-c to check_…
kpdev May 5, 2024
03cfdcb
[PP-Ext][Patterns] Add init version of factory-method-p2c
kpdev May 11, 2024
d54d35f
[PP-Ext][Patterns] Add factory-method-p2c to check_all.py
kpdev May 11, 2024
5f751a7
[PP-EXT][Test] Add PPEXT_DUMP define
kpdev May 26, 2024
8d83335
[PP-EXT][Test] Add initial version of Examples/PPP/misc projects
kpdev May 29, 2024
b412603
[PP-EXT][Test] Add misc/container-tag project to check_all.py
kpdev May 29, 2024
9b8dad6
[PP-EXT] Change syntax of create_spec
kpdev Jun 5, 2024
d3682e6
[PP-EXT] Add pp-related info to the readme
kpdev Jun 9, 2024
64de61f
[PP-EXT] Add support for pointer specialization
kpdev Jun 23, 2024
ac7ccd1
[PP-EXT] Fix pp-tagged-create_spec.c, and remove cmake tests from che…
kpdev Jun 23, 2024
ee5b1e2
[PP-EXT] Add initializer for global vars tags
kpdev Jun 25, 2024
5de46da
[PP-EXT] Add support for pointer types in tagged specializations
kpdev Jun 26, 2024
9f8f2ed
[PP-EXT] Add an attribute "weak" to create_spec
kpdev Jun 27, 2024
0b0352a
[PP-EXT] Add support for int as a spec type
kpdev Jul 9, 2024
236f324
[PP-EXT] Allow tagged generalization extension with basic types
kpdev Jul 9, 2024
b757bf5
[PP-EXT][Test] Extend pp-spec* tests
kpdev Jul 14, 2024
49383de
[PP-EXT] Allow to use ptr to specialization in ordinary functions
kpdev Jul 16, 2024
d6dada3
[PP-EXT] Allow tagged generalization extension with void
kpdev Jul 18, 2024
cde87fe
[PP-EXT] Allow (tagged) generalization extension with ptrs
kpdev Jul 20, 2024
b193be1
[PP-EXT] Add support for =0 as default MM body
kpdev Jul 20, 2024
fa0a93a
[PP-EXT] Replace trians with dots for object difinitions
kpdev Jul 24, 2024
757797e
[PP-EXT] Replace trians with dots in create_spec. Update all tests
kpdev Jul 25, 2024
1e39bec
[PP-EXT] Support int in gen extensions T + <int;>;
kpdev Jul 27, 2024
f3f68a4
[PP-EXT] Support using specialization in cast expression
kpdev Aug 3, 2024
a84ee61
[PP-EXT] Refactor PPExtGetIdForExistingOrNewlyCreatedGen
kpdev Aug 6, 2024
6754ba3
[PP-EXT] Add init_spec implementation
kpdev Aug 21, 2024
27ee454
[PP-EXT] Align generalization for 8 bytes
kpdev Aug 26, 2024
99be4e8
[PP-EXT] Fix passing specialization as a argument to a function
kpdev Aug 31, 2024
343ff4f
[PP-EXT] Add basic types support (char, double, float)
kpdev Sep 6, 2024
34920f8
[PP-EXT] Introduce get_spec_size
kpdev Oct 31, 2024
9362b00
[PP-EXT] Generate create_spec declaration for each specialization
kpdev Nov 9, 2024
18a3c1b
[PP-EXT] Generate body for default declaration of create_spec
kpdev Nov 10, 2024
94e15d8
[PP-EXT] Add initializer for array of create_spec
kpdev Nov 10, 2024
0653f92
[PP-EXT] Implement recording of create_spec to global array
kpdev Nov 10, 2024
550dcf0
[PP-EXT] Implement get_spec_size
kpdev Nov 16, 2024
4a1f6ae
[PP-EXT] Add support for generalization in get_spec_ptr
kpdev Nov 20, 2024
23f64a6
[PP-EXT] get_spec_size returns tags+1 value
kpdev Nov 21, 2024
c9c8253
[PP-EXT] Change logic in MM to handle 0 index in generalizations
kpdev Nov 23, 2024
7ff1da9
[PP-EXT] Introduce spec_index_cmp
kpdev Nov 27, 2024
6dfc782
[PP-EXT] Support struct fields in generalization
kpdev Nov 28, 2024
c9bbce1
[PP-EXT] Support usage of spec_index_cmp in conditions
kpdev Nov 30, 2024
31d426a
[PP-EXT] Add tag init for empty generalization on stack
kpdev Nov 30, 2024
23991bc
[PP-EXT][Test] Cleanup tests directory and script
kpdev Dec 1, 2024
9264971
[PP-EXT] Add support for init direct fields in generalizations
kpdev Dec 6, 2024
7e438e5
[PP-EXT][Test] Rename Figure.c to pp-base.c
kpdev Dec 7, 2024
ce3b5f6
[PP-EXT][Refactoring] Outline utils function from Parser to CGFunctio…
kpdev Dec 7, 2024
0e5da9e
Revert "[PP-EXT][Refactoring] Outline utils function from Parser to C…
kpdev Dec 7, 2024
7cca918
[PP-EXT] Init global empty generalization
kpdev Dec 9, 2024
b9e1b1d
[PP-EXT] Support direct field init for local and global variables
kpdev Dec 9, 2024
85c3e43
[PP-EXT] Fix empty generalization init
kpdev Dec 10, 2024
b0ab8e9
[PP-EXT] Support direct field init for create_spec
kpdev Dec 12, 2024
3e6cdce
[PP-EXT] Replace ArrayRef with c-style arrays where possible
kpdev Dec 13, 2024
169e72a
[PP-EXT] Add support for specializations in MM args
kpdev Dec 17, 2024
88e5050
[PP-EXT][Test] Add test for 3d MMs
kpdev Jan 4, 2025
4176f8a
[PP-EXT] Always emit bodies for MMs, even for static
kpdev Jan 5, 2025
99bc5a1
[PP-EXT] Fix support for double and char types in non-tagged speciali…
kpdev Jan 8, 2025
2506f9e
[PP-EXT] Support void* as a specialization
kpdev Jan 9, 2025
e43d2e5
[PP-EXT] Handle global var with anonymous types
kpdev Feb 9, 2025
dd25a7c
[PP-EXT][Refactoring] Unify init for create_spec and globals
kpdev Feb 17, 2025
e28671b
[PP-EXT] Fix init for stack variables
kpdev Feb 17, 2025
e4d745c
[PP-EXT][Refactoring] Unify index calculation for MM
kpdev Feb 21, 2025
fcb7196
[PP-EXT][Refactoring] Simplify getRecordDeclsGenArgsForPPMM
kpdev Feb 21, 2025
d171daf
[PP-EXT] Fix multimethods init
kpdev Feb 21, 2025
b7a43c3
[PP-EXT] Add support for unlimited number of MM params
kpdev Feb 21, 2025
94d6e6c
[PP-EXT] Add support for Gen.void params in multimethods
kpdev Mar 1, 2025
3eaf27f
[PP-EXT] Small refactoring for create_spec registration
kpdev Mar 8, 2025
8a7eaf2
[PP-EXT] Fix spec_index_cmp pointer parameter handling
kpdev Mar 12, 2025
f2eb54e
[PP-EXT] Handle case when @ is used as an arg for multimethod
kpdev May 22, 2025
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,19 @@ Join [LLVM Discourse forums](https://discourse.llvm.org/), [discord chat](https:

The LLVM project has adopted a [code of conduct](https://llvm.org/docs/CodeOfConduct.html) for
participants to all modes of communication within the project.

## Build Procedural-Parametric Extension

It is not differs from mainstream llvm build.
But you can use the recommended command line for debug build
```
cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DBUILD_SHARED_LIBS:STRING=ON "-DLLVM_TARGETS_TO_BUILD:STRING=X86" -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE "-DLLVM_ENABLE_PROJECTS:STRING=clang" -DLLVM_OPTIMIZED_TABLEGEN:STRING=ON -DLLVM_CCACHE_BUILD:STRING=ON -DCMAKE_C_COMPILER:FILEPATH=<path-to-c-compiler> -DCMAKE_CXX_COMPILER:FILEPATH=<path-to-cpp-compiler> -S<source-path> -B<build-path> -G Ninja
```
After that it is needed to build clang:
```
cmake --build <build-path> --config Debug --target all --
```
And check if it is actually works:
```
<build-path>/bin/llvm-lit <source-path>/clang/test/CodeGen/pp-linked.c
```
25 changes: 25 additions & 0 deletions clang/include/clang/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,11 @@ class ParmVarDecl : public VarDecl {
static bool classof(const Decl *D) { return classofKind(D->getKind()); }
static bool classofKind(Kind K) { return K == ParmVar; }

/// Setter and checker for ident type
/// used in multimethods (pp-extension)
bool PPExtIsGenAsSpecIdType() const { return identType == PPExtIdentType::GenAsSpecForMM; }
void PPExtSetIdentType(PPExtIdentType t) { identType = t; }

private:
enum { ParameterIndexSentinel = (1 << NumParameterIndexBits) - 1 };

Expand All @@ -1849,6 +1854,8 @@ class ParmVarDecl : public VarDecl {

void setParameterIndexLarge(unsigned parameterIndex);
unsigned getParameterIndexLarge() const;

PPExtIdentType identType = PPExtIdentType::Default;
};

enum class MultiVersionKind {
Expand Down Expand Up @@ -2546,6 +2553,24 @@ class FunctionDecl : public DeclaratorDecl,
setParams(getASTContext(), NewParamInfo);
}

struct PPMMParam {
RecordDecl* RD;
ParmVarDecl* PVD;
int IdxOfTypeTag; // of __pp_specialization_type
int ParamIdx; //- index of this parameter
RecordDecl* BaseRD; // base of generalization
};

struct MMParams
{
std::vector<PPMMParam> ParamsList;
bool IsSpecialization = false;
};

MMParams getRecordDeclsGenArgsForPPMM() const;

static int getNumOfSpecializationsPPMM(StringRef Name);

/// Returns the minimum number of arguments needed to call this function. This
/// may be fewer than the number of function parameters, if some of the
/// parameters have default arguments (in C++).
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Basic/IdentifierTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ class IdentifierInfoLookup {
/// piece of the code, as each occurrence of every identifier goes through
/// here when lexed.
class IdentifierTable {
public:
// Shark shows that using MallocAllocator is *much* slower than using this
// BumpPtrAllocator!
using HashTableTy = llvm::StringMap<IdentifierInfo *, llvm::BumpPtrAllocator>;
Expand Down
16 changes: 16 additions & 0 deletions clang/include/clang/Basic/Specifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,22 @@ namespace clang {
}
llvm_unreachable("Unknown AccessSpecifier");
}

// PP-EXT
// Enum describes ppstruct identifier type
enum class PPExtIdentType
{
// Default ident type - generalization
// or any specialization
// (including recursive ones)
Default,
// Special ident type - generalization with ".void" postfix
// It is used in multimethod specializations
// to show that this method should be specialized
// for generalization (instead of one of specializations)
GenAsSpecForMM
};

} // end namespace clang

#endif // LLVM_CLANG_BASIC_SPECIFIERS_H
161 changes: 161 additions & 0 deletions clang/include/clang/Parse/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,70 @@ class Parser : public CodeCompletionHandler {
/// Current kind of OpenMP clause
OpenMPClauseKind OMPClauseKind = llvm::omp::OMPC_unknown;

/// Part of PP-EXT
/// When true, we are in parsing base types of pp multimethod invocation
/// (between '<' and '>')
/// MultiMethod<...here...>();
bool IsInPPMM = false;

/// PP-EXT
using NameAndPtr = std::pair<StringRef, bool>;

std::string PPExtConstructGenName(
StringRef BaseName,
NameAndPtr SpecName,
bool AddPrefix = true
);

std::string PPExtConstructGenName(
std::vector<NameAndPtr> Names,
ParsedAttributes& PAttrs
);

RecordDecl* PPExtCreateGeneralization(
StringRef Name,
RecordDecl* Head,
RecordDecl* Tail,
SourceLocation Loc,
ParsedAttributes& PAttrs);

RecordDecl* PPExtGetTypeByName(StringRef Name);

using PPIdDescription = std::pair<PPExtIdentType, IdentifierInfo*>;
PPIdDescription PPExtGetIdForExistingOrNewlyCreatedGen(
StringRef BaseName,
ParsedAttributes& PAttrs,
bool NeedToAddLParen = true,
bool SaveLastIdent = false
);

enum class PPStructType {
Default,
Generalization,
Specialization
};

PPStructType PPExtGetStructType(const RecordDecl* RD) const;

struct PPStructInitDesc {
NamedDecl* VD;
const RecordDecl* RD;
const PPStructType Type;
};

std::vector<PPStructInitDesc> PPExtGetRDListToInit(const RecordDecl* RD) const;

std::string PPExtConstructTagName(StringRef GenName);

struct PPMemberInitData {
Expr* Assign;
Expr* MemberAccess;
};

PPMemberInitData PPExtInitPPStruct(PPStructInitDesc IDesc, Expr* MemberAccess);

static DeclSpec::TST PPExtGetFieldTypeByTokKind(tok::TokenKind TK);

/// RAII class that manages the template parameter depth.
class TemplateParameterDepthRAII {
unsigned &Depth;
Expand Down Expand Up @@ -483,6 +547,16 @@ class Parser : public CodeCompletionHandler {
return ParseTopLevelDecl(Result, IS);
}

std::vector<clang::Parser::DeclGroupPtrTy> m_PPTypedefs;
std::vector<clang::Parser::DeclGroupPtrTy> m_PPCtors;
std::vector<clang::Parser::DeclGroupPtrTy> m_PPGlobalVars;
// PP-EXT TODO: Combine these two fields
bool IsInPPMultimethod = false;
StringRef PPMultimethodNameStr;
Declarator* PPMMDecl;
int NumberOfPPSpecilizations = 0;
void FinalizePPArgsParsing();

/// ConsumeToken - Consume the current 'peek token' and lex the next one.
/// This does not work with special tokens: string literals, code completion,
/// annotation tokens and balanced tokens must be handled using the specific
Expand Down Expand Up @@ -2172,6 +2246,93 @@ class Parser : public CodeCompletionHandler {
StmtResult ParseSEHFinallyBlock(SourceLocation Loc);
StmtResult ParseSEHLeaveStatement();

//===--------------------------------------------------------------------===//
// Procedural-parametric extension

struct SpecsDescr {
std::string VariantName;
IdentifierInfo* FullNameIInfo = nullptr;
bool IsPtr = false;
};
using SpecsVec = SmallVector<SpecsDescr>;
Optional<SpecsVec> TryParsePPExt(Decl *TagDecl,
SmallVector<Decl *, 32>& FieldDecls);

void PPExtAddAlign8Attr(ParsedAttributes &Attrs);

void FieldGenerator(const char* FieldName,
DeclSpec::TST FieldType,
Decl *TagDecl,
RecordDecl* RD,
SmallVector<Decl *, 32>& FieldDecls,
const ParsedAttributes& Attrs,
bool IsPointer);
enum class PPFuncMode {
Ctor,
Init,
Increment,
CreateSpec,
MMDefault
};

struct PPMangledNames {
struct PPVariant {
std::string VariantName;
std::string VariantInitFuncName;
std::string VariantTagVariableName;
std::string VariantCreateSpecFuncName;
};

std::string BaseStructName;
std::string BaseTagVariableName;
std::string BaseCtorName;
std::string BaseIncFuncName;
std::vector<PPVariant> VariantStructNames;

void setBaseName(std::string BaseName);

void addVariantName(std::string VariantName);

std::string MMName;
std::string MMArrayName;

void setMMName(std::string Name);

LLVM_ATTRIBUTE_NOINLINE
void dump();
};

static void dumpPPNames(PPMangledNames& p);

void AddStmts(StmtVector& Stmts,
PPFuncMode Mode,
std::string StrVarName,
PPMangledNames& ppMNames);

void AddFunc(std::string FuncName,
PPFuncMode Mode,
std::string TagNameToInit,
PPMangledNames& ppMNames,
DeclSpec::TST ReturnType = DeclSpec::TST_void,
SmallVector<DeclaratorChunk::ParamInfo, 16> *ParamInfo = nullptr);

void FieldGenerator(const char* FieldName,
DeclSpec::TST FieldType,
RecordDecl* RD,
bool IsPointer,
const ParsedAttributes& TestAttrs,
Decl *TestDecl,
SmallVector<Decl *, 32>& FieldDecls);

Sema::DeclGroupPtrTy VarGenerate(std::string TypeVarName,
bool IsPointer = false,
std::string TypeNameStr = "");
Sema::DeclGroupPtrTy TypedefGenerate(std::string TypeVarName,
DeclSpec::TST ReturnTypeSpecifier,
SmallVector<DeclaratorChunk::ParamInfo, 16>& ParamInfo);

bool PPExtNextTokIsLParen = false;

//===--------------------------------------------------------------------===//
// Objective-C Statements

Expand Down
7 changes: 7 additions & 0 deletions clang/include/clang/Sema/DeclSpec.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ class DeclSpec {

ObjCDeclSpec *ObjCQualifiers;

PPExtIdentType identType = PPExtIdentType::Default;

static bool isTypeRep(TST T) {
return (T == TST_typename || T == TST_typeofType ||
T == TST_underlyingType || T == TST_atomic);
Expand Down Expand Up @@ -816,6 +818,11 @@ class DeclSpec {
///
/// Only tag declspecs can stand alone.
bool isMissingDeclaratorOk();

/// Setter and getter for ident type
/// used in multimethods (pp-extension)
PPExtIdentType PPExtGetIdentType() const { return identType; }
void PPExtSetIdentType(PPExtIdentType t) { identType = t; }
};

/// Captures information about "declaration specifiers" specific to
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Sema/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ class Scope {
/// scope.
Scope *AnyParent;

public:
/// Flags - This contains a set of ScopeFlags, which indicates how the scope
/// interrelates with other control flow statements.
unsigned Flags;

private:
/// Depth - This is the depth of this scope. The translation-unit scope has
/// depth 0.
unsigned short Depth;
Expand All @@ -161,10 +163,12 @@ class Scope {

unsigned short MSCurManglingNumber;

public:
/// PrototypeDepth - This is the number of function prototype scopes
/// enclosing this scope, including this scope.
unsigned short PrototypeDepth;

private:
/// PrototypeIndex - This is the number of parameters currently
/// declared in this scope.
unsigned short PrototypeIndex;
Expand Down
7 changes: 7 additions & 0 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11588,6 +11588,13 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
return true;

if (const auto *FD = dyn_cast<FunctionDecl>(D)) {

if (FD->getName().startswith("__pp_mm_")) {
// PP-EXT: Always emit bodies for multimethods
// even if they are marked as `static`
return true;
}

// Forward declarations aren't required.
if (!FD->doesThisDeclarationHaveABody())
return FD->doesDeclarationForceExternallyVisibleDefinition();
Expand Down
Loading