pass command line parameters into clang pass plugin - clang

I write a custom pass and register it into optimization pipeline by clang -fpass-plugin. But I can't pass command line parameter into my pass(I define some parameter by cl::opt, cl::list).
Possible methods I have tried include -mllvm myArg, -Xclang myArg, -fplugin-arg-MyPlugin-myArg. But they seem don't work.
So there is any method to pass command line parameter into my pass(Actually, it seems to me that clang will not call cl::parsecommandline After loading my pass)?

Related

Can we insert custom Intrinsic at the start of function via LLVM Function Pass?

I have added a new Intrinsic to RISCV Backend. Now I am planning to implement a Pass to insert the custom Intrinsic at the start of every function, as the first instruction, in-accordance with a command line argument which specifies the list of functions to be omitted. Is it possible to implement this as a normal FunctionPass called via opt tool? Or, should I call use the MachineFunctionPass?
Also, if I have to use the MachineFunctionPass, is it possible to automatically enable that pass from Clang command line, similar to how the normal opt based Target-Independent passes are enabled via -Xclang -load ?
Please guide me in this.
Thank you so much.

Clang libtooling: how to print compiler macro definitions

I have a LibTooling based utility and I would like to output a list of macro definitions for debug purposes. One can print compiler macro definitions with clang/gcc -dM -E -, but it does not seem to work if I pass -dM -E or -dD to ClangTool. Is it possible to do so with LibTooling API or CLI options in any way? It does not matter if it will include macros defined in a parsed source code or not.
I've looked at other similar questions, and as far as I can tell they all are about macros expanded in a parsed source code. That's not exactly what I need.
The answer is blindingly obvious—in retrospect. clang::Preprocessor::getPredefines() returns just that—a list of compiler predefines. The preprocessor object can be obtained e.g. from clang::CompilerInstance, as an argument in clang::DiagnosticConsumer::BeginSourceFile(), etc.
Just for the sake of completeness, this functionality is not available via libclang API, but I could do that using the fact that all predefines are present in the beginning of a translation unit. So after parsing I just listed all top-level cursors of CursorKind.MACRO_DEFINITION that are not in any real location (location.file is None using python bindings notation)

Can I control HSA config generated by AMDGPU backend?

I am using llvm clang to offline compile my opencl code into assembly. My target is amdgpu--amdhsa. The assembly file generated by clang has config of "enable_sgpr_dispatch_ptr = 1". Can I do something to turn that off in the generated assembly file? Also, it seems that the order of kernel arguments is in the reverse order of AMDCL2 convention. i.e. user argument is placed at the first place while hidden arguments like "HiddenGlobalOffsetX" are placed after user arguments. Can I change the order of the arguments so that the first argument will be hidden arguments before user arguments?

Why did JSLint mark this line as an error

/*global THREE Coordinates $ document window*/
JSLint says it was expecting */ but got Coordinates instead
but the line passed when passed when I ran it in Eclipse javascript project.
Js lint thought you were using the /*global*/ directive. This is used to indicate a variable is global and somewhere else.
See: JS Lint Global Directive

How can I pass the arguments to the lua file through the lua CLI

I have a LUA CLI which takes in the lua command,
Something like this
(lua)> #
Now here inorder to execute the lua file I run the command
(lua)> # dofile("a.lua")
I want a command which will execute the file and also pass a argument to it.
Now here I want to pass a argument to the "a.lua" file which will take this argument and call one more lua file, and this 2nd lua file is called according to the argument, So, I need to parse this argument.
Please, can somebody tell me about the parsing commands that will be used in a.lua. I mean what are the functions to be used to parse it.
Please, can somebody tell me how to pass a argument to this file "a.lua".
Now here inorder to execute the lua file I run the command
This is generally not how you execute Lua files. Usually, if you have some Lua script, you execute it with this command: lua a.lua. You don't type lua and then use the interface there to execute it.
Using a proper command line to execute the script, you can pass string parameters to the file: lua a.lua someParam "Param with spaces". The a.lua script can then fetch these parameters using the standard Lua ... mechanic:
local params = {...}
params[1] -- first parameter, if any.
params[2] -- second parameter, if any.
#params -- number of parameters.
However, if you insist on trying to execute this using your method of invoking the interpreter (with lua) and typing commands into it one by one, then you can do this:
> GlobalVariable = assert(loadfile(`a.lua`))
> GlobalVariable(--[[Insert parameters here]])
However, if you don't want to do it in two steps, with the intermediate global variable, you can do it in one:
> assert(loadfile(`a.lua`))(--[[Insert parameters here]])

Resources